public final class utf util extends test case public void test fake utfutil testcase testfake private filename generator fg public temp bucket migration test throws io exception fg new filename generator weakprng false null junit filenamegenerator tempbucketmigrationtest ioexception filenamegenerator public void test ram limit create throws io exception temp bucket factory tbf new temp bucket factory exec fg 16 128 strongprng weakprng false int max ram bucket 128 16 create excess max total ram size last one should be on disk temp bucket b new temp bucket max ram bucket 1 for int i 0 i max ram bucket 1 i b i temp bucket tbf make bucket 16 output stream os b i get output stream os write new byte 16 os close try assert true b 0 isram bucket assert false b max ram bucket isram bucket free some reused the space b 0 free b max ram bucket free b 0 temp bucket tbf make bucket 8 b max ram bucket temp bucket tbf make bucket 8 assert true b 0 isram bucket assert true b max ram bucket isram bucket finally for bucket bb b bb free testramlimitcreate ioexception tempbucketfactory tempbucketfactory maxrambucket maxtotalramsize tempbucket tempbucket maxrambucket maxrambucket tempbucket makebucket outputstream getoutputstream asserttrue isrambucket assertfalse maxrambucket isrambucket maxrambucket tempbucket makebucket maxrambucket tempbucket makebucket asserttrue isrambucket asserttrue maxrambucket isrambucket public void test write excess conversion factor throws io exception temp bucket factory tbf new temp bucket factory exec fg 16 128 strongprng weakprng false temp bucket b temp bucket tbf make bucket 16 try assert true b isram bucket output stream os b get output stream os write new byte 16 assert true b isram bucket for int i 0 i temp bucket factory rambucket conversion factor 1 i os write new byte 16 assert false b isram bucket finally b free testwriteexcessconversionfactor ioexception tempbucketfactory tempbucketfactory tempbucket tempbucket makebucket asserttrue isrambucket outputstream getoutputstream asserttrue isrambucket tempbucketfactory rambucket_conversion_factor assertfalse isrambucket public void test write excess limit throws io exception temp bucket factory tbf new temp bucket factory exec fg 16 17 strongprng weakprng false temp bucket b temp bucket tbf make bucket 16 try assert true b isram bucket output stream os b get output stream os write new byte 16 assert true b isram bucket os write new byte 2 assert false b isram bucket finally b free testwriteexcesslimit ioexception tempbucketfactory tempbucketfactory tempbucket tempbucket makebucket asserttrue isrambucket outputstream getoutputstream asserttrue isrambucket assertfalse isrambucket this can happen due to memory pressure public void test conversion while reading throws io exception temp bucket factory tbf new temp bucket factory exec fg 1024 65536 strongprng weakprng false temp bucket bucket temp bucket tbf make bucket 64 output stream os bucket get output stream os write new byte 16 input stream is bucket get input stream bucket migrate to file bucket byte read to new byte 16 assert true is read read to 0 16 16 for int i 0 i read to length i assert true read to i 0 is close os close testconversionwhilereading ioexception tempbucketfactory tempbucketfactory tempbucket tempbucket makebucket outputstream getoutputstream inputstream getinputstream migratetofilebucket readto asserttrue readto readto asserttrue readto do a bigger read verify contents public void test big conversion while reading throws io exception temp bucket factory tbf new temp bucket factory exec fg 4096 65536 strongprng weakprng false temp bucket bucket temp bucket tbf make bucket 2048 output stream os bucket get output stream byte data new byte 2048 new random 89 next bytes data os write data input stream is bucket get input stream bucket migrate to file bucket byte read to new byte 2048 new data input stream is read fully read to for int i 0 i read to length i assert true read to i data i is close os close testbigconversionwhilereading ioexception tempbucketfactory tempbucketfactory tempbucket tempbucket makebucket outputstream getoutputstream nextbytes inputstream getinputstream migratetofilebucket readto datainputstream readfully readto readto asserttrue readto public realtempbuckettest int max ram size int max total ram size boolean encrypted throws io exception fg new filename generator weakprng false null junit tbf new temp bucket factory exec fg max ram size max total ram size strongprng weakprng encrypted can overwrite false realtempbuckettest_ maxramsize maxtotalramsize ioexception filenamegenerator tempbucketfactory maxramsize maxtotalramsize canoverwrite override protected void free bucket bucket bucket throws io exception bucket free freebucket ioexception override protected bucket make bucket long size throws io exception return tbf make bucket 1 temp bucket allow resize makebucket ioexception makebucket tempbucket public static class realtempbuckettest 8 16 f extends realtempbuckettest public realtempbuckettest 8 16 f throws io exception super 8 16 false realtempbuckettest_8_16_f realtempbuckettest_ realtempbuckettest_8_16_f ioexception public static class realtempbuckettest 64 128 f extends realtempbuckettest public realtempbuckettest 64 128 f throws io exception super 64 128 false realtempbuckettest_64_128_f realtempbuckettest_ realtempbuckettest_64_128_f ioexception public static class realtempbuckettest 64k 128k f extends realtempbuckettest public realtempbuckettest 64k 128k f throws io exception super 64 1024 128 1024 false realtempbuckettest_64k_128k_f realtempbuckettest_ realtempbuckettest_64k_128k_f ioexception public static class realtempbuckettest 8 16 t extends realtempbuckettest public realtempbuckettest 8 16 t throws io exception super 8 16 true realtempbuckettest_8_16_t realtempbuckettest_ realtempbuckettest_8_16_t ioexception public static class realtempbuckettest 64k 128k t extends realtempbuckettest public realtempbuckettest 64k 128k t throws io exception super 64 1024 128 1024 true realtempbuckettest_64k_128k_t realtempbuckettest_ realtempbuckettest_64k_128k_t ioexception public temp bucket test super temp bucket test add test new test suite realtempbuckettest 8 16 f class add test new test suite realtempbuckettest 64 128 f class add test new test suite realtempbuckettest 64k 128k f class add test new test suite realtempbuckettest 8 16 t class add test new test suite realtempbuckettest 64k 128k t class add test new test suite temp bucket migration test class tempbuckettest tempbuckettest addtest testsuite realtempbuckettest_8_16_f addtest testsuite realtempbuckettest_64_128_f addtest testsuite realtempbuckettest_64k_128k_f addtest testsuite realtempbuckettest_8_16_t addtest testsuite realtempbuckettest_64k_128k_t addtest testsuite tempbucketmigrationtest public static test suite test suite suite new test suite temp bucket test suite add test new test suite realtempbuckettest 8 16 f class suite add test new test suite realtempbuckettest 64 128 f class suite add test new test suite realtempbuckettest 64k 128k f class suite add test new test suite realtempbuckettest 8 16 t class suite add test new test suite realtempbuckettest 64k 128k t class suite add test new test suite temp bucket migration test class return suite testsuite testsuite tempbuckettest addtest testsuite realtempbuckettest_8_16_f addtest testsuite realtempbuckettest_64_128_f addtest testsuite realtempbuckettest_64k_128k_f addtest testsuite realtempbuckettest_8_16_t addtest testsuite realtempbuckettest_64k_128k_t addtest testsuite tempbucketmigrationtest byte 0xd6 byte 0xe7 byte 0xf8 protected abstract bucket make bucket long size throws io exception makebucket ioexception protected abstract bucket make bucket long size throws io exception protected abstract void free bucket bucket bucket throws io exception makebucket ioexception freebucket ioexception public void test read empty throws io exception bucket bucket make bucket 3 try assert equals size 0 0 bucket size output stream os bucket get output stream os close read byte input stream is bucket get input stream byte data new byte 10 int read is read data 0 10 is close assert equals read empty 1 read finally free bucket bucket testreadempty ioexception makebucket assertequals outputstream getoutputstream inputstream getinputstream assertequals freebucket public void test read excess throws io exception bucket bucket make bucket math max data1 length data2 length try assert equals size 0 0 bucket size write output stream os bucket get output stream os write new byte 5 os close assert equals read excess size 1 bucket size read byte input stream is bucket get input stream byte data new byte 10 int read is read data 0 10 assert equals read excess 1 read assert equals read excess 5 5 data 0 read is read data 0 10 assert equals read excess eof 1 read is close finally free bucket bucket testreadexcess ioexception makebucket assertequals outputstream getoutputstream assertequals inputstream getinputstream assertequals assertequals assertequals freebucket public void test read write throws io exception bucket bucket make bucket math max data1 length data2 length try assert equals size 0 0 bucket size write output stream os bucket get output stream os write data1 os close assert equals size 1 data1 length bucket size read byte input stream is bucket get input stream byte data new byte data1 length int read is read data 0 data1 length is close assert equals simple read 1 size data1 length read assert equals simple read 1 new byte array wrapper data1 new byte array wrapper data read byte is bucket get input stream for byte b data1 assert equals simple read 2 b byte is read eof assert equals simple read eof0 1 is read new byte 4 assert equals simple read eof1 1 is read assert equals simple read eof2 1 is read is close finally free bucket bucket testreadwrite ioexception makebucket assertequals outputstream getoutputstream assertequals inputstream getinputstream assertequals simpleread assertequals simpleread bytearraywrapper bytearraywrapper getinputstream assertequals simpleread assertequals simpleread assertequals simpleread assertequals simpleread freebucket write twice should overwrite not append public void test reuse throws io exception if can overwrite return bucket bucket make bucket math max data1 length data2 length try write output stream os bucket get output stream os write data1 os close read byte input stream is bucket get input stream byte data new byte data1 length int read is read data 0 data1 length is close assert equals read 1 size data1 length read assert equals read 1 new byte array wrapper data1 new byte array wrapper data write again os bucket get output stream os write data2 os close read byte is bucket get input stream data new byte data2 length read is read data 0 data2 length is close assert equals read 2 size data2 length read assert equals read 2 new byte array wrapper data2 new byte array wrapper data finally free bucket bucket testreuse ioexception canoverwrite makebucket outputstream getoutputstream inputstream getinputstream assertequals assertequals bytearraywrapper bytearraywrapper getoutputstream getinputstream assertequals assertequals bytearraywrapper bytearraywrapper freebucket public void test negative throws io exception bucket bucket make bucket math max data1 length data2 length try write output stream os bucket get output stream os write 0 os write 1 os write 2 os write 123 os close read byte input stream is bucket get input stream assert equals write 0 0xff byte 0 is read assert equals write 1 0xff byte 1 is read assert equals write 2 0xff byte 2 is read assert equals write 123 0xff byte 123 is read assert equals eof 1 is read is close finally free bucket bucket testnegative ioexception makebucket outputstream getoutputstream inputstream getinputstream assertequals assertequals assertequals assertequals assertequals freebucket public void test large data throws io exception bucket bucket make bucket data long length 16 try write output stream os bucket get output stream for int i 0 i 16 i os write data long os close read byte input stream is bucket get input stream for int i 0 i 16 i byte buf new byte data long length int read is read buf assert equals read long size data long length read assert equals read long new byte array wrapper data long new byte array wrapper buf int read is read new byte 1 assert equals read long size 1 read is close finally free bucket bucket testlargedata ioexception makebucket data_long outputstream getoutputstream data_long inputstream getinputstream data_long assertequals data_long assertequals bytearraywrapper data_long bytearraywrapper assertequals freebucket public void test read line without marking throws exception try utf8 input stream is new byte array input stream stressed line get bytes utf 8 line reading input stream instance new line reading input stream is assert equals instance read line without marking max length buffer size true assert equals u0114 instance read line without marking max length buffer size true assert null instance read line without marking max length buffer size true try iso 8859 1 is new byte array input stream block get bytes iso 8859 1 instance new line reading input stream is for string expected line lines assert equals expected line instance read line without marking max length buffer size false assert null instance read line without marking max length buffer size false is it returning null is new mock input stream instance new line reading input stream is assert null instance read line without marking 0 buffer size false assert null instance read line without marking 0 0 false is it throwing is new byte array input stream length checking line get bytes instance new line reading input stream is try instance read line without marking length checking line lf 1 buffer size true fail catch too long exception e same test shouldn t throw is new byte array input stream length checking line get bytes instance new line reading input stream is assert equals length checking line substring 0 length checking line lf instance read line without marking length checking line lf buffer size true is it handling nulls properly see 2501 is new byte array input stream null line get bytes instance new line reading input stream is assert equals null line substring 0 5 instance read line without marking buffer size 1 true testreadlinewithoutmarking inputstream bytearrayinputstream stressed_line getbytes linereadinginputstream linereadinginputstream assertequals readlinewithoutmarking max_length buffer_size assertequals readlinewithoutmarking max_length buffer_size assertnull readlinewithoutmarking max_length buffer_size bytearrayinputstream getbytes linereadinginputstream expectedline assertequals expectedline readlinewithoutmarking max_length buffer_size assertnull readlinewithoutmarking max_length buffer_size mockinputstream linereadinginputstream assertnull readlinewithoutmarking buffer_size assertnull readlinewithoutmarking bytearrayinputstream length_checking_line getbytes linereadinginputstream readlinewithoutmarking length_checking_line_lf buffer_size toolongexception bytearrayinputstream length_checking_line getbytes linereadinginputstream assertequals length_checking_line length_checking_line_lf readlinewithoutmarking length_checking_line_lf buffer_size bytearrayinputstream null_line getbytes linereadinginputstream assertequals null_line readlinewithoutmarking buffer_size public void test read line throws exception try utf8 input stream is new byte array input stream stressed line get bytes utf 8 line reading input stream instance new line reading input stream is assert equals instance read line max length buffer size true assert equals u0114 instance read line max length buffer size true assert null instance read line max length buffer size true try iso 8859 1 is new byte array input stream block get bytes iso 8859 1 instance new line reading input stream is for string expected line lines assert equals expected line instance read line max length buffer size false assert null instance read line max length buffer size false is it returning null and blocking when it should be is new mock input stream instance new line reading input stream is assert null instance read line 0 buffer size false assert null instance read line 0 0 false is it throwing is new byte array input stream length checking line get bytes instance new line reading input stream is try instance read line length checking line lf 1 buffer size true fail catch too long exception e same test shouldn t throw is new byte array input stream length checking line get bytes instance new line reading input stream is assert equals length checking line substring 0 length checking line lf instance read line length checking line lf buffer size true is it handling nulls properly see 2501 is new byte array input stream null line get bytes instance new line reading input stream is assert equals null line substring 0 5 instance read line buffer size 1 true testreadline inputstream bytearrayinputstream stressed_line getbytes linereadinginputstream linereadinginputstream assertequals readline max_length buffer_size assertequals readline max_length buffer_size assertnull readline max_length buffer_size bytearrayinputstream getbytes linereadinginputstream expectedline assertequals expectedline readline max_length buffer_size assertnull readline max_length buffer_size mockinputstream linereadinginputstream assertnull readline buffer_size assertnull readline bytearrayinputstream length_checking_line getbytes linereadinginputstream readline length_checking_line_lf buffer_size toolongexception bytearrayinputstream length_checking_line getbytes linereadinginputstream assertequals length_checking_line length_checking_line_lf readline length_checking_line_lf buffer_size bytearrayinputstream null_line getbytes linereadinginputstream assertequals null_line readline buffer_size public void test both implementation throws exception cwd is either the node s or the build tree file f new file freenet ini if f exists f new file build xml buffered input stream bis1 new buffered input stream new file input stream f buffered input stream bis2 new buffered input stream new file input stream f line reading input stream lris1 new line reading input stream bis1 line reading input stream lris2 new line reading input stream bis2 while bis1 available 0 bis2 available 0 string string without mark lris2 read line without marking max length 10 buffer size true string string with mark lris1 read line max length 10 buffer size true assert equals string with mark string without mark assert null lris1 read line max length buffer size true assert null lris2 read line without marking max length buffer size true testbothimplementation bufferedinputstream bufferedinputstream fileinputstream bufferedinputstream bufferedinputstream fileinputstream linereadinginputstream linereadinginputstream linereadinginputstream linereadinginputstream stringwithoutmark readlinewithoutmarking max_length buffer_size stringwithmark readline max_length buffer_size assertequals stringwithmark stringwithoutmark assertnull readline max_length buffer_size assertnull readlinewithoutmarking max_length buffer_size test gzip compressor s identity and functionality public void test gzip compressor compressor compressor type gzip compressor compressor compressor type gzip compressor compressor zero compressor compressor type get compressor by metadataid short 0 check gzip is the first compressor assert equals gzip compressor compressor zero testgzipcompressor compressor_type gzipcompressor compressor_type compressorzero compressor_type getcompressorbymetadataid assertequals gzipcompressor compressorzero public void test compress do gzip compression byte compressed data do compress uncompressed data 1 get bytes output size same as expected assert equals compressed data length compressed data 1 length check each byte is exactly as expected for int i 0 i compressed data length i assert equals compressed data 1 i compressed data i testcompress compresseddata docompress uncompressed_data_1 getbytes assertequals compresseddata compressed_data_1 compresseddata assertequals compressed_data_1 compresseddata public void test bucket decompress byte compressed data compressed data 1 do gzip decompression with buckets byte uncompressed data do bucket decompress compressed data is the round tripped uncompressed string the same as the original string uncompressed string new string uncompressed data assert equals uncompressed string uncompressed data 1 testbucketdecompress compresseddata compressed_data_1 uncompresseddata dobucketdecompress compresseddata uncompressedstring uncompresseddata assertequals uncompressedstring uncompressed_data_1 public void test byte array decompress build 5k array byte original uncompressed data new byte 5 1024 for int i 0 i original uncompressed data length i original uncompressed data i 1 byte compressed data do compress original uncompressed data byte out uncompressed data new byte 5 1024 int written bytes 0 try written bytes compressor compressor type gzip decompress compressed data 0 compressed data length out uncompressed data catch compression output size exception e fail unexpected exception thrown e get message assert equals written bytes original uncompressed data length assert equals original uncompressed data length out uncompressed data length check each byte is exactly as expected for int i 0 i out uncompressed data length i assert equals original uncompressed data i out uncompressed data i testbytearraydecompress originaluncompresseddata originaluncompresseddata originaluncompresseddata compresseddata docompress originaluncompresseddata outuncompresseddata writtenbytes writtenbytes compressor_type compresseddata compresseddata outuncompresseddata compressionoutputsizeexception getmessage assertequals writtenbytes originaluncompresseddata assertequals originaluncompresseddata outuncompresseddata outuncompresseddata assertequals originaluncompresseddata outuncompresseddata public void test compress exception byte uncompressed data uncompressed data 1 get bytes bucket in bucket new array bucket uncompressed data bucket factory factory new array bucket factory try compressor compressor type gzip compress in bucket factory 32 32 catch io exception e fail unexpected exception thrown e get message catch compression output size exception e expect this testcompressexception uncompresseddata uncompressed_data_1 getbytes inbucket arraybucket uncompresseddata bucketfactory arraybucketfactory compressor_type inbucket ioexception getmessage compressionoutputsizeexception public void test decompress exception build 5k array byte uncompressed data new byte 5 1024 for int i 0 i uncompressed data length i uncompressed data i 1 byte compressed data do compress uncompressed data bucket in bucket new array bucket compressed data bucket factory factory new array bucket factory try compressor compressor type gzip decompress in bucket factory 4096 10 4096 20 null catch io exception e fail unexpected exception thrown e get message catch compression output size exception e expect this testdecompressexception uncompresseddata uncompresseddata uncompresseddata compresseddata docompress uncompresseddata inbucket arraybucket compresseddata bucketfactory arraybucketfactory compressor_type inbucket ioexception getmessage compressionoutputsizeexception private byte do bucket decompress byte compressed data bucket in bucket new array bucket compressed data bucket factory factory new array bucket factory bucket out bucket null try out bucket compressor compressor type gzip decompress in bucket factory 32768 32768 2 null catch io exception e fail unexpected exception thrown e get message catch compression output size exception e fail unexpected exception thrown e get message input stream in null try in out bucket get input stream catch io exception e1 fail unexpected exception thrown e1 get message long size out bucket size byte out buf new byte int size try in read out buf catch io exception e fail unexpected exception thrown e get message return out buf dobucketdecompress compresseddata inbucket arraybucket compresseddata bucketfactory arraybucketfactory outbucket outbucket compressor_type inbucket ioexception getmessage compressionoutputsizeexception getmessage inputstream outbucket getinputstream ioexception getmessage outbucket outbuf outbuf ioexception getmessage outbuf private byte do compress byte uncompressed data bucket in bucket new array bucket uncompressed data bucket factory factory new array bucket factory bucket out bucket null try out bucket compressor compressor type gzip compress in bucket factory 32768 32768 catch io exception e fail unexpected exception thrown e get message catch compression output size exception e fail unexpected exception thrown e get message input stream in null try in out bucket get input stream catch io exception e1 fail unexpected exception thrown e1 get message long size out bucket size byte out buf new byte int size try in read out buf catch io exception e fail unexpected exception thrown e get message return out buf docompress uncompresseddata inbucket arraybucket uncompresseddata bucketfactory arraybucketfactory outbucket outbucket compressor_type inbucket ioexception getmessage compressionoutputsizeexception getmessage inputstream outbucket getinputstream ioexception getmessage outbucket outbuf outbuf ioexception getmessage outbuf test bzip2 compressor s identity and functionality public void test bzip2 compressor compressor compressor type bz2compressor compressor compressor type bzip2 compressor compressor zero compressor compressor type get compressor by metadataid short 1 check bzip2 is the second compressor assert equals bz2compressor compressor zero testbzip2compressor compressor_type compressor_type compressorzero compressor_type getcompressorbymetadataid assertequals compressorzero public void test compress do bzip2 compression byte compressed data do compress uncompressed data 1 get bytes output size same as expected assert equals compressed data length compressed data 1 length check each byte is exactly as expected for int i 0 i compressed data length i assert equals compressed data 1 i compressed data i testcompress compresseddata docompress uncompressed_data_1 getbytes assertequals compresseddata compressed_data_1 compresseddata assertequals compressed_data_1 compresseddata public void test bucket decompress byte compressed data compressed data 1 do bzip2 decompression with buckets byte uncompressed data do bucket decompress compressed data is the round tripped uncompressed string the same as the original string uncompressed string new string uncompressed data assert equals uncompressed string uncompressed data 1 testbucketdecompress compresseddata compressed_data_1 uncompresseddata dobucketdecompress compresseddata uncompressedstring uncompresseddata assertequals uncompressedstring uncompressed_data_1 public void test byte array decompress build 5k array byte original uncompressed data new byte 5 1024 for int i 0 i original uncompressed data length i original uncompressed data i 1 byte compressed data do compress original uncompressed data byte out uncompressed data new byte 5 1024 int written bytes 0 try written bytes compressor compressor type bzip2 decompress compressed data 0 compressed data length out uncompressed data catch compression output size exception e fail unexpected exception thrown e get message assert equals written bytes original uncompressed data length assert equals original uncompressed data length out uncompressed data length check each byte is exactly as expected for int i 0 i out uncompressed data length i assert equals original uncompressed data i out uncompressed data i testbytearraydecompress originaluncompresseddata originaluncompresseddata originaluncompresseddata compresseddata docompress originaluncompresseddata outuncompresseddata writtenbytes writtenbytes compressor_type compresseddata compresseddata outuncompresseddata compressionoutputsizeexception getmessage assertequals writtenbytes originaluncompresseddata assertequals originaluncompresseddata outuncompresseddata outuncompresseddata assertequals originaluncompresseddata outuncompresseddata public void test compress exception byte uncompressed data uncompressed data 1 get bytes bucket in bucket new array bucket uncompressed data bucket factory factory new array bucket factory try compressor compressor type bzip2 compress in bucket factory 32 32 catch io exception e fail unexpected exception thrown e get message catch compression output size exception e expect this testcompressexception uncompresseddata uncompressed_data_1 getbytes inbucket arraybucket uncompresseddata bucketfactory arraybucketfactory compressor_type inbucket ioexception getmessage compressionoutputsizeexception public void test decompress exception build 5k array byte uncompressed data new byte 5 1024 for int i 0 i uncompressed data length i uncompressed data i 1 byte compressed data do compress uncompressed data bucket in bucket new array bucket compressed data bucket factory factory new array bucket factory try compressor compressor type bzip2 decompress in bucket factory 4096 10 4096 20 null catch io exception e fail unexpected exception thrown e get message catch compression output size exception e expect this testdecompressexception uncompresseddata uncompresseddata uncompresseddata compresseddata docompress uncompresseddata inbucket arraybucket compresseddata bucketfactory arraybucketfactory compressor_type inbucket ioexception getmessage compressionoutputsizeexception private byte do bucket decompress byte compressed data bucket in bucket new array bucket compressed data bucket factory factory new array bucket factory bucket out bucket null try out bucket compressor compressor type bzip2 decompress in bucket factory 32768 32768 2 null catch io exception e fail unexpected exception thrown e get message catch compression output size exception e fail unexpected exception thrown e get message input stream in null try in out bucket get input stream catch io exception e1 fail unexpected exception thrown e1 get message long size out bucket size byte out buf new byte int size try in read out buf catch io exception e fail unexpected exception thrown e get message return out buf dobucketdecompress compresseddata inbucket arraybucket compresseddata bucketfactory arraybucketfactory outbucket outbucket compressor_type inbucket ioexception getmessage compressionoutputsizeexception getmessage inputstream outbucket getinputstream ioexception getmessage outbucket outbuf outbuf ioexception getmessage outbuf private byte do compress byte uncompressed data bucket in bucket new array bucket uncompressed data bucket factory factory new array bucket factory bucket out bucket null try out bucket compressor compressor type bzip2 compress in bucket factory 32768 32768 catch io exception e fail unexpected exception thrown e get message catch compression output size exception e fail unexpected exception thrown e get message input stream in null try in out bucket get input stream catch io exception e1 fail unexpected exception thrown e1 get message long size out bucket size byte out buf new byte int size try in read out buf catch io exception e fail unexpected exception thrown e get message return out buf docompress uncompresseddata inbucket arraybucket uncompresseddata bucketfactory arraybucketfactory outbucket outbucket compressor_type inbucket ioexception getmessage compressionoutputsizeexception getmessage inputstream outbucket getinputstream ioexception getmessage outbucket outbuf outbuf ioexception getmessage outbuf creates an array of objects with a specified size param size the array size return the objects array private object create sample objects int size object sample objects new object size for int i 0 i sample objects length i sample objects i new object return sample objects createsampleobjects sampleobjects sampleobjects sampleobjects sampleobjects creates a lru queue filled with the specified objects number param size queue size return the created lru queue private lru queue object create sample queue int size lru queue object methodlru queue new lru queue object object sample objects create sample objects size for int i 0 i sample objects length i methodlru queue push sample objects i return methodlru queue lruqueue lruqueue lruqueue createsamplequeue lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleobjects methodlruqueue sampleobjects methodlruqueue verifies if an element is present in an array param an array the array to search into param a element to search the object that must be found return true if there is at least one reference to the object private boolean is present object an array object a element to search for int i 0 i an array length i if an array i equals a element to search return true return false anarray aelementtosearch ispresent anarray aelementtosearch anarray anarray aelementtosearch verifies if the order of the last two elements in the queue is correct param alru queue the lru queue to check param next to last the next to last element expected param last the last element expected return true if the order is correct private boolean verify last elems order lru queue object alru queue object next to last object last boolean ret val true int size alru queue size enumeration object method enum alru queue elements int counter 0 while method enum has more elements next to last object if counter size 2 ret val method enum next element equals next to last last object else if counter size 1 ret val method enum next element equals last else method enum next element counter return ret val alruqueue lruqueue nexttolast verifylastelemsorder lruqueue alruqueue nexttolast retval alruqueue methodenum alruqueue methodenum hasmoreelements retval methodenum nextelement nexttolast retval methodenum nextelement methodenum nextelement retval tests link lru queue push object method providing a null object as argument after setting up a sample queue and verifying if the correct exception is raised public void test push null lru queue object methodlru queue this create sample queue sample elems number try methodlru queue push null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception try methodlru queue push least null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception lruqueue testpushnull lruqueue methodlruqueue createsamplequeue sampleelemsnumber methodlruqueue nullpointerexception anexception assertnotnull anexception methodlruqueue pushleast nullpointerexception anexception assertnotnull anexception tests link lru queue push object method and verifies the behaviour when pushing the same object more than one time public void test push same obj twice lru queue object methodlru queue this create sample queue sample elems number object sample obj new object new object methodlru queue push sample obj 0 methodlru queue push sample obj 1 check size assert equals sample elems number 2 methodlru queue size check order assert true verify last elems order methodlru queue sample obj 0 sample obj 1 methodlru queue push sample obj 0 check size assert equals sample elems number 2 methodlru queue size check order assert true verify last elems order methodlru queue sample obj 1 sample obj 0 lruqueue testpushsameobjtwice lruqueue methodlruqueue createsamplequeue sampleelemsnumber sampleobj methodlruqueue sampleobj methodlruqueue sampleobj assertequals sampleelemsnumber methodlruqueue asserttrue verifylastelemsorder methodlruqueue sampleobj sampleobj methodlruqueue sampleobj assertequals sampleelemsnumber methodlruqueue asserttrue verifylastelemsorder methodlruqueue sampleobj sampleobj tests link lru queue push least object method public void test push least lru queue object methodlru queue new lru queue object object sample obj new object new object methodlru queue push sample obj 0 methodlru queue push least sample obj 1 assert equals 2 methodlru queue size assert true verify last elems order methodlru queue sample obj 1 sample obj 0 same element methodlru queue push least sample obj 0 assert equals 2 methodlru queue size assert true verify last elems order methodlru queue sample obj 0 sample obj 1 lruqueue pushleast testpushleast lruqueue methodlruqueue lruqueue sampleobj methodlruqueue sampleobj methodlruqueue pushleast sampleobj assertequals methodlruqueue asserttrue verifylastelemsorder methodlruqueue sampleobj sampleobj methodlruqueue pushleast sampleobj assertequals methodlruqueue asserttrue verifylastelemsorder methodlruqueue sampleobj sampleobj tests link lru queue pop method pushing and popping objects and verifying if they are correctly in a fifo manner fetched and deleted public void test pop lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i getting objects for int i 0 i sample objects length i assert equals sample objects i methodlru queue pop the queue must be empty assert null methodlru queue pop lruqueue testpop lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects sampleobjects assertequals sampleobjects methodlruqueue assertnull methodlruqueue tests link lru queue size method checking size when empty when putting each object and when popping each object public void test size object sample objects create sample objects sample elems number lru queue object methodlru queue new lru queue object assert equals 0 methodlru queue size pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i assert equals i 1 methodlru queue size getting all objects for int i sample objects length 1 i 0 i methodlru queue pop assert equals i methodlru queue size assert equals 0 methodlru queue size lruqueue testsize sampleobjects createsampleobjects sampleelemsnumber lruqueue methodlruqueue lruqueue assertequals methodlruqueue sampleobjects methodlruqueue sampleobjects assertequals methodlruqueue sampleobjects methodlruqueue assertequals methodlruqueue assertequals methodlruqueue tests link lru queue remove object method verifies if all objects are correctly removed checking the method return value if the object is still contained and the queue size public void test remove lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number for int i 0 i sample objects length i methodlru queue push sample objects i removing all objects in the opposite way used by pop method for int i sample objects length 1 i 0 i assert true methodlru queue remove sample objects i assert false methodlru queue contains sample objects i assert equals i methodlru queue size lruqueue testremove lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects sampleobjects asserttrue methodlruqueue sampleobjects assertfalse methodlruqueue sampleobjects assertequals methodlruqueue tests link lru queue remove object providing a null argument and trying to remove it after setting up a sample queue public void test remove null lru queue object methodlru queue create sample queue sample elems number try methodlru queue remove null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception lruqueue testremovenull lruqueue methodlruqueue createsamplequeue sampleelemsnumber methodlruqueue nullpointerexception anexception assertnotnull anexception tests link lru queue remove object method trying to remove a not present object after setting up a sample queue public void test remove not present lru queue object methodlru queue create sample queue sample elems number assert false methodlru queue remove new object lruqueue testremovenotpresent lruqueue methodlruqueue createsamplequeue sampleelemsnumber assertfalse methodlruqueue tests link lru queue contains object method trying to find a not present object after setting up a sample queue then it search a present object public void test contains lru queue object methodlru queue create sample queue sample elems number assert false methodlru queue contains new object object method sample obj new object methodlru queue push method sample obj assert true methodlru queue contains method sample obj lruqueue testcontains lruqueue methodlruqueue createsamplequeue sampleelemsnumber assertfalse methodlruqueue methodsampleobj methodlruqueue methodsampleobj asserttrue methodlruqueue methodsampleobj tests link lru queue elements method verifying if the enumeration provided is correct public void test elements object sample objects create sample objects sample elems number lru queue object methodlru queue new lru queue object pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i enumeration object method enumeration methodlru queue elements int j 0 while method enumeration has more elements assert equals sample objects j method enumeration next element j lruqueue testelements sampleobjects createsampleobjects sampleelemsnumber lruqueue methodlruqueue lruqueue sampleobjects methodlruqueue sampleobjects methodenumeration methodlruqueue methodenumeration hasmoreelements assertequals sampleobjects methodenumeration nextelement tests link lru queue to array method verifying if the array generated has the same object that are put into the created lru queue public void test to array lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i object resulting array methodlru queue to array assert equals sample objects length resulting array length for int i 0 i sample objects length i assert true is present resulting array sample objects i lruqueue toarray lruqueue testtoarray lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects resultingarray methodlruqueue toarray assertequals sampleobjects resultingarray sampleobjects asserttrue ispresent resultingarray sampleobjects tests link lru queue to array object method public void test to array2 lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i object resulting array new object sample objects length methodlru queue to array resulting array assert equals sample objects length resulting array length for int i 0 i sample objects length i assert true is present resulting array sample objects i lruqueue toarray testtoarray2 lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects resultingarray sampleobjects methodlruqueue toarray resultingarray assertequals sampleobjects resultingarray sampleobjects asserttrue ispresent resultingarray sampleobjects tests link lru queue to array ordered method public void test to array ordered lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i object resulting array methodlru queue to array ordered assert equals sample objects length resulting array length for int i 0 i sample objects length i assert equals sample objects i resulting array i lruqueue toarrayordered testtoarrayordered lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects resultingarray methodlruqueue toarrayordered assertequals sampleobjects resultingarray sampleobjects assertequals sampleobjects resultingarray tests code to array ordered object code method public void test to array ordered2 lru queue object methodlru queue new lru queue object object sample objects create sample objects sample elems number pushing objects for int i 0 i sample objects length i methodlru queue push sample objects i object resulting array new object sample objects length methodlru queue to array ordered resulting array assert equals resulting array length sample objects length for int i 0 i sample objects length i assert equals sample objects i resulting array i toarrayordered testtoarrayordered2 lruqueue methodlruqueue lruqueue sampleobjects createsampleobjects sampleelemsnumber sampleobjects methodlruqueue sampleobjects resultingarray sampleobjects methodlruqueue toarrayordered resultingarray assertequals resultingarray sampleobjects sampleobjects assertequals sampleobjects resultingarray tests to array method when the queue is empty public void test to array empty queue lru queue object methodlru queue new lru queue object assert equals 0 methodlru queue to array length toarray testtoarrayemptyqueue lruqueue methodlruqueue lruqueue assertequals methodlruqueue toarray tests is empty method trying it with an empty queue and then with a sample queue public void test is empty lru queue object methodlru queue new lru queue object assert true methodlru queue is empty methodlru queue create sample queue sample elems number assert false methodlru queue is empty emptying the queue for int i 0 i sample elems number i methodlru queue pop assert true methodlru queue is empty isempty testisempty lruqueue methodlruqueue lruqueue asserttrue methodlruqueue isempty methodlruqueue createsamplequeue sampleelemsnumber assertfalse methodlruqueue isempty sampleelemsnumber methodlruqueue asserttrue methodlruqueue isempty public void test loader object o null try o loader get instance java lang string catch invocation target exception e fail unexpected exception e get message catch no such method exception e fail unexpected exception e get message catch instantiation exception e fail unexpected exception e get message catch illegal access exception e fail unexpected exception e get message catch class not found exception e fail unexpected exception e get message assert true o instanceof java lang string testloader getinstance invocationtargetexception getmessage nosuchmethodexception getmessage instantiationexception getmessage illegalaccessexception getmessage classnotfoundexception getmessage asserttrue public void test wrapper byte data1 data string 1 get bytes byte data2 data string 2 get bytes byte array wrapper wrapper1 new byte array wrapper data1 byte array wrapper wrapper2 new byte array wrapper data1 byte array wrapper wrapper3 new byte array wrapper data2 assert equals wrapper1 wrapper2 assert true wrapper1 equals wrapper2 assert false wrapper2 equals wrapper3 assert false wrapper1 equals new string map byte array wrapper byte array wrapper map new hash map byte array wrapper byte array wrapper map put wrapper1 wrapper1 map put wrapper2 wrapper2 should clobber 1 by hashcode map put wrapper3 wrapper3 object o1 map get wrapper1 object o2 map get wrapper2 object o3 map get wrapper3 assert equals o1 o2 are wrapper1 and wrapper2 considered equivalent by hashcode assert false o1 wrapper1 did wrapper1 survive assert true o1 wrapper2 did wrapper1 get replaced by 2 assert true o3 wrapper3 did wrapper3 get returned by hashcode correctly testwrapper data_string_1 getbytes data_string_2 getbytes bytearraywrapper bytearraywrapper bytearraywrapper bytearraywrapper bytearraywrapper bytearraywrapper assertequals asserttrue assertfalse assertfalse bytearraywrapper bytearraywrapper hashmap bytearraywrapper bytearraywrapper assertequals assertfalse asserttrue asserttrue public void test format size long long method long method long long value of val and expected 0 0 assert equals size util format size method long long value 1 val and expected 0 1 for int i 1 i val and expected length i method long long value of val and expected i 0 assert equals size util format size method long long value 1 0 val and expected i 1 testformatsizelong methodlong methodlong valueof valandexpected assertequals sizeutil formatsize methodlong longvalue valandexpected valandexpected methodlong valueof valandexpected assertequals sizeutil formatsize methodlong longvalue valandexpected tests if format size long method works correctly with intermediate values i e 1 4 1 2 3 4 public void testformatsizelong withintermediatevalues long method long string actual value 1 0 1 25 1 5 1 75 for int i 1 i val and expected length i method long long value of val and expected i 0 for int j 0 j 4 j assert equals size util format size method long long value method long long value j 4 actual value j val and expected i 1 formatsize testformatsizelong_withintermediatevalues methodlong actualvalue valandexpected methodlong valueof valandexpected assertequals sizeutil formatsize methodlong longvalue methodlong longvalue actualvalue valandexpected private long one for term long 694861001 override protected void set up throws exception locale set default locale us onefortermlong setup setdefault tests format time long int boolean method trying the biggest long value public void testformattime longintboolean maxvalue string expected for max long value 15250284452w3d7h12m55 807s assert equals time util format time long max value 6 true expected for max long value formattime testformattime_longintboolean_maxvalue expectedformaxlongvalue assertequals timeutil formattime max_value expectedformaxlongvalue tests format time long int method trying the biggest long value public void testformattime longint string expected for max long value 15250284452w3d7h12m55s assert equals time util format time long max value 6 expected for max long value formattime testformattime_longint expectedformaxlongvalue assertequals timeutil formattime max_value expectedformaxlongvalue tests format time long method trying the biggest long value public void testformattime long it uses two terms by default string expected for max long value 15250284452w3d assert equals time util format time long max value expected for max long value formattime testformattime_long expectedformaxlongvalue assertequals timeutil formattime max_value expectedformaxlongvalue tests format time long method using known values they could be checked using google calculator http www google com intl en help features html calculator public void testformattime knownvalues long method long string val and expected one week 604800000 1w one day 86400000 1d one hour 3600000 1h one minute 60000 1m one second 1000 1s for int i 0 i val and expected length i method long long value of val and expected i 0 assert equals time util format time method long long value val and expected i 1 formattime testformattime_knownvalues methodlong valandexpected valandexpected methodlong valueof valandexpected assertequals timeutil formattime methodlong longvalue valandexpected tests format time long int method using a long value that generate every possible term kind it tests if the max terms arguments works correctly public void testformattime longintboolean maxterms string val and expected 0 terms 1 term 1w 2 terms 1w1d 3 terms 1w1d1h 4 terms 1w1d1h1m 5 terms 1w1d1h1m1s 6 terms 1w1d1h1m1 001s for int i 0 i val and expected length i assert equals time util format time one for term long i true val and expected i formattime maxterms testformattime_longintboolean_maxterms valandexpected valandexpected assertequals timeutil formattime onefortermlong valandexpected tests format time long int method using one millisecond time interval it tests if the with second fractions argument works correctly public void testformattime longintboolean milliseconds long method value 1 1ms assert equals time util format time method value 6 false 0 assert equals time util format time method value 6 true 0 001s formattime withsecondfractions testformattime_longintboolean_milliseconds methodvalue assertequals timeutil formattime methodvalue assertequals timeutil formattime methodvalue tests format time long int method using a long value that generate every possible term kind it tests if the max terms arguments works correctly public void testformattime longintboolean toomanyterms try time util format time one for term long 7 fail expected illegal argument exception not thrown catch illegal argument exception an exception assert not null an exception formattime maxterms testformattime_longintboolean_toomanyterms timeutil formattime onefortermlong illegalargumentexception illegalargumentexception anexception assertnotnull anexception creates a double array of objects with a specified size where object i 0 is the key and is an integer and object i 1 is the value param size the array size return the objects double array private object create sample key val int size object sample objects new object size 2 for int i 0 i sample objects length i key sample objects i 0 new integer i value sample objects i 1 new object return sample objects createsamplekeyval sampleobjects sampleobjects sampleobjects sampleobjects sampleobjects creates a lru hashtable filled with the specified objects number param size hash table size return the created lru hashtable private lru hashtable object object create sample hash table int size lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val size for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 return methodlr uht lruhashtable hashtable lruhashtable lruhashtable createsamplehashtable lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleobjects methodlruht sampleobjects sampleobjects methodlruht it verifies if a key value pair is present in a lru hashtable param alr uht a lru hashtable to check in param a key a key to find param a value the correspondent value return true if the key is present and returned value is the same as in the argument private boolean verify key val presence lru hashtable object object alr uht object a key object a value if alr uht contains key a key return alr uht get a key equals a value return false lruhashtable alruht lruhashtable akey avalue verifykeyvalpresence lruhashtable alruht akey avalue alruht containskey akey alruht akey avalue tests push object object method providing null object as arguments after setting up a sample hash table and verifying if the correct exception is raised public void test push null lru hashtable object object methodlr uht create sample hash table sample elems number try a null value is admitted methodlr uht push new object null catch null pointer exception an exception fail not expected exception thrown an exception get message try methodlr uht push null null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception try methodlr uht push null new object fail expected exception error not thrown catch null pointer exception an exception assert not null an exception hashtable testpushnull lruhashtable methodlruht createsamplehashtable sampleelemsnumber methodlruht nullpointerexception anexception anexception getmessage methodlruht nullpointerexception anexception assertnotnull anexception methodlruht nullpointerexception anexception assertnotnull anexception tests push object object method and verifies the behaviour when pushing the same object more than one time public void test push same obj twice lru hashtable object object methodlr uht create sample hash table sample elems number object sample obj new integer sample elems number new object new integer sample elems number 1 new object methodlr uht push sample obj 0 0 sample obj 0 1 methodlr uht push sample obj 1 0 sample obj 1 1 check presence assert true verify key val presence methodlr uht sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 1 0 sample obj 1 1 check size assert true methodlr uht size sample elems number 2 push the same object another time methodlr uht push sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 1 0 sample obj 1 1 assert true methodlr uht size sample elems number 2 testpushsameobjtwice lruhashtable methodlruht createsamplehashtable sampleelemsnumber sampleobj sampleelemsnumber sampleelemsnumber methodlruht sampleobj sampleobj methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue methodlruht sampleelemsnumber methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue methodlruht sampleelemsnumber tests push object object method and verifies the behaviour when pushing the same key with two different values public void test push same key lru hashtable object object methodlr uht create sample hash table sample elems number object sample obj new integer sample elems number new object new integer sample elems number 1 new object methodlr uht push sample obj 0 0 sample obj 0 1 methodlr uht push sample obj 1 0 sample obj 1 1 check presence assert true verify key val presence methodlr uht sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 1 0 sample obj 1 1 check size assert true methodlr uht size sample elems number 2 creating and pushing a different value sample obj 0 1 new object methodlr uht push sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 0 0 sample obj 0 1 assert true verify key val presence methodlr uht sample obj 1 0 sample obj 1 1 assert true methodlr uht size sample elems number 2 testpushsamekey lruhashtable methodlruht createsamplehashtable sampleelemsnumber sampleobj sampleelemsnumber sampleelemsnumber methodlruht sampleobj sampleobj methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue methodlruht sampleelemsnumber sampleobj methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue verifykeyvalpresence methodlruht sampleobj sampleobj asserttrue methodlruht sampleelemsnumber tests pop key method pushing and popping objects and verifying if their keys are correctly in a fifo manner fetched and the hash table entry deleted public void test pop key lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 getting keys for int i 0 i sample objects length i assert equals sample objects i 0 methodlr uht pop key the hash table must be empty assert null methodlr uht pop key popkey hashtable testpopkey lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects sampleobjects assertequals sampleobjects methodlruht popkey hashtable assertnull methodlruht popkey tests pop value method pushing and popping objects and verifying if their values are correctly in a fifo manner fetched and the hash table entry deleted public void test pop value lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 getting values for int i 0 i sample objects length i assert equals sample objects i 1 methodlr uht pop value the hash table must be empty assert null methodlr uht pop key popvalue hashtable testpopvalue lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects sampleobjects assertequals sampleobjects methodlruht popvalue hashtable assertnull methodlruht popkey tests pop value method popping a value from an empty lru hashtable public void test pop value from empty lru hashtable methodlr uht new lru hashtable object object assert null methodlr uht pop value popvalue lruhashtable testpopvaluefromempty lruhashtable methodlruht lruhashtable assertnull methodlruht popvalue tests peek value method pushing and popping objects and verifying if their peek value is correct public void test peek value lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 getting values for int i 0 i sample objects length i assert equals sample objects i 1 methodlr uht peek value methodlr uht pop key the hash table must be empty assert null methodlr uht peek value insert and fetch a null value methodlr uht push new object null assert null methodlr uht peek value peekvalue peekvalue testpeekvalue lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects sampleobjects assertequals sampleobjects methodlruht peekvalue methodlruht popkey hashtable assertnull methodlruht peekvalue methodlruht assertnull methodlruht peekvalue tests size method pushing and popping elements into the lru hash table public void test size lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number assert true methodlr uht size 0 pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 assert true methodlr uht size i 1 popping keys for int i sample objects length 1 i 0 i methodlr uht pop key assert true methodlr uht size i lruhashtable testsize lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber asserttrue methodlruht sampleobjects methodlruht sampleobjects sampleobjects asserttrue methodlruht sampleobjects methodlruht popkey asserttrue methodlruht tests remove key object method verifies if all elements are correctly removed checking the method return value if the element is still contained and the hash table size public void test remove key lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 popping keys for int i sample objects length 1 i 0 i assert true methodlr uht remove key sample objects i 0 assert false methodlr uht contains key sample objects i 0 assert true methodlr uht size i removekey hashtable testremovekey lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects sampleobjects asserttrue methodlruht removekey sampleobjects assertfalse methodlruht containskey sampleobjects asserttrue methodlruht tests remove key object providing a null key and trying to remove it after setting up a sample queue public void test remove null key lru hashtable object object methodlr uht create sample hash table sample elems number try methodlr uht remove key null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception removekey testremovenullkey lruhashtable methodlruht createsamplehashtable sampleelemsnumber methodlruht removekey nullpointerexception anexception assertnotnull anexception tests remove key object method trying to remove a not present key after setting up a sample lru hashtable public void test remove not present lru hashtable object object methodlr uht create sample hash table sample elems number assert false methodlr uht remove key new object removekey lruhashtable testremovenotpresent lruhashtable methodlruht createsamplehashtable sampleelemsnumber assertfalse methodlruht removekey tests contains key object method trying to find a not present key after setting up a sample queue then it search for a present one public void test contains key lru hashtable object object methodlr uht create sample hash table sample elems number assert false methodlr uht contains key new object object method sample obj new object methodlr uht push method sample obj null assert true methodlr uht contains key method sample obj containskey testcontainskey lruhashtable methodlruht createsamplehashtable sampleelemsnumber assertfalse methodlruht containskey methodsampleobj methodlruht methodsampleobj asserttrue methodlruht containskey methodsampleobj tests get object method trying to find a not present key after setting up a sample hash table then it search a present key public void test get lru hashtable object object methodlr uht create sample hash table sample elems number assert null methodlr uht get new object object method sample key new object object method sample value new object methodlr uht push method sample key method sample value assert equals methodlr uht get method sample key method sample value hashtable testget lruhashtable methodlruht createsamplehashtable sampleelemsnumber assertnull methodlruht methodsamplekey methodsamplevalue methodlruht methodsamplekey methodsamplevalue assertequals methodlruht methodsamplekey methodsamplevalue tests get object trying to fetch a null key public void test get null key lru hashtable object object methodlr uht create sample hash table sample elems number try methodlr uht get null fail expected exception error not thrown catch null pointer exception an exception assert not null an exception testgetnullkey lruhashtable methodlruht createsamplehashtable sampleelemsnumber methodlruht nullpointerexception anexception assertnotnull anexception tests keys method verifying if the enumeration provided is correct public void test keys lru hashtable object object methodlr uht new lru hashtable object object object sample objects create sample key val sample elems number pushing objects for int i 0 i sample objects length i methodlr uht push sample objects i 0 sample objects i 1 enumeration object method enumeration methodlr uht keys int j 0 while method enumeration has more elements assert equals method enumeration next element sample objects j 0 j testkeys lruhashtable methodlruht lruhashtable sampleobjects createsamplekeyval sampleelemsnumber sampleobjects methodlruht sampleobjects sampleobjects methodenumeration methodlruht methodenumeration hasmoreelements assertequals methodenumeration nextelement sampleobjects tests is empty method trying it with a new generated hash table and after popping out all keys in a sample lru hash table public void test is empty lru hashtable object object methodlr uht new lru hashtable object object assert true methodlr uht is empty methodlr uht create sample hash table sample elems number popping keys for int i 0 i sample elems number i methodlr uht pop key assert true methodlr uht is empty isempty hashtable lruhashtable testisempty lruhashtable methodlruht lruhashtable asserttrue methodlruht isempty methodlruht createsamplehashtable sampleelemsnumber sampleelemsnumber methodlruht popkey asserttrue methodlruht isempty public void test hex to long long l1 fields hex to long 0 assert equals l1 0 l1 fields hex to long 000000 assert equals l1 0 l1 fields hex to long 1 assert equals l1 1 l1 fields hex to long a assert equals l1 10 l1 fields hex to long ff assert equals l1 255 l1 fields hex to long ffffffff assert equals l1 4294967295l l1 fields hex to long 7fffffffffffffff assert equals l1 long max value l1 fields hex to long 8000000000000000 assert equals l1 long min value l1 fields hex to long f ffff fff mix case assert equals l1 4294967295l try l1 fields hex to long abcdef123456789aa 17 chars fail catch number format exception e expect this try l1 fields hex to long deadc0der invalid char fail catch number format exception e expect this see javadoc l1 fields hex to long long to hex string 20 assert equals 20 l1 l1 fields hex to long long to hex string long min value assert equals long min value l1 see javadoc try string long as string long to string 1 16 l1 fields hex to long long as string fail catch number format exception e expect this testhextolong hextolong assertequals hextolong assertequals hextolong assertequals hextolong assertequals hextolong assertequals hextolong assertequals hextolong assertequals max_value hextolong assertequals min_value hextolong ffffffff assertequals hextolong numberformatexception hextolong numberformatexception hextolong tohexstring assertequals hextolong tohexstring min_value assertequals min_value longasstring tostring hextolong longasstring numberformatexception public void test hex to int int i1 fields hex to int 0 assert equals i1 0 i1 fields hex to int 000000 assert equals i1 0 i1 fields hex to int 1 assert equals i1 1 i1 fields hex to int a assert equals i1 10 i1 fields hex to int ff assert equals i1 255 i1 fields hex to int 80000000 assert equals i1 integer min value i1 fields hex to int 0000000080000000 16 chars assert equals i1 integer min value i1 fields hex to int 7fffffff assert equals i1 integer max value try i1 fields hex to int 0123456789abcdef0 17 chars fail catch number format exception e expect this try i1 fields hex to int c0der invalid char fail catch number format exception e expect this see javadoc i1 fields hex to int integer to hex string 20 assert equals 20 i1 i1 fields hex to int long to hex string integer min value assert equals integer min value i1 see javadoc try string integer as string integer to string 1 16 i1 fields hex to int integer as string fail catch number format exception e expect this testhextoint hextoint assertequals hextoint assertequals hextoint assertequals hextoint assertequals hextoint assertequals hextoint assertequals min_value hextoint assertequals min_value hextoint assertequals max_value hextoint numberformatexception hextoint numberformatexception hextoint tohexstring assertequals hextoint tohexstring min_value assertequals min_value integerasstring tostring hextoint integerasstring numberformatexception public void test string to bool assert true fields string to bool true assert true fields string to bool true assert false fields string to bool false assert false fields string to bool false try fields string to bool free tibet fail catch number format exception e expect this try fields string to bool null fail catch number format exception e expect this teststringtobool asserttrue stringtobool asserttrue stringtobool assertfalse stringtobool assertfalse stringtobool stringtobool numberformatexception stringtobool numberformatexception public void test string to bool with default assert true fields string to bool true false assert false fields string to bool false true assert true fields string to bool true false assert false fields string to bool false true assert true fields string to bool truexxx true assert false fields string to bool xxx false false assert true fields string to bool null true teststringtoboolwithdefault asserttrue stringtobool assertfalse stringtobool asserttrue stringtobool assertfalse stringtobool asserttrue stringtobool assertfalse stringtobool xxxfalse asserttrue stringtobool public void test bool to string assert equals fields bool to string true true assert equals fields bool to string false false testbooltostring assertequals booltostring assertequals booltostring public void test comma list from string string expected new string one two three four string actual fields comma list one two three four for int i 0 i expected length i assert equals expected i actual i null assert null fields comma list string null no items expected new string actual fields comma list assert true expected length actual length testcommalistfromstring commalist assertequals assertnull commalist commalist asserttrue public void test string array to comma list string input new string one two three four string expected one two three four string actual fields comma list input assert equals expected actual empty input new string expected actual fields comma list input assert equals expected actual teststringarraytocommalist commalist assertequals commalist assertequals public void test hashcode for byte array byte input new byte 0 1 2 3 4 5 6 7 assert equals 67372036 fields hash code input empty input new byte assert equals 0 fields hash code input testhashcodeforbytearray assertequals hashcode assertequals hashcode public void test long hashcode byte b1 new byte 1 1 2 2 3 3 byte b2 new byte 2 2 3 3 4 4 byte b3 new byte 1 1 2 2 3 3 long l1 new long fields long hash code b1 long l2 new long fields long hash code b2 long l3 new long fields long hash code b3 assert false l1 equals l2 assert false l2 equals l3 assert true l3 equals l1 should be same due to fields long hashcode testlonghashcode longhashcode longhashcode longhashcode assertfalse assertfalse asserttrue longhashcode public void test ints to bytes int longs new int do round trip ints array to bytes array longs longs new int integer min value do round trip ints array to bytes array longs longs new int 0 integer max value integer min value do round trip ints array to bytes array longs longs new int 33685760 51511577 do round trip ints array to bytes array longs testintstobytes doroundtripintsarraytobytesarray min_value doroundtripintsarraytobytesarray max_value min_value doroundtripintsarraytobytesarray doroundtripintsarraytobytesarray private void do round trip ints array to bytes array int ints byte bytes fields ints to bytes ints assert bytes length ints length 8 int out longs fields bytes to ints bytes for int i 0 i ints length i assert true out longs i ints i assert equals out longs length ints length doroundtripintsarraytobytesarray intstobytes outlongs bytestoints asserttrue outlongs assertequals outlongs public void test bytes to longs exception byte bytes new byte 3 try fields bytes to longs bytes 0 bytes length fail catch illegal argument exception e expect this testbytestolongsexception bytestolongs illegalargumentexception public void test bytes to int byte bytes new byte 0 1 2 2 int out long fields bytes to int bytes 0 we did dupplicate the code to avoid cross dependancies todo will need to be updated when next ext is released int out longmt mersenne twister bytes to int bytes 0 assert equals out long out longmt assert equals out long 33685760 do test round trip bytes array to int bytes bytes new byte try do test round trip bytes array to int bytes fail catch illegal argument exception e expect this bytes new byte 1 1 1 1 do test round trip bytes array to int bytes testbytestoint outlong bytestoint outlongmt mersennetwister bytestoint assertequals outlong outlongmt assertequals outlong dotestroundtripbytesarraytoint dotestroundtripbytesarraytoint illegalargumentexception dotestroundtripbytesarraytoint private void do test round trip bytes array to int byte in bytes int out long fields bytes to int in bytes 0 assert equals out long mersenne twister bytes to int in bytes 0 byte out bytes fields int to bytes out long for int i 0 i in bytes length i assert equals out bytes i in bytes i assert equals out bytes length in bytes length dotestroundtripbytesarraytoint inbytes outlong bytestoint inbytes assertequals outlong mersennetwister bytestoint inbytes outbytes inttobytes outlong inbytes assertequals outbytes inbytes assertequals outbytes inbytes public void test longs to bytes long longs new long do round trip longs array to bytes array longs longs new long long min value do round trip longs array to bytes array longs longs new long 0l long max value long min value do round trip longs array to bytes array longs longs new long 3733393793879837l do round trip longs array to bytes array longs testlongstobytes doroundtriplongsarraytobytesarray min_value doroundtriplongsarraytobytesarray max_value min_value doroundtriplongsarraytobytesarray doroundtriplongsarraytobytesarray private void do round trip longs array to bytes array long longs byte bytes fields longs to bytes longs assert bytes length longs length 8 long out longs fields bytes to longs bytes for int i 0 i longs length i assert true out longs i longs i assert equals out longs length longs length doroundtriplongsarraytobytesarray longstobytes outlongs bytestolongs asserttrue outlongs assertequals outlongs public void test bytes to long exception byte bytes new byte 3 try fields bytes to longs bytes 0 bytes length fail catch illegal argument exception e expect this testbytestolongexception bytestolongs illegalargumentexception public void test bytes to long byte bytes new byte 0 1 2 2 1 3 6 7 long out long fields bytes to long bytes assert equals out long 506095310989295872l do test round trip bytes array to long bytes bytes new byte try do test round trip bytes array to long bytes fail catch illegal argument exception e expect this bytes new byte 1 1 1 1 1 1 1 1 do test round trip bytes array to long bytes testbytestolong outlong bytestolong assertequals outlong dotestroundtripbytesarraytolong dotestroundtripbytesarraytolong illegalargumentexception dotestroundtripbytesarraytolong private void do test round trip bytes array to long byte in bytes long out long fields bytes to long in bytes byte out bytes fields long to bytes out long for int i 0 i in bytes length i assert equals out bytes i in bytes i assert equals out bytes length in bytes length dotestroundtripbytesarraytolong inbytes outlong bytestolong inbytes outbytes longtobytes outlong inbytes assertequals outbytes inbytes assertequals outbytes inbytes private int value public t int v this value v public doubly linked list get parent return parent doublylinkedlist getparent public doubly linked list set parent doubly linked list l doubly linked list old parent parent l return old doublylinkedlist setparent doublylinkedlist doublylinkedlist public int compare to object o t t t o return t value value 0 t value value 1 1 compareto void assertv int v assert equals v value assertequals override public boolean equals object o if o null return false if o get class this get class return false t t t o return t value value getclass getclass override public int hash code return value hashcode public string to string return value tostring public void test add1 throws updatable sorted linked list killed exception updatable sorted linked list l new updatable sorted linked list l debug true assert true is empty l is empty assert equals size 0 l size l add new t 2 assert false is empty l is empty l add new t 5 l add new t 1 l add new t 5 l add new t 3 l add new t 0 l add new t 1 l add new t 3 l add new t 2 l add new t 4 l add new t 4 assert equals size 11 l size updatable sorted linked list item a l to array assert equals t a 0 value 5 assert equals t a 1 value 4 assert equals t a 2 value 3 assert equals t a 3 value 2 assert equals t a 4 value 1 assert equals t a 5 value 0 assert equals t a 6 value 1 assert equals t a 7 value 2 assert equals t a 8 value 3 assert equals t a 9 value 4 assert equals t a 10 value 5 t l get lowest assertv 5 t l remove lowest assertv 5 assert false is empty l is empty assert equals size 10 l size t l remove lowest assertv 4 t l remove lowest assertv 3 t l get lowest assertv 2 t l remove lowest assertv 2 t l remove lowest assertv 1 t l remove lowest assertv 0 t l remove lowest assertv 1 t l remove lowest assertv 2 t l remove lowest assertv 3 t l remove lowest assertv 4 t l remove lowest assertv 5 assert true is empty l is empty assert equals size 0 l size testadd1 updatablesortedlinkedlistkilledexception updatablesortedlinkedlist updatablesortedlinkedlist asserttrue isempty isempty assertequals assertfalse isempty isempty assertequals updatablesortedlinkedlistitem toarray assertequals assertequals assertequals assertequals assertequals assertequals assertequals assertequals assertequals assertequals assertequals getlowest removelowest assertfalse isempty isempty assertequals removelowest removelowest getlowest removelowest removelowest removelowest removelowest removelowest removelowest removelowest removelowest asserttrue isempty isempty assertequals public void test update throws updatable sorted linked list killed exception updatable sorted linked list l new updatable sorted linked list l debug true t t new t new t 0 new t 1 new t 2 new t 3 new t 4 l add t 0 l add t 1 l add t 2 l add t 3 l add t 4 t 1 value 99 l update t 1 t 0 value 99 l update t 0 t 4 value 98 l update t 4 t 2 value 98 l update t 2 l update t 0 l update t 1 l update t 4 assert same t 1 l remove lowest assert same t 4 l remove lowest assert same t 3 l remove lowest assert same t 2 l remove lowest assert same t 0 l remove lowest testupdate updatablesortedlinkedlistkilledexception updatablesortedlinkedlist updatablesortedlinkedlist assertsame removelowest assertsame removelowest assertsame removelowest assertsame removelowest assertsame removelowest public void test clear kill throws updatable sorted linked list killed exception updatable sorted linked list l new updatable sorted linked list l debug true l add new t 2 l add new t 5 l add new t 1 l add new t 5 l clear assert equals l size 0 l add new t 3 l add new t 0 l add new t 1 l add new t 3 l add new t 2 l add new t 4 assert equals l size 6 updatable sorted linked list item a l to array assert equals t a 0 value 3 assert equals t a 1 value 2 assert equals t a 2 value 0 assert equals t a 3 value 1 assert equals t a 4 value 3 assert equals t a 5 value 4 l kill assert equals l size 0 try l add new t 4 fail no updatable sorted linked list killed exception on add catch updatable sorted linked list killed exception usllke try l remove new t 4 fail no updatable sorted linked list killed exception on remove catch updatable sorted linked list killed exception usllke try l update new t 4 fail no updatable sorted linked list killed exception on update catch updatable sorted linked list killed exception usllke try l to array fail no updatable sorted linked list killed exception on to array catch updatable sorted linked list killed exception usllke try l remove lowest should it throw catch updatable sorted linked list killed exception usllke fail updatable sorted linked list killed exception on remove lowest testclearkill updatablesortedlinkedlistkilledexception updatablesortedlinkedlist updatablesortedlinkedlist assertequals assertequals updatablesortedlinkedlistitem toarray assertequals assertequals assertequals assertequals assertequals assertequals assertequals updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception toarray updatablesortedlinkedlistkilledexception toarray updatablesortedlinkedlistkilledexception removelowest updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception removelowest test the bytes to hex byte method against every possible single byte value public void testbytestohex byte byte method byte array new byte 1 string expected result for int i 255 i 0 i method byte array 0 byte i integer to hex string works with int so it doesn t return always a two digit hex for this reason we need the next switch case expected result i 15 0 integer to hex string i integer to hex string i assert equals expected result hex util bytes to hex method byte array bytestohex testbytestohex_byte methodbytearray expectedresult methodbytearray tohexstring expectedresult tohexstring tohexstring assertequals expectedresult hexutil bytestohex methodbytearray test the hex to bytes string method against the hex representation of every possible single byte the starting offset is always 0 public void testhextobytes string byte expected byte array new byte 1 string method hex string for int i 255 i 0 i expected byte array 0 byte i integer to hex string works with int so it doesn t return always a two digit hex for this reason we need the next switch case method hex string i 15 0 integer to hex string i integer to hex string i assert true arrays equals expected byte array hex util hex to bytes method hex string hextobytes testhextobytes_string expectedbytearray methodhexstring expectedbytearray tohexstring methodhexstring tohexstring tohexstring asserttrue expectedbytearray hexutil hextobytes methodhexstring test the hex to bytes string int method against the hex representation of every possible single byte the starting offset is always 0 public void testhextobytes stringint byte expected byte array new byte 1 string method hex string for int i 255 i 0 i expected byte array 0 byte i integer to hex string works with int so it doesn t return always a two digit hex for this reason we need the next switch case method hex string i 15 0 integer to hex string i integer to hex string i assert true arrays equals expected byte array hex util hex to bytes method hex string 0 hextobytes testhextobytes_stringint expectedbytearray methodhexstring expectedbytearray tohexstring methodhexstring tohexstring tohexstring asserttrue expectedbytearray hexutil hextobytes methodhexstring test the hex to bytes string byte int method against the hex representation of every possible single byte public void testhextobytes stringbyteint byte expected byte array new byte 1 byte output array new byte 1 string method hex string for int i 255 i 0 i expected byte array 0 byte i integer to hex string works with int so it doesn t return always a two digit hex for this reason we need the next switch case method hex string i 15 0 integer to hex string i integer to hex string i hex util hex to bytes method hex string output array 0 assert true arrays equals expected byte array output array hextobytes testhextobytes_stringbyteint expectedbytearray outputarray methodhexstring expectedbytearray tohexstring methodhexstring tohexstring tohexstring hexutil hextobytes methodhexstring outputarray asserttrue expectedbytearray outputarray test the bits to byte bit set int method against the bit representation of every possible single byte public void testbitstobytes bitsetint byte expected byte array new byte 1 byte output array new byte 1 bit set method bit set new bit set 8 for int i 0 i 256 i output array hex util bits to bytes method bit set 8 expected byte array 0 byte i assert true arrays equals expected byte array output array add one method bit set bitstobyte bitset testbitstobytes_bitsetint expectedbytearray outputarray bitset methodbitset bitset outputarray hexutil bitstobytes methodbitset expectedbytearray asserttrue expectedbytearray outputarray addone methodbitset it adds 1 to a given bit set param a bit set private void add one bit set a bit set int bit set index 0 while a bit set get bit set index true a bit set flip bit set index bit set index a bit set flip bit set index bitset abitset addone bitset abitset bitsetindex abitset bitsetindex abitset bitsetindex bitsetindex abitset bitsetindex test count bytes for bits int method against all possible values until 256 bytes public void testcountbytesforbits int border case assert equals hex util count bytes for bits 0 0 for int expected bytes count 1 expected bytes count 256 expected bytes count for int bits expected bytes count 1 8 1 bits expected bytes count 8 bits assert equals hex util count bytes for bits bits expected bytes count countbytesforbits testcountbytesforbits_int assertequals hexutil countbytesforbits expectedbytescount expectedbytescount expectedbytescount expectedbytescount expectedbytescount assertequals hexutil countbytesforbits expectedbytescount test bytes to bits byte bit set int method against all possible single byte value it uses hex util bits to bytes method for the check so be sure that method works correctly public void testbytestobits bytebitsetint byte method byte array new byte 1 bit set method bit set new bit set 8 for int i 0 i 255 i method byte array 0 byte i hex util bytes to bits method byte array method bit set 7 assert true arrays equals method byte array hex util bits to bytes method bit set 8 bytestobits bitset hexutil bitstobytes testbytestobits_bytebitsetint methodbytearray bitset methodbitset bitset methodbytearray hexutil bytestobits methodbytearray methodbitset asserttrue methodbytearray hexutil bitstobytes methodbitset test bi to hex big integer method comparing its results to results provided by different scientific valid calculators public void testbitohex biginteger big integer method big integer new big integer 999999999999999 string expected hex value 038d7ea4c67fff assert equals hex util bi to hex method big integer expected hex value method big integer new big integer 0 expected hex value 00 assert equals hex util bi to hex method big integer expected hex value method big integer new big integer 72057594037927935 expected hex value 00ffffffffffffff assert equals hex util bi to hex method big integer expected hex value bitohex biginteger testbitohex_biginteger biginteger methodbiginteger biginteger expectedhexvalue assertequals hexutil bitohex methodbiginteger expectedhexvalue methodbiginteger biginteger expectedhexvalue assertequals hexutil bitohex methodbiginteger expectedhexvalue methodbiginteger biginteger expectedhexvalue assertequals hexutil bitohex methodbiginteger expectedhexvalue test bits to hex string bit set int method comparing its results to results provided by different scientific valid calculators public void test bits to hex string bit set method bit set new bit set 8 string expected string 00 assert equals hex util bits to hex string method bit set 8 expected string method bit set set 0 7 true 0x7f expected string 7f assert equals hex util bits to hex string method bit set 8 expected string method bit set set 0 9 true 0xff expected string ff assert equals hex util bits to hex string method bit set 8 expected string bitstohexstring bitset testbitstohexstring bitset methodbitset bitset expectedstring assertequals hexutil bitstohexstring methodbitset expectedstring methodbitset expectedstring assertequals hexutil bitstohexstring methodbitset expectedstring methodbitset expectedstring assertequals hexutil bitstohexstring methodbitset expectedstring tests hex to bits string bit set int method public void test hex to bits string method string to store 00 bit set method bit set new bit set 8 hex util hex to bits method string to store method bit set method bit set size assert true method bit set cardinality 0 bit set expected bit set new bit set 8 expected bit set set 0 7 true 0x7f method string to store 7f method bit set new bit set 8 hex util hex to bits method string to store method bit set method bit set size assert true method bit set intersects expected bit set expected bit set set 0 9 true 0xff method string to store ff method bit set new bit set 8 hex util hex to bits method string to store method bit set method bit set size assert true method bit set intersects expected bit set hextobits bitset testhextobits methodstringtostore bitset methodbitset bitset hexutil hextobits methodstringtostore methodbitset methodbitset asserttrue methodbitset bitset expectedbitset bitset expectedbitset methodstringtostore methodbitset bitset hexutil hextobits methodstringtostore methodbitset methodbitset asserttrue methodbitset expectedbitset expectedbitset methodstringtostore methodbitset bitset hexutil hextobits methodstringtostore methodbitset methodbitset asserttrue methodbitset expectedbitset tests write big integer big integer data output stream and read big integer data input stream comparing a big integer after writing it to a stream and reading it from the writing result public void test write and read big integer big integer method big integer new big integer 999999999999999 byte array output stream method byte array out stream new byte array output stream data output stream method data out stream new data output stream method byte array out stream try hex util write big integer method big integer method data out stream byte array input stream method byte array in stream new byte array input stream method byte array out stream to byte array data input stream method data in stream new data input stream method byte array in stream assert true method big integer compare to hex util read big integer method data in stream 0 catch io exception a exception fail not expected exception thrown a exception get message writebiginteger biginteger dataoutputstream readbiginteger datainputstream biginteger testwriteandreadbiginteger biginteger methodbiginteger biginteger bytearrayoutputstream methodbytearrayoutstream bytearrayoutputstream dataoutputstream methoddataoutstream dataoutputstream methodbytearrayoutstream hexutil writebiginteger methodbiginteger methoddataoutstream bytearrayinputstream methodbytearrayinstream bytearrayinputstream methodbytearrayoutstream tobytearray datainputstream methoddatainstream datainputstream methodbytearrayinstream asserttrue methodbiginteger compareto hexutil readbiginteger methoddatainstream ioexception aexception aexception getmessage test bytes to hex byte int int method with a too long starting offset the tested method should raise an exception public void testbytestohex byteintint withlongoffset try int array length 3 byte method bytes array new byte array length hex util bytes to hex method bytes array array length 1 1 fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception bytestohex testbytestohex_byteintint_withlongoffset arraylength methodbytesarray arraylength hexutil bytestohex methodbytesarray arraylength illegalargumentexception anexception assertnotnull anexception test bytes to hex byte int int method with asking to read too many bytes the tested method should raise an exception public void testbytestohex byteintint withlongreading try int array length 3 byte method bytes array new byte array length hex util bytes to hex method bytes array 0 array length 1 fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception bytestohex testbytestohex_byteintint_withlongreading arraylength methodbytesarray arraylength hexutil bytestohex methodbytesarray arraylength illegalargumentexception anexception assertnotnull anexception test bytes to hex byte int int method with a 0 length public void testbytestohex byteintint withzerolength int length 0 byte method bytes array 1 2 3 a non zero bytes array assert equals hex util bytes to hex method bytes array 0 length bytestohex testbytestohex_byteintint_withzerolength methodbytesarray assertequals hexutil bytestohex methodbytesarray test hex to bytes string byte int method with a too long offset the method should raise an exception public void testhextobytes stringbyteint withlongoffset try string method string 0 byte method byte array new byte 1 hex util hex to bytes method string method byte array method byte array length fail expected exception error not thrown catch array index out of bounds exception an exception assert not null an exception hextobytes testhextobytes_stringbyteint_withlongoffset methodstring methodbytearray hexutil hextobytes methodstring methodbytearray methodbytearray arrayindexoutofboundsexception anexception assertnotnull anexception test hex to bytes string byte int method with a too short byte to put the result the method should raise an exception public void testhextobytes stringbyteint withshortarray try string method string 0000 byte method byte array new byte 1 hex util hex to bytes method string method byte array 0 fail expected exception error not thrown catch index out of bounds exception an exception assert not null an exception hextobytes testhextobytes_stringbyteint_withshortarray methodstring methodbytearray hexutil hextobytes methodstring methodbytearray indexoutofboundsexception anexception assertnotnull anexception test all hex to bytes methods with a not valid character the method should raise an exception public void testhextobytes withbaddigit string method string 00 0 try byte method byte array new byte method string length hex util hex to bytes method string method byte array 0 fail expected exception error not thrown catch number format exception an exception assert not null an exception try hex util hex to bytes method string 0 fail expected exception error not thrown catch number format exception an exception assert not null an exception try hex util hex to bytes method string fail expected exception error not thrown catch number format exception an exception assert not null an exception hextobytes testhextobytes_withbaddigit methodstring methodbytearray methodstring hexutil hextobytes methodstring methodbytearray numberformatexception anexception assertnotnull anexception hexutil hextobytes methodstring numberformatexception anexception assertnotnull anexception hexutil hextobytes methodstring numberformatexception anexception assertnotnull anexception test the bits to byte bit set int method using a size smaller than the actual number of bits in the bit set public void testbitstobytes withshortsize byte expected byte array new byte 1 byte output array new byte 1 bit set method bit set new bit set 8 0x01 method bit set flip 0 expected byte array 0 byte 1 0x01 0x00 0x01 output array hex util bits to bytes method bit set 0 assert false arrays equals expected byte array output array 0x01 0x01 0x01 output array hex util bits to bytes method bit set 1 assert true arrays equals expected byte array output array 0x80 method bit set flip 7 0x08 method bit set flip 3 expected byte array 0 byte 128 8 1 0x89 0x08 0x89 output array hex util bits to bytes method bit set 3 assert false arrays equals expected byte array output array 0x89 0xff 0x89 output array hex util bits to bytes method bit set 8 assert true arrays equals expected byte array output array bitstobyte bitset bitset testbitstobytes_withshortsize expectedbytearray outputarray bitset methodbitset bitset methodbitset expectedbytearray outputarray hexutil bitstobytes methodbitset assertfalse expectedbytearray outputarray outputarray hexutil bitstobytes methodbitset asserttrue expectedbytearray outputarray methodbitset methodbitset expectedbytearray outputarray hexutil bitstobytes methodbitset assertfalse expectedbytearray outputarray outputarray hexutil bitstobytes methodbitset asserttrue expectedbytearray outputarray override protected void set up throws exception super set up example node null try example node new html node sample okay node name catch illegal argument exception iae1 fail unexpected exception thrown assert not null example node assert equals 0 example node children size setup setup examplenode examplenode htmlnode sample_okay_node_name illegalargumentexception assertnotnull examplenode assertequals examplenode tests html node string string string string constructor using non ascii chars public void testhtmlnode stringstringstringstring wrongnodename try new html node sample wrong node name sample okay attribute name sample attribute value sample node content fail expected exception not thrown catch illegal argument exception iae1 try new html node sample okay node name sample okay attribute name sample attribute value sample node content catch illegal argument exception iae1 fail unexpected exception thrown htmlnode testhtmlnode_stringstringstringstring_wrongnodename htmlnode sample_wrong_node_name sample_okay_attribute_name sample_attribute_value sample_node_content illegalargumentexception htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content illegalargumentexception public void testhtmlnode stringstringstringstring wrongattributename try new html node sample okay node name sample wrong attribute name sample attribute value sample node content fail expected exception not thrown catch illegal argument exception iae1 try new html node sample okay node name sample okay attribute name sample attribute value sample node content catch illegal argument exception iae1 fail unexpected exception thrown testhtmlnode_stringstringstringstring_wrongattributename htmlnode sample_okay_node_name sample_wrong_attribute_name sample_attribute_value sample_node_content illegalargumentexception htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content illegalargumentexception tests html node string string string string constructor verifying if all attributes are correctly inserted public void testhtmlnode attributesarray int size 100 string method attributes name new string size string method attributes value new string size for int i 0 i size i method attributes name i attribute name i method attributes value i value i html node methodhtml node new html node sample okay node name method attributes name method attributes value sample node content checks presence for int i 0 i size i assert equals method attributes value i methodhtml node get attribute method attributes name i checks size assert equals size methodhtml node get attributes size htmlnode testhtmlnode_attributesarray methodattributesname methodattributesvalue methodattributesname attributename methodattributesvalue htmlnode methodhtmlnode htmlnode sample_okay_node_name methodattributesname methodattributesvalue sample_node_content assertequals methodattributesvalue methodhtmlnode getattribute methodattributesname assertequals methodhtmlnode getattributes tests add attribute string string method adding the same attribute many times and verifying it keeps only one reference to it public void test same attribute many times int times 100 string method attribute name example attribute name string method attribute value example attribute value for int i 0 i times i example node add attribute method attribute name method attribute value assert equals example node get attributes size 1 addattribute testsameattributemanytimes methodattributename exampleattributename methodattributevalue exampleattributevalue examplenode addattribute methodattributename methodattributevalue assertequals examplenode getattributes tests add child html node method adding the node itself as its child the method should rise an exception public void test add child using the node itself as child try example node add child example node fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addchild htmlnode testaddchildusingthenodeitselfaschild examplenode addchild examplenode illegalargumentexception anexception assertnotnull anexception tests add children html node method adding the node itself as its child the method should rise an exception public void test add children using the node itself as child html node methodhtml nodes array new html node sample okay node name example node new html node sample okay node name 1 try example node add children methodhtml nodes array fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addchildren htmlnode testaddchildrenusingthenodeitselfaschild htmlnode methodhtmlnodesarray htmlnode sample_okay_node_name examplenode htmlnode sample_okay_node_name examplenode addchildren methodhtmlnodesarray illegalargumentexception anexception assertnotnull anexception tests add child string method using the same name every time and verifying that a real new html is always added public void test add child same name int times 100 for int i 1 i times i example node add child sample okay node name assert equals example node children size i addchild testaddchildsamename examplenode addchild sample_okay_node_name assertequals examplenode tests add child html node method verifying the behavior when adding the same html node instance two times it should raise an illegal argument exception public void test add child same object html node methodhtml node new html node sample okay node name example node add child methodhtml node try example node add child methodhtml node fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addchild htmlnode htmlnode illegalargument testaddchildsameobject htmlnode methodhtmlnode htmlnode sample_okay_node_name examplenode addchild methodhtmlnode examplenode addchild methodhtmlnode illegalargumentexception anexception assertnotnull anexception tests add children html node method verifying the behavior when adding the same html node instance two times public void test add children same object html node methodhtml node new html node sample okay node name html node methodhtml nodes array methodhtml node methodhtml node try example node add children methodhtml nodes array fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addchildren htmlnode htmlnode testaddchildrensameobject htmlnode methodhtmlnode htmlnode sample_okay_node_name htmlnode methodhtmlnodesarray methodhtmlnode methodhtmlnode examplenode addchildren methodhtmlnodesarray illegalargumentexception anexception assertnotnull anexception tests add children string string string method verifying if the child is correctly added and if it generates good output using generate method public void testaddchild stringstringstring html node methodhtml node new html node sample okay node name methodhtml node add child sample okay node name sample okay attribute name sample attribute value list html node children list methodhtml node children assert equals 1 children list size assert equals generate no content node output sample okay node name sample okay attribute name sample attribute value children list get 0 generate addchildren testaddchild_stringstringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addchild sample_okay_node_name sample_okay_attribute_name sample_attribute_value htmlnode childrenlist methodhtmlnode assertequals childrenlist assertequals generatenocontentnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value childrenlist tests add children string string string string method verifying if the child is correctly added and if it generates good output using generate method public void testaddchild stringstringstringstring html node methodhtml node new html node sample okay node name methodhtml node add child sample okay node name sample okay attribute name sample attribute value sample node content list html node children list methodhtml node children assert equals 1 children list size assert equals generate full node output sample okay node name sample okay attribute name sample attribute value sample node content children list get 0 generate addchildren testaddchild_stringstringstringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addchild sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content htmlnode childrenlist methodhtmlnode assertequals childrenlist assertequals generatefullnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content childrenlist tests add children string string string method verifying if the child is correctly added and the child attributes are corrects public void testaddchild stringarrayarray string method attributes names array first name second name third name string method attributes values array first value second value third value html node methodhtml node new html node sample okay node name methodhtml node add child sample okay node name method attributes names array method attributes values array test single child attributes methodhtml node method attributes names array method attributes values array addchildren testaddchild_stringarrayarray methodattributesnamesarray firstname secondname thirdname methodattributesvaluesarray firstvalue secondvalue thirdvalue htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addchild sample_okay_node_name methodattributesnamesarray methodattributesvaluesarray testsinglechildattributes methodhtmlnode methodattributesnamesarray methodattributesvaluesarray tests add children string string string string method verifying if the child is correctly added and the child attributes are corrects public void testaddchild stringarrayarraystring string method attributes names array first name second name third name string method attributes values array first value second value third value html node methodhtml node new html node sample okay node name methodhtml node add child sample okay node name method attributes names array method attributes values array sample node content test single child attributes methodhtml node method attributes names array method attributes values array addchildren testaddchild_stringarrayarraystring methodattributesnamesarray firstname secondname thirdname methodattributesvaluesarray firstvalue secondvalue thirdvalue htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addchild sample_okay_node_name methodattributesnamesarray methodattributesvaluesarray sample_node_content testsinglechildattributes methodhtmlnode methodattributesnamesarray methodattributesvaluesarray check the passed html node only child attributes param ahtml node where we fetch the only child param attibutes names the attributes names to check param attributes values the attributes values to check private void test single child attributes html node ahtml node string attibutes names string attributes values list html node children list ahtml node children assert equals 1 children list size html node childhtml node children list get 0 assert equals attibutes names length childhtml node get attributes size for int i 0 i attibutes names length i assert equals attributes values i childhtml node get attribute attibutes names i htmlnode ahtmlnode attibutesnames attributesvalues testsinglechildattributes htmlnode ahtmlnode attibutesnames attributesvalues htmlnode childrenlist ahtmlnode assertequals childrenlist htmlnode childhtmlnode childrenlist assertequals attibutesnames childhtmlnode getattributes attibutesnames assertequals attributesvalues childhtmlnode getattribute attibutesnames tests get content method using common sample html node and named nodes public void test get content html node methodhtml node new html node sample okay node name assert null methodhtml node get content methodhtml node new html node sample okay node name sample node content since the html node name is not or the content will be a new child with the name assert equals sample node content methodhtml node children get 0 get content assert null methodhtml node get content methodhtml node new html node sample node content assert equals sample node content methodhtml node get content methodhtml node new html node sample node content assert equals sample node content methodhtml node get content getcontent htmlnode testgetcontent htmlnode methodhtmlnode htmlnode sample_okay_node_name assertnull methodhtmlnode getcontent methodhtmlnode htmlnode sample_okay_node_name sample_node_content htmlnode assertequals sample_node_content methodhtmlnode getcontent assertnull methodhtmlnode getcontent methodhtmlnode htmlnode sample_node_content assertequals sample_node_content methodhtmlnode getcontent methodhtmlnode htmlnode sample_node_content assertequals sample_node_content methodhtmlnode getcontent tests get attribute method using common sample html node and named nodes public void test get attribute html node methodhtml node new html node sample okay node name assert null methodhtml node get attribute sample okay attribute name methodhtml node new html node sample okay node name sample okay attribute name sample attribute value assert equals sample attribute value methodhtml node get attribute sample okay attribute name methodhtml node new html node sample okay attribute name sample attribute value assert equals sample attribute value methodhtml node get attribute sample okay attribute name methodhtml node new html node sample okay attribute name sample attribute value assert equals sample attribute value methodhtml node get attribute sample okay attribute name getattribute htmlnode testgetattribute htmlnode methodhtmlnode htmlnode sample_okay_node_name assertnull methodhtmlnode getattribute sample_okay_attribute_name methodhtmlnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value assertequals sample_attribute_value methodhtmlnode getattribute sample_okay_attribute_name methodhtmlnode htmlnode sample_okay_attribute_name sample_attribute_value assertequals sample_attribute_value methodhtmlnode getattribute sample_okay_attribute_name methodhtmlnode htmlnode sample_okay_attribute_name sample_attribute_value assertequals sample_attribute_value methodhtmlnode getattribute sample_okay_attribute_name tests get attributes and set attribute string string methods verifying if attributes are correctly inserted and fetched public void test add get attributes int attributes number 100 string method attribute name string counter string html node methodhtml node new html node sample okay node name for int i 0 i attributes number i counter string string value of i method attribute name attribute counter string assert equals i methodhtml node get attributes size methodhtml node add attribute method attribute name counter string assert equals counter string methodhtml node get attribute method attribute name assert equals counter string methodhtml node get attributes get method attribute name getattributes setattribute testaddgetattributes attributesnumber methodattributename counterstring htmlnode methodhtmlnode htmlnode sample_okay_node_name attributesnumber counterstring valueof methodattributename counterstring assertequals methodhtmlnode getattributes methodhtmlnode addattribute methodattributename counterstring assertequals counterstring methodhtmlnode getattribute methodattributename assertequals counterstring methodhtmlnode getattributes methodattributename tests add attribute string string method trying to insert an attribute with a null as name value it should rise an illegal argument exception public void testaddattribute nullattributename html node methodhtml node new html node sample okay node name try methodhtml node add attribute null sample attribute value fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addattribute illegalargument testaddattribute_nullattributename htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addattribute sample_attribute_value illegalargumentexception anexception assertnotnull anexception tests add attribute string string method trying to insert an attribute with a null as attribute value it should rise an illegal argument exception public void testaddattribute nullattributevalue html node methodhtml node new html node sample okay node name try methodhtml node add attribute sample wrong attribute name null fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception addattribute illegalargument testaddattribute_nullattributevalue htmlnode methodhtmlnode htmlnode sample_okay_node_name methodhtmlnode addattribute sample_wrong_attribute_name illegalargumentexception anexception assertnotnull anexception tests html node string string string string and html node string string string constructors trying to create a node that has attribute name null it should raise an illegal argument exception public void testhtmlnode nullattributename try new html node sample okay node name null sample attribute value sample node content fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception try new html node sample okay node name null sample attribute value fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception htmlnode htmlnode illegalargument testhtmlnode_nullattributename htmlnode sample_okay_node_name sample_attribute_value sample_node_content illegalargumentexception anexception assertnotnull anexception htmlnode sample_okay_node_name sample_attribute_value illegalargumentexception anexception assertnotnull anexception tests html node string string string string and html node string string string constructors trying to create a node that has attribute value null it should raise an illegal argument exception public void testhtmlnode nullattributevalue try new html node sample okay node name sample wrong attribute name null sample node content fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception try new html node sample okay node name sample wrong attribute name null fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception htmlnode htmlnode illegalargument testhtmlnode_nullattributevalue htmlnode sample_okay_node_name sample_wrong_attribute_name sample_node_content illegalargumentexception anexception assertnotnull anexception htmlnode sample_okay_node_name sample_wrong_attribute_name illegalargumentexception anexception assertnotnull anexception tests html node string string string string constructor trying to create a node that has attributes name null it should raise an illegal argument exception public void testhtmlnodearray nullattributename string method attributes name array first null after string method attributes value array sample attribute value sample attribute value sample attribute value testhtmlnodearray null method attributes name array method attributes value array htmlnode illegalargument testhtmlnodearray_nullattributename methodattributesnamearray methodattributesvaluearray sample_attribute_value sample_attribute_value sample_attribute_value testhtmlnodearray_null methodattributesnamearray methodattributesvaluearray tests html node string string string string constructor trying to create a node that has attributes value null it should raise an illegal argument exception public void testhtmlnodearray nullattributevalue string method attributes name array sample wrong attribute name sample wrong attribute name sample wrong attribute name string method attributes value array first null after testhtmlnodearray null method attributes name array method attributes value array htmlnode illegalargument testhtmlnodearray_nullattributevalue methodattributesnamearray sample_wrong_attribute_name sample_wrong_attribute_name sample_wrong_attribute_name methodattributesvaluearray testhtmlnodearray_null methodattributesnamearray methodattributesvaluearray tests html node string string string string constructor trying to create a node that has different length for attributes names array and attributes values array it should raise an illegal argument exception public void testhtmlnode attributearrays differentlengths string method attributes name array sample wrong attribute name sample wrong attribute name string method attributes value array sample attribute value sample attribute value sample attribute value testhtmlnodearray null method attributes name array method attributes value array htmlnode illegalargument testhtmlnode_attributearrays_differentlengths methodattributesnamearray sample_wrong_attribute_name sample_wrong_attribute_name methodattributesvaluearray sample_attribute_value sample_attribute_value sample_attribute_value testhtmlnodearray_null methodattributesnamearray methodattributesvaluearray tests if the passed arrays raise an illegal argument exception using them to create a new html node i e one of the name or value must be null param attributes names the array of attribute names param attributes values the array of attribute values private void testhtmlnodearray null string attributes names string attributes values try new html node sample okay node name attributes names attributes values sample node content fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception illegalargumentexception htmlnode attributesnames attributesvalues testhtmlnodearray_null attributesnames attributesvalues htmlnode sample_okay_node_name attributesnames attributesvalues sample_node_content illegalargumentexception anexception assertnotnull anexception fetches the first line of a string param a string the string to consider return the first line of the string private string read first line string a string int new line index a string index of n if new line index 1 return a string return a string substring 0 new line index astring readfirstline astring newlineindex astring indexof newlineindex astring astring newlineindex tests generate method with a html node that has textarea div a as node name since they generates a different output from all other names public void testgenerate fromhtmlnode textareadiva html node methodhtml node string node names array textarea div a for int i 0 i node names array length i methodhtml node new html node node names array i sample okay attribute name sample attribute value assert equals generate full node output node names array i sample okay attribute name sample attribute value methodhtml node generate htmlnode testgenerate_fromhtmlnode_textareadiva htmlnode methodhtmlnode nodenamesarray nodenamesarray methodhtmlnode htmlnode nodenamesarray sample_okay_attribute_name sample_attribute_value assertequals generatefullnodeoutput nodenamesarray sample_okay_attribute_name sample_attribute_value methodhtmlnode tests generate method when the node has a special name i e div form input script table tr td and a child public void testgenerate fromhtmlnodewithchild specialnames html node methodhtml node string node names array div form input script table tr td html node method child node new html node sample okay node name sample okay attribute name sample attribute value sample node content for int i 0 i node names array length i methodhtml node new html node node names array i sample okay attribute name sample attribute value sample node content methodhtml node add child method child node assert equals node names array i to lower case sample okay attribute name sample attribute value n sample node content child generate full node output sample okay node name sample okay attribute name sample attribute value sample node content node names array i to lower case n methodhtml node generate testgenerate_fromhtmlnodewithchild_specialnames htmlnode methodhtmlnode nodenamesarray htmlnode methodchildnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content nodenamesarray methodhtmlnode htmlnode nodenamesarray sample_okay_attribute_name sample_attribute_value sample_node_content methodhtmlnode addchild methodchildnode assertequals nodenamesarray tolowercase sample_okay_attribute_name sample_attribute_value sample_node_content generatefullnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content nodenamesarray tolowercase methodhtmlnode tests generate method with a html node with only the name the resulting string should be in the form node name public void testgenerate fromhtmlnode string html node methodhtml node new html node sample okay node name assert equals sample okay node name to lower case methodhtml node generate htmlnode node_name testgenerate_fromhtmlnode_string htmlnode methodhtmlnode htmlnode sample_okay_node_name assertequals sample_okay_node_name tolowercase methodhtmlnode tests generate method with a html node with the name and content the resulting string should be in the form node name node content node name public void testgenerate fromhtmlnode stringstring html node methodhtml node new html node sample okay node name sample node content assert equals sample okay node name to lower case sample node content sample okay node name to lower case methodhtml node generate htmlnode node_name node_content node_name testgenerate_fromhtmlnode_stringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name sample_node_content assertequals sample_okay_node_name tolowercase sample_node_content sample_okay_node_name tolowercase methodhtmlnode tests generate method with a html node with the name an attribute and its value the resulting string should be in the form node name attribute name attribute value public void testgenerate fromhtmlnode stringstringstring html node methodhtml node new html node sample okay node name sample okay attribute name sample attribute value assert equals generate no content node output sample okay node name sample okay attribute name sample attribute value methodhtml node generate htmlnode node_name attribute_name attribute_value testgenerate_fromhtmlnode_stringstringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value assertequals generatenocontentnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value methodhtmlnode tests generate method with a html node with the name an attribute and its value the resulting string should be in the form node name attribute name attribute value node content node name public void testgenerate fromhtmlnode stringstringstringstring html node methodhtml node new html node sample okay node name sample okay attribute name sample attribute value sample node content assert equals generate full node output sample okay node name sample okay attribute name sample attribute value sample node content methodhtml node generate htmlnode node_name attribute_name attribute_value node_content node_name testgenerate_fromhtmlnode_stringstringstringstring htmlnode methodhtmlnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content assertequals generatefullnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content methodhtmlnode generates the correct output for the html node generate method when called from a single node having only a name and an attribute name and value param a name the html node name param a attribute name the html node attribute name param a attribute value the html node attribute value return the correct output expected by html node generate method private string generate no content node output string a name string a attribute name string a attribute value return a name to lower case a attribute name a attribute value htmlnode aname htmlnode aattributename htmlnode aattributevalue htmlnode htmlnode generatenocontentnodeoutput aname aattributename aattributevalue aname tolowercase aattributename aattributevalue generates the correct output for the html node generate method when called from a single node having the specified parameters param a name the html node name param a attribute name the html node attribute name param a attribute value the html node attribute value param a content the html node content return the correct output expected by html node generate method private string generate full node output string a name string a attribute name string a attribute value string a content return a name to lower case a attribute name a attribute value a content a name to lower case htmlnode aname htmlnode aattributename htmlnode aattributevalue htmlnode acontent htmlnode htmlnode generatefullnodeoutput aname aattributename aattributevalue acontent aname tolowercase aattributename aattributevalue acontent aname tolowercase tests generate method with a html node that has a child node name attribute name attribute value node content child node name child attribute name child attribute value child node content child node name node name public void testgenerate htmlnode withchild html node methodhtml node new html node sample okay node name sample okay attribute name sample attribute value sample node content html node methodhtml node child new html node sample okay node name sample okay attribute name sample attribute value sample node content methodhtml node add child methodhtml node child assert equals sample okay node name to lower case sample okay attribute name sample attribute value sample node content child generate full node output sample okay node name sample okay attribute name sample attribute value sample node content sample okay node name to lower case methodhtml node generate htmlnode node_name attribute_name attribute_value node_content child_node_name child_attribute_name child_attribute_value child_node_content child_node_name node_name testgenerate_htmlnode_withchild htmlnode methodhtmlnode htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content htmlnode methodhtmlnodechild htmlnode sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content methodhtmlnode addchild methodhtmlnodechild assertequals sample_okay_node_name tolowercase sample_okay_attribute_name sample_attribute_value sample_node_content generatefullnodeoutput sample_okay_node_name sample_okay_attribute_name sample_attribute_value sample_node_content sample_okay_node_name tolowercase methodhtmlnode tests generate method with a html node that has as name the expected output is just the html node content public void testgenerate fromhtmlnode percentname html node methodhtml node new html node sample okay attribute name sample attribute value sample node content assert equals sample node content methodhtml node generate htmlnode htmlnode testgenerate_fromhtmlnode_percentname htmlnode methodhtmlnode htmlnode sample_okay_attribute_name sample_attribute_value sample_node_content assertequals sample_node_content methodhtmlnode tests html doctype generate method comparing the result with the expected string it is useful for regression tests public void testhtmldoctype generate string sample doc type html string sample system uri w3c dtd xhtml 1 1 en html node methodhtml node doc new html node html doctype sample doc type sample system uri methodhtml node doc add child sample okay node name string generated string methodhtml node doc generate consider only the html doc type generated text assert equals doctype sample doc type public sample system uri read first line generated string htmldoctype testhtmldoctype_generate sampledoctype samplesystemuri htmlnode methodhtmlnodedoc htmlnode htmldoctype sampledoctype samplesystemuri methodhtmlnodedoc addchild sample_okay_node_name generatedstring methodhtmlnodedoc htmldoctype assertequals sampledoctype samplesystemuri readfirstline generatedstring protected sorted long set perpare long array sorted long set set new sorted long set for int i 0 i array length i set add array i return set sortedlongset sortedlongset sortedlongset public void test get first construction and get sorted long set set perpare test array assert equals long min value set get first assert equals long min value set get first make sure not removed testgetfirst sortedlongset testarray assertequals min_value getfirst assertequals min_value getfirst test method for link freenet support sorted long set is empty public void test is empty emptiness sorted long set set1 perpare new long assert true set1 is empty sorted long set set2 perpare test array assert false set2 is empty remove and is empty for int i 0 i test array length i set2 remove test array i assert true set2 is empty sortedlongset isempty testisempty sortedlongset asserttrue isempty sortedlongset testarray assertfalse isempty isempty testarray testarray asserttrue isempty test method for link freenet support sorted long set contains long public void test contains construction and get sorted long set set perpare test array contain assert true set contains 0l assert true set contains 3l assert true set contains long max value assert true set contains long min value not contain assert false set contains 13l assert false set contains 13l remove and not contain set remove 0l assert false set contains 0l sortedlongset testcontains sortedlongset testarray asserttrue asserttrue asserttrue max_value asserttrue min_value assertfalse assertfalse assertfalse test method for link freenet support sorted long set remove long public void test remove construction and get sorted long set set perpare test array remove assert true set contains 0l set remove 0l assert false set contains 0l construction and get sorted long set set2 perpare test array remove non exist assert false set2 contains 101l set remove 101l make sure no other element removed for int i 0 i test array length i assert true set2 contains test array i sortedlongset testremove sortedlongset testarray asserttrue assertfalse sortedlongset testarray assertfalse testarray asserttrue testarray test method for link freenet support sorted long set push long public void test push sorted long set set perpare test array assert true set push 100l assert true set contains 100l assert false set push 100l sortedlongset testpush sortedlongset testarray asserttrue asserttrue assertfalse test method for link freenet support sorted long set add long public void test add sorted long set set perpare test array set add 100l assert true set contains 100l boolean ok false try set add 100l catch illegal argument exception iae good ok true assert true exception not thrown ok sortedlongset testadd sortedlongset testarray asserttrue illegalargumentexception asserttrue test method for link freenet support sorted long set remove first public void test remove first construction and get sorted long set set perpare test array assert equals long min value set remove first assert equals 0l set remove first sortedlongset removefirst testremovefirst sortedlongset testarray assertequals min_value removefirst assertequals removefirst test method for link freenet support sorted long set clear public void test clear sorted long set set perpare test array assert false set is empty set clear assert true set is empty assert false set contains 0l sortedlongset testclear sortedlongset testarray assertfalse isempty asserttrue isempty assertfalse test method for link freenet support sorted long set to array public void test to array sorted long set set perpare test array long sorted array new long test array length system arraycopy test array 0 sorted array 0 test array length arrays sort sorted array assert true arrays equals sorted array set to array sorted long set set0 new sorted long set assert true arrays equals new long set0 to array sortedlongset toarray testtoarray sortedlongset testarray sortedarray testarray testarray sortedarray testarray sortedarray asserttrue sortedarray toarray sortedlongset sortedlongset asserttrue toarray public void test grown and scale sorted long set set new sorted long set for long i 1 i 512 i set add i set add i for long i 1 i 512 i assert true set contains i assert true set contains i remove and shink for long i 1 i 512 i set remove i assert false set contains i assert true set contains i set remove i assert false set contains i testgrownandscale sortedlongset sortedlongset asserttrue asserttrue assertfalse asserttrue assertfalse public class time sorted hashtable test extends test case public void test add remove time sorted hashtable string tsh new time sorted hashtable string assert false tsh contains value key1 assert equals 0 tsh count values after 0 assert equals 0 tsh size tsh push key1 100 assert equals 1 tsh count values after 0 assert equals 1 tsh size assert equals 1 tsh count values after 99 assert equals 0 tsh count values after 100 assert equals 0 tsh count values after 101 assert true tsh contains value key1 tsh push key2 100 assert equals 2 tsh count values after 0 assert equals 2 tsh size assert equals 0 tsh count values after 100 assert equals 0 tsh count values after 101 assert true tsh contains value key1 assert true tsh contains value key2 tsh push key3 300 assert equals 3 tsh count values after 0 assert equals 3 tsh size assert equals 1 tsh count values after 100 assert equals 1 tsh count values after 101 assert true tsh contains value key1 assert true tsh contains value key2 assert true tsh contains value key3 tsh push key1 200 assert equals 3 tsh count values after 0 assert equals 3 tsh size assert equals 2 tsh count values after 100 assert equals 2 tsh count values after 101 assert true tsh contains value key1 assert true tsh contains value key2 assert true tsh contains value key3 assert true tsh remove value key1 assert equals 2 tsh count values after 0 assert equals 2 tsh size assert equals 1 tsh count values after 100 assert equals 1 tsh count values after 101 assert false tsh contains value key1 assert true tsh contains value key2 assert true tsh contains value key3 tsh remove before 105 assert equals 1 tsh count values after 0 assert equals 1 tsh size assert equals 1 tsh count values after 100 assert equals 1 tsh count values after 101 assert false tsh contains value key1 assert false tsh contains value key2 assert true tsh contains value key3 timesortedhashtabletest testcase testaddremove timesortedhashtable timesortedhashtable assertfalse containsvalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue asserttrue containsvalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue asserttrue containsvalue asserttrue containsvalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue asserttrue containsvalue asserttrue containsvalue asserttrue removevalue assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter assertfalse containsvalue asserttrue containsvalue asserttrue containsvalue removebefore assertequals countvaluesafter assertequals assertequals countvaluesafter assertequals countvaluesafter assertfalse containsvalue assertfalse containsvalue asserttrue containsvalue public void test add removets time sorted hashtable string tsh new time sorted hashtable string tsh push key1 100 100 key1 tsh push key2 100 100 key1 100 key2 tsh push key3 300 100 key1 100 key2 300 key3 tsh push key1 200 100 key2 200 key1 300 key3 tsh remove before 105 200 key1 300 key3 assert equals 2 tsh size assert equals 2 tsh count values after 0 assert equals 2 tsh count values after 100 assert equals 1 tsh count values after 201 assert equals 0 tsh count values after 301 assert true tsh contains value key1 assert false tsh contains value key2 assert true tsh contains value key3 assert equals 200 tsh get time key1 assert equals 1 tsh get time key2 assert equals 300 tsh get time key3 testaddremovets timesortedhashtable timesortedhashtable removebefore assertequals assertequals countvaluesafter assertequals countvaluesafter assertequals countvaluesafter assertequals countvaluesafter asserttrue containsvalue assertfalse containsvalue asserttrue containsvalue assertequals gettime assertequals gettime assertequals gettime public void test before inclusive time sorted hashtable string tsh new time sorted hashtable string tsh push key1 100 100 key1 tsh push key2 100 100 key1 100 key2 tsh push key3 300 100 key1 100 key2 300 key3 tsh remove before 100 assert equals 1 tsh size testbeforeinclusive timesortedhashtable timesortedhashtable removebefore assertequals public void test pairs time sorted hashtable string tsh new time sorted hashtable string tsh push key1 100 100 key1 tsh push key2 100 100 key1 100 key2 tsh push key3 300 100 key1 100 key2 300 key3 object p tsh pairs after 1 new string 3 assert equals 100 long long p 1 0 assert equals key1 string p 0 0 assert equals 100 long long p 1 1 assert equals key2 string p 0 1 assert equals 300 long long p 1 2 assert equals key3 string p 0 2 tsh push key1 200 100 key2 200 key1 300 key3 p tsh pairs after 1 new string 3 assert equals 100 long long p 1 0 assert equals key2 string p 0 0 assert equals 200 long long p 1 1 assert equals key1 string p 0 1 assert equals 300 long long p 1 2 assert equals key3 string p 0 2 tsh remove before 105 200 key1 300 key3 p tsh pairs after 1 new string 2 assert equals 200 long long p 1 0 assert equals key1 string p 0 0 assert equals 300 long long p 1 1 assert equals key3 string p 0 1 testpairs timesortedhashtable timesortedhashtable pairsafter assertequals assertequals assertequals assertequals assertequals assertequals pairsafter assertequals assertequals assertequals assertequals assertequals assertequals removebefore pairsafter assertequals assertequals assertequals assertequals private boolean contains only valid chars string a string char each char for int i 0 i a string length i each char a string char at i if uri pre encoder allowed chars index of each char 0 return false return true containsonlyvalidchars astring eachchar astring eachchar astring charat uripreencoder allowedchars indexof eachchar tests encode string method to verify if it converts all not safe chars into safe chars public void test encode string to encode prtbl ascii stressedutf 8chars string encoded uri pre encoder encode to encode assert true contains only valid chars encoded testencode toencode prtblascii stressedutf_8chars uripreencoder toencode asserttrue containsonlyvalidchars tests encodeuri string method to verify if it converts all not safe chars into safe chars public void test encodeuri string to encode prtbl ascii stressedutf 8chars uri encoded try encoded uri pre encoder encodeuri to encode this method will throw a not expected exception because is included as a valid char assert true contains only valid chars encoded to string catch uri syntax exception an exception fail not expected exception thrown an exception get message testencodeuri toencode prtblascii stressedutf_8chars uripreencoder toencode asserttrue containsonlyvalidchars tostring urisyntaxexception anexception anexception getmessage public void test byte array buffer byte data data string 1 get bytes buffer buffer new buffer data assert equals data buffer get data do test buffer data buffer testbytearraybuffer data_string_1 getbytes assertequals getdata dotestbuffer public void test byte array index buffer get content byte data data string 1 get bytes byte data sub new byte 5 prepare substring system arraycopy data 4 data sub 0 5 buffer buffer new buffer data 4 5 assert false data sub equals buffer get data do test buffer data sub buffer testbytearrayindexbuffer data_string_1 getbytes datasub datasub assertfalse datasub getdata dotestbuffer datasub public void test data input stream buffer byte data data string 1 get bytes get some content byte data2 new byte data length 4 make room for 4 byte length indicator int length data string 1 get bytes length populate length as first 4 bytes data2 0 byte length 0xff000000 24 data2 1 byte length 0xff0000 16 data2 2 byte length 0xff00 8 data2 3 byte length 0xff system arraycopy data 0 data2 4 data length populate rest of content data input stream dis new data input stream new byte array input stream data2 buffer buffer null try buffer new buffer dis catch io exception e fail unexpected exception e get message perform rest of test with the original array because buffer data input stream chomps first 4 bytes do test buffer data buffer testdatainputstreambuffer data_string_1 getbytes data_string_1 getbytes datainputstream datainputstream bytearrayinputstream ioexception getmessage datainputstream dotestbuffer private void do test buffer byte data buffer buffer assert equals data length buffer get length for int i 0 i buffer get length i assert equals data i buffer byte at i try buffer byte at data length 1 expect exception fail catch array index out of bounds exception e expect this dotestbuffer assertequals getlength getlength assertequals byteat byteat arrayindexoutofboundsexception public void test long buffer to string buffer buffer new buffer data string 1 get bytes string long string buffer to string assert equals buffer buffer get length long string testlongbuffertostring data_string_1 getbytes longstring tostring assertequals getlength longstring public void test short buffer to string string short string feep buffer short buffer new buffer short string get bytes string out string short buffer to string assert equals out string 4 102 101 101 112 fixme final brace testshortbuffertostring shortstring shortbuffer shortstring getbytes outstring shortbuffer tostring assertequals outstring public void test equals buffer b1 new buffer buffer1 get bytes buffer b2 new buffer buffer2 get bytes buffer b3 new buffer buffer1 get bytes assert false b1 equals b2 assert true b1 equals b3 assert false b2 equals b3 assert true b1 equals b1 assert true b2 equals b2 assert true b3 equals b1 testequals getbytes getbytes getbytes assertfalse asserttrue assertfalse asserttrue asserttrue asserttrue public void test hashcode buffer b1 new buffer buffer1 get bytes buffer b2 new buffer buffer2 get bytes buffer b3 new buffer buffer1 get bytes map buffer buffer hash map new hash map buffer buffer hash map put b1 b1 hash map put b2 b2 hash map put b3 b3 should clobber b1 due to content see if b3 survived object o hash map get b3 assert false o b1 assert true o b3 see if b1 survived o hash map get b1 assert false o b1 assert true o b3 testhashcode getbytes getbytes getbytes hashmap hashmap hashmap hashmap hashmap hashmap assertfalse asserttrue hashmap assertfalse asserttrue public void test copy byte old buf data string 1 get bytes buffer b new buffer old buf byte new buf new byte b get length b copy to new buf 0 for int i 0 i old buf length i assert equals new buf i old buf i testcopy oldbuf data_string_1 getbytes oldbuf newbuf getlength copyto newbuf oldbuf assertequals newbuf oldbuf public void test mutable boolean mutable boolean bool new mutable boolean bool value false assert false bool value bool value true assert true bool value testmutableboolean mutableboolean mutableboolean assertfalse asserttrue private string name j string name int prio this name name this prio prio public int get priority return prio getpriority public void run synchronized this notify all try assert true exec on thread completing job put name catch interrupted exception e fail e to string notifyall asserttrue onthread completingjob interruptedexception tostring override protected void set up throws exception super set up real exec new pooled executor completed jobs new array list string completing job new synchronous queue string exec new prioritized serial executor native thread max priority 10 5 true setup setup realexec pooledexecutor completedjobs arraylist completingjob synchronousqueue prioritizedserialexecutor nativethread max_priority private void q string j int i boolean wait for start throws interrupted exception j job new j j i synchronized job exec execute job j if wait for start job wait 5000 waitforstart interruptedexception waitforstart private void wait for int count throws interrupted exception int completed 0 while completed count string s completing job poll 5 time unit seconds if s null fail hang completed completed jobs add s system out println completed jobs waitfor interruptedexception completingjob timeunit completedjobs completedjobs public void test run throws interrupted exception assert true completed jobs is empty q j1 0 false q j2 0 false q j3 0 false q j4 0 false thread yield thread sleep 10 assert true completed jobs is empty not started yet exec start real exec test run start wait for 4 assert true completed jobs contains j1 assert true completed jobs contains j2 assert true completed jobs contains j3 assert true completed jobs contains j4 assert false exec on thread testrun interruptedexception asserttrue completedjobs isempty asserttrue completedjobs isempty realexec testrun waitfor asserttrue completedjobs asserttrue completedjobs asserttrue completedjobs asserttrue completedjobs assertfalse onthread public void test run prio throws interrupted exception assert true completed jobs is empty q jm 9 false q j8 8 false assert true completed jobs is empty not started yet assert equals 0 exec get waiting threads count exec start real exec test run prio start wait for 1 jm q j2 2 false q jn 4 false q jo 2 false q jp 3 false assert equals 0 exec get queue size 9 assert equals 1 exec get queue size 3 assert equals 2 exec get queue size 2 wait for 2 j8 jn assert equals 0 exec get queue size 9 assert equals 0 exec get queue size 4 assert equals 2 exec get queue size 2 thread yield thread sleep 10 q jq 4 false q jr 0 false assert equals 1 exec get queue size 4 assert equals 2 exec get queue size 2 assert equals 0 exec get queue size 1 assert equals 1 exec get queue size 0 int r exec queued jobs assert true arrays equals new int 1 0 2 0 1 0 0 0 0 0 r arrays equals new int 1 0 2 1 1 0 0 0 0 0 r wait for 5 jp jq j2 jo jr int i 0 for string s new string jm j8 jn jp jq j2 jo jr assert equals s s completed jobs get i testrunprio interruptedexception asserttrue completedjobs isempty asserttrue completedjobs isempty assertequals getwaitingthreadscount realexec testrunprio waitfor assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize waitfor assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize assertequals getqueuesize queuedjobs asserttrue waitfor assertequals completedjobs private void testfilterpositive bloom filter filter byte list new byte pass pos for int i 0 i pass pos i byte b new byte 32 rand next bytes b filter add key b list i b for byte b list assert true filter check filter b _testfilterpositive bloomfilter pass_pos pass_pos nextbytes addkey asserttrue checkfilter public void test counting filter positive int k bloom filter optimialk filter size pass pos bloom filter filter bloom filter create filter filter size k true testfilterpositive filter testcountingfilterpositive bloomfilter filter_size pass_pos bloomfilter bloomfilter createfilter filter_size _testfilterpositive public void test binary filter positive int k bloom filter optimialk filter size pass pos bloom filter filter bloom filter create filter filter size k false testfilterpositive filter testbinaryfilterpositive bloomfilter filter_size pass_pos bloomfilter bloomfilter createfilter filter_size _testfilterpositive public void test counting filter remove int k bloom filter optimialk filter size pass bloom filter filter bloom filter create filter filter size k true map byte array wrapper byte base list new hash map byte array wrapper byte add keys for int i 0 i pass i byte b new byte 32 do rand next bytes b while base list contains key new byte array wrapper b filter add key b base list put new byte array wrapper b b assert true check add base filter check filter b add some false pass keys map byte array wrapper byte new list new hash map byte array wrapper byte int f pos 0 for int i 0 i pass remove i byte b new byte 64 byte array wrapper wrapper do rand next bytes b wrapper new byte array wrapper b while new list contains key wrapper filter add key b new list put wrapper b assert true check add new filter check filter b remove the new keys and count false positive for byte b new list values filter remove key b for byte b new list values if filter check filter b f pos check if some should were removed assert false 100 false positive f pos pass remove check if old keys still here for byte b base list values assert true check original filter check filter b testcountingfilterremove bloomfilter filter_size bloomfilter bloomfilter createfilter filter_size bytearraywrapper baselist hashmap bytearraywrapper nextbytes baselist containskey bytearraywrapper addkey baselist bytearraywrapper asserttrue checkfilter false_pass bytearraywrapper newlist hashmap bytearraywrapper fpos pass_remove bytearraywrapper nextbytes bytearraywrapper newlist containskey addkey newlist asserttrue checkfilter newlist removekey newlist checkfilter fpos assertfalse fpos pass_remove baselist asserttrue checkfilter private void testfilterfalsepositive bloom filter filter set byte array wrapper list new hash set byte array wrapper add keys for int i 0 i pass i byte b new byte 32 do rand next bytes b while list contains new byte array wrapper b filter add key b list add new byte array wrapper b assert true check add filter check filter b system out println filter int f pos 0 for int i 0 i pass false i byte b new byte 64 64 bytes sure not exist rand next bytes b if filter check filter b f pos final int k filter getk final double q 1 math pow 1 1 0 filter size k pass final double p math pow q k final double actual double f pos pass false final double limit p 1 05 1 0 pass false system out println k k system out println q q system out println p p system out println limit limit system out println actual actual system out println actual p actual p assert false false positive p p actual actual actual limit _testfilterfalsepositive bloomfilter bytearraywrapper hashset bytearraywrapper nextbytes bytearraywrapper addkey bytearraywrapper asserttrue checkfilter fpos pass_false nextbytes checkfilter fpos filter_size fpos pass_false pass_false assertfalse public void test counting filter false positive int k bloom filter optimialk filter size pass bloom filter filter bloom filter create filter filter size k true testfilterfalsepositive filter testcountingfilterfalsepositive bloomfilter filter_size bloomfilter bloomfilter createfilter filter_size _testfilterfalsepositive public void test binary filter false positive int k bloom filter optimialk filter size pass bloom filter filter bloom filter create filter filter size k false testfilterfalsepositive filter testbinaryfilterfalsepositive bloomfilter filter_size bloomfilter bloomfilter createfilter filter_size _testfilterfalsepositive tests decode string method trying to decode entity by entity public void test decode single entities for int i 0 i utf util html entities utf length i assert equals html decoder decode utf util html entities utf i 1 utf util html entities utf i 0 testdecodesingleentities utfutil html_entities_utf assertequals htmldecoder utfutil html_entities_utf utfutil html_entities_utf tests decode string method trying to decode a long string with all possible entity appended public void test decode appended entities string builder to decode new string builder string builder expected new string builder for int i 0 i utf util html entities utf length i to decode append utf util html entities utf i 1 expected append utf util html entities utf i 0 assert equals html decoder decode to decode to string expected to string testdecodeappendedentities stringbuilder todecode stringbuilder stringbuilder stringbuilder utfutil html_entities_utf todecode utfutil html_entities_utf utfutil html_entities_utf assertequals htmldecoder todecode tostring tostring tests decode string method trying to decode incomplete entities the incomplete entity must remain the same as before encoding public void test decode incomplete without ending semicolon assert equals html decoder decode phi phi an entity without a char which means a not existing entity assert equals html decoder decode ph ph without ash assert equals html decoder decode 1234 1234 without ampersand assert equals html decoder decode phi phi emtpy string assert equals html decoder decode testdecodeincomplete assertequals htmldecoder assertequals htmldecoder assertequals htmldecoder assertequals htmldecoder assertequals htmldecoder tests compact string method trying to compact string with repeated whitespaces of every kind e g tabs newline space public void test compact repeated string builder str buffer new string builder 6 for int i 0 i str buffer length i str buffer i new string builder for int i 0 i 100 i adding different whitespaces str buffer 0 append whitespace str buffer 1 append tab str buffer 2 append unix newline str buffer 3 append mac newline str buffer 4 append control str buffer 5 append zerowidthspace for int j 0 j str buffer length j assert equals html decoder compact str buffer j to string testcompactrepeated stringbuilder strbuffer stringbuilder strbuffer strbuffer stringbuilder strbuffer strbuffer strbuffer unix_newline strbuffer mac_newline strbuffer strbuffer strbuffer assertequals htmldecoder strbuffer tostring tests compact string method with each kind of whitespace public void test compact mixed string to compact u0020 t n r u200b u000c assert equals html decoder compact to compact testcompactmixed tocompact assertequals htmldecoder tocompact tests is white space method against all possible html white space type public void test is white space assert true html decoder is whitespace whitespace assert true html decoder is whitespace tab assert true html decoder is whitespace unix newline assert true html decoder is whitespace mac newline assert true html decoder is whitespace control assert true html decoder is whitespace zerowidthspace iswhitespace testiswhitespace asserttrue htmldecoder iswhitespace asserttrue htmldecoder iswhitespace asserttrue htmldecoder iswhitespace unix_newline asserttrue htmldecoder iswhitespace mac_newline asserttrue htmldecoder iswhitespace asserttrue htmldecoder iswhitespace tests put single string string method trying to store a key with two paired multi level chars i e public void testsimplefieldsetputsingle stringstring withtwopairedmultilevelchars simple field set methodsfs new simple field set true string method key foo bar string method value foobar methodsfs put single method key method value assert equals methodsfs subset foo subset subset bar get method value assert equals methodsfs get method key method value putsingle multi_level_chars testsimplefieldsetputsingle_stringstring_withtwopairedmultilevelchars simplefieldset simplefieldset methodkey methodvalue putsingle methodkey methodvalue assertequals methodvalue assertequals methodkey methodvalue tests put append string string method trying to store a key with two paired multi level chars i e public void testsimplefieldsetputappend stringstring withtwopairedmultilevelchars simple field set methodsfs new simple field set true string method key foo bar string method value foobar methodsfs put append method key method value assert equals methodsfs get method key method value putappend multi_level_chars testsimplefieldsetputappend_stringstring_withtwopairedmultilevelchars simplefieldset simplefieldset methodkey methodvalue putappend methodkey methodvalue assertequals methodkey methodvalue tests put and get methods using a normal map behaviour and without multi level chars public void testsimplefieldsetputandget nomultilevel string method pairs array a a b b c c d d e e f f assert true check put and get pairs method pairs array multi_level_chars testsimplefieldsetputandget_nomultilevel methodpairsarray asserttrue checkputandgetpairs methodpairsarray tests put and get methods using a normal map behaviour and with multi level chars public void testsimplefieldsetputandget multilevel string methodpairsarray doublelevel a a aa a b ab a c ac a d ad a e ae a f af string methodpairsarray multilevel a a a a aa a b a ab a c cc ac a d f ad a e g ae a f j ii ui boo af assert true check put and get pairs methodpairsarray doublelevel assert true check put and get pairs methodpairsarray multilevel multi_level_chars testsimplefieldsetputandget_multilevel methodpairsarray_doublelevel methodpairsarray_multilevel asserttrue checkputandgetpairs methodpairsarray_doublelevel asserttrue checkputandgetpairs methodpairsarray_multilevel it puts key value pairs in a simple field set and verify if it can do the correspondant get correctly param a pairs array return true if it is correct private boolean check put and get pairs string a pairs array boolean ret value true simple field set methodsfs new simple field set true putting values for int i 0 i a pairs array length i methodsfs put single a pairs array i 0 a pairs array i 1 for int i 0 i a pairs array length i getting values ret value methodsfs get a pairs array i 0 equals a pairs array i 1 ret value check simple field set size methodsfs a pairs array length return ret value simplefieldset apairsarray checkputandgetpairs apairsarray retvalue simplefieldset simplefieldset apairsarray putsingle apairsarray apairsarray apairsarray retvalue apairsarray apairsarray retvalue checksimplefieldsetsize apairsarray retvalue tests subset string method putting two levels keys and fetching it through subset method on the first level and then get on the second public void testsimplefieldsetsubset string simple field set methodsfs new simple field set true string methodpairsarray multilevel a a aa a b ab a c ac a d ad a e ae a f af putting values for int i 0 i methodpairsarray multilevel length i methodsfs put single methodpairsarray multilevel i 0 simple field set multi level char methodpairsarray multilevel i 1 methodpairsarray multilevel i 2 getting subsets and then values for int i 0 i methodpairsarray multilevel length i assert equals methodsfs subset methodpairsarray multilevel i 0 get methodpairsarray multilevel i 1 methodpairsarray multilevel i 2 assert true check simple field set size methodsfs methodpairsarray multilevel length testsimplefieldsetsubset_string simplefieldset simplefieldset methodpairsarray_multilevel methodpairsarray_multilevel putsingle methodpairsarray_multilevel simplefieldset multi_level_char methodpairsarray_multilevel methodpairsarray_multilevel methodpairsarray_multilevel assertequals methodpairsarray_multilevel methodpairsarray_multilevel methodpairsarray_multilevel asserttrue checksimplefieldsetsize methodpairsarray_multilevel tests put all overwrite simple field set method trying to overwrite a whole simple field set with another with same keys but different values public void test put all overwrite string method appended string buu simple field set methodsfs sfs from sample string pairs simple field set method newsfs this sfs from string pairs method appended string methodsfs put all overwrite method newsfs for int i 0 i sample string pairs length i assert equals methodsfs get sample string pairs i 0 sample string pairs i 1 method appended string simple field set nullsfs new simple field set false nullsfs put all overwrite method newsfs for int i 0 i sample string pairs length i assert equals nullsfs get sample string pairs i 0 sample string pairs i 1 method appended string putalloverwrite simplefieldset simplefieldset testputalloverwrite methodappendedstring simplefieldset sfsfromsamplestringpairs simplefieldset methodnewsfs sfsfromstringpairs methodappendedstring putalloverwrite methodnewsfs sample_string_pairs assertequals sample_string_pairs sample_string_pairs methodappendedstring simplefieldset simplefieldset putalloverwrite methodnewsfs sample_string_pairs assertequals sample_string_pairs sample_string_pairs methodappendedstring tests put string simple field set method public void testput stringsimplefieldset string method key prefix simple field set methodsfs new simple field set true methodsfs put method key sfs from sample string pairs for int i 0 i sample string pairs length i assert equals methodsfs get method key simple field set multi level char sample string pairs i 0 sample string pairs i 1 simplefieldset testput_stringsimplefieldset methodkey simplefieldset simplefieldset methodkey sfsfromsamplestringpairs sample_string_pairs assertequals methodkey simplefieldset multi_level_char sample_string_pairs sample_string_pairs tests put string simple field set method public void testtput stringsimplefieldset string method key prefix simple field set methodsfs new simple field set true methodsfs tput method key sfs from sample string pairs for int i 0 i sample string pairs length i assert equals methodsfs get method key simple field set multi level char sample string pairs i 0 sample string pairs i 1 simplefieldset testtput_stringsimplefieldset methodkey simplefieldset simplefieldset methodkey sfsfromsamplestringpairs sample_string_pairs assertequals methodkey simplefieldset multi_level_char sample_string_pairs sample_string_pairs tests put string simple field set and tput string simple field set trying to add empty data structures public void testputandtput withempty simple field set method emptysfs new simple field set true simple field set method samplesfs sfs from sample string pairs try method samplesfs put sample method emptysfs fail expected exception error not thrown catch illegal argument exception an exception assert not null an exception try method samplesfs tput sample method samplesfs catch illegal argument exception a exception fail not expected exception thrown a exception get message simplefieldset simplefieldset testputandtput_withempty simplefieldset methodemptysfs simplefieldset simplefieldset methodsamplesfs sfsfromsamplestringpairs methodsamplesfs methodemptysfs illegalargumentexception anexception assertnotnull anexception methodsamplesfs methodsamplesfs illegalargumentexception aexception aexception getmessage it creates a sfs from the sample string pairs and putting a suffix after every value param a suffix to put after every value return the simple field set created private simple field set sfs from string pairs string a suffix simple field set methodsfs new simple field set true creating new for int i 0 i sample string pairs length i methodsfs put single sample string pairs i 0 sample string pairs i 1 a suffix return methodsfs sample_string_pairs asuffix simplefieldset simplefieldset sfsfromstringpairs asuffix simplefieldset simplefieldset sample_string_pairs putsingle sample_string_pairs sample_string_pairs asuffix tests put string boolean and get boolean string boolean methods consistency the default value returned if the key is not found is set to false and the real value is always set to true so we are sure if it finds the right value or not and does not use the default public void testput stringboolean simple field set methodsfs new simple field set true int length 15 for int i 0 i length i methodsfs put integer to string i true for int i 0 i length i assert equals methodsfs get boolean integer to string i false true assert true check simple field set size methodsfs length getboolean testput_stringboolean simplefieldset simplefieldset tostring assertequals getboolean tostring asserttrue checksimplefieldsetsize checks if the provided simple field set has the right size param a simple field set param expected size return true if the size is the expected private boolean check simple field set size simple field set a simple field set int expected size int actual size 0 iterator method key iterator a simple field set key iterator while method key iterator has next method key iterator next actual size return expected size actual size simplefieldset asimplefieldset expectedsize checksimplefieldsetsize simplefieldset asimplefieldset expectedsize actualsize methodkeyiterator asimplefieldset keyiterator methodkeyiterator hasnext methodkeyiterator actualsize expectedsize actualsize tests put string int and get int string get int string int methods consistency the default value returned if the key is not found is set to a not present int value so we are sure if it finds the right value or not and does not use the default public void testput stringint simple field set methodsfs new simple field set true int method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put integer to string method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try assert equals methodsfs get int integer to string method pairs array i 0 method pairs array i 1 assert equals methodsfs get int integer to string method pairs array i 0 5 method pairs array i 1 catch fs parse exception a exception fail not expected exception thrown a exception get message getint getint testput_stringint simplefieldset simplefieldset methodpairsarray methodpairsarray tostring methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals getint tostring methodpairsarray methodpairsarray assertequals getint tostring methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage tests put string long and get long string get long string long methods consistency the default value returned if the key is not found is set to a not present long value so we are sure if it finds the right value or not and does not use the default public void testput stringlong simple field set methodsfs new simple field set true long method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put long to string method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try assert equals methodsfs get long long to string method pairs array i 0 method pairs array i 1 assert equals methodsfs get long long to string method pairs array i 0 5 method pairs array i 1 catch fs parse exception a exception fail not expected exception thrown a exception get message getlong getlong testput_stringlong simplefieldset simplefieldset methodpairsarray methodpairsarray tostring methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals getlong tostring methodpairsarray methodpairsarray assertequals getlong tostring methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage tests put string char and get char string get char string char methods consistency the default value returned if the key is not found is set to a not present char value so we are sure if it finds the right value or not and does not use the default public void testput stringchar simple field set methodsfs new simple field set true char method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put string value of method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try assert equals methodsfs get char string value of method pairs array i 0 method pairs array i 1 assert equals methodsfs get char string value of method pairs array i 0 5 method pairs array i 1 catch fs parse exception a exception fail not expected exception thrown a exception get message getchar getchar testput_stringchar simplefieldset simplefieldset methodpairsarray methodpairsarray valueof methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals getchar valueof methodpairsarray methodpairsarray assertequals getchar valueof methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage tests put string short and get short string get short string short methods consistency the default value returned if the key is not found is set to a not present short value so we are sure if it finds the right value or not and does not use the default public void testput stringshort simple field set methodsfs new simple field set true short method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put short to string method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try assert equals methodsfs get short short to string method pairs array i 0 method pairs array i 1 assert equals methodsfs get short short to string method pairs array i 0 short 5 method pairs array i 1 catch fs parse exception a exception fail not expected exception thrown a exception get message getshort getshort testput_stringshort simplefieldset simplefieldset methodpairsarray methodpairsarray tostring methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals getshort tostring methodpairsarray methodpairsarray assertequals getshort tostring methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage tests put string double and get double string get double string double methods consistency the default value returned if the key is not found is set to a not present double value so we are sure if it finds the right value or not and does not use the default public void testput stringdouble simple field set methodsfs new simple field set true double method pairs array 1 1 2 2 3 3 4 4 for int i 0 i method pairs array length i methodsfs put double to string method pairs array i 0 method pairs array i 1 assert true check simple field set size methodsfs method pairs array length for int i 0 i method pairs array length i try there is no assert equals double double so we are obliged to do this way assert equals double compare methodsfs get double double to string method pairs array i 0 method pairs array i 1 0 assert equals double compare methodsfs get double double to string method pairs array i 0 double 5 method pairs array i 1 0 catch fs parse exception a exception fail not expected exception thrown a exception get message getdouble getdouble testput_stringdouble simplefieldset simplefieldset methodpairsarray methodpairsarray tostring methodpairsarray methodpairsarray asserttrue checksimplefieldsetsize methodpairsarray methodpairsarray assertequals _ assertequals getdouble tostring methodpairsarray methodpairsarray assertequals getdouble tostring methodpairsarray methodpairsarray fsparseexception aexception aexception getmessage generates a string for the sfs parser in the canonical form key value end param a string pairs array return a string ready to be read by a sfs parser private string sfs ready string string a string pairs array string method string to return for int i 0 i a string pairs array length i method string to return a string pairs array i 0 key value separator a string pairs array i 1 n method string to return sample end marker return method string to return astringpairsarray sfsreadystring astringpairsarray methodstringtoreturn astringpairsarray methodstringtoreturn astringpairsarray key_value_separator astringpairsarray methodstringtoreturn sample_end_marker methodstringtoreturn tests simple field set string boolean boolean constructor with simple and border cases of the canonical form public void testsimplefieldset stringbooleanboolean string method string pairs sample string pairs string method string to parse sfs ready string method string pairs try simple field set methodsfs new simple field set method string to parse false false for int i 0 i method string pairs length i assert equals methodsfs get method string pairs i 0 method string pairs i 1 catch io exception a exception fail not expected exception thrown a exception get message simplefieldset testsimplefieldset_stringbooleanboolean methodstringpairs sample_string_pairs methodstringtoparse sfsreadystring methodstringpairs simplefieldset simplefieldset methodstringtoparse methodstringpairs assertequals methodstringpairs methodstringpairs ioexception aexception aexception getmessage tests simple field set buffered reader boolean boolean constructor with simple and border cases of the canonical form public void testsimplefieldset bufferedreaderbooleanboolean string method string pairs sample string pairs buffered reader method buffered reader new buffered reader new string reader sfs ready string method string pairs try simple field set methodsfs new simple field set method buffered reader false false for int i 0 i method string pairs length i assert equals methodsfs get method string pairs i 0 method string pairs i 1 catch io exception a exception fail not expected exception thrown a exception get message simplefieldset bufferedreader testsimplefieldset_bufferedreaderbooleanboolean methodstringpairs sample_string_pairs bufferedreader methodbufferedreader bufferedreader stringreader sfsreadystring methodstringpairs simplefieldset simplefieldset methodbufferedreader methodstringpairs assertequals methodstringpairs methodstringpairs ioexception aexception aexception getmessage generates a simple field set using the sample string pairs and sfs put method return a simple field set private simple field set sfs from sample string pairs simple field set methodsfs new simple field set true for int i 0 i sample string pairs length i methodsfs put single sample string pairs i 0 sample string pairs i 1 assert true check simple field set size methodsfs sample string pairs length return methodsfs simplefieldset sample_string_pairs simplefieldset simplefieldset sfsfromsamplestringpairs simplefieldset simplefieldset sample_string_pairs putsingle sample_string_pairs sample_string_pairs asserttrue checksimplefieldsetsize sample_string_pairs tests simple field set simple field set constructor with simple and border cases of the canonical form public void testsimplefieldset simplefieldset simple field set methodsfs new simple field set sfs from sample string pairs string method string pairs sample string pairs for int i 0 i method string pairs length i assert equals methodsfs get method string pairs i 0 method string pairs i 1 simplefieldset simplefieldset testsimplefieldset_simplefieldset simplefieldset simplefieldset sfsfromsamplestringpairs methodstringpairs sample_string_pairs methodstringpairs assertequals methodstringpairs methodstringpairs tests get set end marker string methods using them after a string parsing public void test end marker string method end marker another ending string method string to parse sfs ready string sample string pairs try simple field set methodsfs new simple field set method string to parse false false assert equals methodsfs get end marker sample end marker methodsfs set end marker method end marker assert equals methodsfs get end marker method end marker catch io exception a exception fail not expected exception thrown a exception get message endmarker testendmarker methodendmarker methodstringtoparse sfsreadystring sample_string_pairs simplefieldset simplefieldset methodstringtoparse assertequals getendmarker sample_end_marker setendmarker methodendmarker assertequals getendmarker methodendmarker ioexception aexception aexception getmessage tests is empty method public void test is empty simple field set methodsfs sfs from sample string pairs assert false methodsfs is empty methodsfs new simple field set true assert true methodsfs is empty isempty testisempty simplefieldset sfsfromsamplestringpairs assertfalse isempty simplefieldset asserttrue isempty tests direct subset name iterator method it uses sample string pairs and for this reason the expected subset is foo public void test direct subset name iterator simple field set methodsfs sfs from sample string pairs string expected subset sample string pairs 0 0 foo iterator method iter methodsfs direct subset name iterator while method iter has next assert equals method iter next expected subset methodsfs new simple field set true method iter methodsfs direct subset name iterator assert null method iter directsubsetnameiterator sample_string_pairs testdirectsubsetnameiterator simplefieldset sfsfromsamplestringpairs expectedsubset sample_string_pairs methoditer directsubsetnameiterator methoditer hasnext assertequals methoditer expectedsubset simplefieldset methoditer directsubsetnameiterator assertnull methoditer tests name of direct subsets method public void test names of direct subsets string expected result sample string pairs 0 0 simple field set methodsfs sfs from sample string pairs assert true arrays equals methodsfs names of direct subsets expected result methodsfs new simple field set true assert true arrays equals methodsfs names of direct subsets new string 0 nameofdirectsubsets testnamesofdirectsubsets expectedresult sample_string_pairs simplefieldset sfsfromsamplestringpairs asserttrue namesofdirectsubsets expectedresult simplefieldset asserttrue namesofdirectsubsets test the put overwrite string string method public void testputoverwrite string string method key foo bar string method values boo bar zoo string expected result zoo simple field set methodsfs new simple field set true for int i 0 i method values length i methodsfs put overwrite method key method values i assert equals methodsfs get method key expected result putoverwrite testputoverwrite_string methodkey methodvalues expectedresult simplefieldset simplefieldset methodvalues putoverwrite methodkey methodvalues assertequals methodkey expectedresult test the put overwrite string string method public void testputoverwrite stringarray string method key foo bar string method values boo bar zoo simple field set methodsfs new simple field set true methodsfs put overwrite method key method values assert true arrays equals methodsfs get all method key method values putoverwrite testputoverwrite_stringarray methodkey methodvalues simplefieldset simplefieldset putoverwrite methodkey methodvalues asserttrue getall methodkey methodvalues test the put append string string method public void test put append string method key foo bar string method values boo bar zoo string expected result boo simple field set multi value char bar simple field set multi value char zoo simple field set methodsfs new simple field set true for int i 0 i method values length i methodsfs put append method key method values i assert equals methodsfs get method key expected result putappend testputappend methodkey methodvalues expectedresult simplefieldset multi_value_char simplefieldset multi_value_char simplefieldset simplefieldset methodvalues putappend methodkey methodvalues assertequals methodkey expectedresult tests the get all string method public void test get all string method key foo bar string method values boo bar zoo simple field set methodsfs new simple field set true for int i 0 i method values length i methodsfs put append method key method values i assert true arrays equals methodsfs get all method key method values getall testgetall methodkey methodvalues simplefieldset simplefieldset methodvalues putappend methodkey methodvalues asserttrue getall methodkey methodvalues tests the get int array string method public void test get int array simple field set methodsfs new simple field set true string key prefix foo for int i 0 i 15 i methodsfs put append key prefix string value of i int result methodsfs get int array key prefix for int i 0 i 15 i assert true result i i getintarray testgetintarray simplefieldset simplefieldset keyprefix putappend keyprefix valueof getintarray keyprefix asserttrue tests the get double array string method public void test get double array simple field set methodsfs new simple field set true string key prefix foo for int i 0 i 15 i methodsfs put append key prefix string value of double i double result methodsfs get double array key prefix for int i 0 i 15 i assert true result i double i getdoublearray testgetdoublearray simplefieldset simplefieldset keyprefix putappend keyprefix valueof getdoublearray keyprefix asserttrue tests remove value string method public void test remove value simple field set methodsfs sfs from sample string pairs methodsfs remove value foo assert null methodsfs get sample string pairs 0 0 for int i 1 i sample string pairs length i assert equals methodsfs get sample string pairs i 0 sample string pairs i 1 removevalue testremovevalue simplefieldset sfsfromsamplestringpairs removevalue assertnull sample_string_pairs sample_string_pairs assertequals sample_string_pairs sample_string_pairs tests remove subset string method public void test remove subset simple field set methodsfs sfs from sample string pairs methodsfs remove subset foo for int i 1 i 4 i assert null methodsfs get sample string pairs i 0 assert equals methodsfs get sample string pairs 0 0 sample string pairs 0 1 for int i 4 i 6 i assert equals methodsfs get sample string pairs i 0 sample string pairs i 1 removesubset testremovesubset simplefieldset sfsfromsamplestringpairs removesubset assertnull sample_string_pairs assertequals sample_string_pairs sample_string_pairs assertequals sample_string_pairs sample_string_pairs searches for a key in a given string array we consider that keys are stored in string x 0 param a string pairs array param a prefix that could be put before found key param a key to be searched return true if there is the key private boolean isa key string a string pairs array string a prefix string a key for int i 0 i a string pairs array length i if a key equals a prefix a string pairs array i 0 return true return false astringpairsarray aprefix akey isakey astringpairsarray aprefix akey astringpairsarray akey aprefix astringpairsarray verifies if all keys in a string we consider that keys are stored in string x 0 are the same that the iterator provides in this way both has next and next methods are tested param a string pairs array param a prefix that could be put before found key param a iterator return true if they have the same key set private boolean are all contained keys string a string pairs array string a prefix iterator a iterator boolean ret value true int actual length 0 while a iterator has next actual length ret value isa key a string pairs array a prefix string a iterator next ret value actual length a string pairs array length return ret value hasnext astringpairsarray aprefix aiterator areallcontainedkeys astringpairsarray aprefix aiterator retvalue actuallength aiterator hasnext actuallength retvalue isakey astringpairsarray aprefix aiterator retvalue actuallength astringpairsarray retvalue tests the iterator given for the simple field set class it tests has next and next methods public void test key iterator simple field set methodsfs sfs from sample string pairs iterator itr methodsfs key iterator assert true are all contained keys sample string pairs itr simplefieldset hasnext testkeyiterator simplefieldset sfsfromsamplestringpairs keyiterator asserttrue areallcontainedkeys sample_string_pairs tests the iterator created using prefix given for the simple field set class public void testkeyiterator string string method prefix bob simple field set methodsfs sfs from sample string pairs iterator itr methodsfs key iterator method prefix assert true are all contained keys sample string pairs method prefix itr simplefieldset testkeyiterator_string methodprefix simplefieldset sfsfromsamplestringpairs keyiterator methodprefix asserttrue areallcontainedkeys sample_string_pairs methodprefix tests the toplevel iterator given for the simple field set class it tests has next and next methods todo improve the test public void test toplevel key iterator simple field set methodsfs sfs from sample string pairs iterator itr methodsfs toplevel key iterator for int i 0 i 3 i assert true itr has next assert true isa key sample string pairs string itr next assert false itr has next topleveliterator simplefieldset hasnext testtoplevelkeyiterator simplefieldset sfsfromsamplestringpairs toplevelkeyiterator asserttrue hasnext asserttrue isakey sample_string_pairs assertfalse hasnext boolean is clone t int v value v isclone override public t clone t c new t value c is clone true return c isclone override public string to string if is clone return value else return value tostring isclone void assertv int v assert equals v value assertequals public void assert is clone assert true is clone is clone assertisclone asserttrue isclone isclone public void assert is not clone assert false is clone is clone assertisnotclone assertfalse isclone isclone override public boolean equals object o if o null return false if o get class this get class return false t t t o return t value value t is clone is clone getclass getclass isclone isclone override public int hash code return value hashcode public void test forward push pop doubly linked list t list new doubly linked list impl t list push new t 0 list push new t 1 list push new t 2 list push new t 3 assert false is empty list is empty list pop assertv 3 assert false is empty list is empty list pop assertv 2 assert false is empty list is empty add again list push new t 4 list push new t 5 list pop assertv 5 assert false is empty list is empty list pop assertv 4 assert false is empty list is empty list pop assertv 1 assert false is empty list is empty list pop assertv 0 assert true is empty list is empty assert null pop list pop testforwardpushpop doublylinkedlist doublylinkedlistimpl assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty asserttrue isempty isempty assertnull public void test forward shift unshift doubly linked list t list new doubly linked list impl t list unshift new t 0 list unshift new t 1 list unshift new t 2 list unshift new t 3 assert false is empty list is empty list shift assertv 3 assert false is empty list is empty list shift assertv 2 assert false is empty list is empty add again list unshift new t 4 list unshift new t 5 list shift assertv 5 assert false is empty list is empty list shift assertv 4 assert false is empty list is empty list shift assertv 1 assert false is empty list is empty list shift assertv 0 assert true is empty list is empty assert null shift list shift testforwardshiftunshift doublylinkedlist doublylinkedlistimpl assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty assertfalse isempty isempty asserttrue isempty isempty assertnull public void test clear size doubly linked list t list new doubly linked list impl t list unshift new t 0 list unshift new t 1 list unshift new t 2 list unshift new t 3 assert equals size 4 list size assert false is empty list is empty list shift assertv 3 assert equals size 3 list size assert false is empty list is empty list shift assertv 2 assert equals size 2 list size assert false is empty list is empty list clear assert equals size 0 list size assert true is empty list is empty add again list unshift new t 4 list unshift new t 5 assert equals size 2 list size assert false is empty list is empty list shift assertv 5 list shift assertv 4 assert equals size 0 list size assert true is empty list is empty testclearsize doublylinkedlist doublylinkedlistimpl assertequals assertfalse isempty isempty assertequals assertfalse isempty isempty assertequals assertfalse isempty isempty assertequals asserttrue isempty isempty assertequals assertfalse isempty isempty assertequals asserttrue isempty isempty public void test shiftn doubly linked list t list new doubly linked list impl t for int i 0 i 5 i list push new t i doubly linked list t list2 list shift 2 assert equals list2 size 2 list2 size list2 shift assertv 0 list2 shift assertv 1 assert true list2 is empty list2 is empty assert equals list size 3 list size list shift assertv 2 list2 list shift 20 assert true list is empty list is empty list2 shift assertv 3 list2 shift assertv 4 assert true list2 is empty list2 is empty list2 list shift 20 assert true list2 is empty list2 is empty testshiftn doublylinkedlist doublylinkedlistimpl doublylinkedlist assertequals asserttrue isempty isempty assertequals asserttrue isempty isempty asserttrue isempty isempty asserttrue isempty isempty public void test popn doubly linked list t list new doubly linked list impl t for int i 0 i 5 i list unshift new t i doubly linked list t list2 list pop 2 assert equals list2 size 2 list2 size list2 pop assertv 0 list2 pop assertv 1 assert true list2 is empty list2 is empty assert equals list size 3 list size list pop assertv 2 list2 list pop 20 assert true list is empty list is empty list2 pop assertv 3 list2 pop assertv 4 assert true list2 is empty list2 is empty list2 list pop 20 assert true list2 is empty list2 is empty testpopn doublylinkedlist doublylinkedlistimpl doublylinkedlist assertequals asserttrue isempty isempty assertequals asserttrue isempty isempty asserttrue isempty isempty asserttrue isempty isempty public void test head tail doubly linked list t list new doubly linked list impl t assert null head null list head assert null tail null list tail t array new t 5 for int i 0 i 5 i array i new t i list push array i assert true head 0 array 0 list head assert true tail 4 array 4 list tail list shift assert true head 1 array 1 list head assert true tail 4 array 4 list tail list pop assert true head 1 array 1 list head assert true tail 3 array 3 list tail list clear assert null head null list head assert null tail null list tail testheadtail doublylinkedlist doublylinkedlistimpl assertnull assertnull asserttrue asserttrue asserttrue asserttrue asserttrue asserttrue assertnull assertnull public void test iternator doubly linked list t list new doubly linked list impl t t array new t 5 for int i 0 i 5 i array i new t i list push array i manual forward t h list head for int i 0 i 5 i assert equals manual iternate forward array i h assert equals doubly linked list next item next h get next list next h assert equals has next i 4 list has next h assert equals has prev i 0 list has prev h h assertv i h list next h assert equals h null null h manual reverse t t list tail for int i 4 i 0 i assert equals manual iternate reverse array i t assert equals doubly linked list prev item get prev tail get prev list prev tail assert equals has next i 4 list has next t assert equals has prev i 0 list has prev t t assertv i t list prev t assert null t null t enumeration t e list elements for int i 0 i 5 i assert true has more elements e has more elements t n e next element n assertv i assert equals has more elements i 4 e has more elements try e next element fail no such element exception catch no such element exception nsee testiternator doublylinkedlist doublylinkedlistimpl assertequals assertequals doublylinkedlist getnext assertequals hasnext hasnext assertequals hasprev hasprev assertequals assertequals assertequals doublylinkedlist getprev getprev assertequals hasnext hasnext assertequals hasprev hasprev assertnull asserttrue hasmoreelements hasmoreelements nextelement assertequals hasmoreelements hasmoreelements nextelement nosuchelementexception nosuchelementexception public void test random remove push doubly linked list t list new doubly linked list impl t t array new t 5 for int i 0 i 5 i array i new t i list push array i assert true list remove array 3 array 3 list push array 3 remove non exist item give null assert null list remove new t 1 remove non identical but equal item give null assert null list remove new t 2 list shift assertv 0 list shift assertv 1 list shift assertv 2 list shift assertv 4 list shift assertv 3 assert null list remove new t 1 testrandomremovepush doublylinkedlist doublylinkedlistimpl asserttrue assertnull assertnull assertnull public void test random shift push doubly linked list t list new doubly linked list impl t list push new t 0 list push new t 1 list unshift new t 2 list push new t 3 list unshift new t 4 list unshift new t 5 list shift assertv 5 list pop assertv 3 list pop assertv 1 list pop assertv 0 list shift assertv 4 list shift assertv 2 testrandomshiftpush doublylinkedlist doublylinkedlistimpl public void test random insert doubly linked list t list new doubly linked list impl t t array new t 5 for int i 0 i 5 i array i new t i list push array i list insert prev array 0 new t 100 list insert prev array 2 new t 102 list insert next array 4 new t 104 list insert next array 4 new t 105 doubly linked list t list2 new doubly linked list impl t t l2 new t 9999 list2 push l2 try already exist list2 insert next l2 l2 fail promiscuous item exception catch promiscuous item exception pie try already exist list2 insert next l2 l2 fail promiscuous item exception catch promiscuous item exception pie try bad position list2 insert prev array 3 new t 8888 fail promiscuous item exception catch promiscuous item exception pie try bad position list2 insert next array 3 new t 8888 fail promiscuous item exception catch promiscuous item exception pie try item in other list list2 insert prev l2 array 3 fail promiscuous item exception catch promiscuous item exception pie try item in other list list2 insert next l2 array 3 fail promiscuous item exception catch promiscuous item exception pie t l3 new t 9999 list2 push l3 try virgin item exception l3 set prev null corrupt it list2 insert prev l3 new t 8888 fail virgin item exception catch virgin item exception vie try virgin item exception l2 set next null corrupt it list2 insert next l2 new t 8888 fail virgin item exception catch virgin item exception vie list shift assertv 100 list shift assertv 0 list shift assertv 1 list shift assertv 102 list shift assertv 2 list shift assertv 3 list shift assertv 4 list shift assertv 105 list shift assertv 104 testrandominsert doublylinkedlist doublylinkedlistimpl insertprev insertprev insertnext insertnext doublylinkedlist doublylinkedlistimpl insertnext promiscuousitemexception promiscuousitemexception insertnext promiscuousitemexception promiscuousitemexception insertprev promiscuousitemexception promiscuousitemexception insertnext promiscuousitemexception promiscuousitemexception insertprev promiscuousitemexception promiscuousitemexception insertnext promiscuousitemexception promiscuousitemexception virginitemexception setprev insertprev virginitemexception virginitemexception virginitemexception setnext insertnext virginitemexception virginitemexception create a object filled with increasing integers as keys and a list of generic objects as values param keys number the number of keys to create param value number the maximum value number per key param is random if true each key could have 1 values number values chosen randomly if false each key will have values number values return the object created private object create sample key multi val int keys number int values number boolean is random object sample objects new object keys number values number int method values number values number for int i 0 i sample objects length i if is random method values number 1 rnd next int values number sample objects i 0 i sample objects i 1 fill sample values list method values number return sample objects keysnumber valuenumber israndom valuesnumber valuesnumber createsamplekeymultival keysnumber valuesnumber israndom sampleobjects keysnumber valuesnumber methodvaluesnumber valuesnumber sampleobjects israndom methodvaluesnumber nextint valuesnumber sampleobjects sampleobjects fillsamplevalueslist methodvaluesnumber sampleobjects create a sample list filled with the specified number of generic objects param values number number of objects to create return the sample list private list object fill sample values list int values number list object sample values new linked list object for int i 0 i values number i sample values add new object return sample values valuesnumber fillsamplevalueslist valuesnumber samplevalues linkedlist valuesnumber samplevalues samplevalues create a sample multi value table param key number the number of key to insert in the multi value table param max value number the maximum number of value for each key param is random true if the max value number is an upper bound false if it is the actual value return the sample multi value table created private multi value table object object create sample multi value table int key number int max value number boolean is random object sample objects create sample key multi val key number max value number is random return fill multi value table sample objects multivaluetable keynumber multivaluetable maxvaluenumber israndom maxvaluenumber multivaluetable multivaluetable createsamplemultivaluetable keynumber maxvaluenumber israndom sampleobjects createsamplekeymultival keynumber maxvaluenumber israndom fillmultivaluetable sampleobjects given an enumeration it returns the number of present objects param an enumeration return the number of present objects private int enumeration size enumeration object an enumeration int counter 0 while an enumeration has more elements an enumeration next element counter return counter anenumeration enumerationsize anenumeration anenumeration hasmoreelements anenumeration nextelement fill a new multi value table from a object provided the object must be in the same form generated by create sample key multi val method param sample objects object array with i 0 as key and i 1 as list of values return the created multi value table suppress warnings unchecked private multi value table object object fill multi value table object sample objects multi value table object object methodmv table new multi value table object object iterator object itr for int i 0 i sample key number i itr list object sample objects i 1 iterator while itr has next methodmv table put sample objects i 0 itr next return methodmv table multivaluetable createsamplekeymultival sampleobjects multivaluetable suppresswarnings multivaluetable fillmultivaluetable sampleobjects multivaluetable methodmvtable multivaluetable samplekeynumber sampleobjects hasnext methodmvtable sampleobjects methodmvtable tests if there are problems when putting values in a sample multi value table public void test put assert not null create sample multi value table sample key number sample max value number sample is random multivaluetable testput assertnotnull createsamplemultivaluetable samplekeynumber samplemaxvaluenumber sampleisrandom tests get object method with both present keys and not present suppress warnings unchecked public void test get multi value table object object methodmv table new multi value table object object assert null methodmv table get new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert equals methodmv table get sample objects i 0 list object sample objects i 1 get 0 suppresswarnings testget multivaluetable methodmvtable multivaluetable assertnull methodmvtable sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects assertequals methodmvtable sampleobjects sampleobjects tests contains key object method verifying if all keys inserted are correctly found it verifies the correct behavior with empty multi value table and not present keys too public void test contains key multi value table object object methodmv table new multi value table object object assert false methodmv table contains key new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert true methodmv table contains key sample objects i 0 assert false methodmv table contains key new object containskey multivaluetable testcontainskey multivaluetable methodmvtable multivaluetable assertfalse methodmvtable containskey sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects asserttrue methodmvtable containskey sampleobjects assertfalse methodmvtable containskey tests contains element object object method verifying if all values inserted are correctly found it verifies the correct behavior with empty multi value table and not present elements too suppress warnings unchecked public void test contains element multi value table object object methodmv table new multi value table object object assert false methodmv table contains element new object new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects iterator object iter for int i 0 i sample objects length i iter list object sample objects i 1 iterator assert false methodmv table contains element sample objects i 0 new object while iter has next assert true methodmv table contains element sample objects i 0 iter next containselement multivaluetable suppresswarnings testcontainselement multivaluetable methodmvtable multivaluetable assertfalse methodmvtable containselement sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects sampleobjects assertfalse methodmvtable containselement sampleobjects hasnext asserttrue methodmvtable containselement sampleobjects tests get all method suppress warnings unchecked public void test get all multi value table object object methodmv table new multi value table object object todo verifies if an exception is necessary methodmv table get all new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects iterator object iter enumeration object method enumeration for int i 0 i sample objects length i iter list object sample objects i 1 iterator method enumeration methodmv table get all sample objects i 0 while iter has next assert equals method enumeration next element iter next getall suppresswarnings testgetall multivaluetable methodmvtable multivaluetable methodmvtable getall sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects methodenumeration sampleobjects sampleobjects methodenumeration methodmvtable getall sampleobjects hasnext assertequals methodenumeration nextelement tests count all method suppress warnings unchecked public void test count all multi value table object object methodmv table new multi value table object object assert equals methodmv table count all new object 0 object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert equals list object sample objects i 1 size methodmv table count all sample objects i 0 countall suppresswarnings testcountall multivaluetable methodmvtable multivaluetable assertequals methodmvtable countall sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects assertequals sampleobjects methodmvtable countall sampleobjects tests get sync object method fetching both present and not present keys suppress warnings cast unchecked public void test get sync multi value table object object methodmv table new multi value table object object assert null methodmv table get sync new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert equals methodmv table get sync sample objects i 0 list object sample objects i 1 getsync suppresswarnings testgetsync multivaluetable methodmvtable multivaluetable assertnull methodmvtable getsync sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects assertequals methodmvtable getsync sampleobjects sampleobjects tests get array object method both with a present key and a not present key suppress warnings unchecked public void test get array multi value table object object methodmv table new multi value table object object assert null methodmv table get array new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i assert true arrays equals list object sample objects i 1 to array methodmv table get array sample objects i 0 getarray suppresswarnings testgetarray multivaluetable methodmvtable multivaluetable assertnull methodmvtable getarray sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects asserttrue sampleobjects toarray methodmvtable getarray sampleobjects tests remove object method trying to remove all keys inserted in a multi value table it verifies the behavior when removing a not present key too public void test remove multi value table object object methodmv table new multi value table object object todo shouldn t it raise an exception methodmv table remove new object object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects for int i 0 i sample objects length i methodmv table remove sample objects i 0 assert true methodmv table is empty multivaluetable testremove multivaluetable methodmvtable multivaluetable methodmvtable sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects sampleobjects methodmvtable sampleobjects asserttrue methodmvtable isempty tests is empty method with an empty multi value table after putting objects and after removing all of them public void test is empty multi value table object object methodmv table new multi value table object object assert true methodmv table is empty object sample objects create sample key multi val sample key number sample max value number sample is random methodmv table fill multi value table sample objects assert false methodmv table is empty for int i 0 i sample objects length i methodmv table remove sample objects i 0 assert true methodmv table is empty isempty multivaluetable testisempty multivaluetable methodmvtable multivaluetable asserttrue methodmvtable isempty sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom methodmvtable fillmultivaluetable sampleobjects assertfalse methodmvtable isempty sampleobjects methodmvtable sampleobjects asserttrue methodmvtable isempty tests clear method filling a multi value table and verifying if all keys are correctly removed finally it verifies the result of is empty method public void test clear object sample objects create sample key multi val sample key number sample max value number sample is random multi value table object object methodmv table fill multi value table sample objects methodmv table clear for int i 0 i sample objects length i assert false methodmv table contains key sample objects i 0 assert true methodmv table is empty multivaluetable isempty testclear sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom multivaluetable methodmvtable fillmultivaluetable sampleobjects methodmvtable sampleobjects assertfalse methodmvtable containskey sampleobjects asserttrue methodmvtable isempty tests remove element object object removing all elements from a sample multi value table and verifying if they are correctly removed and if the result of is empty method is correct suppress warnings unchecked public void test remove element object sample objects create sample key multi val sample key number sample max value number sample is random multi value table object object methodmv table fill multi value table sample objects object method value iterator object iter for int i 0 i sample objects length i iter list object sample objects i 1 iterator assert false methodmv table remove element sample objects i 0 new object while iter has next method value iter next assert true methodmv table remove element sample objects i 0 method value assert false methodmv table contains element sample objects i 0 method value assert true methodmv table is empty removeelement multivaluetable isempty suppresswarnings testremoveelement sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom multivaluetable methodmvtable fillmultivaluetable sampleobjects methodvalue sampleobjects sampleobjects assertfalse methodmvtable removeelement sampleobjects hasnext methodvalue asserttrue methodmvtable removeelement sampleobjects methodvalue assertfalse methodmvtable containselement sampleobjects methodvalue asserttrue methodmvtable isempty tests keys method verifying if all keys inserted are correctly present in the resulting enumeration public void test keys object sample objects create sample key multi val sample key number sample max value number sample is random multi value table object object methodmv table fill multi value table sample objects todo shouldn t it respect keys order int j sample objects length 1 enumeration object method enumeration methodmv table keys while method enumeration has more elements assert equals sample objects j 0 method enumeration next element j testkeys sampleobjects createsamplekeymultival samplekeynumber samplemaxvaluenumber sampleisrandom multivaluetable methodmvtable fillmultivaluetable sampleobjects sampleobjects methodenumeration methodmvtable methodenumeration hasmoreelements assertequals sampleobjects methodenumeration nextelement tests elements and keys method verifying their behavior when putting the same value for different keys public void test different keys same element int keys number 2 multi value table object object methodmv table new multi value table object object string sample value sample value putting the same value for different keys for int i 0 i keys number i methodmv table put new object sample value assert equals enumeration size methodmv table elements 1 assert equals enumeration size methodmv table keys keys number testdifferentkeyssameelement keysnumber multivaluetable methodmvtable multivaluetable samplevalue samplevalue keysnumber methodmvtable samplevalue assertequals enumerationsize methodmvtable assertequals enumerationsize methodmvtable keysnumber tests if url encode encode string and url decode decode string boolean methods work correctly together both with safe characters and not safe base i e ascii chars public void testencodedecodestring notsafebasechars string to encode safe chars url encoder safeurl characters prtbl ascii triple char if badly encoded it will generate an exception no chars try assert true are correctly encoded decoded to encode true assert true are correctly encoded decoded to encode false catch url encoded format exception an exception fail not expected exception thrown an exception get message urlencode urldecode testencodedecodestring_notsafebasechars toencode urlencoder safeurlcharacters prtblascii asserttrue arecorrectlyencodeddecoded toencode asserttrue arecorrectlyencodeddecoded toencode urlencodedformatexception anexception anexception getmessage tests if url encode encode string and url decode decode string boolean methods work correctly together both with safe characters and not safe advanced i e not ascii chars public void testencodedecodestring notsafeadvchars string to encode stressedutf 8chars try assert true are correctly encoded decoded to encode true assert true are correctly encoded decoded to encode false catch url encoded format exception an exception fail not expected exception thrown an exception get message urlencode urldecode testencodedecodestring_notsafeadvchars toencode stressedutf_8chars asserttrue arecorrectlyencodeddecoded toencode asserttrue arecorrectlyencodeddecoded toencode urlencodedformatexception anexception anexception getmessage verifies if a string is the same after being processed by encoding and decoding methods param to encode string to encode return true means to be tolerant of bogus escapes throws url encoded format exception private boolean are correctly encoded decoded string to encode boolean with letters throws url encoded format exception boolean ret value true string encoded new string to encode length encoding for int i 0 i encoded length i encoded i url encoder encode to encode i with letters decoding for int i 0 i encoded length i ret value url decoder decode encoded i with letters equals to encode i return ret value toencode urlencodedformatexception arecorrectlyencodeddecoded toencode withletters urlencodedformatexception retvalue toencode urlencoder toencode withletters retvalue urldecoder withletters toencode retvalue tests encode string string boolean method to verify if the force parameter is well managed for each safeurl character with both true and false ascii flag public void test encode forced string to encode expected result char each char for int i 0 i url encoder safeurl characters length i each char url encoder safeurl characters char at i to encode string value of each char try expected result hex util bytes to hex since safe chars are only us ascii to encode get bytes us ascii assert equals url encoder encode to encode to encode false expected result assert equals url encoder encode to encode to encode true expected result catch unsupported encoding exception an exception fail not expected exception thrown an exception get message safeurlcharacter testencodeforced toencode expectedresult eachchar urlencoder safeurlcharacters eachchar urlencoder safeurlcharacters charat toencode valueof eachchar expectedresult hexutil bytestohex toencode getbytes assertequals urlencoder toencode toencode expectedresult assertequals urlencoder toencode toencode expectedresult unsupportedencodingexception anexception anexception getmessage verifies if a url encoded format exception is raised when decoding the provided string param to decode the string to decode param tolerant whether the decoding should be tolerant with return private boolean is decode raising encoded exception string to decode boolean tolerant boolean ret value false try system out println url decoder decode to decode false catch url encoded format exception an exception ret value true return ret value urlencodedformatexception todecode isdecoderaisingencodedexception todecode retvalue urldecoder todecode urlencodedformatexception anexception retvalue retvalue tests decode string boolean method using not valid encoded string to verifies if it raises an exception public void test decode wrong string string to decode 00 assert true is decode raising encoded exception to decode false testdecodewrongstring todecode asserttrue isdecoderaisingencodedexception todecode tests decode string boolean method using not valid hex values string to verifies if it raises an exception public void test decode wrong hex string to decode 123456789abcde prtbl ascii stressedutf 8chars for int i 0 i to decode length i assert true is decode raising encoded exception to decode substring i i 1 false testdecodewronghex todecode prtblascii stressedutf_8chars todecode asserttrue isdecoderaisingencodedexception todecode tests decode string boolean method trying the boolean argument to verify if it work correctly as a hack to allow users to paste in ur ls containing s public void test tolerant decoding string to decode try assert equals url decoder decode to decode true to decode catch url encoded format exception an exception fail not expected exception thrown an exception get message urls testtolerantdecoding todecode assertequals urldecoder todecode todecode urlencodedformatexception anexception anexception getmessage creates a bit array with all values set to the boolean argument param array size the size of the bit array param value the value for each bit return the set bit array private bit array create all equals bit array int array size boolean value bit array method bit array new bit array array size setting all bits true for int i 0 i method bit array get size i method bit array set bit i value return method bit array bitarray arraysize bitarray bitarray bitarray createallequalsbitarray arraysize bitarray methodbitarray bitarray arraysize methodbitarray getsize methodbitarray setbit methodbitarray creates a string of to repeat string as long as needed param string size length requested param to repeat string to repeat string size times return the string of to repeat private string create all one string int string size string to repeat string builder method string builder new string builder for int i 0 i string size i method string builder append to repeat return method string builder to string torepeat stringsize torepeat stringsize torepeat createallonestring stringsize torepeat stringbuilder methodstringbuilder stringbuilder stringsize methodstringbuilder torepeat methodstringbuilder tostring tests bit array int constructor and verifies if the instance is well created all values must be readables and false and the length has to be correct public void testbitarray int bit array method bit array new bit array sample bits number for int i 0 i sample bits number i assert false method bit array bit at i assert equals method bit array get size sample bits number bitarray testbitarray_int bitarray methodbitarray bitarray samplebitsnumber samplebitsnumber assertfalse methodbitarray bitat assertequals methodbitarray getsize samplebitsnumber tests to string method creating bit arrays with same value bits public void test to string all equals bit array method bit array create all equals bit array sample bits number true string expected string create all one string sample bits number 1 assert equals method bit array to string expected string method bit array create all equals bit array sample bits number false expected string create all one string sample bits number 0 assert equals method bit array to string expected string tostring bitarrays testtostringallequals bitarray methodbitarray createallequalsbitarray samplebitsnumber expectedstring createallonestring samplebitsnumber assertequals methodbitarray tostring expectedstring methodbitarray createallequalsbitarray samplebitsnumber expectedstring createallonestring samplebitsnumber assertequals methodbitarray tostring expectedstring tests to string method with a bit array with size zero public void test to string empty bit array method bit array new bit array 0 assert equals method bit array to string length 0 tostring bitarray testtostringempty bitarray methodbitarray bitarray assertequals methodbitarray tostring tests set bit int boolean method trying to set a bit out of bounds public void testsetbit outofbounds bit array method bit array new bit array sample bits number try method bit array set bit sample bits number true fail expected exception error not thrown catch array index out of bounds exception an exception assert not null an exception setbit testsetbit_outofbounds bitarray methodbitarray bitarray samplebitsnumber methodbitarray setbit samplebitsnumber arrayindexoutofboundsexception anexception assertnotnull anexception tests set bit int boolean method using get at int to verify if they are consistent public void test set and get bit bit array method bit array new bit array sample bits number setting true even bits for int i 0 i method bit array get size i i 2 method bit array set bit i true checking even bits for int i 0 i method bit array get size i i 2 assert true method bit array bit at i checking odd bits for int i 1 i method bit array get size i i 2 assert false method bit array bit at i setbit getat testsetandgetbit bitarray methodbitarray bitarray samplebitsnumber methodbitarray getsize methodbitarray setbit methodbitarray getsize asserttrue methodbitarray bitat methodbitarray getsize assertfalse methodbitarray bitat tests unsigned byte to int byte method trying it correctness for every possible i e 256 byte value public void test unsigned byte to int byte sample byte for int i 0 i 256 i sample byte byte i assert equals i bit array unsigned byte to int sample byte unsignedbytetoint testunsignedbytetoint samplebyte samplebyte assertequals bitarray unsignedbytetoint samplebyte tests get size method public void test get size bit array method bit array new bit array 0 assert equals method bit array get size 0 method bit array create all equals bit array sample bits number true assert equals method bit array get size sample bits number getsize testgetsize bitarray methodbitarray bitarray assertequals methodbitarray getsize methodbitarray createallequalsbitarray samplebitsnumber assertequals methodbitarray getsize samplebitsnumber tests set all ones method comparing the result to a bit array with already all ones set public void test set all ones bit array method bit array create all equals bit array sample bits number true bit array method bit array to verify new bit array sample bits number method bit array to verify set all ones assert equals method bit array method bit array to verify setallones bitarray testsetallones bitarray methodbitarray createallequalsbitarray samplebitsnumber bitarray methodbitarraytoverify bitarray samplebitsnumber methodbitarraytoverify setallones assertequals methodbitarray methodbitarraytoverify tests first one method far all possible first one position in a bit array with as many bits as in a single byte public void test first one bit array method bit array new bit array one byte bits only one 1 for int i 0 i one byte bits i method bit array new bit array one byte bits method bit array set bit i true assert equals method bit array first one i method bit array set all ones augmenting zeros for int i 0 i one byte bits 1 i method bit array set bit i false assert equals method bit array first one i 1 all zeros method bit array set bit one byte bits 1 false assert equals method bit array first one 1 firstone bitarray testfirstone bitarray methodbitarray bitarray onebytebits onebytebits methodbitarray bitarray onebytebits methodbitarray setbit assertequals methodbitarray firstone methodbitarray setallones onebytebits methodbitarray setbit assertequals methodbitarray firstone methodbitarray setbit onebytebits assertequals methodbitarray firstone test the encode byte method against a well known example see http en wikipedia org wiki base 64 as reference to verify if it encode works correctly public void test encode string to encode man is distinguished not only by his reason but by this singular passion from other animals which is a lust of the mind that by a perseverance of delight in the continued and indefatigable generation of knowledge exceeds the short vehemence of any carnal pleasure string expected result tw fui glzig rpc3 rpbmd1ax nozw qsig5vdc bvbmx5igj5i ghpcy byzw fzb24sigj 1dc biesb0a glzih npbmd1bg fyih bhc3 npb24g zn jvbs bvd ghlci bhbmlty wxzlcb3a gljac bpcy bhig x1c3 qgb2 ygd ghlig1pbm qsih royx qg ynkgys bwzx jzzx zlcm fuy2 ugb2 ygzg vsa wdodc bpbib0ag ugy 29ud gludw vkig fuzc bpbm rl zmf0a wdh ymxli gdlbm vyyx rpb24gb2 yga25vd2xlz gdllc bleg nlzw rz ih rozs bzag9ydcb2z whlbw vuy2 ugb2 ygyw55ig nhcm5hbc bwbg vhc3 vyzs4 byte a byte array to encode to encode get bytes assert equals base64 encode a byte array to encode expected result base_64 testencode toencode expectedresult twfuiglzigrpc3rpbmd1axnozwqsig5vdcbvbmx5igj5ighpcybyzwfzb24sigj 1dcbiesb0aglzihnpbmd1bgfyihbhc3npb24gznjvbsbvdghlcibhbmltywxzlcb3agljacbpcybhig x1c3qgb2ygdghlig1pbmqsihroyxqgynkgysbwzxjzzxzlcmfuy2ugb2ygzgvsawdodcbpbib0agugy 29udgludwvkigfuzcbpbmrlzmf0awdhymxligdlbmvyyxrpb24gb2yga25vd2xlzgdllcblegnlzwrz ihrozsbzag9ydcb2zwhlbwvuy2ugb2ygyw55ignhcm5hbcbwbgvhc3vyzs4 abytearraytoencode toencode getbytes assertequals abytearraytoencode expectedresult test the decode string method against a well known example see http en wikipedia org wiki base 64 as reference to verify if it decode an already encoded string correctly public void test decode string to decode tw fui glzig rpc3 rpbmd1ax nozw qsig5vdc bvbmx5igj5i ghpcy byzw fzb24sigj 1dc biesb0a glzih npbmd1bg fyih bhc3 npb24g zn jvbs bvd ghlci bhbmlty wxzlcb3a gljac bpcy bhig x1c3 qgb2 ygd ghlig1pbm qsih royx qg ynkgys bwzx jzzx zlcm fuy2 ugb2 ygzg vsa wdodc bpbib0ag ugy 29ud gludw vkig fuzc bpbm rl zmf0a wdh ymxli gdlbm vyyx rpb24gb2 yga25vd2xlz gdllc bleg nlzw rz ih rozs bzag9ydcb2z whlbw vuy2 ugb2 ygyw55ig nhcm5hbc bwbg vhc3 vyzs4 string expected result man is distinguished not only by his reason but by this singular passion from other animals which is a lust of the mind that by a perseverance of delight in the continued and indefatigable generation of knowledge exceeds the short vehemence of any carnal pleasure try string decoded string new string base64 decode to decode assert equals decoded string expected result catch illegal base64 exception a exception fail not expected exception thrown a exception get message base_64 testdecode todecode twfuiglzigrpc3rpbmd1axnozwqsig5vdcbvbmx5igj5ighpcybyzwfzb24sigj 1dcbiesb0aglzihnpbmd1bgfyihbhc3npb24gznjvbsbvdghlcibhbmltywxzlcb3agljacbpcybhig x1c3qgb2ygdghlig1pbmqsihroyxqgynkgysbwzxjzzxzlcmfuy2ugb2ygzgvsawdodcbpbib0agugy 29udgludwvkigfuzcbpbmrlzmf0awdhymxligdlbmvyyxrpb24gb2yga25vd2xlzgdllcblegnlzwrz ihrozsbzag9ydcb2zwhlbwvuy2ugb2ygyw55ignhcm5hbcbwbgvhc3vyzs4 expectedresult decodedstring todecode assertequals decodedstring expectedresult illegalbase64exception aexception aexception getmessage test encode byte in and decode string in str methods to verify if they work correctly together it compares the string before encoding and with the one after decoding public void test encode decode byte bytes decoded byte bytes to encode new byte 5 byte upper bound bytes to encode 0 127 bytes to encode 1 64 bytes to encode 2 0 bytes to encode 3 64 byte lower bound bytes to encode 4 128 string a base64 encoded string base64 encode bytes to encode try bytes decoded base64 decode a base64 encoded string assert true arrays equals bytes to encode bytes decoded catch illegal base64 exception a exception fail not expected exception thrown a exception get message instr testencodedecode bytesdecoded bytestoencode bytestoencode bytestoencode bytestoencode bytestoencode bytestoencode abase64encodedstring bytestoencode bytesdecoded abase64encodedstring asserttrue bytestoencode bytesdecoded illegalbase64exception aexception aexception getmessage test the encode string boolean method to verify if the padding character is correctly placed public void test encode padding byte method bytes array three byte array no padding char expected 4 4 4 two byte array one padding char expected 4 4 one byte array two padding chars expected 4 string encoded for int i 0 i method bytes array length i encoded base64 encode method bytes array i true if i 0 no occurrences expected assert equals encoded index of 1 else assert equals encoded index of encoded length i testencodepadding methodbytesarray methodbytesarray methodbytesarray assertequals indexof assertequals indexof test if the decode string method raise correctly an exception when providing a string with non base64 characters public void test illegal base character todo check many other possibile cases string illegal char string abcd fghilmn try base64 decode illegal char string fail expected illegal base64 exception not thrown catch illegal base64 exception exception assert same illegal base64 character exception get message testillegalbasecharacter illegalcharstring illegalcharstring illegalbase64exception illegalbase64exception assertsame getmessage test if the decode string method raise correctly an exception when providing a string with a wrong base64 length as we can consider not padded strings too the only wrong lengths are the ones where number mod 4 1 public void test illegal base length most interesting case string illegal length string a try base64 decode illegal length string fail expected illegal base64 exception not thrown catch illegal base64 exception exception assert same illegal base64 length exception get message testillegalbaselength illegallengthstring illegallengthstring illegalbase64exception illegalbase64exception assertsame getmessage random test throws illegal base64 exception public void test random throws illegal base64 exception int iter random r new random 1234 for iter 0 iter 1000 iter byte b new byte r next int 64 for int i 0 i b length i b i byte r next int 256 string encoded base64 encode b byte decoded base64 decode encoded assert equals length mismatch decoded length b length for int i 0 i b length i assert equals data mismatch index i of b length should be 0x integer to hex string b i 0xff was 0x integer to hex string decoded i 0xff b i decoded i illegalbase64exception testrandom illegalbase64exception nextint nextint assertequals assertequals tohexstring tohexstring public void test ssk forusk throws malformedurl exception freeneturi uri1 new freeneturi wanna usk 1 freeneturi uri2 new freeneturi wanna ssk 1 assert equals uri2 uri1 ssk forusk assert equals uri1 uri2 usk forssk try uri1 usk forssk fail no excpetion throw catch illegal state exception e pass try uri2 ssk forusk fail no excpetion throw catch illegal state exception e pass try new freeneturi wanna chk 1 ssk forusk fail no excpetion throw catch illegal state exception e pass try new freeneturi wanna chk 1 usk forssk fail no excpetion throw catch illegal state exception e pass try new freeneturi ssk 5hh 39 ftja7a9 vx wtbki prud tujzu ruddg0x fn3ka g dgr gt5f6xqbmo wra qtu54x4h 871 sho9 hz6hc 0ra aqacaae search 17xxxx index d51 xml ssk forusk fail no excpetion throw catch illegal state exception e pass try new freeneturi ssk 5hh 39 ftja7a9 vx wtbki prud tujzu ruddg0x fn3ka g dgr gt5f6xqbmo wra qtu54x4h 871 sho9 hz6hc 0ra aqacaae search17 index d51 xml ssk forusk fail no excpetion throw catch illegal state exception e pass testsskforusk malformedurlexception wanna_usk_1 wanna_ssk_1 assertequals sskforusk assertequals uskforssk uskforssk illegalstateexception sskforusk illegalstateexception wanna_chk_1 sskforusk illegalstateexception wanna_chk_1 uskforssk illegalstateexception 39ftja7a9 vxwtbki prudtujzuruddg0xfn3ka gdgrgt5f6xqbmo wraqtu54x4h 871sho9hz6hc index_d51 sskforusk illegalstateexception 39ftja7a9 vxwtbki prudtujzuruddg0xfn3ka gdgrgt5f6xqbmo wraqtu54x4h 871sho9hz6hc index_d51 sskforusk illegalstateexception public void test throws exception inet4 address matcher matcher new inet4 address matcher 192 168 1 2 assert equals false matcher matches inet address get by name 192 168 1 1 assert equals true matcher matches inet address get by name 192 168 1 2 assert equals false matcher matches inet address get by name 127 0 0 1 assert equals false matcher matches inet address get by name 0 0 0 0 matcher new inet4 address matcher 192 168 1 2 8 assert equals true matcher matches inet address get by name 192 168 1 1 assert equals true matcher matches inet address get by name 192 168 1 2 assert equals true matcher matches inet address get by name 192 168 2 1 assert equals true matcher matches inet address get by name 192 16 81 1 assert equals true matcher matches inet address get by name 192 255 255 255 assert equals false matcher matches inet address get by name 172 16 1 1 assert equals false matcher matches inet address get by name 127 0 0 1 assert equals false matcher matches inet address get by name 0 0 0 0 assert equals true matcher matches inet address get by name 192 0 0 0 some fancy matching matcher new inet4 address matcher 192 168 1 1 255 0 255 0 assert equals true matcher matches inet address get by name 192 168 1 1 assert equals true matcher matches inet address get by name 192 16 1 1 assert equals false matcher matches inet address get by name 192 168 2 1 assert equals false matcher matches inet address get by name 192 16 2 1 assert equals false matcher matches inet address get by name 127 0 0 1 matcher new inet4 address matcher 127 0 0 1 8 assert equals true matcher matches inet address get by name 127 0 0 1 assert equals true matcher matches inet address get by name 127 23 42 64 assert equals true matcher matches inet address get by name 127 0 0 0 assert equals true matcher matches inet address get by name 127 255 255 255 assert equals false matcher matches inet address get by name 28 0 0 1 matcher new inet4 address matcher 0 0 0 0 0 assert equals true matcher matches inet address get by name 127 0 0 1 assert equals true matcher matches inet address get by name 192 168 1 1 assert equals true matcher matches inet address get by name 192 168 2 1 assert equals true matcher matches inet address get by name 172 16 42 23 assert equals true matcher matches inet address get by name 10 0 0 1 assert equals true matcher matches inet address get by name 224 0 0 1 inet4addressmatcher inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet4addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname public void test throws exception inet6 address matcher matcher new inet6 address matcher 0 0 0 0 0 0 0 0 0 assert equals true matcher matches inet address get by name fe80 0 0 0 203 dff fe22 420f matcher new inet6 address matcher fe80 0 0 0 203 dff fe22 420f 64 assert equals true matcher matches inet address get by name fe80 0 0 0 203 dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0203 0dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0204 0dff fe22 420f assert equals false matcher matches inet address get by name fe81 0 0 0 0203 0dff fe22 420f assert equals false matcher matches inet address get by name 0 0 0 0 0 0 0 1 assert equals true matcher matches inet address get by name fe80 0 0 0 0 0 0 1 matcher new inet6 address matcher fe80 0 0 0 203 dff fe22 420f ffff ffff ffff ffff 0 0 0 0 assert equals true matcher matches inet address get by name fe80 0 0 0 203 dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0203 0dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0204 0dff fe22 420f assert equals false matcher matches inet address get by name fe81 0 0 0 0203 0dff fe22 420f assert equals false matcher matches inet address get by name 0 0 0 0 0 0 0 1 assert equals true matcher matches inet address get by name fe80 0 0 0 0 0 0 1 matcher new inet6 address matcher fe80 0 0 0 203 dff fe22 420f 128 assert equals true matcher matches inet address get by name fe80 0 0 0 203 dff fe22 420f assert equals true matcher matches inet address get by name fe80 0 0 0 0203 0dff fe22 420f assert equals false matcher matches inet address get by name fe80 0 0 0 0204 0dff fe22 420f assert equals false matcher matches inet address get by name fe81 0 0 0 0203 0dff fe22 420f assert equals false matcher matches inet address get by name 0 0 0 0 0 0 0 1 assert equals false matcher matches inet address get by name fe80 0 0 0 0 0 0 1 inet6addressmatcher inet6addressmatcher assertequals inetaddress getbyname inet6addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet6addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname inet6addressmatcher assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname assertequals inetaddress getbyname public void test test real i pv4 addresses assert equals address type i pv4 address identifier get address type 0 0 0 0 assert equals address type i pv4 address identifier get address type 127 0 0 1 assert equals address type i pv4 address identifier get address type 255 255 255 255 in case you didn t know 183 24 17 183 24 0 17 assert equals address type i pv4 address identifier get address type 183 24 17 and 127 1 127 0 0 1 assert equals address type i pv4 address identifier get address type 127 1 test fake i pv4 addresses assert equals address type other address identifier get address type 192 168 370 12 assert equals address type other address identifier get address type 127 0 0 0 1 test real unabridged i pv6 addresses assert equals address type i pv6 address identifier get address type 0 0 0 0 0 0 0 1 assert equals address type i pv6 address identifier get address type fe80 0 0 0 203 dff fe22 420f test fake i pv6 addresses assert equals address type other address identifier get address type 1 2 3 4 5 6 7 8 9 assert equals address type other address identifier get address type 12345 6 7 8 9 ipv4 assertequals addresstype ipv4 addressidentifier getaddresstype assertequals addresstype ipv4 addressidentifier getaddresstype assertequals addresstype ipv4 addressidentifier getaddresstype assertequals addresstype ipv4 addressidentifier getaddresstype assertequals addresstype ipv4 addressidentifier getaddresstype ipv4 assertequals addresstype addressidentifier getaddresstype assertequals addresstype addressidentifier getaddresstype ipv6 assertequals addresstype ipv6 addressidentifier getaddresstype assertequals addresstype ipv6 addressidentifier getaddresstype ipv6 assertequals addresstype addressidentifier getaddresstype assertequals addresstype addressidentifier getaddresstype public void test is anisatapi pv6 address assert false address identifier is anisatapi pv6 address fe80 0 0 0 203 dff fe22 420f assert false address identifier is anisatapi pv6 address fe80 0 5efe 0 203 dff fe22 420f assert true address identifier is anisatapi pv6 address 2001 1 2 3 0 5efe c801 20a testisanisatapipv6address assertfalse addressidentifier isanisatapipv6address assertfalse addressidentifier isanisatapipv6address asserttrue addressidentifier isanisatapipv6address public void test known value throws unsupported cipher exception rijndael aes128 new rijndael 128 128 byte res128 new byte 128 8 aes128 initialize key128 1 aes128 encipher plaintxt128 1 res128 assert true 128 128 encipher arrays equals res128 cipher128 1 byte des128 new byte 128 8 aes128 decipher res128 des128 assert true 128 128 decipher arrays equals des128 plaintxt128 1 rijndael aes192 new rijndael 192 192 byte res192 new byte 192 8 aes192 initialize key192 1 aes192 encipher plaintxt192 1 res192 assert true 192 192 encipher arrays equals res192 cipher192 1 byte des192 new byte 192 8 aes192 decipher res192 des192 assert true 192 192 decipher arrays equals des192 plaintxt192 1 rijndael aes256 new rijndael 256 256 byte res256 new byte 256 8 aes256 initialize key256 1 aes256 encipher plaintxt256 1 res256 assert true 256 256 encipher arrays equals res256 cipher256 1 byte des256 new byte 256 8 aes256 decipher res256 des256 assert true 256 256 decipher arrays equals des256 plaintxt256 1 testknownvalue unsupportedcipherexception key128_1 plaintxt128_1 asserttrue cipher128_1 asserttrue plaintxt128_1 key192_1 plaintxt192_1 asserttrue cipher192_1 asserttrue plaintxt192_1 key256_1 plaintxt256_1 asserttrue cipher256_1 asserttrue plaintxt256_1 public void test standard testvk throws unsupported cipher exception keysize 128 rijndael aes128 new rijndael 128 128 for int i 0 i test vk128 length i aes128 initialize test vk128 i 0 byte cipher new byte 128 8 aes128 encipher test vk pt cipher assert true ecb vk keysize 128 i i 1 arrays equals cipher test vk128 i 1 keysize 192 this case would fail rijndael aes192 new rijndael 192 128 for int i 0 i test vk192 length i aes192 initialize test vk192 i 0 byte cipher new byte 192 8 aes192 encipher test vk pt cipher assert true ecb vk keysize 192 i i 1 arrays equals cipher test vk192 i 1 teststandardtestvk unsupportedcipherexception test_vk128 test_vk128 test_vk_pt asserttrue ecb_vk test_vk128 test_vk192 test_vk192 test_vk_pt asserttrue ecb_vk test_vk192 public void test random throws unsupported cipher exception final int size new int 128 192 256 for int k 0 k size length k int size size k rijndael aes new rijndael size size byte key new byte size 8 rand next bytes key aes initialize key for int i 0 i 1024 i byte plain new byte size 8 rand next bytes plain byte cipher new byte size 8 aes encipher plain cipher byte plain2 new byte size 8 aes decipher cipher plain2 assert true size size key hex util bytes to hex key plain hex util bytes to hex plain cipher hex util bytes to hex cipher plain2 hex util bytes to hex plain2 arrays equals plain plain2 testrandom unsupportedcipherexception nextbytes nextbytes asserttrue hexutil bytestohex hexutil bytestohex hexutil bytestohex hexutil bytestohex private random source random source public dsa test string test name super test name randomsource randomsource dsatest testname testname override protected void set up throws exception random source new dummy random source setup randomsource dummyrandomsource override protected void tear down throws exception teardown test of verify and sign method consistency using fips examples public void test sign and verify dsa signature a signature dsa sign fips dsa group fips dsa private key fips k fips sha1 m random source assert true dsa verify fips dsa public key a signature fips sha1 m false testsignandverify dsasignature asignature fips_dsa_group fips_dsa_private_key fips_k fips_sha1_m randomsource asserttrue fips_dsa_public_key asignature fips_sha1_m test of verify dsa public key kp dsa signature sig big integer m boolean force mod method comparing it with the dsa values based on fips examples public void test verify assert true dsa verify fips dsa public key fips dsa signature fips sha1 m false dsapublickey dsasignature biginteger forcemod testverify asserttrue fips_dsa_public_key fips_dsa_signature fips_sha1_m test sign method consistency it performs two signature of the same message and verifies if they are identical public void test same sign consistency dsa signature first signature dsa sign fips dsa group fips dsa private key fips k fips sha1 m random source dsa signature second signature dsa sign fips dsa group fips dsa private key fips k fips sha1 m random source assert equals first signature getr second signature getr assert equals first signature gets second signature gets testsamesignconsistency dsasignature firstsignature fips_dsa_group fips_dsa_private_key fips_k fips_sha1_m randomsource dsasignature secondsignature fips_dsa_group fips_dsa_private_key fips_k fips_sha1_m randomsource assertequals firstsignature secondsignature assertequals firstsignature secondsignature test sign dsa group g dsa private key x big integer m random source r method using a q value that is too small shorter than dsa group q bit length to generate a correct k value public void test sign smallq value try dsa sign fips dsa group fips dsa private key fips sha1 m random source fail exception error not thrown catch illegal argument exception an exception assert not null an exception dsagroup dsaprivatekey biginteger randomsource dsagroup q_bit_length testsignsmallqvalue fips_dsa_group fips_dsa_private_key fips_sha1_m randomsource illegalargumentexception anexception assertnotnull anexception test sign dsa group g dsa private key x big integer r big integer k inv big integer m random source random method comparing it with the dsa signature based on fips examples public void testsign grp pvtkey r kinv m rand dsa signature a signature dsa sign fips dsa group fips dsa private key fips r fips k inv fips sha1 m random source assert equals a signature getr fips r assert equals a signature gets fips s dsagroup dsaprivatekey biginteger biginteger kinv biginteger randomsource dsasignature testsign_grp_pvtkey_r_kinv_m_rand dsasignature asignature fips_dsa_group fips_dsa_private_key fips_r fips_k_inv fips_sha1_m randomsource assertequals asignature fips_r assertequals asignature fips_s test sign dsa group g dsa private key x big integer k big integer m random source random method comparing it with the dsa signature based on fips examples public void testsign grp pvtkey k m rand big integer x fips x dsa private key a test private key dsa signature another signature dsa signature a signature dsa sign fips dsa group fips dsa private key fips k fips sha1 m random source big integer generatedr a signature getr big integer generateds a signature gets assert equals generatedr fips r assert equals generateds fips s for int i 0 i fips x bit count i x x flip bit i if x compare to fips x 0 a test private key new dsa private key x fips dsa group another signature dsa sign fips dsa group a test private key fips k fips sha1 m random source assert false generatedr compare to another signature getr 0 generateds compare to another signature gets 0 dsagroup dsaprivatekey biginteger biginteger randomsource dsasignature testsign_grp_pvtkey_k_m_rand biginteger fips_x dsaprivatekey atestprivatekey dsasignature anothersignature dsasignature asignature fips_dsa_group fips_dsa_private_key fips_k fips_sha1_m randomsource biginteger asignature biginteger asignature assertequals fips_r assertequals fips_s fips_x bitcount flipbit compareto fips_x atestprivatekey dsaprivatekey fips_dsa_group anothersignature fips_dsa_group atestprivatekey fips_k fips_sha1_m randomsource assertfalse compareto anothersignature compareto anothersignature test sign dsa group g dsa private key x big integer m random source r method using verify method as the verify test passed then we can consider it a tested way to verify this sign method accuracy since it is impossible to test it using fips examples as they are based on sha1 and thus they use q values that are shorter than current dsa group q bit length public void testsign grp pvtkey m rand dsa group ads agroup global ds agroup biga dsa private key adsa priv key new dsa private key ads agroup random source dsa public key adsa pub key new dsa public key ads agroup adsa priv key dsa signature a signature dsa sign ads agroup adsa priv key adsa priv key getx random source assert true dsa verify adsa pub key a signature adsa priv key getx false dsagroup dsaprivatekey biginteger randomsource dsagroup q_bit_length testsign_grp_pvtkey_m_rand dsagroup adsagroup dsagroupbiga dsaprivatekey adsaprivkey dsaprivatekey adsagroup randomsource dsapublickey adsapubkey dsapublickey adsagroup adsaprivkey dsasignature asignature adsagroup adsaprivkey adsaprivkey randomsource asserttrue adsapubkey asignature adsaprivkey override protected void set up throws exception super set up file writer fw new file writer seed file for int i 0 i 256 i fw write i fw flush fw close setup setup filewriter filewriter seed_file override protected void tear down throws exception super tear down assert true seed file delete teardown teardown asserttrue seed_file public void test double yarrow y new yarrow seed file sha1 rijndael false false false scalar sample statistics sample new scalar sample statistics for int i 0 i 10000 i sample add y next double assert equals 0 5 sample get mean 0 02 assert equals 1 0 2 0 math sqrt 3 0 sample get standard deviation 0 002 testdouble seed_file scalarsamplestatistics scalarsamplestatistics nextdouble assertequals getmean assertequals getstandarddeviation public void test next int yarrow y new yarrow seed file sha1 rijndael false false false for int n 1 n 20 n int count new int n for int k 0 k 10000 k int l y next int n count l assert true l 0 assert true l n for int i 0 i n i assert true n count i 8800 assert true n count i 11100 testnextint seed_file nextint asserttrue asserttrue asserttrue asserttrue public void test next boolean yarrow y new yarrow seed file sha1 rijndael false false false int results new int 2 int runs 1000000 for int i 0 i runs i if y next boolean results 0 else results 1 assert equals runs results 0 results 1 assert true results 0 runs 2 runs 1000 assert true results 1 runs 2 runs 1000 testnextboolean seed_file nextboolean assertequals asserttrue asserttrue sub config sc public config test string name super name subconfig configtest override protected void set up throws exception super set up conf new config sc new sub config testing conf setup setup subconfig public void test config assert not null new config testconfig assertnotnull public void test register test if we can register string builder sb new string builder for int i 0 i utf util printable ascii length i sb append utf util printable ascii i for int i 0 i utf util stressed utf length i sb append utf util stressed utf i assert not null new sub config sb to string conf test if it prevents multiple registrations try conf register sc catch illegal argument exception ie return fail testregister stringbuilder stringbuilder utfutil printable_ascii utfutil printable_ascii utfutil stressed_utf utfutil stressed_utf assertnotnull subconfig tostring illegalargumentexception public void test get configs assert not null conf get configs assert false new config get configs equals conf assert equals 1 conf get configs length assert same sc conf get configs 0 testgetconfigs assertnotnull getconfigs assertfalse getconfigs assertequals getconfigs assertsame getconfigs public void test get assert same sc conf get testing testget assertsame public void testcss1 selector throws io exception for string css css1 selector assert equals css1 selector css filter css testcss1selector ioexception css1_selector assertequals css1_selector public void testcss2 selector throws io exception for string css css2 selector assert equals css2 selector css filter css testcss2selector ioexception css2_selector assertequals css2_selector public void testcss3 selector throws io exception for string css css3 selector assert equals css3 selector css filter css testcss3selector ioexception css3_selector assertequals css3_selector private string filter string css throws io exception string writer w new string writer css parser p new css parser new string reader css w false null p parse return w to string ioexception stringwriter stringwriter cssparser cssparser stringreader tostring public void test suite test throws io exception png filter filter new png filter false false true for object test test images string filename string test 0 boolean valid boolean test 1 bucket ib try ib resource to bucket filename catch io exception e system out println filename not found test skipped continue try bucket ob filter read filter ib new array bucket factory null null assert true filename should valid not be valid valid catch data filter exception dfe assert false filename should valid not be valid valid testsuitetest ioexception pngfilter pngfilter testimages resourcetobucket ioexception readfilter arraybucketfactory asserttrue datafilterexception assertfalse protected bucket resource to bucket string filename throws io exception input stream is get class get resource as stream filename if is null throw new java io file not found exception array bucket ab new array bucket bucket tools copy from ab is long max value return ab resourcetobucket ioexception inputstream getclass getresourceasstream filenotfoundexception arraybucket arraybucket buckettools copyfrom max_value public void testhtml filter throws exception general sanity checks is relativization working assert equals internal relative link html filter internal relative link assert equals internal relative link html filter internal absolute link are external links stripped out assert true html filter external link check1 starts with external link ok assert true html filter external link check2 contains generic read filter callback magichttp escape string assert true html filter external link check3 starts with external link ok regression testing bug 710 assert equals anchor test html filter anchor test assert equals anchor test empty html filter anchor test empty assert equals anchor test special html filter anchor test special assert equals anchor test special2 result html filter anchor test special2 bug 2496 assert equals anchor relative1 html filter anchor relative1 assert equals anchor relative2 html filter anchor relative2 assert equals anchor false pos1 html filter anchor false pos1 assert equals anchor false pos2 html filter anchor false pos2 evil hack test for 2496 2451 assert equals anchor mixed result html filter anchor mixed bug 2451 assert equals pount character encoding test result html filter pount character encoding test bug 2297 assert true html filter prevent fproxy access contains generic read filter callback magichttp escape string bug 2921 assert true html filter prevent external access css simple contains checked http assert false html filter prevent external access css escape contains http assert true html filter prevent external access css case contains checked http assert equals whitelist static content html filter whitelist static content testhtmlfilter assertequals internal_relative_link htmlfilter internal_relative_link assertequals internal_relative_link htmlfilter internal_absolute_link asserttrue htmlfilter external_link_check1 startswith external_link_ok asserttrue htmlfilter external_link_check2 genericreadfiltercallback magichttpescapestring asserttrue htmlfilter external_link_check3 startswith external_link_ok assertequals anchor_test htmlfilter anchor_test assertequals anchor_test_empty htmlfilter anchor_test_empty assertequals anchor_test_special htmlfilter anchor_test_special assertequals anchor_test_special2_result htmlfilter anchor_test_special2 assertequals anchor_relative1 htmlfilter anchor_relative1 assertequals anchor_relative2 htmlfilter anchor_relative2 assertequals anchor_false_pos1 htmlfilter anchor_false_pos1 assertequals anchor_false_pos2 htmlfilter anchor_false_pos2 assertequals anchor_mixed_result htmlfilter anchor_mixed assertequals pount_character_encoding_test_result htmlfilter pount_character_encoding_test asserttrue htmlfilter prevent_fproxy_access genericreadfiltercallback magichttpescapestring asserttrue htmlfilter prevent_external_access_css_simple checked_http assertfalse htmlfilter prevent_external_access_css_escape asserttrue htmlfilter prevent_external_access_css_case checked_http assertequals whitelist_static_content htmlfilter whitelist_static_content private string html filter string data throws exception string type name text html uri baseuri new uri base uri byte data to filter data get bytes utf 8 return content filter filter new array bucket data to filter bf type name baseuri null data to string htmlfilter typename base_uri datatofilter getbytes contentfilter arraybucket datatofilter typename tostring creates k packets of size sz of random data encodes them and tries to decode index contains the permutation entry private static final void encode decode fec code encode fec code decode int index byte src new byte kk packet size util rand next bytes src buffer src bufs new buffer kk for int i 0 i src bufs length i src bufs i new buffer src i packet size packet size byte repair new byte kk packet size buffer repair bufs new buffer kk for int i 0 i repair bufs length i repair bufs i new buffer repair i packet size packet size encode encode src bufs repair bufs index decode decode repair bufs index for int i 0 i src length i assert assert equals src i repair i encodedecode feccode feccode packet_size nextbytes srcbufs srcbufs srcbufs packet_size packet_size packet_size repairbufs repairbufs repairbufs packet_size packet_size srcbufs repairbufs repairbufs assertequals public void test benchmark if benchmark return int lim fec math gf size 1 fec code maybe native fec code factory get default createfec code kk lim fec code pure code new pure code kk lim int index new int kk for int i 0 i kk i index i lim i 1 byte src new byte kk packet size util rand next bytes src buffer src bufs new buffer kk for int i 0 i src bufs length i src bufs i new buffer src i packet size packet size byte repair new byte kk packet size buffer repair bufs new buffer kk for int i 0 i repair bufs length i repair bufs i new buffer repair i packet size packet size int index backup new int index length system arraycopy index 0 index backup 0 index length system out println getting ready for benchmarking encode long t1 system current time millis maybe native encode src bufs repair bufs index long t2 system current time millis pure code encode src bufs repair bufs index backup long t3 system current time millis float d native encode t2 t1 float d pure encode t3 t2 buffer repair bufs2 repair bufs clone system arraycopy repair bufs 0 repair bufs2 0 repair bufs length system out println getting ready for benchmarking decode t1 system current time millis maybe native decode repair bufs index t2 system current time millis pure code decode repair bufs2 index backup t3 system current time millis float d native decode t2 t1 float d pure decode t3 t2 system out println maybe native system out println pure code system out println native code took d native encode ms whereas java s code took d pure encode ms to encode system out println native code took d native decode ms whereas java s code took d pure decode ms to decode testbenchmark fecmath gfsize feccode maybenative feccodefactory getdefault createfeccode feccode purecode purecode packet_size nextbytes srcbufs srcbufs srcbufs packet_size packet_size packet_size repairbufs repairbufs repairbufs packet_size packet_size indexbackup indexbackup currenttimemillis maybenative srcbufs repairbufs currenttimemillis purecode srcbufs repairbufs indexbackup currenttimemillis dnativeencode dpureencode repairbufs2 repairbufs repairbufs repairbufs2 repairbufs currenttimemillis maybenative repairbufs currenttimemillis purecode repairbufs2 indexbackup currenttimemillis dnativedecode dpuredecode maybenative purecode dnativeencode dpureencode dnativedecode dpuredecode public void test simple rev int lim fec math gf size 1 fec code code fec code factory get default createfec code kk lim fec code code2 new pure code kk lim int index new int kk for int i 0 i kk i index i lim i 1 encode decode code code2 index encode decode code2 code index testsimplerev fecmath gfsize feccode feccodefactory getdefault createfeccode feccode purecode encodedecode encodedecode public void test simple int lim fec math gf size 1 fec code code fec code factory get default createfec code kk lim fec code code2 new pure code kk lim int index new int kk for int i 0 i kk i index i kk i encode decode code code2 index encode decode code2 code index testsimple fecmath gfsize feccode feccodefactory getdefault createfeccode feccode purecode encodedecode encodedecode public void test shifted int lim fec math gf size 1 fec code code fec code factory get default createfec code kk lim fec code code2 new pure code kk lim int index new int kk int max i0 kk 2 if max i0 kk lim max i0 lim kk for int s max i0 2 s max i0 s for int i 0 i kk i index i i s encode decode code code2 index encode decode code2 code index testshifted fecmath gfsize feccode feccodefactory getdefault createfeccode feccode purecode max_i0 max_i0 max_i0 max_i0 max_i0 encodedecode encodedecode return returns the filename of the database this is the name of the current test function plus db4o public string get database filename return get name db4o getdatabasefilename getname you have to call super set up if you override this method override protected void set up throws exception super set up file database file new file get database filename if database file exists database file delete assert false database file exists m wot new wot get database filename setup setup setup databasefile getdatabasefilename databasefile databasefile assertfalse databasefile mwot getdatabasefilename you have to call super tear down if you override this method override protected void tear down throws exception super tear down m wot terminate new file get database filename delete teardown teardown teardown mwot getdatabasefilename does nothing just here because j unit will complain if there are no tests public void test self junit testself return returns the filename of the database this is the name of the current test function plus db4o public string get database filename return get name db4o getdatabasefilename getname you have to call super set up if you override this method protected void set up throws exception super set up file database file new file get database filename if database file exists database file delete assert false database file exists db db4o open file get database filename ext setup setup setup databasefile getdatabasefilename databasefile databasefile assertfalse databasefile openfile getdatabasefilename you have to call super tear down if you override this method protected void tear down throws exception super tear down db close db null new file get database filename delete teardown teardown teardown getdatabasefilename does nothing just here because j unit will complain if there are no tests public void test self junit testself public void set up throws exception mssk new freeneturi ssk s zmdq gtog7v1wn3bui lo mpucyd6v5krs yr vqf uf hosg s ls rq9q9 zlrmus9 keyk2pmhej4wbtw602 uwx0o0e w0 aqacaae freetalk message list 1 muuid uuid from string d5b0dcc4 91cb 4870 8ab9 8588e895fa5d m messageid muuid base64 encode mssk get routing key m otherssk new freeneturi ssk tqaux3 nm4eh9wxtbv xx6vshv23l lpkwt bh7pe40st2o ng5 ar 2ya6r5m16b q i3o dj do linv curyd ns1b9 ew aqacaae7 freetalk message list 1 m otheruuid uuid from string 6d01e2f0 dfdd 4be9 9e93 7a35c03f3f12 mmessageid withothersskbutsameuuid muuid base64 encode m otherssk get routing key mmessageid withotheruuidbutsamessk m otheruuid base64 encode mssk get routing key mksk new freeneturi ksk test mchk new freeneturi chk 7qms7 lkly ihbz88i0 u97lxrlks2ux nwzwq oj pd xn jw ila f sjww2mp wlz wx7 fgp zbb er yd lkqie1u srcn lbm aaia 8 m invaliduuid d5b0dcc491cb48708ab98588e895fa5d m invalid messageid m invaliduuid base64 encode mssk get routing key setup szmdqgtog7v1wn3builompucyd6v5krsyrvqfufhosg slsrq9q9zlrmus9keyk2pmhej4wbtw602uwx0o0e messagelist fromstring mmessageid getroutingkey motherssk tqaux3nm4eh9wxtbvxx6vshv23llpkwtbh7pe40st2o ng5ar i3odj dolinvcurydns1b9ew messagelist motheruuid fromstring mmessageid_withothersskbutsameuuid motherssk getroutingkey mmessageid_withotheruuidbutsamessk motheruuid getroutingkey 7qms7lklyihbz88i0 u97lxrlks2uxnwzwqojpdxnjw fsjww2mpwlzwx7fgpzbberydlkqie1usrcn minvaliduuid minvalidmessageid minvaliduuid getroutingkey public void tear down throws exception teardown public void test wot messageuri freeneturi string test construction of invalid ur is try new wot messageuri null m messageid fail construction of wot messageuri with null freeneturi is possible catch illegal argument exception e try new wot messageuri mssk null fail construction of wot messageuri with null message id is possible catch illegal argument exception e try new wot messageuri mssk mmessageid withothersskbutsameuuid fail construction of wot messageuri with a message id not belonging to the author s ssk is possible catch illegal argument exception e try new wot messageuri mchk m messageid fail construction of wot messageuri with invalid key type is possible catch illegal argument exception e try new wot messageuri mksk m messageid fail construction of wot messageuri with invalid key type is possible catch illegal argument exception e try new wot messageuri mssk m invalid messageid fail construction of wot messageuri with invalid uuid is possible catch illegal argument exception e test construction of valid ur is wot messageuri uri new wot messageuri mssk m messageid assert equals mssk uri get freeneturi assert equals m messageid uri get messageid the uri should always be stored as ssk even if constructed with usk uri new wot messageuri mssk usk forssk m messageid assert true uri get freeneturi isssk assert equals mssk uri get freeneturi testwotmessageurifreeneturistring uris wotmessageuri mmessageid wotmessageuri illegalargumentexception wotmessageuri wotmessageuri illegalargumentexception wotmessageuri mmessageid_withothersskbutsameuuid wotmessageuri illegalargumentexception wotmessageuri mmessageid wotmessageuri illegalargumentexception wotmessageuri mmessageid wotmessageuri illegalargumentexception wotmessageuri minvalidmessageid wotmessageuri illegalargumentexception uris wotmessageuri wotmessageuri mmessageid assertequals getfreeneturi assertequals mmessageid getmessageid wotmessageuri uskforssk mmessageid asserttrue getfreeneturi assertequals getfreeneturi public void test wot messageuri string throws malformedurl exception test construction of invalid ur is try new wot messageuri null fail construction of wot messageuri with null uri possible catch illegal argument exception e catch malformedurl exception e fail wrong exception thrown try new wot messageuri mssk toascii string fail construction of wot messageuri without message uuid possible catch malformedurl exception e try new wot messageuri mchk toascii string muuid fail construction of wot messageuri with invalid key type is possible catch malformedurl exception e try new wot messageuri mksk toascii string muuid fail construction of wot messageuri with invalid key type is possible catch malformedurl exception e try new wot messageuri mssk toascii string m invaliduuid fail construction of wot messageuri with invalid uuid is possible catch malformedurl exception e test construction of valid ur is wot messageuri uri new wot messageuri mssk toascii string muuid assert equals mssk uri get freeneturi assert equals m messageid uri get messageid the uri should always be stored as ssk even if constructed with usk uri new wot messageuri mssk usk forssk toascii string muuid assert true uri get freeneturi isssk assert equals mssk uri get freeneturi testwotmessageuristring malformedurlexception uris wotmessageuri wotmessageuri illegalargumentexception malformedurlexception wotmessageuri toasciistring wotmessageuri malformedurlexception wotmessageuri toasciistring wotmessageuri malformedurlexception wotmessageuri toasciistring wotmessageuri malformedurlexception wotmessageuri toasciistring minvaliduuid wotmessageuri malformedurlexception uris wotmessageuri wotmessageuri toasciistring assertequals getfreeneturi assertequals mmessageid getmessageid wotmessageuri uskforssk toasciistring asserttrue getfreeneturi assertequals getfreeneturi public void test get freeneturi throws malformedurl exception wot messageuri uri new wot messageuri mssk toascii string muuid assert equals mssk uri get freeneturi testgetfreeneturi malformedurlexception wotmessageuri wotmessageuri toasciistring assertequals getfreeneturi public void test get messageid throws malformedurl exception wot messageuri uri new wot messageuri mssk toascii string muuid assert equals m messageid uri get messageid testgetmessageid malformedurlexception wotmessageuri wotmessageuri toasciistring assertequals mmessageid getmessageid public void test equals wot messageuri uri1a new wot messageuri mssk m messageid wot messageuri uri1b new wot messageuri mssk m messageid wot messageuri uri2 new wot messageuri mssk mmessageid withotheruuidbutsamessk wot messageuri uri3 new wot messageuri m otherssk mmessageid withothersskbutsameuuid assert true uri1a equals uri1a assert true uri1a equals uri1b assert true uri1b equals uri1a assert false uri1a equals uri2 assert false uri2 equals uri1a assert false uri1a equals uri3 assert false uri3 equals uri1a testequals wotmessageuri wotmessageuri mmessageid wotmessageuri wotmessageuri mmessageid wotmessageuri wotmessageuri mmessageid_withotheruuidbutsamessk wotmessageuri wotmessageuri motherssk mmessageid_withothersskbutsameuuid asserttrue asserttrue asserttrue assertfalse assertfalse assertfalse assertfalse public void test to string wot messageuri uri new wot messageuri mssk m messageid assert equals mssk to string muuid uri to string testtostring wotmessageuri wotmessageuri mmessageid assertequals tostring tostring private float icentrey public sphere filter set edge action clamp set radius 100 0f spherefilter setedgeaction setradius set the index of refaction param refraction index the index of refaction see get refraction index public void set refraction index float refraction index this refraction index refraction index refractionindex getrefractionindex setrefractionindex refractionindex refractionindex refractionindex get the index of refaction return the index of refaction see set refraction index public float get refraction index return refraction index setrefractionindex getrefractionindex refractionindex set the radius of the effect param r the radius min value 0 see get radius public void set radius float r this a r this b r getradius setradius get the radius of the effect return the radius see set radius public float get radius return a setradius getradius set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex public float get centrex return centrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre override public buffered image filter buffered image src buffered image dst int width src get width int height src get height icentrex width centrex icentrey height centrey if a 0 a width 2 if b 0 b height 2 a2 a a b2 b b return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight override protected void transform inverse int x int y float out float dx x icentrex float dy y icentrey float x2 dx dx float y2 dy dy if y2 b2 b2 x2 a2 out 0 x out 1 y else float r refraction 1 0f refraction index float z float math sqrt 1 0f x2 a2 y2 b2 a b float z2 z z float x angle float math acos dx math sqrt x2 z2 float angle1 image math half pi x angle float angle2 float math asin math sin angle1 r refraction angle2 image math half pi x angle angle2 out 0 x float math tan angle2 z float y angle float math acos dy math sqrt y2 z2 angle1 image math half pi y angle angle2 float math asin math sin angle1 r refraction angle2 image math half pi y angle angle2 out 1 y float math tan angle2 z transforminverse rrefraction refractionindex xangle imagemath half_pi xangle rrefraction imagemath half_pi xangle yangle imagemath half_pi yangle rrefraction imagemath half_pi yangle override public string to string return distort sphere tostring public subscription request subscriptionrequest public subscription request http request http req set http req subscriptionrequest httprequest httpreq httpreq private void set service service service string event suburl service get event suburl thanks for giordano sassaroli sassarol cefriel it 05 21 03 seturi event suburl true string url base str device dev service get device if dev null url base str dev geturl base if url base str null url base str length 0 device root dev service get root device if root dev null url base str root dev geturl base thansk for markus thurner markus thurner fh hagenberg at 06 11 2004 if url base str null url base str length 0 device root dev service get root device if root dev null url base str root dev get location thanks for giordano sassaroli sassarol cefriel it 09 02 03 if url base str null url base str length 0 if http is absoluteurl event suburl url base str event suburl string req host http get host url base str int req port http get port url base str set host req host req port set request host req host set request port req port setservice eventsuburl geteventsuburl eventsuburl urlbasestr getdevice urlbasestr geturlbase urlbasestr urlbasestr rootdev getrootdevice rootdev urlbasestr rootdev geturlbase urlbasestr urlbasestr rootdev getrootdevice rootdev urlbasestr rootdev getlocation urlbasestr urlbasestr isabsoluteurl eventsuburl urlbasestr eventsuburl reqhost gethost urlbasestr reqport getport urlbasestr sethost reqhost reqport setrequesthost reqhost setrequestport reqport public void set subscribe request service service string callback long timeout set method subscription subscribe method set service service set callback callback setnt nt event set timeout timeout setsubscriberequest setmethod subscribe_method setservice setcallback settimeout public void set renew request service service string uuid long timeout set method subscription subscribe method set service service setsid uuid set timeout timeout setrenewrequest setmethod subscribe_method setservice settimeout public void set unsubscribe request service service set method subscription unsubscribe method set service service setsid service getsid setunsubscriberequest setmethod unsubscribe_method setservice public void setnt string value set header http nt value setheader public string getnt return get header value http nt getheadervalue public boolean hasnt string nt getnt return nt null 0 nt length true false private final static string callback end with public void set callback string value set string header http callback value callback start with callback end with callback_end_with setcallback setstringheader callback_start_with callback_end_with public string get callback return get string header value http callback callback start with callback end with getcallback getstringheadervalue callback_start_with callback_end_with public boolean has callback string callback get callback return callback null 0 callback length true false hascallback getcallback public void setsid string id set header http sid subscription tosid header string id setheader tosidheaderstring public string getsid thanks for grzegorz lehmann and stefano lenzi 12 06 04 string sid subscription getsid get header value http sid if sid null return return sid getheadervalue public boolean hassid string sid getsid return sid null 0 sid length true false public final void set timeout long value set header http timeout subscription to timeout header string value settimeout setheader totimeoutheaderstring public long get timeout return subscription get timeout get header value http timeout gettimeout gettimeout getheadervalue public void post subscription response sub res super post sub res subscriptionresponse subres subres public subscription response post http response http res post get request host get request port return new subscription response http res subscriptionresponse httpresponse httpres getrequesthost getrequestport subscriptionresponse httpres public class compress database this utility accepts one argument path to database file it creates new file at the same location and with the same name but with with dbz extension public static void main string args throws io exception if args length 0 args length 2 system err println usage java plugins xml spider org garret perst compress database database file path compression level return string path args 0 file input stream in new file input stream path int ext path last index of string zip path substring 0 ext dbz file output stream out new file output stream zip byte segment new byte compressed file segment length zip output stream zout new zip output stream out if args length 2 zout set level integer parse int args 1 long pos 0 int rc 1 do int offs 0 while offs segment length rc in read segment offs segment length offs 0 offs rc if offs 0 string name 000000000000 pos zip entry entry new zip entry name substring name length 12 entry set size offs zout put next entry entry zout write segment 0 offs zout close entry pos offs while rc 0 zout finish zout close system out println file zip is written compressdatabase ioexception xmlspider compressdatabase database_file_path fileinputstream fileinputstream lastindexof fileoutputstream fileoutputstream compressedfile segment_length zipoutputstream zipoutputstream setlevel parseint zipentry zipentry setsize putnextentry closeentry bootstrapping decaying running average avg public decaying keyspace average double default value int max reports simple field set fs avg new bootstrapping decaying running average default value 2 0 2 0 max reports fs bootstrappingdecayingrunningaverage decayingkeyspaceaverage defaultvalue maxreports simplefieldset bootstrappingdecayingrunningaverage defaultvalue maxreports public decaying keyspace average bootstrapping decaying running average a check the max min values ignore them avg bootstrapping decaying running average a clone decayingkeyspaceaverage bootstrappingdecayingrunningaverage bootstrappingdecayingrunningaverage override public synchronized object clone return new decaying keyspace average avg decayingkeyspaceaverage public synchronized double current value return avg current value currentvalue currentvalue public synchronized void report double d if d 0 0 d 1 0 just because we use non normalized locations doesn t mean we can accept them throw new illegal argument exception not a valid normalized key d double super value avg current value double this value location normalize super value double diff location change this value d double to average super value diff to gracefully wrap around the 1 0 0 0 threshold we average over or under it and simply normalize the result when reporting a current value example d 0 2 being reported super value 1 9 already wrapped once but at 0 9 this value 0 9 the normalized value of where we are in the keyspace diff 0 3 the diff from the normalized values location change 0 9 0 2 avg report 2 2 to successfully move the average towards the closest route to the given value avg report to average double new value avg current value if new value 0 0 new value 1 0 avg set current value location normalize new value illegalargumentexception supervalue currentvalue thisvalue supervalue thisvalue toaverage supervalue currentvalue supervalue thisvalue toaverage newvalue currentvalue newvalue newvalue setcurrentvalue newvalue public synchronized double value if reported double d if d 0 0 d 1 0 throw new illegal argument exception not a valid normalized key d double super value avg current value double this value location normalize super value double diff location change this value d return location normalize avg value if reported super value diff valueifreported illegalargumentexception supervalue currentvalue thisvalue supervalue thisvalue valueifreported supervalue public synchronized long count reports return avg count reports countreports countreports public void report long d throw new illegal argument exception keyspace average does not like longs illegalargumentexception keyspaceaverage public synchronized void change max reports int max reports avg change max reports max reports changemaxreports maxreports changemaxreports maxreports public synchronized simple field set export field set boolean short lived return avg export field set short lived simplefieldset exportfieldset shortlived exportfieldset shortlived todo make this a junit test public static void main string args decaying keyspace average a new decaying keyspace average 0 9 10 null a report 0 9 for int i 10 i 0 i a report 0 2 system out println 0 2 current a current value for int i 10 i 0 i a report 0 8 system out println 0 8 current a current value system out println positive wrap test for int wrap 3 wrap 0 wrap system out println wrap test wrap for int i 10 i 0 i a report 0 25 system out println 0 25 current a current value for int i 10 i 0 i a report 0 5 system out println 0 5 current a current value for int i 10 i 0 i a report 0 75 system out println 0 75 current a current value for int i 10 i 0 i a report 1 0 system out println 1 0 current a current value system out println negative wrap test a new decaying keyspace average 0 2 10 null a report 0 2 for int wrap 3 wrap 0 wrap system out println negwrap test wrap for int i 10 i 0 i a report 0 75 system out println 0 75 current a current value for int i 10 i 0 i a report 0 5 system out println 0 5 current a current value for int i 10 i 0 i a report 0 25 system out println 0 25 current a current value for int i 10 i 0 i a report 1 0 system out println 1 0 current a current value decayingkeyspaceaverage decayingkeyspaceaverage currentvalue currentvalue currentvalue currentvalue currentvalue currentvalue decayingkeyspaceaverage currentvalue currentvalue currentvalue currentvalue public class reference signature verification exception extends exception private static final long serial versionuid 1 public reference signature verification exception exception e super e referencesignatureverificationexception serialversionuid referencesignatureverificationexception public reference signature verification exception super referencesignatureverificationexception public reference signature verification exception string string super string referencesignatureverificationexception list page pages page status long count list page pages this count count this pages pages pagestatus main page xml spider xml spider this xml spider xml spider page maker xml spider get page maker pr xml spider get plugin respirator mainpage xmlspider xmlspider xmlspider xmlspider pagemaker xmlspider getpagemaker xmlspider getpluginrespirator public void process post request http request request html node content node create index if request is part set create index synchronized this xml spider schedule make index html node infobox page maker get infobox infobox infobox success scheduled creating index infobox add child index will start create soon content node add child infobox queue uri string adduri request get part as string adduri 512 if adduri null adduri length 0 try freeneturi uri new freeneturi adduri xml spider queueuri uri manually true html node infobox page maker get infobox infobox infobox success uri added infobox add child added uri content node add child infobox catch exception e html node infobox page maker get infobox infobox infobox error error adding uri infobox add child e get message content node add child infobox logger normal this manual added uri cause exception e xml spider start some requests processpostrequest httprequest htmlnode contentnode ispartset createindex xmlspider schedulemakeindex htmlnode pagemaker getinfobox addchild contentnode addchild getpartasstring xmlspider htmlnode pagemaker getinfobox addchild contentnode addchild htmlnode pagemaker getinfobox addchild getmessage contentnode addchild xmlspider startsomerequests public void write content http request request html node content node html node overview table content node add child table class column html node overview table row overview table add child tr page status queued status get page status status queued page status succeeded status get page status status succeeded page status failed status get page status status failed list page running fetch xml spider get running fetch config config xml spider get config column 1 html node next table cell overview table row add child td class first html node status box page maker get infobox spider status html node status content page maker get content node status box status content add child running request running fetch size config get max parallel requests status content add child br status content add child queued queued status count status content add child br status content add child succeeded succeeded status count status content add child br status content add child failed failed status count status content add child br status content add child br status content add child queued event xml spider callback executor get queue size status content add child br status content add child index writer synchronized this if xml spider is writing index status content add child span style color red font weight bold running else if xml spider is write index scheduled status content add child span style color blue font weight bold scheduled else status content add child span style color green font weight bold idle status content add child br status content add child last written xml spider get index writer t produced index 0 never new date xml spider get index writer t produced index to string next table cell add child status box column 2 next table cell overview table row add child td class second html node main box page maker get infobox main html node main content page maker get content node main box html node add form pr add form child main content plugins xml spider xml spider add form add form add child label for adduri add uri add form add child input new string name style new string adduri width 20em add form add child input type submit next table cell add child main box html node index box page maker get infobox create index html node index content page maker get content node index box html node index form pr add form child index content plugins xml spider xml spider index form index form add child input new string name type value new string create index hidden create index index form add child input new string type value new string submit create index now next table cell add child index box html node running box page maker get infobox running uri running box add attribute style right 0 html node running content page maker get content node running box if running fetch is empty running content add child no uri else html node list running content add child ol style overflow auto white space nowrap iterator page pi running fetch iterator int maxuri config get max shownur is for int i 0 i maxuri pi has next i page page pi next html node litem list add child li title page get comment litem add child a href freenet page geturi page geturi content node add child running box html node queued box page maker get infobox queued uri queued box add attribute style right 0 overflow auto html node queued content page maker get content node queued box list pages queued status queued content content node add child queued box html node succeeded box page maker get infobox succeeded uri succeeded box add attribute style right 0 html node succeeded content page maker get content node succeeded box list pages succeeded status succeeded content content node add child succeeded box html node failed box page maker get infobox failed uri failed box add attribute style right 0 html node failed content page maker get content node failed box list pages failed status failed content content node add child failed box writecontent httprequest htmlnode contentnode htmlnode overviewtable contentnode addchild htmlnode overviewtablerow overviewtable addchild pagestatus queuedstatus getpagestatus pagestatus succeededstatus getpagestatus pagestatus failedstatus getpagestatus runningfetch xmlspider getrunningfetch xmlspider getconfig htmlnode nexttablecell overviewtablerow addchild htmlnode statusbox pagemaker getinfobox htmlnode statuscontent pagemaker getcontentnode statusbox statuscontent addchild runningfetch getmaxparallelrequests statuscontent addchild statuscontent addchild queuedstatus statuscontent addchild statuscontent addchild succeededstatus statuscontent addchild statuscontent addchild failedstatus statuscontent addchild statuscontent addchild statuscontent addchild xmlspider callbackexecutor getqueue statuscontent addchild statuscontent addchild xmlspider iswritingindex statuscontent addchild xmlspider iswriteindexscheduled statuscontent addchild statuscontent addchild statuscontent addchild statuscontent addchild xmlspider getindexwriter tproducedindex xmlspider getindexwriter tproducedindex tostring nexttablecell addchild statusbox nexttablecell overviewtablerow addchild htmlnode mainbox pagemaker getinfobox htmlnode maincontent pagemaker getcontentnode mainbox htmlnode addform addformchild maincontent xmlspider xmlspider addform addform addchild addform addchild addform addchild nexttablecell addchild mainbox htmlnode indexbox pagemaker getinfobox htmlnode indexcontent pagemaker getcontentnode indexbox htmlnode indexform addformchild indexcontent xmlspider xmlspider indexform indexform addchild createindex createindex indexform addchild nexttablecell addchild indexbox htmlnode runningbox pagemaker getinfobox runningbox addattribute htmlnode runningcontent pagemaker getcontentnode runningbox runningfetch isempty runningcontent addchild htmlnode runningcontent addchild runningfetch getmaxshownuris hasnext htmlnode addchild getcomment addchild contentnode addchild runningbox htmlnode queuedbox pagemaker getinfobox queuedbox addattribute htmlnode queuedcontent pagemaker getcontentnode queuedbox listpages queuedstatus queuedcontent contentnode addchild queuedbox htmlnode succeededbox pagemaker getinfobox succeededbox addattribute htmlnode succeededcontent pagemaker getcontentnode succeededbox listpages succeededstatus succeededcontent contentnode addchild succeededbox htmlnode failedbox pagemaker getinfobox failedbox addattribute htmlnode failedcontent pagemaker getcontentnode failedbox listpages failedstatus failedcontent contentnode addchild failedbox utilities private page status get page status status status perst root root xml spider get root synchronized root int count root get page count status iterator page it root get pages status int showuri xml spider get config get max shownur is list page page new array list while page size showuri it has next page add it next return new page status count page pagestatus getpagestatus perstroot xmlspider getroot getpagecount getpages xmlspider getconfig getmaxshownuris arraylist hasnext pagestatus private void list pages page status page status html node parent if page status pages is empty parent add child no uri else html node list parent add child ol style overflow auto white space nowrap for page page page status pages html node litem list add child li title page get comment litem add child a href freenet page geturi page geturi listpages pagestatus pagestatus htmlnode pagestatus isempty addchild htmlnode addchild pagestatus htmlnode addchild getcomment addchild private boolean settimeout false private message filter timeoutfromwait true _settimeout messagefilter _timeoutfromwait public static message filter create return new message filter messagefilter messagefilter void on start waiting boolean wait for synchronized this we cannot wait on a message filter with a callback because on matched calls clear matched if we have a callback the solution would be to set a flag indicating we are wait for ing a filter here on matching a message set message call the callback immediately if not wait for ing if we are wait for ing call the callback when we exit wait for on stop waiting if wait for callback null throw new illegal state exception cannot wait on a message filter with a callback if settimeout logger error this no timeout set on filter this new exception error if initialtimeout 0 timeoutfromwait timeout system current time millis initialtimeout if or null or on start waiting wait for onstartwaiting waitfor messagefilter onmatched clearmatched waitfor setmessage waitfor waitfor waitfor onstopwaiting waitfor _callback illegalstateexception messagefilter _settimeout _initialtimeout _timeoutfromwait _timeout currenttimemillis _initialtimeout _or _or onstartwaiting waitfor set whether the timeout is relative to the creation of the filter or the start of wait for param b if true the timeout is relative to the time at which set timeout was called if false it s relative to the start of wait for public message filter set timeout relative to creation boolean b timeoutfromwait b return this waitfor settimeout waitfor messagefilter settimeoutrelativetocreation _timeoutfromwait this filter will expire after the specificed amount of time note also that where two or more filters match the same message the one with the nearer expiry time will get priority param timeout the time before this filter expires in ms return this message filter public message filter set timeout int timeout settimeout true initialtimeout timeout timeout system current time millis timeout return this messagefilter settimeout _settimeout _initialtimeout _timeout currenttimemillis public message filter set no timeout settimeout true timeout long max value initialtimeout 0 return this messagefilter setnotimeout _settimeout _timeout max_value _initialtimeout public message filter set type message type type type type return this messagefilter settype messagetype _type public message filter set source peer context source source source if source null oldbootid source get bootid return this messagefilter setsource peercontext _source _oldbootid getbootid returns the source that this filter or chain matches public peer context get source return source peercontext getsource _source public message filter set field string field name boolean value return set field field name boolean value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name byte value return set field field name byte value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name short value return set field field name short value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name int value return set field field name integer value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name long value return set field field name long value of value messagefilter setfield fieldname setfield fieldname valueof public message filter set field string field name object field value if type null type check type field name field value throw new incorrect type exception got field value get class expected type type of field name for type get name synchronized fields if fields put field name field value null fieldlist add field name return this messagefilter setfield fieldname fieldvalue _type _type checktype fieldname fieldvalue incorrecttypeexception fieldvalue getclass _type typeof fieldname _type getname _fields _fields fieldname fieldvalue _fieldlist fieldname public message filter or message filter or if or null or null or or fixme maybe throw this is almost certainly a bug and a nasty one too logger error this or replacement or or new exception error or or return this messagefilter messagefilter _or _or _or _or public message filter set async callback async message filter callback cb callback cb return this messagefilter setasynccallback asyncmessagefiltercallback _callback public boolean match message m if or null or match m return true if type null type equals m get spec return false if source null source equals m get source return false synchronized fields for string field name fieldlist if m is set field name return false if fields get field name equals m get from payload field name return false if really timed out system current time millis return false return true _or _or _type _type getspec _source _source getsource _fields fieldname _fieldlist isset fieldname _fields fieldname getfrompayload fieldname reallytimedout currenttimemillis public boolean matched return matched _matched which connection dropped or was restarted public peer context dropped connection return droppedconnection peercontext droppedconnection _droppedconnection boolean really timed out long time if callback null callback should timeout timeout 1 timeout immediately return timeout time reallytimedout _callback _callback shouldtimeout _timeout _timeout param time the current time in milliseconds return true if the filter has timed out or if it has been matched already caller will remove the filter from filters if we return true boolean timed out long time if matched logger error this impossible filter already matched in timed out this new exception error return true remove it return really timed out time _filters timedout _matched timedout reallytimedout public message get message return message getmessage _message public synchronized void set message message message logger debug this set message message on this new exception debug message message matched message null notify all setmessage setmessage _message _matched _message notifyall public int get initial timeout return initialtimeout getinitialtimeout _initialtimeout public long get timeout return timeout gettimeout _timeout override public string to string return super to string type get name tostring tostring _type getname public void clear matched if the filter matched in an or and it is re used then we need to clear all the or s message filter or synchronized this matched false message null or or if or null or clear matched clearmatched _or _or messagefilter _matched _message _or clearmatched public void clear or or null clearor _or public boolean matches dropped connection peer context ctx if source ctx return true if or null return or matches dropped connection ctx return false matchesdroppedconnection peercontext _source _or _or matchesdroppedconnection public boolean matches restarted connection peer context ctx if source ctx return true if or null return or matches restarted connection ctx return false matchesrestartedconnection peercontext _source _or _or matchesrestartedconnection notify because of a dropped connection caller must verify matchesdroppedconnection and source param ctx public void on dropped connection peer context ctx synchronized this droppedconnection ctx notify all if callback null callback on disconnect ctx _matchesdroppedconnection _source ondroppedconnection peercontext _droppedconnection notifyall _callback _callback ondisconnect notify because of a restarted connection caller must verify matchesdroppedconnection and source param ctx public void on restarted connection peer context ctx synchronized this droppedconnection ctx notify all if callback null callback on restarted ctx _matchesdroppedconnection _source onrestartedconnection peercontext _droppedconnection notifyall _callback _callback onrestarted notify waiters that we have been matched hopefully no locks will be held at this point by the caller public void on matched message msg async message filter callback cb synchronized this msg message cb callback clear matched before calling callback in case we are re added if callback null clear matched if cb null cb on matched msg onmatched asyncmessagefiltercallback _message _callback _callback clearmatched onmatched notify waiters that we have timed out public void on timed out synchronized this notify all if callback null callback on timeout ontimedout notifyall _callback _callback ontimeout returns true if a connection related to this filter has been dropped or restarted public boolean any connections dropped if matched return false if source null if source is connected return true else if source get bootid oldbootid return true counts as a disconnect if or null return or any connections dropped return false anyconnectionsdropped _matched _source _source isconnected _source getbootid _oldbootid _or _or anyconnectionsdropped public bucket read filter bucket bucket bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception if logger should log logger debug this logger debug this running this on bucket charset input stream strm bucket get input stream bucket temp bf make bucket 1 output stream os temp get output stream reader r null writer w null input stream reader isr null output stream writer osw null try try isr new input stream reader strm charset osw new output stream writer os charset r new buffered reader isr 32768 w new buffered writer osw 32768 catch unsupported encoding exception e closer close osw closer close os throw unknown charset exception create e charset css parser parser new css parser r w false cb parser parse r close finally do not close output related things here closer close strm closer close isr closer close r closer close w return temp readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception shouldlog inputstream getinputstream makebucket outputstream getoutputstream inputstreamreader outputstreamwriter inputstreamreader outputstreamwriter bufferedreader bufferedwriter unsupportedencodingexception unknowncharsetexception cssparser cssparser public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception throw new unsupported operation exception writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception unsupportedoperationexception public string get charset bucket bucket string parse charset throws data filter exception io exception input stream strm bucket get input stream writer w new null writer reader r r new buffered reader new input stream reader strm parse charset 32768 css parser parser new css parser r w false new null filter callback try parser parse catch throwable t ignore all errors if logger should log logger minor this logger minor this caught t trying to detect mime type with parse charset r close return parser detected charset getcharset parsecharset datafilterexception ioexception inputstream getinputstream nullwriter bufferedreader inputstreamreader parsecharset cssparser cssparser nullfiltercallback shouldlog parsecharset detectedcharset public class virgin item exception extends runtime exception private static final long serial versionuid 1 virgin item exception doubly linked list item item super item to string virginitemexception runtimeexception serialversionuid virginitemexception doublylinkedlist tostring public wot message list inserter node my node high level simple client my client string my name wot identity manager my identity manager wot message manager my message manager super my node my client my name my identity manager my message manager m message manager my message manager m random m node fast weak random start wotmessagelistinserter mynode highlevelsimpleclient myclient myname wotidentitymanager myidentitymanager wotmessagemanager mymessagemanager mynode myclient myname myidentitymanager mymessagemanager mmessagemanager mymessagemanager mrandom mnode fastweakrandom override protected void clear being inserted flags wot message manager message manager wot message manager super m message manager synchronized message manager for wot own message list list message manager get being inserted own message lists list cancel insert clearbeinginsertedflags wotmessagemanager messagemanager wotmessagemanager mmessagemanager messagemanager wotownmessagelist messagemanager getbeinginsertedownmessagelists cancelinsert override protected collection client getter create fetch storage return null clientgetter createfetchstorage override protected collection base client putter create insert storage return new hash set base client putter max parallel messagelist insert count 2 baseclientputter createinsertstorage hashset baseclientputter max_parallel_messagelist_insert_count override public int get priority return native thread norm priority getpriority nativethread norm_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period override protected synchronized void iterate abort all transfers synchronized m message manager for wot own message list list m message manager get not inserted own message lists try fixme ensure that after creation of a message list we wait for at least a few minutes so that if the author writes more messages they will be put in the same list insert message list list catch exception e logger error this insert of wot own message list failed e abortalltransfers mmessagemanager wotownmessagelist mmessagemanager getnotinsertedownmessagelists insertmessagelist wotownmessagelist you have to synchronize on this code wot message list inserter code when using this function private void insert message list wot own message list list throws transformer exception parser configuration exception no such message exception io exception insert exception bucket tempb mtbf make bucket 4096 todo set to a reasonable value output stream os null try os tempb get output stream list begin of insert wot message listxml encode m message manager list os os close os null tempb set read only we do not specifiy a client meta data with mimetype because that would result in the insertion of an additional chk insert block ib new insert block tempb null list get inserturi insert context ictx m client get insert context true client putter pu m client insert ib false null false ictx this pu set priority class request starter update priority class pluginmanager defaults to interactive priority add insert pu tempb null logger debug this started insert of wot own message list at request uri list geturi finally if tempb null tempb free closer close os wotmessagelistinserter insertmessagelist wotownmessagelist transformerexception parserconfigurationexception nosuchmessageexception ioexception insertexception makebucket outputstream getoutputstream beginofinsert wotmessagelistxml mmessagemanager setreadonly clientmetadata insertblock insertblock getinserturi insertcontext mclient getinsertcontext clientputter mclient setpriorityclass requeststarter update_priority_class addinsert wotownmessagelist override public synchronized void on success base client putter state object container container try logger debug this successfully inserted wot own message list at state geturi wot own message list list wot own message list m message manager get own message list message list getid fromuri state geturi list mark as inserted catch exception e logger error this wot own message list insert succeeded but on success failed e finally remove insert state onsuccess baseclientputter objectcontainer wotownmessagelist wotownmessagelist wotownmessagelist mmessagemanager getownmessagelist messagelist getidfromuri markasinserted wotownmessagelist onsuccess removeinsert override public synchronized void on failure insert exception e base client putter state object container container try if e get mode insert exception collision logger error this wot own message list insert collided trying to insert with higher index try wot own message list list wot own message list m message manager get own message list message list getid fromuri state geturi list increment insert index insert message list list catch exception ex logger error this inserting wot own message list with higher index failed ex else throw e catch exception ex logger error this wot own message list insert failed ex finally remove insert state onfailure insertexception baseclientputter objectcontainer getmode insertexception wotownmessagelist wotownmessagelist wotownmessagelist mmessagemanager getownmessagelist messagelist getidfromuri incrementinsertindex insertmessagelist wotownmessagelist wotownmessagelist removeinsert not needed functions override public void on success fetch result result client getter state object container container onsuccess fetchresult clientgetter objectcontainer public void on success fetch result result client getter state object container container override public void on failure fetch exception e client getter state object container container onsuccess fetchresult clientgetter objectcontainer onfailure fetchexception clientgetter objectcontainer public void on failure fetch exception e client getter state object container container override public void on generateduri freeneturi uri base client putter state object container container onfailure fetchexception clientgetter objectcontainer ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container override public void on fetchable base client putter state object container container ongenerateduri baseclientputter objectcontainer onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container override public void on major progress object container container onfetchable baseclientputter objectcontainer onmajorprogress objectcontainer static final int max items key space 4 static int getn items page pg return bytes unpack2 pg data 0 maxitems keyspace getnitems return bytes unpack2 pg data 0 static int get size page pg return bytes unpack2 pg data 2 getsize return bytes unpack2 pg data 2 static int get key str oid page pg int index return bytes unpack4 pg data first key offs index 8 getkeystroid firstkeyoffs return bytes unpack4 pg data first key offs index 8 static int get key str size page pg int index return bytes unpack2 pg data first key offs index 8 4 firstkeyoffs getkeystrsize firstkeyoffs return bytes unpack2 pg data first key offs index 8 4 static int get key str offs page pg int index return bytes unpack2 pg data first key offs index 8 6 firstkeyoffs getkeystroffs firstkeyoffs static int get reference page pg int index return bytes unpack4 pg data first key offs index 4 getreference firstkeyoffs static void setn items page pg int n items bytes pack2 pg data 0 short n items setnitems nitems nitems bytes pack2 pg data 0 short n items static void set size page pg int size bytes pack2 pg data 2 short size nitems setsize bytes pack2 pg data 2 short size static void set key str oid page pg int index int oid bytes pack4 pg data first key offs index 8 oid setkeystroid firstkeyoffs bytes pack4 pg data first key offs index 8 oid static void set key str size page pg int index int size bytes pack2 pg data first key offs index 8 4 short size firstkeyoffs setkeystrsize firstkeyoffs bytes pack2 pg data first key offs index 8 4 short size static void set key str offs page pg int index int offs bytes pack2 pg data first key offs index 8 6 short offs firstkeyoffs setkeystroffs firstkeyoffs static void set key str chars page pg int offs char str int len str length for int i 0 i len i bytes pack2 pg data first key offs offs short str i offs 2 setkeystrchars firstkeyoffs static void set key bytes page pg int offs byte bytes system arraycopy bytes 0 pg data first key offs offs bytes length setkeybytes firstkeyoffs system arraycopy bytes 0 pg data first key offs offs bytes length static void set reference page pg int index int oid bytes pack4 pg data first key offs index 4 oid firstkeyoffs setreference firstkeyoffs final static int compare key key page pg int i long i8 int i4 float r4 double r8 switch key type case class descriptor tp boolean case class descriptor tp byte return byte key ival pg data btree page first key offs i case class descriptor tp short return short key ival bytes unpack2 pg data btree page first key offs i 2 case class descriptor tp char return char key ival char bytes unpack2 pg data btree page first key offs i 2 case class descriptor tp object case class descriptor tp int case class descriptor tp enum i4 bytes unpack4 pg data btree page first key offs i 4 return key ival i4 1 key ival i4 0 1 case class descriptor tp long case class descriptor tp date i8 bytes unpack8 pg data btree page first key offs i 8 return key lval i8 1 key lval i8 0 1 case class descriptor tp float r4 float int bits to float bytes unpack4 pg data btree page first key offs i 4 return key dval r4 1 key dval r4 0 1 case class descriptor tp double r8 double long bits to double bytes unpack8 pg data btree page first key offs i 8 return key dval r8 1 key dval r8 0 1 assert failed invalid type return 0 classdescriptor tpboolean classdescriptor tpbyte btreepage firstkeyoffs classdescriptor tpshort btreepage firstkeyoffs classdescriptor tpchar btreepage firstkeyoffs classdescriptor tpobject classdescriptor tpint classdescriptor tpenum btreepage firstkeyoffs classdescriptor tplong classdescriptor tpdate btreepage firstkeyoffs classdescriptor tpfloat intbitstofloat btreepage firstkeyoffs classdescriptor tpdouble longbitstodouble btreepage firstkeyoffs final static int compare str key key page pg int i char chars char key oval int alen chars length int blen btree page get key str size pg i int minlen alen blen alen blen int offs btree page get key str offs pg i btree page first key offs byte b pg data for int j 0 j minlen j int diff chars j char bytes unpack2 b offs if diff 0 return diff offs 2 return alen blen comparestr btreepage getkeystrsize btreepage getkeystroffs btreepage firstkeyoffs final static int compare prefix char key page pg int i int alen key length int blen btree page get key str size pg i int minlen alen blen alen blen int offs btree page get key str offs pg i btree page first key offs byte b pg data for int j 0 j minlen j int diff key j char bytes unpack2 b offs if diff 0 return diff offs 2 return minlen blen compareprefix btreepage getkeystrsize btreepage getkeystroffs btreepage firstkeyoffs static boolean find storage impl db int page id key first key key last key btree tree int height array list result page pg db get page page id int l 0 n getn items pg r n int oid height 1 try if tree type class descriptor tp string if first key null while l r int i l r 1 if compare str first key pg i first key inclusion l i 1 else r i assert that r l if last key null if height 0 while l n if compare str last key pg l last key inclusion return false oid get key str oid pg l result add db lookup object oid null l 1 else do if find db get key str oid pg l first key last key tree height result return false if l n return true while compare str last key pg l 0 return false else if height 0 while l n oid get key str oid pg l result add db lookup object oid null l 1 else do if find db get key str oid pg l first key last key tree height result return false while l n else if tree type class descriptor tp array of byte if first key null while l r int i l r 1 if tree compare byte arrays first key pg i first key inclusion l i 1 else r i assert that r l if last key null if height 0 while l n if tree compare byte arrays last key pg l last key inclusion return false oid get key str oid pg l result add db lookup object oid null l 1 else do if find db get key str oid pg l first key last key tree height result return false if l n return true while tree compare byte arrays last key pg l 0 return false else if height 0 while l n oid get key str oid pg l result add db lookup object oid null l 1 else do if find db get key str oid pg l first key last key tree height result return false while l n else if first key null while l r int i l r 1 if compare first key pg i first key inclusion l i 1 else r i assert that r l if last key null if height 0 while l n if compare last key pg l last key inclusion return false oid get reference pg max items 1 l result add db lookup object oid null l 1 return true else do if find db get reference pg max items 1 l first key last key tree height result return false if l n return true while compare last key pg l 0 return false if height 0 while l n oid get reference pg max items 1 l result add db lookup object oid null l 1 else do if find db get reference pg max items 1 l first key last key tree height result return false while l n finally db pool unfix pg return true storageimpl pageid firstkey lastkey arraylist getpage pageid getnitems classdescriptor tpstring firstkey comparestr firstkey firstkey lastkey comparestr lastkey lastkey getkeystroid lookupobject getkeystroid firstkey lastkey comparestr lastkey getkeystroid lookupobject getkeystroid firstkey lastkey classdescriptor tparrayofbyte firstkey comparebytearrays firstkey firstkey lastkey comparebytearrays lastkey lastkey getkeystroid lookupobject getkeystroid firstkey lastkey comparebytearrays lastkey getkeystroid lookupobject getkeystroid firstkey lastkey firstkey firstkey firstkey lastkey lastkey lastkey getreference maxitems lookupobject getreference maxitems firstkey lastkey lastkey getreference maxitems lookupobject getreference maxitems firstkey lastkey static boolean prefix search storage impl db int page id char key int height array list result page pg db get page page id int l 0 n getn items pg r n int oid height 1 try while l r int i l r 1 if compare prefix key pg i 0 l i 1 else r i assert that r l if height 0 while l n if compare prefix key pg l 0 return false oid get key str oid pg l result add db lookup object oid null l 1 else do if prefix search db get key str oid pg l key height result return false if l n return true while compare prefix key pg l 0 return false finally db pool unfix pg return true prefixsearch storageimpl pageid arraylist getpage pageid getnitems compareprefix compareprefix getkeystroid lookupobject prefixsearch getkeystroid compareprefix static int allocate storage impl db int root int type btree key ins int page id db allocate page page pg db put page page id setn items pg 1 if type class descriptor tp string char sval char ins key oval int len sval length set size pg len 2 set key str offs pg 0 key space len 2 set key str size pg 0 len set key str oid pg 0 ins oid set key str oid pg 1 root set key str chars pg key space len 2 sval else if type class descriptor tp array of byte byte bval byte ins key oval int len bval length set size pg len set key str offs pg 0 key space len set key str size pg 0 len set key str oid pg 0 ins oid set key str oid pg 1 root set key bytes pg key space len bval else ins pack pg 0 set reference pg max items 2 root db pool unfix pg return page id storageimpl btreekey pageid allocatepage putpage pageid setnitems classdescriptor tpstring setsize setkeystroffs keyspace setkeystrsize setkeystroid setkeystroid setkeystrchars keyspace classdescriptor tparrayofbyte setsize setkeystroffs keyspace setkeystrsize setkeystroid setkeystroid setkeybytes keyspace setreference maxitems pageid static void memcpy page dst pg int dst idx page src pg int src idx int len int item size system arraycopy src pg data first key offs src idx item size dst pg data first key offs dst idx item size len item size dst_pg dst_idx src_pg src_idx itemsize src_pg firstkeyoffs src_idx itemsize dst_pg firstkeyoffs dst_idx itemsize itemsize static int insert storage impl db int page id btree tree btree key ins int height boolean unique boolean overwrite page pg db get page page id int result int l 0 n getn items pg r n int ahead unique 1 0 try if tree type class descriptor tp string while l r int i l r 1 if compare str ins key pg i ahead l i 1 else r i assert that l r if height 0 result insert db get key str oid pg r tree ins height unique overwrite assert that result btree op not found if result btree op overflow return result else if r n compare str ins key pg r 0 if overwrite db pool unfix pg pg null pg db put page page id ins old oid get key str oid pg r set key str oid pg r ins oid return btree op overwrite else if unique return btree op duplicate db pool unfix pg pg null pg db put page page id return insert str key db pg r ins height else if tree type class descriptor tp array of byte while l r int i l r 1 if tree compare byte arrays ins key pg i ahead l i 1 else r i assert that l r if height 0 result insert db get key str oid pg r tree ins height unique overwrite assert that result btree op not found if result btree op overflow return result else if r n tree compare byte arrays ins key pg r 0 if overwrite db pool unfix pg pg null pg db put page page id ins old oid get key str oid pg r set key str oid pg r ins oid return btree op overwrite else if unique return btree op duplicate db pool unfix pg pg null pg db put page page id return insert byte array key db pg r ins height else while l r int i l r 1 if compare ins key pg i ahead l i 1 else r i assert that l r insert before e r if height 0 result insert db get reference pg max items r 1 tree ins height unique overwrite assert that result btree op not found if result btree op overflow return result n 1 else if r n compare ins key pg r 0 if overwrite db pool unfix pg pg null pg db put page page id ins old oid get reference pg max items r 1 set reference pg max items r 1 ins oid return btree op overwrite else if unique return btree op duplicate db pool unfix pg pg null pg db put page page id int item size class descriptor sizeof tree type int max key space 4 item size if n max memcpy pg r 1 pg r n r item size memcpy pg max items n 1 pg max items n n r 4 ins pack pg r setn items pg getn items pg 1 return btree op done else page is full then divide page page id db allocate page page b db put page page id assert that n max int m max 2 if r m memcpy b 0 pg 0 r item size memcpy b r 1 pg r m r 1 item size memcpy pg 0 pg m 1 max m 1 item size memcpy b max items r pg max items r r 4 ins pack b r memcpy b max items m pg max items m 1 m r 1 4 memcpy pg max items max m 1 pg max items max max m 1 4 else memcpy b 0 pg 0 m item size memcpy pg 0 pg m r m item size memcpy pg r m 1 pg r max r item size memcpy b max items m pg max items m m 4 memcpy pg max items r m pg max items r r m 4 ins pack pg r m memcpy pg max items max m 1 pg max items max max r 4 ins oid page id ins extract b first key offs m 1 item size tree type if height 0 setn items pg max m 1 setn items b m else setn items pg max m setn items b m 1 db pool unfix b return btree op overflow finally if pg null db pool unfix pg storageimpl pageid btreekey getpage pageid getnitems classdescriptor tpstring comparestr getkeystroid op_not_found op_overflow comparestr putpage pageid oldoid getkeystroid setkeystroid op_overwrite op_duplicate putpage pageid insertstrkey classdescriptor tparrayofbyte comparebytearrays getkeystroid op_not_found op_overflow comparebytearrays putpage pageid oldoid getkeystroid setkeystroid op_overwrite op_duplicate putpage pageid insertbytearraykey getreference maxitems op_not_found op_overflow putpage pageid oldoid getreference maxitems setreference maxitems op_overwrite op_duplicate putpage pageid itemsize classdescriptor keyspace itemsize itemsize maxitems maxitems setnitems getnitems op_done pageid allocatepage putpage pageid itemsize itemsize itemsize maxitems maxitems maxitems maxitems maxitems maxitems itemsize itemsize itemsize maxitems maxitems maxitems maxitems maxitems maxitems pageid firstkeyoffs itemsize setnitems setnitems setnitems setnitems op_overflow static int insert str key storage impl db page pg int r btree key ins int height int n items getn items pg int size get size pg int n height 0 n items 1 n items insert before e r char sval char ins key oval int len sval length if size len 2 n 1 str key size key space memcpy pg r 1 pg r n r str key size size len 2 set key str offs pg r key space size set key str size pg r len set key str oid pg r ins oid set key str chars pg key space size sval n items 1 else page is full then divide page int page id db allocate page page b db put page page id int moved 0 int inserted len 2 str key size int prev delta 1 31 1 for int bn 0 i 0 bn 1 int add size sub size int j n items i 1 int key len get key str size pg i if bn r key len len inserted 0 add size len if height 0 sub size 0 j 1 else sub size get key str size pg i else add size sub size key len if height 0 if i 1 r sub size get key str size pg i 1 j 1 else inserted 0 int delta moved add size 2 bn 1 str key size j str key size size sub size 2 inserted if delta prev delta if height 0 ins get str b bn 1 else assert that string fits in the b tree page moved bn 1 str key size key space if bn r ins get str pg i set key str oid b bn get key str oid pg i size key len 2 i 1 else set key str oid b bn ins oid n items compactify strings pg i if bn r bn r height 0 memcpy pg r i 1 pg r i n r str key size size len 2 n items 1 assert that string fits in the b tree page size n i 1 str key size key space set key str offs pg r i key space size set key str size pg r i len set key str oid pg r i ins oid set key str chars pg key space size sval setn items b bn set size b moved set size pg size setn items pg n items ins oid page id db pool unfix b return btree op overflow moved key len 2 prev delta delta assert that string fits in the b tree page moved bn 1 str key size key space set key str size b bn key len set key str offs b bn key space moved if bn r set key str oid b bn ins oid set key str chars b key space moved sval else set key str oid b bn get key str oid pg i memcpy b key space moved pg get key str offs pg i key len 2 1 size key len 2 i 1 setn items pg n items set size pg size return size str key size n items 1 key space 2 btree op underflow btree op done insertstrkey storageimpl btreekey nitems getnitems getsize nitems nitems strkeysize keyspace strkeysize setkeystroffs keyspace setkeystrsize setkeystroid setkeystrchars keyspace nitems pageid allocatepage putpage pageid strkeysize prevdelta addsize subsize nitems keylen getkeystrsize keylen addsize subsize subsize getkeystrsize addsize subsize keylen subsize getkeystrsize addsize strkeysize strkeysize subsize prevdelta getstr strkeysize keyspace getstr setkeystroid getkeystroid keylen setkeystroid nitems compactifystrings strkeysize nitems strkeysize keyspace setkeystroffs keyspace setkeystrsize setkeystroid setkeystrchars keyspace setnitems setsize setsize setnitems nitems pageid op_overflow keylen prevdelta strkeysize keyspace setkeystrsize keylen setkeystroffs keyspace setkeystroid setkeystrchars keyspace setkeystroid getkeystroid keyspace getkeystroffs keylen keylen setnitems nitems setsize strkeysize nitems keyspace op_underflow op_done static int insert byte array key storage impl db page pg int r btree key ins int height int n items getn items pg int size get size pg int n height 0 n items 1 n items byte bval byte ins key oval insert before e r int len bval length if size len n 1 str key size key space memcpy pg r 1 pg r n r str key size size len set key str offs pg r key space size set key str size pg r len set key str oid pg r ins oid set key bytes pg key space size bval n items 1 else page is full then divide page int page id db allocate page page b db put page page id int moved 0 int inserted len str key size int prev delta 1 31 1 for int bn 0 i 0 bn 1 int add size sub size int j n items i 1 int key len get key str size pg i if bn r key len len inserted 0 add size len if height 0 sub size 0 j 1 else sub size get key str size pg i else add size sub size key len if height 0 if i 1 r sub size get key str size pg i 1 j 1 else inserted 0 int delta moved add size bn 1 str key size j str key size size sub size inserted if delta prev delta if height 0 ins get byte array b bn 1 else assert that string fits in the b tree page moved bn 1 str key size key space if bn r ins get byte array pg i set key str oid b bn get key str oid pg i size key len i 1 else set key str oid b bn ins oid n items compactify byte arrays pg i if bn r bn r height 0 memcpy pg r i 1 pg r i n r str key size size len n items 1 assert that string fits in the b tree page size n i 1 str key size key space set key str offs pg r i key space size set key str size pg r i len set key str oid pg r i ins oid set key bytes pg key space size bval setn items b bn set size b moved set size pg size setn items pg n items ins oid page id db pool unfix b return btree op overflow moved key len prev delta delta assert that string fits in the b tree page moved bn 1 str key size key space set key str size b bn key len set key str offs b bn key space moved if bn r set key str oid b bn ins oid set key bytes b key space moved bval else set key str oid b bn get key str oid pg i memcpy b key space moved pg get key str offs pg i key len 1 size key len i 1 setn items pg n items set size pg size return size str key size n items 1 key space 2 btree op underflow btree op done insertbytearraykey storageimpl btreekey nitems getnitems getsize nitems nitems strkeysize keyspace strkeysize setkeystroffs keyspace setkeystrsize setkeystroid setkeybytes keyspace nitems pageid allocatepage putpage pageid strkeysize prevdelta addsize subsize nitems keylen getkeystrsize keylen addsize subsize subsize getkeystrsize addsize subsize keylen subsize getkeystrsize addsize strkeysize strkeysize subsize prevdelta getbytearray strkeysize keyspace getbytearray setkeystroid getkeystroid keylen setkeystroid nitems compactifybytearrays strkeysize nitems strkeysize keyspace setkeystroffs keyspace setkeystrsize setkeystroid setkeybytes keyspace setnitems setsize setsize setnitems nitems pageid op_overflow keylen prevdelta strkeysize keyspace setkeystrsize keylen setkeystroffs keyspace setkeystroid setkeybytes keyspace setkeystroid getkeystroid keyspace getkeystroffs keylen keylen setnitems nitems setsize strkeysize nitems keyspace op_underflow op_done static int compactify strings page pg int m int i j offs len n getn items pg int size new int key space 2 1 int index new int key space 2 1 if m 0 return n int n zero length strings 0 if m 0 m m for i 0 i n m i len get key str size pg i if len 0 offs get key str offs pg i 1 size offs len len index offs len i else n zero length strings 1 for i n i len get key str size pg i if len 0 offs get key str offs pg i 1 size offs len len index offs len 1 else for i 0 i m i len get key str size pg i if len 0 offs get key str offs pg i 1 size offs len len index offs len 1 for i n i len get key str size pg i if len 0 offs get key str offs pg i 1 size offs len len index offs len i m else n zero length strings 1 set key str oid pg i m get key str oid pg i set key str size pg i m len set key str oid pg i m get key str oid pg i int n items n m n n zero length strings for offs key space 2 i offs n 0 i len len size i j index i if j 0 offs len n 1 set key str offs pg j offs 2 if offs i len memcpy pg offs pg i len len 2 return n items compactifystrings getnitems keyspace keyspace nzerolengthstrings getkeystrsize getkeystroffs nzerolengthstrings getkeystrsize getkeystroffs getkeystrsize getkeystroffs getkeystrsize getkeystroffs nzerolengthstrings setkeystroid getkeystroid setkeystrsize setkeystroid getkeystroid nitems nzerolengthstrings keyspace setkeystroffs nitems static int compactify byte arrays page pg int m int i j offs len n getn items pg int size new int key space 1 int index new int key space 1 if m 0 return n int n zero length arrays 0 if m 0 m m for i 0 i n m i len get key str size pg i if len 0 offs get key str offs pg i size offs len len index offs len i else n zero length arrays 1 for i n i len get key str size pg i if len 0 offs get key str offs pg i size offs len len index offs len 1 else for i 0 i m i len get key str size pg i if len 0 offs get key str offs pg i size offs len len index offs len 1 for i n i len get key str size pg i if len 0 offs get key str offs pg i size offs len len index offs len i m else n zero length arrays 1 set key str oid pg i m get key str oid pg i set key str size pg i m len set key str oid pg i m get key str oid pg i int n items n m n n zero length arrays for offs key space i offs n 0 i len len size i j index i if j 0 offs len n 1 set key str offs pg j offs if offs i len memcpy pg offs pg i len len 1 return n items compactifybytearrays getnitems keyspace keyspace nzerolengtharrays getkeystrsize getkeystroffs nzerolengtharrays getkeystrsize getkeystroffs getkeystrsize getkeystroffs getkeystrsize getkeystroffs nzerolengtharrays setkeystroid getkeystroid setkeystrsize setkeystroid getkeystroid nitems nzerolengtharrays keyspace setkeystroffs nitems static int remove str key page pg int r int len get key str size pg r 2 int offs get key str offs pg r int size get size pg int n items getn items pg if n items 1 str key size key space memcpy pg r pg r 1 n items r 1 str key size else memcpy pg r pg r 1 n items r str key size if len 0 memcpy pg key space size len pg key space size size key space offs 1 for int i n items i 0 if get key str offs pg i offs set key str offs pg i get key str offs pg i len set size pg size len setn items pg n items 1 return size str key size n items key space 2 btree op underflow btree op done removestrkey getkeystrsize getkeystroffs getsize nitems getnitems nitems strkeysize keyspace nitems strkeysize nitems strkeysize keyspace keyspace keyspace nitems getkeystroffs setkeystroffs getkeystroffs setsize setnitems nitems strkeysize nitems keyspace op_underflow op_done static int remove byte array key page pg int r int len get key str size pg r int offs get key str offs pg r int size get size pg int n items getn items pg if n items 1 str key size key space memcpy pg r pg r 1 n items r 1 str key size else memcpy pg r pg r 1 n items r str key size if len 0 memcpy pg key space size len pg key space size size key space offs 1 for int i n items i 0 if get key str offs pg i offs set key str offs pg i get key str offs pg i len set size pg size len setn items pg n items 1 return size str key size n items key space 2 btree op underflow btree op done removebytearraykey getkeystrsize getkeystroffs getsize nitems getnitems nitems strkeysize keyspace nitems strkeysize nitems strkeysize keyspace keyspace keyspace nitems getkeystroffs setkeystroffs getkeystroffs setsize setnitems nitems strkeysize nitems keyspace op_underflow op_done static int replace str key storage impl db page pg int r btree key ins int height ins oid get key str oid pg r remove str key pg r return insert str key db pg r ins height replacestrkey storageimpl btreekey getkeystroid removestrkey insertstrkey static int replace byte array key storage impl db page pg int r btree key ins int height ins oid get key str oid pg r remove byte array key pg r return insert byte array key db pg r ins height replacebytearraykey storageimpl btreekey getkeystroid removebytearraykey insertbytearraykey static int handle page underflow storage impl db page pg int r int type btree key rem int height int n items getn items pg if type class descriptor tp string page a db put page get key str oid pg r int an getn items a if r n items exists greater page page b db get page get key str oid pg r 1 int bn getn items b int merged size an bn str key size get size a get size b if height 1 merged size get key str size pg r 2 str key size 2 if merged size key space reallocation of nodes between pages a and b int i j k db pool unfix b b db put page get key str oid pg r 1 int size a get size a int size b get size b int add size sub size if height 1 add size get key str size pg r sub size get key str size b 0 else add size sub size get key str size b 0 i 0 int prev delta an str key size size a bn str key size size b while true i 1 int delta an i str key size size a add size 2 bn i str key size size b sub size 2 if delta 0 if delta prev delta i 1 break size a add size 2 size b sub size 2 prev delta delta if height 1 add size sub size sub size get key str size b i else add size sub size get key str size b i int result btree op done if i 0 k i if height 1 int len get key str size pg r set size a get size a len 2 set key str offs a an key space get size a set key str size a an len memcpy a get key str offs a an pg get key str offs pg r len 2 1 k 1 an 1 set key str oid a an k get key str oid b k set size b get size b get key str size b k 2 for j 0 j k j int len get key str size b j set size a get size a len 2 set size b get size b len 2 set key str offs a an key space get size a set key str size a an len set key str oid a an get key str oid b j memcpy a get key str offs a an b get key str offs b j len 2 1 an 1 rem get str b i 1 result replace str key db pg r rem height setn items a an setn items b compactify strings b i db pool unfix a db pool unfix b return result else merge page b to a if height 1 int r len get key str size pg r set key str size a an r len set size a get size a r len 2 set key str offs a an key space get size a memcpy a get key str offs a an pg get key str offs pg r r len 2 1 an 1 set key str oid a an bn get key str oid b bn for int i 0 i bn i an set key str size a an get key str size b i set key str offs a an get key str offs b i get size a set key str oid a an get key str oid b i set size a get size a get size b setn items a an memcpy a key space get size a b key space get size b get size b 1 db pool unfix a db pool unfix b db free page get key str oid pg r 1 set key str oid pg r 1 get key str oid pg r return remove str key pg r else page b is before a page b db get page get key str oid pg r 1 int bn getn items b int merged size an bn str key size get size a get size b if height 1 merged size get key str size pg r 1 2 str key size 2 if merged size key space reallocation of nodes between pages a and b int i j k len db pool unfix b b db put page get key str oid pg r 1 int size a get size a int size b get size b int add size sub size if height 1 add size get key str size pg r 1 sub size get key str size b bn 1 else add size sub size get key str size b bn 1 i 0 int prev delta an str key size size a bn str key size size b while true i 1 int delta an i str key size size a add size 2 bn i str key size size b sub size 2 if delta 0 if delta prev delta i 1 break prev delta delta size a add size 2 size b sub size 2 if height 1 add size sub size sub size get key str size b bn i 1 else add size sub size get key str size b bn i 1 int result btree op done if i 0 k i assert that i bn if height 1 set size b get size b get key str size b bn k 2 memcpy a i a 0 an 1 str key size k 1 set key str oid a k get key str oid b bn len get key str size pg r 1 set key str size a k len set size a get size a len 2 set key str offs a k key space get size a memcpy a get key str offs a k pg get key str offs pg r 1 len 2 1 else memcpy a i a 0 an str key size for j 0 j k j len get key str size b bn k j set size a get size a len 2 set size b get size b len 2 set key str offs a j key space get size a set key str size a j len set key str oid a j get key str oid b bn k j memcpy a get key str offs a j b get key str offs b bn k j len 2 1 an i setn items a an rem get str b bn k 1 result replace str key db pg r 1 rem height setn items b compactify strings b i db pool unfix a db pool unfix b return result else merge page b to a if height 1 memcpy a bn 1 a 0 an 1 str key size int len get key str size pg r 1 set key str size a bn len set size a get size a len 2 set key str offs a bn key space get size a set key str oid a bn get key str oid b bn memcpy a get key str offs a bn pg get key str offs pg r 1 len 2 1 an 1 else handlepageunderflow storageimpl btreekey nitems getnitems classdescriptor tpstring putpage getkeystroid getnitems nitems getpage getkeystroid getnitems merged_size strkeysize getsize getsize merged_size getkeystrsize strkeysize merged_size keyspace putpage getkeystroid size_a getsize size_b getsize addsize subsize addsize getkeystrsize subsize getkeystrsize addsize subsize getkeystrsize prevdelta strkeysize size_a strkeysize size_b strkeysize size_a addsize strkeysize size_b subsize prevdelta size_a addsize size_b subsize prevdelta addsize subsize subsize getkeystrsize addsize subsize getkeystrsize op_done getkeystrsize setsize getsize setkeystroffs keyspace getsize setkeystrsize getkeystroffs getkeystroffs setkeystroid getkeystroid setsize getsize getkeystrsize getkeystrsize setsize getsize setsize getsize setkeystroffs keyspace getsize setkeystrsize setkeystroid getkeystroid getkeystroffs getkeystroffs getstr replacestrkey setnitems setnitems compactifystrings r_len getkeystrsize setkeystrsize r_len setsize getsize r_len setkeystroffs keyspace getsize getkeystroffs getkeystroffs r_len setkeystroid getkeystroid setkeystrsize getkeystrsize setkeystroffs getkeystroffs getsize setkeystroid getkeystroid setsize getsize getsize setnitems keyspace getsize keyspace getsize getsize freepage getkeystroid setkeystroid getkeystroid removestrkey getpage getkeystroid getnitems merged_size strkeysize getsize getsize merged_size getkeystrsize strkeysize merged_size keyspace putpage getkeystroid size_a getsize size_b getsize addsize subsize addsize getkeystrsize subsize getkeystrsize addsize subsize getkeystrsize prevdelta strkeysize size_a strkeysize size_b strkeysize size_a addsize strkeysize size_b subsize prevdelta prevdelta size_a addsize size_b subsize addsize subsize subsize getkeystrsize addsize subsize getkeystrsize op_done setsize getsize getkeystrsize strkeysize setkeystroid getkeystroid getkeystrsize setkeystrsize setsize getsize setkeystroffs keyspace getsize getkeystroffs getkeystroffs strkeysize getkeystrsize setsize getsize setsize getsize setkeystroffs keyspace getsize setkeystrsize setkeystroid getkeystroid getkeystroffs getkeystroffs setnitems getstr replacestrkey setnitems compactifystrings strkeysize getkeystrsize setkeystrsize setsize getsize setkeystroffs keyspace getsize setkeystroid getkeystroid getkeystroffs getkeystroffs static int remove storage impl db int page id btree tree btree key rem int height page pg db get page page id try int i n getn items pg l 0 r n if tree type class descriptor tp string while l r i l r 1 if compare str rem key pg i 0 l i 1 else r i if height 0 do switch remove db get key str oid pg r tree rem height case btree op underflow db pool unfix pg pg null pg db put page page id return handle page underflow db pg r tree type rem height case btree op done return btree op done case btree op overflow db pool unfix pg pg null pg db put page page id return insert str key db pg r rem height while r n else while r n if compare str rem key pg r 0 int oid get key str oid pg r if oid rem oid rem oid 0 rem old oid oid db pool unfix pg pg null pg db put page page id return remove str key pg r else break r 1 else if tree type class descriptor tp array of byte while l r i l r 1 if tree compare byte arrays rem key pg i 0 l i 1 else r i if height 0 do switch remove db get key str oid pg r tree rem height case btree op underflow db pool unfix pg pg null pg db put page page id return handle page underflow db pg r tree type rem height case btree op done return btree op done case btree op overflow db pool unfix pg pg null pg db put page page id return insert byte array key db pg r rem height while r n else while r n if tree compare byte arrays rem key pg r 0 int oid get key str oid pg r if oid rem oid rem oid 0 rem old oid oid db pool unfix pg pg null pg db put page page id return remove byte array key pg r else break r 1 else scalar types int item size class descriptor sizeof tree type while l r i l r 1 if compare rem key pg i 0 l i 1 else r i if height 0 int oid rem oid while r n if compare rem key pg r 0 if get reference pg max items r 1 oid oid 0 rem old oid get reference pg max items r 1 db pool unfix pg pg null pg db put page page id memcpy pg r pg r 1 n r 1 item size memcpy pg max items n 1 pg max items n n r 1 4 setn items pg n return n item size 4 key space 2 btree op underflow btree op done else break r 1 return btree op not found do switch remove db get reference pg max items r 1 tree rem height case btree op underflow db pool unfix pg pg null pg db put page page id return handle page underflow db pg r tree type rem height case btree op done return btree op done while r n return btree op not found finally if pg null db pool unfix pg storageimpl pageid btreekey getpage pageid getnitems classdescriptor tpstring comparestr getkeystroid op_underflow putpage pageid handlepageunderflow op_done op_done op_overflow putpage pageid insertstrkey comparestr getkeystroid oldoid putpage pageid removestrkey classdescriptor tparrayofbyte comparebytearrays getkeystroid op_underflow putpage pageid handlepageunderflow op_done op_done op_overflow putpage pageid insertbytearraykey comparebytearrays getkeystroid oldoid putpage pageid removebytearraykey itemsize classdescriptor getreference maxitems oldoid getreference maxitems putpage pageid itemsize maxitems maxitems setnitems itemsize keyspace op_underflow op_done op_not_found getreference maxitems op_underflow putpage pageid handlepageunderflow op_done op_done op_not_found static void purge storage impl db int page id int type int height if height 0 page pg db get page page id int n getn items pg 1 if type class descriptor tp string type class descriptor tp array of byte page of strings while n 0 purge db get key str oid pg n type height else while n 0 purge db get reference pg max items n 1 type height db pool unfix pg db free page page id storageimpl pageid getpage pageid getnitems classdescriptor tpstring classdescriptor tparrayofbyte getkeystroid getreference maxitems freepage pageid static int traverse forward storage impl db int page id int type int height i persistent result int pos page pg db get page page id int oid try int i n getn items pg if height 0 if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i pos traverse forward db get key str oid pg i type height result pos else for i 0 i n i pos traverse forward db get reference pg max items i 1 type height result pos else if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i oid get key str oid pg i result pos db lookup object oid null else page of scalars for i 0 i n i oid get reference pg max items 1 i result pos db lookup object oid null return pos finally db pool unfix pg traverseforward storageimpl pageid ipersistent getpage pageid getnitems classdescriptor tpstring classdescriptor tparrayofbyte traverseforward getkeystroid traverseforward getreference maxitems classdescriptor tpstring classdescriptor tparrayofbyte getkeystroid lookupobject getreference maxitems lookupobject static int mark page storage impl db int page id int type int height int n pages 1 page pg db getgc page page id try int i n getn items pg if height 0 if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i n pages mark page db get key str oid pg i type height else for i 0 i n i n pages mark page db get reference pg max items i 1 type height else if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i db mark oid get key str oid pg i else page of scalars for i 0 i n i db mark oid get reference pg max items 1 i finally db pool unfix pg return n pages markpage storageimpl pageid npages getgcpage pageid getnitems classdescriptor tpstring classdescriptor tparrayofbyte npages markpage getkeystroid npages markpage getreference maxitems classdescriptor tpstring classdescriptor tparrayofbyte markoid getkeystroid markoid getreference maxitems npages static void export page storage impl db xml exporter exporter int page id int type int height throws java io io exception page pg db get page page id try int i n getn items pg if height 0 if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i export page db exporter get key str oid pg i type height else for i 0 i n i export page db exporter get reference pg max items i 1 type height else if type class descriptor tp string type class descriptor tp array of byte page of strings for i 0 i n i exporter export assoc get key str oid pg i pg data btree page first key offs btree page get key str offs pg i btree page get key str size pg i type else for i 0 i n i exporter export assoc get reference pg max items 1 i pg data btree page first key offs i class descriptor sizeof type class descriptor sizeof type type finally db pool unfix pg exportpage storageimpl xmlexporter pageid ioexception getpage pageid getnitems classdescriptor tpstring classdescriptor tparrayofbyte exportpage getkeystroid exportpage getreference maxitems classdescriptor tpstring classdescriptor tparrayofbyte exportassoc getkeystroid btreepage firstkeyoffs btreepage getkeystroffs btreepage getkeystrsize exportassoc getreference maxitems btreepage firstkeyoffs classdescriptor classdescriptor public static final sendable request item null item new null sendable request item public void dump do nothing we will be gc ed sendablerequestitem nullitem nullsendablerequestitem transient field fld btree field index btreefieldindex private final void locate field fld class descriptor locate field cls field name if fld null throw new storage error storage error indexed field not found class name field name locatefield classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return new field fld getkeyfields public void on load cls class descriptor load class get storage class name locate field onload classdescriptor loadclass getstorage classname locatefield btree field index class cls string field name boolean unique this cls field name unique 0 btreefieldindex fieldname fieldname btree field index class cls string field name boolean unique long autoinc count this cls cls this unique unique this field name field name this class name class descriptor get class name cls this autoinc count autoinc count locate field type check type fld get type btreefieldindex fieldname autoinccount fieldname fieldname classname classdescriptor getclassname autoinccount autoinccount locatefield checktype gettype protected object unpack enum int val return fld get type get enum constants val unpackenum gettype getenumconstants private key extract key i persistent obj try field f fld key key null switch type case class descriptor tp boolean key new key f get boolean obj break case class descriptor tp byte key new key f get byte obj break case class descriptor tp short key new key f get short obj break case class descriptor tp char key new key f get char obj break case class descriptor tp int key new key f get int obj break case class descriptor tp object i persistent ptr i persistent f get obj if ptr null ptr is persistent get storage make persistent ptr key new key ptr break case class descriptor tp long key new key f get long obj break case class descriptor tp date key new key date f get obj break case class descriptor tp float key new key f get float obj break case class descriptor tp double key new key f get double obj break case class descriptor tp enum key new key enum f get obj break case class descriptor tp string key new key string f get obj break default assert failed invalid type return key catch exception x throw new storage error storage error access violation x extractkey ipersistent classdescriptor tpboolean getboolean classdescriptor tpbyte getbyte classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tpobject ipersistent ipersistent ispersistent getstorage makepersistent classdescriptor tplong getlong classdescriptor tpdate classdescriptor tpfloat getfloat classdescriptor tpdouble getdouble classdescriptor tpenum classdescriptor tpstring storageerror storageerror access_violation public boolean add t obj return put obj public boolean put t obj return super insert extract key obj obj false 0 extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public synchronized void append t obj key key try switch type case class descriptor tp int key new key int autoinc count fld set int obj int autoinc count break case class descriptor tp long key new key autoinc count fld set long obj autoinc count break default throw new storage error storage error unsupported index type fld get type catch exception x throw new storage error storage error access violation x autoinc count 1 obj modify super insert key obj false classdescriptor tpint autoinccount setint autoinccount classdescriptor tplong autoinccount setlong autoinccount storageerror storageerror unsupported_index_type gettype storageerror storageerror access_violation autoinccount public t get prefix string prefix array list t list get list new key prefix true new key prefix character max value false return t list to array t array new instance cls list size getprefix arraylist getlist max_value toarray newinstance public t prefix search string key array list t list prefix search list key return t list to array t array new instance cls list size prefixsearch arraylist prefixsearchlist toarray newinstance public t get key from key till array list list new array list if root 0 btree page find storage impl get storage root check key from check key till this height list return t list to array t array new instance cls list size arraylist arraylist btreepage storageimpl getstorage checkkey checkkey toarray newinstance public t to persistent array t arr t array new instance cls n elems if root 0 btree page traverse forward storage impl get storage root type height arr 0 return arr topersistentarray newinstance nelems btreepage traverseforward storageimpl getstorage public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class btree case insensitive field index t extends i persistent extends btree field index t btree case insensitive field index btreecaseinsensitivefieldindex ipersistent btreefieldindex btreecaseinsensitivefieldindex btree case insensitive field index btree case insensitive field index class cls string field name boolean unique super cls field name unique btreecaseinsensitivefieldindex btreecaseinsensitivefieldindex fieldname fieldname btree case insensitive field index class cls string field name boolean unique long autoinc count super cls field name unique autoinc count btreecaseinsensitivefieldindex fieldname autoinccount fieldname autoinccount key check key key key if key null key oval instanceof string key new key string key oval to lower case key inclusion 0 return super check key key checkkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive nodeip port detector node node nodeip detector ip detector node crypto crypto boolean enablear ks this node node this ip detector ip detector this crypto crypto ark putter new nodeark inserter node crypto this enablear ks ip detector add port detector this nodeipportdetector nodeipdetector ipdetector nodecrypto enablearks ipdetector ipdetector arkputter nodearkinserter enablearks ipdetector addportdetector combine the nodeip detector s output with any per port information we may have to get a definitive for that port node crypto list of ip addresses still without port numbers freenet inet address detect primaryip address freenet inet address addr crypto get bind to if addr is real internet address false true false binding to a real internet address don t want us to use the others most likely he is on a multi homed box where only one ip can be used for freenet return new freenet inet address addr return ip detector detect primaryip address crypto config include local addresses in noderefs nodeipdetector nodecrypto freenetinetaddress detectprimaryipaddress freenetinetaddress getbindto isrealinternetaddress freenetinetaddress ipdetector detectprimaryipaddress includelocaladdressesinnoderefs get our peer s this is a list of ip port s at which we might be contactable some of them will have the same port as the listen port but if we are behind a nat which rewrites our port number some of them may not if we re behind a symmetric nat which rewrites it differently for each connection we re stuffed and we tell the user peer detect primary peers boolean logminor logger should log logger minor this array list peer addresses new array list peer freenet inet address addrs detect primaryip address for int i 0 i addrs length i addresses add new peer addrs i crypto port number if logminor logger minor this adding addrs i now try to get the rewritten port number from our peers only considering those within this crypto port this time peer node peer list crypto get peer nodes if peer list null hash map peer integer counts by peer new hash map peer integer fixme use a standard mutable int object we have one somewhere for int i 0 i peer list length i peer p peer list i get remote detected peer if p null p is null continue dns requester doesn t deal with our own node if ip util is valid address p get address true false continue if logger should log logger minor this logger minor this peer peer list i get peer thinks we are p if counts by peer contains key p counts by peer put p counts by peer get p 1 else counts by peer put p 1 if counts by peer size 1 iterator peer it counts by peer key set iterator peer p it next logger minor this everyone agrees we are p if addresses contains p addresses add p else if counts by peer size 1 take two most popular addresses peer best null peer second best null int best popularity 0 int second best popularity 0 for map entry peer integer entry counts by peer entry set peer cur entry get key int cur pop entry get value logger normal this detected peer cur popularity cur pop if cur pop best popularity second best popularity best popularity best popularity cur pop second best best best cur if best null if best popularity 1 addrs length 0 if addresses contains best logger normal this adding best peer best best popularity addresses add best if second best null second best popularity 1 if addresses contains second best logger normal this adding second best peer second best second best addresses add second best if best get address equals second best get address best popularity 1 logger error this hrrrm maybe this is a symmetric nat expect trouble connecting system err println hrrrm maybe this is a symmetric nat expect trouble connecting ip detector set maybe symmetric peer p new peer best get freenet address crypto port number if addresses contains p addresses add p last peers addresses to array new peer addresses size if logminor logger minor this returning for port crypto port number arrays to string last peers return last peers listenport detectprimarypeers shouldlog arraylist arraylist freenetinetaddress detectprimaryipaddress portnumber peernode peerlist getpeernodes peerlist hashmap countsbypeer hashmap peerlist peerlist getremotedetectedpeer isnull dnsrequester iputil isvalidaddress getaddress shouldlog peerlist getpeer countsbypeer containskey countsbypeer countsbypeer countsbypeer countsbypeer countsbypeer keyset countsbypeer secondbest bestpopularity secondbestpopularity countsbypeer entryset getkey curpop getvalue curpop curpop bestpopularity secondbestpopularity bestpopularity bestpopularity curpop secondbest bestpopularity bestpopularity secondbest secondbestpopularity secondbest secondbest secondbest secondbest getaddress secondbest getaddress bestpopularity ipdetector setmaybesymmetric getfreenetaddress portnumber lastpeers toarray portnumber tostring lastpeers lastpeers void update ark putter update arkputter void startark ark putter start arkputter public peer get primary peers if last peers null return detect primary peers else return last peers getprimarypeers lastpeers detectprimarypeers lastpeers public boolean includes freenet inet address addr freenet inet address a detect primaryip address for int i 0 i a length i if a i equals addr return true return false freenetinetaddress freenetinetaddress detectprimaryipaddress public class action data extends node data public action data actiondata nodedata actiondata private action listener action listener null public action listener get action listener return action listener actionlistener actionlistener actionlistener getactionlistener actionlistener public void set action listener action listener action listener this action listener action listener setactionlistener actionlistener actionlistener actionlistener actionlistener private control response ctrl res null public control response get control response return ctrl res controlresponse ctrlres controlresponse getcontrolresponse ctrlres public void set control response control response res ctrl res res setcontrolresponse controlresponse ctrlres param jmdns impl public type resolver jmdns impl jmdns impl this jmdns impl jmdns impl jmdnsimpl typeresolver jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl public void start timer timer timer schedule this dns constants query wait interval dns constants query wait interval dnsconstants query_wait_interval dnsconstants query_wait_interval public void run try if this jmdns impl get state dns state announced if count 3 logger finer run jmdns querying type dns outgoing out new dns outgoing dns constants flags qr query out add question new dns question services dns sd udp local dns constants type ptr dns constants class in for iterator iterator this jmdns impl get service types values iterator iterator has next out add answer new dns record pointer services dns sd udp local dns constants type ptr dns constants class in dns constants dns ttl string iterator next 0 this jmdns impl send out else after three queries we can quit this cancel else if this jmdns impl get state dns state canceled this cancel catch throwable e logger log level warning run exception e this jmdns impl recover jmdnsimpl getstate dnsstate dnsoutgoing dnsoutgoing dnsconstants flags_qr_query addquestion dnsquestion _services _dns _udp dnsconstants type_ptr dnsconstants class_in jmdnsimpl getservicetypes hasnext addanswer dnsrecord _services _dns _udp dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl jmdnsimpl jmdnsimpl getstate dnsstate jmdnsimpl final boolean global public identifier collision message string id boolean global this identifier id this global global identifiercollisionmessage override public simple field set get field set simple field set sfs new simple field set true sfs put single identifier identifier if global sfs put single global true return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle override public string get name return identifier collision getname identifiercollision override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message identifier collision goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message identifiercollision override public void remove from object container container container delete this removefrom objectcontainer smallest y coordinate of the rectangle public final double get top return top gettop smallest x coordinate of the rectangle public final double get left return left getleft greatest y coordinate of the rectangle public final double get bottom return bottom getbottom greatest x coordinate of the rectangle public final double get right return right getright rectangle area public final double area return bottom top right left area of covered rectangle for two sepcified rectangles public static double join area rectangler2 a rectangler2 b double left a left b left a left b left double right a right b right a right b right double top a top b top a top b top double bottom a bottom b bottom a bottom b bottom return bottom top right left joinarea clone rectangle public object clone try rectangler2 r rectangler2 super clone r top this top r left this left r bottom this bottom r right this right return r catch clone not supported exception e this shouldn t happen since we are cloneable throw new internal error clonenotsupportedexception internalerror create copy of the rectangle public rectangler2 rectangler2 r this top r top this left r left this bottom r bottom this right r right construct rectangle with specified coordinates public rectangler2 double top double left double bottom double right assert that top bottom left right this top top this left left this bottom bottom this right right default constructor for perst public rectangler2 join two rectangles this rectangle is updates to contain cover of this and specified rectangle param r rectangle to be joined with this rectangle public final void join rectangler2 r if left r left left r left if right r right right r right if top r top top r top if bottom r bottom bottom r bottom non destructive join of two rectangles param a first joined rectangle param b second joined rectangle return rectangle containing cover of these two rectangles public static rectangler2 join rectangler2 a rectangler2 b rectangler2 r new rectangler2 a r join b return r checks if this rectangle intersects with specified rectangle public final boolean intersects rectangler2 r return left r right top r bottom right r left bottom r top checks if this rectangle contains the specified rectangle public final boolean contains rectangler2 r return left r left top r top right r right bottom r bottom check if two rectangles are equal public boolean equals object o if o instanceof rectangler2 rectangler2 r rectangler2 o return left r left top r top right r right bottom r bottom return false hash code consists of all rectangle coordinates public int hash code return int double double to long bits top double double to long bits bottom 1 double double to long bits left 2 double double to long bits right 3 hashcode doubletolongbits doubletolongbits doubletolongbits doubletolongbits public string to string return top top left left bottom bottom right right tostring public http packet set version http version set content input stream null httppacket setversion setcontentinputstream public http packet http packet http packet set version http version set http packet set content input stream null httppacket httppacket httppacket setversion httppacket setcontentinputstream public http packet input stream in set version http version set in set content input stream null httppacket inputstream setversion setcontentinputstream public void init set first line clear headers set content new byte 0 false set content input stream null setfirstline clearheaders setcontent setcontentinputstream private string version public void set version string ver version ver setversion public string get version return version getversion protected boolean set input stream in boolean only headers try buffered reader reader new buffered reader new input stream reader in string first line reader read line if first line null first line length 0 return false set first line first line thanks for giordano sassaroli sassarol cefriel it 09 03 03 http status http status new http status first line int stat code http status get status code if stat code http status continue ad hoc code for managing iis non standard behaviour iis sends 100 code response and a 200 code response in the same stream so the code should check the presence of the actual response in the stream skip all header lines string header line reader read line while header line null 0 header line length http header header new http header header line if header has name true set header header header line reader read line look forward another first line string actual first line reader read line if actual first line null 0 actual first line length this is the actual first line set first line actual first line else return true string header line reader read line while header line null 0 header line length http header header new http header header line if header has name true set header header header line reader read line if only headers true set content false return true boolean is chunked request is chunked long content len 0 if is chunked request true try string chunk size line reader read line content len long parse long new string chunk size line get bytes 0 chunk size line length 2 catch exception e else content len get content length string builder content buf new string builder while 0 content len int chunk size http get chunk size char read buf new char chunk size long read cnt 0 while read cnt content len try thanks for mark retallack 02 02 05 long buf read len content len read cnt if chunk size buf read len buf read len chunk size int read len reader read read buf 0 int buf read len if read len 0 break content buf append new string read buf 0 read len read cnt read len catch exception e debug warning e break if is chunked request true skip crlf long skip len 0 do long skip cnt reader skip http crlf length skip len if skip cnt 0 break skip len skip cnt while skip len http crlf length read next chunk size try string chunk size line reader read line content len long parse long new string chunk size line get bytes 0 chunk size line length 2 catch exception e content len 0 else content len 0 thanks for ralf g r bergs 02 09 04 string content str content buf to string set content content str get bytes false catch exception e debug warning e return false return true inputstream onlyheaders bufferedreader bufferedreader inputstreamreader firstline readline firstline firstline setfirstline firstline httpstatus httpstatus httpstatus firstline statcode httpstatus getstatuscode statcode httpstatus headerline readline headerline headerline httpheader httpheader headerline hasname setheader headerline readline actualfirstline readline actualfirstline actualfirstline setfirstline actualfirstline headerline readline headerline headerline httpheader httpheader headerline hasname setheader headerline readline onlyheaders setcontent ischunkedrequest ischunked contentlen ischunkedrequest chunksizeline readline contentlen parselong chunksizeline getbytes chunksizeline contentlen getcontentlength stringbuilder contentbuf stringbuilder contentlen chunksize getchunksize readbuf chunksize readcnt readcnt contentlen bufreadlen contentlen readcnt chunksize bufreadlen bufreadlen chunksize readlen readbuf bufreadlen readlen contentbuf readbuf readlen readcnt readlen ischunkedrequest skiplen skipcnt skiplen skipcnt skiplen skipcnt skiplen chunksizeline readline contentlen parselong chunksizeline getbytes chunksizeline contentlen contentlen contentstr contentbuf tostring setcontent contentstr getbytes protected boolean set input stream in return set in false inputstream protected boolean set http socket http sock return set http sock get input stream httpsocket httpsock httpsock getinputstream protected void set http packet http packet set first line http packet get first line clear headers int n headers http packet getn headers for int n 0 n n headers n http header header http packet get header n add header header set content http packet get content httppacket httppacket setfirstline httppacket getfirstline clearheaders nheaders httppacket getnheaders nheaders httpheader httppacket getheader addheader setcontent httppacket getcontent public boolean read http socket http sock init return set http sock httpsocket httpsock httpsock private string first line private void set first line string value first line value firstline setfirstline firstline protected string get first line return first line getfirstline firstline protected string get first line token int num string tokenizer st new string tokenizer first line http reqest line delim string last token for int n 0 n num n if st has more tokens false return last token st next token return last token getfirstlinetoken stringtokenizer stringtokenizer firstline reqest_line_delim lasttoken hasmoretokens lasttoken nexttoken lasttoken public boolean has first line return 0 first line length true false hasfirstline firstline private vector http header list new vector public int getn headers return http header list size httpheaderlist getnheaders httpheaderlist public void add header http header header http header list add header addheader httpheader httpheaderlist public void add header string name string value http header header new http header name value http header list add header addheader httpheader httpheader httpheaderlist public http header get header int n return http header http header list get n httpheader getheader httpheader httpheaderlist public http header get header string name int n headers getn headers for int n 0 n n headers n http header header get header n string header name header get name if header name equals ignore case name true return header return null httpheader getheader nheaders getnheaders nheaders httpheader getheader headername getname headername equalsignorecase public void clear headers http header list clear http header list new vector clearheaders httpheaderlist httpheaderlist public boolean has header string name return get header name null true false hasheader getheader public void set header string name string value http header header get header name if header null header set value value return add header name value setheader httpheader getheader setvalue addheader public void set header string name int value set header name integer to string value setheader setheader tostring public void set header string name long value set header name long to string value setheader setheader tostring public void set header http header header set header header get name header get value setheader httpheader setheader getname getvalue public string get header value string name http header header get header name if header null return return header get value getheadervalue httpheader getheader getvalue public void set string header string name string value string start width string end width string header value value if header value starts with start width false header value start width header value if header value ends with end width false header value header value end width set header name header value setstringheader startwidth endwidth headervalue headervalue startswith startwidth headervalue startwidth headervalue headervalue endswith endwidth headervalue headervalue endwidth setheader headervalue public void set string header string name string value set string header name value setstringheader setstringheader public string get string header value string name string start width string end width string header value get header value name if header value starts with start width true header value header value substring 1 header value length if header value ends with end width true header value header value substring 0 header value length 1 return header value getstringheadervalue startwidth endwidth headervalue getheadervalue headervalue startswith startwidth headervalue headervalue headervalue headervalue endswith endwidth headervalue headervalue headervalue headervalue public string get string header value string name return get string header value name getstringheadervalue getstringheadervalue public void set integer header string name int value set header name integer to string value setintegerheader setheader tostring public void set long header string name long value set header name long to string value setlongheader setheader tostring public int get integer header value string name http header header get header name if header null return 0 return string util to integer header get value getintegerheadervalue httpheader getheader stringutil tointeger getvalue public long get long header value string name http header header get header name if header null return 0 return string util to long header get value getlongheadervalue httpheader getheader stringutil tolong getvalue public string get header string string builder str new string builder int n headers getn headers for int n 0 n n headers n http header header get header n str append header get name header get value http crlf return str to string getheaderstring stringbuilder stringbuilder nheaders getnheaders nheaders httpheader getheader getname getvalue tostring public void set content byte data boolean update with content length content data if update with content length true set content length data length setcontent updatewithcontentlength updatewithcontentlength setcontentlength public void set content byte data set content data true setcontent setcontent public void set content string data boolean update with content length set content data get bytes update with content length setcontent updatewithcontentlength setcontent getbytes updatewithcontentlength public void set content string data set content data true setcontent setcontent public byte get content return content getcontent public string get content string return new string content getcontentstring public boolean has content return content length 0 true false hascontent private input stream content input null public void set content input stream input stream in content input in inputstream contentinput setcontentinputstream inputstream contentinput public input stream get content input stream return content input inputstream getcontentinputstream contentinput public boolean has content input stream return content input null true false hascontentinputstream contentinput public void set content type string type set header http content type type setcontenttype setheader content_type public string get content type return get header value http content type getcontenttype getheadervalue content_type public void set content length long len set long header http content length len setcontentlength setlongheader content_length public long get content length return get long header value http content length getcontentlength getlongheadervalue content_length public boolean has connection return has header http connection hasconnection hasheader public void set connection string value set header http connection value setconnection setheader public string get connection return get header value http connection getconnection getheadervalue public boolean is close connection if has connection false return false string connection get connection if connection null return false return connection equals ignore case http close iscloseconnection hasconnection getconnection equalsignorecase public boolean is keep alive connection if has connection false return false string connection get connection if connection null return false return connection equals ignore case http keep alive iskeepaliveconnection hasconnection getconnection equalsignorecase keep_alive public boolean has content range return has header http content range has header http range hascontentrange hasheader content_range hasheader public void set content range long first pos long last pos long length string range str range str http content range bytes range str long to string first pos range str long to string last pos range str 0 length long to string length set header http content range range str setcontentrange firstpos lastpos rangestr rangestr content_range_bytes rangestr tostring firstpos rangestr tostring lastpos rangestr tostring setheader content_range rangestr public long get content range long range new long 3 range 0 range 1 range 2 0 if has content range false return range string range line get header value http content range thanks for brent hills 10 20 04 if range line length 0 range line get header value http range if range line length 0 return range thanks for brent hills 10 20 04 string tokenizer str token new string tokenizer range line skip bytes if str token has more tokens false return range str token next token get first byte pos if str token has more tokens false return range string first pos str str token next token try range 0 long parse long first pos str catch number format exception e if str token has more tokens false return range string last pos str str token next token try range 1 long parse long last pos str catch number format exception e if str token has more tokens false return range string length str str token next token try range 2 long parse long length str catch number format exception e return range getcontentrange hascontentrange rangeline getheadervalue content_range rangeline rangeline getheadervalue rangeline stringtokenizer strtoken stringtokenizer rangeline strtoken hasmoretokens strtoken nexttoken strtoken hasmoretokens firstposstr strtoken nexttoken parselong firstposstr numberformatexception strtoken hasmoretokens lastposstr strtoken nexttoken parselong lastposstr numberformatexception strtoken hasmoretokens lengthstr strtoken nexttoken parselong lengthstr numberformatexception public long get content range first position long range get content range return range 0 getcontentrangefirstposition getcontentrange public long get content range last position long range get content range return range 1 getcontentrangelastposition getcontentrange public long get content range instance length long range get content range return range 2 getcontentrangeinstancelength getcontentrange public void set cache control string directive set header http cache control directive setcachecontrol setheader cache_control public void set cache control string directive int value string str val directive integer to string value set header http cache control str val setcachecontrol strval tostring setheader cache_control strval public void set cache control int value set cache control http max age value setcachecontrol setcachecontrol max_age public string get cache control return get header value http cache control getcachecontrol getheadervalue cache_control public void set server string name set header http server name setserver setheader public string get server return get header value http server getserver getheadervalue public void set host string host int port string host addr host if host interface isi pv6 address host true host addr host set header http host host addr integer to string port sethost hostaddr hostinterface isipv6address hostaddr setheader hostaddr tostring public string get host return get header value http host gethost getheadervalue public void set date calendar cal date date new date cal set header http date date get date string setdate setheader getdatestring public string get date return get header value http date getdate getheadervalue public boolean has transfer encoding return has header http transfer encoding hastransferencoding hasheader transfer_encoding public void set transfer encoding string value set header http transfer encoding value settransferencoding setheader transfer_encoding public string get transfer encoding return get header value http transfer encoding gettransferencoding getheadervalue transfer_encoding public boolean is chunked if has transfer encoding false return false string trans enc get transfer encoding if trans enc null return false return trans enc equals ignore case http chunked ischunked hastransferencoding transenc gettransferencoding transenc transenc equalsignorecase static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private static final boolean local requests compete fairly true public static boolean is valid priority class int prio return prio maximum priority class prio minimum priority class local_requests_compete_fairly isvalidpriorityclass maximum_priority_class minimum_priority_class public request starter node client core node base request throttle throttle string name token bucket output bucket token bucket input bucket running average average output bytes per request running average average input bytes per request boolean is insert boolean isssk this core node this stats core node stats this throttle throttle this name name this output bucket output bucket this input bucket input bucket this average output bytes per request average output bytes per request this average input bytes per request average input bytes per request this is insert is insert this isssk isssk requeststarter nodeclientcore baserequestthrottle tokenbucket outputbucket tokenbucket inputbucket runningaverage averageoutputbytesperrequest runningaverage averageinputbytesperrequest isinsert nodestats outputbucket outputbucket inputbucket inputbucket averageoutputbytesperrequest averageoutputbytesperrequest averageinputbytesperrequest averageinputbytesperrequest isinsert isinsert void set scheduler request scheduler sched this sched sched setscheduler requestscheduler void start sched start core core get executor execute this name sched queue fill request starter queue getexecutor queuefillrequeststarterqueue final string name override public string to string return name tostring void real run chosen block req null sent request time system current time millis the last time at which we sent a request or decided not to long cycle time sent request time while true allow 5 minutes before we start killing requests due to not connecting opennet manager om if core node peers count connected peers 3 om core node get opennet null system current time millis om get creation time 5 60 1000 try synchronized this wait 1000 catch interrupted exception e todo auto generated catch block e print stack trace continue if req null req sched grab request if req null if logminor logger minor this running req priority req get priority wait long delay throttle get delay if logminor logger minor this delay delay from throttle long sleep until cycle time delay if local requests compete fairly input bucket blocking grab int math max 0 average input bytes per request current value output bucket blocking grab int math max 0 average output bytes per request current value long now do now system current time millis if now sleep until try thread sleep sleep until now if logminor logger minor this slept sleep until now ms catch interrupted exception e ignore while now sleep until string reason if local requests compete fairly if reason stats should reject request true is insert isssk true false null null if logminor logger minor this not sending local request reason wait one throttle delay before trying again cycle time system current time millis continue let local requests compete with all the others else stats wait until not overloaded is insert else if logminor logger minor this waiting always take the lock on request starter first afaics we don t synchronize on request starter anywhere else nested locks here prevent extra latency when there is a race and therefore allow us to sleep indefinitely synchronized this req sched grab request if req null try wait 100 1000 as close to indefinite as i m comfortable with toad catch interrupted exception e ignore if req null continue if start request req logminor don t log if it s a cancelled transient request if req is persistent req is cancelled logger normal this no requests to start on req req null cycle time sent request time system current time millis realrun chosenblock sentrequesttime currenttimemillis cycletime sentrequesttime opennetmanager countconnectedpeers getopennet currenttimemillis getcreationtime interruptedexception printstacktrace grabrequest getpriority getdelay sleepuntil cycletime local_requests_compete_fairly inputbucket blockinggrab averageinputbytesperrequest currentvalue outputbucket blockinggrab averageoutputbytesperrequest currentvalue currenttimemillis sleepuntil sleepuntil sleepuntil interruptedexception sleepuntil local_requests_compete_fairly shouldrejectrequest isinsert cycletime currenttimemillis waituntilnotoverloaded isinsert requeststarter requeststarter grabrequest interruptedexception startrequest ispersistent iscancelled cycletime sentrequesttime currenttimemillis private boolean start request chosen block req boolean logminor if req is persistent req is cancelled req on dumped return false if req key null if sched add to fetching req key req on dumped return false else if req is persistent transient chosen block req request instanceof sendable insert if sched add transient insert fetching sendable insert transient chosen block req request req token req on dumped return false if logminor logger minor this running request req priority req get priority core get executor execute new sender thread req req key request starter sender thread for req return true startrequest chosenblock ispersistent iscancelled ondumped addtofetching ondumped ispersistent transientchosenblock sendableinsert addtransientinsertfetching sendableinsert transientchosenblock ondumped getpriority getexecutor senderthread requeststarter senderthread public void run freenet support logger os thread logpid this while true try real run catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t osthread realrun outofmemoryerror oomhandler private final key key public sender thread chosen block req key key this req req this key key senderthread chosenblock public void run try freenet support logger os thread logpid this fixme key is not known for inserts here if key null stats report outgoing local request location key to normalized double if req send core sched if req is persistent req is cancelled logger error this run not able to send a request on req else logger normal this run not able to send a request on req request was cancelled if logminor logger minor this finished req finally if key null sched remove fetching key key else if req is persistent transient chosen block req request instanceof sendable insert sched remove transient insert fetching sendable insert transient chosen block req request req token osthread reportoutgoinglocalrequestlocation tonormalizeddouble ispersistent iscancelled removefetchingkey ispersistent transientchosenblock sendableinsert removetransientinsertfetching sendableinsert transientchosenblock public void wake up synchronized this notify all wakeup notifyall public boolean exclude random grab array item item object container container client context context if sched is running or queued persistent request sendable request item logger normal this excluding already running request item new exception debug return true if is insert return false if item instanceof base sendable get logger error this on a request scheduler exclude called with item new exception error return false base sendable get get base sendable get item if get has valid keys sched fetching keys container context return false logger normal this excluding no valid keys get return true randomgrabarrayitem objectcontainer clientcontext isrunningorqueuedpersistentrequest sendablerequest isinsert basesendableget basesendableget basesendableget hasvalidkeys fetchingkeys applies distortion by adding fish eye effect and horizontal vertical lines param base image the base image return the distorted image public buffered image get distorted image buffered image base image graphics2d graph graphics2d base image get graphics int image height base image get height int image width base image get width want lines put them in a variable so we might configure these later int horizontal lines image height 7 int vertical lines image width 7 calculate space between lines int horizontal gaps image height horizontal lines 1 int vertical gaps image width vertical lines 1 draw the horizontal stripes for int i horizontal gaps i image height i i horizontal gaps graph set color color blue graph draw line 0 i image width i draw the vertical stripes for int i vertical gaps i image width i i vertical gaps graph set color color red graph draw line i 0 i image height create a pixel array of the original image we need this later to do the operations on int pix new int image height image width int j 0 for int j1 0 j1 image width j1 for int k1 0 k1 image height k1 pix j base image getrgb j1 k1 j double distance ran int image width 4 image width 3 put the distortion in the dead middle int width middle base image get width 2 int height middle base image get height 2 again iterate over all pixels for int x 0 x base image get width x for int y 0 y base image get height y int relx x width middle int rely y height middle double d1 math sqrt relx relx rely rely if d1 distance int j2 width middle int fish eye formula d1 distance distance d1 double x width middle int k2 height middle int fish eye formula d1 distance distance d1 double y height middle base image setrgb x y pix j2 image height k2 return base image baseimage bufferedimage getdistortedimage bufferedimage baseimage baseimage getgraphics imageheight baseimage getheight imagewidth baseimage getwidth horizontallines imageheight verticallines imagewidth horizontalgaps imageheight horizontallines verticalgaps imagewidth verticallines horizontalgaps imageheight horizontalgaps setcolor drawline imagewidth verticalgaps imagewidth verticalgaps setcolor drawline imageheight imageheight imagewidth imagewidth imageheight baseimage ranint imagewidth imagewidth widthmiddle baseimage getwidth heightmiddle baseimage getheight baseimage getwidth baseimage getheight widthmiddle heightmiddle widthmiddle fisheyeformula widthmiddle heightmiddle fisheyeformula heightmiddle baseimage imageheight baseimage param i param j return private int ran int int i int j double d math random return int double i double j i 1 d ranint implementation of g s 3 4 s3 3 2 s2 1 4 s with s from 0 to 1 param s return private double fish eye formula double s if s 0 0d return 0 0d if s 1 0d return s else return 0 75d s s s 1 5d s s 0 25d s fisheyeformula private config config null public config get config return this config getconfig public void set config config config this config config setconfig public class seed client peer node extends peer node public seed client peer node simple field set fs node node2 node crypto crypto peer manager peers boolean from local boolean no sig outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception super fs node2 crypto peers from local no sig mangler true seedclientpeernode peernode seedclientpeernode simplefieldset nodecrypto peermanager fromlocal nosig outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception fromlocal nosig override public peer node status get status boolean no heavy return new peer node status this no heavy peernodestatus getstatus noheavy peernodestatus noheavy override public boolean is darknet return false isdarknet override public boolean is opennet return false not exactly isopennet override public boolean is seed return true isseed override public boolean is real connection return false we may be connected to the same node as a seed and as a regular connection isrealconnection override public boolean equals object o if o this return true only equal to seednode of its own type different to an opennet peer node with the same identity if o instanceof seed client peer node return super equals o else return false opennetpeernode seedclientpeernode override public void on success boolean insert boolean ssk ignore onsuccess override public boolean is routing compatible return false isroutingcompatible override public boolean can accept announcements return true canacceptannouncements override public boolean record status return false recordstatus override public boolean handshake unknown initiator return true handshakeunknowninitiator override public int handshake setup type return fnp packet mangler setup opennet seednode handshakesetuptype fnppacketmangler setup_opennet_seednode override public boolean should send handshake return false shouldsendhandshake override public boolean disconnected boolean dump message queue boolean dump trackers boolean ret super disconnected dump message queue dump trackers node peers disconnect this false false false return ret dumpmessagequeue dumptrackers dumpmessagequeue dumptrackers override protected boolean generate identity from pubkey return true generateidentityfrompubkey override protected boolean ignore last good version return true ignorelastgoodversion override void startark fetcher do not start an ark fetcher startarkfetcher override public boolean should disconnect and remove now if is connected seed client peer node s always start off unverified if it doesn t manage to connect in 60 seconds dump it however we don t want to be dumped before we connect so we need to check that first synchronize to avoid messy races synchronized this if time last connection completed 0 system current time millis last received packet time 60 1000 return true else disconnect after an hour in any event if system current time millis time last connection completed 60 60 1000 return true return false shoulddisconnectandremovenow isconnected seedclientpeernode timelastconnectioncompleted currenttimemillis lastreceivedpackettime currenttimemillis timelastconnectioncompleted plugin respirator pr private static final string plug name test gallery public void terminate goon false pluginrespirator plugname testgallery private string get array element string array int element try return array element catch exception e e print stack trace return getarrayelement printstacktrace public string handlehttp post http request request throws pluginhttp exception return null handlehttppost httprequest pluginhttpexception private string mk default page string builder out new string builder out append html head title plug name title head body n out append center h1 plug name h1 br br br n out append load gallery from the following key br out append form method get out append input type text name uri value default gallery uri size 80 out append input type submit value go form n out append center body html return out to string mkdefaultpage stringbuilder stringbuilder plugname plugname default_gallery_uri tostring public string handlehttp get http request request throws pluginhttp exception string builder out new string builder int page request get int param page 1 string uri request get param uri request get path if uri equals return mk default page try int i 0 cache later high level simple client hlsc pr gethl simple client string imglist new string hlsc fetch new freeneturi uri as byte array trim imglist imglist replace all r n imglist imglist replace all n n n imglist imglist replace all n n n imglist imglist replace all n n n imglist imglist replace all n n n imglist imglist replace all n n n cache string imgarr imglist split n string title imgarr 0 trim replace all freenet index of 3 untitled imgarr i imgarr 0 title out append html head title append title append title head body n out append center h1 append title append h1 br page append page append br br n mk page index out imgarr length page uri out append table tr n int images 0 int flush page 1 6 4 for i 1 i imgarr length images 6 4 i url name size if imgarr i trim length 5 continue if flush 0 flush continue images string imginfo imgarr i split string iname get array element imginfo 1 trim string isname iname if iname length 15 isname iname substring 0 11 iname substring iname last index of f2 echo f rev cut d f2 rev cut c 13 echo f rev cut d f1 rev string isize get array element imginfo 2 trim string iurl get array element imginfo 0 trim iurl iurl replace all uri iurl iurl replace all freenet if iurl starts with iurl iurl out append td align center valign top width 102px n out append a title append iname append href append iurl append img src append iurl append border 0 width 100 br n if imginfo length 1 out append font size 2 append isname append font n out append a n for int j 2 j imginfo length j out append br font size 2 append imginfo j trim append font n out append td n new row if i 6 0 out append tr tr n out append tr table n mk page index out imgarr length page uri out append center body html return out to string catch exception e todo auto generated catch block return e to string e print stack trace handlehttpget httprequest pluginhttpexception stringbuilder stringbuilder getintparam getparam getpath mkdefaultpage highlevelsimpleclient gethlsimpleclient asbytearray replaceall replaceall replaceall replaceall replaceall replaceall replaceall indexof mkpageindex getarrayelement lastindexof getarrayelement getarrayelement replaceall replaceall startswith mkpageindex tostring tostring printstacktrace private void mk page index string builder out int imgarrlength int page string uri for int pg 1 pg int math ceil imgarrlength 1 6 4 pg out append nbsp if pg page out append a href append uri append page append pg append append pg append a else out append append pg append out append nbsp n mkpageindex stringbuilder public void run plugin plugin respirator pr this pr pr while goon try thread sleep 300000 catch interrupted exception e runplugin pluginrespirator interruptedexception private static final long serial versionuid 4071292828166415028l public ssdp search socket list serialversionuid ssdpsearchsocketlist public ssdp search socket getssdp search socket int n return ssdp search socket get n ssdpsearchsocket getssdpsearchsocket ssdpsearchsocket public void add search listener search listener listener int n servers size for int n 0 n n servers n ssdp search socket sock getssdp search socket n sock add search listener listener addsearchlistener searchlistener nservers nservers ssdpsearchsocket getssdpsearchsocket addsearchlistener public boolean open int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n ssdp search socket ssdp search socket new ssdp search socket bind addr add ssdp search socket return true nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress ssdpsearchsocket ssdpsearchsocket ssdpsearchsocket bindaddr ssdpsearchsocket public void close int n sockets size for int n 0 n n sockets n ssdp search socket sock getssdp search socket n sock close clear nsockets nsockets ssdpsearchsocket getssdpsearchsocket public void start int n sockets size for int n 0 n n sockets n ssdp search socket sock getssdp search socket n sock start nsockets nsockets ssdpsearchsocket getssdpsearchsocket public void stop int n sockets size for int n 0 n n sockets n ssdp search socket sock getssdp search socket n sock stop nsockets nsockets ssdpsearchsocket getssdpsearchsocket public article parser author name null author domain null title null date null boards null reply to board null parentid null text null articleparser authorname authordomain replytoboard public string get author name return author name getauthorname authorname public string get author domain return author domain getauthordomain authordomain public string get title return title gettitle public list string get boards return boards getboards public string get reply to board return reply to board getreplytoboard replytoboard public string get parentid throws no such field exception if parentid null throw new no such field exception fixme also throw this in the other getter functions return parentid getparentid nosuchfieldexception nosuchfieldexception public string get text return text gettext public content type string type string subtype string charset string boundary this type type this subtype subtype this charset charset this boundary boundary contenttype parse a content type header public static content type parse header string hdr header tokenizer tokenizer new header tokenizer hdr true true content type result new content type null null us ascii null if tokenizer get token 0 return null result type tokenizer get token text if tokenizer get token return null if tokenizer get token 0 return null result subtype tokenizer get token text while tokenizer get token if tokenizer get token 0 break string param tokenizer get token text if tokenizer get token break if tokenizer get token 0 break string value tokenizer get token text if param equals ignore case charset result charset value else if param equals ignore case boundary result boundary value return result contenttype parseheader headertokenizer headertokenizer contenttype contenttype gettoken gettokentext gettoken gettoken gettokentext gettoken gettoken gettokentext gettoken gettoken gettokentext equalsignorecase equalsignorecase public mailbox string name string local string domain this name name this local local this domain domain parse a from header and extract the first address this does not fully parse the header so it will accept strings that are not actually valid mailing addresses public static mailbox parse header string hdr header tokenizer tokenizer new header tokenizer hdr string name null local null domain null string builder current new string builder boolean in domain false in angles false while tokenizer tokens remaining int c tokenizer get token if c if in domain return null local current to string in domain true current new string builder else if c current append else if c 0 string word tokenizer get token text current append word else if c if in angles in domain return null name current to string in angles true current new string builder else if in domain c in angles false break else if in domain c c break else name local domain null in domain in angles false current new string builder if in domain in angles domain current to string return new mailbox name local domain else return null parseheader headertokenizer headertokenizer stringbuilder stringbuilder indomain inangles tokensremaining gettoken indomain tostring indomain stringbuilder gettokentext inangles indomain tostring inangles stringbuilder indomain inangles indomain indomain inangles stringbuilder indomain inangles tostring parse a newsgroups or follow to header and return a list of newsgroup names private static array list string parse newsgroups string hdr header tokenizer tokenizer new header tokenizer hdr false false array list string result new array list string while tokenizer tokens remaining int c tokenizer get token if c 0 string name tokenizer get token text string board name freetalknntp group group to board name name if board is name valid board name result add board name return result arraylist parsenewsgroups headertokenizer headertokenizer arraylist arraylist tokensremaining gettoken gettokentext boardname freetalknntpgroup grouptoboardname isnamevalid boardname boardname parse a references header and return a list of message i ds private static array list string parse references string hdr header tokenizer tokenizer new header tokenizer hdr string builder current null array list string result new array list string while tokenizer tokens remaining int c tokenizer get token if c current new string builder else if c if current null result add current to string current null else if c 0 if current null current append tokenizer get token text else if c 0 if current null current append char c return result ids arraylist parsereferences headertokenizer headertokenizer stringbuilder arraylist arraylist tokensremaining gettoken stringbuilder tostring gettokentext decode any encoded words in the header as per rfc 2047 private static string decodemime header string str string builder result new string builder matcher matcher encoded word pattern matcher str int pos 0 while matcher find string charset name matcher group 1 string encoding name matcher group 2 string data matcher group 3 result append str substring pos matcher start try charset charset charset for name charset name transfer encoding encoding transfer encoding header word encoding encoding name byte encoded bytes data get bytes us ascii byte buffer decoded bytes encoding decode byte buffer wrap encoded bytes result append charset decode decoded bytes catch exception e result append matcher group pos matcher end result append str substring pos return result to string decodemimeheader stringbuilder stringbuilder encodedwordpattern charsetname encodingname forname charsetname transferencoding transferencoding headerwordencoding encodingname encodedbytes getbytes bytebuffer decodedbytes bytebuffer encodedbytes decodedbytes tostring get the named header contents private static string get header string head lines string name int i j for i 0 i head lines length i for j 0 j name length j head lines i length j if name char at j character to lower case head lines i char at j break if j name length continue while j head lines i length head lines i char at j head lines i char at j t j if j head lines i length head lines i char at j continue j skip initial whitespace while j head lines i length head lines i char at j head lines i char at j t j string builder result new string builder decodemime header head lines i substring j find continuation lines i while i head lines length head lines i length 0 head lines i char at 0 head lines i char at 0 t result append n result append decodemime header head lines i i return result to string return null getheader headlines headlines headlines charat tolowercase headlines charat headlines headlines charat headlines charat headlines headlines charat headlines headlines charat headlines charat stringbuilder stringbuilder decodemimeheader headlines headlines headlines headlines charat headlines charat decodemimeheader headlines tostring parse the message body private void parse body byte buffer bytes content type type string encoding name fixme handle multi part content upload non text parts as attachments etc charset body charset try body charset charset for name type charset catch illegal argument exception e body charset charset for name utf 8 try transfer encoding encoding transfer encoding body encoding encoding name byte buffer decoded bytes encoding decode bytes text body charset decode decoded bytes to string catch exception e text body charset decode bytes to string parsebody bytebuffer contenttype encodingname bodycharset bodycharset forname illegalargumentexception bodycharset forname transferencoding transferencoding bodyencoding encodingname bytebuffer decodedbytes bodycharset decodedbytes tostring bodycharset tostring parse a complete message the input is given as a byte buffer since we do not know what encoding has been used until we parse the header return true if the message was parsed successfully public boolean parse message byte buffer bytes split up message into head body byte buffer head bytes body bytes boolean linestart true find the blank line separating head from body while bytes has remaining byte b bytes get if bytes has remaining b r b bytes get if b n if linestart break else linestart true else linestart false if bytes has remaining logger debug this unable to find start of message body return false save remaining unread bytes in body bytes body bytes bytes slice and previous bytes in head bytes bytes flip head bytes bytes slice first try decoding headers as utf 8 charset utf8 charset for name utf 8 string headutf8 utf8 decode head bytes to string string head lines headutf8 split r n read newsgroups followup to and references headers string newsgroups header get header head lines newsgroups string followup to header get header head lines followup to string references header get header head lines references string in reply to header get header head lines in reply to string transfer encoding header get header head lines content transfer encoding if newsgroups header null logger debug this unable to find newsgroups header return false read content type header string type header get header head lines content type content type body type null if type header null body type content type parse header type header if body type null body type new content type text plain utf 8 null and then try decoding the headers again using the body charset charset body charset try body charset charset for name body type charset catch illegal argument exception e body charset charset for name utf 8 head bytes rewind string head body charset decode head bytes to string head lines head split r n read from and subject headers using the body charset string from header get header head lines from string subject header get header head lines subject if from header null logger debug this unable to find from header return false if subject header null logger debug this unable to find subject header return false try using the body charset for newsgroups and followup to if utf 8 didn t work if newsgroups header index of 0xfffd 1 followup to header null followup to header index of 0xfffd 1 newsgroups header get header head lines newsgroups followup to header get header head lines followup to mailbox addr mailbox parse header from header if addr null logger debug this unable to parse from header return false author name addr local author domain addr domain title message make title valid subject header boards parse newsgroups newsgroups header if followup to header null array list string followups parse newsgroups followup to header if followups is empty reply to board followups get 0 if in reply to header null array list string refs parse references in reply to header if refs is empty parentid refs get refs size 1 else if references header null array list string refs parse references references header if refs is empty parentid refs get refs size 1 if transfer encoding header null parse body body bytes body type transfer encoding header else parse body body bytes body type 8bit return true parsemessage bytebuffer bytebuffer headbytes bodybytes hasremaining hasremaining hasremaining bodybytes bodybytes headbytes headbytes forname headbytes tostring headlines newsgroupsheader getheader headlines followuptoheader getheader headlines referencesheader getheader headlines inreplytoheader getheader headlines transferencodingheader getheader headlines newsgroupsheader typeheader getheader headlines contenttype bodytype typeheader bodytype contenttype parseheader typeheader bodytype bodytype contenttype bodycharset bodycharset forname bodytype illegalargumentexception bodycharset forname headbytes bodycharset headbytes tostring headlines fromheader getheader headlines subjectheader getheader headlines fromheader subjectheader newsgroupsheader indexof followuptoheader followuptoheader indexof newsgroupsheader getheader headlines followuptoheader getheader headlines parseheader fromheader authorname authordomain maketitlevalid subjectheader parsenewsgroups newsgroupsheader followuptoheader arraylist parsenewsgroups followuptoheader isempty replytoboard inreplytoheader arraylist parsereferences inreplytoheader isempty referencesheader arraylist parsereferences referencesheader isempty transferencodingheader parsebody bodybytes bodytype transferencodingheader parsebody bodybytes bodytype static void make kleinberg network node nodes boolean ideal locations int degree boolean force neighbour connections if ideal locations first set the locations up so we don t spend a long time swapping just to stabilise each network double div 1 0 nodes length double loc 0 0 for int i 0 i nodes length i nodes i set location loc loc div if force neighbour connections for int i 0 i nodes length i int next i 1 nodes length connect nodes i nodes next for int i 0 i nodes length i node a nodes i normalise the probabilities double norm 0 0 for int j 0 j nodes length j node b nodes j if a get location b get location continue norm 1 0 distance a b create degree 2 outgoing connections for int k 0 k nodes length k node b nodes k if a get location b get location continue double p 1 0 distance a b norm for int n 0 n degree 2 n if math random p connect a b break makekleinbergnetwork ideallocations forceneighbourconnections ideallocations setlocation forceneighbourconnections getlocation getlocation getlocation getlocation static void connect node a node b try a connect b b connect a catch fs parse exception e logger error real node secret ping test class cannot connect e catch peer parse exception e logger error real node secret ping test class cannot connect 2 e catch freenet io comm reference signature verification exception e logger error real node secret ping test class cannot connect 3 e fsparseexception realnodesecretpingtest peerparseexception realnodesecretpingtest referencesignatureverificationexception realnodesecretpingtest static double distance node a node b double al a get location double bl b get location return location distance al bl getlocation getlocation static string get port number peer node p if p null p get peer null return null return integer to string p get peer get port getportnumber peernode getpeer tostring getpeer getport static string get port number node n if n null return null return integer to string n get darknet port number getportnumber tostring getdarknetportnumber static void wait for all connected node nodes throws interrupted exception long t start system current time millis while true int count fully connected 0 int count really connected 0 int total peers 0 int total connections 0 int total partial connections 0 int total compatible connections 0 int total backed off 0 double total ping time 0 0 double max ping time 0 0 double min ping time double max value for int i 0 i nodes length i int count connected nodes i peers count connected darknet peers int count almost connected nodes i peers count almost connected darknet peers int count total nodes i peers count valid peers int count backed off nodes i peers count backed off peers int count compatible nodes i peers count compatible darknet peers total peers count total total connections count connected total partial connections count almost connected total compatible connections count compatible total backed off count backed off double ping time nodes i node stats get node average ping time total ping time ping time if ping time max ping time max ping time ping time if ping time min ping time min ping time ping time if count connected count total count fully connected if count backed off 0 count really connected else if logger should log logger minor real node test class logger minor real node test class connection count for nodes i count connected partial count almost connected if count backed off 0 if logger should log logger minor real node test class logger minor real node test class backed off nodes i count backed off double avg ping time total ping time nodes length if count fully connected nodes length count really connected nodes length min ping time node stats sub max ping time max ping time node stats sub max ping time avg ping time node stats sub max ping time system err println all nodes fully connected logger normal real node test class all nodes fully connected system err println return else long t delta system current time millis t start 1000 system err println waiting for nodes to be fully connected count fully connected nodes length total connections total peers connections total partial total partial connections compatible total compatible connections backed off total backed off ping min avg max int min ping time int avg ping time int max ping time at t delta s logger normal real node test class waiting for nodes to be fully connected count fully connected nodes length total connections total peers connections total partial total partial connections compatible total compatible connections backed off total backed off ping min avg max int min ping time int avg ping time int max ping time at t delta s thread sleep 1000 waitforallconnected interruptedexception tstart currenttimemillis countfullyconnected countreallyconnected totalpeers totalconnections totalpartialconnections totalcompatibleconnections totalbackedoff totalpingtime maxpingtime minpingtime max_value countconnected countconnecteddarknetpeers countalmostconnected countalmostconnecteddarknetpeers counttotal countvalidpeers countbackedoff countbackedoffpeers countcompatible countcompatibledarknetpeers totalpeers counttotal totalconnections countconnected totalpartialconnections countalmostconnected totalcompatibleconnections countcompatible totalbackedoff countbackedoff pingtime nodestats getnodeaveragepingtime totalpingtime pingtime pingtime maxpingtime maxpingtime pingtime pingtime minpingtime minpingtime pingtime countconnected counttotal countfullyconnected countbackedoff countreallyconnected shouldlog realnodetest realnodetest countconnected countalmostconnected countbackedoff shouldlog realnodetest realnodetest countbackedoff avgpingtime totalpingtime countfullyconnected countreallyconnected minpingtime nodestats sub_max_ping_time maxpingtime nodestats sub_max_ping_time avgpingtime nodestats sub_max_ping_time realnodetest tdelta currenttimemillis tstart countfullyconnected totalconnections totalpeers totalpartialconnections totalcompatibleconnections totalbackedoff minpingtime avgpingtime maxpingtime tdelta realnodetest countfullyconnected totalconnections totalpeers totalpartialconnections totalcompatibleconnections totalbackedoff minpingtime avgpingtime maxpingtime tdelta public get request status message simple field set fs this identifier fs get identifier this global fields string to bool fs get global false this only data fields string to bool fs get only data false getrequeststatusmessage simplefieldset stringtobool onlydata stringtobool onlydata override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle override public string get name return name getname override public void run final fcp connection handler handler node node throws message invalid exception client request req handler get reboot request global handler identifier if req null node client core client context job runner queue new db job public void run object container container client context context client request req handler get forever request global handler identifier container container activate req 1 if req null protocol error message msg new protocol error message protocol error message no such identifier false null identifier global handler output handler queue msg else req send pending messages handler output handler true true only data container container deactivate req 1 native thread norm priority false else req send pending messages handler output handler true true only data null fcpconnectionhandler messageinvalidexception clientrequest getrebootrequest clientcore clientcontext jobrunner dbjob objectcontainer clientcontext clientrequest getforeverrequest protocolerrormessage protocolerrormessage protocolerrormessage no_such_identifier outputhandler sendpendingmessages outputhandler onlydata nativethread norm_priority sendpendingmessages outputhandler onlydata public void run object container container client context context client request req handler get forever request global handler identifier container container activate req 1 if req null protocol error message msg new protocol error message protocol error message no such identifier false null identifier global handler output handler queue msg else req send pending messages handler output handler true true only data container container deactivate req 1 objectcontainer clientcontext clientrequest getforeverrequest protocolerrormessage protocolerrormessage protocolerrormessage no_such_identifier outputhandler sendpendingmessages outputhandler onlydata override public void remove from object container container container delete this removefrom objectcontainer private static final long serial versionuid 1 node init exception int exit code string msg super msg exit code this exit code exit code serialversionuid nodeinitexception exitcode exitcode exitcode exitcode private static final long serial versionuid 1 public ssk decode exception string string super string serialversionuid sskdecodeexception node crypto config sub config config int sort order boolean is opennet security levels security levels throws node init exception config register listen port 1 means random sort order true true node port node port long new int callback override public integer get synchronized node crypto config class if crypto null port number crypto port number return port number override public void set integer val throws invalid config value exception if port number 1 port number 0 port number 65535 throw new invalid config value exception invalid port number synchronized node crypto config class if port number val return fixme implement on the fly listen port changing note that this sort of thing should be the exception rather than the rule if crypto null throw new invalid config value exception switching listen port on the fly not yet supported port number val override public boolean is read only return true false try port number config get int listen port catch exception e fixme is this really necessary logger error this caught e e system err println e e print stack trace port number 1 config register bind to 0 0 0 0 sort order true true node bind to node bind to long new node bindto callback try bind to new freenet inet address config get string bind to false catch unknown host exception e throw new node init exception node init exception exit could not bind usm invalid bind to config get string bind to config register testing drop packets every 0 sort order true false node drop packet every node drop packet every long new int callback override public integer get synchronized node crypto config this return drop probability override public void set integer val throws invalid config value exception if val 0 throw new invalid config value exception testing drop packets every must not be negative synchronized node crypto config this if val drop probability return drop probability val if crypto null return crypto on set drop probability val false drop probability config get int testing drop packets every config register one connection perip is opennet sort order true false node one connection perip node one connection perip long new boolean callback override public boolean get synchronized node crypto config this return one connection per address override public void set boolean val throws invalid config value exception synchronized node crypto config this one connection per address val one connection per address config get boolean one connection perip if is opennet security levels add network threat level listener new security level listener network threat level public void on change network threat level old level network threat level new level might be useful for nodes on the same nat etc so turn it off for low otherwise is sensible it s always off on darknet since we can reasonably expect to know our peers even if we are paranoid about them if new level network threat level low one connection per address false if old level network threat level low one connection per address true config register always allow local addresses is opennet sort order true false node always allow local addresses node always allow local addresses long new boolean callback override public boolean get synchronized node crypto config this return always allow local addresses override public void set boolean val throws invalid config value exception synchronized node crypto config this always allow local addresses val always allow local addresses config get boolean always allow local addresses if is opennet security levels add friends threat level listener new security level listener friends threat level public void on change friends threat level old level friends threat level new level if new level friends threat level high always allow local addresses false if old level friends threat level high always allow local addresses false config register assumena ted true sort order true true node assumena ted node assumena ted long new boolean callback override public boolean get return assumena ted override public void set boolean val throws invalid config value exception assumena ted val assumena ted config get boolean assumena ted include local i ps in noderef file config register include local addresses in noderefs is opennet sort order true false nodeip dectector incl local address nodeip dectector incl local address long new boolean callback override public boolean get return include local addresses in noderefs override public void set boolean val throws invalid config value exception include local addresses in noderefs val include local addresses in noderefs config get boolean include local addresses in noderefs enable disable padding of outgoing packets won t affect auth packets config register padd data packets true sort order true false node padd data packets node padd data packets long new boolean callback override public boolean get return padd data packets override public void set boolean val throws invalid config value exception node need restart exception if val equals get return padd data packets val padd data packets config get boolean padd data packets security levels add network threat level listener new security level listener network threat level public void on change network threat level old level network threat level new level might be useful for nodes which are running with a tight bandwidth quota to minimize the overhead so turn it off for low otherwise is sensible if new level network threat level low padd data packets false if old level network threat level low padd data packets true nodecryptoconfig subconfig sortorder isopennet securitylevels securitylevels nodeinitexception listenport sortorder portlong intcallback nodecryptoconfig portnumber portnumber portnumber invalidconfigvalueexception portnumber portnumber portnumber invalidconfigvalueexception nodecryptoconfig portnumber listenport invalidconfigvalueexception listenport portnumber isreadonly portnumber getint listenport printstacktrace portnumber bindto sortorder bindto bindtolong nodebindtocallback bindto freenetinetaddress getstring bindto unknownhostexception nodeinitexception nodeinitexception exit_could_not_bind_usm bindto getstring bindto testingdroppacketsevery sortorder droppacketevery droppacketeverylong intcallback nodecryptoconfig dropprobability invalidconfigvalueexception invalidconfigvalueexception testingdroppacketsevery nodecryptoconfig dropprobability dropprobability onsetdropprobability dropprobability getint testingdroppacketsevery oneconnectionperip isopennet sortorder oneconnectionperip oneconnectionperiplong booleancallback nodecryptoconfig oneconnectionperaddress invalidconfigvalueexception nodecryptoconfig oneconnectionperaddress oneconnectionperaddress getboolean oneconnectionperip isopennet securitylevels addnetworkthreatlevellistener securitylevellistener network_threat_level onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level oneconnectionperaddress oldlevel network_threat_level oneconnectionperaddress alwaysallowlocaladdresses isopennet sortorder alwaysallowlocaladdresses alwaysallowlocaladdresseslong booleancallback nodecryptoconfig alwaysallowlocaladdresses invalidconfigvalueexception nodecryptoconfig alwaysallowlocaladdresses alwaysallowlocaladdresses getboolean alwaysallowlocaladdresses isopennet securitylevels addfriendsthreatlevellistener securitylevellistener friends_threat_level onchange friends_threat_level oldlevel friends_threat_level newlevel newlevel friends_threat_level alwaysallowlocaladdresses oldlevel friends_threat_level alwaysallowlocaladdresses assumenated sortorder assumenated assumenatedlong booleancallback assumenated invalidconfigvalueexception assumenated assumenated getboolean assumenated ips includelocaladdressesinnoderefs isopennet sortorder nodeipdectector incllocaladdress nodeipdectector incllocaladdresslong booleancallback includelocaladdressesinnoderefs invalidconfigvalueexception includelocaladdressesinnoderefs includelocaladdressesinnoderefs getboolean includelocaladdressesinnoderefs padddatapackets sortorder padddatapackets padddatapacketslong booleancallback padddatapackets invalidconfigvalueexception nodeneedrestartexception padddatapackets padddatapackets getboolean padddatapackets securitylevels addnetworkthreatlevellistener securitylevellistener network_threat_level onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level padddatapackets oldlevel network_threat_level padddatapackets config register listen port 1 means random sort order true true node port node port long new int callback override public integer get synchronized node crypto config class if crypto null port number crypto port number return port number listenport sortorder portlong intcallback nodecryptoconfig portnumber portnumber portnumber override public void set integer val throws invalid config value exception if port number 1 port number 0 port number 65535 throw new invalid config value exception invalid port number synchronized node crypto config class if port number val return fixme implement on the fly listen port changing note that this sort of thing should be the exception rather than the rule if crypto null throw new invalid config value exception switching listen port on the fly not yet supported port number val invalidconfigvalueexception portnumber portnumber portnumber invalidconfigvalueexception nodecryptoconfig portnumber listenport invalidconfigvalueexception listenport portnumber override public boolean is read only return true isreadonly override public integer get synchronized node crypto config this return drop probability nodecryptoconfig dropprobability override public void set integer val throws invalid config value exception if val 0 throw new invalid config value exception testing drop packets every must not be negative synchronized node crypto config this if val drop probability return drop probability val if crypto null return crypto on set drop probability val invalidconfigvalueexception invalidconfigvalueexception testingdroppacketsevery nodecryptoconfig dropprobability dropprobability onsetdropprobability override public boolean get synchronized node crypto config this return one connection per address nodecryptoconfig oneconnectionperaddress override public void set boolean val throws invalid config value exception synchronized node crypto config this one connection per address val invalidconfigvalueexception nodecryptoconfig oneconnectionperaddress public void on change network threat level old level network threat level new level might be useful for nodes on the same nat etc so turn it off for low otherwise is sensible it s always off on darknet since we can reasonably expect to know our peers even if we are paranoid about them if new level network threat level low one connection per address false if old level network threat level low one connection per address true onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level oneconnectionperaddress oldlevel network_threat_level oneconnectionperaddress override public boolean get synchronized node crypto config this return always allow local addresses nodecryptoconfig alwaysallowlocaladdresses override public void set boolean val throws invalid config value exception synchronized node crypto config this always allow local addresses val invalidconfigvalueexception nodecryptoconfig alwaysallowlocaladdresses public void on change friends threat level old level friends threat level new level if new level friends threat level high always allow local addresses false if old level friends threat level high always allow local addresses false onchange friends_threat_level oldlevel friends_threat_level newlevel newlevel friends_threat_level alwaysallowlocaladdresses oldlevel friends_threat_level alwaysallowlocaladdresses config register assumena ted true sort order true true node assumena ted node assumena ted long new boolean callback override public boolean get return assumena ted assumenated sortorder assumenated assumenatedlong booleancallback assumenated override public void set boolean val throws invalid config value exception assumena ted val invalidconfigvalueexception assumenated config register include local addresses in noderefs is opennet sort order true false nodeip dectector incl local address nodeip dectector incl local address long new boolean callback override public boolean get return include local addresses in noderefs includelocaladdressesinnoderefs isopennet sortorder nodeipdectector incllocaladdress nodeipdectector incllocaladdresslong booleancallback includelocaladdressesinnoderefs override public void set boolean val throws invalid config value exception include local addresses in noderefs val invalidconfigvalueexception includelocaladdressesinnoderefs config register padd data packets true sort order true false node padd data packets node padd data packets long new boolean callback override public boolean get return padd data packets padddatapackets sortorder padddatapackets padddatapacketslong booleancallback padddatapackets override public void set boolean val throws invalid config value exception node need restart exception if val equals get return padd data packets val invalidconfigvalueexception nodeneedrestartexception padddatapackets public void on change network threat level old level network threat level new level might be useful for nodes which are running with a tight bandwidth quota to minimize the overhead so turn it off for low otherwise is sensible if new level network threat level low padd data packets false if old level network threat level low padd data packets true onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level padddatapackets oldlevel network_threat_level padddatapackets public static final int option count 3 synchronized void starting node crypto crypto2 if crypto null throw new illegal state exception replacing existing node crypto crypto with crypto2 crypto crypto2 option_count nodecrypto illegalstateexception nodecrypto synchronized void started node crypto crypto2 if crypto null throw new illegal state exception replacing existing node crypto crypto with crypto2 nodecrypto illegalstateexception nodecrypto synchronized void maybe started node crypto crypto2 maybestarted nodecrypto synchronized void stopping node crypto crypto2 crypto null nodecrypto public synchronized int get port return port number getport portnumber class node bindto callback extends string callback override public string get return bind to to string nodebindtocallback stringcallback bindto tostring override public void set string val throws invalid config value exception if val equals get return fixme why not can t we use freenet io network interface like everywhere else just adapt it for udp throw new invalid config value exception cannot be updated on the fly invalidconfigvalueexception networkinterface invalidconfigvalueexception throw new invalid config value exception cannot be updated on the fly override public boolean is read only return true invalidconfigvalueexception isreadonly public synchronized freenet inet address get bind to return bind to freenetinetaddress getbindto bindto public synchronized void set port int port port number port setport portnumber public synchronized int get drop probability return drop probability getdropprobability dropprobability public synchronized boolean one connection per address return one connection per address oneconnectionperaddress oneconnectionperaddress public synchronized boolean always allow local addresses return always allow local addresses alwaysallowlocaladdresses alwaysallowlocaladdresses public boolean always handshake aggressively return assumena ted alwayshandshakeaggressively assumenated public boolean include local addresses in noderefs return include local addresses in noderefs includelocaladdressesinnoderefs includelocaladdressesinnoderefs public boolean padd data packets return padd data packets padddatapackets padddatapackets protected string name public string get name return name getname protected void set name string s name s length 0 s l10n get string bookmark no name setname getstring noname override public boolean equals object o if o this return true if o instanceof bookmark bookmark b bookmark o if b name equals name return false return true else return false override public int hash code return name hash code hashcode hashcode public abstract simple field set get simple field set simplefieldset getsimplefieldset private static final long serial versionuid 1l public no such identity exception super serialversionuid nosuchidentityexception public no such identity exception string id super unknown identity id id nosuchidentityexception override public boolean equals object o if o instanceof ssk block return false ssk block block ssk block o if block pub key equals pub key return false if block node key equals node key return false if block headers offset headers offset return false if block hash identifier hash identifier return false if block sym cipher identifier sym cipher identifier return false only compare some of the headers see top for int i 0 i header compare to i if block headers i headers i return false if arrays equals block headers headers return false if arrays equals block data data return false return true sskblock sskblock sskblock pubkey pubkey nodekey nodekey headersoffset headersoffset hashidentifier hashidentifier symcipheridentifier symcipheridentifier header_compare_to override public int hash code return hash code hashcode hashcode initialize and verify data headers against key provided key must have a pubkey or we throw public ssk block byte data byte headers nodessk node key boolean dont verify throws ssk verify exception if headers length total headers length throw new illegal argument exception headers length headers length should be total headers length this data data this headers headers this node key node key if data length data length throw new ssk verify exception data length wrong data length should be data length this pub key node key get pub key if pub key null throw new ssk verify exception pub key was null from node key message digest md sha256 get message digest now verify it hash identifier short headers 0 0xff 8 headers 1 0xff if hash identifier hash sha256 throw new ssk verify exception hash not sha 256 int x 2 sym cipher identifier short headers x 0xff 8 headers x 1 0xff x 2 then e h docname byte eh docname new byte e h docname length system arraycopy headers x eh docname 0 eh docname length x e h docname length headers offset x is index to start of encrypted headers x encrypted headers length extract the signature byte bufr new byte sig r length byte bufs new byte sig s length if x sig r length sig s length headers length throw new ssk verify exception headers too short headers length should be at least x sig r length sig s length if dont verify system arraycopy headers x bufr 0 sig r length x sig r length if dont verify system arraycopy headers x bufs 0 sig s length x sig s length compute the hash on the data if dont verify md update data byte data hash md digest all headers up to and not including the signature md update headers 0 headers offset encrypted headers length then the implicit data hash md update data hash makes the implicit overall hash byte overall hash md digest now verify it native big integer r new native big integer 1 bufr native big integer s new native big integer 1 bufs if dsa verify pub key new dsa signature r s new native big integer 1 overall hash false dsa verify pub key new dsa signature r s new native big integer 1 overall hash true throw new ssk verify exception signature verification failed for node level ssk if arrays equals eh docname node key encrypted hashed docname throw new ssk verify exception e h docname wrong wrong key nfrom headers hex util bytes to hex eh docname nfrom key hex util bytes to hex node key encrypted hashed docname sha256 return message digest md hash code fields hash code data fields hash code headers node key hash code pub key hash code hash identifier sskblock nodekey dontverify sskverifyexception total_headers_length illegalargumentexception total_headers_length nodekey nodekey data_length sskverifyexception data_length pubkey nodekey getpubkey pubkey sskverifyexception pubkey nodekey messagedigest getmessagedigest hashidentifier hashidentifier hash_sha256 sskverifyexception symcipheridentifier ehdocname e_h_docname_length ehdocname ehdocname e_h_docname_length headersoffset encrypted_headers_length sig_r_length sig_s_length sig_r_length sig_s_length sskverifyexception sig_r_length sig_s_length dontverify sig_r_length sig_r_length dontverify sig_s_length sig_s_length dontverify datahash headersoffset encrypted_headers_length datahash overallhash nativebiginteger nativebiginteger nativebiginteger nativebiginteger pubkey dsasignature nativebiginteger overallhash pubkey dsasignature nativebiginteger overallhash sskverifyexception ehdocname nodekey encryptedhasheddocname sskverifyexception hexutil bytestohex ehdocname hexutil bytestohex nodekey encryptedhasheddocname returnmessagedigest hashcode hashcode hashcode nodekey hashcode pubkey hashcode hashidentifier public key get key return node key getkey nodekey public byte get raw headers return headers getrawheaders public byte get raw data return data getrawdata public dsa public key get pub key return pub key dsapublickey getpubkey pubkey public byte get pubkey bytes return pub key as bytes getpubkeybytes pubkey asbytes public byte get full key return get key get full key getfullkey getkey getfullkey public byte get routing key return get key get routing key getroutingkey getkey getroutingkey public boolean object can new object container container storing an ssk block is not supported there are some complications so lets not implement this since we don t actually use the functionality atm the major problems are in both chk block and ssk block who is responsible for deleting the node keys we have to have them in the objects in ssk block who is responsible for deleting the dsa public key and the dsa group a group might be unique or might be shared between very many ss ks especially in the second case we don t want to just copy every time even for transient uses the best solution may be to copy in object can new but even then callers to the relevant getter methods may be a worry throw new unsupported operation exception block set storage in database not supported objectcannew objectcontainer sskblock chkblock sskblock sskblock dsapublickey dsagroup ssks objectcannew unsupportedoperationexception public plugin talker fred plugin talker fpt node node2 string pluginname2 string connection identifier throws plugin not found exception node node2 plugin name pluginname2 plugin find plugin pluginname2 access fred pluginfcp access direct replysender new plugin reply sender direct node2 fpt pluginname2 connection identifier plugintalker fredplugintalker connectionidentifier pluginnotfoundexception pluginname findplugin fredpluginfcp access_direct pluginreplysenderdirect connectionidentifier public plugin talker node node2 fcp connection handler handler string pluginname2 string connection identifier boolean access2 throws plugin not found exception node node2 plugin name pluginname2 plugin find plugin pluginname2 access access2 fred pluginfcp access fcp full fred pluginfcp access fcp restricted replysender new plugin reply senderfcp handler pluginname2 connection identifier plugintalker fcpconnectionhandler connectionidentifier pluginnotfoundexception pluginname findplugin fredpluginfcp access_fcp_full fredpluginfcp access_fcp_restricted pluginreplysenderfcp connectionidentifier protected fred pluginfcp find plugin string pluginname2 throws plugin not found exception logger normal this searching fcp plugin pluginname2 fred pluginfcp plug node plugin manager getfcp plugin pluginname2 if plug null logger error this could not find fcp plugin pluginname2 throw new plugin not found exception logger normal this found fcp plugin pluginname2 return plug fredpluginfcp findplugin pluginnotfoundexception fredpluginfcp pluginmanager getfcpplugin pluginnotfoundexception public void send final simple field set plugparams final bucket data2 node executor execute new runnable public void run try plugin handle replysender plugparams data2 access catch thread death td throw td fatal thread is stop ed catch virtual machine error vme throw vme oom is included here catch throwable t logger error this cought error while execute fcp plugin handler for plugin name report it to the plugin author t get message t fcp plugin talk runner for this simplefieldset threaddeath virtualmachineerror pluginname getmessage fcpplugin public void run try plugin handle replysender plugparams data2 access catch thread death td throw td fatal thread is stop ed catch virtual machine error vme throw vme oom is included here catch throwable t logger error this cought error while execute fcp plugin handler for plugin name report it to the plugin author t get message t threaddeath virtualmachineerror pluginname getmessage override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog create a single block inserter param parent param data param compression codec the compression codec param uri param ctx param cb param is metadata param source length the length of the original uncompressed data param token param getchk only param add to parent param dont send encoded param token object param container param context param persistent param free data public single block inserter base client putter parent bucket data short compression codec freeneturi uri insert context ctx put completion callback cb boolean is metadata int source length int token boolean getchk only boolean add to parent boolean dont send encoded object token object object container container client context context boolean persistent boolean free data super persistent assert persistent parent persistent this consecutivern fs 0 this token object token object this token token this parent parent this dont send encoded dont send encoded this retries 0 this finished false this ctx ctx this free data free data errors new failure code tracker true this cb cb this uri uri this compression codec compression codec this source data data if source data null throw new null pointer exception this is metadata is metadata this source length source length this getchk only getchk only isssk uri get key type to upper case equals ssk if add to parent parent add block container parent add must succeed blocks 1 container parent notify clients container context singleblockinserter compressioncodec ismetadata sourcelength getchkonly addtoparent dontsendencoded tokenobject freedata singleblockinserter baseclientputter compressioncodec insertcontext putcompletioncallback ismetadata sourcelength getchkonly addtoparent dontsendencoded tokenobject objectcontainer clientcontext freedata consecutivernfs tokenobject tokenobject dontsendencoded dontsendencoded freedata freedata failurecodetracker compressioncodec compressioncodec sourcedata sourcedata nullpointerexception ismetadata ismetadata sourcelength sourcelength getchkonly getchkonly getkeytype touppercase addtoparent addblock addmustsucceedblocks notifyclients protected client key block inner encode random source random object container container throws insert exception if persistent container activate uri 1 container activate source data 1 try return inner encode random uri source data is metadata compression codec source length catch key encode exception e logger error single block inserter class caught e e throw new insert exception insert exception internal error e null catch malformedurl exception e throw new insert exception insert exception invalid uri e null catch io exception e logger error single block inserter class caught e encoding data source data e throw new insert exception insert exception bucket error e null clientkeyblock innerencode randomsource objectcontainer insertexception sourcedata innerencode sourcedata ismetadata compressioncodec sourcelength keyencodeexception singleblockinserter insertexception insertexception internal_error malformedurlexception insertexception insertexception invalid_uri ioexception singleblockinserter sourcedata insertexception insertexception bucket_error protected static client key block inner encode random source random freeneturi uri bucket source data boolean is metadata short compression codec int source length throws insert exception chk encode exception io exception ssk encode exception malformedurl exception string uri type uri get key type if uri type equals chk return clientchk block encode source data is metadata compression codec 1 compression codec source length else if uri type equals ssk uri type equals ksk insertable clientssk ik insertable clientssk create uri return ik encode source data is metadata compression codec 1 compression codec source length random else throw new insert exception insert exception invalid uri unknown keytype uri type null clientkeyblock innerencode randomsource sourcedata ismetadata compressioncodec sourcelength insertexception chkencodeexception ioexception sskencodeexception malformedurlexception uritype getkeytype uritype clientchkblock sourcedata ismetadata compressioncodec compressioncodec sourcelength uritype uritype insertableclientssk insertableclientssk sourcedata ismetadata compressioncodec compressioncodec sourcelength insertexception insertexception invalid_uri uritype protected void on encode client key key object container container client context context synchronized this if finished return if resultinguri null return resultinguri key geturi if persistent container store this container activate cb 1 cb on encode key this container context if persistent container deactivate cb 1 onencode clientkey objectcontainer clientcontext onencode protected client key block encode object container container client context context boolean called bycb throws insert exception if persistent container activate source data 1 container activate cb 1 client key block block boolean should send synchronized this if finished return null if source data null logger error this source data is null on this but not finished return null block inner encode context random container should send resultinguri null resultinguri block get client key geturi if logminor logger minor this encoded resultinguri for this should send should send dont send encoded dont send encoded if should send dont send encoded cb on encode block get client key this container context if should send persistent container store this if persistent called bycb container deactivate cb 1 return block clientkeyblock objectcontainer clientcontext calledbycb insertexception sourcedata clientkeyblock shouldsend sourcedata innerencode shouldsend getclientkey shouldsend shouldsend dontsendencoded dontsendencoded shouldsend dontsendencoded onencode getclientkey shouldsend calledbycb override public short get priority class object container container if persistent container activate parent 1 return parent get priority class not much point deactivating getpriorityclass objectcontainer getpriorityclass override public int get retry count return retries getretrycount override public void on failure low level put exception e object key num object container container client context context synchronized this if finished return if persistent container activate errors 1 if parent is cancelled fail new insert exception insert exception cancelled container context return if logminor logger minor this on failure on e for this switch e code case low level put exception collision fail new insert exception insert exception collision container context return case low level put exception internal error fail new insert exception insert exception internal error container context return case low level put exception rejected overload errors inc insert exception rejected overload break case low level put exception route not found errors inc insert exception route not found break case low level put exception route really not found errors inc insert exception route really not found break default logger error this unknown low level put exception code e code errors inc insert exception internal error if persistent container activate ctx 1 if e code low level put exception route not found e code low level put exception route really not found consecutivern fs if logminor logger minor this consecutive rn fs consecutivern fs ctx consecutivern fs count as success if consecutivern fs ctx consecutivern fs count as success if logminor logger minor this consecutive rn fs consecutivern fs counting as success on success key num container context return else consecutivern fs 0 if logminor logger minor this failed e retries if retries ctx max insert retries ctx max insert retries 1 fail insert exception construct persistent errors clone errors container context if persistent container deactivate ctx 1 return if persistent container store this container deactivate ctx 1 get scheduler context register insert this persistent false true container onfailure lowlevelputexception keynum objectcontainer clientcontext iscancelled insertexception insertexception onfailure lowlevelputexception insertexception insertexception lowlevelputexception internal_error insertexception insertexception internal_error lowlevelputexception rejected_overload insertexception rejected_overload lowlevelputexception route_not_found insertexception route_not_found lowlevelputexception route_really_not_found insertexception route_really_not_found lowlevelputexception insertexception internal_error lowlevelputexception route_not_found lowlevelputexception route_really_not_found consecutivernfs rnfs consecutivernfs consecutivernfscountassuccess consecutivernfs consecutivernfscountassuccess rnfs consecutivernfs onsuccess keynum consecutivernfs maxinsertretries maxinsertretries insertexception getscheduler registerinsert private void fail insert exception e object container container client context context fail e false container context insertexception objectcontainer clientcontext private void fail insert exception e boolean force fatal object container container client context context synchronized this if finished return finished true if persistent container store this if e is fatal force fatal parent fatally failed block container context else parent failed block container context unregister container context if free data if persistent container activate source data 1 source data free if persistent source data remove from container source data null if persistent container store this if persistent container activate cb 1 cb on failure e this container context insertexception forcefatal objectcontainer clientcontext isfatal forcefatal fatallyfailedblock failedblock freedata sourcedata sourcedata sourcedata removefrom sourcedata onfailure public client key block get block object container container client context context boolean called bycb try synchronized this if finished return null if persistent container store this return encode container context called bycb catch insert exception e if persistent container activate cb 1 cb on failure e this container context if persistent called bycb container deactivate cb 1 return null catch throwable t if persistent container activate cb 1 logger error this caught t t cb on failure new insert exception insert exception internal error t null this container context if persistent called bycb container deactivate cb 1 return null clientkeyblock getblock objectcontainer clientcontext calledbycb calledbycb insertexception onfailure calledbycb onfailure insertexception insertexception internal_error calledbycb public void schedule object container container client context context throws insert exception synchronized this if finished if logminor logger minor this finished already this return if getchk only boolean deactivatecb false if persistent deactivatecb container ext is active cb if deactivatecb container activate cb 1 container activate parent 1 client key block block encode container context true cb on encode block get client key this container context parent completed block false container context cb on success this container context finished true if persistent container store this if deactivatecb container deactivate cb 1 else get scheduler context register insert this persistent true true container objectcontainer clientcontext insertexception getchkonly isactive clientkeyblock onencode getclientkey completedblock onsuccess getscheduler registerinsert override public boolean isssk return isssk public freeneturi geturi object container container client context context synchronized this if resultinguri null if persistent container activate resultinguri 5 return persistent resultinguri clone resultinguri get block container context true synchronized this fixme not really necessary resultinguri is never dropped only set if persistent container activate resultinguri 5 return persistent resultinguri clone resultinguri objectcontainer clientcontext getblock public synchronized freeneturi geturi no encode return resultinguri geturinoencode override public void on success object key num object container container client context context if logminor logger minor this succeeded this token if persistent container activate parent 1 if parent is cancelled fail new insert exception insert exception cancelled container context return synchronized this if finished normal with persistence logger normal this block already completed this return finished true if persistent container store this container activate source data 1 if free data source data free if persistent source data remove from container source data null if persistent container store this parent completed block false container context unregister container context if persistent container activate cb 1 if logminor logger minor this calling on success for cb cb on success this container context if persistent container deactivate cb 1 onsuccess keynum objectcontainer clientcontext iscancelled insertexception insertexception sourcedata freedata sourcedata sourcedata removefrom sourcedata completedblock onsuccess onsuccess public base client putter get parent return parent baseclientputter getparent public void cancel object container container client context context synchronized this if finished return finished true boolean was active true if persistent container store this was active container ext is active cb if was active container activate cb 1 container activate source data 1 if free data source data free if persistent source data remove from container source data null if persistent container store this super unregister container context cb on failure new insert exception insert exception cancelled this container context if was active container deactivate cb 1 objectcontainer clientcontext wasactive wasactive isactive wasactive sourcedata freedata sourcedata sourcedata removefrom sourcedata onfailure insertexception insertexception wasactive public synchronized boolean is empty object container container return finished isempty objectcontainer override public synchronized boolean is cancelled object container container return finished iscancelled objectcontainer override public sendable request sender get sender object container container client context context return new sendable request sender public boolean send node client core core request scheduler sched final client context context chosen block req ignore key num key since we re only sending one block client key block b client key key null if logminor logger minor this starting request single block inserter this block item block block item req token try try b inner encode context random block uri block copy bucket block is metadata block compression codec block source length catch chk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch ssk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch malformedurl exception e throw new low level put exception low level put exception internal error e to string e get message e catch insert exception e throw new low level put exception low level put exception internal error e to string e get message e catch io exception e throw new low level put exception low level put exception internal error e to string e get message e if b null logger error this asked to send empty block on single block inserter this new exception error return false key b get client key final client key k key if block persistent context job runner queue new db job public void run object container container client context context if container ext is stored single block inserter this return container activate single block inserter this 1 on encode k container context container deactivate single block inserter this 1 native thread norm priority 1 false else context main executor execute new runnable public void run on encode k null context got uri core real put b req cache local requests catch low level put exception e if e code low level put exception collision collision try clientssk block collided clientssk block core node fetch clientssk key true byte data collided memory decode true byte inserting bucket tools to byte array block copy bucket if collided is metadata block is metadata collided get compression codec block compression codec arrays equals data inserting if logminor logger minor this collided with identical data single block inserter this req on insert success context return true catch key verify exception e1 logger error this caught e1 when checking collision e1 catch key decode exception e1 logger error this caught e1 when checking collision e1 catch io exception e1 logger error this caught e1 when checking collision e1 req on failure e context if logminor logger minor this request failed single block inserter this for e return true finally block copy bucket free if logminor logger minor this request succeeded single block inserter this req on insert success context return true sendablerequestsender getsender objectcontainer clientcontext sendablerequestsender nodeclientcore requestscheduler clientcontext chosenblock keynum clientkeyblock clientkey singleblockinserter blockitem blockitem innerencode copybucket ismetadata compressioncodec sourcelength chkencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage sskencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage malformedurlexception lowlevelputexception lowlevelputexception internal_error tostring getmessage insertexception lowlevelputexception lowlevelputexception internal_error tostring getmessage ioexception lowlevelputexception lowlevelputexception internal_error tostring getmessage singleblockinserter getclientkey clientkey jobrunner dbjob objectcontainer clientcontext isstored singleblockinserter singleblockinserter onencode singleblockinserter nativethread norm_priority mainexecutor onencode realput cachelocalrequests lowlevelputexception lowlevelputexception clientsskblock clientsskblock memorydecode buckettools tobytearray copybucket ismetadata ismetadata getcompressioncodec compressioncodec singleblockinserter oninsertsuccess keyverifyexception keydecodeexception ioexception onfailure singleblockinserter copybucket singleblockinserter oninsertsuccess public boolean send node client core core request scheduler sched final client context context chosen block req ignore key num key since we re only sending one block client key block b client key key null if logminor logger minor this starting request single block inserter this block item block block item req token try try b inner encode context random block uri block copy bucket block is metadata block compression codec block source length catch chk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch ssk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch malformedurl exception e throw new low level put exception low level put exception internal error e to string e get message e catch insert exception e throw new low level put exception low level put exception internal error e to string e get message e catch io exception e throw new low level put exception low level put exception internal error e to string e get message e if b null logger error this asked to send empty block on single block inserter this new exception error return false key b get client key final client key k key if block persistent context job runner queue new db job public void run object container container client context context if container ext is stored single block inserter this return container activate single block inserter this 1 on encode k container context container deactivate single block inserter this 1 native thread norm priority 1 false else context main executor execute new runnable public void run on encode k null context got uri core real put b req cache local requests catch low level put exception e if e code low level put exception collision collision try clientssk block collided clientssk block core node fetch clientssk key true byte data collided memory decode true byte inserting bucket tools to byte array block copy bucket if collided is metadata block is metadata collided get compression codec block compression codec arrays equals data inserting if logminor logger minor this collided with identical data single block inserter this req on insert success context return true catch key verify exception e1 logger error this caught e1 when checking collision e1 catch key decode exception e1 logger error this caught e1 when checking collision e1 catch io exception e1 logger error this caught e1 when checking collision e1 req on failure e context if logminor logger minor this request failed single block inserter this for e return true finally block copy bucket free if logminor logger minor this request succeeded single block inserter this req on insert success context return true nodeclientcore requestscheduler clientcontext chosenblock keynum clientkeyblock clientkey singleblockinserter blockitem blockitem innerencode copybucket ismetadata compressioncodec sourcelength chkencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage sskencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage malformedurlexception lowlevelputexception lowlevelputexception internal_error tostring getmessage insertexception lowlevelputexception lowlevelputexception internal_error tostring getmessage ioexception lowlevelputexception lowlevelputexception internal_error tostring getmessage singleblockinserter getclientkey clientkey jobrunner dbjob objectcontainer clientcontext isstored singleblockinserter singleblockinserter onencode singleblockinserter nativethread norm_priority mainexecutor onencode realput cachelocalrequests lowlevelputexception lowlevelputexception clientsskblock clientsskblock memorydecode buckettools tobytearray copybucket ismetadata ismetadata getcompressioncodec compressioncodec singleblockinserter oninsertsuccess keyverifyexception keydecodeexception ioexception onfailure singleblockinserter copybucket singleblockinserter oninsertsuccess public void run object container container client context context if container ext is stored single block inserter this return container activate single block inserter this 1 on encode k container context container deactivate single block inserter this 1 objectcontainer clientcontext isstored singleblockinserter singleblockinserter onencode singleblockinserter context main executor execute new runnable public void run on encode k null context mainexecutor onencode override public request client get client object container container if persistent container activate parent 1 return parent get client requestclient getclient objectcontainer getclient override public client requester get client request return parent clientrequester getclientrequest public object get token return token object gettoken tokenobject attempt to encode the block if necessary public void try encode object container container client context context synchronized this if resultinguri null return if finished return try encode container context false catch insert exception e fail e container context catch throwable t logger error this caught t t don t requeue on background block encoder not necessary to do so we ll ask again when we need it and it ll probably just break again tryencode objectcontainer clientcontext insertexception backgroundblockencoder override public synchronized long count sendable keys object container container client context context if finished return 0 else return 1 countsendablekeys objectcontainer clientcontext override public synchronized long count all keys object container container client context context return count sendable keys container context countallkeys objectcontainer clientcontext countsendablekeys override public synchronized sendable request item choose key keys fetching locally ignored object container container client context context if finished return null if persistent if ignored has transient insert this new fake block item return null return get block item container context sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext hastransientinsert fakeblockitem getblockitem private block item get block item object container container client context context try synchronized this if finished return null if persistent if source data null logger error this get block item source data null but active container ext is active this return null boolean deactivate bucket false if persistent container activate uri 1 deactivate bucket container ext is active source data if deactivate bucket container activate source data 1 bucket data source data create shadow freeneturi u uri if u get key type equals chk persistent u freeneturi empty chk uri else u u clone if data null data context temp bucket factory make bucket source data size bucket tools copy source data data if persistent if deactivate bucket container deactivate source data 1 container deactivate uri 1 return new block item this data is metadata compression codec source length u hash code persistent catch io exception e fail new insert exception insert exception bucket error e null container context return null blockitem getblockitem objectcontainer clientcontext sourcedata getblockitem sourcedata isactive deactivatebucket deactivatebucket isactive sourcedata deactivatebucket sourcedata sourcedata createshadow getkeytype empty_chk_uri tempbucketfactory makebucket sourcedata buckettools sourcedata deactivatebucket sourcedata blockitem ismetadata compressioncodec sourcelength hashcode ioexception insertexception insertexception bucket_error override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context block item item get block item container context if item null return null persistent chosen block block new persistent chosen block true request item null null sched return collections singleton list block persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext blockitem getblockitem persistentchosenblock persistentchosenblock singletonlist block item single block inserter parent bucket bucket boolean meta short codec int srclen freeneturi u int hash code boolean persistent throws io exception this parent parent this copy bucket bucket this is metadata meta this compression codec codec this source length srclen this uri u this hash code hash code this persistent persistent blockitem singleblockinserter hashcode ioexception copybucket ismetadata compressioncodec sourcelength hashcode hashcode public void dump copy bucket free copybucket override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof block item if block item o parent parent return true else if o instanceof fake block item if fake block item o get parent parent return true return false blockitem blockitem fakeblockitem fakeblockitem getparent private class fake block item implements sendable request item public void dump do nothing fakeblockitem sendablerequestitem public single block inserter get parent return single block inserter this singleblockinserter getparent singleblockinserter override public int hash code return single block inserter this hash code hashcode singleblockinserter hashcode override public boolean equals object o if o instanceof block item if block item o parent single block inserter this return true else if o instanceof fake block item if fake block item o get parent single block inserter this return true return false blockitem blockitem singleblockinserter fakeblockitem fakeblockitem getparent singleblockinserter public void remove from object container container client context context if logminor logger minor this remove from on this container activate uri 5 uri remove from container if resultinguri null container activate resultinguri 5 resultinguri remove from container cb parent are responsible for removing themselves ctx is passed in and unmodified usually the client putter removes it container activate errors 5 errors remove from container if free data source data null container ext is stored source data logger error this data not removed container activate source data 1 source data remove from container container delete this removefrom objectcontainer clientcontext removefrom removefrom removefrom clientputter removefrom freedata sourcedata isstored sourcedata sourcedata sourcedata removefrom override public boolean cache inserts object container container boolean deactivate false if persistent deactivate container ext is active ctx if deactivate container activate ctx 1 boolean retval ctx cache local requests if deactivate container deactivate ctx 1 return retval cacheinserts objectcontainer isactive cachelocalrequests public boolean object can new object container container if finished logger error this object can new when already finished on this return false if logdebug logger debug this object can new on this new exception debug return true objectcannew objectcontainer objectcannew objectcannew private insert exception error public void on success fetch result result client getter state object container container ignore insertexception onsuccess fetchresult clientgetter objectcontainer public void on failure fetch exception e client getter state object container container ignore onfailure fetchexception clientgetter objectcontainer public synchronized void on success base client putter state object container container succeeded true finished true notify all onsuccess baseclientputter objectcontainer notifyall public synchronized void on failure insert exception e base client putter state object container container error e finished true notify all onfailure insertexception baseclientputter objectcontainer notifyall public synchronized void on generateduri freeneturi uri base client putter state object container container if logger should log logger minor this logger minor this uri uri if this uri null this uri uri if uri equals this uri return logger error this uri already set this uri but new uri uri new exception error ongenerateduri baseclientputter objectcontainer shouldlog public synchronized freeneturi wait for completion throws insert exception while finished try wait catch interrupted exception e ignore if error null error uri uri throw error if succeeded return uri logger error this did not succeed but no error throw new insert exception insert exception internal error did not succeed but no error uri waitforcompletion insertexception interruptedexception insertexception insertexception internal_error public void on major progress object container container ignore onmajorprogress objectcontainer public void on fetchable base client putter state object container container ignore onfetchable baseclientputter objectcontainer public client context node client core core fec queue fec queue executor main executor background block encoder block encoder archive manager archive manager persistent temp bucket factory ptbf bucket factory tbf healing queue hq usk manager usk manager random source strong random random fast weak random ticker ticker filename generator fg filename generator persistentfg real compressor rc this bootid core node bootid this fec queue fec queue job runner core this main executor main executor this nodedb handle core node nodedb handle this background block encoder block encoder this random strong random this archive manager archive manager this persistent bucket factory ptbf if persistent bucket factory null throw new null pointer exception this temp bucket factory tbf if temp bucket factory null throw new null pointer exception this healing queue hq this usk manager usk manager this fast weak random fast weak random this ticker ticker this fg fg this persistentfg persistentfg this rc rc clientcontext nodeclientcore fecqueue fecqueue mainexecutor backgroundblockencoder blockencoder archivemanager archivemanager persistenttempbucketfactory bucketfactory healingqueue uskmanager uskmanager randomsource strongrandom fastweakrandom filenamegenerator filenamegenerator realcompressor fecqueue fecqueue jobrunner mainexecutor mainexecutor nodedbhandle nodedbhandle backgroundblockencoder blockencoder strongrandom archivemanager archivemanager persistentbucketfactory persistentbucketfactory nullpointerexception tempbucketfactory tempbucketfactory nullpointerexception healingqueue uskmanager uskmanager fastweakrandom fastweakrandom public void init request starter group starters this ssk fetch scheduler starters ssk fetch scheduler this chk fetch scheduler starters chk fetch scheduler this ssk insert scheduler starters ssk put scheduler this chk insert scheduler starters chk put scheduler requeststartergroup sskfetchscheduler sskfetchscheduler chkfetchscheduler chkfetchscheduler sskinsertscheduler sskputscheduler chkinsertscheduler chkputscheduler public client request scheduler get ssk fetch scheduler return ssk fetch scheduler clientrequestscheduler getsskfetchscheduler sskfetchscheduler public client request scheduler get chk fetch scheduler return chk fetch scheduler clientrequestscheduler getchkfetchscheduler chkfetchscheduler public client request scheduler get ssk insert scheduler return ssk insert scheduler clientrequestscheduler getsskinsertscheduler sskinsertscheduler public client request scheduler get chk insert scheduler return chk insert scheduler clientrequestscheduler getchkinsertscheduler chkinsertscheduler public void start final client putter inserter final boolean early encode throws insert exception if inserter persistent job runner queue new db job public void run object container container client context context container activate inserter 1 try inserter start early encode false container context catch insert exception e inserter client on failure e inserter container container deactivate inserter 1 native thread norm priority false else inserter start early encode false null this clientputter earlyencode insertexception jobrunner dbjob objectcontainer clientcontext earlyencode insertexception onfailure nativethread norm_priority earlyencode public void run object container container client context context container activate inserter 1 try inserter start early encode false container context catch insert exception e inserter client on failure e inserter container container deactivate inserter 1 objectcontainer clientcontext earlyencode insertexception onfailure public void start final client getter getter throws fetch exception if getter persistent job runner queue new db job public void run object container container client context context container activate getter 1 try getter start container context catch fetch exception e getter client callback on failure e getter container container deactivate getter 1 native thread norm priority false else getter start null this clientgetter fetchexception jobrunner dbjob objectcontainer clientcontext fetchexception clientcallback onfailure nativethread norm_priority public void run object container container client context context container activate getter 1 try getter start container context catch fetch exception e getter client callback on failure e getter container container deactivate getter 1 objectcontainer clientcontext fetchexception clientcallback onfailure public void start final simple manifest putter inserter throws insert exception if inserter persistent job runner queue new db job public void run object container container client context context container activate inserter 1 try inserter start container context catch insert exception e inserter cb on failure e inserter container container deactivate inserter 1 native thread norm priority false else inserter start null this simplemanifestputter insertexception jobrunner dbjob objectcontainer clientcontext insertexception onfailure nativethread norm_priority public void run object container container client context context container activate inserter 1 try inserter start container context catch insert exception e inserter cb on failure e inserter container container deactivate inserter 1 objectcontainer clientcontext insertexception onfailure public void start final base manifest putter inserter throws insert exception if inserter persistent job runner queue new db job public void run object container container client context context container activate inserter 1 try inserter start container context catch insert exception e inserter cb on failure e inserter container container deactivate inserter 1 native thread norm priority false else inserter start null this basemanifestputter insertexception jobrunner dbjob objectcontainer clientcontext insertexception onfailure nativethread norm_priority public void run object container container client context context container activate inserter 1 try inserter start container context catch insert exception e inserter cb on failure e inserter container container deactivate inserter 1 objectcontainer clientcontext insertexception onfailure public bucket factory get bucket factory boolean persistent if persistent return persistent bucket factory else return temp bucket factory bucketfactory getbucketfactory persistentbucketfactory tempbucketfactory public request scheduler get fetch scheduler boolean ssk if ssk return ssk fetch scheduler return chk fetch scheduler requestscheduler getfetchscheduler sskfetchscheduler chkfetchscheduler public boolean object can new object container container logger error this not storing client context in database new exception error return false objectcannew objectcontainer clientcontext public string arr option sub config conf string option name string default value int sort order boolean expert boolean force write string short desc string long desc string arr callback cb super conf option name cb sort order expert force write short desc long desc option data type string array this default value default value null new string 0 default value this current value default value null new string 0 default value stringarroption subconfig optionname defaultvalue sortorder forcewrite shortdesc longdesc stringarrcallback optionname sortorder forcewrite shortdesc longdesc datatype string_array defaultvalue defaultvalue defaultvalue currentvalue defaultvalue defaultvalue override public string parse string string val throws invalid config value exception if val length 0 return new string 0 string out val split delimiter try for int i 0 i out length i if out i equals out i else out i url decoder decode out i true fixme false catch url encoded format exception e throw new invalid config value exception l10n parse error error e get localized message return out parsestring invalidconfigvalueexception urldecoder urlencodedformatexception invalidconfigvalueexception parseerror getlocalizedmessage public void set initial value string val throws invalid config value exception this current value val setinitialvalue invalidconfigvalueexception currentvalue private string l10n string key string pattern string value return l10n get string string arr option key pattern value getstring stringarroption override public string to string string arr if arr null return null string builder sb new string builder for int i 0 i arr length i string val arr i if val length 0 sb append append delimiter else sb append url encoder encode arr i false append delimiter if sb length 0 sb set length sb length 1 drop surplus delimiter return sb to string tostring stringbuilder stringbuilder urlencoder setlength tostring public static string decode string s try return url decoder decode s false catch url encoded format exception e return null urldecoder urlencodedformatexception override public boolean is default get value return current value null false arrays equals current value default value isdefault getvalue currentvalue currentvalue defaultvalue private int levels 256 public oil filter oilfilter set the range of the effect in pixels param range the range see get range public void set range int range this range range getrange setrange get the range of the effect in pixels return the range see set range public int get range return range setrange getrange set the number of levels for the effect param levels the number of levels see get levels public void set levels int levels this levels levels getlevels setlevels get the number of levels for the effect return the number of levels see set levels public int get levels return levels setlevels getlevels override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int r histogram new int levels int g histogram new int levels int b histogram new int levels int r total new int levels int g total new int levels int b total new int levels int out pixels new int width height for int y 0 y height y for int x 0 x width x for int i 0 i levels i r histogram i g histogram i b histogram i r total i g total i b total i 0 for int row range row range row int iy y row int ioffset if 0 iy iy height ioffset iy width for int col range col range col int ix x col if 0 ix ix width int rgb in pixels ioffset ix int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int ri r levels 256 int gi g levels 256 int bi b levels 256 r total ri r g total gi g b total bi b r histogram ri g histogram gi b histogram bi int r 0 g 0 b 0 for int i 1 i levels i if r histogram i r histogram r r i if g histogram i g histogram g g i if b histogram i b histogram b b i r r total r r histogram r g g total g g histogram g b b total b b histogram b out pixels index 0xff000000 r 16 g 8 b return out pixels filterpixels inpixels transformedspace rhistogram ghistogram bhistogram rtotal gtotal btotal outpixels rhistogram ghistogram bhistogram rtotal gtotal btotal inpixels rtotal gtotal btotal rhistogram ghistogram bhistogram rhistogram rhistogram ghistogram ghistogram bhistogram bhistogram rtotal rhistogram gtotal ghistogram btotal bhistogram outpixels outpixels override public string to string return stylize oil tostring public class key decode exception extends exception private static final long serial versionuid 1 public key decode exception string message super message keydecodeexception serialversionuid keydecodeexception public key decode exception super keydecodeexception public key decode exception string message throwable cause super message cause keydecodeexception public key decode exception throwable cause super cause keydecodeexception public simple progress message string identifier boolean global splitfile progress event event this ident identifier this event event this global global simpleprogressmessage splitfileprogressevent override public simple field set get field set simple field set fs new simple field set true fs put total event total blocks fs put required event min successful blocks fs put failed event failed blocks fs put fatally failed event fatally failed blocks fs put succeeded event succeed blocks fs put finalized total event finalized total fs put single identifier ident if global fs put single global true return fs simplefieldset getfieldset simplefieldset simplefieldset totalblocks minsuccessfulblocks failedblocks fatallyfailed fatallyfailedblocks succeedblocks finalizedtotal finalizedtotal putsingle putsingle override public string get name return simple progress getname simpleprogress override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message simple progress goes from server to client not the other way around ident global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message simpleprogress public double get fraction return double event succeed blocks double event total blocks getfraction succeedblocks totalblocks public double get min blocks return event min successful blocks getminblocks minsuccessfulblocks public double get total blocks return event total blocks gettotalblocks totalblocks public double get fetched blocks return event succeed blocks getfetchedblocks succeedblocks public double get failed blocks return event failed blocks getfailedblocks failedblocks public double get fataly failed blocks return event fatally failed blocks getfatalyfailedblocks fatallyfailedblocks public boolean is total finalized return event finalized total istotalfinalized finalizedtotal override public void remove from object container container container activate event 1 event remove from container container delete this removefrom objectcontainer removefrom public class vector3f extends tuple3f public vector3f this 0 0 0 public vector3f float x this x x 0 this y x 1 this z x 2 public vector3f float x float y float z this x x this y y this z z public vector3f vector3f t this x t x this y t y this z t z public vector3f tuple3f t this x t x this y t y this z t z public float angle vector3f v return float math acos dot v length v length public float dot vector3f v return v x x v y y v z z public void cross vector3f v1 vector3f v2 x v1 y v2 z v1 z v2 y y v1 z v2 x v1 x v2 z z v1 x v2 y v1 y v2 x public float length return float math sqrt x x y y z z public void normalize float d 1 0f float math sqrt x x y y z z x d y d z d bookmark editor toadlet high level simple client client node client core core bookmark manager bookmarks super client this core core this bookmark manager bookmarks this cuted path null bookmarkeditortoadlet highlevelsimpleclient nodeclientcore bookmarkmanager bookmarkmanager cutedpath get all bookmark as a tree of lt li gt lt li gt s private void add category to list bookmark category cat string path html node list list bookmark item items cat get items final string edit l10n get string bookmark editor toadlet edit final string delete l10n get string bookmark editor toadlet delete final string cut l10n get string bookmark editor toadlet cut final string move up l10n get string bookmark editor toadlet move up final string move down l10n get string bookmark editor toadlet move down final string paste l10n get string bookmark editor toadlet paste final string add bookmark l10n get string bookmark editor toadlet add bookmark final string add category l10n get string bookmark editor toadlet add category for int i 0 i items size i bookmark item item items get i string item path url encoder encode path item get name false html node li new html node li class item item get name html node actions new html node span class actions actions add child a href action edit bookmark item path add child img new string src alt title new string static icon edit png edit edit actions add child a href action del bookmark item path add child img new string src alt title new string static icon delete png delete delete if cuted path null actions add child a href action cut bookmark item path add child img new string src alt title new string static icon cut png cut cut if i 0 actions add child a href action up bookmark item path add child img new string src alt title new string static icon go up png move up move up if i items size 1 actions add child a href action down bookmark item path add child img new string src alt title new string static icon go down png move down move down li add child actions list add child li list bookmark category cats cat get sub categories for int i 0 i cats size i string cat path path cats get i get name string cat path encoded url encoder encode cat path false html node sub cat list add child li class cat cats get i get name html node actions new html node span class actions actions add child a href action edit bookmark cat path encoded add child img new string src alt title new string static icon edit png edit edit actions add child a href action del bookmark cat path encoded add child img new string src alt title new string static icon delete png delete delete actions add child a href action add item bookmark cat path encoded add child img new string src alt title new string static icon bookmark new png add bookmark add bookmark actions add child a href action add cat bookmark cat path encoded add child img new string src alt title new string static icon folder new png add category add category if cuted path null actions add child a href action cut bookmark cat path encoded add child img new string src alt title new string static icon cut png cut cut if i 0 actions add child a href action up bookmark cat path encoded add child img new string src alt title new string static icon go up png move up move up if i cats size 1 actions add child a href action down bookmark cat path encoded add child img new string src alt title new string static icon go down png move down move down if cuted path null cat path encoded starts with cuted path cat path encoded equals bookmark manager parent path cuted path actions add child a href action paste bookmark cat path encoded add child img new string src alt title new string static icon paste png paste paste sub cat add child actions if cats get i size 0 add category to list cats get i cat path list add child li add child ul addcategorytolist bookmarkcategory htmlnode bookmarkitem getitems getstring bookmarkeditortoadlet getstring bookmarkeditortoadlet getstring bookmarkeditortoadlet moveup getstring bookmarkeditortoadlet moveup movedown getstring bookmarkeditortoadlet movedown getstring bookmarkeditortoadlet addbookmark getstring bookmarkeditortoadlet addbookmark addcategory getstring bookmarkeditortoadlet addcategory bookmarkitem itempath urlencoder getname htmlnode htmlnode getname htmlnode htmlnode addchild itempath addchild addchild itempath addchild cutedpath addchild itempath addchild addchild itempath addchild moveup moveup addchild itempath addchild movedown movedown addchild addchild bookmarkcategory getsubcategories catpath getname catpathencoded urlencoder catpath htmlnode subcat addchild getname htmlnode htmlnode addchild catpathencoded addchild addchild catpathencoded addchild addchild additem catpathencoded addchild addbookmark addbookmark addchild addcat catpathencoded addchild addcategory addcategory cutedpath addchild catpathencoded addchild addchild catpathencoded addchild moveup moveup addchild catpathencoded addchild movedown movedown cutedpath catpathencoded startswith cutedpath catpathencoded bookmarkmanager parentpath cutedpath addchild catpathencoded addchild subcat addchild addcategorytolist catpath addchild addchild public html node get bookmarks list html node bookmarks new html node ul id bookmarks html node root bookmarks add child li class cat root html node actions new html node span class actions string add bookmark l10n get string bookmark editor toadlet add bookmark string add category l10n get string bookmark editor toadlet add category string paste l10n get string bookmark editor toadlet paste actions add child a href action add item bookmark add child img new string src alt title new string static icon bookmark new png add bookmark add bookmark actions add child a href action add cat bookmark add child img new string src alt title new string static icon folder new png add category add category if cuted path null equals bookmark manager parent path cuted path actions add child a href action paste bookmark add child img new string src alt title new string static icon paste png paste paste root add child actions add category to list bookmark manager main category root add child ul return bookmarks htmlnode getbookmarkslist htmlnode htmlnode htmlnode addchild htmlnode htmlnode addbookmark getstring bookmarkeditortoadlet addbookmark addcategory getstring bookmarkeditortoadlet addcategory getstring bookmarkeditortoadlet addchild additem addchild addbookmark addbookmark addchild addcat addchild addcategory addcategory cutedpath bookmarkmanager parentpath cutedpath addchild addchild addchild addcategorytolist bookmarkmanager main_category addchild override public void handle get uri uri http request req toadlet context ctx throws toadlet context closed exception io exception page maker page maker ctx get page maker string editor title l10n get string bookmark editor toadlet title string error l10n get string bookmark editor toadlet error html node page node page maker get page node editor title ctx html node content page maker get content node page node string original bookmark req get param bookmark if req get param action length 0 original bookmark length 0 string action req get param action string bookmark path try bookmark path url decoder decode original bookmark false catch url encoded format exception e html node error box content add child page maker get infobox infobox error error page maker get content node error box add child l10n get string bookmark editor toadlet url decode error writehtml reply ctx 200 ok page node generate return bookmark bookmark if bookmark path ends with bookmark bookmark manager get category by path bookmark path else bookmark bookmark manager get item by path bookmark path if bookmark null html node error box content add child page maker get infobox infobox error error page maker get content node error box add child l10n get string bookmark editor toadlet bookmark does not exist new string bookmark new string bookmark path this writehtml reply ctx 200 ok page node generate return else if del equals action string bm new string bookmark string path new string bookmark path string query title l10n get string bookmark editor toadlet bookmark instanceof bookmark item delete bookmark delete category html node info box content add child page maker get infobox infobox query query title html node info box content page maker get content node info box string query l10n get string bookmark editor toadlet bookmark instanceof bookmark item delete bookmark confirm delete category confirm bm path info box content add child p add child query html node confirm form ctx add form child info box content confirm delete form confirm form add child input new string type name value new string hidden bookmark bookmark path confirm form add child input new string type name value new string submit cancel l10n get string toadlet cancel confirm form add child input new string type name value new string submit confirmdelete l10n get string bookmark editor toadlet confirm delete else if cut equals action cuted path bookmark path else if paste equals action cuted path null bookmark manager move bookmark cuted path bookmark path bookmark manager store bookmarks cuted path null else if edit equals action add item equals action add cat equals action string header if edit equals action header l10n get string bookmark editor toadlet edit bookmark instanceof bookmark item bookmark category title else if add item equals action header l10n get string bookmark editor toadlet add new bookmark else header l10n get string bookmark editor toadlet add new category html node action box content add child page maker get infobox infobox query header html node form ctx add form child page maker get content node action box edit bookmark form form add child label for name l10n get string bookmark editor toadlet name label form add child input new string type id name size value new string text name name 20 edit equals action bookmark get name form add child br boolean is new false if edit equals action bookmark instanceof bookmark item is new add item equals action bookmark item item is new null bookmark item bookmark string key action equals edit item get key form add child label for key l10n get string bookmark editor toadlet key label form add child input new string type id name size value new string text key key 50 key form add child br form add child label for descb l10n get string bookmark editor toadlet desc label form add child br form add child textarea new string id name row cols new string descb descb 3 70 item null item get description form add child br form add child label for has an activelink l10n get string bookmark editor toadlet has an activelink label if item null item has an activelink form add child input new string type id name checked new string checkbox has an activelink has an activelink string value of item has an activelink else form add child input new string type id name new string checkbox has an activelink has an activelink form add child input new string type name value new string hidden bookmark bookmark path form add child input new string type name value new string hidden action req get param action form add child br form add child input new string type value new string submit l10n get string bookmark editor toadlet save else if up equals action bookmark manager move bookmark up bookmark path true else if down equals action bookmark manager move bookmark down bookmark path true if cuted path null html node info box content add child page maker get infobox infobox normal l10n get string bookmark editor toadlet paste title html node info box content page maker get content node info box info box content add child l10n get string bookmark editor toadlet paste or cancel html node cancel form ctx add form child info box content bookmark editor cancel cut form cancel form add child input new string type name value new string submit cancel cut l10n get string bookmark editor toadlet cancel cut cancel form add child input new string type name value new string hidden action cancel cut html node bookmarks box content add child page maker get infobox infobox normal l10n get string bookmark editor toadlet my bookmarks title page maker get content node bookmarks box add child get bookmarks list html node add default bookmarks form ctx add form child content add default bookmarks add default bookmarks form add child input new string type name value new string submit add default bookmarks l10n get string bookmark editor toadlet add default bookmarks if logger should log logger debug this logger debug this returning n page node generate this writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception pagemaker pagemaker getpagemaker editortitle getstring bookmarkeditortoadlet getstring bookmarkeditortoadlet htmlnode pagenode pagemaker getpagenode editortitle htmlnode pagemaker getcontentnode pagenode originalbookmark getparam getparam originalbookmark getparam bookmarkpath bookmarkpath urldecoder originalbookmark urlencodedformatexception htmlnode errorbox addchild pagemaker getinfobox pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet urldecodeerror writehtmlreply pagenode bookmarkpath endswith bookmarkmanager getcategorybypath bookmarkpath bookmarkmanager getitembypath bookmarkpath htmlnode errorbox addchild pagemaker getinfobox pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet bookmarkdoesnotexist bookmarkpath writehtmlreply pagenode bookmarkpath querytitle getstring bookmarkeditortoadlet bookmarkitem deletebookmark deletecategory htmlnode infobox addchild pagemaker getinfobox querytitle htmlnode infoboxcontent pagemaker getcontentnode infobox getstring bookmarkeditortoadlet bookmarkitem deletebookmarkconfirm deletecategoryconfirm infoboxcontent addchild addchild htmlnode confirmform addformchild infoboxcontent confirmdeleteform confirmform addchild bookmarkpath confirmform addchild getstring confirmform addchild getstring bookmarkeditortoadlet confirmdelete cutedpath bookmarkpath cutedpath bookmarkmanager movebookmark cutedpath bookmarkpath bookmarkmanager storebookmarks cutedpath additem addcat getstring bookmarkeditortoadlet bookmarkitem additem getstring bookmarkeditortoadlet addnewbookmark getstring bookmarkeditortoadlet addnewcategory htmlnode actionbox addchild pagemaker getinfobox htmlnode addformchild pagemaker getcontentnode actionbox editbookmarkform addchild getstring bookmarkeditortoadlet namelabel addchild getname addchild isnew bookmarkitem isnew additem bookmarkitem isnew bookmarkitem getkey addchild getstring bookmarkeditortoadlet keylabel addchild addchild addchild getstring bookmarkeditortoadlet desclabel addchild addchild getdescription addchild addchild hasanactivelink getstring bookmarkeditortoadlet hasanactivelinklabel hasanactivelink addchild hasanactivelink hasanactivelink valueof hasanactivelink addchild hasanactivelink hasanactivelink addchild bookmarkpath addchild getparam addchild addchild getstring bookmarkeditortoadlet bookmarkmanager movebookmarkup bookmarkpath bookmarkmanager movebookmarkdown bookmarkpath cutedpath htmlnode infobox addchild pagemaker getinfobox getstring bookmarkeditortoadlet pastetitle htmlnode infoboxcontent pagemaker getcontentnode infobox infoboxcontent addchild getstring bookmarkeditortoadlet pasteorcancel htmlnode cancelform addformchild infoboxcontent bookmarkeditor cancelcutform cancelform addchild cancelcut getstring bookmarkeditortoadlet cancelcut cancelform addchild cancelcut htmlnode bookmarksbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet mybookmarkstitle pagemaker getcontentnode bookmarksbox addchild getbookmarkslist htmlnode adddefaultbookmarksform addformchild adddefaultbookmarks adddefaultbookmarksform addchild adddefaultbookmarks getstring bookmarkeditortoadlet adddefaultbookmarks shouldlog pagenode writehtmlreply pagenode override public void handle post uri uri http request req toadlet context ctx throws toadlet context closed exception io exception page maker page maker ctx get page maker html node page node page maker get page node l10n get string bookmark editor toadlet title ctx html node content page maker get content node page node string passwd req get part as string form password 32 boolean no password passwd null passwd equals core form password if no password write permanent redirect ctx invalid return if req is part set add default bookmarks bookmark manager re add default bookmarks this write temporary redirect ctx ok return string bookmark path req get part as string bookmark max bookmark path length try bookmark bookmark if bookmark path ends with bookmark bookmark manager get category by path bookmark path else bookmark bookmark manager get item by path bookmark path if bookmark null req is part set cancel cut html node error box content add child page maker get infobox infobox error l10n get string bookmark editor toadlet error page maker get content node error box add child l10n get string bookmark editor toadlet bookmark does not exist new string bookmark new string bookmark path this writehtml reply ctx 200 ok page node generate return string action req get part as string action max action length if req is part set confirmdelete bookmark manager remove bookmark bookmark path bookmark manager store bookmarks html node success box content add child page maker get infobox infobox success l10n get string bookmark editor toadlet delete succeeded title page maker get content node success box add child p l10n get string bookmark editor toadlet delete succeeded else if req is part set cancel cut cuted path null else if edit equals action add item equals action add cat equals action string name unnamed if req is part set name name req get part as string name max name length if edit equals action bookmark manager rename bookmark bookmark path name boolean has an activelink req is part set has an activelink if bookmark instanceof bookmark item bookmark item bookmark update new freeneturi req get part as string key max key length has an activelink req get part as string descb max key length bookmark manager store bookmarks html node success box content add child page maker get infobox infobox success l10n get string bookmark editor toadlet changes saved title page maker get content node success box add child p l10n get string bookmark editor toadlet changes saved else if add item equals action add cat equals action bookmark new bookmark null if add item equals action freeneturi key new freeneturi req get part as string key max key length todo nextgens i suggest you implement a http request get boolean string name using fields stringtobool nextgens http request get boolean string name boolean default even values as on true yes should be accepted boolean has an activelink req is part set has an activelink if name contains html node error box content add child page maker get infobox infobox error l10n get string bookmark editor toadlet invalid name title page maker get content node error box add child l10n get string bookmark editor toadlet invalid name else new bookmark new bookmark item key name req get part as string descb max key length has an activelink core alerts else if name contains html node error box content add child page maker get infobox infobox error l10n get string bookmark editor toadlet invalid name title page maker get content node error box add child l10n get string bookmark editor toadlet invalid name else new bookmark new bookmark category name if new bookmark null bookmark manager add bookmark bookmark path new bookmark bookmark manager store bookmarks html node success box content add child page maker get infobox infobox success l10n get string bookmark editor toadlet added new bookmark title page maker get content node success box add child p l10n get string bookmark editor toadlet added new bookmark catch malformedurl exception mue html node error box content add child page maker get infobox infobox error l10n get string bookmark editor toadlet invalid key title page maker get content node error box add child l10n get string bookmark editor toadlet invalid key html node bookmarks box content add child page maker get infobox infobox normal l10n get string bookmark editor toadlet my bookmarks title page maker get content node bookmarks box add child get bookmarks list html node add default bookmarks form ctx add form child content add default bookmarks add default bookmarks form add child input new string type name value new string submit add default bookmarks l10n get string bookmark editor toadlet add default bookmarks this writehtml reply ctx 200 ok page node generate handlepost httprequest toadletcontext toadletcontextclosedexception ioexception pagemaker pagemaker getpagemaker htmlnode pagenode pagemaker getpagenode getstring bookmarkeditortoadlet htmlnode pagemaker getcontentnode pagenode getpartasstring formpassword nopassword formpassword nopassword writepermanentredirect ispartset adddefaultbookmarks bookmarkmanager readddefaultbookmarks writetemporaryredirect bookmarkpath getpartasstring max_bookmark_path_length bookmarkpath endswith bookmarkmanager getcategorybypath bookmarkpath bookmarkmanager getitembypath bookmarkpath ispartset cancelcut htmlnode errorbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet bookmarkdoesnotexist bookmarkpath writehtmlreply pagenode getpartasstring max_action_length ispartset bookmarkmanager removebookmark bookmarkpath bookmarkmanager storebookmarks htmlnode successbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet deletesucceededtitle pagemaker getcontentnode successbox addchild getstring bookmarkeditortoadlet deletesucceeded ispartset cancelcut cutedpath additem addcat ispartset getpartasstring max_name_length bookmarkmanager renamebookmark bookmarkpath hasanactivelink ispartset hasanactivelink bookmarkitem bookmarkitem getpartasstring max_key_length hasanactivelink getpartasstring max_key_length bookmarkmanager storebookmarks htmlnode successbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet changessavedtitle pagemaker getcontentnode successbox addchild getstring bookmarkeditortoadlet changessaved additem addcat newbookmark additem getpartasstring max_key_length httprequest getboolean httprequest getboolean hasanactivelink ispartset hasanactivelink htmlnode errorbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet invalidnametitle pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet invalidname newbookmark bookmarkitem getpartasstring max_key_length hasanactivelink htmlnode errorbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet invalidnametitle pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet invalidname newbookmark bookmarkcategory newbookmark bookmarkmanager addbookmark bookmarkpath newbookmark bookmarkmanager storebookmarks htmlnode successbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet addednewbookmarktitle pagemaker getcontentnode successbox addchild getstring bookmarkeditortoadlet addednewbookmark malformedurlexception htmlnode errorbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet invalidkeytitle pagemaker getcontentnode errorbox addchild getstring bookmarkeditortoadlet invalidkey htmlnode bookmarksbox addchild pagemaker getinfobox getstring bookmarkeditortoadlet mybookmarkstitle pagemaker getcontentnode bookmarksbox addchild getbookmarkslist htmlnode adddefaultbookmarksform addformchild adddefaultbookmarks adddefaultbookmarksform addchild adddefaultbookmarks getstring bookmarkeditortoadlet adddefaultbookmarks writehtmlreply pagenode override public string supported methods return get post supportedmethods static final string name list persistent requests public list persistent requests message simple field set fs do nothing listpersistentrequests listpersistentrequestsmessage simplefieldset override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run final fcp connection handler handler node node throws message invalid exception fcp client reboot client handler get reboot client reboot client queue pending messages on connection restart handler output handler null reboot client queue pending messages from running requests handler output handler null if handler get reboot client watch global fcp client global reboot client handler server global reboot client global reboot client queue pending messages on connection restart handler output handler null global reboot client queue pending messages from running requests handler output handler null node client core client context job runner queue new db job public void run object container container client context context fcp client forever client handler get forever client container container activate forever client 1 forever client queue pending messages on connection restart handler output handler container forever client queue pending messages from running requests handler output handler container if handler get reboot client watch global fcp client global forever client handler server global forever client global forever client queue pending messages on connection restart handler output handler container global forever client queue pending messages from running requests handler output handler container handler output handler queue new end list persistent requests message container deactivate forever client 1 native thread high priority 1 false fcpconnectionhandler messageinvalidexception fcpclient rebootclient getrebootclient rebootclient queuependingmessagesonconnectionrestart outputhandler rebootclient queuependingmessagesfromrunningrequests outputhandler getrebootclient watchglobal fcpclient globalrebootclient globalrebootclient globalrebootclient queuependingmessagesonconnectionrestart outputhandler globalrebootclient queuependingmessagesfromrunningrequests outputhandler clientcore clientcontext jobrunner dbjob objectcontainer clientcontext fcpclient foreverclient getforeverclient foreverclient foreverclient queuependingmessagesonconnectionrestart outputhandler foreverclient queuependingmessagesfromrunningrequests outputhandler getrebootclient watchglobal fcpclient globalforeverclient globalforeverclient globalforeverclient queuependingmessagesonconnectionrestart outputhandler globalforeverclient queuependingmessagesfromrunningrequests outputhandler outputhandler endlistpersistentrequestsmessage foreverclient nativethread high_priority public void run object container container client context context fcp client forever client handler get forever client container container activate forever client 1 forever client queue pending messages on connection restart handler output handler container forever client queue pending messages from running requests handler output handler container if handler get reboot client watch global fcp client global forever client handler server global forever client global forever client queue pending messages on connection restart handler output handler container global forever client queue pending messages from running requests handler output handler container handler output handler queue new end list persistent requests message container deactivate forever client 1 objectcontainer clientcontext fcpclient foreverclient getforeverclient foreverclient foreverclient queuependingmessagesonconnectionrestart outputhandler foreverclient queuependingmessagesfromrunningrequests outputhandler getrebootclient watchglobal fcpclient globalforeverclient globalforeverclient globalforeverclient queuependingmessagesonconnectionrestart outputhandler globalforeverclient queuependingmessagesfromrunningrequests outputhandler outputhandler endlistpersistentrequestsmessage foreverclient override public void remove from object container container container delete this removefrom objectcontainer persistent map impl storage storage class key type int initial size super storage type get type code key type keys new comparable initial size values storage v create link initial size persistentmapimpl keytype initialsize gettypecode keytype initialsize createlink initialsize v value public k get key return key getkey public v get value return value getvalue public v set value v value modify v prev value this value this value value return prev value setvalue prevvalue prevvalue persistent map entry k key v value this key key this value value persistentmapentry this value value persistent map entry persistentmapentry static class persistent map comparator k extends comparable v extends i persistent extends persistent comparator persistent map entry k v public int compare members persistent map entry k v m1 persistent map entry k v m2 return m1 key compare to m2 key persistentmapcomparator ipersistent persistentcomparator persistentmapentry comparemembers persistentmapentry persistentmapentry compareto public int compare member with key persistent map entry k v mbr object key return mbr key compare to key comparememberwithkey persistentmapentry compareto persistent map impl persistentmapimpl protected int get type code class c if c equals byte class c equals byte class return class descriptor tp byte else if c equals short class c equals short class return class descriptor tp short else if c equals char class c equals character class return class descriptor tp char else if c equals int class c equals integer class return class descriptor tp int else if c equals long class c equals long class return class descriptor tp long else if c equals float class c equals float class return class descriptor tp float else if c equals double class c equals double class return class descriptor tp double else if c equals string class return class descriptor tp string else if c equals boolean class c equals boolean class return class descriptor tp boolean else if c is enum return class descriptor tp enum else if c equals java util date class return class descriptor tp date else if comparable class is assignable from c return class descriptor tp raw else throw new storage error storage error unsupported type c gettypecode classdescriptor tpbyte classdescriptor tpshort classdescriptor tpchar classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpstring classdescriptor tpboolean isenum classdescriptor tpenum classdescriptor tpdate isassignablefrom classdescriptor tpraw storageerror storageerror unsupported_type public int size return index null collection index size values size public boolean is empty return size 0 isempty public boolean contains value object value iterator entry k v i entry set iterator if value null while i has next entry k v e i next if e get value null return true else while i has next entry k v e i next if value equals e get value return true return false containsvalue entryset hasnext getvalue hasnext getvalue private int binary search object key comparable keys comparable this keys int l 0 r values size while l r int i l r 1 if keys i compare to key 0 l i 1 else r i return r binarysearch compareto public boolean contains key object key if index null if type class descriptor tp raw return sorted collection index contains key key else key k generate key key return index index entry iterator k k index ascent order has next else int i binary search key return i values size comparable keys i equals key containskey classdescriptor tpraw sortedcollection containskey generatekey entryiterator ascent_order hasnext binarysearch public v get object key if index null if type class descriptor tp raw persistent map entry k v entry sorted collection persistent map entry k v index get key return entry null entry value null else return index v index get generate key key else int i binary search key if i values size comparable keys i equals key return values get i return null classdescriptor tpraw persistentmapentry sortedcollection persistentmapentry generatekey binarysearch public entry k v get entry object key if index null if type class descriptor tp raw return sorted collection persistent map entry k v index get key else v value index v index get generate key key return value null new persistent map entry k key value null else int i binary search key if i values size comparable keys i equals key v value values get i return value null new persistent map entry k key value null return null getentry classdescriptor tpraw sortedcollection persistentmapentry generatekey persistentmapentry binarysearch persistentmapentry public v put k key v value v prev null if index null int size values size int i binary search key if i size key equals comparable keys i prev values set i value else if size btree treshold comparable keys comparable this keys if type class descriptor tp raw sorted collection persistent map entry k v col get storage persistent map entry k v create sorted collection new persistent map comparator k v true index col for i 0 i size i col add new persistent map entry k keys i values get i prev insert in sorted collection key value else index v idx get storage v create index btree map key type type true index idx for i 0 i size i idx set generate key keys i values get i prev idx set generate key key value this keys null this values null modify else object old keys object keys if size old keys length comparable new keys new comparable size 1 old keys length 2 size 1 old keys length 2 system arraycopy old keys 0 new keys 0 i system arraycopy old keys i new keys i 1 size i keys new keys new keys i key else system arraycopy old keys i old keys i 1 size i old keys i key values insert i value else if type class descriptor tp raw prev insert in sorted collection key value else prev index v index set generate key key value return prev binarysearch btree_treshold classdescriptor tpraw sortedcollection persistentmapentry getstorage persistentmapentry createsortedcollection persistentmapcomparator persistentmapentry insertinsortedcollection getstorage createindex mapkeytype generatekey generatekey oldkeys oldkeys newkeys oldkeys oldkeys oldkeys newkeys oldkeys newkeys newkeys newkeys oldkeys oldkeys oldkeys classdescriptor tpraw insertinsortedcollection generatekey private v insert in sorted collection k key v value sorted collection persistent map entry k v col sorted collection persistent map entry k v index persistent map entry k v entry col get key v prev null get storage make persistent value if entry null col add new persistent map entry key value else prev entry set value value return prev insertinsortedcollection sortedcollection persistentmapentry sortedcollection persistentmapentry persistentmapentry getstorage makepersistent persistentmapentry setvalue public v remove object key if index null int size values size int i binary search key if i size comparable keys i equals key system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null return values remove i return null else if type class descriptor tp raw sorted collection persistent map entry k v col sorted collection persistent map entry k v index persistent map entry k v entry col get key if entry null return null col remove entry return entry value else try return index v index remove generate key key catch storage error x if x get error code storage error key not found return null throw x binarysearch classdescriptor tpraw sortedcollection persistentmapentry sortedcollection persistentmapentry persistentmapentry generatekey storageerror geterrorcode storageerror key_not_found public void put all map extends k extends v t iterator extends entry extends k extends v i t entry set iterator while i has next entry extends k extends v e i next put e get key e get value putall entryset hasnext getkey getvalue public void clear if index null collection index clear else values clear keys new comparable comparable keys length public set k key set if key set null key set new abstract set k public iterator k iterator return new iterator k private iterator entry k v i entry set iterator public boolean has next return i has next public k next return i next get key public void remove i remove public int size return persistent map impl this size public boolean contains object k return persistent map impl this contains key k return key set keyset keyset keyset abstractset entryset hasnext hasnext getkey persistentmapimpl persistentmapimpl containskey keyset key set new abstract set k public iterator k iterator return new iterator k private iterator entry k v i entry set iterator public boolean has next return i has next public k next return i next get key public void remove i remove keyset abstractset entryset hasnext hasnext getkey private iterator entry k v i entry set iterator public boolean has next return i has next entryset hasnext hasnext public k next return i next get key getkey public void remove i remove public int size return persistent map impl this size persistentmapimpl public boolean contains object k return persistent map impl this contains key k persistentmapimpl containskey public collection v values if values col null values col new abstract collection v public iterator v iterator return new iterator v private iterator entry k v i entry set iterator public boolean has next return i has next public v next return i next get value public void remove i remove public int size return persistent map impl this size public boolean contains object v return persistent map impl this contains value v return values col valuescol valuescol abstractcollection entryset hasnext hasnext getvalue persistentmapimpl persistentmapimpl containsvalue valuescol values col new abstract collection v public iterator v iterator return new iterator v private iterator entry k v i entry set iterator public boolean has next return i has next public v next return i next get value public void remove i remove valuescol abstractcollection entryset hasnext hasnext getvalue private iterator entry k v i entry set iterator public boolean has next return i has next entryset hasnext hasnext public v next return i next get value getvalue public void remove i remove public int size return persistent map impl this size persistentmapimpl public boolean contains object v return persistent map impl this contains value v persistentmapimpl containsvalue protected iterator entry k v entry iterator if index null if type class descriptor tp raw return new iterator entry k v private iterator persistent map entry k v i sorted collection persistent map entry k v index iterator public boolean has next return i has next public entry k v next return i next public void remove i remove else return new iterator entry k v private iterator entry object v i index v index entry iterator public boolean has next return i has next public entry k v next final entry object v e i next return new entry k v public k get key return k e get key public v get value return e get value public v set value v value throw new unsupported operation exception entry map set value public void remove i remove else return new iterator entry k v private int i 1 public boolean has next return i 1 values size public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i i 1 entryiterator classdescriptor tpraw persistentmapentry sortedcollection persistentmapentry hasnext hasnext entryiterator hasnext hasnext getkey getkey getvalue getvalue setvalue unsupportedoperationexception setvalue hasnext hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue illegalstateexception removeobject private iterator persistent map entry k v i sorted collection persistent map entry k v index iterator public boolean has next return i has next persistentmapentry sortedcollection persistentmapentry hasnext hasnext public entry k v next return i next public void remove i remove private iterator entry object v i index v index entry iterator public boolean has next return i has next entryiterator hasnext hasnext public entry k v next final entry object v e i next return new entry k v public k get key return k e get key public v get value return e get value public v set value v value throw new unsupported operation exception entry map set value getkey getkey getvalue getvalue setvalue unsupportedoperationexception setvalue final entry object v e i next return new entry k v public k get key return k e get key getkey getkey return k e get key public v get value return e get value getkey getvalue getvalue return e get value public v set value v value throw new unsupported operation exception entry map set value getvalue setvalue unsupportedoperationexception setvalue public void remove i remove private int i 1 public boolean has next return i 1 values size hasnext public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue i 1 return new entry k v public k get key return k comparable keys i getkey return k comparable keys i public v get value return values get i getvalue return values get i public v set value v value throw new unsupported operation exception entry map set value setvalue unsupportedoperationexception setvalue public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i i 1 illegalstateexception removeobject public set entry k v entry set if entry set null entry set new abstract set entry k v public iterator entry k v iterator return entry iterator public int size return persistent map impl this size public boolean remove object o if o instanceof map entry return false map entry k v entry map entry k v o k key entry get key v value entry get value if value null v v persistent map impl this get key if value equals v persistent map impl this remove key return true else if persistent map impl this contains key key persistent map impl this get key null persistent map impl this remove key return true return false public boolean contains object k entry k v e entry k v k if e get value null return e get value equals persistent map impl this get e get key else return persistent map impl this contains key e get key persistent map impl this get e get key null return entry set entryset entryset entryset abstractset entryiterator persistentmapimpl getkey getvalue persistentmapimpl persistentmapimpl persistentmapimpl containskey persistentmapimpl persistentmapimpl getvalue getvalue persistentmapimpl getkey persistentmapimpl containskey getkey persistentmapimpl getkey entryset if entry set null entry set new abstract set entry k v public iterator entry k v iterator return entry iterator entryset entryset abstractset entryiterator public int size return persistent map impl this size persistentmapimpl public boolean remove object o if o instanceof map entry return false map entry k v entry map entry k v o k key entry get key v value entry get value if value null v v persistent map impl this get key if value equals v persistent map impl this remove key return true else if persistent map impl this contains key key persistent map impl this get key null persistent map impl this remove key return true return false getkey getvalue persistentmapimpl persistentmapimpl persistentmapimpl containskey persistentmapimpl persistentmapimpl public boolean contains object k entry k v e entry k v k if e get value null return e get value equals persistent map impl this get e get key else return persistent map impl this contains key e get key persistent map impl this get e get key null getvalue getvalue persistentmapimpl getkey persistentmapimpl containskey getkey persistentmapimpl getkey public boolean equals object o if o this return true if o instanceof map return false map k v t map k v o if t size size return false try iterator entry k v i entry set iterator while i has next entry k v e i next k key e get key v value e get value if value null if t get key null t contains key key return false else if value equals t get key return false catch class cast exception unused return false catch null pointer exception unused return false return true entryset hasnext getkey getvalue containskey classcastexception nullpointerexception public int hash code int h 0 iterator entry k v i entry set iterator while i has next h i next hash code return h hashcode entryset hasnext hashcode public string to string string buffer buf new string buffer buf append iterator entry k v i entry set iterator boolean has next i has next while has next entry k v e i next k key e get key v value e get value if key this buf append this map else buf append key buf append if value this buf append this map else buf append value has next i has next if has next buf append buf append return buf to string tostring stringbuffer stringbuffer entryset hasnext hasnext hasnext getkey getvalue hasnext hasnext hasnext tostring final key generate key object key return generate key key true generatekey generatekey final key generate key object key boolean inclusive if key instanceof integer return new key integer key int value inclusive else if key instanceof byte return new key byte key byte value inclusive else if key instanceof character return new key character key char value inclusive else if key instanceof short return new key short key short value inclusive else if key instanceof long return new key long key long value inclusive else if key instanceof float return new key float key float value inclusive else if key instanceof double return new key double key double value inclusive else if key instanceof string return new key string key inclusive else if key instanceof enum return new key enum key inclusive else if key instanceof java util date return new key java util date key inclusive else throw new storage error storage error unsupported index type key get class generatekey intvalue bytevalue charvalue shortvalue longvalue floatvalue doublevalue storageerror storageerror unsupported_index_type getclass public comparator super k comparator return null public sorted map k v sub map k from k to if from compare to to 0 throw new illegal argument exception from to return new sub map from to sortedmap submap compareto illegalargumentexception submap public sorted map k v head map k to return new sub map null to sortedmap headmap submap public sorted map k v tail map k from return new sub map from null sortedmap tailmap submap sub map k from k to this from from this to to this from key from null generate key from true null this to key to null generate key to false null submap fromkey generatekey tokey generatekey public boolean is empty return entry set is empty isempty entryset isempty public boolean contains key object key return in range k key persistent map impl this contains key key containskey inrange persistentmapimpl containskey public v get object key if in range k key return null return persistent map impl this get key inrange persistentmapimpl public v put k key v value if in range key throw new illegal argument exception key out of range return persistent map impl this put key value inrange illegalargumentexception persistentmapimpl public comparator super k comparator return null public k first key return entry iterator index ascent order next get key firstkey entryiterator ascent_order getkey public k last key return entry iterator index descent order next get key lastkey entryiterator descent_order getkey protected iterator entry k v entry iterator final int order if index null if type class descriptor tp raw if order index ascent order return new iterator entry k v private iterator persistent map entry k v i sorted collection persistent map entry k v index iterator from key to key public boolean has next return i has next public entry k v next return i next public void remove i remove else return new iterator entry k v private array list persistent map entry k v entries sorted collection persistent map entry k v index get list from key to key private int i entries size public boolean has next return i 0 public entry k v next if has next throw new no such element exception return entries get i public void remove if i entries size entries get i null throw new illegal state exception sorted collection persistent map entry k v index remove entries get i entries set i null else return new iterator entry k v private iterator entry object v i index v index entry iterator from key to key order public boolean has next return i has next public entry k v next final entry object v e i next return new entry k v public k get key return k e get key public v get value return e get value public v set value v value throw new unsupported operation exception entry map set value public void remove i remove else if order index ascent order final int beg from null binary search from 0 1 final int end values size return new iterator entry k v private int i beg public boolean has next return i 1 end to null comparable keys i 1 compare to to 0 public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i i 1 else final int beg to null binary search to 0 1 return new iterator entry k v private int i beg public boolean has next return i 0 from null comparable keys i 1 compare to from 0 public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i entryiterator classdescriptor tpraw ascent_order persistentmapentry sortedcollection persistentmapentry fromkey tokey hasnext hasnext arraylist persistentmapentry sortedcollection persistentmapentry getlist fromkey tokey hasnext hasnext nosuchelementexception illegalstateexception sortedcollection persistentmapentry entryiterator fromkey tokey hasnext hasnext getkey getkey getvalue getvalue setvalue unsupportedoperationexception setvalue ascent_order binarysearch hasnext compareto hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue illegalstateexception removeobject binarysearch hasnext compareto hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue illegalstateexception removeobject private iterator persistent map entry k v i sorted collection persistent map entry k v index iterator from key to key public boolean has next return i has next persistentmapentry sortedcollection persistentmapentry fromkey tokey hasnext hasnext return i has next public entry k v next return i next hasnext return i next public void remove i remove private int i entries size public boolean has next return i 0 hasnext public entry k v next if has next throw new no such element exception return entries get i hasnext nosuchelementexception public void remove if i entries size entries get i null throw new illegal state exception sorted collection persistent map entry k v index remove entries get i entries set i null illegalstateexception sortedcollection persistentmapentry private iterator entry object v i index v index entry iterator from key to key order public boolean has next return i has next entryiterator fromkey tokey hasnext hasnext public entry k v next final entry object v e i next return new entry k v public k get key return k e get key public v get value return e get value public v set value v value throw new unsupported operation exception entry map set value getkey getkey getvalue getvalue setvalue unsupportedoperationexception setvalue final entry object v e i next return new entry k v public k get key return k e get key getkey getkey return k e get key public v get value return e get value getkey getvalue getvalue return e get value public v set value v value throw new unsupported operation exception entry map set value getvalue setvalue unsupportedoperationexception setvalue public void remove i remove private int i beg public boolean has next return i 1 end to null comparable keys i 1 compare to to 0 hasnext compareto public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue i 1 return new entry k v public k get key return k comparable keys i getkey return k comparable keys i public v get value return values get i getvalue return values get i public v set value v value throw new unsupported operation exception entry map set value setvalue unsupportedoperationexception setvalue public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i i 1 illegalstateexception removeobject private int i beg public boolean has next return i 0 from null comparable keys i 1 compare to from 0 hasnext compareto public entry k v next if has next throw new no such element exception i 1 return new entry k v public k get key return k comparable keys i public v get value return values get i public v set value v value throw new unsupported operation exception entry map set value hasnext nosuchelementexception getkey getvalue setvalue unsupportedoperationexception setvalue i 1 return new entry k v public k get key return k comparable keys i getkey return k comparable keys i public v get value return values get i getvalue return values get i public v set value v value throw new unsupported operation exception entry map set value setvalue unsupportedoperationexception setvalue public void remove if i 0 throw new illegal state exception int size values size system arraycopy keys i 1 keys i size i 1 comparable keys size 1 null values remove object i illegalstateexception removeobject public set entry k v entry set if entry set null entry set new abstract set entry k v public iterator entry k v iterator return entry iterator index ascent order public int size iterator entry k v i iterator int n for n 0 i has next i next n 1 return n public boolean is empty return iterator has next public boolean remove object o if o instanceof map entry return false map entry k v entry map entry k v o k key entry get key if in range key return false v value entry get value if value null v v persistent map impl this get key if value equals v persistent map impl this remove key return true else if persistent map impl this contains key key persistent map impl this get key null persistent map impl this remove key return true return false public boolean contains object k entry k v e entry k v k if in range e get key return false if e get value null return e get value equals persistent map impl this get e get key else return persistent map impl this contains key e get key persistent map impl this get e get key null return entry set entryset entryset entryset abstractset entryiterator ascent_order hasnext isempty hasnext getkey inrange getvalue persistentmapimpl persistentmapimpl persistentmapimpl containskey persistentmapimpl persistentmapimpl inrange getkey getvalue getvalue persistentmapimpl getkey persistentmapimpl containskey getkey persistentmapimpl getkey entryset if entry set null entry set new abstract set entry k v public iterator entry k v iterator return entry iterator index ascent order entryset entryset abstractset entryiterator ascent_order public int size iterator entry k v i iterator int n for n 0 i has next i next n 1 return n hasnext public boolean is empty return iterator has next isempty hasnext public boolean remove object o if o instanceof map entry return false map entry k v entry map entry k v o k key entry get key if in range key return false v value entry get value if value null v v persistent map impl this get key if value equals v persistent map impl this remove key return true else if persistent map impl this contains key key persistent map impl this get key null persistent map impl this remove key return true return false getkey inrange getvalue persistentmapimpl persistentmapimpl persistentmapimpl containskey persistentmapimpl persistentmapimpl public boolean contains object k entry k v e entry k v k if in range e get key return false if e get value null return e get value equals persistent map impl this get e get key else return persistent map impl this contains key e get key persistent map impl this get e get key null inrange getkey getvalue getvalue persistentmapimpl getkey persistentmapimpl containskey getkey persistentmapimpl getkey public sorted map k v sub map k from k to if in range2 from throw new illegal argument exception from out of range if in range2 to throw new illegal argument exception to out of range return new sub map from to sortedmap submap inrange2 illegalargumentexception inrange2 illegalargumentexception submap public sorted map k v head map k to if in range2 to throw new illegal argument exception to out of range return new sub map this from to sortedmap headmap inrange2 illegalargumentexception submap public sorted map k v tail map k from if in range2 from throw new illegal argument exception from out of range return new sub map from this to sortedmap tailmap inrange2 illegalargumentexception submap private boolean in range k key return from null key compare to from 0 to null key compare to to 0 inrange compareto compareto this form allows the high endpoint as well as all legit keys private boolean in range2 k key return from null key compare to from 0 to null key compare to to 0 inrange2 compareto compareto public k first key if index null if type class descriptor tp raw return sorted collection persistent map entry k v index iterator next key else return k index v index entry iterator next get key else comparable keys comparable this keys if values size 0 throw new no such element exception return k comparable keys 0 firstkey classdescriptor tpraw sortedcollection persistentmapentry entryiterator getkey nosuchelementexception public k last key if index null if type class descriptor tp raw array list persistent map entry k v entries sorted collection persistent map entry k v index get list null null return entries get entries size 1 key else return k index v index entry iterator null null index descent order next get key else int size values size if size 0 throw new no such element exception return k comparable keys size 1 lastkey classdescriptor tpraw arraylist persistentmapentry sortedcollection persistentmapentry getlist entryiterator descent_order getkey nosuchelementexception public iterator v select class cls string predicate query v query new query impl v get storage return query select cls values iterator predicate queryimpl getstorage int types btree compound index btreecompoundindex btree compound index class key types boolean unique this unique unique type class descriptor tp array of byte types new int key types length for int i 0 i key types length i types i get compound key component type key types i btreecompoundindex keytypes classdescriptor tparrayofbyte keytypes keytypes getcompoundkeycomponenttype keytypes btree compound index int types boolean unique this types types this unique unique btreecompoundindex static int get compound key component type class c if c equals boolean class return class descriptor tp boolean else if c equals byte class return class descriptor tp byte else if c equals character class return class descriptor tp char else if c equals short class return class descriptor tp short else if c equals integer class return class descriptor tp int else if c equals long class return class descriptor tp long else if c equals float class return class descriptor tp float else if c equals double class return class descriptor tp double else if c equals string class return class descriptor tp string else if c equals date class return class descriptor tp date else if c equals byte class return class descriptor tp array of byte else if i persistent class is assignable from c return class descriptor tp object else throw new storage error storage error unsupported index type c getcompoundkeycomponenttype classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpstring classdescriptor tpdate classdescriptor tparrayofbyte ipersistent isassignablefrom classdescriptor tpobject storageerror storageerror unsupported_index_type public class get key types class key types new class types length for int i 0 i key types length i key types i map key type types i return key types getkeytypes keytypes keytypes keytypes mapkeytype keytypes int compare byte arrays byte key byte item int offs int lengtn int o1 0 int o2 offs byte a1 key byte a2 item for int i 0 i types length o1 key length i int diff 0 switch types i case class descriptor tp boolean case class descriptor tp byte diff a1 o1 a2 o2 break case class descriptor tp short diff bytes unpack2 a1 o1 bytes unpack2 a2 o2 o1 2 o2 2 break case class descriptor tp char diff char bytes unpack2 a1 o1 char bytes unpack2 a2 o2 o1 2 o2 2 break case class descriptor tp int case class descriptor tp object case class descriptor tp enum int i1 bytes unpack4 a1 o1 int i2 bytes unpack4 a2 o2 diff i1 i2 1 i1 i2 0 1 o1 4 o2 4 break case class descriptor tp long case class descriptor tp date long l1 bytes unpack8 a1 o1 long l2 bytes unpack8 a2 o2 diff l1 l2 1 l1 l2 0 1 o1 8 o2 8 break case class descriptor tp float float f1 float int bits to float bytes unpack4 a1 o1 float f2 float int bits to float bytes unpack4 a2 o2 diff f1 f2 1 f1 f2 0 1 o1 4 o2 4 break case class descriptor tp double double d1 double long bits to double bytes unpack8 a1 o1 double d2 double long bits to double bytes unpack8 a2 o2 diff d1 d2 1 d1 d2 0 1 o1 8 o2 8 break case class descriptor tp string int len1 bytes unpack4 a1 o1 int len2 bytes unpack4 a2 o2 o1 4 o2 4 int len len1 len2 len1 len2 while len 0 diff char bytes unpack2 a1 o1 char bytes unpack2 a2 o2 if diff 0 return diff o1 2 o2 2 diff len1 len2 break case class descriptor tp array of byte int len1 bytes unpack4 a1 o1 int len2 bytes unpack4 a2 o2 o1 4 o2 4 int len len1 len2 len1 len2 while len 0 diff a1 o1 a2 o2 if diff 0 return diff diff len1 len2 break default assert failed invalid type if diff 0 return diff return 0 comparebytearrays classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpshort classdescriptor tpchar classdescriptor tpint classdescriptor tpobject classdescriptor tpenum classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat intbitstofloat classdescriptor tpdouble longbitstodouble longbitstodouble classdescriptor tpstring classdescriptor tparrayofbyte object unpack byte array key page pg int pos int offs btree page first key offs btree page get key str offs pg pos byte data pg data object values new object types length for int i 0 i types length i object v null switch types i case class descriptor tp boolean v boolean value of data offs 0 break case class descriptor tp byte v new byte data offs break case class descriptor tp short v short value of bytes unpack2 data offs offs 2 break case class descriptor tp char v new character char bytes unpack2 data offs offs 2 break case class descriptor tp int v new integer bytes unpack4 data offs offs 4 break case class descriptor tp object int oid bytes unpack4 data offs v oid 0 null storage impl get storage lookup object oid null offs 4 break case class descriptor tp long v new long bytes unpack8 data offs offs 8 break case class descriptor tp date long msec bytes unpack8 data offs v msec 1 null new date msec offs 8 break case class descriptor tp float v new float float int bits to float bytes unpack4 data offs offs 4 break case class descriptor tp double v new double double long bits to double bytes unpack8 data offs offs 8 break case class descriptor tp string int len bytes unpack4 data offs offs 4 char sval new char len for int j 0 j len j sval j char bytes unpack2 data offs offs 2 v new string sval break case class descriptor tp array of byte int len bytes unpack4 data offs offs 4 byte bval new byte len system arraycopy data offs bval 0 len offs len break default assert failed invalid type values i v return values unpackbytearraykey btreepage firstkeyoffs btreepage getkeystroffs classdescriptor tpboolean valueof classdescriptor tpbyte classdescriptor tpshort valueof classdescriptor tpchar classdescriptor tpint classdescriptor tpobject storageimpl getstorage lookupobject classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat classdescriptor tpdouble longbitstodouble classdescriptor tpstring classdescriptor tparrayofbyte private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type object values object key oval byte buffer buf new byte buffer int dst 0 for int i 0 i values length i object v values i switch types i case class descriptor tp boolean buf extend dst 1 buf arr dst byte boolean v boolean value 1 0 break case class descriptor tp byte buf extend dst 1 buf arr dst number v byte value break case class descriptor tp short buf extend dst 2 bytes pack2 buf arr dst number v short value dst 2 break case class descriptor tp char buf extend dst 2 bytes pack2 buf arr dst v instanceof number number v short value short character v char value dst 2 break case class descriptor tp int buf extend dst 4 bytes pack4 buf arr dst number v int value dst 4 break case class descriptor tp object buf extend dst 4 bytes pack4 buf arr dst v null 0 i persistent v get oid dst 4 break case class descriptor tp long buf extend dst 8 bytes pack8 buf arr dst number v long value dst 8 break case class descriptor tp date buf extend dst 8 bytes pack8 buf arr dst v null 1 date v get time dst 8 break case class descriptor tp float buf extend dst 4 bytes pack4 buf arr dst float float to int bits number v float value dst 4 break case class descriptor tp double buf extend dst 8 bytes pack8 buf arr dst double double to long bits number v double value dst 8 break case class descriptor tp enum buf extend dst 4 bytes pack4 buf arr dst enum v ordinal dst 4 break case class descriptor tp string buf extend dst 4 if v null string str string v int len str length bytes pack4 buf arr dst len dst 4 buf extend dst len 2 for int j 0 j len j bytes pack2 buf arr dst short str char at j dst 2 else bytes pack4 buf arr dst 0 dst 4 break case class descriptor tp array of byte buf extend dst 4 if v null byte arr byte v int len arr length bytes pack4 buf arr dst len dst 4 buf extend dst len system arraycopy arr 0 buf arr dst len dst len else bytes pack4 buf arr dst 0 dst 4 break default assert failed invalid type return new key buf to array key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type bytebuffer bytebuffer classdescriptor tpboolean booleanvalue classdescriptor tpbyte bytevalue classdescriptor tpshort shortvalue classdescriptor tpchar shortvalue charvalue classdescriptor tpint intvalue classdescriptor tpobject ipersistent getoid classdescriptor tplong longvalue classdescriptor tpdate gettime classdescriptor tpfloat floattointbits floatvalue classdescriptor tpdouble doubletolongbits doublevalue classdescriptor tpenum classdescriptor tpstring charat classdescriptor tparrayofbyte toarray public array list t get list key from key till return super get list convert key from convert key till arraylist getlist getlist convertkey convertkey public t get key key return super get convert key key convertkey public t remove key key return super remove convert key key convertkey public void remove key key t obj super remove convert key key obj convertkey public t set key key t obj return super set convert key key obj convertkey public boolean put key key t obj return super put convert key key obj convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public static string encode string s int n s length string builder sb new string builder n encode to buffer n s sb return sb to string stringbuilder stringbuilder encodetobuffer tostring public static void encode to buffer string s string builder sb encode to buffer s length s sb encodetobuffer stringbuilder encodetobuffer private static void encode to buffer int n string s string builder sb for int i 0 i n i char c s char at i if character is letter or digit c only special characters need checking sb append c else if char table contains key c sb append sb append char table get c sb append else sb append c encodetobuffer stringbuilder charat isletterordigit chartable containskey chartable encode string so it is safe to be used in xml attribute value and text html encode encode use some html specific entities e g amp hence not suitable for generic xml public static string encodexml string s extensible markup language xml 1 0 fifth edition 10 att value reference reference 14 char data s s replace 38 s s replace 34 s s replace 39 s s replace 60 s s replace 62 char data can t contain return s htmlencode attvalue chardata chardata public char table hash map character string map int keys new int map size int key index 0 int max 0 for character key map key set int val key char value keys key index val if val max max val modulo map size int collision table new int max 1 using integers instead of booleans no cleanup boolean ok false while ok modulo try a higher modulo ok true for int i 0 ok i keys length i key index keys i modulo try this modulo if collision table key index modulo is this value already used ok false else collision table key index modulo system out println the modulo is modulo was the modulo is 1474 chars new char modulo strings new string modulo for character character map key set key index character char value modulo chars key index character char value strings key index map get character if chars 0 0 strings 0 null chars 0 1 chartable hashmap keyindex keyset charvalue keyindex collisiontable keyindex collisiontable keyindex collisiontable keyindex keyset keyindex charvalue keyindex charvalue keyindex public boolean contains key char key return chars key modulo key containskey public string get char key return chars key modulo key strings key modulo null public request tag boolean isssk start start super this start start this isssk isssk requesttag public void set request sender finished int status request sender finished code status setrequestsenderfinished requestsenderfinishedcode public void set sender request sender rs sender new weak reference request sender rs setsender requestsender weakreference requestsender public void handler threw throwable t this handler threw t handlerthrew handlerthrew public void set served from datastore served from datastore true setservedfromdatastore servedfromdatastore public void set rejected rejected true setrejected override public void log still present long uid string buffer sb new string buffer sb append still present after append time util format time age sb append append uid append start append start sb append ssk append isssk append from store append served from datastore if sender null sb append sender hasn t been set else request sender s sender get if s null sb append sender null else sb append sender append s sb append status sb append s get status string sb append finished code append request sender finished code sb append rejected append rejected sb append thrown append handler threw if aborted downstream transfer sb append aborted downstream transfer reason sb append aborted downstream reason sb append desc sb append aborted downstream desc if handler disconnected sb append handler disconnected true if handler threw null logger error this sb to string handler threw else logger error this sb to string logstillpresent stringbuffer stringbuffer timeutil formattime servedfromdatastore requestsender getstatusstring finishedcode requestsenderfinishedcode handlerthrew aborteddownstreamtransfer aborteddownstreamtransfer aborteddownstreamreason aborteddownstreamdesc handlerdisconnected handlerdisconnected handlerthrew tostring handlerthrew tostring public void on abort downstream transfers int reason string desc aborted downstream transfer true aborted downstream reason reason aborted downstream desc desc onabortdownstreamtransfers aborteddownstreamtransfer aborteddownstreamreason aborteddownstreamdesc public void handler disconnected handler disconnected true handlerdisconnected handlerdisconnected public static double get location string init try if init null return 1 double d double parse double init if d 0 0 d 1 0 return 1 return d catch number format exception e return 1 getlocation parsedouble numberformatexception static double distance peer node p double loc double d distance p get location loc return d return d p get bias peernode getlocation getbias distance between two locations both parameters must be in 0 0 1 0 public static double distance double a double b return distance a b false public static double distance double a double b boolean allow crazy circular keyspace if allow crazy if a 0 0 a 1 0 b 0 0 b 1 0 logger error peer manager class invalid location a a b b please report this bug new exception error throw new null pointer exception return simple distance a b else if a 0 0 a 1 0 a 2 0 if b 0 0 b 1 0 b 2 0 if a 1 0 b 2 0 return 0 0 both are out of range so both are equal if a 1 0 return a b if b 1 0 return b a return simple distance a b allowcrazy allowcrazy peermanager nullpointerexception simpledistance simpledistance private static double simple distance double a double b if a b return math min a b 1 0 a b else return math min b a 1 0 b a simpledistance patterned after distance double double but also retuns the direction of the change positive negative when given two values on opposite ends of the keyspace it will return 0 5 public static double change double from double to if to from double direct difference to from double opposite difference 1 0 to from if direct difference opposite difference return direct difference else return opposite difference else it s going the other way return 1 change to from except the edge case of 0 5 double direct difference from to double opposite difference 1 0 from to if direct difference opposite difference return direct difference else return opposite difference directdifference oppositedifference directdifference oppositedifference directdifference oppositedifference directdifference oppositedifference directdifference oppositedifference directdifference oppositedifference given an arbitrary double not bound to 0 0 1 0 return the normalized double 0 0 1 0 which would result in simple wrapping overflowing e g normalize 1 0 0 5 0 5 normalize 0 5 1 0 0 5 normalize 0 0 1 0 0 0 1 0 bug if given double has wrapped too many times the return value may be not be precise public static double normalize double rough int int part int rough double maybe negative rough int part note maybe negative is bound between 1 0 1 0 if maybe negative 0 return 1 0 maybe negative return maybe negative intpart maybenegative intpart maybenegative maybenegative maybenegative maybenegative public static boolean equals double new loc double current location return math abs new loc current location double min value 2 newloc currentlocation newloc currentlocation min_value int types alt btree compound index altbtreecompoundindex alt btree compound index class key types boolean unique this unique unique type class descriptor tp raw types new int key types length for int i 0 i key types length i types i get compound key component type key types i altbtreecompoundindex keytypes classdescriptor tpraw keytypes keytypes getcompoundkeycomponenttype keytypes static int get compound key component type class c if c equals boolean class return class descriptor tp boolean else if c equals byte class return class descriptor tp byte else if c equals character class return class descriptor tp char else if c equals short class return class descriptor tp short else if c equals integer class return class descriptor tp int else if c equals long class return class descriptor tp long else if c equals float class return class descriptor tp float else if c equals double class return class descriptor tp double else if c equals string class return class descriptor tp string else if c equals date class return class descriptor tp date else if i persistent class is assignable from c return class descriptor tp object else if comparable class is assignable from c return class descriptor tp raw else throw new storage error storage error unsupported index type c getcompoundkeycomponenttype classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpstring classdescriptor tpdate ipersistent isassignablefrom classdescriptor tpobject isassignablefrom classdescriptor tpraw storageerror storageerror unsupported_index_type public class get key types class key types new class types length for int i 0 i key types length i key types i map key type types i return key types getkeytypes keytypes keytypes keytypes mapkeytype keytypes public int compare to object o compound key c compound key o int n keys length c keys length keys length c keys length for int i 0 i n i int diff comparable keys i compare to c keys i if diff 0 return diff return 0 allow to compare part of the compound key compareto compoundkey compoundkey compareto compound key object keys this keys keys compoundkey private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type object key components object key oval if key components length types length throw new storage error storage error incompatible key type boolean is copy false for int i 0 i key components length i int type types i if type class descriptor tp object type class descriptor tp boolean if is copy object new key components new object key components length system arraycopy key components 0 new key components 0 key components length key components new key components is copy true key components i type class descriptor tp object object new integer key components i null 0 i persistent key components i get oid object new byte byte boolean key components i boolean value 1 0 return new key new compound key key components key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type keycomponents keycomponents storageerror storageerror incompatible_key_type iscopy keycomponents classdescriptor tpobject classdescriptor tpboolean iscopy newkeycomponents keycomponents keycomponents newkeycomponents keycomponents keycomponents newkeycomponents iscopy keycomponents classdescriptor tpobject keycomponents ipersistent keycomponents getoid keycomponents booleanvalue compoundkey keycomponents public array list t get list key from key till return super get list convert key from convert key till arraylist getlist getlist convertkey convertkey public t get key key return super get convert key key convertkey public t remove key key return super remove convert key key convertkey public void remove key key t obj super remove convert key key obj convertkey public t set key key t obj return super set convert key key obj convertkey public boolean put key key t obj return super put convert key key obj convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public native thread string name int priority boolean dont check renice super name this current priority priority this dont check renice dont check renice nativethread dontcheckrenice currentpriority dontcheckrenice dontcheckrenice public native thread runnable r string name int priority boolean dont check renice super r name this current priority priority this dont check renice dont check renice nativethread dontcheckrenice currentpriority dontcheckrenice dontcheckrenice public native thread thread group g runnable r string name int priority boolean dont check renice super g r name this current priority priority this dont check renice dont check renice nativethread threadgroup dontcheckrenice currentpriority dontcheckrenice dontcheckrenice set linux priority jni call return true if successful false otherwise private static native boolean set linux priority int prio get linux priority jni call private static native int get linux priority setlinuxpriority getlinuxpriority override public void run if set native priority current priority system err println set native priority current priority has failed super run setnativepriority currentpriority setnativepriority currentpriority rescale java priority and set linux priority private boolean set native priority int prio logger minor this set native priority prio set priority prio if loadnative logger minor this loadnative is false return true int real prio get linux priority if disabled logger normal this not setting native priority as disabled due to renicing return false if native priority base real prio dont check renice the user has reniced freenet or we didn t use the packet sender to create the thread either ways it s bad for us let s disable the renicing as we can t rely on it anymore disabled true logger error this freenet has detected it has been reniced that s bad don t do it nice level detected statically native priority base actual nice level real prio on this system err println freenet has detected it has been reniced that s bad don t do it nice level detected statically native priority base actual nice level real prio on this new null pointer exception print stack trace return false final int linux priority native priority base native priority range native priority range prio min priority java priority range if linux priority real prio return true ok that s an obvious coding mistake if prio current priority throw new illegal state exception you re trying to set a thread priority above the current value it s not possible if you aren t root and shouldn t ever occur in our code asked prio linux priority current max current priority native priority base shoudln t happen please report logger minor this setting native priority to linux priority base native priority base for this return set linux priority linux priority setnativepriority setnativepriority setpriority _loadnative _loadnative realprio getlinuxpriority _disabled native_priority_base realprio dontcheckrenice packetsender _disabled native_priority_base realprio native_priority_base realprio nullpointerexception printstacktrace linuxpriority native_priority_base native_priority_range native_priority_range min_priority java_priority_range linuxpriority realprio currentpriority illegalstateexception linuxpriority currentmax currentpriority native_priority_base linuxpriority native_priority_base setlinuxpriority linuxpriority public int get native priority return current priority getnativepriority currentpriority public static boolean using native code return loadnative disabled usingnativecode _loadnative _disabled public static final string code2 string int code switch code case invalid action return invalid action case invalid args return invalid args case out of sync return out of sync case invalid var return invalid var case precondition failed return precondition failed case action failed return action failed return code2string invalid_action invalid_args out_of_sync invalid_var precondition_failed action_failed public u pnp status set code 0 set description upnpstatus setcode setdescription public u pnp status int code string desc set code code set description desc upnpstatus setcode setdescription public int get code return code getcode public void set code int code this code code setcode public string get description return description getdescription public void set description string description this description description setdescription override protected bucket make bucket long size throws io exception filename generator filename generator new filename generator weakprng false null junit temp file bucket file bucket new temp file bucket filename generator make random filename filename generator return new padded ephemerally encrypted bucket file bucket 1024 strongprng weakprng makebucket ioexception filenamegenerator filenamegenerator filenamegenerator tempfilebucket filebucket tempfilebucket filenamegenerator makerandomfilename filenamegenerator paddedephemerallyencryptedbucket filebucket override protected void free bucket bucket bucket throws io exception bucket free freebucket ioexception private int count public int size return count public array list t elements array list t list new array list t count fill list root zero fill list root one return list arraylist arraylist arraylist rootzero rootone public object to array return elements to array toarray toarray public e e to array e arr return elements to array arr toarray toarray public iterator t iterator return elements iterator private static e extends i persistent void fill array list e list p trie node e node if node null list add node obj fill list node child zero fill list node child one ipersistent arraylist ptrienode childzero childone private static int first bit long key int key length return int key key length 1 1 firstbit keylength keylength private static int get common part length long keya int key lengtha long keyb int key lengthb if key lengtha key lengthb keya key lengtha key lengthb key lengtha key lengthb else keyb key lengthb key lengtha key lengthb key lengtha long diff keya keyb int count 0 while diff 0 diff 1 count 1 return key lengtha count getcommonpartlength keylengtha keylengthb keylengtha keylengthb keylengtha keylengthb keylengtha keylengthb keylengthb keylengtha keylengthb keylengtha keylengtha public t add patricia trie key key t obj modify count 1 if first bit key mask key length 1 if root one null return root one add key mask key length obj else root one new p trie node t key mask key length obj return null else if root zero null return root zero add key mask key length obj else root zero new p trie node t key mask key length obj return null patriciatriekey firstbit rootone rootone rootone ptrienode rootzero rootzero rootzero ptrienode public t find best match patricia trie key key if first bit key mask key length 1 if root one null return root one find best match key mask key length else if root zero null return root zero find best match key mask key length return null findbestmatch patriciatriekey firstbit rootone rootone findbestmatch rootzero rootzero findbestmatch public t find exact match patricia trie key key if first bit key mask key length 1 if root one null return root one find exact match key mask key length else if root zero null return root zero find exact match key mask key length return null findexactmatch patriciatriekey firstbit rootone rootone findexactmatch rootzero rootzero findexactmatch public t remove patricia trie key key if first bit key mask key length 1 if root one null t obj root one remove key mask key length if obj null modify count 1 if root one is not used root one deallocate root one null return obj else if root zero null t obj root zero remove key mask key length if obj null modify count 1 if root zero is not used root zero deallocate root zero null return obj return null patriciatriekey firstbit rootone rootone rootone isnotused rootone rootone rootzero rootzero rootzero isnotused rootzero rootzero public void clear if root one null root one deallocate root one null if root zero null root zero deallocate root zero null count 0 rootone rootone rootone rootzero rootzero rootzero p trie node long key int key length t obj this obj obj this key key this key length key length ptrienode keylength keylength keylength p trie node ptrienode t add long key int key length t obj if key this key key length this key length modify t prev obj this obj this obj obj return prev obj int key length common get common part length key key length this key this key length int key length diff this key length key length common long key common key key length key length common long key diff this key key common key length diff if key length diff 0 modify p trie node t new node new p trie node t key diff key length diff this obj new node child zero child zero new node child one child one this key key common this key length key length common this obj null if first bit key diff key length diff 1 child zero null child one new node else child zero new node child one null if key length key length common key length diff key length key length common key diff key key common key length diff if first bit key diff key length diff 1 if child one null return child one add key diff key length diff obj else modify child one new p trie node t key diff key length diff obj return null else if child zero null return child zero add key diff key length diff obj else modify child zero new p trie node t key diff key length diff obj return null else t prev obj this obj this obj obj return prev obj keylength keylength keylength prevobj prevobj keylengthcommon getcommonpartlength keylength keylength keylengthdiff keylength keylengthcommon keycommon keylength keylengthcommon keydiff keycommon keylengthdiff keylengthdiff ptrienode newnode ptrienode keydiff keylengthdiff newnode childzero childzero newnode childone childone keycommon keylength keylengthcommon firstbit keydiff keylengthdiff childzero childone newnode childzero newnode childone keylength keylengthcommon keylengthdiff keylength keylengthcommon keydiff keycommon keylengthdiff firstbit keydiff keylengthdiff childone childone keydiff keylengthdiff childone ptrienode keydiff keylengthdiff childzero childzero keydiff keylengthdiff childzero ptrienode keydiff keylengthdiff prevobj prevobj t find best match long key int key length if key length this key length int key length common get common part length key key length this key this key length int key length diff key length key length common long key common key key length diff long key diff key key common key length diff if first bit key diff key length diff 1 if child one null return child one find best match key diff key length diff else if child zero null return child zero find best match key diff key length diff return obj findbestmatch keylength keylength keylength keylengthcommon getcommonpartlength keylength keylength keylengthdiff keylength keylengthcommon keycommon keylengthdiff keydiff keycommon keylengthdiff firstbit keydiff keylengthdiff childone childone findbestmatch keydiff keylengthdiff childzero childzero findbestmatch keydiff keylengthdiff t find exact match long key int key length if key length this key length if key this key key length this key length return obj else int key length common get common part length key key length this key this key length if key length common this key length int key length diff key length key length common long key common key key length diff long key diff key key common key length diff if first bit key diff key length diff 1 if child one null return child one find best match key diff key length diff else if child zero null return child zero find best match key diff key length diff return null findexactmatch keylength keylength keylength keylength keylength keylengthcommon getcommonpartlength keylength keylength keylengthcommon keylength keylengthdiff keylength keylengthcommon keycommon keylengthdiff keydiff keycommon keylengthdiff firstbit keydiff keylengthdiff childone childone findbestmatch keydiff keylengthdiff childzero childzero findbestmatch keydiff keylengthdiff boolean is not used return obj null child one null child zero null isnotused childone childzero t remove long key int key length if key length this key length if key this key key length this key length t obj this obj this obj null return obj else int key length common get common part length key key length this key this key length int key length diff key length key length common long key common key key length diff long key diff key key common key length diff if first bit key diff key length diff 1 if child one null t obj child one find best match key diff key length diff if obj null if child one is not used modify child one deallocate child one null return obj else if child zero null t obj child zero find best match key diff key length diff if obj null if child zero is not used modify child zero deallocate child zero null return obj return null keylength keylength keylength keylength keylength keylengthcommon getcommonpartlength keylength keylength keylengthdiff keylength keylengthcommon keycommon keylengthdiff keydiff keycommon keylengthdiff firstbit keydiff keylengthdiff childone childone findbestmatch keydiff keylengthdiff childone isnotused childone childone childzero childzero findbestmatch keydiff keylengthdiff childzero isnotused childzero childzero public void deallocate if child one null child one deallocate if child zero null child zero deallocate super deallocate childone childone childzero childzero construct a curl filter with no distortion public curl filter set edge action zero curlfilter curlfilter setedgeaction public void set transition float transition this transition transition settransition public float get transition return transition gettransition public void set angle float angle this angle angle setangle public float get angle return angle getangle public void set radius float radius this radius radius setradius public float get radius return radius getradius public sampler buffered image image int width image get width int height image get height int type image get type in pixels image utils getrgb image 0 0 width height null bufferedimage getwidth getheight gettype inpixels imageutils public int sample float x float y int srcx int math floor x int srcy int math floor y float x weight x srcx float y weight y srcy int nw ne sw se if srcx 0 srcx width 1 srcy 0 srcy height 1 easy case all corners are in the image int i width srcy srcx nw in pixels i ne in pixels i 1 sw in pixels i width se in pixels i width 1 else some of the corners are off the image nw get pixel in pixels srcx srcy width height ne get pixel in pixels srcx 1 srcy width height sw get pixel in pixels srcx srcy 1 width height se get pixel in pixels srcx 1 srcy 1 width height return image math bilinear interpolate x weight y weight nw ne sw se xweight yweight inpixels inpixels inpixels inpixels getpixel inpixels getpixel inpixels getpixel inpixels getpixel inpixels imagemath bilinearinterpolate xweight yweight final private int get pixel int pixels int x int y int width int height if x 0 x width y 0 y height switch edge action case zero default return 0 case wrap return pixels image math mod y height width image math mod x width case clamp return pixels image math clamp y 0 height 1 width image math clamp x 0 width 1 return pixels y width x getpixel edgeaction imagemath imagemath imagemath imagemath override public buffered image filter buffered image src buffered image dst int width src get width int height src get height this width src get width this height src get height int type src get type original space new rectangle 0 0 width height transformed space new rectangle 0 0 width height transform space transformed space if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster transformed space width transformed space height dstcm is alpha premultiplied null writable raster dst raster dst get raster int in pixels getrgb src 0 0 width height null if interpolation nearest neighbour return filter pixelsnn dst width height in pixels transformed space int src width width int src height height int src width1 width 1 int src height1 height 1 int out width transformed space width int out height transformed space height int outx outy int index 0 int out pixels new int out width outx transformed space x outy transformed space y float out new float 4 for int y 0 y out height y for int x 0 x out width x transform inverse outx x outy y out int srcx int math floor out 0 int srcy int math floor out 1 float x weight out 0 srcx float y weight out 1 srcy int nw ne sw se if srcx 0 srcx src width1 srcy 0 srcy src height1 easy case all corners are in the image int i src width srcy srcx nw in pixels i ne in pixels i 1 sw in pixels i src width se in pixels i src width 1 else some of the corners are off the image nw get pixel in pixels srcx srcy src width src height ne get pixel in pixels srcx 1 srcy src width src height sw get pixel in pixels srcx srcy 1 src width src height se get pixel in pixels srcx 1 srcy 1 src width src height int rgb image math bilinear interpolate x weight y weight nw ne sw se int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff float shade out 2 r int r shade g int g shade b int b shade rgb rgb 0xff000000 r 16 g 8 b if out 3 0 out pixels x pixel utils combine pixels rgb in pixels src width y x pixel utils normal else out pixels x rgb setrgb dst 0 y transformed space width 1 out pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight getwidth getheight gettype originalspace transformedspace transformspace transformedspace colormodel getcolormodel bufferedimage createcompatiblewritableraster transformedspace transformedspace isalphapremultiplied writableraster dstraster getraster inpixels nearest_neighbour filterpixelsnn inpixels transformedspace srcwidth srcheight srcwidth1 srcheight1 outwidth transformedspace outheight transformedspace outpixels outwidth transformedspace transformedspace outheight outwidth transforminverse xweight yweight srcwidth1 srcheight1 srcwidth inpixels inpixels inpixels srcwidth inpixels srcwidth getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight imagemath bilinearinterpolate xweight yweight outpixels pixelutils combinepixels inpixels srcwidth pixelutils outpixels transformedspace outpixels final private int get pixel int pixels int x int y int width int height if x 0 x width y 0 y height switch edge action case zero default return 0 case wrap return pixels image math mod y height width image math mod x width case clamp return pixels image math clamp y 0 height 1 width image math clamp x 0 width 1 return pixels y width x getpixel edgeaction imagemath imagemath imagemath imagemath override protected void transform inverse int x int y float out fisheye float mirror distance width centrex float mirror radius width centrey float cx width 5f float cy height 5f float dx x cx float dy y cy float r2 dx dx dy dy float r float math sqrt r2 float phi float math pi 5 math asin math sqrt mirror radius mirror radius r2 mirror radius r r mirror radius width mirror distance float math tan phi phi float math atan2 dy dx out 0 cx r float math cos phi out 1 cy r float math sin phi float t transition float px x py y float s float math sin angle float c float math cos angle float tx t width tx t float math sqrt width width height height start from the correct corner according to the angle float xoffset c 0 width 0 float yoffset s 0 height 0 transform into unrotated coordinates px xoffset py yoffset float qx px c py s float qy px s py c boolean outside qx tx boolean unfolded qx tx 2 boolean oncurl outside unfolded qx qx tx 2 qx 2 tx qx transform back into rotated coordinates px qx c qy s py qx s qy c px xoffset py yoffset see if we re off the edge of the page boolean offpage px 0 py 0 px width py height if we re off the edge but in the curl if offpage oncurl px x py y shade the curl float shade offpage oncurl 1 9f 1 0f float math cos math exp qx tx radius 0 out 2 1 shade if outside out 0 out 1 1 else out 0 px out 1 py out 3 offpage oncurl 1 0 transforminverse mirrordistance mirrorradius mirrorradius mirrorradius mirrorradius mirrorradius mirrordistance override public string to string return distort curl tostring private static final long serial versionuid 2379889735659369065l public http server list serialversionuid httpserverlist public void add request listener http request listener listener int n servers size for int n 0 n n servers n http server server gethttp server n server add request listener listener addrequestlistener httprequestlistener nservers nservers httpserver gethttpserver addrequestlistener public http server gethttp server int n return http server get n httpserver gethttpserver httpserver public void close int n servers size for int n 0 n n servers n http server server gethttp server n server close nservers nservers httpserver gethttpserver public boolean open int port int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n http server http server new http server if http server open bind addr port false close clear return false add http server return true nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress httpserver httpserver httpserver httpserver bindaddr httpserver public void start int n servers size for int n 0 n n servers n http server server gethttp server n server start nservers nservers httpserver gethttpserver public void stop int n servers size for int n 0 n n servers n http server server gethttp server n server stop nservers nservers httpserver gethttpserver private final string id public node hello message final node node string id this node node this id id nodehellomessage override public simple field set get field set simple field set sfs new simple field set true fixme sfs put single fcp version 2 0 sfs put single node fred sfs put single version version get version string sfs put build version build number sfs put single revision version cvs revision sfs put ext build node starter ext build number sfs put single ext revision node starter ext revision number sfs put single testnet boolean to string node null false node is testnet enabled sfs put single compression codecs integer to string compressor compressor type values length sfs put single connection identifier id sfs put single node language l10n get selected language to string return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle fcpversion putsingle putsingle getversionstring buildnumber putsingle cvsrevision extbuild nodestarter extbuildnumber putsingle extrevision nodestarter extrevisionnumber putsingle tostring istestnetenabled putsingle compressioncodecs tostring compressor_type putsingle connectionidentifier putsingle nodelanguage getselectedlanguage tostring override public string get name return node hello message name getname nodehellomessage override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message node hello goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message nodehello override public void remove from object container container container delete this removefrom objectcontainer public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int in pixels new int width height int out pixels new int width height getrgb src 0 0 width height in pixels kernel kernel gaussian filter make kernel h radius threshold blur kernel in pixels out pixels width height true threshold blur kernel out pixels in pixels height width true setrgb dst 0 0 width height in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage inpixels outpixels inpixels gaussianfilter makekernel hradius thresholdblur inpixels outpixels thresholdblur outpixels inpixels inpixels convolve with a kernel consisting of one row private void threshold blur kernel kernel int in pixels int out pixels int width int height boolean alpha int index 0 float matrix kernel get kernel data null int cols kernel get width int cols2 cols 2 for int y 0 y height y int ioffset y width int out index y for int x 0 x width x float r 0 g 0 b 0 a 0 int moffset cols2 int rgb1 in pixels ioffset x int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff float af 0 rf 0 gf 0 bf 0 for int col cols2 col cols2 col float f matrix moffset col if f 0 int ix x col if 0 ix ix width ix x int rgb2 in pixels ioffset ix int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff int d d a1 a2 if d threshold d threshold a f a2 af f d r1 r2 if d threshold d threshold r f r2 rf f d g1 g2 if d threshold d threshold g f g2 gf f d b1 b2 if d threshold d threshold b f b2 bf f a af 0 a1 a af r rf 0 r1 r rf g gf 0 g1 g gf b bf 0 b1 b bf int ia alpha pixel utils clamp int a 0 5 0xff int ir pixel utils clamp int r 0 5 int ig pixel utils clamp int g 0 5 int ib pixel utils clamp int b 0 5 out pixels out index ia 24 ir 16 ig 8 ib out index height thresholdblur inpixels outpixels getkerneldata getwidth outindex inpixels inpixels pixelutils pixelutils pixelutils pixelutils outpixels outindex outindex set the horizontal size of the blur param h radius the radius of the blur in the horizontal direction min value 0 see geth radius public void seth radius int h radius this h radius h radius hradius gethradius sethradius hradius hradius hradius get the horizontal size of the blur return the radius of the blur in the horizontal direction see seth radius public int geth radius return h radius sethradius gethradius hradius set the vertical size of the blur param v radius the radius of the blur in the vertical direction min value 0 see getv radius public void setv radius int v radius this v radius v radius vradius getvradius setvradius vradius vradius vradius get the vertical size of the blur return the radius of the blur in the vertical direction see setv radius public int getv radius return v radius setvradius getvradius vradius set the radius of the effect param radius the radius min value 0 see get radius public void set radius int radius this h radius this v radius radius getradius setradius hradius vradius get the radius of the effect return the radius see set radius public int get radius return h radius setradius getradius hradius set the threshold value param threshold the threshold value see get threshold public void set threshold int threshold this threshold threshold getthreshold setthreshold get the threshold value return the threshold value see set threshold public int get threshold return threshold setthreshold getthreshold override public string to string return blur smart blur tostring public peer message peer node pn boolean with metadata boolean with volatile string identifier this pn pn this with metadata with metadata this with volatile with volatile this identifier identifier peermessage peernode withmetadata withvolatile withmetadata withmetadata withvolatile withvolatile override public simple field set get field set simple field set fs pn export field set if with metadata simple field set meta pn export metadata field set if meta is empty fs put metadata meta if with volatile simple field set vol pn export volatile field set if vol is empty fs put volatile vol if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset exportfieldset withmetadata simplefieldset exportmetadatafieldset isempty withvolatile simplefieldset exportvolatilefieldset isempty putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message peer goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container container delete this removefrom objectcontainer public class node data public node data set node null nodedata nodedata setnode private node node public void set node node node this node node setnode public node get node return node getnode private usk fetcher tag usk origusk usk fetcher callback callback long nodedb handle boolean persistent object container container fetch context ctx boolean keep last data long token boolean has own fetch context this nodedb handle nodedb handle this callback callback this origusk origusk this edition origusk suggested edition this persistent persistent this ctx ctx this keep last data keep last data this token token this own fetch context has own fetch context polling priority normal callback get polling priority normal polling priority progress callback get polling priority progress priority polling priority normal uskfetchertag uskfetchercallback nodedbhandle objectcontainer fetchcontext keeplastdata hasownfetchcontext nodedbhandle nodedbhandle suggestededition keeplastdata keeplastdata ownfetchcontext hasownfetchcontext pollingprioritynormal getpollingprioritynormal pollingpriorityprogress getpollingpriorityprogress pollingprioritynormal for a persistent request the caller must call remove from database when finished note that the caller is responsible for deleting the usk fetcher callback and the fetch context param usk param callback param nodedb handle param persistent param container param ctx param keep last param token return public static usk fetcher tag create usk usk usk fetcher callback callback long nodedb handle boolean persistent object container container fetch context ctx boolean keep last int token boolean has own fetch context usk fetcher tag tag new usk fetcher tag usk callback nodedb handle persistent container ctx keep last token has own fetch context if persistent container store tag return tag removefromdatabase uskfetchercallback fetchcontext nodedbhandle keeplast uskfetchertag uskfetchercallback nodedbhandle objectcontainer fetchcontext keeplast hasownfetchcontext uskfetchertag uskfetchertag nodedbhandle keeplast hasownfetchcontext synchronized void updated edition long ed object container container if edition ed edition ed if persistent container store this update updatededition objectcontainer private static final request client client new request client public boolean persistent the actual usk fetch is non persistent only the tags survive a restart return false requestclient requestclient public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public void start usk manager manager client context context object container container usk usk origusk if persistent container activate origusk 5 if usk suggested edition edition usk usk copy edition else if persistent copy it to avoid deactivation issues usk usk clone fetcher manager get fetcher usk ctx new usk fetcher wrapper usk priority client keep last data fetcher add callback this fetcher schedule null context non persistent uskmanager clientcontext objectcontainer suggestededition getfetcher uskfetcherwrapper keeplastdata addcallback public void cancel object container container client context context if fetcher null fetcher cancel null context synchronized this finished true on cancelled will remove from so we do not want to store this objectcontainer clientcontext oncancelled removefrom public long get token return token gettoken public void schedule object container container client context context start context usk manager context container objectcontainer clientcontext uskmanager public void on cancelled object container container client context context synchronized this finished true if persistent if cancelled externally and this function is called from usk fetcher container may be null even though we are running on the database thread resulting in a database leak context job runner run blocking new db job public void run object container container client context context container activate callback 1 callback on cancelled container context remove from container context container deactivate callback 1 native thread high priority else callback on cancelled container context oncancelled objectcontainer clientcontext uskfetcher jobrunner runblocking dbjob objectcontainer clientcontext oncancelled removefrom nativethread high_priority oncancelled public void run object container container client context context container activate callback 1 callback on cancelled container context remove from container context container deactivate callback 1 objectcontainer clientcontext oncancelled removefrom public void on failure object container container client context context synchronized this finished true if persistent if container null container activate callback 1 callback on failure container context container deactivate callback 1 remove from container context else context job runner queue new db job public void run object container container client context context container activate callback 1 callback on failure container context container deactivate callback 1 remove from container context native thread high priority false else callback on failure container context onfailure objectcontainer clientcontext onfailure removefrom jobrunner dbjob objectcontainer clientcontext onfailure removefrom nativethread high_priority onfailure public void run object container container client context context container activate callback 1 callback on failure container context container deactivate callback 1 remove from container context objectcontainer clientcontext onfailure removefrom public short get polling priority normal return polling priority normal getpollingprioritynormal pollingprioritynormal public short get polling priority progress return polling priority progress getpollingpriorityprogress pollingpriorityprogress public void on found edition final long l final usk key object container container client context context final boolean metadata final short codec final byte data final boolean new known good final boolean new slot too synchronized this if fetcher null logger error this on found edition but fetcher is null isn t on found edition terminal for usk fetcher callback s new exception debug finished true fetcher null if persistent if container null container activate callback 1 callback on found edition l key container context metadata codec data new known good new slot too container deactivate callback 1 remove from container context else context job runner queue new db job public void run object container container client context context container activate callback 1 callback on found edition l key container context metadata codec data new known good new slot too container deactivate callback 1 remove from container context native thread high priority false else callback on found edition l key container context metadata codec data new known good new slot too onfoundedition objectcontainer clientcontext newknowngood newslottoo onfoundedition onfoundedition uskfetchercallback onfoundedition newknowngood newslottoo removefrom jobrunner dbjob objectcontainer clientcontext onfoundedition newknowngood newslottoo removefrom nativethread high_priority onfoundedition newknowngood newslottoo public void run object container container client context context container activate callback 1 callback on found edition l key container context metadata codec data new known good new slot too container deactivate callback 1 remove from container context objectcontainer clientcontext onfoundedition newknowngood newslottoo removefrom public final boolean is finished return finished isfinished override public void should update logminor logger should log logger minor this logdebug logger should log logger minor this shouldupdate shouldlog shouldlog public void remove from object container container client context context if logminor logger minor this removing this container activate origusk 5 origusk remove from container if own fetch context container activate ctx 1 ctx remove from container container delete this removefrom objectcontainer clientcontext removefrom ownfetchcontext removefrom public boolean object can deactivate object container container return false objectcandeactivate objectcontainer private string value new string public parameter public parameter string name string value set name name set value value setname setvalue public void set name string name this name name setname public string get name return name getname public void set value string value this value value setvalue public string get value return value getvalue binary blob inserter bucket blob client putter parent request client client context boolean tolerant short prio class insert context ctx client context context object container container throws io exception binary blob format exception logminor logger should log logger minor this this ctx ctx this max retries ctx max insert retries this consecutivern fs count as success ctx consecutivern fs count as success this parent parent this client context client context this errors new failure code tracker true data input stream dis new data input stream blob get input stream block set blocks new simple block set binary blob read binary blob dis blocks tolerant dis close vector my inserters new vector iterator i blocks keys iterator int x 0 while i has next key key key i next key block block blocks get key my sendable insert inserter new my sendable insert x block prio class get scheduler block context client context my inserters add inserter inserters my sendable insert my inserters to array new my sendable insert my inserters size parent add must succeed blocks inserters length container parent notify clients container context binaryblobinserter clientputter requestclient clientcontext prioclass insertcontext clientcontext objectcontainer ioexception binaryblobformatexception shouldlog maxretries maxinsertretries consecutivernfscountassuccess consecutivernfscountassuccess clientcontext clientcontext failurecodetracker datainputstream datainputstream getinputstream blockset simpleblockset binaryblob readbinaryblob myinserters hasnext keyblock mysendableinsert mysendableinsert prioclass getscheduler clientcontext myinserters mysendableinsert myinserters toarray mysendableinsert myinserters addmustsucceedblocks notifyclients private client request scheduler get scheduler key block block client context context if block instanceof chk block return context get chk insert scheduler else if block instanceof ssk block return context get ssk insert scheduler else throw new illegal argument exception unknown block type block get class block clientrequestscheduler getscheduler keyblock clientcontext chkblock getchkinsertscheduler sskblock getsskinsertscheduler illegalargumentexception getclass public void cancel object container container client context context for int i 0 i inserters length i if inserters i null inserters i cancel container context parent on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext onfailure insertexception insertexception public base client putter get parent return parent baseclientputter getparent public object get token return client context gettoken clientcontext public void schedule object container container client context context throws insert exception for int i 0 i inserters length i inserters i schedule objectcontainer clientcontext insertexception private int retries public my sendable insert int i key block block short prio class client request scheduler scheduler request client client super block prio class client scheduler this block num i mysendableinsert keyblock prioclass clientrequestscheduler requestclient prioclass blocknum public void on success object container container client context context synchronized this if inserters block num null return inserters block num null completed blocks succeeded blocks parent completed block false container context maybe finish container context onsuccess objectcontainer clientcontext blocknum blocknum completedblocks succeededblocks completedblock maybefinish fixme combine it somehow override public void on failure low level put exception e object key num object container container client context context synchronized binary blob inserter this if inserters block num null return if parent is cancelled fail new insert exception insert exception cancelled true container context return logminor logger should log logger minor binary blob inserter this switch e code case low level put exception collision fail new insert exception insert exception collision false container context break case low level put exception internal error errors inc insert exception internal error break case low level put exception rejected overload errors inc insert exception rejected overload break case low level put exception route not found errors inc insert exception route not found break case low level put exception route really not found errors inc insert exception route really not found break default logger error this unknown low level put exception code e code errors inc insert exception internal error if e code low level put exception route not found consecutivern fs if logminor logger minor this consecutive rn fs consecutivern fs consecutivern fs count as success if consecutivern fs consecutivern fs count as success if logminor logger minor this consecutive rn fs consecutivern fs counting as success on success container context return else consecutivern fs 0 if logminor logger minor this failed e retries if retries max retries max retries 1 fail insert exception construct errors false container context return retry this block this schedule onfailure lowlevelputexception keynum objectcontainer clientcontext binaryblobinserter blocknum iscancelled insertexception insertexception shouldlog binaryblobinserter lowlevelputexception insertexception insertexception lowlevelputexception internal_error insertexception internal_error lowlevelputexception rejected_overload insertexception rejected_overload lowlevelputexception route_not_found insertexception route_not_found lowlevelputexception route_really_not_found insertexception route_really_not_found lowlevelputexception insertexception internal_error lowlevelputexception route_not_found consecutivernfs rnfs consecutivernfs consecutivernfscountassuccess consecutivernfs consecutivernfscountassuccess rnfs consecutivernfs onsuccess consecutivernfs maxretries maxretries insertexception private void fail insert exception e boolean fatal object container container client context context synchronized binary blob inserter this if inserters block num null return inserters block num null completed blocks if fatal binary blob inserter this fatal true if fatal parent fatally failed block container context else parent failed block container context maybe finish container context insertexception objectcontainer clientcontext binaryblobinserter blocknum blocknum completedblocks binaryblobinserter fatallyfailedblock failedblock maybefinish override public boolean should cache return ctx cache local requests shouldcache cachelocalrequests public void maybe finish object container container client context context boolean success boolean was fatal synchronized this if completed blocks inserters length return success completed blocks succeeded blocks was fatal fatal if success parent on success this container context else if was fatal parent on failure new insert exception insert exception fatal errors in blocks errors null this container context else parent on failure new insert exception insert exception too many retries in blocks errors null this container context maybefinish objectcontainer clientcontext wasfatal completedblocks completedblocks succeededblocks wasfatal onsuccess wasfatal onfailure insertexception insertexception fatal_errors_in_blocks onfailure insertexception insertexception too_many_retries_in_blocks public void remove from object container container client context context fixme persistent blob inserts are not supported throw new unsupported operation exception removefrom objectcontainer clientcontext unsupportedoperationexception it converts a given time interval into a week day hour second milliseconds string param time interval interval to convert param max terms the terms number to display e g 2 means h and m if the time could be expressed in hour 3 means h m s in the same example the maximum terms number available is 6 param with second fractions if true it displays seconds milliseconds return the formatted string public static string format time long time interval int max terms boolean with second fractions if max terms 6 throw new illegal argument exception string builder sb new string builder 64 long l time interval int term count 0 if l 0 sb append l l 1 if with second fractions l 1000 return 0 if term count max terms return sb to string long weeks l 7l 24 60 60 1000 if weeks 0 sb append weeks append w term count l l weeks 7l 24 60 60 1000 if term count max terms return sb to string long days l 24l 60 60 1000 if days 0 sb append days append d term count l l days 24l 60 60 1000 if term count max terms return sb to string long hours l 60l 60 1000 if hours 0 sb append hours append h term count l l hours 60l 60 1000 if term count max terms return sb to string long minutes l 60l 1000 if minutes 0 sb append minutes append m term count l l minutes 60l 1000 if term count max terms return sb to string if with second fractions max terms term count 2 if l 0 double fractional seconds l 1000 0d decimal format fix3 new decimal format 0 000 sb append fix3 format fractional seconds append s term count l l long fractional seconds long 1000 else long seconds l 1000l if seconds 0 sb append seconds append s term count l l long seconds long 1000 return sb to string timeinterval maxterms withsecondfractions formattime timeinterval maxterms withsecondfractions maxterms illegalargumentexception stringbuilder stringbuilder timeinterval termcount withsecondfractions termcount maxterms tostring termcount termcount maxterms tostring termcount termcount maxterms tostring termcount termcount maxterms tostring termcount termcount maxterms tostring withsecondfractions maxterms termcount fractionalseconds decimalformat decimalformat fractionalseconds termcount fractionalseconds termcount tostring public static string format time long time interval return format time time interval 2 false formattime timeinterval formattime timeinterval public static string format time long time interval int max terms return format time time interval max terms false formattime timeinterval maxterms formattime timeinterval maxterms public class chk store extends store callback override public boolean collision possible return false chkstore storecallback collisionpossible override public storable block construct byte data byte headers byte routing key byte full key throws key verify exception if data null headers null throw new chk verify exception need either data and headers return chk block construct data headers storableblock routingkey fullkey keyverifyexception chkverifyexception chkblock public chk block fetch nodechk chk boolean dont promote throws io exception return chk block store fetch chk get routing key null dont promote chkblock dontpromote ioexception chkblock getroutingkey dontpromote public void put chk block b throws io exception nodechk key nodechk b get key try store put b key get routing key key get full key b get raw data b get raw headers false catch key collision exception e logger error this impossible for chk store e e chkblock ioexception getkey getroutingkey getfullkey getrawdata getrawheaders keycollisionexception chkstore override public int data length return chk block data length datalength chkblock data_length override public int full key length return nodechk full key length fullkeylength full_key_length override public int header length return chk block total headers length headerlength chkblock total_headers_length override public int routing key length return nodechk key length routingkeylength key_length override public boolean store full keys worth the extra two file descriptors because if we have the keys we can do lazy reconstruction i e don t construct each block just transcode from the keys file straight into the database return true storefullkeys override public boolean construct needs key return false constructneedskey override public byte routing key from full key byte key buf return nodechk routing key from full key key buf routingkeyfromfullkey keybuf routingkeyfromfullkey keybuf private static final long serial versionuid 7670838856130773012l public archive restart exception string msg super msg serialversionuid archiverestartexception public ssdp search response socket set control point null ssdpsearchresponsesocket setcontrolpoint public ssdp search response socket string bind addr int port super bind addr port set control point null ssdpsearchresponsesocket bindaddr bindaddr setcontrolpoint private control point control point null public void set control point control point ctrlp this control point ctrlp controlpoint controlpoint setcontrolpoint controlpoint controlpoint public control point get control point return control point controlpoint getcontrolpoint controlpoint public void run thread this thread thread current thread control point ctrl point get control point while device search response thread this thread thread yield ssdp packet packet receive if packet null break if ctrl point null ctrl point search response received packet thisthread currentthread controlpoint ctrlpoint getcontrolpoint devicesearchresponsethread thisthread ssdppacket ctrlpoint ctrlpoint searchresponsereceived public void start device search response thread new thread this u pnp ssdp search response socket device search response thread set daemon true device search response thread start devicesearchresponsethread upnp ssdpsearchresponsesocket devicesearchresponsethread setdaemon devicesearchresponsethread public void stop device search response thread null devicesearchresponsethread public boolean post string addr int port ssdp search response res return post addr port res get header ssdpsearchresponse getheader public boolean post string addr int port ssdp search request req return post addr port req to string ssdpsearchrequest tostring private float m11 1 0f public swim filter swimfilter set the amount of swim param amount the amount of swim min value 0 max value 100 see get amount public void set amount float amount this amount amount getamount setamount get the amount of swim return the amount swim see set amount public float get amount return amount setamount getamount specifies the scale of the distortion param scale the scale of the distortion min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the distortion return the scale of the distortion see set scale public float get scale return scale setscale getscale specifies the stretch factor of the distortion param stretch the stretch factor of the distortion min value 1 max value 50 see get stretch public void set stretch float stretch this stretch stretch getstretch setstretch returns the stretch factor of the distortion return the stretch factor of the distortion see set stretch public float get stretch return stretch setstretch getstretch specifies the angle of the effect param angle the angle of the effect angle see get angle public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos getangle setangle returns the angle of the effect return the angle of the effect see set angle public float get angle return angle setangle getangle specifies the turbulence of the texture param turbulence the turbulence of the texture min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the effect return the turbulence of the effect see set turbulence public float get turbulence return turbulence setturbulence getturbulence specifies the time use this to animate the effect param time the time angle see get time public void set time float time this time time gettime settime returns the time return the time see set time public float get time return time settime gettime override protected void transform inverse int x int y float out float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch if turbulence 1 0f out 0 x amount noise noise3 nx 0 5f ny time out 1 y amount noise noise3 nx ny 0 5f time else out 0 x amount noise turbulence3 nx 0 5f ny turbulence time out 1 y amount noise turbulence3 nx ny 0 5f turbulence time transforminverse override public string to string return distort swim tostring param args throws io exception public static void main string args throws io exception file f1 new file args 0 file f2 new file args 1 simple field set fs1 simple field set read from f1 false true simple field set fs2 simple field set read from f2 false true fs1 put all overwrite fs2 print writer pw new print writer system out fs1 write to ordered pw pw flush ioexception ioexception simplefieldset simplefieldset readfrom simplefieldset simplefieldset readfrom putalloverwrite printwriter printwriter writetoordered transient field fld rnd btree multi field index rndbtreemultifieldindex rnd btree multi field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate fields type class descriptor tp raw rndbtreemultifieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefields classdescriptor tpraw private final void locate fields class scope cls fld new field field name length for int i 0 i field name length i fld i class descriptor locate field cls field name i if fld i null throw new storage error storage error indexed field not found class name field name i locatefields fieldname fieldname classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return fld getkeyfields public void on load cls class descriptor load class get storage class name locate fields onload classdescriptor loadclass getstorage classname locatefields public int compare to object o compound key c compound key o int n keys length c keys length keys length c keys length for int i 0 i n i int diff comparable keys i compare to c keys i if diff 0 return diff return 0 allow to compare part of the compound key compareto compoundkey compoundkey compareto compound key object keys this keys keys compoundkey private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type return new key new compound key object key oval key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type compoundkey private key extract key i persistent obj object keys new object fld length try for int i 0 i keys length i keys i fld i get obj if keys i instanceof i persistent i persistent p i persistent keys i if p is persistent get storage make persistent p catch exception x throw new storage error storage error access violation x return new key new compound key keys extractkey ipersistent ipersistent ipersistent ipersistent ispersistent getstorage makepersistent storageerror storageerror access_violation compoundkey public boolean put t obj return super put extract key obj obj extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public t remove key key return super remove convert key key convertkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public void append t obj throw new storage error storage error unsupported index type storageerror storageerror unsupported_index_type public t get key from key till array list list new array list if root null root find convert key from convert key till height list return t list to array t array new instance cls list size arraylist arraylist convertkey convertkey toarray newinstance public t get prefix string prefix throw new storage error storage error incompatible key type getprefix storageerror storageerror incompatible_key_type public t prefix search string key throw new storage error storage error incompatible key type prefixsearch storageerror storageerror incompatible_key_type public t to persistent array t arr t array new instance cls n elems if root null root traverse forward height arr 0 return arr topersistentarray newinstance nelems traverseforward public t get key key return super get convert key key convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class rnd btree case insensitive multi field index t extends i persistent extends rnd btree multi field index t rnd btree case insensitive multi field index rndbtreecaseinsensitivemultifieldindex ipersistent rndbtreemultifieldindex rndbtreecaseinsensitivemultifieldindex rnd btree case insensitive multi field index rnd btree case insensitive multi field index class cls string field names boolean unique super cls field names unique rndbtreecaseinsensitivemultifieldindex rndbtreecaseinsensitivemultifieldindex fieldnames fieldnames key check key key key if key null compound key ck compound key key oval for int i 0 i ck keys length i if ck keys i instanceof string ck keys i string ck keys i to lower case return super check key key checkkey compoundkey compoundkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive public class snmp port number callback extends int callback public snmp port number callback snmpportnumbercallback intcallback snmpportnumbercallback public integer get return snmp agent getsnmp agent getsnm port snmpagent getsnmpagent getsnmport public void set integer val throws invalid config value exception if val equals get snmp agent setsnmp port val invalidconfigvalueexception snmpagent setsnmpport create an entry dns entry string name int type int clazz this key name to lower case this name name this type type this clazz clazz dns constants class mask this unique clazz dns constants class unique 0 dnsentry tolowercase dnsconstants class_mask dnsconstants class_unique check if two entries have exactly the same name type and class public boolean equals object obj if obj instanceof dns entry dns entry other dns entry obj return name equals other name type other type clazz other clazz return false dnsentry dnsentry dnsentry public string get name return name getname public int get type return type gettype overriden to return a value which is consistent with the value returned by equals object public int hash code return name hash code type clazz hashcode hashcode get a string given a clazz static string get clazz int clazz switch clazz dns constants class mask case dns constants class in return in case dns constants class cs return cs case dns constants class ch return ch case dns constants class hs return hs case dns constants class none return none case dns constants class any return any default return getclazz dnsconstants class_mask dnsconstants class_in dnsconstants class_cs dnsconstants class_ch dnsconstants class_hs dnsconstants class_none dnsconstants class_any get a string given a type static string get type int type switch type case dns constants type a return a case dns constants type aaaa return aaaa case dns constants type ns return ns case dns constants type md return md case dns constants type mf return mf case dns constants type cname return cname case dns constants type soa return soa case dns constants type mb return mb case dns constants type mg return mg case dns constants type mr return mr case dns constants type null return null case dns constants type wks return wks case dns constants type ptr return ptr case dns constants type hinfo return hinfo case dns constants type minfo return minfo case dns constants type mx return mx case dns constants type txt return txt case dns constants type srv return srv case dns constants type any return any default return gettype dnsconstants type_a dnsconstants type_aaaa dnsconstants type_ns dnsconstants type_md dnsconstants type_mf dnsconstants type_cname dnsconstants type_soa dnsconstants type_mb dnsconstants type_mg dnsconstants type_mr dnsconstants type_null dnsconstants type_wks dnsconstants type_ptr dnsconstants type_hinfo dnsconstants type_minfo dnsconstants type_mx dnsconstants type_txt dnsconstants type_srv dnsconstants type_any public string to string string hdr string other return hdr get type type get clazz clazz unique unique name other null other tostring gettype getclazz tries to resolve the best type of cpu that we have an optimized jbigi dll so for return a string containing the cpu type or null if cpu type is unknown private static string resolvecpu type try if system get property os arch to lower case matches i x0 9 86 64 amd64 return jbigi optimization x86 64 else if system get property os arch to lower case matches ppc system out println detected powerpc return jbigi optimization ppc else cpu info c cpuid get info if c instanceof amdcpu info amdcpu info amdcpu amdcpu info c if amdcpu is athlon64 compatible return jbigi optimization x86 64 32 if amdcpu is athlon compatible return jbigi optimization athlon if amdcpu isk6 3 compatible return jbigi optimization k6 3 if amdcpu isk6 2 compatible return jbigi optimization k6 2 if amdcpu isk6 compatible return jbigi optimization k6 else if c instanceof intelcpu info intelcpu info intelcpu intelcpu info c if intelcpu is pentium4 compatible return jbigi optimization pentium4 if intelcpu is pentium3 compatible return jbigi optimization pentium3 if intelcpu is pentium2 compatible return jbigi optimization pentium2 if intelcpu is pentiummmx compatible return jbigi optimization pentiummmx if intelcpu is pentium compatible return jbigi optimization pentium return null catch unknowncpu exception e return null todo log something here maybe resolvecputype getproperty tolowercase 86_64 jbigi_optimization_x86_64 getproperty tolowercase jbigi_optimization_ppc cpuinfo getinfo amdcpuinfo amdcpuinfo amdcpuinfo isathlon64compatible jbigi_optimization_x86_64_32 isathloncompatible jbigi_optimization_athlon isk6_3_compatible jbigi_optimization_k6_3 isk6_2_compatible jbigi_optimization_k6_2 isk6compatible jbigi_optimization_k6 intelcpuinfo intelcpuinfo intelcpuinfo ispentium4compatible jbigi_optimization_pentium4 ispentium3compatible jbigi_optimization_pentium3 ispentium2compatible jbigi_optimization_pentium2 ispentiummmxcompatible jbigi_optimization_pentiummmx ispentiumcompatible jbigi_optimization_pentium unknowncpuexception calculate base exponent modulus param base big endian twos complement representation of the base but it must be positive param exponent big endian twos complement representation of the exponent param modulus big endian twos complement representation of the modulus return big endian twos complement representation of base exponent modulus converts a big integer byte array to a double param ba big endian twos complement representation of the big integer to convert to a double return the plain double value represented by ba biginteger biginteger public native big integer byte val super val takes up too much ram int target length bit length 8 1 if val length target length cached ba val nativebiginteger targetlength bitlength targetlength cachedba public native big integer int signum byte magnitude super signum magnitude nativebiginteger public native big integer int bitlen int certainty random rnd super bitlen certainty rnd nativebiginteger public native big integer int numbits random rnd super numbits rnd nativebiginteger public native big integer string val super val nativebiginteger public native big integer string val int radix super val radix nativebiginteger creates a new native big integer with the same value as the supplied big integer warning not very efficent public native big integer big integer integer now why doesn t sun provide a constructor like this one in big integer this integer to byte array nativebiginteger biginteger nativebiginteger biginteger biginteger tobytearray override public big integer mod pow big integer exponent big integer m if nativeok return new native big integer native mod pow to byte array exponent to byte array m to byte array else return new native big integer super mod pow exponent m biginteger modpow biginteger biginteger _nativeok nativebiginteger nativemodpow tobytearray tobytearray tobytearray nativebiginteger modpow override public byte to byte array if cached ba null since we are immutable it is safe to never update the cached ba after it has initially been generated cached ba super to byte array return cached ba tobytearray cachedba cachedba tobytearray cachedba override public string to string int radix if radix 16 return to hex string return super to string radix tostring tohexstring tostring public string to hex string byte buf to byte array return hex util bytes to hex buf tohexstring tobytearray hexutil bytestohex override public double double value if nativeok return native double value to byte array else return super double value doublevalue _nativeok nativedoublevalue tobytearray doublevalue return true iff native methods will be used by this class public static boolean is native return nativeok isnative _nativeok p do whatever we can to load up the native library backing this big integer s native methods if it can find a custom built jbigi dll libjbigi so it ll use that otherwise it ll try to look in the classpath for the correct library see load from resource if the user specifies djbigi enable false it ll skip all of this p private static final void load native try string wanted prop system get property jbigi enable true boolean want native true equals ignore case wanted prop if want native boolean loaded load from resource true if loaded nativeok true if dolog system err println info optimized native big integer library get resource name true loaded from resource else loaded load generic true if loaded nativeok true if dolog system err println info optimized native big integer library get middle name true loaded from somewhere in the path else loaded load from resource false if loaded nativeok true if dolog system err println info non optimized native big integer library get resource name false loaded from resource else loaded load generic false if loaded nativeok true if dolog system err println info non optimized native big integer library get middle name false loaded from somewhere in the path else nativeok false if dolog nativeok system err println info native big integer library jbigi not loaded using pure java catch throwable e if dolog system err println info native big integer library jbigi not loaded reason e get message using pure java biginteger loadfromresource loadnative wantedprop getproperty wantnative equalsignorecase wantedprop wantnative loadfromresource _nativeok _dolog biginteger getresourcename loadgeneric _nativeok _dolog biginteger getmiddlename loadfromresource _nativeok _dolog biginteger getresourcename loadgeneric _nativeok _dolog biginteger getmiddlename _nativeok _dolog _nativeok biginteger _dolog biginteger getmessage p try loading it from an explictly build jbigi dll libjbigi so first before looking into a jbigi jar for any other libraries p return true if it was loaded successfully else false private static final boolean load generic boolean optimized try string name get middle name optimized if name null return false system load library name return true catch unsatisfied link error ule return false loadgeneric getmiddlename loadlibrary unsatisfiedlinkerror a helper function to make loading the native library easier param f the file to which to write the library param url the url of the resource return true is the library was loaded false on error throws file not found exception if the library could not be read from the reference throws unsatisfied link error if and only if the library is incompatible with this system private static final boolean try load resource file f url resource throws file not found exception unsatisfied link error input stream is try is resource open stream catch io exception e f delete throw new file not found exception file output stream fos null try f delete on exit fos new file output stream f byte buf new byte 4096 1024 int read while read is read buf 0 fos write buf 0 read fos close fos null system load f get absolute path return true catch io exception e catch unsatisfied link error ule likely to be noexec if ule to string to lower case index of not permitted 1 throw ule finally closer close fos f delete return false filenotfoundexception unsatisfiedlinkerror tryloadresource filenotfoundexception unsatisfiedlinkerror inputstream openstream ioexception filenotfoundexception fileoutputstream deleteonexit fileoutputstream getabsolutepath ioexception unsatisfiedlinkerror tostring tolowercase indexof p check all of the jars in the classpath for the file specified by the environmental property jbigi impl and load it as the native library implementation for instance a windows user on a p4 would define djbigi impl win 686 if there is a jbigi jar in the classpath containing the files win 686 win athlon freebsd p4 linux p3 where each of those files contain the correct binary file for a native library e g windows dll or a nix so p p this is a pretty ugly hack using the general technique illustrated by the onion fec libraries it works by pulling the resource writing out the byte stream to a temporary file loading the native library from that file then deleting the file p return true if it was loaded successfully else false private static final boolean load from resource boolean optimized string resource name get resource name optimized if resource name null return false url resource native big integer class get class loader get resource resource name if resource null if dolog system err println notice resource name get resource name true was not found return false file temp null try try temp file create temp file jbigi lib tmp if try load resource temp resource return true catch io exception e finally if temp null temp delete logger error native big integer class can t load from system get property java io tmpdir system err println can t load from system get property java io tmpdir temp new file jbigi lib tmp if try load resource temp resource return true catch exception fnf logger error native big integer class error reading jbigi resource fnf system err println error reading jbigi resource catch unsatisfied link error ule logger error native big integer class library resource name is not appropriate for this system system err println library resource name is not appropriate for this system finally if temp null temp delete return false loadfromresource resourcename getresourcename resourcename nativebiginteger getclassloader getresource resourcename _dolog getresourcename createtempfile tryloadresource ioexception nativebiginteger getproperty getproperty tryloadresource nativebiginteger unsatisfiedlinkerror nativebiginteger resourcename resourcename private static final string get resource name boolean optimized string pname native big integer class get package get name replace string pref get library prefix string middle get middle name optimized string suff get library suffix if pref null middle null suff null return null return pname pref middle suff getresourcename nativebiginteger getpackage getname getlibraryprefix getmiddlename getlibrarysuffix private static final string get middle name boolean optimized string s append if optimized if scpu type null return null else s append scpu type else s append none boolean is windows system get property os name to lower case index of windows 1 boolean is linux system get property os name to lower case index of linux 1 boolean is freebsd system get property os name to lower case index of freebsd 1 boolean is macos system get property os name to lower case index of mac os x 1 if is windows return jbigi windows s append the convention on windows if is linux return jbigi linux s append the convention on linux if is freebsd return jbigi freebsd s append the convention on freebsd if is macos return jbigi osx s append the convention on mac os x throw new runtime exception dont know jbigi library name for os type system get property os name getmiddlename sappend scputype sappend scputype sappend iswindows getproperty tolowercase indexof islinux getproperty tolowercase indexof isfreebsd getproperty tolowercase indexof ismacos getproperty tolowercase indexof iswindows sappend islinux sappend isfreebsd sappend ismacos sappend runtimeexception getproperty private static final string get library suffix boolean is windows system get property os name to lower case index of windows 1 boolean is macos system get property os name to lower case index of mac os x 1 if is windows return dll else if is macos return jnilib else return so getlibrarysuffix iswindows getproperty tolowercase indexof ismacos getproperty tolowercase indexof iswindows ismacos private static final string get library prefix boolean is windows system get property os name to lower case index of windows 1 if is windows return else return lib getlibraryprefix iswindows getproperty tolowercase indexof iswindows public lru object cache int size int initial capacity size 0 default init size size threshold int initial capacity load factor table new entry initial capacity pin list new entry 0 null null pin limit size pin list lru pin list mru pin list lruobjectcache initialcapacity defaultinitsize initialcapacity loadfactor initialcapacity pinlist pinlimit pinlist pinlist pinlist public synchronized boolean remove int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index prev null e null prev e e e next if e oid oid if prev null prev next e next else tab index e next e clear unpin object e count 1 return true return false unpinobject protected reference create reference object obj return new weak reference obj createreference weakreference private final void unpin object entry e if e pin null e unpin n pinned 1 unpinobject npinned private final void pin object entry e i persistent obj if pin limit 0 if e pin null e unlink else if n pinned pin limit pin list lru unpin else n pinned 1 e link after pin list obj pinobject ipersistent pinlimit npinned pinlimit pinlist npinned linkafter pinlist public synchronized void put int oid i persistent obj reference ref create reference obj entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e ref ref pin object e obj return if count threshold flushing rehash the table if the threshold is exceeded rehash tab table index oid 0x7fffffff tab length creates the new entry tab index new entry oid ref tab index pin object tab index obj count ipersistent createreference pinobject pinobject public i persistent get int oid while true cs synchronized this entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid i persistent obj i persistent e ref get if obj null if e dirty 0 break cs else if obj is deleted e ref clear unpin object e return null pin object e obj return obj return null runtime run finalization ipersistent ipersistent ipersistent isdeleted unpinobject pinobject runfinalization public void flush while true cs synchronized this flushing true for int i 0 i table length i entry e next prev for e table i prev null e null e next i persistent obj i persistent e ref get next e next if obj null if obj is modified obj store prev e else if e dirty 0 break cs else count 1 e clear if prev null table i next else prev next next flushing false if count threshold rehash the table if the threshold is exceeded rehash return runtime run finalization ipersistent ipersistent ismodified runfinalization public void invalidate while true cs synchronized this for int i 0 i table length i for entry e table i e null e e next i persistent obj i persistent e ref get if obj null if obj is modified e dirty 0 unpin object e obj invalidate else if e dirty 0 break cs table i null count 0 n pinned 0 pin list lru pin list mru pin list return runtime run finalization ipersistent ipersistent ismodified unpinobject npinned pinlist pinlist pinlist runfinalization public synchronized void clear entry tab table for int i 0 i tab length i tab i null count 0 n pinned 0 pin list lru pin list mru pin list npinned pinlist pinlist pinlist void rehash int old capacity table length entry old map table int i for i old capacity i 0 entry e next prev for prev null e old map i e null e next next e next i persistent obj i persistent e ref get if obj null obj is deleted e dirty 0 count 1 e clear if prev null old map i next else prev next next else prev e if count threshold 1 return int new capacity old capacity 2 1 entry new map new entry new capacity threshold int new capacity load factor table new map for i old capacity i 0 for entry old old map i old null entry e old old old next int index e oid 0x7fffffff new capacity e next new map index new map index e oldcapacity oldmap oldcapacity oldmap ipersistent ipersistent isdeleted oldmap newcapacity oldcapacity newmap newcapacity newcapacity loadfactor newmap oldcapacity oldmap newcapacity newmap newmap public synchronized void set dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e dirty 1 return setdirty ipersistent getoid public synchronized void clear dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid if e dirty 0 e dirty 1 return cleardirty ipersistent getoid public int size return count i persistent pin void unlink lru mru mru mru lru lru ipersistent void unpin unlink lru mru null pin null void link after entry head i persistent obj mru head mru mru lru this head mru this lru head pin obj linkafter ipersistent void clear ref clear ref null dirty 0 next null entry int oid reference ref entry chain next chain this oid oid this ref ref protected void set up throws exception super set up m identity manager new wot identity manager db m message manager new wot message manager db m identity manager construct identities setup setup midentitymanager wotidentitymanager mmessagemanager wotmessagemanager midentitymanager constructidentities private void construct identities throws malformedurl exception string requestss ks new string ssk ly n0 nk5n qpt6br ggtckfhpy11 gzgk dn4v dszl6fw pg gd ql sg9ncbbf8xis cx yb lm9 jxe3 oi sydy oa zgcs4k aqacaae wot ssk wc oy byjh hpye gea4f0q tm8 wxim leu tehh0 ovo iysli m2xhpkg lhq1yqpqd yp0 yvbs qdnju4pd0 nm wga1cwre aqacaae wot ssk oh iaam npk igdbkwpc ob9phc qoa015n aoia0ud 9a4tm 5 jp16w6 ys ai qwe fljj g jck0a yxzu nfs6 bjkx psk aqacaae wot ssk vm fi2tyuli54 kgl nmm hz4k xh kl nhldvgoc fdll5vru 00v jvrvf8p5xrd3kuiawxhn7rp dxb5kjp9z8x uqe a aqacaae wot ssk hh v2 xm cb zp 738qte67j ug1m5l5fl vv qfc2b ype1o4 c8h39jkp08cao ejvtv ris hlc mnl tlpnfi czl4gmz4 aqacaae wot string insertss ks new string ssk egaz bi trp gsilvbjgt91mox5jtc6pfidf dyjt3 fcsri gd ql sg9ncbbf8xis cx yb lm9 jxe3 oi sydy oa zgcs4k aqecaae wot ssk ze0 i5n rq60j549pck sb2zsyf98kn kcz psa ggt1lue m2xhpkg lhq1yqpqd yp0 yvbs qdnju4pd0 nm wga1cwre aqecaae wot ssk rgnz2 lrmns3 djx5 dfp uf dpaq wn mmalbvh9x8ub9 cg rc 5 jp16w6 ys ai qwe fljj g jck0a yxzu nfs6 bjkx psk aqecaae wot ssk xj het73nz3vikr hc km8 gtwce muzo6aem iw16 pft6ha 00v jvrvf8p5xrd3kuiawxhn7rp dxb5kjp9z8x uqe a aqecaae wot ssk req uma bjh dr rd8z8kog mw9d vd5q3 rhhe asyjqr luxgy c8h39jkp08cao ejvtv ris hlc mnl tlpnfi czl4gmz4 aqecaae wot m own identities new wot own identity requestss ks length for int i 0 i requestss ks length i freeneturi requesturi new freeneturi requestss ks i freeneturi inserturi new freeneturi insertss ks i m own identities i new wot own identity wot own identity getuid fromuri requesturi requesturi inserturi nickname i m own identities i initialize transient db m identity manager m own identities i store constructidentities malformedurlexception requestssks n0nk5nqpt6brggtckfhpy11gzgkdn4vdszl6fwpg gdqlsg9ncbbf8xis cxyb lm9jxe3oisydyoazgcs4k wcoybyjhhpye gea4f0qtm8wximleutehh0ovoiysli m2xhpkglhq1yqpqdyp0yvbs qdnju4pd0nmwga1cwre ohiaamnpkigdbkwpcob9phcqoa015naoia0ud 5jp16w6 aiqwefljj gjck0ayxzu nfs6bjkxpsk vmfi2tyuli54kglnmmhz4k xhklnhldvgocfdll5vru jvrvf8p5xrd3kuiawxhn7rpdxb5kjp9z8xuqe v2xmcbzp 738qte67jug1m5l5flvvqfc2bype1o4 rishlcmnltlpnficzl4gmz4 insertssks egazbitrpgsilvbjgt91mox5jtc6pfidfdyjt3fcsri gdqlsg9ncbbf8xis cxyb lm9jxe3oisydyoazgcs4k i5nrq60j549pck sb2zsyf98knkczpsaggt1lue m2xhpkglhq1yqpqdyp0yvbs qdnju4pd0nmwga1cwre rgnz2lrmns3djx5dfpufdpaqwnmmalbvh9x8ub9cgrc 5jp16w6 aiqwefljj gjck0ayxzu nfs6bjkxpsk xjhet73nz3vikrhc km8gtwcemuzo6aemiw16pft6ha jvrvf8p5xrd3kuiawxhn7rpdxb5kjp9z8xuqe requmabjhdrrd8z8kogmw9dvd5q3rhheasyjqrluxgy rishlcmnltlpnficzl4gmz4 mownidentities wotownidentity requestssks requestssks requestssks insertssks mownidentities wotownidentity wotownidentity getuidfromuri mownidentities initializetransient midentitymanager mownidentities constructor when we are returning the data f proxy fetch result f proxy fetch in progress parent bucket data string mime type long time started boolean gone to network long eta boolean has waited this data data this mime type mime type this size data size this time started time started this gone to network gone to network total blocks required blocks fetched blocks failed blocks fatally failed blocks 0 finalized blocks true failed null this progress parent this eta eta this has waited has waited fproxyfetchresult fproxyfetchinprogress mimetype timestarted gonetonetwork haswaited mimetype mimetype timestarted timestarted gonetonetwork gonetonetwork totalblocks requiredblocks fetchedblocks failedblocks fatallyfailedblocks finalizedblocks haswaited haswaited constructor when we are not returning the data because it is still running or it failed f proxy fetch result f proxy fetch in progress parent string mime type long size long time started boolean gone to network int total blocks int required blocks int fetched blocks int failed blocks int fatally failed blocks boolean finalized blocks fetch exception failed long eta boolean has waited this data null this mime type mime type this size size this time started time started this gone to network gone to network this total blocks total blocks this required blocks required blocks this fetched blocks fetched blocks this failed blocks failed blocks this fatally failed blocks fatally failed blocks this finalized blocks finalized blocks this failed failed this progress parent this eta eta this has waited has waited fproxyfetchresult fproxyfetchinprogress mimetype timestarted gonetonetwork totalblocks requiredblocks fetchedblocks failedblocks fatallyfailedblocks finalizedblocks fetchexception haswaited mimetype mimetype timestarted timestarted gonetonetwork gonetonetwork totalblocks totalblocks requiredblocks requiredblocks fetchedblocks fetchedblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks finalizedblocks finalizedblocks haswaited haswaited must be called when fproxy has finished with the data public void close progress close this public boolean has data return data null hasdata public boolean has waited return has waited haswaited haswaited public ssdp search response set status code http status ok set cache control device default lease time set header http server u pnp get server name set header http ext ssdpsearchresponse setstatuscode httpstatus setcachecontrol default_lease_time setheader upnp getservername setheader public void on load cls class descriptor load class get storage class name locate fields onload classdescriptor loadclass getstorage classname locatefields private final void locate fields if field names null fields cls get declared fields else fields new field field names length for int i 0 i fields length i fields i class descriptor locate field cls field names i if fields i null throw new storage error storage error indexed field not found class name field names i locatefields fieldnames getdeclaredfields fieldnames classdescriptor locatefield fieldnames storageerror storageerror indexed_field_not_found classname fieldnames public reflection multidimensional comparator storage storage class cls string field names boolean treate zero as undefined value super storage this cls cls this field names field names this treate zero as undefined value treate zero as undefined value class name class descriptor get class name cls locate fields reflectionmultidimensionalcomparator fieldnames treatezeroasundefinedvalue fieldnames fieldnames treatezeroasundefinedvalue treatezeroasundefinedvalue classname classdescriptor getclassname locatefields reflection multidimensional comparator reflectionmultidimensionalcomparator private static boolean is zero object val return val instanceof double val instanceof float number val double value 0 0 val instanceof number number val long value 0 false iszero doublevalue longvalue public int compare t m1 t m2 int i try comparable c1 comparable fields i get m1 comparable c2 comparable fields i get m2 if c1 null c2 null return eq else if c1 null treate zero as undefined value is zero c1 return left undefined else if c2 null treate zero as undefined value is zero c2 return right undefined else int diff c1 compare to c2 return diff 0 lt diff 0 eq gt catch illegal access exception x throw new illegal access error treatezeroasundefinedvalue iszero left_undefined treatezeroasundefinedvalue iszero right_undefined compareto illegalaccessexception illegalaccesserror public int get number of dimensions return fields length getnumberofdimensions public t clone field t obj int i if desc null desc storage impl get storage find class descriptor cls t clone t desc new instance try fields i set clone fields i get obj return clone catch illegal access exception x throw new illegal access error clonefield storageimpl getstorage findclassdescriptor newinstance illegalaccessexception illegalaccesserror set the action to perform for pixels off the edge of the image param edge action one of zero clamp or wrap see get edge action public void set edge action int edge action this edge action edge action edgeaction getedgeaction setedgeaction edgeaction edgeaction edgeaction get the action to perform for pixels off the edge of the image return one of zero clamp or wrap see set edge action public int get edge action return edge action setedgeaction getedgeaction edgeaction set the type of interpolation to perform param interpolation one of nearest neighbour or bilinear see get interpolation public void set interpolation int interpolation this interpolation interpolation nearest_neighbour getinterpolation setinterpolation get the type of interpolation to perform return one of nearest neighbour or bilinear see set interpolation public int get interpolation return interpolation nearest_neighbour setinterpolation getinterpolation inverse transform a point this method needs to be overriden by all subclasses param x the x position of the pixel in the output image param y the y position of the pixel in the output image param out the position of the pixel in the input image forward transform a rectangle used to determine the size of the output image param rect the rectangle to transform protected void transform space rectangle rect transformspace public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster original space new rectangle 0 0 width height transformed space new rectangle 0 0 width height transform space transformed space if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster transformed space width transformed space height dstcm is alpha premultiplied null writable raster dst raster dst get raster int in pixels getrgb src 0 0 width height null if interpolation nearest neighbour return filter pixelsnn dst width height in pixels transformed space int src width width int src height height int src width1 width 1 int src height1 height 1 int out width transformed space width int out height transformed space height int outx outy int index 0 int out pixels new int out width outx transformed space x outy transformed space y float out new float 2 for int y 0 y out height y for int x 0 x out width x transform inverse outx x outy y out int srcx int math floor out 0 int srcy int math floor out 1 float x weight out 0 srcx float y weight out 1 srcy int nw ne sw se if srcx 0 srcx src width1 srcy 0 srcy src height1 easy case all corners are in the image int i src width srcy srcx nw in pixels i ne in pixels i 1 sw in pixels i src width se in pixels i src width 1 else some of the corners are off the image nw get pixel in pixels srcx srcy src width src height ne get pixel in pixels srcx 1 srcy src width src height sw get pixel in pixels srcx srcy 1 src width src height se get pixel in pixels srcx 1 srcy 1 src width src height out pixels x image math bilinear interpolate x weight y weight nw ne sw se setrgb dst 0 y transformed space width 1 out pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster originalspace transformedspace transformspace transformedspace colormodel getcolormodel bufferedimage createcompatiblewritableraster transformedspace transformedspace isalphapremultiplied writableraster dstraster getraster inpixels nearest_neighbour filterpixelsnn inpixels transformedspace srcwidth srcheight srcwidth1 srcheight1 outwidth transformedspace outheight transformedspace outpixels outwidth transformedspace transformedspace outheight outwidth transforminverse xweight yweight srcwidth1 srcheight1 srcwidth inpixels inpixels inpixels srcwidth inpixels srcwidth getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight getpixel inpixels srcwidth srcheight outpixels imagemath bilinearinterpolate xweight yweight transformedspace outpixels final private int get pixel int pixels int x int y int width int height if x 0 x width y 0 y height switch edge action case zero default return 0 case wrap return pixels image math mod y height width image math mod x width case clamp return pixels image math clamp y 0 height 1 width image math clamp x 0 width 1 return pixels y width x getpixel edgeaction imagemath imagemath imagemath imagemath protected buffered image filter pixelsnn buffered image dst int width int height int in pixels rectangle transformed space int src width width int src height height int out width transformed space width int out height transformed space height int outx outy srcx srcy int out pixels new int out width outx transformed space x outy transformed space y int rgb new int 4 float out new float 2 for int y 0 y out height y for int x 0 x out width x transform inverse outx x outy y out srcx int out 0 srcy int out 1 int casting rounds towards zero so we check out 0 0 not srcx 0 if out 0 0 srcx src width out 1 0 srcy src height int p switch edge action case zero default p 0 break case wrap p in pixels image math mod srcy src height src width image math mod srcx src width break case clamp p in pixels image math clamp srcy 0 src height 1 src width image math clamp srcx 0 src width 1 break out pixels x p else int i src width srcy srcx rgb 0 in pixels i out pixels x in pixels i setrgb dst 0 y transformed space width 1 out pixels return dst bufferedimage filterpixelsnn bufferedimage inpixels transformedspace srcwidth srcheight outwidth transformedspace outheight transformedspace outpixels outwidth transformedspace transformedspace outheight outwidth transforminverse srcwidth srcheight edgeaction inpixels imagemath srcheight srcwidth imagemath srcwidth inpixels imagemath srcheight srcwidth imagemath srcwidth outpixels srcwidth inpixels outpixels inpixels transformedspace outpixels bucket data public minimal splitfile block int n this number n minimalsplitfileblock public int get number return number getnumber public boolean has data return data null hasdata public bucket get data return data getdata public void set data bucket data this data data setdata public void store to object container container if logger should log logger minor this logger minor this storing this with data data if data null data store to container container store this storeto objectcontainer shouldlog storeto public void remove from object container container if data null container activate data 1 data remove from container container delete this removefrom objectcontainer removefrom public persistent chosen block boolean is insert persistent chosen request parent sendable request item token key key client key ckey request scheduler sched super token key ckey parent local request only parent cache local requests parent ignore store sched this is insert is insert this parent parent if logger should log logger minor this logger minor this created this for parent ckey ckey persistentchosenblock isinsert persistentchosenrequest sendablerequestitem clientkey requestscheduler localrequestonly cachelocalrequests ignorestore isinsert isinsert shouldlog override public void on fetch success client context context assert is insert synchronized this if finished logger error this already finished in on success on this new exception debug return finished true fetch succeeded true parent on finished this context parent scheduler succeeded sendable get parent request true onfetchsuccess clientcontext isinsert onsuccess fetchsucceeded onfinished sendableget override public void on failure low level get exception e client context context assert is insert synchronized this if finished logger error this already finished in on failure on this new exception debug return if e null throw new null pointer exception failed get e finished true parent on finished this context onfailure lowlevelgetexception clientcontext isinsert onfailure nullpointerexception failedget onfinished override public void on insert success client context context assert is insert synchronized this if finished logger error this already finished in on success on this new exception debug return insert succeeded true finished true parent on finished this context oninsertsuccess clientcontext isinsert onsuccess insertsucceeded onfinished override public void on failure low level put exception e client context context assert is insert synchronized this if finished logger error this already finished in on failure on this new exception debug return if e null throw new null pointer exception failed put e finished true parent on finished this context onfailure lowlevelputexception clientcontext isinsert onfailure nullpointerexception failedput onfinished low level get exception failed get return failed get lowlevelgetexception failedget failedget boolean insert succeeded return insert succeeded insertsucceeded insertsucceeded boolean fetch succeeded return fetch succeeded fetchsucceeded fetchsucceeded low level put exception failed put return failed put lowlevelputexception failedput failedput override public boolean is persistent return true ispersistent override public boolean is cancelled we can t tell without accesing the database and we can t access the database on the request starter thread return false iscancelled override public boolean send node client core core request scheduler sched try return super send core sched finally boolean was finished synchronized this was finished finished if finished finished true if parent request instanceof sendable get logger error this sendable get parent request didn t call a callback on this if was finished parent on finished this sched get context nodeclientcore requestscheduler wasfinished wasfinished sendableget sendableget wasfinished onfinished getcontext override public short get priority return parent prio getpriority override public sendable request sender get sender client context context return parent sender sendablerequestsender getsender clientcontext logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog archive handler impl freeneturi key archive type archive type compressor type ctype boolean force refetch archive this key key this archive type archive type this compressor type ctype this force refetch archive force refetch archive archivehandlerimpl archive_type archivetype compressor_type forcerefetcharchive archivetype archivetype compressortype forcerefetcharchive forcerefetcharchive public bucket get string internal name archive context archive context archive manager manager throws archive failure exception archive restart exception metadata parse exception fetch exception do loop detection on the archive that we are about to fetch archive context do loop detection key if force refetch archive return null bucket data fetch from cache if logminor logger minor this checking cache key internal name if data manager get cached key internal name null return data return null internalname archivecontext archivecontext archivemanager archivefailureexception archiverestartexception metadataparseexception fetchexception archivecontext doloopdetection forcerefetcharchive internalname getcached internalname public bucket get metadata archive context archive context archive manager manager throws archive failure exception archive restart exception metadata parse exception fetch exception return get metadata archive context manager getmetadata archivecontext archivecontext archivemanager archivefailureexception archiverestartexception metadataparseexception fetchexception archivecontext public void extract to cache bucket bucket archive context actx string element archive extract callback callback archive manager manager object container container client context context throws archive failure exception archive restart exception force refetch archive false now we don t need to force refetch any more archive store context ctx manager make context key archive type compressor type false manager extract to cache key archive type compressor type bucket actx ctx element callback container context extracttocache archivecontext archiveextractcallback archivemanager objectcontainer clientcontext archivefailureexception archiverestartexception forcerefetcharchive archivestorecontext makecontext archivetype compressortype extracttocache archivetype compressortype public archive type get archive type return archive type archive_type getarchivetype archivetype public compressor type get compressor type return compressor type compressor_type getcompressortype compressortype public freeneturi get key return key getkey unpack a fetched archive on a separate thread for a persistent caller this involves add a tag to the database so that it will be restarted on a crash run the actual unpack on a separate thread copy the data to a persistent bucket schedule a database job call the callback param bucket param actx param element param callback param container param context public void extract persistent off thread bucket bucket boolean free bucket archive context actx string element archive extract callback callback object container container final client context context assert element null no callback would be called final archive manager manager context archive manager final archive extract tag tag new archive extract tag this bucket free bucket actx element callback context nodedb handle container store tag run persistent off thread tag context manager context persistent bucket factory extractpersistentoffthread freebucket archivecontext archiveextractcallback objectcontainer clientcontext archivemanager archivemanager archiveextracttag archiveextracttag freebucket nodedbhandle runpersistentoffthread persistentbucketfactory private static void run persistent off thread final archive extract tag tag final client context context final archive manager manager final bucket factory bf final proxy callback proxy callback new proxy callback if logminor logger minor archive handler impl class scheduling off thread extraction tag data for tag handler key element tag element for tag callback new exception debug context main executor execute new runnable public void run try if logminor logger minor this extracting off thread tag data for tag handler key element tag element for tag callback tag handler extract to cache tag data tag actx tag element proxy callback manager null context if logminor logger minor this extracted final bucket data if proxy callback data null data null else try if logminor logger minor this copying data data bf make bucket proxy callback data size bucket tools copy proxy callback data data proxy callback data free if logminor logger minor this copied and freed original catch io exception e throw new archive failure exception failure copying data to persistent storage e context job runner queue new db job public void run object container container client context context if logminor logger minor this calling callback for tag data for tag handler key element tag element for tag callback container activate tag callback 1 if proxy callback data null tag callback not in archive container context else tag callback got bucket data container context tag callback remove from container if tag free bucket tag data free tag data remove from container container deactivate tag callback 1 container delete tag native thread norm priority false catch final archive failure exception e context job runner queue new db job public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag native thread norm priority false catch final archive restart exception e context job runner queue new db job public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag native thread norm priority false off thread extract runpersistentoffthread archiveextracttag clientcontext archivemanager bucketfactory proxycallback proxycallback proxycallback archivehandlerimpl mainexecutor extracttocache proxycallback proxycallback makebucket proxycallback buckettools proxycallback proxycallback ioexception archivefailureexception jobrunner dbjob objectcontainer clientcontext proxycallback notinarchive gotbucket removefrom freebucket removefrom nativethread norm_priority archivefailureexception jobrunner dbjob objectcontainer clientcontext onfailed removefrom freebucket removefrom nativethread norm_priority archiverestartexception jobrunner dbjob objectcontainer clientcontext onfailed removefrom freebucket removefrom nativethread norm_priority public void run try if logminor logger minor this extracting off thread tag data for tag handler key element tag element for tag callback tag handler extract to cache tag data tag actx tag element proxy callback manager null context if logminor logger minor this extracted final bucket data if proxy callback data null data null else try if logminor logger minor this copying data data bf make bucket proxy callback data size bucket tools copy proxy callback data data proxy callback data free if logminor logger minor this copied and freed original catch io exception e throw new archive failure exception failure copying data to persistent storage e context job runner queue new db job public void run object container container client context context if logminor logger minor this calling callback for tag data for tag handler key element tag element for tag callback container activate tag callback 1 if proxy callback data null tag callback not in archive container context else tag callback got bucket data container context tag callback remove from container if tag free bucket tag data free tag data remove from container container deactivate tag callback 1 container delete tag native thread norm priority false catch final archive failure exception e context job runner queue new db job public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag native thread norm priority false catch final archive restart exception e context job runner queue new db job public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag native thread norm priority false extracttocache proxycallback proxycallback makebucket proxycallback buckettools proxycallback proxycallback ioexception archivefailureexception jobrunner dbjob objectcontainer clientcontext proxycallback notinarchive gotbucket removefrom freebucket removefrom nativethread norm_priority archivefailureexception jobrunner dbjob objectcontainer clientcontext onfailed removefrom freebucket removefrom nativethread norm_priority archiverestartexception jobrunner dbjob objectcontainer clientcontext onfailed removefrom freebucket removefrom nativethread norm_priority public void run object container container client context context if logminor logger minor this calling callback for tag data for tag handler key element tag element for tag callback container activate tag callback 1 if proxy callback data null tag callback not in archive container context else tag callback got bucket data container context tag callback remove from container if tag free bucket tag data free tag data remove from container container deactivate tag callback 1 container delete tag objectcontainer clientcontext proxycallback notinarchive gotbucket removefrom freebucket removefrom public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag objectcontainer clientcontext onfailed removefrom freebucket removefrom public void run object container container client context context container activate tag callback 1 tag callback on failed e container context tag callback remove from container if tag free bucket tag data free tag data remove from container container delete tag objectcontainer clientcontext onfailed removefrom freebucket removefrom called from archive manager init static void init object container container client context context final long nodedb handle object set archive extract tag set container query new predicate archive extract tag override public boolean match archive extract tag tag return tag nodedb handle nodedb handle while set has next archive extract tag tag set next tag activate for execution container run persistent off thread tag context context archive manager context persistent bucket factory archivemanager objectcontainer clientcontext nodedbhandle objectset archiveextracttag archiveextracttag archiveextracttag nodedbhandle nodedbhandle hasnext archiveextracttag activateforexecution runpersistentoffthread archivemanager persistentbucketfactory static void init object container container client context context final long nodedb handle object set archive extract tag set container query new predicate archive extract tag override public boolean match archive extract tag tag return tag nodedb handle nodedb handle objectcontainer clientcontext nodedbhandle objectset archiveextracttag archiveextracttag archiveextracttag nodedbhandle nodedbhandle bucket data public void got bucket bucket data object container container client context context this data data gotbucket objectcontainer clientcontext public void not in archive object container container client context context this data null notinarchive objectcontainer clientcontext public void on failed archive restart exception e object container container client context context must not be called throw new unsupported operation exception onfailed archiverestartexception objectcontainer clientcontext unsupportedoperationexception public void on failed archive failure exception e object container container client context context must not be called throw new unsupported operation exception onfailed archivefailureexception objectcontainer clientcontext unsupportedoperationexception public void remove from object container container container delete this removefrom objectcontainer public void activate for execution object container container container activate this 1 container activate key 5 activateforexecution objectcontainer public archive handler clone handler return new archive handler impl key clone archive type compressor type force refetch archive archivehandler clonehandler archivehandlerimpl archivetype compressortype forcerefetcharchive public void remove from object container container if key null logger error this remove from key null for this i exist container ext is stored this i am active container ext is active this new exception error else key remove from container container delete this removefrom objectcontainer removefrom isstored isactive removefrom archive extract tag archive handler impl handler bucket data boolean free bucket archive context actx string element archive extract callback callback long nodedb handle this handler handler this data data this free bucket free bucket this actx actx this element element this callback callback this nodedb handle nodedb handle archiveextracttag archivehandlerimpl freebucket archivecontext archiveextractcallback nodedbhandle freebucket freebucket nodedbhandle nodedbhandle public void activate for execution object container container container activate this 1 container activate data 5 handler activate for execution container container activate actx 5 container activate callback 1 activateforexecution objectcontainer activateforexecution public static void main string args throws fs parse exception peer parse exception invalid threshold exception node init exception reference signature verification exception logger setup stdout logging logger normal freenet node cpu adjusting swap request interval minor freenet node location manager debug freenet node fnp packet manager normal freenet io comm message core debug system out println secret ping network coloring test using real nodes system out println string wd real node network color test new file wd mkdir note global test init returns in ignored random source node starter global test init wd false logger error freenet node location normal freenet node simulator real node network coloring test normal freenet node networkid manager normal true dummy random source random new dummy random source diffie hellman init random node subneta new node number of nodes node subnetb new node number of nodes node bridges new node bridges int total nodes number of nodes 2 bridges node all nodes new node total nodes cheat and use total nodes as a counter for a moment total nodes 0 logger normal real node routing test class creating nodes executor executor new pooled executor allow secret pings and send them automatically must be done before creating the nodes freenet node networkid manager disable secret pings false freenet node networkid manager disable secret pinger false freenet node networkid manager disable swap segregation false for int i 0 i number of nodes i all nodes total nodes subneta i node starter create test node 5001 total nodes 0 wd false true true max htl 0 no dropped packets random executor 500 number of nodes store size true true false false false false true 0 enable foaf false null total nodes logger normal real node routing test class created a node total nodes for int i 0 i number of nodes i all nodes total nodes subnetb i node starter create test node 5001 total nodes 0 wd false true true max htl 0 no dropped packets random executor 500 number of nodes store size true true false false false false true 0 enable foaf false null total nodes logger normal real node routing test class created b node total nodes for int i 0 i bridges i all nodes total nodes bridges i node starter create test node 5001 total nodes 0 wd false true true max htl 0 no dropped packets random executor 500 number of nodes store size true true false false false false true 0 enable foaf false null total nodes logger normal real node routing test class created bridge node total nodes logger normal real node routing test class created total nodes nodes now link them up make kleinberg network subneta true make it easy we re not testing swapping here degree false make kleinberg network subnetb true make it easy we re not testing swapping here degree false int a target count leafs subneta 1 int b target count leafs subnetb 1 int general target a target b target bridges logger normal real node routing test class added small world links weakly connect the subnets if bridges 0 for int i 0 i bridge links i connect a random node from a to a random node from b node a subneta random next int number of nodes node b subnetb random next int number of nodes connect a b else for int b 0 b bridges b node bridge bridges b make bridge links into a for int i 0 i bridge links i node nodea subneta random next int number of nodes connect bridge nodea make bridge links into b for int i 0 i bridge links i node nodeb subnetb random next int number of nodes connect bridge nodeb for int i 0 i total nodes i all nodes i start false now sit back and watch the fireworks int cycle number 0 running average general new bootstrapping decaying running average 0 0 0 0 1 0 2000 null running average a rate new bootstrapping decaying running average 0 0 0 0 1 0 500 null running average b rate new bootstrapping decaying running average 0 0 0 0 1 0 500 null running average bridge rate new bootstrapping decaying running average 0 0 0 0 1 0 500 null hash set integer general ids new hash set integer hash set integer a ids new hash set integer hash set integer b ids new hash set integer hash set integer bridge ids new hash set integer while true cycle number try thread sleep 5000 catch interrupted exception e ignore running average a loc new trivial running average running average b loc new trivial running average long total successes 0 long total total pings 0 general ids clear a ids clear b ids clear bridge ids clear for int i 0 i number of nodes i long good subneta i netid secret ping successes long total subneta i netid total secret ping attempts int id subneta i netid our network id a loc report subneta i get location total successes good total total pings total eh not really but i guess it s close reset this nodes good total double rate 0 0 if total 0 rate 1 0 good total general report rate a rate report rate general ids add integer value of id a ids add integer value of id for int i 0 i number of nodes i long good subnetb i netid secret ping successes long total subnetb i netid total secret ping attempts int id subnetb i netid our network id b loc report subnetb i get location total successes good total total pings total eh not really but i guess it s close reset this nodes good total double rate 0 0 if total 0 rate 1 0 good total general report rate b rate report rate general ids add integer value of id b ids add integer value of id for int i 0 i bridges i long good bridges i netid secret ping successes long total bridges i netid total secret ping attempts int id bridges i netid our network id total successes good total total pings total eh not really but i guess it s close reset this nodes good total double rate 0 0 if total 0 rate 1 0 good total general report rate bridge rate report rate general ids add integer value of id bridge ids add integer value of id logger error log cycle cycle number logger error log total secret pings total total pings logger error log total successful total successes logger error log p success all general current value logger error log p success a a rate current value logger error log p success b b rate current value if bridges 0 logger error log p success brg bridge rate current value id report all general ids general target id report a a ids a target id report b b ids b target if bridges 0 id report brg bridge ids bridges this is really rough but can generally give an indication of keyspace skew statistically they should remain 0 5 but if one keyspace starts to get absorbed into the other the balance will shift does not work if the aborbtion point is 0 5 logger error log a loc a loc current value logger error log b loc b loc current value fsparseexception peerparseexception invalidthresholdexception nodeinitexception referencesignatureverificationexception setupstdoutlogging cpuadjustingswaprequestinterval locationmanager fnppacketmanager messagecore secretping networkcoloring realnodenetworkcolortest globaltestinit nodestarter globaltestinit realnodenetworkcoloringtest networkidmanager dummyrandomsource dummyrandomsource diffiehellman number_of_nodes number_of_nodes totalnodes number_of_nodes allnodes totalnodes totalnodes totalnodes realnoderoutingtest pooledexecutor networkidmanager disablesecretpings networkidmanager disablesecretpinger networkidmanager disableswapsegregation number_of_nodes allnodes totalnodes nodestarter createtestnode totalnodes max_htl number_of_nodes storesize enable_foaf totalnodes realnoderoutingtest totalnodes number_of_nodes allnodes totalnodes nodestarter createtestnode totalnodes max_htl number_of_nodes storesize enable_foaf totalnodes realnoderoutingtest totalnodes allnodes totalnodes nodestarter createtestnode totalnodes max_htl number_of_nodes storesize enable_foaf totalnodes realnoderoutingtest totalnodes realnoderoutingtest totalnodes makekleinbergnetwork makekleinbergnetwork atarget countleafs btarget countleafs generaltarget atarget btarget realnoderoutingtest bridge_links nextint number_of_nodes nextint number_of_nodes bridge_links bridge_links nextint number_of_nodes bridge_links bridge_links nextint number_of_nodes totalnodes allnodes cyclenumber runningaverage bootstrappingdecayingrunningaverage runningaverage arate bootstrappingdecayingrunningaverage runningaverage brate bootstrappingdecayingrunningaverage runningaverage bridgerate bootstrappingdecayingrunningaverage hashset generalids hashset hashset aids hashset hashset bids hashset hashset bridgeids hashset cyclenumber interruptedexception runningaverage aloc trivialrunningaverage runningaverage bloc trivialrunningaverage totalsuccesses totaltotalpings generalids aids bids bridgeids number_of_nodes secretpingsuccesses totalsecretpingattempts ournetworkid aloc getlocation totalsuccesses totaltotalpings arate generalids valueof aids valueof number_of_nodes secretpingsuccesses totalsecretpingattempts ournetworkid bloc getlocation totalsuccesses totaltotalpings brate generalids valueof bids valueof secretpingsuccesses totalsecretpingattempts ournetworkid totalsuccesses totaltotalpings bridgerate generalids valueof bridgeids valueof cyclenumber secretpings totaltotalpings totalsuccesses psuccess currentvalue psuccess arate currentvalue psuccess brate currentvalue psuccess bridgerate currentvalue idreport generalids generaltarget idreport aids atarget idreport bids btarget idreport bridgeids aloc aloc currentvalue bloc bloc currentvalue private static void id report string group hash set integer ids int target num print out the number which are non zero display the distinct ones if a few int size ids size int max 6 string builder sb new string builder integer to string size append append integer to string target num sb append ids append group append iterator integer iter ids iterator for int i 0 i max i size i string this id iter next to string if i 0 sb append this id else sb append append this id if size max sb append logger error log sb to string idreport hashset targetnum stringbuilder stringbuilder tostring tostring targetnum thisid tostring thisid thisid tostring private static int count leafs node network int retval 0 for int i 0 i network length i int peers network i peers count valid peers if peers 1 retval return retval countleafs countvalidpeers public boolean has next if curr obj null return true while iterator has next object obj iterator next if query cls is instance obj curr obj t obj if condition null return true try if condition evaluate bool this return true catch jsql runtime exception x query report runtime error x curr obj null return false hasnext currobj hasnext isinstance currobj evaluatebool jsqlruntimeexception reportruntimeerror currobj public t next if has next throw new no such element exception t obj curr obj curr obj null return obj hasnext nosuchelementexception currobj currobj public void remove throw new unsupported operation exception unsupportedoperationexception filter iterator query impl query iterator t iterator node condition this query query this iterator iterator this condition condition index var new int max index vars filteriterator queryimpl indexvar maxindexvars final static int op date const 154 static string wrap null string object val return val null string val opdateconst wrapnullstring public boolean equals object o return o instanceof node node o tag tag node o type type static final boolean equal objects object a object b return a b a null a equals b equalobjects static final int get field type class type if type equals byte class type equals short class type equals int class type equals long class return tp int else if type equals boolean class return tp bool else if type equals double class type equals float class return tp real else if type equals string class return tp str else if type equals date class return tp date else if type equals boolean class return tp array bool else if type equals byte class return tp array int1 else if type equals short class return tp array int2 else if type equals char class return tp array char else if type equals int class return tp array int4 else if type equals long class return tp array int8 else if type equals float class return tp array real4 else if type equals double class return tp array real8 else if type equals string class return tp array str else if collection class is assignable from type return tp collection else if type is array return tp array obj else if type equals object class return tp any else return tp obj getfieldtype tpint tpbool tpreal tpstr tpdate tparraybool tparrayint1 tparrayint2 tparraychar tparrayint4 tparrayint8 tparrayreal4 tparrayreal8 tparraystr isassignablefrom tpcollection isarray tparrayobj tpany tpobj string get field name return null getfieldname boolean evaluate bool filter iterator t throw new abstract method error evaluatebool filteriterator abstractmethoderror throw new abstract method error long evaluate int filter iterator t throw new abstract method error abstractmethoderror evaluateint filteriterator abstractmethoderror throw new abstract method error double evaluate real filter iterator t throw new abstract method error abstractmethoderror evaluatereal filteriterator abstractmethoderror throw new abstract method error string evaluate str filter iterator t return wrap null string evaluate obj t abstractmethoderror evaluatestr filteriterator wrapnullstring evaluateobj return wrap null string evaluate obj t date evaluate date filter iterator t return date evaluate obj t wrapnullstring evaluateobj evaluatedate filteriterator evaluateobj object evaluate obj filter iterator t switch type case tp str return evaluate str t case tp date return evaluate date t case tp int return new long evaluate int t case tp real return new double evaluate real t case tp bool return evaluate bool t boolean true boolean false default throw new abstract method error evaluateobj filteriterator tpstr evaluatestr tpdate evaluatedate tpint evaluateint tpreal evaluatereal tpbool evaluatebool abstractmethoderror class get type return null gettype public string to string return node tag tag type type tostring node int type int tag this type type this tag tag class empty node extends node boolean evaluate bool filter iterator t return true emptynode evaluatebool filteriterator empty node super tp bool op true emptynode tpbool optrue abstract class literal node extends node abstract object get value literalnode getvalue abstract object get value object evaluate obj filter iterator t return get value getvalue evaluateobj filteriterator getvalue literal node int type int tag super type tag literalnode long value public boolean equals object o return o instanceof int literal node int literal node o value value intliteralnode intliteralnode object get value return new long value getvalue long evaluate int filter iterator t return value evaluateint filteriterator int literal node long value super tp int op int const this value value intliteralnode tpint opintconst double value public boolean equals object o return o instanceof real literal node real literal node o value value realliteralnode realliteralnode object get value return new double value getvalue double evaluate real filter iterator t return value evaluatereal filteriterator real literal node double value super tp real op real const this value value realliteralnode tpreal oprealconst string value public boolean equals object o return o instanceof str literal node str literal node o value equals value strliteralnode strliteralnode object get value return value getvalue string evaluate str filter iterator t return value evaluatestr filteriterator str literal node string value super tp str op str const this value value strliteralnode tpstr opstrconst class current node extends node class get type return cls currentnode gettype object evaluate obj filter iterator t return t curr obj evaluateobj filteriterator currobj current node class cls super tp obj op current this cls cls currentnode tpobj opcurrent date value public boolean equals object o return o instanceof date literal node date literal node o value equals value dateliteralnode dateliteralnode object get value return value getvalue date evaluate date filter iterator t return value evaluatedate filteriterator date literal node date value super tp date op date const this value value dateliteralnode tpdate opdateconst class constant node extends literal node object get value switch tag case op null return null case op false return boolean false case op true return boolean true default throw new error invalid tag tag constantnode literalnode getvalue opnull opfalse optrue boolean evaluate bool filter iterator t return tag op false evaluatebool filteriterator opfalse constant node int type int tag super type tag constantnode int loop id index out of range error int loop loop id loop loopid indexoutofrangeerror loopid int loop id public boolean equals object o return o instanceof exists node exists node o expr equals expr exists node o loop id loop id loopid existsnode existsnode existsnode loopid loopid boolean evaluate bool filter iterator t t index var loop id 0 try while expr evaluate bool t t index var loop id 1 return true catch index out of range error x if x loop id loop id throw x return false evaluatebool filteriterator indexvar loopid evaluatebool indexvar loopid indexoutofrangeerror loopid loopid exists node node expr int loop id super tp bool op exists this expr expr this loop id loop id existsnode loopid tpbool opexists loopid loopid int loop id public boolean equals object o return o instanceof index node index node o loop id loop id loopid indexnode indexnode loopid loopid long evaluate int filter iterator t return t index var loop id evaluateint filteriterator indexvar loopid index node int loop super tp int op index var loop id loop indexnode tpint opindexvar loopid node right public boolean equals object o return o instanceof get at node get at node o left equals left get at node o right equals right getatnode getatnode getatnode long evaluate int filter iterator t object arr left evaluate obj t long idx right evaluate int t if right tag op index var try if idx array get length arr throw new index out of range error index node right loop id catch illegal argument exception x throw new error argument is not array int index int idx switch tag case op get at int1 return byte arr index case op get at int2 return short arr index case op get at int4 return int arr index case op get at int8 return long arr index case op get at char return char arr index case op str get at return string arr char at index default throw new error invalid tag tag evaluateint filteriterator evaluateobj evaluateint opindexvar getlength indexoutofrangeerror indexnode loopid illegalargumentexception opgetatint1 opgetatint2 opgetatint4 opgetatint8 opgetatchar opstrgetat charat double evaluate real filter iterator t object arr left evaluate obj t long index right evaluate int t if right tag op index var try if index array get length arr throw new index out of range error index node right loop id catch illegal argument exception x throw new error argument is not array switch tag case op get at real4 return float arr int index case op get at real8 return double arr int index default throw new error invalid tag tag evaluatereal filteriterator evaluateobj evaluateint opindexvar getlength indexoutofrangeerror indexnode loopid illegalargumentexception opgetatreal4 opgetatreal8 boolean evaluate bool filter iterator t boolean arr boolean left evaluate obj t long index right evaluate int t if right tag op index var try if index arr length throw new index out of range error index node right loop id catch illegal argument exception x throw new error argument is not array return arr int index evaluatebool filteriterator evaluateobj evaluateint opindexvar indexoutofrangeerror indexnode loopid illegalargumentexception string evaluate str filter iterator t string arr string left evaluate obj t long index right evaluate int t if right tag op index var try if index arr length throw new index out of range error index node right loop id catch illegal argument exception x throw new error argument is not array return wrap null string arr int index evaluatestr filteriterator evaluateobj evaluateint opindexvar indexoutofrangeerror indexnode loopid illegalargumentexception wrapnullstring object evaluate obj filter iterator t object arr left evaluate obj t long index right evaluate int t try if right tag node op index var if index array get length arr throw new index out of range error index node right loop id return array get arr int index catch illegal argument exception x throw new error argument is not array evaluateobj filteriterator evaluateobj evaluateint opindexvar getlength indexoutofrangeerror indexnode loopid illegalargumentexception get at node int type int tag node base node index super type tag left base right index getatnode public boolean equals object o return o instanceof invoke node equal objects invoke node o target target arrays equals invoke node o arguments arguments equal objects invoke node o mth mth invokenode equalobjects invokenode invokenode equalobjects invokenode class get type return mth get return type gettype getreturntype string get field name if target null target tag op current string base name target get field name return base name null base name mth get name null else return mth get name getfieldname opcurrent basename getfieldname basename basename getname getname object get target filter iterator t if target null return t curr obj object obj target evaluate obj t if obj null throw new jsql null pointer exception target get type mth to string return obj gettarget filteriterator currobj evaluateobj jsqlnullpointerexception gettype tostring object evaluate arguments filter iterator t object parameters null int n arguments length if n 0 parameters new object n for int i 0 i n i node arg arguments i object value switch arg type case node tp int value new long arg evaluate int t break case node tp real value new double arg evaluate real t break case node tp str value arg evaluate str t break case node tp date value arg evaluate date t break case node tp bool value new boolean arg evaluate bool t break default value arg evaluate obj t parameters i value return parameters evaluatearguments filteriterator tpint evaluateint tpreal evaluatereal tpstr evaluatestr tpdate evaluatedate tpbool evaluatebool evaluateobj long evaluate int filter iterator t object obj get target t object parameters evaluate arguments t try return number mth invoke obj parameters long value catch exception x x print stack trace throw new error method invocation error evaluateint filteriterator gettarget evaluatearguments longvalue printstacktrace double evaluate real filter iterator t object obj get target t object parameters evaluate arguments t try return number mth invoke obj parameters double value catch exception x x print stack trace throw new error method invocation error evaluatereal filteriterator gettarget evaluatearguments doublevalue printstacktrace boolean evaluate bool filter iterator t object obj get target t object parameters evaluate arguments t try return boolean mth invoke obj parameters boolean value catch exception x x print stack trace throw new error method invocation error evaluatebool filteriterator gettarget evaluatearguments booleanvalue printstacktrace string evaluate str filter iterator t object obj get target t object parameters evaluate arguments t try return wrap null string mth invoke obj parameters catch exception x x print stack trace throw new error method invocation error evaluatestr filteriterator gettarget evaluatearguments wrapnullstring printstacktrace object evaluate obj filter iterator t object obj get target t object parameters evaluate arguments t try return mth invoke obj parameters catch exception x x print stack trace throw new error method invocation error evaluateobj filteriterator gettarget evaluatearguments printstacktrace invoke node node target method mth node arguments super get field type mth get return type op invoke this target target this arguments arguments this mth mth invokenode getfieldtype getreturntype opinvoke public boolean equals object o if o instanceof invoke any node return false invoke any node node invoke any node o return equal objects node target target arrays equals node arguments arguments arrays equals node profile profile equal objects node method name method name equal objects node contains field name contains field name invokeanynode invokeanynode invokeanynode equalobjects equalobjects methodname methodname equalobjects containsfieldname containsfieldname class get type return object class gettype string get field name if target null if target tag op current string base name target get field name return base name null base name method name null else return method name else return contains field name null contains field name method name method name getfieldname opcurrent basename getfieldname basename basename methodname methodname containsfieldname containsfieldname methodname methodname invoke any node node target string name node arguments string contains field name super tp any op invoke any this target target this contains field name contains field name method name name this arguments arguments profile new class arguments length invokeanynode containsfieldname tpany opinvokeany containsfieldname containsfieldname methodname object evaluate obj filter iterator t class cls method m object obj t curr obj if target null obj target evaluate obj t if obj null throw new jsql null pointer exception null method name object parameters null int n arguments length if n 0 parameters new object n for int i 0 i n i node arg arguments i object value class type switch arg type case node tp int value new long arg evaluate int t type long class break case node tp real value new double arg evaluate real t type double class break case node tp str value arg evaluate str t type string class break case node tp date value arg evaluate date t type date class break case node tp bool value new boolean arg evaluate bool t type boolean class break default value arg evaluate obj t if value null type value get class if type equals long class type equals integer class type equals byte class type equals character class type equals short class type long class else if type equals float class type equals double class type double class else if type equals boolean class type boolean class else type object class parameters i value profile i type try if target null t contains elem null if m query impl lookup method t contains elem get class method name profile null return t query resolve m invoke t contains elem parameters cls obj get class if m query impl lookup method cls method name profile null return t query resolve m invoke t contains elem parameters catch invocation target exception x x print stack trace throw new illegal access error catch illegal access exception x x print stack trace throw new illegal access error throw new jsql no such field exception cls method name evaluateobj filteriterator currobj evaluateobj jsqlnullpointerexception methodname tpint evaluateint tpreal evaluatereal tpstr evaluatestr tpdate evaluatedate tpbool evaluatebool evaluateobj getclass containselem queryimpl lookupmethod containselem getclass methodname containselem getclass queryimpl lookupmethod methodname containselem invocationtargetexception printstacktrace illegalaccesserror illegalaccessexception printstacktrace illegalaccesserror jsqlnosuchfieldexception methodname class convert any node extends node public boolean equals object o return o instanceof convert any node super equals o convert any node o expr equals expr convertanynode convertanynode convertanynode boolean evaluate bool filter iterator t return boolean evaluate obj t boolean value evaluatebool filteriterator evaluateobj booleanvalue long evaluate int filter iterator t return number evaluate obj t long value evaluateint filteriterator evaluateobj longvalue double evaluate real filter iterator t return number evaluate obj t double value evaluatereal filteriterator evaluateobj doublevalue object evaluate obj filter iterator t return expr evaluate obj t evaluateobj filteriterator evaluateobj convert any node int type node expr super type op convert any this expr expr convertanynode opconvertany public boolean equals object o return o instanceof bin op node super equals o bin op node o left equals left bin op node o right equals right binopnode binopnode binopnode long evaluate int filter iterator t long lval left evaluate int t long rval right evaluate int t long res switch tag case op int add return lval rval case op int sub return lval rval case op int mul return lval rval case op int div if rval 0 throw new jsql arithmetic exception divided by zero return lval rval case op int and return lval rval case op int or return lval rval case op int pow res 1 if rval 0 lval 1 lval rval rval while rval 0 if rval 1 0 res lval lval lval rval 1 return res default throw new error invalid tag evaluateint filteriterator evaluateint evaluateint opintadd opintsub opintmul opintdiv jsqlarithmeticexception opintand opintor opintpow double evaluate real filter iterator t double lval left evaluate real t double rval right evaluate real t switch tag case op real add return lval rval case op real sub return lval rval case op real mul return lval rval case op real div return lval rval case op real pow return math pow lval rval default throw new error invalid tag evaluatereal filteriterator evaluatereal evaluatereal oprealadd oprealsub oprealmul oprealdiv oprealpow string evaluate str filter iterator t string lval left evaluate str t string rval right evaluate str t return lval rval evaluatestr filteriterator evaluatestr evaluatestr object evaluate obj filter iterator t object lval rval try lval left evaluate obj t catch jsql runtime exception x t query report runtime error x rval right evaluate obj t if rval instanceof boolean return boolean rval boolean value boolean true boolean false throw x if lval instanceof boolean switch tag case op any and return boolean lval boolean value boolean right evaluate obj t boolean value boolean true boolean false case op any or return boolean lval boolean value boolean right evaluate obj t boolean value boolean true boolean false default throw new error operation is not applicable to operands of boolean type rval right evaluate obj t if lval instanceof double lval instanceof float rval instanceof double rval instanceof float double r1 number lval double value double r2 number rval double value switch tag case op any add return new double r1 r2 case op any sub return new double r1 r2 case op any mul return new double r1 r2 case op any div return new double r1 r2 case op any pow return new double math pow r1 r2 default throw new error operation is not applicable to operands of real type else if lval instanceof string rval instanceof string return string lval string rval else long i1 number lval long value long i2 number rval long value long res switch tag case op any add return new long i1 i2 case op any sub return new long i1 i2 case op any mul return new long i1 i2 case op any div if i2 0 throw new jsql arithmetic exception divided by zero return new long i1 i2 case op any and return new long i1 i2 case op any or return new long i1 i2 case op any pow res 1 if i1 0 i2 1 i2 i1 i1 while i1 0 if i1 1 0 res i2 i2 i2 i1 1 return new long res default throw new error operation is not applicable to operands of integer type evaluateobj filteriterator evaluateobj jsqlruntimeexception reportruntimeerror evaluateobj booleanvalue opanyand booleanvalue evaluateobj booleanvalue opanyor booleanvalue evaluateobj booleanvalue evaluateobj doublevalue doublevalue opanyadd opanysub opanymul opanydiv opanypow longvalue longvalue opanyadd opanysub opanymul opanydiv jsqlarithmeticexception opanyand opanyor opanypow static boolean are equal object a object b if a b return true if a instanceof double a instanceof float b instanceof double b instanceof float return number a double value number b double value else if a instanceof number b instanceof number return number a long value number b long value else if a null return a equals b return false areequal doublevalue doublevalue longvalue longvalue static int compare object a object b if a null return b null 0 1 else if b null return 1 else if a instanceof double a instanceof float b instanceof double b instanceof float double r1 number a double value double r2 number b double value return r1 r2 1 r1 r2 0 1 else if a instanceof number b instanceof number long i1 number a long value long i2 number b long value return i1 i2 1 i1 i2 0 1 else return comparable a compare to b doublevalue doublevalue longvalue longvalue compareto boolean evaluate bool filter iterator t switch tag case op any eq return are equal left evaluate obj t right evaluate obj t case op any ne return are equal left evaluate obj t right evaluate obj t case op any lt return compare left evaluate obj t right evaluate obj t 0 case op any le return compare left evaluate obj t right evaluate obj t 0 case op any gt return compare left evaluate obj t right evaluate obj t 0 case op any ge return compare left evaluate obj t right evaluate obj t 0 case op in any object elem left evaluate obj t object set right evaluate obj t if set instanceof string return string set index of string elem 0 else object arr object set for int i arr length i 0 if elem equals arr i return true return false case op bool and try if left evaluate bool t return false catch jsql runtime exception x t query report runtime error x return right evaluate bool t case op bool or try if left evaluate bool t return true catch jsql runtime exception x t query report runtime error x return right evaluate bool t case op int eq return left evaluate int t right evaluate int t case op int ne return left evaluate int t right evaluate int t case op int lt return left evaluate int t right evaluate int t case op int le return left evaluate int t right evaluate int t case op int gt return left evaluate int t right evaluate int t case op int ge return left evaluate int t right evaluate int t case op real eq return left evaluate real t right evaluate real t case op real ne return left evaluate real t right evaluate real t case op real lt return left evaluate real t right evaluate real t case op real le return left evaluate real t right evaluate real t case op real gt return left evaluate real t right evaluate real t case op real ge return left evaluate real t right evaluate real t case op str eq return left evaluate str t equals right evaluate str t case op str ne return left evaluate str t equals right evaluate str t case op str lt return left evaluate str t compare to right evaluate str t 0 case op str le return left evaluate str t compare to right evaluate str t 0 case op str gt return left evaluate str t compare to right evaluate str t 0 case op str ge return left evaluate str t compare to right evaluate str t 0 case op date eq return left evaluate date t equals right evaluate date t case op date ne return left evaluate date t equals right evaluate date t case op date lt return left evaluate date t compare to right evaluate date t 0 case op date le return left evaluate date t compare to right evaluate date t 0 case op date gt return left evaluate date t compare to right evaluate date t 0 case op date ge return left evaluate date t compare to right evaluate date t 0 case op bool eq return left evaluate bool t right evaluate bool t case op bool ne return left evaluate bool t right evaluate bool t case op obj eq return are equal left evaluate obj t right evaluate obj t case op obj ne return are equal left evaluate obj t right evaluate obj t case op scan collection return collection right evaluate obj t contains left evaluate obj t case op scan array bool boolean val left evaluate bool t boolean arr boolean right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array int1 long val left evaluate int t byte arr byte right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array char long val left evaluate int t char arr char right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array int2 long val left evaluate int t short arr short right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array int4 long val left evaluate int t int arr int right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array int8 long val left evaluate int t long arr long right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array real4 double val left evaluate real t float arr float right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array real8 double val left evaluate real t double arr double right evaluate obj t for int i arr length i 0 if arr i val return true return false case op scan array str string val left evaluate str t string arr string right evaluate obj t for int i arr length i 0 if val equals arr i return true return false case op scan array obj object val left evaluate obj t object arr object right evaluate obj t for int i arr length i 0 if are equal val arr i return true return false case op in string string substr left evaluate str t string str right evaluate str t return str index of substr 0 default throw new error invalid tag tag evaluatebool filteriterator opanyeq areequal evaluateobj evaluateobj opanyne areequal evaluateobj evaluateobj opanylt evaluateobj evaluateobj opanyle evaluateobj evaluateobj opanygt evaluateobj evaluateobj opanyge evaluateobj evaluateobj opinany evaluateobj evaluateobj indexof opbooland evaluatebool jsqlruntimeexception reportruntimeerror evaluatebool opboolor evaluatebool jsqlruntimeexception reportruntimeerror evaluatebool opinteq evaluateint evaluateint opintne evaluateint evaluateint opintlt evaluateint evaluateint opintle evaluateint evaluateint opintgt evaluateint evaluateint opintge evaluateint evaluateint oprealeq evaluatereal evaluatereal oprealne evaluatereal evaluatereal opreallt evaluatereal evaluatereal oprealle evaluatereal evaluatereal oprealgt evaluatereal evaluatereal oprealge evaluatereal evaluatereal opstreq evaluatestr evaluatestr opstrne evaluatestr evaluatestr opstrlt evaluatestr compareto evaluatestr opstrle evaluatestr compareto evaluatestr opstrgt evaluatestr compareto evaluatestr opstrge evaluatestr compareto evaluatestr opdateeq evaluatedate evaluatedate opdatene evaluatedate evaluatedate opdatelt evaluatedate compareto evaluatedate opdatele evaluatedate compareto evaluatedate opdategt evaluatedate compareto evaluatedate opdatege evaluatedate compareto evaluatedate opbooleq evaluatebool evaluatebool opboolne evaluatebool evaluatebool opobjeq areequal evaluateobj evaluateobj opobjne areequal evaluateobj evaluateobj opscancollection evaluateobj evaluateobj opscanarraybool evaluatebool evaluateobj opscanarrayint1 evaluateint evaluateobj opscanarraychar evaluateint evaluateobj opscanarrayint2 evaluateint evaluateobj opscanarrayint4 evaluateint evaluateobj opscanarrayint8 evaluateint evaluateobj opscanarrayreal4 evaluatereal evaluateobj opscanarrayreal8 evaluatereal evaluateobj opscanarraystr evaluatestr evaluateobj opscanarrayobj evaluateobj evaluateobj areequal opinstring evaluatestr evaluatestr indexof bin op node int type int tag node left node right super type tag this left left this right right binopnode public boolean equals object o return o instanceof compare node super equals o compare node o o1 equals o1 compare node o o2 equals o2 equal objects compare node o o3 o3 comparenode comparenode comparenode equalobjects comparenode boolean evaluate bool filter iterator t switch tag case op any between object val o1 evaluate obj t return bin op node compare val o2 evaluate obj t 0 bin op node compare val o3 evaluate obj t 0 case op int between long val o1 evaluate int t return val o2 evaluate int t val o3 evaluate int t case op real between double val o1 evaluate real t return val o2 evaluate real t val o3 evaluate real t case op str between string val o1 evaluate str t return val compare to o2 evaluate str t 0 val compare to o3 evaluate str t 0 case op date between date val o1 evaluate date t return val compare to o2 evaluate date t 0 val compare to o3 evaluate date t 0 case op str like string str o1 evaluate str t string pat o2 evaluate str t int pi 0 si 0 pn pat length sn str length int wildcard 1 strpos 1 while true if pi pn pat char at pi wildcard pi strpos si else if si sn return pi pn else if pi pn str char at si pat char at pi pat char at pi si 1 pi 1 else if wildcard 0 si strpos pi wildcard else return false case op str like esc string str o1 evaluate str t string pat o2 evaluate str t char escape o3 evaluate str t char at 0 int pi 0 si 0 pn pat length sn str length int wildcard 1 strpos 1 while true if pi pn pat char at pi wildcard pi strpos si else if si sn return pi pn else if pi 1 pn pat char at pi escape pat char at pi 1 str char at si si 1 pi 2 else if pi pn pat char at pi escape str char at si pat char at pi pat char at pi si 1 pi 1 else if wildcard 0 si strpos pi wildcard else return false default throw new error invalid tag tag evaluatebool filteriterator opanybetween evaluateobj binopnode evaluateobj binopnode evaluateobj opintbetween evaluateint evaluateint evaluateint oprealbetween evaluatereal evaluatereal evaluatereal opstrbetween evaluatestr compareto evaluatestr compareto evaluatestr opdatebetween evaluatedate compareto evaluatedate compareto evaluatedate opstrlike evaluatestr evaluatestr charat charat charat charat _ opstrlikeesc evaluatestr evaluatestr evaluatestr charat charat charat charat charat charat charat charat charat _ compare node int tag node a node b node c super tp bool tag o1 a o2 b o3 c comparenode tpbool node opd public boolean equals object o return o instanceof unary op node super equals o unary op node o opd equals opd unaryopnode unaryopnode object evaluate obj filter iterator t object val opd evaluate obj t switch tag case op any neg return val instanceof double val instanceof float object new double number val double value object new long number val long value case op any abs if val instanceof double val instanceof float double rval number val double value return new double rval 0 rval rval else long ival number val long value return new long ival 0 ival ival case op any not return val instanceof boolean boolean val boolean value boolean false boolean true object new long number val long value default throw new error invalid tag tag evaluateobj filteriterator evaluateobj opanyneg doublevalue longvalue opanyabs doublevalue longvalue opanynot booleanvalue longvalue long evaluate int filter iterator t long val switch tag case op int not return opd evaluate int t case op int neg return opd evaluate int t case op int abs val opd evaluate int t return val 0 val val case op real to int return long opd evaluate real t case op any length object obj opd evaluate obj t if obj instanceof string return string obj length else try return array get length obj catch illegal argument exception x throw new error argument is not array case op length try return array get length opd evaluate obj t catch illegal argument exception x throw new error argument is not array case op str length return opd evaluate str t length default throw new error invalid tag tag evaluateint filteriterator opintnot evaluateint opintneg evaluateint opintabs evaluateint oprealtoint evaluatereal opanylength evaluateobj getlength illegalargumentexception oplength getlength evaluateobj illegalargumentexception opstrlength evaluatestr double evaluate real filter iterator t double val switch tag case op real neg return opd evaluate real t case op real abs val opd evaluate real t return val 0 val val case op real sin return math sin opd evaluate real t case op real cos return math cos opd evaluate real t case op real tan return math tan opd evaluate real t case op real asin return math asin opd evaluate real t case op real acos return math acos opd evaluate real t case op real atan return math atan opd evaluate real t case op real exp return math exp opd evaluate real t case op real log return math log opd evaluate real t case op real sqrt return math sqrt opd evaluate real t case op real ceil return math ceil opd evaluate real t case op real floor return math floor opd evaluate real t case op int to real return double opd evaluate int t default throw new error invalid tag tag evaluatereal filteriterator oprealneg evaluatereal oprealabs evaluatereal oprealsin evaluatereal oprealcos evaluatereal oprealtan evaluatereal oprealasin evaluatereal oprealacos evaluatereal oprealatan evaluatereal oprealexp evaluatereal opreallog evaluatereal oprealsqrt evaluatereal oprealceil evaluatereal oprealfloor evaluatereal opinttoreal evaluateint date evaluate date filter iterator t switch tag case op str to date return query impl parse date opd evaluate str t default throw new error invalid tag tag evaluatedate filteriterator opstrtodate queryimpl parsedate evaluatestr string evaluate str filter iterator t switch tag case op str upper return opd evaluate str t to upper case case op str lower return opd evaluate str t to lower case case op int to str return long to string opd evaluate int t 10 case op real to str return double to string opd evaluate real t case op date to str return opd evaluate date t to string case op any to str return opd evaluate obj t to string default throw new error invalid tag tag evaluatestr filteriterator opstrupper evaluatestr touppercase opstrlower evaluatestr tolowercase opinttostr tostring evaluateint oprealtostr tostring evaluatereal opdatetostr evaluatedate tostring opanytostr evaluateobj tostring boolean evaluate bool filter iterator t switch tag case op bool not return opd evaluate bool t case op is null return opd evaluate obj t null default throw new error invalid tag tag evaluatebool filteriterator opboolnot evaluatebool opisnull evaluateobj unary op node int type int tag node node super type tag opd node unaryopnode public boolean equals object o if o instanceof load any node return false load any node node load any node o return equal objects node base base equal objects node field name field name equal objects node f f equal objects node m m loadanynode loadanynode loadanynode equalobjects equalobjects fieldname fieldname equalobjects equalobjects class get type return object class gettype string get field name if base null if base tag op current string base name base get field name return base name null base name field name null else return field name else return contains field name null contains field name field name field name getfieldname opcurrent basename getfieldname basename basename fieldname fieldname containsfieldname containsfieldname fieldname fieldname load any node node base string name string contains field name super tp any op load any field name name this contains field name contains field name this base base loadanynode containsfieldname tpany oploadany fieldname containsfieldname containsfieldname public string to string return load any node field name field name contains field name contains field name base base f f m m tostring loadanynode fieldname fieldname containsfieldname containsfieldname object evaluate obj filter iterator t object obj class cls field f this f method m this m try if base null if t contains elem null obj t contains elem cls obj get class if f null f get declaring class equals cls return t query resolve f get obj if m null m get declaring class equals cls return t query resolve m invoke obj if f class descriptor locate field cls field name null this f f return t query resolve f get obj if m query impl lookup method cls field name query impl default profile null this m m return t query resolve m invoke obj obj t curr obj else obj base evaluate obj t if obj null throw new jsql null pointer exception null field name cls obj get class if f null f get declaring class equals cls return t query resolve f get obj if m null m get declaring class equals cls return t query resolve m invoke obj if f class descriptor locate field cls field name null this f f return t query resolve f get obj if m query impl lookup method cls field name query impl default profile null this m m return t query resolve m invoke obj catch illegal access exception x x print stack trace throw new illegal access error catch invocation target exception x x print stack trace throw new illegal access error throw new jsql no such field exception cls field name evaluateobj filteriterator containselem containselem getclass getdeclaringclass getdeclaringclass classdescriptor locatefield fieldname queryimpl lookupmethod fieldname queryimpl defaultprofile currobj evaluateobj jsqlnullpointerexception fieldname getclass getdeclaringclass getdeclaringclass classdescriptor locatefield fieldname queryimpl lookupmethod fieldname queryimpl defaultprofile illegalaccessexception printstacktrace illegalaccesserror invocationtargetexception printstacktrace illegalaccesserror jsqlnosuchfieldexception fieldname public boolean equals object o return o instanceof resolve node resolve node o expr equals expr resolve node o resolver equals resolver resolve node o resolved class equals resolved class resolvenode resolvenode resolvenode resolvenode resolvedclass resolvedclass class get type return resolved class gettype resolvedclass object evaluate obj filter iterator t return resolver resolve expr evaluate obj t evaluateobj filteriterator evaluateobj string get field name if expr null return expr get field name else return null getfieldname getfieldname resolve node node expr resolver resolver class resolved class super tp obj op resolve this expr expr this resolver resolver this resolved class resolved class resolvenode resolvedclass tpobj opresolve resolvedclass resolvedclass public boolean equals object o return o instanceof load node super equals o load node o field equals field equal objects load node o base base loadnode loadnode equalobjects loadnode class get type return field get type gettype gettype string get field name if base null base tag op current string base name base get field name return base name null base name field get name null else return field get name getfieldname opcurrent basename getfieldname basename basename getname getname final object get base filter iterator t if base null return t curr obj object obj base evaluate obj t if obj null throw new jsql null pointer exception base get type field get name return obj getbase filteriterator currobj evaluateobj jsqlnullpointerexception gettype getname long evaluate int filter iterator t try return field get long get base t catch illegal access exception x throw new illegal access error evaluateint filteriterator getlong getbase illegalaccessexception illegalaccesserror double evaluate real filter iterator t try return field get double get base t catch illegal access exception x throw new illegal access error evaluatereal filteriterator getdouble getbase illegalaccessexception illegalaccesserror boolean evaluate bool filter iterator t try return field get boolean get base t catch illegal access exception x throw new illegal access error evaluatebool filteriterator getboolean getbase illegalaccessexception illegalaccesserror string evaluate str filter iterator t try return wrap null string field get get base t catch illegal access exception x throw new illegal access error evaluatestr filteriterator wrapnullstring getbase illegalaccessexception illegalaccesserror object evaluate obj filter iterator t try return field get get base t catch illegal access exception x throw new illegal access error evaluateobj filteriterator getbase illegalaccessexception illegalaccesserror load node node base field f super get field type f get type op load field f this base base loadnode getfieldtype gettype opload class aggregate function node extends node public boolean equals object o return o instanceof aggregate function node super equals o equal objects aggregate function node o argument argument aggregate function node o index index aggregatefunctionnode aggregatefunctionnode equalobjects aggregatefunctionnode aggregatefunctionnode long evaluate int filter iterator t return t int aggragate func value index evaluateint filteriterator intaggragatefuncvalue double evaluate real filter iterator t return t real aggragate func value index evaluatereal filteriterator realaggragatefuncvalue aggregate function node int type int tag node arg super type tag argument arg aggregatefunctionnode string contains array name invoke element node method mth node arguments string array name super null mth arguments contains array name array name containsarrayname invokeelementnode arrayname containsarrayname arrayname public boolean equals object o return o instanceof invoke element node super equals o invokeelementnode object get target filter iterator t return t contains elem gettarget filteriterator containselem string get field name if contains array name null return contains array name mth get name else return null getfieldname containsarrayname containsarrayname getname public boolean equals object o return o instanceof element node equal objects element node o array name array name equal objects element node o field field equal objects element node o type type elementnode equalobjects elementnode arrayname arrayname equalobjects elementnode equalobjects elementnode element node string array field f super get field type f get type op element array name array type f get type field f elementnode getfieldtype gettype opelement arrayname gettype string get field name return array name null array name field get name null getfieldname arrayname arrayname getname boolean evaluate bool filter iterator t try return field get boolean t contains elem catch illegal access exception x throw new illegal access error evaluatebool filteriterator getboolean containselem illegalaccessexception illegalaccesserror long evaluate int filter iterator t try return field get long t contains elem catch illegal access exception x throw new illegal access error evaluateint filteriterator getlong containselem illegalaccessexception illegalaccesserror double evaluate real filter iterator t try return field get double t contains elem catch illegal access exception x throw new illegal access error evaluatereal filteriterator getdouble containselem illegalaccessexception illegalaccesserror string evaluate str filter iterator t try return wrap null string field get t contains elem catch illegal access exception x throw new illegal access error evaluatestr filteriterator wrapnullstring containselem illegalaccessexception illegalaccesserror object evaluate obj filter iterator t try return field get t contains elem catch illegal access exception x throw new illegal access error evaluateobj filteriterator containselem illegalaccessexception illegalaccesserror class get type return type gettype public boolean equals object o if o instanceof contains node return false contains node node contains node o return node contains expr equals contains expr equal objects node group by field group by field equal objects node group by method group by method equal objects node group by field name group by field name equal objects node contains field class contains field class node group by type group by type equal objects node having expr having expr equal objects node with expr with expr equal objects node aggregate functions aggregate functions containsnode containsnode containsnode containsexpr containsexpr equalobjects groupbyfield groupbyfield equalobjects groupbymethod groupbymethod equalobjects groupbyfieldname groupbyfieldname equalobjects containsfieldclass containsfieldclass groupbytype groupbytype equalobjects havingexpr havingexpr equalobjects withexpr withexpr equalobjects aggregatefunctions aggregatefunctions public int compare object o1 object o2 if o1 o2 return 0 try if group by method null return comparable group by method invoke o1 compare to group by method invoke o2 switch group by type case tp int long v1 group by field get long o1 long v2 group by field get long o2 return v1 v2 1 v1 v2 0 1 case tp real double v1 group by field get double o1 double v2 group by field get double o2 return v1 v2 1 v1 v2 0 1 case tp bool boolean v1 group by field get boolean o1 boolean v2 group by field get boolean o2 return v1 v2 0 1 v2 1 0 default return comparable group by field get o1 compare to group by field get o2 catch invocation target exception x x print stack trace throw new illegal access error catch illegal access exception x x print stack trace throw new illegal access error groupbymethod groupbymethod compareto groupbymethod groupbytype tpint groupbyfield getlong groupbyfield getlong tpreal groupbyfield getdouble groupbyfield getdouble tpbool groupbyfield getboolean groupbyfield getboolean groupbyfield compareto groupbyfield invocationtargetexception printstacktrace illegalaccesserror illegalaccessexception printstacktrace illegalaccesserror boolean evaluate bool filter iterator t int i j k l n 0 len 0 object collection collection contains expr evaluate obj t if collection null return false object sorted array null if having expr null with expr null collection instanceof collection n collection instanceof collection collection collection size object collection length if t contains array null t contains array length n t contains array new object n sorted array t contains array t contains array null prevent reuse of the same array by nexted contains in with expression object save contains elem t contains elem if collection instanceof collection if with expr null object elem iterator iterator collection collection iterator while iterator has next elem iterator next if elem null if resolver null elem resolver resolve elem else elem t query resolve elem t contains elem elem try if with expr evaluate bool t if having expr null t contains elem save contains elem return true sorted array len elem catch jsql runtime exception x t query report runtime error x else sorted array collection collection to array n sorted array length if t query resolve map null for i 0 i n i sorted array i t query resolve sorted array i len n else object a object collection n a length if with expr null for i 0 i n i object elem a i if elem null if resolver null elem resolver resolve elem else elem t query resolve elem t contains elem elem try if with expr evaluate bool t if having expr null t contains elem save contains elem return true sorted array len elem catch jsql runtime exception x t query report runtime error x else system arraycopy a 0 sorted array 0 n if t query resolve map null for i 0 i n i sorted array i t query resolve sorted array i len n t contains elem save contains elem if sorted array null t contains array sorted array if len 0 return false if group by field name null len 0 class type sorted array 0 get class group by field class descriptor locate field type group by field name if group by field null group by method query impl lookup method type group by field name query impl default profile if group by method null throw new jsql no such field exception type group by field name else group by type node get field type group by field get type arrays sort sorted array 0 len this n aggregate functions size if t int aggragate func value null t int aggragate func value length n t int aggragate func value new long n t real aggragate func value new double n for i 0 i len i j for j i 1 j len compare sorted array i sorted array j 0 j for k 0 k n k aggregate function node agr aggregate function node aggregate functions get k node argument agr argument if agr type tp int long ival 0 switch agr tag case op sum for l i l j l t contains elem sorted array l ival argument evaluate int t break case op avg for l i l j l t contains elem sorted array l ival argument evaluate int t ival j i break case op min ival long max value for l i l j l t contains elem sorted array l long v argument evaluate int t if v ival ival v break case op max ival long min value for l i l j l t contains elem sorted array l long v argument evaluate int t if v ival ival v break case op count ival j i t int aggragate func value k ival else double rval 0 0 switch agr tag case op sum for l i l j l t contains elem sorted array l rval argument evaluate real t break case op avg for l i l j l t contains elem sorted array l rval argument evaluate real t rval j i break case op min rval double positive infinity for l i l j l t contains elem sorted array l double v argument evaluate real t if v rval rval v break case op max rval double negative infinity for l i l j l t contains elem sorted array l double v argument evaluate real t if v rval rval v t real aggragate func value k rval t contains elem save contains elem try if having expr evaluate bool t return true catch jsql runtime exception x t query report runtime error x return false evaluatebool filteriterator containsexpr evaluateobj sortedarray havingexpr withexpr containsarray containsarray containsarray sortedarray containsarray containsarray savecontainselem containselem withexpr hasnext containselem withexpr evaluatebool havingexpr containselem savecontainselem sortedarray jsqlruntimeexception reportruntimeerror sortedarray toarray sortedarray resolvemap sortedarray sortedarray withexpr containselem withexpr evaluatebool havingexpr containselem savecontainselem sortedarray jsqlruntimeexception reportruntimeerror sortedarray resolvemap sortedarray sortedarray containselem savecontainselem sortedarray containsarray sortedarray groupbyfieldname sortedarray getclass groupbyfield classdescriptor locatefield groupbyfieldname groupbyfield groupbymethod queryimpl lookupmethod groupbyfieldname queryimpl defaultprofile groupbymethod jsqlnosuchfieldexception groupbyfieldname groupbytype getfieldtype groupbyfield gettype sortedarray aggregatefunctions intaggragatefuncvalue intaggragatefuncvalue intaggragatefuncvalue realaggragatefuncvalue sortedarray sortedarray aggregatefunctionnode aggregatefunctionnode aggregatefunctions tpint opsum containselem sortedarray evaluateint opavg containselem sortedarray evaluateint opmin max_value containselem sortedarray evaluateint opmax min_value containselem sortedarray evaluateint opcount intaggragatefuncvalue opsum containselem sortedarray evaluatereal opavg containselem sortedarray evaluatereal opmin positive_infinity containselem sortedarray evaluatereal opmax negative_infinity containselem sortedarray evaluatereal realaggragatefuncvalue containselem savecontainselem havingexpr evaluatebool jsqlruntimeexception reportruntimeerror contains node node contains expr class contains field class super tp bool op contains this contains expr contains expr this contains field class contains field class aggregate functions new array list containsnode containsexpr containsfieldclass tpbool opcontains containsexpr containsexpr containsfieldclass containsfieldclass aggregatefunctions arraylist final int compare object a object b int diff try if method null diff comparable method invoke a compare to method invoke b else switch type case class descriptor tp boolean diff field get boolean a field get boolean b 0 1 field get boolean b 1 0 break case class descriptor tp char diff field get char a field get char b break case class descriptor tp byte diff field get byte a field get byte b break case class descriptor tp short diff field get short a field get short b break case class descriptor tp int int l field get int a int r field get int b diff l r 1 l r 0 1 break case class descriptor tp long long l field get long a long r field get long b diff l r 1 l r 0 1 break case class descriptor tp float float l field get float a float r field get float b diff l r 1 l r 0 1 break case class descriptor tp double double l field get double a double r field get double b diff l r 1 l r 0 1 break default diff comparable field get a compare to field get b break catch illegal access exception x x print stack trace throw new illegal access error catch invocation target exception x x print stack trace throw new illegal access error if diff 0 next null return next compare a b if ascent diff diff return diff compareto classdescriptor tpboolean getboolean getboolean getboolean classdescriptor tpchar getchar getchar classdescriptor tpbyte getbyte getbyte classdescriptor tpshort getshort getshort classdescriptor tpint getint getint classdescriptor tplong getlong getlong classdescriptor tpfloat getfloat getfloat classdescriptor tpdouble getdouble getdouble compareto illegalaccessexception printstacktrace illegalaccesserror invocationtargetexception printstacktrace illegalaccesserror void resolve name class cls field class descriptor locate field cls field name if field null method query impl lookup method cls field name query impl default profile if method null throw new jsql no such field exception cls field name resolvename classdescriptor locatefield fieldname queryimpl lookupmethod fieldname queryimpl defaultprofile jsqlnosuchfieldexception fieldname order node int type field field this type type this field field ascent true ordernode ascent true order node method method this method method ascent true ordernode ascent true order node string name field name name ascent true ordernode fieldname int index public boolean equals object o return o instanceof parameter node parameter node o index index parameternode parameternode boolean evaluate bool filter iterator t return boolean params get index boolean value evaluatebool filteriterator booleanvalue return boolean params get index boolean value long evaluate int filter iterator t return number params get index long value booleanvalue evaluateint filteriterator longvalue return number params get index long value double evaluate real filter iterator t return number params get index double value longvalue evaluatereal filteriterator doublevalue return number params get index double value string evaluate str filter iterator t return string params get index doublevalue evaluatestr filteriterator return string params get index date evaluate date filter iterator t return date params get index evaluatedate filteriterator object get value return params get index getvalue parameter node array list parameter list super tp unknown op parameter params parameter list index params size params add null parameternode arraylist parameterlist tpunknown opparameter parameterlist int tkn symbol int tkn this tkn tkn binding string ident int loop binding chain name ident used false next chain loop id loop loopid public iterable iterator t select class cls iterator t iterator string query throws compile error this query query buf query to char array str new char buf length this cls cls compile return execute iterator iterableiterator compileerror tochararray public iterable iterator t select string class name iterator t iterator string query throws compile error cls class descriptor load class storage class name return select cls iterator query iterableiterator classname compileerror classdescriptor loadclass classname public void set parameter int index object value parameters set index 1 value setparameter public void set int parameter int index long value set parameter index new long value setintparameter setparameter public void set real parameter int index double value set parameter index new double value setrealparameter setparameter public void set bool parameter int index boolean value set parameter index new boolean value setboolparameter setparameter public void prepare class cls string query this query query buf query to char array str new char buf length this cls cls compile tochararray public void prepare string class name string query cls class descriptor load class storage class name this query query buf query to char array str new char buf length compile classname classdescriptor loadclass classname tochararray public iterable iterator t execute iterator t iterator iterable iterator t result iterable iterator t apply index tree if result null if storage listener null storage listener sequential search performed query result new filter iterator t this iterator tree if order null array list t list new array list t while result has next list add result next sort list return new iterator wrapper t list iterator return result iterableiterator iterableiterator iterableiterator applyindex sequentialsearchperformed filteriterator arraylist arraylist hasnext iteratorwrapper private void sort array list t selection int i j k n order node order this order t top if selection size 0 return for order node ord order ord null ord ord next if ord field name null ord resolve name selection get 0 get class for n selection size i n 2 j i i 1 i k i top selection get k 1 do if k 2 n order compare selection get k 2 1 selection get k 2 0 if order compare top selection get k 2 1 0 break selection set k 1 selection get k 2 1 k k 2 else if order compare top selection get k 2 0 break selection set k 1 selection get k 2 k k 2 1 while k j selection set k 1 top for i n i 2 i top selection get i 1 selection set i 1 selection get 0 selection set 0 top for k 1 j i 1 2 k j if k 2 i 1 order compare selection get k 2 1 selection get k 2 0 if order compare top selection get k 2 1 0 break selection set k 1 selection get k 2 1 k k 2 else if order compare top selection get k 2 0 break selection set k 1 selection get k 2 k k 2 1 selection set k 1 top arraylist ordernode ordernode fieldname resolvename getclass public void report runtime error jsql runtime exception x if runtime errors reporting string buffer buf new string buffer buf append x get message class cls x get target if cls null buf append cls get name buf append string field name x get field name if field name null buf append field name system err println buf if storage null storage listener null storage listener jsql runtime error x reportruntimeerror jsqlruntimeexception runtimeerrorsreporting stringbuffer stringbuffer getmessage gettarget getname fieldname getfieldname fieldname fieldname jsqlruntimeerror public void enable runtime error reporting boolean enabled runtime errors reporting enabled enableruntimeerrorreporting runtimeerrorsreporting resolver resolver resolve mapping class resolved resolver resolver this resolved resolved this resolver resolver resolvemapping public void set resolver class original class resolved resolver resolver if resolve map null resolve map new hash map resolve map put original new resolve mapping resolved resolver setresolver resolvemap resolvemap hashmap resolvemap resolvemapping public void add index string key generic index t index if indices null indices new hash map indices put key index addindex genericindex hashmap private final generic index t get index string key return indices null generic index indices get key null genericindex getindex genericindex private static key key literal class type node node boolean inclusive object value literal node node get value if type equals long class return new key number value long value inclusive else if type equals int class return new key number value int value inclusive else if type equals byte class return new key number value byte value inclusive else if type equals short class return new key number value short value inclusive else if type equals char class return new key value instanceof number char number value int value character value char value inclusive else if type equals float class return new key number value float value inclusive else if type equals double class return new key number value double value inclusive else if type equals string class return new key string value inclusive else if type equals date class return new key date value inclusive return null keyliteral literalnode getvalue longvalue intvalue bytevalue shortvalue intvalue charvalue floatvalue doublevalue public query impl storage storage this storage storage impl storage parameters new array list runtime errors reporting true queryimpl storageimpl arraylist runtimeerrorsreporting static date parse date string source parse position pos new parse position 0 date result synchronized date format result date format parse source pos if pos get index 0 throw new error parse error for date source at position pos get error index return result parsedate parseposition parseposition dateformat dateformat getindex geterrorindex final int scan int p pos int eol buf length char ch 0 int i while p eol character is whitespace ch buf p p 1 if p eol return tkn eof pos p switch ch case return tkn add case return tkn sub case return tkn mul case return tkn div case return tkn dot case return tkn comma case return tkn lpar case return tkn rpar case return tkn lbr case return tkn rbr case return tkn col case return tkn power case return tkn param case if p eol if buf p pos 1 return tkn le if buf p pos 1 return tkn ne return tkn lt case if p eol buf p pos 1 return tkn ge return tkn gt case return tkn eq case if p eol buf p throw new compile error invalid token p 1 pos 1 return tkn ne case if p eol buf p throw new compile error invalid token p 1 pos 1 return tkn add case i 0 while true if p eol throw new compile error unexpected end of string constant p if buf p if p eol buf p svalue new string str 0 i pos p return tkn sconst str i buf p case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 case 8 case 9 i p 1 while p eol character is digit ch buf p p 1 if ch ch e ch e while p eol character is digit buf p buf p e buf p e buf p ch e ch e buf p buf p pos p try fvalue double value of query substring i p double value catch number format exception x throw new compile error bad floating point constant i return tkn fconst else pos p try ivalue long parse long query substring i p 10 catch number format exception x throw new compile error bad floating point constant i return tkn iconst default if character is letter ch ch ch i p 1 while p eol character is letter or digit ch buf p ch ch p 1 pos p ident query substring i p symbol s symbol symtab get ident return s null tkn ident s tkn else throw new compile error invalid symbol ch p 1 iswhitespace tkneof tknadd tknsub tknmul tkndiv tkndot tkncomma tknlpar tknrpar tknlbr tknrbr tkncol tknpower tknparam tknle tknne tknlt tknge tkngt tkneq compileerror tknne compileerror tknadd compileerror tknsconst isdigit isdigit valueof doublevalue numberformatexception compileerror tknfconst parselong numberformatexception compileerror tkniconst isletter _ isletterordigit _ tknident compileerror final node disjunction node left conjunction if lex tkn or int p pos node right disjunction if left type node tp int right type node tp int left new bin op node node tp int node op int or left right else if left type node tp bool right type node tp bool left new bin op node node tp bool node op bool or left right else if left type node tp any right type node tp any left new bin op node node tp any node op any or left right else throw new compile error bad operands for or operator p return left tknor tpint tpint binopnode tpint opintor tpbool tpbool binopnode tpbool opboolor tpany tpany binopnode tpany opanyor compileerror final node conjunction node left comparison if lex tkn and int p pos node right conjunction if left type node tp int right type node tp int left new bin op node node tp int node op int and left right else if left type node tp bool right type node tp bool left new bin op node node tp bool node op bool and left right else if left type node tp any right type node tp any left new bin op node node tp any node op any and left right else throw new compile error bad operands for and operator p return left tknand tpint tpint binopnode tpint opintand tpbool tpbool binopnode tpbool opbooland tpany tpany binopnode tpany opanyand compileerror final static node int2real node expr if expr tag node op int const return new real literal node double int literal node expr value return new unary op node node tp real node op int to real expr opintconst realliteralnode intliteralnode unaryopnode tpreal opinttoreal final static node str2date node expr if expr tag node op str const return new date literal node parse date str literal node expr value return new unary op node node tp date node op str to date expr opstrconst dateliteralnode parsedate strliteralnode unaryopnode tpdate opstrtodate final int compare node expr bin op node list int n 1 if list left null n compare expr bin op node list left node elem list right int cop node op nop if elem type node tp unknown elem type expr type if expr type node tp int if elem type node tp real expr new unary op node node tp real node op int to real expr cop node op real eq else if elem type node tp int cop node op int eq else if expr type node tp real if elem type node tp real cop node op real eq else if elem type node tp int cop node op real eq elem int2real elem else if expr type node tp date elem type node tp date cop node op date eq else if expr type node tp str elem type node tp str cop node op str eq else if expr type node tp obj elem type node tp obj cop node op obj eq else if expr type node tp bool elem type node tp bool cop node op bool eq else if expr type node tp any cop node op any eq if cop node op nop throw new compile error expression n in right part of in operator has incompatible type pos list type node tp bool if list left null list right new bin op node node tp bool cop expr elem list tag node op bool or else list left expr list right elem list tag cop return n binopnode binopnode opnop tpunknown tpint tpreal unaryopnode tpreal opinttoreal oprealeq tpint opinteq tpreal tpreal oprealeq tpint oprealeq tpdate tpdate opdateeq tpstr tpstr opstreq tpobj tpobj opobjeq tpbool tpbool opbooleq tpany opanyeq opnop compileerror tpbool binopnode tpbool opboolor final node comparison int left pos pos node left right left addition int cop lex if cop tkn eq cop tkn ne cop tkn gt cop tkn ge cop tkn le cop tkn lt cop tkn between cop tkn like cop tkn not cop tkn is cop tkn in int right pos pos boolean not false if cop tkn not not true cop scan if cop tkn like cop tkn between cop tkn in throw new compile error like between or in expected right pos right pos pos else if cop tkn is if left type node tp obj throw new compile error is not null predicate can be applied only to references arrays or string right pos right pos pos if cop scan tkn null left new unary op node node tp bool node op is null left else if cop tkn not right pos pos if scan tkn null left new unary op node node tp bool node op bool not new unary op node node tp bool node op is null left else throw new compile error null expected right pos else throw new compile error not null expected right pos lex scan return left right addition if cop tkn in int type if right type node tp list left type node tp any right type node tp any left new bin op node node tp bool node op in any left right else switch right type case node tp collection left new bin op node node tp bool node op scan collection left right break case node tp array bool if left type node tp bool throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array bool left right break case node tp array int1 if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array int1 left right break case node tp array char if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array char left right break case node tp array int2 if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array int2 left right break case node tp array int4 if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array int4 left right break case node tp array int8 if left type node tp int throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array int8 left right break case node tp array real4 if left type node tp int left int2real left else if left type node tp real throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array real4 left right break case node tp array real8 if left type node tp int left int2real left else if left type node tp real throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array real8 left right break case node tp array obj if left type node tp obj throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array obj left right break case node tp array str if left type node tp str throw new compile error incompatible types of in operator operands right pos left new bin op node node tp bool node op scan array str left right break case node tp str if left type node tp str throw new compile error left operand of in expression hasn t string type left pos left new bin op node node tp bool node op in string left right break case node tp list compare left bin op node right left right break default throw new compile error list of expressions or array expected right pos else if cop tkn between int and pos pos if lex tkn and throw new compile error and expected pos node right2 addition if right type node tp unknown right type left type if right2 type node tp unknown right2 type left type if left type node tp any right type node tp any right2 type node tp any left new compare node node op any between left right right2 else if left type node tp real right type node tp real right2 type node tp real if left type node tp int left int2real left else if left type node tp real throw new compile error operand of between operator should be of integer real or string type left pos if right type node tp int right int2real right else if right type node tp real throw new compile error operand of between operator should be of integer real or string type right pos if right2 type node tp int right2 int2real right2 else if right2 type node tp real throw new compile error operand of between operator should be of integer real or string type leftpos tkneq tknne tkngt tknge tknle tknlt tknbetween tknlike tknnot tknis tknin rightpos tknnot tknlike tknbetween tknin compileerror rightpos rightpos tknis tpobj compileerror rightpos rightpos tknnull unaryopnode tpbool opisnull tknnot rightpos tknnull unaryopnode tpbool opboolnot unaryopnode tpbool opisnull compileerror rightpos compileerror rightpos tknin tplist tpany tpany binopnode tpbool opinany tpcollection binopnode tpbool opscancollection tparraybool tpbool compileerror rightpos binopnode tpbool opscanarraybool tparrayint1 tpint compileerror rightpos binopnode tpbool opscanarrayint1 tparraychar tpint compileerror rightpos binopnode tpbool opscanarraychar tparrayint2 tpint compileerror rightpos binopnode tpbool opscanarrayint2 tparrayint4 tpint compileerror rightpos binopnode tpbool opscanarrayint4 tparrayint8 tpint compileerror rightpos binopnode tpbool opscanarrayint8 tparrayreal4 tpint tpreal compileerror rightpos binopnode tpbool opscanarrayreal4 tparrayreal8 tpint tpreal compileerror rightpos binopnode tpbool opscanarrayreal8 tparrayobj tpobj compileerror rightpos binopnode tpbool opscanarrayobj tparraystr tpstr compileerror rightpos binopnode tpbool opscanarraystr tpstr tpstr compileerror leftpos binopnode tpbool opinstring tplist binopnode compileerror rightpos tknbetween andpos tknand compileerror tpunknown tpunknown tpany tpany tpany comparenode opanybetween tpreal tpreal tpreal tpint tpreal compileerror leftpos tpint tpreal compileerror rightpos tpint tpreal compileerror final node addition int left pos pos node left multiplication while lex tkn add lex tkn sub int cop lex int right pos pos node right multiplication if left type node tp any right type node tp any left new bin op node node tp any cop tkn add node op any add node op any sub left right else if left type node tp real right type node tp real if left type node tp int left int2real left else if left type node tp real throw new compile error operands of arithmetic operators should be of integer or real type left pos if right type node tp int right int2real right else if right type node tp real throw new compile error operands of arithmetic operator should be of integer or real type right pos left new bin op node node tp real cop tkn add node op real add node op real sub left right else if left type node tp int right type node tp int left new bin op node node tp int cop tkn add node op int add node op int sub left right else if left type node tp str right type node tp str if cop tkn add left new bin op node node tp str node op str concat left right else throw new compile error operation is not defined for strings right pos else throw new compile error operands of arithmentic operator should be of integer or real type right pos left pos right pos return left leftpos tknadd tknsub rightpos tpany tpany binopnode tpany tknadd opanyadd opanysub tpreal tpreal tpint tpreal compileerror leftpos tpint tpreal compileerror rightpos binopnode tpreal tknadd oprealadd oprealsub tpint tpint binopnode tpint tknadd opintadd opintsub tpstr tpstr tknadd binopnode tpstr opstrconcat compileerror rightpos compileerror rightpos leftpos rightpos final node multiplication int left pos pos node left power while lex tkn mul lex tkn div int cop lex int right pos pos node right power if left type node tp any right type node tp any left new bin op node node tp any cop tkn mul node op any mul node op any div left right else if left type node tp real right type node tp real if left type node tp int left int2real left else if left type node tp real throw new compile error operands of arithmetic operators should be of integer or real type left pos if right type node tp int right int2real right else if right type node tp real throw new compile error operands of arithmetic operator should be of integer or real type right pos left new bin op node node tp real cop tkn mul node op real mul node op real div left right else if left type node tp int right type node tp int left new bin op node node tp int cop tkn mul node op int mul node op int div left right else throw new compile error operands of arithmentic operator should be of integer or real type right pos left pos right pos return left leftpos tknmul tkndiv rightpos tpany tpany binopnode tpany tknmul opanymul opanydiv tpreal tpreal tpint tpreal compileerror leftpos tpint tpreal compileerror rightpos binopnode tpreal tknmul oprealmul oprealdiv tpint tpint binopnode tpint tknmul opintmul opintdiv compileerror rightpos leftpos rightpos final node power int left pos pos node left term if lex tkn power int right pos pos node right power if left type node tp any right type node tp any left new bin op node node tp any node op any pow left right else if left type node tp real right type node tp real if left type node tp int left int2real left else if left type node tp real throw new compile error operands of arithmetic operators should be of integer or real type left pos if right type node tp int right int2real right else if right type node tp real throw new compile error operands of arithmetic operator should be of integer or real type right pos left new bin op node node tp real node op real pow left right else if left type node tp int right type node tp int left new bin op node node tp int node op int pow left right else throw new compile error operands of arithmentic operator should be of integer or real type right pos return left leftpos tknpower rightpos tpany tpany binopnode tpany opanypow tpreal tpreal tpint tpreal compileerror leftpos tpint tpreal compileerror rightpos binopnode tpreal oprealpow tpint tpint binopnode tpint opintpow compileerror rightpos static method lookup method class cls string ident class profile method m null for class scope cls scope null scope scope get superclass try m scope get declared method ident profile break catch exception x if m null profile length 0 ident get character to upper case ident char at 0 ident substring 1 for class scope cls scope null scope scope get superclass try m scope get declared method ident profile break catch exception x if m null try m set accessible true catch exception x return m lookupmethod getsuperclass getdeclaredmethod touppercase charat getsuperclass getdeclaredmethod setaccessible final object resolve object obj if resolve map null resolve mapping rm resolve mapping resolve map get obj get class if rm null obj rm resolver resolve obj return obj resolvemap resolvemapping resolvemapping resolvemap getclass final node component node base class cls string c string ident this ident field f lex scan if lex tkn lpar if base null contains null f class descriptor locate field contains contains field class ident if f null return new element node contains contains expr get field name f else if cls null f class descriptor locate field cls ident if f null return new load node base f class profile default profile node arguments no arguments if lex tkn lpar array list argument list new array list do argument list add disjunction while lex tkn comma if lex tkn rpar throw new compile error expected pos lex scan profile new class argument list size arguments new node profile length boolean unknown profile false for int i 0 i profile length i node arg node argument list get i arguments i arg class arg type switch arg type case node tp int arg type long class break case node tp real arg type double class break case node tp str arg type string class break case node tp date arg type date class break case node tp bool arg type boolean class break case node tp obj arg type arg get type break case node tp array bool arg type boolean class break case node tp array char arg type char class break case node tp array int1 arg type byte class break case node tp array int2 arg type short class break case node tp array int4 arg type int class break case node tp array int8 arg type long class break case node tp array real4 arg type float class break case node tp array real8 arg type double class break case node tp array str arg type string class break case node tp array obj arg type object class break case node tp unknown case node tp any arg type object class unknown profile true break default throw new compile error invalid method argument type pos profile i arg type if unknown profile if cls equals object class base null contains null return new invoke any node base ident arguments null else return new invoke any node base ident arguments contains contains expr get field name method m null if base null contains null m lookup method contains contains field class ident profile if m null return new invoke element node m arguments contains contains expr get field name if arguments no arguments cls null f class descriptor locate field cls ident if f null return new load node base f if cls null m lookup method cls ident profile if m null return new invoke node base m arguments if object class equals cls return profile length 0 node new load any node base ident null node new invoke any node base ident arguments null else if base null contains null contains contains field class equals object class string arr field name contains contains expr get field name return profile length 0 node new load any node base ident arr field name node new invoke any node base ident arguments arr field name else throw new compile error no field or method ident in class cls null contains contains field class cls get name pos tknlpar classdescriptor locatefield containsfieldclass elementnode containsexpr getfieldname classdescriptor locatefield loadnode defaultprofile noarguments tknlpar arraylist argumentlist arraylist argumentlist tkncomma tknrpar compileerror argumentlist unknownprofile argumentlist argtype tpint argtype tpreal argtype tpstr argtype tpdate argtype tpbool argtype tpobj argtype gettype tparraybool argtype tparraychar argtype tparrayint1 argtype tparrayint2 argtype tparrayint4 argtype tparrayint8 argtype tparrayreal4 argtype tparrayreal8 argtype tparraystr argtype tparrayobj argtype tpunknown tpany argtype unknownprofile compileerror argtype unknownprofile invokeanynode invokeanynode containsexpr getfieldname lookupmethod containsfieldclass invokeelementnode containsexpr getfieldname noarguments classdescriptor locatefield loadnode lookupmethod invokenode loadanynode invokeanynode containsfieldclass arrfieldname containsexpr getfieldname loadanynode arrfieldname invokeanynode arrfieldname compileerror containsfieldclass getname final node field node expr int p pos int type int tag class cls expr get type while true if resolve map null expr type node tp obj cls null resolve mapping rm resolve mapping resolve map get cls if rm null expr new resolve node expr rm resolver rm resolved cls rm resolved switch lex case tkn dot if scan tkn ident throw new compile error identifier expected p if expr type node tp obj expr type node tp any expr type node tp collection throw new compile error left operand of should be reference p if contains null contains contains expr equals expr expr component null null else if expr type node tp collection throw new compile error left operand of should be reference p expr component expr cls cls expr get type continue case tkn lbr switch expr type case node tp array bool tag node op get at bool type node tp bool break case node tp array char tag node op get at char type node tp int break case node tp str tag node op str get at type node tp int break case node tp array int1 tag node op get at int1 type node tp int break case node tp array int2 tag node op get at int2 type node tp int break case node tp array int4 tag node op get at int4 type node tp int break case node tp array int8 tag node op get at int8 type node tp int break case node tp array real4 tag node op get at real4 type node tp real break case node tp array real8 tag node op get at real8 type node tp real break case node tp array str tag node op get at str type node tp str break case node tp array obj tag node op get at obj cls cls get component type type cls is array node tp array obj cls equals object class node tp any node tp obj break case node tp any tag node op get at obj type node tp any break default throw new compile error index can be applied only to arrays p p pos node index disjunction if lex tkn rbr throw new compile error expected pos if index type node tp any index new convert any node node tp int index else if index type node tp int index type node tp free var throw new compile error index should have integer type p expr new get at node type tag expr index lex scan continue default return expr gettype resolvemap tpobj resolvemapping resolvemapping resolvemap resolvenode tkndot tknident compileerror tpobj tpany tpcollection compileerror containsexpr tpcollection compileerror gettype tknlbr tparraybool opgetatbool tpbool tparraychar opgetatchar tpint tpstr opstrgetat tpint tparrayint1 opgetatint1 tpint tparrayint2 opgetatint2 tpint tparrayint4 opgetatint4 tpint tparrayint8 opgetatint8 tpint tparrayreal4 opgetatreal4 tpreal tparrayreal8 opgetatreal8 tpreal tparraystr opgetatstr tpstr tparrayobj opgetatobj getcomponenttype isarray tparrayobj tpany tpobj tpany opgetatobj tpany compileerror tknrbr compileerror tpany convertanynode tpint tpint tpfreevar compileerror getatnode final node contains element int p pos node contains expr term class arr class contains expr get type if arr class null arr class is array arr class equals object class collection class is assignable from arr class throw new compile error contains clause can be applied only to arrays or collections p class arr elem type arr class is array arr class get component type object class p pos node with condition null contains node outer contains contains contains node inner contains new contains node contains expr arr elem type contains inner contains if resolve map null resolve mapping rm resolve mapping resolve map get arr elem type if rm null inner contains resolver rm resolver arr elem type rm resolved if lex tkn with inner contains with expr check type node tp bool disjunction if lex tkn group p pos if scan tkn by throw new compile error group by expected p p pos if scan tkn ident throw new compile error group by field expected p if arr elem type equals object class inner contains group by field name ident else field group by field class descriptor locate field arr elem type ident if group by field null method group by method lookup method arr elem type ident default profile if group by method null throw new compile error field ident is not found p inner contains group by method group by method class rt group by method get return type if rt equals void class rt is primitive comparable class is assignable from rt throw new compile error result type rt of sort method should be comparable p else class type group by field get type if type is primitive comparable class is assignable from type throw new compile error order by field type type should be comparable p inner contains group by field group by field inner contains group by type node get field type type if scan tkn having throw new compile error having expected pos inner contains having expr check type node tp bool disjunction contains outer contains return inner contains containselement containsexpr arrclass containsexpr gettype arrclass arrclass isarray arrclass isassignablefrom arrclass compileerror arrelemtype arrclass isarray arrclass getcomponenttype withcondition containsnode outercontains containsnode innercontains containsnode containsexpr arrelemtype innercontains resolvemap resolvemapping resolvemapping resolvemap arrelemtype innercontains arrelemtype tknwith innercontains withexpr checktype tpbool tkngroup tknby compileerror tknident compileerror arrelemtype innercontains groupbyfieldname groupbyfield classdescriptor locatefield arrelemtype groupbyfield groupbymethod lookupmethod arrelemtype defaultprofile groupbymethod compileerror innercontains groupbymethod groupbymethod groupbymethod getreturntype isprimitive isassignablefrom compileerror groupbyfield gettype isprimitive isassignablefrom compileerror innercontains groupbyfield groupbyfield innercontains groupbytype getfieldtype tknhaving compileerror innercontains havingexpr checktype tpbool outercontains innercontains final node aggregate function int cop int p pos aggregate function node agr if contains null contains group by field null contains group by method null contains group by field name null throw new compile error aggregate function can be used only inside having clause p if cop tkn count if scan tkn lpar scan tkn mul scan tkn rpar throw new compile error count expected p lex scan agr new aggregate function node node tp int node op count null else node arg term if arg type node tp any arg new convert any node node tp real arg else if arg type node tp int arg type node tp real throw new compile error argument of aggregate function should have scalar type p agr new aggregate function node arg type cop node op avg tkn avg arg agr index contains aggregate functions size contains aggregate functions add agr return agr aggregatefunction aggregatefunctionnode groupbyfield groupbymethod groupbyfieldname compileerror tkncount tknlpar tknmul tknrpar compileerror aggregatefunctionnode tpint opcount tpany convertanynode tpreal tpint tpreal compileerror aggregatefunctionnode opavg tknavg aggregatefunctions aggregatefunctions final node check type int type node expr if expr type type if expr type node tp any expr new convert any node type expr else if expr type node tp unknown expr type type else throw new compile error node type names type expression expected pos return expr checktype tpany convertanynode tpunknown compileerror typenames final node term int cop scan int p pos node expr binding bp switch cop case tkn eof case tkn order lex cop return new empty node case tkn param expr new parameter node parameters break case tkn ident for bp bindings bp null bp bp next if bp name equals ident lex scan bp used true return new index node bp loop id expr component null cls return field expr case tkn contains return contains element case tkn exists if scan tkn ident throw new compile error free variable name expected p bindings bp new binding ident vars bindings if vars filter iterator max index vars throw new compile error too many nested exists clauses p p pos if scan tkn col throw new compile error expected p expr check type node tp bool term if bp used expr new exists node expr vars 1 vars 1 bindings bp next return expr case tkn current lex scan return field new current node cls case tkn false expr new constant node node tp bool node op false break case tkn true expr new constant node node tp bool node op true break case tkn null expr new constant node node tp obj node op null break case tkn iconst expr new int literal node ivalue break case tkn fconst expr new real literal node fvalue break case tkn sconst expr new str literal node svalue lex scan return field expr case tkn sum case tkn min case tkn max case tkn avg case tkn count return aggregate function cop case tkn sin case tkn cos case tkn tan case tkn asin case tkn acos case tkn atan case tkn exp case tkn log case tkn sqrt case tkn ceil case tkn floor expr term if expr type node tp int expr int2real expr else if expr type node tp any expr new convert any node node tp real expr else if expr type node tp real throw new compile error numeric argument expected p return new unary op node node tp real cop node op real sin tkn sin expr case tkn abs expr term if expr type node tp int return new unary op node node tp int node op int abs expr else if expr type node tp real return new unary op node node tp real node op real abs expr else if expr type node tp any return new unary op node node tp any node op any abs expr else throw new compile error abs function can be applied only to integer or real expression p case tkn length expr term if expr type node tp str return new unary op node node tp int node op str length expr else if expr type node tp any return new unary op node node tp int node op any length expr else if expr type node tp array bool return new unary op node node tp int node op length expr else throw new compile error length function is defined only for arrays and strings p case tkn lower return field new unary op node node tp str node op str lower check type node tp str term case tkn upper return field new unary op node node tp str node op str upper check type node tp str term case tkn integer return new unary op node node tp int node op real to int check type node tp real term case tkn real return new unary op node node tp int node op int to real check type node tp int term case tkn string expr term if expr type node tp int return field new unary op node node tp str node op int to str expr else if expr type node tp real return field new unary op node node tp str node op real to str expr else if expr type node tp date return field new unary op node node tp str node op date to str expr else if expr type node tp any return field new unary op node node tp str node op any to str expr throw new compile error string function can be applied only to integer or real expression p case tkn lpar expr disjunction node list null while lex tkn comma list new bin op node node tp list node op nop list expr expr disjunction if lex tkn rpar throw new compile error expected pos if list null expr new bin op node node tp list node op nop list expr break case tkn not expr comparison if expr type node tp int if expr tag node op int const int literal node ic int literal node expr ic value ic value else expr new unary op node node tp int node op int not expr return expr else if expr type node tp bool return new unary op node node tp bool node op bool not expr else if expr type node tp any return new unary op node node tp any node op any not expr else throw new compile error not operator can be applied only to integer or boolean expressions p case tkn add throw new compile error using of unary plus operator has no sense p case tkn sub expr term if expr type node tp int if expr tag node op int const int literal node ic int literal node expr ic value ic value else expr new unary op node node tp int node op int neg expr else if expr type node tp real if expr tag node op real const real literal node fc real literal node expr fc value fc value else expr new unary op node node tp real node op real neg expr else if expr type node tp any expr new unary op node node tp any node op any neg expr else throw new compile error unary minus can be applied only to numeric expressions p return expr default throw new compile error operand expected p lex scan return expr tkneof tknorder emptynode tknparam parameternode tknident indexnode loopid tkncontains containselement tknexists tknident compileerror filteriterator maxindexvars compileerror tkncol compileerror checktype tpbool existsnode tkncurrent currentnode tknfalse constantnode tpbool opfalse tkntrue constantnode tpbool optrue tknnull constantnode tpobj opnull tkniconst intliteralnode tknfconst realliteralnode tknsconst strliteralnode tknsum tknmin tknmax tknavg tkncount aggregatefunction tknsin tkncos tkntan tknasin tknacos tknatan tknexp tknlog tknsqrt tknceil tknfloor tpint tpany convertanynode tpreal tpreal compileerror unaryopnode tpreal oprealsin tknsin tknabs tpint unaryopnode tpint opintabs tpreal unaryopnode tpreal oprealabs tpany unaryopnode tpany opanyabs compileerror tknlength tpstr unaryopnode tpint opstrlength tpany unaryopnode tpint opanylength tparraybool unaryopnode tpint oplength compileerror tknlower unaryopnode tpstr opstrlower checktype tpstr tknupper unaryopnode tpstr opstrupper checktype tpstr tkninteger unaryopnode tpint oprealtoint checktype tpreal tknreal unaryopnode tpint opinttoreal checktype tpint tknstring tpint unaryopnode tpstr opinttostr tpreal unaryopnode tpstr oprealtostr tpdate unaryopnode tpstr opdatetostr tpany unaryopnode tpstr opanytostr compileerror tknlpar tkncomma binopnode tplist opnop tknrpar compileerror binopnode tplist opnop tknnot tpint opintconst intliteralnode intliteralnode unaryopnode tpint opintnot tpbool unaryopnode tpbool opboolnot tpany unaryopnode tpany opanynot compileerror tknadd compileerror tknsub tpint opintconst intliteralnode intliteralnode unaryopnode tpint opintneg tpreal oprealconst realliteralnode realliteralnode unaryopnode tpreal oprealneg tpany unaryopnode tpany opanyneg compileerror compileerror final iterable iterator t filter iterable iterator iterator node condition return new filter iterator t this iterator condition iterableiterator iterableiterator filteriterator final iterable iterator t apply index node condition node filter condition null node expr condition iterator result if expr tag node op bool and filter condition bin op node expr right expr bin op node expr left if expr tag node op contains contains node contains contains node expr if contains with expr null return null if contains having expr null filter condition condition expr contains with expr if expr instanceof bin op node bin op node cmp bin op node expr string key cmp left get field name if key null cmp right instanceof literal node generic index index get index key if index null return null switch expr tag case node op any eq case node op int eq case node op real eq case node op str eq case node op date eq case node op bool eq key value key literal index get key type cmp right true if value null return filter index iterator value value index ascent order filter condition return null case node op int gt case node op real gt case node op str gt case node op date gt case node op any gt key value key literal index get key type cmp right false if value null return filter index iterator value null index ascent order filter condition return null case node op int ge case node op real ge case node op str ge case node op date ge case node op any ge key value key literal index get key type cmp right true if value null return filter index iterator value null index ascent order filter condition return null case node op int lt case node op real lt case node op str lt case node op date lt case node op any lt key value key literal index get key type cmp right false if value null return filter index iterator null value index ascent order filter condition return null case node op int le case node op real le case node op str le case node op date le case node op any le key value key literal index get key type cmp right true if value null return filter index iterator null value index ascent order filter condition return null else if expr instanceof compare node compare node cmp compare node expr string key cmp o1 get field name if key null cmp o2 instanceof literal node cmp o3 null cmp o3 instanceof literal node generic index index get index key if index null return null switch expr tag case node op int between case node op str between case node op real between case node op date between case node op any between key value1 key literal index get key type cmp o2 true key value2 key literal index get key type cmp o3 true if value1 null value2 null return filter index iterator value1 value2 index ascent order filter condition return null case node op str like case node op str like esc string pattern string literal node cmp o2 get value char escape cmp o3 null string literal node cmp o3 get value char at 0 int pref 0 while pref pattern length char ch pattern char at pref if ch ch break else if ch escape pref 2 else pref 1 if pref 0 if pref pattern length key value new key pattern return filter index iterator value value index ascent order filter condition else if filter condition null return filter index prefix iterator pattern substring 0 pref condition return null iterableiterator applyindex filtercondition opbooland filtercondition binopnode binopnode opcontains containsnode containsnode withexpr havingexpr filtercondition withexpr binopnode binopnode binopnode getfieldname literalnode genericindex getindex opanyeq opinteq oprealeq opstreq opdateeq opbooleq keyliteral getkeytype ascent_order filtercondition opintgt oprealgt opstrgt opdategt opanygt keyliteral getkeytype ascent_order filtercondition opintge oprealge opstrge opdatege opanyge keyliteral getkeytype ascent_order filtercondition opintlt opreallt opstrlt opdatelt opanylt keyliteral getkeytype ascent_order filtercondition opintle oprealle opstrle opdatele opanyle keyliteral getkeytype ascent_order filtercondition comparenode comparenode comparenode getfieldname literalnode literalnode genericindex getindex opintbetween opstrbetween oprealbetween opdatebetween opanybetween keyliteral getkeytype keyliteral getkeytype ascent_order filtercondition opstrlike opstrlikeesc literalnode getvalue literalnode getvalue charat charat _ ascent_order filtercondition filtercondition prefixiterator final void compile pos 0 vars 0 tree check type node tp bool disjunction order node last null order null if lex tkn eof return if lex tkn order throw new compile error order by expected pos int tkn int p pos if scan tkn by throw new compile error by expected after order p do p pos if scan tkn ident throw new compile error field name expected p order node node field f class descriptor locate field cls ident if f null method m lookup method cls ident default profile if m null if cls equals object class throw new compile error no field ident in class cls get name p node new order node ident else node new order node m else node new order node class descriptor get type code f get type f if last null last next node else order node last node p pos tkn scan if tkn tkn desc node ascent false tkn scan else if tkn tkn asc tkn scan while tkn tkn comma if tkn tkn eof throw new compile error expected p checktype tpbool ordernode tkneof tknorder compileerror tknby compileerror tknident compileerror ordernode classdescriptor locatefield lookupmethod defaultprofile compileerror getname ordernode ordernode ordernode classdescriptor gettypecode gettype tkndesc tknasc tkncomma tkneof compileerror public class storage factory create new instance of the storage return new instance of the storage unopened you should explicitely invoke open method public storage create storage return new storage impl storagefactory createstorage storageimpl create new instance of the master node of replicated storage there are two kinds of replication slave nodes statically defined and dynamically added first one are specified by replication slave nodes parameter when replication master is started it tries to eastablish connection with all of the specified nodes it is expected that state of each such node is synchronized with state of the master node it is not possible to add or remove static replication slave node without stopping master node dynamic slave nodes can be added at any moment of time replication master will send to such node complete snapshot of the database param port socket port at which replication master will listen for dynamic slave nodes connections if this parameter is 1 then no dynamic slave node conenctions are accepted param replication slave nodes addresses of static replicatin slave nodes i e hosts to which replication will be performed address is specified as name port param async buf size if value of this parameter is greater than zero then replication will be asynchronous done by separate thread and not blocking main application otherwise data is send to the slave nodes by the same thread which updates the database if space asynchronous buffer is exhausted then main thread will be also blocked until the data is send return new instance of the master storage unopened you should explicitely invoke open method public replication master storage create replication master storage int port string replication slave nodes int async buf size return new replication master storage impl port replication slave nodes async buf size replicationslavenodes replicationslavenodes asyncbufsize replicationmasterstorage createreplicationmasterstorage replicationslavenodes asyncbufsize replicationmasterstorageimpl replicationslavenodes asyncbufsize create new instance of the static slave node of replicated storage the address of this host should be sepecified in the replication slave nodes parameter of create replication master storage method when replication master is started it tries to eastablish connection with all of the specified nodes param slave port socket port at which connection from master will be established return new instance of the slave storage unopened you should explicitely invoke open method public replication slave storage create replication slave storage int slave port return new replication static slave storage impl slave port replicationslavenodes createreplicationmasterstorage slaveport replicationslavestorage createreplicationslavestorage slaveport replicationstaticslavestorageimpl slaveport add new instance of the dynamic slave node of replicated storage param replication master node name of the host where replication master is running param master port replication master socket port to which connection should be established return new instance of the slave storage unopened you should explicitely invoke open method public replication slave storage add replication slave storage string replication master node int master port return new replication dynamic slave storage impl replication master node master port replicationmasternode masterport replicationslavestorage addreplicationslavestorage replicationmasternode masterport replicationdynamicslavestorageimpl replicationmasternode masterport get instance of storage factory so new storages should be create in application in the following way code storage factory get instance create storage code return instance of the storage factory public static storage factory get instance return instance storagefactory getinstance createstorage storagefactory getinstance public modify peer simple field set fs this fs fs this identifier fs get identifier fs remove value identifier modifypeer simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied modify peer requires full access identifier false string node identifier fs get node identifier if node identifier null throw new message invalid exception protocol error message missing field error node identifier field missing identifier false peer node pn node get peer node node identifier if pn null fcp message msg new unknown node identifier message node identifier identifier handler output handler queue msg return if pn instanceof darknet peer node throw new message invalid exception protocol error message darknet only modify peer only available for darknet peers identifier false darknet peer node dpn darknet peer node pn string is disabled string fs get is disabled if is disabled string null if is disabled string equals if fields string to bool is disabled string false dpn disable peer else dpn enable peer string is listen only string fs get is listen only if is listen only string null if is listen only string equals dpn set listen only fields string to bool is listen only string false string is burst only string fs get is burst only if is burst only string null if is burst only string equals dpn set burst only fields string to bool is burst only string false string ignore source port string fs get ignore source port if ignore source port string null if ignore source port string equals dpn set ignore source port fields string to bool ignore source port string false string allow local addresses string fs get allow local addresses if allow local addresses string null if allow local addresses string equals dpn set allow local addresses fields string to bool allow local addresses string false handler output handler queue new peer message pn true true identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied modifypeer nodeidentifier nodeidentifier nodeidentifier messageinvalidexception protocolerrormessage missing_field nodeidentifier peernode getpeernode nodeidentifier fcpmessage unknownnodeidentifiermessage nodeidentifier outputhandler darknetpeernode messageinvalidexception protocolerrormessage darknet_only modifypeer darknetpeernode darknetpeernode isdisabledstring isdisabled isdisabledstring isdisabledstring stringtobool isdisabledstring disablepeer enablepeer islistenonlystring islistenonly islistenonlystring islistenonlystring setlistenonly stringtobool islistenonlystring isburstonlystring isburstonly isburstonlystring isburstonlystring setburstonly stringtobool isburstonlystring ignoresourceportstring ignoresourceport ignoresourceportstring ignoresourceportstring setignoresourceport stringtobool ignoresourceportstring allowlocaladdressesstring allowlocaladdresses allowlocaladdressesstring allowlocaladdressesstring setallowlocaladdresses stringtobool allowlocaladdressesstring outputhandler peermessage override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception query node visitor it provides convenient way of iterating through query nodes public void visit full text query visitor visitor visitor visit this fulltextqueryvisitor this method checks that query can be executed by interection of keyword occurrences lists return true if quuery can be executed by full text index false otherwise public boolean is constrained return false fulltextindex isconstrained query node constructor param op operation code public full text query int op this op op fulltextquery it won t reset the message digest for you param input stream param message digest return throws io exception public static void hash input stream is message digest md throws io exception try byte buf new byte 4096 int read bytes is read buf while read bytes 1 md update buf 0 read bytes read bytes is read buf is close finally closer close is inputstream messagedigest ioexception inputstream messagedigest ioexception readbytes readbytes readbytes readbytes create a new sha 256 message digest either succeed or stop the node public synchronized static message digest get message digest try if digests is empty return digests remove digests size 1 return message digest get instance sha 256 catch no such algorithm exception e2 todo maybe we should point to a howto for freejvms logger error node class check your jvm settings especially the jce e2 system err println check your jvm settings especially the jce e2 e2 print stack trace wrapper manager stop node init exception exit crappy jvm throw new runtime exception messagedigest messagedigest getmessagedigest isempty messagedigest getinstance nosuchalgorithmexception printstacktrace wrappermanager nodeinitexception exit_crappy_jvm runtimeexception return a message digest to the pool must be sha 256 public synchronized static void return message digest message digest md256 if md256 null return string algo md256 get algorithm if algo equals sha 256 algo equals sha256 throw new illegal argument exception should be sha 256 but is algo if digests size 16 no cache don t cache too many of them return md256 reset digests add md256 messagedigest returnmessagedigest messagedigest getalgorithm illegalargumentexception nocache public static byte digest byte data message digest md get message digest byte hash md digest data return message digest md return hash messagedigest getmessagedigest returnmessagedigest public static int get digest length return hash size getdigestlength hash_size static oom handler addoom hook new oom hook public void handle low memory throws exception digests clear no cache true oomhandler addoomhook oomhook handlelowmemory nocache public void handle out of memory throws exception digests clear no cache true handleoutofmemory nocache override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog public base file bucket file file boolean delete on exit if file null throw new null pointer exception this length file length if delete on exit set delete on exit file basefilebucket deleteonexit nullpointerexception deleteonexit setdeleteonexit protected void set delete on exit file file try file delete on exit catch null pointer exception e if wrapper manager has shutdown hook been triggered logger normal this null pointer exception setting delete on exit while shutting down buggy jvm code e e else logger error this caught e doing delete on exit for file jvm bug setdeleteonexit deleteonexit nullpointerexception wrappermanager hasshutdownhookbeentriggered nullpointerexception deleteonexit deleteonexit public output stream get output stream throws io exception synchronized this file file get file if freed throw new io exception file already freed this if is read only throw new io exception bucket is read only this if create file only file exists throw new file exists exception file if streams null streams is empty logger error this streams open on this while opening an output stream streams new exception debug file tempfile create file only get tempfile file long stream number file restart counter file bucket output stream os new file bucket output stream tempfile stream number if logdebug logger debug this creating os new exception debug add stream os return os outputstream getoutputstream ioexception getfile ioexception isreadonly ioexception createfileonly fileexistsexception isempty createfileonly gettempfile streamnumber filerestartcounter filebucketoutputstream filebucketoutputstream streamnumber addstream private synchronized void add stream object stream base file bucket is a very common object and often very long lived so we need to minimize memory usage even at the cost of frequent allocations if streams null streams new vector object 1 1 streams add stream addstream basefilebucket private synchronized void remove stream object stream race condition is possible if streams null return streams remove stream if streams is empty streams null removestream isempty protected abstract boolean create file only createfileonly protected abstract boolean create file only protected abstract boolean delete on exit createfileonly deleteonexit protected abstract boolean delete on exit protected abstract boolean delete on finalize deleteonexit deleteonfinalize protected abstract boolean delete on finalize protected abstract boolean delete on free deleteonfinalize deleteonfree create a temporary file in the same directory as this file protected file get tempfile throws io exception file file get file file f file create temp file file get name freenet tmp file get parent file if delete on exit f delete on exit return f gettempfile ioexception getfile createtempfile getname getparentfile deleteonexit deleteonexit protected synchronized void reset length length 0 resetlength protected file bucket output stream file tempfile long restart count throws file not found exception super tempfile false if logminor logger minor this writing to tempfile for get file this this tempfile tempfile reset length this restart count restart count closed false filebucketoutputstream restartcount filenotfoundexception getfile resetlength restartcount restartcount protected void confirm write synchronized throws io exception synchronized base file bucket this if file restart counter restart count throw new illegal state exception writing to file after restart if freed throw new io exception writing to file after it has been freed if is read only throw new io exception file is read only confirmwritesynchronized ioexception basefilebucket filerestartcounter restartcount illegalstateexception ioexception isreadonly ioexception override public void write byte b throws io exception synchronized base file bucket this confirm write synchronized super write b length b length ioexception basefilebucket confirmwritesynchronized override public void write byte b int off int len throws io exception synchronized base file bucket this confirm write synchronized super write b off len length len ioexception basefilebucket confirmwritesynchronized override public void write int b throws io exception synchronized base file bucket this confirm write synchronized super write b length ioexception basefilebucket confirmwritesynchronized override public void close throws io exception file file synchronized this if closed return closed true file get file remove stream this if logminor logger minor this closing base file bucket this try super close catch io exception e if logminor logger minor this failed closing base file bucket this e e if create file only tempfile delete throw e if create file only if file exists if logminor logger minor this file exists creating file for this tempfile delete throw new file exists exception file if tempfile rename to file if logminor logger minor this cannot rename file for this if file exists throw new file exists exception file tempfile delete if logminor logger minor this deleted cannot rename file for this throw new io exception cannot rename file ioexception getfile removestream basefilebucket ioexception basefilebucket createfileonly createfileonly fileexistsexception renameto fileexistsexception ioexception override public string to string return super to string base file bucket this to string tostring tostring basefilebucket tostring boolean closed public file bucket input stream file f throws io exception super f filebucketinputstream ioexception override public void close throws io exception synchronized this if closed return closed true remove stream this super close ioexception removestream override public string to string return super to string base file bucket this to string tostring tostring basefilebucket tostring public synchronized input stream get input stream throws io exception if freed throw new io exception file already freed this file file get file if file exists logger normal this file does not exist file for this return new null input stream else file bucket input stream is new file bucket input stream file add stream is if logdebug logger debug this creating is new exception debug return is inputstream getinputstream ioexception ioexception getfile nullinputstream filebucketinputstream filebucketinputstream addstream return the name of the file public synchronized string get name return get file get name getname getfile getname public synchronized long size return length actually delete the underlying file called by finalizer will not be called twice but length must still be valid when calling it protected synchronized void delete file if logminor logger minor this deleting get file for this new exception debug get file delete deletefile getfile getfile override protected void finalize if delete on finalize free true deleteonfinalize return directory used for temp files public final synchronized static string get temp dir return temp dir fixme todo locking on temp dir needs to be checked by a java guru for consistency gettempdir tempdir tempdir set temp file directory p the directory must exist public final synchronized static void set temp dir string dir name file dir new file dir name if dir exists dir is directory dir can write throw new illegal argument exception bad temp directory dir get absolute path temp dir dir name fixme todo locking on temp dir needs to be checked by a java guru for consistency settempdir dirname dirname isdirectory canwrite illegalargumentexception getabsolutepath tempdir dirname tempdir public synchronized bucket split int split size if length long integer max value split size throw new illegal argument exception way too big length for split size int bucket count int length split size if length split size 0 bucket count bucket buckets new bucket bucket count file file get file for int i 0 i buckets length i long start at 1l i split size long end at math min start at split size 1l length long len end at start at buckets i new read only file slice bucket file start at len return buckets splitsize max_value splitsize illegalargumentexception splitsize bucketcount splitsize splitsize bucketcount bucketcount getfile startat splitsize endat startat splitsize endat startat readonlyfileslicebucket startat public void free free false public void free boolean force free object to close if logminor logger minor this freeing this new exception debug synchronized this if freed return freed true to close streams null null streams to array streams null if to close null logger error this streams open free ing this arrays to string to close new exception debug for int i 0 i to close length i try if to close i instanceof file bucket output stream file bucket output stream to close i close else file bucket input stream to close i close catch io exception e logger error this caught closing stream in free e e catch throwable t logger error this caught closing stream in free t t file file get file if delete on free force free file exists logger debug this deleting bucket file get name new exception debug delete file if file exists logger error this delete failed on bucket file get name forcefree toclose toclose toarray toclose tostring toclose toclose toclose filebucketoutputstream filebucketoutputstream toclose filebucketinputstream toclose ioexception getfile deleteonfree forcefree getname deletefile getname override public synchronized string to string string buffer sb new string buffer sb append super to string sb append sb append get file get path sb append streams sb append streams null 0 streams size return sb to string tostring stringbuffer stringbuffer tostring getfile getpath tostring returns the file object this buckets data is kept in public abstract file get file getfile public synchronized simple field set to field set if delete on finalize return null simple field set fs new simple field set false fs put single type file bucket fs put single filename get file to string fs put length size return fs simplefieldset tofieldset deleteonfinalize simplefieldset simplefieldset putsingle filebucket putsingle getfile tostring public static bucket create simple field set fs persistent file tracker f throws cannot create from field set exception string tmp fs get filename if tmp null throw new cannot create from field set exception no filename file file file util get canonical file new file tmp if f matches file return persistent temp file bucket create fs f tmp fs get length if tmp null throw new cannot create from field set exception no length try long length fields parse long tmp 1 if length file length throw new cannot create from field set exception invalid length should be length actually file length on file catch number format exception e throw new cannot create from field set exception corrupt length tmp e file bucket bucket new file bucket file false true false false false if file exists no point otherwise f register file return bucket simplefieldset persistentfiletracker cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception fileutil getcanonicalfile persistenttempfilebucket cannotcreatefromfieldsetexception parselong cannotcreatefromfieldsetexception numberformatexception cannotcreatefromfieldsetexception filebucket filebucket archive store context freeneturi key archive manager archive type archive type this key key this archive type archive type my items new doubly linked list impl archive store item archivestorecontext archivemanager archive_type archivetype archivetype archivetype myitems doublylinkedlistimpl archivestoreitem returns the size of the archive last time we fetched it or 1 long get last size return last size getlastsize lastsize sets the size of the archive see get last size void set last size long size last size size getlastsize setlastsize lastsize returns the hash of the archive last time we fetched it or null byte get last hash return last hash getlasthash lasthash sets the hash of the archive see get last hash void set last hash byte real hash last hash real hash getlasthash setlasthash realhash lasthash realhash remove all archive store items with this key from the cache void remove all cached items archive manager manager archive store item item null while true synchronized my items remove cached item will call remove item so don t remove it here item my items head if item null break manager remove cached item item archivestoreitems removeallcacheditems archivemanager archivestoreitem myitems removecacheditem removeitem myitems removecacheditem notify that a new archive store item with this key has been added to the cache void add item archive store item item synchronized my items my items push item additem archivestoreitem myitems myitems notify that an archive store item with this key has been expelled from the cache remove it from our local cache and ask it to free the bucket if necessary void remove item archive store item item synchronized my items if my items remove item null if logger should log logger minor this logger minor this not removing item for this already removed return only removed once item inner close removeitem archivestoreitem myitems myitems shouldlog innerclose public short get archive type return archive type metadataid getarchivetype archivetype public freeneturi get key return key getkey client request scheduler non persistent client request scheduler sched boolean for inserts boolean forss ks super for inserts forss ks this sched sched if for inserts recent successes new linked list base sendable get else recent successes null logminor logger should log logger minor this clientrequestschedulernonpersistent clientrequestscheduler forinserts forssks forinserts forssks forinserts recentsuccesses linkedlist basesendableget recentsuccesses shouldlog override boolean persistent return false object container container return null objectcontainer override public void succeeded base sendable get succeeded object container container do nothing fixme keep a list of recently succeeded client requester s if is insert scheduler return if persistent container activate succeeded 1 if succeeded is empty container return if logminor logger minor this recording successful fetch from succeeded recent successes add succeeded while recent successes size 8 recent successes remove 0 basesendableget objectcontainer clientrequester isinsertscheduler isempty recentsuccesses recentsuccesses recentsuccesses public boolean object can new object container container logger error this not storing client request scheduler non persistent in database new exception error return false objectcannew objectcontainer clientrequestschedulernonpersistent private static string ipv6 address public static final void seti pv6 address string addr ipv6 address addr ipv6_address setipv6address ipv6_address public static final string geti pv6 address return ipv6 address getipv6address ipv6_address public final static int get lease time string cache cont int equ idx cache cont index of int mx 0 try string mx str new string cache cont get bytes equ idx 1 cache cont length equ idx 1 mx integer parse int mx str catch exception e return mx getleasetime cachecont equidx cachecont indexof mxstr cachecont getbytes equidx cachecont equidx parseint mxstr public static boolean enabled false public static final void on enabled true enabled true public static final void off enabled false enabled false public static boolean is on return enabled ison return enabled public static final void message string s if enabled true system out println cyber garage message s cybergarage public static final void message string m1 string m2 if enabled true system out println cyber garage message system out println m1 system out println m2 cybergarage system out println m2 public static final void warning string s system out println cyber garage warning s cybergarage system out println cyber garage warning s public static final void warning string m exception e system out println cyber garage warning m e get message cybergarage cybergarage getmessage system out println cyber garage warning m e get message public static final void warning exception e warning e get message e print stack trace cybergarage getmessage getmessage printstacktrace static final int sizeof object header sizeof 4 4 1 btree objectheader static int check type class c int elem type class descriptor get type code c if elem type class descriptor tp object elem type class descriptor tp enum elem type class descriptor tp array of byte throw new storage error storage error unsupported index type c return elem type checktype elemtype classdescriptor gettypecode elemtype classdescriptor tpobject elemtype classdescriptor tpenum elemtype classdescriptor tparrayofbyte storageerror storageerror unsupported_index_type elemtype int compare byte arrays byte key byte item int offs int length int n key length length length key length for int i 0 i n i int diff key i item i offs if diff 0 return diff return key length length comparebytearrays btree class cls boolean unique this unique unique type check type cls checktype btree int type boolean unique this type type this unique unique btree byte obj int offs height bytes unpack4 obj offs offs 4 n elems bytes unpack4 obj offs offs 4 root bytes unpack4 obj offs offs 4 type bytes unpack4 obj offs offs 4 unique obj offs 0 nelems static final int op overwrite 5 public class get key types return new class get key type op_overwrite getkeytypes getkeytype public class get key type return map key type type getkeytype mapkeytype static class map key type int type switch type case class descriptor tp boolean return boolean class case class descriptor tp byte return byte class case class descriptor tp char return char class case class descriptor tp short return short class case class descriptor tp int return int class case class descriptor tp long return long class case class descriptor tp float return float class case class descriptor tp double return double class case class descriptor tp enum return enum class case class descriptor tp string return string class case class descriptor tp date return date class case class descriptor tp object return i persistent class case class descriptor tp array of byte return byte class default return comparable class mapkeytype classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpenum classdescriptor tpstring classdescriptor tpdate classdescriptor tpobject ipersistent classdescriptor tparrayofbyte key check key key key if key null if key type type throw new storage error storage error incompatible key type if type class descriptor tp object key ival 0 key oval null i persistent obj i persistent key oval get storage make persistent obj key new key obj key inclusion 0 if key oval instanceof string key new key string key oval to char array key inclusion 0 return key checkkey storageerror storageerror incompatible_key_type classdescriptor tpobject ipersistent ipersistent getstorage makepersistent tochararray public t get key key key check key key if root 0 array list list new array list btree page find storage impl get storage root key key this height list if list size 1 throw new storage error storage error key not unique else if list size 0 return null else return t list get 0 return null checkkey arraylist arraylist btreepage storageimpl getstorage storageerror storageerror key_not_unique public array list t prefix search list string key if class descriptor tp string type throw new storage error storage error incompatible key type array list t list new array list t if root 0 btree page prefix search storage impl get storage root key to char array height list return list arraylist prefixsearchlist classdescriptor tpstring storageerror storageerror incompatible_key_type arraylist arraylist btreepage prefixsearch storageimpl getstorage tochararray public i persistent prefix search string key array list t list prefix search list key return i persistent list to array new i persistent list size ipersistent prefixsearch arraylist prefixsearchlist ipersistent toarray ipersistent public array list t get list key from key till array list t list new array list t if root 0 btree page find storage impl get storage root check key from check key till this height list return list arraylist getlist arraylist arraylist btreepage storageimpl getstorage checkkey checkkey public array list t get list object from object till return get list get key from object from get key from object till arraylist getlist getlist getkeyfromobject getkeyfromobject public t get object key return get get key from object key getkeyfromobject public i persistent get key from key till array list t list get list from till return i persistent list to array new i persistent list size ipersistent arraylist getlist ipersistent toarray ipersistent public i persistent get object from object till return get get key from object from get key from object till ipersistent getkeyfromobject getkeyfromobject public boolean put key key t obj return insert key obj false 0 public t set key key t obj int oid insert key obj true return t oid 0 storage impl get storage lookup object oid null null storageimpl getstorage lookupobject final int insert key key t obj boolean overwrite storage impl db storage impl get storage if db null throw new storage error storage error deleted object key check key key if obj is persistent db make persistent obj btree key ins new btree key key obj get oid if root 0 root btree page allocate db 0 type ins height 1 else int result btree page insert db root this ins height unique overwrite if result op overflow root btree page allocate db root type ins height 1 else if result op duplicate return 1 else if result op overwrite return ins old oid update counter 1 n elems 1 modify return 0 storageimpl storageimpl getstorage storageerror storageerror deleted_object checkkey ispersistent makepersistent btreekey btreekey getoid btreepage btreepage op_overflow btreepage op_duplicate op_overwrite oldoid updatecounter nelems public void remove key key t obj remove new btree key check key key obj get oid btreekey checkkey getoid void remove btree key rem if remove if exists rem throw new storage error storage error key not found btreekey removeifexists storageerror storageerror key_not_found boolean remove if exists btree key rem storage impl db storage impl get storage if db null throw new storage error storage error deleted object if root 0 return false int result btree page remove db root this rem height if result op not found return false n elems 1 if result op underflow page pg db get page root if btree page getn items pg 0 int new root 0 if height 1 new root type class descriptor tp string type class descriptor tp array of byte btree page get key str oid pg 0 btree page get reference pg btree page max items 1 db free page root root new root height 1 db pool unfix pg else if result op overflow root btree page allocate db root type rem height 1 update counter 1 modify return true removeifexists btreekey storageimpl storageimpl getstorage storageerror storageerror deleted_object btreepage op_not_found nelems op_underflow getpage btreepage getnitems newroot newroot classdescriptor tpstring classdescriptor tparrayofbyte btreepage getkeystroid btreepage getreference btreepage maxitems freepage newroot op_overflow btreepage updatecounter public t remove key key if unique throw new storage error storage error key not unique btree key rk new btree key check key key 0 storage impl db storage impl get storage remove rk return t db lookup object rk old oid null storageerror storageerror key_not_unique btreekey btreekey checkkey storageimpl storageimpl getstorage lookupobject oldoid static key get key from object object o if o null return null else if o instanceof byte return new key byte o byte value else if o instanceof short return new key short o short value else if o instanceof integer return new key integer o int value else if o instanceof long return new key long o long value else if o instanceof float return new key float o float value else if o instanceof double return new key double o double value else if o instanceof boolean return new key boolean o boolean value else if o instanceof character return new key character o char value else if o instanceof string return new key string o else if o instanceof java util date return new key java util date o else if o instanceof byte return new key byte o else if o instanceof object return new key object o else if o instanceof enum return new key enum o else if o instanceof i persistent return new key i persistent o else if o instanceof comparable return new key comparable o throw new storage error storage error unsupported type getkeyfromobject bytevalue shortvalue intvalue longvalue floatvalue doublevalue booleanvalue charvalue ipersistent ipersistent storageerror storageerror unsupported_type public array list t get prefix list string prefix return get list new key prefix to char array true new key prefix character max value to char array false arraylist getprefixlist getlist tochararray max_value tochararray public i persistent get prefix string prefix return get new key prefix to char array true new key prefix character max value to char array false ipersistent getprefix tochararray max_value tochararray public boolean put object key t obj return put get key from object key obj getkeyfromobject public t set object key t obj return set get key from object key obj getkeyfromobject public void remove object key t obj remove get key from object key obj getkeyfromobject public t remove key object key return remove get key from object key removekey getkeyfromobject public t remove string key return remove new key key public int size return n elems nelems public void clear if root 0 btree page purge storage impl get storage root type height root 0 n elems 0 height 0 update counter 1 modify btreepage storageimpl getstorage nelems updatecounter public i persistent to persistent array i persistent arr new i persistent n elems if root 0 btree page traverse forward storage impl get storage root type height arr 0 return arr ipersistent topersistentarray ipersistent ipersistent nelems btreepage traverseforward storageimpl getstorage public object to array return to persistent array toarray topersistentarray public e e to array e arr if arr length n elems arr e array new instance arr get class get component type n elems if root 0 btree page traverse forward storage impl get storage root type height i persistent arr 0 if arr length n elems arr n elems null return arr toarray nelems newinstance getclass getcomponenttype nelems btreepage traverseforward storageimpl getstorage ipersistent nelems nelems public void deallocate if root 0 btree page purge storage impl get storage root type height super deallocate btreepage storageimpl getstorage public int mark tree if root 0 return btree page mark page storage impl get storage root type height return 0 marktree btreepage markpage storageimpl getstorage protected object unpack enum int val base b tree class has no information about particular enum type so it is not able to correctly unpack enum key return object val unpackenum public void export xml exporter exporter throws java io io exception if root 0 btree page export page storage impl get storage exporter root type height xmlexporter ioexception btreepage exportpage storageimpl getstorage static class btree entry t implements map entry object t public object get key return key btreeentry getkey public t get value return t db lookup object oid null getvalue lookupobject public t set value t value throw new unsupported operation exception setvalue unsupportedoperationexception public boolean equals object o if o instanceof map entry return false map entry e map entry o return get key null e get key null get key equals e get key get value null e get value null get value equals e get value getkey getkey getkey getkey getvalue getvalue getvalue getvalue public int hash code return get key null 0 get key hash code get value null 0 get value hash code hashcode getkey getkey hashcode getvalue getvalue hashcode public string to string return get key get value tostring getkey getvalue btree entry storage impl db object key int oid this db db this key key this oid oid btreeentry storageimpl object unpack key storage impl db page pg int pos byte data pg data int offs btree page first key offs pos class descriptor sizeof type switch type case class descriptor tp boolean return boolean value of data offs 0 case class descriptor tp byte return new byte data offs case class descriptor tp short return short value of bytes unpack2 data offs case class descriptor tp char return new character char bytes unpack2 data offs case class descriptor tp int return new integer bytes unpack4 data offs case class descriptor tp object return db lookup object bytes unpack4 data offs null case class descriptor tp long return new long bytes unpack8 data offs case class descriptor tp date return new date bytes unpack8 data offs case class descriptor tp float return new float float int bits to float bytes unpack4 data offs case class descriptor tp double return new double double long bits to double bytes unpack8 data offs case class descriptor tp enum return unpack enum bytes unpack4 data offs case class descriptor tp string return unpack str key pg pos case class descriptor tp array of byte return unpack byte array key pg pos default assert failed invalid type return null unpackkey storageimpl btreepage firstkeyoffs classdescriptor classdescriptor tpboolean valueof classdescriptor tpbyte classdescriptor tpshort valueof classdescriptor tpchar classdescriptor tpint classdescriptor tpobject lookupobject classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat classdescriptor tpdouble longbitstodouble classdescriptor tpenum unpackenum classdescriptor tpstring unpackstrkey classdescriptor tparrayofbyte unpackbytearraykey static string unpack str key page pg int pos int len btree page get key str size pg pos int offs btree page first key offs btree page get key str offs pg pos byte data pg data char sval new char len for int j 0 j len j sval j char bytes unpack2 data offs offs 2 return new string sval unpackstrkey btreepage getkeystrsize btreepage firstkeyoffs btreepage getkeystroffs object unpack byte array key page pg int pos int len btree page get key str size pg pos int offs btree page first key offs btree page get key str offs pg pos byte val new byte len system arraycopy pg data offs val 0 len return val unpackbytearraykey btreepage getkeystrsize btreepage firstkeyoffs btreepage getkeystroffs public iterator t iterator return iterator null null ascent order ascent_order public iterable iterator map entry object t entry iterator return entry iterator null null ascent order iterableiterator entryiterator entryiterator ascent_order final int compare byte arrays key key page pg int i return compare byte arrays byte key oval pg data btree page get key str offs pg i btree page first key offs btree page get key str size pg i comparebytearrays comparebytearrays btreepage getkeystroffs btreepage firstkeyoffs btreepage getkeystrsize class btree selection iterator e extends iterable iterator e implements persistent iterator btree selection iterator key from key till int order this from from this till till this order order reset btreeselectioniterator iterableiterator persistentiterator btreeselectioniterator void reset int i l r sp 0 counter update counter if height 0 return int page id root storage impl db storage impl get storage if db null throw new storage error storage error deleted object int h height page stack new int h pos stack new int h if type class descriptor tp string if order ascent order if from null while h 0 pos stack sp 0 page stack sp page id page pg db get page page id page id btree page get key str oid pg 0 end btree page getn items pg db pool unfix pg sp 1 else while h 0 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if btree page compare str from pg i from inclusion l i 1 else r i assert that r l pos stack sp r page id btree page get key str oid pg r db pool unfix pg sp 1 page stack sp page id page pg db get page page id l 0 end r btree page getn items pg while l r i l r 1 if btree page compare str from pg i from inclusion l i 1 else r i assert that r l if r end sp 1 goto next item pg r 1 else pos stack sp r db pool unfix pg if sp 0 till null page pg db get page page stack sp 1 if btree page compare str till pg pos stack sp 1 till inclusion sp 0 db pool unfix pg else descent order if till null while h 0 page stack sp page id page pg db get page page id pos stack sp btree page getn items pg page id btree page get key str oid pg pos stack sp db pool unfix pg sp 1 page stack sp page id page pg db get page page id pos stack sp btree page getn items pg 1 db pool unfix pg else while h 0 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if btree page compare str till pg i 1 till inclusion l i 1 else r i assert that r l pos stack sp r page id btree page get key str oid pg r db pool unfix pg sp 1 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if btree page compare str till pg i 1 till inclusion l i 1 else r i assert that r l if r 0 sp 1 goto next item pg r else pos stack sp r 1 db pool unfix pg if sp 0 from null page pg db get page page stack sp 1 if btree page compare str from pg pos stack sp 1 from inclusion sp 0 db pool unfix pg else if type class descriptor tp array of byte if order ascent order if from null while h 0 pos stack sp 0 page stack sp page id page pg db get page page id page id btree page get key str oid pg 0 end btree page getn items pg db pool unfix pg sp 1 else while h 0 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if compare byte arrays from pg i from inclusion l i 1 else r i assert that r l pos stack sp r page id btree page get key str oid pg r db pool unfix pg sp 1 page stack sp page id page pg db get page page id l 0 end r btree page getn items pg while l r i l r 1 if compare byte arrays from pg i from inclusion l i 1 else r i assert that r l if r end sp 1 goto next item pg r 1 else pos stack sp r db pool unfix pg if sp 0 till null page pg db get page page stack sp 1 if compare byte arrays till pg pos stack sp 1 till inclusion sp 0 db pool unfix pg else descent order if till null while h 0 page stack sp page id page pg db get page page id pos stack sp btree page getn items pg page id btree page get key str oid pg pos stack sp db pool unfix pg sp 1 page stack sp page id page pg db get page page id pos stack sp btree page getn items pg 1 db pool unfix pg else while h 0 page stack sp page id page pg db get page page id l 0 r btree page getn items pg while l r i l r 1 if updatecounter pageid storageimpl storageimpl getstorage storageerror storageerror deleted_object pagestack posstack classdescriptor tpstring ascent_order posstack pagestack pageid getpage pageid pageid btreepage getkeystroid btreepage getnitems pagestack pageid getpage pageid btreepage getnitems btreepage comparestr posstack pageid btreepage getkeystroid pagestack pageid getpage pageid btreepage getnitems btreepage comparestr gotonextitem posstack getpage pagestack btreepage comparestr posstack pagestack pageid getpage pageid posstack btreepage getnitems pageid btreepage getkeystroid posstack pagestack pageid getpage pageid posstack btreepage getnitems pagestack pageid getpage pageid btreepage getnitems btreepage comparestr posstack pageid btreepage getkeystroid pagestack pageid getpage pageid btreepage getnitems btreepage comparestr gotonextitem posstack getpage pagestack btreepage comparestr posstack classdescriptor tparrayofbyte ascent_order posstack pagestack pageid getpage pageid pageid btreepage getkeystroid btreepage getnitems pagestack pageid getpage pageid btreepage getnitems comparebytearrays posstack pageid btreepage getkeystroid pagestack pageid getpage pageid btreepage getnitems comparebytearrays gotonextitem posstack getpage pagestack comparebytearrays posstack pagestack pageid getpage pageid posstack btreepage getnitems pageid btreepage getkeystroid posstack pagestack pageid getpage pageid posstack btreepage getnitems pagestack pageid getpage pageid btreepage getnitems public boolean has next if counter update counter if storage impl get storage concurrent iterator refresh else throw new concurrent modification exception return sp 0 hasnext updatecounter storageimpl getstorage concurrentiterator concurrentmodificationexception public e next if has next throw new no such element exception storage impl db storage impl get storage int pos pos stack sp 1 curr pos pos curr page page stack sp 1 page pg db get page curr page e curr e get current pg pos if db concurrent iterator curr key get current key pg pos goto next item pg pos return curr hasnext nosuchelementexception storageimpl storageimpl getstorage posstack currpos currpage pagestack getpage currpage getcurrent concurrentiterator currkey getcurrentkey gotonextitem public int next oid if has next throw new no such element exception storage impl db storage impl get storage int pos pos stack sp 1 curr pos pos curr page page stack sp 1 page pg db get page curr page int oid get reference pg pos if db concurrent iterator curr key get current key pg pos goto next item pg pos return oid nextoid hasnext nosuchelementexception storageimpl storageimpl getstorage posstack currpos currpage pagestack getpage currpage getreference concurrentiterator currkey getcurrentkey gotonextitem private int get reference page pg int pos return type class descriptor tp string type class descriptor tp array of byte btree page get key str oid pg pos btree page get reference pg btree page max items 1 pos getreference classdescriptor tpstring classdescriptor tparrayofbyte btreepage getkeystroid btreepage getreference btreepage maxitems protected object get current page pg int pos storage impl db storage impl get storage return db lookup object get reference pg pos null getcurrent storageimpl storageimpl getstorage lookupobject getreference protected final void goto next item page pg int pos storage impl db storage impl get storage if type class descriptor tp string if order ascent order if pos end while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos btree page getn items pg pos stack sp 1 pos do int page id btree page get key str oid pg pos db pool unfix pg pg db get page page id end btree page getn items pg page stack sp page id pos stack sp pos 0 while sp page stack length break else pos stack sp 1 pos if sp 0 till null btree page compare str till pg pos till inclusion sp 0 else descent order if pos 0 while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos 0 pos stack sp 1 pos do int page id btree page get key str oid pg pos db pool unfix pg pg db get page page id page stack sp page id pos stack sp pos btree page getn items pg while sp page stack length pos stack sp 1 pos break else pos stack sp 1 pos if sp 0 from null btree page compare str from pg pos from inclusion sp 0 else if type class descriptor tp array of byte if order ascent order if pos end while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos btree page getn items pg pos stack sp 1 pos do int page id btree page get key str oid pg pos db pool unfix pg pg db get page page id end btree page getn items pg page stack sp page id pos stack sp pos 0 while sp page stack length break else pos stack sp 1 pos if sp 0 till null compare byte arrays till pg pos till inclusion sp 0 else descent order if pos 0 while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos 0 pos stack sp 1 pos do int page id btree page get key str oid pg pos db pool unfix pg pg db get page page id page stack sp page id pos stack sp pos btree page getn items pg while sp page stack length pos stack sp 1 pos break else pos stack sp 1 pos if sp 0 from null compare byte arrays from pg pos from inclusion sp 0 else scalar type if order ascent order if pos end while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos btree page getn items pg pos stack sp 1 pos do int page id btree page get reference pg btree page max items 1 pos db pool unfix pg pg db get page page id end btree page getn items pg page stack sp page id pos stack sp pos 0 while sp page stack length break else pos stack sp 1 pos if sp 0 till null btree page compare till pg pos till inclusion sp 0 else descent order if pos 0 while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos 0 pos stack sp 1 pos do int page id btree page get reference pg btree page max items 1 pos db pool unfix pg pg db get page page id page stack sp page id pos stack sp pos btree page getn items pg while sp page stack length pos stack sp 1 pos break else pos stack sp 1 pos if sp 0 from null btree page compare from pg pos from inclusion sp 0 if db concurrent iterator sp 0 next key get current key pg pos db pool unfix pg gotonextitem storageimpl storageimpl getstorage classdescriptor tpstring ascent_order posstack getpage pagestack btreepage getnitems posstack pageid btreepage getkeystroid getpage pageid btreepage getnitems pagestack pageid posstack pagestack posstack btreepage comparestr posstack getpage pagestack posstack pageid btreepage getkeystroid getpage pageid pagestack pageid posstack btreepage getnitems pagestack posstack posstack btreepage comparestr classdescriptor tparrayofbyte ascent_order posstack getpage pagestack btreepage getnitems posstack pageid btreepage getkeystroid getpage pageid btreepage getnitems pagestack pageid posstack pagestack posstack comparebytearrays posstack getpage pagestack posstack pageid btreepage getkeystroid getpage pageid pagestack pageid posstack btreepage getnitems pagestack posstack posstack comparebytearrays ascent_order posstack getpage pagestack btreepage getnitems posstack pageid btreepage getreference btreepage maxitems getpage pageid btreepage getnitems pagestack pageid posstack pagestack posstack btreepage posstack getpage pagestack posstack pageid btreepage getreference btreepage maxitems getpage pageid pagestack pageid posstack btreepage getnitems pagestack posstack posstack btreepage concurrentiterator nextkey getcurrentkey private void refresh if sp 0 if next key null reset else if order ascent order from next key key else till next key key int next next key oid reset storage impl db storage impl get storage while true int pos pos stack sp 1 page pg db get page page stack sp 1 int oid type class descriptor tp string type class descriptor tp array of byte btree page get key str oid pg pos btree page get reference pg btree page max items 1 pos if oid next goto next item pg pos else db pool unfix pg break counter update counter nextkey ascent_order nextkey nextkey nextkey storageimpl storageimpl getstorage posstack getpage pagestack classdescriptor tpstring classdescriptor tparrayofbyte btreepage getkeystroid btreepage getreference btreepage maxitems gotonextitem updatecounter btree key get current key page pg int pos btree key key switch type case class descriptor tp string key new btree key null btree page get key str oid pg pos key get str pg pos break case class descriptor tp array of byte key new btree key null btree page get key str oid pg pos key get byte array pg pos break default key new btree key null btree page get reference pg btree page max items 1 pos key extract pg btree page first key offs pos class descriptor sizeof type type return key btreekey getcurrentkey btreekey classdescriptor tpstring btreekey btreepage getkeystroid getstr classdescriptor tparrayofbyte btreekey btreepage getkeystroid getbytearray btreekey btreepage getreference btreepage maxitems btreepage firstkeyoffs classdescriptor public void remove if curr page 0 throw new no such element exception storage impl db storage impl get storage if db concurrent iterator if counter update counter throw new concurrent modification exception page pg db get page curr page curr key get current key pg curr pos db pool unfix pg if sp 0 int pos pos stack sp 1 pg db get page page stack sp 1 next key get current key pg pos db pool unfix pg system out println deleted key deleted key key ival next key next key key ival btree this remove if exists curr key refresh curr page 0 currpage nosuchelementexception storageimpl storageimpl getstorage concurrentiterator updatecounter concurrentmodificationexception getpage currpage currkey getcurrentkey currpos posstack getpage pagestack nextkey getcurrentkey deletedkey nextkey removeifexists currkey currpage class btree selection entry iterator extends btree selection iterator map entry object t btree selection entry iterator key from key till int order super from till order btreeselectionentryiterator btreeselectioniterator btreeselectionentryiterator protected object get current page pg int pos storage impl db storage impl get storage switch type case class descriptor tp string return new btree entry t db unpack str key pg pos btree page get key str oid pg pos case class descriptor tp array of byte return new btree entry t db unpack byte array key pg pos btree page get key str oid pg pos default return new btree entry t db unpack key db pg pos btree page get reference pg btree page max items 1 pos getcurrent storageimpl storageimpl getstorage classdescriptor tpstring btreeentry unpackstrkey btreepage getkeystroid classdescriptor tparrayofbyte btreeentry unpackbytearraykey btreepage getkeystroid btreeentry unpackkey btreepage getreference btreepage maxitems btree entry start from iterator int start int order super null null order this start start reset btreeentrystartfromiterator void reset super reset int skip order ascent order start n elems start 1 while skip 0 has next next ascent_order nelems hasnext public iterable iterator t iterator key from key till int order return new btree selection iterator t check key from check key till order iterableiterator btreeselectioniterator checkkey checkkey public iterable iterator t prefix iterator string prefix return iterator new key prefix to char array new key prefix character max value to char array false ascent order iterableiterator prefixiterator tochararray max_value tochararray ascent_order public iterable iterator map entry object t entry iterator key from key till int order return new btree selection entry iterator check key from check key till order iterableiterator entryiterator btreeselectionentryiterator checkkey checkkey public iterable iterator t iterator object from object till int order return new btree selection iterator t check key get key from object from check key get key from object till order iterableiterator btreeselectioniterator checkkey getkeyfromobject checkkey getkeyfromobject public iterable iterator map entry object t entry iterator object from object till int order return new btree selection entry iterator check key get key from object from check key get key from object till order iterableiterator entryiterator btreeselectionentryiterator checkkey getkeyfromobject checkkey getkeyfromobject public t get at int i iterable iterator map entry object t iterator if i 0 i n elems throw new index out of bounds exception position i index size n elems if i n elems 2 iterator entry iterator null null ascent order while i 0 iterator next else iterator entry iterator null null descent order i n elems while i 0 iterator next return iterator next get value getat iterableiterator nelems indexoutofboundsexception nelems nelems entryiterator ascent_order entryiterator descent_order nelems getvalue public iterable iterator map entry object t entry iterator int start int order return new btree entry start from iterator start order iterableiterator entryiterator btreeentrystartfromiterator public boolean is unique return unique isunique public put failed message insert exception e string identifier boolean global this code e get mode this code description insert exception get message code this short code description insert exception get short message code this extra description e extra this tracker e error codes this expecteduri e uri this identifier identifier this global global this is fatal insert exception is fatal code putfailedmessage insertexception getmode codedescription insertexception getmessage shortcodedescription insertexception getshortmessage extradescription errorcodes isfatal insertexception isfatal construct from a fieldset used in serialization of persistent requests will need to be made more tolerant of syntax errors if is used in an fcp client library fixme param use verbose fields if true read in verbose fields code description etc if false reconstruct them from the error code throws malformedurl exception public put failed message simple field set fs boolean use verbose fields throws malformedurl exception identifier fs get identifier if identifier null throw new null pointer exception global fs get boolean global false code integer parse int fs get code if use verbose fields code description fs get code description is fatal fields string to bool fs get fatal false short code description fs get short code description else code description insert exception get message code is fatal insert exception is fatal code short code description insert exception get short message code extra description fs get extra description string euri fs get expecteduri if euri null euri length 0 expecteduri new freeneturi euri else expecteduri null simple field set tracker subset fs subset errors if tracker subset null tracker new failure code tracker true tracker subset else tracker null useverbosefields codedescription malformedurlexception putfailedmessage simplefieldset useverbosefields malformedurlexception nullpointerexception getboolean parseint useverbosefields codedescription codedescription isfatal stringtobool shortcodedescription shortcodedescription codedescription insertexception getmessage isfatal insertexception isfatal shortcodedescription insertexception getshortmessage extradescription extradescription simplefieldset trackersubset trackersubset failurecodetracker trackersubset override public simple field set get field set return get field set true simplefieldset getfieldset getfieldset public simple field set get field set boolean verbose simple field set fs new simple field set true fs put single identifier identifier if global fs put single global true fs put code code if verbose fs put single code description code description if extra description null fs put single extra description extra description if tracker null fs tput errors tracker to field set verbose if verbose fs put fatal is fatal if verbose fs put single short code description short code description if expecteduri null fs put single expecteduri expecteduri to string return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle putsingle codedescription codedescription extradescription putsingle extradescription extradescription tofieldset isfatal putsingle shortcodedescription shortcodedescription putsingle tostring override public string get name return put failed getname putfailed override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message put failed goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message putfailed override public void remove from object container container container activate this 5 everything if tracker null tracker remove from container if expecteduri null expecteduri remove from container container delete this removefrom objectcontainer removefrom removefrom simple single file fetcher client key key int max retries fetch context ctx client requester parent get completion callback rcb boolean is essential boolean dont add long l object container container client context context boolean delete fetch context super key max retries ctx parent delete fetch context this rcb rcb this token l if dont add parent add block container if is essential parent add must succeed blocks 1 container parent notify clients container context simplesinglefilefetcher clientkey maxretries fetchcontext clientrequester getcompletioncallback isessential dontadd objectcontainer clientcontext deletefetchcontext maxretries deletefetchcontext dontadd addblock isessential addmustsucceedblocks notifyclients translate it then call the real on failure override public void on failure low level get exception e object req token ignored object container container client context context switch e code case low level get exception data not found on failure new fetch exception fetch exception data not found false container context return case low level get exception data not found in store on failure new fetch exception fetch exception data not found false container context return case low level get exception recently failed on failure new fetch exception fetch exception recently failed false container context return case low level get exception decode failed on failure new fetch exception fetch exception block decode error false container context return case low level get exception internal error on failure new fetch exception fetch exception internal error false container context return case low level get exception rejected overload on failure new fetch exception fetch exception rejected overload false container context return case low level get exception route not found on failure new fetch exception fetch exception route not found false container context return case low level get exception transfer failed on failure new fetch exception fetch exception transfer failed false container context return case low level get exception verify failed on failure new fetch exception fetch exception block decode error false container context return case low level get exception cancelled on failure new fetch exception fetch exception cancelled false container context return default logger error this unknown low level get exception code e code on failure new fetch exception fetch exception internal error false container context return onfailure onfailure lowlevelgetexception reqtokenignored objectcontainer clientcontext lowlevelgetexception data_not_found onfailure fetchexception fetchexception data_not_found lowlevelgetexception data_not_found_in_store onfailure fetchexception fetchexception data_not_found lowlevelgetexception recently_failed onfailure fetchexception fetchexception recently_failed lowlevelgetexception decode_failed onfailure fetchexception fetchexception block_decode_error lowlevelgetexception internal_error onfailure fetchexception fetchexception internal_error lowlevelgetexception rejected_overload onfailure fetchexception fetchexception rejected_overload lowlevelgetexception route_not_found onfailure fetchexception fetchexception route_not_found lowlevelgetexception transfer_failed onfailure fetchexception fetchexception transfer_failed lowlevelgetexception verify_failed onfailure fetchexception fetchexception block_decode_error lowlevelgetexception onfailure fetchexception fetchexception lowlevelgetexception onfailure fetchexception fetchexception internal_error real on failure protected void on failure fetch exception e boolean force fatal object container container client context context if persistent container activate parent 1 container activate rcb 1 boolean logminor logger should log logger minor this if logminor logger minor this on failure e force fatal e if parent is cancelled cancelled if logminor logger minor this failing cancelled e new fetch exception fetch exception cancelled force fatal true if e is fatal force fatal if retry container context if logminor logger minor this retrying return unregister all container context synchronized this finished true if persistent container store this if e is fatal force fatal parent fatally failed block container context else parent failed block container context rcb on failure e this container context onfailure onfailure fetchexception forcefatal objectcontainer clientcontext shouldlog onfailure forcefatal iscancelled fetchexception fetchexception forcefatal isfatal forcefatal unregisterall isfatal forcefatal fatallyfailedblock failedblock onfailure will be overridden by single file fetcher protected void on success fetch result data object container container client context context if persistent container activate parent 1 container activate rcb 1 if parent is cancelled data as bucket free if persistent data as bucket remove from container on failure new fetch exception fetch exception cancelled false container context return rcb on success data this container context singlefilefetcher onsuccess fetchresult objectcontainer clientcontext iscancelled asbucket asbucket removefrom onfailure fetchexception fetchexception onsuccess override public void on success client key block block boolean from store object req token ignored object container container client context context if persistent container activate parent 1 if parent instanceof client getter client getter parent add key to binary blob block container context bucket data extract block container context if data null return failed if block is metadata if key instanceof clientssk try freeneturi uri this key geturi if uri isssk uri isssk forusk uri uri usk forssk usk u usk create uri context usk manager update known good u uri get suggested edition context catch malformedurl exception e logger error this caught e e catch throwable t don t let the usk hint cause us to not succeed on the block logger error this caught t t on success new fetch result client metadata null data container context else on failure new fetch exception fetch exception invalid metadata metadata where expected data false container context onsuccess clientkeyblock fromstore reqtokenignored objectcontainer clientcontext clientgetter clientgetter addkeytobinaryblob ismetadata issskforusk uskforssk uskmanager updateknowngood getsuggestededition malformedurlexception onsuccess fetchresult clientmetadata onfailure fetchexception fetchexception invalid_metadata convert a client key block to a bucket if an error occurs report it via on failure and return null protected bucket extract client key block block object container container client context context bucket data try data block decode context get bucket factory parent persistent int math min ctx max output length integer max value false catch key decode exception e1 if logger should log logger minor this logger minor this decode failure e1 e1 on failure new fetch exception fetch exception block decode error e1 get message false container context return null catch too big exception e on failure new fetch exception fetch exception too big e false container context return null catch io exception e logger error this could not capture data disk full e e on failure new fetch exception fetch exception bucket error e false container context return null return data clientkeyblock onfailure clientkeyblock objectcontainer clientcontext getbucketfactory maxoutputlength max_value keydecodeexception shouldlog onfailure fetchexception fetchexception block_decode_error getmessage toobigexception onfailure fetchexception fetchexception too_big ioexception onfailure fetchexception fetchexception bucket_error get token is not supported public long get token return token gettoken gettoken public void on failed key listener construction exception e object container container client context context on failure e get fetch exception false container context onfailed keylistenerconstructionexception objectcontainer clientcontext onfailure getfetchexception override public void remove from object container container client context context super remove from container context rcb is definitely not our responsibility removefrom objectcontainer clientcontext removefrom override public void cancel object container container client context context super cancel container context if persistent container activate rcb 1 rcb on failure new fetch exception fetch exception cancelled this container context objectcontainer clientcontext onfailure fetchexception fetchexception public class seed server test peer node extends seed server peer node public seed server test peer node simple field set fs node node2 node crypto crypto peer manager peers boolean from local outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception super fs node2 crypto peers from local mangler seedservertestpeernode seedserverpeernode seedservertestpeernode simplefieldset nodecrypto peermanager fromlocal outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception fromlocal override public simple field set export field set simple field set sfs super export field set sfs put overwrite opennet true return sfs simplefieldset exportfieldset simplefieldset exportfieldset putoverwrite override public boolean should disconnect and remove now return false shoulddisconnectandremovenow override protected void send initial messages sendinitialmessages override public void on remove long last received data packet time last received data packet time if last received data packet time 0 time last connection completed 0 system err println this get identity string removed timeout no packets received after successful connection setup else if time last connection completed 0 system err println this get identity string removed never connected else system err println this get identity string removed unknown cause super on remove onremove lastreceiveddatapackettime lastreceiveddatapackettime lastreceiveddatapackettime timelastconnectioncompleted getidentitystring timelastconnectioncompleted getidentitystring getidentitystring onremove public fate get fate long last received data packet time last received data packet time if is connected if last received data packet time 0 return fate connected no packets received else if this is unroutable older version return fate connected too old else return fate connected success long last connection time time last connection completed if last connection time 0 return fate never connected if last received data packet time 0 return fate connected timeout no packets received return fate connected disconnected unknown getfate lastreceiveddatapackettime lastreceiveddatapackettime isconnected lastreceiveddatapackettime connected_no_packets_received isunroutableolderversion connected_too_old connected_success lastconnectiontime timelastconnectioncompleted lastconnectiontime never_connected lastreceiveddatapackettime connected_timeout_no_packets_received connected_disconnected_unknown public static string get wrapper property string name synchronized wrapper config class if overrides contains key name return overrides get name return wrapper manager get properties get property name null getwrapperproperty wrapperconfig containskey wrappermanager getproperties getproperty public static boolean can change properties if wrapper manager is controlled by native wrapper logger normal wrapper config class cannot alter properties not running under wrapper return false file f new file wrapper conf if f exists logger normal wrapper config class cannot alter properties wrapper conf does not exist return false if f can read logger normal wrapper config class cannot alter properties wrapper conf not readable return false if f can write logger normal wrapper config class cannot alter properties wrapper conf not writable return false if file util get canonical file f get parent file can write logger normal wrapper config class cannot alter properties parent dir not writable return false can we create a file in order to rename over wrapper conf return true canchangeproperties wrappermanager iscontrolledbynativewrapper wrapperconfig wrapperconfig canread wrapperconfig canwrite wrapperconfig fileutil getcanonicalfile getparentfile canwrite wrapperconfig synchronized because we only want one instance running at once param name the property to set param value the value to set it to return true if the property was successfully updated public static synchronized boolean set wrapper property string name string value some of this copied from update deploy context hence no gpl header on this file as none there file old config new file wrapper conf file new config new file wrapper conf new file input stream fis null file output stream fos null try fis new file input stream old config buffered input stream bis new buffered input stream fis input stream reader isr new input stream reader bis buffered reader br new buffered reader isr fos new file output stream new config output stream writer osw new output stream writer fos buffered writer bw new buffered writer osw string line boolean written false boolean written reload false while line br read line null if line starts with name bw write name value n written true else if line equals ignore case wrapper restart reload configuration true written reload true else bw write line n br close fis null if written bw write name value n if written reload bw write wrapper restart reload configuration true n bw close fos null catch io exception e closer close fis closer close fos fis null fos null if old config exists new config delete logger error wrapper config class cannot update wrapper property name e e system err println unable to update wrapper property name e return false finally closer close fis closer close fos if new config rename to old config file old old config new file wrapper conf old if old old config exists old old config delete try old old config file create temp file wrapper conf old tmp new file catch io exception e string error unable to create temporary file and unable to copy wrapper conf to wrapper conf old could not update wrapper conf trying to set property name logger error wrapper config class error system err println error return false if old config rename to old old config string error unable to change property name could not move old config file old config so could not rename new config file new config over it already tried without deleting logger error wrapper config class error system err println error return false if new config rename to old config string error unable to rename new config to old config even after moving the old config file out of the way trying to restore previous config file so the node will start up logger error wrapper config class error system err println error if old old config rename to old config system err println catastrophic update error unable to rename backup copy of config file over the current config file after failing to update config file the node will not boot until you get a new wrapper conf n the old config file is saved in old old config and it should be renamed to wrapper conf system exit node init exception exit broke wrapper conf wrapper properties are read only so don t set property overrides put name value return true setwrapperproperty updatedeploycontext oldconfig newconfig fileinputstream fileoutputstream fileinputstream oldconfig bufferedinputstream bufferedinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader fileoutputstream newconfig outputstreamwriter outputstreamwriter bufferedwriter bufferedwriter writtenreload readline startswith equalsignorecase reload_configuration writtenreload writtenreload reload_configuration ioexception oldconfig newconfig wrapperconfig newconfig renameto oldconfig oldoldconfig oldoldconfig oldoldconfig oldoldconfig createtempfile ioexception wrapperconfig oldconfig renameto oldoldconfig oldconfig newconfig wrapperconfig newconfig renameto oldconfig newconfig oldconfig wrapperconfig oldoldconfig renameto oldconfig oldoldconfig nodeinitexception exit_broke_wrapper_conf setproperty private stack fstack public ber encoder this byte 0x30 berencoder public ber encoder byte id fields new id vector id fstack new stack fstack add fields berencoder idvector public int to bytes byte buf while fields size 1 end sequence int len vec to bytes fields buf 0 byte tmpbt remember this function writes backwards first for int i 0 i len 2 i tmpbt buf i buf i buf len 1 i buf len 1 i tmpbt return len tobytes endsequence vectobytes private int vec to bytes id vector v byte buf int offset int inoffset offset for int i v size 1 i 0 i object o v get i if o instanceof integer int dlen int to bytes integer o int value buf offset if o null buf offset 0x00 buf offset 0x05 else if o instanceof long int dlen int to bytes long o long value buf offset offset dlen offset int tober bytes dlen buf offset buf offset 0x02 else if o instanceof snmp type wrapper num int dlen int to bytes snmp type wrapper num o get value buf offset offset dlen offset int tober bytes dlen buf offset buf offset snmp type wrapper num o get typeid else if o instanceof id vector int dlen vec to bytes id vector o buf offset offset dlen offset int tober bytes dlen buf offset buf offset id vector o get vid else if o instanceof byte arr wrapper byte barr byte arr wrapper o arr for int j 0 j barr length j buf offset j barr barr length 1 j offset barr length offset int tober bytes barr length buf offset buf offset byte arr wrapper o id myoffset int to bytes v get i buf myoffset return offset inoffset vectobytes idvector inttobytes intvalue inttobytes longvalue inttoberbytes snmptypewrappernum inttobytes snmptypewrappernum getvalue inttoberbytes snmptypewrappernum gettypeid idvector vectobytes idvector inttoberbytes idvector getvid bytearrwrapper bytearrwrapper inttoberbytes bytearrwrapper inttobytes private int int to bytes long i byte buf int offset todo handle negative numbers also int inoffset offset if i 0 buf offset 0 else for i 0 i i 256 buf offset byte i 256 offset make the number unsigned no we should allow signed numbers if buf offset 1 0 buf offset 0 return offset inoffset inttobytes private int int tober bytes long i byte buf int offset string bs long to binary string i int len bs length 7 bs 0000000 bs substring len char bits bs to char array int eatenbits 0 buf offset 0 int inoffset offset for int j bits length 1 j 0 j long j i system out print int tober bytes i if i 0 offset else for j 0 j j 128 buf offset byte j 128 buf offset byte j 127 128 0 system out print j 128 j 127 128 0 j 128 j 127 128 0 now turn it around if offset inoffset 1 system err println started at inoffset ended at offset for int p 0 p offset inoffset 2 p system err println stap offset p 1 inoffset p byte tmp buf offset p 1 buf offset p 1 buf inoffset p buf inoffset p tmp system err println for int j 0 j bits length j if eatenbits 7 buf offset 128 offset eatenbits 0 buf offset 0 buf offset bits j 1 1 0 6 eatenbits eatenbits offset return offset inoffset inttoberbytes tobinarystring tochararray inttoberbytes public void putsnmp type wrapper num snmp type wrapper num o add to top o clone putsnmptypewrappernum snmptypewrappernum addtotop add to top new integer i public void put timeticks long i add to top new snmp time ticks i addtotop puttimeticks addtotop snmptimeticks public void put integer long i add to top new long i putinteger addtotop public void put counter32 long i add to top new snmp counter32 i putcounter32 addtotop snmpcounter32 public void put null add to top null putnull addtotop public void put octet string byte buf add to top new byte arr wrapper byte buf clone byte 0x04 putoctetstring addtotop bytearrwrapper public void putoid long buf byte bufa new byte 10 buf length int offset 1 bufa 0 0x2b for int i 2 i buf length i offset int tober bytes buf i bufa offset byte bufb new byte offset for int i 0 i bufb length i bufb i bufa i add to top new byte arr wrapper bufb byte 0x06 inttoberbytes addtotop bytearrwrapper public void start sequence start sequence byte 0x30 startsequence startsequence public void start sequence byte id id vector v new id vector id add to top v fstack add v startsequence idvector idvector addtotop public void end sequence fstack pop endsequence private void add to top object o id vector fstack peek add element o addtotop idvector addelement public byte id public byte arr wrapper byte arr byte id this arr arr this id id bytearrwrapper byte vid byte 0x30 public id vector byte id super vid id idvector public byte get vid return vid getvid public class ssdp search socket extends httpmu socket implements runnable public ssdp search socket ssdpsearchsocket httpmusocket ssdpsearchsocket public ssdp search socket string bind addr open bind addr ssdpsearchsocket bindaddr bindaddr public boolean open string bind addr string addr ssdp address if host interface isi pv6 address bind addr true addr ssdp geti pv6 address return open addr ssdp port bind addr bindaddr hostinterface isipv6address bindaddr getipv6address bindaddr private listener list device search listener list new listener list public void add search listener search listener listener device search listener list add listener listenerlist devicesearchlistenerlist listenerlist addsearchlistener searchlistener devicesearchlistenerlist public void remove search listener search listener listener device search listener list remove listener removesearchlistener searchlistener devicesearchlistenerlist public void perform search listener ssdp packet ssdp packet int listener size device search listener list size for int n 0 n listener size n search listener listener search listener device search listener list get n listener device search received ssdp packet performsearchlistener ssdppacket ssdppacket listenersize devicesearchlistenerlist listenersize searchlistener searchlistener devicesearchlistenerlist devicesearchreceived ssdppacket public void run thread this thread thread current thread while device search thread this thread thread yield ssdp packet packet receive thanks for mikael hakman 04 20 05 if packet null continue if packet is discover true perform search listener packet thisthread currentthread devicesearchthread thisthread ssdppacket isdiscover performsearchlistener public void start device search thread new thread this u pnp ssdp search socket device search thread set daemon true device search thread start devicesearchthread upnp ssdpsearchsocket devicesearchthread setdaemon devicesearchthread public void stop thanks for mikael hakman 04 20 05 close device search thread null devicesearchthread private static final long serial versionuid 1l public updater parser exception string msg super msg serialversionuid updaterparserexception public plugin manager node node logminor logger should log logger minor this logdebug logger should log logger debug this config toadlet list new hash map string fred plugin plugin wrappers new vector plugin info wrapper plugins failed load new vector string this node node this core node client core if logminor logger minor this starting plugin manager if logdebug logger debug this initialize plugin manager config client core make client request starter interactive priority class true callback executor executor new serial executor native thread norm priority executor start node executor pm callback executor pmconfig new sub config pluginmanager node config pmconfig register configfile fplugins ini 9 true true plugin config config file plugin config config file long new string callback public string get return config file public void set string val throws invalid config value exception config file val config file pmconfig get string configfile pmconfig register installdir fplugins 9 true true plugin config install dir plugin config install dir long new string callback public string get return install dir return get config load string public void set string val throws invalid config value exception install dir val if store dir equals new file val return fixme throw new invalid config value exception l10n get string plugin manager cannot set once loaded install dir pmconfig get string installdir start plugins in the config pmconfig register loadplugin null 0 true false plugin manager loaded on startup plugin manager loaded on startup long new string arr callback override public string get return get config load string override public void set string val throws invalid config value exception if store dir equals new file val return fixme throw new invalid config value exception l10n get string plugin manager cannot set once loaded override public boolean is read only return true to start pmconfig get string arr loadplugin pmconfig finished initialization fproxy theme theme theme from name node config get fproxy get string css selfinstance this pluginmanager shouldlog shouldlog toadletlist hashmap fredplugin pluginwrappers plugininfowrapper pluginsfailedload clientcore makeclient requeststarter interactive_priority_class serialexecutor nativethread norm_priority subconfig pluginconfig configfile pluginconfig configfilelong stringcallback configfile invalidconfigvalueexception configfile configfile getstring pluginconfig installdir pluginconfig installdirlong stringcallback installdir getconfigloadstring invalidconfigvalueexception installdir storedir invalidconfigvalueexception getstring pluginmanager cannotsetonceloaded installdir getstring pluginmanager loadedonstartup pluginmanager loadedonstartuplong stringarrcallback getconfigloadstring invalidconfigvalueexception storedir invalidconfigvalueexception getstring pluginmanager cannotsetonceloaded isreadonly tostart getstringarr finishedinitialization fproxytheme themefromname getstring new string arr callback override public string get return get config load string stringarrcallback getconfigloadstring override public void set string val throws invalid config value exception if store dir equals new file val return fixme throw new invalid config value exception l10n get string plugin manager cannot set once loaded invalidconfigvalueexception storedir invalidconfigvalueexception getstring pluginmanager cannotsetonceloaded override public boolean is read only return true isreadonly public void start config config if to start null for string name to start start plugin auto name false synchronized plugin wrappers started true to start null tostart tostart startpluginauto pluginwrappers tostart private string get config load string vector string v new vector string synchronized plugin wrappers if started return to start for plugin info wrapper pi plugin wrappers v add pi get filename for string s plugins failed load v add s return v to array new string v size getconfigloadstring pluginwrappers tostart plugininfowrapper pluginwrappers getfilename pluginsfailedload toarray returns a set of all currently starting plugins return all currently starting plugins public set plugin progress get starting plugins synchronized starting plugins return new hash set plugin progress starting plugins pluginprogress getstartingplugins startingplugins hashset pluginprogress startingplugins try to guess around public void start plugin auto final string pluginname boolean store if is official plugin pluginname start plugin official pluginname store return try new freeneturi pluginname test for malformedurl exception start plugin freenet pluginname store return catch malformedurl exception e not a freenet key file roots file list roots for file f roots if pluginname starts with f get name new file pluginname exists start plugin file pluginname store return start pluginurl pluginname store startpluginauto isofficialplugin startpluginofficial malformedurlexception startpluginfreenet malformedurlexception listroots startswith getname startpluginfile startpluginurl public void start plugin official final string pluginname boolean store real start plugin new plugin down loader official pluginname store startpluginofficial realstartplugin plugindownloaderofficial public void start plugin file final string filename boolean store real start plugin new plugin down loader file filename store startpluginfile realstartplugin plugindownloaderfile public void start pluginurl final string filename boolean store real start plugin new plugin down loaderurl filename store startpluginurl realstartplugin plugindownloaderurl public void start plugin freenet final string filename boolean store real start plugin new plugin down loader freenet client filename store startpluginfreenet realstartplugin plugindownloaderfreenet private void real start plugin final plugin down loader pdl final string filename final boolean store if filename trim length 0 return final plugin progress plugin progress new plugin progress filename synchronized starting plugins starting plugins add plugin progress logger normal this loading plugin filename fred plugin plug try plug load plugin pdl filename if plug null return already loaded plugin progress set progress plugin progress starting plugin info wrapper pi plugin handler start plugin plugin manager this filename plug new plugin respirator node plugin manager this plug synchronized plugin wrappers plugin wrappers add pi plugins failed load remove filename logger normal this plugin loaded filename catch plugin not found exception e logger normal this loading plugin failed filename e string message e get message synchronized plugin wrappers plugins failed load add filename core alerts register new plugin load failed user alert filename pdl instanceof plugin down loader official message catch unsupported class version error e logger error this could not load plugin filename e e system err println could not load plugin filename e e print stack trace system err println plugin filename appears to require a later jvm logger error this plugin filename appears to require a later jvm synchronized plugin wrappers plugins failed load add filename core alerts register new plugin load failed user alert filename pdl instanceof plugin down loader official l10n plugin req newerjvm title name filename finally synchronized starting plugins starting plugins remove plugin progress try not to destroy the config synchronized this if store core store config realstartplugin plugindownloader pluginprogress pluginprogress pluginprogress startingplugins startingplugins pluginprogress fredplugin loadplugin pluginprogress setprogress pluginprogress plugininfowrapper pluginhandler startplugin pluginmanager pluginrespirator pluginmanager pluginwrappers pluginwrappers pluginsfailedload pluginnotfoundexception getmessage pluginwrappers pluginsfailedload pluginloadfaileduseralert plugindownloaderofficial unsupportedclassversionerror printstacktrace pluginwrappers pluginsfailedload pluginloadfaileduseralert plugindownloaderofficial pluginreqnewerjvmtitle startingplugins startingplugins pluginprogress storeconfig public plugin load failed user alert string filename boolean official string message this filename filename this official official this message message pluginloadfaileduseralert public string dismiss button text return l10n delete failed plugin button dismissbuttontext deletefailedpluginbutton public void on dismiss synchronized plugin wrappers plugins failed load remove filename ondismiss pluginwrappers pluginsfailedload public string anchor return pluginfailed filename public html node gethtml text html node p new html node p p add child l10n plugin loading failed with message new string name message new string filename message if official html node reload form p add child form new string action method new string plugins post reload form add child input new string type name value new string hidden form password node client core form password reload form add child input new string type name value new string hidden plugin name filename reload form add child input new string type name value new string submit submit official l10n official plugin load failed try again return p htmlnode gethtmltext htmlnode htmlnode addchild pluginloadingfailedwithmessage htmlnode reloadform addchild reloadform addchild formpassword clientcore formpassword reloadform addchild reloadform addchild officialpluginloadfailedtryagain public short get priority class return user alert error getpriorityclass useralert public string get short text return l10n plugin loading failed short name filename getshorttext pluginloadingfailedshort public string get text return l10n plugin loading failed with message new string name message new string filename message gettext pluginloadingfailedwithmessage public string get title return l10n plugin loading failed title gettitle pluginloadingfailedtitle public object get user identifier return plugin manager class getuseridentifier pluginmanager public boolean is event notification return false iseventnotification public boolean is valid boolean success synchronized plugin wrappers success plugins failed load contains filename if success core alerts unregister this return success isvalid pluginwrappers pluginsfailedload public void is valid boolean validity isvalid public boolean should unregister on dismiss return true shouldunregisterondismiss public boolean user can dismiss return true usercandismiss void register fred plugin plug plugin info wrapper pi handles f proxy if so register if pi is pproxy plugin register toadlet plug if pi isip detector plugin node ip detector registerip detector plugin fred pluginip detector plug if pi is port forward plugin node ip detector register port forward plugin fred plugin port forward plug if pi is bandwidth indicator node ip detector register bandwidth indicator plugin fred plugin bandwidth indicator plug fredplugin plugininfowrapper fproxy ispproxyplugin registertoadlet isipdetectorplugin ipdetector registeripdetectorplugin fredpluginipdetector isportforwardplugin ipdetector registerportforwardplugin fredpluginportforward isbandwidthindicator ipdetector registerbandwidthindicatorplugin fredpluginbandwidthindicator returns the translation of the given key prefixed by the short name of the current class param key the key to fetch return the translation private string l10n string key return l10n get string plugin manager key getstring pluginmanager private string l10n string key string pattern string value return l10n get string plugin manager key pattern value getstring pluginmanager returns the translation of the given key replacing each occurence of code em pattern em code with code value code param key the key to fetch param patterns the patterns to replace param values the values to substitute return the translation private string l10n string key string patterns string values return l10n get string plugin manager key patterns values getstring pluginmanager private void register toadlet fred plugin pl toadlet list put e get stack trace 1 get class to string pl synchronized toadlet list toadlet list put pl get class get name pl logger normal this added http handler for plugins pl get class get name registertoadlet fredplugin toadletlist getstacktrace getclass tostring toadletlist toadletlist getclass getname getclass getname remove a plugin from the plugin list public void remove plugin plugin info wrapper pi synchronized plugin wrappers if plugin wrappers remove pi return core store config removeplugin plugininfowrapper pluginwrappers pluginwrappers storeconfig removes the cached copy of the given plugin from the plugins directory param plugin specification the plugin specification public void remove cached copy string plugin specification int last slash plugin specification last index of file plugin file if last slash 1 windows maybe last slash plugin specification last index of file plugin directory new file node get node dir plugins if last slash 1 it s an official plugin plugin file new file plugin directory plugin specification jar else plugin file new file plugin directory plugin specification substring last slash 1 if logdebug logger minor this delete plugin plugname plugin specification filename plugin file get absolute path new exception debug if plugin file exists plugin file delete pluginspecification removecachedcopy pluginspecification lastslash pluginspecification lastindexof pluginfile lastslash lastslash pluginspecification lastindexof plugindirectory getnodedir lastslash pluginfile plugindirectory pluginspecification pluginfile plugindirectory pluginspecification lastslash pluginspecification pluginfile getabsolutepath pluginfile pluginfile public void unregister plugin toadlet plugin info wrapper pi synchronized toadlet list try toadlet list remove pi get plugin class name logger normal this removed http handler for plugins pi get plugin class name new exception debug catch throwable ex logger error this removing plugin ex unregisterplugintoadlet plugininfowrapper toadletlist toadletlist getpluginclassname getpluginclassname public void add toadlet symlinks plugin info wrapper pi synchronized toadlet list try string targets pi get plugin toadlet symlinks if targets null return for int i 0 i targets length i toadlet list remove targets i logger normal this removed http symlink targets i plugins pi get plugin class name catch throwable ex logger error this removing toadlet link ex addtoadletsymlinks plugininfowrapper toadletlist getplugintoadletsymlinks toadletlist getpluginclassname public void remove toadlet symlinks plugin info wrapper pi synchronized toadlet list string rm null try string targets pi get plugin toadlet symlinks if targets null return for int i 0 i targets length i rm targets i toadlet list remove targets i pi remove plugin toadlet symlink targets i logger normal this removed http symlink targets i plugins pi get plugin class name catch throwable ex logger error this removing toadlet link rm ex removetoadletsymlinks plugininfowrapper toadletlist getplugintoadletsymlinks toadletlist removeplugintoadletsymlink getpluginclassname public string dump plugins string builder out new string builder synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i out append pi to string out append n return out to string dumpplugins stringbuilder stringbuilder pluginwrappers pluginwrappers plugininfowrapper pluginwrappers tostring tostring public set plugin info wrapper get plugins hash set plugin info wrapper out new hash set plugin info wrapper synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i out add pi return out plugininfowrapper getplugins hashset plugininfowrapper hashset plugininfowrapper pluginwrappers pluginwrappers plugininfowrapper pluginwrappers look for plugin info for a fcp plugin with given classname param plugname return the plugin info or null if not found public plugin info wrapper getfcp plugin info string plugname synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i if pi get plugin class name equals plugname return pi return null plugininfo fcpplugin plugininfo plugininfowrapper getfcpplugininfo pluginwrappers pluginwrappers plugininfowrapper pluginwrappers getpluginclassname look for a fcp plugin with given classname param plugname return the plugin or null if not found public fred pluginfcp getfcp plugin string plugname synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i if pi isfcp plugin pi get plugin class name equals plugname return fred pluginfcp pi plug return null fcpplugin fredpluginfcp getfcpplugin pluginwrappers pluginwrappers plugininfowrapper pluginwrappers isfcpplugin getpluginclassname fredpluginfcp look for a plugin with given classname param plugname return the true if not found public boolean is plugin loaded string plugname synchronized plugin wrappers for int i 0 i plugin wrappers size i plugin info wrapper pi plugin wrappers get i if pi get plugin class name equals plugname return true return false ispluginloaded pluginwrappers pluginwrappers plugininfowrapper pluginwrappers getpluginclassname public string handlehttp get string plugin http request request throws pluginhttp exception fred plugin handler null synchronized toadlet list handler toadlet list get plugin if handler null return null class loader old class loader thread current thread get context class loader class loader plugin class loader handler get class get class loader thread current thread set context class loader plugin class loader try if handler instanceof fred pluginhttp return fred pluginhttp handler handlehttp get request finally thread current thread set context class loader old class loader throw new not found pluginhttp exception plugin not found plugins handlehttpget httprequest pluginhttpexception fredplugin toadletlist toadletlist classloader oldclassloader currentthread getcontextclassloader classloader pluginclassloader getclass getclassloader currentthread setcontextclassloader pluginclassloader fredpluginhttp fredpluginhttp handlehttpget currentthread setcontextclassloader oldclassloader notfoundpluginhttpexception public string handlehttp post string plugin http request request throws pluginhttp exception fred plugin handler null synchronized toadlet list handler toadlet list get plugin if handler null throw new not found pluginhttp exception plugin plugin not found plugins class loader old class loader thread current thread get context class loader class loader plugin class loader handler get class get class loader thread current thread set context class loader plugin class loader try if handler instanceof fred pluginhttp return fred pluginhttp handler handlehttp post request finally thread current thread set context class loader old class loader throw new not found pluginhttp exception plugin plugin not found plugins handlehttppost httprequest pluginhttpexception fredplugin toadletlist toadletlist notfoundpluginhttpexception classloader oldclassloader currentthread getcontextclassloader classloader pluginclassloader getclass getclassloader currentthread setcontextclassloader pluginclassloader fredpluginhttp fredpluginhttp handlehttppost currentthread setcontextclassloader oldclassloader notfoundpluginhttpexception public void kill plugin string name int max wait time plugin info wrapper pi null boolean found false synchronized plugin wrappers for int i 0 i plugin wrappers size found i pi plugin wrappers get i if pi get thread name equals name found true break if found pi stop plugin this max wait time killplugin maxwaittime plugininfowrapper pluginwrappers pluginwrappers pluginwrappers getthreadname stopplugin maxwaittime public void kill plugin fred plugin plugin int max wait time plugin info wrapper pi null boolean found false synchronized plugin wrappers for int i 0 i plugin wrappers size found i pi plugin wrappers get i if pi plug plugin found true if found pi stop plugin this max wait time killplugin fredplugin maxwaittime plugininfowrapper pluginwrappers pluginwrappers pluginwrappers stopplugin maxwaittime official plugin description string name boolean essential long min ver this name name this essential essential this minimum version min ver officialplugindescription minver minimumversion minver static void add official plugin string name official plugins put name new official plugin description name false 1 addofficialplugin officialplugins officialplugindescription static void add official plugin string name boolean essential long min ver official plugins put name new official plugin description name essential min ver addofficialplugin minver officialplugins officialplugindescription minver returns a list of the names of all available official plugins right now this list is hardcoded but in future we could retrieve this list from emu or from freenet itself return a list of all available plugin names public list string find available plugins list string available plugins new array list string available plugins add all official plugins key set return available plugins findavailableplugins availableplugins arraylist availableplugins addall officialplugins keyset availableplugins public boolean is official plugin string name if name null name trim length 0 return false list string available plugins find available plugins for string n available plugins if n equals name return true return false isofficialplugin availableplugins findavailableplugins availableplugins tries to load a plugin from the given name if the name only contains the name of a plugin it is loaded from the plugin directory if found otherwise it s loaded from the project server if the name contains a complete url and the short file already exists in the plugin directory it s loaded from the plugin directory otherwise it s retrieved from the remote server param pdl param name the specification of the plugin return an instanciated object of the plugin throws plugin not found exception if anything goes wrong private fred plugin load plugin plugin down loader pdl string name throws plugin not found exception pdl set source name check for plugin directory file plugin directory new file node get node dir plugins if plugin directory exists plugin directory is directory plugin directory exists plugin directory mkdirs logger error this could not create plugin directory throw new plugin not found exception could not create plugin directory get plugin filename string filename pdl get plugin name name file plugin file new file plugin directory filename check if file needs to be downloaded if logminor logger minor this plugin file plugin file get absolute path exists plugin file exists downloader pdl name name int retries 5 for int i 0 i retries i if plugin file exists plugin file length 0 try system err println downloading plugin name wrapper manager signal starting 5 60 1000 file temp plugin file null output stream plugin output stream null input stream plugin input stream null try temp plugin file file create temp file plugin jar plugin directory temp plugin file delete on exit plugin output stream new file output stream temp plugin file plugin input stream pdl get input stream byte buffer new byte 1024 int read while read plugin input stream read buffer 1 plugin output stream write buffer 0 read plugin output stream close if temp plugin file length 0 throw new plugin not found exception downloaded zero length file if file util rename to temp plugin file plugin file logger error this could not rename temp file to plugin file throw new plugin not found exception could not rename temp file to plugin file try strongest first string testsum null string digest pdl getsha256sum if digest null digest pdl getsha1sum else testsum get file digest plugin file sha 256 if digest null testsum null testsum get file digest plugin file sha 1 if digest null if digest equals ignore case testsum logger error this checksum verification failed should be digest but was testsum throw new plugin not found exception checksum verification failed should be digest but was testsum catch io exception ioe1 logger error this could not load plugin ioe1 if temp plugin file null temp plugin file delete throw new plugin not found exception could not load plugin ioe1 get message ioe1 finally closer close plugin output stream closer close plugin input stream catch plugin not found exception e if i retries 1 logger normal this failed to load plugin e e continue else throw e we do quite a lot inside the lock use a dedicated one synchronized plugin load sync object if this is plugin loaded filename logger error this plugin already loaded filename return null now get the manifest file jar file plugin jar file null string plugin main class name null try plugin jar file new jar file plugin file manifest manifest plugin jar file get manifest if manifest null logger error this could not load manifest from plugin file plugin file delete throw new plugin not found exception could not load manifest from plugin file attributes main attributes manifest get main attributes if main attributes null logger error this manifest does not contain attributes plugin file delete throw new plugin not found exception manifest does not contain attributes plugin main class name main attributes get value plugin main class if plugin main class name null logger error this manifest does not contain a plugin main class attribute plugin file delete throw new plugin not found exception manifest does not contain a plugin main class attribute catch jar exception je1 logger error this could not process jar file je1 plugin file delete throw new plugin not found exception could not process jar file je1 catch zip exception ze1 logger error this could not process jar file ze1 plugin file delete throw new plugin not found exception could not process jar file ze1 catch io exception ioe1 logger error this error processing jar file ioe1 plugin file delete throw new plugin not found exception error procesesing jar file ioe1 finally closer close plugin jar file try jar class loader jar class loader new jar class loader plugin file class plugin main class jar class loader load class plugin main class name object object plugin main class new instance if object instanceof fred plugin logger error this plugin main class is not a plugin plugin file delete throw new plugin not found exception plugin main class is not a plugin if object instanceof fred plugin with class loader fred plugin with class loader object set class loader jar class loader if pdl instanceof plugin down loader official system err println loading official plugin name check the version after loading it building it into the manifest would be better in that it would avoid having to unload but building it into the manifest is problematic specifically it involves either platform specific scripts that aren t distributed and devs won t use when they build locally or executing java code which would mean we have to protect the versioning info either way is bad the latter is less bad if we don t auto build ugh this is just as messy ideas maybe we need to have os detection and use grep sed on unix and find on windows official plugin description desc official plugins get name long min ver desc minimum version long ver 1 if min ver 1 if object instanceof fred plugin real versioned ver fred plugin real versioned object get real version if ver min ver system err println failed to load plugin name too old need at least version min ver but is ver logger error this failed to load plugin name too old need at least version min ver but is ver try if object instanceof fred plugin threadless fred plugin object run plugin new plugin respirator node plugin manager this fred plugin object catch throwable t logger error this failed to start plugin to prevent np es while terminating it because it is too old t t try fred plugin object terminate catch throwable t logger error this plugin failed to terminate t t try jar class loader close catch throwable t logger error this failed to close jar classloader for plugin t t throw new plugin not found exception plugin too old need at least version min ver return fred plugin object catch io exception ioe1 logger error this could not load plugin ioe1 plugin file delete throw new plugin not found exception could not load plugin ioe1 catch class not found exception cnfe1 logger error this could not find plugin class cnfe1 plugin file delete throw new plugin not found exception could not find plugin class cnfe1 catch instantiation exception ie1 logger error this could not instantiate plugin ie1 plugin file delete throw new plugin not found exception could not instantiate plugin ie1 catch illegal access exception iae1 logger error this could not access plugin main class iae1 plugin file delete throw new plugin not found exception could not access plugin main class iae1 catch no class def found error ncdfe1 logger error this could not find class def may a missing lib ncdfe1 plugin file delete throw new plugin not found exception could not find class def may a missing lib ncdfe1 catch throwable t logger error this unexpected error while plugin loading t plugin file delete throw new plugin not found exception unexpected error while plugin loading t t pluginnotfoundexception fredplugin loadplugin plugindownloader pluginnotfoundexception setsource plugindirectory getnodedir plugindirectory plugindirectory isdirectory plugindirectory plugindirectory pluginnotfoundexception getpluginname pluginfile plugindirectory pluginfile getabsolutepath pluginfile pluginfile pluginfile wrappermanager signalstarting temppluginfile outputstream pluginoutputstream inputstream plugininputstream temppluginfile createtempfile plugindirectory temppluginfile deleteonexit pluginoutputstream fileoutputstream temppluginfile plugininputstream getinputstream plugininputstream pluginoutputstream pluginoutputstream temppluginfile pluginnotfoundexception fileutil renameto temppluginfile pluginfile pluginnotfoundexception getfiledigest pluginfile getfiledigest pluginfile equalsignorecase pluginnotfoundexception ioexception temppluginfile temppluginfile pluginnotfoundexception getmessage pluginoutputstream plugininputstream pluginnotfoundexception pluginloadsyncobject ispluginloaded jarfile pluginjarfile pluginmainclassname pluginjarfile jarfile pluginfile pluginjarfile getmanifest pluginfile pluginnotfoundexception mainattributes getmainattributes mainattributes pluginfile pluginnotfoundexception pluginmainclassname mainattributes getvalue pluginmainclassname pluginfile pluginnotfoundexception jarexception pluginfile pluginnotfoundexception zipexception pluginfile pluginnotfoundexception ioexception pluginfile pluginnotfoundexception pluginjarfile jarclassloader jarclassloader jarclassloader pluginfile pluginmainclass jarclassloader loadclass pluginmainclassname pluginmainclass newinstance fredplugin pluginfile pluginnotfoundexception fredpluginwithclassloader fredpluginwithclassloader setclassloader jarclassloader plugindownloaderofficial officialplugindescription officialplugins minver minimumversion minver fredpluginrealversioned fredpluginrealversioned getrealversion minver minver minver fredpluginthreadless fredplugin runplugin pluginrespirator pluginmanager fredplugin npes fredplugin jarclassloader pluginnotfoundexception minver fredplugin ioexception pluginfile pluginnotfoundexception classnotfoundexception pluginfile pluginnotfoundexception instantiationexception pluginfile pluginnotfoundexception illegalaccessexception pluginfile pluginnotfoundexception noclassdeffounderror pluginfile pluginnotfoundexception pluginfile pluginnotfoundexception private string get file digest file file string digest throws plugin not found exception final int buffersize 4096 message digest hash null file input stream fis null buffered input stream bis null boolean was from digest256 pool false string result try if sha 256 equals digest hash sha256 get message digest grab digest from pool was from digest256 pool true else hash message digest get instance digest we compute the hash http java sun com developer tech tips 1998 tt0915 html tip2 fis new file input stream file bis new buffered input stream fis int len 0 byte buffer new byte buffersize while len bis read buffer 1 hash update buffer 0 len result hex util bytes to hex hash digest if was from digest256 pool sha256 return message digest hash catch exception e throw new plugin not found exception error while computing hash digest of the downloaded plugin e e finally closer close bis closer close fis return result getfiledigest pluginnotfoundexception messagedigest fileinputstream bufferedinputstream wasfromdigest256pool getmessagedigest wasfromdigest256pool messagedigest getinstance techtips fileinputstream bufferedinputstream hexutil bytestohex wasfromdigest256pool returnmessagedigest pluginnotfoundexception ticker get ticker return node get ticker getticker getticker private constructor for state constants private plugin progress pluginprogress creates a new progress tracker for a plugin that is loaded by the given name param name the name by which the plugin is loaded plugin progress string name this name name plugin progress downloading pluginprogress pluginprogress returns the number of milliseconds this plugin is already being loaded return the time this plugin is already being loaded in milliseconds public long get time return system current time millis starting time gettime currenttimemillis startingtime returns the name by which the plugin is loaded return the name by which the plugin is loaded public string get name return name getname returns the current state of the plugin start procedure return the current state of the plugin public plugin progress get progress return plugin progress pluginprogress getprogress pluginprogress sets the current state of the plugin start procedure param plugin progress the current state void set progress plugin progress plugin progress this plugin progress plugin progress pluginprogress setprogress pluginprogress pluginprogress pluginprogress pluginprogress if this object is one of the constants link downloading or link starting the name of those constants will be returned otherwise a textual representation of the plugin progress is returned return the name of a constant or the plugin progress override public string to string if this downloading return downloading else if this starting return starting return plugin progress name name starting time starting time progress plugin progress tostring pluginprogress startingtime startingtime pluginprogress public void setf proxy theme final theme css name if fproxy theme equals css name return fproxy theme css name synchronized plugin wrappers for plugin info wrapper pi plugin wrappers pi pr get page maker set theme css name if pi is themed plugin final fred plugin themed plug fred plugin themed pi plug executor execute new runnable public void run try plug set theme css name catch throwable t logger error this cought trowable in callback t callback setfproxytheme cssname fproxytheme cssname fproxytheme cssname pluginwrappers plugininfowrapper pluginwrappers getpagemaker settheme cssname isthemedplugin fredpluginthemed fredpluginthemed settheme cssname executor execute new runnable public void run try plug set theme css name catch throwable t logger error this cought trowable in callback t settheme cssname public static void set language language lang if selfinstance null return selfinstance set plugin language lang setlanguage setpluginlanguage private void set plugin language final language lang synchronized plugin wrappers for plugin info wrapper pi plugin wrappers if pi isl10n plugin final fred pluginl10n plug fred pluginl10n pi plug executor execute new runnable public void run try plug set language lang catch throwable t logger error this cought trowable in callback t callback setpluginlanguage pluginwrappers plugininfowrapper pluginwrappers isl10nplugin fredpluginl10n fredpluginl10n setlanguage executor execute new runnable public void run try plug set language lang catch throwable t logger error this cought trowable in callback t setlanguage public theme getf proxy theme return fproxy theme getfproxytheme fproxytheme static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public final file seedfile a file to which seed data should be dumped periodically public yarrow this prng seed sha1 rijndael true true public yarrow boolean can block this prng seed sha1 rijndael true can block canblock canblock public yarrow string seed string digest string cipher boolean update seed boolean can block this new file seed digest cipher update seed can block updateseed canblock updateseed canblock public yarrow file seed string digest string cipher boolean update seed boolean can block this seed digest cipher update seed can block true updateseed canblock updateseed canblock unset reseed on startup only in unit test yarrow file seed string digest string cipher boolean update seed boolean can block boolean reseed on startup secure random s try s secure random get instance sha1prng catch no such algorithm exception e s null sr s try accumulator init digest reseed init digest generator init cipher catch no such algorithm exception e logger error this could not init pools trying to get instance digest e e throw new runtime exception cannot initialize yarrow e e if update seed seed to string equals dev urandom dont try to update the seedfile if we know that it wont be possible anyways seedfile seed else seedfile null if reseed on startup entropy init seed reseed on startup seed from external stuff can block if we don t reseed at this point we will be predictable because the startup entropy won t cause a reseed fast pool reseed slow pool reseed else read seed seed reseedonstartup updateseed canblock reseedonstartup securerandom securerandom getinstance nosuchalgorithmexception accumulator_init reseed_init generator_init nosuchalgorithmexception getinstance runtimeexception updateseed tostring reseedonstartup entropy_init reseedonstartup seedfromexternalstuff canblock fast_pool_reseed slow_pool_reseed read_seed private void seed from external stuff boolean can block byte buf new byte 32 if file separator char data input stream dis null file input stream fis null file hwrng new file dev hwrng if hwrng exists hwrng can read try fis new file input stream hwrng dis new data input stream fis dis read fully buf consume bytes buf dis read fully buf consume bytes buf dis close catch throwable t logger normal this can t read dev hwrng even though exists and is readable t t finally closer close dis closer close fis boolean is system entropy available true read some bits from dev urandom try fis new file input stream dev urandom dis new data input stream fis dis read fully buf consume bytes buf dis read fully buf consume bytes buf catch throwable t logger normal this can t read dev urandom t t we can t read it let s skip dev random and seed from secure random generate seed can block true is system entropy available false finally closer close dis closer close fis if can block is system entropy available read some bits from dev random try fis new file input stream dev random dis new data input stream fis dis read fully buf consume bytes buf dis read fully buf consume bytes buf catch throwable t logger normal this can t read dev random t t finally closer close dis closer close fis fis null else force generate seed since we can t read random data from anywhere else anyway windows s capi won t block can block true if can block secure random hopefully acts as a proxy for capi on windows buf sr generate seed 32 consume bytes buf buf sr generate seed 32 consume bytes buf a few more bits consume string long to hex string runtime get runtime free memory consume string long to hex string runtime get runtime total memory seedfromexternalstuff canblock separatorchar datainputstream fileinputstream canread fileinputstream datainputstream readfully consumebytes readfully consumebytes issystementropyavailable fileinputstream datainputstream readfully consumebytes readfully consumebytes securerandom generateseed canblock issystementropyavailable canblock issystementropyavailable fileinputstream datainputstream readfully consumebytes readfully consumebytes generateseed canblock canblock securerandom generateseed consumebytes generateseed consumebytes consumestring tohexstring getruntime freememory consumestring tohexstring getruntime totalmemory private void entropy init file seed boolean reseed on startup if reseed on startup properties sys system get properties entropy source startup entropy new entropy source consume the system properties list for enumeration enu sys property names enu has more elements string key string enu next element consume string key consume string sys get property key consume the local ip address try consume string inet address get local host to string catch exception e ignore read startup entropy startup entropy read seed seed entropy_init reseedonstartup reseedonstartup getproperties entropysource startupentropy entropysource propertynames hasmoreelements nextelement consumestring consumestring getproperty consumestring inetaddress getlocalhost tostring readstartupentropy startupentropy read_seed protected void read startup entropy entropy source startup entropy consume the current time accept entropy startup entropy system current time millis 0 accept entropy startup entropy system nano time 0 free memory accept entropy startup entropy runtime get runtime free memory 0 total memory accept entropy startup entropy runtime get runtime total memory 0 readstartupentropy entropysource startupentropy acceptentropy startupentropy currenttimemillis acceptentropy startupentropy nanotime acceptentropy startupentropy getruntime freememory acceptentropy startupentropy getruntime totalmemory seed handling private void read seed file filename file input stream fis null buffered input stream bis null data input stream dis null try fis new file input stream filename bis new buffered input stream fis dis new data input stream bis entropy source seed file new entropy source try for int i 0 i 32 i accept entropy seed file dis read long 64 catch eof exception f dis close catch io exception e logger error this ioe trying to read the seedfile from disk e get message finally closer close dis closer close bis closer close fis fast pool reseed read_seed fileinputstream bufferedinputstream datainputstream fileinputstream bufferedinputstream datainputstream entropysource seedfile entropysource acceptentropy seedfile readlong eofexception ioexception getmessage fast_pool_reseed private long time last wrote seed 1 private void write seed file filename write seed filename false timelastwroteseed write_seed write_seed public void write seed file filename boolean force if force synchronized this long now system current time millis if now time last wrote seed 60 60 1000 once per hour return else time last wrote seed now file output stream fos null buffered output stream bos null data output stream dos null try fos new file output stream filename bos new buffered output stream fos dos new data output stream bos for int i 0 i 32 i dos write long next long dos flush dos close catch io exception e logger error this ioe while saving the seed file e get message finally closer close dos closer close bos closer close fos write_seed currenttimemillis timelastwroteseed timelastwroteseed fileoutputstream bufferedoutputstream dataoutputstream fileoutputstream bufferedoutputstream dataoutputstream writelong nextlong ioexception getmessage private void generator init string cipher cipher ctx util get cipher by name cipher output buffer new byte cipher ctx get block size 8 counter new byte cipher ctx get block size 8 all zero string new byte cipher ctx get block size 8 tmp new byte cipher ctx get key size 8 fetch counter output buffer length generator_init cipher_ctx getcipherbyname output_buffer cipher_ctx getblocksize cipher_ctx getblocksize allzerostring cipher_ctx getblocksize cipher_ctx getkeysize fetch_counter output_buffer private final void counter inc for int i counter length 1 i 0 i if counter i 0 break counterinc private final void generate output counter inc output buffer new byte counter length cipher ctx encipher counter output buffer if output count pg output count 0 next bytes tmp rekey tmp generateoutput counterinc output_buffer cipher_ctx output_buffer output_count output_count nextbytes private void rekey byte key cipher ctx initialize key counter new byte all zero string length cipher ctx encipher all zero string counter arrays fill key byte 0 cipher_ctx allzerostring cipher_ctx allzerostring an offset to the bytes private synchronized int get bytes int count if fetch counter count output buffer length fetch counter 0 generate output return get bytes count int rv fetch counter fetch counter count return rv getbytes fetch_counter output_buffer fetch_counter generateoutput getbytes fetch_counter fetch_counter when this was not synchronized we were getting repeats override protected synchronized int next int bits int parameters bit table bits int offset get bytes parameters 0 int val output buffer offset if parameters 0 4 val output buffer offset 1 24 output buffer offset 2 16 output buffer offset 3 8 else if parameters 0 3 val output buffer offset 1 16 output buffer offset 2 8 else if parameters 0 2 val output buffer offset 2 8 return val parameters 1 bittable getbytes output_buffer output_buffer output_buffer output_buffer output_buffer output_buffer output_buffer private void accumulator init string digest throws no such algorithm exception fast pool message digest get instance digest slow pool message digest get instance digest entropy seen new hash map entropy source int accumulator_init nosuchalgorithmexception fast_pool messagedigest getinstance slow_pool messagedigest getinstance entropyseen hashmap entropysource override public int accept entropy entropy source source long data int entropy guess return accept entropy source data entropy guess 1 0 acceptentropy entropysource entropyguess acceptentropy entropyguess override public int accept entropy bytes entropy source source byte buf int offset int length double bias int total real entropy 0 for int i 0 i length i 8 long thingy 0 int bytes 0 for int j 0 j math min length i 8 j thingy thingy 8 buf j bytes total real entropy accept entropy source thingy bytes 8 bias return total real entropy acceptentropybytes entropysource totalrealentropy totalrealentropy acceptentropy totalrealentropy private int accept entropy entropy source source long data int entropy guess double bias return accept entropy data source int bias math min 32 math min estimate entropy source data entropy guess acceptentropy entropysource entropyguess accept_entropy estimateentropy entropyguess private int accept entropy long data entropy source source int actual entropy boolean performed pool reseed false byte b new byte byte data byte data 8 byte data 16 byte data 24 byte data 32 byte data 40 byte data 48 byte data 56 synchronized this fast select fast select message digest pool fast select fast pool slow pool pool update b if fast select fast entropy actual entropy if fast entropy fast threshold fast pool reseed performed pool reseed true else slow entropy actual entropy if source null int contributed entropy entropy seen get source if contributed entropy null contributed entropy new int actual entropy entropy seen put source contributed entropy else contributed entropy 0 actual entropy if slow entropy slow threshold 2 int kc 0 for map entry entropy source int e entropy seen entry set entropy source key e get key int v e get value if debug logger normal this key key v if v 0 slow threshold kc if kc slow k slow pool reseed performed pool reseed true break if debug core logger log this fast pool fast entropy t slow pool slow entropy logger normal system err println fast pool fast entropy t slow pool slow entropy if performed pool reseed seedfile null dont do this while synchronized on this since opening a file seems to be suprisingly slow on windows if logminor logger minor this writing seedfile write seed seedfile if logminor logger minor this written seedfile return actual entropy accept_entropy entropysource actualentropy performedpoolreseed fast_select fast_select messagedigest fast_select fast_pool slow_pool fast_select fast_entropy actualentropy fast_entropy fast_threshold fast_pool_reseed performedpoolreseed slow_entropy actualentropy contributedentropy entropyseen contributedentropy contributedentropy actualentropy entropyseen contributedentropy contributedentropy actualentropy slow_entropy slow_threshold entropysource entropyseen entryset entropysource getkey getvalue slow_threshold slow_k slow_pool_reseed performedpoolreseed fast_entropy tslow slow_entropy fast_entropy tslow slow_entropy performedpoolreseed write_seed actualentropy private int estimate entropy entropy source source long new val int delta int new val source last val int delta2 delta source last delta source last delta delta int delta3 delta2 source last delta2 source last delta2 delta2 if delta 0 delta delta if delta2 0 delta2 delta2 if delta3 0 delta3 delta3 if delta delta2 delta delta2 if delta delta3 delta delta3 delta is now minimum absolute delta round down by 1 bit on general principles and limit entropy entimate to 12 bits delta 1 delta 1 12 1 smear msbit right to make an n bit mask delta delta 8 delta delta 4 delta delta 2 delta delta 1 remove one bit to make this a logarithm delta 1 count the bits set in the word delta delta 1 0x555 delta delta 0x333 delta 2 0x333 delta delta 4 delta delta 8 source last val new val return delta 15 estimateentropy entropysource newval newval lastval lastdelta lastdelta lastdelta2 lastdelta2 lastval newval override public int accept timer entropy entropy source timer return accept timer entropy timer 1 0 accepttimerentropy entropysource accepttimerentropy override public int accept timer entropy entropy source timer double bias long now system current time millis return accept entropy timer now timer last val 32 bias accepttimerentropy entropysource currenttimemillis acceptentropy lastval if entropy estimation is supported this method will block until the specified number of bits of entropy are available if estimation isn t supported this method will return immediately override public void wait for entropy int bits waitforentropy private message digest reseed ctx private void reseed init string digest throws no such algorithm exception reseed ctx message digest get instance digest messagedigest reseed_ctx reseed_init nosuchalgorithmexception reseed_ctx messagedigest getinstance private void fast pool reseed long start time system current time millis byte v0 fast pool digest byte vi v0 for byte i 0 i pt i reseed ctx update vi 0 vi length reseed ctx update v0 0 v0 length reseed ctx update i vi reseed ctx digest v pt vi util make key vi tmp 0 tmp length rekey tmp arrays fill v0 byte 0 blank out for security fast entropy 0 if debug long end time system current time millis if end time start time 5000 logger normal this fast pool reseed took end time start time ms fast_pool_reseed starttime currenttimemillis fast_pool reseed_ctx reseed_ctx reseed_ctx reseed_ctx vpt makekey fast_entropy endtime currenttimemillis endtime starttime endtime starttime private void slow pool reseed byte slow hash slow pool digest fast pool update slow hash 0 slow hash length fast pool reseed slow entropy 0 entropy seen clear slow_pool_reseed slow_hash slow_pool fast_pool slow_hash slow_hash fast_pool_reseed slow_entropy entropyseen if the random source has any resources it wants to close it can do so when this method is called override public void close randomsource test routine public static void main string args throws exception yarrow r new yarrow new file dev urandom sha1 rijndael true false byte b new byte 1024 if args length 0 args 0 equals ignore case latency if args length 2 b new byte integer parse int args 1 long start system current time millis for int i 0 i 100 i r next bytes b system out println double system current time millis start 100 b length 1024 ms k start system current time millis for int i 0 i 1000 i r next int system out println double system current time millis start 1000 ms int start system current time millis for int i 0 i 1000 i r next long system out println double system current time millis start 1000 ms long else if args 0 equals ignore case randomness int kb integer parse int args 1 for int i 0 i kb i r next bytes b system out write b else if args 0 equals ignore case gathering system gc entropy source t new entropy source long start system current time millis for int i 0 i 100000 i r accept entropy t system current time millis 32 system err println double system current time millis start 100000 system gc start system current time millis for int i 0 i 100000 i r accept timer entropy t system err println double system current time millis start 100000 else if args 0 equals ignore case volume b new byte 1020 long duration system current time millis integer parse int args 1 while system current time millis duration r next bytes b system out write b else if args 0 equals stream rand file f new rand file args 1 entropy source rf new entropy source byte buffer new byte 131072 while true r accept entropy rf f next long 32 r next bytes buffer system out write buffer else if args 0 equals ignore case bitstream while true int v r next int for int i 0 i 32 i if v i 1 1 system out print 1 else system out print 0 else if args 0 equals ignore case sample if args length 1 args 1 equals general system out println next int for int i 0 i 3 i system out println r next int system out println next long for int i 0 i 3 i system out println r next long system out println next float for int i 0 i 3 i system out println r next float system out println next double for int i 0 i 3 i system out println r next double system out println next full float for int i 0 i 3 i system out println r next full float system out println next full double for int i 0 i 3 i system out println r next full double else if args 1 equals normalized for int i 0 i 20 i system out println r next double equalsignorecase parseint currenttimemillis nextbytes currenttimemillis currenttimemillis nextint currenttimemillis currenttimemillis nextlong currenttimemillis equalsignorecase parseint nextbytes equalsignorecase entropysource entropysource currenttimemillis acceptentropy currenttimemillis currenttimemillis currenttimemillis accepttimerentropy currenttimemillis equalsignorecase currenttimemillis parseint currenttimemillis nextbytes randfile randfile entropysource entropysource acceptentropy nextlong nextbytes equalsignorecase nextint equalsignorecase nextint nextint nextlong nextlong nextfloat nextfloat nextdouble nextdouble nextfullfloat nextfullfloat nextfulldouble nextfulldouble nextdouble private void consume string string str byte b try b str get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e consume bytes b consumestring getbytes unsupportedencodingexception consumebytes private void consume bytes byte bytes if fast select fast pool update bytes 0 bytes length else slow pool update bytes 0 bytes length fast select fast select consumebytes fast_select fast_pool slow_pool fast_select fast_select logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private final string possible values new string client request scheduler priority hard client request scheduler priority soft priority scheduler callback client request scheduler cs this cs cs possiblevalues clientrequestscheduler priority_hard clientrequestscheduler priority_soft priorityschedulercallback clientrequestscheduler override public string get if cs null return cs get choosen priority scheduler else return client request scheduler priority hard getchoosenpriorityscheduler clientrequestscheduler priority_hard override public void set string val throws invalid config value exception string value if val null val equals ignore case get return if val equals ignore case client request scheduler priority hard value client request scheduler priority hard else if val equals ignore case client request scheduler priority soft value client request scheduler priority soft else throw new invalid config value exception invalid priority scheme cs set priority scheduler value invalidconfigvalueexception equalsignorecase equalsignorecase clientrequestscheduler priority_hard clientrequestscheduler priority_hard equalsignorecase clientrequestscheduler priority_soft clientrequestscheduler priority_soft invalidconfigvalueexception setpriorityscheduler public string get possible values return possible values getpossiblevalues possiblevalues public client request scheduler boolean for inserts boolean forss ks random source random request starter starter node node node client core core sub config sc string name client context context this is insert scheduler for inserts this isssk scheduler forss ks sched core client request scheduler core create node for inserts forss ks node db cooldown period core client database executor this context sched transient new client request scheduler non persistent this for inserts forss ks persistent cooldown queue sched core persistent cooldown queue this database executor core client database executor this datastore checker core store checker this starter starter this random random this node node this client context context this name name sc register name priority policy priority hard name hash code true false request starter group scheduler forss ks ssk chk for inserts inserts requests request starter group scheduler long new priority scheduler callback this this choosen priority scheduler sc get string name priority policy if for inserts offered keys new offered keys list request starter number of priority classes for short i 0 i request starter number of priority classes i offered keys i new offered keys list core random i forss ks else offered keys null if for inserts transient cooldown queue new request cooldown queue cooldown period else transient cooldown queue null job runner client context job runner clientrequestscheduler forinserts forssks randomsource requeststarter nodeclientcore subconfig clientcontext isinsertscheduler forinserts issskscheduler forssks schedcore clientrequestschedulercore forinserts forssks cooldown_period clientdatabaseexecutor schedtransient clientrequestschedulernonpersistent forinserts forssks persistentcooldownqueue schedcore persistentcooldownqueue databaseexecutor clientdatabaseexecutor datastorechecker storechecker clientcontext _priority_policy priority_hard hashcode requeststartergroup forssks forinserts requeststartergroup schedulerlong priorityschedulercallback choosenpriorityscheduler getstring _priority_policy forinserts offeredkeys offeredkeyslist requeststarter number_of_priority_classes requeststarter number_of_priority_classes offeredkeys offeredkeyslist forssks offeredkeys forinserts transientcooldownqueue requestcooldownqueue cooldown_period transientcooldownqueue jobrunner clientcontext jobrunner public static void load key listeners final object container container client context context object set has key listener results db4o bugs query container has key listener class for has key listener l results container activate l 1 try if l is cancelled container continue key listener listener l make key listener container context if listener null if listener isssk context get ssk fetch scheduler add persistent pending keys listener else context get chk fetch scheduler add persistent pending keys listener system err println loaded request key listener listener for l catch key listener construction exception e system err println failed to load request bloom filters e print stack trace logger error client request scheduler core class failed to load request bloom filters e e catch throwable t probably an error on last startup logger error client request scheduler core class failed to load request t t system err println failed to load request t t print stack trace container deactivate l 1 loadkeylisteners objectcontainer clientcontext objectset haskeylistener db4obugs haskeylistener haskeylistener iscancelled keylistener makekeylistener getsskfetchscheduler addpersistentpendingkeys getchkfetchscheduler addpersistentpendingkeys keylistenerconstructionexception printstacktrace clientrequestschedulercore clientrequestschedulercore printstacktrace public void start node client core core sched core start core queue fill request starter queue nodeclientcore schedcore queuefillrequeststarterqueue called by the config callback param val protected synchronized void set priority scheduler string val choosen priority scheduler val setpriorityscheduler choosenpriorityscheduler public void register insert final sendable request req boolean persistent boolean regme only object container container register insert req persistent regme only database executor on thread container registerinsert sendablerequest regmeonly objectcontainer registerinsert regmeonly databaseexecutor onthread public void register insert final sendable request req boolean persistent boolean regme only boolean on database thread object container container if is insert scheduler throw new illegal argument exception adding a sendable insert to a request scheduler if persistent if on database thread if regme only long bootid 0 boolean queue full job runner get queue size native thread norm priority queue threshold if queue full bootid this node bootid final register me regme new register me req req get priority class container sched core null bootid container store regme if logminor logger minor this added insert register me regme if queue full job runner queue new db job public void run object container container client context context container delete regme if req is cancelled container if logminor logger minor this request already cancelled return if container ext is active req logger error this already active req in delayed insert register container activate req 1 register insert req true false true container container deactivate req 1 native thread norm priority false else sched core rerun register me runner job runner container deactivate req 1 return sched core inner register req random container null starter wake up else job runner queue new db job public void run object container container client context context if container ext is active req logger error this already active req in off thread insert register container activate req 1 sched core inner register req random container null container deactivate req 1 native thread norm priority false else sched transient inner register req random null null starter wake up registerinsert sendablerequest regmeonly ondatabasethread objectcontainer isinsertscheduler illegalargumentexception sendableinsert ondatabasethread regmeonly queuefull jobrunner getqueuesize nativethread norm_priority queue_threshold queuefull registerme registerme getpriorityclass schedcore registerme queuefull jobrunner dbjob objectcontainer clientcontext iscancelled isactive registerinsert nativethread norm_priority schedcore rerunregistermerunner jobrunner schedcore innerregister wakeup jobrunner dbjob objectcontainer clientcontext isactive schedcore innerregister nativethread norm_priority schedtransient innerregister wakeup register a group of requests not inserts a got key listener and or one or more sendable get s param listener listens for specific keys can be null if the listener is already registered i e on retrying param getters the actual requests to register to the request sender queue param persistent true if the request is persistent param on database thread true if we are running on the database thread note delayed store check probably not in store is unnecessary because we only register the listener once throws fetch exception public void register final has key listener has listener final sendable get getters final boolean persistent boolean on database thread object container container final block set blocks final boolean no check store throws key listener construction exception if logminor logger minor this register persistent has listener getters if is insert scheduler illegal state exception e new illegal state exception finish register on an insert scheduler throw e if persistent if on database thread inner register has listener getters blocks no check store container else job runner queue new db job public void run object container container client context context register off thread would be pointless because this is a separate job if has listener null if container ext is active has listener logger error this already active in delayed register has listener container activate has listener 1 if getters null for int i 0 i getters length i if container ext is active getters i logger error this already active in delayed register getters i container activate getters i 1 try inner register has listener getters blocks no check store container catch key listener construction exception e logger error this registration failed to create bloom filters e on has listener e if has listener null container deactivate has listener 1 if getters null for int i 0 i getters length i container deactivate getters i 1 native thread norm priority false else final key listener listener if has listener null listener has listener make key listener container client context if listener null sched transient add pending keys listener else logger normal this no key listener for has listener else listener null if getters null no check store for sendable get getter getters datastore checker queue transient request getter blocks else boolean any valid false for int i 0 i getters length i if getters i is cancelled null getters i is empty null any valid true finish register getters false on database thread container any valid null gotkeylistener sendableget ondatabasethread delayedstorecheck probablynotinstore fetchexception haskeylistener haslistener sendableget ondatabasethread objectcontainer blockset nocheckstore keylistenerconstructionexception haslistener isinsertscheduler illegalstateexception illegalstateexception finishregister ondatabasethread innerregister haslistener nocheckstore jobrunner dbjob objectcontainer clientcontext registeroffthread haslistener isactive haslistener haslistener haslistener isactive innerregister haslistener nocheckstore keylistenerconstructionexception haslistener haslistener haslistener nativethread norm_priority keylistener haslistener haslistener makekeylistener clientcontext schedtransient addpendingkeys keylistener haslistener nocheckstore sendableget datastorechecker queuetransientrequest anyvalid iscancelled isempty anyvalid finishregister ondatabasethread anyvalid private void inner register final has key listener has listener final sendable get getters final block set blocks boolean no check store object container container throws key listener construction exception final key listener listener if has listener null listener has listener make key listener container client context sched core add pending keys listener container store has listener else listener null avoid np es due to deactivation if getters null for sendable get getter getters container activate getter 1 container store getter if is insert scheduler throw new illegal state exception finish register on an insert scheduler if no check store check the datastore before proceding for sendable get getter getters container activate getter 1 datastore checker queue persistent request getter blocks container container deactivate getter 1 else we have already checked the datastore this is a retry the listener hasn t been unregistered this finish register getters true true container true null innerregister haskeylistener haslistener sendableget blockset nocheckstore objectcontainer keylistenerconstructionexception keylistener haslistener haslistener makekeylistener clientcontext schedcore addpendingkeys haslistener npes sendableget isinsertscheduler illegalstateexception finishregister nocheckstore sendableget datastorechecker queuepersistentrequest finishregister void finish register final sendable get getters boolean persistent boolean on database thread object container container final boolean any valid final datastore checker item reg if is insert scheduler illegal state exception e new illegal state exception finish register on an insert scheduler if on database thread persistent for int i 0 i getters length i if persistent container activate getters i 1 getters i internal error e this container client context persistent if persistent container deactivate getters i 1 throw e if persistent add to the persistent registration queue if on database thread if database executor on thread throw new illegal state exception not on database thread if persistent container activate getters 1 if logminor logger minor this finish register for getters if any valid boolean were any valid false for int i 0 i getters length i sendable get getter getters i container activate getter 1 if getter is cancelled container getter is empty container were any valid true getter pre register container client context true sched core inner register getter random container getters else getter pre register container client context false if were any valid logger normal this no requests valid getters else logger normal this no valid requests passed in getters if reg null container delete reg maybe fill starter queue container client context getters starter wake up else job runner queue new db job public void run object container container client context context if logminor logger minor this finish register for getters boolean were any valid false for sendable get getter getters if container ext is active getter logger error this already active in delayed finish register getter container activate getter 1 if getter is cancelled container getter is empty container were any valid true getter pre register container client context true sched core inner register getter random container getters else getter pre register container client context false container deactivate getter 1 if were any valid logger normal this no requests valid getters if reg null container delete reg maybe fill starter queue container context getters starter wake up native thread norm priority 1 false else register immediately for int i 0 i getters length i if any valid getters i is cancelled null getters i is empty null getters i pre register container client context false continue else getters i pre register container client context true sched transient inner register getters i random null getters starter wake up finishregister sendableget ondatabasethread objectcontainer anyvalid datastorecheckeritem isinsertscheduler illegalstateexception illegalstateexception finishregister ondatabasethread internalerror clientcontext ondatabasethread databaseexecutor onthread illegalstateexception finishregister anyvalid wereanyvalid sendableget iscancelled isempty wereanyvalid preregister clientcontext schedcore innerregister preregister clientcontext wereanyvalid maybefillstarterqueue clientcontext wakeup jobrunner dbjob objectcontainer clientcontext finishregister wereanyvalid sendableget isactive finishregister iscancelled isempty wereanyvalid preregister clientcontext schedcore innerregister preregister clientcontext wereanyvalid maybefillstarterqueue wakeup nativethread norm_priority anyvalid iscancelled isempty preregister clientcontext preregister clientcontext schedtransient innerregister wakeup private void maybe fill starter queue object container container client context context sendable request might be active synchronized this if starter queue size max starter queue size 2 return fill request starter queue container context might be active maybefillstarterqueue objectcontainer clientcontext sendablerequest mightbeactive starterqueue max_starter_queue_size fillrequeststarterqueue mightbeactive public chosen block get better non persistent request short prio int retry count short fuzz 1 if priority soft equals choosen priority scheduler fuzz 1 else if priority hard equals choosen priority scheduler fuzz 0 return sched core remove first transient fuzz random offered keys starter sched transient prio retry count client context null chosenblock getbetternonpersistentrequest retrycount priority_soft choosenpriorityscheduler priority_hard choosenpriorityscheduler schedcore removefirsttransient offeredkeys schedtransient retrycount clientcontext public void remove running request sendable request request synchronized starter queue for int i 0 i running persistent requests size i if running persistent requests get i request running persistent requests remove i i if logminor logger minor this removed running request request size now running persistent requests size removerunningrequest sendablerequest starterqueue runningpersistentrequests runningpersistentrequests runningpersistentrequests runningpersistentrequests public boolean is running or queued persistent request sendable request request synchronized starter queue for int i 0 i running persistent requests size i if running persistent requests get i request return true for persistent chosen request req starter queue if req request request return true return false isrunningorqueuedpersistentrequest sendablerequest starterqueue runningpersistentrequests runningpersistentrequests persistentchosenrequest starterqueue called by request starter to find a request to run public chosen block grab request while true persistent chosen request req group null synchronized starter queue short best priority short max value int best retry count integer max value for persistent chosen request req starter queue if req prio best priority req prio best priority req retry count best retry count best priority req prio best retry count req retry count req group req if req group null try to find a better non persistent request if logminor logger minor this persistent request req group prio req group prio retry count req group retry count chosen block better get better non persistent request req group prio req group retry count if better null if better get priority req group prio logger error this selected better as better than req group but isn t better return better if req group null queue fill request starter queue return get better non persistent request short max value integer max value chosen block block int final length 0 synchronized starter queue block req group grab not started client context fast weak random this if block null for int i 0 i starter queue size i if starter queue get i req group starter queue remove i if logminor logger minor this removed req group from starter queue because is empty i else final length starter queue get i size not started continue else prevent this request being selected even though we may remove the pcr from the starter queue in the very near future when the pcr finishes the requests will be un blocked if running persistent requests contains req group request running persistent requests add req group request if final length max starter queue size queue fill request starter queue if logminor logger minor this grab request returning block for req group return block requeststarter chosenblock grabrequest persistentchosenrequest reqgroup starterqueue bestpriority max_value bestretrycount max_value persistentchosenrequest starterqueue bestpriority bestpriority retrycount bestretrycount bestpriority bestretrycount retrycount reqgroup reqgroup reqgroup reqgroup retrycount reqgroup retrycount chosenblock getbetternonpersistentrequest reqgroup reqgroup retrycount getpriority reqgroup reqgroup reqgroup queuefillrequeststarterqueue getbetternonpersistentrequest max_value max_value chosenblock finallength starterqueue reqgroup grabnotstarted clientcontext fastweakrandom starterqueue starterqueue reqgroup starterqueue reqgroup finallength starterqueue sizenotstarted runningpersistentrequests reqgroup runningpersistentrequests reqgroup finallength max_starter_queue_size queuefillrequeststarterqueue grabrequest reqgroup public void queue fill request starter queue if system current time millis next queue fill request starter queue return if starter queue length max starter queue size 2 return job runner queue request starter queue filler native thread max priority true queuefillrequeststarterqueue currenttimemillis nextqueuefillrequeststarterqueue starterqueuelength max_starter_queue_size jobrunner requeststarterqueuefiller nativethread max_priority private int starter queue length int length 0 synchronized starter queue for persistent chosen request request starter queue length request size not started return length starterqueuelength starterqueue persistentchosenrequest starterqueue sizenotstarted param request param container return true if the queue is now full over full boolean add to starter queue sendable request request object container container if logminor logger minor this adding to starter queue request container activate request 1 persistent chosen request chosen try chosen new persistent chosen request request request get priority class container request get retry count container client request scheduler this client context catch no valid blocks exception e return false if logminor logger minor this created pcr chosen container deactivate request 1 boolean dump new false synchronized starter queue for persistent chosen request req starter queue if req request request logger error this already on starter queue req for request new exception debug dump new true break if dump new starter queue add chosen int length starter queue length length chosen size not started running persistent requests add request if logminor logger minor this added to running persistent requests size now running persistent requests size request return length max starter queue size if dump new chosen on dumped sched core container false return false addtostarterqueue sendablerequest objectcontainer persistentchosenrequest persistentchosenrequest getpriorityclass getretrycount clientrequestscheduler clientcontext novalidblocksexception dumpnew starterqueue persistentchosenrequest starterqueue dumpnew dumpnew starterqueue starterqueuelength sizenotstarted runningpersistentrequests runningpersistentrequests max_starter_queue_size dumpnew ondumped schedcore void remove from starter queue sendable request req object container container boolean req already active persistent chosen request dumped null synchronized starter queue for int i 0 i starter queue size i persistent chosen request pcr starter queue get i if pcr request req starter queue remove i dumped pcr break if dumped null dumped on dumped sched core container req already active removefromstarterqueue sendablerequest objectcontainer reqalreadyactive persistentchosenrequest starterqueue starterqueue persistentchosenrequest starterqueue starterqueue ondumped schedcore reqalreadyactive int starter queue size synchronized starter queue return starter queue size starterqueuesize starterqueue starterqueue private db job request starter queue filler new db job public void run object container container client context context fill request starter queue container context null dbjob requeststarterqueuefiller dbjob objectcontainer clientcontext fillrequeststarterqueue private void fill request starter queue object container container client context context sendable request might be active if logminor logger minor this filling request queue ssk isssk scheduler insert is insert scheduler long no later than long max value if is insert scheduler no later than move keys from cooldown queue persistent cooldown queue true container no later than math min no later than move keys from cooldown queue transient cooldown queue false container if anything has been re added the request starter will have been woken up short fuzz 1 if priority soft equals choosen priority scheduler fuzz 1 else if priority hard equals choosen priority scheduler fuzz 0 boolean added false synchronized starter queue if logminor isssk scheduler is insert scheduler logger minor this scheduling chk fetches for sendable request req running persistent requests boolean was active container ext is active req if was active container activate req 1 logger minor this running persistent request req if was active container deactivate req 1 recompute starter queue length int length 0 persistent chosen request old null for persistent chosen request req starter queue if old req logger error this duplicate chosen requests on queue req if old null old request req request logger error this duplicate request on queue old vs req both req request boolean ignore active false if might be active null for sendable request tmp might be active if tmp req request ignore active true if ignore active if container ext is active req request logger error this request already activated req request for req while checking request queue in filling request queue else if logminor logger minor this not already activated for req in while checking request queue in filling request queue else if logminor logger minor this ignoring active because just registered req request req prune duplicates client request scheduler this old req length req size not started if logminor logger minor this queue size length ssk isssk scheduler insert is insert scheduler if length max starter queue size 3 4 if length warning starter queue size logger error this queue already full length return if isssk scheduler is insert scheduler logger minor this scheduling chk fetches boolean added more false while true sendable request request sched core remove first inner fuzz random offered keys starter sched transient false true short max value integer max value context container if request null synchronized client request scheduler this don t wake up for a while but no later than the time we expect the next item to come off the cooldown queue if added next queue fill request starter queue system current time millis wait after nothing to start if next queue fill request starter queue no later than next queue fill request starter queue no later than 1 if added more starter wake up return boolean full add to starter queue request container container deactivate request 1 if added starter wake up else added more true added true if full if added more starter wake up return fillrequeststarterqueue objectcontainer clientcontext sendablerequest mightbeactive issskscheduler isinsertscheduler nolaterthan max_value isinsertscheduler nolaterthan movekeysfromcooldownqueue persistentcooldownqueue nolaterthan nolaterthan movekeysfromcooldownqueue transientcooldownqueue priority_soft choosenpriorityscheduler priority_hard choosenpriorityscheduler starterqueue issskscheduler isinsertscheduler sendablerequest runningpersistentrequests wasactive isactive wasactive wasactive starterqueuelength persistentchosenrequest persistentchosenrequest starterqueue ignoreactive mightbeactive sendablerequest mightbeactive ignoreactive ignoreactive isactive pruneduplicates clientrequestscheduler sizenotstarted issskscheduler isinsertscheduler max_starter_queue_size warning_starter_queue_size issskscheduler isinsertscheduler addedmore sendablerequest schedcore removefirstinner offeredkeys schedtransient max_value max_value clientrequestscheduler nextqueuefillrequeststarterqueue currenttimemillis wait_after_nothing_to_start nextqueuefillrequeststarterqueue nolaterthan nextqueuefillrequeststarterqueue nolaterthan addedmore wakeup addtostarterqueue wakeup addedmore addedmore wakeup compare a recently registered sendable request to what is already on the starter queue if it is better kick out stuff from the queue until we are just over the limit param req param container public void maybe add to starter queue sendable request req object container container sendable request might be active short prio req get priority class container int retry count req get retry count if logminor logger minor this maybe adding to starter queue prio prio retry count retry count boolean logdebug logger should log logger debug this synchronized starter queue boolean better than some false int size 0 persistent chosen request prev null for persistent chosen request old starter queue if old request req wait for a reselect otherwise we can starve other requests note that this happens with persistent sbi s they are added at the new retry count before being removed at the old retry count if logminor logger minor this already on starter queue old for req return if prev old logger error this on starter queue twice prev for prev request if prev null prev request old request logger error this request on starter queue twice prev for prev request vs old for old request boolean ignore active false if might be active null for sendable request tmp might be active if tmp old request ignore active true if ignore active if container ext is active old request logger error this request already activated old request for old while checking request queue in maybe add to starter queue for req else if logdebug logger debug this not already activated for old in while checking request queue in maybe add to starter queue for req else if logminor logger minor this ignoring active because just registered old request in maybe add to starter queue for req size old size not started if old prio prio old prio prio old retry count retry count better than some true if old request req return prev old if size max starter queue size better than some if logminor logger minor this not adding to starter queue over limit and req not better than any queued requests return add to starter queue req container trim starter queue container sendablerequest maybeaddtostarterqueue sendablerequest objectcontainer sendablerequest mightbeactive getpriorityclass retrycount getretrycount retrycount shouldlog starterqueue betterthansome persistentchosenrequest persistentchosenrequest starterqueue ignoreactive mightbeactive sendablerequest mightbeactive ignoreactive ignoreactive isactive maybeaddtostarterqueue maybeaddtostarterqueue maybeaddtostarterqueue sizenotstarted retrycount retrycount betterthansome max_starter_queue_size betterthansome addtostarterqueue trimstarterqueue private void trim starter queue object container container array list persistent chosen request dumped null synchronized starter queue int length starter queue length while length max starter queue size find the lowest priority retry count request if we can dump it without going below the limit then do so if we can t return persistent chosen request worst null short worst prio 1 int worst retry count 1 int worst index 1 int worst length 1 if starter queue is empty break length 0 for int i 0 i starter queue size i persistent chosen request req starter queue get i short prio req prio int retry count req retry count int size req size not started length size if prio worst prio prio worst prio retry count worst retry count worst prio prio worst retry count retry count worst req worst index i worst length size continue int length after length worst length if length after max starter queue size if dumped null dumped new array list persistent chosen request 2 dumped add worst starter queue remove worst index if length after max starter queue size break else can t remove any more break if dumped null return for persistent chosen request req dumped req on dumped sched core container false trimstarterqueue objectcontainer arraylist persistentchosenrequest starterqueue starterqueuelength max_starter_queue_size persistentchosenrequest worstprio worstretrycount worstindex worstlength starterqueue isempty starterqueue persistentchosenrequest starterqueue retrycount retrycount sizenotstarted worstprio worstprio retrycount worstretrycount worstprio worstretrycount retrycount worstindex worstlength lengthafter worstlength lengthafter max_starter_queue_size arraylist persistentchosenrequest starterqueue worstindex lengthafter max_starter_queue_size persistentchosenrequest ondumped schedcore remove a key listener from the list of key listeners param getter param complain public void remove pending keys key listener getter boolean complain boolean found sched transient remove pending keys getter found sched core remove pending keys getter if complain found logger error this listener not found when removing getter keylistener keylisteners removependingkeys keylistener schedtransient removependingkeys schedcore removependingkeys remove a key listener from the list of key listeners param getter param complain public void remove pending keys has key listener getter boolean complain boolean found sched transient remove pending keys getter found sched core remove pending keys getter if complain found logger error this listener not found when removing getter keylistener keylisteners removependingkeys haskeylistener schedtransient removependingkeys schedcore removependingkeys public void reregister all final client requester request object container container sched transient reregister all request random this null client context sched core reregister all request random this container client context starter wake up reregisterall clientrequester objectcontainer schedtransient reregisterall clientcontext schedcore reregisterall clientcontext wakeup public string get choosen priority scheduler return choosen priority scheduler getchoosenpriorityscheduler choosenpriorityscheduler public synchronized void succeeded final base sendable get succeeded boolean persistent if persistent job runner queue new db job public void run object container container client context context if container ext is active succeeded logger error this already active in succeeded succeeded container activate succeeded 1 sched core succeeded succeeded container container deactivate succeeded 1 trip pending priority false boost the priority so the persistent chosen request gets deleted reasonably quickly else sched transient succeeded succeeded null basesendableget jobrunner dbjob objectcontainer clientcontext isactive schedcore trip_pending_priority persistentchosenrequest schedtransient public void run object container container client context context if container ext is active succeeded logger error this already active in succeeded succeeded container activate succeeded 1 sched core succeeded succeeded container container deactivate succeeded 1 objectcontainer clientcontext isactive schedcore public void trip pending key final key block block if logminor logger minor this trip pending key block get key if offered keys null for int i 0 i offered keys length i offered keys i remove block get key final key key block get key sched transient trip pending key key block null client context if sched core any probably want key key client context job runner queue new db job public void run object container container client context context if logminor logger minor this trip pending key for key sched core trip pending key key block container client context trip pending priority false else sched core count negative trippendingkey keyblock trippendingkey getkey offeredkeys offeredkeys offeredkeys getkey getkey schedtransient trippendingkey clientcontext schedcore anyprobablywantkey clientcontext jobrunner dbjob objectcontainer clientcontext trippendingkey schedcore trippendingkey clientcontext trip_pending_priority schedcore countnegative job runner queue new db job public void run object container container client context context if logminor logger minor this trip pending key for key sched core trip pending key key block container client context jobrunner dbjob objectcontainer clientcontext trippendingkey schedcore trippendingkey clientcontext if we want the offered key or if force is enabled queue it public void maybe queue offered key final key key boolean force if logminor logger minor this maybe queue offered key key force short priority short max value if force fixme what priority priority request starter bulk splitfile priority class priority sched transient get key prio key priority null client context if priority short max value offered keys priority queue key key starter wake up final short old prio priority job runner queue new db job public void run object container container client context context don t activate deactivate the key because it s not persistent in the first place short priority sched core get key prio key old prio container context if priority old prio return already on list at priority offered keys priority queue key key clone key starter wake up native thread norm priority false maybequeueofferedkey maybequeueofferedkey max_value requeststarter bulk_splitfile_priority_class schedtransient getkeyprio clientcontext max_value offeredkeys queuekey wakeup oldprio jobrunner dbjob objectcontainer clientcontext schedcore getkeyprio oldprio oldprio offeredkeys queuekey clonekey wakeup nativethread norm_priority public void run object container container client context context don t activate deactivate the key because it s not persistent in the first place short priority sched core get key prio key old prio container context if priority old prio return already on list at priority offered keys priority queue key key clone key starter wake up objectcontainer clientcontext schedcore getkeyprio oldprio oldprio offeredkeys queuekey clonekey wakeup public void dequeue offered key key key for int i 0 i offered keys length i offered keys i remove key dequeueofferedkey offeredkeys offeredkeys must be called from database thread public long queue cooldown client key key sendable get getter object container container if getter persistent return persistent cooldown queue add key get node key getter container else return transient cooldown queue add key get node key getter null queuecooldown clientkey sendableget objectcontainer persistentcooldownqueue getnodekey transientcooldownqueue getnodekey restore keys from the given cooldown queue find any keys that are due to be restored restore all requests both persistent and non persistent for those keys param queue param persistent param container return long max value if nothing is queued in the next wait after nothing to start millis the time at which the next key is due to be restored if there are keys queued to be restarted in the near future private long move keys from cooldown queue cooldown queue queue boolean persistent object container container if queue null return long max value long now system current time millis only go around once we will be called again if there are keys to move then request starter will not sleep because it will start them then it will come back here if we are off thread i e on the database thread then we will wake it up if we find keys and we ll be scheduled again fixme i think we need to restore all the listeners for a single key simultaneously to avoid some kind of race condition or could we just restore the one request on the queue maybe it s just a misguided optimisation iirc we had some severe problems when we didn t have this related to requests somehow being lost altogether is it essential we can save a query if it s not is this about requests or about keys should we limit all requests across any sendable request s to 3 every half hour for a specific key probably yes in which case can the cooldown queue be entirely in ram and would it be useful for it to be less disk more ram for fast nodes with little ram it would be bad final int max keys 20 object ret queue remove key before now wait after nothing to start container max keys if ret null return long max value if ret instanceof long return long ret key keys key ret for int j 0 j keys length j key key keys j if persistent container activate key 5 if logminor logger minor this restoring key key sendable get reqs sched core requests for key key container client context sendable get transient reqs sched transient requests for key key container client context if reqs null transient reqs null not an error as this can happen due to race conditions etc if logminor logger minor this restoring key but no keys queued for key if reqs null for int i 0 i reqs length i requests may or may not be returned activated from requests for key so don t check but do deactivate them once we re done with them container activate reqs i 1 reqs i requeue after cooldown key now container client context container deactivate reqs i 1 if transient reqs null for int i 0 i transient reqs length i transient reqs i requeue after cooldown key now container client context if persistent container deactivate key 5 return long max value max_value wait_after_nothing_to_start movekeysfromcooldownqueue cooldownqueue objectcontainer max_value currenttimemillis requeststarter sendablerequest max_keys removekeybefore wait_after_nothing_to_start max_keys max_value sendableget schedcore requestsforkey clientcontext sendableget transientreqs schedtransient requestsforkey clientcontext transientreqs requestsforkey requeueaftercooldown clientcontext transientreqs transientreqs transientreqs requeueaftercooldown clientcontext max_value public long count transient queued requests return sched transient count queued requests null client context counttransientqueuedrequests schedtransient countqueuedrequests clientcontext public keys fetching locally fetching keys return sched core keysfetchinglocally fetchingkeys schedcore public void remove fetching key key key sched core remove fetching key key removefetchingkey schedcore removefetchingkey public void remove transient insert fetching sendable insert insert object token sched core remove transient insert fetching insert token removetransientinsertfetching sendableinsert schedcore removetransientinsertfetching public void call failure final sendable get get final low level get exception e int prio boolean persistent if persistent get on failure e null null client context else job runner queue new db job public void run object container container client context context if container ext is active get logger error this already active get in call failure request container activate get 1 get on failure e null container client context container deactivate get 1 prio false callfailure sendableget lowlevelgetexception onfailure clientcontext jobrunner dbjob objectcontainer clientcontext isactive callfailure onfailure clientcontext public void run object container container client context context if container ext is active get logger error this already active get in call failure request container activate get 1 get on failure e null container client context container deactivate get 1 objectcontainer clientcontext isactive callfailure onfailure clientcontext public void call failure final sendable insert insert final low level put exception e int prio boolean persistent if persistent insert on failure e null null client context else job runner queue new db job public void run object container container client context context if container ext is active insert logger error this already active insert in call failure insert container activate insert 1 insert on failure e null container context container deactivate insert 1 prio false callfailure sendableinsert lowlevelputexception onfailure clientcontext jobrunner dbjob objectcontainer clientcontext isactive callfailure onfailure public void run object container container client context context if container ext is active insert logger error this already active insert in call failure insert container activate insert 1 insert on failure e null container context container deactivate insert 1 objectcontainer clientcontext isactive callfailure onfailure public fec queue getfec queue return client context fec queue fecqueue getfecqueue clientcontext fecqueue public client context get context return client context clientcontext getcontext clientcontext return true unless the key was already present public boolean add to fetching key key return sched core add to fetching key addtofetching schedcore addtofetching public boolean add transient insert fetching sendable insert insert object token return sched core add transient insert fetching insert token addtransientinsertfetching sendableinsert schedcore addtransientinsertfetching public boolean has fetching key key key return sched core has key key hasfetchingkey schedcore haskey public long count persistent waiting keys object container container return sched core count waiting keys container countpersistentwaitingkeys objectcontainer schedcore countwaitingkeys public long count persistent queued requests object container container return sched core count queued requests container client context countpersistentqueuedrequests objectcontainer schedcore countqueuedrequests clientcontext public boolean is queue almost empty return starter queue size max starter queue size 4 isqueuealmostempty starterqueuesize max_starter_queue_size public boolean is insert scheduler return is insert scheduler isinsertscheduler isinsertscheduler public void remove from all requests by client request client requester client request sendable request get boolean dont complain object container container if get persistent sched core remove from all requests by client request get client request dont complain container else sched transient remove from all requests by client request get client request dont complain null removefromallrequestsbyclientrequest clientrequester clientrequest sendablerequest dontcomplain objectcontainer schedcore removefromallrequestsbyclientrequest clientrequest dontcomplain schedtransient removefromallrequestsbyclientrequest clientrequest dontcomplain public byte salt key key key message digest md sha256 get message digest md update key get routing key md update sched core global salt byte ret md digest sha256 return message digest md return ret saltkey messagedigest getmessagedigest getroutingkey schedcore globalsalt returnmessagedigest void add persistent pending keys key listener listener sched core add pending keys listener addpersistentpendingkeys keylistener schedcore addpendingkeys public boolean object can new object container container logger error this not storing client request scheduler in database new exception error return false objectcannew objectcontainer clientrequestscheduler public void wake starter starter wake up wakestarter wakeup public boolean cache inserts return this node client core cache inserts cacheinserts clientcore cacheinserts class alt persistent set t extends i persistent extends alt btree t implements i persistent set t alt persistent set type class descriptor tp object unique true altpersistentset ipersistent altbtree ipersistentset altpersistentset classdescriptor tpobject public boolean is empty return n elems 0 isempty nelems public boolean contains object o if o instanceof i persistent key key new key i persistent o iterator i iterator key key ascent order return i has next return false ipersistent ipersistent ascent_order hasnext public object to array return to persistent array toarray topersistentarray public e e to array e arr return e super to array t arr toarray toarray public boolean add t obj return put new key obj obj public boolean remove object o t obj t o return remove if exists new btree key check key new key obj obj removeifexists btreekey checkkey public boolean equals object o if o this return true if o instanceof set return false collection c collection o if c size size return false return contains all c containsall public int hash code int h 0 iterator i iterator while i has next h i persistent i next get oid return h hashcode hasnext ipersistent getoid param baseuri base uri of the index exclude the tt index xml tt part param plugin respirator public index string baseuri plugin respirator plugin respirator if baseuri ends with baseuri this baseuri baseuri this pr plugin respirator pluginrespirator pluginrespirator pluginrespirator endswith pluginrespirator fetch the main index file throws io exception throws fetch exception throws sax exception public synchronized void fetch throws io exception fetch exception sax exception fetch new progress ioexception fetchexception saxexception ioexception fetchexception saxexception public synchronized void fetch progress progress throws io exception fetch exception sax exception if fetched return progress set getting base index bucket bucket util fetch bucket baseuri default file pr progress set fetched base index try input stream is bucket get input stream parse is is close finally bucket free fetched true ioexception fetchexception saxexception fetchbucket default_file inputstream getinputstream private void parse input stream is throws sax exception io exception sax parser factory factory sax parser factory new instance try factory set namespace aware true factory set feature http xml org sax features namespaces true factory set feature http apache org xml features disallow doctype decl true sax parser sax parser factory newsax parser main index parser parser new main index parser sax parser parse is parser version parser get version if version 1 title parser get header title owner name parser get header owner owner email parser get header email sub indice list new array list string sub indice new tree map string string for string key parser get sub indice sub indice list add key sub indice put key index key xml collections sort sub indice list catch parser configuration exception e logger error this sax parser configuration exception e throw new sax exception e inputstream saxexception ioexception saxparserfactory saxparserfactory newinstance setnamespaceaware setfeature setfeature saxparser saxparser newsaxparser mainindexparser mainindexparser saxparser getversion getheader ownername getheader owneremail getheader subindicelist arraylist subindice treemap getsubindice subindicelist subindice index_ subindicelist parserconfigurationexception parserconfigurationexception saxexception protected string get sub index string keyword string md5 xml librarian md5 keyword int idx collections binary search sub indice list md5 if idx 0 idx idx 2 return sub indice get sub indice list get idx getsubindex xmllibrarian binarysearch subindicelist subindice subindicelist protected list uri wrapper search string keyword throws exception return search keyword new progress uriwrapper protected list uri wrapper search string keyword progress progress throws exception list uri wrapper result new linked list uri wrapper string sub index get sub index keyword try progress set getting subindex sub index to search for keyword bucket bucket util fetch bucket baseuri sub index pr progress set fetched subindex sub index to search for keyword sax parser factory factory sax parser factory new instance try factory set feature http apache org xml features disallow doctype decl true sax parser sax parser factory newsax parser input stream is bucket get input stream sax parser parse is new librarian handler keyword result is close catch throwable err err print stack trace throw new exception could not parse xml err to string finally bucket free catch exception e logger error this baseuri sub index could not be opened e to string e throw e return result uriwrapper uriwrapper linkedlist uriwrapper subindex getsubindex subindex fetchbucket subindex subindex saxparserfactory saxparserfactory newinstance setfeature saxparser saxparser newsaxparser inputstream getinputstream saxparser librarianhandler printstacktrace tostring subindex tostring public list uri wrapper search string keywords throws exception return search keywords new progress uriwrapper public list uri wrapper search string keywords progress progress throws exception list uri wrapper result null for string keyword keywords if keyword length 3 continue list uri wrapper s search keyword progress if result null result s else result retain all s if result null result new linked list uri wrapper return result uriwrapper uriwrapper uriwrapper retainall linkedlist uriwrapper protected byte buffer buf public byte buffer input stream byte array this array 0 array length bytebuffer bytebufferinputstream public byte buffer input stream byte array int offset int length this byte buffer wrap array offset length bytebufferinputstream bytebuffer this byte buffer wrap array offset length public byte buffer input stream byte buffer buf this buf buf bytebuffer bytebufferinputstream bytebuffer override public int read throws io exception try return buf get integer max value catch buffer underflow exception e return 1 ioexception max_value bufferunderflowexception public int remaining return buf remaining public boolean read boolean throws io exception try return buf get 0 catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readboolean ioexception bufferunderflowexception eofexception eofexception initcause public byte read byte throws io exception try return buf get catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readbyte ioexception bufferunderflowexception eofexception eofexception initcause public char read char throws io exception try return buf get char catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readchar ioexception getchar bufferunderflowexception eofexception eofexception initcause public double read double throws io exception try return buf get double catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readdouble ioexception getdouble bufferunderflowexception eofexception eofexception initcause public float read float throws io exception try return buf get float catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readfloat ioexception getfloat bufferunderflowexception eofexception eofexception initcause public void read fully byte b throws io exception try buf get b catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readfully ioexception bufferunderflowexception eofexception eofexception initcause public void read fully byte b int off int len throws io exception try buf get b off len catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readfully ioexception bufferunderflowexception eofexception eofexception initcause public int read int throws io exception try return buf get int catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readint ioexception getint bufferunderflowexception eofexception eofexception initcause public long read long throws io exception try return buf get long catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readlong ioexception getlong bufferunderflowexception eofexception eofexception initcause public short read short throws io exception try return buf get short catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readshort ioexception getshort bufferunderflowexception eofexception eofexception initcause public int read unsigned byte throws io exception try return buf get integer max value catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readunsignedbyte ioexception max_value bufferunderflowexception eofexception eofexception initcause public int read unsigned short throws io exception try return buf get short integer max value catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe readunsignedshort ioexception getshort max_value bufferunderflowexception eofexception eofexception initcause public int skip bytes int n throws io exception int skip math min n buf remaining buf position buf position skip return skip skipbytes ioexception public string readutf throws io exception return data input stream readutf this ioexception datainputstream deprecated link data input stream read line is deprecated so why not deprecated public string read line throws io exception hmmmm bad return new data input stream this read line datainputstream readline readline ioexception datainputstream readline slice a piece of byte buffer into a new byte buffer input stream param size public byte buffer input stream slice int size throws io exception try if buf remaining size throw new eof exception byte buffer bf2 buf slice bf2 limit size skip size return new byte buffer input stream bf2 catch buffer underflow exception e eof exception ioe new eof exception ioe init cause e throw ioe bytebuffer bytebufferinputstream bytebufferinputstream ioexception eofexception bytebuffer bytebufferinputstream bufferunderflowexception eofexception eofexception initcause private final linked list toadlet element toadlets private static class toadlet element public toadlet element toadlet t2 string url prefix t t2 prefix url prefix linkedlist toadletelement toadletelement toadletelement urlprefix urlprefix config callbacks private class f proxyssl callback extends boolean callback override public boolean get return ssl fproxysslcallback booleancallback override public void set boolean val throws invalid config value exception if get equals val return if ssl available throw new invalid config value exception enable ssl support before use ssl with fproxy ssl val throw new invalid config value exception cannot change ssl on the fly please restart freenet invalidconfigvalueexception invalidconfigvalueexception invalidconfigvalueexception throw new invalid config value exception cannot change ssl on the fly please restart freenet override public boolean is read only return true invalidconfigvalueexception isreadonly private static class f proxy passthru max size extends long callback override public long get return f proxy toadlet max length fproxypassthrumaxsize longcallback fproxytoadlet max_length override public void set long val throws invalid config value exception if get equals val return f proxy toadlet max length val invalidconfigvalueexception fproxytoadlet max_length private integer saved port override public integer get if saved port null saved port port return saved port savedport savedport savedport savedport override public void set integer new port throws node need restart exception if saved port int new port saved port port throw new node need restart exception port cannot change on the fly newport nodeneedrestartexception savedport newport savedport nodeneedrestartexception private class f proxy bindto callback extends string callback override public string get return bind to fproxybindtocallback stringcallback bindto override public void set string bind to throws invalid config value exception if bind to equals get try network interface set bind to bind to false simple toadlet server this bind to bind to catch io exception e this is an advanced option for reasons of reducing clutter but it is expected to be used by regular users not devs so we translate the error messages throw new invalid config value exception l10n could not change bind to error e get localized message bindto invalidconfigvalueexception bindto networkinterface setbindto bindto simpletoadletserver bindto bindto ioexception invalidconfigvalueexception couldnotchangebindto getlocalizedmessage private class f proxy allowed hosts callback extends string callback override public string get return network interface get allowed hosts fproxyallowedhostscallback stringcallback networkinterface getallowedhosts override public void set string allowed hosts if allowed hosts equals get network interface set allowed hosts allowed hosts allowedhosts allowedhosts networkinterface setallowedhosts allowedhosts private class f proxycss name callback extends string callback implements enumerable option callback override public string get return css theme code fproxycssnamecallback stringcallback enumerableoptioncallback csstheme override public void set string css name throws invalid config value exception if css name index of 1 css name index of 1 throw new invalid config value exception l10n illegalcss name css theme theme theme from name css name page maker set theme css theme if core node plugin manager null core node plugin manager setf proxy theme css theme cssname invalidconfigvalueexception cssname indexof cssname indexof invalidconfigvalueexception illegalcssname csstheme themefromname cssname pagemaker settheme csstheme pluginmanager pluginmanager setfproxytheme csstheme public string get possible values return theme possible values getpossiblevalues possiblevalues private class f proxycss override callback extends string callback override public string get return css override null css override to string fproxycssoverridecallback stringcallback cssoverride cssoverride tostring override public void set string val throws invalid config value exception if core null return if val equals get val equals css override null else file tmp new file val trim if core allow upload from tmp throw new invalid config value exception l10n css override not in uploads filename tmp to string else if tmp can read tmp is file throw new invalid config value exception l10n css override cant read filename tmp to string css override tmp get absolute file page maker set override css override invalidconfigvalueexception cssoverride allowuploadfrom invalidconfigvalueexception cssoverridenotinuploads tostring canread isfile invalidconfigvalueexception cssoverridecantread tostring cssoverride getabsolutefile pagemaker setoverride cssoverride private class f proxy enabled callback extends boolean callback override public boolean get synchronized simple toadlet server this return my thread null fproxyenabledcallback booleancallback simpletoadletserver mythread override public void set boolean val throws invalid config value exception if get equals val return synchronized simple toadlet server this if val start it my thread new thread simple toadlet server this simple toadlet server else my thread interrupt my thread null return create fproxy my thread set daemon true my thread start invalidconfigvalueexception simpletoadletserver mythread simpletoadletserver simpletoadletserver mythread mythread createfproxy mythread setdaemon mythread private final simple toadlet server ts f proxy advanced mode enabled callback simple toadlet server ts this ts ts simpletoadletserver fproxyadvancedmodeenabledcallback simpletoadletserver override public boolean get return ts is advanced mode enabled isadvancedmodeenabled override public void set boolean val throws invalid config value exception if get equals val return ts enable advanced mode val invalidconfigvalueexception enableadvancedmode private final simple toadlet server ts f proxy javascript enabled callback simple toadlet server ts this ts ts simpletoadletserver fproxyjavascriptenabledcallback simpletoadletserver override public boolean get return ts isf proxy javascript enabled isfproxyjavascriptenabled override public void set boolean val throws invalid config value exception if get equals val return ts enablef proxy javascript val invalidconfigvalueexception enablefproxyjavascript public void create fproxy synchronized this if have calledf proxy return have calledf proxy true bookmark manager new bookmark manager core try f proxy toadlet maybe createf proxy etc core core node core node config this bookmark manager catch io exception e logger error this could not start fproxy e e system err println could not start fproxy e print stack trace createfproxy havecalledfproxy havecalledfproxy bookmarkmanager bookmarkmanager fproxytoadlet maybecreatefproxyetc bookmarkmanager ioexception printstacktrace public synchronized void set core node client core core this core core setcore nodeclientcore create a simple toadlet server using the settings from the sub config the fproxy config public simple toadlet server sub config fproxy config bucket factory bucket factory executor executor throws io exception invalid config value exception this executor executor int config item order 0 fproxy config register enabled true config item order true true simple toadlet server enabled simple toadlet server enabled long new f proxy enabled callback boolean enabled fproxy config get boolean enabled fproxy config register ssl false config item order true true simple toadlet server ssl simple toadlet server ssl long new f proxyssl callback fproxy config register port default fproxy port config item order true true simple toadlet server port simple toadlet server port long new f proxy port callback false fproxy config register bind to network interface default bind to config item order true true simple toadlet server bind to simple toadlet server bind to long new f proxy bindto callback fproxy config register css clean config item order false false simple toadlet server css name simple toadlet server css name long new f proxycss name callback fproxy config register css override config item order true false simple toadlet server css override simple toadlet server css override long new f proxycss override callback fproxy config register advanced mode enabled false config item order true false simple toadlet server advanced mode simple toadlet server advanced mode long new f proxy advanced mode enabled callback this fproxy config register javascript enabled false config item order true false simple toadlet server enablejs simple toadlet server enablejs long new f proxy javascript enabled callback this fproxy config register has completed wizard false config item order true false simple toadlet server has completed wizard simple toadlet server has completed wizard long new boolean callback override public boolean get return fproxy has completed wizard override public void set boolean val throws invalid config value exception node need restart exception if get equals val return fproxy has completed wizard val fproxy has completed wizard fproxy config get boolean has completed wizard fproxy config register show panic button false config item order true true simple toadlet server panic button simple toadlet server panic button long new boolean callback override public boolean get return simple toadlet server is panic button to be shown override public void set boolean value if value simple toadlet server is panic button to be shown return else simple toadlet server is panic button to be shown value fproxy config register public gateway mode false config item order true true simple toadlet server public gateway mode simple toadlet server public gateway mode long new boolean callback override public boolean get return public gateway mode override public void set boolean val throws invalid config value exception node need restart exception public gateway mode val public gateway mode fproxy config get boolean public gateway mode this is off by default because for example firefox has a limit of 2 persistent connections per server but 8 non persistent connections per server we need 8 conns more than we need the efficiency gain of reusing connections especially on first install fproxy config register enable persistent connections false config item order true false simple toadlet server enable persistent connections simple toadlet server enable persistent connections long new boolean callback override public boolean get synchronized simple toadlet server this return enable persistent connections override public void set boolean val throws invalid config value exception synchronized simple toadlet server this enable persistent connections val enable persistent connections fproxy config get boolean enable persistent connections off by default i had hoped it would yield a significant performance boost to bootstrap performance on browsers with low numbers of simultaneous connections unfortunately the bottleneck appears to be that the node does very few local requests compared to external requests for anonymity s sake fproxy config register enable inline prefetch false config item order true false simple toadlet server enable inline prefetch simple toadlet server enable inline prefetch long new boolean callback override public boolean get synchronized simple toadlet server this return enable inline prefetch override public void set boolean val throws invalid config value exception synchronized simple toadlet server this enable inline prefetch val enable inline prefetch fproxy config get boolean enable inline prefetch fproxy config register enable activelinks false config item order false false simple toadlet server enable activelinks simple toadlet server enable activelinks long new boolean callback override public boolean get return enable activelinks override public void set boolean val throws invalid config value exception node need restart exception enable activelinks val enable activelinks fproxy config get boolean enable activelinks fproxy config register passthrough max size 2l 1024 1024 config item order true false simple toadlet server passthrough max size simple toadlet server passthrough max size long new f proxy passthru max size true f proxy toadlet max length fproxy config get long passthrough max size fproxy config register allowed hosts 127 0 0 1 0 0 0 0 0 0 0 1 config item order true true simple toadlet server allowed hosts simple toadlet server allowed hosts long new f proxy allowed hosts callback fproxy config register allowed hosts full access 127 0 0 1 0 0 0 0 0 0 0 1 config item order true true simple toadlet server allowed full access simple toadlet server allowed full access long new string callback override public string get return allowed full access get allowed hosts override public void set string val throws invalid config value exception allowed full access set allowed hosts val allowed full access new allowed hosts fproxy config get string allowed hosts full access fproxy config register do robots false config item order true false simple toadlet server do robots simple toadlet server do robots long new boolean callback override public boolean get return do robots override public void set boolean val throws invalid config value exception do robots val do robots fproxy config get boolean do robots simple toadlet server is panic button to be shown fproxy config get boolean show panic button this bf bucket factory port fproxy config get int port bind to fproxy config get string bind to string css name fproxy config get string css if css name index of 1 css name index of 1 throw new invalid config value exception css name must not contain slashes or colons css theme theme theme from name css name page maker new page maker css theme if fproxy config get option css override is default css override new file fproxy config get string css override page maker set override css override else css override null this advanced mode enabled fproxy config get boolean advanced mode enabled toadlets new linked list toadlet element if ssl available ssl fproxy config get boolean ssl this allowed hosts fproxy config get string allowed hosts if enabled logger normal simple toadlet server this not starting f proxy as it s disabled system out println not starting f proxy as it s disabled else maybe get network interface my thread new thread this simple toadlet server my thread set daemon true register static toadlet and startup toadlet static toadlet statictoadlet new static toadlet register statictoadlet static false false freenet is starting up page to be removed at remove startup toadlet startup toadlet new startup toadlet statictoadlet register startup toadlet false false simpletoadletserver subconfig simpletoadletserver subconfig fproxyconfig bucketfactory bucketfactory ioexception invalidconfigvalueexception configitemorder fproxyconfig configitemorder simpletoadletserver simpletoadletserver enabledlong fproxyenabledcallback fproxyconfig getboolean fproxyconfig configitemorder simpletoadletserver simpletoadletserver ssllong fproxysslcallback fproxyconfig default_fproxy_port configitemorder simpletoadletserver simpletoadletserver portlong fproxyportcallback fproxyconfig bindto networkinterface default_bind_to configitemorder simpletoadletserver bindto simpletoadletserver bindtolong fproxybindtocallback fproxyconfig configitemorder simpletoadletserver cssname simpletoadletserver cssnamelong fproxycssnamecallback fproxyconfig cssoverride configitemorder simpletoadletserver cssoverride simpletoadletserver cssoverridelong fproxycssoverridecallback fproxyconfig advancedmodeenabled configitemorder simpletoadletserver advancedmode simpletoadletserver advancedmodelong fproxyadvancedmodeenabledcallback fproxyconfig javascriptenabled configitemorder simpletoadletserver simpletoadletserver enablejslong fproxyjavascriptenabledcallback fproxyconfig hascompletedwizard configitemorder simpletoadletserver hascompletedwizard simpletoadletserver hascompletedwizardlong booleancallback fproxyhascompletedwizard invalidconfigvalueexception nodeneedrestartexception fproxyhascompletedwizard fproxyhascompletedwizard fproxyconfig getboolean hascompletedwizard fproxyconfig showpanicbutton configitemorder simpletoadletserver panicbutton simpletoadletserver panicbuttonlong booleancallback simpletoadletserver ispanicbuttontobeshown simpletoadletserver ispanicbuttontobeshown simpletoadletserver ispanicbuttontobeshown fproxyconfig publicgatewaymode configitemorder simpletoadletserver publicgatewaymode simpletoadletserver publicgatewaymodelong booleancallback publicgatewaymode invalidconfigvalueexception nodeneedrestartexception publicgatewaymode publicgatewaymode fproxyconfig getboolean publicgatewaymode fproxyconfig enablepersistentconnections configitemorder simpletoadletserver enablepersistentconnections simpletoadletserver enablepersistentconnectionslong booleancallback simpletoadletserver enablepersistentconnections invalidconfigvalueexception simpletoadletserver enablepersistentconnections enablepersistentconnections fproxyconfig getboolean enablepersistentconnections fproxyconfig enableinlineprefetch configitemorder simpletoadletserver enableinlineprefetch simpletoadletserver enableinlineprefetchlong booleancallback simpletoadletserver enableinlineprefetch invalidconfigvalueexception simpletoadletserver enableinlineprefetch enableinlineprefetch fproxyconfig getboolean enableinlineprefetch fproxyconfig enableactivelinks configitemorder simpletoadletserver enableactivelinks simpletoadletserver enableactivelinkslong booleancallback enableactivelinks invalidconfigvalueexception nodeneedrestartexception enableactivelinks enableactivelinks fproxyconfig getboolean enableactivelinks fproxyconfig passthroughmaxsize configitemorder simpletoadletserver passthroughmaxsize simpletoadletserver passthroughmaxsizelong fproxypassthrumaxsize fproxytoadlet max_length fproxyconfig getlong passthroughmaxsize fproxyconfig allowedhosts configitemorder simpletoadletserver allowedhosts simpletoadletserver allowedhostslong fproxyallowedhostscallback fproxyconfig allowedhostsfullaccess configitemorder simpletoadletserver allowedfullaccess simpletoadletserver allowedfullaccesslong stringcallback allowedfullaccess getallowedhosts invalidconfigvalueexception allowedfullaccess setallowedhosts allowedfullaccess allowedhosts fproxyconfig getstring allowedhostsfullaccess fproxyconfig dorobots configitemorder simpletoadletserver dorobots simpletoadletserver dorobotslong booleancallback dorobots invalidconfigvalueexception dorobots dorobots fproxyconfig getboolean dorobots simpletoadletserver ispanicbuttontobeshown fproxyconfig getboolean showpanicbutton bucketfactory fproxyconfig getint bindto fproxyconfig getstring bindto cssname fproxyconfig getstring cssname indexof cssname indexof invalidconfigvalueexception csstheme themefromname cssname pagemaker pagemaker csstheme fproxyconfig getoption cssoverride isdefault cssoverride fproxyconfig getstring cssoverride pagemaker setoverride cssoverride cssoverride advancedmodeenabled fproxyconfig getboolean advancedmodeenabled linkedlist toadletelement fproxyconfig getboolean allowedhosts fproxyconfig getstring allowedhosts simpletoadletserver fproxy fproxy maybegetnetworkinterface mythread simpletoadletserver mythread setdaemon statictoadlet statictoadlet removestartuptoadlet startuptoadlet startuptoadlet startuptoadlet fproxy config register has completed wizard false config item order true false simple toadlet server has completed wizard simple toadlet server has completed wizard long new boolean callback override public boolean get return fproxy has completed wizard fproxyconfig hascompletedwizard configitemorder simpletoadletserver hascompletedwizard simpletoadletserver hascompletedwizardlong booleancallback fproxyhascompletedwizard override public void set boolean val throws invalid config value exception node need restart exception if get equals val return fproxy has completed wizard val invalidconfigvalueexception nodeneedrestartexception fproxyhascompletedwizard fproxy config register show panic button false config item order true true simple toadlet server panic button simple toadlet server panic button long new boolean callback override public boolean get return simple toadlet server is panic button to be shown fproxyconfig showpanicbutton configitemorder simpletoadletserver panicbutton simpletoadletserver panicbuttonlong booleancallback simpletoadletserver ispanicbuttontobeshown override public void set boolean value if value simple toadlet server is panic button to be shown return else simple toadlet server is panic button to be shown value simpletoadletserver ispanicbuttontobeshown simpletoadletserver ispanicbuttontobeshown fproxy config register public gateway mode false config item order true true simple toadlet server public gateway mode simple toadlet server public gateway mode long new boolean callback override public boolean get return public gateway mode fproxyconfig publicgatewaymode configitemorder simpletoadletserver publicgatewaymode simpletoadletserver publicgatewaymodelong booleancallback publicgatewaymode override public void set boolean val throws invalid config value exception node need restart exception public gateway mode val invalidconfigvalueexception nodeneedrestartexception publicgatewaymode override public boolean get synchronized simple toadlet server this return enable persistent connections simpletoadletserver enablepersistentconnections override public void set boolean val throws invalid config value exception synchronized simple toadlet server this enable persistent connections val invalidconfigvalueexception simpletoadletserver enablepersistentconnections override public boolean get synchronized simple toadlet server this return enable inline prefetch simpletoadletserver enableinlineprefetch override public void set boolean val throws invalid config value exception synchronized simple toadlet server this enable inline prefetch val invalidconfigvalueexception simpletoadletserver enableinlineprefetch fproxy config register enable activelinks false config item order false false simple toadlet server enable activelinks simple toadlet server enable activelinks long new boolean callback override public boolean get return enable activelinks fproxyconfig enableactivelinks configitemorder simpletoadletserver enableactivelinks simpletoadletserver enableactivelinkslong booleancallback enableactivelinks override public void set boolean val throws invalid config value exception node need restart exception enable activelinks val invalidconfigvalueexception nodeneedrestartexception enableactivelinks new string callback override public string get return allowed full access get allowed hosts stringcallback allowedfullaccess getallowedhosts override public void set string val throws invalid config value exception allowed full access set allowed hosts val invalidconfigvalueexception allowedfullaccess setallowedhosts fproxy config register do robots false config item order true false simple toadlet server do robots simple toadlet server do robots long new boolean callback override public boolean get return do robots fproxyconfig dorobots configitemorder simpletoadletserver dorobots simpletoadletserver dorobotslong booleancallback dorobots return do robots override public void set boolean val throws invalid config value exception do robots val dorobots invalidconfigvalueexception dorobots public void remove startup toadlet unregister startup toadlet ready to be g ced startup toadlet null not in the navbar removestartuptoadlet startuptoadlet gced startuptoadlet private void maybe get network interface throws io exception if this network interface null return if ssl this network interface ssl network interface create port this bind to allowed hosts executor true else this network interface network interface create port this bind to allowed hosts executor true maybegetnetworkinterface ioexception networkinterface networkinterface sslnetworkinterface bindto allowedhosts networkinterface networkinterface bindto allowedhosts public boolean do robots return do robots dorobots dorobots public boolean public gateway mode return public gateway mode publicgatewaymode publicgatewaymode public void start if my thread null try maybe get network interface my thread start logger normal this starting f proxy on bind to port system out println starting f proxy on bind to port catch io exception e logger error this could not bind network port for f proxy e mythread maybegetnetworkinterface mythread fproxy bindto fproxy bindto ioexception fproxy public void register toadlet t string url prefix boolean at front boolean full only register t url prefix at front null null full only null urlprefix atfront fullonly urlprefix atfront fullonly public void register toadlet t string url prefix boolean at front string name string title boolean full only link enabled callback cb toadlet element te new toadlet element t url prefix if at front toadlets add first te else toadlets add last te t container this if name null page maker add navigation link url prefix name title full only cb urlprefix atfront fullonly linkenabledcallback toadletelement toadletelement urlprefix atfront addfirst addlast pagemaker addnavigationlink urlprefix fullonly public synchronized void unregister toadlet t for iterator toadlet element i toadlets iterator i has next toadlet element e i next if e t t i remove return toadletelement hasnext toadletelement public startup toadlet get startup toadlet return startup toadlet startuptoadlet getstartuptoadlet startuptoadlet public toadlet find toadlet uri uri throws permanent redirect exception string path uri get path show the wizard until dismissed by the user see bug 2624 if fproxy has completed wizard if core null core node null core node is opennet enabled core node get peer nodes length 0 if path starts with first time wizard toadlet toadlet url path starts with static toadlet root url try throw new permanent redirect exception new uri first time wizard toadlet toadlet url catch uri syntax exception e throw new error e iterator toadlet element i toadlets iterator while i has next toadlet element te i next if path starts with te prefix return te t if te prefix length 0 te prefix char at te prefix length 1 if path equals te prefix substring 0 te prefix length 1 uri newuri try newuri new uri te prefix catch uri syntax exception e throw new error e throw new permanent redirect exception newuri return null findtoadlet permanentredirectexception getpath fproxyhascompletedwizard isopennetenabled getpeernodes startswith firsttimewizardtoadlet toadlet_url startswith statictoadlet root_url permanentredirectexception firsttimewizardtoadlet toadlet_url urisyntaxexception toadletelement hasnext toadletelement startswith charat urisyntaxexception permanentredirectexception public void run try network interface set so timeout 500 catch socket exception e1 logger error this could not set so timeout to 500ms on the fly disabling of the interface will not work while true synchronized this if my thread null return socket conn network interface accept if conn null continue timeout if logger should log logger minor this logger minor this accepted connection socket handler sh new socket handler conn sh start networkinterface setsotimeout socketexception mythread networkinterface shouldlog sockethandler sockethandler socket sock public socket handler socket conn this sock conn sockethandler void start executor execute this http socket handler hash code hashcode public void run freenet support logger os thread logpid this boolean logminor logger should log logger minor this if logminor logger minor this handling connection try toadlet context impl handle sock simple toadlet server this page maker catch out of memory error e oom handler handleoom e system err println simple toadlet server request above failed logger error this oom in socket handler catch throwable t system err println caught in simple toadlet server t t print stack trace logger error this caught in simple toadlet server t t if logminor logger minor this handled connection osthread shouldlog toadletcontextimpl simpletoadletserver pagemaker outofmemoryerror oomhandler simpletoadletserver sockethandler simpletoadletserver printstacktrace simpletoadletserver public theme get theme return this css theme gettheme csstheme public void setcss name theme theme this css theme theme setcssname csstheme public synchronized boolean is advanced mode enabled return this advanced mode enabled isadvancedmodeenabled advancedmodeenabled public synchronized void enable advanced mode boolean b advanced mode enabled b enableadvancedmode advancedmodeenabled public synchronized boolean isf proxy javascript enabled return this f proxy javascript enabled isfproxyjavascriptenabled fproxyjavascriptenabled public synchronized void enablef proxy javascript boolean b f proxy javascript enabled b enablefproxyjavascript fproxyjavascriptenabled public string get form password if core null return return core form password getformpassword formpassword public boolean is allowed full access inet address remote addr return this allowed full access allowed remote addr isallowedfullaccess inetaddress remoteaddr allowedfullaccess remoteaddr private static string l10n string key string pattern string value return l10n get string simple toadlet server key pattern value getstring simpletoadletserver private static string l10n string key return l10n get string simple toadlet server key getstring simpletoadletserver public html node add form child html node parent node string target string id html node form node parent node add child form new string action method enctype id accept charset new string target post multipart form data id utf 8 add child div form node add child input new string type name value new string hidden form password get form password return form node htmlnode addformchild htmlnode parentnode htmlnode formnode parentnode addchild addchild formnode addchild formpassword getformpassword formnode public void set bucket factory bucket factory temp bucket factory this bf temp bucket factory setbucketfactory bucketfactory tempbucketfactory tempbucketfactory public boolean is enabled return my thread null isenabled mythread public bookmark manager get bookmarks return bookmark manager bookmarkmanager getbookmarks bookmarkmanager public freeneturi get bookmarkur is if bookmark manager null return new freeneturi 0 return bookmark manager get bookmarkur is getbookmarkuris bookmarkmanager bookmarkmanager getbookmarkuris public boolean enable persistent connections return enable persistent connections enablepersistentconnections enablepersistentconnections public boolean enable inline prefetch return enable inline prefetch enableinlineprefetch enableinlineprefetch public synchronized boolean allow posts return bf instanceof array bucket factory allowposts arraybucketfactory public synchronized bucket factory get bucket factory return bf bucketfactory getbucketfactory public boolean enable activelinks return enable activelinks enableactivelinks enableactivelinks logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private final int hash code override public int hash code return hash code hashcode hashcode hashcode public split file fetcher metadata metadata get completion callback rcb client requester parent2 fetch context new ctx boolean delete fetch context list decompressors2 client metadata client metadata archive context actx int recursion level bucket return bucket long token2 object container container client context context throws fetch exception metadata parse exception this persistent parent2 persistent this delete fetch context delete fetch context if logminor logger minor this persistence persistent from parent2 new exception debug int hash super hash code if hash 0 hash 1 this hash code hash this finished false this return bucket return bucket this fetch context new ctx if new ctx null throw new null pointer exception this archive context actx this decompressors persistent new array list decompressors2 decompressors2 if decompressors size 1 logger error this multiple decompressors decompressors size this is almost certainly a bug new exception debug this client metadata client metadata null new client metadata client metadata clone copy it as in single file fetcher this cb rcb this recursion level recursion level 1 this parent parent2 local salt new byte 32 context random next bytes local salt if parent2 is cancelled throw new fetch exception fetch exception cancelled override length metadata data length this splitfile type metadata get splitfile type clientchk splitfile data blocks metadata get splitfile data keys clientchk splitfile check blocks metadata get splitfile check keys if persistent clear them here so they don t get deleted and we don t need to clone them metadata clear splitfile keys container store metadata for int i 0 i splitfile data blocks length i if splitfile data blocks i null throw new metadata parse exception null data block i of splitfile data blocks length for int i 0 i splitfile check blocks length i if splitfile check blocks i null throw new metadata parse exception null check block i of splitfile check blocks length long final length 1l splitfile data blocks length chk block data length if final length override length if final length override length chk block data length throw new fetch exception fetch exception invalid metadata splitfile is final length but length is final length final length override length long eventual length math max override length metadata uncompressed data length boolean was active true if persistent was active container ext is active cb if was active container activate cb 1 cb on expected size eventual length container context string mime type metadata getmime type if mime type null cb on expectedmime mime type container context if metadata uncompressed data length 0 cb on finalized metadata container if was active container deactivate cb 1 if eventual length 0 new ctx max output length 0 eventual length new ctx max output length throw new fetch exception fetch exception too big eventual length true client metadata getmime type this token token2 if splitfile type metadata splitfile nonredundant don t need to do much just fetch everything and piece it together blocks per segment 1 check blocks per segment 1 segment count 1 if splitfile check blocks length 0 logger error this splitfile type is splitfile nonredundant yet splitfile check blocks length check blocks found this throw new fetch exception fetch exception invalid metadata splitfile type is non redundant yet have splitfile check blocks length check blocks else if splitfile type metadata splitfile onion standard byte params metadata splitfile params if params null params length 8 throw new metadata parse exception no splitfile params blocks per segment fields bytes to int params 0 int check blocks fields bytes to int params 4 fixme remove this eventually will break compat with a few files inserted between 1135 and 1136 work around a bug around build 1135 we were splitting as 128 255 but we were then setting the check blocks per segment to 64 detect this if check blocks 64 blocks per segment 128 splitfile check blocks length splitfile data blocks length splitfile data blocks length 128 logger normal this activating 1135 wrong check blocks per segment workaround for this check blocks 127 check blocks per segment check blocks if blocks per segment fetch context max data blocks per segment check blocks per segment fetch context max check blocks per segment throw new fetch exception fetch exception too many blocks per segment too many blocks per segment blocks per segment data check blocks per segment check segment count splitfile data blocks length blocks per segment splitfile data blocks length blocks per segment 0 0 1 onion 128 192 will be segmented else throw new metadata parse exception unknown splitfile format splitfile type this max temp length fetch context max temp length if logminor logger minor this algorithm splitfile type blocks per segment blocks per segment check blocks per segment check blocks per segment segments segment count data blocks splitfile data blocks length check blocks splitfile check blocks length segments new split file fetcher segment segment count initially null on all entries setup bloom parameters if persistent fixme should this be encrypted it s protected to some degree by the salt since it isn t encrypted it s likely to be very sparse we should name it appropriately try main bloom file context persistentfg make random file alt bloom file context persistentfg make random file catch io exception e throw new fetch exception fetch exception bucket error unable to create bloom filter files e else not persistent keep purely in ram main bloom file null alt bloom file null int main elements per key default main bloom elements per key int orig size splitfile data blocks length splitfile check blocks length main bloomk int main elements per key 0 7 long elements long orig size main elements per key redflag size limit 3 36tb limit if elements long integer max value throw new fetch exception fetch exception too big cannot fetch splitfiles with more than integer max value main elements per key keys approx 3 3tb int main size bits int elements long counting filter if main size bits 7 0 main size bits 8 main size bits 7 main bloom filter size bytes main size bits 8 2 counting filter double acceptable false positives acceptable bloom false positives all segments segments length int per segment bits per key int math ceil math log acceptable false positives math log 0 6185 int seg blocks blocks per segment check blocks per segment if seg blocks orig size seg blocks orig size int per segment size per segment bits per key seg blocks if per segment size 7 0 per segment size 8 per segment size 7 per segment bloom filter size bytes per segment size 8 per segmentk bloom filter optimialk per segment size seg blocks key count orig size now create it if logminor logger minor this creating block filter for this keys splitfile data blocks length splitfile check blocks length main bloom size main bloom filter size bytes bytes k main bloomk filename main bloom file alt bloom filter filename alt bloom file segments segments length each is per segment bloom filter size bytes bytes k per segmentk try temp listener new split file fetcher key listener this key count main bloom file alt bloom file main bloom filter size bytes main bloomk fetch context cache local requests local salt segments length per segment bloom filter size bytes per segmentk persistent true catch io exception e throw new fetch exception fetch exception bucket error unable to write bloom filters for splitfile if persistent container store this block fetch context new fetch context fetch context fetch context splitfile default block mask true null if segment count 1 splitfile will be overwritten this is bad so copy them clientchk new splitfile data blocks new clientchk splitfile data blocks length clientchk new splitfile check blocks new clientchk splitfile check blocks length system arraycopy splitfile data blocks 0 new splitfile data blocks 0 splitfile data blocks length if splitfile check blocks length 0 system arraycopy splitfile check blocks 0 new splitfile check blocks 0 splitfile check blocks length segments 0 new split file fetcher segment splitfile type new splitfile data blocks new splitfile check blocks this archive context block fetch context max temp length recursion level parent 0 true for int i 0 i new splitfile data blocks length i if logminor logger minor this added data block i new splitfile data blocks i get node key temp listener add key new splitfile data blocks i get node key 0 context for int i 0 i new splitfile check blocks length i if logminor logger minor this added check block i new splitfile check blocks i get node key temp listener add key new splitfile check blocks i get node key 0 context if persistent container store segments 0 segments 0 deactivate keys container container deactivate segments 0 1 else int data blocks ptr 0 splitfilefetcher getcompletioncallback clientrequester fetchcontext newctx deletefetchcontext clientmetadata clientmetadata archivecontext recursionlevel returnbucket objectcontainer clientcontext fetchexception metadataparseexception deletefetchcontext deletefetchcontext hashcode hashcode returnbucket returnbucket fetchcontext newctx newctx nullpointerexception archivecontext arraylist clientmetadata clientmetadata clientmetadata clientmetadata singlefilefetcher recursionlevel recursionlevel localsalt nextbytes localsalt iscancelled fetchexception fetchexception overridelength datalength splitfiletype getsplitfiletype splitfiledatablocks getsplitfiledatakeys splitfilecheckblocks getsplitfilecheckkeys clearsplitfilekeys splitfiledatablocks splitfiledatablocks metadataparseexception splitfiledatablocks splitfilecheckblocks splitfilecheckblocks metadataparseexception splitfilecheckblocks finallength splitfiledatablocks chkblock data_length finallength overridelength finallength overridelength chkblock data_length fetchexception fetchexception invalid_metadata finallength finallength finallength overridelength eventuallength overridelength uncompresseddatalength wasactive wasactive isactive wasactive onexpectedsize eventuallength mimetype getmimetype mimetype onexpectedmime mimetype uncompresseddatalength onfinalizedmetadata wasactive eventuallength newctx maxoutputlength eventuallength newctx maxoutputlength fetchexception fetchexception too_big eventuallength clientmetadata getmimetype splitfiletype splitfile_nonredundant blockspersegment checkblockspersegment segmentcount splitfilecheckblocks splitfile_nonredundant splitfilecheckblocks fetchexception fetchexception invalid_metadata splitfilecheckblocks splitfiletype splitfile_onion_standard splitfileparams metadataparseexception blockspersegment bytestoint checkblocks bytestoint checkblockspersegment checkblocks blockspersegment splitfilecheckblocks splitfiledatablocks splitfiledatablocks checkblocks checkblockspersegment checkblocks blockspersegment fetchcontext maxdatablockspersegment checkblockspersegment fetchcontext maxcheckblockspersegment fetchexception fetchexception too_many_blocks_per_segment blockspersegment checkblockspersegment segmentcount splitfiledatablocks blockspersegment splitfiledatablocks blockspersegment metadataparseexception splitfiletype maxtemplength fetchcontext maxtemplength splitfiletype blockspersegment checkblockspersegment segmentcount splitfiledatablocks splitfilecheckblocks splitfilefetchersegment segmentcount mainbloomfile makerandomfile altbloomfile makerandomfile ioexception fetchexception fetchexception bucket_error mainbloomfile altbloomfile mainelementsperkey default_main_bloom_elements_per_key origsize splitfiledatablocks splitfilecheckblocks mainbloomk mainelementsperkey elementslong origsize mainelementsperkey elementslong max_value fetchexception fetchexception too_big max_value mainelementsperkey mainsizebits elementslong mainsizebits mainsizebits mainsizebits mainbloomfiltersizebytes mainsizebits acceptablefalsepositives acceptable_bloom_false_positives_all_segments persegmentbitsperkey acceptablefalsepositives segblocks blockspersegment checkblockspersegment segblocks origsize segblocks origsize persegmentsize persegmentbitsperkey segblocks persegmentsize persegmentsize persegmentsize persegmentbloomfiltersizebytes persegmentsize persegmentk bloomfilter persegmentsize segblocks keycount origsize splitfiledatablocks splitfilecheckblocks mainbloomfiltersizebytes mainbloomk mainbloomfile altbloomfile persegmentbloomfiltersizebytes persegmentk templistener splitfilefetcherkeylistener keycount mainbloomfile altbloomfile mainbloomfiltersizebytes mainbloomk fetchcontext cachelocalrequests localsalt persegmentbloomfiltersizebytes persegmentk ioexception fetchexception fetchexception bucket_error blockfetchcontext fetchcontext fetchcontext fetchcontext splitfile_default_block_mask segmentcount newsplitfiledatablocks splitfiledatablocks newsplitfilecheckblocks splitfilecheckblocks splitfiledatablocks newsplitfiledatablocks splitfiledatablocks splitfilecheckblocks splitfilecheckblocks newsplitfilecheckblocks splitfilecheckblocks splitfilefetchersegment splitfiletype newsplitfiledatablocks newsplitfilecheckblocks archivecontext blockfetchcontext maxtemplength recursionlevel newsplitfiledatablocks newsplitfiledatablocks getnodekey templistener addkey newsplitfiledatablocks getnodekey newsplitfilecheckblocks newsplitfilecheckblocks getnodekey templistener addkey newsplitfilecheckblocks getnodekey deactivatekeys datablocksptr return the final status of the fetch throws an exception or returns a bucket containing the fetched data throws fetch exception if the fetch failed for some reason private bucket final status object container container client context context throws fetch exception long final length 0 for int i 0 i segments length i split file fetcher segment s segments i if persistent container activate s 1 if s succeeded throw new illegal state exception not all finished s throw error container if still here it succeeded long sz s decoded length container final length sz if logminor logger minor this segment i decoded length sz total length now final length for s data buckets length blocks which should be s data buckets length nodechk block size healing is done by segment if final length override length if final length override length chk block data length throw new fetch exception fetch exception invalid metadata splitfile is final length but length is final length final length override length long bytes written 0 output stream os null bucket output if persistent container activate decompressors 5 if return bucket null container activate return bucket 5 try if return bucket null decompressors is empty output return bucket else output context get bucket factory parent persistent make bucket final length os output get output stream for int i 0 i segments length i split file fetcher segment s segments i long max final length 0 0 final length bytes written bytes written s write decoded data to os max s free decoded data container catch io exception e throw new fetch exception fetch exception bucket error e finally if os null try os close catch io exception e if it fails to close it may return corrupt data throw new fetch exception fetch exception bucket error e if final length output size logger error this final length is supposed to be final length but only written output size return output fetchexception finalstatus objectcontainer clientcontext fetchexception finallength splitfilefetchersegment illegalstateexception throwerror decodedlength finallength finallength databuckets databuckets block_size finallength overridelength finallength overridelength chkblock data_length fetchexception fetchexception invalid_metadata finallength finallength finallength overridelength byteswritten outputstream returnbucket returnbucket returnbucket isempty returnbucket getbucketfactory makebucket finallength getoutputstream splitfilefetchersegment finallength finallength byteswritten byteswritten writedecodeddatato freedecodeddata ioexception fetchexception fetchexception bucket_error ioexception fetchexception fetchexception bucket_error finallength finallength public void segment finished split file fetcher segment segment object container container client context context if persistent container activate this 1 if logminor logger minor this finished segment segment boolean finish false synchronized this boolean all done true for int i 0 i segments length i if persistent container activate segments i 1 if segments i succeeded if logminor logger minor this segment segments i is not finished all done false if all done if all segments finished logger error this was already finished segment finished segment new exception debug else all segments finished true finish true else for int i 0 i segments length i if segments i segment continue if persistent container deactivate segments i 1 notify all if persistent container store this if finish finish container context segmentfinished splitfilefetchersegment objectcontainer clientcontext alldone alldone alldone allsegmentsfinished segmentfinished allsegmentsfinished notifyall private void finish object container container client context context if persistent container activate cb 1 context get chk fetch scheduler remove pending keys this true boolean cb was active true try synchronized this if other failure null throw other failure if finished logger error this was already finished return finished true if persistent container store this bucket data final status container context decompress if persistent container activate decompressors 5 container activate return bucket 5 cb was active container ext is active cb if cb was active container activate cb 1 container activate fetch context 1 if fetch context null logger error this fetch context is null if container ext is active fetch context logger error this fetch context is null and splitfile is not activated new exception error container activate this 1 container activate decompressors 5 container activate return bucket 5 container activate fetch context 1 else logger error this fetch context is null and splitfile is activated new exception error container activate fetch context 1 int count 0 while decompressors is empty compressor c compressor decompressors remove decompressors size 1 if logminor logger minor this decompressing with c long max len math max fetch context max temp length fetch context max output length bucket orig data try bucket out return bucket if decompressors is empty out null data c decompress data context get bucket factory parent persistent max len max len 4 out catch io exception e if e get message equals not in gzip format count 1 logger error this attempting to decompress twice failed returning first round data this break cb on failure new fetch exception fetch exception bucket error e this container context return catch compression output size exception e if logminor logger minor this too big max size fetch context max output length max temp size fetch context max temp length cb on failure new fetch exception fetch exception too big e estimated size false fixme client metadata getmime type this container context return finally if orig data orig free if persistent orig remove from container count cb on success new fetch result client metadata data this container context catch fetch exception e cb on failure e this container context catch out of memory error e oom handler handleoom e system err println failing above attempted fetch cb on failure new fetch exception fetch exception internal error e this container context catch throwable t logger error this caught t t cb on failure new fetch exception fetch exception internal error t this container context if cb was active container deactivate cb 1 objectcontainer clientcontext getchkfetchscheduler removependingkeys cbwasactive otherfailure otherfailure finalstatus returnbucket cbwasactive isactive cbwasactive fetchcontext fetchcontext isactive fetchcontext returnbucket fetchcontext fetchcontext isempty maxlen fetchcontext maxtemplength fetchcontext maxoutputlength returnbucket isempty getbucketfactory maxlen maxlen ioexception getmessage onfailure fetchexception fetchexception bucket_error compressionoutputsizeexception maxsize fetchcontext maxoutputlength maxtempsize fetchcontext maxtemplength onfailure fetchexception fetchexception too_big estimatedsize clientmetadata getmimetype removefrom onsuccess fetchresult clientmetadata fetchexception onfailure outofmemoryerror oomhandler onfailure fetchexception fetchexception internal_error onfailure fetchexception fetchexception internal_error cbwasactive public void schedule object container container client context context throws key listener construction exception if persistent container activate this 1 if logminor logger minor this scheduling this sendable get getters new sendable get segments length for int i 0 i segments length i if logminor logger minor this scheduling segment i segments i if persistent container activate segments i 1 getters i segments i schedule container context if persistent container deactivate segments i 1 block set blocks fetch context blocks context get chk fetch scheduler register this getters persistent true container blocks false objectcontainer clientcontext keylistenerconstructionexception sendableget sendableget blockset fetchcontext getchkfetchscheduler public void cancel object container container client context context boolean persist persistent if persist container activate this 1 for int i 0 i segments length i if logminor logger minor this cancelling segment i if segments null persist container ext is active this fixme is this normal if so just reactivate logger error this deactivated mid cancel on this new exception error container activate this 1 if segments i null synchronized this if finished not unusual if some of the later segments are already finished when cancel is called if logminor logger minor this finished mid cancel on this return if persist container activate segments i 1 segments i cancel container context objectcontainer clientcontext isactive public long get token return token gettoken make our split file fetcher key listener returns the one we created in the constructor if possible otherwise makes a new one we must have already constructed one at some point maybe before a restart throws fetch exception public key listener make key listener object container container client context context throws key listener construction exception synchronized this if finished return null if temp listener null recently constructed return temp listener file main file alt boolean cache local requests if fetch context null logger error this fetch context deleted without splitfile being deleted return null if persistent container activate main bloom file 5 container activate alt bloom file 5 main new file main bloom file get path alt new file alt bloom file get path container deactivate main bloom file 1 container deactivate alt bloom file 1 container activate fetch context 1 cache local requests fetch context cache local requests container deactivate fetch context 1 else main null alt null cache local requests fetch context cache local requests try if logminor logger minor this attempting to read bloom filter for this main file main alt file alt temp listener new split file fetcher key listener this key count main alt main bloom filter size bytes main bloomk cache local requests local salt segments length per segment bloom filter size bytes per segmentk persistent false catch io exception e logger error this unable to read bloom filter for this attempting to reconstruct e main delete alt delete try main bloom file context fg make random file alt bloom file context fg make random file if persistent container store this catch io exception e1 throw new key listener construction exception new fetch exception fetch exception bucket error unable to create bloom filter files in reconstruction e1 try temp listener new split file fetcher key listener this key count main bloom file alt bloom file main bloom filter size bytes main bloomk fetch context cache local requests local salt segments length per segment bloom filter size bytes per segmentk persistent true catch io exception e1 throw new key listener construction exception new fetch exception fetch exception bucket error unable to reconstruct bloom filters e1 e1 return temp listener splitfilefetcherkeylistener fetchexception keylistener makekeylistener objectcontainer clientcontext keylistenerconstructionexception templistener templistener cachelocalrequests fetchcontext fetchcontext mainbloomfile altbloomfile mainbloomfile getpath altbloomfile getpath mainbloomfile altbloomfile fetchcontext cachelocalrequests fetchcontext cachelocalrequests fetchcontext cachelocalrequests fetchcontext cachelocalrequests templistener splitfilefetcherkeylistener keycount mainbloomfiltersizebytes mainbloomk cachelocalrequests localsalt persegmentbloomfiltersizebytes persegmentk ioexception mainbloomfile makerandomfile altbloomfile makerandomfile ioexception keylistenerconstructionexception fetchexception fetchexception bucket_error templistener splitfilefetcherkeylistener keycount mainbloomfile altbloomfile mainbloomfiltersizebytes mainbloomk fetchcontext cachelocalrequests localsalt persegmentbloomfiltersizebytes persegmentk ioexception keylistenerconstructionexception fetchexception fetchexception bucket_error templistener public synchronized boolean is cancelled object container container return finished iscancelled objectcontainer public split file fetcher segment get segment int i return segments i splitfilefetchersegment getsegment public void remove my pending keys split file fetcher segment segment object container container client context context key count temp listener kill segment segment container context removemypendingkeys splitfilefetchersegment objectcontainer clientcontext keycount templistener killsegment void set key count int key count2 object container container this key count key count2 if persistent container store this setkeycount keycount2 objectcontainer keycount keycount2 public void on failed key listener construction exception e object container container client context context other failure e get fetch exception cancel container context onfailed keylistenerconstructionexception objectcontainer clientcontext otherfailure getfetchexception public void remove from object container container client context context if logminor logger minor this remove from on this new exception debug if container ext is stored this logger error this already removed on this new exception error return container activate block fetch context 1 block fetch context remove from container if delete fetch context container activate fetch context 1 fetch context remove from container container activate client metadata 1 client metadata remove from container container activate decompressors 1 container delete decompressors for int i 0 i segments length i split file fetcher segment segment segments i segments i null container activate segment 1 segment fetcher finished container context container activate main bloom file 5 container activate alt bloom file 5 if main bloom file null main bloom file delete main bloom file exists logger error this unable to delete main bloom file main bloom file for this else if main bloom file null logger error this main bloom file is null on this else if logminor logger minor this deleted main bloom file main bloom file if alt bloom file null alt bloom file delete alt bloom file exists logger error this unable to delete alt bloom file alt bloom file for this else if alt bloom file null logger error this alt bloom file is null on this else if logminor logger minor this deleted alt bloom file alt bloom file container delete main bloom file container delete alt bloom file container delete this removefrom objectcontainer clientcontext removefrom isstored blockfetchcontext blockfetchcontext removefrom deletefetchcontext fetchcontext fetchcontext removefrom clientmetadata clientmetadata removefrom splitfilefetchersegment fetcherfinished mainbloomfile altbloomfile mainbloomfile mainbloomfile mainbloomfile mainbloomfile mainbloomfile mainbloomfile mainbloomfile altbloomfile altbloomfile altbloomfile altbloomfile altbloomfile altbloomfile altbloomfile mainbloomfile altbloomfile public boolean object can update object container container if hash code 0 logger error this trying to update with hash 0 already deleted active container ext is active this stored container ext is stored this new exception error return false return true objectcanupdate objectcontainer hashcode isactive isstored public boolean object can new object container container if hash code 0 logger error this trying to write with hash 0 already deleted active container ext is active this stored container ext is stored this new exception error return false return true objectcannew objectcontainer hashcode isactive isstored public xml pull parser exception string s super s xmlpullparserexception public xml pull parser exception string msg xml pull parser parser throwable chain super msg null msg parser null position parser get position description chain null caused by chain if parser null this row parser get line number this column parser get column number this detail chain xmlpullparserexception xmlpullparser getpositiondescription getlinenumber getcolumnnumber public throwable get detail return detail getdetail public throwable get detail return detail public void set detail throwable cause this detail cause public int get line number return row getdetail setdetail getlinenumber public void set detail throwable cause this detail cause public int get line number return row public int get column number return column setdetail getlinenumber getcolumnnumber note code that prints this and detail is difficult in j2me public void print stack trace if detail null super print stack trace else synchronized system err system err println super get message nested exception is detail print stack trace printstacktrace printstacktrace getmessage printstacktrace private float interpolation public interpolate filter interpolatefilter set the destination image param destination the destination image see get destination public void set destination buffered image destination this destination destination getdestination setdestination bufferedimage get the destination image return the destination image see set destination public buffered image get destination return destination setdestination bufferedimage getdestination set the interpolation factor param interpolation the interpolation factor see get interpolation public void set interpolation float interpolation this interpolation interpolation getinterpolation setinterpolation get the interpolation factor return the interpolation factor see set interpolation public float get interpolation return interpolation setinterpolation getinterpolation public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster if dst null dst create compatible dest image src null writable raster dst raster dst get raster if destination null width math min width destination get width height math min height destination get width int pixels1 null int pixels2 null for int y 0 y height y pixels1 getrgb src 0 y width 1 pixels1 pixels2 getrgb destination 0 y width 1 pixels2 for int x 0 x width x int rgb1 pixels1 x int rgb2 pixels2 x int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff r1 pixel utils clamp image math lerp interpolation r1 r2 g1 pixel utils clamp image math lerp interpolation g1 g2 b1 pixel utils clamp image math lerp interpolation b1 b2 pixels1 x a1 24 r1 16 g1 8 b1 setrgb dst 0 y width 1 pixels1 return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster createcompatibledestimage writableraster dstraster getraster getwidth getwidth pixelutils imagemath pixelutils imagemath pixelutils imagemath override public string to string return effects interpolate tostring suppress warnings serial public class invalid config value exception extends config exception public invalid config value exception string msg super msg suppresswarnings invalidconfigvalueexception configexception invalidconfigvalueexception public final class color dodge composite extends rgb composite public color dodge composite float alpha super alpha colordodgecomposite rgbcomposite colordodgecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob if sr 255 dor math min dir 8 255 sr 255 else dor sr if sg 255 dog math min dig 8 255 sg 255 else dog sg if sb 255 dob math min dib 8 255 sb 255 else dob sb float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public final static boolean is root device string nt value if nt value null return false return nt value starts with rootdevice isrootdevice ntvalue ntvalue ntvalue startswith public sun14 reflection provider try class object stream class class for name java io object stream class field reflector field unsafe field object stream class get declared field unsafe unsafe field set accessible true unsafe unsafe unsafe field get null java lang object constructor object class get declared constructor new class 0 factory reflection factory get reflection factory constructor hash new hash map catch exception x throw new error failed to initialize reflection provider sun14reflectionprovider objectstreamclass forname objectstreamclass fieldreflector unsafefield objectstreamclass getdeclaredfield unsafefield setaccessible unsafefield javalangobjectconstructor getdeclaredconstructor reflectionfactory getreflectionfactory constructorhash hashmap public constructor get default constructor class cls throws exception constructor cons constructor constructor hash get cls if cons null try cons cls get declared constructor default constructor profile catch no such method exception x cons factory new constructor for serialization cls java lang object constructor constructor hash put cls cons return cons getdefaultconstructor constructorhash getdeclaredconstructor defaultconstructorprofile nosuchmethodexception newconstructorforserialization javalangobjectconstructor constructorhash public void set int field field object object int value throws exception unsafe put int object unsafe object field offset field value setint putint objectfieldoffset public void set long field field object object long value throws exception unsafe put long object unsafe object field offset field value setlong putlong objectfieldoffset public void set short field field object object short value throws exception unsafe put short object unsafe object field offset field value setshort putshort objectfieldoffset public void set char field field object object char value throws exception unsafe put char object unsafe object field offset field value setchar putchar objectfieldoffset public void set byte field field object object byte value throws exception unsafe put byte object unsafe object field offset field value setbyte putbyte objectfieldoffset public void set float field field object object float value throws exception unsafe put float object unsafe object field offset field value setfloat putfloat objectfieldoffset public void set double field field object object double value throws exception unsafe put double object unsafe object field offset field value setdouble putdouble objectfieldoffset public void set boolean field field object object boolean value throws exception unsafe put boolean object unsafe object field offset field value setboolean putboolean objectfieldoffset public void set field field object object object value throws exception unsafe put object object unsafe object field offset field value putobject objectfieldoffset public class null file implements i file public void write long pos byte buf nullfile ifile public void write long pos byte buf public int read long pos byte buf return 0 public void sync public void sync public boolean try lock boolean shared return true trylock public void lock boolean shared public void unlock public void close public void close public long length return 0 public class pubkey store extends store callback override public boolean collision possible return false pubkeystore storecallback collisionpossible override public storable block construct byte data byte headers byte routing key byte full key throws key verify exception if data null throw new pubkey verify exception need data to construct pubkey try return dsa public key create data catch crypt format exception e throw new pubkey verify exception e storableblock routingkey fullkey keyverifyexception pubkeyverifyexception dsapublickey cryptformatexception pubkeyverifyexception public dsa public key fetch byte hash boolean dont promote throws io exception return dsa public key store fetch hash null dont promote dsapublickey dontpromote ioexception dsapublickey dontpromote public void put byte hash dsa public key key throws io exception try store put key key get routing key key get full key key as padded bytes empty false catch key collision exception e logger error this impossible for pubkey store e e dsapublickey ioexception getroutingkey getfullkey aspaddedbytes keycollisionexception pubkeystore override public int data length return dsa public key padded size datalength dsapublickey padded_size override public int full key length return dsa public key hash length fullkeylength dsapublickey hash_length override public int header length return 0 headerlength override public int routing key length return dsa public key hash length routingkeylength dsapublickey hash_length override public boolean store full keys return false storefullkeys override public boolean construct needs key return false constructneedskey override public byte routing key from full key byte key buf return key buf routingkeyfromfullkey keybuf keybuf public final class difference composite extends rgb composite public difference composite float alpha super alpha differencecomposite rgbcomposite differencecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr if dor 0 dor dor dog dig sg if dog 0 dog dog dob dib sb if dob 0 dob dob float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public class cannot create from field set exception extends exception private static final long serial versionuid 1l public cannot create from field set exception string msg super msg cannotcreatefromfieldsetexception serialversionuid cannotcreatefromfieldsetexception public cannot create from field set exception string msg exception e super msg e e cannotcreatefromfieldsetexception static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public nodeip detector node node this node node ip detector manager new ip detector plugin manager node this ip detector new ip address detector 10 1000 this invalid address override alert new invalid address override user alert node primaryip undetected alert new ip undetected user alert node port detectors new nodeip port detector 0 nodeipdetector ipdetectormanager ipdetectorpluginmanager ipdetector ipaddressdetector invalidaddressoverridealert invalidaddressoverrideuseralert primaryipundetectedalert ipundetecteduseralert portdetectors nodeipportdetector public synchronized void add port detector nodeip port detector detector nodeip port detector new detectors new nodeip port detector port detectors length 1 system arraycopy port detectors 0 new detectors 0 port detectors length new detectors port detectors length detector port detectors new detectors addportdetector nodeipportdetector nodeipportdetector newdetectors nodeipportdetector portdetectors portdetectors newdetectors portdetectors newdetectors portdetectors portdetectors newdetectors what is my ip address use all globally available information everything which isn t specific to a given port i e opennet or darknet to determine our current ip addresses will include more than one ip in many cases when we are not strictly multi homed for example if we have a dns name set we will usually return an ip as well will warn the user with a user alert if we don t have sufficient information freenet inet address detect primaryip address boolean dump local addresses boolean added validip false logger minor this redetecting i ps array list freenet inet address addresses new array list freenet inet address if overrideip address null if the ip is overridden and the override is valid the override has to be the first element overrideip address will be null if the override is invalid addresses add overrideip address if overrideip address is real internet address false true false added validip true if node dont detect added validip inner detect addresses if node client core null boolean had validip synchronized this had validip has validip has validip added validip if first detection had validip added validip first detection false if had validip added validip if added validip if logminor logger minor this got valid ip on added validip else if logminor logger minor this no valid ip on not added validip else if logminor logger minor this client core not loaded synchronized this has validip added validip lastip address addresses to array new freenet inet address addresses size if dump local addresses array list freenet inet address filtered new array list freenet inet address lastip address length for int i 0 i lastip address length i if lastip address i null continue if lastip address i overrideip address lastip address i has hostname noip filtered add lastip address i else if lastip address i has hostname noip continue else if ip util is valid address lastip address i get address false filtered add lastip address i return filtered to array new freenet inet address filtered size return lastip address useralert freenetinetaddress detectprimaryipaddress dumplocaladdresses addedvalidip ips arraylist freenetinetaddress arraylist freenetinetaddress overrideipaddress overrideipaddress overrideipaddress overrideipaddress isrealinternetaddress addedvalidip dontdetect addedvalidip innerdetect clientcore hadvalidip hadvalidip hasvalidip hasvalidip addedvalidip firstdetection hadvalidip addedvalidip firstdetection hadvalidip addedvalidip addedvalidip onaddedvalidip onnotaddedvalidip hasvalidip addedvalidip lastipaddress toarray freenetinetaddress dumplocaladdresses arraylist freenetinetaddress arraylist freenetinetaddress lastipaddress lastipaddress lastipaddress lastipaddress overrideipaddress lastipaddress hashostnamenoip lastipaddress lastipaddress hashostnamenoip iputil isvalidaddress lastipaddress getaddress lastipaddress toarray freenetinetaddress lastipaddress boolean has validip synchronized this return has validip hasvalidip hasvalidip private void on added validip node client core alerts unregister primaryip undetected alert node on added validip onaddedvalidip clientcore primaryipundetectedalert onaddedvalidip private void on not added validip node client core alerts register primaryip undetected alert onnotaddedvalidip clientcore primaryipundetectedalert core of the ip detection algorithm param addresses param added validip return private boolean inner detect list freenet inet address addresses boolean added validip false inet address detected addrs ip detector get address assert detected addrs null synchronized this has detectediad true for int i 0 i detected addrs length i freenet inet address addr new freenet inet address detected addrs i if addresses contains addr logger normal this detected ip address addr addresses add addr if addr is real internet address false false false added validip true if plugin detectedi ps null plugin detectedi ps length 0 for int i 0 i plugin detectedi ps length i inet address addr plugin detectedi ps i public address if addr null continue freenet inet address a new freenet inet address addr if addresses contains a logger normal this plugin detected ip address a addresses add a if a is real internet address false false false added validip true if added validip oldip address null oldip address equals overrideip address addresses add oldip address don t set added validip there is an excellent chance that this is out of date so we still want to nag the user until we have some confirmation try to pick it up from our connections if node peers null peer node peer list node peers my peers hash map freenet inet address integer counts by peer new hash map freenet inet address integer fixme use a standard mutable int object we have one somewhere for int i 0 i peer list length i if peer list i is connected if logminor logger minor this not connected continue if peer list i is real connection only let seed server connections through we have to trust them anyway if peer list i instanceof seed server peer node continue if logminor logger minor this not a real connection and not a seed node peer list i if logminor logger minor this maybe a usable connection for ip peer list i peer p peer list i get remote detected peer if logminor logger minor this remote detected peer p if p null p is null continue freenet inet address addr p get freenet address if logminor logger minor this address addr if addr null continue if ip util is valid address addr get address false false if logminor logger minor this address not valid continue if logminor logger minor this peer peer list i get peer thinks we are addr if counts by peer contains key addr counts by peer put addr counts by peer get addr 1 else counts by peer put addr 1 if counts by peer size 1 iterator freenet inet address it counts by peer key set iterator freenet inet address addr it next logger minor this everyone agrees we are addr if addresses contains addr if addr is real internet address false false false added validip true addresses add addr else if counts by peer size 1 take two most popular addresses freenet inet address best null freenet inet address second best null int best popularity 0 int second best popularity 0 for map entry freenet inet address integer entry counts by peer entry set freenet inet address cur entry get key int cur pop entry get value logger minor this detected peer cur popularity cur pop if cur pop best popularity second best popularity best popularity best popularity cur pop second best best best cur if best null boolean has real detected address false for int i 0 i detected addrs length i if ip util is valid address detected addrs i false has real detected address true if best popularity 1 has real detected address if addresses contains best logger minor this adding best peer best best popularity addresses add best if best is real internet address false false false added validip true if second best null second best popularity 1 if addresses contains second best logger minor this adding second best peer second best second best addresses add second best if second best is real internet address false false false added validip true return added validip addedvalidip innerdetect freenetinetaddress addedvalidip inetaddress detectedaddrs ipdetector getaddress detectedaddrs hasdetectediad detectedaddrs freenetinetaddress freenetinetaddress detectedaddrs isrealinternetaddress addedvalidip plugindetectedips plugindetectedips plugindetectedips inetaddress plugindetectedips publicaddress freenetinetaddress freenetinetaddress isrealinternetaddress addedvalidip addedvalidip oldipaddress oldipaddress overrideipaddress oldipaddress addedvalidip peernode peerlist mypeers hashmap freenetinetaddress countsbypeer hashmap freenetinetaddress peerlist peerlist isconnected peerlist isrealconnection peerlist seedserverpeernode peerlist peerlist peerlist getremotedetectedpeer isnull freenetinetaddress getfreenetaddress iputil isvalidaddress getaddress peerlist getpeer countsbypeer containskey countsbypeer countsbypeer countsbypeer countsbypeer freenetinetaddress countsbypeer keyset freenetinetaddress isrealinternetaddress addedvalidip countsbypeer freenetinetaddress freenetinetaddress secondbest bestpopularity secondbestpopularity freenetinetaddress countsbypeer entryset freenetinetaddress getkey curpop getvalue curpop curpop bestpopularity secondbestpopularity bestpopularity bestpopularity curpop secondbest hasrealdetectedaddress detectedaddrs iputil isvalidaddress detectedaddrs hasrealdetectedaddress bestpopularity hasrealdetectedaddress bestpopularity isrealinternetaddress addedvalidip secondbest secondbestpopularity secondbest secondbest secondbest secondbest secondbest isrealinternetaddress addedvalidip addedvalidip private string l10n string key return l10n get string nodeip detector key getstring nodeipdetector private string l10n string key string pattern string value return l10n get string nodeip detector key pattern value getstring nodeipdetector freenet inet address get primaryip address boolean dump local if lastip address null return detect primaryip address dump local return lastip address freenetinetaddress getprimaryipaddress dumplocal lastipaddress detectprimaryipaddress dumplocal lastipaddress public boolean has directly detectedip inet address addrs ip detector get address if addrs null addrs length 0 return false for int i 0 i addrs length i if ip util is valid address addrs i false if logminor logger minor this has a directly detected ip addrs i return true return false hasdirectlydetectedip inetaddress ipdetector getaddress iputil isvalidaddress process a list of detectedip s from the ip detector plugin manager detectedip s can tell us what kind of nat we are behind as well as our public ip address public void process detectedi ps detectedip list plugin detectedi ps list for int i 0 i plugin detectedi ps length i int mtu plugin detectedi ps i mtu if minimummtu mtu mtu 0 minimummtu mtu logger normal this reducing the mtu to minimummtu if mtu udp socket handler min mtu node on too lowmtu minimummtu udp socket handler min mtu redetect address processdetectedips plugindetectedips plugindetectedips plugindetectedips udpsockethandler min_mtu ontoolowmtu udpsockethandler min_mtu redetectaddress public void redetect address freenet inet address newip detect primaryip address false nodeip port detector detectors synchronized this if arrays equals newip lastip return lastip newip detectors port detectors for int i 0 i detectors length i detectors i update node write node file redetectaddress freenetinetaddress detectprimaryipaddress nodeipportdetector portdetectors writenodefile public void set oldip address freenet inet address freenet address this oldip address freenet address setoldipaddress freenetinetaddress freenetaddress oldipaddress freenetaddress public int register configs sub config node config int sort order ip address override node config register ip address override sort order true false nodeip dectector ip override nodeip dectector ip override long new string callback override public string get if overrideip address string null return else return overrideip address string override public void set string val throws invalid config value exception boolean had valid address override has valid address override fixme do we need to tell anyone if val length 0 set to null overrideip address string val overrideip address null lastip address null redetect address return freenet inet address addr try addr new freenet inet address val false true catch hostname syntax exception e throw new invalid config value exception l10n unknown host error inip override error hostname or ip address syntax error catch unknown host exception e throw new invalid config value exception l10n unknown host error inip override error e get message compare as i ps if addr equals overrideip address return overrideip address string val overrideip address addr lastip address null synchronized this has valid address override true if had valid address override on get valid address override redetect address has valid address override true overrideip address string node config get string ip address override if overrideip address string length 0 overrideip address null else try overrideip address new freenet inet address overrideip address string false true catch hostname syntax exception e synchronized this has valid address override false string msg invalid ip override syntax overrideip address string in config e get message logger error this msg system err println msg but starting up anyway ignoring the configured ip override overrideip address null catch unknown host exception e fixme this never happens for this reason with current freenet inet address string boolean boolean code perhaps it needs review string msg unknown host overrideip address string in config e get message logger error this msg system err println msg but starting up anyway with no ip override overrideip address null temporary ip address hint node config register tempip address hint sort order true false nodeip dectector temp address hint nodeip dectector temp address hint long new string callback override public string get return override public void set string val throws invalid config value exception if val length 0 return if overrideip address null return try oldip address new freenet inet address val false catch unknown host exception e throw new invalid config value exception unknown host e get message redetect address string ip hint string node config get string tempip address hint if ip hint string length 0 try oldip address new freenet inet address ip hint string false catch unknown host exception e string msg unknown host ip hint string in config e get message logger error this msg system err println msg oldip address null return sort order registerconfigs subconfig nodeconfig sortorder nodeconfig ipaddressoverride sortorder nodeipdectector ipoverride nodeipdectector ipoverridelong stringcallback overrideipaddressstring overrideipaddressstring invalidconfigvalueexception hadvalidaddressoverride hasvalidaddressoverride overrideipaddressstring overrideipaddress lastipaddress redetectaddress freenetinetaddress freenetinetaddress hostnamesyntaxexception invalidconfigvalueexception unknownhosterrorinipoverride unknownhostexception invalidconfigvalueexception unknownhosterrorinipoverride getmessage ips overrideipaddress overrideipaddressstring overrideipaddress lastipaddress hasvalidaddressoverride hadvalidaddressoverride ongetvalidaddressoverride redetectaddress hasvalidaddressoverride overrideipaddressstring nodeconfig getstring ipaddressoverride overrideipaddressstring overrideipaddress overrideipaddress freenetinetaddress overrideipaddressstring hostnamesyntaxexception hasvalidaddressoverride overrideipaddressstring getmessage overrideipaddress unknownhostexception freenetinetaddress overrideipaddressstring getmessage overrideipaddress nodeconfig tempipaddresshint sortorder nodeipdectector tempaddresshint nodeipdectector tempaddresshintlong stringcallback invalidconfigvalueexception overrideipaddress oldipaddress freenetinetaddress unknownhostexception invalidconfigvalueexception getmessage redetectaddress iphintstring nodeconfig getstring tempipaddresshint iphintstring oldipaddress freenetinetaddress iphintstring unknownhostexception iphintstring getmessage oldipaddress sortorder override public string get if overrideip address string null return else return overrideip address string overrideipaddressstring overrideipaddressstring override public void set string val throws invalid config value exception boolean had valid address override has valid address override fixme do we need to tell anyone if val length 0 set to null overrideip address string val overrideip address null lastip address null redetect address return freenet inet address addr try addr new freenet inet address val false true catch hostname syntax exception e throw new invalid config value exception l10n unknown host error inip override error hostname or ip address syntax error catch unknown host exception e throw new invalid config value exception l10n unknown host error inip override error e get message compare as i ps if addr equals overrideip address return overrideip address string val overrideip address addr lastip address null synchronized this has valid address override true if had valid address override on get valid address override redetect address invalidconfigvalueexception hadvalidaddressoverride hasvalidaddressoverride overrideipaddressstring overrideipaddress lastipaddress redetectaddress freenetinetaddress freenetinetaddress hostnamesyntaxexception invalidconfigvalueexception unknownhosterrorinipoverride unknownhostexception invalidconfigvalueexception unknownhosterrorinipoverride getmessage ips overrideipaddress overrideipaddressstring overrideipaddress lastipaddress hasvalidaddressoverride hadvalidaddressoverride ongetvalidaddressoverride redetectaddress node config register tempip address hint sort order true false nodeip dectector temp address hint nodeip dectector temp address hint long new string callback override public string get return nodeconfig tempipaddresshint sortorder nodeipdectector tempaddresshint nodeipdectector tempaddresshintlong stringcallback override public void set string val throws invalid config value exception if val length 0 return if overrideip address null return try oldip address new freenet inet address val false catch unknown host exception e throw new invalid config value exception unknown host e get message redetect address invalidconfigvalueexception overrideipaddress oldipaddress freenetinetaddress unknownhostexception invalidconfigvalueexception getmessage redetectaddress start all ip detection related processes public void start boolean have valid address override has valid address override if have valid address override on not get valid address override node executor execute ip detector ip address re detector redetect address 60 second delay for inserting ark to avoid reinserting more than necessary if we don t detect ip on startup not a fast runnable as it can take a while to start the insert node get ticker queue timed job new runnable public void run nodeip port detector detectors synchronized this detectors port detectors for int i 0 i detectors length i detectors i startark 60 1000 havevalidaddressoverride hasvalidaddressoverride havevalidaddressoverride onnotgetvalidaddressoverride ipdetector redetectaddress fastrunnable getticker queuetimedjob nodeipportdetector portdetectors node get ticker queue timed job new runnable public void run nodeip port detector detectors synchronized this detectors port detectors for int i 0 i detectors length i detectors i startark getticker queuetimedjob nodeipportdetector portdetectors public void on connected peer ip detector manager maybe run onconnectedpeer ipdetectormanager mayberun public void registerip detector plugin fred pluginip detector detector ip detector manager register detector plugin detector registeripdetectorplugin fredpluginipdetector ipdetectormanager registerdetectorplugin public void unregisterip detector plugin fred pluginip detector detector ip detector manager unregister detector plugin detector unregisteripdetectorplugin fredpluginipdetector ipdetectormanager unregisterdetectorplugin public synchronized boolean is detecting return has detectedpm has detectediad isdetecting hasdetectedpm hasdetectediad void has detectedpm if logminor logger minor this has detectedpm called new exception debug synchronized this has detectedpm true hasdetectedpm hasdetectedpm hasdetectedpm public int get minimum detectedmtu return minimummtu 0 minimummtu 1500 getminimumdetectedmtu public void set maybe symmetric if ip detector manager null ip detector manager is empty if maybe symmetric alert null maybe symmetric alert new simple user alert true l10n maybe symmetric title l10n maybe symmetric l10n maybe symmetric short user alert error if node client core null node client core alerts null node client core alerts register maybe symmetric alert else if maybe symmetric alert null node client core alerts unregister maybe symmetric alert setmaybesymmetric ipdetectormanager ipdetectormanager isempty maybesymmetricalert maybesymmetricalert simpleuseralert maybesymmetrictitle maybesymmetric maybesymmetricshort useralert clientcore clientcore clientcore maybesymmetricalert maybesymmetricalert clientcore maybesymmetricalert public void register port forward plugin fred plugin port forward forward ip detector manager register port forward plugin forward registerportforwardplugin fredpluginportforward ipdetectormanager registerportforwardplugin public void unregister port forward plugin fred plugin port forward forward ip detector manager unregister port forward plugin forward unregisterportforwardplugin fredpluginportforward ipdetectormanager unregisterportforwardplugin todo ugly deal with multiple instances properly public synchronized void register bandwidth indicator plugin fred plugin bandwidth indicator indicator bandwidth indicator indicator registerbandwidthindicatorplugin fredpluginbandwidthindicator bandwidthindicator bandwidth indicator indicator public synchronized void unregister bandwidth indicator plugin fred plugin bandwidth indicator indicator bandwidth indicator null bandwidthindicator unregisterbandwidthindicatorplugin fredpluginbandwidthindicator bandwidthindicator bandwidth indicator null public synchronized fred plugin bandwidth indicator get bandwidth indicator return bandwidth indicator bandwidthindicator fredpluginbandwidthindicator getbandwidthindicator bandwidthindicator boolean has valid address override synchronized this return has valid address override hasvalidaddressoverride hasvalidaddressoverride private void on get valid address override node client core alerts unregister invalid address override alert ongetvalidaddressoverride clientcore invalidaddressoverridealert private void on not get valid address override node client core alerts register invalid address override alert onnotgetvalidaddressoverride clientcore invalidaddressoverridealert public void add connection type box html node content node ip detector manager add connection type box content node addconnectiontypebox htmlnode contentnode ipdetectormanager addconnectiontypebox contentnode public boolean no detect plugins return ip detector manager has detectors nodetectplugins ipdetectormanager hasdetectors transient field fld alt btree field index altbtreefieldindex private final void locate field fld class descriptor locate field cls field name if fld null throw new storage error storage error indexed field not found class name field name locatefield classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return new field fld getkeyfields public void on load cls class descriptor load class get storage class name locate field onload classdescriptor loadclass getstorage classname locatefield alt btree field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate field type check type fld get type altbtreefieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefield checktype gettype private key extract key i persistent obj try field f fld key key null switch type case class descriptor tp boolean key new key f get boolean obj break case class descriptor tp byte key new key f get byte obj break case class descriptor tp short key new key f get short obj break case class descriptor tp char key new key f get char obj break case class descriptor tp int key new key f get int obj break case class descriptor tp object i persistent ptr i persistent f get obj if ptr null ptr is persistent get storage make persistent ptr key new key ptr break case class descriptor tp long key new key f get long obj break case class descriptor tp date key new key date f get obj break case class descriptor tp float key new key f get float obj break case class descriptor tp double key new key f get double obj break case class descriptor tp enum key new key enum f get obj break case class descriptor tp string key new key string f get obj break case class descriptor tp raw key new key comparable f get obj break default assert failed invalid type return key catch exception x throw new storage error storage error access violation x extractkey ipersistent classdescriptor tpboolean getboolean classdescriptor tpbyte getbyte classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tpobject ipersistent ipersistent ispersistent getstorage makepersistent classdescriptor tplong getlong classdescriptor tpdate classdescriptor tpfloat getfloat classdescriptor tpdouble getdouble classdescriptor tpenum classdescriptor tpstring classdescriptor tpraw storageerror storageerror access_violation public boolean put t obj return super insert extract key obj obj false null extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public synchronized void append t obj key key try switch type case class descriptor tp int key new key int autoinc count fld set int obj int autoinc count break case class descriptor tp long key new key autoinc count fld set long obj autoinc count break default throw new storage error storage error unsupported index type fld get type catch exception x throw new storage error storage error access violation x autoinc count 1 obj modify super insert key obj false classdescriptor tpint autoinccount setint autoinccount classdescriptor tplong autoinccount setlong autoinccount storageerror storageerror unsupported_index_type gettype storageerror storageerror access_violation autoinccount public t get prefix string prefix array list t list get list new key prefix true new key prefix character max value false return t list to array t array new instance cls list size getprefix arraylist getlist max_value toarray newinstance public t prefix search string key array list t list prefix search list key return t list to array t array new instance cls list size prefixsearch arraylist prefixsearchlist toarray newinstance public t get key from key till array list t list new array list if root null root find check key from check key till height list return t list to array t array new instance cls list size arraylist arraylist checkkey checkkey toarray newinstance public t to persistent array t arr t array new instance cls n elems if root null root traverse forward height arr 0 return arr topersistentarray newinstance nelems traverseforward public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class alt btree case insensitive field index t extends i persistent extends alt btree field index t alt btree case insensitive field index altbtreecaseinsensitivefieldindex ipersistent altbtreefieldindex altbtreecaseinsensitivefieldindex alt btree case insensitive field index alt btree case insensitive field index class cls string field name boolean unique super cls field name unique altbtreecaseinsensitivefieldindex altbtreecaseinsensitivefieldindex fieldname fieldname key check key key key if key null key oval instanceof string key new key string key oval to lower case key inclusion 0 return super check key key checkkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive construct a spcetrum color map public spectrum colormap spectrumcolormap convert a value in the range 0 1 to an rgb color param v a value in the range 0 1 return an rgb color public int get color float v return spectrum wavelength torgb 380 400 image math clamp v 0 1 0f getcolor wavelengthtorgb imagemath private int edge color 0xff000000 public crystallize filter set scale 16 set randomness 0 0f edgecolor crystallizefilter setscale setrandomness public void set edge thickness float edge thickness this edge thickness edge thickness setedgethickness edgethickness edgethickness edgethickness public float get edge thickness return edge thickness getedgethickness edgethickness public void set fade edges boolean fade edges this fade edges fade edges setfadeedges fadeedges fadeedges fadeedges public boolean get fade edges return fade edges getfadeedges fadeedges public void set edge color int edge color this edge color edge color setedgecolor edgecolor edgecolor edgecolor public int get edge color return edge color getedgecolor edgecolor override public int get pixel int x int y int in pixels int width int height float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch nx 1000 ny 1000 reduce artifacts around 0 0 float f evaluate nx ny float f1 results 0 distance float f2 results 1 distance int srcx image math clamp int results 0 x 1000 scale 0 width 1 int srcy image math clamp int results 0 y 1000 scale 0 height 1 int v in pixels srcy width srcx f f2 f1 edge thickness f image math smooth step 0 edge thickness f if fade edges srcx image math clamp int results 1 x 1000 scale 0 width 1 srcy image math clamp int results 1 y 1000 scale 0 height 1 int v2 in pixels srcy width srcx v2 image math mix colors 0 5f v2 v v image math mix colors f v2 v else v image math mix colors f edge color v return v getpixel inpixels imagemath imagemath inpixels edgethickness imagemath smoothstep edgethickness fadeedges imagemath imagemath inpixels imagemath mixcolors imagemath mixcolors imagemath mixcolors edgecolor override public string to string return stylize crystallize tostring logger register log threshold callback new log threshold callback override public void should update logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public would block exception string string super string wouldblockexception public would block exception super wouldblockexception http blogs sun com jrose entry longjumps considered inexpensive resubmit damnit override public final synchronized throwable fill in stack trace if logdebug return super fill in stack trace return null longjumps_considered_inexpensive fillinstacktrace fillinstacktrace public static bloom filter create filter int length int k boolean counting if length 0 return new null bloom filter length k if counting return new counting bloom filter length k else return new binary bloom filter length k bloomfilter createfilter nullbloomfilter countingbloomfilter binarybloomfilter public static bloom filter create filter file file int length int k boolean counting throws io exception if length 0 return new null bloom filter length k if counting return new counting bloom filter file length k else return new binary bloom filter file length k bloomfilter createfilter ioexception nullbloomfilter countingbloomfilter binarybloomfilter protected bloom filter int length int k if length 8 0 length length 8 this length length this k k bloomfilter core public void add key byte key random hashes get hashes key lock write lock lock try for int i 0 i k i set bit hashes next int length finally lock write lock unlock if forked filter null forked filter add key key addkey gethashes writelock setbit nextint writelock forkedfilter forkedfilter addkey add to the forked filter only public void add key forked byte key if forked filter null forked filter add key key addkeyforked forkedfilter forkedfilter addkey public boolean check filter byte key random hashes get hashes key lock read lock lock try for int i 0 i k i if get bit hashes next int length return false finally lock read lock unlock return true checkfilter gethashes readlock getbit nextint readlock public void remove key byte key random hashes get hashes key lock write lock lock try for int i 0 i k i unset bit hashes next int length finally lock write lock unlock if forked filter null forked filter remove key key removekey gethashes writelock unsetbit nextint writelock forkedfilter forkedfilter removekey bits and hashes protected abstract boolean get bit int offset getbit protected abstract boolean get bit int offset protected abstract void set bit int offset getbit setbit protected abstract void set bit int offset protected abstract void unset bit int offset setbit unsetbit wierd impl s should override public void unset all int x filter limit for int i 0 i x i filter put i byte 0 unsetall protected random get hashes byte key return new mersenne twister key gethashes mersennetwister create an empty in memory copy of bloom filter new updates are written to both filters this is written back to disk on merge public void merge lock write lock lock try if forked filter null return lock forked lock forked filter lock write lock forked lock lock try filter position 0 forked filter filter position 0 filter put forked filter filter filter position 0 forked filter close forked filter null finally forked lock unlock finally lock write lock unlock writelock forkedfilter forkedlock forkedfilter writelock forkedlock forkedfilter forkedfilter forkedfilter forkedfilter forkedlock writelock public void discard lock write lock lock try if forked filter null return forked filter close forked filter null finally lock write lock unlock writelock forkedfilter forkedfilter forkedfilter writelock misc calculate optimal k value param filter length filter length in bits param max key return optimal k public static int optimialk int filter length long max key long k math round math log 2 filter length max key if k 64 k 64 if k 1 k 1 return int k filterlength maxkey filterlength maxkey filterlength maxkey public int getk return k public boolean need rebuild boolean needrebuild need rebuild need rebuild false return needrebuild needrebuild _needrebuild needrebuild needrebuild _needrebuild public void force if filter instanceof mapped byte buffer mapped byte buffer filter force mappedbytebuffer mappedbytebuffer public void close if filter null force filter null forked filter null forkedfilter override protected void finalize close private int total public failure code tracker boolean insert this insert insert failurecodetracker create a failure code tracker from a simple field set param is insert whether this is an insert param fs the simple field set containing the field set non verbose form of the tracker public failure code tracker boolean is insert simple field set fs this insert is insert iterator string i fs direct subset name iterator while i has next string name i next simple field set f fs subset name we ignore the description if there is one we just want the count int num integer parse int name int count integer parse int f get count if count 0 throw new illegal argument exception count 0 map put integer value of num new item count total count failurecodetracker simplefieldset isinsert simplefieldset fieldset failurecodetracker isinsert simplefieldset isinsert directsubsetnameiterator hasnext simplefieldset parseint parseint illegalargumentexception valueof private static class item item int count this x count item this x 0 public synchronized void inc int k if map null map new hash map integer item integer key k item i map get key if i null map put key i new item i x total hashmap public synchronized void inc integer k int val if map null map new hash map integer item integer key k item i map get key if i null map put key i new item i x val total val hashmap public synchronized string to verbose string if map null return super to string empty string builder sb new string builder for map entry integer item e map entry set integer x e get key item val e get value string s insert insert exception get message x int value fetch exception get message x int value sb append val x sb append t sb append s sb append n return sb to string toverbosestring tostring stringbuilder stringbuilder entryset getkey getvalue insertexception getmessage intvalue fetchexception getmessage intvalue tostring override public synchronized string to string if map null return super to string empty string builder sb new string builder super to string sb append if map size 0 sb append empty else if map size 1 sb append one integer code integer map key set to array 0 sb append code sb append sb append map get code x else sb append map size return sb to string tostring tostring stringbuilder stringbuilder tostring keyset toarray tostring merge codes from another tracker into this one public synchronized failure code tracker merge failure code tracker source if source map null return this if map null map new hash map integer item for map entry integer item e source map entry set integer k e get key item item e get value inc k item x return this failurecodetracker failurecodetracker hashmap entryset getkey getvalue public void merge fetch exception e if insert throw new illegal state exception merging a fetch exception in an insert if e error codes null merge e error codes increment mode anyway so we get the splitfile error as well inc e mode fetchexception illegalstateexception fetchexception errorcodes errorcodes public synchronized int total count return total totalcount copy verbosely to a simple field set public synchronized simple field set to field set boolean verbose simple field set sfs new simple field set false if map null for map entry integer item e map entry set integer k e get key item item e get value int code k int value prefix num description code description prefix num count count if verbose sfs put single integer to string code description insert insert exception get message code fetch exception get message code sfs put integer to string code count item x return sfs simplefieldset simplefieldset tofieldset simplefieldset simplefieldset entryset getkey getvalue intvalue putsingle tostring insertexception getmessage fetchexception getmessage tostring public synchronized boolean is one code only return map size 1 isonecodeonly public synchronized int get first code return integer map key set to array 0 int value getfirstcode keyset toarray intvalue public synchronized boolean is fatal boolean insert if map null return false for map entry integer item e map entry set integer code e get key if e get value x 0 continue if insert if insert exception is fatal code int value return true else if fetch exception is fatal code int value return true return false isfatal entryset getkey getvalue insertexception isfatal intvalue fetchexception isfatal intvalue public void merge insert exception e if insert throw new illegal argument exception this is not an insert yet merge e called if e error codes null merge e error codes inc e get mode insertexception illegalargumentexception errorcodes errorcodes getmode public synchronized boolean is empty return map null map is empty isempty isempty public void remove from object container container item items integer ints synchronized this items map null null map values to array new item map size ints map null null map key set to array new integer map size if map null map clear if items null for int i 0 i items length i container delete items i container delete ints i if map null container activate map 5 container delete map container delete this removefrom objectcontainer toarray keyset toarray public void object on activate object container container if map null container activate map 5 objectonactivate objectcontainer override public failure code tracker clone failure code tracker tracker new failure code tracker insert tracker merge this return tracker failurecodetracker failurecodetracker failurecodetracker private static final long serial versionuid 1 public ssk verify exception string string super string serialversionuid sskverifyexception public redirect dir put file simple field set subset string identifier boolean global throws message invalid exception super subset identifier global string target subset get targeturi if target null throw new message invalid exception protocol error message missing field targeturi missing but upload from redirect identifier global try targeturi new freeneturi target catch malformedurl exception e throw new message invalid exception protocol error message invalid field invalid targeturi e identifier global if logger should log logger minor this logger minor this targeturi targeturi redirectdirputfile simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field uploadfrom malformedurlexception messageinvalidexception protocolerrormessage invalid_field shouldlog override public bucket get data return null getdata override public manifest element get element return new manifest element name targeturi getmime type manifestelement getelement manifestelement getmimetype override public void remove from object container container container activate targeturi 5 targeturi remove from container container delete this removefrom objectcontainer removefrom private int contour color 0xff000000 public contour filter contourcolor contourfilter public void set levels float levels this levels levels setlevels public float get levels return levels getlevels specifies the scale of the contours param scale the scale of the contours min value 0 max value 1 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the contours return the scale of the contours see set scale public float get scale return scale setscale getscale public void set offset float offset this offset offset setoffset public float get offset return offset getoffset public void set contour color int contour color this contour color contour color setcontourcolor contourcolor contourcolor contourcolor public int get contour color return contour color getcontourcolor contourcolor override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 short r new short 3 width int out pixels new int width height short table new short 256 int offsetl int offset 256 levels for int i 0 i 256 i table i short pixel utils clamp int 255 math floor levels i offsetl 256 levels 1 offsetl for int x 0 x width x int rgb in pixels x r 1 x short pixel utils brightness rgb for int y 0 y height y boolean y in y 0 y height 1 int next row index index width if y height 1 for int x 0 x width x int rgb in pixels next row index r 2 x short pixel utils brightness rgb for int x 0 x width x boolean x in x 0 x width 1 int w x 1 int e x 1 int v 0 if y in x in short nwb r 0 w short neb r 0 x short swb r 1 w short seb r 1 x short nw table nwb short ne table neb short sw table swb short se table seb if nw ne nw sw ne se sw se v int scale math abs nwb neb math abs nwb swb math abs neb seb math abs swb seb v 255 if v 255 v 255 if v 0 out pixels index pixel utils combine pixels in pixels index contour color pixel utils normal v out pixels index pixel utils combine pixels contour color 0xff v 24 in pixels index pixel utils normal else out pixels index in pixels index index short t t r 0 r 0 r 1 r 1 r 2 r 2 t return out pixels filterpixels inpixels transformedspace outpixels pixelutils inpixels pixelutils yin nextrowindex inpixels nextrowindex pixelutils xin yin xin outpixels pixelutils combinepixels inpixels contourcolor pixelutils outpixels pixelutils combinepixels contourcolor inpixels pixelutils outpixels inpixels outpixels override public string to string return stylize contour tostring public static void main string args throws fs parse exception peer parse exception invalid threshold exception node init exception reference signature verification exception logger setup stdout logging logger normal freenet node cpu adjusting swap request interval minor freenet node location manager debug freenet node fnp packet manager normal freenet io comm message core debug system out println secret ping cram test using real nodes system out println string wd real node secret ping test new file wd mkdir note global test init returns in ignored random source node starter global test init wd false logger error freenet node location normal freenet node simulator real node secret ping test normal freenet node networkid manager normal true dummy random source random new dummy random source diffie hellman init random node nodes new node number of nodes logger normal real node routing test class creating nodes executor executor new pooled executor allow secret pings but don t automatically send them this is the test for them freenet node networkid manager disable secret pings false freenet node networkid manager disable secret pinger true for int i 0 i number of nodes i nodes i node starter create test node 5001 i 0 wd false true true max htl 0 no dropped packets random executor 500 number of nodes store size true true false false false true true 0 true false null logger normal real node routing test class created node i logger normal real node routing test class created number of nodes nodes now link them up make kleinberg network nodes logger normal real node routing test class added small world links for int i 0 i number of nodes i nodes i start false now sit back and watch the fireworks int cycle number 0 running average avg2 new bootstrapping decaying running average 0 0 0 0 1 0 100 null while true cycle number try thread sleep 2000 catch interrupted exception e ignore node source nodes random next int number of nodes peer node verify source peers get random peer peer node pathway source peers get random peer verify logger error source verify get port number verify through get port number pathway so far avg2 current value long uid random next long long secret random next long if verify null logger error source verify peernode is null continue if pathway null logger error source pathway peernode is null continue try send the fnp store secret message to the verify node verify send sync dmt createfnp store secret uid secret null if get ack source verify uid logger error source did not get storesecret ack for uid avg2 report 0 0 continue send the request for the secret through the pathway node pathway send sync dmt createfnp secret ping uid verify get location ping htl dawn htl 0 verify get identity null long result get secret ping response source pathway uid if result secret logger error source not matched secret result avg2 report 0 0 else logger error source match secret avg2 report 1 0 catch not connected exception e logger error source what e avg2 report 0 0 catch disconnected exception e logger error source huh e avg2 report 0 0 fsparseexception peerparseexception invalidthresholdexception nodeinitexception referencesignatureverificationexception setupstdoutlogging cpuadjustingswaprequestinterval locationmanager fnppacketmanager messagecore secretping realnodesecretpingtest globaltestinit nodestarter globaltestinit realnodesecretpingtest networkidmanager dummyrandomsource dummyrandomsource diffiehellman number_of_nodes realnoderoutingtest pooledexecutor networkidmanager disablesecretpings networkidmanager disablesecretpinger number_of_nodes nodestarter createtestnode max_htl number_of_nodes storesize realnoderoutingtest realnoderoutingtest number_of_nodes makekleinbergnetwork realnoderoutingtest number_of_nodes cyclenumber runningaverage bootstrappingdecayingrunningaverage cyclenumber interruptedexception nextint number_of_nodes peernode getrandompeer peernode getrandompeer getportnumber getportnumber currentvalue nextlong nextlong fnpstoresecret sendsync createfnpstoresecret getack sendsync createfnpsecretping getlocation ping_htl dawn_htl getidentity getsecretpingresponse notconnectedexception disconnectedexception private static boolean get ack node source peer node pathway long uid throws disconnected exception wait for an accepted message filter mf accepted message filter create set source pathway set field dmt uid uid set timeout secretpong timeout set type dmt fnp accepted message msg source getusm wait for mf accepted null if msg null return false if msg get spec dmt fnp accepted return true logger error source got msg return false getack peernode disconnectedexception messagefilter mfaccepted messagefilter setsource setfield settimeout secretpong_timeout settype fnpaccepted waitfor mfaccepted getspec fnpaccepted private static long get secret ping response node source peer node pathway long uid throws disconnected exception wait for a reject or pong message filter mf pong message filter create set source pathway set field dmt uid uid set timeout secretpong timeout set type dmt fnp secret pong message filter mf reject loop message filter create set source pathway set field dmt uid uid set timeout secretpong timeout set type dmt fnp rejected loop message msg source getusm wait for mf pong or mf reject loop null if msg null logger error source fatal timeout in waiting for secretpong from get port number pathway return 2 if msg get spec dmt fnp secret pong int supplied counter msg get int dmt counter long secret msg get long dmt secret logger normal source got secret counter supplied counter return secret if msg get spec dmt fnp rejected loop logger error source top level secret ping should not reject get port number source get port number pathway return 1 return 3 getsecretpingresponse peernode disconnectedexception messagefilter mfpong messagefilter setsource setfield settimeout secretpong_timeout settype fnpsecretpong messagefilter mfrejectloop messagefilter setsource setfield settimeout secretpong_timeout settype fnprejectedloop waitfor mfpong mfrejectloop getportnumber getspec fnpsecretpong suppliedcounter getint getlong suppliedcounter getspec fnprejectedloop getportnumber getportnumber static void make kleinberg network node nodes for int i 0 i nodes length i node a nodes i normalise the probabilities double norm 0 0 for int j 0 j nodes length j node b nodes j if a get location b get location continue norm 1 0 distance a b create degree 2 outgoing connections for int k 0 k nodes length k node b nodes k if a get location b get location continue double p 1 0 distance a b norm for int n 0 n degree 2 n if math random p try a connect b b connect a catch fs parse exception e logger error real node secret ping test class cannot connect e catch peer parse exception e logger error real node secret ping test class cannot connect 2 e catch freenet io comm reference signature verification exception e logger error real node secret ping test class cannot connect 3 e break makekleinbergnetwork getlocation getlocation getlocation getlocation fsparseexception realnodesecretpingtest peerparseexception realnodesecretpingtest referencesignatureverificationexception realnodesecretpingtest static double distance node a node b double al a get location double bl b get location return location distance al bl getlocation getlocation static string get port number peer node p if p null p get peer null return null return integer to string p get peer get port getportnumber peernode getpeer tostring getpeer getport static string get port number node n if n null return null return integer to string n get darknet port number getportnumber tostring getdarknetportnumber private boolean resize true public shear filter shearfilter public void set resize boolean resize this resize resize setresize public boolean is resize return resize isresize public void setx angle float xangle this xangle xangle initialize setxangle public float getx angle return xangle getxangle public void sety angle float yangle this yangle yangle initialize setyangle public float gety angle return yangle getyangle private void initialize shx float math sin xangle shy float math sin yangle override protected void transform space rectangle r float tangent float math tan xangle xoffset r height tangent if tangent 0 0 tangent tangent r width int r height tangent r width 0 999999f tangent float math tan yangle yoffset r width tangent if tangent 0 0 tangent tangent r height int r width tangent r height 0 999999f transformspace override protected void transform inverse int x int y float out out 0 x xoffset y shx out 1 y yoffset x shy transforminverse override public string to string return distort shear tostring see plugins mdns discovery javax jmdns service info create string string int string public service info impl string type string name int port string text this type name port 0 0 text mdnsdiscovery serviceinfo serviceinfoimpl see plugins mdns discovery javax jmdns service info create string string int int int string public service info impl string type string name int port int weight int priority string text this type name port weight priority byte null try byte array output stream out new byte array output stream text length writeutf out text byte data out to byte array this set text new byte data length 1 this get text 0 byte data length system arraycopy data 0 this get text 1 data length catch io exception e throw new runtime exception unexpected exception e mdnsdiscovery serviceinfo serviceinfoimpl bytearrayoutputstream bytearrayoutputstream tobytearray settext gettext gettext ioexception runtimeexception see plugins mdns discovery javax jmdns service info create string string int int int hashtable public service info impl string type string name int port int weight int priority hashtable props this type name port weight priority new byte 0 if props null try byte array output stream out new byte array output stream 256 for enumeration e props keys e has more elements string key string e next element object val props get key byte array output stream out2 new byte array output stream 100 writeutf out2 key if val instanceof string out2 write writeutf out2 string val else if val instanceof byte out2 write byte bval byte val out2 write bval 0 bval length else if val no value throw new illegal argument exception invalid property value val byte data out2 to byte array out write data length out write data 0 data length this set text out to byte array catch io exception e throw new runtime exception unexpected exception e mdnsdiscovery serviceinfo serviceinfoimpl bytearrayoutputstream bytearrayoutputstream hasmoreelements nextelement bytearrayoutputstream bytearrayoutputstream no_value illegalargumentexception tobytearray settext tobytearray ioexception runtimeexception see plugins mdns discovery javax jmdns service info create string string int int int byte public service info impl string type string name int port int weight int priority byte text this type type this name name this port port this weight weight this priority priority this set text text mdnsdiscovery serviceinfo serviceinfoimpl settext construct a service record during service discovery service info impl string type string name if type ends with throw new illegal argument exception type must be fully qualified dns name ending in type this type type this name name serviceinfoimpl endswith illegalargumentexception during recovery we need to duplicate service info to reregister them service info impl service info impl info if info null this type info type this name info name this port info port this weight info weight this priority info priority this set text info get text serviceinfoimpl serviceinfoimpl settext gettext see plugins mdns discovery javax jmdns service info get type public string get type return type mdnsdiscovery serviceinfo gettype gettype see plugins mdns discovery javax jmdns service info get name public string get name return name mdnsdiscovery serviceinfo getname getname sets the service instance name param name unqualified service instance name such as code foobar code void set name string name this name name setname see plugins mdns discovery javax jmdns service info get qualified name public string get qualified name return name type mdnsdiscovery serviceinfo getqualifiedname getqualifiedname see plugins mdns discovery javax jmdns service info get server public string get server return server mdnsdiscovery serviceinfo getserver getserver see plugins mdns discovery javax jmdns service info get host address public string get host address return addr null addr get host address mdnsdiscovery serviceinfo gethostaddress gethostaddress gethostaddress public inet address get address return addr inetaddress getaddress see plugins mdns discovery javax jmdns service info get inet address public inet address get inet address return addr mdnsdiscovery serviceinfo getinetaddress inetaddress getinetaddress see plugins mdns discovery javax jmdns service info get port public int get port return port mdnsdiscovery serviceinfo getport getport see plugins mdns discovery javax jmdns service info get priority public int get priority return priority mdnsdiscovery serviceinfo getpriority getpriority see plugins mdns discovery javax jmdns service info get weight public int get weight return weight mdnsdiscovery serviceinfo getweight getweight see plugins mdns discovery javax jmdns service info get text bytes public byte get text bytes return get text mdnsdiscovery serviceinfo gettextbytes gettextbytes gettext see plugins mdns discovery javax jmdns service info get text string public string get text string if get text null get text length 0 get text length 1 get text 0 0 return null return readutf get text 0 get text length mdnsdiscovery serviceinfo gettextstring gettextstring gettext gettext gettext gettext gettext gettext see plugins mdns discovery javax jmdns service info geturl public string geturl return geturl http mdnsdiscovery serviceinfo see plugins mdns discovery javax jmdns service info geturl java lang string public string geturl string protocol string url protocol get host address get port string path get property string path if path null if path index of 0 url path else url path starts with path path return url mdnsdiscovery serviceinfo gethostaddress getport getpropertystring indexof startswith see plugins mdns discovery javax jmdns service info get property bytes java lang string public synchronized byte get property bytes string name return byte get properties get name mdnsdiscovery serviceinfo getpropertybytes getpropertybytes getproperties see plugins mdns discovery javax jmdns service info get property string java lang string public synchronized string get property string string name byte data byte get properties get name if data null return null if data no value return true return readutf data 0 data length mdnsdiscovery serviceinfo getpropertystring getpropertystring getproperties no_value see plugins mdns discovery javax jmdns service info get property names public enumeration get property names hashtable props get properties return props null props keys new vector elements mdnsdiscovery serviceinfo getpropertynames getpropertynames getproperties write a utf string with a length to a stream void writeutf output stream out string str throws io exception for int i 0 len str length i len i int c str char at i if c 0x0001 c 0x007f out write c else if c 0x07ff out write 0xe0 c 12 0x0f out write 0x80 c 6 0x3f out write 0x80 c 0 0x3f else out write 0xc0 c 6 0x1f out write 0x80 c 0 0x3f outputstream ioexception charat read data bytes as a utf stream string readutf byte data int off int len string buffer buf new string buffer for int end off len off end int ch data off 0xff switch ch 4 case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 0xxxxxxx break case 12 case 13 if off len return null 110x xxxx 10xx xxxx ch ch 0x1f 6 data off 0x3f break case 14 if off 2 len return null 1110 xxxx 10xx xxxx 10xx xxxx ch ch 0x0f 12 data off 0x3f 6 data off 0x3f break default if off 1 len return null 10xx xxxx 1111 xxxx ch ch 0x3f 4 data off 0x0f break buf append char ch return buf to string stringbuffer stringbuffer tostring synchronized hashtable get properties if props null get text null hashtable props new hashtable int off 0 while off get text length length of the next key value pair int len get text off 0xff if len 0 off len get text length props clear break look for the int i 0 for i len get text off i i get the property name string name readutf get text off i if name null props clear break if i len props put name no value else byte value new byte len i system arraycopy get text off i value 0 len i props put name value off len this props props return props getproperties gettext gettext gettext gettext gettext gettext no_value gettext jmdns callback to update a dns record public void update record jmdns impl jmdns long now dns record rec if rec null rec is expired now switch rec type case dns constants type a i pv4 case dns constants type aaaa i pv6 fixme pjyf oct 14 2004 this has not been tested if rec name equals server addr dns record address rec get address break case dns constants type srv if rec name equals get qualified name dns record service srv dns record service rec server srv server port srv port weight srv weight priority srv priority addr null changed to use get cache instead jeffs update record jmdns now dns record jmdns cache get server type a class in update record jmdns now dns record jmdns get cache get server dns constants type a dns constants class in break case dns constants type txt if rec name equals get qualified name dns record text txt dns record text rec set text txt text break future design pattern this is done to notify the wait loop in method jmdns get service info type name timeout if has data get dns null get dns handle service resolved this set dns null synchronized this notify all updaterecord jmdnsimpl dnsrecord isexpired dnsconstants type_a ipv4 dnsconstants type_aaaa ipv6 dnsrecord getaddress dnsconstants type_srv getqualifiedname dnsrecord dnsrecord getcache updaterecord dnsrecord type_a class_in updaterecord dnsrecord getcache dnsconstants type_a dnsconstants class_in dnsconstants type_txt getqualifiedname dnsrecord dnsrecord settext getserviceinfo hasdata getdns getdns handleserviceresolved setdns notifyall returns true if the service info is filled with data public boolean has data return server null addr null get text null hasdata gettext state machine sets the state and notifies all objects that wait on the service info public synchronized void advance state state state advance notify all serviceinfo advancestate notifyall sets the state and notifies all objects that wait on the service info synchronized void revert state state state revert notify all serviceinfo revertstate notifyall sets the state and notifies all objects that wait on the service info synchronized void cancel state dns state canceled notify all serviceinfo dnsstate notifyall returns the current state of this info public dns state get state return state dnsstate getstate public int hash code return get qualified name hash code hashcode getqualifiedname hashcode public boolean equals object obj return obj instanceof service info impl get qualified name equals service info impl obj get qualified name serviceinfoimpl getqualifiedname serviceinfoimpl getqualifiedname public string get nice text string string buffer buf new string buffer for int i 0 len get text length i len i if i 20 buf append break int ch get text i 0xff if ch ch 127 buf append 0 buf append integer to string ch 8 else buf append char ch return buf to string getnicetextstring stringbuffer stringbuffer gettext gettext tostring tostring public string to string string buffer buf new string buffer buf append service buf append get qualified name buf append buf append get address buf append buf append port buf append buf append get nice text string buf append return buf to string tostring stringbuffer stringbuffer getqualifiedname getaddress getnicetextstring tostring public void add answers dns outgoing out int ttl host info local host throws io exception out add answer new pointer type dns constants type ptr dns constants class in ttl get qualified name 0 out add answer new service get qualified name dns constants type srv dns constants class in dns constants class unique ttl priority weight port local host get name 0 out add answer new text get qualified name dns constants type txt dns constants class in dns constants class unique ttl get text 0 addanswers dnsoutgoing hostinfo localhost ioexception addanswer dnsconstants type_ptr dnsconstants class_in getqualifiedname addanswer getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique localhost getname addanswer getqualifiedname dnsconstants type_txt dnsconstants class_in dnsconstants class_unique gettext public void set task timer task task this task task settask timertask public timer task get task return task timertask gettask public void set text byte text this text text settext public byte get text return text gettext public void set dns jmdns impl dns this dns dns setdns jmdnsimpl public jmdns impl get dns return dns jmdnsimpl getdns public config data node node boolean with current boolean with defaults boolean with sort order boolean with expert flag boolean with force write flag boolean with short description boolean with long description boolean with data types string identifier this node node this with current with current this with defaults with defaults this with sort order with sort order this with expert flag with expert flag this with force write flag with force write flag this with short description with short description this with long description with long description this with data types with data types this identifier identifier configdata withcurrent withdefaults withsortorder withexpertflag withforcewriteflag withshortdescription withlongdescription withdatatypes withcurrent withcurrent withdefaults withdefaults withsortorder withsortorder withexpertflag withexpertflag withforcewriteflag withforcewriteflag withshortdescription withshortdescription withlongdescription withlongdescription withdatatypes withdatatypes override public simple field set get field set simple field set fs new simple field set true if with current simple field set current node config export field set config request type current settings true if current is empty fs put current current if with defaults simple field set default settings node config export field set config request type default settings false if default settings is empty fs put default default settings if with sort order simple field set sort order node config export field set config request type sort order false if sort order is empty fs put sort order sort order if with expert flag simple field set expert flag node config export field set config request type expert flag false if expert flag is empty fs put expert flag expert flag if with force write flag simple field set force write flag node config export field set config request type force write flag false if force write flag is empty fs put force write flag force write flag if with short description simple field set short description node config export field set config request type short description false if short description is empty fs put short description short description if with long description simple field set long description node config export field set config request type long description false if long description is empty fs put long description long description if with data types simple field set type node config export field set config request type data type false if type is empty fs put data type type if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset withcurrent simplefieldset exportfieldset requesttype current_settings isempty withdefaults simplefieldset defaultsettings exportfieldset requesttype default_settings defaultsettings isempty defaultsettings withsortorder simplefieldset sortorder exportfieldset requesttype sort_order sortorder isempty sortorder sortorder withexpertflag simplefieldset expertflag exportfieldset requesttype expert_flag expertflag isempty expertflag expertflag withforcewriteflag simplefieldset forcewriteflag exportfieldset requesttype force_write_flag forcewriteflag isempty forcewriteflag forcewriteflag withshortdescription simplefieldset shortdescription exportfieldset requesttype short_description shortdescription isempty shortdescription shortdescription withlongdescription simplefieldset longdescription exportfieldset requesttype long_description longdescription isempty longdescription longdescription withdatatypes simplefieldset exportfieldset requesttype data_type isempty datatype putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message config data goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message configdata override public void remove from object container container container delete this removefrom objectcontainer protected boolean alpha false public image function2d buffered image image this image false imagefunction2d bufferedimage public image function2d buffered image image boolean alpha this image zero alpha imagefunction2d bufferedimage public image function2d buffered image image int edge action boolean alpha init getrgb image 0 0 image get width image get height null image get width image get height edge action alpha imagefunction2d bufferedimage edgeaction getwidth getheight getwidth getheight edgeaction public image function2d int pixels int width int height int edge action boolean alpha init pixels width height edge action alpha imagefunction2d edgeaction edgeaction public image function2d image image this image zero false imagefunction2d public image function2d image image int edge action boolean alpha pixel grabber pg new pixel grabber image 0 0 1 1 null 0 1 try pg grab pixels catch interrupted exception e throw new runtime exception interrupted waiting for pixels if pg status image observer abort 0 throw new runtime exception image fetch aborted init int pg get pixels pg get width pg get height edge action alpha imagefunction2d edgeaction pixelgrabber pixelgrabber grabpixels interruptedexception runtimeexception imageobserver runtimeexception getpixels getwidth getheight edgeaction a convenience method for getting argb pixels from an image this tries to avoid the performance penalty of buffered image getrgb unmanaging the image public int getrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb return int image get raster get data elements x y width height pixels return image getrgb x y width height pixels 0 width bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster getdataelements public void init int pixels int width int height int edge action boolean alpha this pixels pixels this width width this height height this edge action edge action this alpha alpha edgeaction edgeaction edgeaction public float evaluate float x float y int ix int x int iy int y if edge action wrap ix image math mod ix width iy image math mod iy height else if ix 0 iy 0 ix width iy height if edge action zero return 0 if ix 0 ix 0 else if ix width ix width 1 if iy 0 iy 0 else if iy height iy height 1 return alpha pixels iy width ix 24 0xff 255 0f pixel utils brightness pixels iy width ix 255 0f edgeaction imagemath imagemath edgeaction pixelutils public void set edge action int edge action this edge action edge action setedgeaction edgeaction edgeaction edgeaction public int get edge action return edge action getedgeaction edgeaction public int get width return width getwidth public int get height return height getheight public int get pixels return pixels getpixels final string prefix public output stream logger int prio string prefix this prio prio this prefix prefix outputstreamlogger override public void write int b logger log static this prefix char b prio logstatic override public void write byte buf int offset int length logger log static this prefix new string buf offset length prio logstatic override public void write byte buf write buf 0 buf length private static final long serial versionuid 1 public dummy random source serialversionuid dummyrandomsource public dummy random source public dummy random source long seed set seed seed dummyrandomsource dummyrandomsource setseed override public int accept entropy entropy source source long data int entropy guess return 0 acceptentropy entropysource entropyguess override public int accept timer entropy entropy source timer return 0 accepttimerentropy entropysource override public int accept timer entropy entropy source fnp timing source double bias return 0 accepttimerentropy entropysource fnptimingsource override public int accept entropy bytes entropy source my packet data source byte buf int offset int length double bias return 0 acceptentropybytes entropysource mypacketdatasource override public void close private static final long serial versionuid 1 public packet sequence exception string string super string serialversionuid packetsequenceexception override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog public split file inserter segment split file inserter parent boolean persistent base client putter putter short splitfile algo int check block count bucket orig data blocks insert context block insert context boolean getchk only int seg no object container container super persistent this parent parent this getchk only getchk only this persistent persistent this errors new failure code tracker true this block insert context block insert context this splitfile algo splitfile algo this data blocks orig data blocks check blocks new bucket check block count checkur is new clientchk check block count dataur is new clientchk orig data blocks length data retries new int orig data blocks length check retries new int check block count data finished new boolean orig data blocks length check finished new boolean check block count data failed new boolean orig data blocks length check failed new boolean check block count data consecutivern fs new int orig data blocks length check consecutivern fs new int check block count blocks new array list integer putter add blocks dataur is length checkur is length container putter add must succeed blocks dataur is length checkur is length container this seg no seg no if persistent container activate block insert context 1 max retries block insert context max insert retries this putter putter splitfileinsertersegment splitfileinserter baseclientputter splitfilealgo checkblockcount origdatablocks insertcontext blockinsertcontext getchkonly segno objectcontainer getchkonly getchkonly failurecodetracker blockinsertcontext blockinsertcontext splitfilealgo splitfilealgo datablocks origdatablocks checkblocks checkblockcount checkuris checkblockcount datauris origdatablocks dataretries origdatablocks checkretries checkblockcount datafinished origdatablocks checkfinished checkblockcount datafailed origdatablocks checkfailed checkblockcount dataconsecutivernfs origdatablocks checkconsecutivernfs checkblockcount arraylist addblocks datauris checkuris addmustsucceedblocks datauris checkuris segno segno blockinsertcontext maxretries blockinsertcontext maxinsertretries resume an insert segment throws resume exception public split file inserter segment split file inserter parent boolean persistent base client putter putter simple field set fs short splitfile algorithm insert context ctx boolean getchk only int seg no client context context object container container throws resume exception super persistent this parent parent this splitfile algo splitfile algorithm this getchk only getchk only this persistent persistent this block insert context ctx this max retries ctx max insert retries this seg no seg no if split file inserter segment equals fs get type throw new resume exception wrong type fs get type finished fields string to bool fs get finished false encoded true started fields string to bool fs get started false simple field set errorsfs fs subset errors if errorsfs null this errors new failure code tracker true errorsfs else this errors new failure code tracker true if finished errors is empty to throw insert exception construct errors blocks goturi 0 blocks completed 0 simple field set datafs fs subset data blocks if datafs null throw new resume exception no data blocks string tmp datafs get count if tmp null throw new resume exception no data block count int data block count try data block count integer parse int tmp catch number format exception e throw new resume exception corrupt data blocks count e tmp hasur is true data blocks new bucket data block count dataur is new clientchk data block count data retries new int data block count data consecutivern fs new int data block count data finished new boolean data block count data failed new boolean data block count blocks new array list integer this putter putter check blocks first because if there are missing check blocks we need all the data blocks so we can re encode simple field set checkfs fs subset check blocks if checkfs null tmp checkfs get count if tmp null throw new resume exception check blocks but no check block count int check block count try check block count integer parse int tmp catch number format exception e throw new resume exception corrupt check blocks count e tmp check blocks new bucket check block count checkur is new clientchk check block count check retries new int check block count check consecutivern fs new int check block count check finished new boolean check block count check failed new boolean check block count for int i 0 i check block count i string index integer to string i simple field set blockfs checkfs subset index if blockfs null hasur is false encoded false logger normal this clearing encoded because block i of seg no missing continue tmp blockfs get uri if tmp null try checkur is i clientchk client key get base key new freeneturi tmp blocks goturi catch malformedurl exception e throw new resume exception corrupt uri e tmp else hasur is false boolean block finished fields string to bool blockfs get finished false checkur is i null if block finished checkur is i null logger error this no uri for check block i of seg no yet apparently finished encoded false read data only necessary if the block isn t finished if block finished simple field set bucketfs blockfs subset data if bucketfs null try check blocks i serializable to field set bucket util create bucketfs context random ctx persistent file tracker if logminor logger minor this check block i check blocks i catch cannot create from field set exception e logger error this failed to deserialize check block i of seg no e e re encode it check blocks i null encoded false if check blocks i null throw new resume exception check block i of seg no not finished but no data create returned null don t create fetcher yet that happens in start else blocks completed if check blocks i null checkur is i null logger normal this clearing encoded because block i of seg no missing encoded false checkfs remove subset index if check blocks length data blocks length work around 1135 bug fixme remove throw new resume exception detected 1135 insert bug you must restart the insert else logger normal this not encoded because no check blocks encoded false fec codec splitfile algo fec codec get codec splitfile algorithm data block count int check blocks count splitfile algo count check blocks this checkur is new clientchk check blocks count this check blocks new bucket check blocks count check retries new int check blocks count check consecutivern fs new int check blocks count check finished new boolean check blocks count check failed new boolean check blocks count hasur is false for int i 0 i data block count i string index integer to string i simple field set blockfs datafs subset index if blockfs null throw new resume exception no data block i on segment seg no tmp blockfs get uri if tmp null try dataur is i clientchk client key get base key new freeneturi tmp blocks goturi catch malformedurl exception e throw new resume exception corrupt uri e tmp else hasur is false boolean block finished fields string to bool blockfs get finished false if block finished dataur is i null throw new resume exception block i of seg no finished but no uri if block finished finished false else blocks completed read data simple field set bucketfs blockfs subset data if bucketfs null if block finished throw new resume exception block i of seg no not finished but no data else if splitfile algorithm 0 encoded throw new resume exception block i of seg no data not available even though not encoded else try data blocks i serializable to field set bucket util create bucketfs context random ctx persistent file tracker if logminor logger minor this data block i data blocks i catch cannot create from field set exception e throw new resume exception failed to deserialize block i of seg no e e if data blocks i null throw new resume exception block i of seg no could not serialize data create returned null from bucketfs don t create fetcher yet that happens in start datafs remove subset index if encoded finished false hasur is false for int i 0 i data blocks length i if data blocks i null throw new resume exception missing data block i and need to reconstruct check blocks putter add blocks dataur is length checkur is length container putter add must succeed blocks dataur is length checkur is length container resumeexception splitfileinsertersegment splitfileinserter baseclientputter simplefieldset splitfilealgorithm insertcontext getchkonly segno clientcontext objectcontainer resumeexception splitfilealgo splitfilealgorithm getchkonly getchkonly blockinsertcontext maxretries maxinsertretries segno segno splitfileinsertersegment resumeexception stringtobool stringtobool simplefieldset failurecodetracker failurecodetracker isempty tothrow insertexception blocksgoturi blockscompleted simplefieldset datablocks resumeexception resumeexception datablockcount datablockcount parseint numberformatexception resumeexception hasuris datablocks datablockcount datauris datablockcount dataretries datablockcount dataconsecutivernfs datablockcount datafinished datablockcount datafailed datablockcount arraylist simplefieldset checkblocks resumeexception checkblockcount checkblockcount parseint numberformatexception resumeexception checkblocks checkblockcount checkuris checkblockcount checkretries checkblockcount checkconsecutivernfs checkblockcount checkfinished checkblockcount checkfailed checkblockcount checkblockcount tostring simplefieldset hasuris segno checkuris clientkey getbasekey blocksgoturi malformedurlexception resumeexception hasuris blockfinished stringtobool checkuris blockfinished checkuris segno blockfinished simplefieldset checkblocks serializabletofieldsetbucketutil persistentfiletracker checkblocks cannotcreatefromfieldsetexception segno checkblocks checkblocks resumeexception segno blockscompleted checkblocks checkuris segno removesubset checkblocks datablocks resumeexception feccodec splitfilealgo feccodec getcodec splitfilealgorithm datablockcount checkblockscount splitfilealgo countcheckblocks checkuris checkblockscount checkblocks checkblockscount checkretries checkblockscount checkconsecutivernfs checkblockscount checkfinished checkblockscount checkfailed checkblockscount hasuris datablockcount tostring simplefieldset resumeexception segno datauris clientkey getbasekey blocksgoturi malformedurlexception resumeexception hasuris blockfinished stringtobool blockfinished datauris resumeexception segno blockfinished blockscompleted simplefieldset blockfinished resumeexception segno splitfilealgorithm resumeexception segno datablocks serializabletofieldsetbucketutil persistentfiletracker datablocks cannotcreatefromfieldsetexception resumeexception segno datablocks resumeexception segno removesubset hasuris datablocks datablocks resumeexception addblocks datauris checkuris addmustsucceedblocks datauris checkuris public void start object container container client context context throws insert exception always called by parent so don t activate or deactivate parent if persistent container activate parent 1 container activate parent parent 1 container activate blocks 2 if logminor if parent null throw new null pointer exception logger minor this starting segment seg no of parent parent data length this finished finished encoded encoded hasur is hasur is persistent persistent boolean fin true for int i 0 i data blocks length i if data blocks i null else already finished on creation fin false synchronized this blocks add i else parent parent completed block true container context parent parent notify clients started true fec job job null fec codec splitfile algo null if encoded if logminor logger minor this segment seg no of parent parent data length is not encoded splitfile algo fec codec get codec this splitfile algo data blocks length check blocks length if logminor logger minor this encoding segment seg no of parent parent data length persistent persistent encode blocks synchronized this if encoded fixme necessary the queue is persistence aware won t it activate them if persistent for int i 0 i data blocks length i container activate data blocks i 5 job encode job new fec job splitfile algo context fec queue data blocks check blocks chk block data length persistent block insert context persistent bucket factory context temp bucket factory this false parent parent get priority class persistent fin false else for int i 0 i check blocks length i if check blocks i null synchronized this blocks add i data blocks length fin false else parent parent completed block true container context on encoded segment container context null data blocks check blocks null null if hasur is parent segment hasur is this container context boolean fetchable synchronized this fetchable blocks completed data blocks length if persistent container store this container store blocks if fetchable parent segment fetchable this container if fin finish container context parent else schedule container context if finished finish container context parent if job null splitfile algo add to queue job context fec queue container objectcontainer clientcontext insertexception nullpointerexception segno datalength hasuris hasuris datablocks datablocks completedblock notifyclients fecjob feccodec splitfilealgo segno datalength splitfilealgo feccodec getcodec splitfilealgo datablocks checkblocks segno datalength datablocks datablocks encodejob fecjob splitfilealgo fecqueue datablocks checkblocks chkblock data_length blockinsertcontext persistentbucketfactory tempbucketfactory getpriorityclass checkblocks checkblocks datablocks completedblock onencodedsegment datablocks checkblocks hasuris segmenthasuris blockscompleted datablocks segmentfetchable splitfilealgo addtoqueue fecqueue private void schedule object container container client context context if getchk only this get scheduler context register insert this persistent false container else try encode container context objectcontainer clientcontext getchkonly getscheduler registerinsert tryencode public void try encode object container container client context context for int i 0 i data blocks length i if dataur is i null data blocks i null try boolean deactivate false if persistent deactivate container ext is active data blocks i if deactivate container activate data blocks i 1 clientchk key clientchk encode bucket data blocks i get client key if deactivate container deactivate data blocks i 1 on encode i key container context catch chk encode exception e fail new insert exception insert exception internal error e null container context catch io exception e fail new insert exception insert exception bucket error e null container context else if dataur is i null data blocks i null fail new insert exception insert exception internal error data block i cannot be encoded no data null container context if encoded for int i 0 i check blocks length i if checkur is i null check blocks i null try boolean deactivate false if persistent deactivate container ext is active check blocks i if deactivate container activate check blocks i 1 clientchk key clientchk encode bucket check blocks i get client key if deactivate container deactivate check blocks i 1 on encode i data blocks length key container context catch chk encode exception e fail new insert exception insert exception internal error e null container context catch io exception e fail new insert exception insert exception bucket error e null container context else if checkur is i null check blocks i null fail new insert exception insert exception internal error data block i cannot be encoded no data null container context tryencode objectcontainer clientcontext datablocks datauris datablocks isactive datablocks datablocks encodebucket datablocks getclientkey datablocks onencode chkencodeexception insertexception insertexception internal_error ioexception insertexception insertexception bucket_error datauris datablocks insertexception insertexception internal_error checkblocks checkuris checkblocks isactive checkblocks checkblocks encodebucket checkblocks getclientkey checkblocks onencode datablocks chkencodeexception insertexception insertexception internal_error ioexception insertexception insertexception bucket_error checkuris checkblocks insertexception insertexception internal_error public void on decoded segment object container container client context context fec job job bucket data buckets bucket check buckets splitfile block data block status splitfile block check block status irrevelant ondecodedsegment objectcontainer clientcontext fecjob databuckets checkbuckets splitfileblock datablockstatus splitfileblock checkblockstatus public void on encoded segment object container container client context context fec job job bucket data buckets bucket check buckets splitfile block data block status splitfile block check block status if persistent container activate parent 1 container activate parent parent 1 container activate blocks 2 boolean fin synchronized this fin finished encode job null if remove on encode if logminor logger minor this removing on encode this free buckets array container data buckets free buckets array container check buckets remove from container context return if fin logger error this encoded segment even though segment finished freeing buckets free buckets array container data buckets free buckets array container check buckets return start the inserts try if logminor logger minor this scheduling check blocks length check blocks for int i 0 i check blocks length i see comments on fec callback we must copy the data back check blocks i check buckets i if check blocks i null if logminor logger minor this skipping check block i is null continue if persistent check blocks i store to container if persistent container deactivate check blocks i 1 synchronized this for int i 0 i check blocks length i blocks add data blocks length i if persistent container store blocks catch throwable t logger error this caught t while encoding this t insert exception ex new insert exception insert exception internal error t null finish ex container context parent if persistent container deactivate parent 1 return synchronized this encoded true if persistent container store this container activate parent 1 tell parent only after have started the inserts because of the counting parent encoded segment this container context synchronized this free buckets array container data blocks if persistent container store this container deactivate parent 1 schedule container context onencodedsegment objectcontainer clientcontext fecjob databuckets checkbuckets splitfileblock datablockstatus splitfileblock checkblockstatus encodejob removeonencode freebucketsarray databuckets freebucketsarray checkbuckets removefrom freebucketsarray databuckets freebucketsarray checkbuckets checkblocks checkblocks feccallback checkblocks checkbuckets checkblocks checkblocks storeto checkblocks checkblocks datablocks insertexception insertexception insertexception internal_error encodedsegment freebucketsarray datablocks caller must activate and pass in parent param ex param container param context param parent void finish insert exception ex object container container client context context split file inserter parent if logminor logger minor this finishing this with ex ex synchronized this if finished return finished true to throw ex if persistent container store this parent segment finished this container context free buckets array container data blocks free buckets array container check blocks insertexception objectcontainer clientcontext splitfileinserter tothrow segmentfinished freebucketsarray datablocks freebucketsarray checkblocks caller must activate and pass in parent param container param context param parent private void finish object container container client context context split file inserter parent if logminor logger minor this finishing this if persistent container activate errors 5 synchronized this if finished return finished true if blocks succeeded blocks completed to throw insert exception construct errors if persistent container store this container deactivate errors 5 unregister container context parent segment finished this container context free buckets array container data blocks free buckets array container check blocks objectcontainer clientcontext splitfileinserter blockssucceeded blockscompleted tothrow insertexception segmentfinished freebucketsarray datablocks freebucketsarray checkblocks private void on encode int x clientchk key object container container client context context if logminor logger minor this encoded block x on this synchronized this if finished return if x data blocks length if checkur is x data blocks length null return checkur is x data blocks length key else if dataur is x null return dataur is x key blocks goturi if persistent container store this if logminor logger minor this blocks got uri blocks goturi of data blocks length check blocks length if blocks goturi data blocks length check blocks length return double check for int i 0 i checkur is length i if checkur is i null logger error this check uri i is null return for int i 0 i dataur is length i if dataur is i null logger error this data uri i is null return hasur is true if persistent container activate parent 1 container store this parent segment hasur is this container context if persistent container deactivate parent 1 onencode objectcontainer clientcontext datablocks checkuris datablocks checkuris datablocks datauris datauris blocksgoturi blocksgoturi datablocks checkblocks blocksgoturi datablocks checkblocks checkuris checkuris datauris datauris hasuris segmenthasuris public synchronized boolean is finished return finished isfinished public boolean is encoded return encoded isencoded public int count check blocks return check blocks length countcheckblocks checkblocks public int count data blocks return data blocks length countdatablocks datablocks public clientchk get checkch ks return checkur is getcheckchks checkuris public clientchk get datach ks return dataur is getdatachks datauris get the insert exception for this segment note this will be deleted when the segment is deleted do not store it or pass it on insert exception get exception synchronized this return to throw insertexception insertexception getexception tothrow public void cancel object container container client context context synchronized this if finished return finished true if to throw null to throw new insert exception insert exception cancelled cancel inner container context objectcontainer clientcontext tothrow tothrow insertexception insertexception cancelinner private void cancel inner object container container client context context if logminor logger minor this cancelling this super unregister container context if persistent container store this container activate parent 1 parent segment finished this container context free buckets array container data blocks free buckets array container check blocks cancelinner objectcontainer clientcontext segmentfinished freebucketsarray datablocks freebucketsarray checkblocks public void on transition client put state old state client put state new state object container container logger error this illegal transition in split file inserter segment old state new state ontransition clientputstate oldstate clientputstate newstate objectcontainer splitfileinsertersegment oldstate newstate public void on metadata metadata m client put state state object container container client context context logger error this got on metadata from state onmetadata clientputstate objectcontainer clientcontext onmetadata public void on block set finished client put state state object container container client context context ignore logger error this should not happen on block set finished state on this onblocksetfinished clientputstate objectcontainer clientcontext onblocksetfinished public synchronized boolean hasur is return hasur is hasuris hasuris public synchronized boolean is fetchable return blocks completed data blocks length isfetchable blockscompleted datablocks public void on fetchable client put state state object container container ignore onfetchable clientputstate objectcontainer force the remaining blocks which haven t been encoded so far to be encoded asap public void force encode object container container client context context context background block encoder queue this container context forceencode objectcontainer clientcontext backgroundblockencoder public void fail insert exception e object container container client context context synchronized this if finished logger error this failing but already finished on this return finished true logger error this insert segment failed e for this e this to throw e if persistent container store this cancel inner container context insertexception objectcontainer clientcontext tothrow cancelinner public void on failed throwable t object container container client context context synchronized this if finished logger error this fec decode or encode failed but already finished t t return finished true logger error this insert segment failed t for this t this to throw new insert exception insert exception internal error fec failure t null cancel inner container context onfailed objectcontainer clientcontext tothrow insertexception insertexception internal_error cancelinner bucket get bucket int block num if block num data blocks length return check blocks block num data blocks length else return data blocks block num getbucket blocknum blocknum datablocks checkblocks blocknum datablocks datablocks blocknum private block item get block item object container container client context context int block num throws io exception bucket source data get bucket block num if source data null logger error this selected block block num but is null already finished on this return null boolean deactivate bucket false if persistent deactivate bucket container ext is active source data if deactivate bucket container activate source data 1 bucket data source data create shadow if data null data context temp bucket factory make bucket source data size bucket tools copy source data data if logminor logger minor this block block num bucket source data shadow data if persistent if deactivate bucket container deactivate source data 1 return new block item this block num data persistent blockitem getblockitem objectcontainer clientcontext blocknum ioexception sourcedata getbucket blocknum sourcedata blocknum deactivatebucket deactivatebucket isactive sourcedata deactivatebucket sourcedata sourcedata createshadow tempbucketfactory makebucket sourcedata buckettools sourcedata blocknum sourcedata deactivatebucket sourcedata blockitem blocknum private int hash code for block int block num fixme standard hash code pattern assumes both inputs are evenly distributed this is not true here return hash code block num 1 hashcodeforblock blocknum hashcode hashcode blocknum block item split file inserter segment parent int block num bucket bucket boolean persistent throws io exception this parent parent this block num block num this copy bucket bucket this hash code parent hash code for block block num this persistent persistent blockitem splitfileinsertersegment blocknum ioexception blocknum blocknum copybucket hashcode hashcodeforblock blocknum public void dump copy bucket free copybucket override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof block item if block item o parent parent block item o block num block num return true else if o instanceof fake block item if fake block item o get parent parent fake block item o block num block num return true return false blockitem blockitem blockitem blocknum blocknum fakeblockitem fakeblockitem getparent fakeblockitem blocknum blocknum fake block item int block num this block num block num this hash code hash code for block block num fakeblockitem blocknum blocknum blocknum hashcode hashcodeforblock blocknum public void dump do nothing public split file inserter segment get parent return split file inserter segment this splitfileinsertersegment getparent splitfileinsertersegment override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof block item if block item o parent split file inserter segment this block item o block num block num return true else if o instanceof fake block item if fake block item o get parent split file inserter segment this fake block item o block num block num return true return false blockitem blockitem splitfileinsertersegment blockitem blocknum blocknum fakeblockitem fakeblockitem getparent splitfileinsertersegment fakeblockitem blocknum blocknum override public void on failure low level put exception e object key num object container container client context context block item block block item key num synchronized this if finished return first report the error if persistent container activate errors 5 switch e code case low level put exception collision logger error this collision on a chk fail new insert exception insert exception internal error collision on a chk null container context return case low level put exception internal error logger error this internal error e e fail new insert exception insert exception internal error e to string null container context return case low level put exception rejected overload errors inc insert exception rejected overload break case low level put exception route not found errors inc insert exception route not found break case low level put exception route really not found errors inc insert exception route really not found break default logger error this unknown low level put exception code e code fail new insert exception insert exception internal error e to string null container context return if persistent container store errors boolean isrnf e code low level put exception route not found e code low level put exception route really not found int block num block block num if logminor logger minor this block block num failed on this e boolean treat as success false boolean failed block false int completed int succeeded synchronized this if block num data blocks length check block int check num block num data blocks length if check finished check num if check failed check num logger error this got on failure but block has already failed check block check num on this else logger error this got on failure but block has already succeeded check block check num on this return if isrnf check consecutivern fs check num if persistent container activate block insert context 1 if logminor logger minor this consecutive rn fs check consecutivern fs check num block insert context consecutivern fs count as success if check consecutivern fs check num block insert context consecutivern fs count as success treat as success treat as success true else check consecutivern fs check num 0 if treat as success check retries check num if check retries check num max retries max retries 1 failed block true treat as failed check finished check num true check failed check num true blocks completed if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks if check blocks check num null if persistent container activate check blocks check num 1 check blocks check num free if persistent check blocks check num remove from container check blocks check num null if logminor logger minor this failed to insert check block check num on this else logger error this check block check num failed on this but bucket is already nulled out else we are still registered but will have to be re selected for persistent requests the current persistent chosen request will not re run the same block this is okay else better handle it here to minimize race conditions check finished check num true check failed check num false treating as succeeded blocks completed blocks succeeded if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks if check blocks check num null if persistent container activate check blocks check num 1 check blocks check num free if persistent check blocks check num remove from container check blocks check num null if logminor logger minor this repeated rnf treating as success for check block check num on this else logger error this check block check num succeeded sort of on this but bucket is already nulled out else data block if data finished block num if data failed block num logger error this got on failure but block has already failed data block block num on this else logger error this got on failure but block has already succeeded data block block num on this return if isrnf data consecutivern fs block num if persistent container activate block insert context 1 if logminor logger minor this consecutive rn fs data consecutivern fs block num block insert context consecutivern fs count as success if data consecutivern fs block num block insert context consecutivern fs count as success treat as success treat as success true else data consecutivern fs block num 0 if treat as success data retries block num if data retries block num max retries max retries 1 failed block true treat as failed data finished block num true data failed block num true blocks completed if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks if data blocks block num null if persistent container activate data blocks block num 1 data blocks block num free if persistent data blocks block num remove from container data blocks block num null if logminor logger minor this failed to insert data block block num on this else logger error this data block block num failed on this but bucket is already nulled out else we are still registered but will have to be re selected for persistent requests the current persistent chosen request will not re run the same block this is okay else better handle it here to minimize race conditions data finished block num true data failed block num false treating as succeeded blocks completed blocks succeeded if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks if data blocks block num null encoded if persistent container activate data blocks block num 1 data blocks block num free if persistent data blocks block num remove from container data blocks block num null if logminor logger minor this repeated rnf treating as success for data block block num on this else logger error this data block block num succeeded sort of on this but bucket is already nulled out if persistent container store this completed blocks completed succeeded blocks succeeded if persistent container activate putter 1 if failed block putter failed block container context else if treat as success putter completed block false container context if persistent container deactivate putter 1 if treat as success succeeded data blocks length if persistent container activate parent 1 parent segment fetchable this container if persistent container deactivate parent 1 else if completed data blocks length check blocks length if persistent container activate parent 1 finish container context parent if persistent container deactivate parent 1 onfailure lowlevelputexception keynum objectcontainer clientcontext blockitem blockitem keynum lowlevelputexception insertexception insertexception internal_error lowlevelputexception internal_error insertexception insertexception internal_error tostring lowlevelputexception rejected_overload insertexception rejected_overload lowlevelputexception route_not_found insertexception route_not_found lowlevelputexception route_really_not_found insertexception route_really_not_found lowlevelputexception insertexception insertexception internal_error tostring lowlevelputexception route_not_found lowlevelputexception route_really_not_found blocknum blocknum blocknum treatassuccess failedblock blocknum datablocks checknum blocknum datablocks checkfinished checknum checkfailed checknum onfailure checknum onfailure checknum checkconsecutivernfs checknum blockinsertcontext rnfs checkconsecutivernfs checknum blockinsertcontext consecutivernfscountassuccess checkconsecutivernfs checknum blockinsertcontext consecutivernfscountassuccess treatassuccess checkconsecutivernfs checknum treatassuccess checkretries checknum checkretries checknum maxretries maxretries failedblock checkfinished checknum checkfailed checknum blockscompleted valueof blocknum checkblocks checknum checkblocks checknum checkblocks checknum checkblocks checknum removefrom checkblocks checknum checknum checknum persistentchosenrequest checkfinished checknum checkfailed checknum blockscompleted blockssucceeded valueof blocknum checkblocks checknum checkblocks checknum checkblocks checknum checkblocks checknum removefrom checkblocks checknum checknum checknum datafinished blocknum datafailed blocknum onfailure blocknum onfailure blocknum dataconsecutivernfs blocknum blockinsertcontext rnfs dataconsecutivernfs blocknum blockinsertcontext consecutivernfscountassuccess dataconsecutivernfs blocknum blockinsertcontext consecutivernfscountassuccess treatassuccess dataconsecutivernfs blocknum treatassuccess dataretries blocknum dataretries blocknum maxretries maxretries failedblock datafinished blocknum datafailed blocknum blockscompleted valueof blocknum datablocks blocknum datablocks blocknum datablocks blocknum datablocks blocknum removefrom datablocks blocknum blocknum blocknum persistentchosenrequest datafinished blocknum datafailed blocknum blockscompleted blockssucceeded valueof blocknum datablocks blocknum datablocks blocknum datablocks blocknum datablocks blocknum removefrom datablocks blocknum blocknum blocknum blockscompleted blockssucceeded failedblock failedblock treatassuccess completedblock treatassuccess datablocks segmentfetchable datablocks checkblocks override public void on success object key num object container container client context context block item block block item key num int block num block block num int completed int succeeded if logminor logger minor this block block num succeeded on this synchronized this if finished return if block num data blocks length check block int check num block num data blocks length if check finished check num check finished check num true check failed check num false blocks completed blocks succeeded if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks else if check failed check num logger error this got on success but block has already failed check block check num on this else logger error this got on success but block has already succeeded check block check num on this return if check blocks check num null if persistent container activate check blocks check num 1 check blocks check num free if persistent check blocks check num remove from container check blocks check num null else logger error this check block check num succeeded on this but bucket is already nulled out else data block if data finished block num data finished block num true data failed block num false blocks completed blocks succeeded if persistent container activate blocks 2 blocks remove integer value of block num if persistent container store blocks else if data failed block num logger error this got on success but block has already failed data block block num on this else logger error this got on success but block has already succeeded data block block num on this return data blocks may not be freed until after we have encoded the check blocks if encoded data blocks block num null if persistent container activate data blocks block num 1 data blocks block num free if persistent data blocks block num remove from container data blocks block num null else if data blocks block num null logger error this data block block num succeeded on this but bucket is already nulled out if persistent logger minor this activation state container ext is active this if persistent container store this completed blocks completed succeeded blocks succeeded if persistent container activate putter 1 putter completed block false container context if persistent container deactivate putter 1 if succeeded data blocks length if persistent container activate parent 1 parent segment fetchable this container if persistent container deactivate parent 1 else if completed data blocks length check blocks length if persistent container activate parent 1 finish container context parent if persistent container deactivate parent 1 onsuccess keynum objectcontainer clientcontext blockitem blockitem keynum blocknum blocknum blocknum blocknum datablocks checknum blocknum datablocks checkfinished checknum checkfinished checknum checkfailed checknum blockscompleted blockssucceeded valueof blocknum checkfailed checknum onsuccess checknum onsuccess checknum checkblocks checknum checkblocks checknum checkblocks checknum checkblocks checknum removefrom checkblocks checknum checknum datafinished blocknum datafinished blocknum datafailed blocknum blockscompleted blockssucceeded valueof blocknum datafailed blocknum onsuccess blocknum onsuccess blocknum datablocks blocknum datablocks blocknum datablocks blocknum datablocks blocknum removefrom datablocks blocknum datablocks blocknum blocknum isactive blockscompleted blockssucceeded completedblock datablocks segmentfetchable datablocks checkblocks override public long count all keys object container container client context context return count sendable keys container context countallkeys objectcontainer clientcontext countsendablekeys override public sendable request item choose key keys fetching locally keys object container container client context context if persistent container activate this 1 container activate blocks 1 synchronized this if finished return null if blocks is empty if logminor logger minor this no blocks to remove return null for int i 0 i 10 i integer ret int x if blocks size 0 return null x context random next int blocks size ret blocks get x int num ret check whether it is already running if persistent if keys has transient insert this new fake block item num return null try return get block item container context num catch io exception e fail new insert exception insert exception bucket error e null container context return null return null sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext isempty nextint hastransientinsert fakeblockitem getblockitem ioexception insertexception insertexception bucket_error override public request client get client object container container if persistent container activate putter 1 return putter get client requestclient getclient objectcontainer getclient override public client requester get client request return putter clientrequester getclientrequest override public short get priority class object container container if persistent container activate putter 1 return putter get priority class getpriorityclass objectcontainer getpriorityclass override public int get retry count no point scheduling inserts by retry count fixme either implement sub segments to schedule by retry count or more likely imho make the scheduler not care about retry counts for inserts return 0 getretrycount override public sendable request sender get sender object container container client context context return new sendable request sender public boolean send node client core core request scheduler sched final client context context chosen block req ignore key num key since we re only sending one block try block item block block item req token if logminor logger minor this starting request split file inserter segment this block number block block num clientchk block b try b encode bucket block copy bucket catch chk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch malformedurl exception e throw new low level put exception low level put exception internal error e to string e get message e catch io exception e throw new low level put exception low level put exception internal error e to string e get message e finally block copy bucket free if b null logger error this asked to send empty block on split file inserter segment this new exception error return false final clientchk key clientchk b get client key final int num block block num if block persistent context job runner queue new db job public void run object container container client context context if container ext is stored split file inserter segment this return container activate split file inserter segment this 1 on encode num key container context container deactivate split file inserter segment this 1 native thread norm priority 1 false else context main executor execute new runnable public void run on encode num key null context got uri core real put b req cache local requests catch low level put exception e req on failure e context if logminor logger minor this request failed split file inserter segment this for e return true if logminor logger minor this request succeeded split file inserter segment this req on insert success context return true sendablerequestsender getsender objectcontainer clientcontext sendablerequestsender nodeclientcore requestscheduler clientcontext chosenblock keynum blockitem blockitem splitfileinsertersegment blocknum clientchkblock encodebucket copybucket chkencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage malformedurlexception lowlevelputexception lowlevelputexception internal_error tostring getmessage ioexception lowlevelputexception lowlevelputexception internal_error tostring getmessage copybucket splitfileinsertersegment getclientkey blocknum jobrunner dbjob objectcontainer clientcontext isstored splitfileinsertersegment splitfileinsertersegment onencode splitfileinsertersegment nativethread norm_priority mainexecutor onencode realput cachelocalrequests lowlevelputexception onfailure splitfileinsertersegment splitfileinsertersegment oninsertsuccess public boolean send node client core core request scheduler sched final client context context chosen block req ignore key num key since we re only sending one block try block item block block item req token if logminor logger minor this starting request split file inserter segment this block number block block num clientchk block b try b encode bucket block copy bucket catch chk encode exception e throw new low level put exception low level put exception internal error e to string e get message e catch malformedurl exception e throw new low level put exception low level put exception internal error e to string e get message e catch io exception e throw new low level put exception low level put exception internal error e to string e get message e finally block copy bucket free if b null logger error this asked to send empty block on split file inserter segment this new exception error return false final clientchk key clientchk b get client key final int num block block num if block persistent context job runner queue new db job public void run object container container client context context if container ext is stored split file inserter segment this return container activate split file inserter segment this 1 on encode num key container context container deactivate split file inserter segment this 1 native thread norm priority 1 false else context main executor execute new runnable public void run on encode num key null context got uri core real put b req cache local requests catch low level put exception e req on failure e context if logminor logger minor this request failed split file inserter segment this for e return true if logminor logger minor this request succeeded split file inserter segment this req on insert success context return true nodeclientcore requestscheduler clientcontext chosenblock keynum blockitem blockitem splitfileinsertersegment blocknum clientchkblock encodebucket copybucket chkencodeexception lowlevelputexception lowlevelputexception internal_error tostring getmessage malformedurlexception lowlevelputexception lowlevelputexception internal_error tostring getmessage ioexception lowlevelputexception lowlevelputexception internal_error tostring getmessage copybucket splitfileinsertersegment getclientkey blocknum jobrunner dbjob objectcontainer clientcontext isstored splitfileinsertersegment splitfileinsertersegment onencode splitfileinsertersegment nativethread norm_priority mainexecutor onencode realput cachelocalrequests lowlevelputexception onfailure splitfileinsertersegment splitfileinsertersegment oninsertsuccess public void run object container container client context context if container ext is stored split file inserter segment this return container activate split file inserter segment this 1 on encode num key container context container deactivate split file inserter segment this 1 objectcontainer clientcontext isstored splitfileinsertersegment splitfileinsertersegment onencode splitfileinsertersegment context main executor execute new runnable public void run on encode num key null context mainexecutor onencode protected clientchk block encode bucket bucket copy bucket throws chk encode exception io exception return clientchk block encode copy bucket false true short 1 chk block data length clientchkblock encodebucket copybucket chkencodeexception ioexception clientchkblock copybucket chkblock data_length override public boolean is cancelled object container container return finished iscancelled objectcontainer override public boolean isssk return false override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context if persistent container activate blocks 1 integer block numbers synchronized this block numbers blocks to array new integer blocks size array list persistent chosen block ret new array list persistent chosen block arrays sort block numbers int prev block number 1 for int i 0 i block numbers length i int block number block numbers i if block number prev block number logger error this duplicate block number in make blocks in this two copies of block number continue prev block number block number sendable request item item try item get block item container context block number catch io exception e fail new insert exception insert exception bucket error e null container context return null persistent chosen block block new persistent chosen block true request item null null sched if logminor logger minor this created block block for block number block number on this ret add block if persistent container deactivate blocks 1 if logminor logger minor this returning ret size blocks return ret persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext blocknumbers blocknumbers toarray arraylist persistentchosenblock arraylist persistentchosenblock blocknumbers prevblocknumber blocknumbers blocknumber blocknumbers blocknumber prevblocknumber makeblocks blocknumber prevblocknumber blocknumber sendablerequestitem getblockitem blocknumber ioexception insertexception insertexception bucket_error persistentchosenblock persistentchosenblock blocknumber override public synchronized long count sendable keys object container container client context context if persistent container activate blocks 1 int sz blocks size if persistent container deactivate blocks 1 return sz countsendablekeys objectcontainer clientcontext public synchronized boolean is empty object container container if persistent container activate blocks 2 boolean ret finished blocks is empty if persistent container deactivate blocks 1 return ret isempty objectcontainer isempty public void remove from object container container client context context if encode job null if encode job cancel container context synchronized this remove on encode true if logminor logger minor this will remove after encode finished this container store this return encode job null parent putter can deal with themselves free buckets array container data blocks free buckets array container check blocks for clientchk chk dataur is if chk null if logminor logger minor this datauri is null on this container activate chk 5 chk remove from container for clientchk chk checkur is if chk null if logminor logger minor this checkuri is null on this container activate chk 5 chk remove from container container activate blocks 5 for integer i blocks container activate i 1 container delete i container delete blocks if to throw null container activate to throw 5 to throw remove from container if errors null container activate errors 1 errors remove from container container delete this removefrom objectcontainer clientcontext encodejob encodejob removeonencode encodejob freebucketsarray datablocks freebucketsarray checkblocks datauris removefrom checkuris removefrom tothrow tothrow tothrow removefrom removefrom override public boolean cache inserts object container container boolean deactivate false if persistent deactivate container ext is active block insert context if deactivate container activate block insert context 1 boolean retval block insert context cache local requests if deactivate container deactivate block insert context 1 return retval cacheinserts objectcontainer isactive blockinsertcontext blockinsertcontext blockinsertcontext cachelocalrequests blockinsertcontext public boolean object can new object container container if finished logger error this storing this when already finished new exception error return false if logdebug logger debug this storing this activated container ext is active this stored container ext is stored this new exception debug return true objectcannew objectcontainer isactive isstored private void free buckets array object container container bucket buckets for int i 0 i buckets length i if buckets i null continue if persistent container activate buckets i 1 buckets i free if persistent buckets i remove from container buckets i null freebucketsarray objectcontainer removefrom private static final long serial versionuid 4542976419025644806l throttle deprecated exception packet throttle target this target target serialversionuid throttledeprecatedexception packetthrottle creates an exception param name the name of the element where the error is located param message a message describing what went wrong dl dl dt b preconditions b dt dd ul li code message null code ul dd dl dl dt b postconditions b dt dd ul li get line nr no line ul dd dl dl public xml parse exception string name string message super xml parse exception during parsing of name null the xml definition a name element message this line nr xml parse exception no line getlinenr no_line xmlparseexception linenr xmlparseexception no_line creates an exception param name the name of the element where the error is located param line nr the number of the line in the input param message a message describing what went wrong dl dl dt b preconditions b dt dd ul li code message null code li code line nr gt 0 code ul dd dl dl dt b postconditions b dt dd ul li get line nr line nr ul dd dl dl public xml parse exception string name int line nr string message super xml parse exception during parsing of name null the xml definition a name element at line line nr message this line nr line nr linenr linenr getlinenr linenr xmlparseexception linenr linenr linenr linenr where the error occurred or code no line code if the line number is unknown see nanoxml xml parse exception no line public int get line nr return this line nr no_line xmlparseexception no_line getlinenr linenr public usk byte pub key hash byte crypto key byte extra string site name long suggested edition throws malformedurl exception this pub key hash pub key hash this crypto key crypto key this site name site name this suggested edition suggested edition if extra null throw new malformedurl exception no extra bytes third bit in usk if pub key hash null throw new malformedurl exception no pubkey hash first bit in usk if crypto key null throw new malformedurl exception no crypto key second bit in usk verify extra bytes get crypto algorithm fixme this should be a static method or something clientssk tmp new clientssk site name pub key hash extra null crypto key crypto algorithm tmp crypto algorithm if pub key hash length nodessk pubkey hash size throw new malformedurl exception pubkey hash wrong length pub key hash length should be nodessk pubkey hash size if crypto key length clientssk crypto key length throw new malformedurl exception decryption key wrong length crypto key length should be clientssk crypto key length hash code fields hash code pub key hash fields hash code crypto key site name hash code int suggested edition int suggested edition 32 pubkeyhash cryptokey sitename suggestededition malformedurlexception pubkeyhash pubkeyhash cryptokey cryptokey sitename sitename suggestededition suggestededition malformedurlexception pubkeyhash malformedurlexception cryptokey malformedurlexception cryptoalgorithm sitename pubkeyhash cryptokey cryptoalgorithm cryptoalgorithm pubkeyhash pubkey_hash_size malformedurlexception pubkeyhash pubkey_hash_size cryptokey crypto_key_length malformedurlexception cryptokey crypto_key_length hashcode hashcode pubkeyhash hashcode cryptokey sitename hashcode suggestededition suggestededition public static usk create freeneturi uri throws malformedurl exception if uri isusk throw new malformedurl exception not a usk return new usk uri get routing key uri get crypto key uri get extra uri get doc name uri get suggested edition malformedurlexception malformedurlexception getroutingkey getcryptokey getextra getdocname getsuggestededition protected usk byte pub key hash2 byte crypto key2 string site name2 long suggested edition2 byte crypto algorithm this pub key hash pub key hash2 this crypto key crypto key2 this site name site name2 this suggested edition suggested edition2 this crypto algorithm crypto algorithm hash code fields hash code pub key hash fields hash code crypto key site name hash code int suggested edition int suggested edition 32 pubkeyhash2 cryptokey2 sitename2 suggestededition2 cryptoalgorithm pubkeyhash pubkeyhash2 cryptokey cryptokey2 sitename sitename2 suggestededition suggestededition2 cryptoalgorithm cryptoalgorithm hashcode hashcode pubkeyhash hashcode cryptokey sitename hashcode suggestededition suggestededition fixme be careful with this constructor there must not be an edition in the clientssk public usk clientssk ssk long myark number this pub key hash ssk pub key hash this crypto key ssk crypto key this site name ssk doc name this suggested edition myark number this crypto algorithm ssk crypto algorithm if site name matches 0 9 not error just possible bug logger normal this possible bug edition in clientssk ssk new exception debug hash code fields hash code pub key hash fields hash code crypto key site name hash code int suggested edition int suggested edition 32 myarknumber pubkeyhash pubkeyhash cryptokey cryptokey sitename docname suggestededition myarknumber cryptoalgorithm cryptoalgorithm sitename hashcode hashcode pubkeyhash hashcode cryptokey sitename hashcode suggestededition suggestededition public usk usk usk this pub key hash new byte usk pub key hash length system arraycopy usk pub key hash 0 pub key hash 0 usk pub key hash length this crypto algorithm usk crypto algorithm this crypto key usk crypto key this site name usk site name this suggested edition usk suggested edition hash code fields hash code pub key hash fields hash code crypto key site name hash code int suggested edition int suggested edition 32 pubkeyhash pubkeyhash pubkeyhash pubkeyhash pubkeyhash cryptoalgorithm cryptoalgorithm cryptokey cryptokey sitename sitename suggestededition suggestededition hashcode hashcode pubkeyhash hashcode cryptokey sitename hashcode suggestededition suggestededition override public freeneturi geturi return new freeneturi pub key hash crypto key clientssk get extra bytes crypto algorithm site name suggested edition pubkeyhash cryptokey getextrabytes cryptoalgorithm sitename suggestededition public clientssk getssk long ver try return new clientssk site name separator ver pub key hash clientssk get extra bytes crypto algorithm null crypto key catch malformedurl exception e logger error this caught e should not be possible in usk getssk e throw new error e sitename pubkeyhash getextrabytes cryptoalgorithm cryptokey malformedurlexception public client key getssk return getssk suggested edition clientkey suggestededition public usk copy long edition if suggested edition edition return this return new usk pub key hash crypto key site name edition crypto algorithm suggestededition pubkeyhash cryptokey sitename cryptoalgorithm public usk clear copy return copy 0 clearcopy override public usk clone return new usk this override public boolean equals object o if o null o instanceof usk return false return equals o true public boolean equals object o boolean include version if o instanceof usk usk u usk o if arrays equals pub key hash u pub key hash return false if arrays equals crypto key u crypto key return false if site name equals u site name return false if include version suggested edition u suggested edition return false return true return false includeversion pubkeyhash pubkeyhash cryptokey cryptokey sitename sitename includeversion suggestededition suggestededition override public int hash code return hash code hashcode hashcode public freeneturi get basessk return new freeneturi ssk site name pub key hash crypto key clientssk get extra bytes crypto algorithm getbasessk sitename pubkeyhash cryptokey getextrabytes cryptoalgorithm override public string to string return super to string geturi tostring tostring public freeneturi turn myssk intousk freeneturi uri if uri get key type equals ssk arrays equals uri get routing key pub key hash arrays equals uri get crypto key crypto key arrays equals uri get extra clientssk get extra bytes crypto algorithm uri get doc name null uri get doc name starts with site name string doc uri get doc name doc doc substring site name length if doc length 2 doc char at 0 return uri doc doc substring 1 long edition try edition long parse long doc catch number format exception e logger normal this trying to turn ssk back into usk uri doc doc caught e e return uri if doc equals long to string edition return uri return new freeneturi usk site name uri get all meta strings pub key hash crypto key clientssk get extra bytes crypto algorithm edition return uri turnmysskintousk getkeytype getroutingkey pubkeyhash getcryptokey cryptokey getextra getextrabytes cryptoalgorithm getdocname getdocname startswith sitename getdocname sitename charat parselong numberformatexception tostring sitename getallmetastrings pubkeyhash cryptokey getextrabytes cryptoalgorithm public void remove from object container container container delete this removefrom objectcontainer public unsubscribeusk message simple field set fs throws message invalid exception this identifier fs get identifier if identifier null throw new message invalid exception protocol error message missing field no identifier null false unsubscribeuskmessage simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field override public simple field set get field set throw new unsupported operation exception simplefieldset getfieldset unsupportedoperationexception override public string get name return name getname override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception override public void run fcp connection handler handler node node throws message invalid exception handler unsubscribe identifier fcpconnectionhandler messageinvalidexception multidimensional comparator t comparator private kd tree multidimensionalcomparator kdtree private kd tree kd tree storage storage multidimensional comparator t comparator super storage this comparator comparator kdtree kdtree multidimensionalcomparator kd tree storage storage class cls string field names boolean treate zero as undefined value super storage this comparator new reflection multidimensional comparator t storage cls field names treate zero as undefined value kdtree fieldnames treatezeroasundefinedvalue reflectionmultidimensionalcomparator fieldnames treatezeroasundefinedvalue public multidimensional comparator t get comparator return comparator multidimensionalcomparator getcomparator boolean deleted kd tree node t obj this obj obj kdtreenode private kd tree node kdtreenode private kd tree node public void load super load obj load kdtreenode public boolean recursive loading return false recursiveloading int insert t ins multidimensional comparator t comparator int level load int diff comparator compare ins obj level comparator get number of dimensions if diff multidimensional comparator eq deleted obj deallocate modify obj ins deleted false return level else if diff multidimensional comparator gt if left null modify left new kd tree node t ins return level 1 else return left insert ins comparator level 1 else if right null modify right new kd tree node t ins return level 1 else return right insert ins comparator level 1 multidimensionalcomparator getnumberofdimensions multidimensionalcomparator multidimensionalcomparator kdtreenode kdtreenode int remove t rem multidimensional comparator t comparator int level load if obj rem if left null right null deallocate return truncate else modify obj comparator clone field obj level comparator get number of dimensions deleted true return ok int diff comparator compare rem obj level comparator get number of dimensions if diff multidimensional comparator gt left null int result left remove rem comparator level 1 if result truncate modify left null return ok else if result ok return ok if diff multidimensional comparator lt right null int result right remove rem comparator level 1 if result truncate modify right null return ok else if result ok return ok return not found multidimensionalcomparator clonefield getnumberofdimensions getnumberofdimensions multidimensionalcomparator multidimensionalcomparator not_found public void deallocate load if deleted obj deallocate if left null left deallocate if right null right deallocate super deallocate public void optimize iterator t itr iterator int n n members i persistent members new i persistent n for int i 0 i n i members i itr next random rnd new random for int i 0 i n i int j rnd next int n i persistent tmp members j members j members i members i tmp clear for int i 0 i n i add t members i nmembers ipersistent ipersistent nextint ipersistent public boolean add t obj modify if root null root new kd tree node t obj height 1 else int level root insert obj comparator 0 if level height height level 1 n members 1 return true kdtreenode nmembers public boolean remove t obj if root null return false int result root remove obj comparator 0 if result not found return false modify if result truncate root null n members 1 return true not_found nmembers public iterator t iterator return iterator null null public iterable iterator t iterator t pattern return iterator pattern pattern iterableiterator public iterable iterator t iterator t low t high return new kd tree iterator low high iterableiterator kdtreeiterator public array list t query by example t pattern return query by example pattern pattern arraylist querybyexample querybyexample public array list t query by example t low t high iterator t i iterator low high array list t list new array list t while i has next list add i next return list arraylist querybyexample arraylist arraylist hasnext public object to array return query by example null null to array toarray querybyexample toarray public e e to array e arr return query by example null null to array arr toarray querybyexample toarray public int size return n members nmembers public int get height return height getheight public void clear if root null root deallocate modify root null n members 0 height 0 nmembers public boolean contains t member iterator t i iterator member while i has next if i next member return true return false hasnext public void deallocate if root null root deallocate super deallocate int compare all components t pattern t obj int n comparator get number of dimensions int result multidimensional comparator eq for int i 0 i n i int diff comparator compare pattern obj i if diff multidimensional comparator right undefined return diff else if diff multidimensional comparator lt if result multidimensional comparator gt return multidimensional comparator ne else result multidimensional comparator lt else if diff multidimensional comparator gt if result multidimensional comparator lt return multidimensional comparator ne else result multidimensional comparator gt return result compareallcomponents getnumberofdimensions multidimensionalcomparator multidimensionalcomparator right_undefined multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator multidimensionalcomparator kd tree iterator t low t high this low low this high high n dims comparator get number of dimensions stack new stack kd tree node t get min root kdtreeiterator ndims getnumberofdimensions kdtreenode getmin public int get level return curr level getlevel currlevel private boolean get min kd tree node t node if node null while true node load stack push node int diff low null multidimensional comparator left undefined comparator compare low node obj stack size 1 n dims if diff multidimensional comparator gt node left null node node left else return true return false getmin kdtreenode multidimensionalcomparator left_undefined ndims multidimensionalcomparator public boolean has next if next null return true while stack empty kd tree node t node stack pop if node null if node deleted int result if low null result compare all components low node obj multidimensional comparator lt result multidimensional comparator eq high null result compare all components high node obj multidimensional comparator gt result multidimensional comparator eq next node curr level stack size if node right null high null comparator compare high node obj stack size n dims multidimensional comparator lt stack push null if get min node right stack pop if next null return true return false hasnext kdtreenode compareallcomponents multidimensionalcomparator multidimensionalcomparator compareallcomponents multidimensionalcomparator multidimensionalcomparator currlevel ndims multidimensionalcomparator getmin public t next if has next throw new no such element exception curr next next null return curr obj hasnext nosuchelementexception public int next oid return next get oid nextoid getoid public void remove if curr null throw new illegal state exception curr modify curr obj comparator clone field curr obj curr level n dims curr deleted true curr null illegalstateexception clonefield currlevel ndims public static string get simplified architecture string arch if system get property os arch to lower case matches i x0 9 86 64 amd64 arch amd64 else if system get property os arch to lower case matches ppc arch ppc else we want to try the i386 libraries if the architecture is unknown wrappers must fallback to plain java implementation if loading native libraries fails arch i386 return arch getsimplifiedarchitecture getproperty tolowercase 86_64 getproperty tolowercase public static boolean load native string path string library name boolean success false final boolean is windows file path separator char final string prefix is windows dll system get property os name to lower case starts with mac jnilib so final string library name with prefix is windows lib library name final string library name with prefix and arch library name with prefix get simplified architecture final string library name with prefix and arch and suffix library name with prefix and arch prefix string resource name path library name with prefix and arch and suffix file native lib new file system get property java library path lib library name prefix if native lib exists system out println attempting to load the native thread library library name system load library library name success true else try get the resource url resource library loader class get resource resource name get input stream from jar resource input stream input stream resource open stream copy resource to filesystem in a temp folder with a unique name file temporary lib file create temp file library name with prefix and arch tmp delete on exit the dll temporary lib delete on exit file output stream output stream new file output stream temporary lib byte array new byte 2048 int read 0 while read input stream read array 0 output stream write array 0 read output stream close finally load the dll system out println attempting to load the library name library resource system load temporary lib get path success true catch throwable e system err println caught the following exception attempting to load resource name e print stack trace return success loadnative libraryname iswindows pathseparatorchar iswindows getproperty tolowercase startswith librarynamewithprefix iswindows libraryname librarynamewithprefixandarch librarynamewithprefix getsimplifiedarchitecture librarynamewithprefixandarchandsuffix librarynamewithprefixandarch resourcename librarynamewithprefixandarchandsuffix nativelib getproperty libraryname nativelib nativethread libraryname loadlibrary libraryname libraryloader getresource resourcename inputstream inputstream openstream temporarylib createtempfile librarynamewithprefixandarch temporarylib deleteonexit fileoutputstream outputstream fileoutputstream temporarylib inputstream outputstream outputstream libraryname temporarylib getpath resourcename printstacktrace creates a new own identities page param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public create identity page web interface my web interface http request my request super my web interface my request ownidentitiespage mywebinterface webinterface myrequest createidentitypage webinterface mywebinterface httprequest myrequest mywebinterface myrequest public void make if request is part set create identity try own identity new identity wot create own identity request get part as string inserturi 1024 request get part as string requesturi 1024 request get part as string nickname 1024 request get part as string publish trust list 5 equals true freetalk fixme freetalk should do that itself fixme inline the own identities page first we need to modify our base class to be able to do so see freetalk add content box your identity was created add child please go to the own identities page and solve introduction puzzles otherwise nobody will see the identity catch exception e add error box identity creation failed e get message else make create form request get part as string nickname 1024 ispartset createidentity ownidentity newidentity createownidentity getpartasstring getpartasstring getpartasstring getpartasstring publishtrustlist addcontentbox addchild adderrorbox getmessage makecreateform getpartasstring creates a form with pre filled keypair to create an new own identity param client a reference to a high level simple client param pr a reference to the plugin respirator param nick name the nick name supplied by the user private void make create form string nick name html node box content add content box identity creation freeneturi keypair wot get plugin respirator gethl simple client generate key pair wot html node create form pr add form child box content uri create identity create form add child input new string type name value new string hidden page create identity create form add child request uri create form add child input new string type name size value new string text requesturi 70 keypair 1 to string create form add child br create form add child insert uri create form add child input new string type name size value new string text inserturi 70 keypair 0 to string create form add child br create form add child publish trust list create form add child input new string type name value checked new string checkbox publish trust list true checked create form add child br create form add child input new string type name value new string hidden nickname nick name create form add child input new string type name value new string submit create identity create it ownidentity highlevelsimpleclient pluginrespirator nickname nickname makecreateform nickname htmlnode boxcontent addcontentbox getpluginrespirator gethlsimpleclient generatekeypair htmlnode createform addformchild boxcontent createidentity createform addchild createidentity createform addchild createform addchild tostring createform addchild createform addchild createform addchild tostring createform addchild createform addchild createform addchild publishtrustlist createform addchild createform addchild nickname createform addchild createidentity public void add last message item item if item msg null if items noid null items noid new linked list message item items noid add last item return object o item msg get object dmt uid if o null o instanceof long if items noid null items noid new linked list message item items noid add last item return long id long o linked list message item list if items byid null items byid new hash map long linked list message item items withid new array list linked list message item itemsi ds new array list long list new linked list message item items withid add list itemsi ds add id items byid put id list else list items byid get id if list null list new linked list message item items withid add list items byid put id list itemsi ds add id list add last item addlast messageitem itemsnoid itemsnoid linkedlist messageitem itemsnoid addlast getobject itemsnoid itemsnoid linkedlist messageitem itemsnoid addlast linkedlist messageitem itemsbyid itemsbyid hashmap linkedlist messageitem itemswithid arraylist linkedlist messageitem itemsids arraylist linkedlist messageitem itemswithid itemsids itemsbyid itemsbyid linkedlist messageitem itemswithid itemsbyid itemsids addlast public void add first message item item if item msg null if items noid null items noid new linked list message item items noid add first item return object o item msg get object dmt uid if o null o instanceof long if items noid null items noid new linked list message item items noid add first item return long id long o linked list message item list if items byid null items byid new hash map long linked list message item items withid new array list linked list message item itemsi ds new array list long list new linked list message item items withid add list itemsi ds add id items byid put id list else list items byid get id if list null list new linked list message item items withid add list itemsi ds add id items byid put id list list add first item addfirst messageitem itemsnoid itemsnoid linkedlist messageitem itemsnoid addfirst getobject itemsnoid itemsnoid linkedlist messageitem itemsnoid addfirst linkedlist messageitem itemsbyid itemsbyid hashmap linkedlist messageitem itemswithid arraylist linkedlist messageitem itemsids arraylist linkedlist messageitem itemswithid itemsids itemsbyid itemsbyid linkedlist messageitem itemswithid itemsids itemsbyid addfirst public int size int size 0 if items noid null size items noid size if items withid null for linked list message item list items withid size list size return size itemsnoid itemsnoid itemswithid linkedlist messageitem itemswithid public int add to message item output int ptr if items noid null for message item item items noid output ptr item if items withid null for linked list message item list items withid for message item item list output ptr item return ptr addto messageitem itemsnoid messageitem itemsnoid itemswithid linkedlist messageitem itemswithid messageitem public long get next urgent time long t long now if items noid null t math min t items noid get first submitted packet sender max coalescing delay if t now return t if items withid null for linked list message item items items withid t math min t items get first submitted packet sender max coalescing delay if t now return t return t getnexturgenttime itemsnoid itemsnoid getfirst packetsender max_coalescing_delay itemswithid linkedlist messageitem itemswithid getfirst packetsender max_coalescing_delay public int add size int length int max size if items noid null for message item item items noid int this len item get length length this len if length max size return length if items withid null for linked list message item list items withid for message item item list int this len item get length length this len if length max size return length return length addsize maxsize itemsnoid messageitem itemsnoid thislen getlength thislen maxsize itemswithid linkedlist messageitem itemswithid messageitem thislen getlength thislen maxsize private int add messages int size int min size int max size long now array list message item messages boolean is urgent int lists 0 if items noid null lists if items withid null lists items withid size for int i 0 i lists i linked list message item list int l i round robin counter 1 lists int list num 1 if items noid null if l 0 list items noid else list num l 1 list items withid get list num else list num l list items withid get l while true if list is empty break message item item list get first if is urgent item submitted packet sender max coalescing delay now break int this size item get length if size 2 this size max size if size min size send it anyway nothing else to send size 2 this size list remove first if list is empty if list items noid items noid null lists else long id itemsi ds get list num items withid remove list num itemsi ds remove list num items byid remove id lists messages add item round robin counter i return size return size size 2 this size list remove first if list is empty if list items noid items noid null lists else long id itemsi ds get list num items withid remove list num itemsi ds remove list num items byid remove id lists messages add item round robin counter i return size addmessages minsize maxsize arraylist messageitem isurgent itemsnoid itemswithid itemswithid linkedlist messageitem roundrobincounter listnum itemsnoid itemsnoid listnum itemswithid listnum listnum itemswithid isempty messageitem getfirst isurgent packetsender max_coalescing_delay thissize getlength thissize maxsize minsize thissize removefirst isempty itemsnoid itemsnoid itemsids listnum itemswithid listnum itemsids listnum itemsbyid roundrobincounter thissize removefirst isempty itemsnoid itemsnoid itemsids listnum itemswithid listnum itemsids listnum itemsbyid roundrobincounter param size param min size param max size param now param messages return the new size of the packet multiplied by 1 iff there are more messages but they don t fit public int add urgent messages int size int min size int max size long now array list message item messages return add messages size min size max size now messages true minsize maxsize addurgentmessages minsize maxsize arraylist messageitem addmessages minsize maxsize param size param min size param max size param now param messages return the new size of the packet multiplied by 1 iff there are more messages but they don t fit public int add messages int size int min size int max size long now array list message item messages return add messages size min size max size now messages false minsize maxsize addmessages minsize maxsize arraylist messageitem addmessages minsize maxsize public void clear items noid null items withid null itemsi ds null items byid null itemsnoid itemswithid itemsids itemsbyid peer message queue queues by priority new prio queue dmt num priorities for int i 0 i queues by priority length i queues by priority i new prio queue peermessagequeue queuesbypriority prioqueue num_priorities queuesbypriority queuesbypriority prioqueue public synchronized int queue and estimate size message item item enqueue prioritized message item item int x 0 for prio queue pq queues by priority if pq items noid null for message item it pq items noid x it get length 2 if x 1024 break if pq items withid null for linked list message item q pq items withid for message item it q x it get length 2 if x 1024 break return x queueandestimatesize messageitem enqueueprioritizedmessageitem prioqueue queuesbypriority itemsnoid messageitem itemsnoid getlength itemswithid linkedlist messageitem itemswithid messageitem getlength public synchronized long get message queue length bytes long x 0 for prio queue pq queues by priority if pq items noid null for message item it pq items noid x it get length 2 if pq items withid null for linked list message item q pq items withid for message item it q x it get length 2 return x getmessagequeuelengthbytes prioqueue queuesbypriority itemsnoid messageitem itemsnoid getlength itemswithid linkedlist messageitem itemswithid messageitem getlength private synchronized void enqueue prioritized message item message item add me assume it goes on the end both the common case short prio add me get priority queues by priority prio add last add me enqueueprioritizedmessageitem messageitem addme addme getpriority queuesbypriority addlast addme like enqueue prioritized message item but adds it to the front of those in the same priority synchronized void pushfront prioritized message item message item add me assume it goes on the front short prio add me get priority queues by priority prio add first add me enqueueprioritizedmessageitem pushfrontprioritizedmessageitem messageitem addme addme getpriority queuesbypriority addfirst addme public synchronized message item grab queued message items int size 0 for int i 0 i queues by priority length i size queues by priority i size message item output new message item size int ptr 0 for prio queue queue queues by priority ptr queue add to output ptr queue clear return output messageitem grabqueuedmessageitems queuesbypriority queuesbypriority messageitem messageitem prioqueue queuesbypriority addto get the time at which the next message must be sent if any message is overdue we will return a value less than now which may not be completely accurate param t param now return public synchronized long get next urgent time long t long now for prio queue queue queues by priority t math min t queue get next urgent time t now if t now return t how much in the past doesn t matter as long as it s in the past return t getnexturgenttime prioqueue queuesbypriority getnexturgenttime public boolean must send now long now return get next urgent time long max value now now mustsendnow getnexturgenttime max_value public synchronized boolean must send size int min size int max size int length min size for prio queue items queues by priority length items add size length max size if length max size return true return false mustsendsize minsize maxsize minsize prioqueue queuesbypriority addsize maxsize maxsize add urgent messages to the queue param size param now param min size param max size param messages return the new size of the packet multiplied by 1 iff there are more messages but they don t fit public synchronized int add urgent messages int size long now int min size int max size array list message item messages boolean got enough false for prio queue queue queues by priority size queue add urgent messages size min size max size now messages if size 0 size size got enough true if got enough return size else return size minsize maxsize addurgentmessages minsize maxsize arraylist messageitem gotenough prioqueue queuesbypriority addurgentmessages minsize maxsize gotenough gotenough add non urgent messages to the queue param size param now param min size param max size param messages return the new size of the packet multiplied by 1 iff there are more messages but they don t fit public synchronized int add non urgent messages int size long now int min size int max size array list message item messages boolean got enough false for prio queue queue queues by priority size queue add messages size min size max size now messages if size 0 size size got enough true if got enough return size else return size minsize maxsize addnonurgentmessages minsize maxsize arraylist messageitem gotenough prioqueue queuesbypriority addmessages minsize maxsize gotenough gotenough public static t extends object object set t query object container container class t clazz db4o 7 4 84 12673 throws a runtime exception not supported when we use this documented api to query all elements of a class isn t that great fixme file a bug with db4o object set has key listener results container query has key listener class query query container query query constrain clazz return query execute objectset objectcontainer runtimeexception objectset haskeylistener haskeylistener private final hash set sendable request set transient sendable request set set new hash set sendable request hashset sendablerequest transientsendablerequestset hashset sendablerequest public synchronized boolean add request sendable request req object container container return set add req addrequest sendablerequest objectcontainer public synchronized sendable request list requests object container container return set to array new sendable request set size sendablerequest listrequests objectcontainer toarray sendablerequest public synchronized boolean remove request sendable request req object container container return set remove req removerequest sendablerequest objectcontainer public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public boolean object can new object container container logger error this not storing transient sendable request set in database new exception error return false objectcannew objectcontainer transientsendablerequestset public static void main string args throws fs parse exception peer parse exception interrupted exception reference signature verification exception node init exception invalid threshold exception random source random node starter global test init pingtest false logger error true create 2 nodes executor executor new pooled executor node node1 node starter create test node 5001 0 pingtest false false true node default max htl 0 random executor 1000 65536 true false false false false false true 0 false false null node node2 node starter create test node 5002 0 pingtest false false true node default max htl 0 random executor 1000 65536 true false false false false false true 0 false false null connect node1 connect node2 node2 connect node1 no swapping node1 start true node2 start true ping peer node pn node1 get peer nodes 0 int pingid 0 thread sleep 20000 node1 usm set drop probability 4 while true logger minor real node ping test class sending ping pingid boolean success try success pn ping pingid catch not connected exception e1 logger normal real node ping test class not connected continue if success logger normal real node ping test class ping pingid successful else logger normal real node ping test class ping failed pingid try thread sleep 2000 catch interrupted exception e shouldn t happen pingid fsparseexception peerparseexception interruptedexception referencesignatureverificationexception nodeinitexception invalidthresholdexception randomsource nodestarter globaltestinit pooledexecutor nodestarter createtestnode default_max_htl nodestarter createtestnode default_max_htl peernode getpeernodes setdropprobability realnodepingtest notconnectedexception realnodepingtest realnodepingtest realnodepingtest interruptedexception apply a bias to a number in the unit interval moving numbers towards 0 or 1 according to the bias parameter param a the number to bias param b the bias parameter 0 5 means no change smaller values bias towards 0 larger towards 1 return the output value public static float bias float a float b return float math pow a math log b math log 0 5 return a 1 0f b 2 1 0f a 1 a variant of the gamma function param a the number to apply gain to param b the gain parameter 0 5 means no change smaller values reduce gain larger values increase gain return the output value public static float gain float a float b float p float math log 1 0 b float math log 0 5 if a 001 return 0 0f else if a 999 return 1 0f if a 0 5 return float math pow 2 a p 2 else return 1 0f float math pow 2 1 a p 2 float c 1 0f b 2 0f 1 0f 2 0f a if a 0 5 return a c 1 0f else return c a c 1 0f the step function returns 0 below a threshold 1 above param a the threshold position param x the input parameter return the output value 0 or 1 public static float step float a float x return x a 0 0f 1 0f the pulse function returns 1 between two thresholds 0 outside param a the lower threshold position param b the upper threshold position param x the input parameter return the output value 0 or 1 public static float pulse float a float b float x return x a x b 0 0f 1 0f a smoothed pulse function a cubic function is used to smooth the step between two thresholds param a1 the lower threshold position for the start of the pulse param a2 the upper threshold position for the start of the pulse param b1 the lower threshold position for the end of the pulse param b2 the upper threshold position for the end of the pulse param x the input parameter return the output value public static float smooth pulse float a1 float a2 float b1 float b2 float x if x a1 x b2 return 0 if x a2 if x b1 return 1 0f x x b1 b2 b1 return 1 0f x x 3 0f 2 0f x x x a1 a2 a1 return x x 3 0f 2 0f x smoothpulse a smoothed step function a cubic function is used to smooth the step between two thresholds param a the lower threshold position param b the upper threshold position param x the input parameter return the output value public static float smooth step float a float b float x if x a return 0 if x b return 1 x x a b a return x x 3 2 x smoothstep a circle up function returns y on a unit circle given 1 x useful for forming bevels param x the input parameter in the range 0 1 return the output value public static float circle up float x x 1 x return float math sqrt 1 x x circleup a circle down function returns 1 y on a unit circle given x useful for forming bevels param x the input parameter in the range 0 1 return the output value public static float circle down float x return 1 0f float math sqrt 1 x x circledown clamp a value to an interval param a the lower clamp threshold param b the upper clamp threshold param x the input parameter return the clamped value public static float clamp float x float a float b return x a a x b b x clamp a value to an interval param a the lower clamp threshold param b the upper clamp threshold param x the input parameter return the clamped value public static int clamp int x int a int b return x a a x b b x return a mod b this differs from the operator with respect to negative numbers param a the dividend param b the divisor return a mod b public static double mod double a double b int n int a b a n b if a 0 return a b return a return a mod b this differs from the operator with respect to negative numbers param a the dividend param b the divisor return a mod b public static float mod float a float b int n int a b a n b if a 0 return a b return a return a mod b this differs from the operator with respect to negative numbers param a the dividend param b the divisor return a mod b public static int mod int a int b int n a b a n b if a 0 return a b return a the triangle function returns a repeating triangle shape in the range 0 1 with wavelength 1 0 param x the input parameter return the output value public static float triangle float x float r mod x 1 0f return 2 0f r 0 5 r 1 r linear interpolation param t the interpolation parameter param a the lower interpolation range param b the upper interpolation range return the interpolated value public static float lerp float t float a float b return a t b a linear interpolation param t the interpolation parameter param a the lower interpolation range param b the upper interpolation range return the interpolated value public static int lerp float t int a int b return int a t b a linear interpolation of argb values param t the interpolation parameter param rgb1 the lower interpolation range param rgb2 the upper interpolation range return the interpolated value public static int mix colors float t int rgb1 int rgb2 int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff a1 lerp t a1 a2 r1 lerp t r1 r2 g1 lerp t g1 g2 b1 lerp t b1 b2 return a1 24 r1 16 g1 8 b1 mixcolors bilinear interpolation of argb values param x the x interpolation parameter 0 1 param y the y interpolation parameter 0 1 param rgb array of four argb values in the order nw ne sw se return the interpolated value public static int bilinear interpolate float x float y int nw int ne int sw int se float m0 m1 int a0 nw 24 0xff int r0 nw 16 0xff int g0 nw 8 0xff int b0 nw 0xff int a1 ne 24 0xff int r1 ne 16 0xff int g1 ne 8 0xff int b1 ne 0xff int a2 sw 24 0xff int r2 sw 16 0xff int g2 sw 8 0xff int b2 sw 0xff int a3 se 24 0xff int r3 se 16 0xff int g3 se 8 0xff int b3 se 0xff float cx 1 0f x float cy 1 0f y m0 cx a0 x a1 m1 cx a2 x a3 int a int cy m0 y m1 m0 cx r0 x r1 m1 cx r2 x r3 int r int cy m0 y m1 m0 cx g0 x g1 m1 cx g2 x g3 int g int cy m0 y m1 m0 cx b0 x b1 m1 cx b2 x b3 int b int cy m0 y m1 return a 24 r 16 g 8 b bilinearinterpolate return the ntsc gray level of an rgb value param rgb1 the input pixel return the gray level 0 255 public static int brightnessntsc int rgb int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff return int r 0 299f g 0 587f b 0 114f compute a catmull rom spline param x the input parameter param num knots the number of knots in the spline param knots the array of knots return the spline value public static float spline float x int num knots float knots int span int num spans num knots 3 float k0 k1 k2 k3 float c0 c1 c2 c3 if num spans 1 throw new illegal argument exception too few knots in spline x clamp x 0 1 num spans span int x if span num knots 4 span num knots 4 x span k0 knots span k1 knots span 1 k2 knots span 2 k3 knots span 3 c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m21 k1 m22 k2 m23 k3 c0 m30 k0 m31 k1 m32 k2 m33 k3 return c3 x c2 x c1 x c0 numknots numknots numspans numknots numspans illegalargumentexception numspans numknots numknots compute a catmull rom spline but with variable knot spacing param x the input parameter param num knots the number of knots in the spline param xknots the array of knot x values param yknots the array of knot y values return the spline value public static float spline float x int num knots int xknots int yknots int span int num spans num knots 3 float k0 k1 k2 k3 float c0 c1 c2 c3 if num spans 1 throw new illegal argument exception too few knots in spline for span 0 span num spans span if xknots span 1 x break if span num knots 3 span num knots 3 float t float x xknots span xknots span 1 xknots span span if span 0 span 0 t 0 k0 yknots span k1 yknots span 1 k2 yknots span 2 k3 yknots span 3 c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m21 k1 m22 k2 m23 k3 c0 m30 k0 m31 k1 m32 k2 m33 k3 return c3 t c2 t c1 t c0 numknots numknots numspans numknots numspans illegalargumentexception numspans numknots numknots compute a catmull rom spline for rgb values param x the input parameter param num knots the number of knots in the spline param knots the array of knots return the spline value public static int color spline float x int num knots int knots int span int num spans num knots 3 float k0 k1 k2 k3 float c0 c1 c2 c3 if num spans 1 throw new illegal argument exception too few knots in spline x clamp x 0 1 num spans span int x if span num knots 4 span num knots 4 x span int v 0 for int i 0 i 4 i int shift i 8 k0 knots span shift 0xff k1 knots span 1 shift 0xff k2 knots span 2 shift 0xff k3 knots span 3 shift 0xff c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m21 k1 m22 k2 m23 k3 c0 m30 k0 m31 k1 m32 k2 m33 k3 int n int c3 x c2 x c1 x c0 if n 0 n 0 else if n 255 n 255 v n shift return v numknots colorspline numknots numspans numknots numspans illegalargumentexception numspans numknots numknots compute a catmull rom spline for rgb values but with variable knot spacing param x the input parameter param num knots the number of knots in the spline param xknots the array of knot x values param yknots the array of knot y values return the spline value public static int color spline int x int num knots int xknots int yknots int span int num spans num knots 3 float k0 k1 k2 k3 float c0 c1 c2 c3 if num spans 1 throw new illegal argument exception too few knots in spline for span 0 span num spans span if xknots span 1 x break if span num knots 3 span num knots 3 float t float x xknots span xknots span 1 xknots span span if span 0 span 0 t 0 int v 0 for int i 0 i 4 i int shift i 8 k0 yknots span shift 0xff k1 yknots span 1 shift 0xff k2 yknots span 2 shift 0xff k3 yknots span 3 shift 0xff c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m21 k1 m22 k2 m23 k3 c0 m30 k0 m31 k1 m32 k2 m33 k3 int n int c3 t c2 t c1 t c0 if n 0 n 0 else if n 255 n 255 v n shift return v numknots colorspline numknots numspans numknots numspans illegalargumentexception numspans numknots numknots an implementation of fant s resampling algorithm param source the source pixels param dest the destination pixels param length the length of the scanline to resample param offset the start offset into the arrays param stride the offset between pixels in consecutive rows param out an array of output positions for each pixel public static void resample int source int dest int length int offset int stride float out int i j float sizfac float in segment float out segment int a r g b nexta nextr nextg nextb float a sum r sum g sum b sum float in int src index offset int dest index offset int last index source length int rgb in new float length 2 i 0 for j 0 j length j while out i 1 j i in j i float j out i out i 1 out i in j image math clamp in j 0 length 1 in length length in length 1 length in segment 1 0f out segment in 1 sizfac out segment a sum r sum g sum b sum 0 0f rgb source src index a rgb 24 0xff r rgb 16 0xff g rgb 8 0xff b rgb 0xff src index stride rgb source src index nexta rgb 24 0xff nextr rgb 16 0xff nextg rgb 8 0xff nextb rgb 0xff src index stride i 1 while i length float a intensity in segment a 1 0f in segment nexta float r intensity in segment r 1 0f in segment nextr float g intensity in segment g 1 0f in segment nextg float b intensity in segment b 1 0f in segment nextb if in segment out segment a sum a intensity in segment r sum r intensity in segment g sum g intensity in segment b sum b intensity in segment out segment in segment in segment 1 0f a nexta r nextr g nextg b nextb if src index last index rgb source src index nexta rgb 24 0xff nextr rgb 16 0xff nextg rgb 8 0xff nextb rgb 0xff src index stride else a sum a intensity out segment r sum r intensity out segment g sum g intensity out segment b sum b intensity out segment dest dest index int math min a sum sizfac 255 24 int math min r sum sizfac 255 16 int math min g sum sizfac 255 8 int math min b sum sizfac 255 dest index stride a sum r sum g sum b sum 0 0f in segment out segment out segment in i 1 in i sizfac out segment i insegment outsegment asum rsum gsum bsum srcindex destindex lastindex imagemath insegment outsegment outsegment asum rsum gsum bsum srcindex srcindex srcindex srcindex aintensity insegment insegment rintensity insegment insegment gintensity insegment insegment bintensity insegment insegment insegment outsegment asum aintensity insegment rsum rintensity insegment gsum gintensity insegment bsum bintensity insegment outsegment insegment insegment srcindex lastindex srcindex srcindex asum aintensity outsegment rsum rintensity outsegment gsum gintensity outsegment bsum bintensity outsegment destindex asum rsum gsum bsum destindex asum rsum gsum bsum insegment outsegment outsegment outsegment premultiply a block of pixels public static void premultiply int p int offset int length length offset for int i offset i length i int rgb p i int a rgb 24 0xff int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff float f a 1 0f 255 0f r f g f b f p i a 24 r 16 g 8 b premultiply a block of pixels public static void unpremultiply int p int offset int length length offset for int i offset i length i int rgb p i int a rgb 24 0xff int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if a 0 a 255 float f 255 0f a r f g f b f if r 255 r 255 if g 255 g 255 if b 255 b 255 p i a 24 r 16 g 8 b creates an introduction server public introduction server wot my wot identity fetcher my fetcher super my wot get plugin respirator get node my wot get plugin respirator gethl simple client wot introduction server m wot my wot m puzzle store m wot get introduction puzzle store m random m wot get plugin respirator get node fast weak random start introductionserver introductionserver mywot identityfetcher myfetcher mywot getpluginrespirator getnode mywot getpluginrespirator gethlsimpleclient mwot mywot mpuzzlestore mwot getintroductionpuzzlestore mrandom mwot getpluginrespirator getnode fastweakrandom public static int get identity puzzle count identity i try return math max integer parse int i get property introduction server puzzle count property 0 catch invalid parameter exception e return 0 getidentitypuzzlecount parseint getproperty introductionserver puzzle_count_property invalidparameterexception override protected collection client getter create fetch storage return new array list client getter default puzzle count 5 1 just assume that there are 5 identities clientgetter createfetchstorage arraylist clientgetter default_puzzle_count override protected collection base client putter create insert storage return new array list base client putter default puzzle count 5 1 just assume that there are 5 identities baseclientputter createinsertstorage arraylist baseclientputter default_puzzle_count public int get priority return native thread low priority getpriority nativethread low_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period called by the superclass transfer thread after get startup delay milliseconds and then after each get sleep time milliseconds deletes old puzzles downloads solutions of existing ones and inserts new ones override protected void iterate m puzzle store delete expired puzzles synchronized m wot todo we might want to not lock all the time during captcha creation figure out how long this takes for own identity identity m wot get all own identities if identity has context introduction puzzle introduction context try logger debug this managing puzzles of identity get nickname download solutions identity generate new puzzles identity insert puzzles identity logger debug this managing puzzles finished catch exception e logger error this puzzle management failed for identity get nickname e transferthread getstartupdelay getsleeptime mpuzzlestore deleteexpiredpuzzles mwot ownidentity mwot getallownidentities hascontext introductionpuzzle introduction_context getnickname downloadsolutions generatenewpuzzles insertpuzzles getnickname private void download solutions own identity inserter throws fetch exception todo we restart all requests in every iteration decide whether this makes sense or not if not add code to re use requests for puzzles which still exist i think it makes sense to restart them because there are not many puzzles and therefore not many requests abort fetches synchronized m puzzle store object set own introduction puzzle puzzles m puzzle store get unsolved by inserter inserter logger debug this identity inserter get nickname has puzzles size unsolved puzzles stored trying to fetch solutions for own introduction puzzle p puzzles fetch context fetch context m client get fetch context fixme toad are these parameters correct fetch context max splitfile block retries 1 retry forever fetch context max non splitfile retries 1 retry forever client getter g m client fetch p get solutionuri xml transformer max introduction byte size m wot get request client this fetch context fixme set to a reasonable value before release plugin manager default is interactive priority g set priority class request starter update priority class m wot get plugin respirator get node client core client context null add fetch g logger debug this trying to fetch captcha solution for p get requesturi at p get solutionuri to string downloadsolutions ownidentity fetchexception abortfetches mpuzzlestore objectset ownintroductionpuzzle mpuzzlestore getunsolvedbyinserter getnickname ownintroductionpuzzle fetchcontext fetchcontext mclient getfetchcontext fetchcontext maxsplitfileblockretries fetchcontext maxnonsplitfileretries clientgetter mclient getsolutionuri xmltransformer max_introduction_byte_size mwot getrequestclient fetchcontext pluginmanager setpriorityclass requeststarter update_priority_class mwot getpluginrespirator getnode clientcore clientcontext addfetch getrequesturi getsolutionuri tostring private void generate new puzzles own identity identity throws io exception synchronized m puzzle store int puzzles to generate get identity puzzle count identity m puzzle store get of today by inserter identity size logger debug this trying to generate puzzles to generate new puzzles from identity get nickname while puzzles to generate 0 m puzzle factories m random next int m puzzle factories length generate puzzle m puzzle store identity puzzles to generate logger debug this finished generating puzzles from identity get nickname generatenewpuzzles ownidentity ioexception mpuzzlestore puzzlestogenerate getidentitypuzzlecount mpuzzlestore getoftodaybyinserter puzzlestogenerate getnickname puzzlestogenerate mpuzzlefactories mrandom nextint mpuzzlefactories generatepuzzle mpuzzlestore puzzlestogenerate getnickname private void insert puzzles own identity identity throws io exception insert exception synchronized m puzzle store object set own introduction puzzle puzzles m puzzle store get uninserted own puzzles by inserter identity logger debug this trying to insert puzzles size puzzles from identity get nickname for own introduction puzzle p puzzles try insert puzzle p catch exception e logger error this puzzle insert failed e logger debug this finished inserting puzzles from identity get nickname insertpuzzles ownidentity ioexception insertexception mpuzzlestore objectset ownintroductionpuzzle mpuzzlestore getuninsertedownpuzzlesbyinserter getnickname ownintroductionpuzzle insertpuzzle getnickname not synchronized because it s caller is synchronized already private void insert puzzle own introduction puzzle puzzle throws io exception insert exception transformer exception parser configuration exception assert puzzle was inserted bucket tempb mtbf make bucket xml transformer max introductionpuzzle byte size output stream os null try os tempb get output stream m wot getxml transformer export introduction puzzle puzzle os provides synchronization on the puzzle os close os null tempb set read only fixme toad are these parameters correct insert block ib new insert block tempb null puzzle get inserturi insert context ictx m client get insert context true client putter pu m client insert ib false null false ictx this fixme set to a reasonable value before release plugin manager default is interactive priority pu set priority class request starter update priority class m wot get plugin respirator get node client core client context null add insert pu tempb null logger debug this started insert of puzzle from puzzle get inserter get nickname finally if tempb null tempb free closer close os insertpuzzle ownintroductionpuzzle ioexception insertexception transformerexception parserconfigurationexception wasinserted makebucket xmltransformer max_introductionpuzzle_byte_size outputstream getoutputstream mwot getxmltransformer exportintroductionpuzzle setreadonly insertblock insertblock getinserturi insertcontext mclient getinsertcontext clientputter mclient pluginmanager setpriorityclass requeststarter update_priority_class mwot getpluginrespirator getnode clientcore clientcontext addinsert getinserter getnickname called when a puzzle was successfully inserted public void on success base client putter state object container container logger debug this successful insert of puzzle state geturi try synchronized m wot synchronized m puzzle store own introduction puzzle puzzle m puzzle store get own puzzle by requesturi state geturi be careful this locks the wot puzzle set inserted m puzzle store store and commit puzzle catch exception e logger error this error e finally remove insert state onsuccess baseclientputter objectcontainer mwot mpuzzlestore ownintroductionpuzzle mpuzzlestore getownpuzzlebyrequesturi setinserted mpuzzlestore storeandcommit removeinsert called when the insertion of a puzzle failed public void on failure insert exception e base client putter state object container container if e get mode insert exception cancelled logger debug this insert cancelled state geturi return try logger error this insert of puzzle failed state geturi e finally remove insert state onfailure insertexception baseclientputter objectcontainer getmode insertexception removeinsert called when a puzzle solution is successfully fetched we then add the identity which solved the puzzle public void on success fetch result result client getter state object container container logger debug this fetched puzzle solution state geturi try import introduction locks the wot so we need to do that here first to keep the locking order the same everywhere to prevent deadlocks synchronized m wot synchronized m puzzle store own introduction puzzle p m puzzle store get own puzzle by solutionuri state geturi synchronized p own identity puzzle owner own identity p get inserter identity new identity m wot getxml transformer import introduction puzzle owner result as bucket get input stream logger debug this imported identity introduction for identity new identity get requesturi to the own identity puzzle owner p set solved m puzzle store store and commit p catch exception e logger error this parsing failed for state geturi e finally remove fetch state onsuccess fetchresult clientgetter objectcontainer importintroduction mwot mpuzzlestore ownintroductionpuzzle mpuzzlestore getownpuzzlebysolutionuri ownidentity puzzleowner ownidentity getinserter newidentity mwot getxmltransformer importintroduction puzzleowner asbucket getinputstream newidentity getrequesturi ownidentity puzzleowner setsolved mpuzzlestore storeandcommit removefetch called when the node can t fetch a file or when there is a newer edition in our case called when there is no solution to a puzzle in the network public void on failure fetch exception e client getter state object container container if e get mode fetch exception cancelled logger debug this fetch cancelled state geturi return try if e get mode fetch exception data not found this is the normal case the puzzle was not solved else logger error this downloading puzzle solution state geturi failed e finally remove fetch state onfailure fetchexception clientgetter objectcontainer getmode fetchexception getmode fetchexception data_not_found removefetch not needed functions from the client callback interface only called by inserts public void on fetchable base client putter state object container container clientcallback onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container only called by inserts public void on generateduri freeneturi uri base client putter state object container container onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container called when freenet async thinks that the request should be serialized to disk if it is a persistent request public void on major progress object container container ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer public web interface freetalk my freetalk m freetalk my freetalk m page maker m freetalk get plugin respirator get page maker m own identity null webinterface myfreetalk mfreetalk myfreetalk mpagemaker mfreetalk getpluginrespirator getpagemaker mownidentity private void set up menu m page maker remove all navigation links if m own identity null m page maker add navigation link back to freenet back to nodes home false null return m page maker add navigation link freetalk plugin uri home freetalk plugin home false null m page maker add navigation link freetalk plugin uri messages boards view all boards false null m page maker add navigation link freetalk plugin uri identities identities manage your own and known identities false null m page maker add navigation link freetalk plugin uri log out log out log out false null m page maker add navigation link back to freenet back to your freenet node false null setupmenu mpagemaker removeallnavigationlinks mownidentity mpagemaker addnavigationlink mpagemaker addnavigationlink plugin_uri mpagemaker addnavigationlink plugin_uri mpagemaker addnavigationlink plugin_uri mpagemaker addnavigationlink plugin_uri logout mpagemaker addnavigationlink private void set logged in own identity ft own identity user m own identity user setloggedinownidentity ftownidentity mownidentity private ft own identity get logged in own identity return m own identity ftownidentity getloggedinownidentity mownidentity todo this function is ugly clean it up public string handlehttp get http request request throws pluginhttp exception fixme string pass request get param form password if pass null fixme is this correct what if the client just does not specify the password so that its null if pass length 0 pass equals pr get node client core form password return errors make error page this buh invalid form password fixme ugly hack remove string page request get path substring freetalk plugin uri length int end index request get path index of if end index 0 page page substring 0 end index if page equals log out set logged in own identity null set up menu if page equals create identity return new create identity wizard this request tohtml if page equals log in try set logged in own identity m freetalk get identity manager get own identity request get param own identityid set up menu return new welcome this get logged in own identity request tohtml catch no such identity exception e ignore and continue as if the user did not specify an identity he will end up with a log in page if get logged in own identity null return new log in page this null request tohtml anything below this line assumes that we have a logged in own identity if page length 1 equals page return new welcome this get logged in own identity request tohtml if identities equals page return new identity editor this get logged in own identity request tohtml if messages equals page return new boards page this get logged in own identity request tohtml try fixme also use get logged in own identity here if page equals show board return new board page this get logged in own identity request tohtml if page equals show thread return new thread page this get logged in own identity request tohtml todo make this exceptions store the specified non existant element theirselves catch no such board exception e throw new not found pluginhttp exception unknown board request get param name page catch no such message exception e throw new not found pluginhttp exception unknown message request get param id page throw new not found pluginhttp exception resource not found in freetalk plugin page handlehttpget httprequest pluginhttpexception getparam formpassword getnode clientcore formpassword makeerrorpage getpath plugin_uri endindex getpath indexof endindex endindex logout setloggedinownidentity setupmenu createidentity createidentitywizard login setloggedinownidentity mfreetalk getidentitymanager getownidentity getparam ownidentityid setupmenu getloggedinownidentity nosuchidentityexception loginpage getloggedinownidentity loginpage getloggedinownidentity identityeditor getloggedinownidentity boardspage getloggedinownidentity getloggedinownidentity showboard boardpage getloggedinownidentity showthread threadpage getloggedinownidentity nosuchboardexception notfoundpluginhttpexception getparam nosuchmessageexception notfoundpluginhttpexception getparam notfoundpluginhttpexception todo this function is ugly clean it up public string handlehttp post http request request throws pluginhttp exception string pass request get part as string form password 32 if pass null pass length 0 pass equals m freetalk get plugin respirator get node client core form password return new error page this null request error invalid form password tohtml string page request get path substring freetalk plugin uri length if page length 1 throw new not found pluginhttp exception resource not found page try if page equals create identity set up menu return new create identity wizard this request tohtml anything below this line requires the user to be logged in with a certain own identity ft own identity own id m freetalk get identity manager get own identity request get part as string own identityid 64 if page equals log in set logged in own identity own id set up menu return new welcome this own id request tohtml set up menu if page equals new board return new new board page this own id request tohtml if page equals new thread return new new thread page this own id request tohtml if page equals new reply return new new reply page this own id request tohtml catch no such identity exception e throw new not found pluginhttp exception e get message page catch no such board exception e throw new not found pluginhttp exception e get message page catch no such message exception e throw new not found pluginhttp exception e get message page if page equals exportdb string writer sw new string writer try backup export config db db sw catch io exception e logger error this error while exporting database e return errors make error page this server buh buh e get message throw new download pluginhttp exception sw to string get bytes utf 8 fms kidding xml fms clone db backup if page equals importdb http uploaded file file request get uploaded file filename if file null file get filename trim length 0 return errors make error page this no file to import selected try backup import config db db file get data get input stream catch exception e logger error this error while importing db from file get filename e return errors make error page this error while importing db from file get filename e get message throw new redirect pluginhttp exception m freetalk plugin uri if page equals createownidentity list string err new array list string string nick request get part as string nick 1024 trim string request uri request get part as string requesturi 1024 string insert uri request get part as string inserturi 1024 boolean publish true equals request get part as string publish trust list 24 identity editor check nick err nick if request uri length 0 insert uri length 0 freeneturi kp m client generate key pair fms insert uri kp 0 to string request uri kp 1 to string err add uri was empty i generated one for you return identity editor make new own identity page this nick request uri insert uri publish err identity editor check inserturi err insert uri identity editor check requesturi err request uri if err size 0 fixme use identity manager to implement this throw new unsupported operation exception ft own identity oi new ft own identity nick request uri insert uri publish identity editor add new own identity db config oi err if err size 0 throw new redirect pluginhttp exception m freetalk plugin uri ownidentities return identity editor make new own identity page this nick request uri insert uri publish err if page equals addknownidentity list string err new array list string string request uri request get part as string requesturi 1024 if request uri length 0 err add are you jokingly uri was empty return identity editor make new known identity page this request uri err identity editor check requesturi err request uri if err size 0 fixme use identity manager to implement this throw new unsupported operation exception ft identity i new ft identity request uri identity editor add new known identity db config i err if err size 0 throw new redirect pluginhttp exception m freetalk plugin uri knownidentities return identity editor make new known identity page this request uri err if page equals delete own identity list string err new array list string string request uri request get part as string identity 1024 if request uri length 0 err add are you jokingly uri was empty return identity editor make delete own identity page this request uri err if request is part set confirmed identity editor delete identity this request uri err else err add please confirm if err size 0 return identity editor make delete own identity page this request uri err throw new redirect pluginhttp exception m freetalk plugin uri ownidentities return identity editor make delete own identity page fms request uri err if page equals delete identity list string err new array list string string request uri request get part as string identity 1024 if request uri length 0 err add are you jokingly uri was empty return identity editor make delete known identity page this request uri err if request is part set confirmed identity editor delete identity this request uri err else err add please confirm if err size 0 return identity editor make delete known identity page this request uri err throw new redirect pluginhttp exception m freetalk plugin uri knownidentities throw new not found pluginhttp exception resource not found page handlehttppost httprequest pluginhttpexception getpartasstring formpassword mfreetalk getpluginrespirator getnode clientcore formpassword errorpage getpath plugin_uri notfoundpluginhttpexception createidentity setupmenu createidentitywizard ftownidentity ownid mfreetalk getidentitymanager getownidentity getpartasstring ownidentityid login setloggedinownidentity ownid setupmenu ownid setupmenu newboard newboardpage ownid newthread newthreadpage ownid newreply newreplypage ownid nosuchidentityexception notfoundpluginhttpexception getmessage nosuchboardexception notfoundpluginhttpexception getmessage nosuchmessageexception notfoundpluginhttpexception getmessage stringwriter stringwriter exportconfigdb ioexception makeerrorpage buhbuh getmessage downloadpluginhttpexception tostring getbytes httpuploadedfile getuploadedfile getfilename makeerrorpage importconfigdb getdata getinputstream getfilename makeerrorpage getfilename getmessage redirectpluginhttpexception mfreetalk plugin_uri arraylist getpartasstring requesturi getpartasstring inserturi getpartasstring getpartasstring publishtrustlist identityeditor checknick requesturi inserturi mclient generatekeypair inserturi tostring requesturi tostring identityeditor makenewownidentitypage requesturi inserturi identityeditor checkinserturi inserturi identityeditor checkrequesturi requesturi unsupportedoperationexception ftownidentity ftownidentity requesturi inserturi identityeditor addnewownidentity db_config redirectpluginhttpexception mfreetalk plugin_uri identityeditor makenewownidentitypage requesturi inserturi arraylist requesturi getpartasstring requesturi identityeditor makenewknownidentitypage requesturi identityeditor checkrequesturi requesturi unsupportedoperationexception ftidentity ftidentity requesturi identityeditor addnewknownidentity db_config redirectpluginhttpexception mfreetalk plugin_uri identityeditor makenewknownidentitypage requesturi deleteownidentity arraylist requesturi getpartasstring requesturi identityeditor makedeleteownidentitypage requesturi ispartset identityeditor deleteidentity requesturi identityeditor makedeleteownidentitypage requesturi redirectpluginhttpexception mfreetalk plugin_uri identityeditor makedeleteownidentitypage requesturi deleteidentity arraylist requesturi getpartasstring requesturi identityeditor makedeleteknownidentitypage requesturi ispartset identityeditor deleteidentity requesturi identityeditor makedeleteknownidentitypage requesturi redirectpluginhttpexception mfreetalk plugin_uri notfoundpluginhttpexception public final freetalk get freetalk return m freetalk getfreetalk mfreetalk public final page maker get page maker return m page maker pagemaker getpagemaker mpagemaker return the code ft own identity code which is currently logged in public final ft own identity get own identity iterator ft own identity iter m freetalk get identity manager own identity iterator return iter has next iter next null ftownidentity ftownidentity getownidentity ftownidentity mfreetalk getidentitymanager ownidentityiterator hasnext private static final long serial versionuid 1 public not trusted exception string message super message serialversionuid nottrustedexception public class median filter extends whole image filter public median filter medianfilter wholeimagefilter medianfilter private int median int array int max max index for int i 0 i 4 i max 0 max index 0 for int j 0 j 9 j if array j max max array j max index j array max index 0 max 0 for int i 0 i 9 i if array i max max array i return max maxindex maxindex maxindex maxindex private int rgb median int r int g int b int sum index 0 min integer max value for int i 0 i 9 i sum 0 for int j 0 j 9 j sum math abs r i r j sum math abs g i g j sum math abs b i b j if sum min min sum index i return index rgbmedian max_value override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int argb new int 9 int r new int 9 int g new int 9 int b new int 9 int out pixels new int width height for int y 0 y height y for int x 0 x width x int k 0 for int dy 1 dy 1 dy int iy y dy if 0 iy iy height int ioffset iy width for int dx 1 dx 1 dx int ix x dx if 0 ix ix width int rgb in pixels ioffset ix argb k rgb r k rgb 16 0xff g k rgb 8 0xff b k rgb 0xff k while k 9 argb k 0xff000000 r k g k b k 0 k out pixels index argb rgb median r g b return out pixels filterpixels inpixels transformedspace outpixels inpixels outpixels rgbmedian outpixels override public string to string return blur median tostring public read only file slice bucket file f long start at long length this file new file f get path copy so we can delete it this start at start at this length length readonlyfileslicebucket startat getpath startat startat public read only file slice bucket simple field set fs throws cannot create from field set exception string tmp fs get filename if tmp null throw new cannot create from field set exception no filename this file new file tmp tmp fs get length if tmp null throw new cannot create from field set exception no length try length long parse long tmp catch number format exception e throw new cannot create from field set exception corrupt length tmp e tmp fs get offset if tmp null throw new cannot create from field set exception no offset try start at long parse long tmp catch number format exception e throw new cannot create from field set exception corrupt offset tmp e readonlyfileslicebucket simplefieldset cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception parselong numberformatexception cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception startat parselong numberformatexception cannotcreatefromfieldsetexception public output stream get output stream throws io exception throw new io exception bucket is read only outputstream getoutputstream ioexception ioexception public input stream get input stream throws io exception return new my input stream inputstream getinputstream ioexception myinputstream public string get name return rofs file get absolute path start at length getname getabsolutepath startat public long size return length public boolean is read only return true isreadonly public void set read only do nothing setreadonly my input stream throws io exception try this f new random access file file r f seek start at if f length start at length throw new read only file slice bucket exception file truncated length f length but start at start at for length bytes ptr 0 catch file not found exception e throw new read only file slice bucket exception e myinputstream ioexception randomaccessfile startat startat readonlyfileslicebucketexception startat filenotfoundexception readonlyfileslicebucketexception override public int read throws io exception if ptr length return 1 int x f read if x 1 ptr return x ioexception override public int read byte buf int offset int len throws io exception if ptr length return 1 len int math min len length ptr int x f read buf offset len ptr x return x ioexception override public int read byte buf throws io exception return read buf 0 buf length ioexception override public void close throws io exception f close ioexception private static final long serial versionuid 1 public read only file slice bucket exception file not found exception e super file not found e get message init cause e serialversionuid readonlyfileslicebucketexception filenotfoundexception getmessage initcause public read only file slice bucket exception string string super string readonlyfileslicebucketexception public void free public simple field set to field set simple field set fs new simple field set false fs put single type read only file slice bucket fs put single filename file to string fs put offset start at fs put length length return fs simplefieldset tofieldset simplefieldset simplefieldset putsingle readonlyfileslicebucket putsingle tostring startat public void store to object container container container store this storeto objectcontainer public void remove from object container container container delete file container delete this removefrom objectcontainer public void object on activate object container container cascading activation of dependancies container activate file 5 objectonactivate objectcontainer public bucket create shadow throws io exception string fnam new string file get path file new file new file fnam return new read only file slice bucket new file start at length createshadow ioexception getpath newfile readonlyfileslicebucket newfile startat public void make noise buffered image image float factor one float factor two float factor three float factor four do nothing makenoise bufferedimage factorone factortwo factorthree factorfour private float high output level 1 public levels filter highoutputlevel levelsfilter public void set low level float low level this low level low level setlowlevel lowlevel lowlevel lowlevel public float get low level return low level getlowlevel lowlevel public void set high level float high level this high level high level sethighlevel highlevel highlevel highlevel public float get high level return high level gethighlevel highlevel public void set low output level float low output level this low output level low output level setlowoutputlevel lowoutputlevel lowoutputlevel lowoutputlevel public float get low output level return low output level getlowoutputlevel lowoutputlevel public void set high output level float high output level this high output level high output level sethighoutputlevel highoutputlevel highoutputlevel highoutputlevel public float get high output level return high output level gethighoutputlevel highoutputlevel override protected int filter pixels int width int height int in pixels rectangle transformed space histogram histogram new histogram in pixels width height 0 width int i j if histogram get num samples 0 float scale 255 0f histogram get num samples lut new int 3 256 float low low level 255 float high high level 255 if low high high for i 0 i 3 i for j 0 j 256 j lut i j pixel utils clamp int 255 low output level high output level low output level j low high low else lut null i 0 for int y 0 y height y for int x 0 x width x in pixels i filterrgb x y in pixels i i lut null return in pixels filterpixels inpixels transformedspace inpixels getnumsamples getnumsamples lowlevel highlevel pixelutils lowoutputlevel highoutputlevel lowoutputlevel inpixels inpixels inpixels public int filterrgb int x int y int rgb if lut null int a rgb 0xff000000 int r lut histogram red rgb 16 0xff int g lut histogram green rgb 8 0xff int b lut histogram blue rgb 0xff return a r 16 g 8 b return rgb override public string to string return colors levels tostring get list head element return list head element or null if list is empty public synchronized l2 list elem head return next this next null l2listelem get list tail element return list tail element or null if list is empty public synchronized l2 list elem tail return prev this prev null l2listelem make list empty public synchronized void clear modify next prev this n elems 0 update counter 1 nelems updatecounter insert element at the beginning of the list public synchronized void prepend l2 list elem elem modify next modify elem modify elem next next elem prev this next prev elem next elem n elems 1 update counter 1 l2listelem nelems updatecounter insert element at the end of the list public synchronized void append l2 list elem elem modify prev modify elem modify elem next this elem prev prev prev next elem prev elem n elems 1 update counter 1 l2listelem nelems updatecounter remove element from the list public synchronized void remove l2 list elem elem modify elem prev modify elem next modify elem next prev elem prev elem prev next elem next n elems 1 update counter 1 l2listelem nelems updatecounter check if list is empty return code true code if list is empty public synchronized boolean is empty return next this isempty add object to the list param obj object added to the list return always returns code true code public synchronized boolean add object obj append l2 list elem obj return true l2listelem remove object from the list param o object to be removed from the list return always returns code true code public synchronized boolean remove object o remove l2 list elem o return true l2listelem get size of the list return number of elements in the list public int size return n elems nelems check if object is in collection param o object to be searched in the collection return code true code if there is an object in the collection which is equals to the specified object public synchronized boolean contains object o for l2 list elem e next e this e e next if e equals o return true return false l2listelem private int counter l2 list iterator curr l2 list this counter update counter l2listiterator l2list updatecounter public object next if has next throw new no such element exception curr curr next return curr hasnext nosuchelementexception public int next oid return i persistent next get oid nextoid ipersistent getoid public boolean has next if counter update counter throw new illegal state exception return curr next l2 list this hasnext updatecounter illegalstateexception l2list public void remove if counter update counter curr l2 list this throw new illegal state exception l2 list this remove curr counter update counter curr curr prev updatecounter l2list illegalstateexception l2list updatecounter get list iterator this iterator supports remove method put concurrent modifications of thje list during iteration are not possible return list iterator public synchronized iterator iterator return new l2 list iterator l2listiterator get array of the list elements return array with list elements public synchronized object to array l2 list elem arr new l2 list elem n elems l2 list elem e this for int i 0 i arr length i arr i e e next return arr toarray l2listelem l2listelem nelems l2listelem returns an array containing all of the elements in this list in the correct order the runtime type of the returned array is that of the specified array if the list fits in the specified array it is returned therein otherwise a new array is allocated with the runtime type of the specified array and the size of this list p if the list fits in the specified array with room to spare i e the array has more elements than the list the element in the array immediately following the end of the collection is set to tt null tt this is useful in determining the length of the list i only i if the caller knows that the list does not contain any tt null tt elements param a the array into which the elements of the list are to be stored if it is big enough otherwise a new array of the same runtime type is allocated for this purpose return an array containing the elements of the list throws array store exception if the runtime type of a is not a supertype of the runtime type of every element in this list public synchronized object to array object a int size n elems if a length size a object java lang reflect array new instance a get class get component type size l2 list elem e this for int i 0 i size i a i e e next if a length size a size null return a arraystoreexception toarray nelems newinstance getclass getcomponenttype l2listelem returns tt true tt if this collection contains all of the elements in the specified collection p this implementation iterates over the specified collection checking each element returned by the iterator in turn to see if it s contained in this collection if all elements are so contained tt true tt is returned otherwise tt false tt param c collection to be checked for containment in this collection return tt true tt if this collection contains all of the elements in the specified collection throws null pointer exception if the specified collection is null see contains object public synchronized boolean contains all collection c iterator e c iterator while e has next if contains e next return false return true nullpointerexception containsall hasnext adds all of the elements in the specified collection to this collection optional operation the behavior of this operation is undefined if the specified collection is modified while the operation is in progress this implies that the behavior of this call is undefined if the specified collection is this collection and this collection is nonempty p this implementation iterates over the specified collection and adds each object returned by the iterator to this collection in turn p note that this implementation will throw an tt unsupported operation exception tt unless tt add tt is overridden assuming the specified collection is non empty param c collection whose elements are to be added to this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if this collection does not support the tt add all tt method throws null pointer exception if the specified collection is null see add object public synchronized boolean add all collection c iterator e c iterator while e has next add e next return true unsupportedoperationexception unsupportedoperationexception addall nullpointerexception addall hasnext removes from this collection all of its elements that are contained in the specified collection optional operation p this implementation iterates over this collection checking each element returned by the iterator in turn to see if it s contained in the specified collection if it s so contained it s removed from this collection with the iterator s tt remove tt method p note that this implementation will throw an tt unsupported operation exception tt if the iterator returned by the tt iterator tt method does not implement the tt remove tt method and this collection contains one or more elements in common with the specified collection param c elements to be removed from this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if the tt remove all tt method is not supported by this collection throws null pointer exception if the specified collection is null see remove object see contains object public synchronized boolean remove all collection c boolean modified false iterator e iterator while e has next if c contains e next e remove modified true return modified unsupportedoperationexception unsupportedoperationexception removeall nullpointerexception removeall hasnext retains only the elements in this collection that are contained in the specified collection optional operation in other words removes from this collection all of its elements that are not contained in the specified collection p this implementation iterates over this collection checking each element returned by the iterator in turn to see if it s contained in the specified collection if it s not so contained it s removed from this collection with the iterator s tt remove tt method p note that this implementation will throw an tt unsupported operation exception tt if the iterator returned by the tt iterator tt method does not implement the tt remove tt method and this collection contains one or more elements not present in the specified collection param c elements to be retained in this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if the tt retain all tt method is not supported by this collection throws null pointer exception if the specified collection is null see remove object see contains object public synchronized boolean retain all collection c boolean modified false iterator e iterator while e has next if c contains e next e remove modified true return modified unsupportedoperationexception unsupportedoperationexception retainall nullpointerexception retainall hasnext select members of the collection using search predicate this iterator doesn t support remove method it is not possible to update list during iteration param cls class of index members param predicate jsql condition return iterator through members of the collection matching search condition public iterable iterator select class cls string predicate query query new query impl get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public ssdp notify request set method http notify seturi ssdpnotifyrequest setmethod param random param wipe files param dir if code null code then use the default temporary directory param prefix throws io exception public filename generator random random boolean wipe files file dir string prefix throws io exception this random random this prefix prefix if dir null tmp dir file util get canonical file new file system get property java io tmpdir else tmp dir file util get canonical file dir if tmp dir exists tmp dir mkdir if tmp dir is directory tmp dir can read tmp dir can write throw new io exception not a directory or cannot read write tmp dir if wipe files long wiped files 0 long wipeable files 0 long start wipe system current time millis file filenames tmp dir list files if filenames null for int i 0 i filenames length i wrapper manager signal starting 5 60 1000 if i 1024 0 i 0 user may want some feedback during startup system err println deleted wiped files temp files i wipeable files non temp files in temp dir file f filenames i string name f get name if file separator char name to lower case starts with prefix to lower case name starts with prefix wipeable files if f delete f exists system err println unable to delete temporary file f permissions problem else wiped files long end wipe system current time millis system err println deleted wiped files of wipeable files temporary files filenames length wipeable files non temp files in temp directory in time util format time end wipe start wipe wipefiles ioexception filenamegenerator wipefiles ioexception tmpdir fileutil getcanonicalfile getproperty tmpdir fileutil getcanonicalfile tmpdir tmpdir tmpdir isdirectory tmpdir canread tmpdir canwrite ioexception tmpdir wipefiles wipedfiles wipeablefiles startwipe currenttimemillis tmpdir listfiles wrappermanager signalstarting wipedfiles wipeablefiles getname separatorchar tolowercase startswith tolowercase startswith wipeablefiles wipedfiles endwipe currenttimemillis wipedfiles wipeablefiles wipeablefiles timeutil formattime endwipe startwipe public long make random filename long random filename should be plenty while true random filename random next long if random filename 1 continue disallowed as used for error reporting string filename prefix long to hex string random filename file ret new file tmp dir filename if ret exists if logger should log logger minor this logger minor this made random filename ret new exception debug return random filename makerandomfilename randomfilename randomfilename nextlong randomfilename tohexstring randomfilename tmpdir shouldlog randomfilename public file get filename long id return new file tmp dir prefix long to hex string id getfilename tmpdir tohexstring public file make random file throws io exception while true file file get filename make random filename if file create new file return file makerandomfile ioexception getfilename makerandomfilename createnewfile public boolean matches file file return getid file 1 public long getid file file if file util get canonical file file get parent file equals tmp dir logger error this not the same dir parent file util get canonical file file get parent file but tmp dir tmp dir return 1 string name file get name if name starts with prefix logger error this does not start with prefix name prefix prefix return 1 try return fields hex to long name substring prefix length catch number format exception e logger error this cannot getid e from name substring prefix length e return 1 fileutil getcanonicalfile getparentfile tmpdir fileutil getcanonicalfile getparentfile tmpdir tmpdir getname startswith hextolong numberformatexception public file get dir return tmp dir getdir tmpdir set up the dir and prefix note that while we can change the dir and prefix we cannot do so online at least not on windows param dir param prefix public void init file dir string prefix random random throws io exception this random random there is a problem with putting file s into db4o iirc i think we workaround this somewhere else symptoms are it trying to move even though the two dirs are blatantly identical file old dir file util get canonical file new file tmp dir get path file new dir file util get canonical file dir system err println old old dir prefix this prefix from tmp dir old path tmp dir get path old parent tmp dir get parent system err println new new dir prefix prefix from dir if old dir equals new dir this prefix equals prefix logger normal this initialised filename generator successfully no change in dir and prefix dir dir prefix prefix else if old dir equals new dir this prefix equals prefix if dir exists old dir rename to dir tmp dir dir this will interest the user since they changed it string msg successfully renamed persistent temporary directory from tmp dir to dir logger error this msg system err println msg else if dir exists if dir mkdir fixme localise these errors somehow system err println unable to create new temporary directory dir throw new io exception unable to create new temporary directory dir if dir can read dir can write fixme localise these errors somehow system err println unable to read and write new temporary directory dir throw new io exception unable to read and write new temporary directory dir int moved 0 int failed 0 move each file file list tmp dir list files for int i 0 i list length i file f list i string name f get name if name starts with prefix continue if file util move to f new file dir name true moved else failed if failed 0 fixme maybe a useralert system err println warning not all files successfully moved changing temp dir failed failed system err println warning some persistent downloads etc may fail else if dir exists if dir mkdir fixme localise these errors somehow system err println unable to create new temporary directory dir throw new io exception unable to create new temporary directory dir if dir can read dir can write fixme localise these errors somehow system err println unable to read and write new temporary directory dir throw new io exception unable to read and write new temporary directory dir int moved 0 int failed 0 move each file file list tmp dir list files for int i 0 i list length i file f list i string name f get name if name starts with this prefix continue string new name prefix name substring this prefix length if file util move to f new file dir new name true moved if failed 0 fixme maybe a useralert system err println warning not all files successfully moved changing temp dir failed failed system err println warning some persistent downloads etc may fail ioexception olddir fileutil getcanonicalfile tmpdir getpath newdir fileutil getcanonicalfile olddir tmpdir tmpdir getpath tmpdir getparent newdir olddir newdir filenamegenerator olddir newdir olddir renameto tmpdir tmpdir ioexception canread canwrite ioexception tmpdir listfiles getname startswith fileutil moveto ioexception canread canwrite ioexception tmpdir listfiles getname startswith newname fileutil moveto newname param bucket size param bf param db job runner if not null use this to store buckets to disk progressively to avoid a big transaction at the end caller then must call store to at some point public bucket chain bucket long bucket size bucket factory bf this bucket size bucket size this buckets new vector bucket this bf bf size 0 freed false read only false bucketsize dbjobrunner storeto bucketchainbucket bucketsize bucketfactory bucketsize bucketsize readonly private bucket chain bucket vector bucket new buckets long bucket size2 long size2 boolean read only bucket factory bf2 this buckets new buckets this bucket size bucket size2 this size size2 this read only read only this bf bf2 bucketchainbucket newbuckets bucketsize2 readonly bucketfactory newbuckets bucketsize bucketsize2 readonly readonly public void free bucket list synchronized this list get buckets freed true buckets clear for int i 0 i list length i list i free getbuckets equivalent to free but don t free the underlying buckets void clear synchronized this size 0 buckets clear public synchronized bucket get buckets return buckets to array new bucket buckets size getbuckets toarray public input stream get input stream throws io exception synchronized this if freed throw new io exception freed if buckets size 0 return new null input stream return new input stream private int bucket no 0 private input stream cur bucket stream get bucket input stream 0 private long read bytes override public int read throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed while true if cur bucket stream null cur bucket stream get bucket input stream 0 if cur bucket stream null return 1 try int x cur bucket stream read if x 0 read bytes return x catch eof exception e handle the same synchronized bucket chain bucket this no more data to read at the moment if read bytes size return 1 bucket no cur bucket stream close cur bucket stream get bucket input stream bucket no override public int read byte buf throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed return read buf 0 buf length override public int read byte buf int offset int length throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if length 0 return 0 while true if cur bucket stream null cur bucket stream get bucket input stream 0 if cur bucket stream null return 1 try int x cur bucket stream read buf offset length if x 0 read bytes x return x catch eof exception e handle the same synchronized bucket chain bucket this no more data to read at the moment if read bytes size return 1 bucket no cur bucket stream close cur bucket stream get bucket input stream bucket no override public int available throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed return int math min integer max value size read bytes override public void close throws io exception if cur bucket stream null cur bucket stream close inputstream getinputstream ioexception ioexception nullinputstream inputstream bucketno inputstream curbucketstream getbucketinputstream readbytes ioexception bucketchainbucket curbucketstream curbucketstream ioexception curbucketstream curbucketstream getbucketinputstream curbucketstream curbucketstream readbytes eofexception bucketchainbucket readbytes bucketno curbucketstream curbucketstream getbucketinputstream bucketno ioexception bucketchainbucket curbucketstream curbucketstream ioexception ioexception bucketchainbucket curbucketstream curbucketstream ioexception curbucketstream curbucketstream getbucketinputstream curbucketstream curbucketstream readbytes eofexception bucketchainbucket readbytes bucketno curbucketstream curbucketstream getbucketinputstream bucketno ioexception bucketchainbucket curbucketstream curbucketstream ioexception max_value readbytes ioexception curbucketstream curbucketstream override public int read throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed while true if cur bucket stream null cur bucket stream get bucket input stream 0 if cur bucket stream null return 1 try int x cur bucket stream read if x 0 read bytes return x catch eof exception e handle the same synchronized bucket chain bucket this no more data to read at the moment if read bytes size return 1 bucket no cur bucket stream close cur bucket stream get bucket input stream bucket no ioexception bucketchainbucket curbucketstream curbucketstream ioexception curbucketstream curbucketstream getbucketinputstream curbucketstream curbucketstream readbytes eofexception bucketchainbucket readbytes bucketno curbucketstream curbucketstream getbucketinputstream bucketno override public int read byte buf throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed return read buf 0 buf length ioexception bucketchainbucket curbucketstream curbucketstream ioexception override public int read byte buf int offset int length throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if length 0 return 0 while true if cur bucket stream null cur bucket stream get bucket input stream 0 if cur bucket stream null return 1 try int x cur bucket stream read buf offset length if x 0 read bytes x return x catch eof exception e handle the same synchronized bucket chain bucket this no more data to read at the moment if read bytes size return 1 bucket no cur bucket stream close cur bucket stream get bucket input stream bucket no ioexception bucketchainbucket curbucketstream curbucketstream ioexception curbucketstream curbucketstream getbucketinputstream curbucketstream curbucketstream readbytes eofexception bucketchainbucket readbytes bucketno curbucketstream curbucketstream getbucketinputstream bucketno override public int available throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed return int math min integer max value size read bytes ioexception bucketchainbucket curbucketstream curbucketstream ioexception max_value readbytes override public void close throws io exception if cur bucket stream null cur bucket stream close ioexception curbucketstream curbucketstream protected synchronized input stream get bucket input stream int i throws io exception bucket bucket buckets get i if bucket null return null return bucket get input stream inputstream getbucketinputstream ioexception getinputstream public string get name return bucket chain bucket getname bucketchainbucket public output stream get output stream throws io exception bucket list synchronized this if read only throw new io exception read only if freed throw new io exception freed size 0 list get buckets buckets clear for int i 0 i list length i list i free return new output stream private int bucket no 0 private output stream cur bucket stream make bucket output stream 0 private long bucket length 0 override public void write int c throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if read only cur bucket stream close cur bucket stream null throw new io exception read only if bucket length bucket size cur bucket stream close cur bucket stream make bucket output stream bucket no bucket length 0 cur bucket stream write c bucket length synchronized bucket chain bucket this size override public void write byte buf throws io exception write buf 0 buf length override public void write byte buf int offset int length throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if read only cur bucket stream close cur bucket stream null throw new io exception read only if length 0 return if bucket length bucket size cur bucket stream close cur bucket stream make bucket output stream bucket no bucket length 0 if bucket length length bucket size int split int bucket size bucket length write buf offset split write buf offset split length split return cur bucket stream write buf offset length bucket length length synchronized bucket chain bucket this size length override public void close throws io exception if cur bucket stream null cur bucket stream close outputstream getoutputstream ioexception readonly ioexception ioexception getbuckets outputstream bucketno outputstream curbucketstream makebucketoutputstream bucketlength ioexception bucketchainbucket curbucketstream curbucketstream ioexception readonly curbucketstream curbucketstream ioexception bucketlength bucketsize curbucketstream curbucketstream makebucketoutputstream bucketno bucketlength curbucketstream bucketlength bucketchainbucket ioexception ioexception bucketchainbucket curbucketstream curbucketstream ioexception readonly curbucketstream curbucketstream ioexception bucketlength bucketsize curbucketstream curbucketstream makebucketoutputstream bucketno bucketlength bucketlength bucketsize bucketsize bucketlength curbucketstream bucketlength bucketchainbucket ioexception curbucketstream curbucketstream override public void write int c throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if read only cur bucket stream close cur bucket stream null throw new io exception read only if bucket length bucket size cur bucket stream close cur bucket stream make bucket output stream bucket no bucket length 0 cur bucket stream write c bucket length synchronized bucket chain bucket this size ioexception bucketchainbucket curbucketstream curbucketstream ioexception readonly curbucketstream curbucketstream ioexception bucketlength bucketsize curbucketstream curbucketstream makebucketoutputstream bucketno bucketlength curbucketstream bucketlength bucketchainbucket override public void write byte buf throws io exception write buf 0 buf length ioexception override public void write byte buf int offset int length throws io exception synchronized bucket chain bucket this if freed cur bucket stream close cur bucket stream null throw new io exception freed if read only cur bucket stream close cur bucket stream null throw new io exception read only if length 0 return if bucket length bucket size cur bucket stream close cur bucket stream make bucket output stream bucket no bucket length 0 if bucket length length bucket size int split int bucket size bucket length write buf offset split write buf offset split length split return cur bucket stream write buf offset length bucket length length synchronized bucket chain bucket this size length ioexception bucketchainbucket curbucketstream curbucketstream ioexception readonly curbucketstream curbucketstream ioexception bucketlength bucketsize curbucketstream curbucketstream makebucketoutputstream bucketno bucketlength bucketlength bucketsize bucketsize bucketlength curbucketstream bucketlength bucketchainbucket override public void close throws io exception if cur bucket stream null cur bucket stream close ioexception curbucketstream curbucketstream protected output stream make bucket output stream int i throws io exception bucket bucket synchronized this bucket bf make bucket bucket size buckets add bucket if buckets size i 1 throw new illegal state exception added bucket size should be i 1 but is buckets size if buckets get i bucket throw new illegal state exception bucket got replaced race condition return bucket get output stream outputstream makebucketoutputstream ioexception makebucket bucketsize illegalstateexception illegalstateexception getoutputstream public boolean is read only return read only isreadonly readonly public void set read only read only true setreadonly readonly public long size return size public void store to object container container throw new unsupported operation exception storeto objectcontainer unsupportedoperationexception public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public bucket create shadow throws io exception vector bucket new buckets new vector bucket for int i 0 i buckets size i bucket data buckets get i bucket shadow data create shadow if shadow null for bucket bucket new buckets bucket free return null new buckets add shadow return new bucket chain bucket new buckets bucket size size true bf createshadow ioexception newbuckets createshadow newbuckets newbuckets bucketchainbucket newbuckets bucketsize public class bytes public static short unpack2 byte arr int offs return short arr offs 8 arr offs 1 0xff return short arr offs 8 arr offs 1 0xff public static int unpack4 byte arr int offs return arr offs 24 arr offs 1 0xff 16 arr offs 2 0xff 8 arr offs 3 0xff arr offs 2 0xff 8 arr offs 3 0xff public static long unpack8 byte arr int offs return long unpack4 arr offs 32 unpack4 arr offs 4 0xffffffffl unpack4 arr offs 4 0xffffffffl public static float unpackf4 byte arr int offs return float int bits to float bytes unpack4 arr offs intbitstofloat return float int bits to float bytes unpack4 arr offs public static double unpackf8 byte arr int offs return double long bits to double bytes unpack8 arr offs intbitstofloat longbitstodouble public static string unpack str byte arr int offs string encoding int len unpack4 arr offs offs 4 if len 0 char chars new char len for int i 0 i len i chars i char unpack2 arr offs offs 2 return new string chars else if len 1 if encoding null try return new string arr offs len 2 encoding catch unsupported encoding exception x throw new storage error storage error unsupported encoding else return new string arr offs len 2 return null unpackstr unsupportedencodingexception storageerror storageerror unsupported_encoding public static void pack2 byte arr int offs short val arr offs byte val 8 arr offs 1 byte val public static void pack4 byte arr int offs int val arr offs byte val 24 arr offs 1 byte val 16 arr offs 2 byte val 8 arr offs 3 byte val arr offs 3 byte val public static void pack8 byte arr int offs long val pack4 arr offs int val 32 pack4 arr offs 4 int val pack4 arr offs 4 int val public static void packf4 byte arr int offs float val pack4 arr offs float float to int bits val floattointbits pack4 arr offs float float to int bits val public static void packf8 byte arr int offs double val pack8 arr offs double double to long bits val floattointbits doubletolongbits public static int pack str byte arr int offs string str string encoding if str null bytes pack4 arr offs 1 offs 4 else if encoding null int n str length bytes pack4 arr offs n offs 4 for int i 0 i n i bytes pack2 arr offs short str char at i offs 2 else try byte bytes str get bytes encoding pack4 arr offs 2 bytes length system arraycopy bytes 0 arr offs 4 bytes length offs 4 bytes length catch unsupported encoding exception x throw new storage error storage error unsupported encoding return offs packstr charat getbytes unsupportedencodingexception storageerror storageerror unsupported_encoding public static int sizeof string str string encoding try return str null 4 encoding null 4 str length 2 4 new string str get bytes encoding length catch unsupported encoding exception x throw new storage error storage error unsupported encoding getbytes unsupportedencodingexception storageerror storageerror unsupported_encoding public static int sizeof byte arr int offs int len unpack4 arr offs if len 0 return 4 len 2 else if len 1 return 4 2 len else return 4 public http server thread http server http server socket sock this http server http server this sock sock this set daemon true httpserverthread httpserver httpserver httpserver httpserver setdaemon public void run http socket http sock new http socket sock if http sock open false return http request http req new http request http req set socket http sock while http req read true http server perform request listener http req if http req is keep alive false break http sock close httpsocket httpsock httpsocket httpsock httprequest httpreq httprequest httpreq setsocket httpsock httpreq httpserver performrequestlistener httpreq httpreq iskeepalive httpsock construct a perspective filter public perspective filter this 0 0 100 0 100 100 0 100 perspectivefilter perspectivefilter construct a perspective filter param x0 the new position of the top left corner param y0 the new position of the top left corner param x1 the new position of the top right corner param y1 the new position of the top right corner param x2 the new position of the bottom right corner param y2 the new position of the bottom right corner param x3 the new position of the bottom left corner param y3 the new position of the bottom left corner public perspective filter float x0 float y0 float x1 float y1 float x2 float y2 float x3 float y3 set corners x0 y0 x1 y1 x2 y2 x3 y3 perspectivefilter perspectivefilter setcorners set the new positions of the image corners param x0 the new position of the top left corner param y0 the new position of the top left corner param x1 the new position of the top right corner param y1 the new position of the top right corner param x2 the new position of the bottom right corner param y2 the new position of the bottom right corner param x3 the new position of the bottom left corner param y3 the new position of the bottom left corner public void set corners float x0 float y0 float x1 float y1 float x2 float y2 float x3 float y3 this x0 x0 this y0 y0 this x1 x1 this y1 y1 this x2 x2 this y2 y2 this x3 x3 this y3 y3 dx1 x1 x2 dy1 y1 y2 dx2 x3 x2 dy2 y3 y2 dx3 x0 x1 x2 x3 dy3 y0 y1 y2 y3 float a11 a12 a13 a21 a22 a23 a31 a32 if dx3 0 dy3 0 a11 x1 x0 a21 x2 x1 a31 x0 a12 y1 y0 a22 y2 y1 a32 y0 a13 a23 0 else a13 dx3 dy2 dx2 dy3 dx1 dy2 dy1 dx2 a23 dx1 dy3 dy1 dx3 dx1 dy2 dy1 dx2 a11 x1 x0 a13 x1 a21 x3 x0 a23 x3 a31 x0 a12 y1 y0 a13 y1 a22 y3 y0 a23 y3 a32 y0 a a22 a32 a23 b a31 a23 a21 c a21 a32 a31 a22 d a32 a13 a12 e a11 a31 a13 f a31 a12 a11 a32 g a12 a23 a22 a13 h a21 a13 a11 a23 i a11 a22 a21 a12 setcorners override protected void transform space rectangle rect rect x int math min math min x0 x1 math min x2 x3 rect y int math min math min y0 y1 math min y2 y3 rect width int math max math max x0 x1 math max x2 x3 rect x rect height int math max math max y0 y1 math max y2 y3 rect y transformspace get the origin of the output image use this for working out where to draw your new image return the x origin public float get originx return x0 int math min math min x0 x1 math min x2 x3 getoriginx get the origin of the output image use this for working out where to draw your new image return the y origin public float get originy return y0 int math min math min y0 y1 math min y2 y3 getoriginy override protected void transform inverse int x int y float out out 0 original space width a x b y c g x h y i out 1 original space height d x e y f g x h y i transforminverse originalspace originalspace override public string to string return distort perspective tostring private final own identity m identity public delete own identity page web interface my web interface http request my request throws unknown identity exception super my web interface my request m identity wot get own identity byid request get part as string id 128 ownidentity midentity deleteownidentitypage webinterface mywebinterface httprequest myrequest unknownidentityexception mywebinterface myrequest midentity getownidentitybyid getpartasstring public void make if request is part set confirm wot delete identity m identity fixme show the own identities page instead use the trick which freetalk does for inlining pages html node box add content box success box add child the identity was deleted else make confirmation ispartset deleteidentity midentity ownidentities htmlnode addcontentbox addchild makeconfirmation private void make confirmation html node box add content box confirm identity deletion box add child new html node p you are about to delete identity m identity get nickname are you sure box add child new html node p you might want to backup its keys for later use html node confirm form pr add form child box uri delete identity confirm form add child input new string type name value new string hidden page delete identity confirm form add child input new string type name value new string hidden id m identity getid confirm form add child input new string type name value new string submit confirm i am sure delete it makeconfirmation htmlnode addcontentbox addchild htmlnode midentity getnickname addchild htmlnode htmlnode confirmform addformchild deleteidentity confirmform addchild deleteidentity confirmform addchild midentity confirmform addchild public message manager ext object container mydb executor my executor identity manager my identity manager assert mydb null assert my identity manager null db mydb m executor my executor m identity manager my identity manager messagemanager extobjectcontainer myexecutor identitymanager myidentitymanager myidentitymanager mexecutor myexecutor midentitymanager myidentitymanager for being used in j unit tests to run without a node public message manager ext object container mydb identity manager my identity manager db mydb m executor null m identity manager my identity manager junit messagemanager extobjectcontainer identitymanager myidentitymanager mexecutor midentitymanager myidentitymanager this is the primary function for posting messages param my parent message the message to which the new message is a reply null if the message should be a thread param my boards the boards to which the new message should be posted has to contain at least one board param my reply to board the board to which replies to this message should be sent this is just a recommendation notice that it should be contained in my boards can be null param my author the author of the new message cannot be null param my title the subject of the new message cannot be null or empty param my date the utc time of the message null to use the current time param my text the body of the new message cannot be null param my attachments the attachments of the new message see code message attachment code set to null if the message has none return the new message throws invalid parameter exception invalid board names invalid title invalid body throws exception public abstract own message post message message my parent message set board my boards board my reply to board ft own identity my author myparentmessage myboards myreplytoboard myboards myauthor mytitle mydate mytext myattachments invalidparameterexception ownmessage postmessage myparentmessage myboards myreplytoboard ftownidentity myauthor public synchronized own message post message message my parent message set string my boards string my reply to board ft own identity my author string my title date my date string my text list attachment my attachments throws exception fixme instead of always creating the boards notify the user that they do not exist and ask if he made a typo hash set board board set new hash set board for iterator string i my boards iterator i has next string board name i next board board get or create board board name board set add board board reply to board null if my reply to board null reply to board get or create board my reply to board return post message my parent message board set reply to board my author my title my date my text my attachments ownmessage postmessage myparentmessage myboards myreplytoboard ftownidentity myauthor mytitle mydate mytext myattachments hashset boardset hashset myboards hasnext boardname getorcreateboard boardname boardset replytoboard myreplytoboard replytoboard getorcreateboard myreplytoboard postmessage myparentmessage boardset replytoboard myauthor mytitle mydate mytext myattachments suppress warnings unchecked public synchronized int count unsent messages fixme this is not fully synchronized message inserter calls own message was inserted to mark a message as inserted and that function synchronizes on the own message object query q db query q constrain own message class q descend m realuri constrain null identity int unsent count q execute size q db query q constrain own message list class q descend i was inserted constrain false object set own message list not inserted lists q execute for own message list list not inserted lists unsent count list get message count return unsent count suppresswarnings countunsentmessages messageinserter ownmessage wasinserted ownmessage ownmessage mrealuri unsentcount ownmessagelist iwasinserted objectset ownmessagelist notinsertedlists ownmessagelist notinsertedlists unsentcount getmessagecount unsentcount public synchronized void on message received message message try get message getid logger debug this downloaded a message which we already have message geturi catch no such message exception e try message initialize transient db this message store for board board message get boards board add message message for message reference ref get all references to message message getid ref set message was downloaded flag catch exception ex fixme delete the message if this happens logger error this exception while storing a downloaded message ex onmessagereceived nosuchmessageexception initializetransient getboards addmessage messagereference getallreferencestomessage setmessagewasdownloadedflag public synchronized void on message list received message list list try get message list list getid logger debug this downloaded a message list which we already have list geturi catch no such message list exception e list initialize transient db this list store onmessagelistreceived messagelist getmessagelist messagelist nosuchmessagelistexception initializetransient abstract because we need to store an object of a child class of message list which is chosen dependent on which implementation of the messging system we are using messagelist public synchronized void on message fetch failed message reference message reference message list message fetch failed reference reason reason if reason message list message fetch failed reference reason data not found todo handle dnf in some reasonable way mark the messages as unavailable after a certain amount of retries maybe return try get message reference get messageid logger debug this trying to mark a message as downlod failed which we actually have message reference geturi catch no such message exception e try message list message fetch failed reference failed marker new message list message fetch failed reference message reference reason failed marker initialize transient db failed marker store for message reference r get all references to message message reference get messageid r set message was downloaded flag logger debug this marked message as download failed with reason reason message reference geturi catch exception ex logger error this exception while marking a not downloadable messge ex onmessagefetchfailed messagereference messagereference messagelist messagefetchfailedreference messagelist messagefetchfailedreference datanotfound messagereference getmessageid messagereference nosuchmessageexception messagelist messagefetchfailedreference failedmarker messagelist messagefetchfailedreference messagereference failedmarker initializetransient failedmarker messagereference getallreferencestomessage messagereference getmessageid setmessagewasdownloadedflag messagereference get a list of all message reference objects to the given message id references to own message are not returned used to mark the references to a message which was downloaded as downloaded private iterable message list message reference get all references to message final string id return new iterable message list message reference suppress warnings unchecked public iterator message list message reference iterator return new iterator message list message reference private iterator message list message reference iter query query db query query constrain message list message reference class query constrain own message list own message reference class not query descend m messageid constrain id fixme this function should only return message references which are for a board which an own identity wants to read and from as specified above this has to be implemented yet fixme order the message references randomly with some trick iter query execute iterator public boolean has next return iter has next public message list message reference next message list message reference next iter next next initialize transient db return next public void remove throw new unsupported operation exception messagereference ownmessage messagelist messagereference getallreferencestomessage messagelist messagereference suppresswarnings messagelist messagereference messagelist messagereference messagelist messagereference messagelist messagereference ownmessagelist ownmessagereference mmessageid messagereferences ownidentity hasnext hasnext messagelist messagereference messagelist messagereference initializetransient unsupportedoperationexception return new iterable message list message reference suppress warnings unchecked public iterator message list message reference iterator return new iterator message list message reference private iterator message list message reference iter query query db query query constrain message list message reference class query constrain own message list own message reference class not query descend m messageid constrain id fixme this function should only return message references which are for a board which an own identity wants to read and from as specified above this has to be implemented yet fixme order the message references randomly with some trick iter query execute iterator public boolean has next return iter has next public message list message reference next message list message reference next iter next next initialize transient db return next public void remove throw new unsupported operation exception messagelist messagereference suppresswarnings messagelist messagereference messagelist messagereference messagelist messagereference messagelist messagereference ownmessagelist ownmessagereference mmessageid messagereferences ownidentity hasnext hasnext messagelist messagereference messagelist messagereference initializetransient unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public message list message reference next message list message reference next iter next next initialize transient db return next messagelist messagereference messagelist messagereference initializetransient public void remove throw new unsupported operation exception unsupportedoperationexception get a message by its uri the transient fields of the returned message will be initialized already this will not return own message objects your own messages will be returned by this function as soon as they have been downloaded throws no such message exception public message get freeneturi uri throws no such message exception return get message getid fromuri uri throw new unsupported operation exception getting a message by it s uri is inefficient compared to getting by id please only repair this function if absolutely unavoidable ownmessage nosuchmessageexception nosuchmessageexception getidfromuri unsupportedoperationexception get a message by its id the transient fields of the returned message will be initialized already this will not return own message objects your own messages will be returned by this function as soon as they have been downloaded as if they were normal messages of someone else throws no such message exception suppress warnings unchecked public synchronized message get string id throws no such message exception query query db query query constrain message class query constrain own message class not query descend mid constrain id object set message result query execute if result size 1 throw new duplicate message exception if result size 0 throw new no such message exception id message m result next m initialize transient db this return m ownmessage nosuchmessageexception suppresswarnings nosuchmessageexception ownmessage objectset duplicatemessageexception nosuchmessageexception initializetransient get a code message list code by its id the transient fields of the returned code message list code will be initialized already this will not return code own message list code objects your own message lists will be returned by this function as soon as they have been downloaded as if they were normal message lists of someone else throws no such message list exception suppress warnings unchecked public synchronized message list get message list string id throws no such message list exception query query db query query constrain message list class query constrain own message list class not query descend mid constrain id object set message list result query execute if result size 1 throw new duplicate message list exception if result size 0 throw new no such message list exception id message list list result next list initialize transient db this return list messagelist messagelist ownmessagelist nosuchmessagelistexception suppresswarnings messagelist getmessagelist nosuchmessagelistexception messagelist ownmessagelist objectset messagelist duplicatemessagelistexception nosuchmessagelistexception messagelist initializetransient suppress warnings unchecked public synchronized own message list get own message list string id throws no such message list exception query query db query query constrain own message list class query descend mid constrain id object set own message list result query execute if result size 1 throw new duplicate message list exception if result size 0 throw new no such message list exception id own message list list result next list initialize transient db this return list suppresswarnings ownmessagelist getownmessagelist nosuchmessagelistexception ownmessagelist objectset ownmessagelist duplicatemessagelistexception nosuchmessagelistexception ownmessagelist initializetransient public own message get own message freeneturi uri throws no such message exception return get own message message getid fromuri uri throw new unsupported operation exception getting a message by it s uri is inefficient compared to getting by id please only repair this function if absolutely unavoidable ownmessage getownmessage nosuchmessageexception getownmessage getidfromuri unsupportedoperationexception suppress warnings unchecked public synchronized own message get own message string id throws no such message exception query query db query query constrain own message class query descend mid constrain id object set own message result query execute if result size 1 throw new duplicate message exception if result size 0 throw new no such message exception id own message m result next m initialize transient db this return m suppresswarnings ownmessage getownmessage nosuchmessageexception ownmessage objectset ownmessage duplicatemessageexception nosuchmessageexception ownmessage initializetransient get a board by its name the transient fields of the returned board will be initialized already throws no such board exception suppress warnings unchecked public synchronized board get board by name string name throws no such board exception name name to lower case query query db query query constrain board class query descend m name constrain name object set board result query execute if result size 1 throw new duplicate board exception if result size 0 throw new no such board exception name board b result next b initialize transient db this return b nosuchboardexception suppresswarnings getboardbyname nosuchboardexception tolowercase mname objectset duplicateboardexception nosuchboardexception initializetransient public synchronized board get or create board string name throws invalid parameter exception name name to lower case board board try board get board by name name catch no such board exception e board new board name board initialize transient db this board store return board getorcreateboard invalidparameterexception tolowercase getboardbyname nosuchboardexception initializetransient for a database query of result type code object set board code this function provides an iterator the iterator of the object set cannot be used instead because it will not call initialize transient on the boards the iterator which is returned by this function takes care of that please synchronize on the code message manager code when using this function it is not synchronized itself suppress warnings unchecked protected iterator board general board iterator final query q return new iterator board private iterator board iter q execute iterator public boolean has next return iter has next public board next board next iter next next initialize transient db self return next public void remove throw new unsupported operation exception boards cannot be deleted yet objectset objectset initializetransient messagemanager suppresswarnings generalboarditerator hasnext hasnext initializetransient unsupportedoperationexception get an iterator of all boards the transient fields of the returned boards will be initialized already public synchronized iterator board board iterator fixme accelerate this query db4o should be configured to keep an alphabetic index of boards query query db query query constrain board class query descend m name order descending return general board iterator query boarditerator mname orderdescending generalboarditerator get an iterator of boards which were first seen after the given date sorted ascending by the date they were first seen at public synchronized iterator board board iterator sorted by date final date seen after query query db query query constrain board class query descend m first seen date constrain seen after greater query descend m first seen date order ascending return general board iterator query boarditeratorsortedbydate seenafter mfirstseendate seenafter mfirstseendate orderascending generalboarditerator get the next index of which a message from the selected identity is not stored public int get unavailable message index ft identity message author query q db query q constrain message class q constrain own message class not we also download our own message this helps the user to spot problems if he does not see his own messages we can hope that he reports a bug q descend m author constrain message author q descend m index order descending fixme write a native db4o query which just looks for the maximum object set message result q execute return result size 0 result next get index 1 0 suppress warnings unchecked public synchronized iterator own message not inserted message iterator return new iterator own message private iterator own message iter query query db query query constrain own message class query descend m realuri constrain null identity iter query execute iterator public boolean has next return iter has next public own message next own message next iter next next initialize transient db self return next public void remove throw new unsupported operation exception getunavailablemessageindex ftidentity messageauthor ownmessage mauthor messageauthor mindex orderdescending objectset getindex suppresswarnings ownmessage notinsertedmessageiterator ownmessage ownmessage ownmessage mrealuri hasnext hasnext ownmessage ownmessage initializetransient unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public own message next own message next iter next next initialize transient db self return next ownmessage ownmessage initializetransient public void remove throw new unsupported operation exception unsupportedoperationexception get a list of not downloaded messages this function only returns messages which are posted to a board which an own identity wants to receive messages from however it might also return messages which are from an author which nobody wants to receive messages from filtering out unwanted authors is done at message list level message lists are only downloaded from identities which we want to read messages from suppress warnings unchecked public synchronized iterator message list message reference not downloaded message iterator return new iterator message list message reference private iterator message list message reference iter query query db query query constrain message list message reference class query constrain own message list own message reference class not query descend i was downloaded constrain false fixme this function should only return message references which are for a board which an own identity wants to read and from as specified above this has to be implemented yet fixme order the message references randomly with some trick iter query execute iterator public boolean has next return iter has next public message list message reference next message list message reference next iter next next initialize transient db return next public void remove throw new unsupported operation exception ownidentity messagelist messagelists suppresswarnings messagelist messagereference notdownloadedmessageiterator messagelist messagereference messagelist messagereference messagelist messagereference ownmessagelist ownmessagereference iwasdownloaded messagereferences ownidentity hasnext hasnext messagelist messagereference messagelist messagereference initializetransient unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public message list message reference next message list message reference next iter next next initialize transient db return next messagelist messagereference messagelist messagereference initializetransient public void remove throw new unsupported operation exception unsupportedoperationexception returns true if the message was not downloaded yet and any of the ft own identity wants the message protected synchronized boolean should download message freeneturi uri ft identity author try get uri return false catch no such message exception e return m identity manager any own identity wants messages from author ftownidentity shoulddownloadmessage ftidentity nosuchmessageexception midentitymanager anyownidentitywantsmessagesfrom public abstract void terminate public identity manager get identity manager return m identity manager identitymanager getidentitymanager midentitymanager private boolean logminor logger should log logger minor this index writer shouldlog indexwriter public synchronized void make index perst root perst root throws exception logminor logger should log logger minor this try time taken system current time millis config config perst root get config file index dir new file config get index dir if index dir exists index dir mkdirs index dir exists index dir is directory logger error this cannot create index directory index dir return if logminor logger minor this spider regenerating index max size config get index subindex max size max entries config get index max entries make sub indices perst root make main index config time taken system current time millis time taken if logminor logger minor this spider indexes regenerated t produced index system current time millis t produced index ms ago time taken time taken ms t produced index system current time millis finally makeindex perstroot perstroot shouldlog time_taken currenttimemillis perstroot getconfig indexdir getindexdir indexdir indexdir indexdir indexdir isdirectory indexdir max_size getindexsubindexmaxsize max_entries getindexmaxentries makesubindices perstroot makemainindex time_taken currenttimemillis time_taken tproducedindex currenttimemillis tproducedindex time_taken tproducedindex currenttimemillis generates the main index file that can be used by librarian for searching in the list of subindices param void author swati throws io exception throws no such algorithm exception private void make main index config config throws io exception no such algorithm exception produce the main index file if logminor logger minor this producing top index the main index file file output file new file config get index dir index xml use a stream so we can explicitly close minimise number of filehandles used buffered output stream fos new buffered output stream new file output stream output file stream result result stream result stream new stream result fos try initialize xml builder document xml doc null document builder factory xml factory null document builder xml builder null dom implementation impl null element root element null xml factory document builder factory new instance try xml builder xml factory new document builder catch javax xml parsers parser configuration exception e logger error this spider error while initializing xml generator e to string e return impl xml builder getdom implementation starting to generate index xml doc impl create document null main index null root element xml doc get document element adding header to the index element header element xml doc create elementns null header title element sub header element xml doc create elementns null title text sub header text xml doc create text node config get index title sub header element append child sub header text header element append child sub header element owner sub header element xml doc create elementns null owner sub header text xml doc create text node config get index owner sub header element append child sub header text header element append child sub header element owner email if config get index owner email null sub header element xml doc create elementns null email sub header text xml doc create text node config get index owner email sub header element append child sub header text header element append child sub header element the max number of digits in md5 to be used for matching with the search query is stored in the xml element prefix element xml doc create elementns null prefix adding word index element keywords element xml doc create elementns null keywords for int i 0 i indices size i element sub index element xml doc create elementns null sub index sub index element set attributens null key indices element at i the subindex element key will contain the bits used for matching in that subindex keywords element append child sub index element prefix element set attributens null value match root element append child prefix element root element append child header element root element append child keywords element serialization dom source dom source new dom source xml doc transformer factory transform factory transformer factory new instance transformer serializer try serializer transform factory new transformer catch javax xml transform transformer configuration exception e logger error this spider error while serializing xml transform factory new transformer e to string e return serializer set output property output keys encoding utf 8 serializer set output property output keys indent yes final step try serializer transform dom source result stream catch javax xml transform transformer exception e logger error this spider error while serializing xml transform e to string e return finally fos close the main xml file is generated as each word is generated enter it into the respective subindex the parsing will start and nodes will be added as needed ioexception nosuchalgorithmexception makemainindex ioexception nosuchalgorithmexception outputfile getindexdir bufferedoutputstream bufferedoutputstream fileoutputstream outputfile streamresult resultstream resultstream streamresult xmldoc documentbuilderfactory xmlfactory documentbuilder xmlbuilder domimplementation rootelement xmlfactory documentbuilderfactory newinstance xmlbuilder xmlfactory newdocumentbuilder parserconfigurationexception tostring xmlbuilder getdomimplementation xmldoc createdocument main_index rootelement xmldoc getdocumentelement headerelement xmldoc createelementns subheaderelement xmldoc createelementns subheadertext xmldoc createtextnode getindextitle subheaderelement appendchild subheadertext headerelement appendchild subheaderelement subheaderelement xmldoc createelementns subheadertext xmldoc createtextnode getindexowner subheaderelement appendchild subheadertext headerelement appendchild subheaderelement getindexowneremail subheaderelement xmldoc createelementns subheadertext xmldoc createtextnode getindexowneremail subheaderelement appendchild subheadertext headerelement appendchild subheaderelement prefixelement xmldoc createelementns keywordselement xmldoc createelementns subindexelement xmldoc createelementns subindex subindexelement setattributens elementat keywordselement appendchild subindexelement prefixelement setattributens rootelement appendchild prefixelement rootelement appendchild headerelement rootelement appendchild keywordselement domsource domsource domsource xmldoc transformerfactory transformfactory transformerfactory newinstance transformfactory newtransformer transformerconfigurationexception transformfactory newtransformer tostring setoutputproperty outputkeys setoutputproperty outputkeys domsource resultstream transformerexception tostring generates the subindices each index has less than code max entries words the original treemap is split into several sublists indexed by the common substring of the hash code of the words throws exception private void make sub indices perst root perst root throws exception logger normal this generating index indices new vector string match 1 for string hex hex generate sub index perst root hex max_entries makesubindices perstroot perstroot generatesubindex perstroot private void generate sub index perst root perst root string prefix throws exception if logminor logger minor this generating subindex for prefix if prefix length match match prefix length if generatexml perst root prefix return if logminor logger minor this too big subindex for prefix for string hex hex generate sub index perst root prefix hex generatesubindex perstroot perstroot perstroot generatesubindex perstroot generates the xml index with the given list of words with prefix number of matching bits in md5 param prefix prefix string return successful throws io exception private boolean generatexml perst root perst root string prefix throws io exception final config config perst root get config final long max size config get index subindex max size final int max entries config get index max entries file output file new file config get index dir index prefix xml buffered output stream fos null int count 0 int estimate size 0 try document builder factory xml factory document builder factory new instance document builder xml builder try xml builder xml factory new document builder catch javax xml parsers parser configuration exception e throw new runtime exception spider error while initializing xml generator e dom implementation impl xml builder getdom implementation starting to generate index document xml doc impl create document sub index null element root element xml doc get document element if config is debug root element set attributens http www w3 org 2000 xmlns xmlns debug urn freenet xmlspider debug root element append child xml doc create comment new date togmt string adding header to the index element header element xml doc create elementns null header title element sub header element xml doc create elementns null title text sub header text xml doc create text node config get index title sub header element append child sub header text header element append child sub header element list of files referenced in this subindex element files element xml doc create elementns null files files element file element set long fileid new hash set long adding word index element keywords element xml doc create elementns null keywords iterable iterator term term iterator perst root get term iterator prefix prefix g for term term term iterator element word element xml doc create elementns null word word element set attributens null v term get word if config is debug word element set attributens urn freenet xmlspider debug debug md5 term getmd5 count estimate size 12 estimate size term get word length set page pages term get pages if count 1 estimate size pages size 13 max size count max entries return false for page page pages term position term pos page get term position term false if term pos null continue synchronized term pos synchronized page adding file information uri element lists the id of the file containing a particular word file element lists the id key title of the files mentioned in the entire subindex element uri element xml doc create elementns null file uri element set attributens null id long to string page get id position by position int positions term pos positions string builder position list new string builder for int k 0 k positions length k if k 0 position list append position list append positions k uri element append child xml doc create text node position list to string word element append child uri element estimate size 13 estimate size position list length if fileid contains page get id fileid add page get id element file element xml doc create elementns null file file element set attributens null id long to string page get id file element set attributens null key page geturi file element set attributens null title page get page title null page get page title page geturi files element append child file element estimate size 15 estimate size files element get attributens null id length estimate size files element get attributens null key length estimate size files element get attributens null title length keywords element append child word element element entries element xml doc create elementns null entries entries element set attributens null value count root element append child entries element root element append child header element root element append child files element root element append child keywords element serialization dom source dom source new dom source xml doc transformer factory transform factory transformer factory new instance transformer serializer try serializer transform factory new transformer catch javax xml transform transformer configuration exception e throw new runtime exception spider error while serializing xml transform factory new transformer e serializer set output property output keys encoding utf 8 serializer set output property output keys indent yes fos new buffered output stream new file output stream output file stream result result stream new stream result fos final step try serializer transform dom source result stream catch javax xml transform transformer exception e throw new runtime exception spider error while serializing xml transform e finally closer close fos if output file length max size count 1 output file delete return false if logminor logger minor this spider indexes regenerated indices add prefix return true ioexception perstroot perstroot ioexception perstroot getconfig max_size getindexsubindexmaxsize max_entries getindexmaxentries outputfile getindexdir index_ bufferedoutputstream estimatesize documentbuilderfactory xmlfactory documentbuilderfactory newinstance documentbuilder xmlbuilder xmlbuilder xmlfactory newdocumentbuilder parserconfigurationexception runtimeexception domimplementation xmlbuilder getdomimplementation xmldoc createdocument sub_index rootelement xmldoc getdocumentelement isdebug rootelement setattributens rootelement appendchild xmldoc createcomment togmtstring headerelement xmldoc createelementns subheaderelement xmldoc createelementns subheadertext xmldoc createtextnode getindextitle subheaderelement appendchild subheadertext headerelement appendchild subheaderelement fileselement xmldoc createelementns fileselement fileelement hashset keywordselement xmldoc createelementns iterableiterator termiterator perstroot gettermiterator termiterator wordelement xmldoc createelementns wordelement setattributens getword isdebug wordelement setattributens estimatesize estimatesize getword getpages estimatesize max_size max_entries termposition termpos gettermposition termpos termpos urielement fileelement urielement xmldoc createelementns urielement setattributens tostring getid termpos stringbuilder positionlist stringbuilder positionlist positionlist urielement appendchild xmldoc createtextnode positionlist tostring wordelement appendchild urielement estimatesize estimatesize positionlist getid getid fileelement xmldoc createelementns fileelement setattributens tostring getid fileelement setattributens fileelement setattributens getpagetitle getpagetitle fileselement appendchild fileelement estimatesize estimatesize fileselement getattributens estimatesize fileselement getattributens estimatesize fileselement getattributens keywordselement appendchild wordelement entrieselement xmldoc createelementns entrieselement setattributens rootelement appendchild entrieselement rootelement appendchild headerelement rootelement appendchild fileselement rootelement appendchild keywordselement domsource domsource domsource xmldoc transformerfactory transformfactory transformerfactory newinstance transformfactory newtransformer transformerconfigurationexception runtimeexception transformfactory newtransformer setoutputproperty outputkeys setoutputproperty outputkeys bufferedoutputstream fileoutputstream outputfile streamresult resultstream streamresult domsource resultstream transformerexception runtimeexception outputfile max_size outputfile public static void main string arg throws exception storage db storage factory get instance create storage db set property perst object cache kind pinned db set property perst object cache init size 8192 db set property perst alternative btree true db set property perst string encoding utf 8 db set property perst concurrent iterator true db set property perst file readonly true db open arg 0 perst root root perst root db get root index writer writer new index writer int benchmark 0 long time taken null if arg 1 null benchmark integer parse int arg 1 time taken new long benchmark for int i 0 i benchmark i long start time system current time millis writer make index root long end time system current time millis long mem free runtime get runtime free memory long mem total runtime get runtime total memory system out println index generated in end time start time ms used memory mem total mem free if benchmark 0 time taken i end time start time system out println cooling down for int j 0 j 3 j system gc system run finalization thread sleep 3000 if benchmark 0 long total time 0 long total sq time 0 for long t time taken total time t total sq time t t double mean time total time benchmark double mean sq time total sq time benchmark system out println mean time long mean time ms system out println sd long math sqrt mean sq time mean time mean time ms storagefactory getinstance createstorage setproperty setproperty setproperty setproperty setproperty setproperty perstroot perstroot getroot indexwriter indexwriter timetaken parseint timetaken starttime currenttimemillis makeindex endtime currenttimemillis memfree getruntime freememory memtotal getruntime totalmemory endtime starttime memtotal memfree timetaken endtime starttime runfinalization totaltime totalsqtime timetaken totaltime totalsqtime meantime totaltime meansqtime totalsqtime meantime meansqtime meantime meantime public action list actionlist public action get action int n return action get n getaction private static final long serial versionuid 1 url encoded format exception serialversionuid urlencodedformatexception url encoded format exception url encoded format exception string s super s urlencodedformatexception urlencodedformatexception private static final long serial versionuid 1 public http range exception throwable cause super cause serialversionuid httprangeexception public http range exception string msg super msg httprangeexception override public final synchronized throwable fill in stack trace return null fillinstacktrace public class snmp integer32 extends snmp type wrapper num public snmp integer32 super snmpinteger32 snmptypewrappernum snmpinteger32 public class snmp integer32 extends snmp type wrapper num public snmp integer32 super public snmp integer32 long value super value snmpinteger32 snmptypewrappernum snmpinteger32 snmpinteger32 public void set value long value todo make it prettier this value new long value int value system err println value cut from value to this value setvalue intvalue protected void init this typeid 0x02 private final exception m error public error page web interface my web interface http request my request exception my error super my web interface my request m error my error merror errorpage webinterface mywebinterface httprequest myrequest myerror mywebinterface myrequest merror myerror public void make html node error box add error box internal error please report this string message m error get localized message if message null message equals message m error get message html node p error box add child p message p error box add child p stack trace for stack trace element element m error get stack trace p add child br p add child element to string htmlnode errorbox adderrorbox merror getlocalizedmessage merror getmessage htmlnode errorbox addchild errorbox addchild stacktraceelement merror getstacktrace addchild addchild tostring suppress warnings unchecked public node restart jobs queue long nodedb handle2 nodedb handle nodedb handle2 db jobs new set native thread java priority range db jobs early new set native thread java priority range for int i 0 i db jobs length i db jobs i new hash set db job db jobs early i new hash set db job suppresswarnings noderestartjobsqueue nodedbhandle2 nodedbhandle nodedbhandle2 dbjobs nativethread java_priority_range dbjobsearly nativethread java_priority_range dbjobs dbjobs hashset dbjob dbjobsearly hashset dbjob public static node restart jobs queue init final long nodedb handle object container container suppress warnings serial object set node restart jobs queue results container query new predicate node restart jobs queue override public boolean match node restart jobs queue arg0 return arg0 nodedb handle nodedb handle if results has next system err println found old restart jobs queue node restart jobs queue queue results next container activate queue 1 queue on init container return queue node restart jobs queue queue new node restart jobs queue nodedb handle container store queue system err println created new restart jobs queue return queue noderestartjobsqueue nodedbhandle objectcontainer suppresswarnings objectset noderestartjobsqueue noderestartjobsqueue noderestartjobsqueue nodedbhandle nodedbhandle hasnext noderestartjobsqueue oninit noderestartjobsqueue noderestartjobsqueue nodedbhandle object set node restart jobs queue results container query new predicate node restart jobs queue override public boolean match node restart jobs queue arg0 return arg0 nodedb handle nodedb handle objectset noderestartjobsqueue noderestartjobsqueue noderestartjobsqueue nodedbhandle nodedbhandle private void on init object container container oninit objectcontainer public synchronized void queue restart job db job job int priority object container container boolean early if logger should log logger minor this logger minor this queueing restart job job at priority priority early early set db job jobs early db jobs early priority db jobs priority container store job container activate jobs 1 if jobs add job store to 1 hop only otherwise db4o will update all the jobs on the queue to a depth of 3 which in practice means all the buckets inside the bucket chain bucket s linked by the bucket chain bucket kill tag s adding new ones this will take ages and is in any case not what we want see http tracker db4o com browse cor 1436 container ext store jobs 1 container deactivate jobs 1 queuerestartjob dbjob objectcontainer shouldlog dbjob dbjobsearly dbjobs bucketchainbucket bucketchainbucketkilltag public synchronized void remove restart job db job job int priority object container container boolean job was active container ext is active job if job was active container activate job 1 container activate db jobs priority 1 container activate db jobs early priority 1 if db jobs priority remove job db jobs early priority remove job int found 0 for int i 0 i db jobs length i container activate db jobs priority 1 if db jobs priority remove job store to 1 hop only otherwise db4o will update all the jobs on the queue to a depth of 3 which in practice means all the buckets inside the bucket chain bucket s linked by the bucket chain bucket kill tag s adding new ones this will take ages and is in any case not what we want see http tracker db4o com browse cor 1436 container ext store db jobs priority 1 found if db jobs early priority remove job store to 1 hop only otherwise db4o will update all the jobs on the queue to a depth of 3 which in practice means all the buckets inside the bucket chain bucket s linked by the bucket chain bucket kill tag s adding new ones this will take ages and is in any case not what we want see http tracker db4o com browse cor 1436 container ext store db jobs early priority 1 found container deactivate db jobs priority 1 container deactivate db jobs early priority 1 if found 0 logger error this job job not in specified priority priority found in found other priorities when removing else logger error this job job not found when removing it else store to 1 hop only otherwise db4o will update all the jobs on the queue to a depth of 3 which in practice means all the buckets inside the bucket chain bucket s linked by the bucket chain bucket kill tag s adding new ones this will take ages and is in any case not what we want see http tracker db4o com browse cor 1436 container ext store db jobs priority 1 container deactivate db jobs priority 1 container ext store db jobs early priority 1 container deactivate db jobs early priority 1 if job was active container deactivate job 1 removerestartjob dbjob objectcontainer jobwasactive isactive jobwasactive dbjobs dbjobsearly dbjobs dbjobsearly dbjobs dbjobs dbjobs bucketchainbucket bucketchainbucketkilltag dbjobs dbjobsearly bucketchainbucket bucketchainbucketkilltag dbjobsearly dbjobs dbjobsearly bucketchainbucket bucketchainbucketkilltag dbjobs dbjobs dbjobsearly dbjobsearly jobwasactive static class restartdb job public restartdb job db job job2 int i job job2 prio i restartdbjob restartdbjob dbjob synchronized restartdb job get early restart database jobs object container container array list restartdb job list new array list restartdb job for int i db jobs early length 1 i 0 i container activate db jobs early i 1 if db jobs early i is empty system err println adding db jobs early i size early restart jobs at priority i for db job job db jobs early i list add new restartdb job job i container deactivate db jobs early i 1 return list to array new restartdb job list size restartdbjob getearlyrestartdatabasejobs objectcontainer arraylist restartdbjob arraylist restartdbjob dbjobsearly dbjobsearly dbjobsearly isempty dbjobsearly dbjob dbjobsearly restartdbjob dbjobsearly toarray restartdbjob void add late restart database jobs db job runner runner object container container for int i db jobs early length 1 i 0 i container activate db jobs i 1 if db jobs i is empty system err println adding db jobs i size restart jobs at priority i for iterator db job it db jobs i iterator it has next db job job it next if job null logger error this late restart job removed without telling the node restart jobs queue on priority i it remove container ext store db jobs i 2 continue container activate job 1 runner queue job i false addlaterestartdatabasejobs dbjobrunner objectcontainer dbjobsearly dbjobs dbjobs isempty dbjobs dbjob dbjobs hasnext dbjob noderestartjobsqueue dbjobs static final string get message int reason switch reason case internal error return internal error probably a bug case route not found return could not store the data on enough nodes case rejected overload return a node downstream either timed out or was overloaded retry case route really not found return the insert could not get off the node at all case collision return the insert collided with different data of the same key already on the network default return unknown error code reason getmessage internal_error route_not_found rejected_overload route_really_not_found public low level put exception int code string message throwable t super message t this code code lowlevelputexception low level put exception int reason super get message reason this code reason lowlevelputexception getmessage public client put dir message simple field set fs throws message invalid exception identifier fs get identifier global fields string to bool fs get global false default name fs get default name if identifier null throw new message invalid exception protocol error message missing field no identifier null global try string u fs get uri if u null throw new message invalid exception protocol error message missing field no uri identifier global freeneturi uu new freeneturi fs get uri client is allowed to put a slash at the end if it wants to but this is discouraged string meta uu get all meta strings if meta null meta length 1 meta 0 length 0 uu uu set meta string null uri uu catch malformedurl exception e throw new message invalid exception protocol error message freenet uri parse error e get message identifier global string verbosity string fs get verbosity if verbosity string null verbosity 0 else try verbosity integer parse int verbosity string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing verbosity field e get message identifier global string max retries string fs get max retries if max retries string null default to 0 max retries 0 else try max retries integer parse int max retries string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing max size field e get message identifier global getchk only fields string to bool fs get getchk only false string priority string fs get priority class if priority string null defaults to the one just below f proxy priority class request starter immediate splitfile priority class else try priority class short parse short priority string 10 if priority class request starter maximum priority class priority class request starter minimum priority class throw new message invalid exception protocol error message invalid field valid priorities are from request starter maximum priority class to request starter minimum priority class identifier global catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing priority class field e get message identifier global dont compress fields string to bool fs get dont compress false string persistence string fs get persistence if persistence string null persistence string equals ignore case connection default persists until connection loss persistence type client request persist connection else if persistence string equals ignore case reboot reports to client by name persists over connection loss not saved to disk so dies on reboot persistence type client request persist reboot else if persistence string equals ignore case forever same as reboot but saved to disk persists forever persistence type client request persist forever else throw new message invalid exception protocol error message error parsing number error parsing persistence field persistence string identifier global client token fs get client token early encode fields string to bool fs get early encode false clientputdirmessage simplefieldset messageinvalidexception stringtobool defaultname defaultname messageinvalidexception protocolerrormessage missing_field messageinvalidexception protocolerrormessage missing_field getallmetastrings setmetastring malformedurlexception messageinvalidexception protocolerrormessage freenet_uri_parse_error getmessage verbositystring verbositystring parseint verbositystring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number getmessage maxretriesstring maxretries maxretriesstring maxretries maxretries parseint maxretriesstring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number maxsize getmessage getchkonly stringtobool getchkonly prioritystring priorityclass prioritystring fproxy priorityclass requeststarter immediate_splitfile_priority_class priorityclass parseshort prioritystring priorityclass requeststarter maximum_priority_class priorityclass requeststarter minimum_priority_class messageinvalidexception protocolerrormessage invalid_field requeststarter maximum_priority_class requeststarter minimum_priority_class numberformatexception messageinvalidexception protocolerrormessage error_parsing_number priorityclass getmessage dontcompress stringtobool dontcompress persistencestring persistencestring persistencestring equalsignorecase persistencetype clientrequest persist_connection persistencestring equalsignorecase persistencetype clientrequest persist_reboot persistencestring equalsignorecase persistencetype clientrequest persist_forever messageinvalidexception protocolerrormessage error_parsing_number persistencestring clienttoken clienttoken earlyencode stringtobool earlyencode override public simple field set get field set simple field set sfs new simple field set true sfs put single uri uri to string sfs put single identifier identifier sfs put single verbosity integer to string verbosity sfs put single max retries integer to string max retries sfs put single client token client token sfs put single getchk only boolean to string getchk only sfs put single priority class short to string priority class sfs put single persistence type client request persistence type string persistence type sfs put single dont compress boolean to string dont compress sfs put single global boolean to string global sfs put single default name default name return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle putsingle tostring putsingle maxretries tostring maxretries putsingle clienttoken clienttoken putsingle getchkonly tostring getchkonly putsingle priorityclass tostring priorityclass putsingle persistencetype clientrequest persistencetypestring persistencetype putsingle dontcompress tostring dontcompress putsingle tostring putsingle defaultname defaultname public final class color composite extends rgb composite public color composite float alpha super alpha colorcomposite rgbcomposite colorcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel private float dhsb new float 3 public context float alpha color model src color model color model dst color model super alpha src color model dst color model colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob color rg btohsb sr sg sb shsb color rg btohsb dir dig dib dhsb dhsb 0 shsb 0 dhsb 1 shsb 1 int dorgb color hs btorgb dhsb 0 dhsb 1 dhsb 2 dor dorgb 0xff0000 16 dog dorgb 0xff00 8 dob dorgb 0xff float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac rgbtohsb rgbtohsb hsbtorgb private t prev public t get next return next getnext suppress warnings unchecked public t set next item i t old next next t i return old suppresswarnings setnext public t get prev return prev getprev suppress warnings unchecked public t set prev item i t old prev prev t i return old suppresswarnings setprev private doubly linked list super t parent list public doubly linked list super t get parent return parent list doublylinkedlist parentlist doublylinkedlist getparent parentlist public doubly linked list super t set parent doubly linked list super t l doubly linked list super t old parent parent list parent list l return old parent doublylinkedlist setparent doublylinkedlist doublylinkedlist oldparent parentlist parentlist oldparent public introduction puzzle store wot my wot m wot my wot mdb my wot getdb delete corrupted puzzles introductionpuzzlestore mywot mwot mywot mywot deletecorruptedpuzzles private synchronized void delete corrupted puzzles synchronized mdb lock object set introduction puzzle puzzles mdb query by example introduction puzzle class for introduction puzzle p puzzles mdb activate p 3 fixme is this the correct depth if p check consistency false logger error this deleting corrupted puzzle mdb delete p mdb commit our goal is to delete the puzzles so we do not rollback here if an exception occurs that would restore the deleted puzzles deletecorruptedpuzzles objectset introductionpuzzle querybyexample introductionpuzzle introductionpuzzle checkconsistency delete puzzles which can no longer be solved because they have expired suppress warnings unchecked protected synchronized void delete expired puzzles synchronized mdb lock query q mdb query q constrain introduction puzzle class q descend m valid until time constrain current timeutc get in millis smaller object set introduction puzzle result q execute for introduction puzzle p result mdb delete p todo minor but interesting optimization result size should take about o n time before the for and o 1 after it if db4o is smart enough verify if it really calculates and stores the size during the iteration if not the log line should be prefixed with if loglevel is debug logger debug introduction puzzle class deleted result size expired puzzles mdb commit our goal is to delete the puzzles so we do not rollback here if an exception occurs that would restore the deleted puzzles suppresswarnings deleteexpiredpuzzles introductionpuzzle mvaliduntiltime currenttimeutc getinmillis objectset introductionpuzzle introductionpuzzle introductionpuzzle delete the oldest puzzles so that only an amount of code puzzle pool size code is left used by the introduction client to delete old puzzles and replace them with new ones param puzzle pool size the amount of puzzles which should not be deleted suppress warnings unchecked protected synchronized void delete oldest unsolved puzzles int puzzle pool size synchronized mdb lock query q mdb query q constrain introduction puzzle class q constrain own introduction puzzle class not q descend m valid until time order ascending object set introduction puzzle result q execute int delete count result size puzzle pool size logger debug introduction puzzle class deleting delete count old puzzles keeping puzzle pool size while delete count 0 result has next introduction puzzle puzzle result next we do not handle the following check in the query so that db4o can use the index on m valid until time to run the query and size in o 1 instead of o amount of puzzles in the database unfortunately toad said that it does not really do that even though it is logically possible todo tell it to do so if puzzle was solved false mdb delete puzzle delete count mdb commit our goal is to delete the puzzles so we do not rollback here if an exception occurs that would restore the deleted puzzles puzzlepoolsize puzzlepoolsize suppresswarnings deleteoldestunsolvedpuzzles puzzlepoolsize introductionpuzzle ownintroductionpuzzle mvaliduntiltime orderascending objectset introductionpuzzle deletecount puzzlepoolsize introductionpuzzle deletecount puzzlepoolsize deletecount hasnext introductionpuzzle mvaliduntiltime toad_ wassolved deletecount public synchronized void store and commit introduction puzzle puzzle todo convert to assert maybe when we are sure that this does not happen duplicate puzzles will be deleted after they expire anyway further isn t there a db4o option which ensures that mid is a primary key and therefore no duplicates can exist synchronized puzzle synchronized mdb lock introduction puzzle existing puzzle get byid puzzle getid if existing puzzle null existing puzzle puzzle throw new illegal argument exception puzzle with id puzzle getid already exists if mdb is stored puzzle mdb is active puzzle throw new runtime exception trying to store an inactive introduction puzzle object try mdb store puzzle get type mdb store puzzle get date of insertion not stored because it is a primitive for db4o mdb store puzzle mdb commit logger debug puzzle commited catch runtime exception e mdb rollback throw e storeandcommit introductionpuzzle introductionpuzzle existingpuzzle getbyid existingpuzzle existingpuzzle illegalargumentexception isstored isactive runtimeexception introductionpuzzle gettype getdateofinsertion runtimeexception get an introduction puzzle or own introduction puzzle by it s id suppress warnings unchecked public synchronized introduction puzzle get byid string id query q mdb query q constrain introduction puzzle class q descend mid constrain id object set introduction puzzle result q execute todo decide whether we maybe should throw to get bug reports if this happens otoh puzzles are not so important assert result size 1 return result has next result next null introductionpuzzle ownintroductionpuzzle suppresswarnings introductionpuzzle getbyid introductionpuzzle objectset introductionpuzzle hasnext get a puzzle by it s request uri if you synchronize on the puzzle store while calling this function you have to synchronize on the wot before synchronizing on the puzzle store because this function locks the wot if you did not lock it before dead locks might occur used by the introduction client to obtain the corresponding puzzle object when an insert succeeded or failed protected introduction puzzle get puzzle by requesturi freeneturi uri throws parse exception unknown identity exception identity inserter m wot get identity byuri uri date date introduction puzzle get date from requesturi uri int index introduction puzzle get index from requesturi uri return introduction puzzle get by inserter date index inserter date index introductionclient introductionpuzzle getpuzzlebyrequesturi parseexception unknownidentityexception mwot getidentitybyuri introductionpuzzle getdatefromrequesturi introductionpuzzle getindexfromrequesturi introductionpuzzle getbyinserterdateindex protected introduction puzzle get puzzle by solutionuri freeneturi uri throws parse exception unknown identity exception return get byid introduction puzzle getid from solutionuri uri introductionpuzzle getpuzzlebysolutionuri parseexception unknownidentityexception getbyid introductionpuzzle getidfromsolutionuri get an own puzzle by it s request uri if you synchronize on the puzzle store while calling this function you have to synchronize on the wot before synchronizing on the puzzle store because this function locks the wot if you did not lock it before dead locks might occur used by the introduction server to obtain the corresponding puzzle object when an insert succeeded or failed protected own introduction puzzle get own puzzle by requesturi freeneturi uri throws parse exception unknown identity exception own identity inserter m wot get own identity byuri uri date date introduction puzzle get date from requesturi uri int index introduction puzzle get index from requesturi uri return own introduction puzzle get by inserter date index inserter date index introductionserver ownintroductionpuzzle getownpuzzlebyrequesturi parseexception unknownidentityexception ownidentity mwot getownidentitybyuri introductionpuzzle getdatefromrequesturi introductionpuzzle getindexfromrequesturi ownintroductionpuzzle getbyinserterdateindex get a puzzle by it s solution uri used by the introduction server when a solution was downloaded from the given uri to retrieve the introduction puzzle object which belongs to the uri param db param uri return throws parse exception protected own introduction puzzle get own puzzle by solutionuri freeneturi uri throws parse exception return own introduction puzzle get byid own introduction puzzle getid from solutionuri uri introductionserver introductionpuzzle parseexception ownintroductionpuzzle getownpuzzlebysolutionuri parseexception ownintroductionpuzzle getbyid ownintroductionpuzzle getidfromsolutionuri used by the introduction puzzle factories for creating new puzzles suppress warnings deprecation unchecked public synchronized int get free index own identity inserter date date query q mdb query q constrain own introduction puzzle class q descend m inserter constrain inserter identity q descend m date of insertion constrain new date date get year date get month date get date q descend m index order descending object set introduction puzzle result q execute return result size 0 result next get index 1 0 introductionpuzzlefactories suppresswarnings getfreeindex ownidentity ownintroductionpuzzle minserter mdateofinsertion getyear getmonth getdate mindex orderdescending objectset introductionpuzzle getindex get all not inserted puzzles of the given identity you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it used by the introduction server for inserting puzzles suppress warnings unchecked public object set own introduction puzzle get uninserted own puzzles by inserter own identity identity query q mdb query q constrain own introduction puzzle class q descend m was inserted constrain false return q execute introductionpuzzlestore introductionserver suppresswarnings objectset ownintroductionpuzzle getuninsertedownpuzzlesbyinserter ownidentity ownintroductionpuzzle mwasinserted get all not solved puzzles which where inserted by the given identity you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it used by the introduction server for downloading solutions suppress warnings unchecked protected synchronized object set own introduction puzzle get unsolved by inserter own identity inserter query q mdb query q constrain own introduction puzzle class q descend m inserter constrain inserter identity q descend m was solved constrain false return q execute introductionpuzzlestore introductionserver suppresswarnings objectset ownintroductionpuzzle getunsolvedbyinserter ownidentity ownintroductionpuzzle minserter mwassolved get a list of puzzles which are from today you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it used by for checking whether new puzzles have to be inserted for a given own identity or can be downloaded from a given identity suppress warnings deprecation unchecked protected synchronized object set introduction puzzle get of today by inserter identity inserter date max age new date current timeutc get year 1900 current timeutc get month current timeutc get day of month query q mdb query q constrain introduction puzzle class q descend m inserter constrain inserter identity q descend m date of insertion constrain max age smaller not return q execute introductionpuzzlestore ownidentity suppresswarnings objectset introductionpuzzle getoftodaybyinserter maxage currenttimeutc getyear currenttimeutc getmonth currenttimeutc getdayofmonth introductionpuzzle minserter mdateofinsertion maxage get a puzzle of a given identity from a given date with a given index used by the introduction client to check whether we already have a puzzle from the given date and index if yes then we do not need to download that one suppress warnings unchecked protected synchronized introduction puzzle get by inserter date index identity inserter date date int index query q mdb query q constrain introduction puzzle class q descend m inserter constrain inserter identity q descend m date of insertion constrain date q descend m index constrain index object set introduction puzzle result q execute todo decide whether we maybe should throw to get bug reports if this happens otoh puzzles are not so important assert result size 1 return result has next result next null introductionclient suppresswarnings introductionpuzzle getbyinserterdateindex introductionpuzzle minserter mdateofinsertion mindex objectset introductionpuzzle hasnext get a list of non own puzzles which were downloaded and not solved yet of a given type you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it suppress warnings unchecked protected synchronized object set introduction puzzle get unsolved puzzles puzzle type puzzle type query q mdb query q constrain introduction puzzle class q constrain own introduction puzzle class not q descend m valid until time order descending q descend m was solved constrain false q descend m type constrain puzzle type object set introduction puzzle puzzles q execute return puzzles introductionpuzzlestore suppresswarnings objectset introductionpuzzle getunsolvedpuzzles puzzletype puzzletype introductionpuzzle ownintroductionpuzzle mvaliduntiltime orderdescending mwassolved mtype puzzletype objectset introductionpuzzle get a list of all solved non own puzzles you have to put a synchronized this introduction puzzle store statement around the call to this function and the processing of the list which was returned by it used by the introduction client for inserting solutions of solved puzzles suppress warnings unchecked public synchronized object set introduction puzzle get uninserted solved puzzles query q mdb query q constrain introduction puzzle class q constrain own introduction puzzle class not q descend m was inserted constrain false q descend m was solved constrain true return q execute introductionpuzzlestore introductionclient suppresswarnings objectset introductionpuzzle getuninsertedsolvedpuzzles introductionpuzzle ownintroductionpuzzle mwasinserted mwassolved public synchronized int get own catpcha amount boolean solved query q mdb query q constrain own introduction puzzle class q descend m was solved constrain solved return q execute size getowncatpchaamount ownintroductionpuzzle mwassolved public synchronized int get non own captcha amount boolean solved query q mdb query q constrain introduction puzzle class q constrain own introduction puzzle class not q descend m was solved constrain solved return q execute size getnonowncaptchaamount introductionpuzzle ownintroductionpuzzle mwassolved memory usage constructor public memory usage class cls this cls cls memoryusage memoryusage protected function2d basis public fbm float h float lacunarity float octaves this h lacunarity octaves new noise public fbm float h float lacunarity float octaves function2d basis this h h this lacunarity lacunarity this octaves octaves this basis basis exponents new float int octaves 1 float frequency 1 0f for int i 0 i int octaves i exponents i float math pow frequency h frequency lacunarity public void set basis function2d basis this basis basis setbasis public function2d get basis type return basis getbasistype public float evaluate float x float y float value 0 0f float remainder int i to prevent cascading effects x 371 y 529 for i 0 i int octaves i value basis evaluate x y exponents i x lacunarity y lacunarity remainder octaves int octaves if remainder 0 value remainder basis evaluate x y exponents i return value public persistent put dir string identifier freeneturi uri int verbosity short priority class short persistence type boolean global string default name hash map string object manifest elements string token boolean started int max retries boolean was disk put object container container this identifier identifier this uri uri this verbosity verbosity this priority class priority class this persistence type persistence type this global global this default name default name this manifest elements manifest elements this token token this started started this max retries max retries this was disk put was disk put cached generate field set container persistentputdir priorityclass persistencetype defaultname hashmap manifestelements maxretries wasdiskput objectcontainer priorityclass priorityclass persistencetype persistencetype defaultname defaultname manifestelements manifestelements maxretries maxretries wasdiskput wasdiskput generatefieldset private simple field set generate field set object container container simple field set fs new simple field set false false because this can get huge fs put single identifier identifier fs put single uri uri to string false false fs put verbosity verbosity fs put single persistence client request persistence type string persistence type fs put priority class priority class fs put single global boolean to string global fs put single put dir type was disk put disk complex simple field set files new simple field set false flatten the hierarchy it can be reconstructed on restarting storing it directly would be a pita fixme resolve the new base manifest putter s container mode does not hold the origin data after composing the put handlers done in base manifest putter they are lost a resumed half done container put can not get the complete file list from base manifest putter is it really necessary to include the file list here manifest element elements simple manifest putter flatten manifest elements fs put single default name default name for int i 0 i elements length i string num integer to string i manifest element e elements i string mime override e get mime type override simple field set subset new simple field set false freeneturi tempuri e get targeturi subset put single name e get name if tempuri null subset put single upload from redirect subset put single targeturi tempuri to string else bucket data e get data if persistence type client request persist forever container activate data 1 if data instanceof delayed free bucket data delayed free bucket data get underlying subset put data length e get size if mime override null subset put single metadata content type mime override what to do with the bucket it is either a persistent encrypted bucket or a file bucket if data null logger error this bucket already freed e get data for e for e get name for identifier else if data instanceof file bucket subset put single upload from disk subset put single filename file bucket data get file get path else if data instanceof padded ephemerally encrypted bucket data instanceof null bucket subset put single upload from direct else throw new illegal state exception don t know what to do with bucket data if persistence type client request persist forever container deactivate data 1 files put num subset files put count elements length fs put files files if token null fs put single client token token fs put started started fs put max retries max retries return fs simplefieldset generatefieldset objectcontainer simplefieldset simplefieldset putsingle putsingle tostring putsingle clientrequest persistencetypestring persistencetype priorityclass priorityclass putsingle tostring putsingle putdirtype wasdiskput simplefieldset simplefieldset basemanifestputter puthandlers basemanifestputter basemanifestputter manifestelement simplemanifestputter manifestelements putsingle defaultname defaultname tostring manifestelement mimeoverride getmimetypeoverride simplefieldset simplefieldset gettargeturi putsingle getname putsingle uploadfrom putsingle tostring getdata persistencetype clientrequest persist_forever delayedfreebucket delayedfreebucket getunderlying datalength getsize mimeoverride putsingle contenttype mimeoverride getdata getname filebucket putsingle uploadfrom putsingle filebucket getfile getpath paddedephemerallyencryptedbucket nullbucket putsingle uploadfrom illegalstateexception persistencetype clientrequest persist_forever putsingle clienttoken maxretries maxretries override public simple field set get field set return cached simplefieldset getfieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message persistent put goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message persistentput override public void remove from object container container container activate uri 5 uri remove from container manifest elements will be removed by client put dir free data not our problem container activate cached integer max value cached remove from container container delete this removefrom objectcontainer removefrom manifestelements clientputdir freedata max_value removefrom private final array list thread late jobs public semi ordered shutdown hook early jobs new array list thread late jobs new array list thread arraylist latejobs semiorderedshutdownhook earlyjobs arraylist latejobs arraylist public synchronized void add early job thread r early jobs add r addearlyjob earlyjobs public synchronized void add late job thread r late jobs add r addlatejob latejobs override public void run system err println shutting down first run early jobs all at once and wait for them to all complete for thread r early jobs r start for thread r early jobs try r join timeout catch interrupted exception e may as well move on then run late jobs all at once and wait for them to all complete jvm will exit when we return for thread r late jobs r start for thread r late jobs try r join timeout catch interrupted exception e may as well move on earlyjobs earlyjobs interruptedexception latejobs latejobs interruptedexception void discard int flags if used 0 flags enable segment caching 0 invalidate next null enable_segment_caching protected int flags public int read byte b new byte 1 return read b 0 1 1 b 0 0xff 1 public int read byte b int off int len if pos first size return 1 int rest first size pos if len rest len rest int rc len while len 0 if blob offs curr body length blob impl prev curr curr prev next curr load curr used 1 if prev first prev discard flags blob offs 0 int n len curr body length blob offs curr body length blob offs len system arraycopy curr body blob offs b off n blob offs n off n len n pos n return rc bloboffs blobimpl bloboffs bloboffs bloboffs bloboffs bloboffs public long set position long new pos if new pos pos if new pos pos blob offs blob offs pos new pos return pos int new pos if first curr curr discard flags curr first pos 0 blob offs 0 skip new pos pos return pos setposition newpos newpos newpos bloboffs bloboffs newpos newpos bloboffs newpos public long get position return pos getposition public long size return first size public long skip long offs int rest first size pos if offs rest offs rest int len int offs while len 0 if blob offs curr body length blob impl prev curr curr prev next curr load curr used 1 if prev first prev discard flags blob offs 0 int n len curr body length blob offs curr body length blob offs len pos n len n blob offs n return offs bloboffs blobimpl bloboffs bloboffs bloboffs bloboffs public int available return first size pos public void close curr discard flags if first curr first discard flags curr first null protected blob input stream blob impl first int flags this flags flags this first first first load curr first first used 1 blobinputstream blobimpl public void write int b byte buf new byte 1 buf 0 byte b write buf 0 1 public void write byte b int off int len while len 0 if blob offs curr body length blob impl prev curr if prev next null int length curr body length if flags double segment size 0 length 1 length length length header size 1 header size blob impl next new blob impl curr get storage length curr prev next next modified true else curr prev next curr load curr used 1 if prev first if modified prev store prev discard flags blob offs 0 int n len curr body length blob offs curr body length blob offs len system arraycopy b off curr body blob offs n modified true blob offs n off n len n pos n if pos first size first size pos bloboffs blobimpl double_segment_size headersize headersize blobimpl blobimpl getstorage bloboffs bloboffs bloboffs bloboffs bloboffs public void close if flags truncate last segment 0 blob offs curr body length curr next null byte tmp new byte blob offs system arraycopy curr body 0 tmp 0 blob offs curr body tmp curr store curr discard flags if curr first first store first discard flags first curr null truncate_last_segment bloboffs bloboffs bloboffs public long set position long new pos if new pos pos if new pos pos blob offs blob offs pos new pos return pos int new pos if first curr if modified curr store modified false curr discard flags curr first pos 0 blob offs 0 skip new pos pos return pos setposition newpos newpos newpos bloboffs bloboffs newpos newpos bloboffs newpos public long get position return pos getposition public long size return first size public long skip long offs int rest first size pos if offs rest offs rest int len int offs while len 0 if blob offs curr body length blob impl prev curr curr prev next curr load curr used 1 if prev first if modified prev store modified false prev discard flags blob offs 0 int n len curr body length blob offs curr body length blob offs len pos n len n blob offs n return offs bloboffs blobimpl bloboffs bloboffs bloboffs bloboffs blob output stream blob impl first int flags this flags flags this first first first load first used 1 curr first if flags append 0 skip first size bloboutputstream blobimpl public boolean recursive loading return false recursiveloading public random access input stream get input stream return get input stream 0 randomaccessinputstream getinputstream getinputstream public random access input stream get input stream int flags return new blob input stream this flags randomaccessinputstream getinputstream blobinputstream public random access output stream get output stream return get output stream append randomaccessoutputstream getoutputstream getoutputstream public random access output stream get output stream boolean multisession return get output stream multisession append truncate last segment append randomaccessoutputstream getoutputstream getoutputstream truncate_last_segment public random access output stream get output stream long position boolean multisession random access output stream stream get output stream multisession stream set position position return stream randomaccessoutputstream getoutputstream randomaccessoutputstream getoutputstream setposition public random access output stream get output stream int flags return new blob output stream this flags randomaccessoutputstream getoutputstream bloboutputstream public void deallocate load if size 0 blob impl curr next while curr null curr load blob impl tail curr next curr deallocate curr tail super deallocate blobimpl blobimpl blob impl storage storage int size super storage body new byte size blobimpl blob impl blobimpl public watch global simple field set fs throws message invalid exception enabled fields string to bool fs get enabled true string s fs get verbosity mask if s null try verbosity mask integer parse int s catch number format exception e throw new message invalid exception protocol error message error parsing number e to string null false else verbosity mask integer max value watchglobal simplefieldset messageinvalidexception stringtobool verbositymask verbositymask parseint numberformatexception messageinvalidexception protocolerrormessage error_parsing_number tostring verbositymask max_value override public simple field set get field set simple field set fs new simple field set true fs put enabled enabled fs put verbosity mask verbosity mask return fs simplefieldset getfieldset simplefieldset simplefieldset verbositymask verbositymask override public string get name return name getname override public void run final fcp connection handler handler node node throws message invalid exception handler get reboot client set watch global enabled verbosity mask node client core getfcp server null handler server core client context job runner queue new db job public void run object container container client context context fcp client client handler get forever client container container activate client 1 client set watch global enabled verbosity mask handler server container container deactivate client 1 native thread high priority false fcpconnectionhandler messageinvalidexception getrebootclient setwatchglobal verbositymask clientcore getfcpserver clientcontext jobrunner dbjob objectcontainer clientcontext fcpclient getforeverclient setwatchglobal verbositymask nativethread high_priority public void run object container container client context context fcp client client handler get forever client container container activate client 1 client set watch global enabled verbosity mask handler server container container deactivate client 1 objectcontainer clientcontext fcpclient getforeverclient setwatchglobal verbositymask override public void remove from object container container container delete this removefrom objectcontainer public class null client callback implements client callback public void on failure fetch exception e client getter state object container container ignore nullclientcallback clientcallback onfailure fetchexception clientgetter objectcontainer public void on failure insert exception e base client putter state object container container impossible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container impossible onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container impossible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container result data free onsuccess fetchresult clientgetter objectcontainer public void on success base client putter state object container container impossible onsuccess baseclientputter objectcontainer protected final linked hash map string sub config configs by prefix public config configs by prefix new linked hash map string sub config linkedhashmap subconfig configsbyprefix configsbyprefix linkedhashmap subconfig public void register sub config sc synchronized this if configs by prefix contains key sc prefix throw new illegal argument exception already registered sc prefix sc configs by prefix put sc prefix sc subconfig configsbyprefix containskey illegalargumentexception configsbyprefix write current config to disk throws io exception public void store do nothing ioexception finished initialization public void finished init do nothing finishedinit public void on register sub config config option o do nothing onregister subconfig fetch all the sub config s used by user facing config thingies public synchronized sub config get configs return configs by prefix values to array new sub config configs by prefix size subconfig subconfig getconfigs configsbyprefix toarray subconfig configsbyprefix public synchronized sub config get string sub config return configs by prefix get sub config subconfig subconfig configsbyprefix subconfig create an image which will have written a distorted text param text the distorted characters return image with the text public buffered image create image string text word renderer word renderer get config get word renderer impl gimpy engine gimpy engine get config get obscurificator impl background producer background producer get config get background impl boolean is border drawn get config is border drawn this width get config get width this height get config get height buffered image bi word renderer render word text width height bi gimpy engine get distorted image bi bi background producer add background bi graphics2d graphics bi create graphics if is border drawn draw box graphics return bi bufferedimage createimage wordrenderer wordrenderer getconfig getwordrendererimpl gimpyengine gimpyengine getconfig getobscurificatorimpl backgroundproducer backgroundproducer getconfig getbackgroundimpl isborderdrawn getconfig isborderdrawn getconfig getwidth getconfig getheight bufferedimage wordrenderer renderword gimpyengine getdistortedimage backgroundproducer addbackground creategraphics isborderdrawn drawbox private void draw box graphics2d graphics color border color get config get border color int border thickness get config get border thickness graphics set color border color if border thickness 1 basic stroke stroke new basic stroke float border thickness graphics set stroke stroke line2d line1 new line2d double 0 0 0 width graphics draw line1 line2d line2 new line2d double 0 0 width 0 graphics draw line2 line2 new line2d double 0 height 1 width height 1 graphics draw line2 line2 new line2d double width 1 height 1 width 1 0 graphics draw line2 drawbox bordercolor getconfig getbordercolor borderthickness getconfig getborderthickness setcolor bordercolor borderthickness basicstroke basicstroke borderthickness setstroke return the text to be drawn public string create text return get config get text producer impl get text createtext getconfig gettextproducerimpl gettext construct a threshold filter public threshold filter this 127 thresholdfilter thresholdfilter construct a threshold filter param t the threshold value public threshold filter int t set lower threshold t set upper threshold t thresholdfilter thresholdfilter setlowerthreshold setupperthreshold set the lower threshold value param lower threshold the threshold value see get lower threshold public void set lower threshold int lower threshold this lower threshold lower threshold lower threshold3 lower threshold 3 lowerthreshold getlowerthreshold setlowerthreshold lowerthreshold lowerthreshold lowerthreshold lowerthreshold3 lowerthreshold get the lower threshold value return the threshold value see set lower threshold public int get lower threshold return lower threshold setlowerthreshold getlowerthreshold lowerthreshold set the upper threshold value param upper threshold the threshold value see get upper threshold public void set upper threshold int upper threshold this upper threshold upper threshold upper threshold3 upper threshold 3 upperthreshold getupperthreshold setupperthreshold upperthreshold upperthreshold upperthreshold upperthreshold3 upperthreshold get the upper threshold value return the threshold value see set upper threshold public int get upper threshold return upper threshold setupperthreshold getupperthreshold upperthreshold set the color to be used for pixels above the upper threshold param white the color see get white public void set white int white this white white getwhite setwhite get the color to be used for pixels above the upper threshold return the color see set white public int get white return white setwhite getwhite set the color to be used for pixels below the lower threshold param black the color see get black public void set black int black this black black getblack setblack set the color to be used for pixels below the lower threshold return the color see set black public int get black return black setblack getblack override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int l r g b if l lower threshold3 return a black else if l upper threshold3 return a white return rgb lowerthreshold3 upperthreshold3 override public string to string return stylize threshold tostring private int tile public shatter filter shatterfilter public void set transition float transition this transition transition settransition public float get transition return transition gettransition public void set distance float distance this distance distance setdistance public float get distance return distance getdistance public void set rotation float rotation this rotation rotation setrotation public float get rotation return rotation getrotation public void set zoom float zoom this zoom zoom setzoom public float get zoom return zoom getzoom public void set start alpha float start alpha this start alpha start alpha setstartalpha startalpha startalpha startalpha public float get start alpha return start alpha getstartalpha startalpha public void set end alpha float end alpha this end alpha end alpha setendalpha endalpha endalpha endalpha public float get end alpha return end alpha getendalpha endalpha public void set centrex float centrex this centrex centrex setcentrex public float get centrex return centrex getcentrex public void set centrey float centrey this centrey centrey setcentrey public float get centrey return centrey getcentrey public void set centre point2d centre this centrex float centre getx this centrey float centre gety setcentre public point2d get centre return new point2d float centrex centrey getcentre public void set iterations int iterations this iterations iterations setiterations public int get iterations return iterations getiterations public void set tile int tile this tile tile settile public int get tile return tile gettile public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null float width float src get width float height float src get height float cx float src get width centrex float cy float src get height centrey float image radius float math sqrt cx cx cy cy buffered image tiles new buffered image iterations int num tiles iterations iterations tile shapes new tile num tiles float rx new float num tiles float ry new float num tiles float rz new float num tiles graphics2d g dst create graphics g draw image src null null random random new random 0 float lastx 0 lasty 0 for int i 0 i num tiles i double angle double i 2 math pi num tiles float x cx width float math cos angle float y cy height float math sin angle g set color color black g set color color gethsb color float angle 1 1 if i 0 rz i 1 tile 2 random next float 1 ry i 1 tile random next float rz i 1 tile random next float general path p new general path p move to cx cy p line to lastx lasty p line to x y p close path shapes i 1 p rectangle r p get bounds r intersect r new rectangle int width int height r lastx x lasty y for int y 0 y iterations y int y1 int height y iterations int y2 int height y 1 iterations for int x 0 x iterations x int i y iterations x int x1 int width x iterations int x2 int width x 1 iterations rx i tile random next float ry i tile random next float rx i 0 ry i 0 rz i tile 2 random next float 1 shape p new rectangle x1 y1 x2 x1 y2 y1 shapes i new tile shapes i shape p shapes i x x1 x2 0 5f shapes i y y1 y2 0 5f shapes i vx width cx x shapes i vy height cy y shapes i w x2 x1 shapes i h y2 y1 for int i 0 i num tiles i float h float i num tiles double angle h 2 math pi float x transition width float math cos angle float y transition height float math sin angle tile tile shapes i rectangle r tile shape get bounds affine transform t g get transform x tile x transition tile vx y tile y transition tile vy g translate x y g translate tile w 0 5f tile h 0 5f g rotate transition rz i g scale float math cos transition rx i float math cos transition ry i g translate tile w 0 5f tile h 0 5f g set color color gethsb color h 1 1 shape clip g get clip g clip tile shape g draw image src 0 0 null g set clip clip g set transform t g dispose return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage getwidth getheight getwidth getheight imageradius bufferedimage bufferedimage numtiles numtiles numtiles numtiles numtiles creategraphics drawimage numtiles numtiles setcolor setcolor gethsbcolor nextfloat nextfloat nextfloat generalpath generalpath moveto lineto lineto closepath getbounds nextfloat nextfloat nextfloat numtiles numtiles getbounds affinetransform gettransform setcolor gethsbcolor getclip drawimage setclip settransform override public string to string return transition shatter tostring public class null long callback extends long callback override public long get return 0l nulllongcallback longcallback override public void set long val throws invalid config value exception ignore invalidconfigvalueexception protected own message messageuri newuri freeneturi new realuri string newid message list new message list messageuri new threaduri messageuri new parenturi set board new boards board new reply to board ft identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception super newuri new realuri newid new message list new threaduri new parenturi new boards new reply to board new author new title new date new text new attachments ownmessage newrealuri messagelist newmessagelist newthreaduri newparenturi newboards newreplytoboard ftidentity newauthor newtitle newdate newtext newattachments invalidparameterexception newrealuri newmessagelist newthreaduri newparenturi newboards newreplytoboard newauthor newtitle newdate newtext newattachments override for synchronization override public synchronized messageuri geturi return muri generate the insert uri for a message public abstract freeneturi get inserturi getinserturi throws runtime exception if the message was not inserted yet and therefore the real uri is unknown return the chk uri of the message public synchronized freeneturi get realuri if m realuri null throw new runtime exception get realuri called on the not inserted message this return m realuri runtimeexception getrealuri mrealuri runtimeexception getrealuri mrealuri public synchronized void set message list own message list new message list m message list new message list store setmessagelist ownmessagelist newmessagelist mmessagelist newmessagelist public synchronized boolean was inserted return m realuri null wasinserted mrealuri public synchronized void mark as inserted freeneturi my realuri m realuri my realuri store markasinserted myrealuri mrealuri myrealuri static final int segment length 128 1024 public void write long pos byte buf throw new unsupported operation exception zip file write segment_length unsupportedoperationexception zipfile public int read long pos byte buf try int seg int pos segment length zip entry e entries seg int size int e get size if e curr entry input stream in file get input stream e int rc offs 0 while offs size rc in read segment offs size offs 0 offs rc if offs size throw new storage error storage error file access error curr entry e int offs int pos long seg segment length if offs size int len buf length size offs buf length size offs system arraycopy segment offs buf 0 len return len return 0 catch io exception x throw new storage error storage error file access error segment_length zipentry getsize currentry inputstream getinputstream storageerror storageerror file_access_error currentry segment_length ioexception storageerror storageerror file_access_error public void sync public boolean try lock boolean shared return true trylock public void lock boolean shared public void unlock public void close try file close catch io exception x throw new storage error storage error file access error ioexception storageerror storageerror file_access_error public long length return long entries length 1 segment length entries entries length 1 get size segment_length getsize constructor of comressed file param path path to the archieve previously prepared by compress database utility public compressed file string path try file new zip file path int n entries file size entries new zip entry n entries enumeration ee file entries for int i 0 ee has more elements i entries i zip entry ee next element segment new byte segment length curr entry null catch io exception x throw new storage error storage error file access error compressdatabase compressedfile zipfile nentries zipentry nentries hasmoreelements zipentry nextelement segment_length currentry ioexception storageerror storageerror file_access_error public bucket compress bucket data bucket factory bf long max read length long max write length throws io exception compression output size exception if max read length 0 throw new illegal argument exception bucket output bf make bucket max write length input stream is null output stream os null gzip output stream gos null try is data get input stream os new buffered output stream output get output stream counted output stream cos new counted output stream os gos new gzip output stream cos long read 0 bigger input buffer so can compress all at once won t hurt on i o either although most o ss will only return a page at a time byte buffer new byte 32768 while true int l int math min buffer length max read length read int x l 0 1 is read buffer 0 l if x 1 break if x 0 throw new io exception returned zero from read gos write buffer 0 x read x if cos written max write length throw new compression output size exception gos flush finally if is null is close if gos null gos close else if os null os close return output bucketfactory maxreadlength maxwritelength ioexception compressionoutputsizeexception maxreadlength illegalargumentexception makebucket maxwritelength inputstream outputstream gzipoutputstream getinputstream bufferedoutputstream getoutputstream countedoutputstream countedoutputstream gzipoutputstream oss maxreadlength ioexception maxwritelength compressionoutputsizeexception public bucket decompress bucket data bucket factory bf long max length long max check size length bucket preferred throws io exception compression output size exception bucket output if preferred null output preferred else output bf make bucket max length input stream is null output stream os null try is data get input stream os output get output stream decompress is os max length max check size length os close os null is close is null return output finally if is null closer close is if os null closer close os bucketfactory maxlength maxchecksizelength ioexception compressionoutputsizeexception makebucket maxlength inputstream outputstream getinputstream getoutputstream maxlength maxchecksizelength private long decompress input stream is output stream os long max length long max check size bytes throws io exception compression output size exception gzip input stream gis new gzip input stream is long written 0 byte buffer new byte 4096 while true int l int math min buffer length max length written we can over read to determine whether we have over read we enforce maximum size this way fixme there is probably a better way to do this int x gis read buffer 0 buffer length if l x logger normal this l l x x written written max length max length throwing a compression output size exception if max check size bytes 0 written x while true l int math min buffer length max length max check size bytes written x gis read buffer 0 l if x 1 throw new compression output size exception written if x 0 throw new io exception returned zero from read written x throw new compression output size exception if x 1 return written if x 0 throw new io exception returned zero from read os write buffer 0 x written x inputstream outputstream maxlength maxchecksizebytes ioexception compressionoutputsizeexception gzipinputstream gzipinputstream maxlength maxlength maxlength compressionoutputsizeexception maxchecksizebytes maxlength maxchecksizebytes compressionoutputsizeexception ioexception compressionoutputsizeexception ioexception public int decompress byte dbuf int i int j byte output throws compression output size exception didn t work with inflater fixme fix sometimes to use inflater format issue byte array input stream bais new byte array input stream dbuf i j byte array output stream baos new byte array output stream output length int bytes 0 try bytes int decompress bais baos output length 1 catch io exception e impossible throw new error got io exception e get message e byte buf baos to byte array system arraycopy buf 0 output 0 bytes return bytes compressionoutputsizeexception bytearrayinputstream bytearrayinputstream bytearrayoutputstream bytearrayoutputstream ioexception ioexception getmessage tobytearray public static final semaphore compressor semaphore new semaphore get max running compression threads public real compressor executor e this exec e compressorsemaphore getmaxrunningcompressionthreads realcompressor public void set client context client context context this context context setclientcontext clientcontext public int get priority return native thread high priority getpriority nativethread high_priority public synchronized void enqueue new job compress job j awaitingjobs add j if logger should log logger minor this logger minor this enqueueing compression job j notify all enqueuenewjob compressjob _awaitingjobs shouldlog notifyall public void run logger normal this starting real compressor while true compress job current job null try synchronized this current job awaitingjobs poll if current job null wait continue compressor semaphore acquire catch interrupted exception e logger error this caught e get message e continue final compress job final job current job exec execute new prio runnable public void run freenet support logger os thread logpid this try try final job try compress context catch insert exception e final job on failure e null context catch out of memory error e oom handler handleoom e system err println off thread compressor thread above failed might not be heap so try anyway final job on failure new insert exception insert exception internal error e null null context catch throwable t logger error this caught in off thread compressor t t system err println caught in off thread compressor t t print stack trace try to fail gracefully final job on failure new insert exception insert exception internal error t null null context catch throwable t logger error this caught t in this t finally compressor semaphore release public int get priority return native thread min priority compressor thread for current job realcompressor compressjob currentjob currentjob _awaitingjobs currentjob compressorsemaphore interruptedexception getmessage compressjob finaljob currentjob priorunnable osthread finaljob trycompress insertexception finaljob onfailure outofmemoryerror oomhandler offthreadcompressor finaljob onfailure insertexception insertexception internal_error offthreadcompressor offthreadcompressor printstacktrace finaljob onfailure insertexception insertexception internal_error compressorsemaphore getpriority nativethread min_priority currentjob exec execute new prio runnable public void run freenet support logger os thread logpid this try try final job try compress context catch insert exception e final job on failure e null context catch out of memory error e oom handler handleoom e system err println off thread compressor thread above failed might not be heap so try anyway final job on failure new insert exception insert exception internal error e null null context catch throwable t logger error this caught in off thread compressor t t system err println caught in off thread compressor t t print stack trace try to fail gracefully final job on failure new insert exception insert exception internal error t null null context catch throwable t logger error this caught t in this t finally compressor semaphore release priorunnable osthread finaljob trycompress insertexception finaljob onfailure outofmemoryerror oomhandler offthreadcompressor finaljob onfailure insertexception insertexception internal_error offthreadcompressor offthreadcompressor printstacktrace finaljob onfailure insertexception insertexception internal_error compressorsemaphore public int get priority return native thread min priority getpriority nativethread min_priority public boolean object can new object container container logger error this not storing real compressor in database new exception error return false objectcannew objectcontainer realcompressor private static int get max running compression threads int max running threads 1 string os name system get property os name if os name index of windows 1 os name to lower case index of mac os x 0 native thread using native code os x niceness is really weak so we don t want any more background cpu load than necessary also on non windows we need the native threads library to be working max running threads 1 else most other o ss will have reasonable niceness so go by ram runtime r runtime get runtime int max r available processors fixme this may change in a vm poll it long max memory r max memory if max memory 128 1024 1024 max 1 else one compressor thread per 128mb of ram available core max math min max int math min integer max value max memory 128 1024 1024 max running threads max logger minor real compressor class maximum compressor threads max running threads return max running threads getmaxrunningcompressionthreads maxrunningthreads osname getproperty osname indexof osname tolowercase indexof nativethread usingnativecode maxrunningthreads oss getruntime availableprocessors maxmemory maxmemory maxmemory max_value maxmemory maxrunningthreads realcompressor maxrunningthreads maxrunningthreads public final class exclusion composite extends rgb composite public exclusion composite float alpha super alpha exclusioncomposite rgbcomposite exclusioncomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir multiply255 sr 255 dir dir dog dig multiply255 sg 255 dig dig dob dib multiply255 sb 255 dib dib float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public warp grid int rows int cols int w int h this rows rows this cols cols x grid new float rows cols y grid new float rows cols int index 0 for int row 0 row rows row for int col 0 col cols col x grid index float col w 1 cols 1 y grid index float row h 1 rows 1 index warpgrid xgrid ygrid xgrid ygrid add a new row to the grid before must be in the range 1 rows 1 i e you can only add rows inside the grid public void add row int before int size rows 1 cols float x new float size float y new float size rows int i 0 int j 0 for int row 0 row rows row for int col 0 col cols col int k j col int l i col if row before x k x grid l x grid k 2 y k y grid l y grid k 2 else x k x grid l y k y grid l if row before 1 i cols j cols x grid x y grid y addrow xgrid xgrid ygrid ygrid xgrid ygrid xgrid ygrid add a new column to the grid before must be in the range 1 cols 1 i e you can only add columns inside the grid public void add col int before int size rows cols 1 float x new float size float y new float size cols int i 0 int j 0 for int row 0 row rows row int i row cols 1 int j row cols for int col 0 col cols col if col before x j x grid i x grid i 1 2 y j y grid i y grid i 1 2 else x j x grid i y j y grid i i j x grid x y grid y addcol xgrid xgrid ygrid ygrid xgrid ygrid xgrid ygrid remove a row from the grid public void remove row int r int size rows 1 cols float x new float size float y new float size rows int i 0 int j 0 for int row 0 row rows row for int col 0 col cols col int k j col int l i col x k x grid l y k y grid l if row r 1 i cols i cols j cols x grid x y grid y removerow xgrid ygrid xgrid ygrid remove a column from the grid public void remove col int r int size rows cols 1 float x new float size float y new float size cols for int row 0 row rows row int i row cols 1 int j row cols for int col 0 col cols col x j x grid i y j y grid i if col r 1 i i j x grid x y grid y removecol xgrid ygrid xgrid ygrid public void lerp float t warp grid destination warp grid intermediate if rows destination rows cols destination cols throw new illegal argument exception source and destination are different sizes if rows intermediate rows cols intermediate cols throw new illegal argument exception source and intermediate are different sizes int index 0 for int row 0 row rows row for int col 0 col cols col intermediate x grid index float image math lerp t x grid index destination x grid index intermediate y grid index float image math lerp t y grid index destination y grid index index warpgrid warpgrid illegalargumentexception illegalargumentexception xgrid imagemath xgrid xgrid ygrid imagemath ygrid ygrid public void warp int in pixels int cols int rows warp grid source grid warp grid dest grid int out pixels try int x y int u v int intermediate warp grid splines if source grid rows dest grid rows source grid cols dest grid cols throw new illegal argument exception source and destination grids are different sizes int size math max cols rows float xrow new float size float yrow new float size float scale new float size 1 float interpolated new float size 1 int grid cols source grid cols int grid rows source grid rows splines new warp grid rows grid cols 1 1 for u 0 u grid cols u int i u for v 0 v grid rows v xrow v source grid x grid i yrow v source grid y grid i i grid cols interpolate spline yrow xrow 0 grid rows interpolated 0 rows i u for y 0 y rows y splines x grid i interpolated y i grid cols for u 0 u grid cols u int i u for v 0 v grid rows v xrow v dest grid x grid i yrow v dest grid y grid i i grid cols interpolate spline yrow xrow 0 grid rows interpolated 0 rows i u for y 0 y rows y splines y grid i interpolated y i grid cols first pass warp x using splines intermediate new int rows cols int offset 0 for y 0 y rows y fit spline to x intercepts resample over all cols interpolate spline splines x grid splines y grid offset grid cols scale 0 cols scale cols cols image math resample in pixels intermediate cols y cols 1 scale offset grid cols create table of y intercepts for intermediate mesh s hor splines splines new warp grid grid rows cols 1 1 offset 0 int offset2 0 for v 0 v grid rows v interpolate spline source grid x grid source grid y grid offset grid cols splines x grid offset2 cols offset grid cols offset2 cols offset 0 offset2 0 for v 0 v grid rows v interpolate spline dest grid x grid dest grid y grid offset grid cols splines y grid offset2 cols offset grid cols offset2 cols second pass warp y for x 0 x cols x int i x for v 0 v grid rows v xrow v splines x grid i yrow v splines y grid i i cols interpolate spline xrow yrow 0 grid rows scale 0 rows scale rows rows image math resample intermediate out pixels rows x cols scale catch exception e e print stack trace inpixels warpgrid sourcegrid warpgrid destgrid outpixels warpgrid sourcegrid destgrid sourcegrid destgrid illegalargumentexception gridcols sourcegrid gridrows sourcegrid warpgrid gridcols gridcols gridrows sourcegrid xgrid sourcegrid ygrid gridcols interpolatespline gridrows xgrid gridcols gridcols gridrows destgrid xgrid destgrid ygrid gridcols interpolatespline gridrows ygrid gridcols interpolatespline xgrid ygrid gridcols imagemath inpixels gridcols warpgrid gridrows gridrows interpolatespline sourcegrid xgrid sourcegrid ygrid gridcols xgrid gridcols gridrows interpolatespline destgrid xgrid destgrid ygrid gridcols ygrid gridcols gridrows xgrid ygrid interpolatespline gridrows imagemath outpixels printstacktrace protected void interpolate spline float x knots float y knots int offset int length float spliney int spline offset int spline length int index offset int end offset length 1 float x0 x1 float k0 k1 k2 k3 float c0 c1 c2 c3 x0 x knots index k0 k1 k2 y knots index x1 x knots index 1 k3 y knots index 1 for int i 0 i spline length i if index end i x knots index k0 k1 k1 k2 k2 k3 x0 x knots index index if index end x1 x knots index if index end k3 y knots index 1 else k3 k2 float t i x0 x1 x0 c3 m00 k0 m01 k1 m02 k2 m03 k3 c2 m10 k0 m11 k1 m12 k2 m13 k3 c1 m20 k0 m22 k2 c0 m31 k1 spliney spline offset i c3 t c2 t c1 t c0 interpolatespline xknots yknots splineoffset splinelength xknots yknots xknots yknots splinelength xknots xknots xknots yknots splineoffset protected void interpolate spline2 float x knots float y knots int offset float spliney int spline offset int spline length int index offset float leftx rightx float lefty righty leftx x knots index lefty y knots index rightx x knots index 1 righty y knots index 1 for int i 0 i spline length i if i x knots index leftx x knots index lefty y knots index index rightx x knots index righty y knots index float f i leftx rightx leftx spliney spline offset i lefty f righty lefty interpolatespline2 xknots yknots splineoffset splinelength xknots yknots xknots yknots splinelength xknots xknots yknots xknots yknots splineoffset suppress warnings deprecation public void set up throws exception super set up hash set board my boards1 new hash set board my boards1 add new board en board1 my boards1 add new board en board2 hash set board my boards2 new hash set board my boards2 add new board en board3 my boards2 add new board en board4 hash set board my boards3 new hash set board my boards3 add new board en board5 my boards3 add new board en board6 freeneturi author requestssk new freeneturi ssk nu16tncs7 isp ta9gw6nf8c3l qpjgfha2 kwt tom ju nk fj cioug sl6ipoe9gl nai9w cp1vpm8k181 gjw62 hhy so aqacaae freeneturi author insertssk new freeneturi ssk ykhv0x0k8jtrg olqwvs4s2 jvmnm64zv5vo nj mfz1nyi fj cioug sl6ipoe9gl nai9w cp1vpm8k181 gjw62 hhy so aqecaae string authorid wot identity getuid fromuri author requestssk wot own identity my author new wot own identity authorid author requestssk author insertssk nickname m message manager new wot message manager db null m messages new wot own message m message manager post message null my boards1 null my author title1 new date 2009 1900 06 1 01 text1 null m message manager post message null my boards2 null my author title2 new date 2008 1900 05 1 02 text2 null m message manager post message null my boards3 null my author title3 new date 2007 1900 04 1 03 text3 null freeneturi messageur is new freeneturi new freeneturi chk 7qms7 lkly ihbz88i0 u97lxrlks2ux nwzwq oj pd xn jw ila f sjww2mp wlz wx7 fgp zbb er yd lkqie1u srcn lbm aaia 8 new freeneturi chk 0yut4b eorqjcet qrl sgh bcw5rl7kq nm6 fbpo3 thz ty4 6 rzuh23 twpq0id qcg poxeyx7yb tgt nydd uj0i9dtq aaia 8 new freeneturi chk h4nfd tqgquq0 ckd pzvrs2f i ikjo cnf en s042j uxuw wk cr ktmvmy qzuo3f4v2 jlb87w jkk0dspmgj ivztyp8 aaia 8 m message list new wot own message list my author 123 m message list initialize transient db m message manager for int i 0 i m messages length i m messages i mark as inserted messageur is i m message list add message m messages i m hardcoded encoded message list new string xml version 1 0 encoding utf 8 standalone no freetalk testing message list version 1 message date 2009 06 01 id m messages 0 getid uri chk 7qms7 lkly ihbz88i0 u97lxrlks2ux nwzwq oj pd xn jw ila f sjww2mp wlz wx7 fgp zbb er yd lkqie1u srcn lbm aaia 8 board name en board1 board name en board2 message message date 2008 05 02 id m messages 1 getid uri chk 0yut4b eorqjcet qrl sgh bcw5rl7kq nm6 fbpo3 thz ty4 6 rzuh23 twpq0id qcg poxeyx7yb tgt nydd uj0i9dtq aaia 8 board name en board3 board name en board4 message message date 2007 04 03 id m messages 2 getid uri chk h4nfd tqgquq0 ckd pzvrs2f i ikjo cnf en s042j uxuw wk cr ktmvmy qzuo3f4v2 jlb87w jkk0dspmgj ivztyp8 aaia 8 board name en board5 board name en board6 message message list freetalk testing suppresswarnings setup setup hashset myboards1 hashset myboards1 myboards1 hashset myboards2 hashset myboards2 myboards2 hashset myboards3 hashset myboards3 myboards3 authorrequestssk ispta9gw6nf8c3lqpjgfha2kwttomjunk fjciougsl6ipoe9glnai9wcp1vpm8k181gjw62hhyso authorinsertssk ykhv0x0k8jtrgolqwvs4s2jvmnm64zv5vonjmfz1nyi fjciougsl6ipoe9glnai9wcp1vpm8k181gjw62hhyso wotidentity getuidfromuri authorrequestssk wotownidentity myauthor wotownidentity authorrequestssk authorinsertssk mmessagemanager wotmessagemanager mmessages wotownmessage mmessagemanager postmessage myboards1 myauthor mmessagemanager postmessage myboards2 myauthor mmessagemanager postmessage myboards3 myauthor messageuris 7qms7lklyihbz88i0 u97lxrlks2uxnwzwqojpdxnjw fsjww2mpwlzwx7fgpzbberydlkqie1usrcn 0yut4beorqjcetqrlsghbcw5rl7kqnm6fbpo3thzty4 6rzuh23 twpq0idqcgpoxeyx7ybtgtnydd h4nfdtqgquq0ckdpzvrs2f iikjocnfen s042juxuw wkcrktmvmyqzuo3f4v2jlb87wjkk0dspmgj mmessagelist wotownmessagelist myauthor mmessagelist initializetransient mmessagemanager mmessages mmessages markasinserted messageuris mmessagelist addmessage mmessages mhardcodedencodedmessagelist messagelist mmessages 7qms7lklyihbz88i0 u97lxrlks2uxnwzwqojpdxnjw fsjww2mpwlzwx7fgpzbberydlkqie1usrcn mmessages 0yut4beorqjcetqrlsghbcw5rl7kqnm6fbpo3thzty4 6rzuh23 twpq0idqcgpoxeyx7ybtgtnydd mmessages h4nfdtqgquq0ckdpzvrs2f iikjocnfen s042juxuw wkcrktmvmyqzuo3f4v2jlb87wjkk0dspmgj messagelist public void test encode throws transformer exception parser configuration exception no such message exception byte array output stream encoded message list new byte array output stream 4096 wot message listxml encode m message manager m message list encoded message list assert equals m hardcoded encoded message list encoded message list to string replace all r n testencode transformerexception parserconfigurationexception nosuchmessageexception bytearrayoutputstream encodedmessagelist bytearrayoutputstream wotmessagelistxml mmessagemanager mmessagelist encodedmessagelist assertequals mhardcodedencodedmessagelist encodedmessagelist tostring replaceall public void test decode throws exception byte array input stream is new byte array input stream m hardcoded encoded message list get bytes wot message list decoded list wot message listxml decode m message manager m message list get author m message list geturi is store the list of boards for each test message multi value table wot own message string message boards new multi value table wot own message string 2 m messages length for wot own message m m messages for board b m get boards message boards put m b get name now we check every message reference we receive from the decoded xml for each seen message board pair we remove that pair from the message boards table if the table is empty at the end the xml decoding has not dropped any of the pairs for message list message reference ref decoded list wot own message message wot own message m message manager get own message ref get messageid assert true a board was listed in the message list multiple times ref get board get name message boards contains element message ref get board get name message boards remove element message ref get board get name assert true not all boards or messages were specified in the message list message boards is empty testdecode bytearrayinputstream bytearrayinputstream mhardcodedencodedmessagelist getbytes wotmessagelist decodedlist wotmessagelistxml mmessagemanager mmessagelist getauthor mmessagelist multivaluetable wotownmessage messageboards multivaluetable wotownmessage mmessages wotownmessage mmessages getboards messageboards getname messageboards messagelist messagereference decodedlist wotownmessage wotownmessage mmessagemanager getownmessage getmessageid asserttrue getboard getname messageboards containselement getboard getname messageboards removeelement getboard getname asserttrue messageboards isempty public class jsql null pointer exception extends jsql runtime exception constructor of exception param target class of the target object in which field was not found param field name name of the locate field public jsql null pointer exception class target string field name super dereferencing null reference target field name jsqlnullpointerexception jsqlruntimeexception fieldname jsqlnullpointerexception fieldname fieldname public boolean has next boolean result if next null collection shared lock if iterator has next next iterator next result true else result false collection unlock else result true return result hasnext sharedlock hasnext public t next t obj next if obj null collection shared lock obj iterator next collection unlock else next null return obj sharedlock public thread safe iterator i resource collection iterator t iterator this collection collection this iterator iterator threadsafeiterator iresource public void remove collection exclusive lock iterator remove collection unlock next null exclusivelock override protected float transfer function float f f image math gain f gain f image math bias f bias return f transferfunction imagemath imagemath set the gain param gain the gain min value 0 max value 1 see get gain public void set gain float gain this gain gain initialized false getgain setgain get the gain return the gain see set gain public float get gain return gain setgain getgain set the bias param bias the bias min value 0 max value 1 see get bias public void set bias float bias this bias bias initialized false getbias setbias get the bias return the bias see set bias public float get bias return bias setbias getbias override public string to string return colors gain tostring private short compression algorithm 1 public clientssk block byte data byte headers clientssk key boolean dont verify throws ssk verify exception super data headers nodessk key get node key dont verify this key key compressionalgorithm clientsskblock dontverify sskverifyexception getnodekey dontverify public static clientssk block construct ssk block block clientssk key throws ssk verify exception constructor expects clientkey to have the pubkey in the case of binary blobs the block may have it instead if key get pub key null key set public key block get pub key return new clientssk block block data block headers key false clientsskblock sskblock sskverifyexception getpubkey setpublickey getpubkey clientsskblock decode the data public bucket decode bucket factory factory int max length boolean dont decompress throws key decode exception io exception we know the signature is valid because it is checked in the constructor we also know e h docname is valid byte decrypted headers new byte encrypted headers length system arraycopy headers headers offset decrypted headers 0 encrypted headers length rijndael aes try logger minor this crypto algorithm key crypto algorithm for get client key geturi aes new rijndael 256 256 catch unsupported cipher exception e throw new error e aes initialize key crypto key pcfb mode pcfb pcfb mode create aes ecb encrypted e h docname serves as iv pcfb reset key eh docname pcfb block decipher decrypted headers 0 decrypted headers length first 32 bytes are the key byte data decrypt key new byte data decrypt key length system arraycopy decrypted headers 0 data decrypt key 0 data decrypt key length aes initialize data decrypt key byte data output new byte data length system arraycopy data 0 data output 0 data length data decrypt key should be unique so use it as iv pcfb reset data decrypt key pcfb block decipher data output 0 data output length 2 bytes data length int data length decrypted headers data decrypt key length 0xff 8 decrypted headers data decrypt key length 1 0xff metadata flag is top bit if data length 32768 0 data length data length 32768 is metadata true if data length data length throw new ssk decode exception data length data length but data length data length compression algorithm short decrypted headers data decrypt key length 2 0xff 8 decrypted headers data decrypt key length 3 0xff decoded true if dont decompress return bucket tools make immutable bucket factory data output data length bucket b key decompress compression algorithm 0 data output data length factory math min max decompressed data length max length compression algorithm true return b bucketfactory maxlength dontdecompress keydecodeexception ioexception decryptedheaders encrypted_headers_length headersoffset decryptedheaders encrypted_headers_length cryptoalgorithm cryptoalgorithm getclientkey unsupportedcipherexception cryptokey pcfbmode pcfbmode ehdocname blockdecipher decryptedheaders decryptedheaders datadecryptkey data_decrypt_key_length decryptedheaders datadecryptkey data_decrypt_key_length datadecryptkey dataoutput dataoutput datadecryptkey blockdecipher dataoutput dataoutput datalength decryptedheaders data_decrypt_key_length decryptedheaders data_decrypt_key_length datalength datalength datalength ismetadata datalength sskdecodeexception datalength compressionalgorithm decryptedheaders data_decrypt_key_length decryptedheaders data_decrypt_key_length dontdecompress buckettools makeimmutablebucket dataoutput datalength compressionalgorithm dataoutput datalength max_decompressed_data_length maxlength compressionalgorithm public boolean is metadata if decoded throw new illegal state exception cannot read is metadata before decoded return is metadata ismetadata illegalstateexception ismetadata ismetadata public client key get client key return key clientkey getclientkey public short get compression codec return compression algorithm getcompressioncodec compressionalgorithm public byte memory decode throws key decode exception return memory decode false memorydecode keydecodeexception memorydecode decode into ram if short throws key decode exception public byte memory decode boolean dont decompress throws key decode exception try array bucket a array bucket decode new array bucket factory 32 1024 dont decompress return bucket tools to byte array a fixme catch io exception e throw new error e keydecodeexception memorydecode dontdecompress keydecodeexception arraybucket arraybucket arraybucketfactory dontdecompress buckettools tobytearray ioexception override public int hash code return super hash code key hash code hashcode hashcode hashcode override public boolean equals object o if o instanceof clientssk block return false clientssk block block clientssk block o if key equals block key return false return super equals o clientsskblock clientsskblock clientsskblock param base image the base image return an image with a gradient background added to the base image public buffered image add background buffered image base image color color from get config get background color from color color to get config get background color to int width base image get width int height base image get height create an opaque image buffered image image with background new buffered image width height buffered image type int rgb graphics2d graph graphics2d image with background get graphics rendering hints hints new rendering hints rendering hints key antialiasing rendering hints value antialias off hints add new rendering hints rendering hints key color rendering rendering hints value color render quality hints add new rendering hints rendering hints key alpha interpolation rendering hints value alpha interpolation quality hints add new rendering hints rendering hints key rendering rendering hints value render quality graph set rendering hints hints gradient paint paint new gradient paint 0 0 color from width height color to graph set paint paint graph fill new rectangle2d double 0 0 width height draw the transparent image over the background graph draw image base image 0 0 null return image with background baseimage bufferedimage addbackground bufferedimage baseimage colorfrom getconfig getbackgroundcolorfrom colorto getconfig getbackgroundcolorto baseimage getwidth baseimage getheight bufferedimage imagewithbackground bufferedimage bufferedimage type_int_rgb imagewithbackground getgraphics renderinghints renderinghints renderinghints key_antialiasing renderinghints value_antialias_off renderinghints renderinghints key_color_rendering renderinghints value_color_render_quality renderinghints renderinghints key_alpha_interpolation renderinghints value_alpha_interpolation_quality renderinghints renderinghints key_rendering renderinghints value_render_quality setrenderinghints gradientpaint gradientpaint colorfrom colorto setpaint drawimage baseimage imagewithbackground long created public info system created system current time millis 10 infosystem currenttimemillis public string getsnmpoid int index switch index case 0 ucd snmp mib mem total real 0 return 1 3 6 1 4 1 2021 4 5 0 case 1 ucd snmp mib mem avail real 0 return 1 3 6 1 4 1 2021 4 6 0 case 2 snm pv2 mib sys name 0 return 1 3 6 1 2 1 1 5 0 case 3 snm pv2 mib sys up time 0 return 1 3 6 1 2 1 1 3 0 case 4 ucd snmp mib mem total real 0 return 1 3 6 1 4 1 2021 4 5 case 5 ucd snmp mib mem avail real 0 return 1 3 6 1 4 1 2021 4 6 default return null memtotalreal memavailreal snmpv2 sysname snmpv2 sysuptime memtotalreal memavailreal public object getsnmp data string oid runtime r runtime get runtime system err println requesting oid if oid equals 1 3 6 1 2 1 1 3 0 snm pv2 mib sys up time 0 return new snmp time ticks system current time millis 10 created if oid equals 1 3 6 1 4 1 2021 4 5 0 ucd snmp mib mem total real 0 return new snmp integer32 r total memory if oid equals 1 3 6 1 4 1 2021 4 6 0 ucd snmp mib mem avail real 0 return new snmp integer32 r free memory if oid equals 1 3 6 1 2 1 1 5 0 snm pv2 mib sys name 0 return version node name version node version version build number if oid equals 1 3 6 1 4 1 2021 4 5 ucd snmp mib mem total real 0 return new snmp integer32 r total memory if oid equals 1 3 6 1 4 1 2021 4 6 ucd snmp mib mem avail real 0 return new snmp integer32 r free memory return null getsnmpdata getruntime snmpv2 sysuptime snmptimeticks currenttimemillis memtotalreal snmpinteger32 totalmemory memavailreal snmpinteger32 freememory snmpv2 sysname nodename nodeversion buildnumber memtotalreal snmpinteger32 totalmemory memavailreal snmpinteger32 freememory renders a word to an image param word the word to be rendered param width the width of the image to be created param height the height of the image to be created return the buffered image created from the word public buffered image render word string word int width int height int font size get config get text producer font size font fonts get config get text producer fonts font size color color get config get text producer font color buffered image image new buffered image width height buffered image type int argb graphics2d g2d image create graphics g2d set color color rendering hints hints new rendering hints rendering hints key antialiasing rendering hints value antialias on hints add new rendering hints rendering hints key rendering rendering hints value render quality g2d set rendering hints hints font render context frc g2d get font render context random random new random int start posx width 2 word length int start posy height font size 5 font size char word chars word to char array for int i 0 i word chars length i font chosen font fonts random next int fonts length g2d set font chosen font char char to draw new char word chars i glyph vector gv chosen font create glyph vector frc char to draw double char width gv get visual bounds get width g2d draw chars char to draw 0 char to draw length start posx start posy start posx start posx int char width 2 return image bufferedimage bufferedimage renderword fontsize getconfig gettextproducerfontsize getconfig gettextproducerfonts fontsize getconfig gettextproducerfontcolor bufferedimage bufferedimage bufferedimage type_int_argb creategraphics setcolor renderinghints renderinghints renderinghints key_antialiasing renderinghints value_antialias_on renderinghints renderinghints key_rendering renderinghints value_render_quality setrenderinghints fontrendercontext getfontrendercontext startposx startposy fontsize fontsize wordchars tochararray wordchars chosenfont nextint setfont chosenfont chartodraw wordchars glyphvector chosenfont createglyphvector chartodraw charwidth getvisualbounds getwidth drawchars chartodraw chartodraw startposx startposy startposx startposx charwidth public modify peer note simple field set fs this fs fs identifier fs get identifier fs remove value identifier modifypeernote simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied modify peer note requires full access identifier false string node identifier fs get node identifier if node identifier null throw new message invalid exception protocol error message missing field error node identifier field missing identifier false peer node pn node get peer node node identifier if pn null fcp message msg new unknown node identifier message node identifier identifier handler output handler queue msg return if pn instanceof darknet peer node throw new message invalid exception protocol error message darknet only modify peer note only available for darknet peers identifier false darknet peer node dpn darknet peer node pn int peer note type try peer note type fs get int peer note type catch fs parse exception e throw new message invalid exception protocol error message invalid field error parsing peer note type field e get message identifier false string encoded note text fs get note text if encoded note text null throw new message invalid exception protocol error message missing field error note text field missing identifier false string note text fixme this should be generalized for multiple peer notes per peer after peer node is similarly generalized try note text new string base64 decode encoded note text catch illegal base64 exception e logger error this bad base64 encoding when decoding a fcp received private darknet comment simple field set e return if peer note type node peer note type private darknet comment dpn set private darknet comment note note text else fcp message msg new unknown peer note type message peer note type identifier handler output handler queue msg return handler output handler queue new peer note node identifier note text peer note type identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied modifypeernote nodeidentifier nodeidentifier nodeidentifier messageinvalidexception protocolerrormessage missing_field nodeidentifier peernode getpeernode nodeidentifier fcpmessage unknownnodeidentifiermessage nodeidentifier outputhandler darknetpeernode messageinvalidexception protocolerrormessage darknet_only modifypeernote darknetpeernode darknetpeernode peernotetype peernotetype getint peernotetype fsparseexception messageinvalidexception protocolerrormessage invalid_field peernotetype getmessage encodednotetext notetext encodednotetext messageinvalidexception protocolerrormessage missing_field notetext notetext peernode notetext encodednotetext illegalbase64exception simplefieldset peernotetype peer_note_type_private_darknet_comment setprivatedarknetcommentnote notetext fcpmessage unknownpeernotetypemessage peernotetype outputhandler outputhandler peernote nodeidentifier notetext peernotetype override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private static final string svn revision custom static string get svn revision return svn revision svnrevision getsvnrevision svnrevision get a list of fields which the database should create an index on public static string get indexed fields return new string m name getindexedfields mname public static string get board message link indexed fields todo ugly find a better way return new string m board m message m message index getboardmessagelinkindexedfields mboard mmessage mmessageindex public static string get allowed language codes return locale getiso languages getallowedlanguagecodes getisolanguages create a board you have to store it yourself after creation param new name the name of the board for restrictions see code is name valid code throws invalid parameter exception if none or an invalid name is given public board string new name throws invalid parameter exception if new name null new name length 0 throw new illegal argument exception empty board name if is name valid new name throw new invalid parameter exception board names have to be either in english or have an iso language code at the beginning followed by a dot fixme validate name and description m name new name to lower case m first seen date current timeutc get m latest message date null newname isnamevalid invalidparameterexception newname invalidparameterexception newname newname illegalargumentexception isnamevalid newname invalidparameterexception mname newname tolowercase mfirstseendate currenttimeutc mlatestmessagedate has to be used after loading a ft board object from the database to initialize the transient fields public void initialize transient ext object container mydb message manager my message manager assert mydb null assert my message manager null db mydb m message manager my message manager ftboard initializetransient extobjectcontainer messagemanager mymessagemanager mymessagemanager mmessagemanager mymessagemanager store this object in the database you have to initialize transient before public synchronized void store fixme check for duplicates synchronized db lock if db ext is stored this db ext is active this throw new runtime exception trying to store a non active board object db store this db commit initializetransient isstored isactive runtimeexception check if a board name is valid board names are required to begin with a known language code and may not contain any blacklisted characters formatting characters must be properly paired within each part of the name special formatting characters may be needed e g for some arabic or hebrew group names to be displayed properly public static boolean is name valid string name paranoia checks if name null name length 0 return false check maximum length if name length max boardname text length return false check for illegal characters if string validity checker contains no linebreaks name string validity checker contains no invalid characters name string validity checker contains no control characters name string validity checker contains noidn blacklist characters name return false for character c name to char array if disallowed name characters index of c 1 return false check for invalid formatting characters each dot separated part of the input string must be valid on its own string parts name split if parts length 2 return false for int i 0 i parts length i if parts i length 0 string validity checker contains no invalid formatting parts i return false first part of name must be a recognized language code return iso languages contains parts 0 isnamevalid max_boardname_text_length stringvaliditychecker containsnolinebreaks stringvaliditychecker containsnoinvalidcharacters stringvaliditychecker containsnocontrolcharacters stringvaliditychecker containsnoidnblacklistcharacters tochararray disallowed_name_characters indexof stringvaliditychecker containsnoinvalidformatting isolanguages return the name public string get name return m name getname mname public date get first seen date return m first seen date getfirstseendate mfirstseendate public synchronized date get latest message date return m latest message date getlatestmessagedate mlatestmessagedate public synchronized string get description ft own identity viewer fixme implement return getdescription ftownidentity compare boards by comparing their names provided so we can sort an array of boards public int compare to board b return get name compare to b get name compareto getname compareto getname called by the code ft message manager code to add a just received message to the board the job for this function is to find the right place in the thread tree for the new message and to move around older messages if a parent message of them is received public synchronized void add message message new message synchronized m message manager if new message instanceof own message we do not add the message to the boards it is posted to because the user should only see the message if it has been downloaded successfully this helps the user to spot problems if he does not see his own messages we can hope that he reports a bug throw new illegal argument exception adding own messages to a board is not allowed new message initialize transient db m message manager new message store synchronized board message link class new board message link this new message get free message index store db if new message is thread message parent thread null try parent thread find parent thread new message get message new message set thread parent thread catch no such message exception e try new message set parent m message manager get new message get parentid todo this allows crossposting figure out whether we need to handle it specially catch no such message exception e the message is an orphan if parent thread null the message is an absolute orphan fixme the message manager should try to download the parent message if it s poster has enough trust if it is programmed to do that it will check its hashtable whether the parent message already exists we also do that here therefore when implementing parent message downloading please do the hashtable checking only once link orphans to new parent new message if m latest message date null new message get date after m latest message date m latest message date new message get date ftmessagemanager addmessage newmessage mmessagemanager newmessage ownmessage illegalargumentexception ownmessages newmessage initializetransient mmessagemanager newmessage boardmessagelink boardmessagelink newmessage getfreemessageindex newmessage isthread parentthread parentthread findparentthread newmessage getmessage newmessage setthread parentthread nosuchmessageexception newmessage setparent mmessagemanager newmessage getparentid nosuchmessageexception parentthread messagemanager linkorphanstonewparent newmessage mlatestmessagedate newmessage getdate mlatestmessagedate mlatestmessagedate newmessage getdate assumes that the transient fields of the new message are initialized already private synchronized void link orphans to new parent message new message if new message is thread iterator message absolute orphans absolute orphan iterator new message getid while absolute orphans has next search in the absolute orphans for messages which belong to this thread message orphan absolute orphans next orphan set thread new message try if orphan get parenturi equals new message geturi orphan set parent new message catch no such message exception e logger error this message is reply to thread but parenturi null orphan geturi else try message parent thread new message get thread search in its parent thread for its children for message parent thread child parent thread get children this try if parent thread child get parenturi equals new message geturi we found its parent yeah parent thread child set parent new message it s a child of the new message not of the parent thread catch no such message exception e logger error this message is reply to thread but parenturi null parent thread child geturi catch no such message exception e the new message is an absolute orphan find its children amongst the other absolute orphans iterator message absolute orphans absolute orphan iterator new message getid while absolute orphans has next search in the orphans for messages which belong to this message message orphan absolute orphans next the following if could be joined into the db4o query in absolute orphan iterator i did not do it because we could cache the list of absolute orphans locally try if orphan get parenturi equals new message geturi orphan set parent new message catch no such message exception error logger error this should not happen error newmessage linkorphanstonewparent newmessage newmessage isthread absoluteorphans absoluteorphaniterator newmessage absoluteorphans hasnext absoluteorphans setthread newmessage getparenturi newmessage setparent newmessage nosuchmessageexception parentthread newmessage getthread parentthreadchild parentthread getchildren parentthreadchild getparenturi newmessage parentthreadchild setparent newmessage newmessage parentthread nosuchmessageexception parentthreadchild nosuchmessageexception absoluteorphans absoluteorphaniterator newmessage absoluteorphans hasnext absoluteorphans absoluteorphaniterator getparenturi newmessage setparent newmessage nosuchmessageexception finds the parent thread of a message in the database the transient fields of the returned message will be initialized already throws no such message exception suppress warnings unchecked private synchronized message reference find parent thread message m throws no such message exception query q db query q constrain board message link class fixme this query has to be optimized maybe we should store the thread id in the board message link or we could first just query for message objects with the given id ignoring board message links and then query for a board message link which links the resulting message to the target board this could be sufficiently fast as the number of messages which are posted to multiple boards will be very small q descend m board constrain this identity q descend m message descend mid constrain m get threadid object set message reference parents q execute assert parents size 1 if parents size 0 throw new no such message exception m get threadid else message reference parent thread parents next assert parent thread get message getid equals m get threadid the query works important it is possible that we receive a message which has a parent thread uri specified but the message at that uri is not really a thread but just a reply to a thread we must not return the thread which is specified as thread in the referred uri instead because the thread id of that one is different to the thread id which is calculated from the false thread uri to explain it in other words the given message has a wrong thread uri stored caused by a malfunction in the client which inserted the message and the thread id which is stored in that message is calculated from the uri therefore it is also wrong if this function did return the real thread for the given message then it would return false information because the id of the returned thread would not match the id which is stored in the given message further we also cannot return the message which is referred by the false uri because it is not a thread other functions in freetalk rely on the fact that messages which are said to be threads are really threads so that is the reason why the following if statement is necessary notice that this comment was written after i figured out that messages are not being displayed if the if is left out so please do not remove it in the future if parent thread get message is thread false throw new no such message exception return parent thread nosuchmessageexception suppresswarnings messagereference findparentthread nosuchmessageexception boardmessagelink boardmessagelink boardmessagelinks boardmessagelink mboard mmessage getthreadid objectset messagereference nosuchmessageexception getthreadid messagereference parentthread parentthread getmessage getthreadid parentthread getmessage isthread nosuchmessageexception parentthread get all threads in the board the view is specified to the ft own identity displaying it therefore you have to pass one as parameter the transient fields of the returned messages will be initialized already param identity the identity viewing the board return an iterator of the message which the identity will see based on its trust levels suppress warnings unchecked public synchronized iterator message reference thread iterator final ft own identity identity return new iterator message reference private final ft own identity m identity identity private final iterator board message link iter private message reference next fixme if db4o supports precompiled queries this one should be stored precompiled reason we sort the threads by date maybe we can just keep the query object and call q execute as many times as we like to or somehow tell db4o to keep a per board thread index which is sorted by date this would be the best solution query q db query q constrain board message link class q descend m board constrain board this q descend m message descend m thread constrain null identity we require m parent to be null because this allows discussions where only the head message is missing to be displayed as a single thread instead of displaying a bunch of single messages where each would appear to be a thread q descend m message descend m parent constrain null identity q descend m message descend m date order descending iter q execute iterator next iter has next iter next null public boolean has next for next null next iter has next iter next null if m identity wants messages from next get message get author return true return false public message reference next message reference result has next next null next iter has next iter next null return result public void remove throw new unsupported operation exception ftownidentity suppresswarnings messagereference threaditerator ftownidentity messagereference ftownidentity midentity boardmessagelink messagereference boardmessagelink mboard mmessage mthread mparent mmessage mparent mmessage mdate orderdescending hasnext hasnext hasnext midentity wantsmessagesfrom getmessage getauthor messagereference messagereference hasnext hasnext unsupportedoperationexception public boolean has next for next null next iter has next iter next null if m identity wants messages from next get message get author return true return false hasnext hasnext midentity wantsmessagesfrom getmessage getauthor public message reference next message reference result has next next null next iter has next iter next null return result messagereference messagereference hasnext hasnext public void remove throw new unsupported operation exception unsupportedoperationexception get an iterator over messages for which the parent thread with the given id was not known the transient fields of the returned messages will be initialized already suppress warnings unchecked private synchronized iterator message absolute orphan iterator final string threadid return new iterator message private final iterator board message link iter fixme this query should be accelerated the amount of absolute orphans is very small usually so we should configure db4o to keep a separate list of those query q db query q constrain board message link class q descend m board constrain board this identity q descend m message descend m threadid constrain threadid q descend m message descend m thread constrain null identity iter q execute iterator public boolean has next return iter has next public message next return iter next get message public void remove throw new unsupported operation exception suppresswarnings absoluteorphaniterator boardmessagelink boardmessagelink mboard mmessage mthreadid mmessage mthread hasnext hasnext getmessage unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public message next return iter next get message getmessage public void remove throw new unsupported operation exception unsupportedoperationexception which picks threads chosen by the viewer see thread iterator for how to do this suppress warnings unchecked public synchronized list message reference get all messages final boolean sort by message index ascending query q db query q constrain board message link class q descend m board constrain this identity if sort by message index ascending q descend m message index order ascending needed for nntp return q execute threaditerator suppresswarnings messagereference getallmessages sortbymessageindexascending boardmessagelink mboard sortbymessageindexascending mmessageindex orderascending suppress warnings unchecked public synchronized int get message index message message throws no such message exception query q db query q constrain board message link class q descend m message constrain message identity object set board message link result q execute if result size 0 throw new no such message exception message getid return result next get index suppresswarnings getmessageindex nosuchmessageexception boardmessagelink mmessage objectset boardmessagelink nosuchmessageexception getindex fixme this function counts all messages not only the ones which the viewer wants to see public synchronized int get last message index return get free message index 1 getlastmessageindex getfreemessageindex suppress warnings unchecked public synchronized message get message by index int index throws no such message exception query q db query q constrain board message link class q descend m board constrain this identity q descend m message index constrain index object set message reference result q execute if result size 0 throw new no such message exception return result next get message suppresswarnings getmessagebyindex nosuchmessageexception boardmessagelink mboard mmessageindex objectset messagereference nosuchmessageexception getmessage suppress warnings unchecked public synchronized list message reference get messages by minimum index int minimum index final boolean sort by message index ascending final boolean sort by message date ascending final query q db query q constrain board message link class q descend m board constrain this identity if minimum index 0 minimum index db4o provides no greater equal so we do it this way q descend m message index constrain minimum index greater if sort by message index ascending q descend m message index order ascending if sort by message date ascending q descend m message descend m date order ascending return q execute suppresswarnings messagereference getmessagesbyminimumindex minimumindex sortbymessageindexascending sortbymessagedateascending boardmessagelink mboard minimumindex minimumindex greaterequal mmessageindex minimumindex sortbymessageindexascending mmessageindex orderascending sortbymessagedateascending mmessage mdate orderascending suppress warnings unchecked public synchronized list message reference get messages by minimum date long minimum date final boolean sort by message index ascending final boolean sort by message date ascending final query q db query q constrain board message link class q descend m board constrain this identity if minimum date 0 minimum date db4o provides no greater equal so we do it this way q descend m message descend m date constrain minimum date greater if sort by message index ascending q descend m message index order ascending if sort by message date ascending q descend m message descend m date order ascending return q execute suppresswarnings messagereference getmessagesbyminimumdate minimumdate sortbymessageindexascending sortbymessagedateascending boardmessagelink mboard minimumdate minimumdate greaterequal mmessage mdate minimumdate sortbymessageindexascending mmessageindex orderascending sortbymessagedateascending mmessage mdate orderascending get the next free nntp index for a message please synchronize on board message link class when creating a message this method does not and cannot provide synchronization as creating a message is no atomic operation suppress warnings unchecked private int get free message index query q db query q constrain board message link class q descend m board constrain this identity q descend m message index order descending fixme use a db4o native query to find the maximum instead of sorting o n vs o n log n object set message reference result q execute return result size 0 1 result next get index 1 boardmessagelink suppresswarnings getfreemessageindex boardmessagelink mboard mmessageindex orderdescending objectset messagereference getindex get the number of messages in this board fixme this function counts all messages not only the ones which the viewer wants to see public synchronized int message count query q db query q constrain board message link class q descend m board constrain this identity return q execute size messagecount boardmessagelink mboard get the number of replies to the given thread fixme this function counts all replies not only the ones which the viewer wants to see public synchronized int thread reply count ft own identity viewer message thread return get all thread replies thread false size threadreplycount ftownidentity getallthreadreplies get all replies to the given thread sorted ascending by date if requested fixme this function returns all replies not only the ones which the viewer wants to see convert the function to an iterator which picks threads chosen by the viewer see thread iterator for how to do this suppress warnings unchecked public synchronized list message reference get all thread replies message thread final boolean sort by date ascending query q db query fixme this query is inefficient it should rather first query for objects of message class which have m threadid thread getid and then check whether a board message link to this board exists q constrain board message link class q descend m board constrain this identity q descend m message constrain thread identity not try q descend m message descend m threadid constrain thread is thread thread getid thread get threadid fixme for some reason m parent seems to stay null on some thread replies even though their parent is present in the database q descend m message descend m parent constrain null identity not catch no such message exception e throw new runtime exception message is no thread but parent threaduri null thread geturi if sort by date ascending q descend m message descend m date order ascending return q execute threaditerator suppresswarnings messagereference getallthreadreplies sortbydateascending mthreadid boardmessagelink boardmessagelink mboard mmessage mmessage mthreadid isthread getthreadid mparent mmessage mparent nosuchmessageexception runtimeexception parentthreaduri sortbydateascending mmessage mdate orderascending public interface message reference get the message to which this reference points public message get message messagereference getmessage public message get message get an unique index number of this message in the board where which the query for the message was executed this index number is needed for nntp public int get index getmessage getindex public board message link board my board message my message int my index assert my board null my message null m board my board m message my message m message index my index boardmessagelink myboard mymessage myindex myboard mymessage mboard myboard mmessage mymessage mmessageindex myindex public void store ext object container local db synchronized db lock if local db ext is stored this local db ext is active this throw new runtime exception trying to store a non active board message link object local db store this local db commit extobjectcontainer localdb localdb isstored localdb isactive runtimeexception boardmessagelink localdb localdb public int get index return m message index getindex mmessageindex public message get message we do not have to initialize m board and can assume that it is initialized because a board message link will only be loaded by the board it belongs to m message initialize transient m board db m board m message manager db activate m message 2 fixme figure out a reasonable depth return m message getmessage mboard boardmessagelink mmessage initializetransient mboard mboard mmessagemanager mmessage mmessage private static final long serial versionuid 1 public key verify exception string message super message serialversionuid keyverifyexception public key verify exception string message throwable cause super message cause keyverifyexception public key verify exception super keyverifyexception public key verify exception throwable cause super cause keyverifyexception public class snmp counter32 extends snmp type wrapper num public snmp counter32 super snmpcounter32 snmptypewrappernum snmpcounter32 public class snmp counter32 extends snmp type wrapper num public snmp counter32 super public snmp counter32 long value super value snmpcounter32 snmptypewrappernum snmpcounter32 snmpcounter32 public void set value long value todo make it prettier this value new long value int value system err println value cut from value to this value setvalue intvalue protected void init this typeid 0x41 session key peer node parent packet tracker tracker block cipher cipher byte session key this pn parent this packets tracker this session cipher cipher this session key session key sessionkey peernode packettracker blockcipher sessionkey sessioncipher sessionkey sessionkey override public string to string return super to string packets to string tostring tostring tostring public static final string code2 string int code switch code case continue return continue case ok return ok case partial content return partial content case bad request return bad request case not found return not found case precondition failed return precondition failed case invalid range return invalid range case internal server error return internal server error return code2string partial_content bad_request not_found precondition_failed invalid_range internal_server_error public http status set version set status code 0 set reason phrase httpstatus setversion setstatuscode setreasonphrase public http status string ver int code string reason set version ver set status code code set reason phrase reason httpstatus setversion setstatuscode setreasonphrase public http status string line str set line str httpstatus linestr linestr private string reason phrase public void set version string value version value reasonphrase setversion public void set status code int value status code value setstatuscode statuscode public void set reason phrase string value reason phrase value setreasonphrase reasonphrase public string get version return version getversion public int get status code return status code getstatuscode statuscode public string get reason phrase return reason phrase getreasonphrase reasonphrase final public static boolean is successful int stat code if 200 stat code stat code 300 return true return false issuccessful statcode statcode statcode public boolean is successful return is successful get status code issuccessful issuccessful getstatuscode public void set string line str if line str null set version http version set status code internal server error set reason phrase code2 string internal server error return try string tokenizer st new string tokenizer line str http status line delim if st has more tokens false return string ver st next token set version ver trim if st has more tokens false return string code str st next token int code 0 try code integer parse int code str catch exception e1 set status code code string reason while st has more tokens true if 0 reason length reason reason st next token set reason phrase reason trim catch exception e debug warning e linestr linestr setversion setstatuscode internal_server_error setreasonphrase code2string internal_server_error stringtokenizer stringtokenizer linestr status_line_delim hasmoretokens nexttoken setversion hasmoretokens codestr nexttoken parseint codestr setstatuscode hasmoretokens nexttoken setreasonphrase cretae a buffered image from an image producer param producer the image producer return a new type int argb buffered image public static buffered image create image image producer producer pixel grabber pg new pixel grabber producer 0 0 1 1 null 0 0 try pg grab pixels catch interrupted exception e throw new runtime exception image fetch interrupted if pg status image observer abort 0 throw new runtime exception image fetch aborted if pg status image observer error 0 throw new runtime exception image fetch error buffered image p new buffered image pg get width pg get height buffered image type int argb p setrgb 0 0 pg get width pg get height int pg get pixels 0 pg get width return p bufferedimage imageproducer imageproducer type_int_argb bufferedimage bufferedimage createimage imageproducer pixelgrabber pixelgrabber grabpixels interruptedexception runtimeexception imageobserver runtimeexception imageobserver runtimeexception bufferedimage bufferedimage getwidth getheight bufferedimage type_int_argb getwidth getheight getpixels getwidth convert an image into a type int argb buffered image if the image is already of this type the original image is returned unchanged param image the image to convert return the converted image public static buffered image convert image toargb image image if image instanceof buffered image buffered image image get type buffered image type int argb return buffered image image buffered image p new buffered image image get width null image get height null buffered image type int argb graphics2d g p create graphics g draw image image 0 0 null g dispose return p type_int_argb bufferedimage bufferedimage convertimagetoargb bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage bufferedimage bufferedimage getwidth getheight bufferedimage type_int_argb creategraphics drawimage returns a copy of a subimage of image this avoids the performance problems associated with buffered image get subimage param image the image param x the x position param y the y position param w the width param h the height return the subimage public static buffered image get subimage buffered image image int x int y int w int h buffered image new image new buffered image w h buffered image type int argb graphics2d g new image create graphics g draw rendered image image affine transform get translate instance x y g dispose return new image bufferedimage getsubimage bufferedimage getsubimage bufferedimage bufferedimage newimage bufferedimage bufferedimage type_int_argb newimage creategraphics drawrenderedimage affinetransform gettranslateinstance newimage clones a buffered image param image the image to clone return the cloned image public static buffered image clone image buffered image image buffered image new image new buffered image image get width image get height buffered image type int argb graphics2d g new image create graphics g draw rendered image image null g dispose return new image bufferedimage bufferedimage cloneimage bufferedimage bufferedimage newimage bufferedimage getwidth getheight bufferedimage type_int_argb newimage creategraphics drawrenderedimage newimage paint a check pattern used for a background to indicate image transparency param c the component to draw into param g the graphics objects param x the x position param y the y position param width the width param height the height public static void paint checked background component c graphics g int x int y int width int height if background image null background image new buffered image 64 64 buffered image type int argb graphics bg background image create graphics for int by 0 by 64 by 8 for int bx 0 bx 64 bx 8 bg set color bx by 8 0 color light gray color white bg fill rect bx by 8 8 bg dispose if background image null shape save clip g get clip rectangle r g get clip bounds if r null r new rectangle c get size r r intersection new rectangle x y width height g set clip r int w background image get width int h background image get height if w 1 h 1 int x1 r x w w int y1 r y h h int x2 r x r width w 1 w w int y2 r y r height h 1 h h for y y1 y y2 y h for x x1 x x2 x w g draw image background image x y c g set clip save clip paintcheckedbackground backgroundimage backgroundimage bufferedimage bufferedimage type_int_argb backgroundimage creategraphics setcolor lightgray fillrect backgroundimage saveclip getclip getclipbounds getsize setclip backgroundimage getwidth backgroundimage getheight drawimage backgroundimage setclip saveclip calculates the bounds of the non transparent parts of the given image param p the image return the bounds of the non transparent area public static rectangle get selected bounds buffered image p int width p get width int height p get height int maxx 0 maxy 0 minx width miny height boolean any selected false int y1 int pixels null for y1 height 1 y1 0 y1 pixels getrgb p 0 y1 width 1 pixels for int x 0 x minx x if pixels x 0xff000000 0 minx x maxy y1 any selected true break for int x width 1 x maxx x if pixels x 0xff000000 0 maxx x maxy y1 any selected true break if any selected break pixels null for int y 0 y y1 y pixels getrgb p 0 y width 1 pixels for int x 0 x minx x if pixels x 0xff000000 0 minx x if y miny miny y any selected true break for int x width 1 x maxx x if pixels x 0xff000000 0 maxx x if y miny miny y any selected true break if any selected return new rectangle minx miny maxx minx 1 maxy miny 1 return null getselectedbounds bufferedimage getwidth getheight anyselected anyselected anyselected anyselected anyselected anyselected anyselected compose src onto dst using the alpha of sel to interpolate between the two i can t think of a way to do this using alpha composite param src the source raster param dst the destination raster param sel the mask raster public static void compose through mask raster src writable raster dst raster sel int x src get minx int y src get miny int w src get width int h src get height int srcrgb null int selrgb null int dstrgb null for int i 0 i h i srcrgb src get pixels x y w 1 srcrgb selrgb sel get pixels x y w 1 selrgb dstrgb dst get pixels x y w 1 dstrgb int k x for int j 0 j w j int sr srcrgb k int dir dstrgb k int sg srcrgb k 1 int dig dstrgb k 1 int sb srcrgb k 2 int dib dstrgb k 2 int sa srcrgb k 3 int dia dstrgb k 3 float a selrgb k 3 255f float ac 1 a dstrgb k int a sr ac dir dstrgb k 1 int a sg ac dig dstrgb k 2 int a sb ac dib dstrgb k 3 int a sa ac dia k 4 dst set pixels x y w 1 dstrgb y alphacomposite composethroughmask writableraster getminx getminy getwidth getheight getpixels getpixels getpixels setpixels a convenience method for getting argb pixels from an image this tries to avoid the performance penalty of buffered image getrgb unmanaging the image param image a buffered image object param x the left edge of the pixel block param y the right edge of the pixel block param width the width of the pixel arry param height the height of the pixel arry param pixels the array to hold the returned pixels may be null return the pixels see setrgb public static int getrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb return int image get raster get data elements x y width height pixels return image getrgb x y width height pixels 0 width bufferedimage bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster getdataelements a convenience method for setting argb pixels in an image this tries to avoid the performance penalty of buffered image setrgb unmanaging the image param image a buffered image object param x the left edge of the pixel block param y the right edge of the pixel block param width the width of the pixel arry param height the height of the pixel arry param pixels the array of pixels to set see getrgb public static void setrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb image get raster set data elements x y width height pixels else image setrgb x y width height pixels 0 width bufferedimage bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster setdataelements construct a gamma filter public gamma filter this 1 0f gammafilter gammafilter construct a gamma filter param gamma the gamma level for all rgb channels public gamma filter float gamma this gamma gamma gamma gammafilter gammafilter construct a gamma filter param r gamma the gamma level for the red channel param g gamma the gamma level for the blue channel param b gamma the gamma level for the green channel public gamma filter float r gamma float g gamma float b gamma set gamma r gamma g gamma b gamma gammafilter rgamma ggamma bgamma gammafilter rgamma ggamma bgamma setgamma rgamma ggamma bgamma set the gamma levels param r gamma the gamma level for the red channel param g gamma the gamma level for the blue channel param b gamma the gamma level for the green channel see get gamma public void set gamma float r gamma float g gamma float b gamma this r gamma r gamma this g gamma g gamma this b gamma b gamma initialized false rgamma ggamma bgamma getgamma setgamma rgamma ggamma bgamma rgamma rgamma ggamma ggamma bgamma bgamma set the gamma level param gamma the gamma level for all rgb channels see get gamma public void set gamma float gamma set gamma gamma gamma gamma getgamma setgamma setgamma get the gamma level return the gamma level for all rgb channels see set gamma public float get gamma return r gamma setgamma getgamma rgamma override protected void initialize r table make table r gamma if g gamma r gamma g table r table else g table make table g gamma if b gamma r gamma b table r table else if b gamma g gamma b table g table else b table make table b gamma rtable maketable rgamma ggamma rgamma gtable rtable gtable maketable ggamma bgamma rgamma btable rtable bgamma ggamma btable gtable btable maketable bgamma private int make table float gamma int table new int 256 for int i 0 i 256 i int v int 255 0 math pow i 255 0 1 0 gamma 0 5 if v 255 v 255 table i v return table maketable override public string to string return colors gamma tostring public class invert filter extends point filter public invert filter can filter index color model true invertfilter pointfilter invertfilter canfilterindexcolormodel override public int filterrgb int x int y int rgb int a rgb 0xff000000 return a rgb 0x00ffffff override public string to string return colors invert tostring create one for a global queued request not made by fcp throws identifier collision exception throws not allowed exception throws io exception public client get fcp client global client freeneturi uri boolean ds only boolean ignoreds int max splitfile retries int max non splitfile retries long max output length short return type boolean persist reboot only string identifier int verbosity short prio class file return filename file return temp filename fcp server server object container container throws identifier collision exception not allowed exception io exception super uri identifier verbosity null global client prio class persist reboot only client request persist reboot client request persist forever null true container fctx new fetch context server default fetch context fetch context identical mask false null fctx event producer add event listener this fctx local request only ds only fctx ignore store ignoreds fctx max non splitfile retries max non splitfile retries fctx max splitfile block retries max splitfile retries fctx max output length max output length fctx max temp length max output length bucket ret null this return type return type binary blob false if return type client get message return type disk this target file return filename this temp file return temp filename if server core allow download to return temp filename server core allow download to return filename throw new not allowed exception ret new file bucket return temp filename false true false false false else if return type client get message return type none target file null temp file null ret new null bucket else target file null temp file null if persistence type persist forever ret server core persistent temp bucket factory make bucket max output length else ret server core temp bucket factory make bucket max output length return bucket ret getter new client getter this uri fctx priority class low level client return bucket null identifiercollisionexception notallowedexception ioexception clientget fcpclient globalclient dsonly maxsplitfileretries maxnonsplitfileretries maxoutputlength returntype persistrebootonly prioclass returnfilename returntempfilename fcpserver objectcontainer identifiercollisionexception notallowedexception ioexception globalclient prioclass persistrebootonly clientrequest persist_reboot clientrequest persist_forever fetchcontext defaultfetchcontext fetchcontext identical_mask eventproducer addeventlistener localrequestonly dsonly ignorestore maxnonsplitfileretries maxnonsplitfileretries maxsplitfileblockretries maxsplitfileretries maxoutputlength maxoutputlength maxtemplength maxoutputlength returntype returntype binaryblob returntype clientgetmessage return_type_disk targetfile returnfilename tempfile returntempfilename allowdownloadto returntempfilename allowdownloadto returnfilename notallowedexception filebucket returntempfilename returntype clientgetmessage return_type_none targetfile tempfile nullbucket targetfile tempfile persistencetype persist_forever persistenttempbucketfactory makebucket maxoutputlength tempbucketfactory makebucket maxoutputlength returnbucket clientgetter priorityclass lowlevelclient returnbucket public client get fcp connection handler handler client get message message fcp server server object container container throws identifier collision exception message invalid exception super message uri message identifier message verbosity handler message priority class message persistence type message client token message global container create a fetcher directly in order to get more fine grained control since the client may override a few context elements fctx new fetch context server default fetch context fetch context identical mask false null fctx event producer add event listener this ignoreds fctx local request only message ds only fctx ignore store message ignoreds fctx max non splitfile retries message max retries fctx max splitfile block retries message max retries fixme do something with verbosity has already been checked fctx max output length message max size fctx max temp length message max temp size if message allowedmime types null fctx allowedmime types new hash set string for string mime message allowedmime types fctx allowedmime types add mime this return type message return type this binary blob message binary blob bucket ret null if return type client get message return type disk this target file message disk file this temp file message temp file if server core allow download to temp file server core allow download to target file throw new message invalid exception protocol error message access denied not allowed to download to temp file or target file identifier global else if handler allowdda from temp file true handler allowdda from target file true throw new message invalid exception protocol error message direct disk access denied not allowed to download to temp file or target file you might need to do a testdda request message name first identifier global ret new file bucket message temp file false true false false false else if return type client get message return type none target file null temp file null ret new null bucket else target file null temp file null try if persistence type persist forever ret server core persistent temp bucket factory make bucket fctx max output length else ret server core temp bucket factory make bucket fctx max output length catch io exception e logger error this cannot create bucket for temp storage e e getter null return bucket null this is not a fetch exception since we don t register it it s a protocol error throw new message invalid exception protocol error message internal error cannot create bucket for temporary storage out of disk space e identifier global if ret null logger error this impossible ret null in fcp constructor for this new exception debug return bucket ret getter new client getter this uri fctx priority class low level client binary blob new null bucket return bucket binary blob return bucket null clientget fcpconnectionhandler clientgetmessage fcpserver objectcontainer identifiercollisionexception messageinvalidexception priorityclass persistencetype clienttoken fetchcontext defaultfetchcontext fetchcontext identical_mask eventproducer addeventlistener localrequestonly dsonly ignorestore maxnonsplitfileretries maxretries maxsplitfileblockretries maxretries maxoutputlength maxsize maxtemplength maxtempsize allowedmimetypes allowedmimetypes hashset allowedmimetypes allowedmimetypes returntype returntype binaryblob binaryblob returntype clientgetmessage return_type_disk targetfile diskfile tempfile tempfile allowdownloadto tempfile allowdownloadto targetfile messageinvalidexception protocolerrormessage access_denied tempfile targetfile allowddafrom tempfile allowddafrom targetfile messageinvalidexception protocolerrormessage direct_disk_access_denied tempfile targetfile testddarequestmessage filebucket tempfile returntype clientgetmessage return_type_none targetfile tempfile nullbucket targetfile tempfile persistencetype persist_forever persistenttempbucketfactory makebucket maxoutputlength tempbucketfactory makebucket maxoutputlength ioexception returnbucket fetchexception messageinvalidexception protocolerrormessage internal_error returnbucket clientgetter priorityclass lowlevelclient binaryblob nullbucket returnbucket binaryblob returnbucket create a client get from a request serialized to a simple field set can throw and does minimal verification as is dealing with data supposedly serialized out by the node throws io exception throws fetch exception public client get simple field set fs fcp client client2 fcp server server throws io exception fetch exception super fs client2 return type client get message parse valid return type fs get return type string f fs get filename if f null target file new file f else target file null f fs get temp filename if f null temp file new file f else temp file null boolean ignoreds fields string to bool fs get ignoreds false boolean ds only fields string to bool fs get ds only false int max retries integer parse int fs get max retries fctx new fetch context server default fetch context fetch context identical mask false null fctx event producer add event listener this ignoreds fctx local request only ds only fctx ignore store ignoreds fctx max non splitfile retries max retries fctx max splitfile block retries max retries binary blob fields string to bool fs get binary blob false succeeded fields string to bool fs get succeeded false if finished if succeeded found data length long parse long fs get found data length found data mime type fs get found data mime type simple field set fs1 fs subset post fetch protocol error if fs1 null post fetch protocol error message new protocol error message fs1 else get failed message new get failed message fs subset get failed false bucket ret null if return type client get message return type disk if succeeded ret new file bucket target file false true false false false else ret new file bucket temp file false true false false false else if return type client get message return type none ret new null bucket else if return type client get message return type direct try ret serializable to field set bucket util create fs subset return bucket server core random server core persistent temp bucket factory if ret null throw new cannot create from field set exception ret null catch cannot create from field set exception e logger error this cannot read this e e try create a new temp bucket if persistence type persist forever ret server core persistent temp bucket factory make bucket fctx max output length else ret server core temp bucket factory make bucket fctx max output length catch io exception e1 logger error this cannot create bucket for temp storage e e getter null return bucket null throw new fetch exception fetch exception bucket error e else throw new illegal argument exception if succeeded if found data length ret size logger error this failing identifier because lost data succeeded false if ret null logger error this impossible ret null in sfs constructor for this new exception debug return bucket ret string allowed fs get all allowedmime types if allowed null fctx allowedmime types new hash set string for string a allowed fctx allowedmime types add a getter new client getter this uri fctx priority class low level client binary blob new null bucket return bucket binary blob return bucket null if finished succeeded all data pending new all data message return bucket identifier global startup time completion time this found data mime type clientget simplefieldset ioexception fetchexception clientget simplefieldset fcpclient fcpserver ioexception fetchexception returntype clientgetmessage parsevalidreturntype returntype targetfile targetfile tempfilename tempfile tempfile stringtobool dsonly stringtobool dsonly maxretries parseint maxretries fetchcontext defaultfetchcontext fetchcontext identical_mask eventproducer addeventlistener localrequestonly dsonly ignorestore maxnonsplitfileretries maxretries maxsplitfileblockretries maxretries binaryblob stringtobool binaryblob stringtobool founddatalength parselong founddatalength founddatamimetype founddatamimetype simplefieldset postfetchprotocolerror postfetchprotocolerrormessage protocolerrormessage getfailedmessage getfailedmessage getfailed returntype clientgetmessage return_type_disk filebucket targetfile filebucket tempfile returntype clientgetmessage return_type_none nullbucket returntype clientgetmessage return_type_direct serializabletofieldsetbucketutil returnbucket persistenttempbucketfactory cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception persistencetype persist_forever persistenttempbucketfactory makebucket maxoutputlength tempbucketfactory makebucket maxoutputlength ioexception returnbucket fetchexception fetchexception bucket_error illegalargumentexception founddatalength returnbucket getall allowedmimetypes allowedmimetypes hashset allowedmimetypes clientgetter priorityclass lowlevelclient binaryblob nullbucket returnbucket binaryblob returnbucket alldatapending alldatamessage returnbucket startuptime completiontime founddatamimetype must be called just after construction but within a transaction throws identifier collision exception if the identifier is already in use override void register object container container boolean lazy resume boolean no tags throws identifier collision exception if client null assert this persistence type client persistence type if persistence type persist connection try client register this lazy resume container catch identifier collision exception e return bucket free if persistence type persist forever return bucket remove from container throw e if persistence type persist connection no tags fcp message msg persistent tag message container client queue client request message msg 0 container identifiercollisionexception objectcontainer lazyresume notags identifiercollisionexception persistencetype persistencetype persistencetype persist_connection lazyresume identifiercollisionexception returnbucket persistencetype persist_forever returnbucket removefrom persistencetype persist_connection notags fcpmessage persistenttagmessage queueclientrequestmessage override public void start object container container client context context try synchronized this if finished return getter start container context if persistence type persist connection finished fcp message msg persistent tag message container client queue client request message msg 0 container synchronized this started true catch fetch exception e synchronized this started true before the failure handler on failure e null container catch throwable t synchronized this started true on failure new fetch exception fetch exception internal error t null container if persistence type persist forever container store this update objectcontainer clientcontext persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage fetchexception onfailure onfailure fetchexception fetchexception internal_error persistencetype persist_forever override public void on lost connection object container container client context context if persistence type persist connection cancel container context otherwise ignore onlostconnection objectcontainer clientcontext persistencetype persist_connection public void on success fetch result result client getter state object container container logger minor this succeeded identifier bucket data result as bucket if persistence type persist forever if data null container activate data 5 if return bucket null container activate return bucket 5 container activate client 1 if temp file null container activate temp file 5 if target file null container activate target file 5 if return bucket data binary blob boolean failed true synchronized this if finished logger error this already finished but on success for this data data new exception debug data free if persistence type persist forever data remove from container return already failed bucket error maybe if return type client get message return type direct return bucket null lost bucket for some reason e g bucket error caused by io exception on previous try recover return bucket data failed false if failed persistence type persist forever if container ext getid return bucket container ext getid data logger error this db4o bug detected without array handling evil horrible bug uid return bucket container ext getid return bucket for return bucket active container ext is active return bucket stored container ext is stored return bucket but uid data container ext getid data for data active container ext is active data stored container ext is stored data succeed anyway hope that the returned bucket is consistent return bucket data failed false if failed logger error this return bucket return bucket but on success data data new exception debug caller guarantees that data return bucket on failure new fetch exception fetch exception internal error data return bucket null container return boolean dont free false fixme i don t think this is a problem in this case disk write while locked all data message adm null synchronized this if succeeded logger error this on success called twice for this identifier return we might be called twice ignore it if so started true if binary blob this found data mime type result get mime type else this found data mime type binary blob mime type if return type client get message return type direct send all the data at once fixme there should be other options fixme completion time is set on finish we need to give it current time here but it means we won t always return the same value to clients does it matter adm new all data message return bucket identifier global startup time system current time millis this found data mime type if persistence type persist connection adm set free on sent dont free true else if return type client get message return type none do nothing else if return type client get message return type disk write to temp file then rename over filename if file util rename to temp file target file post fetch protocol error message new protocol error message protocol error message could not rename file false null identifier global don t delete temp file user might want it return bucket new file bucket target file false true false false false if persistence type persist forever progress pending null container activate progress pending 1 progress pending remove from container progress pending null this found data length return bucket size this succeeded true finished true try send data found or get failed null container if adm null try send all data message adm null container if dont free data free if persistence type persist forever return bucket store to container container store this finish container if client null client notify success this container onsuccess fetchresult clientgetter objectcontainer asbucket persistencetype persist_forever returnbucket returnbucket tempfile tempfile targetfile targetfile returnbucket binaryblob onsuccess persistencetype persist_forever removefrom returntype clientgetmessage return_type_direct returnbucket ioexception returnbucket persistencetype persist_forever returnbucket returnbucket returnbucket returnbucket isactive returnbucket isstored returnbucket isactive isstored returnbucket returnbucket returnbucket onsuccess returnbucket onfailure fetchexception fetchexception internal_error returnbucket dontfree alldatamessage onsuccess binaryblob founddatamimetype getmimetype founddatamimetype binaryblob mime_type returntype clientgetmessage return_type_direct completiontime alldatamessage returnbucket startuptime currenttimemillis founddatamimetype persistencetype persist_connection setfreeonsent dontfree returntype clientgetmessage return_type_none returntype clientgetmessage return_type_disk fileutil renameto tempfile targetfile postfetchprotocolerrormessage protocolerrormessage protocolerrormessage could_not_rename_file returnbucket filebucket targetfile persistencetype persist_forever progresspending progresspending progresspending removefrom progresspending founddatalength returnbucket trysenddatafoundorgetfailed trysendalldatamessage dontfree persistencetype persist_forever returnbucket storeto notifysuccess private void try send data found or get failed fcp connection output handler handler object container container fcp message msg don t need to lock succeeded is only ever set never unset and succeeded and get failed message are both atomic if succeeded msg new data found message found data length found data mime type identifier global else msg get failed message if persistence type persist forever container activate msg 5 if handler null persistence type persist connection handler orig handler output handler if handler null handler queue msg else client queue client request message msg 0 container if post fetch protocol error message null if persistence type persist forever container activate post fetch protocol error message 5 if handler null handler queue post fetch protocol error message else if persistence type persist forever container activate client 1 client queue client request message post fetch protocol error message 0 container trysenddatafoundorgetfailed fcpconnectionoutputhandler objectcontainer fcpmessage getfailedmessage datafoundmessage founddatalength founddatamimetype getfailedmessage persistencetype persist_forever persistencetype persist_connection orighandler outputhandler queueclientrequestmessage postfetchprotocolerrormessage persistencetype persist_forever postfetchprotocolerrormessage postfetchprotocolerrormessage persistencetype persist_forever queueclientrequestmessage postfetchprotocolerrormessage private void try send all data message all data message msg fcp connection output handler handler object container container if persistence type client request persist connection all data pending msg if persistence type client request persist forever container store this return if handler null handler orig handler output handler handler queue msg trysendalldatamessage alldatamessage fcpconnectionoutputhandler objectcontainer persistencetype clientrequest persist_connection alldatapending persistencetype clientrequest persist_forever orighandler outputhandler private void try send progress fcp message msg fcp connection output handler handler object container container if persistence type client request persist connection fcp message old progress progress pending if msg instanceof simple progress message progress pending simple progress message msg else if msg instanceof sending to network message sent to network true if persistence type client request persist forever container store this if old progress null container activate old progress 1 old progress remove from container if persistence type persist forever container activate client 1 if persistence type persist connection handler null handler orig handler output handler if handler null handler queue msg else client queue client request message msg verbosity splitfile progress container if persistence type persist forever client is global queue container deactivate client 1 trysendprogress fcpmessage fcpconnectionoutputhandler objectcontainer persistencetype clientrequest persist_connection fcpmessage oldprogress progresspending simpleprogressmessage progresspending simpleprogressmessage sendingtonetworkmessage senttonetwork persistencetype clientrequest persist_forever oldprogress oldprogress oldprogress removefrom persistencetype persist_forever persistencetype persist_connection orighandler outputhandler queueclientrequestmessage verbosity_splitfile_progress persistencetype persist_forever isglobalqueue override public void send pending messages fcp connection output handler handler boolean include persistent request boolean include data boolean only data object container container if persistence type client request persist connection logger error this wtf persistence type persistence type new exception error return if only data if include persistent request fcp message msg persistent tag message container handler queue msg if progress pending null if persistence type persist forever container activate progress pending 5 handler queue progress pending if sent to network handler queue new sending to network message identifier global if finished try send data found or get failed handler container if only data all data pending null logger error this no data pending if include data all data pending null if persistence type persist forever container activate all data pending 5 handler queue all data pending sendpendingmessages fcpconnectionoutputhandler includepersistentrequest includedata onlydata objectcontainer persistencetype clientrequest persist_connection persistencetype persistencetype onlydata includepersistentrequest fcpmessage persistenttagmessage progresspending persistencetype persist_forever progresspending progresspending senttonetwork sendingtonetworkmessage trysenddatafoundorgetfailed onlydata alldatapending includedata alldatapending persistencetype persist_forever alldatapending alldatapending override protected fcp message persistent tag message object container container if persistence type persist forever container activate uri 5 container activate fctx 1 container activate client 1 container activate target file 5 container activate temp file 5 return new persistent get identifier uri verbosity priority class return type persistence type target file temp file client token client is global queue started fctx max non splitfile retries binary blob fctx max output length fcpmessage persistenttagmessage objectcontainer persistencetype persist_forever targetfile tempfile persistentget priorityclass returntype persistencetype targetfile tempfile clienttoken isglobalqueue maxnonsplitfileretries binaryblob maxoutputlength public void on failure fetch exception e client getter state object container container if finished return synchronized this succeeded false get failed message new get failed message e identifier global finished true started true if logger should log logger minor this logger minor this caught e e try send data found or get failed null container if persistence type persist forever container activate client 1 we do not want the data to be removed on failure because the request may be restarted and the bucket persists on the getter even if we get rid of it here free data container finish container if client null client notify failure this container if persistence type persist forever container store this onfailure fetchexception clientgetter objectcontainer getfailedmessage getfailedmessage shouldlog trysenddatafoundorgetfailed persistencetype persist_forever freedata notifyfailure persistencetype persist_forever public void on success base client putter state object container container ignore onsuccess baseclientputter objectcontainer public void on failure insert exception e base client putter state object container container ignore onfailure insertexception baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore ongenerateduri baseclientputter objectcontainer override public void request was removed object container container client context context if request is still running send a get failed with code cancelled if finished synchronized this succeeded false finished true fetch exception cancelled new fetch exception fetch exception cancelled get failed message new get failed message cancelled identifier global try send data found or get failed null container notify client that request was removed fcp message msg new persistent request removed message get identifier global if persistence type persist connection if persistence type persist forever container activate client 1 client queue client request message msg 0 container free data container if persistence type persist forever container activate fctx 1 if fctx allowedmime types null container activate fctx allowedmime types 5 container delete fctx allowedmime types fctx remove from container getter remove from container context if target file null container delete target file if temp file null container delete temp file if get failed message null container activate get failed message 5 get failed message remove from container if post fetch protocol error message null container activate post fetch protocol error message 5 post fetch protocol error message remove from container if all data pending null container activate all data pending 5 all data pending remove from container if progress pending null container activate progress pending 5 progress pending remove from container super request was removed container context requestwasremoved objectcontainer clientcontext getfailed fetchexception fetchexception fetchexception getfailedmessage getfailedmessage trysenddatafoundorgetfailed fcpmessage persistentrequestremovedmessage getidentifier persistencetype persist_connection persistencetype persist_forever queueclientrequestmessage freedata persistencetype persist_forever allowedmimetypes allowedmimetypes allowedmimetypes removefrom removefrom targetfile targetfile tempfile tempfile getfailedmessage getfailedmessage getfailedmessage removefrom postfetchprotocolerrormessage postfetchprotocolerrormessage postfetchprotocolerrormessage removefrom alldatapending alldatapending alldatapending removefrom progresspending progresspending progresspending removefrom requestwasremoved public void receive client event ce object container container client context context don t need to lock verbosity is final and finished is never unset if finished return final fcp message progress if ce instanceof splitfile progress event if verbosity verbosity splitfile progress verbosity splitfile progress return progress new simple progress message identifier global splitfile progress event ce else if ce instanceof sending to network event if verbosity verbosity sent to network verbosity sent to network return progress new sending to network message identifier global else return don t know what to do with event container may be null if persistence type persist forever container null context job runner queue new db job public void run object container container client context context try send progress progress null container native thread high priority false else try send progress progress null container clientevent objectcontainer clientcontext fcpmessage splitfileprogressevent verbosity_splitfile_progress verbosity_splitfile_progress simpleprogressmessage splitfileprogressevent sendingtonetworkevent verbosity_sent_to_network verbosity_sent_to_network sendingtonetworkmessage persistencetype persist_forever jobrunner dbjob objectcontainer clientcontext trysendprogress nativethread high_priority trysendprogress context job runner queue new db job public void run object container container client context context try send progress progress null container jobrunner dbjob objectcontainer clientcontext trysendprogress different it can store detailed state override public synchronized simple field set get field set simple field set fs new simple field set false we will need multi level later fs put single type get fs put single uri uri to string false false fs put single identifier identifier fs put single verbosity integer to string verbosity fs put single priority class short to string priority class fs put single return type client get message return type string return type fs put single persistence persistence type string persistence type fs put single client name client name if target file null fs put single filename target file get path if temp file null fs put single temp filename temp file get path if client token null fs put single client token client token fs put single ignoreds boolean to string fctx ignore store fs put single ds only boolean to string fctx local request only fs put single max retries integer to string fctx max non splitfile retries fs put single finished boolean to string finished fs put single succeeded boolean to string succeeded if fctx allowedmime types null fs put overwrite allowedmime types string fctx allowedmime types to array new string fctx allowedmime types size if finished if succeeded fs put single found data length long to string found data length fs put single found data mime type found data mime type if post fetch protocol error message null fs put post fetch protocol error post fetch protocol error message get field set else if get failed message null fs put get failed get failed message get field set false return bucket if return type client get message return type direct succeeded false return bucket null bucket tofs fs return bucket false return bucket fs put single global boolean to string client is global queue fs put binary blob binary blob fs put startup time startup time if finished fs put completion time completion time return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring putsingle putsingle tostring putsingle priorityclass tostring priorityclass putsingle returntype clientgetmessage returntypestring returntype putsingle persistencetypestring persistencetype putsingle clientname targetfile putsingle targetfile getpath tempfile putsingle tempfilename tempfile getpath clienttoken putsingle clienttoken clienttoken putsingle tostring ignorestore putsingle dsonly tostring localrequestonly putsingle maxretries tostring maxnonsplitfileretries putsingle tostring putsingle tostring allowedmimetypes putoverwrite allowedmimetypes allowedmimetypes toarray allowedmimetypes putsingle founddatalength tostring founddatalength putsingle founddatamimetype founddatamimetype postfetchprotocolerrormessage postfetchprotocolerror postfetchprotocolerrormessage getfieldset getfailedmessage getfailed getfailedmessage getfieldset returntype clientgetmessage return_type_direct returnbucket buckettofs returnbucket returnbucket putsingle tostring isglobalqueue binaryblob binaryblob startuptime startuptime completiontime completiontime override protected client requester get client request return getter clientrequester getclientrequest override protected void free data object container container bucket data synchronized this data return bucket return bucket null if data null if persistence type persist forever container activate data 5 data free if persistence type persist forever data remove from container if persistence type persist forever container store this freedata objectcontainer returnbucket returnbucket persistencetype persist_forever persistencetype persist_forever removefrom persistencetype persist_forever override public boolean has succeeded return succeeded hassucceeded public boolean is direct return this return type client get message return type direct isdirect returntype clientgetmessage return_type_direct public boolean is to disk return this return type client get message return type disk istodisk returntype clientgetmessage return_type_disk public freeneturi geturi object container container if persistence type persist forever container activate uri 5 return uri objectcontainer persistencetype persist_forever public long get data size object container container if found data length 0 return found data length if getter null if persistence type persist forever container activate getter 1 return getter expected size return 1 getdatasize objectcontainer founddatalength founddatalength persistencetype persist_forever expectedsize public string getmime type object container container if found data mime type null return found data mime type if getter null if persistence type persist forever container activate getter 1 return getter expectedmime return null getmimetype objectcontainer founddatamimetype founddatamimetype persistencetype persist_forever public file get dest filename object container container if persistence type persist forever container activate target file 5 return target file getdestfilename objectcontainer persistencetype persist_forever targetfile targetfile override public double get success fraction object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get fraction else return 1 getsuccessfraction objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getfraction override public double get total blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get total blocks else return 1 gettotalblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending gettotalblocks override public double get min blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get min blocks else return 1 getminblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getminblocks override public double get failed blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get failed blocks else return 0 getfailedblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getfailedblocks override public double get fataly failed blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get fataly failed blocks else return 0 getfatalyfailedblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getfatalyfailedblocks override public double get fetched blocks object container container if persistence type persist forever progress pending null container activate progress pending 2 if progress pending null return progress pending get fetched blocks else return 0 getfetchedblocks objectcontainer persistencetype persist_forever progresspending progresspending progresspending progresspending getfetchedblocks override public string get failure reason object container container if get failed message null return null if persistence type persist forever container activate get failed message 5 string s get failed message short code description if get failed message extra description null s get failed message extra description return s getfailurereason objectcontainer getfailedmessage persistencetype persist_forever getfailedmessage getfailedmessage shortcodedescription getfailedmessage extradescription getfailedmessage extradescription override public boolean is total finalized object container container if finished succeeded return true if progress pending null return false else if persistence type persist forever container activate progress pending 1 return progress pending is total finalized istotalfinalized objectcontainer progresspending persistencetype persist_forever progresspending progresspending istotalfinalized returns the link bucket that contains the downloaded data return the data in a link bucket or code null code if this isn rsquo t applicable public bucket get bucket object container container synchronized this if target file null if succeeded temp file null if persistence type persist forever container activate target file 5 return new file bucket target file false true false false false else if persistence type persist forever container activate temp file 5 return new file bucket temp file false true false false false else return return bucket getbucket objectcontainer targetfile tempfile persistencetype persist_forever targetfile filebucket targetfile persistencetype persist_forever tempfile filebucket tempfile returnbucket public void on fetchable base client putter state object container container ignore we don t insert onfetchable baseclientputter objectcontainer override public boolean can restart if finished logger minor this cannot restart because not finished for identifier return false if succeeded logger minor this cannot restart because succeeded for identifier return false return getter can restart canrestart canrestart override public boolean restart object container container client context context if can restart return false freeneturi redirect synchronized this finished false redirect get failed message null null get failed message redirecturi if persistence type persist forever get failed message null get failed message remove from container this get failed message null if persistence type persist forever all data pending null all data pending remove from container this all data pending null if persistence type persist forever post fetch protocol error message null post fetch protocol error message remove from container this post fetch protocol error message null if persistence type persist forever progress pending null progress pending remove from container this progress pending null started false if persistence type persist forever container store this try if getter restart redirect container context synchronized this if redirect null if persistence type persist forever uri remove from container this uri redirect started true if persistence type persist forever container store this return true catch fetch exception e on failure e null container return false objectcontainer clientcontext canrestart getfailedmessage getfailedmessage persistencetype persist_forever getfailedmessage getfailedmessage removefrom getfailedmessage persistencetype persist_forever alldatapending alldatapending removefrom alldatapending persistencetype persist_forever postfetchprotocolerrormessage postfetchprotocolerrormessage removefrom postfetchprotocolerrormessage persistencetype persist_forever progresspending progresspending removefrom progresspending persistencetype persist_forever persistencetype persist_forever removefrom persistencetype persist_forever fetchexception onfailure public synchronized boolean has perm redirect return get failed message null get failed message redirecturi null haspermredirect getfailedmessage getfailedmessage public void on remove event producer object container container do nothing we called the remove from onremoveeventproducer objectcontainer removefrom private boolean shadow override public int hash code return hash code hashcode hashcode public persistent blob temp bucket persistent blob temp bucket factory factory2 long block size2 long slot persistent blob temp bucket tag tag boolean shadow factory factory2 block size block size2 index slot hash code super hash code if tag null shadow throw new null pointer exception this tag tag this shadow shadow this read only shadow persistentblobtempbucket persistentblobtempbucketfactory blocksize2 persistentblobtempbuckettag blocksize blocksize2 hashcode hashcode nullpointerexception readonly public bucket create shadow throws io exception return factory create shadow this createshadow ioexception createshadow public void free if shadow factory free shadow index this else factory free bucket index this will call on free always take the outer lock first freeshadow freebucket onfree public boolean freed return freed synchronized void on free freed true onfree boolean persisted return persisted public input stream get input stream throws io exception if freed throw new io exception already freed final file channel channel factory channel synchronized persistent blob temp bucket this input streams return new input stream private int offset private boolean closed override public int read throws io exception if closed throw new io exception closed byte buf new byte 1 int res read buf if res 1 return 1 return buf 0 override public int read byte buffer int buf offset int length throws io exception if closed throw new io exception closed long max synchronized persistent blob temp bucket this if freed throw new io exception bucket freed during read max math min block size size if length 0 return 0 if buf offset 0 return 1 throw new eof exception if offset length max length int math min max offset integer max value if length 0 return 1 if length 0 throw new illegal state exception offset buf offset length length buf len buffer length my offset is offset my size is max for this for persistent blob temp bucket this byte buffer buf byte buffer wrap buffer buf offset length int read channel read buf block size index offset if read 0 offset read return read override public int read byte buffer throws io exception if closed throw new io exception closed return read buffer 0 buffer length override public int available return int math min block size offset integer max value override public void close if closed return closed true synchronized persistent blob temp bucket this input streams do nothing inputstream getinputstream ioexception ioexception filechannel persistentblobtempbucket inputstreams inputstream ioexception ioexception bufoffset ioexception ioexception persistentblobtempbucket ioexception blocksize bufoffset eofexception max_value illegalstateexception bufoffset persistentblobtempbucket bytebuffer bytebuffer bufoffset blocksize ioexception ioexception blocksize max_value persistentblobtempbucket inputstreams override public int read throws io exception if closed throw new io exception closed byte buf new byte 1 int res read buf if res 1 return 1 return buf 0 ioexception ioexception override public int read byte buffer int buf offset int length throws io exception if closed throw new io exception closed long max synchronized persistent blob temp bucket this if freed throw new io exception bucket freed during read max math min block size size if length 0 return 0 if buf offset 0 return 1 throw new eof exception if offset length max length int math min max offset integer max value if length 0 return 1 if length 0 throw new illegal state exception offset buf offset length length buf len buffer length my offset is offset my size is max for this for persistent blob temp bucket this byte buffer buf byte buffer wrap buffer buf offset length int read channel read buf block size index offset if read 0 offset read return read bufoffset ioexception ioexception persistentblobtempbucket ioexception blocksize bufoffset eofexception max_value illegalstateexception bufoffset persistentblobtempbucket bytebuffer bytebuffer bufoffset blocksize override public int read byte buffer throws io exception if closed throw new io exception closed return read buffer 0 buffer length ioexception ioexception override public int available return int math min block size offset integer max value blocksize max_value override public void close if closed return closed true synchronized persistent blob temp bucket this input streams do nothing persistentblobtempbucket inputstreams public string get name return factory get name index getname getname public output stream get output stream throws io exception if freed throw new io exception already freed if shadow throw new io exception shadow if read only throw new io exception read only final file channel channel factory channel return new output stream private int offset override public void write int arg throws io exception byte buf new byte byte arg write buf 0 1 override public void write byte buffer int buf offset int length throws io exception synchronized persistent blob temp bucket this if freed throw new io exception bucket freed during write if read only throw new io exception bucket made read only during write long remaining block size offset if remaining 0 throw new io exception too big if length remaining throw new io exception writing too many bytes written offset of block size and now want to write length byte buffer buf byte buffer wrap buffer buf offset length int written 0 while written length int w channel write buf block size index offset offset w synchronized persistent blob temp bucket this size w written w override public void write byte buffer throws io exception write buffer 0 buffer length outputstream getoutputstream ioexception ioexception ioexception readonly ioexception filechannel outputstream ioexception bufoffset ioexception persistentblobtempbucket ioexception readonly ioexception blocksize ioexception ioexception blocksize bytebuffer bytebuffer bufoffset blocksize persistentblobtempbucket ioexception override public void write int arg throws io exception byte buf new byte byte arg write buf 0 1 ioexception override public void write byte buffer int buf offset int length throws io exception synchronized persistent blob temp bucket this if freed throw new io exception bucket freed during write if read only throw new io exception bucket made read only during write long remaining block size offset if remaining 0 throw new io exception too big if length remaining throw new io exception writing too many bytes written offset of block size and now want to write length byte buffer buf byte buffer wrap buffer buf offset length int written 0 while written length int w channel write buf block size index offset offset w synchronized persistent blob temp bucket this size w written w bufoffset ioexception persistentblobtempbucket ioexception readonly ioexception blocksize ioexception ioexception blocksize bytebuffer bytebuffer bufoffset blocksize persistentblobtempbucket override public void write byte buffer throws io exception write buffer 0 buffer length ioexception public synchronized boolean is read only return read only isreadonly readonly public synchronized void set read only read only true setreadonly readonly public synchronized long size return size public void store to object container container if shadow throw new unsupported operation exception can t store a shadow boolean p synchronized this if tag null throw new null pointer exception p persisted persisted true if p factory store this container calls on store take the outer lock first storeto objectcontainer unsupportedoperationexception nullpointerexception onstore public boolean object can new object container container if shadow throw new unsupported operation exception can t store a shadow synchronized this if persisted return true logger error this object on new called but we haven t been stored yet for this for factory index index new exception error return true objectcannew objectcontainer unsupportedoperationexception objectonnew public boolean object can deactivate object container container if input streams 0 logger error this deactivating when have active input streams new exception error return false return true objectcandeactivate objectcontainer inputstreams public void remove from object container container if shadow throw new unsupported operation exception can t store a shadow boolean p synchronized this p persisted if p factory remove this container calls on remove container delete this removefrom objectcontainer unsupportedoperationexception onremove synchronized void on remove persisted false onremove private static final long serial versionuid 4509857798038125744l public ssdp search response socket list serialversionuid ssdpsearchresponsesocketlist public void set control point control point ctrl point int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n sock set control point ctrl point setcontrolpoint controlpoint ctrlpoint nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket setcontrolpoint ctrlpoint public ssdp search response socket getssdp search response socket int n return ssdp search response socket get n ssdpsearchresponsesocket getssdpsearchresponsesocket ssdpsearchresponsesocket public boolean open int port try int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n ssdp search response socket socket new ssdp search response socket bind addr port add socket catch exception e stop close clear return false return true nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress ssdpsearchresponsesocket ssdpsearchresponsesocket bindaddr public boolean open return open ssdp port public void close int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n sock close clear nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket public void start int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n sock start nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket public void stop int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n sock stop nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket public boolean post ssdp search request req boolean ret true int n sockets size for int n 0 n n sockets n ssdp search response socket sock getssdp search response socket n string bind addr sock get local address req set local address bind addr string ssdp addr ssdp address if host interface isi pv6 address bind addr true ssdp addr ssdp geti pv6 address sock join group ssdp addr ssdp port bind addr if sock post ssdp addr ssdp port req false ret false sock leave group ssdp addr ssdp port bind addr return ret ssdpsearchrequest nsockets nsockets ssdpsearchresponsesocket getssdpsearchresponsesocket bindaddr getlocaladdress setlocaladdress bindaddr ssdpaddr hostinterface isipv6address bindaddr ssdpaddr getipv6address joingroup ssdpaddr bindaddr ssdpaddr leavegroup ssdpaddr bindaddr public final subscribeusk message message subscribedusk message subscribeusk message m this message m subscribeuskmessage subscribeduskmessage subscribeuskmessage override public simple field set get field set simple field set sfs new simple field set true sfs put single identifier message identifier sfs put single uri message key geturi to string sfs put dont poll message dont poll return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring dontpoll dontpoll override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message name goes from server to client not the other way around name false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container container activate message 1 message remove from container fixme this is throwing unsupported operation exception container delete this removefrom objectcontainer removefrom unsupportedoperationexception private int hash code public byte array wrapper byte data buf data hash code fields hash code buf hashcode bytearraywrapper hashcode hashcode override public boolean equals object o if o instanceof byte array wrapper byte array wrapper b byte array wrapper o if b buf buf return true return arrays equals b buf buf return false bytearraywrapper bytearraywrapper bytearraywrapper override public int hash code return hash code hashcode hashcode private int lut public equalize filter equalizefilter override protected int filter pixels int width int height int in pixels rectangle transformed space histogram histogram new histogram in pixels width height 0 width int i j if histogram get num samples 0 float scale 255 0f histogram get num samples lut new int 3 256 for i 0 i 3 i lut i 0 histogram get frequency i 0 for j 1 j 256 j lut i j lut i j 1 histogram get frequency i j for j 0 j 256 j lut i j int math round lut i j scale else lut null i 0 for int y 0 y height y for int x 0 x width x in pixels i filterrgb x y in pixels i i lut null return in pixels filterpixels inpixels transformedspace inpixels getnumsamples getnumsamples getfrequency getfrequency inpixels inpixels inpixels private int filterrgb int x int y int rgb if lut null int a rgb 0xff000000 int r lut histogram red rgb 16 0xff int g lut histogram green rgb 8 0xff int b lut histogram blue rgb 0xff return a r 16 g 8 b return rgb override public string to string return colors equalize tostring public advertiser device dev set device dev setdevice private device device public void set device device dev device dev setdevice public device get device return device getdevice public void run device dev get device long lease time dev get lease time long notify interval while is runnable true notify interval lease time 4 long float lease time math random 0 25f notify interval 1000 try thread sleep notify interval catch interrupted exception e dev announce getdevice leasetime getleasetime notifyinterval isrunnable notifyinterval leasetime leasetime notifyinterval notifyinterval interruptedexception public term string word storage storage this word word md5 md5 word page set storage page create scalable set storage make persistent this pageset createscalableset makepersistent public term public boolean add page page page return page set add page addpage pageset public boolean remove page page page return page set remove page removepage pageset public set page get pages return page set getpages pageset public string get word return word getword public string getmd5 return md5 override public boolean equals object o if o null return false if get class o get class return false term t term o return md5 equals t md5 word equals t word getclass getclass override public int hash code return md5 hash code word hash code hashcode hashcode hashcode public static string md5 string text try message digest md message digest get instance md5 byte md5hash new byte 32 byte b text get bytes utf 8 md update b 0 b length md5hash md digest return convert to hex md5hash catch unsupported encoding exception e throw new runtime exception utf 8 not supported e catch no such algorithm exception e throw new runtime exception md5 not supported e messagedigest messagedigest getinstance getbytes converttohex unsupportedencodingexception runtimeexception nosuchalgorithmexception runtimeexception public static string convert to hex byte data string builder buf new string builder for int i 0 i data length i int halfbyte data i 4 0x0f int two halfs 0 do if 0 halfbyte halfbyte 9 buf append char 0 halfbyte else buf append char a halfbyte 10 halfbyte data i 0x0f while two halfs 1 return buf to string converttohex stringbuilder stringbuilder two_halfs two_halfs tostring private static final long serial versionuid 1 too long exception string s super s serialversionuid toolongexception public identity manager ext object container mydb executor my executor logger debug this creating identity manager db mydb m executor my executor identitymanager extobjectcontainer myexecutor mexecutor myexecutor for being used in j unit tests to run without a node public identity manager ext object container mydb db mydb m executor null junit identitymanager extobjectcontainer mexecutor public abstract ft own identity create own identity string new nickname boolean publishes trust list boolean publishes introduction puzzles throws exception ftownidentity createownidentity newnickname publishestrustlist publishesintroductionpuzzles public abstract ft own identity create own identity string new nickname boolean publishes trust list boolean publishes introduction puzzles throws exception public abstract ft own identity create own identity string new nickname boolean publishes trust list boolean publishes introduction puzzles freeneturi requesturi freeneturi inserturi throws exception ftownidentity createownidentity newnickname publishestrustlist publishesintroductionpuzzles ftownidentity createownidentity newnickname publishestrustlist publishesintroductionpuzzles freeneturi requesturi freeneturi inserturi throws exception public abstract iterable extends ft identity get all identities ftidentity getallidentities public synchronized int count known identities fixme this should probably take an ft own identity as param and count the identities seen by it query q db query q constrain ft identity class q constrain ft own identity class not return q execute size countknownidentities ftownidentity ftidentity ftownidentity suppress warnings unchecked public synchronized iterator ft own identity own identity iterator return new iterator ft own identity iterator ft own identity iter query q db query q constrain ft own identity class iter q execute iterator public boolean has next return iter has next public ft own identity next ft own identity oi iter next oi initialize transient db identity manager this return oi public void remove throw new unsupported operation exception cannot delete own identities via own identity iterator suppresswarnings ftownidentity ownidentityiterator ftownidentity ftownidentity ftownidentity hasnext hasnext ftownidentity ftownidentity initializetransient identitymanager unsupportedoperationexception ownidentityiterator public boolean has next return iter has next hasnext hasnext public ft own identity next ft own identity oi iter next oi initialize transient db identity manager this return oi ftownidentity ftownidentity initializetransient identitymanager public void remove throw new unsupported operation exception cannot delete own identities via own identity iterator unsupportedoperationexception ownidentityiterator public abstract ft identity get identity string uid throws no such identity exception ftidentity getidentity nosuchidentityexception public abstract ft identity get identity string uid throws no such identity exception public abstract ft own identity get own identity string uid throws no such identity exception ftidentity getidentity nosuchidentityexception ftownidentity getownidentity nosuchidentityexception public synchronized boolean any own identity wants messages from ft identity identity iterator ft own identity iter own identity iterator boolean no own identities true while iter has next no own identities false ft own identity oid iter next if oid wants messages from identity return true return no own identities true false anyownidentitywantsmessagesfrom ftidentity ftownidentity ownidentityiterator noownidentities hasnext noownidentities ftownidentity wantsmessagesfrom noownidentities public abstract void terminate param spider public web interface xml spider spider xml spider spider page maker xml spider get page maker page maker add navigation link plugins plugins xml spider xml spider home home page false null page maker add navigation link plugins plugins xml spider xml spider config page config configuration false null page maker add navigation link plugins plugins page back to plugins page false null webinterface xmlspider xmlspider pagemaker xmlspider getpagemaker pagemaker addnavigationlink xmlspider xmlspider pagemaker addnavigationlink xmlspider xmlspider configpage pagemaker addnavigationlink interface to the spider data public string handlehttp get http request request throws pluginhttp exception html node page node page maker get page node xml spider plugin name null html node content node page maker get content node page node web page page get page object request page write content request content node return page node generate handlehttpget httprequest pluginhttpexception htmlnode pagenode pagemaker getpagenode xmlspider pluginname htmlnode contentnode pagemaker getcontentnode pagenode webpage getpageobject writecontent contentnode pagenode public string handlehttp post http request request throws pluginhttp exception html node page node page maker get page node xml spider plugin name null html node content node page maker get content node page node web page page get page object request page process post request request content node page write content request content node return page node generate handlehttppost httprequest pluginhttpexception htmlnode pagenode pagemaker getpagenode xmlspider pluginname htmlnode contentnode pagemaker getcontentnode pagenode webpage getpageobject processpostrequest contentnode writecontent contentnode pagenode public web page get page object http request request if request is parameter set config page return new config page xml spider return new main page xml spider webpage getpageobject httprequest isparameterset configpage configpage xmlspider mainpage xmlspider public class state variable data extends node data public state variable data statevariabledata nodedata statevariabledata private string value public string get value return value getvalue public void set value string value this value value setvalue private query listener query listener null public query listener get query listener return query listener querylistener querylistener querylistener getquerylistener querylistener public void set query listener query listener query listener this query listener query listener setquerylistener querylistener querylistener querylistener querylistener private query response query res null public query response get query response return query res queryresponse queryres queryresponse getqueryresponse queryres public void set query response query response res query res res setqueryresponse queryresponse queryres public class compile error extends runtime exception public compile error string msg int pos super msg in position pos compileerror runtimeexception compileerror public progress string initialmsg retrieved false complete false msg initialmsg public void set string msg msg msg retrieved false _msg _msg public void done string msg done msg null public void done string msg string result retrieved false complete true this msg msg this result result null result todo better status format public string get boolean pushonupdate probably best to do this with a lock if pushonupdate look for a progress update while retrieved whilst theres no new msg try thread sleep 500 catch java lang interrupted exception e retrieved true if complete return msg br event description else return msg br event description interruptedexception eventdescription eventdescription public string getresult return result hears an event param container the database context the event was generated in note that it may not have been generated in a database context at all in this case container will be null and you should use context to schedule a db job public void receive client event ce object container maybe container client context context event description ce get description retrieved false dbjob clientevent objectcontainer maybecontainer clientcontext eventdescription getdescription called when the event producer gets remove from object container if the listener is the main listener which probably called remove from it should do nothing if it s a tag along but request specific listener it may need to remove itself public void on remove event producer object container container eventproducer removefrom objectcontainer removefrom onremoveeventproducer objectcontainer private static final long serial versionuid 1 public illegal base64 exception string descr super descr serialversionuid illegalbase64exception public abstract class persistent collection t extends persistent resource implements i table t public iterable iterator t select class cls string predicate query t query new query impl t get storage return query select cls iterator predicate persistentcollection persistentresource itable iterableiterator queryimpl getstorage returns tt true tt if this collection contains all of the elements in the specified collection p this implementation iterates over the specified collection checking each element returned by the iterator in turn to see if it s contained in this collection if all elements are so contained tt true tt is returned otherwise tt false tt param c collection to be checked for containment in this collection return tt true tt if this collection contains all of the elements in the specified collection throws null pointer exception if the specified collection is null see contains object public boolean contains all collection c iterator e c iterator while e has next if contains e next return false return true nullpointerexception containsall hasnext adds all of the elements in the specified collection to this collection optional operation the behavior of this operation is undefined if the specified collection is modified while the operation is in progress this implies that the behavior of this call is undefined if the specified collection is this collection and this collection is nonempty p this implementation iterates over the specified collection and adds each object returned by the iterator to this collection in turn p note that this implementation will throw an tt unsupported operation exception tt unless tt add tt is overridden assuming the specified collection is non empty param c collection whose elements are to be added to this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if this collection does not support the tt add all tt method throws null pointer exception if the specified collection is null see add object public boolean add all collection extends t c boolean modified false iterator extends t e c iterator while e has next if add e next modified true return modified unsupportedoperationexception unsupportedoperationexception addall nullpointerexception addall hasnext removes from this collection all of its elements that are contained in the specified collection optional operation p this implementation iterates over this collection checking each element returned by the iterator in turn to see if it s contained in the specified collection if it s so contained it s removed from this collection with the iterator s tt remove tt method p note that this implementation will throw an tt unsupported operation exception tt if the iterator returned by the tt iterator tt method does not implement the tt remove tt method and this collection contains one or more elements in common with the specified collection param c elements to be removed from this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if the tt remove all tt method is not supported by this collection throws null pointer exception if the specified collection is null see remove object see contains object public boolean remove all collection c boolean modified false iterator i c iterator while i has next modified remove i next return modified unsupportedoperationexception unsupportedoperationexception removeall nullpointerexception removeall hasnext retains only the elements in this collection that are contained in the specified collection optional operation in other words removes from this collection all of its elements that are not contained in the specified collection p this implementation iterates over this collection checking each element returned by the iterator in turn to see if it s contained in the specified collection if it s not so contained it s removed from this collection with the iterator s tt remove tt method p note that this implementation will throw an tt unsupported operation exception tt if the iterator returned by the tt iterator tt method does not implement the tt remove tt method and this collection contains one or more elements not present in the specified collection param c elements to be retained in this collection return tt true tt if this collection changed as a result of the call throws unsupported operation exception if the tt retain all tt method is not supported by this collection throws null pointer exception if the specified collection is null see remove object see contains object public boolean retain all collection c array list t to be removed new array list t iterator t i iterator while i has next t o i next if c contains o to be removed add o int n to be removed size for int j 0 j n j remove to be removed get j return n 0 unsupportedoperationexception unsupportedoperationexception retainall nullpointerexception retainall arraylist toberemoved arraylist hasnext toberemoved toberemoved toberemoved returns tt true tt if this collection contains the specified element more formally returns tt true tt if and only if this collection contains at least one element tt e tt such that tt o null e null o equals e tt p this implementation iterates over the elements in the collection checking each element in turn for equality with the specified element param o object to be checked for containment in this collection return tt true tt if this collection contains the specified element public boolean contains object o iterator t e iterator if o null while e has next if e next null return true else while e has next if o equals e next return true return false hasnext hasnext removes a single instance of the specified element from this collection if it is present optional operation more formally removes an element tt e tt such that tt o null e null o equals e tt if the collection contains one or more such elements returns tt true tt if the collection contained the specified element or equivalently if the collection changed as a result of the call p this implementation iterates over the collection looking for the specified element if it finds the element it removes the element from the collection using the iterator s remove method p note that this implementation throws an tt unsupported operation exception tt if the iterator returned by this collection s iterator method does not implement the tt remove tt method and this collection contains the specified object param o element to be removed from this collection if present return tt true tt if the collection contained the specified element throws unsupported operation exception if the tt remove tt method is not supported by this collection public boolean remove object o iterator t e iterator if o null while e has next if e next null e remove return true else while e has next if o equals e next e remove return true return false unsupportedoperationexception unsupportedoperationexception hasnext hasnext ensures that this collection contains the specified element optional operation returns tt true tt if the collection changed as a result of the call returns tt false tt if this collection does not permit duplicates and already contains the specified element collections that support this operation may place limitations on what elements may be added to the collection in particular some collections will refuse to add tt null tt elements and others will impose restrictions on the type of elements that may be added collection classes should clearly specify in their documentation any restrictions on what elements may be added p this implementation always throws an tt unsupported operation exception tt param o element whose presence in this collection is to be ensured return tt true tt if the collection changed as a result of the call throws unsupported operation exception if the tt add tt method is not supported by this collection throws null pointer exception if this collection does not permit tt null tt elements and the specified element is tt null tt throws class cast exception if the class of the specified element prevents it from being added to this collection throws illegal argument exception if some aspect of this element prevents it from being added to this collection public boolean add t o throw new unsupported operation exception unsupportedoperationexception unsupportedoperationexception nullpointerexception classcastexception illegalargumentexception unsupportedoperationexception returns tt true tt if this collection contains no elements p this implementation returns tt size 0 tt return tt true tt if this collection contains no elements public boolean is empty return size 0 isempty default constructor public persistent collection persistentcollection constructor of the collection associated with the specified storage param storage storage associated with the collection public persistent collection storage storage super storage persistentcollection private static final long serial versionuid 1l public no such board exception super serialversionuid nosuchboardexception public no such board exception string name super unknown board name nosuchboardexception public edit own identity page web interface my web interface http request my request throws unknown identity exception super my web interface my request m identity wot get own identity byid request get part as string id 128 editownidentitypage webinterface mywebinterface httprequest myrequest unknownidentityexception mywebinterface myrequest midentity getownidentitybyid getpartasstring public void make synchronized wot synchronized m identity if request is part set edit try m identity set publish trust list request is part set publish trust list request get part as string publish trust list 6 equals true if request is part set publish puzzles request get part as string publish puzzles 6 equals true m identity add context introduction puzzle introduction context m identity set property introduction server puzzle count property integer to string introduction server default puzzle count else m identity remove context introduction puzzle introduction context m identity remove property introduction server puzzle count property wot store and commit m identity catch exception e add error box saving the changes failed e get message html node box add content box edit identity m identity get nickname html node create form pr add form child box uri edit identity create form add child input new string type name value new string hidden id m identity getid create form add child input new string type name value new string hidden page edit identity create form add child p new string style new string font size x small request uri m identity get requesturi to string create form add child p new string style new string font size x small insert uri keep this secret m identity get inserturi to string todo give the user the ability to edit these create form add child p contexts m identity get contexts create form add child p properties m identity get properties html node p create form add child p publish trust list if m identity does publish trust list p add child input new string type name value checked new string checkbox publish trust list true checked else p add child input new string type name value new string checkbox publish trust list true p create form add child p publish introduction puzzles if m identity has context introduction puzzle introduction context p add child input new string type name value checked new string checkbox publish puzzles true checked else p add child input new string type name value new string checkbox publish puzzles true create form add child input new string type name value new string submit edit save changes midentity ispartset midentity setpublishtrustlist ispartset publishtrustlist getpartasstring publishtrustlist ispartset publishpuzzles getpartasstring publishpuzzles midentity addcontext introductionpuzzle introduction_context midentity setproperty introductionserver puzzle_count_property tostring introductionserver default_puzzle_count midentity removecontext introductionpuzzle introduction_context midentity removeproperty introductionserver puzzle_count_property storeandcommit midentity adderrorbox getmessage htmlnode addcontentbox midentity getnickname htmlnode createform addformchild editidentity createform addchild midentity createform addchild editidentity createform addchild midentity getrequesturi tostring createform addchild midentity getinserturi tostring createform addchild midentity getcontexts createform addchild midentity getproperties htmlnode createform addchild midentity doespublishtrustlist addchild publishtrustlist addchild publishtrustlist createform addchild midentity hascontext introductionpuzzle introduction_context addchild publishpuzzles addchild publishpuzzles createform addchild public http socket socket socket set socket socket open httpsocket setsocket public http socket http socket socket set socket socket get socket set input stream socket get input stream set output stream socket get output stream httpsocket httpsocket setsocket getsocket setinputstream getinputstream setoutputstream getoutputstream public void finalize close private socket socket null private void set socket socket socket this socket socket setsocket public socket get socket return socket getsocket public string get local address return get socket get local address get host address getlocaladdress getsocket getlocaladdress gethostaddress public int get local port return get socket get local port getlocalport getsocket getlocalport private output stream sock out null private void set input stream input stream in sock in in outputstream sockout setinputstream inputstream sockin public input stream get input stream return sock in inputstream getinputstream sockin private void set output stream output stream out sock out out setoutputstream outputstream sockout private output stream get output stream return sock out outputstream getoutputstream sockout public boolean open socket sock get socket try sock in sock get input stream sock out sock get output stream catch exception e return false return true getsocket sockin getinputstream sockout getoutputstream public boolean close try if sock in null sock in close if sock out null sock out close get socket close catch exception e debug warning e return false return true sockin sockin sockout sockout getsocket private boolean post http response http res byte content long content offset long content length boolean is only header http res set date calendar get instance output stream out get output stream try http res set content length content length out write http res get header get bytes out write http crlf get bytes if is only header true out flush return true boolean is chunked response http res is chunked if is chunked response true string chun size buf long to string content length out write chun size buf get bytes out write http crlf get bytes out write content int content offset int content length if is chunked response true out write http crlf get bytes out write 0 get bytes out write http crlf get bytes out flush catch exception e debug warning e return false return true httpresponse httpres contentoffset contentlength isonlyheader httpres setdate getinstance outputstream getoutputstream httpres setcontentlength contentlength httpres getheader getbytes getbytes isonlyheader ischunkedresponse httpres ischunked ischunkedresponse chunsizebuf tostring contentlength chunsizebuf getbytes getbytes contentoffset contentlength ischunkedresponse getbytes getbytes getbytes private boolean post http response http res input stream in long content offset long content length boolean is only header http res set date calendar get instance output stream out get output stream try http res set content length content length out write http res get header get bytes out write http crlf get bytes if is only header true out flush return true boolean is chunked response http res is chunked if 0 content offset in skip content offset int chunk size http get chunk size byte read buf new byte chunk size long read cnt 0 long read size chunk size content length chunk size content length int read len in read read buf 0 int read size while 0 read len read cnt content length if is chunked response true string chun size buf long to string read len out write chun size buf get bytes out write http crlf get bytes out write read buf 0 read len if is chunked response true out write http crlf get bytes read cnt read len read size chunk size content length read cnt chunk size content length read cnt read len in read read buf 0 int read size if is chunked response true out write 0 get bytes out write http crlf get bytes out flush catch exception e debug warning e return false return true httpresponse httpres inputstream contentoffset contentlength isonlyheader httpres setdate getinstance outputstream getoutputstream httpres setcontentlength contentlength httpres getheader getbytes getbytes isonlyheader ischunkedresponse httpres ischunked contentoffset contentoffset chunksize getchunksize readbuf chunksize readcnt readsize chunksize contentlength chunksize contentlength readlen readbuf readsize readlen readcnt contentlength ischunkedresponse chunsizebuf tostring readlen chunsizebuf getbytes getbytes readbuf readlen ischunkedresponse getbytes readcnt readlen readsize chunksize contentlength readcnt chunksize contentlength readcnt readlen readbuf readsize ischunkedresponse getbytes getbytes public boolean post http response http res long content offset long content length boolean is only header if http res has content input stream true return post http res http res get content input stream content offset content length is only header return post http res http res get content content offset content length is only header httpresponse httpres contentoffset contentlength isonlyheader httpres hascontentinputstream httpres httpres getcontentinputstream contentoffset contentlength isonlyheader httpres httpres getcontent contentoffset contentlength isonlyheader public canceler jmdns impl jmdns impl service info impl info object lock this jmdns impl jmdns impl this infos new service info impl info this lock lock this jmdns impl add listener info new dns question info get qualified name dns constants type any dns constants class in jmdnsimpl jmdnsimpl serviceinfoimpl jmdnsimpl jmdnsimpl serviceinfoimpl jmdnsimpl addlistener dnsquestion getqualifiedname dnsconstants type_any dnsconstants class_in public canceler jmdns impl jmdns impl service info impl infos object lock this jmdns impl jmdns impl this infos infos this lock lock jmdnsimpl jmdnsimpl serviceinfoimpl jmdnsimpl jmdnsimpl public canceler jmdns impl jmdns impl collection infos object lock this jmdns impl jmdns impl this infos service info impl infos to array new service info impl infos size this lock lock jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl serviceinfoimpl toarray serviceinfoimpl public void start timer timer timer schedule this 0 dns constants announce wait interval dnsconstants announce_wait_interval public void run try if count 3 logger finer run jmdns canceling service announce the service long now system current time millis dns outgoing out new dns outgoing dns constants flags qr response dns constants flags aa for int i 0 i infos length i service info impl info infos i info add answers out ttl this jmdns impl get local host this jmdns impl get local host add address records out false this jmdns impl send out else after three successful announcements we are finished synchronized lock this jmdns impl set closed true lock notify all this cancel catch throwable e logger log level warning run exception e this jmdns impl recover currenttimemillis dnsoutgoing dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa serviceinfoimpl addanswers jmdnsimpl getlocalhost jmdnsimpl getlocalhost addaddressrecords jmdnsimpl jmdnsimpl setclosed notifyall jmdnsimpl public remove peer simple field set fs this fs fs identifier fs get identifier fs remove value identifier removepeer simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied name requires full access identifier false string node identifier fs get node identifier if node identifier null throw new message invalid exception protocol error message missing field error node identifier field missing identifier false peer node pn node get peer node node identifier if pn null fcp message msg new unknown node identifier message node identifier identifier handler output handler queue msg return string identity pn get identity string node remove peer connection pn handler output handler queue new peer removed identity node identifier identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied nodeidentifier nodeidentifier nodeidentifier messageinvalidexception protocolerrormessage missing_field nodeidentifier peernode getpeernode nodeidentifier fcpmessage unknownnodeidentifiermessage nodeidentifier outputhandler getidentitystring removepeerconnection outputhandler peerremoved nodeidentifier override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception int old oid btree key key key int oid this key key this oid oid oldoid btreekey final void get str page pg int i int len btree page get key str size pg i int offs btree page first key offs btree page get key str offs pg i char sval new char len for int j 0 j len j sval j char bytes unpack2 pg data offs offs 2 key new key sval getstr btreepage getkeystrsize btreepage firstkeyoffs btreepage getkeystroffs final void get byte array page pg int i int len btree page get key str size pg i int offs btree page first key offs btree page get key str offs pg i byte bval new byte len system arraycopy pg data offs bval 0 len key new key bval getbytearray btreepage getkeystrsize btreepage firstkeyoffs btreepage getkeystroffs final void extract page pg int offs int type byte data pg data switch type case class descriptor tp boolean key new key data offs 0 break case class descriptor tp byte key new key data offs break case class descriptor tp short key new key bytes unpack2 data offs break case class descriptor tp char key new key char bytes unpack2 data offs break case class descriptor tp int case class descriptor tp object case class descriptor tp enum key new key bytes unpack4 data offs break case class descriptor tp long case class descriptor tp date key new key bytes unpack8 data offs break case class descriptor tp float key new key float int bits to float bytes unpack4 data offs break case class descriptor tp double key new key double long bits to double bytes unpack8 data offs break default assert failed invalid type classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpshort classdescriptor tpchar classdescriptor tpint classdescriptor tpobject classdescriptor tpenum classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat classdescriptor tpdouble longbitstodouble final void pack page pg int i byte dst pg data switch key type case class descriptor tp boolean case class descriptor tp byte dst btree page first key offs i byte key ival break case class descriptor tp short case class descriptor tp char bytes pack2 dst btree page first key offs i 2 short key ival break case class descriptor tp int case class descriptor tp object case class descriptor tp enum bytes pack4 dst btree page first key offs i 4 key ival break case class descriptor tp long case class descriptor tp date bytes pack8 dst btree page first key offs i 8 key lval break case class descriptor tp float bytes pack4 dst btree page first key offs i 4 float float to int bits float key dval break case class descriptor tp double bytes pack8 dst btree page first key offs i 8 double double to long bits key dval break default assert failed invalid type bytes pack4 dst btree page first key offs btree page max items i 1 4 oid classdescriptor tpboolean classdescriptor tpbyte btreepage firstkeyoffs classdescriptor tpshort classdescriptor tpchar btreepage firstkeyoffs classdescriptor tpint classdescriptor tpobject classdescriptor tpenum btreepage firstkeyoffs classdescriptor tplong classdescriptor tpdate btreepage firstkeyoffs classdescriptor tpfloat btreepage firstkeyoffs floattointbits classdescriptor tpdouble btreepage firstkeyoffs doubletolongbits btreepage firstkeyoffs btreepage maxitems peer node status peer node peer node boolean no heavy peer p peer node get peer if p null peer address null peer port 1 else peer address p get freenet address to string peer port p get port this selection rate peer node selection rate this status value peer node get peer node status this status name peer node get peer node status string this statuscss name peer node get peer node statuscss class name this location peer node get location this peers location peer node get peers location this version peer node get version this simple version peer node get simple version this routing backoff length peer node get routing backoff length this routing backed off until peer node get routing backed off until this connected peer node is connected this routable peer node is routable this is fetchingark peer node is fetchingark this is opennet peer node is opennet this average ping time peer node average ping time this public invalid version peer node public invalid version this public reverse invalid version peer node public reverse invalid version this backed off percent peer node backed off percent current value this last backoff reason peer node get last backoff reason this time last routable peer node time last routable this time last connection completed peer node time last connection completed this peer added time peer node get peer added time if no heavy this local messages received peer node get local node received messages from statistic this local messages sent peer node get local node sent messages to statistic else this local messages received null this local messages sent null this hash code peer node hash code this p reject peer node getp rejected this total bytes in peer node get total input bytes this total bytes out peer node get total output bytes this total bytes in since startup peer node get total input since startup this total bytes out since startup peer node get total output since startup this percent time routable connection peer node get percent time routable connection this throttle peer node get throttle this clock delta peer node get clock delta this record status peer node record status this is seed client peer node instanceof seed client peer node this is seed server peer node instanceof seed server peer node this is searchable peer node is real connection this resend bytes sent peer node get resend bytes sent this reported uptime percentage peer node get uptime peernodestatus peernode peernode noheavy peernode getpeer peeraddress peerport peeraddress getfreenetaddress tostring peerport getport selectionrate peernode selectionrate statusvalue peernode getpeernodestatus statusname peernode getpeernodestatusstring statuscssname peernode getpeernodestatuscssclassname peernode getlocation peerslocation peernode getpeerslocation peernode getversion simpleversion peernode getsimpleversion routingbackofflength peernode getroutingbackofflength routingbackedoffuntil peernode getroutingbackedoffuntil peernode isconnected peernode isroutable isfetchingark peernode isfetchingark isopennet peernode isopennet averagepingtime peernode averagepingtime publicinvalidversion peernode publicinvalidversion publicreverseinvalidversion peernode publicreverseinvalidversion backedoffpercent peernode backedoffpercent currentvalue lastbackoffreason peernode getlastbackoffreason timelastroutable peernode timelastroutable timelastconnectioncompleted peernode timelastconnectioncompleted peeraddedtime peernode getpeeraddedtime noheavy localmessagesreceived peernode getlocalnodereceivedmessagesfromstatistic localmessagessent peernode getlocalnodesentmessagestostatistic localmessagesreceived localmessagessent hashcode peernode hashcode preject peernode getprejected totalbytesin peernode gettotalinputbytes totalbytesout peernode gettotaloutputbytes totalbytesinsincestartup peernode gettotalinputsincestartup totalbytesoutsincestartup peernode gettotaloutputsincestartup percenttimeroutableconnection peernode getpercenttimeroutableconnection peernode getthrottle clockdelta peernode getclockdelta recordstatus peernode recordstatus isseedclient peernode seedclientpeernode isseedserver peernode seedserverpeernode issearchable peernode isrealconnection resendbytessent peernode getresendbytessent reporteduptimepercentage peernode getuptime return the local messages received public map string long get local messages received return local messages received localmessagesreceived getlocalmessagesreceived localmessagesreceived return the local messages sent public map string long get local messages sent return local messages sent localmessagessent getlocalmessagessent localmessagessent return the peer added time public long get peer added time return peer added time peeraddedtime getpeeraddedtime peeraddedtime counts the peers in code peer nodes code that have the specified status param peer node statuses the peer nodes statuses param status the status to count return the number of peers that have the specified status public static int get peer status count peer node status peer node statuses int status int count 0 for int peer index 0 peer count peer node statuses length peer index peer count peer index if peer node statuses peer index get status value status count return count peernodes peernodestatuses getpeerstatuscount peernodestatus peernodestatuses peerindex peercount peernodestatuses peerindex peercount peerindex peernodestatuses peerindex getstatusvalue return the time last connection completed public long get time last connection completed return time last connection completed timelastconnectioncompleted gettimelastconnectioncompleted timelastconnectioncompleted return the backed off percent public double get backed off percent return backed off percent backedoffpercent getbackedoffpercent backedoffpercent return the last backoff reason public string get last backoff reason return last backoff reason lastbackoffreason getlastbackoffreason lastbackoffreason return the time last routable public long get time last routable return time last routable timelastroutable gettimelastroutable timelastroutable return the public invalid version public boolean is public invalid version return public invalid version publicinvalidversion ispublicinvalidversion publicinvalidversion return the public reverse invalid version public boolean is public reverse invalid version return public reverse invalid version publicreverseinvalidversion ispublicreverseinvalidversion publicreverseinvalidversion return the average ping time public double get average ping time return average ping time averagepingtime getaveragepingtime averagepingtime return the get routing backed off until public long get routing backed off until return routing backed off until getroutingbackedoffuntil getroutingbackedoffuntil routingbackedoffuntil return the location public double get location return location getlocation public double get peers location return peers location getpeerslocation peerslocation return the peer address public string get peer address return peer address peeraddress getpeeraddress peeraddress return the peer port public int get peer port return peer port peerport getpeerport peerport return the routing backoff length public int get routing backoff length return routing backoff length routingbackofflength getroutingbackofflength routingbackofflength return the statuscss name public string get statuscss name return statuscss name statuscssname getstatuscssname statuscssname return the status name public string get status name return status name statusname getstatusname statusname return the status value public int get status value return status value statusvalue getstatusvalue statusvalue return the version public string get version return version getversion return the connected public boolean is connected return connected isconnected return the routable public boolean is routable return routable isroutable return the is fetchingark public boolean is fetchingark return is fetchingark isfetchingark isfetchingark isfetchingark return the is opennet public boolean is opennet return is opennet isopennet isopennet isopennet return the simple version public int get simple version return simple version simpleversion getsimpleversion simpleversion override public string to string return status name peer address peer port location version backoff routing backoff length math max routing backed off until system current time millis 0 tostring statusname peeraddress peerport routingbackofflength routingbackedoffuntil currenttimemillis override public int hash code return hash code hashcode hashcode public double getp reject return p reject getpreject preject public long get total input bytes return total bytes in gettotalinputbytes totalbytesin public long get total output bytes return total bytes out gettotaloutputbytes totalbytesout public long get total input since startup return total bytes in since startup gettotalinputsincestartup totalbytesinsincestartup public long get total output since startup return total bytes out since startup gettotaloutputsincestartup totalbytesoutsincestartup public double get percent time routable connection return percent time routable connection getpercenttimeroutableconnection percenttimeroutableconnection public packet throttle get throttle return throttle packetthrottle getthrottle public long get clock delta return clock delta getclockdelta clockdelta public boolean record status return record status recordstatus recordstatus public boolean is seed server return is seed server isseedserver isseedserver public boolean is seed client return is seed client isseedclient isseedclient public boolean is searchable return is searchable issearchable issearchable public long get resend bytes sent return resend bytes sent getresendbytessent resendbytessent public int get reported uptime percentage return reported uptime percentage getreporteduptimepercentage reporteduptimepercentage public double get selection rate return selection rate getselectionrate selectionrate logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public boolean object can update object container container if logminor logger minor this object can update on debugging hash map this stored container ext is stored this active container ext is active this size size new exception debug return true objectcanupdate objectcontainer objectcanupdate debugginghashmap isstored isactive public boolean object can new object container container if logminor logger minor this object can new on debugging hash map this stored container ext is stored this active container ext is active this size size new exception debug return true objectcannew objectcontainer objectcannew debugginghashmap isstored isactive public void object on update object container container if logminor logger minor this object on update on debugging hash map this stored container ext is stored this active container ext is active this size size new exception debug objectonupdate objectcontainer objectonupdate debugginghashmap isstored isactive public void object on new object container container if logminor logger minor this object on new on debugging hash map this stored container ext is stored this active container ext is active this size size new exception debug objectonnew objectcontainer objectonnew debugginghashmap isstored isactive public boolean object can activate object container container if logminor logger minor this object can activate on debugging hash map stored container ext is stored this active container ext is active this size size new exception debug fixme this was an attempt to ensure we always activate to depth 2 it didn t work if activating activating false return true activating true container activate this 2 return false return true objectcanactivate objectcontainer objectcanactivate debugginghashmap isstored isactive boolean flushing public weak hash table int initial capacity threshold int initial capacity load factor table new entry initial capacity weakhashtable initialcapacity initialcapacity loadfactor initialcapacity public synchronized boolean remove int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index prev null e null prev e e e next if e oid oid if prev null prev next e next else tab index e next e clear count 1 return true return false protected reference create reference object obj return new weak reference obj createreference weakreference public synchronized void put int oid i persistent obj reference ref create reference obj entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e ref ref return if count threshold flushing rehash the table if the threshold is exceeded rehash tab table index oid 0x7fffffff tab length creates the new entry tab index new entry oid ref tab index count 1 ipersistent createreference public i persistent get int oid while true cs synchronized this entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid i persistent obj i persistent e ref get if obj null if e dirty 0 break cs else if obj is deleted e ref clear return null return obj return null system run finalization ipersistent ipersistent ipersistent isdeleted runfinalization public void flush while true cs synchronized this flushing true for int i 0 i table length i for entry e table i e null e e next i persistent obj i persistent e ref get if obj null if obj is modified obj store else if e dirty 0 break cs flushing false if count threshold rehash the table if the threshold is exceeded rehash return system run finalization ipersistent ipersistent ismodified runfinalization public void invalidate while true cs synchronized this for int i 0 i table length i for entry e table i e null e e next i persistent obj i persistent e ref get if obj null if obj is modified e dirty 0 obj invalidate else if e dirty 0 break cs table i null count 0 return system run finalization ipersistent ipersistent ismodified runfinalization public synchronized void clear entry tab table for int i 0 i tab length i tab i null count 0 void rehash int old capacity table length entry old map table int i for i old capacity i 0 entry e next prev for prev null e old map i e null e next next e next i persistent obj i persistent e ref get if obj null obj is deleted e dirty 0 count 1 e clear if prev null old map i next else prev next next else prev e if count threshold 1 return int new capacity old capacity 2 1 entry new map new entry new capacity threshold int new capacity load factor table new map for i old capacity i 0 for entry old old map i old null entry e old old old next int index e oid 0x7fffffff new capacity e next new map index new map index e oldcapacity oldmap oldcapacity oldmap ipersistent ipersistent isdeleted oldmap newcapacity oldcapacity newmap newcapacity newcapacity loadfactor newmap oldcapacity oldmap newcapacity newmap newmap public synchronized void set dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e dirty 1 return setdirty ipersistent getoid public synchronized void clear dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid if e dirty 0 e dirty 1 return cleardirty ipersistent getoid public int size return count void clear ref clear ref null dirty 0 next null entry int oid reference ref entry chain next chain this oid oid this ref ref public final static string to timeout header string long time if time subscription infinite value return subscription infinite string return subscription timeout header long to string time totimeoutheaderstring infinite_value infinite_string timeout_header tostring public final static long get timeout string header value int minus idx header value index of long timeout subscription infinite value try string timeout str header value substring minus idx 1 header value length timeout long parse long timeout str catch exception e return timeout gettimeout headervalue minusidx headervalue indexof infinite_value timeoutstr headervalue minusidx headervalue parselong timeoutstr public static final string createsid return u pnp createuuid upnp public final static string tosid header string string id return subscription uuid id tosidheaderstring public final static string getsid string header value if header value null return return header value substring subscription uuid length header value length headervalue headervalue headervalue headervalue public web interface wot my wot string uri m wot my wot muri uri m plugin respirator m wot get plugin respirator m page maker m plugin respirator get page maker m page maker add navigation link muri home home page false null m page maker add navigation link muri own identities own identities manage your own identities false null m page maker add navigation link muri known identities known identities manage others identities false null m page maker add navigation link muri configuration configuration configure the wot plugin false null m page maker add navigation link plugins plugins page back to plugins page false null webinterface mywot mwot mywot mpluginrespirator mwot getpluginrespirator mpagemaker mpluginrespirator getpagemaker mpagemaker addnavigationlink mpagemaker addnavigationlink ownidentities mpagemaker addnavigationlink knownidentities mpagemaker addnavigationlink mpagemaker addnavigationlink public string geturi return muri public string handlehttp get final http request request throws pluginhttp exception web page page null try if request is parameter set own identities page new own identities page this request else if request is parameter set known identities page new known identities page this request else if request is parameter set configuration page new configuration page this request else if request is parameter set show identity page new identity page this request else if request is parameter set puzzle introduction puzzle p m wot get introduction puzzle store get byid request get param id if p null byte data p get data fixme the current plugin manager implementation allows plugins only to send html replies implement general replying with any mime type and return the jpeg return else page new home page this request page make return page tohtml catch exception e try page new error page this request e page make return page tohtml catch exception double fault return double fault to string handlehttpget httprequest pluginhttpexception webpage isparameterset ownidentities ownidentitiespage isparameterset knownidentities knownidentitiespage isparameterset configurationpage isparameterset showidentity identitypage isparameterset introductionpuzzle mwot getintroductionpuzzlestore getbyid getparam getdata pluginmanager homepage errorpage doublefault doublefault tostring public string handlehttp post final http request request throws pluginhttp exception web page page string pass request get part as string form password 32 if pass length 0 pass equals m plugin respirator get node client core form password return invalid form password try string page title request get part as string page 50 if page title equals create identity page new create identity page this request else if page title equals add identity page new known identities page this request else if page title equals view tree page new known identities page this request else if page title equals set trust page new known identities page this request else if page title equals edit identity page new edit own identity page this request else if page title equals introduce identity page title equals solve puzzles page new introduce identity page this request else if page title equals restore identity page new own identities page this request else if page title equals delete identity page new delete own identity page this request else page new home page this request page make return page tohtml catch exception e try page new error page this request e page make return page tohtml catch exception double fault return double fault to string handlehttppost httprequest pluginhttpexception webpage getpartasstring formpassword mpluginrespirator getnode clientcore formpassword pagetitle getpartasstring pagetitle createidentity createidentitypage pagetitle addidentity knownidentitiespage pagetitle viewtree knownidentitiespage pagetitle settrust knownidentitiespage pagetitle editidentity editownidentitypage pagetitle introduceidentity pagetitle solvepuzzles introduceidentitypage pagetitle restoreidentity ownidentitiespage pagetitle deleteidentity deleteownidentitypage homepage errorpage doublefault doublefault tostring public string handlehttp put http request request throws pluginhttp exception return go to hell handlehttpput httprequest pluginhttpexception public page maker get page maker return m page maker pagemaker getpagemaker mpagemaker public wot get wot return m wot getwot mwot private static final string l10n string string return l10n get string config toadlet string getstring configtoadlet private static boolean logminor override public string to string return super to string for uid tostring tostring request sender constructor param key the key to request its public key should have been looked up already request sender will not look it up public resettinghtl probe request sender double target short htl long uid node n double nearest loc boolean reset nearest loc peer node source double best this htl htl this uid uid this node n this source source this nearest loc nearest loc this target target this best best this counter 1 this linear counter 1 this unique counter 1 logminor logger should log logger minor this update best if target 0 0 target 1 0 throw new illegal argument exception requestsender requestsender resettinghtlproberequestsender nearestloc resetnearestloc peernode nearestloc nearestloc linearcounter uniquecounter shouldlog updatebest illegalargumentexception public void start node executor execute this resettinghtl probe request sender for uid uid resettinghtlproberequestsender public void run try real run catch throwable t logger error this caught t t fire timeout internal error finally if logminor logger minor this leaving request sender run for uid realrun firetimeout requestsender private void real run int route attempts 0 int reject overloads 0 hash set peer node nodes routed to new hash set peer node while true if logminor logger minor this htl htl if htl 0 fire completion return route attempts route it peer node next next node peers closer peer source nodes routed to target true node is advanced mode enabled 1 null null if next null if logminor reject overloads 0 logger minor this no more peers but overloads reject overloads route attempts overloaded backtrack firernf return if logminor logger minor this routing request to next nodes routed to add next htl node decrementhtl has forwarded next source htl message req create data request try this is the first contact to this node it is more likely to timeout using send sync could make accepted timeout more accurate as it is measured from the send time use a lot of our time that we have to fulfill this request simply waiting on the send queue or longer if the node just went down using send async could make accepted timeout much more likely leave many hanging requests unclaimedfifo items potentially make overloaded peers more overloaded we make a request and promptly forget about them don t use send async next send sync req this catch not connected exception e logger minor this not connected continue synchronized this has forwarded true message msg null while true what are we waiting for fnp accepted continue fnp rejected loop go to another node fnp rejected overload propagate back to source go to another node if local message filter mf accepted message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp accepted message filter mf rejected loop message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected loop message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected overload mf rejected overload must be the last thing in the or so its or pointer remains null otherwise we need to recreate it below message filter mf mf accepted or mf rejected loop or mf rejected overload try msg node usm wait for mf this if logminor logger minor this first part got msg catch disconnected exception e logger normal this disconnected from next while waiting for accepted on uid break if msg null visited one node at least but maybe already been there counter if logminor logger minor this timeout waiting for accepted timeout waiting for accepted next local rejected overload accepted timeout forward rejected overload try next node break if msg get spec dmt fnp rejected loop visited one node already visited it counter if logminor logger minor this rejected loop find another node to route to break if msg get spec dmt fnp rejected overload visited one and only one node unique counter counter if logminor logger minor this rejected overload non fatal probably still have time left forward rejected overload if msg get boolean dmt is local if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break could be a previous rejection the timeout to incur another accepted timeout is minimal continue if msg get spec dmt fnp accepted logger error this unrecognized message msg continue don t increment here we will let the node do it for us break if msg null msg get spec dmt fnp accepted try another node continue if logminor logger minor this got accepted otherwise must be accepted so wait int got messages 0 string last message null while true message filter mfdf make data found filter next message filter mf route not found message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnp route not found message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnp rejected overload message filter mf pub key message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnpssk pub key message filter mf trace message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnprh probe trace message filter mf mf route not found or mf rejected overload or mfdf or mf pub key or mf trace try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for data on uid break if logminor logger minor this second part got msg if msg null logger normal this request fatal timeout null after accept got messages messages last last message fatal timeout forward rejected overload fire timeout timeout return for debugging purposes remember the number of responses after the insert and the last message type we received got messages last message msg get spec get name if msg get spec dmt fnp route not found backtrack within available hops short new htl msg get short dmt htl if new htl htl htl new htl don t use the new nearest loc since we don t on requests and anyway it doesn t make any sense to do so it s only valid within that pocket message sub msg get sub message dmt fnprh return sub message if sub null double new best sub get double dmt best location if new best target new best best best new best counter math max 0 sub get short dmt counter unique counter math max 0 sub get short dmt unique counter linear counter is unchanged it s only valid on a reply fixme ideally we d return it here if we don t manage to reroute else counter unique counter htl break if msg get spec dmt fnp rejected overload non fatal probably still have time left forward rejected overload reject overloads count the nodes involved for results purposes don t use the htl or nearest loc message sub msg get sub message dmt fnprh return sub message if sub null double new best sub get double dmt best location if new best target new best best best new best counter math max 0 sub get short dmt counter unique counter math max 0 sub get short dmt unique counter if msg get boolean dmt is local nb is local means it s terminal not is local implies that the rejection message was forwarded from a downstream node local from our peers perspective this has nothing to do with local requests source null if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break so long as the node does not send a is local message interestingly messages can often timeout having only received this message continue if msg get spec dmt fnprh probe reply double his nearest msg get double dmt nearest location if location distance his nearest target true location distance nearest loc target true nearest loc his nearest realrun routeattempts rejectoverloads hashset peernode nodesroutedto hashset peernode firecompletion routeattempts peernode closerpeer nodesroutedto isadvancedmodeenabled rejectoverloads rejectoverloads routeattempts nodesroutedto hasforwarded createdatarequest sendsync accepted_timeout sendasync accepted_timeout sendasync sendsync notconnectedexception hasforwarded fnpaccepted fnprejectedloop fnprejectedoverload messagefilter mfaccepted messagefilter setsource setfield settimeout accepted_timeout settype fnpaccepted messagefilter mfrejectedloop messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedloop messagefilter mfrejectedoverload messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedoverload mfrejectedoverload messagefilter mfaccepted mfrejectedloop mfrejectedoverload waitfor disconnectedexception localrejectedoverload acceptedtimeout forwardrejectedoverload getspec fnprejectedloop getspec fnprejectedoverload uniquecounter forwardrejectedoverload getboolean is_local rejectedoverload accepted_timeout getspec fnpaccepted getspec fnpaccepted gotmessages lastmessage messagefilter makedatafoundfilter messagefilter mfroutenotfound messagefilter setsource setfield settimeout fetch_timeout settype fnproutenotfound messagefilter mfrejectedoverload messagefilter setsource setfield settimeout fetch_timeout settype fnprejectedoverload messagefilter mfpubkey messagefilter setsource setfield settimeout fetch_timeout settype fnpsskpubkey messagefilter mftrace messagefilter setsource setfield settimeout fetch_timeout settype fnprhprobetrace messagefilter mfroutenotfound mfrejectedoverload mfpubkey mftrace waitfor disconnectedexception gotmessages lastmessage forwardrejectedoverload firetimeout gotmessages lastmessage getspec getname getspec fnproutenotfound newhtl getshort newhtl newhtl nearestloc getsubmessage fnprhreturnsubmessage newbest getdouble best_location newbest newbest newbest getshort uniquecounter getshort unique_counter linearcounter uniquecounter getspec fnprejectedoverload forwardrejectedoverload rejectoverloads nearestloc getsubmessage fnprhreturnsubmessage newbest getdouble best_location newbest newbest newbest getshort uniquecounter getshort unique_counter getboolean is_local is_local is_local rejectedoverload is_local getspec fnprhprobereply hisnearest getdouble nearest_location hisnearest nearestloc nearestloc hisnearest private void fire trace double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short linear counter string reason long prevuid if this best target this best best best this best if location distance nearest target true location distance this nearest loc target true nearest this nearest loc counter short counter this counter unique counter short unique counter this unique counter linear counter short linear counter this linear counter synchronized listeners for listener l listeners try l on trace uid nearest best htl counter unique counter location myuid peer locs peerui ds short 0 linear counter reason prevuid catch throwable t logger error this caught t t firetrace uniquecounter shortbuffer peerlocs shortbuffer peeruids linearcounter nearestloc nearestloc uniquecounter uniquecounter uniquecounter linearcounter linearcounter linearcounter ontrace uniquecounter peerlocs peeruids linearcounter note that this must be first on the list private message filter make data found filter peer node next return message filter create set source next set field dmt uid uid set timeout fetch timeout set type dmt fnprh probe reply messagefilter makedatafoundfilter peernode messagefilter setsource setfield settimeout fetch_timeout settype fnprhprobereply private message create data request return dmt createfnprh probe request uid target this nearest loc best htl createdatarequest createfnprhproberequest nearestloc forward rejected overload to the request originator private void forward rejected overload synchronized this if has forwarded rejected overload return has forwarded rejected overload true notify all fire received reject overload nearest loc best counter unique counter linear counter rejectedoverload forwardrejectedoverload hasforwardedrejectedoverload hasforwardedrejectedoverload notifyall firereceivedrejectoverload nearestloc uniquecounter linearcounter wait rejected overload wait finished public short gethtl return htl wait_rejected_overload wait_finished public void sent bytes int x synchronized total bytes sync total bytes sent x node node stats probe request ctr sent bytes x sentbytes totalbytessync totalbytessent nodestats proberequestctr sentbytes public int get total sent bytes synchronized total bytes sync return total bytes sent gettotalsentbytes totalbytessync totalbytessent public void received bytes int x synchronized total bytes sync total bytes received x node node stats probe request ctr received bytes x receivedbytes totalbytessync totalbytesreceived nodestats proberequestctr receivedbytes public int get total received bytes synchronized total bytes sync return total bytes received gettotalreceivedbytes totalbytessync totalbytesreceived synchronized boolean has forwarded return has forwarded hasforwarded hasforwarded public void sent payload int x logger error this sent payload x in resettinghtl probe request sender for this new exception error sentpayload sentpayload resettinghtlproberequestsender public boolean is local request search return source null islocalrequestsearch all these methods should return quickly interface listener should return quickly allocate a thread if it needs to block etc throws not connected exception void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception notconnectedexception onreceivedrejectoverload uniquecounter linearcounter notconnectedexception throws not connected exception void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception void on trace long uid double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short s short linear counter string reason long prevuid throws not connected exception notconnectedexception onreceivedrejectoverload uniquecounter linearcounter notconnectedexception ontrace uniquecounter shortbuffer peerlocs shortbuffer peeruids linearcounter notconnectedexception void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception void on trace long uid double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short s short linear counter string reason long prevuid throws not connected exception on completion throws not connected exception void on completion double nearest double best short counter short unique counter short linear counter throws not connected exception onreceivedrejectoverload uniquecounter linearcounter notconnectedexception ontrace uniquecounter shortbuffer peerlocs shortbuffer peeruids linearcounter notconnectedexception notconnectedexception oncompletion uniquecounter linearcounter notconnectedexception throws not connected exception void on completion double nearest double best short counter short unique counter short linear counter throws not connected exception on rnf throws not connected exception void onrnf short htl double nearest double best short counter short unique counter short linear counter throws not connected exception notconnectedexception oncompletion uniquecounter linearcounter notconnectedexception notconnectedexception uniquecounter linearcounter notconnectedexception throws not connected exception void onrnf short htl double nearest double best short counter short unique counter short linear counter throws not connected exception on timeout param reason throws not connected exception void on timeout double nearest double best short counter short unique counter short linear counter string reason throws not connected exception notconnectedexception uniquecounter linearcounter notconnectedexception notconnectedexception ontimeout uniquecounter linearcounter notconnectedexception public void add listener listener l no request coalescing atm must be added before anything has happened synchronized this synchronized listeners listeners add l addlistener private void fire received reject overload double nearest double best short counter short unique counter short linear counter string reason synchronized listeners for listener l listeners try l on received reject overload nearest best counter unique counter linear counter reason catch throwable t logger error this caught t t firereceivedrejectoverload uniquecounter linearcounter onreceivedrejectoverload uniquecounter linearcounter private void fire completion synchronized listeners for listener l listeners try l on completion nearest loc best counter unique counter linear counter catch throwable t logger error this caught t t firecompletion oncompletion nearestloc uniquecounter linearcounter private void firernf synchronized listeners for listener l listeners try l onrnf htl nearest loc best counter unique counter linear counter catch throwable t logger error this caught t t nearestloc uniquecounter linearcounter private void fire timeout string reason synchronized listeners for listener l listeners try l on timeout nearest loc best counter unique counter linear counter reason catch throwable t logger error this caught t t firetimeout ontimeout nearestloc uniquecounter linearcounter private void update best peer node nodes node peers my peers for peer node node nodes if node is connected continue double loc node get location if loc target continue if loc target loc best best loc updatebest peernode mypeers peernode isconnected getlocation public int get priority return native thread high priority getpriority nativethread high_priority double get best return best getbest public double get nearest loc return nearest loc getnearestloc nearestloc public array bucket factory abf new array bucket factory override protected bucket make bucket long size throws io exception return abf make bucket size arraybucketfactory arraybucketfactory makebucket ioexception makebucket override protected void free bucket bucket bucket throws io exception bucket free freebucket ioexception public segmented bucket chain bucket int block size bucket factory factory db job runner runner int segment size2 bucket size block size bf factory db job runner runner segment size segment size2 segments new array list segmented chain bucket segment segmentedbucketchainbucket blocksize bucketfactory dbjobrunner segmentsize2 bucketsize blocksize dbjobrunner segmentsize segmentsize2 arraylist segmentedchainbucketsegment public bucket create shadow throws io exception return null createshadow ioexception public void free synchronized this freed true clearing false due to memory issues we cannot complete the cleanup before returning especially if we are already on the database thread db job free job new db job public void run object container container client context context segmented chain bucket segment segment null if container ext is stored segmented bucket chain bucket this logger error this bucket not stored in free job already deleted container delete this return synchronized this if segments is empty segment segments remove 0 if segment null container activate segment 1 if logger should log logger minor segmented bucket chain bucket this logger minor segmented bucket chain bucket this freeing segment segment segment activate buckets container segment free segment remove from container synchronized this if segments is empty db job runner queue this native thread high priority true db job runner queue restart job this native thread high priority container false container store this return container delete segments container delete segmented bucket chain bucket this container delete this synchronized segmented bucket chain bucket this if kill me null return db job runner remove restart job kill me native thread high priority container container delete kill me must be run blocking so that if we are on the database thread the job is added before committing if we are not on the database thread it doesn t matter db job runner run blocking free job native thread high priority dbjob freejob dbjob objectcontainer clientcontext segmentedchainbucketsegment isstored segmentedbucketchainbucket freejob isempty shouldlog segmentedbucketchainbucket segmentedbucketchainbucket activatebuckets removefrom isempty dbjobrunner nativethread high_priority dbjobrunner queuerestartjob nativethread high_priority segmentedbucketchainbucket segmentedbucketchainbucket killme dbjobrunner removerestartjob killme nativethread high_priority killme dbjobrunner runblocking freejob nativethread high_priority public void run object container container client context context segmented chain bucket segment segment null if container ext is stored segmented bucket chain bucket this logger error this bucket not stored in free job already deleted container delete this return synchronized this if segments is empty segment segments remove 0 if segment null container activate segment 1 if logger should log logger minor segmented bucket chain bucket this logger minor segmented bucket chain bucket this freeing segment segment segment activate buckets container segment free segment remove from container synchronized this if segments is empty db job runner queue this native thread high priority true db job runner queue restart job this native thread high priority container false container store this return container delete segments container delete segmented bucket chain bucket this container delete this synchronized segmented bucket chain bucket this if kill me null return db job runner remove restart job kill me native thread high priority container container delete kill me objectcontainer clientcontext segmentedchainbucketsegment isstored segmentedbucketchainbucket freejob isempty shouldlog segmentedbucketchainbucket segmentedbucketchainbucket activatebuckets removefrom isempty dbjobrunner nativethread high_priority dbjobrunner queuerestartjob nativethread high_priority segmentedbucketchainbucket segmentedbucketchainbucket killme dbjobrunner removerestartjob killme nativethread high_priority killme public input stream get input stream throws io exception synchronized this if freed clearing throw new io exception freed return new input stream int segment no 1 int bucket no segment size segmented chain bucket segment seg null bucket buckets null input stream is null private long bucket read 0 private boolean closed override public int read throws io exception byte b new byte 1 if read b 0 1 0 return 1 return b 0 override public int read byte buf throws io exception return read buf 0 buf length override public int read byte buf int offset int length throws io exception if closed throw new io exception already closed if bucket read bucket size is null if is null is close if buckets null buckets bucket no null bucket read 0 bucket no if bucket no segment size buckets null bucket no 0 segment no seg get segment segment no if seg null return 1 buckets get buckets seg if bucket no buckets length synchronized segmented bucket chain bucket this if segment no segments size no more data return 1 buckets get buckets seg if bucket no buckets length return 1 is buckets bucket no get input stream int r is read buf offset length if r 0 bucket read r return r override public void close throws io exception if closed return if is null is close closed true is null seg null buckets null inputstream getinputstream ioexception ioexception inputstream segmentno bucketno segmentsize segmentedchainbucketsegment inputstream bucketread ioexception ioexception ioexception ioexception bucketread bucketsize bucketno bucketread bucketno bucketno segmentsize bucketno segmentno getsegment segmentno getbuckets bucketno segmentedbucketchainbucket segmentno getbuckets bucketno bucketno getinputstream bucketread ioexception override public int read throws io exception byte b new byte 1 if read b 0 1 0 return 1 return b 0 ioexception override public int read byte buf throws io exception return read buf 0 buf length ioexception override public int read byte buf int offset int length throws io exception if closed throw new io exception already closed if bucket read bucket size is null if is null is close if buckets null buckets bucket no null bucket read 0 bucket no if bucket no segment size buckets null bucket no 0 segment no seg get segment segment no if seg null return 1 buckets get buckets seg if bucket no buckets length synchronized segmented bucket chain bucket this if segment no segments size no more data return 1 buckets get buckets seg if bucket no buckets length return 1 is buckets bucket no get input stream int r is read buf offset length if r 0 bucket read r return r ioexception ioexception bucketread bucketsize bucketno bucketread bucketno bucketno segmentsize bucketno segmentno getsegment segmentno getbuckets bucketno segmentedbucketchainbucket segmentno getbuckets bucketno bucketno getinputstream bucketread override public void close throws io exception if closed return if is null is close closed true is null seg null buckets null ioexception protected synchronized segmented chain bucket segment get segment int i return segments get i segmentedchainbucketsegment getsegment protected bucket get buckets final segmented chain bucket segment seg final bucket array wrapper baw new bucket array wrapper db job runner run blocking new db job public void run object container container client context context container activate seg 1 synchronized baw baw buckets seg shallow copy buckets container deactivate seg 1 native thread high priority synchronized baw return baw buckets getbuckets segmentedchainbucketsegment bucketarraywrapper bucketarraywrapper dbjobrunner runblocking dbjob objectcontainer clientcontext shallowcopybuckets nativethread high_priority public void run object container container client context context container activate seg 1 synchronized baw baw buckets seg shallow copy buckets container deactivate seg 1 objectcontainer clientcontext shallowcopybuckets public string get name return segmented bucket chain bucket getname segmentedbucketchainbucket public output stream get output stream throws io exception final segmented chain bucket segment segs synchronized this if read only throw new io exception read only if freed clearing throw new io exception freed size 0 segs segments to array new segmented chain bucket segment segments size segments clear for int i 0 i segs length i segs i free if segs length 0 db job runner run blocking new db job public void run object container container client context context for int i 0 i segs length i segs i remove from container native thread high priority return new output stream int segment no 0 int bucket no 0 segmented chain bucket segment seg make segment segment no null output stream cur seg make bucket stream bucket no private long bucket length private boolean closed override public void write int arg0 throws io exception write new byte byte arg0 override public void write byte buf throws io exception write buf 0 buf length override public void write byte buf int offset int length throws io exception boolean ro synchronized segmented bucket chain bucket this ro read only if ro if closed close throw new io exception read only if closed throw new io exception already closed while length 0 if bucket length bucket size bucket no cur close if bucket no segment size bucket no 0 segment no seg make segment segment no seg cur seg make bucket stream bucket no bucket length 0 int left int math min integer max value bucket size bucket length int write math min left length cur write buf offset write offset write length write bucket length write synchronized segmented bucket chain bucket class size write override public void close throws io exception if closed return if logger should log logger minor this logger minor this closing this for segmented bucket chain bucket this cur close closed true cur null final segmented chain bucket segment old seg seg seg null db job runner run blocking new db job public void run object container container client context context if container ext is stored old seg if container ext is active old seg logger error this old segment stored but not active old seg new exception error container activate old seg 1 old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 if there is only one segment we didn t add a kill me add one now synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context native thread high priority outputstream getoutputstream ioexception segmentedchainbucketsegment readonly ioexception ioexception toarray segmentedchainbucketsegment dbjobrunner runblocking dbjob objectcontainer clientcontext removefrom nativethread high_priority outputstream segmentno bucketno segmentedchainbucketsegment makesegment segmentno outputstream makebucketstream bucketno bucketlength ioexception ioexception ioexception segmentedbucketchainbucket readonly ioexception ioexception bucketlength bucketsize bucketno bucketno segmentsize bucketno segmentno makesegment segmentno makebucketstream bucketno bucketlength max_value bucketsize bucketlength bucketlength segmentedbucketchainbucket ioexception shouldlog segmentedbucketchainbucket segmentedchainbucketsegment oldseg dbjobrunner runblocking dbjob objectcontainer clientcontext isstored oldseg isactive oldseg oldseg oldseg oldseg storeto segmentedbucketchainbucket oldseg killme segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart nativethread high_priority public void run object container container client context context for int i 0 i segs length i segs i remove from container objectcontainer clientcontext removefrom private boolean closed override public void write int arg0 throws io exception write new byte byte arg0 ioexception override public void write byte buf throws io exception write buf 0 buf length ioexception override public void write byte buf int offset int length throws io exception boolean ro synchronized segmented bucket chain bucket this ro read only if ro if closed close throw new io exception read only if closed throw new io exception already closed while length 0 if bucket length bucket size bucket no cur close if bucket no segment size bucket no 0 segment no seg make segment segment no seg cur seg make bucket stream bucket no bucket length 0 int left int math min integer max value bucket size bucket length int write math min left length cur write buf offset write offset write length write bucket length write synchronized segmented bucket chain bucket class size write ioexception segmentedbucketchainbucket readonly ioexception ioexception bucketlength bucketsize bucketno bucketno segmentsize bucketno segmentno makesegment segmentno makebucketstream bucketno bucketlength max_value bucketsize bucketlength bucketlength segmentedbucketchainbucket override public void close throws io exception if closed return if logger should log logger minor this logger minor this closing this for segmented bucket chain bucket this cur close closed true cur null final segmented chain bucket segment old seg seg seg null db job runner run blocking new db job public void run object container container client context context if container ext is stored old seg if container ext is active old seg logger error this old segment stored but not active old seg new exception error container activate old seg 1 old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 if there is only one segment we didn t add a kill me add one now synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context native thread high priority ioexception shouldlog segmentedbucketchainbucket segmentedchainbucketsegment oldseg dbjobrunner runblocking dbjob objectcontainer clientcontext isstored oldseg isactive oldseg oldseg oldseg oldseg storeto segmentedbucketchainbucket oldseg killme segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart nativethread high_priority public void run object container container client context context if container ext is stored old seg if container ext is active old seg logger error this old segment stored but not active old seg new exception error container activate old seg 1 old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 if there is only one segment we didn t add a kill me add one now synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context objectcontainer clientcontext isstored oldseg isactive oldseg oldseg oldseg oldseg storeto segmentedbucketchainbucket oldseg killme segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart protected segmented chain bucket segment make segment int index final segmented chain bucket segment old seg if logger should log logger minor this logger minor this make a segment for this index index old old seg if old seg null synchronized this while running seg store logger normal this waiting for last segment store job to finish on this try wait catch interrupted exception e ignore running seg store true try db job runner run blocking new db job public void run object container container client context context try old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context finally synchronized segmented bucket chain bucket this running seg store false segmented bucket chain bucket this notify all native thread high priority 1 catch throwable t logger error this caught throwable t t running seg store false synchronized this segmented chain bucket segment seg new segmented chain bucket segment this if segments size index throw new illegal argument exception asked to add segment index but segments length is segments size segments add seg return seg segmentedchainbucketsegment makesegment segmentedchainbucketsegment oldseg shouldlog oldseg oldseg runningsegstore interruptedexception runningsegstore dbjobrunner runblocking dbjob objectcontainer clientcontext oldseg storeto segmentedbucketchainbucket oldseg segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart segmentedbucketchainbucket runningsegstore segmentedbucketchainbucket notifyall nativethread high_priority runningsegstore segmentedchainbucketsegment segmentedchainbucketsegment illegalargumentexception public void run object container container client context context try old seg store to container container ext store segments 1 container ext store segmented bucket chain bucket this 1 container deactivate old seg 1 synchronized segmented bucket chain bucket this if kill me null return kill me new segmented bucket chain bucket kill job segmented bucket chain bucket this kill me schedule restart container context finally synchronized segmented bucket chain bucket this running seg store false segmented bucket chain bucket this notify all objectcontainer clientcontext oldseg storeto segmentedbucketchainbucket oldseg segmentedbucketchainbucket killme killme segmentedbucketchainbucketkilljob segmentedbucketchainbucket killme schedulerestart segmentedbucketchainbucket runningsegstore segmentedbucketchainbucket notifyall public boolean is read only return read only isreadonly readonly public void remove from object container container valid no op if we haven t been stored removefrom objectcontainer public void set read only read only true setreadonly readonly public synchronized long size return size note that we don t recurse inside the segments as it would produce a huge transaction so you will need to close the output stream to commit the progress of writing to a file and yes we can t append so you need to write everything before storing the bucket fixme enforce the rule that you must close any output stream s before calling store to public void store to object container container throw new unsupported operation exception outputstream outputstream storeto storeto objectcontainer unsupportedoperationexception public bucket get buckets final bucket array wrapper baw new bucket array wrapper db job runner run blocking new db job public void run object container container client context context baw buckets get buckets container native thread high priority return baw buckets getbuckets bucketarraywrapper bucketarraywrapper dbjobrunner runblocking dbjob objectcontainer clientcontext getbuckets nativethread high_priority db job runner run blocking new db job public void run object container container client context context baw buckets get buckets container dbjobrunner runblocking dbjob objectcontainer clientcontext getbuckets protected synchronized bucket get buckets object container container int segs segments size if segs 0 return new bucket 0 segmented chain bucket segment seg segments get segs 1 container activate seg 1 seg activate buckets container int size segs 1 segment size seg size bucket buckets new bucket size seg shallow copy buckets buckets segs 1 segment size container deactivate seg 1 int pos 0 for int i 0 i segs 1 i seg segments get i container activate seg 1 seg activate buckets container seg shallow copy buckets buckets pos container deactivate seg 1 pos segment size return buckets getbuckets objectcontainer segmentedchainbucketsegment activatebuckets segmentsize shallowcopybuckets segmentsize activatebuckets shallowcopybuckets segmentsize public synchronized void clear due to memory issues we cannot complete this before we return synchronized this clearing true db job clear job new db job public void run object container container client context context if container ext is stored segmented bucket chain bucket this logger error this bucket not stored in clear job already deleted container delete this return segmented chain bucket segment segment null synchronized this if segments is empty segment segments remove 0 if segment null container activate segment 1 if logger should log logger minor segmented bucket chain bucket this logger minor segmented bucket chain bucket this clearing segment segment segment clear container synchronized this if segments is empty db job runner queue this native thread high priority 1 true db job runner queue restart job this native thread high priority 1 container false container store segments container store segmented bucket chain bucket this return container delete segments container delete segmented bucket chain bucket this container delete this synchronized segmented bucket chain bucket this if kill me null return db job runner remove restart job kill me native thread high priority container container delete kill me must be run blocking so that if we are on the database thread the job is added before committing if we are not on the database thread it doesn t matter db job runner run blocking clear job native thread high priority 1 dbjob clearjob dbjob objectcontainer clientcontext isstored segmentedbucketchainbucket clearjob segmentedchainbucketsegment isempty shouldlog segmentedbucketchainbucket segmentedbucketchainbucket isempty dbjobrunner nativethread high_priority dbjobrunner queuerestartjob nativethread high_priority segmentedbucketchainbucket segmentedbucketchainbucket segmentedbucketchainbucket killme dbjobrunner removerestartjob killme nativethread high_priority killme dbjobrunner runblocking clearjob nativethread high_priority public void run object container container client context context if container ext is stored segmented bucket chain bucket this logger error this bucket not stored in clear job already deleted container delete this return segmented chain bucket segment segment null synchronized this if segments is empty segment segments remove 0 if segment null container activate segment 1 if logger should log logger minor segmented bucket chain bucket this logger minor segmented bucket chain bucket this clearing segment segment segment clear container synchronized this if segments is empty db job runner queue this native thread high priority 1 true db job runner queue restart job this native thread high priority 1 container false container store segments container store segmented bucket chain bucket this return container delete segments container delete segmented bucket chain bucket this container delete this synchronized segmented bucket chain bucket this if kill me null return db job runner remove restart job kill me native thread high priority container container delete kill me objectcontainer clientcontext isstored segmentedbucketchainbucket clearjob segmentedchainbucketsegment isempty shouldlog segmentedbucketchainbucket segmentedbucketchainbucket isempty dbjobrunner nativethread high_priority dbjobrunner queuerestartjob nativethread high_priority segmentedbucketchainbucket segmentedbucketchainbucket segmentedbucketchainbucket killme dbjobrunner removerestartjob killme nativethread high_priority killme param container return true if there is more work to do we don t want to do everything in one transaction because this bucket could be enormous synchronized boolean remove contents object container container boolean logminor logger should log logger minor this while segments size 0 logger normal this freeing unfinished unstored bucket this segments left segments size remove the first so the space is reused at the beginning not at the end removing from the end results in not shrinking segmented chain bucket segment seg segments remove 0 if seg null already removed continue container activate seg 1 if logminor logger minor this removing segment seg size seg size if clearing seg clear container else seg activate buckets container seg free seg remove from container if segments size 0 container store segments container store this return true do some more in the next transaction else break if logminor logger minor this removed segments for this container delete segments container delete this if logminor logger minor this removed this freed true just in case it wasn t already return false removecontents objectcontainer shouldlog segmentedchainbucketsegment activatebuckets removefrom create a warp filter public warp filter warpfilter warpfilter create a warp filter with two warp grids param source grid the source grid param dest grid the destination grid public warp filter warp grid source grid warp grid dest grid this source grid source grid this dest grid dest grid warpfilter sourcegrid destgrid warpfilter warpgrid sourcegrid warpgrid destgrid sourcegrid sourcegrid destgrid destgrid set the source warp grid param source grid the source grid see get source grid public void set source grid warp grid source grid this source grid source grid sourcegrid getsourcegrid setsourcegrid warpgrid sourcegrid sourcegrid sourcegrid get the source warp grid return the source grid see set source grid public warp grid get source grid return source grid setsourcegrid warpgrid getsourcegrid sourcegrid set the destination warp grid param dest grid the destination grid see get dest grid public void set dest grid warp grid dest grid this dest grid dest grid destgrid getdestgrid setdestgrid warpgrid destgrid destgrid destgrid get the destination warp grid return the destination grid see set dest grid public warp grid get dest grid return dest grid setdestgrid warpgrid getdestgrid destgrid public void set frames int frames this frames frames setframes public int get frames return frames getframes for morphing sets the image we re morphing to if not set then we re just warping public void set morph image buffered image morph image this morph image morph image setmorphimage bufferedimage morphimage morphimage morphimage public buffered image get morph image return morph image bufferedimage getmorphimage morphimage public void set time float time this time time settime public float get time return time gettime override protected void transform space rectangle r r width frames transformspace override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height if morph image null int morph pixels getrgb morph image 0 0 width height null morph in pixels morph pixels out pixels source grid dest grid width height time else if frames 1 source grid warp in pixels width height source grid dest grid out pixels else warp grid new grid new warp grid source grid rows source grid cols width height for int i 0 i frames i float t float i frames 1 source grid lerp t dest grid new grid source grid warp in pixels width height source grid new grid out pixels return out pixels filterpixels inpixels transformedspace outpixels morphimage morphpixels morphimage inpixels morphpixels outpixels sourcegrid destgrid sourcegrid inpixels sourcegrid destgrid outpixels warpgrid newgrid warpgrid sourcegrid sourcegrid sourcegrid destgrid newgrid sourcegrid inpixels sourcegrid newgrid outpixels outpixels public void morph int src pixels int dest pixels int out pixels warp grid src grid warp grid dest grid int width int height float t warp grid new grid new warp grid src grid rows src grid cols width height src grid lerp t dest grid new grid src grid warp src pixels width height src grid new grid out pixels int dest pixels2 new int width height dest grid warp dest pixels width height dest grid new grid dest pixels2 cross dissolve out pixels dest pixels2 width height t srcpixels destpixels outpixels warpgrid srcgrid warpgrid destgrid warpgrid newgrid warpgrid srcgrid srcgrid srcgrid destgrid newgrid srcgrid srcpixels srcgrid newgrid outpixels destpixels2 destgrid destpixels destgrid newgrid destpixels2 crossdissolve outpixels destpixels2 public void cross dissolve int pixels1 int pixels2 int width int height float t int index 0 for int y 0 y height y for int x 0 x width x pixels1 index image math mix colors t pixels1 index pixels2 index index crossdissolve imagemath mixcolors override public string to string return distort mesh warp tostring public jaxp parser super jaxpparser public plugins u pnp org cybergarage xml node parse plugins u pnp org cybergarage xml node parent node org w3c dom node dom node int rank int dom node type dom node get node type if dom node type node element node return string dom node name dom node get node name string dom node value dom node get node value debug message rank elem dom node name dom node value type dom node type attrs arrrs len if dom node type org w3c dom node text node parent node set value dom node value return parent node if dom node type org w3c dom node element node return parent node plugins u pnp org cybergarage xml node node new plugins u pnp org cybergarage xml node node set name dom node name node set value dom node value if parent node null parent node add node node named node map attr map dom node get attributes int attr len attr map get length debug message attr len attr len for int n 0 n attr len n org w3c dom node attr attr map item n string attr name attr get node name string attr value attr get node value node set attribute attr name attr value org w3c dom node child dom node get first child while child null parse node child rank 1 child child get next sibling return node upnp upnp parentnode domnode domnodetype domnode getnodetype domnodetype element_node domnodename domnode getnodename domnodevalue domnode getnodevalue domnodename domnodevalue domnodetype arrrslen domnodetype text_node parentnode setvalue domnodevalue parentnode domnodetype element_node parentnode upnp upnp setname domnodename setvalue domnodevalue parentnode parentnode addnode namednodemap attrmap domnode getattributes attrlen attrmap getlength attrlen attrlen attrlen attrmap attrname getnodename attrvalue getnodevalue setattribute attrname attrvalue domnode getfirstchild getnextsibling public plugins u pnp org cybergarage xml node parse plugins u pnp org cybergarage xml node parent node org w3c dom node dom node return parse parent node dom node 0 upnp upnp parentnode domnode parentnode domnode public node parse input stream in stream throws parser exception plugins u pnp org cybergarage xml node root null try document builder factory factory document builder factory new instance document builder builder factory new document builder input source in src new input source in stream document doc builder parse in src org w3c dom element doc elem doc get document element if doc elem null root parse root doc elem node list root list doc get elements by tag name root debug message root list root list get length if 0 root list get length root parse root root list item 0 catch exception e throw new parser exception e return root inputstream instream parserexception upnp documentbuilderfactory documentbuilderfactory newinstance documentbuilder newdocumentbuilder inputsource insrc inputsource instream insrc docelem getdocumentelement docelem docelem nodelist rootlist getelementsbytagname rootlist rootlist getlength rootlist getlength rootlist parserexception private map long condition lock map new hash map long condition lock manager logdebug logger should log logger debug this lockmap hashmap lockmanager shouldlog lock the entry this lock is strong not strong re entrance no threads except cleaner should hold more then one lock at a time or deadlock may occur condition lock entry long offset if logdebug logger debug this try locking offset new exception condition condition try entry lock lock try do if shutdown return null condition lock cond lock map get offset if lock cond null lock cond await 10 time unit seconds 10s for checking shutdown else break while true condition entry lock new condition lock map put offset condition finally entry lock unlock catch interrupted exception e logger error this lock interrupted e return null if logdebug logger debug this locked offset new exception return condition lockentry entrylock lockcond lockmap lockcond lockcond timeunit entrylock newcondition lockmap entrylock interruptedexception unlock the entry void unlock entry long offset condition condition if logdebug logger debug this unlocking offset new exception debug entry lock lock try condition cond lock map remove offset assert cond condition cond signal finally entry lock unlock unlockentry entrylock lockmap entrylock shutdown and wait for all entries unlocked void shutdown shutdown true entry lock lock try while lock map is empty condition cond lock map values iterator next cond await uninterruptibly finally entry lock unlock entrylock lockmap isempty lockmap awaituninterruptibly entrylock public sky filter if sky colors null sky colors image utils create image toolkit get default toolkit get image get class get resource sky colors png get source skyfilter skycolors skycolors imageutils createimage getdefaulttoolkit getimage getclass getresource skycolors getsource public void set amount float amount this amount amount setamount public float get amount return amount getamount public void set operation int operation this operation operation setoperation public int get operation return operation getoperation public void set scale float scale this scale scale setscale public float get scale return scale getscale public void set stretch float stretch this stretch stretch setstretch public float get stretch return stretch getstretch public void sett float t this t t public float gett return t public void setfov float fov this fov fov public float getfov return fov public void set cloud cover float cloud cover this cloud cover cloud cover setcloudcover cloudcover cloudcover cloudcover public float get cloud cover return cloud cover getcloudcover cloudcover public void set cloud sharpness float cloud sharpness this cloud sharpness cloud sharpness setcloudsharpness cloudsharpness cloudsharpness cloudsharpness public float get cloud sharpness return cloud sharpness getcloudsharpness cloudsharpness public void set time float time this time time settime public float get time return time gettime public void set glow float glow this glow glow setglow public float get glow return glow getglow public void set glow falloff float glow falloff this glow falloff glow falloff setglowfalloff glowfalloff glowfalloff glowfalloff public float get glow falloff return glow falloff getglowfalloff glowfalloff public void set angle float angle this angle angle setangle public float get angle return angle getangle public void set octaves float octaves this octaves octaves setoctaves public float get octaves return octaves getoctaves public void seth float h this h h public float geth return h public void set lacunarity float lacunarity this lacunarity lacunarity setlacunarity public float get lacunarity return lacunarity getlacunarity public void set gain float gain this gain gain setgain public float get gain return gain getgain public void set bias float bias this bias bias setbias public float get bias return bias getbias public void set haziness float haziness this haziness haziness sethaziness public float get haziness return haziness gethaziness public void set sun elevation float sun elevation this sun elevation sun elevation setsunelevation sunelevation sunelevation sunelevation public float get sun elevation return sun elevation getsunelevation sunelevation public void set sun azimuth float sun azimuth this sun azimuth sun azimuth setsunazimuth sunazimuth sunazimuth sunazimuth public float get sun azimuth return sun azimuth getsunazimuth sunazimuth public void set sun color int sun color this sun color sun color setsuncolor suncolor suncolor suncolor public int get sun color return sun color getsuncolor suncolor public void set camera elevation float camera elevation this camera elevation camera elevation setcameraelevation cameraelevation cameraelevation cameraelevation public float get camera elevation return camera elevation getcameraelevation cameraelevation public void set camera azimuth float camera azimuth this camera azimuth camera azimuth setcameraazimuth cameraazimuth cameraazimuth cameraazimuth public float get camera azimuth return camera azimuth getcameraazimuth cameraazimuth public void set wind speed float wind speed this wind speed wind speed setwindspeed windspeed windspeed windspeed public float get wind speed return wind speed getwindspeed windspeed float mn mx override public buffered image filter buffered image src buffered image dst long start system current time millis sunr float sun color 16 0xff r255 sung float sun color 8 0xff r255 sunb float sun color 0xff r255 mn 10000 mx 10000 exponents new float int octaves 1 float frequency 1 0f for int i 0 i int octaves i exponents i float math pow 2 i frequency lacunarity min 1 max 1 min 1 2f max 1 2f width src get width height src get height int h src get height tan new float h for int i 0 i h i tan i float math tan fov float i h math pi 0 5 if dst null dst create compatible dest image src null int t int 63 time sky pixels getrgb sky colors t 0 1 64 sky pixels graphics2d g dst create graphics g draw image sky colors 0 0 dst get width dst get height t 0 t 1 64 null g dispose buffered image clouds super filter dst dst g draw rendered image clouds null g dispose long finish system current time millis system out println mn mx finish start 0 001f exponents null tan null return dst bufferedimage bufferedimage bufferedimage currenttimemillis suncolor suncolor suncolor getwidth getheight getheight createcompatibledestimage skypixels skycolors skypixels creategraphics drawimage skycolors getwidth getheight bufferedimage drawrenderedimage currenttimemillis public float evaluate float x float y float value 0 0f float remainder int i to prevent cascading effects x 371 y 529 for i 0 i int octaves i value noise noise3 x y t exponents i x lacunarity y lacunarity remainder octaves int octaves if remainder 0 value remainder noise noise3 x y t exponents i return value override public int filterrgb int x int y int rgb curvature float fx float x width y 20 math sin fx math pi 0 5 float fy y height float haze float math pow haziness 100 fy fy int argb sky pixels int fy float r float rgb 16 0xff r255 float g float rgb 8 0xff r255 float b float rgb 0xff r255 float cx width 0 5f float nx x cx float ny y fov ny float math tan fov fy math pi 0 5 ny tan y nx fx 0 5f 1 ny ny t wind speed wind towards the camera float xscale scale 1 y bias 0 1f nx scale ny scale stretch float f evaluate nx ny float fg f fixme bump map normalize to 0 1 f f min max min f f 1 23f 2 46f f amount int a rgb 0xff000000 int v work out cloud cover float c f cloud cover if c 0 c 0 float cloud alpha 1 float math pow cloud sharpness c cloud alpha amount if cloud alpha 1 cloud alpha 1 mn math min mn cloud alpha mx math max mx cloud alpha sun glow float centrex width sun azimuth float centrey height sun elevation float dx x centrex float dy y centrey float distance2 dx dx dy dy float sun 0 distance2 float math sqrt distance2 distance2 float math pow distance2 glow falloff float sun amount 10 float math exp distance2 glow 0 1f sun glow 10 float math exp distance2 sun glow onto sky r sun sunr g sun sung b sun sunb float cloud color cloud alpha sun bump map float nnx x cx float nny y 1 nnx xscale nny xscale stretch float gf evaluate nnx nny float gradient fg gf if y 100 system out println fg gf gradient cloud color amount gradient r cloud color r cloud alpha g cloud color g cloud alpha b cloud color b cloud alpha clouds get darker as they get thicker float ca 1 cloud alpha cloud alpha cloud alpha cloud alpha 1 sun amount float cloudr sunr ca float cloudg sung ca float cloudb sunb ca apply the haziness as we move further away cloud alpha haze composite the clouds on the sky float i cloud alpha 1 cloud alpha r i cloud alpha r cloud alpha cloudr g i cloud alpha g cloud alpha cloudg b i cloud alpha b cloud alpha cloudb exposure float exposure gain r 1 float math exp r exposure g 1 float math exp g exposure b 1 float math exp b exposure int ir int 255 r 16 int ig int 255 g 8 int ib int 255 b v 0xff000000 ir ig ib return v skypixels windspeed cloudcover cloudalpha cloudsharpness cloudalpha cloudalpha cloudalpha cloudalpha cloudalpha sunazimuth sunelevation glowfalloff cloudcolor cloudalpha cloudcolor cloudcolor cloudalpha cloudcolor cloudalpha cloudcolor cloudalpha cloudalpha cloudalpha cloudalpha cloudalpha cloudalpha icloudalpha cloudalpha icloudalpha cloudalpha icloudalpha cloudalpha icloudalpha cloudalpha override public string to string return texture sky tostring private final object object public sectored random grab array with object object object boolean persistent object container container remove random parent parent super persistent container parent this object object sectoredrandomgrabarraywithobject objectcontainer removerandomparent public object get object return object getobject override public string to string return super to string object tostring tostring public class inet6 address matcher implements address matcher public address type get address type return address type i pv6 inet6addressmatcher addressmatcher addresstype getaddresstype addresstype ipv6 public inet6 address matcher string pattern if pattern index of 1 address convert to bytes pattern substring 0 pattern index of string netmask string pattern substring pattern index of 1 trim if netmask string index of 1 netmask convert to bytes netmask string else netmask new byte 16 int bits integer parse int netmask string for int index 0 index 16 index netmask index byte 255 8 math min bits 8 bits math max bits 8 0 if arrays equals netmask full mask netmask full mask else address convert to bytes pattern netmask full mask if address length 16 throw new illegal argument exception address is not i pv6 inet6addressmatcher indexof converttobytes indexof netmaskstring indexof netmaskstring indexof converttobytes netmaskstring parseint netmaskstring full_mask full_mask converttobytes full_mask illegalargumentexception ipv6 private byte convert to bytes string address string tokenizer address tokens new string tokenizer address if address tokens count tokens 8 throw new illegal argument exception address is not an i pv6 address byte address bytes new byte 16 int count 0 while address tokens has more tokens int address word integer parse int address tokens next token 16 address bytes count 2 byte address word 8 0xff address bytes count 2 1 byte address word 0xff count return address bytes converttobytes stringtokenizer addresstokens stringtokenizer addresstokens counttokens illegalargumentexception ipv6 addressbytes addresstokens hasmoretokens addressword parseint addresstokens nexttoken addressbytes addressword addressbytes addressword addressbytes public boolean matches inet address address if address instanceof inet6 address return false byte address bytes address get address for int index 0 index 16 index if address bytes index netmask index this address index netmask index return false return true inetaddress inet6address addressbytes getaddress addressbytes public static boolean matches string pattern inet address address return new inet6 address matcher pattern matches address inetaddress inet6addressmatcher public string get human representation if netmask full mask return convert to string address else return convert to string address convert to string netmask gethumanrepresentation full_mask converttostring converttostring converttostring private string convert to string byte addr string builder sb new string builder 4 8 7 for int i 0 i 8 i if i 0 sb append int token addr i 2 0xff 8 addr i 2 1 0xff sb append integer to hex string token return sb to string converttostring stringbuilder stringbuilder tohexstring tostring creates a new persistent insert param uri the uri to insert data to param identifier the identifier of the insert param verbosity the verbosity bitmask param handler the fcp connection handler param priority class the priority for this insert param persistence type the persistence type of this insert param client token the client token of this insert param global whether this insert appears on the global queue param getchk only whether only the resulting chk is requested param dont compress whether the file should not be compressed param max retries the maximum number of retries param upload from type where the file is uploaded from param orig filename the original filename param content type the content type of the data param data the data may be code null code if code upload from type code is upload from redirect param redirect target the uri to redirect to if code upload from type code is upload from redirect throws identifier collision exception throws not allowed exception throws file not found exception throws malformedurl exception throws metadata unresolved exception throws insert exception public client put fcp client global client freeneturi uri string identifier int verbosity short priority class short persistence type string client token boolean getchk only boolean dont compress int max retries short upload from type file orig filename string content type bucket data freeneturi redirect target string target filename boolean early encode fcp server server object container container throws identifier collision exception not allowed exception file not found exception malformedurl exception metadata unresolved exception super uri identifier verbosity null global client priority class persistence type null true getchk only dont compress max retries early encode server container if upload from type client put message upload from disk if server core allow upload from orig filename throw new not allowed exception if orig filename exists orig filename can read throw new file not found exception logminor logger should log logger minor this binary blob false this target filename target filename this upload from upload from type this orig filename orig filename now go through the fields one at a time string mime type content type this client token client token bucket temp data data client metadata cm new client metadata mime type boolean is metadata false logminor logger should log logger minor this if logminor logger minor this data temp data upload from client put message upload from string upload from if upload from client put message upload from redirect this targeturi redirect target metadata m new metadata metadata simple redirect null null targeturi cm byte d d m write to byte array temp data new simple read only array bucket d is metadata true else targeturi null this data temp data this client metadata cm putter new client putter this data uri cm ctx priority class getchk only is metadata low level client null target filename binary blob priorityclass persistencetype clienttoken getchkonly dontcompress maxretries uploadfromtype origfilename contenttype uploadfromtype upload_from_redirect redirecttarget uploadfromtype upload_from_redirect identifiercollisionexception notallowedexception filenotfoundexception malformedurlexception metadataunresolvedexception insertexception clientput fcpclient globalclient priorityclass persistencetype clienttoken getchkonly dontcompress maxretries uploadfromtype origfilename contenttype redirecttarget targetfilename earlyencode fcpserver objectcontainer identifiercollisionexception notallowedexception filenotfoundexception malformedurlexception metadataunresolvedexception globalclient priorityclass persistencetype getchkonly dontcompress maxretries earlyencode uploadfromtype clientputmessage upload_from_disk allowuploadfrom origfilename notallowedexception origfilename origfilename canread filenotfoundexception shouldlog binaryblob targetfilename targetfilename uploadfrom uploadfromtype origfilename origfilename mimetype contenttype clienttoken clienttoken tempdata clientmetadata clientmetadata mimetype ismetadata shouldlog tempdata uploadfrom clientputmessage uploadfromstring uploadfrom uploadfrom clientputmessage upload_from_redirect redirecttarget simple_redirect writetobytearray tempdata simplereadonlyarraybucket ismetadata tempdata clientmetadata clientputter priorityclass getchkonly ismetadata lowlevelclient targetfilename binaryblob public client put fcp connection handler handler client put message message fcp server server object container container throws identifier collision exception message invalid exception malformedurl exception super message uri message identifier message verbosity handler message priority class message persistence type message client token message global message getchk only message dont compress message max retries message early encode server container string salt null byte salted hash null binary blob message binary blob if message upload from type client put message upload from disk if handler server core allow upload from message orig filename throw new message invalid exception protocol error message access denied not allowed to upload from message orig filename identifier global if message file hash null try salt handler connection identifier message identifier salted hash base64 decode message file hash catch illegal base64 exception e throw new message invalid exception protocol error message invalid field can t base64 decode client put base file hash identifier global else if handler allowdda from message orig filename false throw new message invalid exception protocol error message direct disk access denied not allowed to upload from message orig filename have you done a testdda previously identifier global this target filename message target filename logminor logger should log logger minor this this upload from message upload from type this orig filename message orig filename now go through the fields one at a time string mime type message content type if binary blob if mime type null mime type equals binary blob mime type throw new message invalid exception protocol error message invalid field no mime type allowed when inserting a binary blob identifier global if mime type null orig filename null mime type defaultmime types guessmime type orig filename get name true if mime type null target filename null mime type defaultmime types guessmime type target filename true if mime type null mime type defaultmime types guessmime type identifier true client token message client token bucket temp data message bucket client metadata cm new client metadata mime type boolean is metadata false if logminor logger minor this data temp data upload from client put message upload from string upload from if upload from client put message upload from redirect this targeturi message redirect target metadata m new metadata metadata simple redirect null null targeturi cm byte d try d m write to byte array catch metadata unresolved exception e impossible logger error this impossible e e this data null client metadata cm putter null this is not an insert exception since we don t register it it s a protocol error throw new message invalid exception protocol error message internal error impossible metadata unresolved e identifier global temp data new simple read only array bucket d is metadata true else targeturi null this data temp data this client metadata cm check the hash allow it to be null for backward compatibility and if testdda is allowed if salt null message digest md sha256 get message digest byte found hash try try md update salt get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e try input stream is data get input stream sha256 hash is md is close catch io exception e sha256 return message digest md logger error this got ioe e get message e throw new message invalid exception protocol error message could not read file unable to access file e identifier global found hash md digest finally sha256 return message digest md if logminor logger minor this file hash result we found base64 encode found hash and were given base64 encode salted hash if arrays equals salted hash found hash throw new message invalid exception protocol error message direct disk access denied the hash doesn t match salt used salt identifier global if logminor logger minor this data data upload from client put message upload from string upload from putter new client putter this data uri cm ctx priority class getchk only is metadata low level client null target filename binary blob clientput fcpconnectionhandler clientputmessage fcpserver objectcontainer identifiercollisionexception messageinvalidexception malformedurlexception priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode saltedhash binaryblob binaryblob uploadfromtype clientputmessage upload_from_disk allowuploadfrom origfilename messageinvalidexception protocolerrormessage access_denied origfilename filehash connectionidentifier saltedhash filehash illegalbase64exception messageinvalidexception protocolerrormessage invalid_field clientputbase file_hash allowddafrom origfilename messageinvalidexception protocolerrormessage direct_disk_access_denied origfilename targetfilename targetfilename shouldlog uploadfrom uploadfromtype origfilename origfilename mimetype contenttype binaryblob mimetype mimetype binaryblob mime_type messageinvalidexception protocolerrormessage invalid_field mimetype origfilename mimetype defaultmimetypes guessmimetype origfilename getname mimetype targetfilename mimetype defaultmimetypes guessmimetype targetfilename mimetype mimetype defaultmimetypes guessmimetype clienttoken clienttoken tempdata clientmetadata clientmetadata mimetype ismetadata tempdata uploadfrom clientputmessage uploadfromstring uploadfrom uploadfrom clientputmessage upload_from_redirect redirecttarget simple_redirect writetobytearray metadataunresolvedexception clientmetadata insertexception messageinvalidexception protocolerrormessage internal_error tempdata simplereadonlyarraybucket ismetadata tempdata clientmetadata messagedigest getmessagedigest foundhash getbytes unsupportedencodingexception inputstream getinputstream ioexception returnmessagedigest getmessage messageinvalidexception protocolerrormessage could_not_read_file foundhash returnmessagedigest filehash foundhash saltedhash saltedhash foundhash messageinvalidexception protocolerrormessage direct_disk_access_denied uploadfrom clientputmessage uploadfromstring uploadfrom clientputter priorityclass getchkonly ismetadata lowlevelclient targetfilename binaryblob create from a persisted simple field set not very tolerant of errors as the input was generated by the node throws persistence parse exception throws io exception throws insert exception public client put simple field set fs fcp client client2 fcp server server object container container throws persistence parse exception io exception insert exception super fs client2 server logminor logger should log logger minor this string mime type fs get metadata content type string from fs get upload from if from equals direct upload from client put message upload from direct else if from equals disk upload from client put message upload from disk else if from equals redirect upload from client put message upload from redirect else throw new persistence parse exception unknown upload from from client metadata cm new client metadata mime type boolean is metadata false binary blob fs get boolean binary blob false target filename fs get target filename if upload from client put message upload from disk orig filename new file fs get filename if logminor logger minor this uploading from disk orig filename for this data new file bucket orig filename true false false false false targeturi null else if upload from client put message upload from direct orig filename null if logminor logger minor this uploading from direct for this if finished try data serializable to field set bucket util create fs subset temp bucket server core random server core persistent temp bucket factory catch cannot create from field set exception e throw new persistence parse exception could not read old bucket for identifier e e else if logger should log logger minor this logger minor this finished already so not reading bucket for this data null targeturi null else if upload from client put message upload from redirect string target fs get targeturi targeturi new freeneturi target if logminor logger minor this uploading from redirect for this targeturi metadata m new metadata metadata simple redirect null null targeturi cm byte d try d m write to byte array catch metadata unresolved exception e impossible logger error this impossible e e this data null client metadata cm orig filename null putter null throw new insert exception insert exception internal error impossible e in client put null data new simple read only array bucket d orig filename null is metadata true else throw new persistence parse exception shouldn t happen if logminor logger minor this data data this client metadata cm simple field set old progress fs subset progress if finished old progress null not useful any more putter new client putter this data uri cm ctx priority class getchk only is metadata low level client old progress target filename binary blob if persistence type persist connection fcp message msg persistent tag message container client queue client request message msg 0 container simplefieldset persistenceparseexception ioexception insertexception clientput simplefieldset fcpclient fcpserver objectcontainer persistenceparseexception ioexception insertexception shouldlog mimetype contenttype uploadfrom uploadfrom clientputmessage upload_from_direct uploadfrom clientputmessage upload_from_disk uploadfrom clientputmessage upload_from_redirect persistenceparseexception uploadfrom clientmetadata clientmetadata mimetype ismetadata binaryblob getboolean binaryblob targetfilename targetfilename uploadfrom clientputmessage upload_from_disk origfilename origfilename filebucket origfilename uploadfrom clientputmessage upload_from_direct origfilename serializabletofieldsetbucketutil tempbucket persistenttempbucketfactory cannotcreatefromfieldsetexception persistenceparseexception shouldlog uploadfrom clientputmessage upload_from_redirect simple_redirect writetobytearray metadataunresolvedexception clientmetadata origfilename insertexception insertexception internal_error clientput simplereadonlyarraybucket origfilename ismetadata persistenceparseexception clientmetadata simplefieldset oldprogress oldprogress clientputter priorityclass getchkonly ismetadata lowlevelclient oldprogress targetfilename binaryblob persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage override void register object container container boolean lazy resume boolean no tags throws identifier collision exception if persistence type persist connection client register this false container if persistence type persist connection no tags fcp message msg persistent tag message container client queue client request message msg 0 container objectcontainer lazyresume notags identifiercollisionexception persistencetype persist_connection persistencetype persist_connection notags fcpmessage persistenttagmessage queueclientrequestmessage override public void start object container container client context context if logger should log logger minor this logger minor this starting this identifier synchronized this if finished return try putter start early encode false container context if persistence type persist connection finished fcp message msg persistent tag message container client queue client request message msg 0 container synchronized this started true if persistence type persist forever container store this update catch insert exception e synchronized this started true on failure e null container catch throwable t synchronized this started true on failure new insert exception insert exception internal error t null null container objectcontainer clientcontext shouldlog earlyencode persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage persistencetype persist_forever insertexception onfailure onfailure insertexception insertexception internal_error override protected void free data object container container bucket d synchronized this d data data null if d null return if persistence type persist forever container activate d 5 finished size d size d free if persistence type persist forever d remove from container freedata objectcontainer persistencetype persist_forever finishedsize persistencetype persist_forever removefrom override protected freenet client async client requester get client request return putter clientrequester getclientrequest override protected fcp message persistent tag message object container container if persistence type persist forever container activate publicuri 5 container activate client metadata 5 container activate orig filename 5 return new persistent put identifier publicuri verbosity priority class upload from targeturi persistence type orig filename client metadata getmime type client is global queue get data size container client token started ctx max insert retries target filename binary blob fcpmessage persistenttagmessage objectcontainer persistencetype persist_forever clientmetadata origfilename persistentput priorityclass uploadfrom persistencetype origfilename clientmetadata getmimetype isglobalqueue getdatasize clienttoken maxinsertretries targetfilename binaryblob override protected string get type name return put gettypename override public boolean has succeeded return succeeded hassucceeded public freeneturi get finaluri object container container if persistence type persist forever container activate generateduri 5 return generateduri getfinaluri objectcontainer persistencetype persist_forever public boolean is direct return upload from client put message upload from direct isdirect uploadfrom clientputmessage upload_from_direct public file get orig filename object container container if upload from client put message upload from disk return null if persistence type persist forever container activate orig filename 5 return orig filename getorigfilename objectcontainer uploadfrom clientputmessage upload_from_disk persistencetype persist_forever origfilename origfilename public long get data size object container container if data null return finished size else if persistence type persist forever container activate data 1 return data size getdatasize objectcontainer finishedsize persistencetype persist_forever public string getmime type return client metadata getmime type getmimetype clientmetadata getmimetype override public boolean can restart if finished logger minor this cannot restart because not finished for identifier return false if succeeded logger minor this cannot restart because succeeded for identifier return false return putter can restart canrestart canrestart override public boolean restart object container container client context context if can restart return false set vars restart container try if putter restart early encode container context synchronized this generateduri null started true if persistence type persist forever container store this return true catch insert exception e on failure e null container return false objectcontainer clientcontext canrestart setvarsrestart earlyencode persistencetype persist_forever insertexception onfailure public void on failure fetch exception e client getter state object container container onfailure fetchexception clientgetter objectcontainer public void on failure fetch exception e client getter state object container container public void on success fetch result result client getter state object container container onfailure fetchexception clientgetter objectcontainer onsuccess fetchresult clientgetter objectcontainer public void on success fetch result result client getter state object container container public void on remove event producer object container container do nothing we called the remove from onsuccess fetchresult clientgetter objectcontainer onremoveeventproducer objectcontainer removefrom override public void request was removed object container container client context context if persistence type persist forever container activate putter 1 putter remove from container context putter null if orig filename null container activate orig filename 5 container delete orig filename client metadata will be deleted by putter if targeturi null container activate targeturi 5 targeturi remove from container super request was removed container context requestwasremoved objectcontainer clientcontext persistencetype persist_forever removefrom origfilename origfilename origfilename clientmetadata removefrom requestwasremoved private final segmented bucket chain bucket bcb public segmented chain bucket segment segmented bucket chain bucket bucket this bcb bucket this buckets new array list bucket segmentedbucketchainbucket segmentedchainbucketsegment segmentedbucketchainbucket arraylist public void free for bucket bucket buckets if bucket null logger error this bucket is null on this continue bucket free public void store to object container container if logger should log logger minor this logger minor this storing segment this for bucket bucket buckets bucket store to container container ext store buckets 1 container ext store this 1 storeto objectcontainer shouldlog storeto public synchronized bucket shallow copy buckets int sz buckets size bucket out new bucket sz for int i 0 i sz i out i buckets get i return out shallowcopybuckets public synchronized void shallow copy buckets bucket out int index int sz buckets size for int i 0 i sz i out index buckets get i shallowcopybuckets public output stream make bucket stream int bucket no throws io exception if bucket no bcb segment size throw new illegal argument exception too many buckets in segment bucket b bcb bf make bucket bcb bucket size synchronized this if buckets size bucket no throw new illegal argument exception next bucket should be buckets size but is bucket no buckets add b return b get output stream outputstream makebucketstream bucketno ioexception bucketno segmentsize illegalargumentexception makebucket bucketsize bucketno illegalargumentexception bucketno getoutputstream public int size return buckets size void activate buckets object container container container activate buckets 1 for bucket bucket buckets container activate bucket 1 will cascade activatebuckets objectcontainer public void clear object container container buckets clear container delete buckets container delete this objectcontainer public void remove from object container container for bucket bucket buckets if bucket null probably not a problem continue container activate bucket 1 bucket remove from container container delete buckets container delete this removefrom objectcontainer removefrom construct a scale filter public scale filter this 32 32 scalefilter scalefilter construct a scale filter param width the width to scale to param height the height to scale to public scale filter int width int height this width width this height height scalefilter scalefilter public buffered image filter buffered image src buffered image dst int w src get width int h src get height if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster w h dstcm is alpha premultiplied null image scale image src get scaled instance w h image scale area averaging graphics2d g dst create graphics g draw image src 0 0 width height null g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight colormodel getcolormodel bufferedimage createcompatiblewritableraster isalphapremultiplied scaleimage getscaledinstance scale_area_averaging creategraphics drawimage override public string to string return distort scale tostring public queue toadlet node client core core fcp server fcp high level simple client client super client this core core this fcp fcp if fcp null throw new null pointer exception fcp set completion callback this load completed identifiers queuetoadlet nodeclientcore fcpserver highlevelsimpleclient nullpointerexception setcompletioncallback loadcompletedidentifiers override public void handle post uri uri http request request final toadlet context ctx throws toadlet context closed exception io exception redirect exception if core has loaded queue write error l10n get string queue toadlet not loaded yet title l10n get string queue toadlet not loaded yet ctx false return if container public gateway mode ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return boolean logminor logger should log logger minor this try browse button if request get part as string insert local 128 length 0 preserve the key freeneturi inserturi string key type request get part as string keytype 3 if chk equals key type inserturi new freeneturi chk else try string u request get part as string key 128 inserturi new freeneturi u if logminor logger minor this inserting key inserturi u catch malformedurl exception mue1 write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return multi value table string string response headers new multi value table string string response headers put location files key inserturi toascii string ctx send reply headers 302 found response headers null 0 return string pass request get part as string form password 32 if pass length 0 pass equals core form password multi value table string string headers new multi value table string string headers put location queue ctx send reply headers 302 found headers null 0 if logminor logger minor this no form password pass return if request is part set remove request request get part as string remove request 32 length 0 string identifier request get part as string identifier max identifier length if logminor logger minor this removing identifier try fcp remove global request blocking identifier catch message invalid exception e this send error page ctx 200 l10n get string queue toadlet failed to remove request l10n get string queue toadlet failed to remove new string id message new string identifier e get message return write permanent redirect ctx done queue return else if request is part set restart request request get part as string restart request 32 length 0 string identifier request get part as string identifier max identifier length if logminor logger minor this restarting identifier fcp restart blocking identifier write permanent redirect ctx done queue return else if request is part set remove allrequests request get part as string remove allrequests 32 length 0 fixme panic button should just dump the entire database fixme what about non global requests boolean success false try success fcp remove all global requests blocking catch exception e logger error this exception on remove all e if success this send error page ctx 200 l10n get string queue toadlet failed to remove request l10n get string queue toadlet failed to remove all else write permanent redirect ctx done queue return else if request is part set download queue a download if request is part set key write error l10n get string queue toadlet error no key l10n get string queue toadlet error no key tod ctx return string expectedmime type null if request is part set type expectedmime type request get part as string type max type length freeneturi fetchuri try fetchuri new freeneturi request get part as string key max key length catch malformedurl exception e write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tod ctx return string persistence request get part as string persistence 32 string return type request get part as string return type 32 try fcp make persistent global request blocking fetchuri expectedmime type persistence return type catch not allowed exception e this write error l10n get string queue toadlet errord to disk l10n get string queue toadlet errord to disk config ctx return write permanent redirect ctx done queue return else if request is part set bulk downloads string bulk downloads as string request get part as string bulk downloads integer max value string keys bulk downloads as string split n if equals bulk downloads as string keys length 1 write permanent redirect ctx done queue return linked list string success new linked list string failure new linked list string for int i 0 i keys length i string current key keys i try freeneturi fetchuri new freeneturi current key fcp make persistent global request blocking fetchuri null forever disk success add current key catch exception e failure add current key logger error this an error occured while attempting to download key i current key e get message boolean display failure box failure size 0 boolean display success box success size 0 html node page node ctx get page maker get page node l10n get string queue toadlet download files ctx html node content node ctx get page maker get content node page node html node alert node content node add child ctx get page maker get infobox display failure box infobox warning infobox info l10n get string queue toadlet download files html node alert content ctx get page maker get content node alert node iterator string it if display success box html node success div alert content add child ul success div add child l10n get string queue toadlet enqueued successfully number string value of success size it success iterator while it has next html node line success div add child li line add child it next success div add child br if display failure box html node failure div alert content add child ul if display failure box failure div add child l10n get string queue toadlet enqueued failure number string value of failure size it failure iterator while it has next html node line failure div add child li line add child it next failure div add child br alert content add child a href queue l10n get string toadlet return to queuepage writehtml reply ctx 200 ok page node generate return else if request is part set change priority string identifier request get part as string identifier max identifier length short new priority short parse short request get part as string priority 32 fcp modify global request blocking identifier null new priority write permanent redirect ctx done queue return fixme factor out the next 3 items they are very messy else if request get part as string insert 128 length 0 final freeneturi inserturi string key type request get part as string keytype 3 if chk equals key type inserturi new freeneturi chk else try string u request get part as string key 128 inserturi new freeneturi u if logminor logger minor this inserting key inserturi u catch malformedurl exception mue1 write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return final http uploaded file file request get uploaded file filename if file null file get filename trim length 0 write error l10n get string queue toadlet error no file selected l10n get string queue toadlet error no file selectedu ctx return final boolean compress request get part as string compress 128 length 0 final string identifier file get filename fred system current time millis final string fnam if inserturi get key type equals chk fnam file get filename else fnam null copy bucket data final bucket copied bucket core persistent temp bucket factory make bucket file get data size bucket tools copy file get data copied bucket final mutable boolean done new mutable boolean core queue new db job public void run object container container client context context try final client put client put try client put new client put fcp get global forever client inserturi identifier integer max value request starter bulk splitfile priority class client request persist forever null false compress 1 client put message upload from direct null file get content type copied bucket null fnam false fcp container if client put null try fcp start blocking client put container context catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return wri handlepost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception hasloadedqueue writeerror getstring queuetoadlet notloadedyettitle getstring queuetoadlet notloadedyet publicgatewaymode isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring shouldlog getpartasstring keytype getpartasstring keytype getpartasstring malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou multivaluetable responseheaders multivaluetable responseheaders toasciistring sendreplyheaders responseheaders getpartasstring formpassword formpassword multivaluetable multivaluetable sendreplyheaders formpassword ispartset remove_request getpartasstring remove_request getpartasstring max_identifier_length removeglobalrequestblocking messageinvalidexception senderrorpage getstring queuetoadlet failedtoremoverequest getstring queuetoadlet failedtoremove getmessage writepermanentredirect ispartset restart_request getpartasstring restart_request getpartasstring max_identifier_length restartblocking writepermanentredirect ispartset remove_allrequests getpartasstring remove_allrequests removeallglobalrequestsblocking senderrorpage getstring queuetoadlet failedtoremoverequest getstring queuetoadlet failedtoremoveall writepermanentredirect ispartset ispartset writeerror getstring queuetoadlet errornokey getstring queuetoadlet errornokeytod expectedmimetype ispartset expectedmimetype getpartasstring max_type_length getpartasstring max_key_length malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritod getpartasstring returntype getpartasstring makepersistentglobalrequestblocking expectedmimetype returntype notallowedexception writeerror getstring queuetoadlet errordtodisk getstring queuetoadlet errordtodiskconfig writepermanentredirect ispartset bulkdownloads bulkdownloadsasstring getpartasstring bulkdownloads max_value bulkdownloadsasstring bulkdownloadsasstring writepermanentredirect linkedlist linkedlist linkedlist currentkey currentkey makepersistentglobalrequestblocking currentkey currentkey currentkey getmessage displayfailurebox displaysuccessbox htmlnode pagenode getpagemaker getpagenode getstring queuetoadlet downloadfiles htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode alertnode contentnode addchild getpagemaker getinfobox displayfailurebox getstring queuetoadlet downloadfiles htmlnode alertcontent getpagemaker getcontentnode alertnode displaysuccessbox htmlnode successdiv alertcontent addchild successdiv addchild getstring queuetoadlet enqueuedsuccessfully valueof hasnext htmlnode successdiv addchild addchild successdiv addchild displayfailurebox htmlnode failurediv alertcontent addchild displayfailurebox failurediv addchild getstring queuetoadlet enqueuedfailure valueof hasnext htmlnode failurediv addchild addchild failurediv addchild alertcontent addchild getstring returntoqueuepage writehtmlreply pagenode ispartset change_priority getpartasstring max_identifier_length newpriority parseshort getpartasstring modifyglobalrequestblocking newpriority writepermanentredirect getpartasstring keytype getpartasstring keytype getpartasstring malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou httpuploadedfile getuploadedfile getfilename writeerror getstring queuetoadlet errornofileselected getstring queuetoadlet errornofileselectedu getpartasstring getfilename currenttimemillis getkeytype getfilename copiedbucket persistenttempbucketfactory makebucket getdata buckettools getdata copiedbucket mutableboolean mutableboolean dbjob objectcontainer clientcontext clientput clientput clientput clientput getglobalforeverclient max_value requeststarter bulk_splitfile_priority_class clientrequest persist_forever clientputmessage upload_from_direct getcontenttype copiedbucket clientput startblocking clientput identifiercollisionexception writepermanentredirect public void run object container container client context context try final client put client put try client put new client put fcp get global forever client inserturi identifier integer max value request starter bulk splitfile priority class client request persist forever null false compress 1 client put message upload from direct null file get content type copied bucket null fnam false fcp container if client put null try fcp start blocking client put container context catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return write permanent redirect ctx done queue return catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return catch not allowed exception e write error l10n get string queue toadlet error access denied l10n get string queue toadlet error access denied file new string file new string file get filename ctx return catch file not found exception e write error l10n get string queue toadlet error no file or cannot read l10n get string queue toadlet error access denied file new string file new string file get filename ctx return catch malformedurl exception mue1 write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return catch metadata unresolved exception e logger error this unresolved metadata in starting insert from data uploaded from browser e e write permanent redirect ctx done queue return fixme should this be a proper localised message it shouldn t happen but we d like to get reports if it does catch throwable t write internal error t ctx finally synchronized done done value true done notify all catch io exception e ignore catch toadlet context closed exception e ignore objectcontainer clientcontext clientput clientput clientput clientput getglobalforeverclient max_value requeststarter bulk_splitfile_priority_class clientrequest persist_forever clientputmessage upload_from_direct getcontenttype copiedbucket clientput startblocking clientput identifiercollisionexception writepermanentredirect writepermanentredirect identifiercollisionexception writepermanentredirect notallowedexception writeerror getstring queuetoadlet erroraccessdenied getstring queuetoadlet erroraccessdeniedfile getfilename filenotfoundexception writeerror getstring queuetoadlet errornofileorcannotread getstring queuetoadlet erroraccessdeniedfile getfilename malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou metadataunresolvedexception writepermanentredirect writeinternalerror notifyall ioexception toadletcontextclosedexception public void run object container container client context context final client put client put try try client put new client put fcp get global forever client furi identifier integer max value request starter bulk splitfile priority class client request persist forever null false false 1 client put message upload from disk file content type new file bucket file true false false false false null target false fcp container if logger should log logger minor this logger minor this started global request to insert file to chk as identifier if client put null try fcp start blocking client put container context catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return write permanent redirect ctx done queue return catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return catch malformedurl exception e write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return catch file not found exception e write error l10n get string queue toadlet error no file or cannot read l10n get string queue toadlet error access denied file new string file new string target ctx return catch not allowed exception e write error l10n get string queue toadlet error access denied l10n get string queue toadlet error access denied file new string file new string file get name ctx return catch metadata unresolved exception e logger error this unresolved metadata in starting insert from data from file e e write permanent redirect ctx done queue return fixme should this be a proper localised message it shouldn t happen but we d like to get reports if it does finally synchronized done done value true done notify all catch io exception e ignore catch toadlet context closed exception e ignore objectcontainer clientcontext clientput clientput clientput clientput getglobalforeverclient max_value requeststarter bulk_splitfile_priority_class clientrequest persist_forever clientputmessage upload_from_disk contenttype filebucket shouldlog clientput startblocking clientput identifiercollisionexception writepermanentredirect writepermanentredirect identifiercollisionexception writepermanentredirect malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou filenotfoundexception writeerror getstring queuetoadlet errornofileorcannotread getstring queuetoadlet erroraccessdeniedfile notallowedexception writeerror getstring queuetoadlet erroraccessdenied getstring queuetoadlet erroraccessdeniedfile getname metadataunresolvedexception writepermanentredirect notifyall ioexception toadletcontextclosedexception public void run object container container client context context client put dir client put dir try try boolean logminor logger should log logger minor this client put dir new client put dir fcp get global forever client furi identifier integer max value request starter bulk splitfile priority class client request persist forever null false false 1 file null false true false fcp container if logminor logger minor this started global request to insert dir file to furi as identifier if client put dir null try fcp start blocking client put dir container context catch identifier collision exception e logger error this cannot put same file twice in same millisecond write permanent redirect ctx done queue return write permanent redirect ctx done queue return catch identifier collision exception e logger error this cannot put same directory twice in same millisecond write permanent redirect ctx done queue return catch malformedurl exception e write error l10n get string queue toadlet error invaliduri l10n get string queue toadlet error invaliduri tou ctx return catch file not found exception e write error l10n get string queue toadlet error no file or cannot read l10n get string queue toadlet error access denied file new string file new string file to string ctx return finally synchronized done done value true done notify all catch io exception e ignore catch toadlet context closed exception e ignore objectcontainer clientcontext clientputdir clientputdir shouldlog clientputdir clientputdir getglobalforeverclient max_value requeststarter bulk_splitfile_priority_class clientrequest persist_forever clientputdir startblocking clientputdir identifiercollisionexception writepermanentredirect writepermanentredirect identifiercollisionexception writepermanentredirect malformedurlexception writeerror getstring queuetoadlet errorinvaliduri getstring queuetoadlet errorinvaliduritou filenotfoundexception writeerror getstring queuetoadlet errornofileorcannotread getstring queuetoadlet erroraccessdeniedfile tostring notifyall ioexception toadletcontextclosedexception private void write error string header string message toadlet context context throws toadlet context closed exception io exception write error header message context true writeerror toadletcontext toadletcontextclosedexception ioexception writeerror private void write error string header string message toadlet context context boolean return to queue page throws toadlet context closed exception io exception page maker page maker context get page maker html node page node page maker get page node header context html node content node page maker get content node page node if context is allowed full access content node add child core alerts create summary html node infobox content node add child page maker get infobox infobox error header html node infobox content page maker get content node infobox infobox content add child message if return to queue page infobox content add child div add children new html node new html node return to new html node a href queue queue page new html node writehtml reply context 400 bad request page node generate writeerror toadletcontext returntoqueuepage toadletcontextclosedexception ioexception pagemaker pagemaker getpagemaker htmlnode pagenode pagemaker getpagenode htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode contentnode addchild pagemaker getinfobox htmlnode infoboxcontent pagemaker getcontentnode infoboxcontent addchild returntoqueuepage infoboxcontent addchild addchildren htmlnode htmlnode htmlnode htmlnode writehtmlreply pagenode override public void handle get uri uri final http request request final toadlet context ctx throws toadlet context closed exception io exception redirect exception we ensure that we have a fcp server running if fcp enabled write error l10n get string queue toadlet fcp is missing l10n get string queue toadlet please enablefcp ctx false return if core has loaded queue write error l10n get string queue toadlet not loaded yet title l10n get string queue toadlet not loaded yet ctx false return if container public gateway mode ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return final string request path request get path substring queue length boolean count requests false if request path length 0 if request path equals count requests html request path equals count requests html count requests true else okay there is something in the path check it try freeneturi key new freeneturi request path locate request temp fetch result result fcp get completed request blocking key if result null bucket data result as bucket string mime type result get mime type string requested mime type request get param type null string force string request get param force f proxy toadlet handle download ctx data ctx get bucket factory mime type requested mime type force string request is parameter set forcedownload queue key queue false ctx core false if result free when done data free return catch malformedurl exception mue1 class output wrapper boolean done html node page node final output wrapper ow new output wrapper final page maker page maker ctx get page maker final boolean count count requests core client context job runner queue new db job public void run object container container client context context html node page node null try if count long queued core request starters chk fetch scheduler count persistent waiting keys container system err println total waiting ch ks queued long really queued core request starters chk fetch scheduler count persistent queued requests container system err println total queued chk requests really queued page node page maker get page node l10n get string queue toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary html node infobox content node add child page maker get infobox infobox information queued requests status html node infobox content page maker get content node infobox infobox content add child p total awaiting ch ks queued infobox content add child p total queued chk requests really queued return else page node handle get inner page maker container context request ctx finally synchronized ow ow done true ow page node page node ow notify all native thread high priority false html node page node synchronized ow while true if ow done page node ow page node break try ow wait catch interrupted exception e ignore multi value table string string page headers new multi value table string string if page node null writehtml reply ctx 200 ok page headers page node generate else this write error internal error internal error ctx handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception writeerror getstring queuetoadlet fcpismissing getstring queuetoadlet pleaseenablefcp hasloadedqueue writeerror getstring queuetoadlet notloadedyettitle getstring queuetoadlet notloadedyet publicgatewaymode isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring requestpath getpath countrequests requestpath requestpath countrequests requestpath countrequests countrequests requestpath tempfetchresult getcompletedrequestblocking asbucket mimetype getmimetype requestedmimetype getparam forcestring getparam fproxytoadlet handledownload getbucketfactory mimetype requestedmimetype forcestring isparameterset freewhendone malformedurlexception outputwrapper htmlnode pagenode outputwrapper outputwrapper pagemaker pagemaker getpagemaker countrequests clientcontext jobrunner dbjob objectcontainer clientcontext htmlnode pagenode requeststarters chkfetchscheduler countpersistentwaitingkeys chks reallyqueued requeststarters chkfetchscheduler countpersistentqueuedrequests reallyqueued pagenode pagemaker getpagenode getstring queuetoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode contentnode addchild pagemaker getinfobox htmlnode infoboxcontent pagemaker getcontentnode infoboxcontent addchild chks infoboxcontent addchild reallyqueued pagenode handlegetinner pagemaker pagenode pagenode notifyall nativethread high_priority htmlnode pagenode pagenode pagenode interruptedexception multivaluetable pageheaders multivaluetable pagenode writehtmlreply pageheaders pagenode writeerror public void run object container container client context context html node page node null try if count long queued core request starters chk fetch scheduler count persistent waiting keys container system err println total waiting ch ks queued long really queued core request starters chk fetch scheduler count persistent queued requests container system err println total queued chk requests really queued page node page maker get page node l10n get string queue toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary html node infobox content node add child page maker get infobox infobox information queued requests status html node infobox content page maker get content node infobox infobox content add child p total awaiting ch ks queued infobox content add child p total queued chk requests really queued return else page node handle get inner page maker container context request ctx finally synchronized ow ow done true ow page node page node ow notify all objectcontainer clientcontext htmlnode pagenode requeststarters chkfetchscheduler countpersistentwaitingkeys chks reallyqueued requeststarters chkfetchscheduler countpersistentqueuedrequests reallyqueued pagenode pagemaker getpagenode getstring queuetoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode contentnode addchild pagemaker getinfobox htmlnode infoboxcontent pagemaker getcontentnode infoboxcontent addchild chks infoboxcontent addchild reallyqueued pagenode handlegetinner pagemaker pagenode pagenode notifyall private html node handle get inner page maker page maker final object container container client context context final http request request toadlet context ctx first get the queued requests and separate them into different types linked list client request completed download to disk new linked list client request linked list client request completed download to temp new linked list client request linked list client request completed upload new linked list client request linked list client request completed dir upload new linked list client request linked list client request failed download new linked list client request linked list client request failed upload new linked list client request linked list client request failed dir upload new linked list client request linked list client request uncompleted download new linked list client request linked list client request uncompleted upload new linked list client request linked list client request uncompleted dir upload new linked list client request client request reqs fcp get global requests container if logger should log logger minor this logger minor this request count reqs length if reqs length 1 html node page node page maker get page node l10n get string queue toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary html node infobox content node add child page maker get infobox infobox information l10n get string queue toadlet global queue is empty html node infobox content page maker get content node infobox infobox content add child l10n get string queue toadlet no task on global queue content node add child create insert box page maker ctx core is advanced mode enabled content node add child create bulk download form ctx page maker return page node short lowest queued prio request starter minimum priority class long total queued download size 0 long total queued upload size 0 for int i 0 i reqs length i client request req reqs i if req instanceof client get client get cg client get req if cg has succeeded if cg is direct completed download to temp add cg else if cg is to disk completed download to disk add cg else fixme logger error this don t know what to do with cg else if cg has finished failed download add cg else short prio cg get priority if prio lowest queued prio lowest queued prio prio uncompleted download add cg long size cg get data size container if size 0 total queued download size size else if req instanceof client put client put cp client put req if cp has succeeded completed upload add cp else if cp has finished failed upload add cp else short prio req get priority if prio lowest queued prio lowest queued prio prio uncompleted upload add cp long size cp get data size container if size 0 total queued upload size size else if req instanceof client put dir client put dir cp client put dir req if cp has succeeded completed dir upload add cp else if cp has finished failed dir upload add cp else short prio req get priority if prio lowest queued prio lowest queued prio prio uncompleted dir upload add cp long size cp get total data size if size 0 total queued upload size size system err println total queued downloads size util format size total queued download size system err println total queued uploads size util format size total queued upload size comparator client request job comparator new comparator client request public int compare client request first request client request second request int result 0 boolean is set true if request is parameter set sort by final string sort by request get param sort by if sort by equals id result first request get identifier compare to ignore case second request get identifier else if sort by equals size result first request get total blocks container second request get total blocks container 0 1 1 else if sort by equals progress result first request get fetched blocks container first request get min blocks container second request get fetched blocks container second request get min blocks container 0 1 1 else is set false else is set false if is set int priority difference first request get priority second request get priority if priority difference 0 result priority difference 0 1 1 else result first request get identifier compare to second request get identifier if result 0 return 0 else if request is parameter set reversed is reversed true return result 0 1 1 else is reversed false return result 0 1 1 collections sort completed download to disk job comparator collections sort completed download to temp job comparator collections sort completed upload job comparator collections sort completed dir upload job comparator collections sort failed download job comparator collections sort failed upload job comparator collections sort failed dir upload job comparator collections sort uncompleted download job comparator collections sort uncompleted upload job comparator collections sort uncompleted dir upload job comparator html node page node page maker get page node uncompleted dir upload size uncompleted download size uncompleted upload size failed dir upload size failed download size failed upload size completed dir upload size completed download to disk size completed download to temp size completed upload size l10n get string queue toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary final int mode page maker draw mode selection array core request content node add file insert box content node add child create insert box page maker ctx mode page maker mode advanced navigation bar html node navigation bar page maker get infobox navbar l10n get string queue toadlet request navigation html node navigation content page maker get content node navigation bar add child ul boolean include navigation bar false if completed download to temp is empty navigation content add child li add child a href completed download to temp l10n get string queue toadlet completed dto temp new string size new string string value of completed download to temp size include navigation bar true if completed download to disk is empty navigation content add child li add child a href completed download to disk l10n get string queue toadlet completed dto disk new string size new string string value of completed download to disk size include navigation bar true if completed upload is empty navigation content add child li add child a href completed upload l10n get string queue toadlet completedu new string size new string string value of completed upload size include navigation bar true if completed dir upload is empty navigation content add child li add child a href completed dir upload l10n get string queue toadlet completeddu new string size new string string value of completed dir upload size include navigation bar true if failed download is empty navigation content add child li add child a href failed download l10n get string queue toadlet failedd new string size new string string value of failed download size include navigation bar true if failed upload is empty navigation content add child li add child a href failed upload l10n get string queue toadlet failedu new string size new string string value of failed upload size include navigation bar true if failed dir upload is empty navigation content add child li add child a href failed dir upload l10n get string queue toadlet faileddu new string size new string string value of failed dir upload size include navigation bar true if uncompleted download is empty navigation content add child li add child a href uncompleted download l10n get string queue toadlet din progress new string size new string string value of uncompleted download size include navigation bar true if uncompleted upload is empty navigation content add child li add child a href uncompleted upload l10n get string queue toadlet uin progress new string size new string string value of uncompleted upload size include navigation bar true if uncompleted dir upload is empty navigation content add child li add child a href uncompleted dir upload l10n get string queue toadlet d uin progress new string size new string string value of uncompleted dir upload size include navigation bar true if total queued download size 0 navigation content add child li l10n get string queue toadlet tota htmlnode handlegetinner pagemaker pagemaker objectcontainer clientcontext httprequest toadletcontext linkedlist clientrequest completeddownloadtodisk linkedlist clientrequest linkedlist clientrequest completeddownloadtotemp linkedlist clientrequest linkedlist clientrequest completedupload linkedlist clientrequest linkedlist clientrequest completeddirupload linkedlist clientrequest linkedlist clientrequest faileddownload linkedlist clientrequest linkedlist clientrequest failedupload linkedlist clientrequest linkedlist clientrequest faileddirupload linkedlist clientrequest linkedlist clientrequest uncompleteddownload linkedlist clientrequest linkedlist clientrequest uncompletedupload linkedlist clientrequest linkedlist clientrequest uncompleteddirupload linkedlist clientrequest clientrequest getglobalrequests shouldlog htmlnode pagenode pagemaker getpagenode getstring queuetoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode contentnode addchild pagemaker getinfobox getstring queuetoadlet globalqueueisempty htmlnode infoboxcontent pagemaker getcontentnode infoboxcontent addchild getstring queuetoadlet notaskonglobalqueue contentnode addchild createinsertbox pagemaker isadvancedmodeenabled contentnode addchild createbulkdownloadform pagemaker pagenode lowestqueuedprio requeststarter minimum_priority_class totalqueueddownloadsize totalqueueduploadsize clientrequest clientget clientget clientget hassucceeded isdirect completeddownloadtotemp istodisk completeddownloadtodisk hasfinished faileddownload getpriority lowestqueuedprio lowestqueuedprio uncompleteddownload getdatasize totalqueueddownloadsize clientput clientput clientput hassucceeded completedupload hasfinished failedupload getpriority lowestqueuedprio lowestqueuedprio uncompletedupload getdatasize totalqueueduploadsize clientputdir clientputdir clientputdir hassucceeded completeddirupload hasfinished faileddirupload getpriority lowestqueuedprio lowestqueuedprio uncompleteddirupload gettotaldatasize totalqueueduploadsize sizeutil formatsize totalqueueddownloadsize sizeutil formatsize totalqueueduploadsize clientrequest jobcomparator clientrequest clientrequest firstrequest clientrequest secondrequest isset isparameterset sortby sortby getparam sortby sortby firstrequest getidentifier comparetoignorecase secondrequest getidentifier sortby firstrequest gettotalblocks secondrequest gettotalblocks sortby firstrequest getfetchedblocks firstrequest getminblocks secondrequest getfetchedblocks secondrequest getminblocks isset isset isset prioritydifference firstrequest getpriority secondrequest getpriority prioritydifference prioritydifference firstrequest getidentifier compareto secondrequest getidentifier isparameterset isreversed isreversed completeddownloadtodisk jobcomparator completeddownloadtotemp jobcomparator completedupload jobcomparator completeddirupload jobcomparator faileddownload jobcomparator failedupload jobcomparator faileddirupload jobcomparator uncompleteddownload jobcomparator uncompletedupload jobcomparator uncompleteddirupload jobcomparator htmlnode pagenode pagemaker getpagenode uncompleteddirupload uncompleteddownload uncompletedupload faileddirupload faileddownload failedupload completeddirupload completeddownloadtodisk completeddownloadtotemp completedupload getstring queuetoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary pagemaker drawmodeselectionarray contentnode contentnode addchild createinsertbox pagemaker pagemaker mode_advanced htmlnode navigationbar pagemaker getinfobox getstring queuetoadlet requestnavigation htmlnode navigationcontent pagemaker getcontentnode navigationbar addchild includenavigationbar completeddownloadtotemp isempty navigationcontent addchild addchild completeddownloadtotemp getstring queuetoadlet completeddtotemp valueof completeddownloadtotemp includenavigationbar completeddownloadtodisk isempty navigationcontent addchild addchild completeddownloadtodisk getstring queuetoadlet completeddtodisk valueof completeddownloadtodisk includenavigationbar completedupload isempty navigationcontent addchild addchild completedupload getstring queuetoadlet valueof completedupload includenavigationbar completeddirupload isempty navigationcontent addchild addchild completeddirupload getstring queuetoadlet valueof completeddirupload includenavigationbar faileddownload isempty navigationcontent addchild addchild faileddownload getstring queuetoadlet valueof faileddownload includenavigationbar failedupload isempty navigationcontent addchild addchild failedupload getstring queuetoadlet valueof failedupload includenavigationbar faileddirupload isempty navigationcontent addchild addchild faileddirupload getstring queuetoadlet valueof faileddirupload includenavigationbar uncompleteddownload isempty navigationcontent addchild addchild uncompleteddownload getstring queuetoadlet dinprogress valueof uncompleteddownload includenavigationbar uncompletedupload isempty navigationcontent addchild addchild uncompletedupload getstring queuetoadlet uinprogress valueof uncompletedupload includenavigationbar uncompleteddirupload isempty navigationcontent addchild addchild uncompleteddirupload getstring queuetoadlet duinprogress valueof uncompleteddirupload includenavigationbar totalqueueddownloadsize navigationcontent addchild getstring queuetoadlet comparator client request job comparator new comparator client request public int compare client request first request client request second request int result 0 boolean is set true if request is parameter set sort by final string sort by request get param sort by if sort by equals id result first request get identifier compare to ignore case second request get identifier else if sort by equals size result first request get total blocks container second request get total blocks container 0 1 1 else if sort by equals progress result first request get fetched blocks container first request get min blocks container second request get fetched blocks container second request get min blocks container 0 1 1 else is set false else is set false if is set int priority difference first request get priority second request get priority if priority difference 0 result priority difference 0 1 1 else result first request get identifier compare to second request get identifier if result 0 return 0 else if request is parameter set reversed is reversed true return result 0 1 1 else is reversed false return result 0 1 1 clientrequest jobcomparator clientrequest clientrequest firstrequest clientrequest secondrequest isset isparameterset sortby sortby getparam sortby sortby firstrequest getidentifier comparetoignorecase secondrequest getidentifier sortby firstrequest gettotalblocks secondrequest gettotalblocks sortby firstrequest getfetchedblocks firstrequest getminblocks secondrequest getfetchedblocks secondrequest getminblocks isset isset isset prioritydifference firstrequest getpriority secondrequest getpriority prioritydifference prioritydifference firstrequest getidentifier compareto secondrequest getidentifier isparameterset isreversed isreversed private html node create reason cell string failure reason html node reason cell new html node td class request reason if failure reason null reason cell add child span class failure reason unknown l10n get string queue toadlet unknown else reason cell add child span class failure reason is failure reason return reason cell htmlnode createreasoncell failurereason htmlnode reasoncell htmlnode failurereason reasoncell addchild failure_reason_unknown getstring queuetoadlet reasoncell addchild failure_reason_is failurereason reasoncell private html node create progress cell boolean started int fetched int failed int fatally failed int min int total boolean finalized boolean upload html node progress cell new html node td class request progress if started progress cell add child l10n get string queue toadlet starting return progress cell double frac p get success fraction if core is advanced mode enabled total min if fetched 0 total 0 progress cell add child span class progress fraction unknown l10n get string queue toadlet unknown else int fetched percent int fetched double total 100 int failed percent int failed double total 100 int fatally failed percent int fatally failed double total 100 int min percent int min double total 100 html node progress bar progress cell add child div class progressbar progress bar add child div new string class style new string progressbar done width fetched percent if failed 0 progress bar add child div new string class style new string progressbar failed width failed percent if fatally failed 0 progress bar add child div new string class style new string progressbar failed2 width fatally failed percent if fetched failed fatally failed min progress bar add child div new string class style new string progressbar min width min percent fetched percent number format nf number format get instance nf set maximum fraction digits 1 string prefix integer to string fetched integer to string min if finalized progress bar add child div new string class title new string progress fraction finalized prefix l10n get string queue toadlet progressbar accurate nf format int fetched double min 1000 10 0 else string text nf format int fetched double min 1000 10 0 if finalized text fetched text progress bar add child div new string class title new string progress fraction not finalized prefix l10n get string upload queue toadlet upload progressbar not accurate queue toadlet progressbar not accurate text return progress cell htmlnode createprogresscell fatallyfailed htmlnode progresscell htmlnode progresscell addchild getstring queuetoadlet progresscell getsuccessfraction isadvancedmodeenabled progresscell addchild progress_fraction_unknown getstring queuetoadlet fetchedpercent failedpercent fatallyfailedpercent fatallyfailed minpercent htmlnode progressbar progresscell addchild progressbar addchild fetchedpercent progressbar addchild failedpercent fatallyfailed progressbar addchild fatallyfailedpercent fatallyfailed progressbar addchild minpercent fetchedpercent numberformat numberformat getinstance setmaximumfractiondigits tostring tostring progressbar addchild progress_fraction_finalized getstring queuetoadlet progressbaraccurate progressbar addchild progress_fraction_not_finalized getstring queuetoadlet uploadprogressbarnotaccurate queuetoadlet progressbarnotaccurate progresscell private html node create number cell int number of files html node number cell new html node td class request files number cell add child span class number of files string value of number of files return number cell htmlnode createnumbercell numberoffiles htmlnode numbercell htmlnode numbercell addchild number_of_files valueof numberoffiles numbercell private html node create filename cell file filename html node filename cell new html node td class request filename if filename null filename cell add child span class filename is filename to string else filename cell add child span class filename none l10n get string queue toadlet none return filename cell htmlnode createfilenamecell htmlnode filenamecell htmlnode filenamecell addchild filename_is tostring filenamecell addchild filename_none getstring queuetoadlet filenamecell private html node create priority cell page maker page maker string identifier short priority class toadlet context ctx string priority classes boolean advanced mode enabled html node priority cell new html node td class request priority nowrap html node priority form ctx add form child priority cell queue queue change priority cell identifier hash code priority form add child input new string type name value new string hidden identifier identifier html node priority select priority form add child select name priority for int p 0 p request starter number of priority classes p if p request starter interactive priority class advanced mode enabled continue if p priority class priority select add child option new string value selected new string string value of p selected priority classes p else priority select add child option value string value of p priority classes p priority form add child input new string type name value new string submit change priority l10n get string queue toadlet change return priority cell htmlnode createprioritycell pagemaker pagemaker priorityclass toadletcontext priorityclasses advancedmodeenabled htmlnode prioritycell htmlnode htmlnode priorityform addformchild prioritycell queuechangeprioritycell hashcode priorityform addchild htmlnode priorityselect priorityform addchild requeststarter number_of_priority_classes requeststarter interactive_priority_class advancedmodeenabled priorityclass priorityselect addchild valueof priorityclasses priorityselect addchild valueof priorityclasses priorityform addchild change_priority getstring queuetoadlet prioritycell private html node create delete cell page maker page maker string identifier client request client request toadlet context ctx html node delete node new html node td class request delete html node delete form ctx add form child delete node queue queue delete form identifier hash code delete form add child input new string type name value new string hidden identifier identifier delete form add child input new string type name value new string submit remove request l10n get string queue toadlet remove if it s failed offer to restart it if client request has finished client request has succeeded client request can restart html node retry form ctx add form child delete node queue queue restart form identifier hash code string restart name l10n get string client request instanceof client get client get client request has perm redirect queue toadlet follow queue toadlet restart retry form add child input new string type name value new string hidden identifier identifier retry form add child input new string type name value new string submit restart request restart name return delete node htmlnode createdeletecell pagemaker pagemaker clientrequest clientrequest toadletcontext htmlnode deletenode htmlnode htmlnode deleteform addformchild deletenode queuedeleteform hashcode deleteform addchild deleteform addchild remove_request getstring queuetoadlet clientrequest hasfinished clientrequest hassucceeded clientrequest canrestart htmlnode retryform addformchild deletenode queuerestartform hashcode restartname getstring clientrequest clientget clientget clientrequest haspermredirect queuetoadlet queuetoadlet retryform addchild retryform addchild restart_request restartname deletenode private html node create panic box page maker page maker toadlet context ctx html node panic box page maker get infobox infobox alert l10n get string queue toadlet panic button html node panic form ctx add form child page maker get content node panic box queue queue panic form panic form add child l10n get string queue toadlet panic button confirmation panic form add child input new string type name value new string submit remove allrequests l10n get string queue toadlet remove return panic box htmlnode createpanicbox pagemaker pagemaker toadletcontext htmlnode panicbox pagemaker getinfobox getstring queuetoadlet panicbutton htmlnode panicform addformchild pagemaker getcontentnode panicbox queuepanicform panicform addchild getstring queuetoadlet panicbuttonconfirmation panicform addchild remove_allrequests getstring queuetoadlet panicbox private html node create identifier cell freeneturi uri string identifier boolean directory html node identifier cell new html node td class request identifier if uri null identifier cell add child span class identifier with uri add child a href uri directory identifier else identifier cell add child span class identifier without uri identifier return identifier cell htmlnode createidentifiercell htmlnode identifiercell htmlnode identifiercell addchild identifier_with_uri addchild identifiercell addchild identifier_without_uri identifiercell private html node create persistence cell boolean persistent boolean persistent forever html node persistence cell new html node td class request persistence if persistent forever persistence cell add child span class persistence forever l10n get string queue toadlet persistence forever else if persistent persistence cell add child span class persistence reboot l10n get string queue toadlet persistence reboot else persistence cell add child span class persistence none l10n get string queue toadlet persistence none return persistence cell htmlnode createpersistencecell persistentforever htmlnode persistencecell htmlnode persistentforever persistencecell addchild persistence_forever getstring queuetoadlet persistenceforever persistencecell addchild persistence_reboot getstring queuetoadlet persistencereboot persistencecell addchild persistence_none getstring queuetoadlet persistencenone persistencecell private html node create download cell page maker page maker client get p object container container html node download cell new html node td class request download freeneturi uri p geturi container if uri null logger error this no uri for p new exception error else download cell add child a href uri to string l10n get string queue toadlet download return download cell htmlnode createdownloadcell pagemaker pagemaker clientget objectcontainer htmlnode downloadcell htmlnode downloadcell addchild tostring getstring queuetoadlet downloadcell private html node create type cell string type html node type cell new html node td class request type if type null type cell add child span class mimetype is type else type cell add child span class mimetype unknown l10n get string queue toadlet unknown return type cell htmlnode createtypecell htmlnode typecell htmlnode typecell addchild mimetype_is typecell addchild mimetype_unknown getstring queuetoadlet typecell private html node create size cell long data size boolean confirmed boolean advanced mode enabled html node size cell new html node td class request size if data size 0 confirmed advanced mode enabled size cell add child span class filesize is confirmed size util format size data size confirmed else size cell add child span class filesize unknown l10n get string queue toadlet unknown return size cell htmlnode createsizecell datasize advancedmodeenabled htmlnode sizecell htmlnode datasize advancedmodeenabled sizecell addchild filesize_is sizeutil formatsize datasize sizecell addchild filesize_unknown getstring queuetoadlet sizecell private html node create key cell freeneturi uri boolean add slash html node key cell new html node td class request key if uri null key cell add child span class key is add child a href uri to string add slash uri to short string add slash else key cell add child span class key unknown l10n get string queue toadlet unknown return key cell htmlnode createkeycell addslash htmlnode keycell htmlnode keycell addchild key_is addchild tostring addslash toshortstring addslash keycell addchild key_unknown getstring queuetoadlet keycell private html node create insert box page maker page maker toadlet context ctx boolean is advanced mode enabled the insert file box html node insert box page maker get infobox l10n get string queue toadlet insert file html node insert content page maker get content node insert box html node insert form ctx add form child insert content queue queue insert form insert form add child l10n get string queue toadlet insert as insert form add child input new string type name value checked new string radio keytype chk checked insert form add child chk u00a0 insert form add child input new string type name value new string radio keytype ksk insert form add child ksk ssk usk u00a0 insert form add child input new string type name value new string text key ksk if ctx is allowed full access insert form add child br insert form add child l10n get string queue toadlet insert file browse label insert form add child input new string type name value new string submit insert local l10n get string queue toadlet insert file browse button insert form add child br insert form add child l10n get string queue toadlet insert file label insert form add child input new string type name value new string file filename insert form add child u00a0 insert form add child input new string type name value new string submit insert l10n get string queue toadlet insert file insert file label insert form add child u00a0 if is advanced mode enabled insert form add child input new string type name checked new string checkbox compress checked insert form add child l10n get string queue toadlet insert file compress label u00a0 else insert form add child input new string type value new string hidden true insert form add child input new string type name new string reset l10n get string queue toadlet insert file reset form return insert box htmlnode createinsertbox pagemaker pagemaker toadletcontext isadvancedmodeenabled htmlnode insertbox pagemaker getinfobox getstring queuetoadlet insertfile htmlnode insertcontent pagemaker getcontentnode insertbox htmlnode insertform addformchild insertcontent queueinsertform insertform addchild getstring queuetoadlet insertas insertform addchild insertform addchild insertform addchild insertform addchild insertform addchild isallowedfullaccess insertform addchild insertform addchild getstring queuetoadlet insertfilebrowselabel insertform addchild getstring queuetoadlet insertfilebrowsebutton insertform addchild insertform addchild getstring queuetoadlet insertfilelabel insertform addchild insertform addchild insertform addchild getstring queuetoadlet insertfileinsertfilelabel insertform addchild isadvancedmodeenabled insertform addchild insertform addchild getstring queuetoadlet insertfilecompresslabel insertform addchild insertform addchild getstring queuetoadlet insertfileresetform insertbox private html node create bulk download form toadlet context ctx page maker page maker html node download box page maker get infobox l10n get string queue toadlet download files html node download box content page maker get content node download box html node download form ctx add form child download box content queue queue download form download form add child l10n get string queue toadlet download files instructions download form add child br download form add child textarea new string id name cols rows new string bulk downloads bulk downloads 120 8 download form add child br download form add child input new string type name value new string submit insert l10n get string queue toadlet download return download box htmlnode createbulkdownloadform toadletcontext pagemaker pagemaker htmlnode downloadbox pagemaker getinfobox getstring queuetoadlet downloadfiles htmlnode downloadboxcontent pagemaker getcontentnode downloadbox htmlnode downloadform addformchild downloadboxcontent queuedownloadform downloadform addchild getstring queuetoadlet downloadfilesinstructions downloadform addchild downloadform addchild bulkdownloads bulkdownloads downloadform addchild downloadform addchild getstring queuetoadlet downloadbox private html node create request table page maker page maker toadlet context ctx list client request requests int columns string priority classes boolean advanced mode enabled boolean is upload object container container html node table new html node table class requests html node header row table add child tr class table header header row add child th for int column index 0 column count columns length column index column count column index int column columns column index if column list identifier header row add child th add child a href is reversed sort by id sort by id reversed add child l10n get string queue toadlet identifier else if column list size header row add child th add child a href is reversed sort by size sort by size reversed add child l10n get string queue toadlet size else if column list download header row add child th l10n get string queue toadlet download else if column list mime type header row add child th l10n get string queue toadlet mime type else if column list persistence header row add child th l10n get string queue toadlet persistence else if column list key header row add child th l10n get string queue toadlet key else if column list filename header row add child th l10n get string queue toadlet file name else if column list priority header row add child th add child a href is reversed sort by priority sort by priority reversed add child l10n get string queue toadlet priority else if column list files header row add child th l10n get string queue toadlet files else if column list total size header row add child th l10n get string queue toadlet total size else if column list progress header row add child th add child a href is reversed sort by progress sort by progress reversed add child l10n get string queue toadlet progress else if column list reason header row add child th l10n get string queue toadlet reason for client request client request requests container activate client request 1 html node request row table add child tr class priority client request get priority request row add child create delete cell page maker client request get identifier client request ctx for int column index 0 column count columns length column index column count column index int column columns column index if column list identifier if client request instanceof client get request row add child create identifier cell client get client request geturi container client request get identifier false else if client request instanceof client put dir request row add child create identifier cell client put dir client request get finaluri container client request get identifier true else if client request instanceof client put request row add child create identifier cell client put client request get finaluri container client request get identifier false else if column list size if client request instanceof client get request row add child create size cell client get client request get data size container client get client request is total finalized container advanced mode enabled else if client request instanceof client put request row add child create size cell client put client request get data size container true advanced mode enabled else if column list download request row add child create download cell page maker client get client request container else if column list mime type if client request instanceof client get request row add child create type cell client get client request getmime type container else if client request instanceof client put request row add child create type cell client put client request getmime type else if column list persistence request row add child create persistence cell client request is persistent client request is persistent forever else if column list key if client request instanceof client get request row add child create key cell client get client request geturi container false else if client request instanceof client put request row add child create key cell client put client request get finaluri container false else request row add child create key cell client put dir client request get finaluri container true else if column list filename if client request instanceof client get request row add child create filename cell client get client request get dest filename container else if client request instanceof client put request row add child create filename cell client put client request get orig filename container else if column list priority request row add child create priority cell page maker client request get identifier client request get priority ctx priority classes advanced mode enabled else if column list files request row add child create number cell client put dir client request get number of files else if column list total size request row add child create size cell client put dir client request get total data size true advanced mode enabled else if column list progress request row add child create progress cell client request is started int client request get fetched blocks container int client request get failed blocks container int client request get fataly failed blocks container int client request get min blocks container int client request get total blocks container client request is total finalized container client request instanceof client put is upload else if column list reason request row add child create reason cell client request get failure reason container return table htmlnode createrequesttable pagemaker pagemaker toadletcontext clientrequest priorityclasses advancedmodeenabled isupload objectcontainer htmlnode htmlnode htmlnode headerrow addchild headerrow addchild columnindex columncount columnindex columncount columnindex columnindex list_identifier headerrow addchild addchild isreversed sortby sortby addchild getstring queuetoadlet list_size headerrow addchild addchild isreversed sortby sortby addchild getstring queuetoadlet list_download headerrow addchild getstring queuetoadlet list_mime_type headerrow addchild getstring queuetoadlet mimetype list_persistence headerrow addchild getstring queuetoadlet list_key headerrow addchild getstring queuetoadlet list_filename headerrow addchild getstring queuetoadlet filename list_priority headerrow addchild addchild isreversed sortby sortby addchild getstring queuetoadlet list_files headerrow addchild getstring queuetoadlet list_total_size headerrow addchild getstring queuetoadlet totalsize list_progress headerrow addchild addchild isreversed sortby sortby addchild getstring queuetoadlet list_reason headerrow addchild getstring queuetoadlet clientrequest clientrequest clientrequest htmlnode requestrow addchild clientrequest getpriority requestrow addchild createdeletecell pagemaker clientrequest getidentifier clientrequest columnindex columncount columnindex columncount columnindex columnindex list_identifier clientrequest clientget requestrow addchild createidentifiercell clientget clientrequest clientrequest getidentifier clientrequest clientputdir requestrow addchild createidentifiercell clientputdir clientrequest getfinaluri clientrequest getidentifier clientrequest clientput requestrow addchild createidentifiercell clientput clientrequest getfinaluri clientrequest getidentifier list_size clientrequest clientget requestrow addchild createsizecell clientget clientrequest getdatasize clientget clientrequest istotalfinalized advancedmodeenabled clientrequest clientput requestrow addchild createsizecell clientput clientrequest getdatasize advancedmodeenabled list_download requestrow addchild createdownloadcell pagemaker clientget clientrequest list_mime_type clientrequest clientget requestrow addchild createtypecell clientget clientrequest getmimetype clientrequest clientput requestrow addchild createtypecell clientput clientrequest getmimetype list_persistence requestrow addchild createpersistencecell clientrequest ispersistent clientrequest ispersistentforever list_key clientrequest clientget requestrow addchild createkeycell clientget clientrequest clientrequest clientput requestrow addchild createkeycell clientput clientrequest getfinaluri requestrow addchild createkeycell clientputdir clientrequest getfinaluri list_filename clientrequest clientget requestrow addchild createfilenamecell clientget clientrequest getdestfilename clientrequest clientput requestrow addchild createfilenamecell clientput clientrequest getorigfilename list_priority requestrow addchild createprioritycell pagemaker clientrequest getidentifier clientrequest getpriority priorityclasses advancedmodeenabled list_files requestrow addchild createnumbercell clientputdir clientrequest getnumberoffiles list_total_size requestrow addchild createsizecell clientputdir clientrequest gettotaldatasize advancedmodeenabled list_progress requestrow addchild createprogresscell clientrequest isstarted clientrequest getfetchedblocks clientrequest getfailedblocks clientrequest getfatalyfailedblocks clientrequest getminblocks clientrequest gettotalblocks clientrequest istotalfinalized clientrequest clientput isupload list_reason requestrow addchild createreasoncell clientrequest getfailurereason override public string supported methods return get post supportedmethods private final hash map string user alert alerts by identifier new hash map string user alert public void notify failure client request req object container container fixme do something hashmap useralert alertsbyidentifier hashmap useralert notifyfailure clientrequest objectcontainer public void notify success client request req object container container synchronized completed request identifiers completed request identifiers add req get identifier register alert req container should be safe here save completed identifiers off thread notifysuccess clientrequest objectcontainer completedrequestidentifiers completedrequestidentifiers getidentifier registeralert savecompletedidentifiersoffthread private void save completed identifiers off thread core get executor execute new runnable public void run save completed identifiers save completed identifiers savecompletedidentifiersoffthread getexecutor savecompletedidentifiers private void save completed identifiers off thread core get executor execute new runnable public void run save completed identifiers savecompletedidentifiersoffthread getexecutor savecompletedidentifiers private void load completed identifiers file completed identifiers list new file core node get node dir completed list file completed identifiers list new new file core node get node dir completed list bak if read completed identifiers completed identifiers list read completed identifiers completed identifiers list new core client context job runner queue new db job public void run object container container client context context string identifiers synchronized completed request identifiers identifiers completed request identifiers to array new string completed request identifiers size for int i 0 i identifiers length i client request req fcp get global request identifiers i container if req null synchronized completed request identifiers completed request identifiers remove identifiers i continue register alert req container native thread high priority false loadcompletedidentifiers completedidentifierslist getnodedir completedidentifierslistnew getnodedir readcompletedidentifiers completedidentifierslist readcompletedidentifiers completedidentifierslistnew clientcontext jobrunner dbjob objectcontainer clientcontext completedrequestidentifiers completedrequestidentifiers toarray completedrequestidentifiers clientrequest getglobalrequest completedrequestidentifiers completedrequestidentifiers registeralert nativethread high_priority public void run object container container client context context string identifiers synchronized completed request identifiers identifiers completed request identifiers to array new string completed request identifiers size for int i 0 i identifiers length i client request req fcp get global request identifiers i container if req null synchronized completed request identifiers completed request identifiers remove identifiers i continue register alert req container objectcontainer clientcontext completedrequestidentifiers completedrequestidentifiers toarray completedrequestidentifiers clientrequest getglobalrequest completedrequestidentifiers completedrequestidentifiers registeralert private boolean read completed identifiers file file file input stream fis null try fis new file input stream file buffered input stream bis new buffered input stream fis input stream reader isr new input stream reader bis utf 8 buffered reader br new buffered reader isr synchronized completed request identifiers completed request identifiers clear while true string identifier br read line if identifier null return true completed request identifiers add identifier catch eof exception e normal return true catch file not found exception e normal return false catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e catch io exception e logger error this could not read completed identifiers list from file return false finally closer close fis readcompletedidentifiers fileinputstream fileinputstream bufferedinputstream bufferedinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader completedrequestidentifiers completedrequestidentifiers readline completedrequestidentifiers eofexception filenotfoundexception unsupportedencodingexception ioexception private void save completed identifiers file output stream fos null buffered writer bw null file completed identifiers list new file core node get node dir completed list file completed identifiers list new new file core node get node dir completed list bak file temp try temp file create temp file completed list tmp core node get node dir temp delete on exit fos new file output stream temp output stream writer osw new output stream writer fos utf 8 bw new buffered writer osw string identifiers synchronized completed request identifiers identifiers completed request identifiers to array new string completed request identifiers size for int i 0 i identifiers length i bw write identifiers i n catch file not found exception e logger error this unable to save completed requests list can t find node directory e e return catch io exception e logger error this unable to save completed requests list e e return finally if bw null try bw close catch io exception e try fos close catch io exception e1 ignore else try fos close catch io exception e1 ignore completed identifiers list new delete temp rename to completed identifiers list new if completed identifiers list new rename to completed identifiers list completed identifiers list delete if completed identifiers list new rename to completed identifiers list logger error this unable to store completed identifiers list because unable to rename completed identifiers list new to completed identifiers list savecompletedidentifiers fileoutputstream bufferedwriter completedidentifierslist getnodedir completedidentifierslistnew getnodedir createtempfile getnodedir deleteonexit fileoutputstream outputstreamwriter outputstreamwriter bufferedwriter completedrequestidentifiers completedrequestidentifiers toarray completedrequestidentifiers filenotfoundexception ioexception ioexception ioexception ioexception completedidentifierslistnew renameto completedidentifierslistnew completedidentifierslistnew renameto completedidentifierslist completedidentifierslist completedidentifierslistnew renameto completedidentifierslist completedidentifierslistnew completedidentifierslist private void register alert client request req object container container final string identifier req get identifier boolean logminor logger should log logger minor this if logminor logger minor this registering alert for identifier if req has finished if logminor logger minor this request hasn t finished req for identifier new exception debug return if req instanceof client get freeneturi uri client get req geturi container if req is persistent forever uri null container activate uri 5 if uri null logger error this no uri for supposedly finished request req return long size client get req get data size container string name uri get preferred filename string title l10n download succeeded title filename name html node text new html node div l10n addl10n substitution text queue toadlet download succeeded new string link link origlink origlink filename size new string a href queue uri toascii string a a href uri toascii string a name size util format size size user alert alert new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread override public boolean is event notification return true core alerts register alert synchronized alerts by identifier alerts by identifier put identifier alert else if req instanceof client put freeneturi uri client put req get finaluri container if req is persistent forever uri null container activate uri 5 if uri null logger error this no uri for supposedly finished request req return long size client put req get data size container string name uri get preferred filename string title l10n upload succeeded title filename name html node text new html node div l10n addl10n substitution text queue toadlet upload succeeded new string link link filename size new string a href uri toascii string a name size util format size size user alert alert new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread override public boolean is event notification return true core alerts register alert synchronized alerts by identifier alerts by identifier put identifier alert else if req instanceof client put dir freeneturi uri client put dir req get finaluri container if req is persistent forever uri null container activate uri 5 if uri null logger error this no uri for supposedly finished request req return long size client put dir req get total data size int files client put dir req get number of files string name uri get preferred filename string title l10n site upload succeeded title filename name html node text new html node div l10n addl10n substitution text queue toadlet site upload succeeded new string link link filename size files new string a href uri toascii string a name size util format size size integer to string files user alert alert new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread override public boolean is event notification return true core alerts register alert synchronized alerts by identifier alerts by identifier put identifier alert registeralert clientrequest objectcontainer getidentifier shouldlog hasfinished clientget clientget ispersistentforever clientget getdatasize getpreferredfilename downloadsucceededtitle htmlnode htmlnode addl10nsubstitution queuetoadlet downloadsucceeded toasciistring toasciistring sizeutil formatsize useralert simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread iseventnotification alertsbyidentifier alertsbyidentifier clientput clientput getfinaluri ispersistentforever clientput getdatasize getpreferredfilename uploadsucceededtitle htmlnode htmlnode addl10nsubstitution queuetoadlet uploadsucceeded toasciistring sizeutil formatsize useralert simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread iseventnotification alertsbyidentifier alertsbyidentifier clientputdir clientputdir getfinaluri ispersistentforever clientputdir gettotaldatasize clientputdir getnumberoffiles getpreferredfilename siteuploadsucceededtitle htmlnode htmlnode addl10nsubstitution queuetoadlet siteuploadsucceeded toasciistring sizeutil formatsize tostring useralert simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread iseventnotification alertsbyidentifier alertsbyidentifier new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread save completed identifiers off thread override public boolean is event notification return true savecompletedidentifiersoffthread iseventnotification new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread save completed identifiers off thread override public boolean is event notification return true savecompletedidentifiersoffthread iseventnotification new simplehtml user alert true title title text user alert minor override public void on dismiss synchronized completed request identifiers completed request identifiers remove identifier synchronized alerts by identifier alerts by identifier remove identifier save completed identifiers off thread simplehtmluseralert useralert ondismiss completedrequestidentifiers completedrequestidentifiers alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread save completed identifiers off thread override public boolean is event notification return true savecompletedidentifiersoffthread iseventnotification string l10n string key string pattern string value return l10n get string queue toadlet key pattern value getstring queuetoadlet public void on remove client request req object container container string identifier req get identifier synchronized completed request identifiers completed request identifiers remove identifier user alert alert synchronized alerts by identifier alert alerts by identifier remove identifier core alerts unregister alert save completed identifiers off thread onremove clientrequest objectcontainer getidentifier completedrequestidentifiers completedrequestidentifiers useralert alertsbyidentifier alertsbyidentifier savecompletedidentifiersoffthread public boolean is enabled toadlet context ctx return container public gateway mode ctx is allowed full access isenabled toadletcontext publicgatewaymode isallowedfullaccess public final static string suffixes b kib mib gib tib pib eib zib yib public static string format size long sz return format size sz false formatsize formatsize public static string format size without space long sz string result formatsize sz return result 0 concat result 1 formatsizewithoutspace _formatsize public static string format size long sz boolean use non breaking space string result formatsize sz return result 0 concat use non breaking space u00a0 concat result 1 formatsize usenonbreakingspace _formatsize usenonbreakingspace public static string formatsize long sz long s 1 int i for i 0 i size util suffixes length i s 1024 if s sz break smaller than multiplier i use the previous one s 1024 we use the previous unit if s 1 bytes then we don t need real numbers with a comma return new string string value of sz size util suffixes 0 else double mantissa double sz double s string o string value of mantissa if o index of 3 o o substring 0 3 else if o index of 1 o index of e 1 o length 4 o o substring 0 4 if i size util suffixes length handle the case where the mantissa is infinity return new string o size util suffixes i return new string o _formatsize sizeutil valueof sizeutil valueof indexof indexof indexof sizeutil sizeutil public subscribeusk subscribeusk message message node client core core fcp connection handler handler throws identifier collision exception this handler handler this dont poll message dont poll this identifier message identifier this core core this usk message key prio message prio prio progress message prio progress handler add subscription identifier this core usk manager subscribe message key this message dont poll handler get reboot client low level client subscribeuskmessage nodeclientcore fcpconnectionhandler identifiercollisionexception dontpoll dontpoll prioprogress prioprogress addsubscription uskmanager dontpoll getrebootclient lowlevelclient public void on found edition long l usk key object container container client context context boolean was metadata short codec byte data boolean new known good boolean new slot too if handler is closed core usk manager unsubscribe key this return if new known good new slot too return fcp message msg new subscribedusk update identifier l key new known good new slot too handler output handler queue msg onfoundedition objectcontainer clientcontext wasmetadata newknowngood newslottoo isclosed uskmanager newknowngood newslottoo fcpmessage subscribeduskupdate newknowngood newslottoo outputhandler public short get polling priority normal return prio getpollingprioritynormal public short get polling priority progress return prio progress getpollingpriorityprogress prioprogress public void unsubscribe core usk manager unsubscribe usk this uskmanager private static final gregorian calendar m calendar new gregorian calendar time zone get time zone utc public static date get return new date gregoriancalendar mcalendar gregoriancalendar timezone gettimezone public static long get in millis return system current time millis getinmillis currenttimemillis public static int get year synchronized m calendar m calendar set time in millis system current time millis return m calendar get calendar year getyear mcalendar mcalendar settimeinmillis currenttimemillis mcalendar public static int get month synchronized m calendar m calendar set time in millis system current time millis return m calendar get calendar month getmonth mcalendar mcalendar settimeinmillis currenttimemillis mcalendar public static int get day of month synchronized m calendar m calendar set time in millis system current time millis return m calendar get calendar day of month getdayofmonth mcalendar mcalendar settimeinmillis currenttimemillis mcalendar day_of_month query node visitor public void visit full text query visitor visitor visitor visit this left visit visitor right visit visitor fulltextqueryvisitor this method checks that query can be executed by interection of keyword occurrences lists return true if quuery can be executed by full text index false otherwise public boolean is constrained return op or left is constrained right is constrained left is constrained right is constrained fulltextindex isconstrained isconstrained isconstrained isconstrained isconstrained public string to string return op or left to string or right to string left to string operator name op right to string tostring tostring tostring tostring operatorname tostring binary node constructor param op operation code param left left operand param right right operand public full text query binary op int op full text query left full text query right super op this left left this right right fulltextquerybinaryop fulltextquery fulltextquery logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog failure table node node entries by key new lru hashtable key failure table entry block offer list by key new lru hashtable key block offer list this node node offer authenticator key new byte 32 node random next bytes offer authenticator key offer executor new serial executor native thread high priority node ps queue timed job new failure table cleaner cleanup period failuretable entriesbykey lruhashtable failuretableentry blockofferlistbykey lruhashtable blockofferlist offerauthenticatorkey nextbytes offerauthenticatorkey offerexecutor serialexecutor nativethread high_priority queuetimedjob failuretablecleaner cleanup_period public void start offer executor start node executor failure table offers executor oom handler addoom hook this offerexecutor failuretable oomhandler addoomhook called when we route to a node and it fails for some reason but we continue the request normally the timeout will be the time it took to route to that node and wait for its response timeout waiting for its response param key param routed to param htl param timeout public void on failed key key peer node routed to short htl int timeout if node enableulpr data propagation node enable per node failure tables return long now system current time millis failure table entry entry synchronized this entry entries by key get key if entry null entry new failure table entry key entries by key push key entry trim entries now entry failed to routed to timeout now htl routedto onfailed peernode routedto enableulprdatapropagation enablepernodefailuretables currenttimemillis failuretableentry entriesbykey failuretableentry entriesbykey trimentries failedto routedto public void on final failure key key peer node routed to short htl int timeout peer node requestor if node enableulpr data propagation node enable per node failure tables return long now system current time millis failure table entry entry synchronized this entry entries by key get key if entry null entry new failure table entry key entries by key push key entry trim entries now if routed to null entry failed to routed to timeout now htl if requestor null entry add requestor requestor now onfinalfailure peernode routedto peernode enableulprdatapropagation enablepernodefailuretables currenttimemillis failuretableentry entriesbykey failuretableentry entriesbykey trimentries routedto failedto routedto addrequestor private synchronized void trim entries long now while entries by key size max entries entries by key pop key trimentries entriesbykey max_entries entriesbykey popkey final failure table entry entry block offer list failure table entry entry block offer offer this entry entry this offers new block offer offer failuretableentry blockofferlist failuretableentry blockoffer blockoffer public synchronized long expires long last 0 for int i 0 i offers length i if offers i offered time last last offers i offered time return last offer expiry time offeredtime offeredtime offer_expiry_time public synchronized boolean is empty long now for int i 0 i offers length i if offers i is expired now return false return true isempty isexpired public void delete offer block offer offer if logminor logger minor this deleting offer from this synchronized this int idx 1 final int offer length offers length for int i 0 i offer length i if offers i offer idx i if idx 0 return block offer new offers new block offer offer length 1 if idx 0 system arraycopy offers 0 new offers 0 idx if idx new offers length system arraycopy offers idx 1 new offers idx offers length idx 1 offers new offers if offers length 1 synchronized failure table this block offer list by key remove key entry key node client core dequeue offered key entry key deleteoffer blockoffer offerlength offerlength blockoffer newoffers blockoffer offerlength newoffers newoffers newoffers newoffers failuretable blockofferlistbykey removekey clientcore dequeueofferedkey public synchronized void add offer block offer offer block offer new offers new block offer offers length 1 system arraycopy offers 0 new offers 0 offers length new offers offers length offer offers new offers addoffer blockoffer blockoffer newoffers blockoffer newoffers newoffers newoffers override public string to string return super to string offers length tostring tostring block offer peer node pn long now byte authenticator long bootid this node ref pn my ref this offered time now this authenticator authenticator this bootid bootid blockoffer peernode noderef myref offeredtime public peer node get peer node return node ref get peernode getpeernode noderef public boolean is expired long now return node ref get null now offered time offer expiry time isexpired noderef offeredtime offer_expiry_time public boolean is expired return is expired system current time millis isexpired isexpired currenttimemillis called when a data block is found after it has been stored there is a good chance of its being available in the near future if there are nodes waiting for it we will offer it to them public void on found key block block if node enableulpr data propagation node enable per node failure tables return key key block get key if key null throw new null pointer exception failure table entry entry synchronized this entry entries by key get key if entry null return nobody cares entries by key remove key key block offer list by key remove key key if node enableulpr data propagation return entry offer onfound keyblock enableulprdatapropagation enablepernodefailuretables getkey nullpointerexception failuretableentry entriesbykey entriesbykey removekey blockofferlistbykey removekey enableulprdatapropagation called when we get an offer for a key if this is an ssk we will only accept it if we have previously asked for it if it is a chk we will accept it if we want it param key the key we are being offered param peer the node offering it param authenticator void on offer final key key final peer node peer final byte authenticator if node enableulpr data propagation return if logminor logger minor this offered key key by peer peer failure table entry entry synchronized this entry entries by key get key if entry null if logminor logger minor this we didn t ask for the key return we haven t asked for it offer executor execute new runnable public void run inner on offer key peer authenticator on offer onoffer peernode enableulprdatapropagation failuretableentry entriesbykey offerexecutor inneronoffer onoffer offer executor execute new runnable public void run inner on offer key peer authenticator offerexecutor inneronoffer this method runs on the serial executor therefore any blocking network i o needs to be scheduled on a separate thread however blocking disk i o should happen on this thread we deliberately serialise it as high latencies can otherwise result protected void inner on offer key key peer node peer byte authenticator if key get routing key null throw new null pointer exception nb node has key executes a datastore fetch if node has key key logger minor this already have key return re check after potentially long disk i o failure table entry entry long now system current time millis synchronized this entry entries by key get key if entry null if logminor logger minor this we didn t ask for the key return we haven t asked for it accept subject to later checks if we asked for it should we accept it if we were asked for it this is bidirectional propagation it s good because it makes the whole structure much more reliable it s bad because it s not entirely under our control we didn t choose to route it to the node the node routed it to us now it s found it before we did attacks frost spamming etc is it easier to offer data to our peers rather than inserting it will it result in it being propagated further the peer node would then do the request rather than this node doing an insert is that beneficial not relevant with ch ks anyway on the plus side propagation to nodes that have asked is worthwhile because reduced polling cost enables more secure messaging systems e g outbox polling social engineering if a key is unpopular you can put a different copy of it on different nodes you can then use this to trace the requestor identify that he is or isn t on the target you can t do this with a regular insert because it will often go several nodes even at htl 0 with subscriptions you might be able to bypass this but only if you know no other nodes in the neighbourhood are subscribed easier with ss ks with ch ks you have only binary information of whether the person got the key with social engineering hard to exploit on darknet if you re that close to the suspect there are easier ways to get at them e g correlation attacks conclusion we should accept the request if we asked for it from that node note that a node might both have asked us and been asked that node asked for it and it s a chk boolean we asked entry asked from peer peer now boolean he asked entry asked by peer peer now if we asked key instanceof nodechk he asked if logminor logger minor this not propagating key we asked we asked he asked he asked if entry is empty now synchronized this entries by key remove key key return if entry is empty now entries by key remove key key valid offer add to offers list synchronized this if logminor logger minor this valid offer block offer list bl block offer list by key get key block offer offer new block offer peer now authenticator peer get bootid if bl null bl new block offer list entry offer else bl add offer offer block offer list by key push key bl trim offers list now now does anyone want it node client core maybe queue offered key key entry others want peer serialexecutor inneronoffer peernode getroutingkey nullpointerexception haskey haskey failuretableentry currenttimemillis entriesbykey chks ssks chks weasked askedfrompeer heasked askedbypeer weasked heasked weasked weasked heasked heasked isempty entriesbykey removekey isempty entriesbykey removekey blockofferlist blockofferlistbykey blockoffer blockoffer getbootid blockofferlist addoffer blockofferlistbykey trimofferslist clientcore maybequeueofferedkey otherswant private synchronized void trim offers list long now while true if block offer list by key is empty return block offer list bl block offer list by key peek value if bl is empty now bl expires now block offer list by key size max offers if logminor logger minor this removing block offer list bl list size now block offer list by key size block offer list by key pop key else return trimofferslist blockofferlistbykey isempty blockofferlist blockofferlistbykey peekvalue isempty blockofferlistbykey max_offers blockofferlistbykey blockofferlistbykey popkey we offered a key a node has responded to the offer note that this runs on the incoming packets thread so should allocate a new thread if it does anything heavy note also that it is responsible for unlocking the uid param key the key to send param isssk whether it is an ssk param uid the uid param source the node that asked for the key throws not connected exception if the sender ceases to be connected public void send offered key final key key final boolean isssk final boolean need pub key final long uid final peer node source final offer reply tag tag throws not connected exception this offer executor execute new runnable public void run try inner send offered key key isssk need pub key uid source tag catch not connected exception e node unlockuid uid isssk false false true false tag too bad catch throwable t node unlockuid uid isssk false false true false tag logger error this caught t sending offered key send offered key notconnectedexception sendofferedkey needpubkey peernode offerreplytag notconnectedexception offerexecutor innersendofferedkey needpubkey notconnectedexception sendofferedkey this offer executor execute new runnable public void run try inner send offered key key isssk need pub key uid source tag catch not connected exception e node unlockuid uid isssk false false true false tag too bad catch throwable t node unlockuid uid isssk false false true false tag logger error this caught t sending offered key offerexecutor innersendofferedkey needpubkey notconnectedexception this method runs on the serial executor therefore any blocking network i o needs to be scheduled on a separate thread however blocking disk i o should happen on this thread we deliberately serialise it as high latencies can otherwise result protected void inner send offered key key key final boolean isssk boolean need pub key final long uid final peer node source final offer reply tag tag throws not connected exception if isssk ssk block block node fetch nodessk key false if block null don t have the key source send async dmt createfnp get offered key invalid uid dmt get offered key rejected no key null sender counter node unlockuid uid isssk false false true false tag return final message data dmt createfnpssk data found data uid block get raw data message headers dmt createfnpssk data found headers uid block get raw headers final int data length block get raw data length source send async headers null sender counter node executor execute new prio runnable public int get priority return native thread high priority public void run try source send throttled message data data length sender counter 60 1000 false null catch not connected exception e catch waited too long exception e logger error this waited too long sending ssk data catch sync send waited too long exception e impossible finally node unlockuid uid isssk false false true false tag send offered ssk if need pub key message pk dmt createfnpssk pub key uid block get pub key source send async pk null sender counter else chk block block node fetch nodechk key false if block null don t have the key source send async dmt createfnp get offered key invalid uid dmt get offered key rejected no key null sender counter node unlockuid uid isssk false false true false tag return message df dmt createfnpchk data found uid block get raw headers source send async df null sender counter partially received block prb new partially received block node packets in block node packet size block get raw data final block transmitter bt new block transmitter node usm source uid prb sender counter node executor execute new prio runnable public int get priority return native thread high priority public void run try bt send node executor catch throwable t logger error this sending offered key failed t t finally node unlockuid uid isssk false false true false tag chk offer sender serialexecutor innersendofferedkey needpubkey peernode offerreplytag notconnectedexception sskblock sendasync createfnpgetofferedkeyinvalid get_offered_key_rejected_no_key sendercounter createfnpsskdatafounddata getrawdata createfnpsskdatafoundheaders getrawheaders datalength getrawdata sendasync sendercounter priorunnable getpriority nativethread high_priority sendthrottledmessage datalength sendercounter notconnectedexception waitedtoolongexception syncsendwaitedtoolongexception needpubkey createfnpsskpubkey getpubkey sendasync sendercounter chkblock sendasync createfnpgetofferedkeyinvalid get_offered_key_rejected_no_key sendercounter createfnpchkdatafound getrawheaders sendasync sendercounter partiallyreceivedblock partiallyreceivedblock packets_in_block packet_size getrawdata blocktransmitter blocktransmitter sendercounter priorunnable getpriority nativethread high_priority node executor execute new prio runnable public int get priority return native thread high priority priorunnable getpriority nativethread high_priority public void run try source send throttled message data data length sender counter 60 1000 false null catch not connected exception e catch waited too long exception e logger error this waited too long sending ssk data catch sync send waited too long exception e impossible finally node unlockuid uid isssk false false true false tag sendthrottledmessage datalength sendercounter notconnectedexception waitedtoolongexception syncsendwaitedtoolongexception node executor execute new prio runnable public int get priority return native thread high priority priorunnable getpriority nativethread high_priority public void run try bt send node executor catch throwable t logger error this sending offered key failed t t finally node unlockuid uid isssk false false true false tag class offered keys byte counter implements byte counter public void received bytes int x node node stats offered keys sender received bytes x offeredkeysbytecounter bytecounter receivedbytes nodestats offeredkeyssenderreceivedbytes public void sent bytes int x node node stats offered keys sender sent bytes x sentbytes nodestats offeredkeyssendersentbytes public void sent payload int x node sent payload x node node stats offered keys sender sent bytes x sentpayload sentpayload nodestats offeredkeyssendersentbytes offer list block offer list offer list this offer list offer list recent offers new vector block offer expired offers new vector block offer long now system current time millis block offer offers offer list offers for int i 0 i offers length i if offers i is expired now recent offers add offers i else expired offers add offers i if logminor logger minor this offers recent offers size recent expired offers size expired offerlist blockofferlist offerlist offerlist offerlist recentoffers blockoffer expiredoffers blockoffer currenttimemillis blockoffer offerlist isexpired recentoffers expiredoffers recentoffers expiredoffers public block offer get first offer if last offer null throw new illegal state exception last offer not dealt with if recent offers is empty int x node random next int recent offers size return last offer recent offers remove x if expired offers is empty int x node random next int expired offers size return last offer expired offers remove x no more offers return null blockoffer getfirstoffer lastoffer illegalstateexception recentoffers isempty nextint recentoffers lastoffer recentoffers expiredoffers isempty nextint expiredoffers lastoffer expiredoffers delete the last offer we have used it successfully or not public void delete last offer offer list delete offer last offer last offer null deletelastoffer offerlist deleteoffer lastoffer lastoffer keep the last offer we weren t able to use it e g because of rejected overload maybe it will be useful again in the future public void keep last offer last offer null rejectedoverload keeplastoffer lastoffer public offer list get offers key key if node enableulpr data propagation return null block offer list bl synchronized this bl block offer list by key get key if bl null return null return new offer list bl offerlist getoffers enableulprdatapropagation blockofferlist blockofferlistbykey offerlist called when a node disconnects public void on disconnect final peer node pn if node enableulpr data propagation node enable per node failure tables return fixme do something off thread if expensive ondisconnect peernode enableulprdatapropagation enablepernodefailuretables public timed out nodes list get timed out nodes list key key if node enable per node failure tables return null synchronized this return entries by key get key timedoutnodeslist gettimedoutnodeslist enablepernodefailuretables entriesbykey public void run try real run catch throwable t logger error this failure table cleaner caught t t finally node ps queue timed job this cleanup period realrun failuretablecleaner queuetimedjob cleanup_period private void real run if logminor logger minor this starting failure table cleanup long start time system current time millis failure table entry entries synchronized failure table this entries new failure table entry entries by key size entries by key values to array entries for int i 0 i entries length i synchronized entries i if entries i cleanup synchronized failure table this if entries i is empty entries by key remove key entries i key long end time system current time millis if logminor logger minor this finished failure table cleanup took end time start time ms realrun failuretable starttime currenttimemillis failuretableentry failuretable failuretableentry entriesbykey entriesbykey valuestoarray failuretable isempty entriesbykey removekey endtime currenttimemillis failuretable endtime starttime public boolean peers want key key key failure table entry entry synchronized this entry entries by key get key if entry null return false nobody cares return entry others want null peerswantkey failuretableentry entriesbykey otherswant public void handle low memory throws exception synchronized this int size entries by key size do entries by key pop key while entries by key size size 2 handlelowmemory entriesbykey entriesbykey popkey entriesbykey public void handle out of memory throws exception synchronized this entries by key clear handleoutofmemory entriesbykey public shade filter bump height 1 0f bump softness 5 0f l new vector3f v new vector3f n new vector3f shaded color new color4f diffuse color new color4f specular color new color4f tmpv new vector3f tmpv2 new vector3f shadefilter bumpheight bumpsoftness shadedcolor diffuse_color specular_color public void set bump function function2d bump function this bump function bump function setbumpfunction bumpfunction bumpfunction bumpfunction public function2d get bump function return bump function getbumpfunction bumpfunction public void set bump height float bump height this bump height bump height setbumpheight bumpheight bumpheight bumpheight public float get bump height return bump height getbumpheight bumpheight public void set bump softness float bump softness this bump softness bump softness setbumpsoftness bumpsoftness bumpsoftness bumpsoftness public float get bump softness return bump softness getbumpsoftness bumpsoftness public void set environment map buffered image environment map this environment map environment map if environment map null env width environment map get width env height environment map get height env pixels getrgb environment map 0 0 env width env height null else env width env height 1 env pixels null setenvironmentmap bufferedimage environmentmap environmentmap environmentmap environmentmap envwidth environmentmap getwidth envheight environmentmap getheight envpixels environmentmap envwidth envheight envwidth envheight envpixels public buffered image get environment map return environment map bufferedimage getenvironmentmap environmentmap public void set bump source int bump source this bump source bump source setbumpsource bumpsource bumpsource bumpsource public int get bump source return bump source getbumpsource bumpsource protected final static float r255 1 0f 255 0f protected void set fromrgb color4f c int argb c set argb 16 0xff r255 argb 8 0xff r255 argb 0xff r255 argb 24 0xff r255 setfromrgb override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height float width45 math abs 6 0f bump height boolean invert bumps bump height 0 vector3f position new vector3f 0 0f 0 0f 0 0f vector3f viewpoint new vector3f float width 2 0f float height 2 0f view distance vector3f normal new vector3f color4f c new color4f function2d bump bump function if bump source bumps from image bump source bumps from image alpha bump source bumps from map bump null if bump softness 0 int bump width width int bump height height int bump pixels in pixels if bump source bumps from map bump function instanceof image function2d image function2d if2d image function2d bump function bump width if2d get width bump height if2d get height bump pixels if2d get pixels kernel kernel gaussian filter make kernel bump softness int tmp pixels new int bump width bump height int soft pixels new int bump width bump height gaussian filter convolve and transpose kernel bump pixels tmp pixels bump width bump height true false false convolve filter clamp edges gaussian filter convolve and transpose kernel tmp pixels soft pixels bump height bump width true false false convolve filter clamp edges bump new image function2d soft pixels bump width bump height image function2d clamp bump source bumps from image alpha else bump new image function2d in pixels width height image function2d clamp bump source bumps from image alpha vector3f v1 new vector3f vector3f v2 new vector3f vector3f n new vector3f loop through each source pixel for int y 0 y height y float ny y position y y for int x 0 x width x float nx x calculate the normal at this point if bump source bumps from bevel complicated and slower method calculate four normals using the gradients in x y directions int count 0 normal x normal y normal z 0 float m0 width45 bump evaluate nx ny float m1 x 0 width45 bump evaluate nx 1 0f ny m0 2 float m2 y 0 width45 bump evaluate nx ny 1 0f m0 2 float m3 x width 1 width45 bump evaluate nx 1 0f ny m0 2 float m4 y height 1 width45 bump evaluate nx ny 1 0f m0 2 if m1 2 m4 2 v1 x 1 0f v1 y 0 0f v1 z m1 v2 x 0 0f v2 y 1 0f v2 z m4 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count if m1 2 m2 2 v1 x 1 0f v1 y 0 0f v1 z m1 v2 x 0 0f v2 y 1 0f v2 z m2 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count if m2 2 m3 2 v1 x 0 0f v1 y 1 0f v1 z m2 v2 x 1 0f v2 y 0 0f v2 z m3 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count if m3 2 m4 2 v1 x 1 0f v1 y 0 0f v1 z m3 v2 x 0 0f v2 y 1 0f v2 z m4 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count average the four normals normal x count normal y count normal z count for testing generate a sphere bump map double dx x 120 double dy y 80 double r2 dx dx dy dy double r math sqrt r2 double t math atan2 dy dx if r2 80 80 double z math sqrt 80 80 r2 normal x float dx normal y float dy normal z float z normal normalize else normal x 0 normal y 0 normal z 1 if invert bumps normal x normal x normal y normal y position x x if normal z 0 get the material colour at this point if environment map null fixme too much normalizing going on here tmpv2 set viewpoint tmpv2 sub position tmpv2 normalize tmpv set normal tmpv normalize reflect tmpv scale 2 0f tmpv dot tmpv2 tmpv sub v tmpv normalize set fromrgb c get environment mapp normal in pixels width height fixme interpolate int alpha in pixels index 0xff000000 int rgb int c x 255 16 int c y 255 8 int c z 255 out pixels index alpha rgb else out pixels index 0 else out pixels index 0 return out pixels filterpixels inpixels transformedspace outpixels bumpheight invertbumps bumpheight viewdistance bumpfunction bumpsource bumps_from_image bumpsource bumps_from_image_alpha bumpsource bumps_from_map bumpsoftness bumpwidth bumpheight bumppixels inpixels bumpsource bumps_from_map bumpfunction imagefunction2d imagefunction2d imagefunction2d bumpfunction bumpwidth getwidth bumpheight getheight bumppixels getpixels gaussianfilter makekernel bumpsoftness tmppixels bumpwidth bumpheight softpixels bumpwidth bumpheight gaussianfilter convolveandtranspose bumppixels tmppixels bumpwidth bumpheight convolvefilter clamp_edges gaussianfilter convolveandtranspose tmppixels softpixels bumpheight bumpwidth convolvefilter clamp_edges imagefunction2d softpixels bumpwidth bumpheight imagefunction2d bumpsource bumps_from_image_alpha imagefunction2d inpixels imagefunction2d bumpsource bumps_from_image_alpha bumpsource bumps_from_bevel invertbumps environmentmap setfromrgb getenvironmentmapp inpixels inpixels outpixels outpixels outpixels outpixels private int get environment mapp vector3f normal int in pixels int width int height if environment map null float x 0 5f 1 normal x float y 0 5f 1 normal y x image math clamp x env width 0 env width 1 y image math clamp y env height 0 env height 1 int ix int x int iy int y float x weight x ix float y weight y iy int i env width iy ix int dx ix env width 1 0 1 int dy iy env height 1 0 env width return image math bilinear interpolate x weight y weight env pixels i env pixels i dx env pixels i dy env pixels i dx dy return 0 getenvironmentmapp inpixels environmentmap imagemath envwidth envwidth imagemath envheight envheight xweight yweight envwidth envwidth envheight envwidth imagemath bilinearinterpolate xweight yweight envpixels envpixels envpixels envpixels override public string to string return stylize shade tostring private float gap public mirror filter mirrorfilter specifies the angle of the mirror param angle the angle of the mirror angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of the mirror return the angle of the mirror see set angle public float get angle return angle setangle getangle public void set distance float distance this distance distance setdistance public float get distance return distance getdistance public void set rotation float rotation this rotation rotation setrotation public float get rotation return rotation getrotation public void set gap float gap this gap gap setgap public float get gap return gap getgap set the opacity of the reflection param opacity the opacity see get opacity public void set opacity float opacity this opacity opacity getopacity setopacity get the opacity of the reflection return the opacity see set opacity public float get opacity return opacity setopacity getopacity public void set centrey float centrey this centrey centrey setcentrey public float get centrey return centrey getcentrey public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null buffered image tsrc src shape clip int width src get width int height src get height int h int centrey height int d int gap height graphics2d g dst create graphics clip g get clip g clip rect 0 0 width h g draw rendered image src null g set clip clip g clip rect 0 h d width height h d g translate 0 2 h d g scale 1 1 g draw rendered image src null g set paint new gradient paint 0 0 new color 1 0f 0 0f 0 0f 0 0f 0 h new color 0 0f 1 0f 0 0f opacity g set composite alpha composite get instance alpha composite dst in g fill rect 0 0 width h g set clip clip g dispose return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage bufferedimage getwidth getheight creategraphics getclip cliprect drawrenderedimage setclip cliprect drawrenderedimage setpaint gradientpaint setcomposite alphacomposite getinstance alphacomposite dst_in fillrect setclip override public string to string return effects mirror tostring final boolean can read public directory access boolean can read boolean can write this can read can read this can write can write canread directoryaccess canread canwrite canread canread canwrite canwrite null if not requested dda check job random r file directory file read filename file write filename this directory directory this read filename read filename this write filename write filename byte random new byte 128 r next bytes random this read content hex util bytes to hex random r next bytes random this write content hex util bytes to hex random ddacheckjob readfilename writefilename readfilename readfilename writefilename writefilename nextbytes readcontent hexutil bytestohex nextbytes writecontent hexutil bytestohex static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public fcp connection handler socket s fcp server server this sock s this server server is closed false this bf server core temp bucket factory requests by identifier new hash map string client request usk subscriptions new hash map string subscribeusk this input handler new fcp connection input handler this this output handler new fcp connection output handler this byte identifier new byte 16 server node random next bytes identifier this connection identifier hex util bytes to hex identifier fcpconnectionhandler fcpserver isclosed tempbucketfactory requestsbyidentifier hashmap clientrequest usksubscriptions hashmap inputhandler fcpconnectioninputhandler outputhandler fcpconnectionoutputhandler nextbytes connectionidentifier hexutil bytestohex void start input handler start output handler start inputhandler outputhandler public void close client request requests if reboot client null reboot client on lost connection this if forever client null forever client on lost connection this boolean dupe subscribeusk subscriptions synchronized this is closed true requests new client request requests by identifier size requests requests by identifier values to array requests subscriptions usk subscriptions values to array new subscribeusk usk subscriptions size dupe killed dupe for int i 0 i requests length i requests i on lost connection null server core client context for subscribeusk sub subscriptions sub unsubscribe if dupe server core client context job runner queue new db job public void run object container container client context context if reboot client null reboot client has persistent requests null server unregister client reboot client null if forever client null if container ext is stored forever client logger normal this forever client is not stored in the database in lost connection non dupe callback not deleting it return container activate forever client 1 if forever client has persistent requests container server unregister client forever client container container deactivate forever client 1 native thread norm priority false output handler on closed clientrequest rebootclient rebootclient onlostconnection foreverclient foreverclient onlostconnection isclosed clientrequest requestsbyidentifier requestsbyidentifier toarray usksubscriptions toarray usksubscriptions killeddupe onlostconnection clientcontext clientcontext jobrunner dbjob objectcontainer clientcontext rebootclient rebootclient haspersistentrequests unregisterclient rebootclient foreverclient isstored foreverclient foreverclient foreverclient foreverclient haspersistentrequests unregisterclient foreverclient foreverclient nativethread norm_priority outputhandler onclosed public void run object container container client context context if reboot client null reboot client has persistent requests null server unregister client reboot client null if forever client null if container ext is stored forever client logger normal this forever client is not stored in the database in lost connection non dupe callback not deleting it return container activate forever client 1 if forever client has persistent requests container server unregister client forever client container container deactivate forever client 1 objectcontainer clientcontext rebootclient rebootclient haspersistentrequests unregisterclient rebootclient foreverclient isstored foreverclient foreverclient foreverclient foreverclient haspersistentrequests unregisterclient foreverclient foreverclient synchronized void set killed dupe killed dupe true setkilleddupe killeddupe public synchronized boolean is closed return is closed isclosed isclosed public void closed input try sock shutdown input catch io exception e ignore synchronized this input closed true if output closed return try sock close catch io exception e ignore closedinput shutdowninput ioexception inputclosed outputclosed ioexception public void closed output try sock shutdown output catch io exception e ignore synchronized this output closed true if input closed return try sock close catch io exception e ignore closedoutput shutdownoutput ioexception outputclosed inputclosed ioexception public void set client name final string name this client name name reboot client server register reboot client name server core this reboot client queue pending messages on connection restart output handler null server core client context job runner queue new db job public void run object container container client context context try create forever client name container catch throwable t logger error this caught t creating persistent client for name t failed get forever true synchronized fcp connection handler this failed get forever true fcp connection handler this notify all native thread norm priority false if logminor logger minor this set client name name setclientname clientname rebootclient registerrebootclient rebootclient queuependingmessagesonconnectionrestart outputhandler clientcontext jobrunner dbjob objectcontainer clientcontext createforeverclient failedgetforever fcpconnectionhandler failedgetforever fcpconnectionhandler notifyall nativethread norm_priority public void run object container container client context context try create forever client name container catch throwable t logger error this caught t creating persistent client for name t failed get forever true synchronized fcp connection handler this failed get forever true fcp connection handler this notify all objectcontainer clientcontext createforeverclient failedgetforever fcpconnectionhandler failedgetforever fcpconnectionhandler notifyall protected fcp client create forever client string name object container container synchronized fcp connection handler this if forever client null return forever client fcp client client server register forever client name server core fcp connection handler this container synchronized fcp connection handler this forever client client fcp connection handler this notify all client queue pending messages on connection restart output handler container return forever client fcpclient createforeverclient objectcontainer fcpconnectionhandler foreverclient foreverclient fcpclient registerforeverclient fcpconnectionhandler fcpconnectionhandler foreverclient fcpconnectionhandler notifyall queuependingmessagesonconnectionrestart outputhandler foreverclient public string get client name return client name getclientname clientname start a client get if there is an identifier collision queue an identifier collision message hence we can run stuff on other threads if we need to as long as we send the right messages public void start client get final client get message message final string id message identifier final boolean global message global client get cg null boolean success boolean persistent message persistence type client request persist connection synchronized this if is closed return we need to track non persistent requests anyway so we may as well check if persistent success true else success requests by identifier contains key id if success try if persistent cg new client get this message server null requests by identifier put id cg else if message persistence type client request persist forever server core client context job runner queue new db job public void run object container container client context context client get getter try getter new client get fcp connection handler this message server container catch identifier collision exception e1 logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch message invalid exception e1 output handler queue new protocol error message e1 protocol code false e1 get message e1 ident e1 global return try getter register container false false container store getter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return getter start container context container deactivate getter 1 native thread high priority 1 false user wants a response soon but doesn t want it to block the queue page etc return don t run the start below else cg new client get this message server null catch identifier collision exception e success false catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return if message persistence type client request persist reboot try cg register null false false catch identifier collision exception e success false if success logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return else cg start null server core client context clientget identifiercollisionmessage startclientget clientgetmessage clientget persistencetype clientrequest persist_connection isclosed requestsbyidentifier containskey clientget requestsbyidentifier persistencetype clientrequest persist_forever clientcontext jobrunner dbjob objectcontainer clientcontext clientget clientget fcpconnectionhandler identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler nativethread high_priority clientget identifiercollisionexception messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage persistencetype clientrequest persist_reboot identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler clientcontext public void run object container container client context context client get getter try getter new client get fcp connection handler this message server container catch identifier collision exception e1 logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch message invalid exception e1 output handler queue new protocol error message e1 protocol code false e1 get message e1 ident e1 global return try getter register container false false container store getter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return getter start container context container deactivate getter 1 objectcontainer clientcontext clientget clientget fcpconnectionhandler identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler public void start client put final client put message message if logminor logger minor this starting insert id message identifier final string id message identifier final boolean global message global client put cp null boolean persistent message persistence type client request persist connection fcp message failed message null synchronized this boolean success if is closed return we need to track non persistent requests anyway so we may as well check if persistent success true else success requests by identifier contains key id if success if persistent try cp new client put this message server null catch identifier collision exception e success false catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return catch malformedurl exception e failed message new protocol error message protocol error message freenet uri parse error true null id message global requests by identifier put id cp else if message persistence type client request persist forever server core client context job runner queue new db job public void run object container container client context context client put putter try putter new client put fcp connection handler this message server container catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return catch malformedurl exception e output handler queue new protocol error message protocol error message freenet uri parse error true null id message global return try putter register container false false container store putter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return putter start container context container deactivate putter 1 native thread high priority 1 false user wants a response soon but doesn t want it to block the queue page etc return don t run the start below else try cp new client put this message server null catch identifier collision exception e success false catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return catch malformedurl exception e failed message new protocol error message protocol error message freenet uri parse error true null id message global if success logger normal this identifier collision on this failed message new identifier collision message id message global if message persistence type client request persist reboot try cp register null false false catch identifier collision exception e failed message new identifier collision message id message global if failed message null output handler queue failed message if persistent message persistence type client request persist forever final client put c cp run on the database thread if persistent because it will try to activate stuff server core client context job runner queue new db job public void run object container container client context context if c null c free data container else message free data container native thread high priority 1 false else if cp null cp free data null else message free data null return else logger minor this starting cp cp start null server core client context startclientput clientputmessage clientput persistencetype clientrequest persist_connection fcpmessage failedmessage isclosed requestsbyidentifier containskey clientput identifiercollisionexception messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage malformedurlexception failedmessage protocolerrormessage protocolerrormessage freenet_uri_parse_error requestsbyidentifier persistencetype clientrequest persist_forever clientcontext jobrunner dbjob objectcontainer clientcontext clientput clientput fcpconnectionhandler identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage malformedurlexception outputhandler protocolerrormessage protocolerrormessage freenet_uri_parse_error identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler nativethread high_priority clientput identifiercollisionexception messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage malformedurlexception failedmessage protocolerrormessage protocolerrormessage freenet_uri_parse_error failedmessage identifiercollisionmessage persistencetype clientrequest persist_reboot identifiercollisionexception failedmessage identifiercollisionmessage failedmessage outputhandler failedmessage persistencetype clientrequest persist_forever clientput clientcontext jobrunner dbjob objectcontainer clientcontext freedata freedata nativethread high_priority freedata freedata clientcontext public void run object container container client context context client put putter try putter new client put fcp connection handler this message server container catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch message invalid exception e output handler queue new protocol error message e protocol code false e get message e ident e global return catch malformedurl exception e output handler queue new protocol error message protocol error message freenet uri parse error true null id message global return try putter register container false false container store putter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return putter start container context container deactivate putter 1 objectcontainer clientcontext clientput clientput fcpconnectionhandler identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler messageinvalidexception outputhandler protocolerrormessage protocolcode getmessage malformedurlexception outputhandler protocolerrormessage protocolerrormessage freenet_uri_parse_error identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler public void run object container container client context context if c null c free data container else message free data container objectcontainer clientcontext freedata freedata public void start client put dir final client put dir message message final hash map string object buckets final boolean was disk put if logminor logger minor this start client put dir final string id message identifier final boolean global message global client put dir cp null fcp message failed message null boolean persistent message persistence type client request persist connection we need to track non persistent requests anyway so we may as well check boolean success synchronized this if is closed return if persistent success true else success requests by identifier contains key id if success if persistent try cp new client put dir this message buckets was disk put server null synchronized this requests by identifier put id cp catch identifier collision exception e success false catch malformedurl exception e failed message new protocol error message protocol error message freenet uri parse error true null id message global fixme register non persistent requests in the constructors also we already register persistent ones else if message persistence type client request persist forever server core client context job runner queue new db job public void run object container container client context context client put dir putter try putter new client put dir fcp connection handler this message buckets was disk put server container catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch malformedurl exception e output handler queue new protocol error message protocol error message freenet uri parse error true null id message global return try putter register container false false container store putter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return putter start container context container deactivate putter 1 native thread high priority 1 false user wants a response soon but doesn t want it to block the queue page etc return don t run the start below else try cp new client put dir this message buckets was disk put server null catch identifier collision exception e success false catch malformedurl exception e failed message new protocol error message protocol error message freenet uri parse error true null id message global if success logger normal this identifier collision on this failed message new identifier collision message id message global if message persistence type client request persist reboot try cp register null false false catch identifier collision exception e failed message new identifier collision message id message global if failed message null fixme do we need to free data output handler queue failed message if cp null cp cancel null server core client context return else if logminor logger minor this starting cp cp start null server core client context startclientputdir clientputdirmessage hashmap wasdiskput clientputdir clientputdir fcpmessage failedmessage persistencetype clientrequest persist_connection isclosed requestsbyidentifier containskey clientputdir wasdiskput requestsbyidentifier identifiercollisionexception malformedurlexception failedmessage protocolerrormessage protocolerrormessage freenet_uri_parse_error persistencetype clientrequest persist_forever clientcontext jobrunner dbjob objectcontainer clientcontext clientputdir clientputdir fcpconnectionhandler wasdiskput identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler malformedurlexception outputhandler protocolerrormessage protocolerrormessage freenet_uri_parse_error identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler nativethread high_priority clientputdir wasdiskput identifiercollisionexception malformedurlexception failedmessage protocolerrormessage protocolerrormessage freenet_uri_parse_error failedmessage identifiercollisionmessage persistencetype clientrequest persist_reboot identifiercollisionexception failedmessage identifiercollisionmessage failedmessage freedata outputhandler failedmessage clientcontext clientcontext public void run object container container client context context client put dir putter try putter new client put dir fcp connection handler this message buckets was disk put server container catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id message global output handler queue msg return catch malformedurl exception e output handler queue new protocol error message protocol error message freenet uri parse error true null id message global return try putter register container false false container store putter catch identifier collision exception e logger normal this identifier collision on this fcp message msg new identifier collision message id global output handler queue msg return putter start container context container deactivate putter 1 objectcontainer clientcontext clientputdir clientputdir fcpconnectionhandler wasdiskput identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler malformedurlexception outputhandler protocolerrormessage protocolerrormessage freenet_uri_parse_error identifiercollisionexception fcpmessage identifiercollisionmessage outputhandler public fcp client get reboot client return reboot client fcpclient getrebootclient rebootclient public fcp client get forever client object container container synchronized this if forever client null forever client create forever client client name container container activate forever client 1 forever client init container return forever client fcpclient getforeverclient objectcontainer foreverclient foreverclient createforeverclient clientname foreverclient foreverclient foreverclient public void finished client request client request get synchronized this requests by identifier remove get get identifier finishedclientrequest clientrequest requestsbyidentifier getidentifier public boolean is global subscribed return reboot client watch global isglobalsubscribed rebootclient watchglobal public boolean has full access return server allowed hosts full access allowed sock get inet address hasfullaccess allowedhostsfullaccess getinetaddress that method ought to be called before any direct disk access operation is performed by the node param filename param write request are willing to write or to read return boolean allowed or not protected boolean allowdda from file filename boolean write request string parent directory file util get canonical file filename get parent directory access da null synchronized checked directories da checked directories get parent directory if logminor logger minor this checking dda da for parent directory if write request return da null server is downloaddda always allowed da can write else return da null server is uploaddda always allowed da can read directdiskaccess writerequest allowddafrom writerequest parentdirectory fileutil getcanonicalfile getparent directoryaccess checkeddirectories checkeddirectories parentdirectory parentdirectory writerequest isdownloadddaalwaysallowed canwrite isuploadddaalwaysallowed canread should be called only from testdda complete param path param read param write protected void register testdda result string path boolean read boolean write directory access da new directory access read write synchronized checked directories checked directories put path da if logminor logger minor this dda read read write write for path testddacomplete registertestddaresult directoryaccess directoryaccess checkeddirectories checkeddirectories return a dda check job the one we created and have enqueued param path param read is read access requested param write is write access requested return throws illegal argument exception fixme maybe we need to enqueue a ps job to delete the created file after something like 5 mins protected dda check job enqueuedda check string path boolean read boolean write throws illegal argument exception file directory file util get canonical file new file path if directory exists directory is directory throw new illegal argument exception the specified path isn t a directory or doesn t exist or the node doesn t have access to it see 1856 dda check job job null synchronized in test directories job in test directories get directory if job null throw new illegal argument exception there is already a testdda going on for that directory file write file write new file path dda check server node fast weak random next int tmp null file read file null if read try read file file create temp file dda check tmp directory read file delete on exit catch io exception e now we know it we can t write there read file null dda check job result new dda check job server node fast weak random directory read file write file synchronized in test directories in test directories put directory result if read read file null read file can write we don t want to attempt to write before in case an io exception is raised we want to inform the client somehow that the node can t write there and setting read file to null means we won t inform it on the status as if it hadn t requested us to do the test file output stream fos null buffered output stream bos null try fos new file output stream result read filename bos new buffered output stream fos bos write result read content get bytes utf 8 bos flush catch io exception e logger error this got a ioe while creating the file read file to string e get message finally closer close bos closer close fos return result ddacheckjob illegalargumentexception ddacheckjob enqueueddacheck illegalargumentexception fileutil getcanonicalfile isdirectory illegalargumentexception ddacheckjob intestdirectories intestdirectories illegalargumentexception writefile ddacheck fastweakrandom nextint readfile readfile createtempfile ddacheck readfile deleteonexit ioexception readfile ddacheckjob ddacheckjob fastweakrandom readfile writefile intestdirectories intestdirectories readfile readfile canwrite ioexception readfile fileoutputstream bufferedoutputstream fileoutputstream readfilename bufferedoutputstream readcontent getbytes ioexception readfile tostring getmessage return a dda check job or null if not found param path return the dda check job throws illegal argument exception protected dda check job popdda check string path throws illegal argument exception file directory file util get canonical file new file path if directory exists directory is directory throw new illegal argument exception the specified path isn t a directory or doesn t exist or the node doesn t have access to it synchronized in test directories return in test directories remove directory ddacheckjob ddacheckjob illegalargumentexception ddacheckjob popddacheck illegalargumentexception fileutil getcanonicalfile isdirectory illegalargumentexception intestdirectories intestdirectories delete the files we have created using dda test called by fcp client on disconnect handler protected void freedda jobs synchronized in test directories iterator file it in test directories key set iterator while it has next dda check job job in test directories get it next if job read filename null job read filename delete ddatest fcpclient ondisconnect freeddajobs intestdirectories intestdirectories keyset hasnext ddacheckjob intestdirectories readfilename readfilename public client request remove request by identifier string identifier boolean kill client request req synchronized this req requests by identifier remove identifier if req null if kill req cancel null server core client context req request was removed null server core client context return req clientrequest removerequestbyidentifier clientrequest requestsbyidentifier clientcontext requestwasremoved clientcontext client request get reboot request boolean global fcp connection handler handler string identifier if global return handler server global reboot client get request identifier null else return handler get reboot client get request identifier null clientrequest getrebootrequest fcpconnectionhandler globalrebootclient getrequest getrebootclient getrequest client request get forever request boolean global fcp connection handler handler string identifier object container container if global return handler server global forever client get request identifier container else return handler get forever client container get request identifier container clientrequest getforeverrequest fcpconnectionhandler objectcontainer globalforeverclient getrequest getforeverclient getrequest client request remove persistent reboot request boolean global string identifier throws message invalid exception fcp client client global server global reboot client get reboot client client request req client get request identifier null if req null client remove by identifier identifier true server null server core client context return req clientrequest removepersistentrebootrequest messageinvalidexception fcpclient globalrebootclient getrebootclient clientrequest getrequest removebyidentifier clientcontext client request remove persistent forever request boolean global string identifier object container container throws message invalid exception fcp client client global server global forever client get forever client container container activate client 1 client request req client get request identifier container if req null client remove by identifier identifier true server container server core client context if global container deactivate client 1 return req clientrequest removepersistentforeverrequest objectcontainer messageinvalidexception fcpclient globalforeverclient getforeverclient clientrequest getrequest removebyidentifier clientcontext public boolean object can new object container container logger error this not storing fcp connection handler in database new exception error return false objectcannew objectcontainer fcpconnectionhandler public synchronized void add subscription string identifier subscribeusk subscribeusk throws identifier collision exception if usk subscriptions contains key identifier throw new identifier collision exception usk subscriptions put identifier subscribeusk addsubscription identifiercollisionexception usksubscriptions containskey identifiercollisionexception usksubscriptions public void unsubscribe string identifier throws message invalid exception subscribeusk sub synchronized this if usk subscriptions contains key identifier throw new message invalid exception protocol error message no such identifier no such identifier unsubscribing identifier false sub usk subscriptions remove identifier sub unsubscribe messageinvalidexception usksubscriptions containskey messageinvalidexception protocolerrormessage no_such_identifier usksubscriptions insert tag boolean ssk start start super this start start this ssk ssk inserttag public void handler threw throwable t handler threw t handlerthrew handlerthrew override public void log still present long uid string buffer sb new string buffer sb append still present after append time util format time age sb append append uid append start append start sb append ssk append ssk sb append thrown append handler threw if handler threw null logger error this sb to string handler threw else logger error this sb to string logstillpresent stringbuffer stringbuffer timeutil formattime handlerthrew handlerthrew tostring handlerthrew tostring static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog failure table entry key key this key key if key null throw new null pointer exception long now system current time millis creation time now received time 1 sent time 1 requestor nodes empty weak reference requestor times empty long array requestor booti ds empty long array requested nodes empty weak reference requested locs empty double array requested booti ds empty long array requested times empty long array requested timeouts empty long array requested timeoutht ls empty short array failuretableentry nullpointerexception currenttimemillis creationtime receivedtime senttime requestornodes empty_weak_reference requestortimes empty_long_array requestorbootids empty_long_array requestednodes empty_weak_reference requestedlocs empty_double_array requestedbootids empty_long_array requestedtimes empty_long_array requestedtimeouts empty_long_array requestedtimeouthtls empty_short_array called when there is a failure which could cause a block to be added either a data not found or a recently failed param htl2 param requestors param requested from public void on failure short htl2 peer node requestors peer node requested from int timeout long now if logminor logger minor this on failure htl2 requestors arrays to string requestors requested from arrays to string requested from timeout timeout synchronized this if requestors null for int i 0 i requestors length i add requestor requestors i now if requested from null for int i 0 i requested from length i add requested from requested from i now datanotfound recentlyfailed requestedfrom onfailure peernode peernode requestedfrom onfailure tostring requestedfrom tostring requestedfrom addrequestor requestedfrom requestedfrom addrequestedfrom requestedfrom public synchronized void failed to peer node routed to int timeout long now short htl if logminor logger minor this failed sending request to routed to short to string timeout timeout int idx add requested from routed to now long cur timeout time requested timeouts idx long new timeout time now timeout fixme htl if new timeout time cur timeout time requested timeouts idx new timeout time requested timeoutht ls idx htl failedto peernode routedto routedto shorttostring addrequestedfrom routedto curtimeouttime requestedtimeouts newtimeouttime newtimeouttime curtimeouttime requestedtimeouts newtimeouttime requestedtimeouthtls synchronized int add requestor peer node requestor long now if logminor logger minor this adding requestors requestor at now received time now boolean included already false int nulls 0 int ret 1 for int i 0 i requestor nodes length i peer node got requestor nodes i null null requestor nodes i get no longer subscribed if they have rebooted or expired if got requestor update existing entry included already true requestor times i now requestor booti ds i requestor get bootid ret i break else if got null got get bootid requestor booti ds i now requestor times i max time between request and offer requestor nodes i null got null if got null nulls if nulls 0 included already return ret int not included included already 0 1 because weak these can become null doesn t matter but we want to minimise memory usage if nulls 1 included already nice special case for int i 0 i requestor nodes length i if requestor nodes i null requestor nodes i get null requestor nodes i requestor my ref requestor times i now requestor booti ds i requestor get bootid return i suppress warnings unchecked weak reference peer node new requestor nodes new weak reference requestor nodes length not included nulls long new requestor times new long requestor nodes length not included nulls long new requestor booti ds new long requestor nodes length not included nulls int to index 0 for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i peer node pn ref null null ref get if pn null continue if pn requestor ret to index new requestor nodes to index requestor nodes i new requestor times to index requestor times i new requestor booti ds to index requestor booti ds i to index if included already new requestor nodes to index requestor my ref new requestor times to index now new requestor booti ds to index requestor get bootid ret to index to index for int i to index i new requestor nodes length i new requestor nodes i null if to index new requestor nodes length 2 suppress warnings unchecked weak reference peer node new new requestor nodes new weak reference to index long new new requestor times new long to index long new new requestor booti ds new long to index system arraycopy new requestor nodes 0 new new requestor nodes 0 to index system arraycopy new requestor times 0 new new requestor times 0 to index system arraycopy new requestor booti ds 0 new new requestor booti ds 0 to index new requestor nodes new new requestor nodes new requestor times new new requestor times new requestor booti ds new new requestor booti ds requestor nodes new requestor nodes requestor times new requestor times requestor booti ds new requestor booti ds return ret addrequestor peernode receivedtime includedalready requestornodes peernode requestornodes requestornodes includedalready requestortimes requestorbootids getbootid getbootid requestorbootids requestortimes max_time_between_request_and_offer requestornodes includedalready notincluded includedalready includedalready requestornodes requestornodes requestornodes requestornodes myref requestortimes requestorbootids getbootid suppresswarnings weakreference peernode newrequestornodes weakreference requestornodes notincluded newrequestortimes requestornodes notincluded newrequestorbootids requestornodes notincluded toindex requestornodes weakreference peernode requestornodes peernode toindex newrequestornodes toindex requestornodes newrequestortimes toindex requestortimes newrequestorbootids toindex requestorbootids toindex includedalready newrequestornodes toindex myref newrequestortimes toindex newrequestorbootids toindex getbootid toindex toindex toindex newrequestornodes newrequestornodes toindex newrequestornodes suppresswarnings weakreference peernode newnewrequestornodes weakreference toindex newnewrequestortimes toindex newnewrequestorbootids toindex newrequestornodes newnewrequestornodes toindex newrequestortimes newnewrequestortimes toindex newrequestorbootids newnewrequestorbootids toindex newrequestornodes newnewrequestornodes newrequestortimes newnewrequestortimes newrequestorbootids newnewrequestorbootids requestornodes newrequestornodes requestortimes newrequestortimes requestorbootids newrequestorbootids private synchronized int add requested from peer node requested from long now if logminor logger minor this adding requested from requested from at now sent time now boolean included already false int nulls 0 int ret 1 for int i 0 i requested nodes length i peer node got requested nodes i null null requested nodes i get if got requested from update existing entry included already true requested locs i requested from get location requested booti ds i requested from get bootid requested times i now ret i break else if got null nulls if included already nulls 0 return ret int not included included already 0 1 because weak these can become null doesn t matter but we want to minimise memory usage if nulls 1 included already nice special case for int i 0 i requested nodes length i if requested nodes i null requested nodes i get null requested nodes i requested from my ref requested locs i requested from get location requested booti ds i requested from get bootid requested times i now requested timeouts i 1 requested timeoutht ls i short 1 return i suppress warnings unchecked weak reference peer node new requested nodes new weak reference requested nodes length not included nulls double new requested locs new double requested nodes length not included nulls long new requested booti ds new long requested nodes length not included nulls long new requested times new long requested nodes length not included nulls long new requested timeouts new long requested nodes length not included nulls short new requested timeoutht ls new short requested nodes length not included nulls int to index 0 for int i 0 i requested nodes length i weak reference peer node ref requested nodes i peer node pn ref null null ref get if pn null continue if pn requested from ret to index new requested nodes to index requested nodes i new requested times to index requested times i new requested booti ds to index requested booti ds i new requested locs to index requested locs i new requested timeouts to index requested timeouts i new requested timeoutht ls to index requested timeoutht ls i to index if included already ret to index new requested nodes to index requested from my ref new requested times to index now new requested booti ds to index requested from get bootid new requested locs to index requested from get location new requested timeouts to index 1 new requested timeoutht ls to index short 1 ret to index to index for int i to index i new requested nodes length i new requested nodes i null if to index new requested nodes length 2 suppress warnings unchecked weak reference peer node new new requested nodes new weak reference to index double new new requested locs new double to index long new new requested booti ds new long to index long new new requested times new long to index long new new requested timeouts new long to index short new new requested timeoutht ls new short to index system arraycopy new requested nodes 0 new new requested nodes 0 to index system arraycopy new requested locs 0 new new requested locs 0 to index system arraycopy new requested booti ds 0 new new requested booti ds 0 to index system arraycopy new requested times 0 new new requested times 0 to index system arraycopy new requested timeouts 0 new new requested timeouts 0 to index system arraycopy new requested timeoutht ls 0 new new requested timeoutht ls 0 to index new requested nodes new new requested nodes new requested locs new new requested locs new requested booti ds new new requested booti ds new requested times new new requested times new requested timeouts new new requested timeouts new requested timeoutht ls new new requested timeoutht ls requested nodes new requested nodes requested locs new requested locs requested booti ds new requested booti ds requested times new requested times requested timeouts new requested timeouts requested timeoutht ls new requested timeoutht ls return ret addrequestedfrom peernode requestedfrom requestedfrom senttime includedalready requestednodes peernode requestednodes requestednodes requestedfrom includedalready requestedlocs requestedfrom getlocation requestedbootids requestedfrom getbootid requestedtimes includedalready notincluded includedalready includedalready requestednodes requestednodes requestednodes requestednodes requestedfrom myref requestedlocs requestedfrom getlocation requestedbootids requestedfrom getbootid requestedtimes requestedtimeouts requestedtimeouthtls suppresswarnings weakreference peernode newrequestednodes weakreference requestednodes notincluded newrequestedlocs requestednodes notincluded newrequestedbootids requestednodes notincluded newrequestedtimes requestednodes notincluded newrequestedtimeouts requestednodes notincluded newrequestedtimeouthtls requestednodes notincluded toindex requestednodes weakreference peernode requestednodes peernode requestedfrom toindex newrequestednodes toindex requestednodes newrequestedtimes toindex requestedtimes newrequestedbootids toindex requestedbootids newrequestedlocs toindex requestedlocs newrequestedtimeouts toindex requestedtimeouts newrequestedtimeouthtls toindex requestedtimeouthtls toindex includedalready toindex newrequestednodes toindex requestedfrom myref newrequestedtimes toindex newrequestedbootids toindex requestedfrom getbootid newrequestedlocs toindex requestedfrom getlocation newrequestedtimeouts toindex newrequestedtimeouthtls toindex toindex toindex toindex newrequestednodes newrequestednodes toindex newrequestednodes suppresswarnings weakreference peernode newnewrequestednodes weakreference toindex newnewrequestedlocs toindex newnewrequestedbootids toindex newnewrequestedtimes toindex newnewrequestedtimeouts toindex newnewrequestedtimeouthtls toindex newrequestednodes newnewrequestednodes toindex newrequestedlocs newnewrequestedlocs toindex newrequestedbootids newnewrequestedbootids toindex newrequestedtimes newnewrequestedtimes toindex newrequestedtimeouts newnewrequestedtimeouts toindex newrequestedtimeouthtls newnewrequestedtimeouthtls toindex newrequestednodes newnewrequestednodes newrequestedlocs newnewrequestedlocs newrequestedbootids newnewrequestedbootids newrequestedtimes newnewrequestedtimes newrequestedtimeouts newnewrequestedtimeouts newrequestedtimeouthtls newnewrequestedtimeouthtls requestednodes newrequestednodes requestedlocs newrequestedlocs requestedbootids newrequestedbootids requestedtimes newrequestedtimes requestedtimeouts newrequestedtimeouts requestedtimeouthtls newrequestedtimeouthtls offer this key to all the nodes that have requested it and all the nodes it has been requested from called after a the data has been stored and b this entry has been removed from the ft public synchronized void offer hash set peer node set new hash set peer node if logminor logger minor this sending offers to nodes which requested the key from us for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i if ref null continue peer node pn ref get if pn null continue if pn get bootid requestor booti ds i continue if set add pn logger error this node is in requestor nodes twice pn pn offer key if logminor logger minor this sending offers to nodes which we sent the key to for int i 0 i requested nodes length i weak reference peer node ref requested nodes i if ref null continue peer node pn ref get if pn null continue if pn get bootid requested booti ds i continue if set contains pn continue pn offer key hashset peernode hashset peernode requestornodes weakreference peernode requestornodes peernode getbootid requestorbootids requestornodes requestednodes weakreference peernode requestednodes peernode getbootid requestedbootids has any node asked for this key public synchronized boolean others want peer node peer boolean any valid false for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i if ref null continue peer node pn ref get if pn null requestor nodes i null continue long bootid pn get bootid if bootid requestor booti ds i requestor nodes i null continue any valid true if any valid requestor nodes empty weak reference requestor times requestor booti ds empty long array return any valid otherswant peernode anyvalid requestornodes weakreference peernode requestornodes peernode requestornodes getbootid requestorbootids requestornodes anyvalid anyvalid requestornodes empty_weak_reference requestortimes requestorbootids empty_long_array anyvalid has this peer asked us for the key public synchronized boolean asked by peer peer node peer long now boolean any valid false boolean ret false for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i if ref null continue peer node pn ref get if pn null requestor nodes i null continue long bootid pn get bootid if bootid requestor booti ds i requestor nodes i null continue if now requestor times i max time between request and offer if pn peer ret true any valid true if any valid requestor nodes empty weak reference requestor times requestor booti ds empty long array return ret askedbypeer peernode anyvalid requestornodes weakreference peernode requestornodes peernode requestornodes getbootid requestorbootids requestornodes requestortimes max_time_between_request_and_offer anyvalid anyvalid requestornodes empty_weak_reference requestortimes requestorbootids empty_long_array have we asked this peer for the key public synchronized boolean asked from peer peer node peer long now boolean any valid false boolean ret false for int i 0 i requested nodes length i weak reference peer node ref requested nodes i if ref null continue peer node pn ref get if pn null requested nodes i null continue long bootid pn get bootid if bootid requested booti ds i requested nodes i null continue any valid true if now requested times i max time between request and offer if pn peer ret true any valid true if any valid requested nodes empty weak reference requested times requested booti ds requested timeouts empty long array requested timeoutht ls empty short array return ret askedfrompeer peernode anyvalid requestednodes weakreference peernode requestednodes peernode requestednodes getbootid requestedbootids requestednodes anyvalid requestedtimes max_time_between_request_and_offer anyvalid anyvalid requestednodes empty_weak_reference requestedtimes requestedbootids requestedtimeouts empty_long_array requestedtimeouthtls empty_short_array public synchronized boolean is empty long now if requested nodes length 0 return false if requestor nodes length 0 return false return true isempty requestednodes requestornodes public synchronized long get timeout time peer node peer for int i 0 i requested nodes length i weak reference peer node ref requested nodes i if ref null ref get peer return requested timeouts i return 1 not timed out gettimeouttime peernode requestednodes weakreference peernode requestednodes requestedtimeouts public synchronized boolean cleanup long now system current time millis don t pass in as a pass over the whole ft may take a while get it in the method boolean empty cleanup requestor now empty cleanup requested now return empty currenttimemillis cleanuprequestor cleanuprequested private boolean cleanup requestor long now boolean empty true int x 0 for int i 0 i requestor nodes length i weak reference peer node ref requestor nodes i if ref null continue peer node pn ref get if pn null continue long bootid pn get bootid if bootid requestor booti ds i continue if pn is connected continue if now requestor times i max time between request and offer continue empty false requestor nodes x requestor nodes i requestor times x requestor times i requestor booti ds x requestor booti ds i x if x requestor nodes length suppress warnings unchecked weak reference peer node new requestor nodes new weak reference x long new requestor times new long x long new requestor booti ds new long x system arraycopy requestor nodes 0 new requestor nodes 0 x system arraycopy requestor times 0 new requestor times 0 x system arraycopy requestor booti ds 0 new requestor booti ds 0 x requestor nodes new requestor nodes requestor times new requestor times requestor booti ds new requestor booti ds return empty cleanuprequestor requestornodes weakreference peernode requestornodes peernode getbootid requestorbootids isconnected requestortimes max_time_between_request_and_offer requestornodes requestornodes requestortimes requestortimes requestorbootids requestorbootids requestornodes suppresswarnings weakreference peernode newrequestornodes weakreference newrequestortimes newrequestorbootids requestornodes newrequestornodes requestortimes newrequestortimes requestorbootids newrequestorbootids requestornodes newrequestornodes requestortimes newrequestortimes requestorbootids newrequestorbootids private boolean cleanup requested long now boolean empty true int x 0 for int i 0 i requested nodes length i weak reference peer node ref requested nodes i if ref null continue peer node pn ref get if pn null continue long bootid pn get bootid if bootid requested booti ds i continue if pn is connected continue if now requested times i max time between request and offer continue empty false requested nodes x requested nodes i requested times x requested times i requested booti ds x requested booti ds i requested locs x requested locs i if now requested timeouts x requested timeouts x requested timeouts i requested timeoutht ls x requested timeoutht ls i else requested timeouts x 1 requested timeoutht ls x short 1 x if x requested nodes length suppress warnings unchecked weak reference peer node new requested nodes new weak reference x long new requested times new long x long new requested booti ds new long x double new requested locs new double x long new requested timeouts new long x short new requested timeoutht ls new short x system arraycopy requested nodes 0 new requested nodes 0 x system arraycopy requested times 0 new requested times 0 x system arraycopy requested booti ds 0 new requested booti ds 0 x system arraycopy requested locs 0 new requested locs 0 x system arraycopy requested timeouts 0 new requested timeouts 0 x system arraycopy requested timeoutht ls 0 new requested timeoutht ls 0 x requested nodes new requested nodes requested times new requested times requested booti ds new requested booti ds requested locs new requested locs requested timeouts new requested timeouts requested timeoutht ls new requested timeoutht ls return empty cleanuprequested requestednodes weakreference peernode requestednodes peernode getbootid requestedbootids isconnected requestedtimes max_time_between_request_and_offer requestednodes requestednodes requestedtimes requestedtimes requestedbootids requestedbootids requestedlocs requestedlocs requestedtimeouts requestedtimeouts requestedtimeouts requestedtimeouthtls requestedtimeouthtls requestedtimeouts requestedtimeouthtls requestednodes suppresswarnings weakreference peernode newrequestednodes weakreference newrequestedtimes newrequestedbootids newrequestedlocs newrequestedtimeouts newrequestedtimeouthtls requestednodes newrequestednodes requestedtimes newrequestedtimes requestedbootids newrequestedbootids requestedlocs newrequestedlocs requestedtimeouts newrequestedtimeouts requestedtimeouthtls newrequestedtimeouthtls requestednodes newrequestednodes requestedtimes newrequestedtimes requestedbootids newrequestedbootids requestedlocs newrequestedlocs requestedtimeouts newrequestedtimeouts requestedtimeouthtls newrequestedtimeouthtls public boolean is empty return is empty system current time millis isempty isempty currenttimemillis construct a diffusion filter public diffusion filter set matrix diffusion matrix diffusionfilter diffusionfilter setmatrix diffusionmatrix set whether to use a serpentine pattern for return or not this can reduce avalanche artifacts in the output param serpentine true to use serpentine pattern see get serpentine public void set serpentine boolean serpentine this serpentine serpentine getserpentine setserpentine return the serpentine setting return the current setting see set serpentine public boolean get serpentine return serpentine setserpentine getserpentine set whether to use a color dither param color dither true to use a color dither see get color dither public void set color dither boolean color dither this color dither color dither colordither getcolordither setcolordither colordither colordither colordither get whether to use a color dither return true to use a color dither see set color dither public boolean get color dither return color dither setcolordither getcolordither colordither set the dither matrix param matrix the dither matrix see get matrix public void set matrix int matrix this matrix matrix sum 0 for int i 0 i matrix length i sum matrix i getmatrix setmatrix get the dither matrix return the dither matrix see set matrix public int get matrix return matrix setmatrix getmatrix set the number of dither levels param levels the number of levels see get levels public void set levels int levels this levels levels getlevels setlevels get the number of dither levels return the number of levels see set levels public int get levels return levels setlevels getlevels override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height int index 0 int map new int levels for int i 0 i levels i int v 255 i levels 1 map i v int div new int 256 for int i 0 i 256 i div i levels i 256 for int y 0 y height y boolean reverse serpentine y 1 1 int direction if reverse index y width width 1 direction 1 else index y width direction 1 for int x 0 x width x int rgb1 in pixels index int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff if color dither r1 g1 b1 r1 g1 b1 3 int r2 map div r1 int g2 map div g1 int b2 map div b1 out pixels index 0xff000000 r2 16 g2 8 b2 int er r1 r2 int eg g1 g2 int eb b1 b2 for int i 1 i 1 i int iy i y if 0 iy iy height for int j 1 j 1 j int jx j x if 0 jx jx width int w if reverse w matrix i 1 3 j 1 else w matrix i 1 3 j 1 if w 0 int k reverse index j index j rgb1 in pixels k r1 rgb1 16 0xff g1 rgb1 8 0xff b1 rgb1 0xff r1 er w sum g1 eg w sum b1 eb w sum in pixels k pixel utils clamp r1 16 pixel utils clamp g1 8 pixel utils clamp b1 index direction return out pixels filterpixels inpixels transformedspace outpixels inpixels colordither outpixels inpixels inpixels pixelutils pixelutils pixelutils outpixels override public string to string return colors diffusion dither tostring public float x y z w public tuple4f this 0 0 0 0 public tuple4f float x this x x 0 this y x 1 this z x 2 this w x 2 public tuple4f float x float y float z float w this x x this y y this z z this w w public tuple4f tuple4f t this x t x this y t y this z t z this w t w public void absolute x math abs x y math abs y z math abs z w math abs w public void absolute tuple4f t x math abs t x y math abs t y z math abs t z w math abs t w public void clamp float min float max if x min x min else if x max x max if y min y min else if y max y max if z min z min else if z max z max if w min w min else if w max w max public void set float x float y float z float w this x x this y y this z z this w w public void set float x this x x 0 this y x 1 this z x 2 this w x 2 public void set tuple4f t x t x y t y z t z w t w public void get tuple4f t t x x t y y t z z t w w public void get float t t 0 x t 1 y t 2 z t 3 w public void negate x x y y z z w w public void negate tuple4f t x t x y t y z t z w t w public void interpolate tuple4f t float alpha float a 1 alpha x a x alpha t x y a y alpha t y z a z alpha t z w a w alpha t w public void scale float s x s y s z s w s public void add tuple4f t x t x y t y z t z w t w public void add tuple4f t1 tuple4f t2 x t1 x t2 x y t1 y t2 y z t1 z t2 z w t1 w t2 w public void sub tuple4f t x t x y t y z t z w t w public void sub tuple4f t1 tuple4f t2 x t1 x t2 x y t1 y t2 y z t1 z t2 z w t1 w t2 w override public string to string return x y z w tostring set the number of iterations the effect is performed param iterations the number of iterations min value 0 see get iterations public void set iterations int iterations this iterations iterations getiterations setiterations get the number of iterations the effect is performed return the number of iterations see set iterations public int get iterations return iterations setiterations getiterations set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set new color int new color this new color new color setnewcolor newcolor newcolor newcolor public int get new color return new color getnewcolor newcolor public void set black function binary function black function this black function black function setblackfunction binaryfunction blackfunction blackfunction blackfunction public binary function get black function return black function binaryfunction getblackfunction blackfunction creates a new config object and stores the default values in it protected config freetalk my freetalk ext object container db m freetalk my freetalk mdb db m string params new hash map string string m int params new hash map string integer set default values false myfreetalk extobjectcontainer mfreetalk myfreetalk mstringparams hashmap mintparams hashmap setdefaultvalues protected void initialize transient freetalk my freetalk ext object container db m freetalk my freetalk mdb db initializetransient myfreetalk extobjectcontainer mfreetalk myfreetalk loads an existing config object from the database and adds any missing default values to it creates and stores a new one if none exists return the config object public static config load or create freetalk my freetalk ext object container db synchronized db lock config config object set config result db query by example config class if result size 0 logger debug my freetalk creating new config config new config my freetalk db config store and commit else if result size 1 do not throw we do not want to prevent freetalk from starting up logger error my freetalk multiple config objects stored logger debug my freetalk loaded config config result next config initialize transient my freetalk db config set default values false return config loadorcreate myfreetalk extobjectcontainer objectset querybyexample myfreetalk myfreetalk storeandcommit myfreetalk myfreetalk initializetransient myfreetalk setdefaultvalues stores the config object in the database please call this after any modifications to the config it is not done automatically because the user interface will usually change many values at once public synchronized void store and commit synchronized mdb lock try mdb store m string params 3 mdb store m int params 3 mdb store this catch runtime exception e mdb rollback throw e storeandcommit mstringparams mintparams runtimeexception sets a string configuration parameter you have to call store and commit to write it to disk param key name of the config parameter param value value of the config parameter public synchronized void set string key string value m string params put key value storeandcommit mstringparams sets an integer configuration parameter and stores it in the database you have to call store and commit to write it to disk param key name of the config parameter param value value of the config parameter public synchronized void set string key int value m int params put key value storeandcommit mintparams gets a string configuration parameter public synchronized string get string string key return m string params get key getstring mstringparams gets an integer configuration parameter public synchronized int get int string key return m int params get key getint mintparams check wheter a string config parameter exists public synchronized boolean contains string string key return m string params contains key key containsstring mstringparams containskey check wheter an integer config parameter exists public synchronized boolean contains int string key return m int params contains key key containsint mintparams containskey get all valid string configuration keys return a string array containing a copy of all keys in the database at the point of calling the function changes to the array do not change the database public synchronized string get all string keys we return a copy of the key set if we returned an iterator of the key set modifications on the configuration hash map would be reflected in the iterator this might lead to problems if the configuration is modified while someone is using an iterator returned by this function further the iterator would allow the user to delete keys from the configuration fixme there is a null pointer somewhere in here i don t have the time for fixing it right now return m string params key set to array new string m string params size getallstringkeys keyset keyset hashmap mstringparams keyset toarray mstringparams get all valid string configuration keys return a string array containing a copy of all keys in the database at the point of calling the function changes to the array do not change the database public synchronized string get all int keys we return a copy of the key set if we returned an iterator of the key set modifications on the configuration hash map would be reflected in the iterator this might lead to problems if the configuration is modified while someone is using an iterator returned by this function further the iterator would allow the user to delete keys from the configuration fixme there is a null pointer somewhere in here i don t have the time for fixing it right now return m int params key set to array new string m string params size getallintkeys keyset keyset hashmap mintparams keyset toarray mstringparams add the default configuration values to the database param overwrite if true overwrite already set values with the default value public synchronized void set default values boolean overwrite do not overwrite it shall only be overwritten when the database has been converted to a new format if contains int database format version set database format version freetalk database format version setdefaultvalues containsint database_format_version database_format_version database_format_version private final boolean require7 bit public identity encoding boolean require short lines boolean require7 bit this require short lines require short lines this require7 bit require7 bit require7bit identityencoding requireshortlines require7bit requireshortlines requireshortlines require7bit require7bit public void set ignore errors boolean ignore setignoreerrors public byte buffer encode byte buffer input fixme maybe we should validate the input here return input slice bytebuffer bytebuffer public byte buffer decode byte buffer input return input slice bytebuffer bytebuffer private static final int marker rst7 0xd7 last reset marker jpeg filter boolean delete comments boolean delete exif this delete comments delete comments this delete exif delete exif marker_rst7 jpegfilter deletecomments deleteexif deletecomments deletecomments deleteexif deleteexif public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception bucket output read filter data bf charset other params cb delete comments delete exif null if output null return output if logger should log logger minor this logger minor this need to modify jpeg bucket filtered bf make bucket 1 output stream os new buffered output stream filtered get output stream try read filter data bf charset other params cb delete comments delete exif os os flush os close os null finally closer close os return filtered readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception readfilter otherparams deletecomments deleteexif shouldlog makebucket outputstream bufferedoutputstream getoutputstream readfilter otherparams deletecomments deleteexif public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb boolean delete comments boolean delete exif output stream output throws data filter exception io exception boolean logminor logger should log logger minor this long length data size if length 6 throw error l10n too short title l10n too short input stream is data get input stream buffered input stream bis new buffered input stream is counted input stream cis new counted input stream bis data input stream dis new data input stream cis try assert header dis soi if output null output write soi byte array output stream baos null data output stream dos null if output null baos new byte array output stream dos new data output stream baos check the chunks boolean finished false int force marker type 1 while dos null finished if baos null baos reset int marker type if force marker type 1 marker type force marker type force marker type 1 else int marker start dis read if marker start 1 no more chunks to scan break else if finished if logminor logger minor this more data after eoi copying to truncate return null if marker start 0xff throw error invalid marker the file includes an invalid marker start integer to hex string marker start and cannot be parsed further if baos null baos write 0xff marker type dis read unsigned byte if baos null baos write marker type if logminor logger minor this marker type integer to hex string marker type long count at start cis count after marker but before type int block length if marker type marker eoi marker type marker rst0 marker type marker rst7 block length 0 else block length dis read unsigned short if dos null dos write short block length if marker type 0xda start of scan marker copy marker if block length 2 throw error invalid frame length the file includes an invalid frame length block length if dos null byte buf new byte block length 2 dis read fully buf dos write buf else skip bytes dis block length 2 logger minor this copied start of frame marker length block length 2 if baos null baos write to output will continue at end now copy the scan itself int prev char 1 while true int x dis read if prev char 1 output null output write prev char if x 1 termination inside a scan valid i suppose break if prev char 0xff x 0 x marker rst0 x marker rst7 reset markers can occur in the scan force marker type x if logminor logger minor this moved scan at cis count found a marker type integer to hex string x if output null output write x break end of scan new marker prev char x continue avoid writing the header twice else if marker type 0xe0 app0 if logminor logger minor this app0 string type read null terminated ascii string dis if baos null write null terminated string baos type if logminor logger minor this type type length type length if type equals jfif logger minor this jfif header file header int major version dis read unsigned byte if major version 1 throw error invalid header unrecognized major version major version if dos null dos write major version int minor version dis read unsigned byte if minor version 2 throw error invalid header unrecognized version 1 minor version if dos null dos write minor version int units dis read unsigned byte if units 2 throw error invalid header unrecognized units type units if dos null dos write units if dos null dos write short dis read short copy xdensity dos write short dis read short copy ydensity else dis read short ignore xdensity dis read short ignore ydensity int thumbx dis read unsigned byte if dos null dos write byte thumbx int thumby dis read unsigned byte if dos null dos write byte thumby int thumb len thumbx thumby 3 if thumb len length cis count throw error invalid header there should be thumb len bytes of thumbnail but there are only length cis count bytes left in the file if dos null byte buf new byte thumb len dis read fully buf dos write buf else skip bytes dis thumb len else if type equals jfxx jfif extension marker int extension code dis read unsigned byte if extension code 0x10 extension code 0x11 extension code 0x13 alternate thumbnail perfectly valid skip rest block length count at start cis dis dos thumbnail frame logger minor this thumbnail frame else throw error unknown jfxx extension extension code the file contains an unknown jfxx extension else if logminor logger minor this dropping application specific app0 chunk named type application specific extension if output null return null skip rest block length count at start cis dis dos application specific frame continue don t write the frame else if marker type 0xe1 exif if output null delete exif return null if delete exif if logminor logger minor this dropping exif data skip bytes dis block length 2 continue don t write the frame skip rest block length count at start cis dis dos exif frame else if marker type 0xfe comment if output null delete comments return null if delete comments skip bytes dis block length 2 if logminor logger minor this dropping comment length block length 2 continue don t write the frame skip rest block length count at start cis dis dos comment else if marker type 0xd9 end of image finished true if logminor logger minor this end of image else boolean valid false we used to support only db c4 c0 because some website said they were sufficient for decoding a jpeg unfortunately they are not jpeg is a very complex standard and the full spec is only available for a fee fixme somebody who has access to the spec should have a look at this and ideally write some chunk sanitizers switch marker type descriptions from http svn xiph org experimental giles jpegdump c gpl case 0xc0 start of frame case 0xc1 extended sequential huffman case 0xc2 progressive huffman case 0xc3 lossless huffman case 0xc5 differential sequential huffman case 0xc6 differential progressive huffman case 0xc7 differential lossless huffman delete 0xc8 reserved for jpeg extension likely to be used for bad things case 0xc9 extended sequential arithmetic case 0xca progressive arithmetic case 0xcb lossless arithmetic case 0xcd differential sequential arithmetic case 0xcf differential lossless arithmetic case 0xc4 define huffman tables case 0xcc define arithmetic coding conditioning restart markers case 0xd0 case 0xd1 case 0xd2 case 0xd3 case 0xd4 case 0xd5 case 0xd6 case 0xd7 delimiters case 0xd8 start of image case 0xd9 end of image case 0xda start of scan case 0xdb define quantization tables case 0xdc define number of lines case 0xdd define restart interval case 0xde define hierarchical progression case 0xdf expand reference components delete app0 app15 application data sections likely to be troublesome delete extension data sections jpg0 6 sof48 lse jpg9 jpg13 jcom comment tem temporary private use for arithmetic coding delete 0x02 0xbf reserved sections do not support jpeg2000 at the moment probably has different headers fixme valid true if valid essential non terminal but unparsed frames if block length 2 throw error invalid frame length the file includes an invalid frame length block length if dos null byte buf new byte block length 2 dis read fully buf dos write buf else skip bytes dis block length 2 logger minor this essential frame type integer to hex string marker type length block length 2 offset at end cis count else if marker type 0xe0 marker type 0xef app marker can be safely deleted if logminor logger minor this dropping application marker type integer to hex string marker type length block length else if logminor logger minor this dropping unknown frame type integer to hex string marker type block length readfilter bucketfactory hashmap otherparams filtercallback deletecomments deleteexif outputstream datafilterexception ioexception shouldlog throwerror tooshorttitle tooshort inputstream getinputstream bufferedinputstream bufferedinputstream countedinputstream countedinputstream datainputstream datainputstream assertheader bytearrayoutputstream dataoutputstream bytearrayoutputstream dataoutputstream forcemarkertype markertype forcemarkertype markertype forcemarkertype forcemarkertype markerstart markerstart markerstart throwerror tohexstring markerstart markertype readunsignedbyte markertype tohexstring markertype countatstart blocklength markertype marker_eoi markertype marker_rst0 markertype marker_rst7 blocklength blocklength readunsignedshort writeshort blocklength markertype blocklength throwerror blocklength blocklength readfully skipbytes blocklength blocklength writeto prevchar prevchar prevchar prevchar marker_rst0 marker_rst7 forcemarkertype tohexstring prevchar markertype readnullterminatedasciistring writenullterminatedstring majorversion readunsignedbyte majorversion throwerror majorversion majorversion minorversion readunsignedbyte minorversion throwerror minorversion minorversion readunsignedbyte throwerror writeshort readshort writeshort readshort readshort readshort readunsignedbyte writebyte readunsignedbyte writebyte thumblen thumblen throwerror thumblen thumblen readfully skipbytes thumblen extensioncode readunsignedbyte extensioncode extensioncode extensioncode skiprest blocklength countatstart throwerror extensioncode skiprest blocklength countatstart markertype deleteexif deleteexif skipbytes blocklength skiprest blocklength countatstart markertype deletecomments deletecomments skipbytes blocklength blocklength skiprest blocklength countatstart markertype markertype blocklength throwerror blocklength blocklength readfully skipbytes blocklength tohexstring markertype blocklength markertype markertype tohexstring markertype blocklength tohexstring markertype blocklength private static string l10n string key return l10n get string jpeg filter key getstring jpegfilter private void write null terminated string byte array output stream baos string type throws io exception try byte data type get bytes iso 8859 1 ascii near enough baos write data baos write 0 catch unsupported encoding exception e throw new error impossible jvm doesn t support iso 8859 1 e e writenullterminatedstring bytearrayoutputstream ioexception getbytes unsupportedencodingexception private string read null terminated ascii string data input stream dis throws io exception string builder sb new string builder while true int x dis read if x 1 throw error invalid extension frame could not read an extension frame name if x 0 break char c char x ascii if x 128 c 32 c 10 c 13 throw error invalid extension frame name non ascii character in extension frame name sb append c return sb to string readnullterminatedasciistring datainputstream ioexception stringbuilder stringbuilder throwerror throwerror tostring private void skip rest int block length long count at start counted input stream cis data input stream dis data output stream dos string thing throws io exception skip the rest of the data int skip int block length cis count count at start if skip 0 throw error invalid thing the file includes an invalid thing if skip 0 return if dos null byte buf new byte skip dis read fully buf dos write buf else skip bytes dis skip skiprest blocklength countatstart countedinputstream datainputstream dataoutputstream ioexception blocklength countatstart throwerror readfully skipbytes fixme factor this out somewhere an io util class maybe private void skip bytes data input stream dis int skip throws io exception int skipped 0 while skipped skip long x dis skip skip skipped if x 0 byte buf new byte math min 4096 skip skipped dis read fully buf skipped buf length else skipped x ioutil skipbytes datainputstream ioexception readfully private void assert header data input stream dis byte expected throws io exception byte read new byte expected length dis read fully read if arrays equals read expected throw error invalid header the file does not start with a valid jpeg jfif header assertheader datainputstream ioexception readfully throwerror private void throw error string short reason string reason throws data filter exception throw an exception string message l10n not jpeg if reason null message reason if short reason null message short reason data filter exception e new data filter exception short reason short reason p message p new html node p add child message if logger should log logger normal this logger normal this throwing e e throw e throwerror shortreason datafilterexception notjpeg shortreason shortreason datafilterexception datafilterexception shortreason shortreason htmlnode addchild shouldlog public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception return null writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception public class simple help toadlet extends toadlet simple help toadlet high level simple client client node client core c super client this core c simplehelptoadlet simplehelptoadlet highlevelsimpleclient nodeclientcore override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception html node page node ctx get page maker get page node freenet l10n get string f proxy toadlet help ctx html node content node ctx get page maker get content node page node if ctx is allowed full access content node add child core alerts create summary description infobox html node help screen box1 content node add child ctx get page maker get infobox infobox content l10n get string simple help toadlet description title html node help screen content1 ctx get page maker get content node help screen box1 help screen content1 add child l10n get string simple help toadlet description text definitions infobox html node help screen box2 content node add child ctx get page maker get infobox infobox content l10n get string simple help toadlet definitions title html node help screen content2 ctx get page maker get content node help screen box2 html node table help screen content2 add child table new string border style new string 0 border none html node row table add child tr html node cell row add child td style border none cell add child cell row add child td style border none cell add child a new string href title new string ctx fix link item get key item get description item get name row add child l10n get string simple help toadlet chk row add child br row add child l10n get string simple help toadlet ssk row add child br row add child l10n get string simple help toadlet usk help screen content2 addchild l10n get string simple help toadlet chk help screen content2 addchild br help screen content2 addchild l10n get string simple help toadlet ssk help screen content2 addchild br help screen content2 addchild l10n get string simple help toadlet usk port forwarding etc html node help screen box3 content node add child ctx get page maker get infobox infobox content l10n get string simple help toadlet connectivity title html node help screen content3 ctx get page maker get content node help screen box3 help screen content3 add child l10n get string simple help toadlet connectivity text this writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception htmlnode pagenode getpagemaker getpagenode getstring fproxytoadlet htmlnode contentnode getpagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode helpscreenbox1 contentnode addchild getpagemaker getinfobox getstring simplehelptoadlet descriptiontitle htmlnode helpscreencontent1 getpagemaker getcontentnode helpscreenbox1 helpscreencontent1 addchild getstring simplehelptoadlet descriptiontext htmlnode helpscreenbox2 contentnode addchild getpagemaker getinfobox getstring simplehelptoadlet definitionstitle htmlnode helpscreencontent2 getpagemaker getcontentnode helpscreenbox2 htmlnode helpscreencontent2 addchild htmlnode addchild htmlnode addchild addchild addchild addchild fixlink getkey getdescription getname addchild getstring simplehelptoadlet addchild addchild getstring simplehelptoadlet addchild addchild getstring simplehelptoadlet helpscreencontent2 getstring simplehelptoadlet helpscreencontent2 helpscreencontent2 getstring simplehelptoadlet helpscreencontent2 helpscreencontent2 getstring simplehelptoadlet htmlnode helpscreenbox3 contentnode addchild getpagemaker getinfobox getstring simplehelptoadlet connectivitytitle htmlnode helpscreencontent3 getpagemaker getcontentnode helpscreenbox3 helpscreencontent3 addchild getstring simplehelptoadlet connectivitytext writehtmlreply pagenode override public string supported methods return get supportedmethods public revocation checker node update manager manager file blob file this manager manager core manager node client core this revocationdnf counter 0 this blob file blob file this logminor logger should log logger minor this ctx revocation core make client short 0 true get fetch context ctx revocation allow splitfiles false ctx revocation cache local requests false ctx revocation max archive levels 1 big enough ctx revocation max output length 4096 ctx revocation max temp length 4096 ctx revocation max splitfile block retries 1 if we find content try forever to get it not used because of the above size limits ctx revocation max non splitfile retries 0 but return quickly normally revocationchecker nodeupdatemanager blobfile clientcore revocationdnfcounter blobfile blobfile shouldlog ctxrevocation makeclient getfetchcontext ctxrevocation allowsplitfiles ctxrevocation cachelocalrequests ctxrevocation maxarchivelevels ctxrevocation maxoutputlength ctxrevocation maxtemplength ctxrevocation maxsplitfileblockretries ctxrevocation maxnonsplitfileretries public int get revocationdnf counter return revocationdnf counter getrevocationdnfcounter revocationdnfcounter public void start boolean aggressive start aggressive true start a fetch param aggressive if set to true then we have just fetched an update and therefore can increase the priority of the fetch to maximum public void start boolean aggressive boolean reset if manager is blown logger error this not starting revocation checker key already blown return logminor logger should log logger minor this try client getter cg null client getter to cancel null synchronized this if aggressive was aggressive ignore old one to cancel revocation getter if logminor logger minor this ignoring old request because was low priority revocation getter null was aggressive aggressive if revocation getter null revocation getter is cancelled revocation getter is finished if logminor logger minor this not queueing another revocation fetcher yet old one still running reset false else if reset if logminor logger minor this resetting dnf count from revocationdnf counter new exception debug revocationdnf counter 0 else if logminor logger minor this revocation count revocationdnf counter if logminor logger minor this fetcher revocation getter if revocation getter null logminor logger minor this revocation fetcher cancelled revocation getter is cancelled finished revocation getter is finished try tmp blob file file create temp file revocation fblob tmp manager node client core get persistent temp dir catch io exception e logger error this cannot record revocation fetch therefore cannot pass it on to peers e e cg revocation getter new client getter this manager revocationuri ctx revocation aggressive request starter maximum priority class request starter immediate splitfile priority class this null tmp blob file null null new file bucket tmp blob file false false false false false if logminor logger minor this queued another revocation fetcher count revocationdnf counter if to cancel null to cancel cancel null core client context if cg null core client context start cg if logminor logger minor this started revocation fetcher catch fetch exception e logger error this not able to start the revocation fetcher manager blow cannot fetch the auto update uri isblown shouldlog clientgetter clientgetter tocancel wasaggressive tocancel revocationgetter revocationgetter wasaggressive revocationgetter revocationgetter iscancelled revocationgetter isfinished revocationdnfcounter revocationdnfcounter revocationdnfcounter revocationgetter revocationgetter revocationgetter iscancelled revocationgetter isfinished tmpblobfile createtempfile clientcore getpersistenttempdir ioexception revocationgetter clientgetter ctxrevocation requeststarter maximum_priority_class requeststarter immediate_splitfile_priority_class tmpblobfile filebucket tmpblobfile revocationdnfcounter tocancel tocancel clientcontext clientcontext fetchexception long last succeeded return last succeeded lastsucceeded lastsucceeded long last succeeded delta if last succeeded 0 return 1 return system current time millis last succeeded lastsucceededdelta lastsucceeded currenttimemillis lastsucceeded called when the revocation uri changes public void on change revocationuri kill start was aggressive onchangerevocationuri wasaggressive public void on success fetch result result client getter state object container container on success result state tmp blob file onsuccess fetchresult clientgetter objectcontainer onsuccess tmpblobfile void on success fetch result result client getter state file blob the key has been blown fixme maybe we need a bigger warning message move blob blob string msg null try byte buf result as byte array msg new string buf catch throwable t try msg failed to extract result when key blown t logger error this msg t system err println msg t print stack trace catch throwable t1 msg internal error after retreiving revocation key manager blow msg onsuccess fetchresult clientgetter moveblob asbytearray printstacktrace private void move blob file tmp blob file if tmp blob file null logger error this no temporary binary blob file moving it may not be able to propagate revocation bug return file util rename to tmp blob file blob file moveblob tmpblobfile tmpblobfile fileutil renameto tmpblobfile blobfile public void on failure fetch exception e client getter state object container container on failure e state tmp blob file onfailure fetchexception clientgetter objectcontainer onfailure tmpblobfile void on failure fetch exception e client getter state file tmp blob file logminor logger should log logger minor this if logminor logger minor this revocation fetch failed e int error code e get mode boolean completed false long now system current time millis if error code fetch exception cancelled if tmp blob file null tmp blob file delete return cancelled by us above or killed either way irrelevant and doesn t need to be restarted if e is fatal manager blow permanent error fetching revocation error inserting the revocation key e to string move blob tmp blob file other peers need to know return if tmp blob file null tmp blob file delete if e newuri null manager blow revocation uri redirecting to e newuri maybe you set the revocation uri to the update uri synchronized this if error code fetch exception data not found revocationdnf counter if logminor logger minor this incremented dnf counter to revocationdnf counter if revocationdnf counter 3 last succeeded now completed true revocationdnf counter 0 revocation getter null if completed manager no revocation found else start was aggressive false onfailure fetchexception clientgetter tmpblobfile shouldlog errorcode getmode currenttimemillis errorcode fetchexception tmpblobfile tmpblobfile isfatal tostring moveblob tmpblobfile tmpblobfile tmpblobfile errorcode fetchexception data_not_found revocationdnfcounter revocationdnfcounter revocationdnfcounter lastsucceeded revocationdnfcounter revocationgetter norevocationfound wasaggressive public void on success base client putter state object container container todo auto generated method stub onsuccess baseclientputter objectcontainer public void on failure insert exception e base client putter state object container container todo auto generated method stub onfailure insertexception baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container todo auto generated method stub ongenerateduri baseclientputter objectcontainer public void on major progress object container container todo auto generated method stub onmajorprogress objectcontainer public void on fetchable base client putter state object container container todo auto generated method stub onfetchable baseclientputter objectcontainer public void kill if revocation getter null revocation getter cancel null core client context revocationgetter revocationgetter clientcontext public long get blob size return blob file length getblobsize blobfile get the binary blob if we have fetched it public file get blob file if manager is blown return null if blob file exists return blob file return null getblobfile isblown blobfile blobfile public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception construct a circle filter public circle filter set edge action zero circlefilter circlefilter setedgeaction set the height of the arc param height the height see get height public void set height float height this height height getheight setheight get the height of the arc return the height see set height public float get height return height setheight getheight set the angle of the arc param angle the angle of the arc angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of the arc return the angle of the arc see set angle public float get angle return angle setangle getangle set the spread angle of the arc param spread angle the angle angle see get spread angle public void set spread angle float spread angle this spread angle spread angle spreadangle getspreadangle setspreadangle spreadangle spreadangle spreadangle get the spread angle of the arc return the angle angle see set spread angle public float get spread angle return spread angle setspreadangle getspreadangle spreadangle set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius set the centre of the effect in the y direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre override public buffered image filter buffered image src buffered image dst i width src get width i height src get height icentrex i width centrex icentrey i height centrey i width return super filter src dst bufferedimage bufferedimage bufferedimage iwidth getwidth iheight getheight iwidth iheight iwidth override protected void transform inverse int x int y float out float dx x icentrex float dy y icentrey float theta float math atan2 dy dx angle float r float math sqrt dx dx dy dy theta image math mod theta 2 float math pi out 0 i width theta spread angle 0 00001f out 1 i height 1 r radius height 0 00001f transforminverse imagemath iwidth spreadangle iheight override public string to string return distort circle tostring public get failed message fetch exception e string identifier boolean global if logger should log logger minor this logger minor this creating get failed from e for identifier e this tracker e error codes this code e mode this code description fetch exception get message code this extra description e extra message this short code description fetch exception get short message code this is fatal e is fatal this identifier identifier this global global this expected data length e expected size this expected mime type e get expected mime type this finalized expected e finalized size this redirecturi e newuri getfailedmessage fetchexception shouldlog errorcodes codedescription fetchexception getmessage extradescription extramessage shortcodedescription fetchexception getshortmessage isfatal isfatal expecteddatalength expectedsize expectedmimetype getexpectedmimetype finalizedexpected finalizedsize construct from a fieldset used in serialization of persistent requests will need to be made more tolerant of syntax errors if is used in an fcp client library fixme param use verbose fields if true read in verbose fields code description etc if false reconstruct them from the error code public get failed message simple field set fs boolean use verbose fields throws malformedurl exception identifier fs get identifier if identifier null throw new null pointer exception code integer parse int fs get code if use verbose fields code description fs get code description is fatal fields string to bool fs get fatal false short code description fs get short code description else code description fetch exception get message code is fatal fetch exception is fatal code short code description fetch exception get short message code extra description fs get extra description simple field set tracker subset fs subset errors if tracker subset null tracker new failure code tracker true tracker subset else tracker null expected mime type fs get expected mime type finalized expected fields string to bool fs get finalized expected false string s fs get expected data length if s null expected data length long parse long s else expected data length 1 s fs get redirecturi if s null this redirecturi new freeneturi s else this redirecturi null this global fields string to bool fs get global false useverbosefields codedescription getfailedmessage simplefieldset useverbosefields malformedurlexception nullpointerexception parseint useverbosefields codedescription codedescription isfatal stringtobool shortcodedescription shortcodedescription codedescription fetchexception getmessage isfatal fetchexception isfatal shortcodedescription fetchexception getshortmessage extradescription extradescription simplefieldset trackersubset trackersubset failurecodetracker trackersubset expectedmimetype expectedmimetype finalizedexpected stringtobool finalizedexpected expecteddatalength expecteddatalength parselong expecteddatalength stringtobool override public simple field set get field set return get field set true simplefieldset getfieldset getfieldset write to a simple field set for storage or transmission param verbose if true include fields which derive directly from static stuff on insert exception and therefore can be omitted if talking to self or another node public simple field set get field set boolean verbose simple field set sfs new simple field set true sfs put single code integer to string code if verbose sfs put single code description code description if extra description null sfs put single extra description extra description if verbose sfs put single fatal boolean to string is fatal if tracker null sfs tput errors tracker to field set verbose if verbose sfs put single short code description short code description sfs put single identifier identifier if expected data length 1 sfs put single expected data length long to string expected data length if expected mime type null sfs put single expected metadata content type expected mime type if finalized expected sfs put single finalized expected true if redirecturi null sfs put single redirecturi redirecturi to string false false return sfs simplefieldset insertexception simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle codedescription codedescription extradescription putsingle extradescription extradescription putsingle tostring isfatal tofieldset putsingle shortcodedescription shortcodedescription putsingle expecteddatalength putsingle expecteddatalength tostring expecteddatalength expectedmimetype putsingle expectedmetadata contenttype expectedmimetype finalizedexpected putsingle finalizedexpected putsingle tostring override public string get name return get failed getname getfailed override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message get failed goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message getfailed override public void remove from object container container if redirecturi null container activate redirecturi 5 redirecturi remove from container uri belongs to the parent which is also being removed if tracker null container activate tracker 5 tracker remove from container container delete this removefrom objectcontainer removefrom removefrom public control response set server u pnp get server name controlresponse setserver upnp getservername public control response soap response soap res super soap res controlresponse soapresponse soapres soapres public void set fault response int err code string err descr set status code http status internal server error node body node get body node node fault node create fault response node err code err descr body node add node fault node node env node get envelope node set content env node setfaultresponse errcode errdescr setstatuscode httpstatus internal_server_error bodynode getbodynode faultnode createfaultresponsenode errcode errdescr bodynode addnode faultnode envnode getenvelopenode setcontent envnode public void set fault response int err code set fault response err code u pnp status code2 string err code setfaultresponse errcode setfaultresponse errcode upnpstatus code2string errcode private node create fault response node int err code string err descr s fault node fault node new node soap xmlns soap delim soap fault faultcode s client faultcode node fault code node new node soap fault code fault code node set value soap xmlns soap delim fault code fault node add node fault code node faultstring u pnp error faultstring node fault string node new node soap fault string fault string node set value fault string fault node add node fault string node detail node detail node new node soap detail fault node add node detail node u pnp error xmlns urn schemas upnp org control 1 0 node upnp error node new node fault string upnp error node set attribute xmlns control xmlns detail node add node upnp error node error code error code error code node error code node new node soap error code error code node set value err code upnp error node add node error code node error description error string error description node error desctiprion node new node soap error description error desctiprion node set value err descr upnp error node add node error desctiprion node return fault node createfaultresponsenode errcode errdescr faultnode faultcodenode fault_code faultcodenode setvalue fault_code faultnode addnode faultcodenode upnperror faultstringnode fault_string faultstringnode setvalue fault_string faultnode addnode faultstringnode detailnode faultnode addnode detailnode upnperror upnperrornode fault_string upnperrornode setattribute detailnode addnode upnperrornode errorcode errorcode errorcodenode error_code errorcodenode setvalue errcode upnperrornode addnode errorcodenode errordescription errordescription errordesctiprionnode error_description errordesctiprionnode setvalue errdescr upnperrornode addnode errordesctiprionnode faultnode private node getu pnp error node node detail node get fault detail node if detail node null return null return detail node get node ends with soap upnp error getupnperrornode detailnode getfaultdetailnode detailnode detailnode getnodeendswith upnp_error private node getu pnp error code node node error node getu pnp error node if error node null return null return error node get node ends with soap error code getupnperrorcodenode errornode getupnperrornode errornode errornode getnodeendswith error_code private node getu pnp error description node node error node getu pnp error node if error node null return null return error node get node ends with soap error description getupnperrordescriptionnode errornode getupnperrornode errornode errornode getnodeendswith error_description public int getu pnp error code node error code node getu pnp error code node if error code node null return 1 string error code str error code node get value try return integer parse int error code str catch exception e return 1 getupnperrorcode errorcodenode getupnperrorcodenode errorcodenode errorcodestr errorcodenode getvalue parseint errorcodestr public string getu pnp error description node error desc node getu pnp error description node if error desc node null return return error desc node get value getupnperrordescription errordescnode getupnperrordescriptionnode errordescnode errordescnode getvalue public u pnp status getu pnp error int code 0 string desc code getu pnp error code desc getu pnp error description upnp err set code code upnp err set description desc return upnp err upnpstatus getupnperror getupnperrorcode getupnperrordescription upnperr setcode upnperr setdescription upnperr public client put disk dir message simple field set fs throws message invalid exception super fs allow unreadable files fields string to bool fs get allow unreadable files false string fnam fs get filename if fnam null throw new message invalid exception protocol error message missing field filename missing identifier global dirname new file fnam clientputdiskdirmessage simplefieldset messageinvalidexception allowunreadablefiles stringtobool allowunreadablefiles messageinvalidexception protocolerrormessage missing_field override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler server core allow upload from dirname throw new message invalid exception protocol error message access denied not allowed to upload from dirname identifier global create a directory listing of buckets of data mapped to manifest element s directories are sub hash map s hash map string object buckets make buckets by name dirname handler start client put dir this buckets true fcpconnectionhandler messageinvalidexception allowuploadfrom messageinvalidexception protocolerrormessage access_denied manifestelement hashmap hashmap makebucketsbyname startclientputdir create a map of string bucket for every file in a directory and its subdirs throws message invalid exception private hash map string object make buckets by name file thisdir string prefix throws message invalid exception if logger should log logger minor this logger minor this listing directory thisdir hash map string object ret new hash map string object file filelist thisdir list files if filelist null throw new message invalid exception protocol error message file not found no such directory identifier global for int i 0 i filelist length i skip unreadable files and dirs skip files nonexistant dangling symlinks check last if filelist i can read filelist i exists if filelist i is file file f filelist i file bucket bucket new file bucket f true false false false false ret put f get name new manifest element f get name prefix f get name bucket defaultmime types guessmime type f get name true f length else if filelist i is directory hash map string object subdir make buckets by name new file thisdir filelist i get name prefix filelist i get name ret put filelist i get name subdir else if allow unreadable files throw new message invalid exception protocol error message file not found not directory and not file filelist i identifier global else if allow unreadable files throw new message invalid exception protocol error message file not found not readable or doesn t exist filelist i identifier global return ret messageinvalidexception hashmap makebucketsbyname messageinvalidexception shouldlog hashmap hashmap listfiles messageinvalidexception protocolerrormessage file_not_found canread isfile filebucket filebucket getname manifestelement getname getname defaultmimetypes guessmimetype getname isdirectory hashmap makebucketsbyname getname getname getname allowunreadablefiles messageinvalidexception protocolerrormessage file_not_found allowunreadablefiles messageinvalidexception protocolerrormessage file_not_found override long data length return 0 datalength string get identifier return identifier getidentifier override public void read from input stream is bucket factory bf fcp server server throws io exception message invalid exception do nothing readfrom inputstream bucketfactory fcpserver ioexception messageinvalidexception override protected void write data output stream os throws io exception do nothing writedata outputstream ioexception override public void remove from object container container container delete dirname container delete this removefrom objectcontainer private t source public string set source string source throws plugin not found exception this source check source source return get plugin name source _source setsource pluginnotfoundexception _source checksource getpluginname public t get source return source getsource _source abstract input stream get input stream throws io exception plugin not found exception inputstream getinputstream ioexception pluginnotfoundexception abstract input stream get input stream throws io exception plugin not found exception abstract t check source string source throws plugin not found exception inputstream getinputstream ioexception pluginnotfoundexception checksource pluginnotfoundexception abstract t check source string source throws plugin not found exception abstract string get plugin name string source throws plugin not found exception checksource pluginnotfoundexception getpluginname pluginnotfoundexception abstract string get plugin name string source throws plugin not found exception abstract string getsha1sum throws plugin not found exception getpluginname pluginnotfoundexception pluginnotfoundexception abstract string getsha1sum throws plugin not found exception abstract string getsha256sum throws plugin not found exception pluginnotfoundexception pluginnotfoundexception private boolean closed public multi reader bucket bucket underlying bucket underlying multireaderbucket get a reader bucket public bucket get reader bucket synchronized this if closed return null bucket d new reader bucket if readers null readers new array list bucket 1 readers add d if logger should log logger minor this logger minor this get reader bucket returning d for this for bucket return d getreaderbucket readerbucket arraylist shouldlog getreaderbucket public void free if logger should log logger minor this logger minor this reader bucket this for multi reader bucket this free ing for bucket synchronized multi reader bucket this if freed return freed true readers remove this if readers is empty return readers null if closed return closed true bucket free shouldlog readerbucket multireaderbucket multireaderbucket isempty public input stream get input stream throws io exception synchronized multi reader bucket this if freed closed throw new io exception already freed return new reader bucket input stream inputstream getinputstream ioexception multireaderbucket ioexception readerbucketinputstream input stream is reader bucket input stream throws io exception is bucket get input stream inputstream readerbucketinputstream ioexception getinputstream override public final int read throws io exception synchronized multi reader bucket this if freed closed throw new io exception already closed return is read ioexception multireaderbucket ioexception override public final int read byte data int offset int length throws io exception synchronized multi reader bucket this if freed closed throw new io exception already closed return is read data offset length ioexception multireaderbucket ioexception override public final int read byte data throws io exception synchronized multi reader bucket this if freed closed throw new io exception already closed return is read data ioexception multireaderbucket ioexception override public final void close throws io exception is close ioexception public string get name return bucket get name getname getname public output stream get output stream throws io exception throw new io exception read only outputstream getoutputstream ioexception ioexception public boolean is read only return true isreadonly public void set read only already read only setreadonly public long size return bucket size override protected void finalize free public void store to object container container container store this storeto objectcontainer public void remove from object container container container delete this synchronized multi reader bucket this if closed return bucket remove from container container delete readers container delete multi reader bucket this removefrom objectcontainer multireaderbucket removefrom multireaderbucket public bucket create shadow throws io exception return null createshadow ioexception override public own introduction puzzle generate puzzle introduction puzzle store store own identity inserter throws io exception byte array output stream out new byte array output stream 10 1024 todo find out the maximum size of the captchas and put it here try default kaptcha captcha new default kaptcha captcha set config new config new properties string text captcha create text buffered image img captcha create image text imageio write img jpg out date date of insertion current timeutc get synchronized store own introduction puzzle puzzle new own introduction puzzle inserter puzzle type captcha image jpeg out to byte array text date of insertion store get free index inserter date of insertion store store and commit puzzle return puzzle finally closer close out ownintroductionpuzzle generatepuzzle introductionpuzzlestore ownidentity ioexception bytearrayoutputstream bytearrayoutputstream defaultkaptcha defaultkaptcha setconfig createtext bufferedimage createimage dateofinsertion currenttimeutc ownintroductionpuzzle ownintroductionpuzzle puzzletype tobytearray dateofinsertion getfreeindex dateofinsertion storeandcommit private int offset public contour composite int offset this offset offset contourcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new contour composite context offset src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints contourcompositecontext srccolormodel dstcolormodel override public int hash code return 0 hashcode override public boolean equals object o if o instanceof contour composite return false return true contourcomposite private int offset public contour composite context int offset color model src color model color model dst color model this offset offset contourcompositecontext colormodel srccolormodel colormodel dstcolormodel public void dispose public void compose raster src raster dst in writable raster dst out int x src get minx int y src get miny int w src get width int h src get height int src pix null int src pix2 null int dst in pix null int dst out pix new int w 4 for int i 0 i h i src pix src get pixels x y w 1 src pix dst in pix dst in get pixels x y w 1 dst in pix int last alpha 0 int k 0 for int j 0 j w j int alpha src pix k 3 int alpha above i 0 src pix2 k 3 alpha if i 0 j 0 alpha last alpha 0x80 0 alpha alpha above 0x80 0 if offset i j 10 4 dst out pix k 0x00 dst out pix k 1 0x00 dst out pix k 2 0x00 else dst out pix k 0xff dst out pix k 1 0xff dst out pix k 2 0x7f dst out pix k 3 0xff else dst out pix k dst in pix k dst out pix k 1 dst in pix k 1 dst out pix k 2 dst in pix k 2 if dst out dst in dst out pix k 0xff dst out pix k 1 0 dst out pix k 2 0 dst out pix k 3 0 else dst out pix k 3 dst in pix k 3 last alpha alpha k 4 dst out set pixels x y w 1 dst out pix int t src pix src pix src pix2 src pix2 t y dstin writableraster dstout getminx getminy getwidth getheight srcpix srcpix2 dstinpix dstoutpix srcpix getpixels srcpix dstinpix dstin getpixels dstinpix lastalpha srcpix alphaabove srcpix2 lastalpha alphaabove dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstinpix dstoutpix dstinpix dstoutpix dstinpix dstout dstin dstoutpix dstoutpix dstoutpix dstoutpix dstoutpix dstinpix lastalpha dstout setpixels dstoutpix srcpix srcpix srcpix2 srcpix2 private int n members private ttree nmembers private ttree ttree persistent comparator t comparator boolean unique this comparator comparator this unique unique persistentcomparator get comparator used in this collection return collection comparator public persistent comparator t get comparator return comparator persistentcomparator getcomparator public boolean recursive loading return false recursiveloading public t get object key if root null array list list new array list root find comparator key 1 key 1 list if list size 1 throw new storage error storage error key not unique else if list size 0 return null else return t list get 0 return null arraylist arraylist storageerror storageerror key_not_unique public array list t get list object from object till array list list new array list if root null root find comparator from 1 till 1 list return list arraylist getlist arraylist arraylist public array list t get list object from boolean from inclusive object till boolean till inclusive array list list new array list if root null root find comparator from from inclusive 1 0 till till inclusive 1 0 list return list arraylist getlist frominclusive tillinclusive arraylist arraylist frominclusive tillinclusive public i persistent get object from object till array list t list get list from till return i persistent list to array new i persistent list size ipersistent arraylist getlist ipersistent toarray ipersistent public i persistent get object from boolean from inclusive object till boolean till inclusive array list t list get list from from inclusive till till inclusive return i persistent list to array new i persistent list size ipersistent frominclusive tillinclusive arraylist getlist frominclusive tillinclusive ipersistent toarray ipersistent add new member to collection param obj new member return code true code if object is successfully added in the index code false code if collection was declared as unique and there is already member with such value of the key in the collection public boolean add t obj ttree page new root if root null new root new ttree page obj else ttree page page reference ref new ttree page page reference root if root insert comparator obj unique ref ttree page not unique return false new root ref pg root new root n members 1 modify return true ttreepage newroot newroot ttreepage ttreepage pagereference ttreepage pagereference ttreepage not_unique newroot newroot nmembers check if collections contains specified member return code true code if specified member belongs to the collection public boolean contains object t member return root null member null root contains object comparator member false containsobject containsobject public boolean contains t member return root null member null root contains comparator member false public boolean contains key object key return root null key null root contains key comparator key false containskey containskey remove member from collection param obj member to be removed exception storage error storage error key not found exception if there is no such key in the collection public void remove t obj if root null throw new storage error storage error key not found ttree page page reference ref new ttree page page reference root if root remove comparator obj ref ttree page not found throw new storage error storage error key not found root ref pg n members 1 modify storageerror storageerror key_not_found storageerror storageerror key_not_found ttreepage pagereference ttreepage pagereference ttreepage not_found storageerror storageerror key_not_found nmembers get number of objects in the collection return number of objects in the collection public int size return n members nmembers remove all objects from the collection public void clear if root null root prune root null n members 0 modify nmembers t tree destructor public void deallocate if root null root prune super deallocate public i persistent to persistent array if root null return empty selection i persistent arr new i persistent n members root to array arr 0 return arr ipersistent topersistentarray emptyselection ipersistent ipersistent nmembers toarray public object to array return to persistent array toarray topersistentarray get all objects in the index as array ordered by index key the runtime type of the returned array is that of the specified array if the index fits in the specified array it is returned therein otherwise a new array is allocated with the runtime type of the specified array and the size of this index p if this index fits in the specified array with room to spare i e the array has more elements than this index the element in the array immediately following the end of the index is set to tt null tt this is useful in determining the length of this index i only i if the caller knows that this index does not contain any tt null tt elements p return array of objects in the index ordered by key value public e e to array e arr if arr length n members arr e array new instance arr get class get component type n members if root null root to array i persistent arr 0 if arr length n members arr n members null return arr toarray nmembers newinstance getclass getcomponenttype nmembers toarray ipersistent nmembers nmembers ttree iterator ttree tree array list list this tree tree this list list i 1 ttreeiterator arraylist public t next if i 1 list size throw new no such element exception removed false return t list get i nosuchelementexception public int next oid return i persistent next get oid nextoid ipersistent getoid public void remove if removed i 0 i list size throw new illegal state exception tree remove i persistent list get i list remove i removed true illegalstateexception ipersistent public boolean has next return i 1 list size hasnext public iterator t iterator return iterator null null public iterable iterator t iterator object from object till return iterator from true till true iterableiterator public iterable iterator t iterator object from boolean from inclusive object till boolean till inclusive array list list new array list if root null root find comparator from from inclusive 1 0 till till inclusive 1 0 list return new ttree iterator t this list iterableiterator frominclusive tillinclusive arraylist arraylist frominclusive tillinclusive ttreeiterator clamp a value to the range 0 255 public static int clamp int c if c 0 return 0 if c 255 return 255 return c public static int interpolate int v1 int v2 float f return clamp int v1 f v2 v1 public static int brightness int rgb int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff return r g b 3 public static boolean near colors int rgb1 int rgb2 int tolerance int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff return math abs r1 r2 tolerance math abs g1 g2 tolerance math abs b1 b2 tolerance nearcolors return rgb1 painted onto rgb2 public static int combine pixels int rgb1 int rgb2 int op return combine pixels rgb1 rgb2 op 0xff combinepixels combinepixels public static int combine pixels int rgb1 int rgb2 int op int extra alpha int channel mask return rgb2 channel mask combine pixels rgb1 channel mask rgb2 op extra alpha combinepixels extraalpha channelmask channelmask combinepixels channelmask extraalpha public static int combine pixels int rgb1 int rgb2 int op int extra alpha if op replace return rgb1 int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff switch op case normal break case min r1 math min r1 r2 g1 math min g1 g2 b1 math min b1 b2 break case max r1 math max r1 r2 g1 math max g1 g2 b1 math max b1 b2 break case add r1 clamp r1 r2 g1 clamp g1 g2 b1 clamp b1 b2 break case subtract r1 clamp r2 r1 g1 clamp g2 g1 b1 clamp b2 b1 break case difference r1 clamp math abs r1 r2 g1 clamp math abs g1 g2 b1 clamp math abs b1 b2 break case multiply r1 clamp r1 r2 255 g1 clamp g1 g2 255 b1 clamp b1 b2 255 break case dissolve if random generator next int 0xff a1 r1 r2 g1 g2 b1 b2 break case average r1 r1 r2 2 g1 g1 g2 2 b1 b1 b2 2 break case hue case saturation case value case color color rg btohsb r1 g1 b1 hsb1 color rg btohsb r2 g2 b2 hsb2 switch op case hue hsb2 0 hsb1 0 break case saturation hsb2 1 hsb1 1 break case value hsb2 2 hsb1 2 break case color hsb2 0 hsb1 0 hsb2 1 hsb1 1 break rgb1 color hs btorgb hsb2 0 hsb2 1 hsb2 2 r1 rgb1 16 0xff g1 rgb1 8 0xff b1 rgb1 0xff break case screen r1 255 255 r1 255 r2 255 g1 255 255 g1 255 g2 255 b1 255 255 b1 255 b2 255 break case overlay int m s s 255 255 r1 255 r2 255 m r1 r2 255 r1 s r1 m 255 r1 255 s 255 255 g1 255 g2 255 m g1 g2 255 g1 s g1 m 255 g1 255 s 255 255 b1 255 b2 255 m b1 b2 255 b1 s b1 m 255 b1 255 break case clear r1 g1 b1 0xff break case dst in r1 clamp r2 a1 255 g1 clamp g2 a1 255 b1 clamp b2 a1 255 a1 clamp a2 a1 255 return a1 24 r1 16 g1 8 b1 case alpha a1 a1 a2 255 return a1 24 r2 16 g2 8 b2 case alpha to gray int na 255 a1 return a1 24 na 16 na 8 na if extra alpha 0xff a1 0xff a1 a1 extra alpha 255 int a3 255 a1 a2 255 r1 clamp r1 a1 r2 a3 255 g1 clamp g1 a1 g2 a3 255 b1 clamp b1 a1 b2 a3 255 a1 clamp a1 a3 return a1 24 r1 16 g1 8 b1 combinepixels extraalpha randomgenerator nextint rgbtohsb rgbtohsb hsbtorgb dst_in alpha_to_gray extraalpha extraalpha link items object get int i return items get i i persistent get position tree position pos int i pos page this pos index i return items get i ipersistent getposition treeposition i persistent get raw position tree position pos int i pos page this pos index i return items get raw i ipersistent getrawposition treeposition getraw object set int i object obj return items set i i persistent obj ipersistent void clear int i int len while len 0 items set object i null setobject void prune deallocate void copy int dst offs list page src int src offs int len system arraycopy src items to raw array src offs items to raw array dst offs len dstoffs listpage srcoffs torawarray srcoffs torawarray dstoffs int get max items return n leaf page items getmaxitems nleafpageitems void set item int i i persistent obj items set object i obj setitem ipersistent setobject int size return n items nitems list page clone page return new list page get storage listpage clonepage listpage getstorage list page listpage list page storage storage super storage int max get max items items storage create link max items set size max listpage getmaxitems createlink setsize i persistent remove int i i persistent obj items get i n items 1 copy i this i 1 n items i items set object n items null modify return obj ipersistent ipersistent nitems nitems setobject nitems boolean underflow return n items get max items 2 nitems getmaxitems list page add int i i persistent obj int max get max items modify if n items max copy i 1 this i n items i set item i obj n items 1 return null else list page b clone page int m max 2 if i m b copy 0 this 0 i b copy i 1 this i m i 1 copy 0 this m 1 max m 1 b set item i obj else b copy 0 this 0 m copy 0 this m i m copy i m 1 this i max i set item i m obj clear max m 1 m 1 n items max m 1 b n items m return b listpage ipersistent getmaxitems nitems nitems setitem nitems listpage clonepage setitem setitem nitems nitems i persistent get position tree position pos int i int j for j 0 i n children j j i n children j return list page items get j get position pos i ipersistent getposition treeposition nchildren nchildren listpage getposition i persistent get raw position tree position pos int i int j for j 0 i n children j j i n children j return list page items get j get raw position pos i ipersistent getrawposition treeposition nchildren nchildren listpage getrawposition object get int i int j for j 0 i n children j j i n children j return list page items get j get i nchildren nchildren listpage object set int i object obj int j for j 0 i n children j j i n children j return list page items get j set i obj nchildren nchildren listpage list page add int i i persistent obj int j for j 0 i n children j j i n children j list page pg list page items get j list page overflow pg add i obj if overflow null count children j pg overflow super add j overflow else modify if n children j integer max value n children j 1 return overflow listpage ipersistent nchildren nchildren listpage listpage listpage countchildren nchildren max_value nchildren i persistent remove int i int j for j 0 i n children j j i n children j list page pg list page items get j i persistent obj pg remove i modify if pg underflow handle page underflow pg j else if n children j integer max value n children j 1 return obj ipersistent nchildren nchildren listpage listpage ipersistent handlepageunderflow nchildren max_value nchildren void count children int i list page pg if n children i integer max value n children i pg size countchildren listpage nchildren max_value nchildren void prune for int i 0 i n items i list page items get i prune deallocate nitems listpage void handle page underflow list page a int r int an a n items int max a get max items if r 1 n items exists greater page list page b list page items get r 1 int bn b n items assert that bn an if an bn max reallocation of nodes between pages a and b int i bn an bn 1 b modify a copy an b 0 i b copy 0 b i bn i b clear bn i i b n items i a n items i n children r a size count children r 1 b else merge page b to a a copy an b 0 bn a n items bn n items 1 n children r n children r 1 copy r 1 this r 2 n items r 1 count children r a items set n items null b deallocate else page b is before a list page b list page items get r 1 int bn b n items assert that bn an b modify if an bn max reallocation of nodes between pages a and b int i bn an bn 1 a copy i a 0 an a copy 0 b bn i i b clear bn i i b n items i a n items i n children r 1 b size count children r a else merge page b to a b copy bn a 0 an b n items an n items 1 n children r 1 n children r count children r 1 b items set r null a deallocate handlepageunderflow listpage nitems getmaxitems nitems listpage listpage nitems nitems nitems nchildren countchildren nitems nitems nchildren nchildren nitems countchildren nitems listpage listpage nitems nitems nitems nchildren countchildren nitems nitems nchildren nchildren countchildren void copy int dst offs list page src int src offs int len super copy dst offs src src offs len system arraycopy list intermediate page src n children src offs n children dst offs len dstoffs listpage srcoffs dstoffs srcoffs listintermediatepage nchildren srcoffs nchildren dstoffs int get max items return n intermediate page items getmaxitems nintermediatepageitems void set item int i i persistent obj super set item i obj n children i list page obj size setitem ipersistent setitem nchildren listpage int size if n children n items 1 integer max value return integer max value else int n 0 for int i 0 i n items i n n children i return n nchildren nitems max_value max_value nitems nchildren list page clone page return new list intermediate page get storage listpage clonepage listintermediatepage getstorage list intermediate page listintermediatepage list intermediate page list intermediate page storage storage super storage n children new int n intermediate page items listintermediatepage listintermediatepage nchildren nintermediatepageitems public e get int i if i 0 i n elems throw new index out of bounds exception index i size n elems return e root get i nelems indexoutofboundsexception nelems e get position tree position pos int i if i 0 i n elems throw new index out of bounds exception index i size n elems if pos page null i pos index i pos index pos page n items return e pos page items get i pos index pos index i return e root get position pos i getposition treeposition nelems indexoutofboundsexception nelems nitems getposition i persistent get raw position tree position pos int i if i 0 i n elems throw new index out of bounds exception index i size n elems if pos page null i pos index i pos index pos page n items return pos page items get raw i pos index pos index i return root get raw position pos i ipersistent getrawposition treeposition nelems indexoutofboundsexception nelems nitems getraw getrawposition public e set int i e obj if i 0 i n elems throw new index out of bounds exception index i size n elems return e root set i obj nelems indexoutofboundsexception nelems public object to array int n n elems object arr new object n iterator e iterator list iterator 0 for int i 0 i n i arr i iterator next return arr toarray nelems listiterator public t t to array t arr int n n elems if arr length n arr t array new instance arr get class get component type n iterator e iterator list iterator 0 for int i 0 i n i arr i t iterator next return arr toarray nelems newinstance getclass getcomponenttype listiterator public boolean is empty return n elems 0 isempty nelems public int size return n elems nelems public boolean contains object o iterator e iterator if o null while e has next if e next null return true else while e has next if o equals e next return true return false hasnext hasnext public boolean add e o add n elems o return true nelems public void add int i e o if i 0 i n elems throw new index out of bounds exception index i size n elems i persistent obj i persistent o list page overflow root add i obj if overflow null list intermediate page pg new list intermediate page get storage pg set item 0 overflow pg items set object 1 root pg n children 1 integer max value pg n items 2 root pg n elems 1 mod count 1 modify nelems indexoutofboundsexception nelems ipersistent ipersistent listpage listintermediatepage listintermediatepage getstorage setitem setobject nchildren max_value nitems nelems modcount public e remove int i if i 0 i n elems throw new index out of bounds exception index i size n elems e obj e root remove i if root n items 1 root instanceof list intermediate page list page new root list page root items get 0 root deallocate root new root n elems 1 mod count 1 modify return obj nelems indexoutofboundsexception nelems nitems listintermediatepage listpage newroot listpage newroot nelems modcount public void clear mod count 1 root prune root new list page get storage n elems 0 modify modcount listpage getstorage nelems public int index of object o list iterator e e list iterator if o null while e has next if e next null return e previous index else while e has next if o equals e next return e previous index return 1 indexof listiterator listiterator hasnext previousindex hasnext previousindex public int last index of object o list iterator e e list iterator size if o null while e has previous if e previous null return e next index else while e has previous if o equals e previous return e next index return 1 lastindexof listiterator listiterator hasprevious nextindex hasprevious nextindex public boolean add all int index collection extends e c boolean modified false iterator extends e e c iterator while e has next add index e next modified true return modified addall hasnext public iterator e iterator return new itr public list iterator e list iterator return list iterator 0 listiterator listiterator listiterator public list iterator e list iterator int index if index 0 index size throw new index out of bounds exception index index return new list itr index listiterator listiterator indexoutofboundsexception listitr int expected mod count mod count public boolean has next return cursor size expectedmodcount modcount hasnext public int next oid check for comodification try int oid get raw position this cursor get oid last ret cursor return oid catch index out of bounds exception e check for comodification throw new no such element exception nextoid checkforcomodification getrawposition getoid lastret indexoutofboundsexception checkforcomodification nosuchelementexception public e next check for comodification try e next get position this cursor last ret cursor return next catch index out of bounds exception e check for comodification throw new no such element exception checkforcomodification getposition lastret indexoutofboundsexception checkforcomodification nosuchelementexception public void remove if last ret 1 throw new illegal state exception check for comodification try persistent list impl this remove last ret if last ret cursor cursor page null last ret 1 expected mod count mod count catch index out of bounds exception e throw new concurrent modification exception lastret illegalstateexception checkforcomodification persistentlistimpl lastret lastret lastret expectedmodcount modcount indexoutofboundsexception concurrentmodificationexception final void check for comodification if mod count expected mod count throw new concurrent modification exception checkforcomodification modcount expectedmodcount concurrentmodificationexception private class list itr extends itr implements list iterator e list itr int index cursor index listitr listiterator listitr public boolean has previous return cursor 0 hasprevious public e previous check for comodification try int i cursor 1 e previous get position this i last ret cursor i return previous catch index out of bounds exception e check for comodification throw new no such element exception checkforcomodification getposition lastret indexoutofboundsexception checkforcomodification nosuchelementexception public int next index return cursor nextindex public int previous index return cursor 1 previousindex public void set e o if last ret 1 throw new illegal state exception check for comodification try persistent list impl this set last ret o expected mod count mod count catch index out of bounds exception e throw new concurrent modification exception lastret illegalstateexception checkforcomodification persistentlistimpl lastret expectedmodcount modcount indexoutofboundsexception concurrentmodificationexception public void add e o check for comodification try persistent list impl this add cursor o last ret 1 page null expected mod count mod count catch index out of bounds exception e throw new concurrent modification exception checkforcomodification persistentlistimpl lastret expectedmodcount modcount indexoutofboundsexception concurrentmodificationexception public list e sub list int from index int to index return new sub list e this from index to index sublist fromindex toindex sublist fromindex toindex protected void remove range int from index int to index while from index to index remove from index to index 1 removerange fromindex toindex fromindex toindex fromindex toindex persistent list impl persistentlistimpl persistent list impl persistent list impl storage storage super storage root new list page storage persistentlistimpl persistentlistimpl listpage sub list persistent list impl e list int from index int to index if from index 0 throw new index out of bounds exception from index from index if to index list size throw new index out of bounds exception to index to index if from index to index throw new illegal argument exception from index from index to index to index l list offset from index size to index from index expected mod count l mod count sublist persistentlistimpl fromindex toindex fromindex indexoutofboundsexception fromindex fromindex toindex indexoutofboundsexception toindex toindex fromindex toindex illegalargumentexception fromindex fromindex toindex toindex fromindex toindex fromindex expectedmodcount modcount public e set int index e element range check index check for comodification return l set index offset element rangecheck checkforcomodification public e get int index range check index check for comodification return l get index offset rangecheck checkforcomodification public int size check for comodification return size checkforcomodification public void add int index e element if index 0 index size throw new index out of bounds exception check for comodification l add index offset element expected mod count l mod count size mod count indexoutofboundsexception checkforcomodification expectedmodcount modcount modcount public e remove int index range check index check for comodification e result l remove index offset expected mod count l mod count size mod count return result rangecheck checkforcomodification expectedmodcount modcount modcount protected void remove range int from index int to index check for comodification l remove range from index offset to index offset expected mod count l mod count size to index from index mod count removerange fromindex toindex checkforcomodification removerange fromindex toindex expectedmodcount modcount toindex fromindex modcount public boolean add all collection extends e c return add all size c addall addall public boolean add all int index collection extends e c if index 0 index size throw new index out of bounds exception index index size size int c size c size if c size 0 return false check for comodification l add all offset index c expected mod count l mod count size c size mod count return true addall indexoutofboundsexception csize csize checkforcomodification addall expectedmodcount modcount csize modcount public iterator e iterator return list iterator listiterator public list iterator e list iterator final int index check for comodification if index 0 index size throw new index out of bounds exception index index size size return new list iterator e private list iterator e i l list iterator index offset public boolean has next return next index size public e next if has next return i next else throw new no such element exception public boolean has previous return previous index 0 public e previous if has previous return i previous else throw new no such element exception public int next index return i next index offset public int previous index return i previous index offset public void remove i remove expected mod count l mod count size mod count public void set e o i set o public void add e o i add o expected mod count l mod count size mod count listiterator listiterator checkforcomodification indexoutofboundsexception listiterator listiterator listiterator hasnext nextindex hasnext nosuchelementexception hasprevious previousindex hasprevious nosuchelementexception nextindex nextindex previousindex previousindex expectedmodcount modcount modcount expectedmodcount modcount modcount private list iterator e i l list iterator index offset public boolean has next return next index size listiterator listiterator hasnext nextindex public e next if has next return i next else throw new no such element exception hasnext nosuchelementexception public boolean has previous return previous index 0 hasprevious previousindex public e previous if has previous return i previous else throw new no such element exception hasprevious nosuchelementexception public int next index return i next index offset nextindex nextindex public int previous index return i previous index offset previousindex previousindex public void remove i remove expected mod count l mod count size mod count expectedmodcount modcount modcount public void set e o i set o public void add e o i add o expected mod count l mod count size mod count expectedmodcount modcount modcount public list e sub list int from index int to index return new sub list e l offset from index offset to index sublist fromindex toindex sublist fromindex toindex private void range check int index if index 0 index size throw new index out of bounds exception index index size size rangecheck indexoutofboundsexception private void check for comodification if l mod count expected mod count throw new concurrent modification exception checkforcomodification modcount expectedmodcount concurrentmodificationexception public class service data extends node data public service data servicedata nodedata servicedata private listener list control action listener list new listener list public listener list get control action listener list return control action listener list listenerlist controlactionlistenerlist listenerlist listenerlist getcontrolactionlistenerlist controlactionlistenerlist private node scpd node null public node getscpd node return scpd node scpdnode getscpdnode scpdnode public void setscpd node node node scpd node node setscpdnode scpdnode private subscriber list subscriber list new subscriber list public subscriber list get subscriber list return subscriber list subscriberlist subscriberlist subscriberlist subscriberlist getsubscriberlist subscriberlist private string sid public string getsid return sid public void setsid string id sid id private long timeout 0 public long get timeout return timeout gettimeout public void set timeout long value timeout value settimeout public http response set content type html content type set server http server get name set content httpresponse setcontenttype content_type setserver httpserver getname setcontent public http response http response http res set http res httpresponse httpresponse httpres httpres public http response input stream in super in httpresponse inputstream public http response http socket http sock this http sock get input stream httpresponse httpsocket httpsock httpsock getinputstream private int status code 0 public void set status code int code status code code statuscode setstatuscode statuscode public int get status code if status code 0 return status code http status http status new http status get first line return http status get status code getstatuscode statuscode statuscode httpstatus httpstatus httpstatus getfirstline httpstatus getstatuscode public boolean is successful return http status is successful get status code issuccessful httpstatus issuccessful getstatuscode public string get status line string return http get version get status code http status code2 string status code http crlf getstatuslinestring getversion getstatuscode httpstatus code2string statuscode public string get header string builder str new string builder str append get status line string str append get header string return str to string getheader stringbuilder stringbuilder getstatuslinestring getheaderstring tostring public string to string string builder str new string builder str append get status line string str append get header string str append http crlf str append get content string return str to string tostring stringbuilder stringbuilder getstatuslinestring getheaderstring getcontentstring tostring public void print system out println to string tostring public class life filter extends binary filter public life filter lifefilter binaryfilter lifefilter override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int r 0 g 0 b 0 int pixel in pixels y width x int a pixel 0xff000000 int neighbours 0 for int row 1 row 1 row int iy y row int ioffset if 0 iy iy height ioffset iy width for int col 1 col 1 col int ix x col if row 0 col 0 0 ix ix width int rgb in pixels ioffset ix if black function is black rgb neighbours if black function is black pixel out pixels index neighbours 2 neighbours 3 pixel 0xffffffff else out pixels index neighbours 3 0xff000000 pixel return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels blackfunction isblack blackfunction isblack outpixels outpixels outpixels override public string to string return binary life tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog final int receivedbytecount public static message decode message from packet byte buf int offset int length peer context peer int overhead byte buffer input stream bb new byte buffer input stream buf offset length return decode message bb peer length overhead true false _receivedbytecount decodemessagefrompacket peercontext bytebufferinputstream bytebufferinputstream decodemessage private static message decode message byte buffer input stream bb peer context peer int recv byte count boolean may have sub messages boolean in sub message message type mspec try mspec message type get spec integer value of bb read int catch io exception e1 if logdebug logger debug message class failed to read message type e1 e1 return null if mspec null return null if mspec is internal only return null silently discard internal only messages message m new message mspec peer recv byte count try for string name mspec get ordered fields class type mspec get fields get name if type equals linked list class special handling for linked list to deal with element type m set name serializer read list from data input stream mspec get linked list types get name bb else m set name serializer read from data input stream type bb if may have sub messages while bb remaining 2 sizeof unsigned short 2 byte buffer input stream bb2 try int size bb read unsigned short if bb remaining size return m bb2 bb slice size catch eof exception e if logminor logger minor message class no submessages returning m return m try message sub message decode message bb2 peer 0 false true if sub message null return m if logminor logger minor message class adding submessage sub message m add sub message sub message catch throwable t logger error message class failed to read sub message t t catch eof exception e string msg peer get peer sent a message packet that ends prematurely while deserialising mspec get name if in sub message logger minor message class msg in sub message e else logger error message class msg e return null catch io exception e logger error message class unexpected io exception e reading from buffer stream e return null if logminor logger minor message class returning message m return m decodemessage bytebufferinputstream peercontext recvbytecount mayhavesubmessages insubmessage messagetype messagetype getspec valueof readint ioexception isinternalonly recvbytecount getorderedfields getfields linkedlist linkedlist readlistfromdatainputstream getlinkedlisttypes readfromdatainputstream mayhavesubmessages bytebufferinputstream readunsignedshort eofexception submessage decodemessage submessage submessage addsubmessage submessage eofexception getpeer getname insubmessage ioexception ioexception public message message type spec this spec null 0 messagetype private message message type spec peer context source int recv byte count local instantiation time system current time millis spec spec if source null internal true sourceref null else internal false sourceref source get weak ref receivedbytecount recv byte count messagetype peercontext recvbytecount localinstantiationtime currenttimemillis _spec _internal _sourceref _internal _sourceref getweakref _receivedbytecount recvbytecount public boolean get boolean string key return boolean payload get key boolean value getboolean _payload booleanvalue public byte get byte string key return byte payload get key byte value getbyte _payload bytevalue public short get short string key return short payload get key short value getshort _payload shortvalue public int get int string key return integer payload get key int value getint _payload intvalue public long get long string key return long payload get key long value getlong _payload longvalue public double get double string key return double payload get key double value getdouble _payload doublevalue public string get string string key return string payload get key getstring _payload public object get object string key return payload get key getobject _payload public void set string key boolean b set key boolean value of b valueof public void set string key byte b set key byte value of b valueof public void set string key short s set key short value of s valueof public void set string key int i set key integer value of i valueof public void set string key long l set key long value of l valueof public void set string key double d set key new double d public void set string key object value if spec check type key value if value null throw new incorrect type exception got null for key throw new incorrect type exception got value get class expected spec type of key payload put key value _spec checktype incorrecttypeexception incorrecttypeexception getclass _spec typeof _payload public byte encode to packet peer context destination return encode to packet destination true false encodetopacket peercontext encodetopacket private byte encode to packet peer context destination boolean include sub messages boolean is sub message if this get spec message types ping this get spec message types pong logger log minor send message this if logdebug logger debug this my spec code spec get name hash code for spec get name byte array output stream baos new byte array output stream data output stream dos new data output stream baos try dos write int spec get name hash code for string name spec get ordered fields serializer write to data output stream payload get name dos destination dos flush catch io exception e e print stack trace throw new illegal state exception e get message if submessages null include sub messages for int i 0 i submessages size i byte temp submessages get i encode to packet destination false true try dos write short temp length dos write temp catch io exception e e print stack trace throw new illegal state exception e get message byte buf baos to byte array if logdebug logger debug this length buf length hash fields hash code buf return buf encodetopacket peercontext includesubmessages issubmessage getspec messagetypes getspec messagetypes logminor _spec getname hashcode _spec getname bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream writeint _spec getname hashcode _spec getorderedfields writetodataoutputstream _payload ioexception printstacktrace illegalstateexception getmessage _submessages includesubmessages _submessages _submessages encodetopacket writeshort ioexception printstacktrace illegalstateexception getmessage tobytearray hashcode override public string to string string builder ret new string builder 1000 string comma ret append spec get name append for string name spec get fields key set ret append comma ret append name append append payload get name comma ret append return ret to string tostring stringbuilder stringbuilder _spec getname _spec getfields keyset _payload tostring public peer context get source return sourceref null null peer context sourceref get peercontext getsource _sourceref peercontext _sourceref public boolean is internal return internal isinternal _internal public message type get spec return spec messagetype getspec _spec public boolean is set string field name return payload contains key field name isset fieldname _payload containskey fieldname public object get from payload string field name throws field not set exception object r payload get field name if r null throw new field not set exception field name not set return r getfrompayload fieldname fieldnotsetexception _payload fieldname fieldnotsetexception fieldname private static final long serial versionuid 1l public field not set exception string message super message serialversionuid fieldnotsetexception set fields for a routed to a specific node message param node identity public void set routed to node fields long uid double target location short htl byte node identity set dmt uid uid set dmt target location target location set dmt htl htl set dmt node identity new short buffer node identity nodeidentity setroutedtonodefields targetlocation nodeidentity target_location targetlocation node_identity shortbuffer nodeidentity public int received byte count return receivedbytecount receivedbytecount _receivedbytecount public void add sub message message sub message if submessages null submessages new array list message submessages add sub message addsubmessage submessage _submessages _submessages arraylist _submessages submessage public message get sub message message type t if submessages null return null for int i 0 i submessages size i message m submessages get i if m get spec t return m return null getsubmessage messagetype _submessages _submessages _submessages getspec public message grab sub message message type t if submessages null return null for int i 0 i submessages size i message m submessages get i if m get spec t submessages remove i return m return null grabsubmessage messagetype _submessages _submessages _submessages getspec _submessages public long age return system current time millis local instantiation time currenttimemillis localinstantiationtime construct an all black colormap public array colormap this map new int 256 arraycolormap construct a colormap with the given map param map the array of argb colors public array colormap int map this map map arraycolormap override public object clone try array colormap g array colormap super clone g map int map clone return g catch clone not supported exception e return null arraycolormap arraycolormap clonenotsupportedexception set the array of colors for the colormap param map the colors see get map public void set map int map this map map getmap setmap get the array of colors for the colormap return the colors see set map public int get map return map setmap getmap convert a value in the range 0 1 to an rgb color param v a value in the range 0 1 return an rgb color see set color public int get color float v v 255 int n int v float f v n if n 0 return map 0 else if n 255 return map 255 return image math mix colors f map n map n 1 int n int v 255 if n 0 n 0 else if n 255 n 255 return map n setcolor getcolor imagemath mixcolors set the color at index to color entries are interpolated linearly from the existing entries at first index and last index to the new entry first index index last index must hold param index the position to set param first index the position of the first color from which to interpolate param last index the position of the second color from which to interpolate param color the color to set public void set color interpolated int index int first index int last index int color int first color map first index int last color map last index for int i first index i index i map i image math mix colors float i first index index first index first color color for int i index i last index i map i image math mix colors float i index last index index color last color firstindex lastindex firstindex lastindex firstindex lastindex setcolorinterpolated firstindex lastindex firstcolor firstindex lastcolor lastindex firstindex imagemath mixcolors firstindex firstindex firstcolor lastindex imagemath mixcolors lastindex lastcolor set a range of the colormap interpolating between two colors param first index the position of the first color param last index the position of the second color param color1 the first color param color2 the second color public void set color range int first index int last index int color1 int color2 for int i first index i last index i map i image math mix colors float i first index last index first index color1 color2 firstindex lastindex setcolorrange firstindex lastindex firstindex lastindex imagemath mixcolors firstindex lastindex firstindex set a range of the colormap to a single color param first index the position of the first color param last index the position of the second color param color the color public void set color range int first index int last index int color for int i first index i last index i map i color firstindex lastindex setcolorrange firstindex lastindex firstindex lastindex set one element of the colormap to a given color param index the position of the color param color the color see get color public void set color int index int color map index color getcolor setcolor public class byte buffer public final void extend int size if size arr length int new len size arr length 2 size arr length 2 byte new arr new byte new len system arraycopy arr 0 new arr 0 used arr new arr used size bytebuffer newlen newarr newlen newarr newarr final byte to array byte result new byte used system arraycopy arr 0 result 0 used return result toarray int pack string int dst string value string encoding if value null extend dst 4 bytes pack4 arr dst 1 dst 4 else int length value length if encoding null extend dst 4 2 length bytes pack4 arr dst length dst 4 for int i 0 i length i bytes pack2 arr dst short value char at i dst 2 else try byte bytes value get bytes encoding extend dst 4 bytes length bytes pack4 arr dst 2 bytes length system arraycopy bytes 0 arr dst 4 bytes length dst 4 bytes length catch unsupported encoding exception x throw new storage error storage error unsupported encoding return dst packstring charat getbytes unsupportedencodingexception storageerror storageerror unsupported_encoding class byte buffer output stream extends output stream public void write int b write new byte byte b 0 1 bytebufferoutputstream outputstream public void write byte b int off int len int pos used extend pos len system arraycopy b off arr pos len public output stream get output stream return new byte buffer output stream outputstream getoutputstream bytebufferoutputstream public int size return used byte buffer arr new byte 64 bytebuffer protected l2 list elem prev public l2 list elem next prev this l2listelem l2listelem get next list element been call for the last list element this method will return first element of the list or list header public l2 list elem get next return next l2listelem getnext get previous list element been call for the first list element this method will return last element of the list or list header public l2 list elem get prev return prev l2listelem getprev make list empty this method should be applied to list header public void prune modify next prev this link specified element in the list after this element param elem element to be linked in the list after this elemen public void link after l2 list elem elem modify next modify elem modify elem next next elem prev this next prev elem next elem linkafter l2listelem link specified element in the list before this element param elem element to be linked in the list before this elemen public void link before l2 list elem elem modify prev modify elem modify elem next this elem prev prev prev next elem prev elem linkbefore l2listelem remove element from the list public void unlink next modify prev modify next prev prev prev next next construct a new empty frost message object public frost message frostmessageobject frostmessage public frost message string base frost board b string from string subject string content set base base set board b set name from if subject null subject equals set subject subject set content content frostmessage frostboard setbase setboard setname setsubject setcontent public string get date and time if date and time null java text simple date format date format new java text simple date format yyyy mm dd hh mm ssz date format set time zone time zone get time zone gmt date and time date format format new date return date and time getdateandtime dateandtime simpledateformat dateformat simpledateformat dateformat settimezone timezone gettimezone dateandtime dateformat dateandtime 2006 9 6 if not pad public string get date str boolean pad string date str java text simple date format date format if pad date format new java text simple date format yyyy mm dd else date format new java text simple date format yyyy m d date format set time zone time zone get time zone gmt date str date format format new date return date str getdatestr datestr simpledateformat dateformat dateformat simpledateformat dateformat simpledateformat dateformat settimezone timezone gettimezone datestr dateformat datestr 02 01 53gmt public string get time str if time str null java text simple date format date format new java text simple date format hh mm ssz date format set time zone time zone get time zone gmt time str date format format new date return time str gettimestr timestr simpledateformat dateformat simpledateformat dateformat settimezone timezone gettimezone timestr dateformat timestr public frost board get board return board frostboard getboard public void set board frost board board this board board setboard frostboard public string get name return name getname public string get id random rnd new random new date get time string builder sb new string builder for int i 0 i 4 i sb append long to hex string rnd next long to upper case return sb to string getid gettime stringbuilder stringbuilder tohexstring nextlong touppercase tostring public void set name string name this name name setname dummy public boolean contains attachments return false containsattachments public int get index return index getindex public void set index int index this index index setindex public string get invalid reason return invalid reason getinvalidreason invalidreason public void set invalid reason string invalid reason this invalid reason invalid reason setinvalidreason invalidreason invalidreason invalidreason public boolean is valid return is valid isvalid isvalid public void set valid boolean is valid this is valid is valid setvalid isvalid isvalid isvalid override public string to string return get subject tostring getsubject return get subject public string get content return content getsubject getcontent return content public string get subject return subject getsubject public void set content string content this content content setcontent this content content public void set subject string subject this subject subject setsubject public void set base string base this base base setbase hack private final string get xml if xml null string message content new string builder append append this get name append append this get date str true append append this get time str append n n append this get content to string string builder sb new string builder sb append xml version 1 0 encoding utf 8 n sb append frost message sb append message id cdata append this get id append message id sb append in reply to in reply to sb append from cdata append this get name append from sb append subject cdata append this get subject append subject non padded string sb append date cdata append this get date str false append date format 02 01 53gmt sb append time cdata append this get time str append time might be a good idea to add anon 2006 09 13 01 53 20gmt sb append body cdata append message content append body sb append board cdata append this get board get name append board sb append signature status cdata old signature status sb append frost message xml sb to string return xml getxml messagecontent stringbuilder getname getdatestr gettimestr getcontent tostring stringbuilder stringbuilder frostmessage messageid getid messageid inreplyto inreplyto getname getsubject getdatestr gettimestr messagecontent getboard getname signaturestatus signaturestatus frostmessage tostring public string get message base return base getmessagebase this method composes the uploading key for the message given a certain index number param index index number to use to compose the key return they composed key public freeneturi compose upload key int index throws malformedurl exception freeneturi key if board is write access board key new freeneturi new string builder append board get private key append append board get name append append this get date str false append append index append xml to string else key new freeneturi ksk new string builder append frost message append this get message base append append this get date str false append append board get name append append index append xml to string system err println fin key is key to string return key composeuploadkey malformedurlexception iswriteaccessboard stringbuilder getprivatekey getname getdatestr tostring stringbuilder getmessagebase getdatestr getname tostring tostring public final freeneturi insert message high level simple client client int innitial index throws insert exception malformedurl exception boolean keepgoing freeneturi key null freeneturi return key null string type text xml int more tries 50 byte data try data this get xml get bytes utf 8 catch unsupported encoding exception e1 throw new error impossible jvm doesn t support utf 8 e1 e1 insert block block null do until the message is inserted key this compose upload key innitial index keepgoing false block new insert block new array bucket data new client metadata type key try inserting the message with the key try return key client insert block false null i don t know what that false is catch insert exception e system err println fin insert failed with the message e get message if more tries 0 throw e keepgoing true innitial index while keepgoing return return key insertmessage highlevelsimpleclient innitialindex insertexception malformedurlexception returnkey moretries getxml getbytes unsupportedencodingexception insertblock composeuploadkey innitialindex insertblock arraybucket clientmetadata returnkey insertexception getmessage moretries innitialindex returnkey construct a kaleidoscope filter with no distortion public kaleidoscope filter set edge action clamp kaleidoscopefilter kaleidoscopefilter setedgeaction set the number of sides of the kaleidoscope param sides the number of sides min value 2 see get sides public void set sides int sides this sides sides getsides setsides get the number of sides of the kaleidoscope return the number of sides see set sides public int get sides return sides setsides getsides set the angle of the kaleidoscope param angle the angle of the kaleidoscope angle see get angle public void set angle float angle this angle angle getangle setangle get the angle of the kaleidoscope return the angle of the kaleidoscope see set angle public float get angle return angle setangle getangle set the secondary angle of the kaleidoscope param angle2 the angle angle see get angle2 public void set angle2 float angle2 this angle2 angle2 getangle2 setangle2 get the secondary angle of the kaleidoscope return the angle see set angle2 public float get angle2 return angle2 setangle2 getangle2 set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius override public buffered image filter buffered image src buffered image dst icentrex src get width centrex icentrey src get height centrey return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight override protected void transform inverse int x int y float out double dx x icentrex double dy y icentrey double r math sqrt dx dx dy dy double theta math atan2 dy dx angle angle2 theta image math triangle float theta math pi sides 5 if radius 0 double c math cos theta double radiusc radius c r radiusc image math triangle float r radiusc theta angle out 0 float icentrex r math cos theta out 1 float icentrey r math sin theta transforminverse imagemath imagemath override public string to string return distort kaleidoscope tostring public argument list argumentlist public argument get argument int n return argument get n getargument public argument get argument string name int n args size for int n 0 n n args n argument arg get argument n string arg name arg get name if arg name null continue if arg name equals name true return arg return null getargument nargs nargs getargument argname getname argname argname public void set argument list in arg list int n in args in arg list size for int n 0 n n in args n argument in arg in arg list get argument n string in arg name in arg get name argument arg get argument in arg name if arg null continue arg set value in arg get value argumentlist inarglist ninargs inarglist ninargs inarg inarglist getargument inargname inarg getname getargument inargname setvalue inarg getvalue get version history containing this versioned object public synchronized version history get version history return history versionhistory getversionhistory get predecessors of this version return array of predecessor versions public synchronized version get predecessors return predecessors to array new version predecessors size getpredecessors toarray get successors of this version return array of predecessor versions public synchronized version get successors return successors to array new version successors size getsuccessors toarray check if version is checked in return code true code if version belongs to version history public boolean is checked in return id null ischeckedin check if version is checked out return code true code if version is cjust created and not checked in yet and so belongs to version history public boolean is checked out return id null ischeckedout create new version which will be direct successor of this version this version has to be checked in in order to be placed in version history public version new version try version new version version clone new version predecessors get storage version create link 1 new version predecessors add this new version successors get storage version create link 1 new version labels new string 0 new version id null new version oid 0 new version state 0 return new version catch clone not supported exception x could not happen sense we clone ourselves throw new assertion failed clone not supported newversion newversion newversion getstorage createlink newversion newversion getstorage createlink newversion newversion newversion newversion newversion clonenotsupportedexception assertionfailed check in new version this method inserts in version history version created by code version new version code or code version history checkout code method public void checkin synchronized history assert that is checked out for int i 0 i predecessors size i version predecessor predecessors get i synchronized predecessor if i 0 id predecessor construct id predecessor successors add this date new date history versions add this history current this modify newversion versionhistory ischeckedout constructid make specified version predecessor of this version this method can be used to perfrom merge of two versions merging of version data should be done by application itself param predecessor version to merged with public void add predecessor version predecessor synchronized predecessor synchronized this predecessors add predecessor if is checked in predecessor successors add this addpredecessor ischeckedin get date of version creation return date when this version was created public date get date return date getdate get labels associated with this version return array of labels assigned to this version public synchronized string get labels return labels getlabels add new label to this version param label label to be associated with this version public synchronized void add label string label string new labels new string labels length 1 system arraycopy labels 0 new labels 0 labels length new labels new labels length 1 label labels new labels modify addlabel newlabels newlabels newlabels newlabels newlabels check if version has specified label param label version label public synchronized boolean has label string label for int i 0 i labels length i if labels i equals label return true return false haslabel get identifier of the version return version identifier automatically assigned by system public string get id return id getid constructor of root version all other versions should be created using code version new version code or code version history checkout code methods protected version storage storage super storage successors storage create link 1 predecessors storage create link 1 labels new string 0 date new date id 1 newversion versionhistory createlink createlink default constuctor not directly accessible private version private string construct id int suffix pos id last index of int suffix integer parse int id substring suffix pos 1 string next id suffix pos 0 integer to string suffix 1 id substring 0 suffix pos integer to string suffix 1 if successors size 0 next id successors size 1 return next id constructid suffixpos lastindexof parseint suffixpos nextid suffixpos tostring suffixpos tostring nextid nextid return the random text public string get text int length get config get text producer char length char chars get config get text producer char string int random context chars length 1 random rand new random string buffer text new string buffer for int i 0 i length i text append chars rand next int random context 1 return text to string gettext getconfig gettextproducercharlength getconfig gettextproducercharstring randomcontext stringbuffer stringbuffer nextint randomcontext tostring private boolean read only public array bucket this array bucket readonly arraybucket arraybucket public array bucket byte initdata this array bucket data initdata arraybucket arraybucket public array bucket string name data new byte 0 this name name arraybucket public output stream get output stream throws io exception if read only throw new io exception read only return new array bucket output stream outputstream getoutputstream ioexception readonly ioexception arraybucketoutputstream public input stream get input stream return new byte array input stream data inputstream getinputstream bytearrayinputstream override public string to string return new string data tostring public long size return data length public string get name return name getname private boolean has been closed false public array bucket output stream super hasbeenclosed arraybucketoutputstream override public synchronized void close throws io exception if has been closed return data super to byte array if read only throw new io exception read only fixme maybe we should throw on write instead has been closed true ioexception hasbeenclosed tobytearray readonly ioexception hasbeenclosed public boolean is read only return read only isreadonly readonly public void set read only read only true setreadonly readonly public void free data new byte 0 not much else we can do public byte to byte array long sz size int size int sz byte buf new byte size system arraycopy data 0 buf 0 size return buf tobytearray public void store to object container container container store data container store this storeto objectcontainer public void remove from object container container container delete data container delete this removefrom objectcontainer public bucket create shadow throws io exception return null createshadow ioexception private node icon node public node get icon node return icon node iconnode geticonnode iconnode public icon node node icon node node iconnode public static boolean is icon node node node return icon elem name equals node get name isiconnode elem_name getname private final static string mime type mime type public void set mime type string value get icon node set node mime type value mime_type mimetype setmimetype geticonnode setnode mime_type public string get mime type return get icon node get node value mime type getmimetype geticonnode getnodevalue mime_type private final static string width width public void set width string value get icon node set node width value setwidth geticonnode setnode public string get width return get icon node get node value width getwidth geticonnode getnodevalue private final static string height height public void set height string value get icon node set node height value setheight geticonnode setnode public string get height return get icon node get node value height getheight geticonnode getnodevalue private final static string depth depth public void set depth string value get icon node set node depth value setdepth geticonnode setnode public string get depth return get icon node get node value depth getdepth geticonnode getnodevalue private final static string url url public void seturl string value get icon node set node url value geticonnode setnode public string geturl return get icon node get node value url geticonnode getnodevalue private final boolean auto register public proxy user alert user alert manager uam boolean auto register this uam uam this auto register auto register autoregister proxyuseralert useralertmanager autoregister autoregister autoregister public void set alert user alert a user alert old alert alert a if auto register if old null alert null uam register this if auto register if alert null uam unregister this setalert useralert useralert autoregister autoregister public boolean user can dismiss return alert user can dismiss usercandismiss usercandismiss public string get title return alert get title gettitle gettitle public string get text return alert get text gettext gettext public html node gethtml text return alert gethtml text htmlnode gethtmltext gethtmltext public short get priority class return alert get priority class getpriorityclass getpriorityclass public boolean is valid return alert null alert is valid isvalid isvalid public void is valid boolean validity if alert null alert is valid validity isvalid isvalid public string dismiss button text return alert dismiss button text dismissbuttontext dismissbuttontext public boolean should unregister on dismiss return alert should unregister on dismiss shouldunregisterondismiss shouldunregisterondismiss public void on dismiss if alert null alert on dismiss ondismiss ondismiss inherit doc public object get user identifier return alert get user identifier inheritdoc getuseridentifier getuseridentifier public string anchor return anchor integer to string hash code tostring hashcode public string get short text return alert get short text getshorttext getshorttext public boolean is event notification if alert null return false return alert is event notification iseventnotification iseventnotification construct a whole image filter public whole image filter wholeimagefilter wholeimagefilter public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster original space new rectangle 0 0 width height transformed space new rectangle 0 0 width height transform space transformed space if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster transformed space width transformed space height dstcm is alpha premultiplied null writable raster dst raster dst get raster int in pixels getrgb src 0 0 width height null in pixels filter pixels width height in pixels transformed space setrgb dst 0 0 transformed space width transformed space height in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster originalspace transformedspace transformspace transformedspace colormodel getcolormodel bufferedimage createcompatiblewritableraster transformedspace transformedspace isalphapremultiplied writableraster dstraster getraster inpixels inpixels filterpixels inpixels transformedspace transformedspace transformedspace inpixels calculate output bounds for given input bounds param rect input and output rectangle protected void transform space rectangle rect transformspace actually filter the pixels param width the image width param height the image height param in pixels the image pixels param transformed space the output bounds return the output pixels inpixels transformedspace public modify config simple field set fs this fs fs this identifier fs get identifier fs remove value identifier modifyconfig simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied modify config requires full access identifier false config config node config sub config sc config get configs boolean logminor logger should log logger minor this for int i 0 i sc length i option o sc i get options string prefix sc i get prefix string config name for int j 0 j o length j config name o j get name if logminor logger minor this setting prefix config name we ignore unreconized parameters if fs get prefix config name null if o j get value string equals fs get prefix config name if logminor logger minor this setting prefix config name to fs get prefix config name try o j set value fs get prefix config name catch exception e bad values silently fail from an fcp perspective but the fcp client can tell if a change took by comparing config data messages before and after logger error this caught e e node client core store config handler output handler queue new config data node true false false false false false false false identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied modifyconfig subconfig getconfigs shouldlog getoptions getprefix configname configname getname configname configname getvaluestring configname configname configname setvalue configname configdata clientcore storeconfig outputhandler configdata override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog override public object clone try return super clone catch clone not supported exception e throw new error yes it is clonenotsupportedexception parse a block of bytes into a metadata structure constructor method because of need to catch impossible exceptions throws metadata parse exception if the metadata is invalid public static metadata construct byte data throws metadata parse exception try return new metadata data catch io exception e metadata parse exception e1 new metadata parse exception caught e e1 init cause e throw e1 metadataparseexception metadataparseexception ioexception metadataparseexception metadataparseexception initcause parse a bucket of data into a metadata structure throws metadata parse exception if the parsing failed because of invalid metadata throws io exception if we could not read the metadata from the bucket public static metadata construct bucket data throws metadata parse exception io exception input stream is data get input stream buffered input stream bis new buffered input stream is 4096 metadata m try data input stream dis new data input stream bis m new metadata dis data size finally is close return m metadataparseexception ioexception metadataparseexception ioexception inputstream getinputstream bufferedinputstream bufferedinputstream datainputstream datainputstream parse some metadata from a byte throws io exception if the data is incomplete or something wierd happens throws metadata parse exception private metadata byte data throws io exception metadata parse exception this new data input stream new byte array input stream data data length ioexception metadataparseexception ioexception metadataparseexception datainputstream bytearrayinputstream override public int hash code return hash code hashcode hashcode parse some metadata from a data input stream throws io exception if an i o error occurs or the data is incomplete public metadata data input stream dis long length throws io exception metadata parse exception hash code super hash code long magic dis read long if magic freenet metadata magic throw new metadata parse exception invalid magic magic short version dis read short if version 0 throw new metadata parse exception unsupported version version document type dis read byte if document type 0 document type 5 throw new metadata parse exception unsupported document type document type if logminor logger minor this document type document type boolean compressed false if have flags short flags dis read short splitfile flags flags splitfile flags splitfile dbr flags flags dbr flags dbr nomime flags flags no mime flags no mime compressedmime flags flags compressed mime flags compressed mime extra metadata flags flags extra metadata flags extra metadata full keys flags flags full keys flags full keys compressed flags flags compressed flags compressed if document type archive manifest if logminor logger minor this archive manifest archive type archive type get archive type dis read short if archive type null throw new metadata parse exception unrecognized archive type archive type if splitfile if logminor logger minor this splitfile data length dis read long if data length 1 throw new metadata parse exception invalid real content length data length if data length 1 if splitfile throw new metadata parse exception splitfile must have a real length if compressed compression codec compressor type get compressor by metadataid dis read short if compression codec null throw new metadata parse exception unrecognized splitfile compression codec compression codec decompressed length dis read long if nomime mime type null if logminor logger minor this nomime enabled else if compressedmime if logminor logger minor this compressed mime short x dis read short compressedmime value short x 32767 chop off last bit has compressedmime params compressedmime value 32768 32768 if has compressedmime params compressedmime params dis read short if compressedmime params 0 throw new metadata parse exception unrecognized mime params id not yet implemented mime type defaultmime types by number x else read an actual raw mime type byte l dis read byte int len l 0xff positive byte to read new byte len dis read fully to read use utf 8 for everything for simplicity mime type new string to read utf 8 if logminor logger minor this raw mime if logminor logger minor this mime mime type if dbr throw new metadata parse exception do not support db rs pending decision on putting them in the key if extra metadata int number of extra fields dis read short 0xffff for int i 0 i number of extra fields i short type dis read short int len dis read byte 0xff byte buf new byte len dis read fully buf logger normal this ignoring type type extra client metadata field of len bytes extra metadata false can t parse can t write client metadata new client metadata mime type if splitfile document type simple redirect document type archive manifest simple redirect key read key dis else if splitfile splitfile algorithm dis read short if splitfile algorithm splitfile nonredundant splitfile algorithm splitfile onion standard throw new metadata parse exception unknown splitfile algorithm splitfile algorithm if splitfile algorithm splitfile nonredundant throw new metadata parse exception non redundant splitfile invalid int params length dis read int if params length max splitfile params length throw new metadata parse exception too many bytes of splitfile parameters params length if params length 0 splitfile params new byte params length dis read fully splitfile params else if params length 0 throw new metadata parse exception invalid splitfile params length params length splitfile blocks dis read int 64tb file size limit if splitfile blocks 0 throw new metadata parse exception invalid number of blocks splitfile blocks if splitfile blocks max splitfile blocks throw new metadata parse exception too many splitfile blocks soft limit to prevent memory dos splitfile blocks splitfile check blocks dis read int if splitfile check blocks 0 throw new metadata parse exception invalid number of check blocks splitfile check blocks if splitfile check blocks max splitfile blocks throw new metadata parse exception too many splitfile check blocks soft limit to prevent memory dos splitfile check blocks splitfile data keys new clientchk splitfile blocks splitfile check keys new clientchk splitfile check blocks for int i 0 i splitfile data keys length i if splitfile data keys i readchk dis null throw new metadata parse exception null data key i for int i 0 i splitfile check keys length i if splitfile check keys i readchk dis null throw new metadata parse exception null check key i if document type simple manifest int manifest entry count dis read int if manifest entry count 0 throw new metadata parse exception invalid manifest entry count manifest entry count manifest entries new hash map string metadata parse the sub manifest if logminor logger minor this simple manifest manifest entry count entries for int i 0 i manifest entry count i short name length dis read short byte buf new byte name length dis read fully buf string name new string buf utf 8 intern if logminor logger minor this entry i name name short len dis read short if len 0 throw new metadata parse exception invalid manifest entry size len if len length throw new metadata parse exception impossibly long manifest entry len metadata size length byte data new byte len dis read fully data try metadata m metadata construct data manifest entries put name m catch throwable t logger error this could not parse sub manifest t t if logminor logger minor this end of manifest make it easy to search for it if document type archive internal redirect document type archive metadata redirect int len dis read short if logminor logger minor this reading archive internal redirect length len byte buf new byte len dis read fully buf name in archive new string buf utf 8 if logminor logger minor this archive internal redirect name in archive len datainputstream ioexception datainputstream ioexception metadataparseexception hashcode hashcode readlong freenet_metadata_magic metadataparseexception readshort metadataparseexception documenttype readbyte documenttype documenttype metadataparseexception documenttype documenttype haveflags readshort flags_splitfile flags_splitfile flags_dbr flags_dbr flags_no_mime flags_no_mime flags_compressed_mime flags_compressed_mime extrametadata flags_extra_metadata flags_extra_metadata fullkeys flags_full_keys flags_full_keys flags_compressed flags_compressed documenttype archive_manifest archivetype archive_type getarchivetype readshort archivetype metadataparseexception archivetype datalength readlong datalength metadataparseexception datalength datalength metadataparseexception compressioncodec compressor_type getcompressorbymetadataid readshort compressioncodec metadataparseexception compressioncodec decompressedlength readlong mimetype readshort compressedmimevalue hascompressedmimeparams compressedmimevalue hascompressedmimeparams compressedmimeparams readshort compressedmimeparams metadataparseexception mimetype defaultmimetypes bynumber readbyte toread readfully toread mimetype toread mimetype metadataparseexception dbrs extrametadata numberofextrafields readshort numberofextrafields readshort readbyte readfully extrametadata clientmetadata clientmetadata mimetype documenttype simple_redirect documenttype archive_manifest simpleredirectkey readkey splitfilealgorithm readshort splitfilealgorithm splitfile_nonredundant splitfilealgorithm splitfile_onion_standard metadataparseexception splitfilealgorithm splitfilealgorithm splitfile_nonredundant metadataparseexception paramslength readint paramslength max_splitfile_params_length metadataparseexception paramslength paramslength splitfileparams paramslength readfully splitfileparams paramslength metadataparseexception paramslength splitfileblocks readint splitfileblocks metadataparseexception splitfileblocks splitfileblocks max_splitfile_blocks metadataparseexception splitfileblocks splitfilecheckblocks readint splitfilecheckblocks metadataparseexception splitfilecheckblocks splitfilecheckblocks max_splitfile_blocks metadataparseexception splitfilecheckblocks splitfiledatakeys splitfileblocks splitfilecheckkeys splitfilecheckblocks splitfiledatakeys splitfiledatakeys metadataparseexception splitfilecheckkeys splitfilecheckkeys metadataparseexception documenttype simple_manifest manifestentrycount readint manifestentrycount metadataparseexception manifestentrycount manifestentries hashmap manifestentrycount manifestentrycount namelength readshort namelength readfully readshort metadataparseexception metadataparseexception readfully manifestentries documenttype archive_internal_redirect documenttype archive_metadata_redirect readshort readfully nameinarchive nameinarchive create an empty metadata object private metadata hash code super hash code should be followed by add redirection manifest hashcode hashcode addredirectionmanifest create a metadata object and add data for redirection to it param dir a map of names string to either files same string or directories more hash map s throws malformedurl exception one of the uri s were malformed private void add redirection manifest hash map string object dir throws malformedurl exception simple manifest contains actual redirects not archive manifest which is basically a redirect document type simple manifest nomime true mime type null client metadata new client metadata null manifest entries new hash map string metadata int count 0 for iterator entry string object i dir entry set iterator i has next map entry string object entry i next string key entry get key intern count object o entry get value metadata target if o instanceof string external redirect freeneturi uri new freeneturi string o target new metadata simple redirect null null uri null else if o instanceof hash map target new metadata target add redirection manifest hash map string object o else throw new illegal argument exception not string nor hash map o manifest entries put key target hashmap malformedurlexception addredirectionmanifest hashmap malformedurlexception documenttype simple_manifest mimetype clientmetadata clientmetadata manifestentries hashmap entryset hasnext getkey getvalue simple_redirect hashmap addredirectionmanifest hashmap illegalargumentexception hashmap manifestentries create a metadata object and add data for redirection to it param dir a map of names string to either files same string or directories more hash map s throws malformedurl exception one of the uri s were malformed public static metadata mk redirection manifest hash map string object dir throws malformedurl exception metadata ret new metadata ret add redirection manifest dir return ret hashmap malformedurlexception mkredirectionmanifest hashmap malformedurlexception addredirectionmanifest create a metadata object and add manifest entries from the given map the map can contain either string metadata or string map the latter indicating subdirs public static metadata mk redirection manifest with metadata hash map string object dir metadata ret new metadata ret add redirection manifest with metadata dir return ret mkredirectionmanifestwithmetadata hashmap addredirectionmanifestwithmetadata private void add redirection manifest with metadata hash map string object dir simple manifest contains actual redirects not archive manifest which is basically a redirect document type simple manifest nomime true mime type null client metadata new client metadata null manifest entries new hash map string metadata int count 0 for iterator string i dir key set iterator i has next string key i next intern if key index of 1 throw new illegal argument exception slashes in simple redirect manifest filenames slashes denote sub manifests key count object o dir get key if o instanceof metadata metadata data metadata dir get key if data null throw new null pointer exception if logger should log logger debug this logger debug this putting metadata for key manifest entries put key data else if o instanceof hash map hash map string object hm hash map string object o if logger should log logger debug this logger debug this making metadata map for key metadata sub map mk redirection manifest with metadata hm manifest entries put key sub map if logger should log logger debug this logger debug this putting metadata map for key addredirectionmanifestwithmetadata hashmap documenttype simple_manifest mimetype clientmetadata clientmetadata manifestentries hashmap keyset hasnext indexof illegalargumentexception nullpointerexception shouldlog manifestentries hashmap hashmap hashmap shouldlog submap mkredirectionmanifestwithmetadata manifestentries submap shouldlog create a metadata object for an archive which does not have its own metadata param dir a map of names string to either files same string or directories more hash map s metadata hash map string object dir string prefix hash code super hash code simple manifest contains actual redirects not archive manifest which is basically a redirect document type simple manifest nomime true mime type null client metadata new client metadata manifest entries new hash map string metadata int count 0 for iterator string i dir key set iterator i has next string key i next intern count object o dir get key metadata target if o instanceof string archive internal redirect target new metadata archive internal redirect null null prefix key new client metadata defaultmime types guessmime type key false else if o instanceof hash map target new metadata hash map string object o prefix key else throw new illegal argument exception not string nor hash map o manifest entries put key target hashmap hashmap hashcode hashcode documenttype simple_manifest mimetype clientmetadata clientmetadata manifestentries hashmap keyset hasnext archive_internal_redirect clientmetadata defaultmimetypes guessmimetype hashmap hashmap illegalargumentexception hashmap manifestentries create a really simple metadata object param doc type the document type must be something that takes a single argument at the moment this means archive internal redirect param arg the argument in the case of archive internal redirect the filename in the archive to read from public metadata byte doc type archive type archive type compressor type compression codec string arg client metadata cm hash code super hash code if doc type archive internal redirect document type doc type this archive type archive type determine mime type this client metadata cm this compression codec compression codec if cm null this setmime type cm getmime type name in archive arg else throw new illegal argument exception doctype archive_internal_redirect archive_internal_redirect doctype archive_type archivetype compressor_type compressioncodec clientmetadata hashcode hashcode doctype archive_internal_redirect documenttype doctype archivetype archivetype clientmetadata compressioncodec compressioncodec setmimetype getmimetype nameinarchive illegalargumentexception create a metadata redircet object that points to resolved metadata inside container doc type archive metadata redirect param name the filename in the archive to read from must be metadata n scheme private metadata byte doc type string name hash code super hash code nomime true if doc type archive metadata redirect document type doc type name in archive name else throw new illegal argument exception doctype archive_metadata_redirect doctype hashcode hashcode doctype archive_metadata_redirect documenttype doctype nameinarchive illegalargumentexception create another kind of simple metadata object a redirect or similar object param doc type the document type param uri the uri pointed to param cm the client metadata if any public metadata byte doc type archive type archive type compressor type compression codec freeneturi uri client metadata cm hash code super hash code if doc type simple redirect doc type archive manifest document type doc type this archive type archive type this compression codec compression codec client metadata cm if cm null cm is trivial setmime type cm getmime type else setmime type defaultmime types default mime type nomime true if uri null throw new null pointer exception simple redirect key uri if uri get key type equals chk uri has meta strings full keys true else throw new illegal argument exception doctype doctype archive_type archivetype compressor_type compressioncodec clientmetadata hashcode hashcode doctype simple_redirect doctype archive_manifest documenttype doctype archivetype archivetype compressioncodec compressioncodec clientmetadata istrivial setmimetype getmimetype setmimetype defaultmimetypes default_mime_type nullpointerexception simpleredirectkey getkeytype hasmetastrings fullkeys illegalargumentexception public metadata short algo clientchk dataur is clientchk checkur is int segment size int check segment size client metadata cm long data length archive type archive type compressor type compression codec long decompressed length boolean is metadata hash code super hash code if is metadata document type multi level metadata else if archive type null document type archive manifest this archive type archive type else document type simple redirect splitfile true splitfile algorithm algo this data length data length this compression codec compression codec splitfile blocks dataur is length splitfile check blocks checkur is length splitfile data keys dataur is assert keys valid splitfile data keys splitfile check keys checkur is assert keys valid splitfile check keys client metadata cm this compression codec compression codec this decompressed length decompressed length if cm null setmime type cm getmime type else setmime type defaultmime types default mime type splitfile params fields ints to bytes new int segment size check segment size datauris checkuris segmentsize checksegmentsize clientmetadata datalength archive_type archivetype compressor_type compressioncodec decompressedlength ismetadata hashcode hashcode ismetadata documenttype multi_level_metadata archivetype documenttype archive_manifest archivetype archivetype documenttype simple_redirect splitfilealgorithm datalength datalength compressioncodec compressioncodec splitfileblocks datauris splitfilecheckblocks checkuris splitfiledatakeys datauris keysvalid splitfiledatakeys splitfilecheckkeys checkuris keysvalid splitfilecheckkeys clientmetadata compressioncodec compressioncodec decompressedlength decompressedlength setmimetype getmimetype setmimetype defaultmimetypes default_mime_type splitfileparams intstobytes segmentsize checksegmentsize private boolean keys valid clientchk keys for int i 0 i keys length i if keys i get nodechk get routing key null return false return true keysvalid getnodechk getroutingkey set the mime type to a string compresses it if possible for transit private void setmime type string type nomime false short s defaultmime types by name type if s 0 compressedmime true compressedmime value s else compressedmime false mime type type setmimetype defaultmimetypes byname compressedmimevalue mimetype write the data to a byte array throws metadata unresolved exception public byte write to byte array throws metadata unresolved exception byte array output stream baos new byte array output stream data output stream dos new data output stream baos try write to dos catch io exception e throw new error could not write to byte array e e return baos to byte array metadataunresolvedexception writetobytearray metadataunresolvedexception bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream writeto ioexception tobytearray private clientchk readchk data input stream dis throws io exception metadata parse exception if full keys throw new metadata parse exception full keys not supported on a splitfile return clientchk read raw binary key dis datainputstream ioexception metadataparseexception fullkeys metadataparseexception fullkeys readrawbinarykey read a key using the current settings throws io exception throws malformedurl exception if the key could not be read due to an error in parsing the key redflag may want to recover from these in future hence the short length private freeneturi read key data input stream dis throws io exception read url if full keys return freeneturi read full binary key with length dis else return clientchk read raw binary key dis geturi ioexception malformedurlexception readkey datainputstream ioexception fullkeys readfullbinarykeywithlength readrawbinarykey write a key using the current settings throws io exception throws malformedurl exception if an error in the key itself prevented it from being written private void write key data output stream dos freeneturi freeneturi throws io exception if full keys freeneturi write full binary key with length dos else string meta freeneturi get all meta strings if meta null meta length 0 throw new malformedurl exception not a plain chk base client key key base client key get base key freeneturi if key instanceof clientchk clientchk key write raw binary key dos else throw new illegal argument exception full keys must be enabled to write non ch ks ioexception malformedurlexception writekey dataoutputstream ioexception fullkeys writefullbinarykeywithlength getallmetastrings malformedurlexception baseclientkey baseclientkey getbasekey writerawbinarykey illegalargumentexception chks private void writechk data output stream dos clientchk chk throws io exception if full keys throw new unsupported operation exception full keys not supported on splitfiles else chk write raw binary key dos dataoutputstream ioexception fullkeys unsupportedoperationexception writerawbinarykey is a manifest public boolean is simple manifest return document type simple manifest issimplemanifest documenttype simple_manifest get the sub document in a manifest file with the given name throws metadata parse exception public metadata get document string name return manifest entries get name metadataparseexception getdocument manifestentries return and remove a specific document used in persistent requests so that when remove from is called the default document won t be removed since it is being processed public metadata grab document string name return manifest entries remove name removefrom grabdocument manifestentries the default document is the one which has an empty name throws metadata parse exception public metadata get default document throws metadata parse exception return get document metadataparseexception getdefaultdocument metadataparseexception getdocument return and remove the default document used in persistent requests so that when remove from is called the default document won t be removed since it is being processed public metadata grab default document return grab document removefrom grabdefaultdocument grabdocument get all documents in the manifest ignores default doc throws metadata parse exception public hash map string metadata get documents hash map string metadata docs new hash map string metadata set string s manifest entries key set iterator string i s iterator while i has next string st i next if st length 1 docs put st manifest entries get st return docs metadataparseexception hashmap getdocuments hashmap hashmap manifestentries keyset hasnext manifestentries does the metadata point to a single uri public boolean is single file redirect return splitfile document type simple redirect document type multi level metadata document type archive manifest issinglefileredirect documenttype simple_redirect documenttype multi_level_metadata documenttype archive_manifest return the single target of this uri public freeneturi get single target return simple redirect key getsingletarget simpleredirectkey is this a archive manifest public boolean is archive manifest return document type archive manifest isarchivemanifest documenttype archive_manifest is this a archive internal metadata redirect return public boolean is archive metadata redirect return document type archive metadata redirect isarchivemetadataredirect documenttype archive_metadata_redirect is this a archive internal redirect return public boolean is archive internal redirect return document type archive internal redirect isarchiveinternalredirect documenttype archive_internal_redirect return the name of the document referred to in the archive if this is a archive internal redirect public string get archive internal name return name in archive getarchiveinternalname nameinarchive return the client metadata mime type etc public client metadata get client metadata return client metadata clientmetadata getclientmetadata clientmetadata is this a splitfile manifest public boolean is splitfile return splitfile issplitfile is this a simple splitfile public boolean is simple splitfile return splitfile document type simple redirect issimplesplitfile documenttype simple_redirect is multi level indirect metadata public boolean is multi level metadata return document type multi level metadata ismultilevelmetadata documenttype multi_level_metadata what kind of archive is it public archive type get archive type return archive type archive_type getarchivetype archivetype change the document type to a simple redirect used by the archive code to fetch split archive manifests public void set simple redirect document type simple redirect setsimpleredirect documenttype simple_redirect write the metadata as binary throws io exception if an i o error occurred while writing the data throws metadata unresolved exception public void write to data output stream dos throws io exception metadata unresolved exception dos write long freenet metadata magic dos write short 0 version dos write byte document type if have flags short flags 0 if splitfile flags flags splitfile if dbr flags flags dbr if nomime flags flags no mime if compressedmime flags flags compressed mime if extra metadata flags flags extra metadata if full keys flags flags full keys if compression codec null flags flags compressed dos write short flags if document type archive manifest short code archive type metadataid dos write short code if splitfile dos write long data length if compression codec null dos write short compression codec metadataid dos write long decompressed length if nomime if compressedmime int x compressedmime value if has compressedmime params x 32768 dos write short short x if has compressedmime params dos write short compressedmime params else byte data mime type get bytes utf 8 if data length 255 throw new error mime type too long data length bytes mime type dos write byte byte data length dos write data if dbr throw new unsupported operation exception no dbr support yet if extra metadata throw new unsupported operation exception no extra metadata support yet if splitfile document type simple redirect document type archive manifest write key dos simple redirect key else if splitfile dos write short splitfile algorithm if splitfile params null dos write int splitfile params length dos write splitfile params else dos write int 0 dos write int splitfile blocks dos write int splitfile check blocks for int i 0 i splitfile blocks i writechk dos splitfile data keys i for int i 0 i splitfile check blocks i writechk dos splitfile check keys i if document type simple manifest dos write int manifest entries size boolean kill false linked list metadata unresolved metadata null for iterator string i manifest entries key set iterator i has next string name i next byte name data name get bytes utf 8 if name data length short max value throw new illegal argument exception manifest name too long dos write short name data length dos write name data metadata meta manifest entries get name try byte data meta write to byte array if data length max size in manifest freeneturi uri meta resolveduri string n meta resolved name if uri null meta new metadata simple redirect null null uri null data meta write to byte array else if n null meta new metadata archive metadata redirect n data meta write to byte array else kill true if unresolved metadata null unresolved metadata new linked list metadata unresolved metadata add last meta dos write short data length dos write data catch metadata unresolved exception e metadata m e must resolve if unresolved metadata null unresolved metadata new linked list metadata for int j 0 j m length j unresolved metadata add first m j kill true if kill metadata meta unresolved metadata to array new metadata unresolved metadata size throw new metadata unresolved exception meta manifest data too long and not resolved if document type archive internal redirect document type archive metadata redirect byte data name in archive get bytes utf 8 if data length short max value throw new illegal argument exception archive internal redirect name too long dos write short data length dos write data ioexception metadataunresolvedexception writeto dataoutputstream ioexception metadataunresolvedexception writelong freenet_metadata_magic writeshort writebyte documenttype haveflags flags_splitfile flags_dbr flags_no_mime flags_compressed_mime extrametadata flags_extra_metadata fullkeys flags_full_keys compressioncodec flags_compressed writeshort documenttype archive_manifest archivetype writeshort writelong datalength compressioncodec writeshort compressioncodec writelong decompressedlength compressedmimevalue hascompressedmimeparams writeshort hascompressedmimeparams writeshort compressedmimeparams mimetype getbytes mimetype writebyte unsupportedoperationexception extrametadata unsupportedoperationexception documenttype simple_redirect documenttype archive_manifest writekey simpleredirectkey writeshort splitfilealgorithm splitfileparams writeint splitfileparams splitfileparams writeint writeint splitfileblocks writeint splitfilecheckblocks splitfileblocks splitfiledatakeys splitfilecheckblocks splitfilecheckkeys documenttype simple_manifest writeint manifestentries linkedlist unresolvedmetadata manifestentries keyset hasnext namedata getbytes namedata max_value illegalargumentexception writeshort namedata namedata manifestentries writetobytearray max_size_in_manifest resolvedname simple_redirect writetobytearray archive_metadata_redirect writetobytearray unresolvedmetadata unresolvedmetadata linkedlist unresolvedmetadata addlast writeshort metadataunresolvedexception mustresolve unresolvedmetadata unresolvedmetadata linkedlist unresolvedmetadata addfirst unresolvedmetadata toarray unresolvedmetadata metadataunresolvedexception documenttype archive_internal_redirect documenttype archive_metadata_redirect nameinarchive getbytes max_value illegalargumentexception writeshort have this metadata flags public boolean have flags return document type simple redirect document type multi level metadata document type archive manifest document type archive internal redirect document type archive metadata redirect haveflags documenttype simple_redirect documenttype multi_level_metadata documenttype archive_manifest documenttype archive_internal_redirect documenttype archive_metadata_redirect get the splitfile type public short get splitfile type return splitfile algorithm getsplitfiletype splitfilealgorithm public clientchk get splitfile data keys return splitfile data keys getsplitfiledatakeys splitfiledatakeys public clientchk get splitfile check keys return splitfile check keys getsplitfilecheckkeys splitfilecheckkeys public boolean is compressed return compression codec null iscompressed compressioncodec public compressor type get compression codec return compression codec compressor_type getcompressioncodec compressioncodec public long data length return data length datalength datalength public byte splitfile params return splitfile params splitfileparams splitfileparams public long uncompressed data length return this decompressed length uncompresseddatalength decompressedlength public freeneturi get resolveduri return resolveduri getresolveduri public void resolve freeneturi uri this resolveduri uri public void resolve string name this resolved name name resolvedname public bucket to bucket bucket factory bf throws metadata unresolved exception io exception byte buf write to byte array return bucket tools make immutable bucket bf buf tobucket bucketfactory metadataunresolvedexception ioexception writetobytearray buckettools makeimmutablebucket public boolean is resolved return resolveduri null resolved name null isresolved resolvedname public void set archive manifest archive type type archive type get archive type client metadata getmime type archive type type compression codec null client metadata clear document type archive manifest setarchivemanifest archive_type archive_type getarchivetype clientmetadata getmimetype archivetype compressioncodec clientmetadata documenttype archive_manifest public string getmime type if client metadata null return null return client metadata getmime type getmimetype clientmetadata clientmetadata getmimetype public void remove from object container container if resolveduri null container activate resolveduri 5 resolveduri remove from container if simple redirect key null container activate simple redirect key 5 simple redirect key remove from container if splitfile data keys null for clientchk key splitfile data keys if key null container activate key 5 key remove from container if splitfile check keys null for clientchk key splitfile check keys if key null container activate key 5 key remove from container if manifest entries null container activate manifest entries 2 for object m manifest entries values metadata meta metadata m container activate meta 1 meta remove from container container delete manifest entries if client metadata null container activate client metadata 1 client metadata remove from container container delete this removefrom objectcontainer removefrom simpleredirectkey simpleredirectkey simpleredirectkey removefrom splitfiledatakeys splitfiledatakeys removefrom splitfilecheckkeys splitfilecheckkeys removefrom manifestentries manifestentries manifestentries removefrom manifestentries clientmetadata clientmetadata clientmetadata removefrom public void clear splitfile keys splitfile data keys null splitfile check keys null clearsplitfilekeys splitfiledatakeys splitfilecheckkeys private float hsb new float 3 public hsb adjust filter this 0 0 0 hsbadjustfilter public hsb adjust filter float r float g float b h factor r s factor g b factor b can filter index color model true hsbadjustfilter hfactor sfactor bfactor canfilterindexcolormodel public void seth factor float h factor this h factor h factor sethfactor hfactor hfactor hfactor public float geth factor return h factor gethfactor hfactor public void sets factor float s factor this s factor s factor setsfactor sfactor sfactor sfactor public float gets factor return s factor getsfactor sfactor public void setb factor float b factor this b factor b factor setbfactor bfactor bfactor bfactor public float getb factor return b factor getbfactor bfactor override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff color rg btohsb r g b hsb hsb 0 h factor while hsb 0 0 hsb 0 math pi 2 hsb 1 s factor if hsb 1 0 hsb 1 0 else if hsb 1 1 0 hsb 1 1 0f hsb 2 b factor if hsb 2 0 hsb 2 0 else if hsb 2 1 0 hsb 2 1 0f rgb color hs btorgb hsb 0 hsb 1 hsb 2 return a rgb 0xffffff rgbtohsb hfactor sfactor bfactor hsbtorgb override public string to string return colors adjust hsb tostring for construction of a puzzle which is meant to be inserted param new type param new data public own introduction puzzle own identity new inserter puzzle type new type string new mime type byte new data string new solution date new date of insertion int my index super new inserter uuid randomuuid to string new inserter getid new type new mime type new data new date of insertion get time introduction server puzzle invalid after days 24 60 60 1000 new date of insertion my index if new solution length minimal solution length throw new illegal argument exception solution is too short new solution length minimal length is minimal solution length m solver null m solution new solution if check consistency false throw new illegal argument exception trying to costruct a corrupted puzzle newtype newdata ownintroductionpuzzle ownidentity newinserter puzzletype newtype newmimetype newdata newsolution newdateofinsertion myindex newinserter tostring newinserter newtype newmimetype newdata newdateofinsertion gettime introductionserver puzzle_invalid_after_days newdateofinsertion myindex newsolution minimal_solution_length illegalargumentexception newsolution minimal_solution_length msolver msolution newsolution checkconsistency illegalargumentexception get the uri at which to insert this puzzle ssk asdfasdf wot introduction yyyy mm dd index of the puzzle public freeneturi get inserturi assert m was inserted false m was solved false string day of insertion synchronized m date format day of insertion m date format format get date of insertion freeneturi baseuri own identity get inserter get inserturi set key type ssk baseuri baseuri set doc name wot wot name introduction context day of insertion get index return baseuri set meta string null getinserturi mwasinserted mwassolved dayofinsertion mdateformat dayofinsertion mdateformat getdateofinsertion ownidentity getinserter getinserturi setkeytype setdocname wot_name introduction_context dayofinsertion getindex setmetastring used by the introduction server to mark a puzzle as solved so it will not try to fetch solutions for it anymore public synchronized void set solved if m was solved throw new runtime exception the puzzle was already solved by m solver m was solved true introductionserver setsolved mwassolved runtimeexception msolver mwassolved public class mock input stream extends input stream public mock input stream mockinputstream inputstream mockinputstream override public int read return 1 override public int read byte data int offset int len return len final static int code 0x0a public int get code return code getcode public string get description return sending to network getdescription public final class welcome extends web page impl public welcome web interface my web interface ft own identity viewer http request request super my web interface viewer request todo auto generated constructor stub webpageimpl webinterface mywebinterface ftownidentity httprequest mywebinterface public final void make make welcome box make overview box makewelcomebox makeoverviewbox private final void make welcome box html node welcome box add content box welcome welcome box add child p important note all messages you post with the current freetalk release are considered as testing messages and will not be readable by the first stable release this is necessary so that we could change internal stuff completely if there is a need to do so html node p welcome box add child p you can use freetalk via the webinterface p add child strike or with a newsreader connected to localhost port 1199 p add child unfortunately the newsreader interface seems to have a bug which makes it cause 100 cpu usage when it is not even being used until we find the time to debug it it is disabled welcome box add child p for the newsreader as the account name specify the nickname of an own identity and as the e mail address specify the freetalk address you can look it up on the identities page a password is not required makewelcomebox htmlnode welcomebox addcontentbox welcomebox addchild htmlnode welcomebox addchild addchild addchild welcomebox addchild private final void make overview box html node overview box add content box overview html node list overview box add child ul list add child new html node li known identities m freetalk get identity manager count known identities list add child new html node li messages waiting to be sent m freetalk get message manager count unsent messages makeoverviewbox htmlnode overviewbox addcontentbox htmlnode overviewbox addchild addchild htmlnode mfreetalk getidentitymanager countknownidentities addchild htmlnode mfreetalk getmessagemanager countunsentmessages create a new http request for the given uri and parse its request parameters param uri the uri being requested public http request impl uri uri this uri uri this parse request parameters uri get raw query true false this data null this parts null this bucketfactory null httprequest httprequestimpl parserequestparameters getrawquery creates a new http request for the given path and url encoded query string param path i e test test html param encoded query string a some text b abc 40def de throws uri syntax exception if the uri is invalid public http request impl string path string encoded query string throws uri syntax exception this data null this parts null this bucketfactory null if encoded query string null encoded query string length 0 this uri new uri path encoded query string else this uri new uri path this parse request parameters uri get raw query true false httprequest encodedquerystring urisyntaxexception httprequestimpl encodedquerystring urisyntaxexception encodedquerystring encodedquerystring encodedquerystring parserequestparameters getrawquery creates a new http request for the given uri and data param uri the uri being requested param h client headers param d the data param ctx the toadlet context for headers and bucket factory throws uri syntax exception if the uri is invalid public http request impl uri uri bucket d toadlet context ctx this uri uri this headers ctx get headers this parse request parameters uri get raw query true false this data d this parts new hash map string bucket this bucketfactory ctx get bucket factory if data null try this parse multi part data catch io exception ioe logger error this temporary files error could not parse ioe ioe httprequest urisyntaxexception httprequestimpl toadletcontext getheaders parserequestparameters getrawquery hashmap getbucketfactory parsemultipartdata ioexception see freenet clients http http request get path public string get path return this uri get path httprequest getpath getpath getpath see freenet clients http http request has parameters public boolean has parameters return this parameter name values map is empty httprequest hasparameters hasparameters parameternamevaluesmap isempty parse the query string and populate link parameter name values map with the lists of values for each parameter if this method is not called at all all other methods would be useless because they rely on the parameter map to be filled param query string the query string in its raw form not yet url decoded param do url decoding todo private void parse request parameters string query string boolean do url decoding boolean as parts boolean logminor logger should log logger minor this if logminor logger minor this query string is query string do url decoding do url decoding nothing to do if there was no query string in the uri if query string null query string length 0 return iterate over all tokens in the query string seperated by string tokenizer tokenizer new string tokenizer query string while tokenizer has more tokens string name value token tokenizer next token if logminor logger minor this token name value token a token can be either a name or a name value pair string name null string value int index of equals char name value token index of if index of equals char 0 it s only a name so the value stays emptys name name value token if logminor logger minor this name name else if index of equals char name value token length 1 it s a name with an empty value so remove the character name name value token substring 0 index of equals char if logminor logger minor this name name else it s a name value pair split into name and value name name value token substring 0 index of equals char value name value token substring index of equals char 1 if logminor logger minor this name name value value url decode the name and value if do url decoding try name url decoder decode name utf 8 value url decoder decode value utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e if logminor logger minor this decoded name name logger minor this decoded value value if as parts store as a part byte buf try buf value get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e fixme some other encoding bucket b new simple read only array bucket buf parts put name b if logminor logger minor this added as part name name value value else get the list of values for this parameter that were parsed so far list string value list this get parameter value list name add this value to the list value list add value parameternamevaluesmap querystring dourldecoding parserequestparameters querystring dourldecoding asparts shouldlog querystring querystring dourldecoding dourldecoding querystring querystring stringtokenizer stringtokenizer querystring hasmoretokens namevaluetoken nexttoken namevaluetoken indexofequalschar namevaluetoken indexof indexofequalschar namevaluetoken indexofequalschar namevaluetoken namevaluetoken indexofequalschar namevaluetoken indexofequalschar namevaluetoken indexofequalschar dourldecoding urldecoder urldecoder unsupportedencodingexception asparts getbytes unsupportedencodingexception simplereadonlyarraybucket valuelist getparametervaluelist valuelist get the first value of the parameter with the given name param name the name of the parameter to get return the first value or code null code if the parameter was not set private string get parameter value string name if this is parameter set name return null list string all values this get parameter value list name return all values get 0 getparametervalue isparameterset allvalues getparametervaluelist allvalues get the list of all values for the parameter with the given name when this method is called for a given parameter for the first time a new empty list of values is created and stored in link parameter name values map this list is returned and should be used to add parameter values if you only want to check if a parameter is set at all you must use link is parameter set string param name the name of the parameter to get return the list of all values for this parameter that were parsed so far private list string get parameter value list string name list string values this parameter name values map get name if values null values new linked list string this parameter name values map put name values return values parameternamevaluesmap isparameterset getparametervaluelist parameternamevaluesmap linkedlist parameternamevaluesmap see freenet clients http http request is parameter set java lang string public boolean is parameter set string name return this parameter name values map contains key name httprequest isparameterset isparameterset parameternamevaluesmap containskey see freenet clients http http request get param java lang string public string get param string name return this get param name httprequest getparam getparam getparam public string get param string name string default value string value this get parameter value name if value null return default value return value getparam defaultvalue getparametervalue defaultvalue see freenet clients http http request get int param java lang string public int get int param string name return this get int param name 0 httprequest getintparam getintparam getintparam public int get int param string name int default value if this is parameter set name return default value string value this get parameter value name try return integer parse int value catch number format exception e return default value getintparam defaultvalue isparameterset defaultvalue getparametervalue parseint numberformatexception defaultvalue public int get int part string name int default value if this is part set name return default value string value this get part as string name 32 try return integer parse int value catch number format exception e return default value getintpart defaultvalue ispartset defaultvalue getpartasstring parseint numberformatexception defaultvalue public string get multiple param string name list string value list this get parameter value list name string values new string value list size value list to array values return values getmultipleparam valuelist getparametervaluelist valuelist valuelist toarray public int get multiple int param string name list string value list this get parameter value list name try parsing all values and put the valid integers in a new list list integer int value list new array list integer for int i 0 i value list size i try int value list add integer value of value list get i catch exception e ignore invalid parameter values convert the valid integers to an array of ints int values new int int value list size for int i 0 i int value list size i values i int value list get i return values getmultipleintparam valuelist getparametervaluelist intvaluelist arraylist valuelist intvaluelist valueof valuelist intvaluelist intvaluelist intvaluelist parse submitted data from a bucket note that if this is application x www form urlencoded it will come out as params whereas if it is multipart form data it will be separated into buckets private void parse multi part data throws io exception input stream is null buffered input stream bis null line reading input stream lis null output stream bucketos null output stream bbos null try boolean logminor logger should log logger minor this if data null return string ctype this headers get content type if ctype null return if logminor logger minor this uploaded content type ctype string ctypeparts ctype split if ctypeparts 0 equals ignore case application x www form urlencoded completely different encoding but easy to handle if data size 1024 1024 throw new io exception too big byte buf bucket tools to byte array data string s new string buf us ascii parse request parameters s true true if ctypeparts 0 trim equals ignore case multipart form data ctypeparts length 2 return string boundary null for int i 0 i ctypeparts length i string subparts ctypeparts i split if subparts length 2 subparts 0 trim equals ignore case boundary boundary subparts 1 if boundary null boundary length 0 return if boundary char at 0 boundary boundary substring 1 if boundary char at boundary length 1 boundary boundary substring 0 boundary length 1 boundary boundary if logminor logger minor this boundary is boundary is this data get input stream bis new buffered input stream is 32768 lis new line reading input stream bis string line line lis read line 100 100 false really it s us ascii but iso 8859 1 is close enough while bis available 0 line equals boundary line lis read line 100 100 false boundary r n boundary bucket filedata null string name null string filename null string content type null while bis available 0 name null filename null content type null chomp headers while line lis read line 200 200 true should be utf 8 as we told the browser to send utf 8 null if line length 0 break string lineparts line split if lineparts null lineparts length 0 continue string hdrname lineparts 0 trim if hdrname equals ignore case content disposition if lineparts length 2 continue string valueparts lineparts 1 split for int i 0 i valueparts length i string subparts valueparts i split if subparts length 2 continue string fieldname subparts 0 trim string value subparts 1 trim if value starts with value ends with value value substring 1 value length 1 if fieldname equals ignore case name name value else if fieldname equals ignore case filename filename value else if hdrname equals ignore case content type content type lineparts 1 trim if logger should log logger minor this logger minor this parsed type content type else do nothing irrelevant header if name null continue we should be at the data now start reading it in checking for the boundary string we can only give an upper bound for the size of the bucket filedata this bucketfactory make bucket bis available bucketos filedata get output stream bbos new buffered output stream bucketos 32768 buffer characters that match the boundary so far fixme use whatever charset was used byte bbound boundary get bytes utf 8 iso 8859 1 boundary should be in us ascii int offset 0 while bis available 0 offset bbound length byte b byte bis read if b bbound offset offset else if b bbound offset offset 0 offset bytes matched but no more write the bytes that matched then the non matching byte bbos write bbound 0 offset offset 0 if b bbound 0 offset 1 else bbos write b else bbos write b bbos flush bbos close parts put name filedata if logminor logger minor this name name length filedata size filename filename if filename null uploaded files put name new http uploaded file impl filename content type filedata finally closer close bbos closer close bucketos closer close lis closer close bis closer close is parsemultipartdata ioexception inputstream bufferedinputstream linereadinginputstream outputstream outputstream shouldlog equalsignorecase ioexception buckettools tobytearray parserequestparameters equalsignorecase equalsignorecase charat charat getinputstream bufferedinputstream linereadinginputstream readline readline contenttype contenttype readline equalsignorecase startswith endswith equalsignorecase equalsignorecase equalsignorecase contenttype shouldlog contenttype makebucket getoutputstream bufferedoutputstream getbytes uploadedfiles httpuploadedfileimpl contenttype see freenet clients http http request get uploaded file java lang string public http uploaded file get uploaded file string name return uploaded files get name httprequest getuploadedfile httpuploadedfile getuploadedfile uploadedfiles see freenet clients http http request get part java lang string public bucket get part string name return this parts get name httprequest getpart getpart public boolean is part set string name if parts null return false return this parts contains key name ispartset containskey public string get part as string string name int maxlength try return new string get part as bytes name maxlength utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e getpartasstring getpartasbytes unsupportedencodingexception public byte get part as bytes string name int maxlength bucket part this parts get name if part null return new byte 0 if part size maxlength return new byte 0 input stream is null data input stream dis null try is part get input stream dis new data input stream is byte buf new byte is available dis read fully buf return buf catch io exception ioe logger error this caught ioe ioe get message finally closer close dis closer close is fixme why are we doing this dis close should close the input stream return new byte 0 getpartasbytes inputstream datainputstream getinputstream datainputstream readfully ioexception getmessage inputstream public void free parts if this parts null return for bucket b this parts values b free parts clear do not free data caller is responsible for that freeparts public long get long param string name long default value if this is parameter set name return default value string value this get parameter value name try return fields parse long value catch number format exception e return default value getlongparam defaultvalue isparameterset defaultvalue getparametervalue parselong numberformatexception defaultvalue creates a new file with the specified filename content type and data param filename the name of the file param content type the content type of the file param data the data of the file public http uploaded file impl string filename string content type bucket data this filename filename this content type content type this data data contenttype httpuploadedfileimpl contenttype contenttype contenttype see freenet clients http http uploaded file get content type public string get content type return content type httpuploadedfile getcontenttype getcontenttype contenttype see freenet clients http http uploaded file get data public bucket get data return data httpuploadedfile getdata getdata see freenet clients http http uploaded file get filename public string get filename return filename httpuploadedfile getfilename getfilename public static void addoom hook oom hook hook synchronized oom hooks oom hooks add hook addoomhook oomhook oomhooks oomhooks call this when running low of memory public static void low memory system gc system run finalization iterate all oom hooks iterator oom hook it oom hooks iterator while it has next oom hook hook it next if hook null try hook handle low memory catch throwable t ignore system gc system run finalization lowmemory runfinalization oomhook oomhooks hasnext oomhook handlelowmemory runfinalization public static void handleoom out of memory error e if isoom logger error null double oom e return isoom true runtime r null try r runtime get runtime long used at start r total memory r free memory if emergency pool null emergency pool null system gc system run finalization iterate all oom hooks iterator oom hook it oom hooks iterator while it has next oom hook hook it next if hook null try hook handle out of memory catch throwable t ignore system gc system run finalization system err println e get class system err println e get message e print stack trace if e get message equals java heap space thread dump stack long used now r total memory r free memory system err println memory gc size util format size used at start false size util format size used now false total size util format size r total memory false free size util format size r free memory false max size util format size r max memory false thread group tg thread current thread get thread group while tg get parent null tg tg get parent system err println running threads tg active count logger after everything else since it might throw logger error null caught e e logger error null memory gc size util format size used at start false size util format size used now false total size util format size r total memory false free size util format size r free memory false max size util format size r max memory false logger error null running threads tg active count catch throwable t try without g cing it might be a thread error g cing creates a thread system err println caught handling oom e t e print stack trace if r null system err println memory total size util format size r total memory false free size util format size r free memory false max size util format size r max memory false thread group tg thread current thread get thread group while tg get parent null tg tg get parent system err println running threads tg active count wrapper manager request thread dump will probably crash but never mind finally isoom false outofmemoryerror getruntime usedatstart totalmemory freememory emergencypool emergencypool runfinalization oomhook oomhooks hasnext oomhook handleoutofmemory runfinalization getclass getmessage printstacktrace getmessage dumpstack usednow totalmemory freememory sizeutil formatsize usedatstart sizeutil formatsize usednow sizeutil formatsize totalmemory sizeutil formatsize freememory sizeutil formatsize maxmemory threadgroup currentthread getthreadgroup getparent getparent activecount sizeutil formatsize usedatstart sizeutil formatsize usednow sizeutil formatsize totalmemory sizeutil formatsize freememory sizeutil formatsize maxmemory activecount gcing gcing printstacktrace sizeutil formatsize totalmemory sizeutil formatsize freememory sizeutil formatsize maxmemory threadgroup currentthread getthreadgroup getparent getparent activecount wrappermanager requestthreaddump public node set user data null set parent node null setuserdata setparentnode public node string name this set name name setname public node string ns string name this set name ns name setname private node parent node null public void set parent node node node parent node node parentnode setparentnode parentnode public node get parent node return parent node getparentnode parentnode public node get root node node root node null node parent node get parent node while parent node null root node parent node parent node root node get parent node return root node getrootnode rootnode parentnode getparentnode parentnode rootnode parentnode parentnode rootnode getparentnode rootnode private string name new string public void set name string name this name name setname public void set name string ns string name this name ns name setname public string get name return name getname public boolean is name string value return name equals value isname private string value public void set value string value this value value setvalue public void set value int value set value integer to string value setvalue setvalue tostring public string get value return value getvalue private attribute list attr list new attribute list public int getn attributes return attr list size attributelist attrlist attributelist getnattributes attrlist public attribute get attribute int index return attr list get attribute index getattribute attrlist getattribute public attribute get attribute string name return attr list get attribute name getattribute attrlist getattribute public void add attribute attribute attr attr list add attr addattribute attrlist public void insert attribute at attribute attr int index attr list insert element at attr index insertattributeat attrlist insertelementat public void add attribute string name string value attribute attr new attribute name value add attribute attr addattribute addattribute public boolean remove attribute attribute attr return attr list remove attr removeattribute attrlist public boolean remove attribute string name return remove attribute get attribute name removeattribute removeattribute getattribute public boolean has attributes if 0 getn attributes return true return false hasattributes getnattributes public void set attribute string name string value attribute attr get attribute name if attr null attr set value value return attr new attribute name value add attribute attr setattribute getattribute setvalue addattribute public void set attribute string name int value set attribute name integer to string value setattribute setattribute tostring public string get attribute value string name attribute attr get attribute name if attr null return attr get value return getattributevalue getattribute getvalue public int get attribute integer value string name string val get attribute value name try return integer parse int val catch exception e return 0 getattributeintegervalue getattributevalue parseint public void set name space string ns string value set attribute xmlns ns value setnamespace setattribute private node list node list new node list public int getn nodes return node list size nodelist nodelist nodelist getnnodes nodelist public node get node int index return node list get node index getnode nodelist getnode public node get node string name return node list get node name getnode nodelist getnode public node get node ends with string name return node list get ends with name getnodeendswith nodelist getendswith public void add node node node node set parent node this node list add node addnode setparentnode nodelist public void insert node node node int index node set parent node this node list insert element at node index insertnode setparentnode nodelist insertelementat public boolean remove node node node node set parent node null return node list remove node removenode setparentnode nodelist public boolean remove node string name return node list remove get node name removenode nodelist getnode public void remove all nodes node list clear removeallnodes nodelist public boolean has nodes if 0 getn nodes return true return false hasnodes getnnodes public void set node string name string value node node get node name if node null node set value value return node new node name node set value value add node node setnode getnode setvalue setvalue addnode public string get node value string name node node get node name if node null return node get value return getnodevalue getnode getvalue private object user data null public void set user data object data user data data userdata setuserdata userdata public object get user data return user data getuserdata userdata public string get indent level string int n indent level char indent string new char n indent level for int n 0 n n indent level n indent string n t return new string indent string getindentlevelstring nindentlevel indentstring nindentlevel nindentlevel indentstring indentstring public void output attributes print writer ps int n attributes getn attributes for int n 0 n n attributes n attribute attr get attribute n ps print attr get name xml escapexml chars attr get value outputattributes printwriter nattributes getnattributes nattributes getattribute getname escapexmlchars getvalue public void output print writer ps int indent level boolean has child node string indent string get indent level string indent level string name get name string value get value if has nodes false has child node false ps print indent string name output attributes ps thnaks for tho beisch 11 09 04 if value null value length 0 no value so use short notation node ps println else ps println xml escapexml chars value name return ps print indent string name output attributes ps ps println int n child nodes getn nodes for int n 0 n n child nodes n node cnode get node n cnode output ps indent level 1 true ps println indent string name printwriter indentlevel haschildnode indentstring getindentlevelstring indentlevel getname getvalue hasnodes haschildnode indentstring outputattributes escapexmlchars indentstring outputattributes nchildnodes getnnodes nchildnodes getnode indentlevel indentstring public string to string boolean has child node byte array output stream byte out new byte array output stream print writer pr new print writer byte out output pr 0 has child node pr flush return byte out to string tostring haschildnode bytearrayoutputstream byteout bytearrayoutputstream printwriter printwriter byteout haschildnode byteout tostring override public string to string return to string true tostring tostring public string toxml string boolean has child node string xml str to string xml str xml str replace all lt xml str xml str replace all gt thanks for theo beisch 11 09 04 xml str xml str replace all amp xml str xml str replace all quot thanks for brian owens 12 02 04 xml str xml str replace all apos return xml str toxmlstring haschildnode xmlstr tostring xmlstr xmlstr replaceall xmlstr xmlstr replaceall xmlstr xmlstr replaceall xmlstr xmlstr replaceall xmlstr xmlstr replaceall xmlstr public string toxml string return toxml string true toxmlstring toxmlstring public void print boolean has child node print writer pr new print writer system out output pr 0 has child node pr flush haschildnode printwriter printwriter haschildnode public void print print true return the build number not svn revision number of this node public static final int build number return build number buildnumber buildnumber return the lowest build number with which the node will connect and exchange data normally public static final int last good build if system current time millis transition time return new last good build else return old last good build lastgoodbuild currenttimemillis transitiontime newlastgoodbuild oldlastgoodbuild return the node s version designators as an array public static final string get version string ret node name node version protocol version build number return ret getversion nodename nodeversion protocolversion buildnumber public static final string get last good version string ret node name node version protocol version last good build return ret getlastgoodversion nodename nodeversion protocolversion lastgoodbuild return the version string that should be presented in the node reference public static final string get version string return fields comma list get version nodereference getversionstring commalist getversion return is needed for the freeviz public static final string get last good version string return fields comma list get last good version getlastgoodversionstring commalist getlastgoodversion return true if requests should be accepted from nodes brandishing this protocol version string private static boolean good protocol string prot if prot equals protocol version uncomment next line to accept stable see also explain bad version below prot equals stable protocol version return true return false goodprotocol protocolversion explainbadversion stableprotocolversion return true if requests should be accepted from nodes brandishing this version string public static final boolean check good version string version if version null logger error version class version null new exception error return false string v fields comma list version if v length 3 good protocol v 2 return false if same version v try int build integer parse int v 3 int req last good build if build req if logdebug logger debug version class not accepting unstable from version version last good build req return false catch number format exception e if logger should log logger minor version class logger minor version class not accepting e from version return false if stable version v try int build integer parse int v 3 if build last good stable build if logdebug logger debug version class not accepting stable from version version last good stable build last good stable build return false catch number format exception e logger minor version class not accepting e from version return false if logdebug logger minor version class accepting version return true checkgoodversion commalist goodprotocol sameversion parseint lastgoodbuild lastgoodbuild numberformatexception shouldlog stableversion parseint lastgoodstablebuild lastgoodstablebuild lastgoodstablebuild numberformatexception return true if requests should be accepted from nodes brandishing this version string given an arbitrary last good version public static final boolean check arbitrary good version string version string last good version if version null logger error version class version null new exception error return false if last good version null logger error version class last good version null new exception error return false string v fields comma list version string lgv fields comma list last good version if v null v length 3 good protocol v 2 return false if lgv null lgv length 3 good protocol lgv 2 return false if same arbitrary version v lgv try int build integer parse int v 3 int min build integer parse int lgv 3 if build min build if logdebug logger debug version class not accepting unstable from version version last good version last good version return false catch number format exception e if logger should log logger minor version class logger minor version class not accepting e from version and or last good version return false if stable version v try int build integer parse int v 3 if build last good stable build if logdebug logger debug version class not accepting stable from version version last good stable build last good stable build return false catch number format exception e logger minor version class not accepting e from version return false if logdebug logger minor version class accepting version return true lastgoodversion checkarbitrarygoodversion lastgoodversion lastgoodversion lastgoodversion commalist commalist lastgoodversion goodprotocol goodprotocol samearbitraryversion parseint min_build parseint min_build lastgoodversion lastgoodversion numberformatexception shouldlog lastgoodversion stableversion parseint lastgoodstablebuild lastgoodstablebuild lastgoodstablebuild numberformatexception return string explaining why a version string is rejected public static final string explain bad version string version string v fields comma list version if v length 3 good protocol v 2 return required protocol version is protocol version uncomment next line if accepting stable see also good protocol above or stable protocol version if same version v try int build integer parse int v 3 int req last good build if build req return build older than last good build req catch number format exception e return build number not numeric if stable version v try int build integer parse int v 3 if build last good stable build return build older than last good stable build last good stable build catch number format exception e return build number not numeric return null explainbadversion commalist goodprotocol protocolversion goodprotocol stableprotocolversion sameversion parseint lastgoodbuild numberformatexception stableversion parseint lastgoodstablebuild lastgoodstablebuild numberformatexception return the build number of an arbitrary version string public static final int get arbitrary build number string version throws version parse exception if version null logger error version class version null new exception error throw new version parse exception version null string v fields comma list version if v length 3 good protocol v 2 throw new version parse exception not long enough or bad protocol version try return integer parse int v 3 catch number format exception e version parse exception ve new version parse exception got number format exception on v 3 e for version ve init cause e throw ve getarbitrarybuildnumber versionparseexception versionparseexception commalist goodprotocol versionparseexception parseint numberformatexception versionparseexception versionparseexception numberformatexception initcause public static final int get arbitrary build number string version int default value try return get arbitrary build number version catch version parse exception e return default value getarbitrarybuildnumber defaultvalue getarbitrarybuildnumber versionparseexception defaultvalue update static variable highest seen build anytime we encounter a new node with a higher version than we ve seen before public static final void seen version string version string v fields comma list version if v null v length 3 return bad but that will be discovered elsewhere if same version v int build no try build no integer parse int v 3 catch number format exception e return if build no highest seen build if logger should log logger minor version class logger minor version class new highest seen build build no highest seen build build no highestseenbuild seenversion commalist sameversion buildno buildno parseint numberformatexception buildno highestseenbuild shouldlog buildno highestseenbuild buildno return true if the string describes the same node version as ours note that the build number may be different and is ignored public static boolean same version string v return v 0 equals node name v 1 equals node version v length 4 sameversion nodename nodeversion return true if the string describes the same node version as an arbitrary one note that the build number may be different and is ignored public static boolean same arbitrary version string v string lgv return v 0 equals lgv 0 v 1 equals lgv 1 v length 4 lgv length 4 samearbitraryversion return true if the string describes a stable node version private static boolean stable version string v return v 0 equals node name v 1 equals stable node version v length 4 stableversion nodename stablenodeversion public static void main string args throws throwable system out println freenet node name node version protocol protocol version build build number last good build last good build nodename nodeversion protocolversion buildnumber lastgoodbuild final object client public random grab array with client object client boolean persistent object container container remove random parent parent super persistent container parent this client client randomgrabarraywithclient objectcontainer removerandomparent public final object get object return client getobject creates a new trust relationship web page param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user throws unknown identity exception public identity page web interface my web interface http request my request throws unknown identity exception super my web interface my request identity wot get identity byid request get param id mywebinterface webinterface myrequest unknownidentityexception identitypage webinterface mywebinterface httprequest myrequest unknownidentityexception mywebinterface myrequest getidentitybyid getparam inherit doc see web page make public void make synchronized identity does not matter much if this information is not synchronous to the trust tables so we put it outside the lock on the wot to reduce the time the whole wot is locked makeuri box make services box html node trustee trusts node add content box identities that identity get nickname trusts html node trustees table trustee trusts node add child table html node trustees table header trustees table add child tr trustees table header add child th nickname trustees table header add child th identity trustees table header add child th value trustees table header add child th comment html node truster trusts node add content box identities that trust identity get nickname html node trusters table truster trusts node add child table html node trusters table header trusters table add child tr trusters table header add child th nickname trusters table header add child th identity trusters table header add child th value trusters table header add child th comment synchronized wot for trust trust wot get given trusts identity html node trust row trustees table add child tr identity trustee trust get trustee trust row add child td add child a href show identity id trustee getid trustee get nickname trust row add child td trustee getid trust row add child td align right byte to string trust get value trust row add child td trust get comment for trust trust wot get received trusts identity html node trust row trusters table add child tr identity truster trust get truster trust row add child td add child a href show identity id truster getid truster get nickname trust row add child td truster getid trust row add child td align right byte to string trust get value trust row add child td trust get comment inheritdoc webpage makeuribox makeservicesbox htmlnode trusteetrustsnode addcontentbox getnickname htmlnode trusteestable trusteetrustsnode addchild htmlnode trusteestableheader trusteestable addchild trusteestableheader addchild trusteestableheader addchild trusteestableheader addchild trusteestableheader addchild htmlnode trustertrustsnode addcontentbox getnickname htmlnode trusterstable trustertrustsnode addchild htmlnode trusterstableheader trusterstable addchild trusterstableheader addchild trusterstableheader addchild trusterstableheader addchild trusterstableheader addchild getgiventrusts htmlnode trustrow trusteestable addchild gettrustee trustrow addchild addchild showidentity getnickname trustrow addchild trustrow addchild tostring getvalue trustrow addchild getcomment getreceivedtrusts htmlnode trustrow trusterstable addchild gettruster trustrow addchild addchild showidentity getnickname trustrow addchild trustrow addchild tostring getvalue trustrow addchild getcomment private void makeuri box html node box content add content box reference of identity identity get nickname box content add child p the following freenet uri is a reference to this identity if you want to tell other people about this identity give the uri to them box content add child p identity get requesturi to string makeuribox htmlnode boxcontent addcontentbox getnickname boxcontent addchild boxcontent addchild getrequesturi tostring private void make services box html node box content add content box services of identity identity get nickname iterator string iter identity get contexts iterator string builder contexts new string builder 128 while iter has next contexts append iter next if iter has next contexts append box content add child p contexts to string makeservicesbox htmlnode boxcontent addcontentbox getnickname getcontexts stringbuilder stringbuilder hasnext hasnext boxcontent addchild tostring public client get message simple field set fs throws message invalid exception short default priority client token fs get client token global fields string to bool fs get global false ignoreds fields string to bool fs get ignoreds false ds only fields string to bool fs get ds only false identifier fs get identifier allowedmime types fs get all allowedmime types if identifier null throw new message invalid exception protocol error message missing field no identifier null global try uri new freeneturi fs get uri catch malformedurl exception e throw new message invalid exception protocol error message freenet uri parse error e get message identifier global string verbosity string fs get verbosity if verbosity string null verbosity 0 else try verbosity integer parse int verbosity string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing verbosity field e get message identifier global string return type string fs get return type return type parse return typefcp return type string if return type return type direct disk file null temp file null default just below f proxy default priority request starter immediate splitfile priority class else if return type return type none disk file null temp file null default priority request starter prefetch priority class else if return type return type disk default priority request starter bulk splitfile priority class string filename fs get filename if filename null throw new message invalid exception protocol error message missing field missing filename identifier global disk file new file filename string temp filename fs get temp filename if temp filename null temp filename filename freenet tmp temp file new file temp filename if disk file get absolute file get parent file equals temp file get absolute file get parent file throw new message invalid exception protocol error message filename and temp filename must be in same dir null identifier global if temp file exists throw new message invalid exception protocol error message disk target exists temp file exists identifier global if disk file exists throw new message invalid exception protocol error message disk target exists null identifier global try check whether we can create it so that we return an error early on then delete it as we have to rename over it anyway atomic creation of a file does not guarantee that it won t be replaced with a symlink if temp file create new file temp file exists temp file can read temp file can write throw new message invalid exception protocol error message could not create file could not create temp file temp file identifier global temp file delete catch io exception e throw new message invalid exception protocol error message could not create file e get message identifier global else throw new message invalid exception protocol error message message parse error unknown return type identifier global string max size string fs get max size if max size string null default to unlimited max size long max value else try max size long parse long max size string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing max size field e get message identifier global string max temp size string fs get max temp size if max temp size string null default to unlimited max temp size long max value else try max temp size long parse long max temp size string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing max size field e get message identifier global string max retries string fs get max retries if max retries string null default to 0 max retries 0 else try max retries integer parse int max retries string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing max size field e get message identifier global if logger should log logger minor this logger minor this max retries max retries string priority string fs get priority class if priority string null defaults to the one just below f proxy priority class default priority else try priority class short parse short priority string 10 if priority class request starter maximum priority class priority class request starter minimum priority class throw new message invalid exception protocol error message invalid field valid priorities are from request starter maximum priority class to request starter minimum priority class identifier global catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing priority class field e get message identifier global string persistence string fs get persistence if persistence string null persistence string equals ignore case connection default persists until connection loss persistence type client request persist connection else if persistence string equals ignore case reboot reports to client by name persists over connection loss not saved to disk so dies on reboot persistence type client request persist reboot else if persistence string equals ignore case forever same as reboot but saved to disk persists forever persistence type client request persist forever else throw new message invalid exception protocol error message error parsing number error parsing persistence field persistence string identifier global if global persistence type client request persist connection throw new message invalid exception protocol error message not supported global requests must be persistent identifier global binary blob fields string to bool fs get binary blob false clientgetmessage simplefieldset messageinvalidexception defaultpriority clienttoken clienttoken stringtobool stringtobool dsonly stringtobool dsonly allowedmimetypes getall allowedmimetypes messageinvalidexception protocolerrormessage missing_field malformedurlexception messageinvalidexception protocolerrormessage freenet_uri_parse_error getmessage verbositystring verbositystring parseint verbositystring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number getmessage returntypestring returntype returntype parsereturntypefcp returntypestring returntype return_type_direct diskfile tempfile fproxy defaultpriority requeststarter immediate_splitfile_priority_class returntype return_type_none diskfile tempfile defaultpriority requeststarter prefetch_priority_class returntype return_type_disk defaultpriority requeststarter bulk_splitfile_priority_class messageinvalidexception protocolerrormessage missing_field diskfile tempfilename tempfilename tempfilename tempfilename tempfile tempfilename diskfile getabsolutefile getparentfile tempfile getabsolutefile getparentfile messageinvalidexception protocolerrormessage filename_and_temp_filename_must_be_in_same_dir tempfile messageinvalidexception protocolerrormessage disk_target_exists diskfile messageinvalidexception protocolerrormessage disk_target_exists tempfile createnewfile tempfile tempfile canread tempfile canwrite messageinvalidexception protocolerrormessage could_not_create_file tempfile tempfile ioexception messageinvalidexception protocolerrormessage could_not_create_file getmessage messageinvalidexception protocolerrormessage message_parse_error maxsizestring maxsize maxsizestring maxsize max_value maxsize parselong maxsizestring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number maxsize getmessage maxtempsizestring maxtempsize maxtempsizestring maxtempsize max_value maxtempsize parselong maxtempsizestring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number maxsize getmessage maxretriesstring maxretries maxretriesstring maxretries maxretries parseint maxretriesstring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number maxsize getmessage shouldlog maxretries prioritystring priorityclass prioritystring fproxy priorityclass defaultpriority priorityclass parseshort prioritystring priorityclass requeststarter maximum_priority_class priorityclass requeststarter minimum_priority_class messageinvalidexception protocolerrormessage invalid_field requeststarter maximum_priority_class requeststarter minimum_priority_class numberformatexception messageinvalidexception protocolerrormessage error_parsing_number priorityclass getmessage persistencestring persistencestring persistencestring equalsignorecase persistencetype clientrequest persist_connection persistencestring equalsignorecase persistencetype clientrequest persist_reboot persistencestring equalsignorecase persistencetype clientrequest persist_forever messageinvalidexception protocolerrormessage error_parsing_number persistencestring persistencetype clientrequest persist_connection messageinvalidexception protocolerrormessage not_supported binaryblob stringtobool binaryblob override public simple field set get field set simple field set fs new simple field set true fs put single ignoreds boolean to string ignoreds fs put single uri uri to string false false fs put single identifier identifier fs put single verbosity integer to string verbosity fs put single return type get return type string fs put single max size long to string max size fs put single max temp size long to string max temp size fs put single max retries integer to string max retries fs put binary blob binary blob return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle tostring putsingle putsingle tostring putsingle returntype getreturntypestring putsingle maxsize tostring maxsize putsingle maxtempsize tostring maxtempsize putsingle maxretries tostring maxretries binaryblob binaryblob private string get return type string return return type string return type getreturntypestring returntypestring returntype override public string get name return name getname override public void run fcp connection handler handler node node handler start client get this fcpconnectionhandler startclientget public static string return type string short type switch type case return type direct return direct case return type none return none case return type disk return disk case return type chunked return chunked default return short to string type returntypestring return_type_direct return_type_none return_type_disk return_type_chunked tostring short parse return typefcp string string throws message invalid exception try return parse return type string catch number format exception e throw new message invalid exception protocol error message invalid field unable to parse return type string e identifier global parsereturntypefcp messageinvalidexception parsereturntype numberformatexception messageinvalidexception protocolerrormessage invalid_field returntype public static short parse return type string string if string null return return type direct if string equals ignore case direct return return type direct if string equals ignore case none return return type none if string equals ignore case disk return return type disk if string equals ignore case chunked return return type chunked return short parse short string parsereturntype return_type_direct equalsignorecase return_type_direct equalsignorecase return_type_none equalsignorecase return_type_disk equalsignorecase return_type_chunked parseshort public static short parse valid return type string string short s parse return type string if s return type direct s return type none s return type disk return s throw new illegal argument exception invalid or unsupported return type return type string s parsevalidreturntype parsereturntype return_type_direct return_type_none return_type_disk illegalargumentexception returntypestring override public void remove from object container container uri remove from container container delete disk file container delete temp file container delete this removefrom objectcontainer removefrom diskfile tempfile public class peer parse exception extends exception private static final long serial versionuid 1 public peer parse exception exception e super e peerparseexception serialversionuid peerparseexception public peer parse exception super peerparseexception public peer parse exception string string super string peerparseexception public final class identity editor extends web page impl public identity editor web interface my web interface ft own identity viewer http request request super my web interface viewer request todo auto generated constructor stub identityeditor webpageimpl identityeditor webinterface mywebinterface ftownidentity httprequest mywebinterface public final void make make own identities box make known identities box makeownidentitiesbox makeknownidentitiesbox private final void make own identities box html node box add content box own identities iterator ft own identity own identities m freetalk get identity manager own identity iterator if own identities has next false box add child p no own identities received from the wot plugin yet please create one there and wait for 15 minutes until it appears here else html node identities table box add child table html node row identities table add child tr row add child th name row add child th freetalk address while own identities has next ft own identity id own identities next row identities table add child tr row add child td id get nickname row add child td id get freetalk address html node last update cell row add child td if id get last insert null last update cell add child p insert in progress else if id get last insert equals new date 0 last update cell add child p never else last update cell add child new html node a href id get requesturi to string id get last insert to string fixme repair i e make it use the wot plugin html node delete cell row add child td html node delete form ft m plugin respirator add form child delete cell freetalk plugin uri delete own identity delete form delete form add child input new string type name value new string hidden identity id get requesturi toacii string delete form add child input new string type name value new string submit delete delete fixme repair i e make it use the wot plugin content node add child create new own identity box ft makeownidentitiesbox htmlnode addcontentbox ftownidentity ownidentities mfreetalk getidentitymanager ownidentityiterator ownidentities hasnext addchild htmlnode identitiestable addchild htmlnode identitiestable addchild addchild addchild ownidentities hasnext ftownidentity ownidentities identitiestable addchild addchild getnickname addchild getfreetalkaddress htmlnode lastupdatecell addchild getlastinsert lastupdatecell addchild getlastinsert lastupdatecell addchild lastupdatecell addchild htmlnode getrequesturi tostring getlastinsert tostring htmlnode deletecell addchild htmlnode deleteform mpluginrespirator addformchild deletecell plugin_uri deleteownidentity deleteform deleteform addchild getrequesturi toaciistring deleteform addchild contentnode addchild createnewownidentitybox private final void make known identities box html node box add content box known identities html node identities table box add child table border 0 html node row identities table add child tr row add child th name row add child th freetalk address row add child th for ft identity id m freetalk get identity manager get all identities if id instanceof ft own identity continue row identities table add child tr row add child td id get nickname row add child td id get freetalk address html node delete cell row add child td fixme repair i e make it use the wot plugin html node delete form ft m plugin respirator add form child delete cell freetalk plugin uri delete identity delete form delete form add child input new string type name value new string hidden identity id get requesturi toacii string delete form add child input new string type name value new string submit delete delete fixme repair i e make it use the wot plugin content node add child create new known identity box ft makeknownidentitiesbox htmlnode addcontentbox htmlnode identitiestable addchild htmlnode identitiestable addchild addchild addchild addchild ftidentity mfreetalk getidentitymanager getallidentities ftownidentity identitiestable addchild addchild getnickname addchild getfreetalkaddress htmlnode deletecell addchild htmlnode deleteform mpluginrespirator addformchild deletecell plugin_uri deleteidentity deleteform deleteform addchild getrequesturi toaciistring deleteform addchild contentnode addchild createnewknownidentitybox final clientchk key override public string to string return super to string key key tostring tostring construct from data retrieved and a key do not do full decode verify what can be verified without doing a full decode param key2 the client key param header the header param data the data public clientchk block byte data byte header clientchk key2 boolean verify throws chk verify exception super data header key2 get nodechk verify key2 crypto algorithm this key key2 clientchkblock chkverifyexception getnodechk cryptoalgorithm construct from a chk block and a key public clientchk block chk block block clientchk key2 throws chk verify exception this block get data block get headers key2 true chkblock clientchkblock chkblock chkverifyexception getdata getheaders decode into ram if short throws chk decode exception public byte memory decode throws chk decode exception try array bucket a array bucket decode new array bucket factory 32 1024 false return bucket tools to byte array a fixme catch io exception e throw new error e chkdecodeexception memorydecode chkdecodeexception arraybucket arraybucket arraybucketfactory buckettools tobytearray ioexception decode the chk and recover the original data return the original data throws io exception if there is a bucket error public bucket decode bucket factory bf int max length boolean dont compress throws chk decode exception io exception overall hash already verified so first job is to decrypt if key crypto algorithm key algo aes pcfb 256 sha256 throw new unsupported operation exception block cipher cipher try cipher new rijndael 256 256 catch unsupported cipher exception e fixme log this properly throw new error e byte crypto key key crypto key if crypto key length node symmetric key length throw new chk decode exception crypto key too short cipher initialize key crypto key pcfb mode pcfb pcfb mode create cipher byte hbuf new byte headers length 2 system arraycopy headers 2 hbuf 0 headers length 2 byte dbuf new byte data length system arraycopy data 0 dbuf 0 data length decipher header first functions as iv pcfb block decipher hbuf 0 hbuf length pcfb block decipher dbuf 0 dbuf length check decryption key hash of data not including header message digest md256 sha256 get message digest byte dkey md256 digest dbuf if java util arrays equals dkey key crypto key sha256 return message digest md256 throw new chk decode exception check failed decrypt key h data check iv hash of decryption key byte prediv md256 digest dkey sha256 return message digest md256 md256 null extract the iv byte iv new byte 32 system arraycopy hbuf 0 iv 0 32 if arrays equals iv prediv throw new chk decode exception check failed decrypted iv h decryption key checks complete int size hbuf 32 0xff 8 hbuf 33 0xff if size 32768 size 0 throw new chk decode exception invalid size size return key decompress dont compress false key is compressed dbuf size bf math min max length max length before compression key compression algorithm false ioexception bucketfactory maxlength dontcompress chkdecodeexception ioexception cryptoalgorithm algo_aes_pcfb_256_sha256 unsupportedoperationexception blockcipher unsupportedcipherexception cryptokey cryptokey cryptokey symmetric_key_length chkdecodeexception cryptokey pcfbmode pcfbmode blockdecipher blockdecipher messagedigest getmessagedigest cryptokey returnmessagedigest chkdecodeexception returnmessagedigest chkdecodeexception chkdecodeexception dontcompress iscompressed maxlength max_length_before_compression compressionalgorithm encode a bucket of data to a chk block param source data the bucket of data to encode can be arbitrarily large param as metadata is this a metadata key param dont compress if set don t even try to compress param already compressed codec if dont compress and this is 0 then the data is already compressed and this is the algorithm throws chk encode exception throws io exception if there is an error reading from the bucket static public clientchk block encode bucket source data boolean as metadata boolean dont compress short already compressed codec long source length throws chk encode exception io exception byte final data null byte data byte header clientchk key short compression algorithm 1 try compressed comp key compress source data dont compress already compressed codec source length max length before compression chk block data length false final data comp compressed data compression algorithm comp compression algorithm catch key encode exception e2 throw new chk encode exception e2 get message e2 now do the actual encode message digest md256 sha256 get message digest first pad it if final data length 32768 hash the data if final data length 0 md256 update final data byte digest md256 digest mersenne twister mt new mersenne twister digest data new byte 32768 system arraycopy final data 0 data 0 final data length byte random bytes new byte 32768 final data length mt next bytes random bytes system arraycopy random bytes 0 data final data length 32768 final data length else data final data now make the header byte enc key md256 digest data md256 reset iv e h crypto key byte plainiv md256 digest enc key header new byte plainiv length 2 2 header 0 byte key block hash sha256 8 header 1 byte key block hash sha256 0xff system arraycopy plainiv 0 header 2 plainiv length header plainiv length 2 byte final data length 8 header plainiv length 3 byte final data length 0xff grrr java 1 4 does not have any symmetric crypto despite exposing asymmetric and hashes now encrypt the header then the data using the same pcfb instance block cipher cipher try cipher new rijndael 256 256 catch unsupported cipher exception e fixme log this properly throw new error e cipher initialize enc key pcfb mode pcfb pcfb mode create cipher pcfb block encipher header 2 header length 2 pcfb block encipher data 0 data length now calculate the final hash md256 update header byte final hash md256 digest data sha256 return message digest md256 now convert it into a clientchk key new clientchk final hash enc key as metadata key algo aes pcfb 256 sha256 compression algorithm try return new clientchk block data header key false catch chk verify exception e3 wtf throw new error e3 chkblock sourcedata asmetadata dontcompress alreadycompressedcodec dontcompress chkencodeexception ioexception clientchkblock sourcedata asmetadata dontcompress alreadycompressedcodec sourcelength chkencodeexception ioexception finaldata compressionalgorithm sourcedata dontcompress alreadycompressedcodec sourcelength max_length_before_compression chkblock data_length finaldata compresseddata compressionalgorithm compressionalgorithm keyencodeexception chkencodeexception getmessage messagedigest getmessagedigest finaldata finaldata finaldata mersennetwister mersennetwister finaldata finaldata randombytes finaldata nextbytes randombytes randombytes finaldata finaldata finaldata enckey enckey keyblock hash_sha256 keyblock hash_sha256 finaldata finaldata blockcipher unsupportedcipherexception enckey pcfbmode pcfbmode blockencipher blockencipher finalhash returnmessagedigest finalhash enckey asmetadata algo_aes_pcfb_256_sha256 compressionalgorithm clientchkblock chkverifyexception encode a block of data to a chk block param source data the data to encode param as metadata is this a metadata key param dont compress if set don t even try to compress param already compressed codec if dont compress and this is 0 then the data is already compressed and this is the algorithm static public clientchk block encode byte source data boolean as metadata boolean dont compress short already compressed codec int source length throws chk encode exception try return encode new array bucket source data as metadata dont compress already compressed codec source length catch io exception e can t happen throw new error e chkblock sourcedata asmetadata dontcompress alreadycompressedcodec dontcompress clientchkblock sourcedata asmetadata dontcompress alreadycompressedcodec sourcelength chkencodeexception arraybucket sourcedata asmetadata dontcompress alreadycompressedcodec sourcelength ioexception public client key get client key return key clientkey getclientkey public boolean is metadata return key is metadata ismetadata ismetadata override public boolean object can new object container container useful to be able to tell whether it s a chk block or a clientchk block so override here too throw new unsupported operation exception clientchk block storage in database not supported objectcannew objectcontainer chkblock clientchkblock unsupportedoperationexception clientchkblock override public int hash code return key hash code hashcode hashcode override public boolean equals object o if o instanceof clientchk block return false clientchk block block clientchk block o if key equals block key return false return super equals o clientchkblock clientchkblock clientchkblock private final void modify if owner null owner modify public int size return used public object clone throws clone not supported exception return super clone clonenotsupportedexception public void set size int new size if new size used for int i used i new size arr i null else reserve space new size used used new size setsize newsize newsize newsize reservespace newsize newsize public t get int i if i 0 i used throw new index out of bounds exception return t load elem i indexoutofboundsexception loadelem public i persistent get raw int i if i 0 i used throw new index out of bounds exception return arr i ipersistent getraw indexoutofboundsexception public void pin for int i 0 n used i n i arr i load elem i loadelem public void unpin for int i 0 n used i n i i persistent elem arr i if elem null elem is raw elem is persistent arr i new persistent stub elem get storage elem get oid ipersistent israw ispersistent persistentstub getstorage getoid public t set int i t obj if i 0 i used throw new index out of bounds exception t prev t load elem i arr i obj modify return prev indexoutofboundsexception loadelem public void set object int i t obj if i 0 i used throw new index out of bounds exception arr i obj modify setobject indexoutofboundsexception public boolean is empty return used 0 isempty protected void remove range int from index int to index int size used int num moved size to index system arraycopy arr to index arr from index num moved let gc do its work int new size size to index from index while size new size arr size null used size modify removerange fromindex toindex nummoved toindex toindex fromindex nummoved newsize toindex fromindex newsize public void remove object int i if i 0 i used throw new index out of bounds exception used 1 system arraycopy arr i 1 arr i used i arr used null modify removeobject indexoutofboundsexception public t remove int i if i 0 i used throw new index out of bounds exception t obj t load elem i used 1 system arraycopy arr i 1 arr i used i arr used null modify return obj indexoutofboundsexception loadelem void reserve space int len if used len arr length i persistent new arr new i persistent used len arr length 2 used len arr length 2 system arraycopy arr 0 new arr 0 used arr new arr modify reservespace ipersistent newarr ipersistent newarr newarr public void add int i t obj insert i obj public void insert int i t obj if i 0 i used throw new index out of bounds exception reserve space 1 system arraycopy arr i arr i 1 used i arr i obj used 1 indexoutofboundsexception reservespace public boolean add t obj reserve space 1 arr used obj return true reservespace public void add all t a add all a 0 a length addall addall public boolean add all int index collection extends t c boolean modified false iterator extends t e c iterator while e has next add index e next modified true return modified addall hasnext public void add all t a int from int length reserve space length system arraycopy a from arr used length used length addall reservespace public boolean add all link t link int n link size reserve space n for int i 0 j used i n i j arr j link get raw i used n return true addall reservespace getraw public object to array return to persistent array toarray topersistentarray public i persistent to raw array return arr ipersistent torawarray public i persistent to persistent array i persistent a new i persistent used for int i used i 0 a i load elem i return a ipersistent topersistentarray ipersistent ipersistent loadelem public t t to array t arr if arr length used arr t array new instance arr get class get component type used for int i used i 0 arr i t load elem i if arr length used arr used null return arr toarray newinstance getclass getcomponenttype loadelem public boolean contains object obj return index of obj 0 indexof public boolean contains object t obj return index of object obj 0 containsobject indexofobject public int last index of object object obj int oid i persistent a arr if obj instanceof i persistent oid i persistent obj get oid 0 for int i used i 0 i persistent elem a i if elem null elem get oid oid return i else for int i used i 0 if a i obj return i return 1 lastindexofobject ipersistent ipersistent ipersistent getoid ipersistent getoid public int index of object object obj int oid i persistent a arr if obj instanceof i persistent oid i persistent obj get oid 0 for int i 0 n used i n i i persistent elem a i if elem null elem get oid oid return i else for int i 0 n used i n i if a i obj return i return 1 indexofobject ipersistent ipersistent ipersistent getoid ipersistent getoid public int index of object obj if obj null for int i 0 n used i n i if arr i null return i else for int i 0 n used i n i if obj equals load elem i return i return 1 indexof loadelem public int last index of object obj if obj null for int i used i 0 if arr i null return i else for int i used i 0 if obj equals load elem i return i return 1 lastindexof loadelem public boolean contains element int i t obj i persistent elem arr i return elem obj elem null elem get oid 0 elem get oid obj get oid containselement ipersistent getoid getoid getoid public void clear for int i used i 0 arr i null used 0 modify public list t sub list int from index int to index return new sub list t this from index to index sublist fromindex toindex sublist fromindex toindex sub list link impl t list int from index int to index if from index 0 throw new index out of bounds exception from index from index if to index list size throw new index out of bounds exception to index to index if from index to index throw new illegal argument exception from index from index to index to index l list offset from index size to index from index sublist linkimpl fromindex toindex fromindex indexoutofboundsexception fromindex fromindex toindex indexoutofboundsexception toindex toindex fromindex toindex illegalargumentexception fromindex fromindex toindex toindex fromindex toindex fromindex public t set int index t element range check index return l set index offset element rangecheck public t get int index range check index return l get index offset rangecheck public int size return size public void add int index t element if index 0 index size throw new index out of bounds exception l add index offset element size indexoutofboundsexception public t remove int index range check index t result l remove index offset size return result rangecheck protected void remove range int from index int to index l remove range from index offset to index offset size to index from index removerange fromindex toindex removerange fromindex toindex toindex fromindex public boolean add all collection extends t c return add all size c addall addall public boolean add all int index collection extends t c if index 0 index size throw new index out of bounds exception index index size size int c size c size if c size 0 return false l add all offset index c size c size return true addall indexoutofboundsexception csize csize addall csize public iterator t iterator return list iterator listiterator public list iterator t list iterator final int index if index 0 index size throw new index out of bounds exception index index size size return new list iterator t private list iterator t i l list iterator index offset public boolean has next return next index size public t next if has next return i next else throw new no such element exception public boolean has previous return previous index 0 public t previous if has previous return i previous else throw new no such element exception public int next index return i next index offset public int previous index return i previous index offset public void remove i remove size public void set t o i set o public void add t o i add o size listiterator listiterator indexoutofboundsexception listiterator listiterator listiterator hasnext nextindex hasnext nosuchelementexception hasprevious previousindex hasprevious nosuchelementexception nextindex nextindex previousindex previousindex private list iterator t i l list iterator index offset public boolean has next return next index size listiterator listiterator hasnext nextindex public t next if has next return i next else throw new no such element exception hasnext nosuchelementexception public boolean has previous return previous index 0 hasprevious previousindex public t previous if has previous return i previous else throw new no such element exception hasprevious nosuchelementexception public int next index return i next index offset nextindex nextindex public int previous index return i previous index offset previousindex previousindex public void remove i remove size public void set t o i set o public void add t o i add o size public list t sub list int from index int to index return new sub list t l offset from index offset to index sublist fromindex toindex sublist fromindex toindex private void range check int index if index 0 index size throw new index out of bounds exception index index size size rangecheck indexoutofboundsexception link iterator link t link int index this link link i index last 1 linkiterator public boolean has next return i link size hasnext public t next throws no such element exception if has next throw new no such element exception last i return link get i nosuchelementexception hasnext nosuchelementexception public int next index return i nextindex public boolean has previous return i 0 hasprevious public t previous throws no such element exception if has previous throw new no such element exception return link get last i nosuchelementexception hasprevious nosuchelementexception public int previous index return i 1 previousindex public int next oid throws no such element exception if has next throw new no such element exception return link get raw i get oid nextoid nosuchelementexception hasnext nosuchelementexception getraw getoid public void remove if last 0 throw new illegal state exception link remove object last if last i i 1 illegalstateexception removeobject public void set t o if last 0 throw new illegal state exception link set object last o illegalstateexception setobject public void add t o link insert i o last 1 public boolean remove object o int i index of o if i 0 remove i return true return false indexof public boolean contains all collection c iterator e c iterator while e has next if contains e next return false return true containsall hasnext public boolean add all collection extends t c boolean modified false iterator extends t e c iterator while e has next if add e next modified true return modified addall hasnext public boolean remove all collection c boolean modified false iterator e iterator while e has next if c contains e next e remove modified true return modified removeall hasnext public boolean retain all collection c boolean modified false iterator t e iterator while e has next if c contains e next e remove modified true return modified retainall hasnext public iterator t iterator return new link iterator t this 0 linkiterator public list iterator t list iterator int index return new link iterator t this index listiterator listiterator linkiterator public list iterator t list iterator return list iterator 0 listiterator listiterator listiterator private final t load elem int i i persistent elem arr i if elem null elem is raw elem storage impl elem get storage lookup object elem get oid null return t elem loadelem ipersistent israw storageimpl getstorage lookupobject getoid public iterable iterator t select class cls string predicate query t query new query impl t null return query select cls iterator predicate iterableiterator queryimpl public void set owner i persistent obj owner obj setowner ipersistent public i persistent get owner return owner ipersistent getowner link impl linkimpl link impl public link impl int init size arr new i persistent init size linkimpl linkimpl initsize ipersistent initsize public link impl t arr i persistent owner this arr arr this owner owner used arr length linkimpl ipersistent public link impl link link i persistent owner used link size arr new i persistent used system arraycopy arr 0 link to raw array 0 used this owner owner linkimpl ipersistent ipersistent torawarray private float scale 1 0f public rescale filter rescalefilter public rescale filter float scale this scale scale rescalefilter override protected float transfer function float v return v scale transferfunction specifies the scale factor param scale the scale factor min value 1 max value 5 see get scale public void set scale float scale this scale scale initialized false getscale setscale returns the scale factor return the scale factor see set scale public float get scale return scale setscale getscale override public string to string return colors rescale tostring public class full text search hit implements comparable get document matching full text query public i persistent get document return storage get object byoid oid fulltextsearchhit ipersistent getdocument getobjectbyoid public final storage storage public int compare to object o float o rank full text search hit o rank return rank o rank 1 rank o rank 1 0 compareto orank fulltextsearchhit orank orank constructor of the full text search result hit public full text search hit storage storage int oid float rank this storage storage this oid oid this rank rank fulltextsearchhit public client put base freeneturi uri string identifier int verbosity fcp connection handler handler short priority class short persistence type string client token boolean global boolean getchk only boolean dont compress int max retries boolean early encode fcp server server object container container throws malformedurl exception super uri identifier verbosity handler priority class persistence type client token global container this getchk only getchk only ctx new insert context server default insert context new simple event producer ctx dont compress dont compress ctx event producer add event listener this ctx max insert retries max retries this early encode early encode publicuri get publicuri uri clientputbase fcpconnectionhandler priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode fcpserver objectcontainer malformedurlexception priorityclass persistencetype clienttoken getchkonly getchkonly insertcontext defaultinsertcontext simpleeventproducer dontcompress dontcompress eventproducer addeventlistener maxinsertretries maxretries earlyencode earlyencode getpublicuri public client put base freeneturi uri string identifier int verbosity fcp connection handler handler fcp client client short priority class short persistence type string client token boolean global boolean getchk only boolean dont compress int max retries boolean early encode fcp server server object container container throws malformedurl exception super uri identifier verbosity handler client priority class persistence type client token global container this getchk only getchk only ctx new insert context server default insert context new simple event producer ctx dont compress dont compress ctx event producer add event listener this ctx max insert retries max retries this early encode early encode publicuri get publicuri uri clientputbase fcpconnectionhandler fcpclient priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode fcpserver objectcontainer malformedurlexception priorityclass persistencetype clienttoken getchkonly getchkonly insertcontext defaultinsertcontext simpleeventproducer dontcompress dontcompress eventproducer addeventlistener maxinsertretries maxretries earlyencode earlyencode getpublicuri public client put base simple field set fs fcp client client2 fcp server server throws malformedurl exception super fs client2 publicuri get publicuri uri getchk only fields string to bool fs get chk only false boolean dont compress fields string to bool fs get dont compress false int max retries integer parse int fs get max retries client token fs get client token finished fields string to bool fs get finished false finished false succeeded fields string to bool fs get succeeded false ctx new insert context server default insert context new simple event producer ctx dont compress dont compress ctx event producer add event listener this ctx max insert retries max retries string genuri fs get generateduri if genuri null generateduri new freeneturi genuri if finished string ctime fs get completion time if ctime null completion time long parse long ctime if succeeded put failed message new put failed message fs subset put failed false early encode fields string to bool fs get early encode false clientputbase simplefieldset fcpclient fcpserver malformedurlexception getpublicuri getchkonly stringtobool chkonly dontcompress stringtobool dontcompress maxretries parseint maxretries clienttoken clienttoken stringtobool stringtobool insertcontext defaultinsertcontext simpleeventproducer dontcompress dontcompress eventproducer addeventlistener maxinsertretries maxretries completiontime completiontime parselong putfailedmessage putfailedmessage putfailed earlyencode stringtobool earlyencode private freeneturi get publicuri freeneturi uri throws malformedurl exception string type uri get key type if type equals ignore case chk return uri else if type equals ignore case ssk type equals ignore case usk if type equals ignore case usk uri uri set key type ssk insertable clientssk issk insertable clientssk create uri uri uri set routing key issk geturi get routing key uri uri set key type type return uri else if type equals ignore case ksk return uri else throw new illegal argument exception getpublicuri malformedurlexception getkeytype equalsignorecase equalsignorecase equalsignorecase equalsignorecase setkeytype insertableclientssk insertableclientssk setroutingkey getroutingkey setkeytype equalsignorecase illegalargumentexception override public void on lost connection object container container client context context if persistence type persist connection cancel container context otherwise ignore onlostconnection objectcontainer clientcontext persistencetype persist_connection public void on success base client putter state object container container synchronized this including this helps with certain bugs progress message null succeeded true finished true if generateduri null logger error this no generated uri in on success for this from state could restart and is on the putter don t free data until we remove the putter free data container finish container try send final message null container if client null client notify success this container onsuccess baseclientputter objectcontainer progressmessage onsuccess freedata trysendfinalmessage notifysuccess public void on failure insert exception e base client putter state object container container if finished return synchronized this finished true put failed message new put failed message e identifier global if persistence type persist forever container store this could restart and is on the putter don t free data until we remove the putter free data container finish container try send final message null container if client null client notify failure this container onfailure insertexception baseclientputter objectcontainer putfailedmessage putfailedmessage persistencetype persist_forever freedata trysendfinalmessage notifyfailure public void on generateduri freeneturi uri base client putter state object container container synchronized this if generateduri null if uri equals generateduri logger error this on generateduri uri state but already set generateduri to generateduri else if logger should log logger minor this logger minor this on generateduri twice with same value generateduri uri else generateduri uri if persistence type persist forever container store this try send generateduri message null container ongenerateduri baseclientputter objectcontainer ongenerateduri shouldlog ongenerateduri persistencetype persist_forever trysendgeneratedurimessage override public void request was removed object container container client context context if request is still running send a put failed with code cancelled if finished synchronized this finished true insert exception cancelled new insert exception insert exception cancelled put failed message new put failed message cancelled identifier global try send final message null container notify client that request was removed fcp message msg new persistent request removed message get identifier global if persistence type persist connection orig handler output handler queue msg else client queue client request message msg 0 container free data container if persistence type persist forever container activate ctx 2 ctx remove from container put failed message pfm freeneturi uri freeneturi puburi fcp message progress synchronized this pfm put failed message put failed message null uri generateduri generateduri null puburi publicuri progress progress message progress message null if pfm null container activate pfm 5 pfm remove from container if uri null container activate uri 5 uri remove from container if progress null container activate progress 1 progress remove from container if puburi null container activate puburi 5 puburi remove from container super request was removed container context requestwasremoved objectcontainer clientcontext putfailed insertexception insertexception insertexception putfailedmessage putfailedmessage trysendfinalmessage fcpmessage persistentrequestremovedmessage getidentifier persistencetype persist_connection orighandler outputhandler queueclientrequestmessage freedata persistencetype persist_forever removefrom putfailedmessage fcpmessage putfailedmessage putfailedmessage progressmessage progressmessage removefrom removefrom removefrom removefrom requestwasremoved public void receive final client event ce object container container client context context if finished return if persistence type persist forever container null context job runner queue new db job public void run object container container client context context container activate client put base this 1 receive ce container context container deactivate client put base this 1 native thread norm priority false return if ce instanceof splitfile progress event if verbosity verbosity splitfile progress verbosity splitfile progress simple progress message progress new simple progress message identifier global splitfile progress event ce try send progress message progress verbosity splitfile progress null container context else if ce instanceof started compression event if verbosity verbosity compression start end verbosity compression start end started compression message msg new started compression message identifier global started compression event ce codec try send progress message msg verbosity compression start end null container context else if ce instanceof finished compression event if verbosity verbosity compression start end verbosity compression start end finished compression message msg new finished compression message identifier global finished compression event ce try send progress message msg verbosity compression start end null container context clientevent objectcontainer clientcontext persistencetype persist_forever jobrunner dbjob objectcontainer clientcontext clientputbase clientputbase nativethread norm_priority splitfileprogressevent verbosity_splitfile_progress verbosity_splitfile_progress simpleprogressmessage simpleprogressmessage splitfileprogressevent trysendprogressmessage verbosity_splitfile_progress startedcompressionevent verbosity_compression_start_end verbosity_compression_start_end startedcompressionmessage startedcompressionmessage startedcompressionevent trysendprogressmessage verbosity_compression_start_end finishedcompressionevent verbosity_compression_start_end verbosity_compression_start_end finishedcompressionmessage finishedcompressionmessage finishedcompressionevent trysendprogressmessage verbosity_compression_start_end public void on fetchable base client putter putter object container container if finished return if verbosity verbosity put fetchable verbosity put fetchable freeneturi temp synchronized this temp generateduri put fetchable message msg new put fetchable message identifier global temp try send progress message msg verbosity put fetchable null container null onfetchable baseclientputter objectcontainer verbosity_put_fetchable verbosity_put_fetchable putfetchablemessage putfetchablemessage trysendprogressmessage verbosity_put_fetchable private void try send final message fcp connection output handler handler object container container fcp message msg synchronized this freeneturi uri generateduri if persistence type persist forever uri null container activate uri 5 uri uri clone if succeeded msg new put successful message identifier global uri startup time completion time else msg put failed message if msg null logger error this trying to send null message on this new exception error else if persistence type persist connection handler null handler orig handler output handler if handler null handler queue msg else client queue client request message msg 0 container trysendfinalmessage fcpconnectionoutputhandler objectcontainer fcpmessage persistencetype persist_forever putsuccessfulmessage startuptime completiontime putfailedmessage persistencetype persist_connection orighandler outputhandler queueclientrequestmessage private void try send generateduri message fcp connection output handler handler object container container fcp message msg if persistence type persist forever container activate client 1 container activate generateduri 5 synchronized this msg new uri generated message generateduri identifier is global queue if persistence type persist connection handler null handler orig handler output handler if handler null handler queue msg else client queue client request message msg 0 container trysendgeneratedurimessage fcpconnectionoutputhandler objectcontainer fcpmessage persistencetype persist_forever urigeneratedmessage isglobalqueue persistencetype persist_connection orighandler outputhandler queueclientrequestmessage param msg param verbosity param handler param container either container or context is required for a persistent request param context can be null if container is not null private void try send progress message final fcp message msg final int verbosity fcp connection output handler handler object container container client context context if persistence type persist forever if container null fcp message old progress null synchronized this if persistence type persist connection old progress progress message progress message msg if old progress null container activate old progress 1 old progress remove from container container store this else final fcp connection output handler h handler context job runner queue new db job public void run object container container client context context container activate client put base this 1 try send progress message msg verbosity h container context container deactivate client put base this 1 native thread norm priority false return else synchronized this if persistence type persist connection progress message msg if persistence type persist connection handler null handler orig handler output handler if handler null handler queue msg else client queue client request message msg verbosity container trysendprogressmessage fcpmessage fcpconnectionoutputhandler objectcontainer clientcontext persistencetype persist_forever fcpmessage oldprogress persistencetype persist_connection oldprogress progressmessage progressmessage oldprogress oldprogress oldprogress removefrom fcpconnectionoutputhandler jobrunner dbjob objectcontainer clientcontext clientputbase trysendprogressmessage clientputbase nativethread norm_priority persistencetype persist_connection progressmessage persistencetype persist_connection orighandler outputhandler queueclientrequestmessage override public void send pending messages fcp connection output handler handler boolean include persistent request boolean include data boolean only data object container container if persistence type persist connection logger error this wtf persistence type persistence type new exception error return if include persistent request fcp message msg persistent tag message container handler queue msg boolean generated false fcp message msg null boolean fin false synchronized this generated generateduri null msg progress message fin finished if persistence type persist forever msg null container activate msg 5 if generated try send generateduri message handler container if msg null handler queue msg if fin try send final message handler container sendpendingmessages fcpconnectionoutputhandler includepersistentrequest includedata onlydata objectcontainer persistencetype persist_connection persistencetype persistencetype includepersistentrequest fcpmessage persistenttagmessage fcpmessage progressmessage persistencetype persist_forever trysendgeneratedurimessage trysendfinalmessage override public synchronized simple field set get field set simple field set fs new simple field set false we will need multi level later fs put single type get type name fs put single uri uri to string false false fs put single identifier identifier fs put single verbosity integer to string verbosity fs put single priority class short to string priority class fs put single persistence client request persistence type string persistence type fs put single client name client name fs put single client token client token fs put single dont compress boolean to string ctx dont compress fs put single max retries integer to string ctx max insert retries fs put single finished boolean to string finished fs put single succeeded boolean to string succeeded fs put single getchk only boolean to string getchk only if generateduri null fs put single generateduri generateduri to string false false if finished succeeded should have a put failed message unless there is a race condition fs put put failed put failed message get field set false fs put single global boolean to string client is global queue fs put startup time startup time if finished fs put completion time completion time return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle gettypename putsingle tostring putsingle putsingle tostring putsingle priorityclass tostring priorityclass putsingle clientrequest persistencetypestring persistencetype putsingle clientname putsingle clienttoken clienttoken putsingle dontcompress tostring dontcompress putsingle maxretries tostring maxinsertretries putsingle tostring putsingle tostring putsingle getchkonly tostring getchkonly putsingle tostring putfailedmessage putfailed putfailedmessage getfieldset putsingle tostring isglobalqueue startuptime startuptime completiontime completiontime protected abstract string get type name gettypename override public synchronized double get success fraction object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get fraction else return 0 else return 1 getsuccessfraction objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getfraction override public synchronized double get total blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get total blocks else return 0 else return 1 gettotalblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage gettotalblocks override public synchronized double get min blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get min blocks else return 0 else return 1 getminblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getminblocks override public synchronized double get failed blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get failed blocks else return 0 else return 1 getfailedblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getfailedblocks override public synchronized double get fataly failed blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get fataly failed blocks else return 0 else return 1 getfatalyfailedblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getfatalyfailedblocks override public synchronized double get fetched blocks object container container if persistence type persist forever progress message null container activate progress message 2 if progress message null if progress message instanceof simple progress message return simple progress message progress message get fetched blocks else return 0 else return 1 getfetchedblocks objectcontainer persistencetype persist_forever progressmessage progressmessage progressmessage progressmessage simpleprogressmessage simpleprogressmessage progressmessage getfetchedblocks override public synchronized boolean is total finalized object container container if progress message instanceof simple progress message return false else if persistence type persist forever container activate progress message 5 return simple progress message progress message is total finalized istotalfinalized objectcontainer progressmessage simpleprogressmessage persistencetype persist_forever progressmessage simpleprogressmessage progressmessage istotalfinalized override public synchronized string get failure reason object container container if put failed message null return null if persistence type persist forever container activate put failed message 5 string s put failed message short code description if put failed message extra description null s put failed message extra description return s getfailurereason objectcontainer putfailedmessage persistencetype persist_forever putfailedmessage putfailedmessage shortcodedescription putfailedmessage extradescription putfailedmessage extradescription public void set vars restart object container container put failed message pfm fcp message progress synchronized this finished false pfm put failed message progress progress message this put failed message null this progress message null started false if pfm null container activate pfm 1 pfm remove from container if progress null container activate progress 1 progress remove from container if persistence type persist forever container store this setvarsrestart objectcontainer putfailedmessage fcpmessage putfailedmessage progressmessage putfailedmessage progressmessage removefrom removefrom persistencetype persist_forever public class unpremultiply filter extends point filter public unpremultiply filter unpremultiplyfilter pointfilter unpremultiplyfilter override public int filterrgb int x int y int rgb int a rgb 24 0xff int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if a 0 a 255 return rgb float f 255 0f a r f g f b f if r 255 r 255 if g 255 g 255 if b 255 b 255 return a 24 r 16 g 8 b override public string to string return alpha unpremultiply tostring public peer removed string identity string node identifier string identifier this identity identity this node identifier node identifier this identifier identifier peerremoved nodeidentifier nodeidentifier nodeidentifier override public simple field set get field set simple field set fs new simple field set true fs put single identity identity fs put single node identifier node identifier if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle nodeidentifier nodeidentifier putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message peer removed goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message peerremoved override public void remove from object container container container delete this removefrom objectcontainer public final string extra get the failure mode public int get mode return mode getmode logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public insert exception int m string msg freeneturi expecteduri super get message m msg extra msg mode m if logminor logger minor this creating insert exception get message mode msg this error codes null this uri expecteduri insertexception getmessage insertexception getmessage errorcodes public insert exception int m freeneturi expecteduri super get message m extra null mode m if logminor logger minor this creating insert exception get message mode this error codes null this uri expecteduri insertexception getmessage insertexception getmessage errorcodes public insert exception int mode throwable e freeneturi expecteduri super get message mode e get message extra e get message if logminor logger minor this creating insert exception get message mode e e this mode mode error codes null init cause e this uri expecteduri insertexception getmessage getmessage getmessage insertexception getmessage errorcodes initcause public insert exception int mode failure code tracker error codes freeneturi expecteduri super get message mode extra null this mode mode if logminor logger minor this creating insert exception get message mode this this error codes error codes this uri expecteduri insertexception failurecodetracker errorcodes getmessage insertexception getmessage errorcodes errorcodes public insert exception int mode super get message mode extra null this mode mode this error codes null this uri null insertexception getmessage errorcodes public insert exception insert exception e super e get message extra e extra mode e mode error codes e error codes clone if e uri null uri null else uri e uri clone insertexception insertexception getmessage errorcodes errorcodes public static string get message int mode string ret l10n get string insert exception long error mode if ret null return unknown error mode else return ret getmessage getstring insertexception longerror public static string get short message int mode string ret l10n get string insert exception short error mode if ret null return unknown error mode else return ret getshortmessage getstring insertexception shorterror is this error fatal non fatal errors are errors which are likely to go away with more retries or at least for which there is some point retrying public boolean is fatal return is fatal mode isfatal isfatal public static boolean is fatal int mode switch mode case invalid uri case fatal errors in blocks case collision case cancelled case meta strings not supported case binary blob format error return true case bucket error maybe case internal error maybe case rejected overload case too many retries in blocks case route not found case route really not found return false default logger error insert exception class error unknown to is fatal get message mode return false isfatal invalid_uri fatal_errors_in_blocks meta_strings_not_supported binary_blob_format_error bucket_error internal_error rejected_overload too_many_retries_in_blocks route_not_found route_really_not_found insertexception isfatal getmessage public static insert exception construct failure code tracker errors if errors null return null if errors is empty return null if errors is one code only return new insert exception errors get first code int mode if errors is fatal true mode fatal errors in blocks else mode too many retries in blocks return new insert exception mode errors null insertexception failurecodetracker isempty isonecodeonly insertexception getfirstcode isfatal fatal_errors_in_blocks too_many_retries_in_blocks insertexception override public insert exception clone return new insert exception this insertexception insertexception public void remove from object container container if error codes null container activate error codes 1 error codes remove from container if uri null container activate uri 5 uri remove from container stack trace element elements get stack trace if elements null for stack trace element element elements container delete element container delete this removefrom objectcontainer errorcodes errorcodes errorcodes removefrom removefrom stacktraceelement getstacktrace stacktraceelement private static final string svn revision custom static string get svn revision return svn revision svnrevision getsvnrevision svnrevision public wot message fetcher node my node high level simple client my client string my name wot identity manager my identity manager wot message manager my message manager super my node my client my name my identity manager my message manager m random m node fast weak random request client my message manager request client start wotmessagefetcher mynode highlevelsimpleclient myclient myname wotidentitymanager myidentitymanager wotmessagemanager mymessagemanager mynode myclient myname myidentitymanager mymessagemanager mrandom mnode fastweakrandom requestclient mymessagemanager requestclient override protected collection client getter create fetch storage return new hash set client getter max parallel message fetch count 2 clientgetter createfetchstorage hashset clientgetter max_parallel_message_fetch_count override protected collection base client putter create insert storage return null baseclientputter createinsertstorage override public int get priority return native thread norm priority getpriority nativethread norm_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period override protected synchronized void iterate abort all transfers fixme i think the counterpart of this synchronized which ensures that message lists are not created when this lock is help might be missing check through the other code and add it where it s needed synchronized message list class todo obtain wot message lists only not all iterator message list message reference iter m message manager not downloaded message iterator while iter has next message list message reference ref iter next fetch message ref get message list ref fixme investigate whether this is fair i e whether it will not always try to download the same messages if downloading of some of them stalls for so long that the thread re iterates before on failure is called which results in the messages not being marked as undownloadable currently we do not mark messages as undownloadable anyway however on failure should do that in the future if fetch count max parallel message fetch count break abortalltransfers messagelists messagelist wotmessagelists messagelist messagereference mmessagemanager notdownloadedmessageiterator hasnext messagelist messagereference fetchmessage getmessagelist onfailure onfailure fetchcount max_parallel_message_fetch_count you have to synchronize on this code wot message fetcher code when using this function private void fetch message message list list message list message reference ref try fetch message list ref geturi catch exception e logger error this error while trying to fetch message ref geturi e wotmessagefetcher fetchmessage messagelist messagelist messagereference fetchmessage you have to synchronize on this code wot message fetcher code when using this function private void fetch message message list list freeneturi uri throws fetch exception todo if a single message is posted to multiple boards a message list message reference is stored for each boards because we query the message manager for message reference objects it might happen that this function is called twice for a single message on the one hand because of this we should check whether we are already downloading the given uri on the other hand most messages will be posted to only a single board so the overhead of creating a hash set freeneturi might not be worthwhile the message manager will ignore duplicates of already downloaded messages anyway fetch context fetch context m client get fetch context fetch context max splitfile block retries 2 fetch context max non splitfile retries 2 client getter g m client fetch uri 1 request client this fetch context g set priority class request starter update priority class pluginmanager defaults to interactive priority add fetch g m message lists put g list getid logger debug this trying to fetch message from uri wotmessagefetcher fetchmessage messagelist fetchexception messagelist messagereference messagemanager messagereference hashset messagemanager fetchcontext fetchcontext mclient getfetchcontext fetchcontext maxsplitfileblockretries fetchcontext maxnonsplitfileretries clientgetter mclient requestclient fetchcontext setpriorityclass requeststarter update_priority_class addfetch mmessagelists override public synchronized void on success fetch result result client getter state object container container logger debug this fetched message state geturi input stream input null wot message list list null try list wot message list m message manager get message list m message lists get state input result as bucket get input stream message message wot messagexml decode m message manager input list state geturi m message manager on message received message catch exception e logger error this parsing failed for message state geturi e if list null try m message manager on message fetch failed list get reference state geturi message list message fetch failed reference reason parsing failed catch no such message exception ex assert false logger error this should not happen ex finally closer close input remove fetch state fixme this was in the try block somewhere else in the ft wot code move it to finally there too fixme this will wake up the loop over and over again we need to store the previous parallel fetch count and if waking up does not increase the fetch count do not wake up again if fetch count min parallel message fetch count next iteration onsuccess fetchresult clientgetter objectcontainer inputstream wotmessagelist wotmessagelist mmessagemanager getmessagelist mmessagelists asbucket getinputstream wotmessagexml mmessagemanager mmessagemanager onmessagereceived mmessagemanager onmessagefetchfailed getreference messagelist messagefetchfailedreference parsingfailed nosuchmessageexception removefetch fetchcount min_parallel_message_fetch_count nextiteration override public synchronized void on failure fetch exception e client getter state object container container try switch e get mode case fetch exception data not found try wot message list list wot message list m message manager get message list m message lists get state m message manager on message fetch failed list get reference state geturi message list message fetch failed reference reason data not found catch exception ex no such message list no such message assert false logger error this should not happen ex finally logger error this dnf for message state geturi break case fetch exception cancelled logger debug this cancelled downloading message state geturi break default logger error this downloading message state geturi failed e break finally remove fetch state fixme this will wake up the loop over and over again we need to store the previous parallel fetch count and if waking up does not increase the fetch count do not wake up again if fetch count min parallel message fetch count next iteration onfailure fetchexception clientgetter objectcontainer getmode fetchexception data_not_found wotmessagelist wotmessagelist mmessagemanager getmessagelist mmessagelists mmessagemanager onmessagefetchfailed getreference messagelist messagefetchfailedreference datanotfound nosuchmessagelist nosuchmessage fetchexception removefetch fetchcount min_parallel_message_fetch_count nextiteration you have to synchronize on this code wot message fetcher code when using this function override protected void abort all transfers super abort all transfers m message lists clear wotmessagefetcher abortalltransfers abortalltransfers mmessagelists you have to synchronize on this code wot message fetcher code when using this function override protected void remove fetch client getter g super remove fetch g m message lists remove g wotmessagefetcher removefetch clientgetter removefetch mmessagelists not needed functions called for inserts override public void on generateduri freeneturi uri base client putter state object container container ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container override public void on success base client putter state object container container ongenerateduri baseclientputter objectcontainer onsuccess baseclientputter objectcontainer public void on success base client putter state object container container override public void on failure insert exception e base client putter state object container container onsuccess baseclientputter objectcontainer onfailure insertexception baseclientputter objectcontainer public void on failure insert exception e base client putter state object container container override public void on fetchable base client putter state object container container onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container override public void on major progress object container container onfetchable baseclientputter objectcontainer onmajorprogress objectcontainer public skeleton filter new color 0xffffffff skeletonfilter newcolor override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height int count 0 int black 0xff000000 int white 0xffffffff for int i 0 i iterations i count 0 for int pass 0 pass 2 pass for int y 1 y height 1 y int offset y width 1 for int x 1 x width 1 x int pixel in pixels offset if pixel black int table index 0 if in pixels offset width 1 black table index 1 if in pixels offset width black table index 2 if in pixels offset width 1 black table index 4 if in pixels offset 1 black table index 8 if in pixels offset width 1 black table index 16 if in pixels offset width black table index 32 if in pixels offset width 1 black table index 64 if in pixels offset 1 black table index 128 int code skeleton table table index if pass 1 if code 2 code 3 if colormap null pixel colormap get color float i iterations else pixel new color count else if code 1 code 3 if colormap null pixel colormap get color float i iterations else pixel new color count out pixels offset pixel if pass 0 in pixels out pixels out pixels new int width height if count 0 break return out pixels filterpixels inpixels transformedspace outpixels inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex inpixels tableindex skeletontable tableindex getcolor newcolor getcolor newcolor outpixels inpixels outpixels outpixels outpixels override public string to string return binary skeletonize tostring override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog protected put handler final simple manifest putter smp string name bucket data client metadata cm boolean getchk only super smp priority class smp client this persistent simple manifest putter this persistent this cm cm this data data insert block block new insert block data cm persistent freeneturi empty chk uri clone freeneturi empty chk uri this origsfi new single file inserter this this block false ctx false getchk only true null null false null early encode metadata null container handle null puthandler simplemanifestputter clientmetadata getchkonly priorityclass simplemanifestputter insertblock insertblock empty_chk_uri empty_chk_uri singlefileinserter getchkonly earlyencode containerhandle protected put handler final simple manifest putter smp string name freeneturi target client metadata cm super smp get priority class smp client this persistent simple manifest putter this persistent this cm cm this data null metadata m new metadata metadata simple redirect null null target cm metadata m if logminor logger minor this simple redirect metadata m origsfi null container handle null puthandler simplemanifestputter clientmetadata getpriorityclass simplemanifestputter simple_redirect containerhandle protected put handler final simple manifest putter smp string name string target in archive client metadata cm bucket data super smp get priority class smp client this persistent simple manifest putter this persistent this cm cm this data data this target in archive target in archive metadata m new metadata metadata archive internal redirect null null target in archive cm metadata m if logminor logger minor this internal redirect m origsfi null container handle null puthandler simplemanifestputter targetinarchive clientmetadata getpriorityclass simplemanifestputter targetinarchive targetinarchive archive_internal_redirect targetinarchive containerhandle public void start object container container client context context throws insert exception if origsfi null logger error this origsfi is null on start should be impossible new exception debug return if metadata null logger error this metdata metadata on start should be impossible new exception debug return client put state sfi synchronized this sfi origsfi current state sfi origsfi null if persistent container activate sfi 1 container store this sfi schedule container context if persistent container deactivate sfi 1 objectcontainer clientcontext insertexception clientputstate currentstate override public void cancel object container container client context context if logger should log logger minor this logger minor this cancelling this new exception debug client put state old state null synchronized this if cancelled return super cancel old state current state if persistent container store this if old state null container activate old state 1 if old state null old state cancel container context on failure new insert exception insert exception cancelled null container context objectcontainer clientcontext shouldlog clientputstate oldstate oldstate currentstate oldstate oldstate oldstate oldstate onfailure insertexception insertexception override public freeneturi geturi return null override public boolean is finished return simple manifest putter this finished cancelled simple manifest putter this cancelled isfinished simplemanifestputter simplemanifestputter public void on success client put state state object container container client context context if logminor logger minor this completed this if persistent container activate simple manifest putter this 1 container activate running put handlers 2 simple manifest putter this on fetchable this container client put state old state boolean inserted all files true synchronized this old state current state current state null synchronized simple manifest putter this if persistent container store this running put handlers remove this if persistent container ext store running put handlers 2 container activate put handlers waiting for metadata 2 if put handlers waiting for metadata contains this put handlers waiting for metadata remove this container ext store put handlers waiting for metadata 2 logger error this put handler was in waiting for metadata in on success on this for simple manifest putter this if persistent container deactivate put handlers waiting for metadata 1 container activate waiting for block sets 2 if waiting for block sets contains this waiting for block sets remove this container store waiting for block sets logger error this put handler was in waiting for block sets in on success on this for simple manifest putter this if persistent container deactivate waiting for block sets 1 container deactivate put handlers waiting for fetchable 1 container activate put handlers waiting for fetchable 2 if put handlers waiting for fetchable contains this put handlers waiting for fetchable remove this container ext store put handlers waiting for fetchable 2 not getting an on fetchable is not unusual just ignore it if logminor logger minor this put handler was in waiting for fetchable in on success on this for simple manifest putter this if persistent container deactivate put handlers waiting for fetchable 1 if running put handlers is empty if logminor logger minor this running put handlers running put handlers size for object o running put handlers boolean activated true if persistent activated container ext is active o if activated container activate o 1 logger minor this still running o if activated container deactivate o 1 inserted all files false if old state null old state state persistent container activate old state 1 old state remove from container context else if state null persistent state remove from container context if inserted all files inserted all files container context if persistent container deactivate running put handlers 1 container deactivate simple manifest putter this 1 onsuccess clientputstate objectcontainer clientcontext simplemanifestputter runningputhandlers simplemanifestputter onfetchable clientputstate oldstate insertedallfiles oldstate currentstate currentstate simplemanifestputter runningputhandlers runningputhandlers puthandlerswaitingformetadata puthandlerswaitingformetadata puthandlerswaitingformetadata puthandlerswaitingformetadata puthandler waitingformetadata onsuccess simplemanifestputter puthandlerswaitingformetadata waitingforblocksets waitingforblocksets waitingforblocksets waitingforblocksets puthandler waitingforblocksets onsuccess simplemanifestputter waitingforblocksets puthandlerswaitingforfetchable puthandlerswaitingforfetchable puthandlerswaitingforfetchable puthandlerswaitingforfetchable puthandlerswaitingforfetchable onfetchable puthandler waitingforfetchable onsuccess simplemanifestputter puthandlerswaitingforfetchable runningputhandlers isempty runningputhandlers runningputhandlers isactive insertedallfiles oldstate oldstate oldstate oldstate removefrom removefrom insertedallfiles insertedallfiles runningputhandlers simplemanifestputter public void on failure insert exception e client put state state object container container client context context client put state old state synchronized this old state current state current state null if old state null old state state persistent container activate old state 1 old state remove from container context else if state null persistent state remove from container context if logminor logger minor this failed this e e if persistent container activate simple manifest putter this 1 fail e container context if persistent container deactivate simple manifest putter this 1 onfailure insertexception clientputstate objectcontainer clientcontext clientputstate oldstate oldstate currentstate currentstate oldstate oldstate oldstate oldstate removefrom removefrom simplemanifestputter simplemanifestputter public void on encode base client key key client put state state object container container client context context if logminor logger minor this on encode key for this if metadata null the file was too small to have its own metadata we get this instead so we make the key into metadata if persistent container activate key 5 container activate simple manifest putter this 1 metadata m new metadata metadata simple redirect null null key geturi cm on metadata m null container context if persistent container deactivate simple manifest putter this 1 onencode baseclientkey clientputstate objectcontainer clientcontext onencode simplemanifestputter simple_redirect onmetadata simplemanifestputter the caller of on transition removes the old state so we don t have to however in on success or on failure we need to remove the new state even if what is passed in is different in which case we remove that too public void on transition client put state old state client put state new state object container container if new state null throw new null pointer exception on transition is not responsible for removing the old state the caller is synchronized this if current state old state current state new state if persistent container store this if logminor logger minor this on transition cur current state old old state new new state for this return logger error this ignoring on transition cur current state old old state new new state for this ontransition onsuccess onfailure ontransition clientputstate oldstate clientputstate newstate objectcontainer newstate nullpointerexception ontransition currentstate oldstate currentstate newstate ontransition currentstate oldstate newstate ontransition currentstate oldstate newstate public void on metadata metadata m client put state state object container container client context context if logminor logger minor this assigning metadata m for this from state persistent persistent new exception debug if metadata null logger error this reassigning metadata new exception debug return metadata m if persistent container activate simple manifest putter this 1 container activate put handlers waiting for metadata 2 boolean all metadatas false synchronized simple manifest putter this put handlers waiting for metadata remove this if persistent container ext store put handlers waiting for metadata 2 container store this all metadatas put handlers waiting for metadata is empty if all metadatas if logminor logger minor this still waiting for metadata put handlers waiting for metadata size if all metadatas will resolve etc got all metadata container context else resolve now to speed up the insert try byte buf m write to byte array if buf length metadata max size in manifest throw new metadata unresolved exception new metadata m too big catch metadata unresolved exception e try resolve e container context catch io exception e1 fail new insert exception insert exception bucket error e1 null container context return catch insert exception e1 fail e1 container context if persistent container deactivate put handlers waiting for metadata 1 container deactivate simple manifest putter this 1 onmetadata clientputstate objectcontainer clientcontext simplemanifestputter puthandlerswaitingformetadata allmetadatas simplemanifestputter puthandlerswaitingformetadata puthandlerswaitingformetadata allmetadatas puthandlerswaitingformetadata isempty allmetadatas puthandlerswaitingformetadata allmetadatas gotallmetadata writetobytearray max_size_in_manifest metadataunresolvedexception metadataunresolvedexception ioexception insertexception insertexception bucket_error insertexception puthandlerswaitingformetadata simplemanifestputter override public void add block object container container if persistent container activate simple manifest putter this 1 simple manifest putter this add block container if persistent container deactivate simple manifest putter this 1 addblock objectcontainer simplemanifestputter simplemanifestputter addblock simplemanifestputter override public void add blocks int num object container container if persistent container activate simple manifest putter this 1 simple manifest putter this add blocks num container if persistent container deactivate simple manifest putter this 1 addblocks objectcontainer simplemanifestputter simplemanifestputter addblocks simplemanifestputter override public void completed block boolean dont notify object container container client context context if persistent container activate simple manifest putter this 1 simple manifest putter this completed block dont notify container context if persistent container deactivate simple manifest putter this 1 completedblock dontnotify objectcontainer clientcontext simplemanifestputter simplemanifestputter completedblock dontnotify simplemanifestputter override public void failed block object container container client context context if persistent container activate simple manifest putter this 1 simple manifest putter this failed block container context if persistent container deactivate simple manifest putter this 1 failedblock objectcontainer clientcontext simplemanifestputter simplemanifestputter failedblock simplemanifestputter override public void fatally failed block object container container client context context if persistent container activate simple manifest putter this 1 simple manifest putter this fatally failed block container context if persistent container deactivate simple manifest putter this 1 fatallyfailedblock objectcontainer clientcontext simplemanifestputter simplemanifestputter fatallyfailedblock simplemanifestputter override public void add must succeed blocks int blocks object container container if persistent container activate simple manifest putter this 1 simple manifest putter this add must succeed blocks blocks container if persistent container deactivate simple manifest putter this 1 addmustsucceedblocks objectcontainer simplemanifestputter simplemanifestputter addmustsucceedblocks simplemanifestputter override public void notify clients object container container client context context if persistent container activate simple manifest putter this 1 simple manifest putter this notify clients container context if persistent container deactivate simple manifest putter this 1 notifyclients objectcontainer clientcontext simplemanifestputter simplemanifestputter notifyclients simplemanifestputter public void on block set finished client put state state object container container client context context if persistent container activate simple manifest putter this 1 container activate waiting for block sets 2 boolean all block sets false synchronized simple manifest putter this waiting for block sets remove this if persistent container store waiting for block sets all block sets waiting for block sets is empty if all block sets simple manifest putter this block set finalized container context if persistent container deactivate waiting for block sets 1 container deactivate simple manifest putter this 1 onblocksetfinished clientputstate objectcontainer clientcontext simplemanifestputter waitingforblocksets allblocksets simplemanifestputter waitingforblocksets waitingforblocksets allblocksets waitingforblocksets isempty allblocksets simplemanifestputter blocksetfinalized waitingforblocksets simplemanifestputter override public void on major progress object container container if persistent container activate simple manifest putter this 1 simple manifest putter this on major progress container if persistent container deactivate simple manifest putter this 1 onmajorprogress objectcontainer simplemanifestputter simplemanifestputter onmajorprogress simplemanifestputter public void on fetchable client put state state object container container if persistent container activate simple manifest putter this 1 simple manifest putter this on fetchable this container if persistent container deactivate simple manifest putter this 1 onfetchable clientputstate objectcontainer simplemanifestputter simplemanifestputter onfetchable simplemanifestputter override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void clear metadata object container container metadata null if persistent container store this clearmetadata objectcontainer override public void remove from object container container client context context if logminor logger minor this removing this client put state oldsfi client put state old state synchronized this oldsfi origsfi old state current state origsfi null current state null if oldsfi null logger error this origsfi is set in remove from on this for simple manifest putter this new exception debug container activate oldsfi 1 oldsfi cancel container context oldsfi remove from container context if old state oldsfi old state null if old state null logger error this current state is set in remove from on this for simple manifest putter this new exception debug container activate old state 1 old state cancel container context old state remove from container context if cm null container activate cm 5 cm remove from container if metadata null possible if cancelled logger normal this metadata is set in remove from on this for simple manifest putter this container activate metadata 1 metadata remove from container data is responsibility of original caller usually client put dir we don t support free data atm super remove from container context removefrom objectcontainer clientcontext clientputstate clientputstate oldstate oldstate currentstate currentstate removefrom simplemanifestputter removefrom oldstate oldstate oldstate currentstate removefrom simplemanifestputter oldstate oldstate oldstate removefrom removefrom removefrom simplemanifestputter removefrom clientputdir freedata removefrom public boolean object can new object container container if cancelled logger error this storing this when already cancelled new exception error return false if logminor logger minor this storing this activated container ext is active this stored container ext is stored this new exception debug return true objectcannew objectcontainer isactive isstored override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext public simple manifest putter client callback cb hash map string object manifest elements short prio class freeneturi target string default name insert context ctx boolean getchk only request client client context boolean early encode super prio class client context this default name default name if client persistent this targeturi target clone else this targeturi target this cb cb this ctx ctx this getchk only getchk only this early encode early encode put handlers by name new hash map string object running put handlers new hash set put handler put handlers waiting for metadata new hash set put handler put handlers waiting for fetchable new hash set put handler waiting for block sets new hash set put handler metadata putters by metadata new hash map metadata client put state metadata putters unfetchable new hash map metadata client put state elements to put in archive new array list put handler make put handlers manifest elements put handlers by name check zips simplemanifestputter clientcallback hashmap manifestelements prioclass defaultname insertcontext getchkonly requestclient clientcontext earlyencode prioclass clientcontext defaultname defaultname getchkonly getchkonly earlyencode earlyencode puthandlersbyname hashmap runningputhandlers hashset puthandler puthandlerswaitingformetadata hashset puthandler puthandlerswaitingforfetchable hashset puthandler waitingforblocksets hashset puthandler metadataputtersbymetadata hashmap clientputstate metadataputtersunfetchable hashmap clientputstate elementstoputinarchive arraylist puthandler makeputhandlers manifestelements puthandlersbyname checkzips private void check zips if there are too few files in the zip then insert them directly instead fixme do something checkzips public void start object container container client context context throws insert exception if logminor logger minor this starting this persistence persistent put handler running if persistent container activate running put handlers 2 synchronized this running running put handlers to array new put handler running put handlers size try boolean persistent persistent this might get deactivated for int i 0 i running length i running i start container context if persistent container ext is active this container activate this 1 if logminor logger minor this started i of running length if is finished if logminor logger minor this already finished killing start on this return if logminor logger minor this started running length put handler s for this if running length 0 inserted all files true if persistent container store this got all metadata container context catch insert exception e synchronized this finished true cancel and finish container context throw e objectcontainer clientcontext insertexception puthandler runningputhandlers runningputhandlers toarray puthandler runningputhandlers isactive isfinished puthandler insertedallfiles gotallmetadata insertexception cancelandfinish protected void make put handlers hash map string object manifest elements hash map string object put handlers by name make put handlers manifest elements put handlers by name makeputhandlers hashmap manifestelements hashmap puthandlersbyname makeputhandlers manifestelements puthandlersbyname private void make put handlers hash map string object manifest elements hash map string object put handlers by name string zip prefix iterator string it manifest elements key set iterator while it has next string name it next object o manifest elements get name if o instanceof hash map hash map string object sub map new hash map string object put handlers by name put name sub map make put handlers hash map string object o sub map zip prefix name if logger should log logger debug this logger debug this sub map for name sub map size elements from hash map o size else manifest element element manifest element o string mime type element mime override if mime type null mime type defaultmime types guessmime type name true client metadata cm if mime type null mime type equals defaultmime types default mime type cm null else cm new client metadata mime type put handler ph bucket data element data if element targeturi null ph new put handler this name element targeturi cm just a placeholder don t actually run it else decide whether to put it in the zip fixme support multiple zi ps and size limits fixme support better heuristics zip is slightly more compact can use this formula int sz int data size 40 element full name length tar is less compact but with a chained compressor is far more efficient due to inter file compression int sz 512 int data size 511 512 512 if data size 65536 tar pads to next 10k and has 1k end headers fixme this also needs to include the metadata fixme no way to know at this point how big that is need major refactoring to make this work for now just assume 64k will cover it bytes on zip sz 2038 64 1024 totally dumb heuristic bytes on zip sz put it in the zip if logminor logger minor this putting into zip name ph new put handler this name zip prefix element full name cm data if logminor logger minor this putting file into container element full name ph elements to put in archive add ph number of files total size data size else ph new put handler this name data cm getchk only running put handlers add ph put handlers waiting for metadata add ph put handlers waiting for fetchable add ph if logminor logger minor this inserting separately as put handler name ph persistent ph persistent ph persistent persistent number of files total size data size put handlers by name put name ph makeputhandlers hashmap manifestelements hashmap puthandlersbyname zipprefix manifestelements keyset hasnext manifestelements hashmap hashmap submap hashmap puthandlersbyname submap makeputhandlers hashmap submap zipprefix shouldlog submap hashmap manifestelement manifestelement mimetype mimeoverride mimetype mimetype defaultmimetypes guessmimetype clientmetadata mimetype mimetype defaultmimetypes default_mime_type clientmetadata mimetype puthandler puthandler zips fullname bytesonzip bytesonzip puthandler zipprefix fullname fullname elementstoputinarchive numberoffiles totalsize puthandler getchkonly runningputhandlers puthandlerswaitingformetadata puthandlerswaitingforfetchable puthandler numberoffiles totalsize puthandlersbyname override public freeneturi geturi return finaluri override public synchronized boolean is finished return finished cancelled isfinished public void run object container container client context context context job runner remove restart job this native thread norm priority container container activate simple manifest putter this 1 inner got all metadata container context container deactivate simple manifest putter this 1 objectcontainer clientcontext jobrunner removerestartjob nativethread norm_priority simplemanifestputter innergotallmetadata simplemanifestputter called when we have metadata for all the put handler s this does not necessarily mean we can immediately insert the final metadata since if these metadata s are too big they will need to be inserted separately see resolve and start base param container param context private void got all metadata object container container client context context this can be huge run it on its own transaction to minimize the build up of stuff to commit and maximise the opportunities for garbage collection if persistent container activate run got all metadata 1 need to activate this context job runner queue restart job run got all metadata native thread norm priority container false context job runner queue run got all metadata native thread norm priority false else inner got all metadata null context puthandler resolveandstartbase gotallmetadata objectcontainer clientcontext rungotallmetadata jobrunner queuerestartjob rungotallmetadata nativethread norm_priority jobrunner rungotallmetadata nativethread norm_priority innergotallmetadata generate the global metadata and then call resolve and start base param container param context private void inner got all metadata object container container client context context cor 1582 we have to carefully avoid activating any hashmap to depth 2 however we cannot afford the memory to activate everything to max depth in advance it looks like activating the hashmap at the top to depth 2 and then activating the sub maps to depth 2 as well works if persistent container activate put handlers by name 2 depth 2 to load elements if logminor logger minor this got all metadata hash map string object names to byte arrays new hash map string object names to byte arrays put handlers by name names to byte arrays container if default name null metadata meta metadata names to byte arrays get default name if meta null fail new insert exception insert exception invalid uri default name default name does not exist null container context return names to byte arrays put meta else for int j 0 j default default names length j string name default default names j metadata meta metadata names to byte arrays get name if meta null names to byte arrays put meta break base metadata metadata mk redirection manifest with metadata names to byte arrays if persistent container store base metadata container store this resolve and start base container context resolveandstartbase innergotallmetadata objectcontainer clientcontext puthandlersbyname hashmap namestobytearrays hashmap namestobytearrays puthandlersbyname namestobytearrays defaultname namestobytearrays defaultname insertexception insertexception invalid_uri defaultname namestobytearrays defaultdefaultnames defaultdefaultnames namestobytearrays namestobytearrays basemetadata mkredirectionmanifestwithmetadata namestobytearrays basemetadata resolveandstartbase attempt to insert the base metadata and the container if the base metadata cannot be resolved try to resolve it start inserts for each part that cannot be resolved and wait for them to generate ur is that can be incorporated into the metadata this method will then be called again and will complete or do more resolutions as necessary param container param context private void resolve and start base object container container client context context bucket bucket null synchronized this if has resolved base return while true try if persistent container activate base metadata integer max value bucket bucket tools make immutable bucket context get bucket factory persistent base metadata write to byte array if logminor logger minor this metadata bucket is bucket size bytes long break catch io exception e fail new insert exception insert exception bucket error e null container context return catch metadata unresolved exception e try start the insert for the sub metadata eventually it will generate a uri and call on encode which will call back here if logminor logger minor this main metadata needs resolving e resolve e container context if persistent container deactivate base metadata 1 return catch io exception e1 if persistent container deactivate base metadata 1 fail new insert exception insert exception bucket error e null container context return catch insert exception e2 if persistent container deactivate base metadata 1 fail e2 container context return if bucket null return synchronized this if has resolved base return has resolved base true if persistent container store this container activate elements to put in archive 2 insert block block boolean is metadata true boolean insert as archive manifest false archive type archive type null if elements to put in archive is empty there is an archive to insert we want to include the metadata we have the metadata fortunately enough because everything has been resolve d so all we need to do is create the actual archive try bucket output bucket context get bucket factory persistent make bucket base metadata data length todo try both maybe not worth it archive type archive type get default string mime type archive type archive type tar create tar bucket bucket output bucket container create zip bucket bucket output bucket container bucket free if persistent bucket remove from container if logminor logger minor this we are using archive type now we have to insert the archive we have generated can we just insert it and not bother with a redirect to it thereby exploiting implicit manifest support which will pick up on metadata we ought to be able to if persistent container activate targeturi 5 block new insert block output bucket new client metadata mime type persistent targeturi clone targeturi is metadata false insert as archive manifest true catch io exception e fail new insert exception insert exception bucket error e null container context if persistent container deactivate base metadata 1 return else block new insert block bucket null persistent targeturi clone targeturi single file inserter metadata inserter try metadata inserter new single file inserter this this block is metadata ctx archive type archive type zip getchk only false base metadata archive type true null early encode if logminor logger minor this inserting main metadata metadata inserter for base metadata if persistent container activate metadata putters by metadata 2 container activate metadata putters unfetchable 2 this metadata putters by metadata put base metadata metadata inserter metadata putters unfetchable put base metadata metadata inserter if persistent container ext store metadata putters by metadata 2 container ext store metadata putters unfetchable 2 container deactivate metadata putters by metadata 1 container deactivate metadata putters unfetchable 1 container deactivate base metadata 1 metadata inserter start null container context catch insert exception e fail e container context return if persistent container deactivate metadata inserter 1 container deactivate elements to put in archive 1 uris resolveandstartbase objectcontainer clientcontext hasresolvedbase basemetadata max_value buckettools makeimmutablebucket getbucketfactory basemetadata writetobytearray ioexception insertexception insertexception bucket_error metadataunresolvedexception onencode basemetadata ioexception basemetadata insertexception insertexception bucket_error insertexception basemetadata hasresolvedbase hasresolvedbase elementstoputinarchive insertblock ismetadata insertasarchivemanifest archive_type archivetype elementstoputinarchive isempty outputbucket getbucketfactory makebucket basemetadata datalength archivetype archive_type getdefault mimetype archivetype archive_type createtarbucket outputbucket createzipbucket outputbucket removefrom archivetype insertblock outputbucket clientmetadata mimetype ismetadata insertasarchivemanifest ioexception insertexception insertexception bucket_error basemetadata insertblock singlefileinserter metadatainserter metadatainserter singlefileinserter ismetadata archivetype archive_type getchkonly basemetadata archivetype earlyencode metadatainserter basemetadata metadataputtersbymetadata metadataputtersunfetchable metadataputtersbymetadata basemetadata metadatainserter metadataputtersunfetchable basemetadata metadatainserter metadataputtersbymetadata metadataputtersunfetchable metadataputtersbymetadata metadataputtersunfetchable basemetadata metadatainserter insertexception metadatainserter elementstoputinarchive private string create tar bucket bucket input bucket bucket output bucket object container container throws io exception if logminor logger minor this create a tar bucket output stream os new buffered output stream output bucket get output stream tar output stream taros new tar output stream os taros set long file mode tar output stream longfile gnu tar entry ze for put handler ph elements to put in archive if persistent container activate ph 1 container activate ph data 1 if logminor logger minor this putting into tar ph data length ph data size name ph target in archive ze new tar entry ph target in archive ze set mod time 0 long size ph data size ze set size size taros put next entry ze bucket tools copy to ph data taros size taros close entry add metadata after the rest if logminor logger minor this putting metadata into tar length is input bucket size ze new tar entry metadata ze set mod time 0 1 now 0 1970 long size input bucket size ze set size size taros put next entry ze bucket tools copy to input bucket taros size taros close entry both finish and close are necessary taros finish taros flush taros close if logminor logger minor this archive size is output bucket size return archive type tar mime types 0 createtarbucket inputbucket outputbucket objectcontainer ioexception outputstream bufferedoutputstream outputbucket getoutputstream taroutputstream taroutputstream setlongfilemode taroutputstream longfile_gnu tarentry puthandler elementstoputinarchive targetinarchive tarentry targetinarchive setmodtime setsize putnextentry buckettools copyto closeentry inputbucket tarentry setmodtime inputbucket setsize putnextentry buckettools copyto inputbucket closeentry outputbucket archive_type mimetypes private string create zip bucket bucket input bucket bucket output bucket object container container throws io exception if logminor logger minor this create a zip bucket output stream os new buffered output stream output bucket get output stream zip output stream zos new zip output stream os zip entry ze for iterator put handler i elements to put in archive iterator i has next put handler ph i next if persistent container activate ph 1 container activate ph data 1 ze new zip entry ph target in archive ze set time 0 zos put next entry ze bucket tools copy to ph data zos ph data size zos close entry add metadata after the rest ze new zip entry metadata ze set time 0 1 now 0 1970 zos put next entry ze bucket tools copy to input bucket zos input bucket size zos close entry both finish and close are necessary zos finish zos flush zos close return archive type zip mime types 0 createzipbucket inputbucket outputbucket objectcontainer ioexception outputstream bufferedoutputstream outputbucket getoutputstream zipoutputstream zipoutputstream zipentry puthandler elementstoputinarchive hasnext puthandler zipentry targetinarchive settime putnextentry buckettools copyto closeentry zipentry settime putnextentry buckettools copyto inputbucket inputbucket closeentry archive_type mimetypes start inserts for unresolved too big metadata s eventually these will call back with an on encode meaning they have the chk and we can progress to resolve and start base param e param container param context return throws insert exception throws io exception private void resolve metadata unresolved exception e object container container client context context throws insert exception io exception metadata metas e must resolve if persistent container activate metadata putters by metadata 2 for int i 0 i metas length i metadata m metas i if persistent container activate m 100 if logminor logger minor this resolving m synchronized this if metadata putters by metadata contains key m if logminor logger minor this already started insert for m in resolve for metas length metadata s continue if m is resolved logger error this already resolved m in resolve race condition if persistent container deactivate m 1 continue try bucket b m to bucket context get bucket factory persistent insert block ib new insert block b null persistent freeneturi empty chk uri clone freeneturi empty chk uri single file inserter metadata inserter new single file inserter this this ib true ctx false getchk only false m null true null early encode if logminor logger minor this inserting subsidiary metadata metadata inserter for m synchronized this this metadata putters by metadata put m metadata inserter metadata inserter start null container context if persistent container deactivate metadata inserter 1 container deactivate m 1 catch metadata unresolved exception e1 resolve e1 container context container deactivate m 1 if persistent container ext store metadata putters by metadata 2 container deactivate metadata putters by metadata 1 onencode resolveandstartbase insertexception ioexception metadataunresolvedexception objectcontainer clientcontext insertexception ioexception mustresolve metadataputtersbymetadata metadataputtersbymetadata containskey isresolved tobucket getbucketfactory insertblock insertblock empty_chk_uri empty_chk_uri singlefileinserter metadatainserter singlefileinserter getchkonly earlyencode metadatainserter metadataputtersbymetadata metadatainserter metadatainserter metadatainserter metadataunresolvedexception metadataputtersbymetadata metadataputtersbymetadata private void names to byte arrays hash map string object put handlers by name hash map string object names to byte arrays object container container iterator string i put handlers by name key set iterator while i has next string name i next object o put handlers by name get name if o instanceof put handler put handler ph put handler o if persistent container activate ph 1 metadata meta ph metadata if ph metadata null logger error this metadata for name ph is null else ph clear metadata container if persistent container activate meta 100 logger minor this putting name names to byte arrays put name meta if logminor logger minor this putting put handler into base metadata ph name name else if o instanceof hash map hash map string object sub map new hash map string object if persistent container activate o 2 depth 1 doesn t load the elements names to byte arrays put name sub map if logminor logger minor this putting hashmap into base metadata name size hash map o size active container null null boolean to string container ext is active o logger minor this putting directory name names to byte arrays hash map string object o sub map container else throw new illegal state exception namestobytearrays hashmap puthandlersbyname hashmap namestobytearrays objectcontainer puthandlersbyname keyset hasnext puthandlersbyname puthandler puthandler puthandler clearmetadata namestobytearrays puthandler hashmap hashmap submap hashmap namestobytearrays submap hashmap tostring isactive namestobytearrays hashmap submap illegalstateexception private void inserted all files object container container client context context if logminor logger minor this inserted all files synchronized this inserted all files true if finished cancelled if logminor logger minor this already finished finished cancelled if persistent container store this return if inserted manifest if logminor logger minor this haven t inserted manifest if persistent container store this return finished true if persistent container store this complete container context insertedallfiles objectcontainer clientcontext insertedallfiles insertedmanifest private void complete object container container client context context fixme we could remove the put handlers after inserting all files but not having finished the insert of the manifest however it would complicate matters for no real gain in most cases also doing it this way means we don t need to worry about if persistent remove put handlers container context boolean deactivatecb false if persistent deactivatecb container ext is active cb container activate cb 1 cb on success this container if deactivatecb container deactivate cb 1 objectcontainer clientcontext removeputhandlers isactive onsuccess private void fail insert exception e object container container client context context cancel all then call the callback synchronized this if finished return finished true cancel and finish container context if persistent remove put handlers container context if persistent container activate cb 1 cb on failure e this container insertexception objectcontainer clientcontext cancelandfinish removeputhandlers onfailure private void remove put handlers object container container client context context container activate put handlers by name 2 container activate running put handlers 2 container activate put handlers waiting for metadata 2 container activate waiting for block sets 2 container activate put handlers waiting for fetchable 2 container activate elements to put in archive 2 remove put handlers by name container context put handlers by name put handlers by name null if running put handlers is empty logger error this running put handlers not part of put handlers by name running put handlers size in remove put handlers on this new exception error put handler handlers running put handlers to array new put handler running put handlers size for put handler handler handlers container activate handler 1 logger error this still running but not in put handlers by name handler handler cancel handler remove from container context running put handlers clear if put handlers waiting for metadata is empty logger error this put handlers waiting for metadata not part of put handlers by name put handlers waiting for metadata size in remove put handlers on this new exception error put handler handlers put handlers waiting for metadata to array new put handler put handlers waiting for metadata size for put handler handler handlers container activate handler 1 logger error this still waiting for metadata but not in put handlers by name handler handler cancel handler remove from container context put handlers waiting for metadata clear if waiting for block sets is empty logger error this put handlers waiting for block sets not part of put handlers by name waiting for block sets size in remove put handlers on this new exception error put handler handlers waiting for block sets to array new put handler waiting for block sets size for put handler handler handlers container activate handler 1 logger error this still waiting for block set but not in put handlers by name handler handler cancel handler remove from container context waiting for block sets clear if put handlers waiting for fetchable is empty logger error this put handlers waiting for fetchable not part of put handlers by name put handlers waiting for fetchable size in remove put handlers on this new exception error put handler handlers put handlers waiting for fetchable to array new put handler put handlers waiting for fetchable size for put handler handler handlers container activate handler 1 logger error this still waiting for fetchable but not in put handlers by name handler handler cancel handler remove from container context put handlers waiting for fetchable clear if elements to put in archive is empty logger error this elements to put in archive not part of put handlers by name elements to put in archive size in remove put handlers on this new exception error put handler handlers elements to put in archive to array new put handler elements to put in archive size for put handler handler handlers container activate handler 1 logger error this to put in archive but not in put handlers by name handler handler remove from container context elements to put in archive clear container delete running put handlers container delete put handlers waiting for metadata container delete waiting for block sets container delete put handlers waiting for fetchable container delete elements to put in archive running put handlers null put handlers waiting for metadata null waiting for block sets null put handlers waiting for fetchable null elements to put in archive null container store this removeputhandlers objectcontainer clientcontext puthandlersbyname runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable elementstoputinarchive removeputhandlersbyname puthandlersbyname puthandlersbyname runningputhandlers isempty puthandlersbyname runningputhandlers removeputhandlers puthandler runningputhandlers toarray puthandler runningputhandlers puthandler puthandlersbyname removefrom runningputhandlers puthandlerswaitingformetadata isempty puthandlersbyname puthandlerswaitingformetadata removeputhandlers puthandler puthandlerswaitingformetadata toarray puthandler puthandlerswaitingformetadata puthandler puthandlersbyname removefrom puthandlerswaitingformetadata waitingforblocksets isempty puthandlersbyname waitingforblocksets removeputhandlers puthandler waitingforblocksets toarray puthandler waitingforblocksets puthandler puthandlersbyname removefrom waitingforblocksets puthandlerswaitingforfetchable isempty puthandlersbyname puthandlerswaitingforfetchable removeputhandlers puthandler puthandlerswaitingforfetchable toarray puthandler puthandlerswaitingforfetchable puthandler puthandlersbyname removefrom puthandlerswaitingforfetchable elementstoputinarchive isempty puthandlersbyname elementstoputinarchive removeputhandlers puthandler elementstoputinarchive toarray puthandler elementstoputinarchive puthandler puthandlersbyname removefrom elementstoputinarchive runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable elementstoputinarchive runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable elementstoputinarchive remove all put handler s from the given put handlers by name sub map remove the put handler s themselves also remove them from and complain about running put handlers put handlers waiting for metadata waiting for block sets put handlers waiting for fetchable which must have been activated by the caller param container param put handlers by name private void remove put handlers by name object container container client context context hash map string object put handlers by name if logminor logger minor this remove put handlers by name on this map size put handlers by name size for map entry string object entry put handlers by name entry set string key entry get key object value entry get value if value instanceof put handler put handler handler put handler value container activate handler 1 if running put handlers remove handler container ext store running put handlers 2 if put handlers waiting for metadata remove handler container ext store put handlers waiting for metadata 2 if waiting for block sets remove handler container ext store waiting for block sets 2 if put handlers waiting for fetchable remove handler container ext store put handlers waiting for fetchable 2 if elements to put in archive remove handler container ext store elements to put in archive 2 handler remove from container context else hash map string object sub map hash map string object value container activate sub map 2 remove put handlers by name container context sub map container delete key put handlers by name clear container delete put handlers by name puthandler puthandlersbyname puthandler runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable puthandlersbyname removeputhandlersbyname objectcontainer clientcontext hashmap puthandlersbyname removeputhandlersbyname puthandlersbyname puthandlersbyname entryset getkey getvalue puthandler puthandler puthandler runningputhandlers runningputhandlers puthandlerswaitingformetadata puthandlerswaitingformetadata waitingforblocksets waitingforblocksets puthandlerswaitingforfetchable puthandlerswaitingforfetchable elementstoputinarchive elementstoputinarchive removefrom hashmap submap hashmap submap removeputhandlersbyname submap puthandlersbyname puthandlersbyname cancel all running inserters private void cancel and finish object container container client context context put handler running boolean persistent persistent if persistent container activate running put handlers 2 synchronized this running running put handlers to array new put handler running put handlers size if logminor logger minor this put handler s to cancel running length for put handler putter running boolean active true if persistent active container ext is active putter if active container activate putter 1 putter cancel container context if active container deactivate putter 1 if persistent container activate this 1 client put state running meta if persistent container activate metadata putters by metadata 2 synchronized this running meta metadata putters by metadata values to array new client put state metadata putters by metadata size if logminor logger minor this metadata putters to cancel running meta length for client put state putter running meta boolean active true if persistent active container ext is active putter if active container activate putter 1 putter cancel container context if active container deactivate putter 1 if persistent container activate this 1 cancelandfinish objectcontainer clientcontext puthandler runningputhandlers runningputhandlers toarray puthandler runningputhandlers puthandler puthandler isactive clientputstate runningmeta metadataputtersbymetadata runningmeta metadataputtersbymetadata toarray clientputstate metadataputtersbymetadata runningmeta clientputstate runningmeta isactive override public void cancel object container container client context context synchronized this if finished return if super cancel return if persistent container store this fail new insert exception insert exception cancelled container context objectcontainer clientcontext insertexception insertexception public void on success client put state state object container container client context context if persistent container activate metadata putters by metadata 2 boolean fin false client put state old state null metadata token metadata state get token synchronized this if persistent container activate token 1 boolean present metadata putters by metadata contains key token if present old state metadata putters by metadata remove token if persistent container activate metadata putters unfetchable 2 if metadata putters unfetchable contains key token metadata putters unfetchable remove token if persistent container ext store metadata putters unfetchable 2 if metadata putters by metadata is empty if logminor logger minor this still running metadata putters metadata putters by metadata size else logger minor this inserted manifest successfully on this state inserted manifest true if finished if logminor logger minor this already finished if persistent container store this else if inserted all files if logminor logger minor this not inserted all files if persistent container store this else finished true if persistent container store this fin true if token base metadata token remove from container if persistent container ext store metadata putters by metadata 2 container deactivate metadata putters by metadata 1 state remove from container context if old state state old state null container activate old state 1 old state remove from container context if fin complete container context onsuccess clientputstate objectcontainer clientcontext metadataputtersbymetadata clientputstate oldstate gettoken metadataputtersbymetadata containskey oldstate metadataputtersbymetadata metadataputtersunfetchable metadataputtersunfetchable containskey metadataputtersunfetchable metadataputtersunfetchable metadataputtersbymetadata isempty metadataputtersbymetadata insertedmanifest insertedallfiles basemetadata removefrom metadataputtersbymetadata metadataputtersbymetadata removefrom oldstate oldstate oldstate oldstate removefrom public void on failure insert exception e client put state state object container container client context context if persistent container activate metadata putters by metadata 2 client put state old state null metadata token metadata state get token synchronized this if persistent container activate token 1 boolean present metadata putters by metadata contains key token if present old state metadata putters by metadata remove token if persistent container activate metadata putters unfetchable 2 if metadata putters unfetchable contains key token metadata putters unfetchable remove token container ext store metadata putters unfetchable 2 if token base metadata token remove from container if persistent container ext store metadata putters by metadata 2 container deactivate metadata putters by metadata 1 state remove from container context if old state state old state null container activate old state 1 old state remove from container context fail e container context onfailure insertexception clientputstate objectcontainer clientcontext metadataputtersbymetadata clientputstate oldstate gettoken metadataputtersbymetadata containskey oldstate metadataputtersbymetadata metadataputtersunfetchable metadataputtersunfetchable containskey metadataputtersunfetchable metadataputtersunfetchable basemetadata removefrom metadataputtersbymetadata metadataputtersbymetadata removefrom oldstate oldstate oldstate oldstate removefrom public void on encode base client key key client put state state object container container client context context if state get token base metadata this finaluri key geturi if logminor logger minor this got metadata key finaluri if persistent container activate cb 1 cb on generateduri persistent finaluri clone finaluri this container if persistent container deactivate cb 1 if persistent container store this else it s a sub metadata metadata m metadata state get token if persistent container activate m 2 m resolve key geturi if persistent container store m if logminor logger minor this resolved m key geturi resolve and start base container context onencode baseclientkey clientputstate objectcontainer clientcontext gettoken basemetadata ongenerateduri gettoken resolveandstartbase public void on transition client put state old state client put state new state object container container metadata m metadata old state get token if persistent container activate m 100 container activate metadata putters unfetchable 2 container activate metadata putters by metadata 2 synchronized this if metadata putters by metadata contains key m client put state prev state metadata putters by metadata get m if prev state old state if logminor logger minor this ignoring transition in this for metadata putter old state new state because current for m is prev state container deactivate metadata putters unfetchable 1 container deactivate metadata putters by metadata 1 return if persistent container store new state metadata putters by metadata put m new state if persistent container ext store metadata putters by metadata 2 if logminor logger minor this metadata putter transition old state new state if metadata putters unfetchable contains key m metadata putters unfetchable put m new state if persistent container ext store metadata putters unfetchable 2 if logminor logger minor this unfetchable metadata putter transition old state new state if logminor logger minor this transition old state new state else logger error this on transition but metadata putters by metadata does not contain metadata tag m for old state should new state if persistent container deactivate m 100 container deactivate metadata putters unfetchable 2 container deactivate metadata putters by metadata 2 ontransition clientputstate oldstate clientputstate newstate objectcontainer oldstate gettoken metadataputtersunfetchable metadataputtersbymetadata metadataputtersbymetadata containskey clientputstate prevstate metadataputtersbymetadata prevstate oldstate oldstate newstate prevstate metadataputtersunfetchable metadataputtersbymetadata newstate metadataputtersbymetadata newstate metadataputtersbymetadata oldstate newstate metadataputtersunfetchable containskey metadataputtersunfetchable newstate metadataputtersunfetchable oldstate newstate oldstate newstate ontransition metadataputtersbymetadata oldstate newstate metadataputtersunfetchable metadataputtersbymetadata public void on metadata metadata m client put state state object container container client context context ignore onmetadata clientputstate objectcontainer clientcontext override public void notify clients object container container client context context if persistent container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new splitfile progress event this total blocks this successful blocks this failed blocks this fatally failed blocks this min success blocks this block set finalized container context notifyclients objectcontainer clientcontext eventproducer eventproducer produceevent splitfileprogressevent totalblocks successfulblocks failedblocks fatallyfailedblocks minsuccessblocks blocksetfinalized public void on block set finished client put state state object container container client context context synchronized this this metadata block set finalized true if persistent container activate waiting for block sets 2 if waiting for block sets is empty if persistent container store this container deactivate waiting for block sets 1 return this block set finalized container context if persistent container store this container deactivate waiting for block sets 1 onblocksetfinished clientputstate objectcontainer clientcontext metadatablocksetfinalized waitingforblocksets waitingforblocksets isempty waitingforblocksets blocksetfinalized waitingforblocksets override public void block set finalized object container container client context context synchronized this if metadata block set finalized return if persistent container activate waiting for block sets 2 if waiting for block sets is empty if persistent container deactivate waiting for block sets 1 return if persistent container deactivate waiting for block sets 1 super block set finalized container context if persistent container store this blocksetfinalized objectcontainer clientcontext metadatablocksetfinalized waitingforblocksets waitingforblocksets isempty waitingforblocksets waitingforblocksets blocksetfinalized convert a hash map of name bucket to a hash set of manifest entry s all are to have mime override null i e we use the auto detected mime type from the filename public static hash map string object buckets by name to manifest entries hash map string object buckets by name hash map string object manifest entries new hash map string object iterator string i buckets by name key set iterator while i has next string name i next object o buckets by name get name if o instanceof bucket bucket data bucket buckets by name get name manifest entries put name new manifest element name data null data size else if o instanceof hash map manifest entries put name buckets by name to manifest entries hash map string object o else throw new illegal argument exception string value of o return manifest entries hashmap hashset manifestentry mimeoverride hashmap bucketsbynametomanifestentries hashmap bucketsbyname hashmap manifestentries hashmap bucketsbyname keyset hasnext bucketsbyname bucketsbyname manifestentries manifestelement hashmap manifestentries bucketsbynametomanifestentries hashmap illegalargumentexception valueof manifestentries convert a hierarchy of hash map s of manifest entries into a series of manifest element s each of which has a full path public static manifest element flatten hash map string object manifest elements vector manifest element v new vector manifest element flatten manifest elements v return v to array new manifest element v size hashmap manifestentries manifestelement manifestelement hashmap manifestelements manifestelement manifestelement manifestelements toarray manifestelement public static void flatten hash map string object manifest elements vector manifest element v string prefix iterator string i manifest elements key set iterator while i has next string name i next string full name prefix length 0 name prefix name object o manifest elements get name if o instanceof hash map flatten hash map string object o v full name else if o instanceof manifest element manifest element me manifest element o v add new manifest element me full name else throw new illegal state exception string value of o hashmap manifestelements manifestelement manifestelements keyset hasnext fullname manifestelements hashmap hashmap fullname manifestelement manifestelement manifestelement manifestelement fullname illegalstateexception valueof opposite of flatten note that this can throw a class cast exception if the vector passed in is bogus has files pretending to be directories public static t hash map string object unflatten list manifest element v hash map string object manifest elements new hash map string object for manifest element old element v add old element old element get name manifest elements return manifest elements classcastexception hashmap manifestelement hashmap manifestelements hashmap manifestelement oldelement oldelement oldelement getname manifestelements manifestelements private static void add manifest element e string name part map string object target int idx name part index of if idx 0 target put name part new manifest element e name part else string before name part substring 0 idx string after name part substring idx 1 suppress warnings unchecked hash map string object hm hash map string object target get before if hm null hm new hash map string object target put before intern hm add e after hm manifestelement namepart namepart indexof namepart manifestelement namepart namepart namepart suppresswarnings hashmap hashmap hashmap public int count files return number of files countfiles numberoffiles public long total size return total size totalsize totalsize override public void on major progress object container container boolean deactivate false if persistent deactivate container ext is active cb if deactivate container activate cb 1 cb on major progress container if deactivate container deactivate cb 1 onmajorprogress objectcontainer isactive onmajorprogress protected void on fetchable put handler handler object container container if persistent container activate put handlers waiting for fetchable 2 container activate metadata putters unfetchable 2 if check fetchable handler if persistent container ext store put handlers waiting for metadata 2 container store this container deactivate put handlers waiting for fetchable 1 container deactivate metadata putters unfetchable 1 container activate cb 1 cb on fetchable this container if persistent container deactivate cb 1 else if persistent container deactivate put handlers waiting for fetchable 1 container deactivate metadata putters unfetchable 1 onfetchable puthandler objectcontainer puthandlerswaitingforfetchable metadataputtersunfetchable checkfetchable puthandlerswaitingformetadata puthandlerswaitingforfetchable metadataputtersunfetchable onfetchable puthandlerswaitingforfetchable metadataputtersunfetchable private synchronized boolean check fetchable put handler handler put handlers waiting for fetchable remove handler if fetchable return false if put handlers waiting for fetchable is empty return false if has resolved base return false if metadata putters unfetchable is empty return false fetchable true return true checkfetchable puthandler puthandlerswaitingforfetchable puthandlerswaitingforfetchable isempty hasresolvedbase metadataputtersunfetchable isempty public void on fetchable client put state state object container container metadata m metadata state get token if persistent container activate m 100 container activate metadata putters unfetchable 2 container activate put handlers waiting for fetchable 2 if check fetchable m if persistent container ext store metadata putters unfetchable 2 container store this container activate cb 1 cb on fetchable this container if persistent container deactivate cb 1 if persistent container deactivate metadata putters unfetchable 1 container deactivate put handlers waiting for fetchable 1 onfetchable clientputstate objectcontainer gettoken metadataputtersunfetchable puthandlerswaitingforfetchable checkfetchable metadataputtersunfetchable onfetchable metadataputtersunfetchable puthandlerswaitingforfetchable private synchronized boolean check fetchable metadata m metadata putters unfetchable remove m if metadata putters unfetchable is empty return false if fetchable return false if put handlers waiting for fetchable is empty return false fetchable true return true checkfetchable metadataputtersunfetchable metadataputtersunfetchable isempty puthandlerswaitingforfetchable isempty override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer override public void remove from object container container client context context if put handlers by name null logger error this put handlers list still present in remove from on this remove put handlers container context if finaluri null container activate finaluri 5 finaluri remove from container container activate targeturi 5 targeturi remove from container this is passed in we should not remove it because the caller client put dir should remove it container activate ctx 1 ctx remove from container container activate metadata putters by metadata 2 container activate metadata putters unfetchable 2 array list metadata metas null if metadata putters by metadata is empty logger error this metadata putters by metadata not empty in remove from on this for map entry metadata client put state entry metadata putters by metadata entry set metadata meta entry get key container activate meta 1 client put state sfi entry get value container activate sfi 1 metadata putters unfetchable remove meta logger error this metadata putters not empty sfi for this sfi cancel container context sfi remove from container context if metas null metas new array list metadata metas add meta if metadata putters unfetchable is empty logger error this metadata putters unfetchable by metadata not empty in remove from on this for map entry metadata client put state entry metadata putters by metadata entry set metadata meta entry get key container activate meta 1 client put state sfi entry get value container activate sfi 1 metadata putters unfetchable remove meta logger error this metadata putters unfetchable not empty sfi for this sfi cancel container context sfi remove from container context if metas null for metadata meta metas if meta base metadata continue container activate meta 1 meta remove from container metadata putters by metadata clear metadata putters unfetchable clear container delete metadata putters by metadata container delete metadata putters unfetchable if base metadata null container activate base metadata 1 base metadata remove from container container activate run got all metadata 1 container delete run got all metadata super remove from container context removefrom objectcontainer clientcontext puthandlersbyname removefrom removeputhandlers removefrom removefrom clientputdir removefrom metadataputtersbymetadata metadataputtersunfetchable arraylist metadataputtersbymetadata isempty removefrom clientputstate metadataputtersbymetadata entryset getkey clientputstate getvalue metadataputtersunfetchable removefrom arraylist metadataputtersunfetchable isempty removefrom clientputstate metadataputtersbymetadata entryset getkey clientputstate getvalue metadataputtersunfetchable removefrom basemetadata removefrom metadataputtersbymetadata metadataputtersunfetchable metadataputtersbymetadata metadataputtersunfetchable basemetadata basemetadata basemetadata removefrom rungotallmetadata rungotallmetadata removefrom public void object on update object container container if logdebug logger debug this updating this activated container ext is active this stored container ext is stored this new exception debug objectonupdate objectcontainer isactive isstored public boolean object can new object container container if finished logger error this storing this when already finished new exception error return false if logdebug logger debug this storing this activated container ext is active this stored container ext is stored this new exception debug return true objectcannew objectcontainer isactive isstored protected final client metadata guess mime string name manifest element me string mime type me mime override if mime type null mime type defaultmime types guessmime type name true client metadata cm if mime type null mime type equals defaultmime types default mime type cm null else cm new client metadata mime type return cm clientmetadata guessmime manifestelement mimetype mimeoverride mimetype mimetype defaultmimetypes guessmimetype clientmetadata mimetype mimetype defaultmimetypes default_mime_type clientmetadata mimetype protected final void add redirect no mime string name manifest element me hash map string object put handlers by name2 add redirect name me null put handlers by name2 addredirectnomime manifestelement hashmap puthandlersbyname2 addredirect puthandlersbyname2 protected final void add redirect string name manifest element me hash map string object put handlers by name2 add redirect name me guess mime name me put handlers by name2 addredirect manifestelement hashmap puthandlersbyname2 addredirect guessmime puthandlersbyname2 protected final void add redirect string name manifest element me client metadata cm hash map string object put handlers by name2 put handler ph bucket data me data if me targeturi null ph new put handler this name me targeturi cm just a placeholder don t actually run it else ph new put handler this name data cm getchk only running put handlers add ph put handlers waiting for metadata add ph put handlers waiting for fetchable add ph if logminor logger minor this inserting separately as put handler name ph persistent ph persistent ph persistent persistent number of files total size data size put handlers by name2 put name ph addredirect manifestelement clientmetadata hashmap puthandlersbyname2 puthandler puthandler puthandler getchkonly runningputhandlers puthandlerswaitingformetadata puthandlerswaitingforfetchable puthandler numberoffiles totalsize puthandlersbyname2 override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext private static final long serial versionuid 1 promiscuous item exception doubly linked list item item super item to string serialversionuid promiscuousitemexception doublylinkedlist tostring public promiscuous item exception item item doubly linked list parent super item to string parent promiscuousitemexception doublylinkedlist tostring public ram freenet store store callback callback int max keys this callback callback this blocks by routing key new lru hashtable byte array wrapper block this max keys max keys callback set store this ramfreenetstore storecallback maxkeys blocksbyroutingkey lruhashtable bytearraywrapper maxkeys maxkeys setstore public synchronized storable block fetch byte routing key byte full key boolean dont promote throws io exception byte array wrapper key new byte array wrapper routing key block block blocks by routing key get key if block null misses return null try storable block ret callback construct block data block header routing key block full key hits if dont promote blocks by routing key push key block return ret catch key verify exception e blocks by routing key remove key key misses return null storableblock routingkey fullkey dontpromote ioexception bytearraywrapper bytearraywrapper routingkey blocksbyroutingkey storableblock routingkey fullkey dontpromote blocksbyroutingkey keyverifyexception blocksbyroutingkey removekey public synchronized long get max keys return max keys getmaxkeys maxkeys public synchronized long hits return hits public synchronized long key count return blocks by routing key size keycount blocksbyroutingkey public synchronized long misses return misses public synchronized void put storable block block byte routingkey byte full key byte data byte header boolean overwrite throws io exception key collision exception writes byte array wrapper key new byte array wrapper routingkey block old block blocks by routing key get key boolean store full keys callback store full keys if old block null if callback collision possible boolean equals arrays equals old block data data arrays equals old block header header store full keys arrays equals old block full key full key true if equals return if overwrite old block data data old block header header if store full keys old block full key full key else throw new key collision exception return else return block store block new block store block data data store block header header if store full keys store block full key full key blocks by routing key push key store block while blocks by routing key size max keys blocks by routing key pop key storableblock fullkey ioexception keycollisionexception bytearraywrapper bytearraywrapper oldblock blocksbyroutingkey storefullkeys storefullkeys oldblock collisionpossible oldblock oldblock storefullkeys oldblock fullkey fullkey oldblock oldblock storefullkeys oldblock fullkey fullkey keycollisionexception storeblock storeblock storeblock storefullkeys storeblock fullkey fullkey blocksbyroutingkey storeblock blocksbyroutingkey maxkeys blocksbyroutingkey popkey public synchronized void set max keys long max store keys boolean shrink now throws database exception io exception this max keys int math min integer max value max store keys always shrink now regardless of parameter as we will shrink on the next put anyway while blocks by routing key size max keys blocks by routing key pop key setmaxkeys maxstorekeys shrinknow databaseexception ioexception maxkeys max_value maxstorekeys blocksbyroutingkey maxkeys blocksbyroutingkey popkey public long writes return writes public long get bloom false positive return 1 getbloomfalsepositive public boolean probably in store byte routing key byte array wrapper key new byte array wrapper routing key return blocks by routing key get key null probablyinstore routingkey bytearraywrapper bytearraywrapper routingkey blocksbyroutingkey private static final long serial versionuid 1 public aborted exception string msg super msg serialversionuid abortedexception transient field fld alt btree multi field index altbtreemultifieldindex alt btree multi field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate fields type class descriptor tp raw altbtreemultifieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefields classdescriptor tpraw private final void locate fields class scope cls fld new field field name length for int i 0 i field name length i fld i class descriptor locate field cls field name i if fld i null throw new storage error storage error indexed field not found class name field name i locatefields fieldname fieldname classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return fld getkeyfields public void on load cls class descriptor load class get storage class name locate fields onload classdescriptor loadclass getstorage classname locatefields public int compare to object o compound key c compound key o int n keys length c keys length keys length c keys length for int i 0 i n i int diff comparable keys i compare to c keys i if diff 0 return diff return 0 allow to compare part of the compound key compareto compoundkey compoundkey compareto compound key object keys this keys keys compoundkey private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type return new key new compound key object key oval key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type compoundkey private key extract key i persistent obj object keys new object fld length try for int i 0 i keys length i keys i fld i get obj if keys i instanceof i persistent i persistent p i persistent keys i if p is persistent get storage make persistent p catch exception x throw new storage error storage error access violation x return new key new compound key keys extractkey ipersistent ipersistent ipersistent ipersistent ispersistent getstorage makepersistent storageerror storageerror access_violation compoundkey public boolean put t obj return super put extract key obj obj extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public t remove key key return super remove convert key key convertkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public void append t obj throw new storage error storage error unsupported index type storageerror storageerror unsupported_index_type public t get key from key till array list list new array list if root null root find convert key from convert key till height list return t list to array t array new instance cls list size arraylist arraylist convertkey convertkey toarray newinstance public t get prefix string prefix throw new storage error storage error incompatible key type getprefix storageerror storageerror incompatible_key_type public t prefix search string key throw new storage error storage error incompatible key type prefixsearch storageerror storageerror incompatible_key_type public t to persistent array t arr t array new instance cls n elems if root null root traverse forward height arr 0 return arr topersistentarray newinstance nelems traverseforward public t get key key return super get convert key key convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class alt btree case insensitive multi field index t extends i persistent extends alt btree multi field index t alt btree case insensitive multi field index altbtreecaseinsensitivemultifieldindex ipersistent altbtreemultifieldindex altbtreecaseinsensitivemultifieldindex alt btree case insensitive multi field index alt btree case insensitive multi field index class cls string field names boolean unique super cls field names unique altbtreecaseinsensitivemultifieldindex altbtreecaseinsensitivemultifieldindex fieldnames fieldnames key check key key key if key null compound key ck compound key key oval for int i 0 i ck keys length i if ck keys i instanceof string ck keys i string ck keys i to lower case return super check key key checkkey compoundkey compoundkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive return a nodechk corresponding to this key basically keep the routing key and lose everything else routingkey public abstract key get node key public abstract client key clone key getnodekey clientkey clonekey public abstract client key clone key public abstract void remove from object container container clientkey clonekey removefrom objectcontainer public boolean equals object o if o instanceof key key key key o return key type type key ival ival key lval lval key dval dval key oval oval return false constructor of boolean key boundary is inclusive public key boolean v this v true constructor of byte key boundary is inclusive public key byte v this v true constructor of char key boundary is inclusive public key char v this v true constructor of short key boundary is inclusive public key short v this v true constructor of int key boundary is inclusive public key int v this v true constructor of long key boundary is inclusive public key long v this v true constructor of float key boundary is inclusive public key float v this v true constructor of double key boundary is inclusive public key double v this v true constructor of date key boundary is inclusive public key java util date v this v true constructor of string key boundary is inclusive public key string v this v true constructor of array of char key boundary is inclusive public key char v this v true constructor of array of byte key boundary is inclusive public key byte v this v true constructor of key of user defined type boundary is inclusive param v user defined value public key comparable v this v true constructor of key of enum type boundary is inclusive param v array of key of enum type public key enum v this v true constructor of compound key boundary is inclusive param v array of compound key values public key object v this v true constructor of compound key with two values boundary is inclusive param v1 first value of compund key param v2 second value of compund key public key object v1 object v2 this new object v1 v2 true constructor of key with persistent object reference boundary is inclusive public key i persistent v this v true ipersistent private key int type long lval double dval object oval boolean inclusive this type type this ival int lval this lval lval this dval dval this oval oval this inclusion inclusive 1 0 constructor of boolean key param v key value param inclusive whether boundary is inclusive or exclusive public key boolean v boolean inclusive this class descriptor tp boolean v 1 0 0 0 null inclusive classdescriptor tpboolean constructor of byte key param v key value param inclusive whether boundary is inclusive or exclusive public key byte v boolean inclusive this class descriptor tp byte v 0 0 null inclusive classdescriptor tpbyte constructor of char key param v key value param inclusive whether boundary is inclusive or exclusive public key char v boolean inclusive this class descriptor tp char v 0 0 null inclusive classdescriptor tpchar constructor of short key param v key value param inclusive whether boundary is inclusive or exclusive public key short v boolean inclusive this class descriptor tp short v 0 0 null inclusive classdescriptor tpshort constructor of int key param v key value param inclusive whether boundary is inclusive or exclusive public key int v boolean inclusive this class descriptor tp int v 0 0 null inclusive classdescriptor tpint constructor of long key param v key value param inclusive whether boundary is inclusive or exclusive public key long v boolean inclusive this class descriptor tp long v 0 0 null inclusive classdescriptor tplong constructor of float key param v key value param inclusive whether boundary is inclusive or exclusive public key float v boolean inclusive this class descriptor tp float 0 v null inclusive classdescriptor tpfloat constructor of double key param v key value param inclusive whether boundary is inclusive or exclusive public key double v boolean inclusive this class descriptor tp double 0 v null inclusive classdescriptor tpdouble constructor of date key param v key value param inclusive whether boundary is inclusive or exclusive public key java util date v boolean inclusive this class descriptor tp date v null 1 v get time 0 0 null inclusive classdescriptor tpdate gettime constructor of string key param v key value param inclusive whether boundary is inclusive or exclusive public key string v boolean inclusive this class descriptor tp string 0 0 0 v inclusive classdescriptor tpstring constructor of array of char key param v key value param inclusive whether boundary is inclusive or exclusive public key char v boolean inclusive this class descriptor tp string 0 0 0 v inclusive classdescriptor tpstring constructor of key with persistent object reference param v key value param inclusive whether boundary is inclusive or exclusive public key i persistent v boolean inclusive this class descriptor tp object v null 0 v get oid 0 0 v inclusive ipersistent classdescriptor tpobject getoid constructor of compound key param v array of key values param inclusive whether boundary is inclusive or exclusive public key object v boolean inclusive this class descriptor tp array of object 0 0 0 v inclusive classdescriptor tparrayofobject constructor of key of used defined type param v user defined value param inclusive whether boundary is inclusive or exclusive public key comparable v boolean inclusive this class descriptor tp raw 0 0 0 v inclusive classdescriptor tpraw constructor of key of enum type param v enum value param inclusive whether boundary is inclusive or exclusive public key enum v boolean inclusive this class descriptor tp enum v ordinal 0 0 v inclusive classdescriptor tpenum constructor of compound key with two values param v1 first value of compund key param v2 second value of compund key param inclusive whether boundary is inclusive or exclusive public key object v1 object v2 boolean inclusive this new object v1 v2 inclusive constructor of byte array key param v byte array value param inclusive whether boundary is inclusive or exclusive public key byte v boolean inclusive this class descriptor tp array of byte 0 0 0 v inclusive classdescriptor tparrayofbyte rtree page storage storage i persistent obj rectangle r branch storage create link card branch set size card b new rectangle card set branch 0 new rectangle r obj n 1 for int i 1 i card i b i new rectangle rtreepage ipersistent createlink setsize setbranch rtree page storage storage rtree page root rtree page p branch storage create link card branch set size card b new rectangle card n 2 set branch 0 root cover root set branch 1 p cover p for int i 2 i card i b i new rectangle rtreepage rtreepage rtreepage createlink setsize setbranch setbranch rtree page rtreepage rtree page insert storage storage rectangle r i persistent obj int level modify if level 0 not leaf page int i mini 0 long min incr long max value long min area long max value for i 0 i n i long area b i area long incr rectangle join area b i r area if incr min incr min incr incr min area area mini i else if incr min incr area min area min area area mini i rtree page p rtree page branch get mini rtree page q p insert storage r obj level if q null child was not split b mini join r return null else child was split set branch mini p cover p return add branch storage q cover q else return add branch storage new rectangle r obj rtreepage ipersistent minincr max_value minarea max_value joinarea minincr minincr minarea minincr minarea minarea rtreepage rtreepage rtreepage setbranch addbranch addbranch int remove rectangle r i persistent obj int level array list reinsert list if level 0 for int i 0 i n i if r intersects b i rtree page pg rtree page branch get i int reinsert level pg remove r obj level reinsert list if reinsert level 0 if pg n min fill set branch i pg cover pg modify else not enough entries in child reinsert list add pg reinsert level level 1 remove branch i return reinsert level else for int i 0 i n i if branch contains element i obj remove branch i return 0 return 1 ipersistent arraylist reinsertlist rtreepage rtreepage reinsertlevel reinsertlist reinsertlevel minfill setbranch reinsertlist reinsertlevel removebranch reinsertlevel containselement removebranch void find rectangle r array list result int level if level 0 this is an internal node in the tree for int i 0 i n i if r intersects b i rtree page branch get i find r result level else this is a leaf node for int i 0 i n i if r intersects b i result add branch get i arraylist rtreepage void purge int level if level 0 this is an internal node in the tree for int i 0 i n i rtree page branch get i purge level deallocate rtreepage final void set branch int i rectangle r i persistent obj b i r branch set object i obj setbranch ipersistent setobject final void remove branch int i n 1 system arraycopy b i 1 b i n i branch remove i branch set size card modify removebranch setsize final rtree page add branch storage storage rectangle r i persistent obj if n card set branch n r obj return null else return split page storage r obj rtreepage addbranch ipersistent setbranch splitpage final rtree page split page storage storage rectangle r i persistent obj int i j seed0 0 seed1 0 long rect area new long card 1 long waste long worst waste long min value as the seeds for the two groups find two rectangles which waste the most area if covered by a single rectangle rect area 0 r area for i 0 i card i rect area i 1 b i area rectangle bp r for i 0 i card i for j i 1 j card j waste rectangle join area bp b j 1 rect area i rect area j if waste worst waste worst waste waste seed0 i seed1 j bp b i byte taken new byte card rectangle group0 group1 long group area0 group area1 int group card0 group card1 rtree page pg taken seed1 1 2 group1 new rectangle b seed1 1 if seed0 0 group0 new rectangle r pg new rtree page storage obj r else group0 new rectangle b seed0 1 pg new rtree page storage branch get raw seed0 1 group0 set branch seed0 1 r obj group card0 group card1 1 group area0 rect area seed0 group area1 rect area seed1 split remaining rectangles between two groups the one chosen is the one with the greatest difference in area expansion depending on which group the rect most strongly attracted to one group and repelled from the other while group card0 group card1 card 1 group card0 card 1 min fill group card1 card 1 min fill int better group 1 chosen 1 long biggest diff 1 for i 0 i card i if taken i 0 long diff rectangle join area group0 b i group area0 rectangle join area group1 b i group area1 if diff biggest diff diff biggest diff chosen i if diff 0 better group 0 biggest diff diff else better group 1 biggest diff diff assert that chosen 0 if better group 0 group0 join b chosen group area0 group0 area taken chosen 1 pg set branch group card0 b chosen branch get raw chosen else group card1 1 group1 join b chosen group area1 group1 area taken chosen 2 if one group gets too full then remaining rectangle are split between two groups in such way to balance cards of two groups if group card0 group card1 card 1 for i 0 i card i if taken i 0 if group card0 group card1 taken i 2 group card1 1 else taken i 1 pg set branch group card0 b i branch get raw i pg n group card0 n group card1 for i 0 j 0 i group card1 j if taken j 2 set branch i b j branch get raw j return pg rtreepage splitpage ipersistent rectarea worstwaste min_value rectarea rectarea joinarea rectarea rectarea worstwaste worstwaste grouparea0 grouparea1 groupcard0 groupcard1 rtreepage rtreepage rtreepage getraw setbranch groupcard0 groupcard1 grouparea0 rectarea grouparea1 rectarea groupcard0 groupcard1 groupcard0 minfill groupcard1 minfill bettergroup biggestdiff joinarea grouparea0 joinarea grouparea1 biggestdiff biggestdiff bettergroup biggestdiff bettergroup biggestdiff bettergroup grouparea0 setbranch groupcard0 getraw groupcard1 grouparea1 groupcard0 groupcard1 groupcard0 groupcard1 groupcard1 setbranch groupcard0 getraw groupcard0 groupcard1 groupcard1 setbranch getraw final rectangle cover rectangle r new rectangle b 0 for int i 1 i n i r join b i return r construct a stamp filter public stamp filter this 0 5f stampfilter stampfilter construct a stamp filter param threshold the threshold value public stamp filter float threshold set threshold threshold stampfilter stampfilter setthreshold set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius set the threshold value param threshold the threshold value see get threshold public void set threshold float threshold this threshold threshold getthreshold setthreshold get the threshold value return the threshold value see set threshold public float get threshold return threshold setthreshold getthreshold set the softness of the effect in the range 0 1 param softness the softness min value 0 max value 1 see get softness public void set softness float softness this softness softness getsoftness setsoftness get the softness of the effect return the softness see set softness public float get softness return softness setsoftness getsoftness set the color to be used for pixels above the upper threshold param white the color see get white public void set white int white this white white getwhite setwhite get the color to be used for pixels above the upper threshold return the color see set white public int get white return white setwhite getwhite set the color to be used for pixels below the lower threshold param black the color see get black public void set black int black this black black getblack setblack set the color to be used for pixels below the lower threshold return the color see set black public int get black return black setblack getblack override public buffered image filter buffered image src buffered image dst dst new gaussian filter int radius filter src null lower threshold3 255 3 threshold softness 0 5f upper threshold3 255 3 threshold softness 0 5f return super filter dst dst bufferedimage bufferedimage bufferedimage gaussianfilter lowerthreshold3 upperthreshold3 override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int l r g b float f image math smooth step lower threshold3 upper threshold3 l return image math mix colors f black white imagemath smoothstep lowerthreshold3 upperthreshold3 imagemath mixcolors override public string to string return stylize stamp tostring private boolean debug public config public config storage storage index dir myindex7 index max entries 4000 index subindex max size 4 1024 1024 index title xml spider index index owner freenet index owner email nil max shownur is 15 max parallel requests working 100 max parallel requests non working 100 begin working period 23 end working period 7 badlisted extensions new string ico bmp png jpg jpeg gif image zip jar gz bz2 rar archive 7z rar arj rpm deb xpi ace cab lza lzh ace exe iso binary mpg ogg ogv mp3 avi wv swf wmv mkv flac ogm media css sig gml df cbr gf pdf other request priority request starter immediate splitfile priority class storage make persistent this indexdir indexmaxentries indexsubindexmaxsize indextitle xmlspider indexowner indexowneremail maxshownuris maxparallelrequestsworking maxparallelrequestsnonworking beginworkingperiod endworkingperiod badlistedextensions requestpriority requeststarter immediate_splitfile_priority_class makepersistent public synchronized config clone try config config config super clone assert config is persistent return config catch clone not supported exception e logger error this impossible exception e throw new runtime exception e ispersistent clonenotsupportedexception runtimeexception public synchronized void set index dir string index dir assert is persistent this index dir index dir setindexdir indexdir ispersistent indexdir indexdir public synchronized string get index dir return index dir getindexdir indexdir public synchronized void set index max entries int index max entries assert is persistent this index max entries index max entries setindexmaxentries indexmaxentries ispersistent indexmaxentries indexmaxentries public synchronized int get index max entries return index max entries getindexmaxentries indexmaxentries public synchronized void set index subindex max size int index subindex max size assert is persistent this index subindex max size index subindex max size setindexsubindexmaxsize indexsubindexmaxsize ispersistent indexsubindexmaxsize indexsubindexmaxsize public synchronized int get index subindex max size return index subindex max size getindexsubindexmaxsize indexsubindexmaxsize public synchronized void set index title string index title assert is persistent this index title index title setindextitle indextitle ispersistent indextitle indextitle public synchronized string get index title return index title getindextitle indextitle public synchronized void set index owner string index owner assert is persistent this index owner index owner setindexowner indexowner ispersistent indexowner indexowner public synchronized string get index owner return index owner getindexowner indexowner public synchronized void set index owner email string index owner email assert is persistent this index owner email index owner email setindexowneremail indexowneremail ispersistent indexowneremail indexowneremail public synchronized void set max shownur is int max shownur is assert is persistent this max shownur is max shownur is setmaxshownuris maxshownuris ispersistent maxshownuris maxshownuris public synchronized int get max shownur is return max shownur is getmaxshownuris maxshownuris public synchronized string get index owner email return index owner email getindexowneremail indexowneremail public synchronized void set max parallel requests working int max parallel requests assert is persistent this max parallel requests working max parallel requests setmaxparallelrequestsworking maxparallelrequests ispersistent maxparallelrequestsworking maxparallelrequests public synchronized int get max parallel requests working return max parallel requests working getmaxparallelrequestsworking maxparallelrequestsworking public synchronized void set max parallel requests non working int max parallel requests assert is persistent this max parallel requests non working max parallel requests setmaxparallelrequestsnonworking maxparallelrequests ispersistent maxparallelrequestsnonworking maxparallelrequests public synchronized int get max parallel requests non working return max parallel requests non working getmaxparallelrequestsnonworking maxparallelrequestsnonworking public synchronized int get max parallel requests int actual hour calendar get instance get calendar hour of day boolean is working true if this get begin working period this get end working period midnight isn t in the interval m m 0 24 is working actual hour this get begin working period actual hour this get end working period else midnight is in the interval m m 0 24 is working actual hour this get begin working period actual hour this get end working period if is working return this get max parallel requests working else return this get max parallel requests non working getmaxparallelrequests actualhour getinstance hour_of_day isworking getbeginworkingperiod getendworkingperiod isworking actualhour getbeginworkingperiod actualhour getendworkingperiod isworking actualhour getbeginworkingperiod actualhour getendworkingperiod isworking getmaxparallelrequestsworking getmaxparallelrequestsnonworking public synchronized void set begin working period int begin working period assert is persistent this begin working period begin working period setbeginworkingperiod beginworkingperiod ispersistent beginworkingperiod beginworkingperiod public synchronized int get begin working period return begin working period getbeginworkingperiod beginworkingperiod public synchronized void set end working period int end working period assert is persistent this end working period end working period setendworkingperiod endworkingperiod ispersistent endworkingperiod endworkingperiod public synchronized int get end working period return end working period getendworkingperiod endworkingperiod public synchronized void set badlisted extensions string badlisted extensions assert is persistent this badlisted extensions badlisted extensions setbadlistedextensions badlistedextensions ispersistent badlistedextensions badlistedextensions public synchronized string get badlisted extensions return badlisted extensions getbadlistedextensions badlistedextensions public synchronized void set request priority short request priority assert is persistent this request priority request priority setrequestpriority requestpriority ispersistent requestpriority requestpriority public synchronized short get request priority return request priority getrequestpriority requestpriority public synchronized boolean is debug return debug isdebug public synchronized void debug boolean debug assert is persistent this debug debug ispersistent protected constructor to be called by factory implementations protected xml pull parser factory xmlpullparserfactory set the features to be set when xml pull parser is created by this factory p b note b factory features are not used for xml serializer param name string with uri identifying feature param state if true feature will be set if false will be ignored public void set feature string name boolean state throws xml pull parser exception features put name new boolean state setfeature xmlpullparserexception return the current value of the feature with given name p b note b factory features are not used for xml serializer param name the name of feature to be retrieved return the value of named feature unknown features are string always strong returned as false public boolean get feature string name boolean value boolean features get name return value null value boolean value false getfeature booleanvalue specifies that the parser produced by this factory will provide support for xml namespaces by default the value of this is set to false param awareness true if the parser produced by this code will provide support for xml namespaces false otherwise public void set namespace aware boolean awareness features put xml pull parser feature process namespaces new boolean awareness setnamespaceaware xmlpullparser feature_process_namespaces indicates whether or not the factory is configured to produce parsers which are namespace aware it simply set feature xml pull parser feature process namespaces to true or false return true if the factory is configured to produce parsers which are namespace aware false otherwise public boolean is namespace aware return get feature xml pull parser feature process namespaces xmlpullparser feature_process_namespaces isnamespaceaware getfeature xmlpullparser feature_process_namespaces specifies that the parser produced by this factory will be validating it simply set feature xml pull parser feature validation to true or false by default the value of this is set to false param validating if true the parsers created by this factory must be validating public void set validating boolean validating features put xml pull parser feature validation new boolean validating xmlpullparser feature_validation setvalidating xmlpullparser feature_validation indicates whether or not the factory is configured to produce parsers which validate the xml content during parse return true if the factory is configured to produce parsers which validate the xml content during parse false otherwise public boolean is validating return get feature xml pull parser feature validation isvalidating getfeature xmlpullparser feature_validation creates a new instance of a xml pull parser using the currently configured factory features return a new instance of a xml pull parser throws xml pull parser exception if a parser cannot be created which satisfies the requested configuration public xml pull parser new pull parser throws xml pull parser exception if parser classes null throw new xml pull parser exception factory initialization was incomplete has not tried class names location if parser classes size 0 throw new xml pull parser exception no valid parser classes found in class names location final string builder issues new string builder for int i 0 i parser classes size i final class pp class class parser classes element at i try final xml pull parser pp xml pull parser pp class new instance if features is empty enumeration keys features keys while keys has more elements for enumeration e features keys e has more elements final string key string e next element final boolean value boolean features get key if value null value boolean value pp set feature key true return pp catch exception ex issues append pp class get name ex to string throw new xml pull parser exception could not create parser issues xmlpullparserexception xmlpullparser newpullparser xmlpullparserexception parserclasses xmlpullparserexception classnameslocation parserclasses xmlpullparserexception classnameslocation stringbuilder stringbuilder parserclasses ppclass parserclasses elementat xmlpullparser xmlpullparser ppclass newinstance isempty hasmoreelements hasmoreelements nextelement booleanvalue setfeature ppclass getname tostring xmlpullparserexception creates a new instance of a xml serializer p b note b factory features are not used for xml serializer return a new instance of a xml serializer throws xml pull parser exception if a parser cannot be created which satisfies the requested configuration public xml serializer new serializer throws xml pull parser exception if serializer classes null throw new xml pull parser exception factory initialization incomplete has not tried class names location if serializer classes size 0 throw new xml pull parser exception no valid serializer classes found in class names location final string builder issues new string builder for int i 0 i serializer classes size i final class pp class class serializer classes element at i try final xml serializer ser xml serializer pp class new instance for enumeration e features keys e has more elements string key string e next element boolean value boolean features get key if value null value boolean value ser set feature key true return ser catch exception ex issues append pp class get name ex to string throw new xml pull parser exception could not create serializer issues xmlpullparserexception xmlserializer newserializer xmlpullparserexception serializerclasses xmlpullparserexception classnameslocation serializerclasses xmlpullparserexception classnameslocation stringbuilder stringbuilder serializerclasses ppclass serializerclasses elementat xmlserializer xmlserializer ppclass newinstance hasmoreelements nextelement booleanvalue setfeature ppclass getname tostring xmlpullparserexception create a new instance of a pull parser factory that can be used to create xml pull parsers see class description for more details return a new instance of a pull parser factory as returned by new instance null null public static xml pull parser factory new instance throws xml pull parser exception return new instance null null pullparserfactory pullparserfactory newinstance xmlpullparserfactory newinstance xmlpullparserexception newinstance public static xml pull parser factory new instance string class names class context throws xml pull parser exception if context null note make sure context uses the same class loader as api classes this is the best we can do without having access to context classloader in j2me if api is in the same classloader as implementation then this will work context reference context class string class names location null if class names null class names length 0 default equals class names try input stream is context get resource as stream resource name if is null throw new xml pull parser exception resource not found resource name make sure that parser implementing xml pull api is available final string builder sb new string builder while true final int ch is read if ch 0 break else if ch sb append char ch is close class names sb to string catch exception e throw new xml pull parser exception null null e class names location resource resource name that contained class names else class names location parameter class names to new instance that contained class names xml pull parser factory factory null final vector parser classes new vector final vector serializer classes new vector int pos 0 while pos class names length int cut class names index of pos if cut 1 cut class names length final string name class names substring pos cut class candidate null object instance null try candidate class for name name necessary because of j2me class issue instance candidate new instance catch exception e if candidate null boolean recognized false if instance instanceof xml pull parser parser classes add element candidate recognized true if instance instanceof xml serializer serializer classes add element candidate recognized true if instance instanceof xml pull parser factory if factory null factory xml pull parser factory instance recognized true if recognized throw new xml pull parser exception incompatible class name pos cut 1 if factory null factory new xml pull parser factory factory parser classes parser classes factory serializer classes serializer classes factory class names location class names location return factory xmlpullparserfactory newinstance classnames xmlpullparserexception referencecontextclass classnameslocation classnames classnames classnames inputstream getresourceasstream resource_name xmlpullparserexception resource_name xmlpull stringbuilder stringbuilder classnames tostring xmlpullparserexception classnameslocation resource_name classnames classnameslocation classnames newinstance classnames xmlpullparserfactory parserclasses serializerclasses classnames classnames indexof classnames classnames forname newinstance xmlpullparser parserclasses addelement xmlserializer serializerclasses addelement xmlpullparserfactory xmlpullparserfactory xmlpullparserexception xmlpullparserfactory parserclasses parserclasses serializerclasses serializerclasses classnameslocation classnameslocation final boolean remove with producer public event dumper print writer writer boolean remove with producer this pw writer this remove with producer remove with producer removewithproducer eventdumper printwriter removewithproducer removewithproducer removewithproducer public void receive client event ce object container container client context context pw println ce get description clientevent objectcontainer clientcontext getdescription public void on remove event producer object container container if remove with producer container delete this onremoveeventproducer objectcontainer removewithproducer public string descr public int compare to uri wrapper o return uri compare to o uri compareto uriwrapper compareto public boolean equals object o if o null o get class get class return false return uri equals uri wrapper o uri getclass getclass uriwrapper public int hash code return uri hash code hashcode hashcode private synchronized void refill buffer override protected void refill buffer encrypt feedback into result rijndael c encipher feedback register feedback register a t register pointer 0 refillbuffer refillbuffer feedback_register feedback_register registerpointer public rijndaelpcfb mode rijndael c super c int temp size c get temp array size a new int temp size t new int temp size rijndaelpcfbmode tempsize gettemparraysize tempsize tempsize public rijndaelpcfb mode rijndael c byte iv super c iv int temp size c get temp array size a new int temp size t new int temp size rijndaelpcfbmode tempsize gettemparraysize tempsize tempsize public class binary bloom filter extends bloom filter constructor param length length in bits protected binary bloom filter int length int k super length k filter byte buffer allocate this length 8 binarybloomfilter bloomfilter binarybloomfilter bytebuffer constructor param file disk file param length length in bits throws io exception protected binary bloom filter file file int length int k throws io exception super length k if file exists file length length 8 need rebuild true random access file raf new random access file file rw raf set length length 8 filter raf get channel map map mode read write 0 length 8 load ioexception binarybloomfilter ioexception needrebuild randomaccessfile randomaccessfile setlength getchannel mapmode read_write public binary bloom filter byte buffer slice int length int k super length k filter slice binarybloomfilter bytebuffer override public void remove key byte key ignore removekey override protected boolean get bit int offset return filter get offset 8 1 offset 8 0 getbit override protected void set bit int offset byte b filter get offset 8 b 1 offset 8 filter put offset 8 b setbit override protected void unset bit int offset no op unsetbit override public void fork int k lock write lock lock try file temp file file create temp file bloom tmp temp file delete on exit forked filter new binary bloom filter temp file length k catch io exception e forked filter new binary bloom filter length k finally lock write lock unlock writelock tempfile createtempfile tempfile deleteonexit forkedfilter binarybloomfilter tempfile ioexception forkedfilter binarybloomfilter writelock construct a rotate filter public rotate filter this image math pi rotatefilter rotatefilter imagemath construct a rotate filter param angle the angle to rotate public rotate filter float angle this angle true rotatefilter rotatefilter construct a rotate filter param angle the angle to rotate param resize true if the output image should be resized public rotate filter float angle boolean resize set angle angle this resize resize rotatefilter rotatefilter setangle specifies the angle of rotation param angle the angle of rotation angle see get angle public void set angle float angle this angle angle cos float math cos this angle sin float math sin this angle getangle setangle returns the angle of rotation return the angle of rotation see set angle public float get angle return angle setangle getangle override protected void transform space rectangle rect if resize point out new point 0 0 int minx integer max value int miny integer max value int maxx integer min value int maxy integer min value int w rect width int h rect height int x rect x int y rect y for int i 0 i 4 i switch i case 0 transform x y out break case 1 transform x w y out break case 2 transform x y h out break case 3 transform x w y h out break minx math min minx out x miny math min miny out y maxx math max maxx out x maxy math max maxy out y rect x minx rect y miny rect width maxx rect x rect height maxy rect y transformspace max_value max_value min_value min_value private void transform int x int y point out out x int x cos y sin out y int y cos x sin override protected void transform inverse int x int y float out out 0 x cos y sin out 1 y cos x sin transforminverse override public string to string return rotate int angle 180 math pi tostring public persistent get string identifier freeneturi uri int verbosity short priority class short return type short persistence type file target file file temp file string client token boolean global boolean started int max retries boolean binary blob long max size this identifier identifier this uri uri this verbosity verbosity this priority class priority class this return type return type this persistence type persistence type this target file target file this temp file temp file this client token client token this global global this started started this max retries max retries this binary blob binary blob this max size max size persistentget priorityclass returntype persistencetype targetfile tempfile clienttoken maxretries binaryblob maxsize priorityclass priorityclass returntype returntype persistencetype persistencetype targetfile targetfile tempfile tempfile clienttoken clienttoken maxretries maxretries binaryblob binaryblob maxsize maxsize override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put single uri uri to string false false fs put verbosity verbosity fs put single return type client get message return type string return type fs put single persistence client request persistence type string persistence type fixme persistence type is backward compatibility cruft everything else uses persistence fs put single persistence type client request persistence type string persistence type if return type client get message return type disk fs put single filename target file get absolute path fs put single temp filename temp file get absolute path fs put priority class priority class if client token null fs put single client token client token fs put global global fs put started started fs put max retries max retries fs put binary blob binary blob fs put max size max size return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring putsingle returntype clientgetmessage returntypestring returntype putsingle clientrequest persistencetypestring persistencetype persistencetype putsingle persistencetype clientrequest persistencetypestring persistencetype returntype clientgetmessage return_type_disk putsingle targetfile getabsolutepath putsingle tempfilename tempfile getabsolutepath priorityclass priorityclass clienttoken putsingle clienttoken clienttoken maxretries maxretries binaryblob binaryblob maxsize maxsize override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message persistent get goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message persistentget override public void remove from object container container container activate uri 5 uri remove from container container activate target file 5 container delete target file container activate temp file 5 container delete temp file container delete this removefrom objectcontainer removefrom targetfile targetfile tempfile tempfile public final class multiply composite extends rgb composite public multiply composite float alpha super alpha multiplycomposite rgbcomposite multiplycomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob int t dir sr 0x80 dor t 8 t 8 t dig sg 0x80 dog t 8 t 8 t dib sb 0x80 dob t 8 t 8 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public final long expected size public expected file size event long size expected size size expectedsize expectedfilesizeevent expectedsize static final int code 0x0c public int get code return code getcode public string get description return expected file size expected size getdescription expectedsize public int last good version 0 public build old age user alert super false null null null null user alert error true l10n get string user alert hide false null lastgoodversion buildoldageuseralert useralert getstring useralert override public string get title return l10n too old title gettitle toooldtitle private string l10n string key return l10n get string build old age user alert key getstring buildoldageuseralert private string l10n string key string pattern string value return l10n get string build old age user alert key pattern value getstring buildoldageuseralert override public string get text if last good version 0 throw new illegal argument exception not valid string s l10n too old lastgood integer to string last good version return s gettext lastgoodversion illegalargumentexception tooold tostring lastgoodversion override public html node gethtml text return new html node div get text htmlnode gethtmltext htmlnode gettext override public boolean is valid if last good version 0 return false return super is valid isvalid lastgoodversion isvalid override public string get short text return l10n too old short lastgood integer to string last good version getshorttext toooldshort tostring lastgoodversion public final long estimated size compression output size exception estimated size 1 estimatedsize compressionoutputsizeexception estimatedsize compression output size exception long sz estimated size sz compressionoutputsizeexception estimatedsize construct a gradient public gradient rebuild gradient rebuildgradient construct a gradient with the given colors param rgb the colors public gradient int rgb this null rgb null construct a gradient with the given colors and knot positions param x the knot positions param rgb the colors public gradient int x int rgb this x rgb null construct a gradient with the given colors knot positions and interpolation types param x the knot positions param rgb the colors param types interpolation types public gradient int x int rgb byte types set knots x rgb types setknots override public object clone gradient g gradient super clone g map int map clone g x knots int x knots clone g y knots int y knots clone g knot types byte knot types clone return g xknots xknots yknots yknots knottypes knottypes copy one gradient into another param g the gradient to copy into public void copy to gradient g g num knots num knots g map int map clone g x knots int x knots clone g y knots int y knots clone g knot types byte knot types clone copyto numknots numknots xknots xknots yknots yknots knottypes knottypes set a knot color param n the knot index param color the color override public void set color int n int color int first color map 0 int last color map 256 1 if n 0 for int i 0 i n i map i image math mix colors float i n first color color if n 256 1 for int i n i 256 i map i image math mix colors float i n 256 n color last color setcolor firstcolor lastcolor imagemath mixcolors firstcolor imagemath mixcolors lastcolor get the number of knots in the gradient return the number of knots public int get num knots return num knots getnumknots numknots set a knot color param n the knot index param color the color see get knot public void set knot int n int color y knots n color rebuild gradient getknot setknot yknots rebuildgradient get a knot color param n the knot index return the knot color see set knot public int get knot int n return y knots n setknot getknot yknots set a knot type param n the knot index param type the type see get knot type public void set knot type int n int type knot types n byte knot types n color mask type rebuild gradient getknottype setknottype knottypes knottypes color_mask rebuildgradient get a knot type param n the knot index return the knot type see set knot type public int get knot type int n return byte knot types n color mask setknottype getknottype knottypes color_mask set a knot blend type param n the knot index param type the knot blend type see get knot blend public void set knot blend int n int type knot types n byte knot types n blend mask type rebuild gradient getknotblend setknotblend knottypes knottypes blend_mask rebuildgradient get a knot blend type param n the knot index return the knot blend type see set knot blend public byte get knot blend int n return byte knot types n blend mask setknotblend getknotblend knottypes blend_mask add a new knot param x the knot position param color the color param type the knot type see remove knot public void add knot int x int color int type int nx new int num knots 1 int ny new int num knots 1 byte nt new byte num knots 1 system arraycopy x knots 0 nx 0 num knots system arraycopy y knots 0 ny 0 num knots system arraycopy knot types 0 nt 0 num knots x knots nx y knots ny knot types nt insert one position before the end so the sort works correctly x knots num knots x knots num knots 1 y knots num knots y knots num knots 1 knot types num knots knot types num knots 1 x knots num knots 1 x y knots num knots 1 color knot types num knots 1 byte type num knots sort knots rebuild gradient removeknot addknot numknots numknots numknots xknots numknots yknots numknots knottypes numknots xknots yknots knottypes xknots numknots xknots numknots yknots numknots yknots numknots knottypes numknots knottypes numknots xknots numknots yknots numknots knottypes numknots numknots sortknots rebuildgradient remove a knot param n the knot index see add knot public void remove knot int n if num knots 4 return if n num knots 1 system arraycopy x knots n 1 x knots n num knots n 1 system arraycopy y knots n 1 y knots n num knots n 1 system arraycopy knot types n 1 knot types n num knots n 1 num knots if x knots 1 0 x knots 1 0 rebuild gradient addknot removeknot numknots numknots xknots xknots numknots yknots yknots numknots knottypes knottypes numknots numknots xknots xknots rebuildgradient set the values of all the knots this version does not require the extra knots at 1 and 256 param x the knot positions param rgb the knot colors param types the knot types public void set knots int x int rgb byte types num knots rgb length 2 x knots new int num knots y knots new int num knots knot types new byte num knots if x null system arraycopy x 0 x knots 1 num knots 2 else for int i 1 i num knots 1 i x knots i 255 i num knots 2 system arraycopy rgb 0 y knots 1 num knots 2 if types null system arraycopy types 0 knot types 1 num knots 2 else for int i 0 i num knots i knot types i rgb spline sort knots rebuild gradient setknots numknots xknots numknots yknots numknots knottypes numknots xknots numknots numknots xknots numknots yknots numknots knottypes numknots numknots knottypes sortknots rebuildgradient set the values of a set of knots param x the knot positions param y the knot colors param types the knot types param offset the first knot to set param count the number of knots public void set knots int x int y byte types int offset int count num knots count x knots new int num knots y knots new int num knots knot types new byte num knots system arraycopy x offset x knots 0 num knots system arraycopy y offset y knots 0 num knots system arraycopy types offset knot types 0 num knots sort knots rebuild gradient setknots numknots xknots numknots yknots numknots knottypes numknots xknots numknots yknots numknots knottypes numknots sortknots rebuildgradient split a span into two by adding a knot in the middle param n the span index public void split span int n int x x knots n x knots n 1 2 add knot x get color x 256 0f knot types n rebuild gradient splitspan xknots xknots addknot getcolor knottypes rebuildgradient set a knot position param n the knot index param x the knot position see set knot position public void set knot position int n int x x knots n image math clamp x 0 255 sort knots rebuild gradient setknotposition setknotposition xknots imagemath sortknots rebuildgradient get a knot position param n the knot index return the knot position see set knot position public int get knot position int n return x knots n setknotposition getknotposition xknots return the knot at a given position param x the position return the knot number or 1 if no knot found public int knot at int x for int i 1 i num knots 1 i if x knots i 1 x return i return 1 knotat numknots xknots private void rebuild gradient x knots 0 1 x knots num knots 1 256 y knots 0 y knots 1 y knots num knots 1 y knots num knots 2 int knot 0 for int i 1 i num knots 1 i float span length x knots i 1 x knots i int end x knots i 1 if i num knots 2 end for int j x knots i j end j int rgb1 y knots i int rgb2 y knots i 1 float hsb1 color rg btohsb rgb1 16 0xff rgb1 8 0xff rgb1 0xff null float hsb2 color rg btohsb rgb2 16 0xff rgb2 8 0xff rgb2 0xff null float t float j x knots i span length int type get knot type i int blend get knot blend i if j 0 j 255 switch blend case constant t 0 break case linear break case spline map i image math color spline j num knots x knots y knots t image math smooth step 0 15f 0 85f t break case circle up t t 1 t float math sqrt 1 t t break case circle down t 1 float math sqrt 1 t t break if blend spline switch type case rgb map j image math mix colors t rgb1 rgb2 break case hue cw case hue ccw if type hue cw if hsb2 0 hsb1 0 hsb2 0 1 0f else if hsb1 0 hsb2 1 hsb1 0 1 0f float h image math lerp t hsb1 0 hsb2 0 image math two pi float s image math lerp t hsb1 1 hsb2 1 float b image math lerp t hsb1 2 hsb2 2 map j 0xff000000 color hs btorgb float h float s float b fixme alpha break rebuildgradient xknots xknots numknots yknots yknots yknots numknots yknots numknots numknots spanlength xknots xknots xknots numknots xknots yknots yknots rgbtohsb rgbtohsb xknots spanlength getknottype getknotblend imagemath colorspline numknots xknots yknots imagemath smoothstep circle_up circle_down imagemath mixcolors hue_cw hue_ccw hue_cw imagemath imagemath two_pi imagemath imagemath hsbtorgb private void sort knots for int i 1 i num knots 1 i for int j 1 j i j if x knots i x knots j int t x knots i x knots i x knots j x knots j t t y knots i y knots i y knots j y knots j t byte bt knot types i knot types i knot types j knot types j bt sortknots numknots xknots xknots xknots xknots xknots xknots yknots yknots yknots yknots knottypes knottypes knottypes knottypes private void rebuild sort knots rebuild gradient sortknots rebuildgradient randomize the gradient public void randomize num knots 4 int 6 math random x knots new int num knots y knots new int num knots knot types new byte num knots for int i 0 i num knots i x knots i int 255 math random y knots i 0xff000000 int 255 math random 16 int 255 math random 8 int 255 math random knot types i rgb spline x knots 0 1 x knots 1 0 x knots num knots 2 255 x knots num knots 1 256 sort knots rebuild gradient numknots xknots numknots yknots numknots knottypes numknots numknots xknots yknots knottypes xknots xknots xknots numknots xknots numknots sortknots rebuildgradient mutate the gradient param amount the amount in the range zero to one public void mutate float amount for int i 0 i num knots i int rgb y knots i int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r pixel utils clamp int r amount 255 math random 0 5 g pixel utils clamp int g amount 255 math random 0 5 b pixel utils clamp int b amount 255 math random 0 5 y knots i 0xff000000 r 16 g 8 b knot types i rgb spline sort knots rebuild gradient numknots yknots pixelutils pixelutils pixelutils yknots knottypes sortknots rebuildgradient build a random gradient return the new gradient public static gradient random gradient gradient g new gradient g randomize return g randomgradient private static final long serial versionuid 1 override public final object clone return new bootstrapping decaying running average this serialversionuid bootstrappingdecayingrunningaverage constructor param default value default value param min minimum value of input data param max maxumum value of input data param max reports param fs link simple field set parameter for this object will override other parameters public bootstrapping decaying running average double default value double min double max int max reports simple field set fs this min min this max max reports 0 current value default value this max reports max reports if fs null current value fs get double current value current value reports fs get long reports reports defaultvalue maxreports simplefieldset bootstrappingdecayingrunningaverage defaultvalue maxreports simplefieldset currentvalue defaultvalue maxreports maxreports currentvalue getdouble currentvalue currentvalue getlong inherit doc public synchronized double current value return current value inheritdoc currentvalue currentvalue strong not a public method strong changes the internally stored code current value code and return the old one used by link decaying keyspace average to normalize the stored averages calling this function may purposefully destroy the utility of the average being kept see decaying keyspace average protected synchronized double set current value double d double old current value current value d return old currentvalue decayingkeyspaceaverage decayingkeyspaceaverage setcurrentvalue currentvalue currentvalue inherit doc public synchronized void report double d if d min if logger should log logger debug this logger debug this too low d new exception debug d min if d max if logger should log logger debug this logger debug this too high d new exception debug d max reports double decay factor 1 0 math min reports max reports current value d decay factor current value 1 decay factor inheritdoc shouldlog shouldlog decayfactor maxreports currentvalue decayfactor currentvalue decayfactor inherit doc public void report long d report double d inheritdoc inherit doc public synchronized double value if reported double d if d min logger error this too low d new exception debug d min if d max logger error this too high d new exception debug d max double decay factor 1 0 math min reports 1 max reports return d decay factor current value 1 decay factor inheritdoc valueifreported decayfactor maxreports decayfactor currentvalue decayfactor change code max reports code param max reports public synchronized void change max reports int max reports this max reports max reports maxreports maxreports changemaxreports maxreports maxreports maxreports copy constructor private bootstrapping decaying running average bootstrapping decaying running average a synchronized a this current value a current value this max a max this max reports a max reports this min a min this reports a reports bootstrappingdecayingrunningaverage bootstrappingdecayingrunningaverage currentvalue currentvalue maxreports maxreports inherit doc public synchronized long count reports return reports inheritdoc countreports export this object as link simple field set param short lived see link simple field set simple field set boolean public synchronized simple field set export field set boolean short lived simple field set fs new simple field set short lived fs put single type bootstrapping decaying running average fs put current value current value fs put reports reports return fs simplefieldset shortlived simplefieldset simplefieldset simplefieldset exportfieldset shortlived simplefieldset simplefieldset shortlived putsingle bootstrappingdecayingrunningaverage currentvalue currentvalue private random random numbers public dissolve filter randomnumbers dissolvefilter set the density of the image in the range 0 1 param density the density min value 0 max value 1 see get density public void set density float density this density density getdensity setdensity get the density of the image return the density see set density public float get density return density setdensity getdensity set the softness of the dissolve in the range 0 1 param softness the softness min value 0 max value 1 see get softness public void set softness float softness this softness softness getsoftness setsoftness get the softness of the dissolve return the softness see set softness public float get softness return softness setsoftness getsoftness override public buffered image filter buffered image src buffered image dst float d 1 density 1 softness min density d softness max density d random numbers new random 0 return super filter src dst bufferedimage bufferedimage bufferedimage mindensity maxdensity randomnumbers override public int filterrgb int x int y int rgb int a rgb 24 0xff float v random numbers next float float f image math smooth step min density max density v return int a f 24 rgb 0x00ffffff randomnumbers nextfloat imagemath smoothstep mindensity maxdensity override public string to string return stylize dissolve tostring public class null int callback extends int callback override public integer get return 0 nullintcallback intcallback override public void set integer val throws invalid config value exception ignore invalidconfigvalueexception public void terminate logger normal this stopping snmp snmp agent stopsnmp agent goon false snmpagent stopsnmpagent public int get port return port getport public string get bindto return bindto getbindto public void run plugin plugin respirator pr this pr pr snmp agent stopsnmp agent try fixme sort out config c pr get node config sub config sc new sub config plugins snmp c sc register port 4000 2 true false snmp port number snmp port number new snmp port number callback sc register bindto 127 0 0 1 2 true false ip address to bind to ip address to bind the snmp server to new snmp bindto callback bindto sc get string bindto port sc get int port sc finished initialization port 4000 bindto 127 0 0 1 snmp agent setsnmp port port system out println starting snmp server on bindto port snmp starter initialize pr get node logger normal this starting snmp server on bindto port while goon try thread sleep 10000 catch interrupted exception e ignore catch illegal argument exception e logger error this error loading snmp server runplugin pluginrespirator snmpagent stopsnmpagent getnode subconfig subconfig snmpportnumbercallback snmpbindtocallback getstring getint finishedinitialization snmpagent setsnmpport snmpstarter getnode interruptedexception illegalargumentexception user alerts toadlet high level simple client client node node node client core core super client this node node this alerts core alerts useralertstoadlet highlevelsimpleclient nodeclientcore private node node override public string supported methods return get supportedmethods override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return html node page node ctx get page maker get page node l10n title with name name node get my name ctx html node content node ctx get page maker get content node page node content node add child alerts create alerts writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring htmlnode pagenode getpagemaker getpagenode titlewithname getmyname htmlnode contentnode getpagemaker getcontentnode pagenode contentnode addchild createalerts writehtmlreply pagenode protected string l10n string name string pattern string value return l10n get string user alerts toadlet name pattern value getstring useralertstoadlet private static final long serial versionuid 1l public no such message list exception string message listid super message listid serialversionuid nosuchmessagelistexception messagelistid messagelistid private final boolean null at start public simple int numbered item comparator boolean null at start this null at start null at start nullatstart simpleintnumbereditemcomparator nullatstart nullatstart nullatstart public int compare object o1 object o2 int x ocompare o1 o2 logger debug this compare o1 o2 x return x public int ocompare object o1 object o2 nulls at the end of the list if o1 null o2 null return 0 null null if o1 null o2 null return null at start 1 1 anything null if o2 null o1 null return null at start 1 1 long i1 i2 if o1 instanceof int numbered item i1 int numbered item o1 get number else if o1 instanceof integer i1 integer o1 int value else throw new class cast exception o1 to string if o2 instanceof int numbered item i2 int numbered item o2 get number else if o2 instanceof integer i2 integer o2 int value else throw new class cast exception o2 to string if i1 i2 return 0 if i1 i2 return 1 else return 1 nullatstart nullatstart intnumbereditem intnumbereditem getnumber intvalue classcastexception tostring intnumbereditem intnumbereditem getnumber intvalue classcastexception tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog override public synchronized int hash code if has hash code return hash code int x key type hash code if doc name null x doc name hash code if meta str null for int i 0 i meta str length i x meta str i hash code if routing key null x fields hash code routing key if crypto key null x fields hash code crypto key if extra null x fields hash code extra if key type equals usk x suggested edition hash code x has hash code true return x hashcode hashashcode hashcode keytype hashcode docname docname hashcode metastr metastr metastr hashcode routingkey hashcode routingkey cryptokey hashcode cryptokey hashcode keytype suggestededition hashcode hashashcode override public boolean equals object o if o instanceof freeneturi return false else freeneturi f freeneturi o if key type equals f key type return false if key type equals usk if suggested edition f suggested edition return false if doc name null f doc name null return false if meta str null f meta str null return false if routing key null f routing key null return false if crypto key null f crypto key null return false if extra null f extra null return false if doc name null doc name equals f doc name return false if meta str null arrays equals meta str f meta str return false if routing key null arrays equals routing key f routing key return false if crypto key null arrays equals crypto key f crypto key return false if extra null arrays equals extra f extra return false return true keytype keytype keytype suggestededition suggestededition docname docname metastr metastr routingkey routingkey cryptokey cryptokey docname docname docname metastr metastr metastr routingkey routingkey routingkey cryptokey cryptokey cryptokey public boolean equals keypair freeneturi u2 if routing key null crypto key null return arrays equals routing key u2 routing key arrays equals crypto key u2 crypto key return false equalskeypair routingkey cryptokey routingkey routingkey cryptokey cryptokey override public final freeneturi clone return new freeneturi this public freeneturi freeneturi uri this unique hash code super hash code key type uri key type doc name uri doc name if uri meta str null meta str new string uri meta str length system arraycopy uri meta str 0 meta str 0 meta str length else meta str null if uri routing key null routing key new byte uri routing key length system arraycopy uri routing key 0 routing key 0 routing key length else routing key null if uri crypto key null crypto key new byte uri crypto key length system arraycopy uri crypto key 0 crypto key 0 crypto key length else crypto key null if uri extra null extra new byte uri extra length system arraycopy uri extra 0 extra 0 extra length else extra null this suggested edition uri suggested edition if logminor logger minor this copied to string from uri to string new exception debug uniquehashcode hashcode keytype keytype docname docname metastr metastr metastr metastr metastr metastr metastr routingkey routingkey routingkey routingkey routingkey routingkey routingkey cryptokey cryptokey cryptokey cryptokey cryptokey cryptokey cryptokey suggestededition suggestededition tostring tostring public freeneturi string key type string doc name this key type doc name string null null null null keytype docname keytype docname public freeneturi string key type string doc name byte routing key byte crypto key byte extra2 this key type doc name string null routing key crypto key extra2 keytype docname routingkey cryptokey keytype docname routingkey cryptokey public freeneturi string key type string doc name string meta str byte routing key byte crypto key this key type doc name meta str null string null new string meta str routing key crypto key null keytype docname metastr routingkey cryptokey keytype docname metastr metastr routingkey cryptokey public freeneturi string key type string doc name string meta str byte routing key byte crypto key byte extra2 this unique hash code super hash code this key type key type trim to upper case intern this doc name doc name this meta str meta str this routing key routing key this crypto key crypto key this extra extra2 this suggested edition 1 if logdebug logger minor this created from components to string new exception debug keytype docname metastr routingkey cryptokey uniquehashcode hashcode keytype keytype touppercase docname docname metastr metastr routingkey routingkey cryptokey cryptokey suggestededition tostring public freeneturi string key type string doc name string meta str byte routing key byte crypto key byte extra2 long suggested edition this unique hash code super hash code this key type key type trim to upper case intern this doc name doc name this meta str meta str this routing key routing key this crypto key crypto key this extra extra2 this suggested edition suggested edition if logdebug logger minor this created from components b to string new exception debug keytype docname metastr routingkey cryptokey suggestededition uniquehashcode hashcode keytype keytype touppercase docname docname metastr metastr routingkey routingkey cryptokey cryptokey suggestededition suggestededition tostring public freeneturi string uri throws malformedurl exception this unique hash code super hash code if uri null throw new malformedurl exception no uri specified uri uri trim if uri index of 0 uri index of 0 encoded url try uri url decoder decode uri false catch url encoded format exception e throw new malformedurl exception invalid uri no or or or is escaped but there are invalid escapes uri uri prefix matcher uri replace first decode key type int atchar uri index of if atchar 1 throw new malformedurl exception there is no in that uri uri string keytype uri substring 0 atchar to upper case uri uri substring atchar 1 boolean valid key type false for int i 0 i valid key types length i if keytype equals valid key types i valid key type true keytype valid key types i break key type keytype if valid key type throw new malformedurl exception invalid key type key type boolean isssk ssk equals key type boolean isusk usk equals key type boolean isksk ksk equals key type decode meta string array list string sv null int slash2 sv new array list string if isksk uri uri ensure that ksk doc names are decoded while slash2 uri last index of 1 string s try s url decoder decode uri substring slash2 1 length true catch url encoded format exception e malformedurl exception ue new malformedurl exception e to string ue init cause e throw ue if s null sv add s uri uri substring 0 slash2 sv is backwards this makes for more efficient handling if isssk isusk isksk if sv is empty throw new malformedurl exception no docname for key type doc name sv remove sv size 1 if isusk if sv is empty throw new malformedurl exception no suggested edition number for usk try suggested edition long parse long sv remove sv size 1 catch number format exception e malformedurl exception e1 new malformedurl exception invalid suggested edition e e1 init cause e throw e1 else suggested edition 1 else doc name not necessary nor is it supported for ch ks doc name null suggested edition 1 if sv is empty meta str new string sv size for int i 0 i meta str length i meta str i sv get meta str length 1 i intern if meta str i null throw new null pointer exception else meta str null if isksk routing key extra crypto key null return strip file extensions from ch ks added by aum david rebirthing co nz if chk equals key type uri uri split 0 uri now contains routing key crypto key meta info string tokenizer st new string tokenizer uri try if st has more tokens routing key base64 decode st next token else routing key crypto key extra null return if st has more tokens crypto key extra null return can be cryptokey or name value pair string t st next token crypto key base64 decode t if st has more tokens extra null return extra base64 decode st next token catch illegal base64 exception e throw new malformedurl exception invalid base64 quantity e if logdebug logger minor this created from parse to string from uri new exception debug malformedurlexception uniquehashcode hashcode malformedurlexception indexof indexof urldecoder urlencodedformatexception malformedurlexception uri_prefix replacefirst keytype indexof malformedurlexception _keytype touppercase validkeytype valid_key_types _keytype valid_key_types validkeytype _keytype valid_key_types keytype _keytype validkeytype malformedurlexception keytype keytype keytype keytype metastring arraylist arraylist docnames lastindexof urldecoder urlencodedformatexception malformedurlexception malformedurlexception tostring initcause isempty malformedurlexception keytype docname isempty malformedurlexception suggestededition parselong numberformatexception malformedurlexception malformedurlexception initcause suggestededition docname chks docname suggestededition isempty metastr metastr metastr metastr metastr nullpointerexception metastr routingkey cryptokey chks keytype routingkey cryptokey metainfo stringtokenizer stringtokenizer hasmoretokens routingkey nexttoken routingkey cryptokey hasmoretokens cryptokey nexttoken cryptokey hasmoretokens nexttoken illegalbase64exception malformedurlexception tostring usk constructor from components public freeneturi byte pub key hash byte crypto key byte extra string site name long suggested edition2 this unique hash code super hash code this key type usk this routing key pub key hash this crypto key crypto key this extra extra this doc name site name this suggested edition suggested edition2 meta str null if logdebug logger minor this created from components usk to string new exception debug pubkeyhash cryptokey sitename suggestededition2 uniquehashcode hashcode keytype routingkey pubkeyhash cryptokey cryptokey docname sitename suggestededition suggestededition2 metastr tostring public void decompose string r routing key null none hex util bytes to hex routing key string k crypto key null none hex util bytes to hex crypto key string e extra null none hex util bytes to hex extra system out println freeneturi this system out println key type key type system out println routing key r system out println crypto key k system out println extra e system out println doc name doc name null none doc name system out print meta strings if meta str null system err println none else for int i 0 i meta str length i system err print meta str i if i meta str length 1 system err println else system err print routingkey hexutil bytestohex routingkey cryptokey hexutil bytestohex cryptokey hexutil bytestohex keytype docname docname metastr metastr metastr metastr public string get guessable key return get doc name getguessablekey getdocname public string get doc name return doc name getdocname docname public string get meta string return meta str null meta str length 0 null meta str 0 getmetastring metastr metastr metastr public string last meta string return meta str null meta str length 0 null meta str meta str length 1 lastmetastring metastr metastr metastr metastr public string get all meta strings return meta str getallmetastrings metastr public boolean has meta strings return meta str null meta str length 0 hasmetastrings metastr metastr public byte get routing key return routing key getroutingkey routingkey public byte get crypto key return crypto key getcryptokey cryptokey public string get key type return key type getkeytype keytype returns a copy of this uri with the first meta string removed public freeneturi pop meta string string new meta str null if meta str null final int meta str length meta str length if meta str length 1 new meta str new string meta str length 1 system arraycopy meta str 1 new meta str 0 new meta str length return set meta string new meta str popmetastring newmetastr metastr metastrlength metastr metastrlength newmetastr metastrlength metastr newmetastr newmetastr setmetastring newmetastr public freeneturi drop last meta strings int i string new meta str null if meta str null meta str length 1 if i meta str length i meta str length new meta str new string meta str length i system arraycopy meta str 0 new meta str 0 new meta str length return set meta string new meta str droplastmetastrings newmetastr metastr metastr metastr metastr newmetastr metastr metastr newmetastr newmetastr setmetastring newmetastr returns a copy of this uri with the given string added as a new meta string public freeneturi push meta string string name string new meta str if name null throw new null pointer exception if meta str null new meta str new string name else new meta str new string meta str length 1 system arraycopy meta str 0 new meta str 0 meta str length new meta str meta str length name intern return set meta string new meta str pushmetastring newmetastr nullpointerexception metastr newmetastr newmetastr metastr metastr newmetastr metastr newmetastr metastr setmetastring newmetastr returns a copy of this uri with the those meta strings appended public freeneturi add meta strings string strs if strs null return this legal noop since get meta strings can return null for int i 0 i strs length i if strs i null throw new null pointer exception element i of strs length is null string new meta str if meta str null return set meta string strs else new meta str new string meta str length strs length if meta str null system arraycopy meta str 0 new meta str 0 meta str length system arraycopy strs 0 new meta str meta str length strs length return set meta string strs addmetastrings getmetastrings nullpointerexception newmetastr metastr setmetastring newmetastr metastr metastr metastr newmetastr metastr newmetastr metastr setmetastring public freeneturi add meta strings list string meta strings return add meta strings meta strings to array new string meta strings size addmetastrings metastrings addmetastrings metastrings toarray metastrings returns a copy of this uri with a new document name set public freeneturi set doc name string name return new freeneturi key type name meta str routing key crypto key extra suggested edition setdocname keytype metastr routingkey cryptokey suggestededition public freeneturi set meta string string new meta str return new freeneturi key type doc name new meta str routing key crypto key extra suggested edition setmetastring newmetastr keytype docname newmetastr routingkey cryptokey suggestededition override public string to string if to string cache null to string cache to string false false super to string unique hash code return to string cache tostring tostringcache tostringcache tostring tostring uniquehashcode tostringcache deprecated use link toascii string instead deprecated public string toacii string return toascii string toasciistring toaciistring toasciistring public string toascii string return to string true true toasciistring tostring public string to string boolean prefix boolean pure ascii if key type null not activated or something if logminor logger minor this not activated in to string prefix pure ascii return null string builder b if prefix b new string builder freenet else b new string builder b append key type append if ksk equals key type if routing key null b append base64 encode routing key if crypto key null b append append base64 encode crypto key if extra null b append append base64 encode extra if doc name null b append if doc name null b append url encoder encode doc name pure ascii if key type equals usk b append b append suggested edition if meta str null for int i 0 i meta str length i b append append url encoder encode meta str i pure ascii return b to string tostring pureascii keytype tostring pureascii stringbuilder stringbuilder stringbuilder keytype keytype routingkey routingkey cryptokey cryptokey docname docname urlencoder docname pureascii keytype suggestededition metastr metastr urlencoder metastr pureascii tostring public string to short string string builder b new string builder b append key type append if ksk equals key type b append if doc name null b append if doc name null b append url encoder encode doc name false if key type equals usk b append b append suggested edition if meta str null for int i 0 i meta str length i b append append url encoder encode meta str i false return b to string toshortstring stringbuilder stringbuilder keytype keytype docname docname urlencoder docname keytype suggestededition metastr metastr urlencoder metastr tostring public static void main string args throws exception new freeneturi args 0 decompose public byte get extra return extra getextra public array list string list meta strings if meta str null array list string l new array list string meta str length for int i 0 i meta str length i l add meta str i return l else return new array list string 0 arraylist listmetastrings metastr arraylist arraylist metastr metastr metastr arraylist public static freeneturi read full binary key with length data input stream dis throws io exception int len dis read short byte buf new byte len dis read fully buf if logminor logger minor freeneturi class read len bytes for key return from full binary key buf readfullbinarykeywithlength datainputstream ioexception readshort readfully fromfullbinarykey public static freeneturi from full binary key byte buf throws io exception byte array input stream bais new byte array input stream buf data input stream dis new data input stream bais return read full binary key dis fromfullbinarykey ioexception bytearrayinputstream bytearrayinputstream datainputstream datainputstream readfullbinarykey public static freeneturi read full binary key data input stream dis throws io exception byte type dis read byte string key type if type chk key type chk else if type ssk key type ssk else if type ksk key type ksk else throw new malformedurl exception unrecognized type type byte routing key null byte crypto key null byte extra null if type chk type ssk routing key is a hash so is exactly 32 bytes routing key new byte 32 dis read fully routing key crypto key is a 256 bit aes key so likewise crypto key new byte 32 dis read fully crypto key number of bytes of extra depends on key type int extra len extra len type chk clientchk extra length clientssk extra length extra new byte extra len dis read fully extra string doc name null if type chk doc name dis readutf int count dis read int string meta strings new string count for int i 0 i meta strings length i meta strings i dis readutf return new freeneturi key type doc name meta strings routing key crypto key extra readfullbinarykey datainputstream ioexception readbyte keytype keytype keytype keytype malformedurlexception routingkey cryptokey routingkey routingkey readfully routingkey cryptokey cryptokey readfully cryptokey extralen extralen extra_length extra_length extralen readfully docname docname readint metastrings metastrings metastrings keytype docname metastrings routingkey cryptokey write a binary representation of this uri with a short length so it can be passed over if necessary param dos the stream to write to throws malformedurl exception if the key could not be written because of inconsistencies or other problems in the key itself throws io exception if an error occurred while writing the key public void write full binary key with length data output stream dos throws io exception byte array output stream baos new byte array output stream data output stream ndos new data output stream baos write full binary key ndos ndos close byte data baos to byte array if data length short max value throw new malformedurl exception full key too long data length this dos write short short data length if logminor logger minor this written data length bytes dos write data malformedurlexception ioexception writefullbinarykeywithlength dataoutputstream ioexception bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream writefullbinarykey tobytearray max_value malformedurlexception writeshort write a binary representation of this uri param dos the stream to write to throws malformedurl exception if the key could not be written because of inconsistencies or other problems in the key itself throws io exception if an error occurred while writing the key private void write full binary key data output stream dos throws io exception if key type equals chk dos write byte chk else if key type equals ssk dos write byte ssk else if key type equals ksk dos write byte ksk else if key type equals usk throw new malformedurl exception cannot write us ks as binary keys else throw new malformedurl exception cannot write key of type key type do not know how if key type equals ksk if routing key length 32 throw new malformedurl exception routing key must be of length 32 dos write routing key if crypto key length 32 throw new malformedurl exception crypto key must be of length 32 dos write crypto key if key type equals chk extra length clientchk extra length throw new malformedurl exception wrong number of extra bytes for chk if key type equals ssk extra length clientssk extra length throw new malformedurl exception wrong number of extra bytes for ssk dos write extra if key type equals chk dos writeutf doc name if meta str null dos write int meta str length for int i 0 i meta str length i dos writeutf meta str i else dos write int 0 malformedurlexception ioexception writefullbinarykey dataoutputstream ioexception keytype writebyte keytype writebyte keytype writebyte keytype malformedurlexception usks malformedurlexception keytype keytype routingkey malformedurlexception routingkey cryptokey malformedurlexception cryptokey keytype extra_length malformedurlexception keytype extra_length malformedurlexception keytype docname metastr writeint metastr metastr metastr writeint get suggested edition only valid for us ks public long get suggested edition if key type equals usk return suggested edition else throw new illegal argument exception not a usk requesting suggested edition usks getsuggestededition keytype suggestededition illegalargumentexception public string get preferred filename if logminor logger minor this getting preferred filename for this array list string names new array list string if key type null key type equals ksk key type equals ssk key type equals usk if logminor logger minor this adding doc name doc name names add doc name if key type equals usk names add long to string suggested edition if meta str null for int i 0 i meta str length i if logminor logger minor this adding meta string i meta str i names add meta str i string builder out new string builder for int i 0 i names size i string s names get i if logminor logger minor this name i s s file util sanitize s if logminor logger minor this sanitized name i s if s length 0 if out length 0 out append out append s if logminor logger minor this out out to string if out length 0 if routing key null if logminor logger minor this returning base64 encoded routing key return base64 encode routing key return unknown return out to string getpreferredfilename arraylist arraylist keytype keytype keytype keytype docname docname docname keytype tostring suggestededition metastr metastr metastring metastr metastr stringbuilder stringbuilder fileutil tostring routingkey routingkey tostring public freeneturi set suggested edition long new edition return new freeneturi key type doc name meta str routing key crypto key extra new edition setsuggestededition newedition keytype docname metastr routingkey cryptokey newedition public freeneturi set key type string new key type return new freeneturi new key type doc name meta str routing key crypto key extra suggested edition setkeytype newkeytype newkeytype docname metastr routingkey cryptokey suggestededition public freeneturi set routing key byte new routing key return new freeneturi key type doc name meta str new routing key crypto key extra suggested edition setroutingkey newroutingkey keytype docname metastr newroutingkey cryptokey suggestededition public void check inserturi throws insert exception if meta str null meta str length 0 throw new insert exception insert exception meta strings not supported this checkinserturi insertexception metastr metastr insertexception insertexception meta_strings_not_supported public static void check inserturi freeneturi uri throws insert exception uri check inserturi checkinserturi insertexception checkinserturi public uri to relativeuri throws uri syntax exception single argument constructor used because it preserves encoded es in path hence we can have slashes question marks etc in the path but they are encoded return new uri to string false false torelativeuri urisyntaxexception tostring public uri touri string base path throws uri syntax exception return new uri base path to string false false basepath urisyntaxexception basepath tostring public boolean isssk return ssk equals key type keytype public void remove from object container container all members are inline arrays ints etc treated as values so we can happily just call delete this container delete this removefrom objectcontainer public boolean object can new object container container if this freeneturi empty chk uri throw new runtime exception storing static chk to database can t remove it return true objectcannew objectcontainer empty_chk_uri runtimeexception public boolean object can update object container container if container ext is active this logger error this updating but not active new exception error return false return true objectcanupdate objectcontainer isactive public void object on delete object container container if logger should log logger debug this logger debug this deleting uri new exception debug objectondelete objectcontainer shouldlog public boolean isusk return usk equals key type keytype public boolean ischk return chk equals key type keytype public freeneturi ssk forusk if key type equals ignore case usk throw new illegal state exception return new freeneturi ssk doc name suggested edition meta str routing key crypto key extra 0 sskforusk keytype equalsignorecase illegalstateexception docname suggestededition metastr routingkey cryptokey public boolean isssk forusk return key type equals ignore case ssk doc name matches 0 9 issskforusk keytype equalsignorecase docname public freeneturi usk forssk if key type equals ignore case ssk throw new illegal state exception if doc name matches 0 9 throw new illegal state exception int offset doc name last index of string site name doc name substring 0 offset long edition long value of doc name substring offset 1 doc name length return new freeneturi usk site name meta str routing key crypto key extra edition uskforssk keytype equalsignorecase illegalstateexception docname illegalstateexception docname lastindexof sitename docname valueof docname docname sitename metastr routingkey cryptokey public long get edition if key type equals ignore case usk return suggested edition else if key type equals ignore case ssk if doc name matches 0 9 taken from usk forssk also modify there if necessary throw new illegal state exception return long value of doc name substring doc name last index of 1 doc name length else throw new illegal state exception getedition keytype equalsignorecase suggestededition keytype equalsignorecase docname uskforssk illegalstateexception valueof docname docname lastindexof docname illegalstateexception ttree page pg page reference ttree page p pg p ttreepage pagereference ttreepage public boolean recursive loading return false recursiveloading ttree page ttreepage ttree page i persistent mbr n items 1 item new i persistent max items item 0 mbr ttreepage ipersistent nitems ipersistent maxitems final i persistent load item int i i persistent mbr item i mbr load return mbr ipersistent loaditem ipersistent final boolean find persistent comparator comparator object min value int min inclusive object max value int max inclusive array list selection int l r m n load n n items if min value null if comparator compare member with key load item 0 min value min inclusive if comparator compare member with key load item n 1 min value min inclusive if right null return right find comparator min value min inclusive max value max inclusive selection return true for l 0 r n l r m l r 1 if comparator compare member with key load item m min value min inclusive l m 1 else r m while r n if max value null comparator compare member with key load item r max value max inclusive return false selection add load item r r 1 if right null return right find comparator min value min inclusive max value max inclusive selection return true if left null if left find comparator min value min inclusive max value max inclusive selection return false for l 0 l n l if max value null comparator compare member with key load item l max value max inclusive return false selection add load item l if right null return right find comparator min value min inclusive max value max inclusive selection return true persistentcomparator minvalue mininclusive maxvalue maxinclusive arraylist nitems minvalue comparememberwithkey loaditem minvalue mininclusive comparememberwithkey loaditem minvalue mininclusive minvalue mininclusive maxvalue maxinclusive comparememberwithkey loaditem minvalue mininclusive maxvalue comparememberwithkey loaditem maxvalue maxinclusive loaditem minvalue mininclusive maxvalue maxinclusive minvalue mininclusive maxvalue maxinclusive maxvalue comparememberwithkey loaditem maxvalue maxinclusive loaditem minvalue mininclusive maxvalue maxinclusive final boolean contains persistent comparator comparator i persistent key int l r m n load n n items if comparator compare members load item 0 key 0 if comparator compare members load item n 1 key 0 if right null return right contains comparator key return false for l 0 r n l r m l r 1 if comparator compare members load item m key 0 l m 1 else r m while r n if key equals load item r return true if comparator compare members item r key 0 return false r 1 if right null return right contains comparator key return false if left null if left contains comparator key return true for l 0 l n l if key equals load item l return true if comparator compare members item l key 0 return false if right null return right contains comparator key return false persistentcomparator ipersistent nitems comparemembers loaditem comparemembers loaditem comparemembers loaditem loaditem comparemembers loaditem comparemembers final boolean contains key persistent comparator comparator object key int l r m n load n n items if comparator compare member with key load item 0 key 0 if comparator compare member with key load item n 1 key 0 if right null return right contains key comparator key return false for l 0 r n l r m l r 1 if comparator compare member with key load item m key 0 l m 1 else r m while r n int diff comparator compare member with key load item r key if diff 0 return true else if diff 0 return false r 1 if right null return right contains key comparator key return false if left null if left contains key comparator key return true for l 0 l n l int diff comparator compare member with key load item l key if diff 0 return true else if diff 0 return false if right null return right contains key comparator key return false containskey persistentcomparator nitems comparememberwithkey loaditem comparememberwithkey loaditem containskey comparememberwithkey loaditem comparememberwithkey loaditem containskey containskey comparememberwithkey loaditem containskey final boolean contains object persistent comparator comparator i persistent mbr int l r m n load n n items if comparator compare members load item 0 mbr 0 if comparator compare members load item n 1 mbr 0 if right null return right contains object comparator mbr return false for l 0 r n l r m l r 1 if comparator compare members load item m mbr 0 l m 1 else r m while r n if mbr item r return true if comparator compare members item r mbr 0 return false r 1 if right null return right contains object comparator mbr return false if left null if left contains object comparator mbr return true for l 0 l n l if mbr item l return true if comparator compare members item l mbr 0 return false if right null return right contains object comparator mbr return false containsobject persistentcomparator ipersistent nitems comparemembers loaditem comparemembers loaditem containsobject comparemembers loaditem comparemembers containsobject containsobject comparemembers containsobject final int insert persistent comparator comparator i persistent mbr boolean unique page reference ref load int n n items ttree page pg int diff comparator compare members mbr load item 0 if diff 0 if unique diff 0 return not unique if left null diff 0 n max items modify for int i n i 0 i item i item i 1 system arraycopy item 0 item 1 n item 0 mbr n items 1 return ok if left null modify left new ttree page mbr else pg ref pg ref pg left int result left insert comparator mbr unique ref if result not unique return not unique modify left ref pg ref pg pg if result ok return ok if balance 0 balance 0 return ok else if balance 0 balance 1 return overflow else ttree page left this left left load left modify if left balance 0 single ll turn this left left right left right this balance 0 left balance 0 ref pg left else double lr turn ttree page right left right right load right modify left right right left right left left this left right right right right this balance right balance 0 1 0 left balance right balance 0 1 0 right balance 0 ref pg right return ok diff comparator compare members mbr load item n 1 if diff 0 if unique diff 0 return not unique if right null diff 0 n max items modify item n mbr n items 1 return ok if right null modify right new ttree page mbr else pg ref pg ref pg right int result right insert comparator mbr unique ref if result not unique return not unique modify right ref pg ref pg pg if result ok return ok if balance 0 balance 0 return ok else if balance 0 balance 1 return overflow else ttree page right this right right load right modify if right balance 0 single rr turn this right right left right left this balance 0 right balance 0 ref pg right else double rl turn ttree page left right left left load left modify right left left right left right right this right left left left left this balance left balance 0 1 0 right balance left balance 0 1 0 left balance 0 ref pg left return ok int l 1 r n 1 while l r int i l r 1 diff comparator compare members mbr load item i if diff 0 l i 1 else r i if diff 0 if unique return not unique break insert before item r modify if n max items system arraycopy item r item r 1 n r for int i n i r i item i item i 1 item r mbr n items 1 return ok else i persistent reinsert item if balance 0 reinsert item load item 0 system arraycopy item 1 item 0 r 1 for int i 1 i r i item i 1 item i item r 1 mbr else reinsert item load item n 1 system arraycopy item r item r 1 n r 1 for int i n 1 i r i item i item i 1 item r mbr return insert comparator reinsert item unique ref persistentcomparator ipersistent pagereference nitems ttreepage comparemembers loaditem not_unique maxitems nitems ttreepage not_unique not_unique ttreepage ttreepage comparemembers loaditem not_unique maxitems nitems ttreepage not_unique not_unique ttreepage ttreepage comparemembers loaditem not_unique maxitems nitems ipersistent reinsertitem reinsertitem loaditem reinsertitem loaditem reinsertitem final int balance left branch page reference ref if balance 0 balance 0 return underflow else if balance 0 balance 1 return ok else ttree page right this right right load right modify if right balance 0 single rr turn this right right left right left this if right balance 0 this balance 1 right balance 1 ref pg right return ok else balance 0 right balance 0 ref pg right return underflow else double rl turn ttree page left right left left load left modify right left left right left right right this right left left left left this balance left balance 0 1 0 right balance left balance 0 1 0 left balance 0 ref pg left return underflow balanceleftbranch pagereference ttreepage ttreepage final int balance right branch page reference ref if balance 0 balance 0 return underflow else if balance 0 balance 1 return ok else ttree page left this left left load left modify if left balance 0 single ll turn this left left right left right this if left balance 0 balance 1 left balance 1 ref pg left return ok else balance 0 left balance 0 ref pg left return underflow else double lr turn ttree page right left right right load right modify left right right left right left left this left right right right right this balance right balance 0 1 0 left balance right balance 0 1 0 right balance 0 ref pg right return underflow balancerightbranch pagereference ttreepage ttreepage final int remove persistent comparator comparator i persistent mbr page reference ref load ttree page pg int n n items int diff comparator compare members mbr load item 0 if diff 0 if left null modify pg ref pg ref pg left int h left remove comparator mbr ref left ref pg ref pg pg if h underflow return balance left branch ref else if h ok return ok diff comparator compare members mbr load item n 1 if diff 0 for int i 0 i n i if item i mbr if n 1 if right null deallocate ref pg left return underflow else if left null deallocate ref pg right return underflow modify if n min items if left null balance 0 ttree page prev left prev load while prev right null prev prev right prev load system arraycopy item 0 item 1 i while i 0 item i 1 item i item 0 prev item prev n items 1 pg ref pg ref pg left int h left remove comparator load item 0 ref left ref pg ref pg pg if h underflow h balance left branch ref return h else if right null ttree page next right next load while next left null next next left next load system arraycopy item i 1 item i n i 1 while i n item i 1 item i item n 1 next item 0 pg ref pg ref pg right int h right remove comparator load item n 1 ref right ref pg ref pg pg if h underflow h balance right branch ref return h system arraycopy item i 1 item i n i 1 while i n item i 1 item i item n 1 null n items 1 return ok if right null modify pg ref pg ref pg right int h right remove comparator mbr ref right ref pg ref pg pg if h underflow return balance right branch ref else return h return not found persistentcomparator ipersistent pagereference ttreepage nitems comparemembers loaditem balanceleftbranch comparemembers loaditem minitems ttreepage nitems loaditem balanceleftbranch ttreepage loaditem balancerightbranch nitems balancerightbranch not_found final int to array i persistent arr int index load if left null index left to array arr index for int i 0 n n items i n i arr index load item i if right null index right to array arr index return index toarray ipersistent toarray nitems loaditem toarray final void prune load if left null left prune if right null right prune deallocate private static final long serial versionuid 1 public incoming packet filter exception string string super string serialversionuid incomingpacketfilterexception public incoming packet filter exception super incomingpacketfilterexception private float s c public caustics filter causticsfilter specifies the scale of the texture param scale the scale of the texture min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale set the brightness param brightness the brightness min value 0 max value 1 see get brightness public void set brightness int brightness this brightness brightness getbrightness setbrightness get the brightness return the brightness see set brightness public int get brightness return brightness setbrightness getbrightness specifies the turbulence of the texture param turbulence the turbulence of the texture min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the effect return the turbulence of the effect see set turbulence public float get turbulence return turbulence setturbulence getturbulence set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of effect return the amount see set amount public float get amount return amount setamount getamount set the dispersion param dispersion the dispersion min value 0 max value 1 see get dispersion public void set dispersion float dispersion this dispersion dispersion getdispersion setdispersion get the dispersion return the dispersion see set dispersion public float get dispersion return dispersion setdispersion getdispersion set the time use this to animate the effect param time the time see get time public void set time float time this time time gettime settime set the time return the time see set time public float get time return time settime gettime set the number of samples per pixel more samples means better quality but slower rendering param samples the number of samples see get samples public void set samples int samples this samples samples getsamples setsamples get the number of samples per pixel return the number of samples see set samples public int get samples return samples setsamples getsamples set the background color param c the color see get bg color public void set bg color int c bg color c getbgcolor setbgcolor bgcolor get the background color return the color see set bg color public int get bg color return bg color setbgcolor getbgcolor bgcolor override protected int filter pixels int width int height int in pixels rectangle transformed space random random new random 0 s float math sin 0 1 c float math cos 0 1 int src width original space width int src height original space height int out width transformed space width int out height transformed space height int index 0 int pixels new int out width out height for int y 0 y out height y for int x 0 x out width x pixels index bg color int v brightness samples if v 0 v 1 float rs 1 0f scale float d 0 95f index 0 for int y 0 y out height y for int x 0 x out width x for int s 0 s samples s float sx x random next float float sy y random next float float nx sx rs float ny sy rs float x displacement y displacement float focus 0 1f amount x displacement evaluate nx d ny evaluate nx d ny y displacement evaluate nx ny d evaluate nx ny d if dispersion 0 for int c 0 c 3 c float ca 1 c dispersion float srcx sx scale focus x displacement ca float srcy sy scale focus y displacement ca if srcx 0 srcx out width 1 srcy 0 srcy out height 1 else int i int srcy out width int srcx int rgb pixels i int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if c 2 r v else if c 1 g v else b v if r 255 r 255 if g 255 g 255 if b 255 b 255 pixels i 0xff000000 r 16 g 8 b else float srcx sx scale focus x displacement float srcy sy scale focus y displacement if srcx 0 srcx out width 1 srcy 0 srcy out height 1 else int i int srcy out width int srcx int rgb pixels i int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r v g v b v if r 255 r 255 if g 255 g 255 if b 255 b 255 pixels i 0xff000000 r 16 g 8 b return pixels filterpixels inpixels transformedspace srcwidth originalspace srcheight originalspace outwidth transformedspace outheight transformedspace outwidth outheight outheight outwidth bgcolor outheight outwidth nextfloat nextfloat xdisplacement ydisplacement xdisplacement ydisplacement xdisplacement ydisplacement outwidth outheight outwidth xdisplacement ydisplacement outwidth outheight outwidth private static int add int rgb float brightness int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r brightness g brightness b brightness if r 255 r 255 if g 255 g 255 if b 255 b 255 return 0xff000000 r 16 g 8 b private static int add int rgb float brightness int c int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if c 2 r brightness else if c 1 g brightness else b brightness if r 255 r 255 if g 255 g 255 if b 255 b 255 return 0xff000000 r 16 g 8 b private static float turbulence2 float x float y float time float octaves float value 0 0f float remainder float lacunarity 2 0f float f 1 0f int i to prevent cascading effects x 371 y 529 for i 0 i int octaves i value noise noise3 x y time f x lacunarity y lacunarity f 2 remainder octaves int octaves if remainder 0 value remainder noise noise3 x y time f return value private float evaluate float x float y float xt s x c time float tt c x c time float f turbulence 0 0 noise noise3 xt y tt turbulence2 xt y tt turbulence return f override public string to string return texture caustics tostring final long created time uid tag created time system current time millis createdtime uidtag createdtime currenttimemillis public abstract void log still present long uid logstillpresent public abstract void log still present long uid long age return system current time millis created time logstillpresent currenttimemillis createdtime construct a flip filter which flips horizontally and vertically public flip filter this flip hv flipfilter flipfilter flip_hv construct a flip filter param operation the filter operation public flip filter int operation this operation operation flipfilter flipfilter set the filter operation param operation the filter operation see get operation public void set operation int operation this operation operation getoperation setoperation get the filter operation return the filter operation see set operation public int get operation return operation setoperation getoperation public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster int in pixels getrgb src 0 0 width height null int x 0 y 0 int w width int h height int newx 0 int newy 0 int neww w int newh h switch operation case flip h newx width x w break case flip v newy height y h break case flip hv neww h newh w newx y newy x break case flip 90cw neww h newh w newx height y h newy x break case flip 90ccw neww h newh w newx y newy width x w break case flip 180 newx width x w newy height y h break int new pixels new int neww newh for int row 0 row h row for int col 0 col w col int index row width col int new row row int new col col switch operation case flip h new col w col 1 break case flip v new row h row 1 break case flip hv new row col new col row break case flip 90cw new row col new col h row 1 break case flip 90ccw new row w col 1 new col row break case flip 180 new row h row 1 new col w col 1 break int new index new row neww new col new pixels new index in pixels index if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster neww newh dstcm is alpha premultiplied null writable raster dst raster dst get raster setrgb dst 0 0 neww newh new pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster inpixels flip_h flip_v flip_hv flip_90cw flip_90ccw flip_180 newpixels newrow newcol flip_h newcol flip_v newrow flip_hv newrow newcol flip_90cw newrow newcol flip_90ccw newrow newcol flip_180 newrow newcol newindex newrow newcol newpixels newindex inpixels colormodel getcolormodel bufferedimage createcompatiblewritableraster isalphapremultiplied writableraster dstraster getraster newpixels override public string to string switch operation case flip h return flip horizontal case flip v return flip vertical case flip hv return flip diagonal case flip 90cw return rotate 90 case flip 90ccw return rotate 90 case flip 180 return rotate 180 return flip tostring flip_h flip_v flip_hv flip_90cw flip_90ccw flip_180 logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog do the request blocking called by request starter also responsible for deleting it return true if a request was executed false if caller should try to find another request and remove this one from the queue public boolean send node client core core final request scheduler sched client context context chosen block req object key num req token client key key req ckey if key null logger error sendable get class key is null in send key num key num for req return false if logminor logger minor sendable get class sending get for key key num key if req is cancelled if logminor logger minor sendable get class cancelled req req on failure new low level get exception low level get exception cancelled context return false try try core real get key key req local request only req cache local requests req ignore store catch final low level get exception e req on failure e context return true catch throwable t logger error this caught t t req on failure new low level get exception low level get exception internal error context return true req on fetch success context catch throwable t logger error this caught t t req on failure new low level get exception low level get exception internal error context return true return true requeststarter nodeclientcore requestscheduler clientcontext chosenblock keynum clientkey sendableget keynum keynum sendableget keynum iscancelled sendableget onfailure lowlevelgetexception lowlevelgetexception realgetkey localrequestonly cachelocalrequests ignorestore lowlevelgetexception onfailure onfailure lowlevelgetexception lowlevelgetexception internal_error onfetchsuccess onfailure lowlevelgetexception lowlevelgetexception internal_error public void run plugin plugin respirator mypr try logger debug this start catpcha generation needs headless mode on linux system set property java awt headless true mpr mypr mdb initdb database filename fixme change before release m config config load or create this if m config get int config database format version wot database format version throw new runtime exception the wot plugin s database format is newer than the wot plugin which is being used upgradedb delete duplicate objects delete orphan objects mxml transformer new xml transformer this m puzzle store new introduction puzzle store this m request client new request client public boolean persistent return false public void remove from object container container throw new unsupported operation exception create seed identities m inserter new identity inserter this m fetcher new identity fetcher this m introduction server new introduction server this m fetcher m introduction client new introduction client this m web interface new web interface this self uri mfcp interface new fcp interface this logger debug this starting fetches of all identities synchronized this for identity identity get all identities m fetcher fetch identity true logger debug this wot startup completed catch exception e logger error this error during startup e we call it so the database is properly closed terminate runplugin pluginrespirator setproperty database_filename mconfig loadorcreate mconfig getint database_format_version database_format_version runtimeexception deleteduplicateobjects deleteorphanobjects mxmltransformer xmltransformer mpuzzlestore introductionpuzzlestore mrequestclient requestclient removefrom objectcontainer unsupportedoperationexception createseedidentities minserter identityinserter mfetcher identityfetcher mintroductionserver introductionserver mfetcher mintroductionclient introductionclient mwebinterface webinterface self_uri mfcpinterface fcpinterface getallidentities mfetcher m request client new request client public boolean persistent return false mrequestclient requestclient public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public wot for use by the unit tests to be able to run wot without a node param database filename the filename of the database public wot string database filename mdb initdb database filename m config config load or create this if m config get int config database format version wot database format version throw new runtime exception the wot plugin s database format is newer than the wot plugin which is being used databasefilename databasefilename databasefilename mconfig loadorcreate mconfig getint database_format_version database_format_version runtimeexception initializes the plugin s db4o database return a db4o code object container code private ext object container initdb string filename configuration cfg db4o new configuration cfg reflect with new jdk reflector m class loader cfg activation depth 5 fixme change to 1 and add explicit activation everywhere cfg exceptions on not storable true for string field identity get indexed fields cfg object class identity class object field field indexed true for string field own identity get indexed fields cfg object class own identity class object field field indexed true for string field trust get indexed fields cfg object class trust class object field field indexed true for string field score get indexed fields cfg object class score class object field field indexed true cfg object class introduction puzzle puzzle type class persist static field values needed to be able to store enums for string field introduction puzzle get indexed fields cfg object class introduction puzzle class object field field indexed true return db4o open file cfg filename ext objectcontainer extobjectcontainer newconfiguration reflectwith jdkreflector mclassloader activationdepth exceptionsonnotstorable getindexedfields objectclass objectfield ownidentity getindexedfields objectclass ownidentity objectfield getindexedfields objectclass objectfield getindexedfields objectclass objectfield objectclass introductionpuzzle puzzletype persiststaticfieldvalues introductionpuzzle getindexedfields objectclass introductionpuzzle objectfield openfile private synchronized void upgradedb int old version m config get int config database format version if old version wot database format version return if old version 100 logger normal this found old database 100 adding last fetched date to all identities for identity identity get all identities identity m last fetched date new date 0 store and commit identity m config set config database format version wot database format version m config store and commit else throw new runtime exception your database is too outdated to be upgraded automatically please create a new one by deleting database filename contact the developers if you really need your old data oldversion mconfig getint database_format_version oldversion database_format_version oldversion getallidentities mlastfetcheddate storeandcommit mconfig database_format_version database_format_version mconfig storeandcommit runtimeexception database_filename debug function for deleting duplicate identities etc which might have been created due to bugs suppress warnings unchecked private synchronized void delete duplicate objects synchronized mdb try object set identity identities get all identities hash set string deleted new hash set string for identity identity identities query q mdb query q constrain identity class q descend mid constrain identity getid q constrain identity identity not object set identity duplicates q execute for identity duplicate duplicates if deleted contains duplicate getid false logger error duplicate deleting duplicate identity duplicate get requesturi for trust trust get received trusts duplicate mdb delete trust for trust trust get given trusts duplicate mdb delete trust for score score get scores duplicate mdb delete score mdb delete duplicate deleted add identity getid mdb commit catch runtime exception e mdb rollback logger error this error while deleting duplicate identities e try for own identity tree owner get all own identities hash set string given to new hash set string for trust trust get given trusts tree owner if given to contains trust get trustee getid false given to add trust get trustee getid else identity trustee trust get trustee logger error this deleting duplicate given trust from tree owner get nickname to trustee get nickname mdb delete trust try update score without commit tree owner trustee catch exception e maybe another duplicate prevents it from working logger error this updating score of trustee get nickname failed e mdb commit catch runtime exception e mdb rollback logger error this error while deleting duplicate trusts e fixme also delete duplicate trust score etc suppresswarnings deleteduplicateobjects objectset getallidentities hashset hashset objectset getrequesturi getreceivedtrusts getgiventrusts getscores runtimeexception ownidentity treeowner getallownidentities hashset givento hashset getgiventrusts treeowner givento gettrustee givento gettrustee gettrustee treeowner getnickname getnickname updatescorewithoutcommit treeowner getnickname runtimeexception debug function for deleting trusts or scores of which one of the involved partners is missing suppress warnings unchecked private synchronized void delete orphan objects synchronized mdb try query q mdb query q constrain trust class q descend m truster constrain null identity or q descend m trustee constrain null identity object set trust orphan trusts q execute for trust trust orphan trusts logger error trust deleting orphan trust truster trust get truster trustee trust get trustee mdb delete trust catch exception e logger error this deleting orphan trusts failed e mdb rollback no need to do so here try query q mdb query q constrain score class q descend m tree owner constrain null identity or q descend m target constrain null identity object set score orphan scores q execute for score score orphan scores logger error score deleting orphan score tree owner score get tree owner target score get target mdb delete score mdb commit catch exception e logger error this deleting orphan trusts failed e mdb rollback no need to do so here suppresswarnings deleteorphanobjects mtruster mtrustee objectset orphantrusts orphantrusts gettruster gettrustee mtreeowner mtarget objectset orphanscores orphanscores treeowner gettreeowner gettarget private synchronized void create seed identities for string seeduri seed identities identity seed try seed get identity byuri seeduri if seed instanceof own identity own identity own seed own identity seed fixme does the cast make that necessary i m adding it to make sure that we do not lose information when storing mdb activate own seed 5 own seed add context introduction puzzle introduction context own seed set property introduction server puzzle count property integer to string introduction server seed identity puzzle count store and commit own seed try seed set edition new freeneturi seeduri get edition catch exception e we already have the latest edition stored catch unknown identity exception uie try seed new identity seeduri null true store and commit seed catch exception e logger error this seed identity creation error e catch exception e logger error this seed identity loading error e createseedidentities seed_identities getidentitybyuri ownidentity ownidentity ownseed ownidentity ownseed ownseed addcontext introductionpuzzle introduction_context ownseed setproperty introductionserver puzzle_count_property tostring introductionserver seed_identity_puzzle_count storeandcommit ownseed setedition getedition unknownidentityexception storeandcommit public void terminate logger debug this wot plugin terminating we use single try catch blocks so that failure of termination of one service does not prevent termination of the others try if m introduction client null m introduction client terminate catch exception e logger error this error during termination e try if m introduction server null m introduction server terminate catch exception e logger error this error during termination e try if m inserter null m inserter terminate catch exception e logger error this error during termination e try if m fetcher null m fetcher stop catch exception e logger error this error during termination e try if mdb null fixme is it possible to ask db4o whether a transaction is pending if the plugin s synchronization works correctly none should be pending here and we should log an error if there are any pending transactions at this point synchronized mdb lock mdb rollback mdb close catch exception e logger error this error during termination e logger debug this wot plugin terminated mintroductionclient mintroductionclient mintroductionserver mintroductionserver minserter minserter mfetcher mfetcher inherited event handler from fred pluginhttp handled in code class web interface code public string handlehttp get http request request throws pluginhttp exception return m web interface handlehttp get request fredpluginhttp webinterface handlehttpget httprequest pluginhttpexception mwebinterface handlehttpget inherited event handler from fred pluginhttp handled in code class web interface code public string handlehttp post http request request throws pluginhttp exception return m web interface handlehttp post request fredpluginhttp webinterface handlehttppost httprequest pluginhttpexception mwebinterface handlehttppost inherited event handler from fred pluginhttp handled in code class web interface code public string handlehttp put http request request throws pluginhttp exception return m web interface handlehttp put request fredpluginhttp webinterface handlehttpput httprequest pluginhttpexception mwebinterface handlehttpput inherited event handler from fred pluginfcp handled in code class fcp interface code public void handle plugin reply sender replysender simple field set params bucket data int accesstype mfcp interface handle replysender params data accesstype fredpluginfcp fcpinterface pluginreplysender simplefieldset mfcpinterface loads an own or normal identity from the database querying on its id param id the id of the identity to load return the identity matching the supplied id throws duplicate identity exception if there are more than one identity with this id in the database throws unknown identity exception if there is no identity with this id in the database suppress warnings unchecked public synchronized identity get identity byid string id throws unknown identity exception query query mdb query query constrain identity class query descend mid constrain id object set identity result query execute if result size 0 throw new unknown identity exception id if result size 1 throw new duplicate identity exception id return result next duplicateidentityexception unknownidentityexception suppresswarnings getidentitybyid unknownidentityexception objectset unknownidentityexception duplicateidentityexception gets an own identity by its id param id the unique identifier to query an own identity return the requested own identity throws unknown identity exception if there is now own identity with that id suppress warnings unchecked public synchronized own identity get own identity byid string id throws unknown identity exception query query mdb query query constrain own identity class query descend mid constrain id object set own identity result query execute if result size 0 throw new unknown identity exception id if result size 1 throw new duplicate identity exception id return result next ownidentity ownidentity ownidentity unknownidentityexception ownidentity suppresswarnings ownidentity getownidentitybyid unknownidentityexception ownidentity objectset ownidentity unknownidentityexception duplicateidentityexception loads an identity from the database querying on its requesturi a valid link freeneturi param uri the requesturi of the identity return the identity matching the supplied requesturi throws unknown identity exception if there is no identity with this id in the database throws duplicate identity exception if there are more than one identity with this id in the database public identity get identity byuri freeneturi uri throws unknown identity exception return get identity byid identity getid fromuri uri unknownidentityexception duplicateidentityexception getidentitybyuri unknownidentityexception getidentitybyid getidfromuri loads an identity from the database querying on its requesturi as string param uri the requesturi of the identity which will be converted to link freeneturi return the identity matching the supplied requesturi throws unknown identity exception if there is no identity with this id in the database throws duplicate identity exception if there are more than one identity with this id in the database throws malformedurl exception if the requesturi isn t a valid freeneturi public identity get identity byuri string uri throws unknown identity exception malformedurl exception return get identity byuri new freeneturi uri unknownidentityexception duplicateidentityexception malformedurlexception getidentitybyuri unknownidentityexception malformedurlexception getidentitybyuri gets an own identity by its requesturi a link freeneturi the own identity s unique identifier is extracted from the supplied requesturi param uri the requesturi of the desired own identity return the requested own identity throws unknown identity exception if the own identity isn t in the database public own identity get own identity byuri freeneturi uri throws unknown identity exception return get own identity byid own identity getid fromuri uri ownidentity ownidentity ownidentity ownidentity unknownidentityexception ownidentity ownidentity getownidentitybyuri unknownidentityexception getownidentitybyid ownidentity getidfromuri gets an own identity by its requesturi as string the given string is converted to link freeneturi in order to extract a unique id param db a reference to the database param uri the requesturi as string of the desired own identity return the requested own identity throws unknown identity exception if the own identity isn t in the database throws duplicate identity exception if the own identity is present more that once in the database should never happen throws malformedurl exception if the supplied requesturi is not a valid freeneturi public own identity get own identity byuri string uri throws unknown identity exception malformedurl exception return get own identity byuri new freeneturi uri ownidentity ownidentity ownidentity unknownidentityexception ownidentity duplicateidentityexception ownidentity malformedurlexception ownidentity getownidentitybyuri unknownidentityexception malformedurlexception getownidentitybyuri returns all identities that are in the database you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all identities present in the database public synchronized object set identity get all identities return mdb query by example identity class objectset objectset getallidentities querybyexample returns all non own identities that are in the database you have to synchronize on this wot when calling the function and processing the returned list suppress warnings unchecked public synchronized object set identity get all non own identities query q mdb query q constrain identity class q constrain own identity class not return q execute suppresswarnings objectset getallnonownidentities ownidentity returns all non own identities that are in the database sorted descending by their date of modification i e recently modified identities will be at the beginning of the list you have to synchronize on this wot when calling the function and processing the returned list used by the introduction client for fetching puzzles from recently modified identities suppress warnings unchecked public synchronized object set identity get all non own identities sorted by modification query q mdb query q constrain identity class q constrain own identity class not fixme as soon as identities announce that they were online every day uncomment the following line q descend m last changed date constrain new date current timeutc get in millis 1 24 60 60 1000 greater q descend m last fetched date order descending return q execute introductionclient suppresswarnings objectset getallnonownidentitiessortedbymodification ownidentity mlastchangeddate currenttimeutc getinmillis mlastfetcheddate orderdescending returns all own identities that are in the database you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all identities present in the database public synchronized object set own identity get all own identities return mdb query by example own identity class objectset objectset ownidentity getallownidentities querybyexample ownidentity public synchronized void store and commit identity identity synchronized identity synchronized mdb lock if mdb ext is stored identity mdb ext is active identity throw new runtime exception trying to store an inactive identity object fixme we also need to check whether the member objects are active here try if identity instanceof own identity own identity own id own identity identity mdb store own id m inserturi mdb store own id m creation date not stored because db4o considers it as a primitive and automatically stores it mdb store own id m last insert date not stored because db4o considers it as a primitive and automatically stores it mdb store mid not stored because db4o considers it as a primitive and automatically stores it mdb store identity m requesturi mdb store m first fetched date not stored because db4o considers it as a primitive and automatically stores it mdb store m last fetched date not stored because db4o considers it as a primitive and automatically stores it mdb store m last changed date not stored because db4o considers it as a primitive and automatically stores it mdb store m nickname not stored because db4o considers it as a primitive and automatically stores it mdb store m does publish trust list not stored because db4o considers it as a primitive and automatically stores it mdb store identity m properties mdb store identity m contexts mdb store identity mdb commit logger debug identity commited catch runtime exception e mdb rollback throw e storeandcommit isstored isactive runtimeexception ownidentity ownidentity ownid ownidentity ownid minserturi ownid mcreationdate ownid mlastinsertdate mrequesturi mfirstfetcheddate mlastfetcheddate mlastchangeddate mnickname mdoespublishtrustlist mproperties mcontexts runtimeexception gets the score of this identity in a trust tree each link own identity has its own trust tree param tree owner the owner of the trust tree param db a reference to the database return the link score of this identity in the required trust tree throws not in trust tree exception if this identity is not in the required trust tree suppress warnings unchecked public synchronized score get score own identity tree owner identity target throws not in trust tree exception query query mdb query query constrain score class query descend m tree owner constrain tree owner identity query descend m target constrain target identity object set score result query execute if result size 0 throw new not in trust tree exception target get requesturi is not in that trust tree if result size 1 throw new duplicate score exception target get requesturi target get nickname has result size scores in tree owner get nickname s trust tree return result next ownidentity treeowner notintrusttreeexception suppresswarnings getscore ownidentity treeowner notintrusttreeexception mtreeowner treeowner mtarget objectset notintrusttreeexception getrequesturi duplicatescoreexception getrequesturi getnickname treeowner getnickname gets a list of all this identity s scores you have to synchronize on this wot around the call to this function and the processing of the returned list param db a reference to the database return an link object set containing all link score this identity has suppress warnings unchecked public synchronized object set score get scores identity identity query query mdb query query constrain score class query descend m target constrain identity identity return query execute objectset suppresswarnings objectset getscores mtarget gets the best score this identity has in existing trust trees 0 if it is not in the trust tree return the best score this identity has public synchronized int get best score identity identity int best score 0 object set score scores get scores identity todo use a db4o native query for this loop maybe use an index indexes should be sorted so maximum search will be o 1 but i guess indexes cannot be done for the target value pair so we might just cache the best score ourselves otoh the number of own identies will be small so the maximum search will probably be fast while scores has next score score scores next best score math max score get score best score return best score getbestscore bestscore objectset getscores hasnext bestscore getscore bestscore bestscore get all scores in the database you have to synchronize on this wot when calling the function and processing the returned list public synchronized object set score get all scores return mdb query by example score class objectset getallscores querybyexample gets identities matching a specified score criteria you have to synchronize on this wot when calling the function and processing the returned list param owner requesturi of the owner of the trust tree null if you want the trusted identities of all owners param select score criteria can be 0 or return an link object set containing identities that match the criteria throws invalid parameter exception if the criteria is not recognised suppress warnings unchecked public synchronized object set score get identities by score own identity tree owner int select query query mdb query query constrain score class if tree owner null query descend m tree owner constrain tree owner identity query descend m target constrain own identity class not we include 0 in the list of identities with positive score because solving captchas gives no points to score if select 0 query descend m value constrain 0 smaller not else if select 0 query descend m value constrain 0 smaller else query descend m value constrain 0 return query execute objectset invalidparameterexception suppresswarnings objectset getidentitiesbyscore ownidentity treeowner treeowner mtreeowner treeowner mtarget ownidentity mvalue mvalue mvalue gets link trust from a specified truster to a specified trustee param truster the identity that gives trust to this identity param trustee the identity which receives the trust return the trust given to the trustee by the specified truster throws not trusted exception if the truster doesn t trust the trustee suppress warnings unchecked public synchronized trust get trust identity truster identity trustee throws not trusted exception duplicate trust exception query query mdb query query constrain trust class query descend m truster constrain truster identity query descend m trustee constrain trustee identity object set trust result query execute if result size 0 throw new not trusted exception truster get nickname does not trust trustee get nickname if result size 1 throw new duplicate trust exception trust from truster get nickname to trustee get nickname exists result size times in the database return result next nottrustedexception suppresswarnings gettrust nottrustedexception duplicatetrustexception mtruster mtrustee objectset nottrustedexception getnickname getnickname duplicatetrustexception getnickname getnickname gets all trusts given by the given truster you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all link trust the passed identity has given suppress warnings unchecked public synchronized object set trust get given trusts identity truster query query mdb query query constrain trust class query descend m truster constrain truster identity return query execute objectset suppresswarnings objectset getgiventrusts mtruster gets all trusts given by the given truster in a trust list older than the given edition number you have to synchronize on this wot when calling the function and processing the returned list suppress warnings unchecked protected synchronized object set trust get given trusts older than identity truster long edition query q mdb query q constrain trust class q descend m truster constrain truster identity q descend m truster trust list edition constrain edition smaller return q execute suppresswarnings objectset getgiventrustsolderthan mtruster mtrustertrustlistedition gets all trusts received by the given trustee you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all link trust the passed identity has received suppress warnings unchecked public synchronized object set trust get received trusts identity trustee query query mdb query query constrain trust class query descend m trustee constrain trustee identity return query execute objectset suppresswarnings objectset getreceivedtrusts mtrustee gets all trusts you have to synchronize on this wot when calling the function and processing the returned list return an link object set containing all link trust the passed identity has received suppress warnings unchecked public synchronized object set trust get all trusts query query mdb query query constrain trust class return query execute objectset suppresswarnings objectset getalltrusts gives some link trust to another identity it creates or updates an existing trust object and make the trustee compute its link score this function does neither lock the database nor commit the transaction you have to surround it with synchronized mdb lock try set trust without commit store and commit truster catch runtime exception e mdb rollback throw e param truster the identity that gives the trust param trustee the identity that receives the trust param new value numeric value of the trust param new comment a comment to explain the given value throws invalid parameter exception if a given parameter isn t valid see trust for details on accepted values protected synchronized void set trust without commit identity truster identity trustee byte new value string new comment throws invalid parameter exception trust trust try check if we are updating an existing trust value trust get trust truster trustee trust truster edition updated trust set comment new comment mdb store trust if trust get value new value trust set value new value mdb store trust logger debug this updated trust value trust now updating score update score without commit trustee catch not trusted exception e trust new trust truster trustee new value new comment mdb store trust logger debug this new trust value trust now updating score update score without commit trustee truster updated settrustwithoutcommit storeandcommit runtimeexception newvalue newcomment invalidparameterexception settrustwithoutcommit newvalue newcomment invalidparameterexception gettrust trustereditionupdated setcomment newcomment getvalue newvalue setvalue newvalue updatescorewithoutcommit nottrustedexception newvalue newcomment updatescorewithoutcommit only for being used by wot internally and by unit tests public synchronized void set trust identity truster identity trustee byte new value string new comment throws invalid parameter exception fixme throw if we are no unit test and the truster is no own identity assert truster instanceof own identity unit tests may ignore this synchronized mdb lock try set trust without commit truster trustee new value new comment store and commit truster catch runtime exception e mdb rollback throw e settrust newvalue newcomment invalidparameterexception ownidentity settrustwithoutcommit newvalue newcomment storeandcommit runtimeexception deletes a trust object param truster param trustee protected synchronized void remove trust own identity truster identity trustee synchronized mdb lock try try trust trust get trust truster trustee mdb delete trust update score without commit trustee catch not trusted exception e logger error this cannot remove trust there is none from truster get nickname to trustee get nickname catch runtime exception e mdb rollback throw e removetrust ownidentity gettrust updatescorewithoutcommit nottrustedexception getnickname getnickname runtimeexception this function does neither lock the database nor commit the transaction you have to surround it with synchronized mdb lock try set trust without commit store and commit truster catch runtime exception e mdb rollback throw e protected synchronized void remove trust without commit trust trust mdb delete trust update score without commit trust get trustee settrustwithoutcommit storeandcommit runtimeexception removetrustwithoutcommit updatescorewithoutcommit gettrustee initializes this own identity s trust tree meaning it creates a score object for this own identity in its own trust tree so it gets a rank and a capacity and can give trust to other identities param db a reference to the database throws duplicate score exception if there already is more than one score for this identity should never happen private synchronized void init trust tree own identity identity throws duplicate score exception synchronized mdb lock try get score identity identity logger error this init trus tree called even though there is already one for identity return catch not in trust tree exception e try mdb store new score identity identity 100 0 100 mdb commit catch runtime exception ex mdb rollback throw ex ownidentity ownidentity duplicatescoreexception inittrusttree ownidentity duplicatescoreexception getscore inittrustree notintrusttreeexception runtimeexception updates this identity s link score in every trust tree this function does neither lock the database nor commit the transaction you have to surround it with synchronized mdb lock try set trust without commit store and commit truster catch runtime exception e mdb rollback throw e private synchronized void update score without commit identity trustee object set own identity tree owners get all own identities if tree owners size 0 logger debug this can t update trustee get nickname s score there is no own identity yet while tree owners has next update score without commit tree owners next trustee settrustwithoutcommit storeandcommit runtimeexception updatescorewithoutcommit objectset ownidentity treeowners getallownidentities treeowners getnickname treeowners hasnext updatescorewithoutcommit treeowners updates this identity s link score in one trust tree makes this identity s trustees update their score if its capacity has changed this function does neither lock the database nor commit the transaction you have to surround it with synchronized mdb lock try set trust without commit store and commit truster catch runtime exception e mdb rollback throw e param db a reference to the database param tree owner the own identity that owns the trust tree private synchronized void update score without commit own identity tree owner identity target if target tree owner return boolean changed capacity false logger debug target updating target get nickname s score in tree owner get nickname s trust tree score score int value compute score value tree owner target int rank compute rank tree owner target if rank 1 1 value means the identity is not in the trust tree try if he had a score we delete it score get score tree owner target mdb delete score he had a score we delete it changed capacity true logger debug target target get nickname is not in tree owner get nickname s trust tree anymore catch not in trust tree exception e else the identity is in the trust tree we must detect if an identity had a null or negative score which has changed to positive if we download the trust list of someone who has no or negative score we do not create the identities in his trust list if the identity now gets a positive score we must re download his current trust list boolean score was negative false try get existing score or create one if needed score get score tree owner target score was negative score get score 0 catch not in trust tree exception e score new score tree owner target 0 1 0 score was negative true if score was negative score get score 0 target decrease edition logger debug this score changed from negative null to positive refetchting target get requesturi m fetcher fetch target score set value value score set rank rank 1 int old capacity score get capacity boolean has negative trust false does the tree owner personally distrust this identity try if get trust tree owner target get value 0 has negative trust true logger debug target target get nickname received negative trust from tree owner get nickname and therefore has no capacity in his trust tree catch not trusted exception e if has negative trust score set capacity 0 else score set capacity score get rank score capacities length 1 score capacities score get rank if score get capacity old capacity changed capacity true mdb store score logger debug target new score score to string if changed capacity we have to update trustees score object set trust given trusts get given trusts target logger debug target target get nickname s capacity has changed in tree owner get nickname s trust tree updating his given trusts size trustees for trust given trust given trusts update score without commit tree owner given trust get trustee settrustwithoutcommit storeandcommit runtimeexception treeowner ownidentity updatescorewithoutcommit ownidentity treeowner treeowner changedcapacity getnickname treeowner getnickname computescorevalue treeowner computerank treeowner getscore treeowner changedcapacity getnickname treeowner getnickname notintrusttreeexception scorewasnegative getscore treeowner scorewasnegative getscore notintrusttreeexception treeowner scorewasnegative scorewasnegative getscore decreaseedition getrequesturi mfetcher setvalue setrank oldcapacity getcapacity hasnegativetrust treeowner gettrust treeowner getvalue hasnegativetrust getnickname treeowner getnickname nottrustedexception hasnegativetrust setcapacity setcapacity getrank getrank getcapacity oldcapacity changedcapacity tostring changedcapacity objectset giventrusts getgiventrusts getnickname treeowner getnickname giventrusts giventrust giventrusts updatescorewithoutcommit treeowner giventrust gettrustee computes the target s score value according to the trusts it has received and the capacity of its trusters in the specified trust tree param db a reference to the database param tree owner the own identity that owns the trust tree return the new score if this identity throws duplicate score exception if there already exist more than one link score objects for the trustee should never happen private synchronized int compute score value own identity tree owner identity target throws duplicate score exception int value 0 object set trust received trusts get received trusts target while received trusts has next trust trust received trusts next try value trust get value get score tree owner trust get truster get capacity 100 catch not in trust tree exception e return value treeowner ownidentity duplicatescoreexception computescorevalue ownidentity treeowner duplicatescoreexception objectset receivedtrusts getreceivedtrusts receivedtrusts hasnext receivedtrusts getvalue getscore treeowner gettruster getcapacity notintrusttreeexception computes the target s rank in the trust tree it gets its best ranked truster s rank plus one or 1 if none of its trusters are in the trust tree param db a reference to the database param tree owner the own identity that owns the trust tree return the new rank if this identity throws duplicate score exception if there already exist more than one link score objects for the trustee should never happen private synchronized int compute rank own identity tree owner identity target throws duplicate score exception int rank 1 object set trust received trusts get received trusts target while received trusts has next trust trust received trusts next try score score get score tree owner trust get truster if score get capacity 0 if the truster has no capacity he can t give his rank if rank 1 score get rank rank if the truster s rank is better than ours or if we have not rank score get rank catch not in trust tree exception e return rank treeowner ownidentity duplicatescoreexception computerank ownidentity treeowner duplicatescoreexception objectset receivedtrusts getreceivedtrusts receivedtrusts hasnext receivedtrusts getscore treeowner gettruster getcapacity getrank getrank notintrusttreeexception public synchronized identity add identity string requesturi throws malformedurl exception invalid parameter exception identity identity try identity get identity byuri requesturi logger debug this tried to manually add an identity we already know ignored throw new invalid parameter exception we already have this identity catch unknown identity exception e identity new identity new freeneturi requesturi null false store and commit identity logger debug this trying to fetch manually added identity identity get requesturi m fetcher fetch identity return identity addidentity malformedurlexception invalidparameterexception getidentitybyuri invalidparameterexception unknownidentityexception storeandcommit getrequesturi mfetcher public synchronized void delete identity identity identity synchronized mdb lock try for score score get scores identity mdb delete score for trust trust get received trusts identity mdb delete trust for trust given trust get given trusts identity mdb delete given trust update score without commit given trust get trustee mdb delete identity mdb commit catch runtime exception e mdb rollback throw e deleteidentity getscores getreceivedtrusts giventrust getgiventrusts giventrust updatescorewithoutcommit giventrust gettrustee runtimeexception public synchronized void delete identity string id throws unknown identity exception synchronized mdb lock identity identity get identity byid id delete identity identity deleteidentity unknownidentityexception getidentitybyid deleteidentity public own identity create own identity string nick name boolean publish trust list string context throws malformedurl exception invalid parameter exception freeneturi keypair get plugin respirator gethl simple client generate key pair wot return create own identity keypair 0 to string keypair 1 to string nick name publish trust list context ownidentity createownidentity nickname publishtrustlist malformedurlexception invalidparameterexception getpluginrespirator gethlsimpleclient generatekeypair createownidentity tostring tostring nickname publishtrustlist public synchronized own identity create own identity string inserturi string requesturi string nick name boolean publish trust list string context throws malformedurl exception invalid parameter exception synchronized mdb lock own identity identity try identity get own identity byuri requesturi logger debug this tried to create an own identity with an already existing request uri throw new invalid parameter exception the uri you specified is already used by the own identity identity get nickname catch unknown identity exception uie identity new own identity new freeneturi inserturi new freeneturi requesturi nick name publish trust list identity add context context identity add context introduction puzzle introduction context fixme make configureable identity set property introduction server puzzle count property integer to string introduction server default puzzle count try mdb store identity init trust tree identity for string seeduri seed identities try set trust without commit identity get identity byuri seeduri byte 100 i trust the freenet developers catch unknown identity exception e logger error this should not happen seed identity not known e mdb commit logger debug this successfully created a new own identity identity get nickname return identity catch runtime exception e mdb rollback throw e ownidentity createownidentity nickname publishtrustlist malformedurlexception invalidparameterexception ownidentity getownidentitybyuri invalidparameterexception getnickname unknownidentityexception ownidentity nickname publishtrustlist addcontext addcontext introductionpuzzle introduction_context setproperty introductionserver puzzle_count_property tostring introductionserver default_puzzle_count inittrusttree seed_identities settrustwithoutcommit getidentitybyuri unknownidentityexception ownidentity getnickname runtimeexception public synchronized void restore identity string requesturi string inserturi throws malformedurl exception invalid parameter exception own identity identity synchronized mdb lock try try identity old get identity byuri requesturi if old instanceof own identity throw new invalid parameter exception there is already an own identity with the given uri pair we already have fetched this identity as a stranger s one we need to update the database identity new own identity inserturi requesturi old get nickname old does publish trust list we re fetch the current edition to make sure all trustees are imported identity set edition old get edition 1 identity set contexts old get contexts identity set properties old get properties update all received trusts for trust old received trust get received trusts old trust new received trust new trust old received trust get truster identity old received trust get value old received trust get comment mdb delete old received trust fixme is this allowed by db4o in a for each loop mdb store new received trust update all received scores for score old score get scores old score new score new score old score get tree owner identity old score get score old score get rank old score get capacity mdb delete old score mdb store new score mdb store identity init trust tree identity update all given trusts for trust given trust get given trusts old set trust without commit identity given trust get trustee given trust get value given trust get comment fixme the old code would just delete the old trust value here instead of doing the following is the following line correct remove trust without commit given trust remove the old identity mdb delete old store and commit identity logger debug this successfully restored an already known identity from freenet identity get nickname catch unknown identity exception e identity new own identity new freeneturi inserturi new freeneturi requesturi null false store the new identity mdb store identity init trust tree identity store and commit identity logger debug this successfully restored not yet known identity from freenet identity get requesturi catch runtime exception e mdb rollback throw e m fetcher fetch identity restoreidentity malformedurlexception invalidparameterexception ownidentity getidentitybyuri ownidentity invalidparameterexception ownidentity getnickname doespublishtrustlist setedition getedition setcontexts getcontexts setproperties getproperties oldreceivedtrust getreceivedtrusts newreceivedtrust oldreceivedtrust gettruster oldreceivedtrust getvalue oldreceivedtrust getcomment oldreceivedtrust newreceivedtrust oldscore getscores newscore oldscore gettreeowner oldscore getscore oldscore getrank oldscore getcapacity oldscore newscore inittrusttree giventrust getgiventrusts settrustwithoutcommit giventrust gettrustee giventrust getvalue giventrust getcomment removetrustwithoutcommit giventrust storeandcommit getnickname unknownidentityexception ownidentity inittrusttree storeandcommit getrequesturi runtimeexception mfetcher public synchronized void set trust string own trusterid string trusteeid byte value string comment throws unknown identity exception number format exception invalid parameter exception own identity truster get own identity byid own trusterid identity trustee get identity byid trusteeid set trust truster trustee value comment settrust owntrusterid unknownidentityexception numberformatexception invalidparameterexception ownidentity getownidentitybyid owntrusterid getidentitybyid settrust public synchronized void remove trust string own trusterid string trusteeid throws unknown identity exception own identity truster get own identity byid own trusterid identity trustee get identity byid trusteeid remove trust truster trustee removetrust owntrusterid unknownidentityexception ownidentity getownidentitybyid owntrusterid getidentitybyid removetrust public synchronized void add context string own identityid string new context throws unknown identity exception invalid parameter exception identity identity get own identity byid own identityid identity add context new context store and commit identity logger debug this added context new context to identity identity get nickname addcontext ownidentityid newcontext unknownidentityexception invalidparameterexception getownidentitybyid ownidentityid addcontext newcontext storeandcommit newcontext getnickname public synchronized void remove context string own identityid string context throws unknown identity exception invalid parameter exception identity identity get own identity byid own identityid identity remove context context store and commit identity logger debug this removed context context from identity identity get nickname removecontext ownidentityid unknownidentityexception invalidparameterexception getownidentitybyid ownidentityid removecontext storeandcommit getnickname public synchronized string get property string identityid string property throws invalid parameter exception unknown identity exception return get identity byid identityid get property property getproperty invalidparameterexception unknownidentityexception getidentitybyid getproperty public synchronized void set property string own identityid string property string value throws unknown identity exception invalid parameter exception identity identity get own identity byid own identityid identity set property property value store and commit identity logger debug this added property property value to identity identity get nickname setproperty ownidentityid unknownidentityexception invalidparameterexception getownidentitybyid ownidentityid setproperty storeandcommit getnickname public void remove property string own identityid string property throws unknown identity exception invalid parameter exception identity identity get own identity byid own identityid identity remove property property store and commit identity logger debug this removed property property from identity identity get nickname removeproperty ownidentityid unknownidentityexception invalidparameterexception getownidentitybyid ownidentityid removeproperty storeandcommit getnickname public string get version return version get marketing version getversion getmarketingversion public long get real version return version get real version getrealversion getrealversion public string get string string key return key getstring public void set class loader class loader my class loader m class loader my class loader setclassloader classloader myclassloader mclassloader myclassloader public void set language language new language setlanguage newlanguage public plugin respirator get plugin respirator return mpr pluginrespirator getpluginrespirator public ext object container getdb return mdb extobjectcontainer public config get config return m config getconfig mconfig public identity fetcher get identity fetcher return m fetcher identityfetcher getidentityfetcher mfetcher public xml transformer getxml transformer return mxml transformer xmltransformer getxmltransformer mxmltransformer public introduction puzzle store get introduction puzzle store return m puzzle store introductionpuzzlestore getintroductionpuzzlestore mpuzzlestore public introduction client get introduction client return m introduction client introductionclient getintroductionclient mintroductionclient public request client get request client return m request client requestclient getrequestclient mrequestclient final bucket data public fetch result client metadata dm bucket fetched metadata dm data fetched fetchresult clientmetadata create a fetch result with a new bucket of data but everything else the same as the old one public fetch result fetch result fr bucket output this data output this metadata fr metadata fetchresult fetchresult fetchresult get the mime type of the fetched data if unknown returns application octet stream public string get mime type return metadata getmime type getmimetype getmimetype public client metadata get metadata return metadata clientmetadata getmetadata return the size of the data fetched in bytes public long size return data size get the result as a simple byte array even if we don t have it as one throws out of memory error throws io exception if it was not possible to read the data public byte as byte array throws io exception return bucket tools to byte array data outofmemoryerror ioexception asbytearray ioexception buckettools tobytearray get the result as a bucket public bucket as bucket return data asbucket public bucket read filter bucket bucket bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception logminor logger should log logger minor this logdebug logger should log logger debug this if logminor logger minor this read filter charset charset input stream strm bucket get input stream buffered input stream bis new buffered input stream strm 4096 bucket temp bf make bucket 1 output stream os temp get output stream buffered output stream bos new buffered output stream os 4096 reader r null writer w null input stream reader isr null output stream writer osw null try try isr new input stream reader bis charset osw new output stream writer bos charset r new buffered reader isr 4096 w new buffered writer osw 4096 catch unsupported encoding exception e throw unknown charset exception create e charset html parse context pc new html parse context r w charset cb false pc run temp w close os null finally closer close os closer close strm return temp readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception shouldlog shouldlog readfilter inputstream getinputstream bufferedinputstream bufferedinputstream makebucket outputstream getoutputstream bufferedoutputstream bufferedoutputstream inputstreamreader outputstreamwriter inputstreamreader outputstreamwriter bufferedreader bufferedwriter unsupportedencodingexception unknowncharsetexception htmlparsecontext htmlparsecontext public bucket write filter bucket bucket bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception throw new unsupported operation exception writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception unsupportedoperationexception public string get charset bucket bucket string parse charset throws data filter exception io exception logminor logger should log logger minor this if logminor logger minor this get charset default parse charset input stream strm bucket get input stream buffered input stream bis new buffered input stream strm 4096 writer w new null writer reader r try r new buffered reader new input stream reader bis parse charset 4096 catch unsupported encoding exception e strm close throw e html parse context pc new html parse context r w null new null filter callback true try pc run null catch malformed input exception e not this charset return null catch io exception e throw e catch throwable t ignore all errors if logminor logger minor this caught t trying to detect mime type with parse charset try r close catch io exception e throw e catch throwable t if logminor logger minor this caught t closing stream after trying to detect mime type with parse charset if logminor logger minor this returning charset pc detected charset return pc detected charset getcharset parsecharset datafilterexception ioexception shouldlog getcharset parsecharset inputstream getinputstream bufferedinputstream bufferedinputstream nullwriter bufferedreader inputstreamreader parsecharset unsupportedencodingexception htmlparsecontext htmlparsecontext nullfiltercallback malformedinputexception ioexception parsecharset ioexception parsecharset detectedcharset detectedcharset html parse context reader r writer w string charset filter callback cb boolean no output this r r this w w this charset charset this cb cb this no output no output htmlparsecontext filtercallback nooutput nooutput nooutput bucket run bucket temp throws io exception data filter exception tokenize modes p 0 in text transitions 1 1 in tag not in quotes comment whitespace transitions whitespace 4 save current element 2 at beginning of tag 3 process whole tag 2 in tag in quotes transitions 1 grumble about markup in quotes in tag might confuse older user agents stay in current state 3 in tag in comment transitions save ignore comment go to 0 or grumble about markup in comments 4 in tag in whitespace transitions 2 save tag 0 anything else not whitespace 1 p string builder b new string builder 100 string builder balt new string builder 4000 list string split tag new array list string string current tag null char pprevc 0 char prevc 0 char c 0 mode intext while true int x try x r read libgcj up to at least 4 2 2 has a bug input stream reader refill throws this exception when buffered input reader refill returns false for eof see line 299 at input stream reader java in refill http www koders com java fidd8f7e2eb1e4c22da90ebe0130306ae30f876ab00 aspx s refill l279 line 355 at buffered input stream java in refill http www koders com java fid1949641524fac0083432d79793f554cd85f46759 aspx s refill l355 todo remove this when the gcj bug is fixed and the affected gcj versions are outdated catch java io char conversion exception cce if freenet node node check forgcj char conversion bug only ignore the exception on affected libgcj x 1 else throw cce if x 1 switch mode case intext save text b current tag w this break default dump unfinished tag break break else pprevc prevc prevc c c char x switch mode case intext if c save text b current tag w this b set length 0 balt set length 0 mode intag else b append c break case intag balt append c if html decoder is whitespace c split tag add b to string mode intagwhitespace b set length 0 else if c character is whitespace balt char at 0 previous was an un escaped in a script save text b current tag w this balt set length 0 b set length 0 split tag clear else if c split tag add b to string b set length 0 process tag split tag w this current tag split tag get 0 split tag clear balt set length 0 mode intext else if b length 2 c prevc pprevc mode intagcomment b append c else if c mode intagquotes b append c else if c mode intagsquotes b append c else if c probable end tag current tag null we didn t remember what was the last tag so b append c else b append c break case intagquotes inside double quotes single quotes are just another character perfectly legal in a url if c mode intag b append c part of the element else if c b append gt else if c b append lt else b append c break case intagsquotes if c mode intag b append c part of the element else if c b append lt else if c b append gt else b append c break comments are often used to temporarily disable markup i shall allow it avian white space is not permitted between the markup declaration open delimiter and the comment open delimiter but is permitted between the comment close delimiter and the markup declaration close delimiter a common error is to include a string of hyphens within a comment authors should avoid putting two or more adjacent hyphens inside comments however the only browser that actually gets it right is ie others either don t allow it or allow other chars as well the only safe course of action is to allow any and all chars but eat them avian case intagcomment if b length 4 c prevc b append c mode intagcommentclosing else b append c break case intagcommentclosing if c save comment b w this b set length 0 mode intext else b append c if c mode intagcomment break case intagwhitespace if c mode intagquotes b append c else if c e g div align center avian this will be converted automatically to double quotes note that single quotes are legal in urls if we have single quotes inside single quotes we could get into a major mess here but that s really malformed code and it will still be safe it will just be unreadable mode intagsquotes b append c else if c if kill tag process tag split tag w this kill tag false current tag split tag get 0 split tag clear b set length 0 balt set length 0 mode intext else if c character is whitespace balt char at 0 previous was an un escaped in a script save text balt current tag w this balt set length 0 b set length 0 split tag clear mode intag else if html decoder is whitespace c more whitespace what fun else mode intag b append c return temp ioexception datafilterexception stringbuilder stringbuilder stringbuilder stringbuilder splittag arraylist currenttag inputstreamreader bufferedinputreader inputstreamreader bufferedinputstream charconversionexception checkforgcjcharconversionbug savetext currenttag savetext currenttag setlength setlength htmldecoder iswhitespace splittag tostring setlength iswhitespace charat savetext currenttag setlength setlength splittag splittag tostring setlength processtag splittag currenttag splittag splittag setlength currenttag savecomment setlength killtag processtag splittag killtag currenttag splittag splittag setlength setlength iswhitespace charat savetext currenttag setlength setlength splittag htmldecoder iswhitespace void save text string builder s string tag name writer w html parse context pc throws io exception if pc no output return if logdebug logger debug this saving text s to string if pc kill text return for int i 0 i s length i char c s char at i if c 32 c t c n c r not a real character strongly suggests somebody is using a bogus charset this could be in order to break the filter s delete char at i if logdebug logger debug this removing c from the output stream string style s to string if pc in style pc in script pc current style script chunk style return is parsed and written elsewhere string builder out new string builder s length 2 for int i 0 i s length i char c s char at i if c out append lt else out append c string sout out to string if pc cb null pc cb on text html decoder decode sout tag name tag name is given as type for the text w write sout savetext stringbuilder tagname htmlparsecontext ioexception nooutput tostring killtext charat deletecharat tostring instyle inscript currentstylescriptchunk stringbuilder stringbuilder charat tostring ontext htmldecoder tagname void process tag list string split tag writer w html parse context pc throws io exception data filter exception first check that it is a recognized tag if logdebug for int i 0 i split tag size i logger debug this tag i split tag get i parsed tag t new parsed tag split tag if pc kill tag t t sanitize pc if pc no output return sanitize has done all the work we are interested in if t null if pc write style script with tag pc write style script with tag false string style pc current style script chunk if style null style length 0 pc write after tag append l10n deleted unknown style else w write style pc current style script chunk t write w if pc write after tag length 0 w write pc write after tag to string pc write after tag new string builder 1024 else pc write style script with tag false else pc kill tag false pc write style script with tag false processtag splittag htmlparsecontext ioexception datafilterexception splittag splittag parsedtag parsedtag splittag killtag nooutput writestylescriptwithtag writestylescriptwithtag currentstylescriptchunk writeaftertag deletedunknownstyle currentstylescriptchunk writeaftertag writeaftertag tostring writeaftertag stringbuilder writestylescriptwithtag killtag writestylescriptwithtag void save comment string builder s writer w html parse context pc throws io exception if pc no output return if s length 3 s char at 0 s char at 1 s char at 2 s delete 0 3 if s char at s length 1 s set length s length 1 if s char at s length 1 s set length s length 1 if logdebug logger debug this saving comment s to string if pc expecting bad comment return ignore it if pc in style pc in script pc current style script chunk s return style handler should write if pc kill tag pc kill tag false return string builder sb new string builder for int i 0 i s length i char c s char at i if c sb append lt else if c sb append gt else sb append c s sb w write w write s to string w write savecomment stringbuilder htmlparsecontext ioexception nooutput charat charat charat charat setlength charat setlength tostring expectingbadcomment instyle inscript currentstylescriptchunk killtag killtag stringbuilder stringbuilder charat tostring static void throw filter exception string msg throws data filter exception fixme string longer l10n failed to parse label throw new data filter exception longer longer msg new html node div msg throwfilterexception datafilterexception failedtoparselabel datafilterexception htmlnode public parsed tag parsed tag t string out attrs this element t element this unparsed attrs out attrs this start slash t start slash this end slash t end slash parsedtag parsedtag outattrs unparsedattrs outattrs startslash startslash endslash endslash public parsed tag list string v int len v size if len 0 element null unparsed attrs new string 0 start slash end slash false return string s v get len 1 if len 1 0 s length 1 s ends with s s substring 0 s length 1 v set len 1 s if s length 0 len end slash true don t need to set it back because everything is an i value else end slash false s v get 0 if s length 1 s starts with s s substring 1 v set 0 s start slash true else start slash false element v get 0 if len 1 unparsed attrs new string len 1 for int x 1 x len x unparsed attrs x 1 v get x else unparsed attrs new string 0 if logdebug logger debug this element element parsedtag unparsedattrs startslash endslash endswith endslash endslash startswith startslash startslash unparsedattrs unparsedattrs unparsedattrs public parsed tag sanitize html parse context pc throws data filter exception tag verifier tv allowed tags verifiers get element to lower case if logdebug logger debug this got verifier tv for element if tv null if delete wierd stuff return null else string err html encoder encode l10n unknown tag tag element if delete errors throw filter exception l10n unknown tag label err return null return tv sanitize this pc parsedtag htmlparsecontext datafilterexception tagverifier allowedtagsverifiers tolowercase deletewierdstuff htmlencoder unknowntag deleteerrors throwfilterexception unknowntaglabel override public string to string if element null return string builder sb new string builder if start slash sb append sb append element if unparsed attrs null int n unparsed attrs length for int i 0 i n i sb append append unparsed attrs i if end slash sb append sb append return sb to string tostring stringbuilder stringbuilder startslash unparsedattrs unparsedattrs unparsedattrs endslash tostring public void write writer w throws io exception string s to string if s null w write s ioexception tostring final hash set string inlineuri attrs tag verifier string tag string allowed attrs this tag allowed attrs null null hashset inlineuriattrs tagverifier allowedattrs allowedattrs tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs this tag tag this allowed attrs new hash set string if allowed attrs null for int x 0 x allowed attrs length x this allowed attrs add allowed attrs x this uri attrs new hash set string if uri attrs null for int x 0 x uri attrs length x this uri attrs add uri attrs x this inlineuri attrs new hash set string if inlineuri attrs null for int x 0 x inlineuri attrs length x this inlineuri attrs add inlineuri attrs x tagverifier allowedattrs uriattrs inlineuriattrs allowedattrs hashset allowedattrs allowedattrs allowedattrs allowedattrs uriattrs hashset uriattrs uriattrs uriattrs uriattrs inlineuriattrs hashset inlineuriattrs inlineuriattrs inlineuriattrs inlineuriattrs parsed tag sanitize parsed tag t html parse context pc throws data filter exception map string object h new hash map string object boolean equals false string prevx if t unparsed attrs null for int i 0 i t unparsed attrs length i string s t unparsed attrs i if equals equals false s strip quotes s h remove prevx h put prevx s prevx else int idx s index of if idx s length 1 equals true if idx 0 prevx already set else prevx s substring 0 s length 1 prevx prevx to lower case else if idx 1 string x s substring 0 idx if x length 0 x prevx x x to lower case string y if idx s length 1 y else y s substring idx 1 s length y strip quotes y h remove x h put x y prevx x else h remove s h put s new object prevx s h sanitize hash h t pc if h null return null if t start slash return new parsed tag t null string out attrs new string h size int i 0 for map entry string object entry h entry set string x entry get key object o entry get value string y if o instanceof string y string o else y null string builder out new string builder x if y null out append append y append out attrs i out to string return new parsed tag t out attrs parsedtag parsedtag htmlparsecontext datafilterexception hashmap unparsedattrs unparsedattrs unparsedattrs stripquotes indexof tolowercase tolowercase stripquotes sanitizehash startslash parsedtag outattrs entryset getkey getvalue stringbuilder stringbuilder outattrs tostring parsedtag outattrs map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn new hash map string object for map entry string object entry h entry set string x entry get key object o entry get value straight attribs if allowed attrs contains x hn put x o continue if uri attrs contains x if logminor logger minor this non inline uri attribute x uri if o instanceof string java s url handling doesn t seem suitable string uri string o uri html decoder decode uri uri html sanitizeuri uri null null pc cb pc false if uri null uri html encoder encode uri hn put x uri fixme rewrite absolute ur ls handle date etc if inlineuri attrs contains x if logminor logger minor this inline uri attribute x uri if o instanceof string java s url handling doesn t seem suitable string uri string o uri html decoder decode uri uri html sanitizeuri uri null null pc cb pc true if uri null uri html encoder encode uri hn put x uri fixme rewrite absolute ur ls handle date etc lang xml lang and dir can go on anything lang or xml lang language country variant the variant can be just about anything no way to test avian string s get hash string h lang if s null hn put lang s s get hash string h xml lang if s null hn put xml lang s s get hash string h dir if s null s equals ignore case ltr s equals ignore case rtl hn put dir s return hn sanitizehash parsedtag htmlparsecontext datafilterexception hashmap entryset getkey getvalue allowedattrs uriattrs htmldecoder htmlsanitizeuri htmlencoder urls inlineuriattrs htmldecoder htmlsanitizeuri htmlencoder urls gethashstring gethashstring gethashstring equalsignorecase equalsignorecase static string strip quotes string s final string quotes if s length 2 int n quotes length for int x 0 x n x char cc quotes char at x if s char at 0 cc s char at s length 1 cc if s length 2 s s substring 1 s length 1 else s break return s stripquotes charat charat charat static abstract class script style tag verifier extends tag verifier script style tag verifier string tag string allowed attrs string uri attrs super tag allowed attrs uri attrs null scriptstyletagverifier tagverifier scriptstyletagverifier allowedattrs uriattrs allowedattrs uriattrs abstract void set style boolean b html parse context pc setstyle htmlparsecontext abstract void set style boolean b html parse context pc abstract boolean get style html parse context pc setstyle htmlparsecontext getstyle htmlparsecontext abstract boolean get style html parse context pc abstract void process style html parse context pc getstyle htmlparsecontext processstyle htmlparsecontext override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc if p start slash return finish h hn pc else return start h hn pc sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash startslash map string object finish map string object h map string object hn html parse context pc throws data filter exception if logdebug logger debug this finishing script style finishing set style false pc pc style script recurse count if pc style script recurse count 0 if delete errors pc write after tag append l10n too many nested style or script tags else throw filter exception l10n too many nested style or script tags long return null if pc kill style process style pc pc write style script with tag true else pc kill style false pc current style script chunk pc expecting bad comment false pass it on no params for style return hn htmlparsecontext datafilterexception setstyle stylescriptrecursecount stylescriptrecursecount deleteerrors writeaftertag toomanynestedstyleorscripttags throwfilterexception toomanynestedstyleorscripttagslong killstyle processstyle writestylescriptwithtag killstyle currentstylescriptchunk expectingbadcomment map string object start map string object h map string object hn html parse context pc throws data filter exception if logdebug logger debug this starting script style pc style script recurse count if pc style script recurse count 1 if delete errors pc write after tag append l10n too many nested style or script tags else throw filter exception l10n too many nested style or script tags long return null set style true pc string type get hash string h type if type null if type equals ignore case text css fixme pc kill style true pc expecting bad comment true return null kill the tag hn put type text css return hn htmlparsecontext datafilterexception stylescriptrecursecount stylescriptrecursecount deleteerrors writeaftertag toomanynestedstyleorscripttags throwfilterexception toomanynestedstyleorscripttagslong setstyle gethashstring equalsignorecase killstyle expectingbadcomment static class style tag verifier extends script style tag verifier style tag verifier super style new string id media title xml space empty string array styletagverifier scriptstyletagverifier styletagverifier emptystringarray override void set style boolean b html parse context pc pc in style b setstyle htmlparsecontext instyle override boolean get style html parse context pc return pc in style getstyle htmlparsecontext instyle override void process style html parse context pc try pc current style script chunk sanitize style pc current style script chunk pc cb pc catch data filter exception e logger error this error parsing style e e pc current style script chunk processstyle htmlparsecontext currentstylescriptchunk sanitizestyle currentstylescriptchunk datafilterexception currentstylescriptchunk static class script tag verifier extends script style tag verifier script tag verifier super script new string id charset type language defer xml space new string src fixme src not supported type ignored we will need to check this when if when we support scripts charset ignored scripttagverifier scriptstyletagverifier scripttagverifier override map string object sanitize hash map string object hn parsed tag p html parse context pc throws data filter exception call parent so we swallow the scripting super sanitize hash hn p pc return null lose the tags sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash override void set style boolean b html parse context pc pc in script b setstyle htmlparsecontext inscript override boolean get style html parse context pc return pc in script getstyle htmlparsecontext inscript override void process style html parse context pc pc current style script chunk sanitize scripting pc current style script chunk processstyle htmlparsecontext currentstylescriptchunk sanitizescripting currentstylescriptchunk static class base core tag verifier extends tag verifier base core tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs super tag allowed attrs uri attrs inlineuri attrs basecoretagverifier tagverifier basecoretagverifier allowedattrs uriattrs inlineuriattrs allowedattrs uriattrs inlineuriattrs override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc i18n dealt with by tag verifier coreattrs string id get hash string h id if id null hn put id id hopefully nobody will be stupid enough to encode ur ls into the unique id string class names get hash string h class if class names null hn put class class names ditto string style get hash string h style if style null style sanitize style style pc cb pc if style null style escape quotes style if style null hn put style style string title get hash string h title if title null paranoia title is plain text right in all user agents hn put title title return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash tagverifier gethashstring urls classnames gethashstring classnames classnames gethashstring sanitizestyle escapequotes gethashstring core tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs string event attrs this tag allowed attrs uri attrs inlineuri attrs event attrs true coretagverifier allowedattrs uriattrs inlineuriattrs eventattrs allowedattrs uriattrs inlineuriattrs eventattrs core tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs string event attrs boolean add std events super tag allowed attrs uri attrs inlineuri attrs this event attrs new hash set string if event attrs null for int x 0 x event attrs length x this event attrs add event attrs x if add std events for int x 0 x std events length x this event attrs add std events x coretagverifier allowedattrs uriattrs inlineuriattrs eventattrs addstdevents allowedattrs uriattrs inlineuriattrs eventattrs hashset eventattrs eventattrs eventattrs eventattrs addstdevents stdevents eventattrs stdevents override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc events default and added for iterator string e event attrs iterator e has next string name e next string arg get hash string h name if arg null arg sanitize scripting arg if arg null hn put name arg return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash eventattrs hasnext gethashstring sanitizescripting static class link tag verifier extends core tag verifier link tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs string event attrs super tag allowed attrs uri attrs inlineuri attrs event attrs linktagverifier coretagverifier linktagverifier allowedattrs uriattrs inlineuriattrs eventattrs allowedattrs uriattrs inlineuriattrs eventattrs override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc string hreflang get hash string h hreflang string charset null string type get hash string h type if type null string typesplit split type type type typesplit 0 if typesplit 1 null typesplit 1 length 0 charset typesplit 1 if logdebug logger debug this processing link tag type type charset charset string c get hash string h charset if c null charset c string href get hash string h href if href null final string rels new string rel rev for int x 0 x rels length x string reltype rels x string rel get hash string h reltype if rel null string tokenizer tok new string tokenizer rel while tok has more tokens string t tok next token if t equals ignore case alternate t equals ignore case stylesheet fixme hardcoding text css type text css fixme do we want to do anything with the other possible rel s hn put reltype rel core logger log this sanitizing uri href with type type and charset charset logger debug href html decoder decode href href html sanitizeuri href type charset pc cb pc false if href null href html encoder encode href hn put href href if type null hn put type type if charset null hn put charset charset if charset null hreflang null hn put hreflang hreflang fixme allow these if the charset and encoding are encoded into the url fixme link types http www w3 org tr html4 types html type links the stylesheet stuff primarily rel and rev properties parse these use same fix as above browser may assume text css for anything linked as a stylesheet return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash gethashstring gethashstring splittype gethashstring gethashstring gethashstring stringtokenizer stringtokenizer hasmoretokens nexttoken equalsignorecase equalsignorecase htmldecoder htmlsanitizeuri htmlencoder static class form tag verifier extends core tag verifier form tag verifier string tag string allowed attrs string uri attrs string event attrs super tag allowed attrs uri attrs null event attrs formtagverifier coretagverifier formtagverifier allowedattrs uriattrs eventattrs allowedattrs uriattrs eventattrs override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc if p start slash allow but only with standard elements return hn string method string h get method string action string h get action string final action try final action pc cb process form method action catch comment exception e pc write after tag append append html encoder encode e to string append return null if final action null return null hn put method method hn put action final action force enctype and accept charset to acceptable values hn put enctype multipart form data hn put accept charset utf 8 return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash startslash finalaction finalaction processform commentexception writeaftertag htmlencoder tostring finalaction finalaction input tag verifier string tag string allowed attrs string uri attrs string inlineuri attrs string event attrs super tag allowed attrs uri attrs inlineuri attrs event attrs this allowed types new hash set string if types null for int x 0 x types length x this allowed types add types x inputtagverifier allowedattrs uriattrs inlineuriattrs eventattrs allowedattrs uriattrs inlineuriattrs eventattrs allowedtypes hashset allowedtypes override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc we drop the whole input if type isn t allowed if allowed types contains hn get type return null return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash allowedtypes static class meta tag verifier extends tag verifier meta tag verifier super meta new string id metatagverifier tagverifier metatagverifier override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc several possibilities a meta http equiv x content y b meta name x content y string http equiv get hash string h http equiv string name get hash string h name string content get hash string h content string scheme get hash string h scheme if logminor logger minor this meta name name content content http equiv http equiv scheme scheme if content null if name null http equiv null if name equals ignore case author hn put name name hn put content content else if name equals ignore case keywords hn put name name hn put content content else if name equals ignore case description hn put name name hn put content content else if http equiv null name null if http equiv equals ignore case expires hn put http equiv http equiv hn put content content else if http equiv equals ignore case content script type we don t support script at this time else if http equiv equals ignore case content style type fixme charsets if content equals ignore case text css fixme selectable style languages only matters when we have implemented more than one fixme if we ever do allow it the spec http www w3 org tr html4 present styles html h 14 2 1 says only the last definition counts but it only counts if it s in the head section so we dont need to parse the whole doc hn put http equiv http equiv hn put content content fixme add some more headers dublin core else if http equiv equals ignore case content type if logminor logger minor this found http equiv content type content string typesplit split type content if logdebug for int i 0 i typesplit length i logger debug this i typesplit i if typesplit 0 equals ignore case text html typesplit 1 null typesplit 1 equals ignore case pc charset hn put http equiv http equiv hn put content typesplit 0 typesplit 1 null charset typesplit 1 if typesplit 1 null pc detected charset typesplit 1 trim else if http equiv equals ignore case content language hn put http equiv content language hn put content content return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash http_equiv gethashstring gethashstring gethashstring gethashstring http_equiv http_equiv equalsignorecase equalsignorecase equalsignorecase http_equiv http_equiv equalsignorecase http_equiv http_equiv equalsignorecase http_equiv equalsignorecase equalsignorecase http_equiv http_equiv equalsignorecase splittype equalsignorecase equalsignorecase http_equiv detectedcharset http_equiv equalsignorecase static class doc type tag verifier extends tag verifier doc type tag verifier string tag super tag null doctypetagverifier tagverifier doctypetagverifier override parsed tag sanitize parsed tag t html parse context pc if t unparsed attrs length 3 t unparsed attrs length 4 return null if t unparsed attrs 0 equals ignore case html return null if t unparsed attrs 1 equals ignore case public return null string s strip quotes t unparsed attrs 2 if dt ds contains key s return null if t unparsed attrs length 4 string ss strip quotes t unparsed attrs 3 string spec get hash string dt ds s if spec null spec equals ss return null return t parsedtag parsedtag htmlparsecontext unparsedattrs unparsedattrs unparsedattrs equalsignorecase unparsedattrs equalsignorecase stripquotes unparsedattrs dtds containskey unparsedattrs stripquotes unparsedattrs gethashstring dtds static class xml tag verifier extends tag verifier xml tag verifier super xml null xmltagverifier tagverifier xmltagverifier override parsed tag sanitize parsed tag t html parse context pc if t unparsed attrs length 2 return null if t unparsed attrs 0 equals version 1 0 return null if t unparsed attrs 1 starts with encoding t unparsed attrs 1 ends with return null if t unparsed attrs 1 substring 10 t unparsed attrs 1 length 2 equals ignore case pc charset return null return t parsedtag parsedtag htmlparsecontext unparsedattrs unparsedattrs unparsedattrs startswith unparsedattrs endswith unparsedattrs unparsedattrs equalsignorecase static class html tag verifier extends tag verifier html tag verifier super html new string id version htmltagverifier tagverifier htmltagverifier override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc string xmlns get hash string h xmlns if xmlns null xmlns equals http www w3 org 1999 xhtml hn put xmlns xmlns return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash gethashstring static class base href tag verifier extends tag verifier base href tag verifier string string string strings string strings2 super string strings strings2 null basehreftagverifier tagverifier basehreftagverifier override map string object sanitize hash map string object h parsed tag p html parse context pc throws data filter exception map string object hn super sanitize hash h p pc get the already sanitized version string base href get hash string hn href if base href null string ref pc cb on base href base href if ref null hn put href ref return hn sanitizehash parsedtag htmlparsecontext datafilterexception sanitizehash basehref gethashstring basehref onbasehref basehref static string sanitize style string style filter callback cb html parse context hpc throws data filter exception if style null return null if hpc no output return null reader r new string reader style writer w new string writer style style trim if logminor logger minor html filter class sanitizing style style css parser pc new css parser r w false cb try pc parse catch io exception e logger error html filter class io exception parsing inline css catch error e if e get message equals error could not match input this sucks it should be a proper exception logger normal html filter class css parse error e return l10n could not parse style else throw e string s w to string if s null s length 0 return null core logger log safer filter class style now s logger debug if logminor logger minor html filter class style finally s return s sanitizestyle filtercallback htmlparsecontext datafilterexception nooutput stringreader stringwriter htmlfilter cssparser cssparser ioexception htmlfilter ioexception getmessage htmlfilter couldnotparsestyle tostring saferfilter htmlfilter static string escape quotes string s string builder buf new string builder s length for int x 0 x s length x char c s char at x if c buf append quot else buf append c return buf to string escapequotes stringbuilder stringbuilder charat tostring static string sanitize scripting string script kill it at some point we may want to allow certain recipes fixme return null sanitizescripting static string sanitizeuri string uri filter callback cb boolean inline throws comment exception return sanitizeuri uri null null cb inline filtercallback commentexception static string split type string type string field parser sfp string charset null param name value int x sfp new string field parser type type sfp next field trim while sfp has more fields param sfp next field x param index of if x 1 name param substring 0 x trim value param substring x 1 trim if name equals charset charset value return new string type charset splittype stringfieldparser stringfieldparser nextfield hasmorefields nextfield indexof private char c public string field parser string str this str t stringfieldparser public string field parser string str char c this str str this max pos str length this cur pos 0 this c c stringfieldparser maxpos curpos public boolean has more fields return cur pos max pos hasmorefields curpos maxpos public string next field int start end if cur pos max pos return null start cur pos while cur pos max pos str char at cur pos c cur pos end cur pos cur pos return str substring start end nextfield curpos maxpos curpos curpos maxpos charat curpos curpos curpos curpos static string html sanitizeuri string suri string override type string override charset filter callback cb html parse context pc boolean inline try return sanitizeuri suri override type override charset cb inline catch comment exception e pc write after tag append append html encoder encode e to string append return null htmlsanitizeuri overridetype overridecharset filtercallback htmlparsecontext overridetype overridecharset commentexception writeaftertag htmlencoder tostring static string sanitizeuri string suri string override type string override charset filter callback cb boolean inline throws comment exception if logminor logger minor html filter class sanitizing uri suri override type override type override charset override charset inline inline new exception debug if override charset null override charset length 0 override type charset override charset return cb processuri suri override type false inline overridetype overridecharset filtercallback commentexception htmlfilter overridetype overridecharset overridecharset overridecharset overridetype overridecharset overridetype static string get hash string map string object h string key object o h get key if o null return null if o instanceof string return string o else return null gethashstring private static string l10n string key return l10n get string html filter key getstring htmlfilter private static string l10n string key string pattern string value return l10n get string html filter key pattern value getstring htmlfilter public dsa private key big integer x dsa group g this x x if x signum 1 x compare to g getq 1 x compare to big integer zero 1 throw new illegal argument exception dsaprivatekey biginteger dsagroup compareto compareto biginteger illegalargumentexception public dsa private key dsa group g random r big integer tempx do tempx new native big integer 256 r while tempx compare to g getq 1 tempx compare to big integer zero 1 this x tempx dsaprivatekey dsagroup biginteger nativebiginteger compareto compareto biginteger override public string key type return dsa s keytype public big integer getx return x biginteger public static crypto key read input stream i dsa group g throws io exception return new dsa private key util readmpi i g cryptokey inputstream dsagroup ioexception dsaprivatekey public string to long string return x hex util bi to hex x tolongstring hexutil bitohex override public byte as bytes return util mp ibytes x asbytes mpibytes override public byte fingerprint return fingerprint new big integer x biginteger public simple field set as field set simple field set fs new simple field set true fs put single x base64 encode x to byte array return fs simplefieldset asfieldset simplefieldset simplefieldset putsingle tobytearray public static dsa private key create simple field set fs dsa group group throws illegal base64 exception native big integer y new native big integer 1 base64 decode fs get x if y bit length 512 throw new illegal base64 exception probably a pubkey return new dsa private key y group dsaprivatekey simplefieldset dsagroup illegalbase64exception nativebiginteger nativebiginteger bitlength illegalbase64exception dsaprivatekey public void remove from object container container container delete x container delete this removefrom objectcontainer final public bucket data result simple field set my params bucket my data params my params data my data simplefieldset myparams mydata myparams mydata public plugin talker blocking plugin respirator mypr throws plugin not found exception m talker mypr get plugin talker this freetalk wot name freetalk plugin title plugintalkerblocking pluginrespirator pluginnotfoundexception mtalker getplugintalker wot_name plugin_title sends a fcp message and blocks execution until the answer was received and then returns the answer this can be used to simplify code which uses fcp very much especially ui code which needs the result of fcp calls directly when using send blocking please make sure that you only ever call it for fcp functions which only send a single result public synchronized result send blocking simple field set params bucket data throws plugin not found exception assert m result null m talker send params data while m result null todo or timeout try wait catch interrupted exception e result result m result m result null return result sendblocking sendblocking simplefieldset pluginnotfoundexception mresult mtalker mresult interruptedexception mresult mresult synchronized because notify all will otherwise throw illegal monitor state exception public synchronized void on reply string pluginname string indentifier simple field set params bucket data if m result null logger error this send blocking called for a fcp function which sends more than 1 reply return m result new result params data notify all notifyall illegalmonitorstateexception onreply simplefieldset mresult sendblocking mresult notifyall public uptime estimator file node dir ticker ticker byte bs this ticker ticker log file new file node dir uptime dat prev file new file node dir uptime old dat time offset int double math abs fields hash code bs bs length 2 bs length bs length 2 integer max value 5 60 1000 uptimeestimator nodedir logfile nodedir prevfile nodedir timeoffset hashcode max_value public void start long now system current time millis int five minutes since epoch int now period int base five minutes since epoch was online length read both files read data prev file base read data log file base schedule system current time millis system out println created uptime estimator time offset is time offset uptime at startup is new decimal format 0 00 format get uptime currenttimemillis fiveminutessinceepoch fiveminutessinceepoch wasonline readdata prevfile readdata logfile currenttimemillis timeoffset decimalformat getuptime private void read data file file int base file input stream fis null try fis new file input stream file data input stream dis new data input stream fis try while true int offset dis read int if offset base continue int slot no offset base if slot no was online length break reached the end restarted within the same timeslot if slot no was online length slot no 0 logger error this corrupt data read from uptime file file 5 minutes from epoch is now base was online length but read slot no break was online slot no true catch eof exception e finished finally closer close dis catch io exception e logger error this unable to read old uptime file file we will assume we weren t online during that period finally closer close fis readdata fileinputstream fileinputstream datainputstream datainputstream readint slotno slotno wasonline slotno wasonline slotno wasonline slotno wasonline slotno eofexception ioexception public void run synchronized this was online slot true slot slot 1 was online length long now system current time millis if log file length was online length 4l prev file delete log file rename to prev file file output stream fos null data output stream dos null int five minutes since epoch int now period try fos new file output stream log file true dos new data output stream fos dos write int five minutes since epoch catch file not found exception e logger error this unable to create or access log file e e catch io exception e logger error this unable to write to uptime estimator log file log file finally closer close dos closer close fos schedule next time schedule now wasonline wasonline currenttimemillis logfile wasonline prevfile logfile renameto prevfile fileoutputstream dataoutputstream fiveminutessinceepoch fileoutputstream logfile dataoutputstream writeint fiveminutessinceepoch filenotfoundexception logfile ioexception logfile private void schedule long now long next time now period period time offset if next time now next time period ticker queue timed job this next time system current time millis nexttime timeoffset nexttime nexttime queuetimedjob nexttime currenttimemillis get the node s uptime fraction over the last 48 hours public synchronized double get uptime int up count 0 for int i 0 i was online length i if was online i up count return double up count double was online length getuptime upcount wasonline wasonline upcount upcount wasonline public icon list iconlist public icon get icon int n return icon get n geticon a debugging method which prints the tree out public void list print stream s int level for int i 0 i level i system out print if count 0 system out println index count count else system out println index count count red total red count green total green count blue total blue count for int i 0 i 8 i if leaf i null leaf i list s level 2 printstream totalred totalgreen totalblue public oct tree quantizer setup 256 color list new vector max level 1 for int i 0 i max level 1 i color list i new vector root new oct tree node octtreequantizer colorlist max_level max_level colorlist octtreenode initialize the quantizer this should be called before adding any pixels param num colors the number of colors we re quantizing to public void setup int num colors maximum colors num colors reduce colors math max 512 num colors 2 numcolors numcolors maximumcolors numcolors reducecolors numcolors add pixels to the quantizer param pixels the array of argb pixels param offset the offset into the array param count the count of pixels public void add pixels int pixels int offset int count for int i 0 i count i insert color pixels i offset if colors reduce colors reduce tree reduce colors addpixels insertcolor reducecolors reducetree reducecolors get the color table index for a color param rgb the color return the index public int get index for color int rgb int red rgb 16 0xff int green rgb 8 0xff int blue rgb 0xff oct tree node node root for int level 0 level max level level oct tree node child int bit 0x80 level int index 0 if red bit 0 index 4 if green bit 0 index 2 if blue bit 0 index 1 child node leaf index if child null return node index else if child is leaf return child index else node child system out println get index for color failed return 0 getindexforcolor octtreenode max_level octtreenode isleaf getindexforcolor private void insert color int rgb int red rgb 16 0xff int green rgb 8 0xff int blue rgb 0xff oct tree node node root system out println insert color integer to hex string rgb for int level 0 level max level level oct tree node child int bit 0x80 level int index 0 if red bit 0 index 4 if green bit 0 index 2 if blue bit 0 index 1 child node leaf index if child null node children child new oct tree node child parent node node leaf index child node is leaf false nodes color list level add element child if level max level child is leaf true child count 1 child total red red child total green green child total blue blue child level level colors return node child else if child is leaf child count child total red red child total green green child total blue blue return else node child system out println insert color failed insertcolor octtreenode insertcolor tohexstring max_level octtreenode octtreenode isleaf colorlist addelement max_level isleaf totalred totalgreen totalblue isleaf totalred totalgreen totalblue insertcolor private void reduce tree int num colors for int level max level 1 level 0 level vector v color list level if v null v size 0 for int j 0 j v size j oct tree node node oct tree node v element at j if node children 0 for int i 0 i 8 i oct tree node child node leaf i if child null if child is leaf system out println not a leaf node count child count node total red child total red node total green child total green node total blue child total blue node leaf i null node children colors nodes color list level 1 remove element child node is leaf true colors if colors num colors return system out println unable to reduce the oct tree reducetree numcolors max_level colorlist octtreenode octtreenode elementat octtreenode isleaf totalred totalred totalgreen totalgreen totalblue totalblue colorlist removeelement isleaf numcolors octtree build the color table return the color table public int build color table int table new int colors build color table root table 0 return table buildcolortable buildcolortable a quick way to use the quantizer just create a table the right size and pass in the pixels param in pixels the input colors param table the output color table public void build color table int in pixels int table int count in pixels length maximum colors table length for int i 0 i count i insert color in pixels i if colors reduce colors reduce tree reduce colors if colors maximum colors reduce tree maximum colors build color table root table 0 inpixels buildcolortable inpixels inpixels maximumcolors insertcolor inpixels reducecolors reducetree reducecolors maximumcolors reducetree maximumcolors buildcolortable private int build color table oct tree node node int table int index if colors maximum colors reduce tree maximum colors if node is leaf int count node count table index 0xff000000 node total red count 16 node total green count 8 node total blue count node index index else for int i 0 i 8 i if node leaf i null node index index index build color table node leaf i table index return index buildcolortable octtreenode maximumcolors reducetree maximumcolors isleaf totalred totalgreen totalblue buildcolortable public class generic sort static void sort generic sort array arr sort1 arr 0 arr size genericsort genericsortarray private static void sort1 generic sort array x int off int len insertion sort on smallest arrays if len 7 for int i off i len off i for int j i j off x compare j 1 j 0 j x swap j j 1 return choose a partition element v int m off len 1 small arrays middle element if len 7 int l off int n off len 1 if len 40 big arrays pseudomedian of 9 int s len 8 l med3 x l l s l 2 s m med3 x m s m m s n med3 x n 2 s n s n m med3 x l m n mid size med of 3 establish invariant v v v v int a off b a c off len 1 d c diff while true while b c diff x compare b m 0 if diff 0 x swap a b b while c b diff x compare c m 0 if diff 0 x swap c d c if b c break x swap b c swap partition elements back to middle int s n off len s math min a off b a vecswap x off b s s s math min d c n d 1 vecswap x b n s s recursively sort non partition elements if s b a 1 sort1 x off s if s d c 1 sort1 x n s s genericsortarray private static void vecswap generic sort array x int a int b int n for int i 0 i n i a b x swap a b genericsortarray private static int med3 generic sort array x int a int b int c return x compare a b 0 x compare b c 0 b x compare a c 0 c a x compare b c 0 b x compare a c 0 c a genericsortarray param jmdns impl socket listener jmdns impl jmdns impl this jmdns impl jmdns impl jmdnsimpl socketlistener jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl public void run try byte buf new byte dns constants max msg absolute datagram packet packet new datagram packet buf buf length while this jmdns impl get state dns state canceled packet set length buf length this jmdns impl get socket receive packet if this jmdns impl get state dns state canceled break try if this jmdns impl get local host should ignore packet packet continue dns incoming msg new dns incoming packet logger finest socket listener run jmdns in msg print true synchronized this jmdns impl get io lock if msg is query if packet get port dns constants mdns port this jmdns impl handle query msg packet get address packet get port this jmdns impl handle query msg this jmdns impl get group dns constants mdns port else this jmdns impl handle response msg catch io exception e logger log level warning run exception e catch io exception e if this jmdns impl get state dns state canceled logger log level warning run exception e this jmdns impl recover dnsconstants max_msg_absolute datagrampacket datagrampacket jmdnsimpl getstate dnsstate setlength jmdnsimpl getsocket jmdnsimpl getstate dnsstate jmdnsimpl getlocalhost shouldignorepacket dnsincoming dnsincoming socketlistener jmdnsimpl getiolock isquery getport dnsconstants mdns_port jmdnsimpl handlequery getaddress getport jmdnsimpl handlequery jmdnsimpl getgroup dnsconstants mdns_port jmdnsimpl handleresponse ioexception ioexception jmdnsimpl getstate dnsstate jmdnsimpl return the time at which this object was last used public synchronized long last used time return last used time lastusedtime lastusedtime static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private final request tag tag override public string to string return super to string for uid requesttag tostring tostring public request handler message m peer node source long id node n short htl key key request tag tag req m node n uid id this source source this htl htl this tag tag if htl 0 htl 1 this key key if key instanceof nodessk needs pub key m get boolean dmt need pub key received bytes m received byte count requesthandler peernode requesttag needspubkey getboolean need_pub_key receivedbytes receivedbytecount public void run freenet support logger os thread logpid this try real run the last thing that real run does is register as a request sender listener so any exception here is the end catch not connected exception e logger normal this requestor gone could not start request handler wait node remove transferring request handler uid tag handler threw e node unlockuid uid key instanceof nodessk false false false false tag catch throwable t logger error this caught t t node remove transferring request handler uid tag handler threw t node unlockuid uid key instanceof nodessk false false false false tag osthread realrun realrun notconnectedexception removetransferringrequesthandler handlerthrew removetransferringrequesthandler handlerthrew private void apply byte counts if disconnected logger normal this not applying byte counts as request source disconnected during receive return if applied byte counts logger error this apply byte counts already called new exception error logger error this first called here previous apply byte count call return previous apply byte count call new exception first call to apply byte counts applied byte counts true if final transfer failed rs null status request sender timed out status request sender generated rejected overload status request sender internal error int sent rcvd synchronized bytes sync sent sent bytes rcvd received bytes sent rs get total sent bytes rcvd rs get total received bytes if key instanceof nodessk if logminor logger minor this remote ssk fetch cost sent rcvd bytes status node node stats remote ssk fetch bytes sent average report sent node node stats remote ssk fetch bytes received average report rcvd if status request sender success can report both parts because we had both a handler and a sender node node stats successful ssk fetch bytes sent average report sent node node stats successful ssk fetch bytes received average report rcvd else if logminor logger minor this remote chk fetch cost sent rcvd bytes status node node stats remote chk fetch bytes sent average report sent node node stats remote chk fetch bytes received average report rcvd if status request sender success can report both parts because we had both a handler and a sender node node stats successful chk fetch bytes sent average report sent node node stats successful chk fetch bytes received average report rcvd applybytecounts appliedbytecounts applybytecounts previousapplybytecountcall previousapplybytecountcall applybytecounts appliedbytecounts finaltransferfailed requestsender timed_out requestsender generated_rejected_overload requestsender internal_error bytessync sentbytes receivedbytes gettotalsentbytes gettotalreceivedbytes nodestats remotesskfetchbytessentaverage nodestats remotesskfetchbytesreceivedaverage requestsender nodestats successfulsskfetchbytessentaverage nodestats successfulsskfetchbytesreceivedaverage nodestats remotechkfetchbytessentaverage nodestats remotechkfetchbytesreceivedaverage requestsender nodestats successfulchkfetchbytessentaverage nodestats successfulchkfetchbytesreceivedaverage private void real run throws not connected exception if logminor logger minor this handling a request uid message accepted dmt createfnp accepted uid source send async accepted null this object o node make request sender key htl uid source false true false false if o instanceof key block tag set served from datastore return local data key block o return if o null ran out of htl message dnf dmt createfnp data not found uid status request sender data not found for byte logging node failure table on final failure key null htl failure table reject time source send terminal dnf return else long queue time source get probable send queue time synchronized this rs request sender o if we cannot respond before this time the source node has already fatally timed out and we need not return packets which will not be claimed search start time system current time millis response deadline search start time request sender fetch timeout queue time rs add listener this realrun notconnectedexception createfnpaccepted sendasync makerequestsender keyblock setservedfromdatastore returnlocaldata keyblock createfnpdatanotfound requestsender data_not_found failuretable onfinalfailure failuretable reject_time sendterminal queuetime getprobablesendqueuetime requestsender searchstarttime currenttimemillis responsedeadline searchstarttime requestsender fetch_timeout queuetime addlistener public void on received reject overload try if sent rejected overload forward rejected overload note this message is only decernable from the terminal messages by the is local flag being false is local terminal message msg dmt createfnp rejected overload uid false source send async msg null this if the status changes e g to success there is little need to send yet another reject overload sent rejected overload true catch not connected exception e logger normal this requestor is gone can t forward reject overload onreceivedrejectoverload sentrejectedoverload rejectedoverload is_local is_local createfnprejectedoverload sendasync sentrejectedoverload notconnectedexception public void onchk transfer begins try is a chk message df dmt createfnpchk data found uid rs get headers source send async df null this partially received block prb rs getprb bt new block transmitter node usm source uid prb this node add transferring request handler uid bt send async node executor catch not connected exception e synchronized this disconnected true tag handler disconnected logger normal this requestor is gone can t begin chk transfer onchktransferbegins createfnpchkdatafound getheaders sendasync partiallyreceivedblock blocktransmitter addtransferringrequesthandler sendasync notconnectedexception handlerdisconnected public void on abort downstream transfers int reason string desc if bt null logger error this no downstream transfer to abort on this return if logminor logger minor this aborting downstream transfer on this tag on abort downstream transfers reason desc try bt abort send reason desc catch not connected exception e ignore onabortdownstreamtransfers onabortdownstreamtransfers abortsend notconnectedexception private void wait and finishchk transfer off thread node executor execute new runnable public void run try wait and finishchk transfer catch not connected exception e for byte logging since the block is the terminal message apply byte counts unregister request handler with node finish chk transfer for key for this waitandfinishchktransferoffthread waitandfinishchktransfer notconnectedexception applybytecounts unregisterrequesthandlerwithnode public void run try wait and finishchk transfer catch not connected exception e for byte logging since the block is the terminal message apply byte counts unregister request handler with node waitandfinishchktransfer notconnectedexception applybytecounts unregisterrequesthandlerwithnode private void wait and finishchk transfer throws not connected exception if logminor logger minor this waiting for chk transfer to finish if bt get async exit status status rs get status successful chk transfer maybe path fold finish opennet checked else final transfer failed true status rs get status for byte logging since the block is the terminal message apply byte counts unregister request handler with node waitandfinishchktransfer notconnectedexception getasyncexitstatus getstatus finishopennetchecked finaltransferfailed getstatus applybytecounts unregisterrequesthandlerwithnode public void on request sender finished int status if logminor logger minor this on request sender finished status on this long now system current time millis this status status boolean too late synchronized this too late response deadline 0 now response deadline if too late offer the data if there is any node failure table on final failure key null htl 1 source peer node routed last rs null null rs routed last a certain number of these are normal logger normal this requestsender took too long to respond to requestor time util format time now search start time 2 true rs null null rs get status string routed to routed last null null routed last short to string apply byte counts unregister request handler with node return if status request sender not finished logger error this on finished but not finished try switch status case request sender not finished case request sender data not found message dnf dmt createfnp data not found uid send terminal dnf return case request sender recently failed message rf dmt createfnp recently failed uid rs get recently failed time left send terminal rf return case request sender generated rejected overload case request sender timed out case request sender internal error locally generated propagate back to source who needs to reduce send rate bug we may not want to translate fatal timeouts into non fatal timeouts message reject dmt createfnp rejected overload uid true send terminal reject return case request sender route not found tell source message rnf dmt createfnp route not found uid rs gethtl send terminal rnf return case request sender success if key instanceof nodessk sendssk rs get headers rs getssk data needs pub key nodessk rs getssk block get key get pub key else if bt null disconnected bug this is impossible logger error this status is success but we never started a transfer on uid obviously this node is confused send a terminal reject to make sure the requestor is not waiting forever reject dmt createfnp rejected overload uid true send terminal reject else if disconnected wait and finishchk transfer off thread else unregister request handler with node return case request sender verify failure case request sender get offer verify failure if key instanceof nodechk if bt null disconnected bug this is impossible logger error this status is verify failure but we never started a transfer on uid obviously this node is confused send a terminal reject to make sure the requestor is not waiting forever reject dmt createfnp rejected overload uid true send terminal reject else if disconnected verify fails after receive is complete so we might as well propagate it wait and finishchk transfer off thread else unregister request handler with node return reject dmt createfnp rejected overload uid true send terminal reject return case request sender transfer failed case request sender get offer transfer failed if key instanceof nodechk if bt null disconnected bug this is impossible logger error this status is transfer failed but we never started a transfer on uid obviously this node is confused send a terminal reject to make sure the requestor is not waiting forever reject dmt createfnp rejected overload uid true send terminal reject else if disconnected wait and finishchk transfer off thread else unregister request handler with node return logger error this finish transfer failed should not be called on ssk new exception error return default treat as internal error reject dmt createfnp rejected overload uid true send terminal reject throw new illegal state exception unknown status code status catch not connected exception e logger normal this requestor is gone can t send terminal message apply byte counts unregister request handler with node onrequestsenderfinished onrequestsenderfinished currenttimemillis toolate toolate responsedeadline responsedeadline toolate failuretable onfinalfailure peernode routedlast routedlast timeutil formattime searchstarttime getstatusstring routedlast routedlast shorttostring applybytecounts unregisterrequesthandlerwithnode requestsender not_finished onfinished requestsender not_finished requestsender data_not_found createfnpdatanotfound sendterminal requestsender recently_failed createfnprecentlyfailed getrecentlyfailedtimeleft sendterminal requestsender generated_rejected_overload requestsender timed_out requestsender internal_error createfnprejectedoverload sendterminal requestsender route_not_found createfnproutenotfound sendterminal requestsender getheaders getsskdata needspubkey getsskblock getkey getpubkey createfnprejectedoverload sendterminal waitandfinishchktransferoffthread unregisterrequesthandlerwithnode requestsender verify_failure requestsender get_offer_verify_failure verify_failure createfnprejectedoverload sendterminal waitandfinishchktransferoffthread unregisterrequesthandlerwithnode createfnprejectedoverload sendterminal requestsender transfer_failed requestsender get_offer_transfer_failed transfer_failed createfnprejectedoverload sendterminal waitandfinishchktransferoffthread unregisterrequesthandlerwithnode transfer_failed createfnprejectedoverload sendterminal illegalstateexception notconnectedexception applybytecounts unregisterrequesthandlerwithnode private void sendssk byte headers final byte data boolean needs pub key2 dsa public key pub key throws not connected exception success requires that both the pubkey and the data headers have been received the pub key will have been set on the ssk key and the ssk block will have been constructed message headers msg dmt createfnpssk data found headers uid headers source send async headers msg null this final message data msg dmt createfnpssk data found data uid data node executor execute new prio runnable public int get priority return request handler this get priority public void run try source send throttled message data msg data length request handler this 60 1000 true null apply byte counts catch not connected exception e okay catch waited too long exception e grrrr logger error this waited too long to send ssk data on request handler this because of bwlimiting catch sync send waited too long exception e logger error this waited too long to send ssk data on request handler this because of peer finally unregister request handler with node send throttled ssk data for request handler this if needs pub key message pk dmt createfnpssk pub key uid pub key source send async pk null this needspubkey2 dsapublickey pubkey notconnectedexception pubkey sskblock headersmsg createfnpsskdatafoundheaders sendasync headersmsg datamsg createfnpsskdatafounddata priorunnable getpriority requesthandler getpriority sendthrottledmessage datamsg requesthandler applybytecounts notconnectedexception waitedtoolongexception requesthandler syncsendwaitedtoolongexception requesthandler unregisterrequesthandlerwithnode requesthandler needspubkey createfnpsskpubkey pubkey sendasync node executor execute new prio runnable public int get priority return request handler this get priority priorunnable getpriority requesthandler getpriority public void run try source send throttled message data msg data length request handler this 60 1000 true null apply byte counts catch not connected exception e okay catch waited too long exception e grrrr logger error this waited too long to send ssk data on request handler this because of bwlimiting catch sync send waited too long exception e logger error this waited too long to send ssk data on request handler this because of peer finally unregister request handler with node sendthrottledmessage datamsg requesthandler applybytecounts notconnectedexception waitedtoolongexception requesthandler syncsendwaitedtoolongexception requesthandler unregisterrequesthandlerwithnode static void sendssk byte headers byte data boolean needs pub key dsa public key pub key final peer node source long uid byte counter ctr throws not connected exception waited too long exception success requires that both the pubkey and the data headers have been received the pub key will have been set on the ssk key and the ssk block will have been constructed message headers msg dmt createfnpssk data found headers uid headers source send async headers msg null ctr final message data msg dmt createfnpssk data found data uid data try source send throttled message data msg data length ctr 60 1000 false null catch sync send waited too long exception e impossible throw new error e if needs pub key message pk dmt createfnpssk pub key uid pub key source send async pk null ctr needspubkey dsapublickey pubkey peernode bytecounter notconnectedexception waitedtoolongexception pubkey sskblock headersmsg createfnpsskdatafoundheaders sendasync headersmsg datamsg createfnpsskdatafounddata sendthrottledmessage datamsg syncsendwaitedtoolongexception needspubkey createfnpsskpubkey pubkey sendasync return data from the datastore param block the block we found in the datastore throws not connected exception if we lose the connected to the request source private void return local data key block block throws not connected exception if key instanceof nodessk sendssk block get raw headers block get raw data needs pub key ssk block block get pub key status request sender success for byte logging else if block instanceof chk block message df dmt createfnpchk data found uid block get raw headers partially received block prb new partially received block node packets in block node packet size block get raw data block transmitter bt new block transmitter node usm source uid prb this node add transferring request handler uid source send async df null this if bt send node executor for byte logging status request sender success we ve fetched it from our datastore so there won t be a downstream noderef but we want to send at least an fnp opennet completed ack otherwise the request source may have to timeout waiting for one that will be the terminal message finish opennet no relay else also for byte logging since the block is the terminal message apply byte counts unregister request handler with node else throw new illegal state exception notconnectedexception returnlocaldata keyblock notconnectedexception getrawheaders getrawdata needspubkey sskblock getpubkey requestsender chkblock createfnpchkdatafound getrawheaders partiallyreceivedblock partiallyreceivedblock packets_in_block packet_size getrawdata blocktransmitter blocktransmitter addtransferringrequesthandler sendasync requestsender fnpopennetcompletedack finishopennetnorelay applybytecounts unregisterrequesthandlerwithnode illegalstateexception private void unregister request handler with node node remove transferring request handler uid node unlockuid uid key instanceof nodessk false false false false tag unregisterrequesthandlerwithnode removetransferringrequesthandler sends the final packet of a request in such a way that the thread can be freed made non runnable exit and the byte counter will still be accurate private void send terminal message msg throws not connected exception if logminor logger minor this send terminal msg new exception debug if send terminal called throw new illegal state exception send terminal should only be called once else send terminal called true source send async msg new terminal message byte count collector this sendterminal notconnectedexception sendterminal sendterminalcalled illegalstateexception sendterminal sendterminalcalled sendasync terminalmessagebytecountcollector public void acknowledged if logminor logger minor this acknowledged terminal message request handler this terminal message ack d by remote peer complete requesthandler terminalmessage public void disconnected if logminor logger minor this peer disconnected before terminal message sent for request handler this complete requesthandler public void fatal error logger error this error sending terminal message for request handler this complete fatalerror requesthandler public void sent if logminor logger minor this sent terminal message request handler this complete requesthandler private void complete synchronized this if completed return completed true if logminor logger minor this completing request handler this for byte counting this relies on the fact that the callback will only be excuted once apply byte counts unregister request handler with node requesthandler applybytecounts unregisterrequesthandlerwithnode either send an ack indicating we ve finished and aren t interested in opennet or wait for a noderef and relay it and wait for a response and relay that or send our own noderef and wait for a response and add that private void finish opennet checked throws not connected exception opennet manager om node get opennet if om null node pass opennet refs through darknet source is opennet finish opennet inner om apply byte counts unregister request handler with node return message msg dmt createfnp opennet completed ack uid send terminal msg finishopennetchecked notconnectedexception opennetmanager getopennet passopennetrefsthroughdarknet isopennet finishopennetinner applybytecounts unregisterrequesthandlerwithnode createfnpopennetcompletedack sendterminal there is no noderef to pass downstream if we want a connection send our noderef and wait for a reply otherwise just send an ack private void finish opennet no relay throws not connected exception opennet manager om node get opennet if om null source is opennet node pass opennet refs through darknet finish opennet no relay inner om apply byte counts unregister request handler with node return otherwise just ack it message msg dmt createfnp opennet completed ack uid send terminal msg finishopennetnorelay notconnectedexception opennetmanager getopennet isopennet passopennetrefsthroughdarknet finishopennetnorelayinner applybytecounts unregisterrequesthandlerwithnode createfnpopennetcompletedack sendterminal private boolean finish opennet inner opennet manager om byte noderef rs wait for opennet noderef if noderef null return finish opennet no relay inner om if node random next int opennet manager reset path folding prob 0 return finish opennet no relay inner om finish opennet relay noderef om return true finishopennetinner opennetmanager waitforopennetnoderef finishopennetnorelayinner nextint opennetmanager reset_path_folding_prob finishopennetnorelayinner finishopennetrelay send our noderef to the request source wait for a reply if we get one add it called when either the request wasn t routed or the node it was routed to didn t return a noderef return true if success or lost connection false if we need to send an ack private boolean finish opennet no relay inner opennet manager om if logminor logger minor this finishing opennet sending own reference if om want peer null false false false return false don t want a reference try om send opennet ref false uid source om crypto my compressed full ref this catch not connected exception e logger normal this can t send opennet ref because node disconnected on this oh well return true wait for response byte noderef om wait for opennet noderef true source uid this if noderef null return false simple field set ref om validate noderef noderef 0 noderef length source false if ref null return false try if node add new opennet node ref null logger normal this asked for opennet ref but didn t want it for this n ref else logger normal this added opennet noderef in this catch fs parse exception e logger error this could not parse opennet noderef for this from source e catch peer parse exception e logger error this could not parse opennet noderef for this from source e catch reference signature verification exception e logger error this bad signature on opennet noderef for this from source e e return true finishopennetnorelayinner opennetmanager wantpeer sendopennetref mycompressedfullref notconnectedexception waitforopennetnoderef simplefieldset validatenoderef addnewopennetnode fsparseexception peerparseexception referencesignatureverificationexception called when the node we routed the request to returned a valid noderef and we don t want it so we relay it downstream to somebody who does and wait to relay the response back upstream param noderef param om private void finish opennet relay byte noderef opennet manager om if logminor logger minor this finishing opennet relaying reference from rs success from send it back to the handler then wait for the connect reply peer node data source rs success from try om send opennet ref false uid source noderef this catch not connected exception e lost contact with request source nothing we can do return now wait for reply from the request source byte new noderef om wait for opennet noderef true source uid this if new noderef null already sent a ref no way to tell upstream that we didn t receive one return send it forward to the data source if it is valid if om validate noderef new noderef 0 new noderef length source false null try om send opennet ref true uid data source new noderef this catch not connected exception e how sad return finishopennetrelay opennetmanager successfrom connectreply peernode datasource successfrom sendopennetref notconnectedexception newnoderef waitforopennetnoderef newnoderef validatenoderef newnoderef newnoderef sendopennetref datasource newnoderef notconnectedexception public void sent bytes int x synchronized bytes sync sent bytes x node node stats request sent bytes key instanceof nodessk x if logminor logger minor this sent bytes x on this sentbytes bytessync sentbytes nodestats requestsentbytes sentbytes public void received bytes int x synchronized bytes sync received bytes x node node stats request received bytes key instanceof nodessk x receivedbytes bytessync receivedbytes nodestats requestreceivedbytes public void sent payload int x do not add payload to sent bytes sent bytes is called with the actual sent bytes and we do not deduct the already reported bytes which are only used for accounting for the bandwidth throttle node sent payload x node node stats request sent bytes key instanceof nodessk x if logminor logger minor this sent payload x on this sentpayload sentbytes sentbytes alreadyreportedbytes sentpayload nodestats requestsentbytes sentpayload public int get priority return native thread high priority getpriority nativethread high_priority public abstract class messageuri public abstract freeneturi get freeneturi getfreeneturi public abstract freeneturi get freeneturi public abstract string get messageid getfreeneturi getmessageid public abstract string get messageid override public abstract boolean equals object obj getmessageid public abstract boolean equals object obj override public abstract string to string tostring public class black function implements binary function public boolean is black int rgb return rgb 0xff000000 blackfunction binaryfunction isblack private string value new string public attribute public attribute string name string value set name name set value value setname setvalue public void set name string name this name name setname public string get name return name getname public void set value string value this value value setvalue public string get value return value getvalue public final class saturation composite extends rgb composite public saturation composite float alpha super alpha saturationcomposite rgbcomposite saturationcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel private float dhsb new float 3 public context float alpha color model src color model color model dst color model super alpha src color model dst color model colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob color rg btohsb sr sg sb shsb color rg btohsb dir dig dib dhsb dhsb 1 shsb 1 int dorgb color hs btorgb dhsb 0 dhsb 1 dhsb 2 dor dorgb 0xff0000 16 dog dorgb 0xff00 8 dob dorgb 0xff float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac rgbtohsb rgbtohsb hsbtorgb get a list of fields which the database should create an index on public static string get indexed fields return new string mid m last fetched date getindexedfields mlastfetcheddate creates an identity param new requesturi a link freeneturi to fetch this identity param new nickname the nickname of this identity param does publish trust list whether this identity publishes its trust list or not throws invalid parameter exception if a supplied parameter is invalid protected identity freeneturi new requesturi string new nickname boolean does publish trust list throws invalid parameter exception set requesturi new requesturi mid getid fromuri get requesturi m added date current timeutc get m first fetched date new date 0 m last fetched date new date 0 m last changed date new date 0 set nickname new nickname set publish trust list does publish trust list m contexts new array list string 4 currently we have introduction freetalk m properties new hash map string string logger debug this new identity get nickname uri new requesturi newrequesturi newnickname doespublishtrustlist trustlist invalidparameterexception newrequesturi newnickname doespublishtrustlist invalidparameterexception setrequesturi newrequesturi getidfromuri getrequesturi maddeddate currenttimeutc mfirstfetcheddate mlastfetcheddate mlastchangeddate setnickname newnickname setpublishtrustlist doespublishtrustlist mcontexts arraylist mproperties hashmap getnickname newrequesturi creates an identity only for being used by the wot package and unit tests not for user interfaces param new requesturi a string that will be converted to link freeneturi before creating the identity param new nickname the nickname of this identity param does publish trust list whether this identity publishes its trust list or not throws invalid parameter exception if a supplied parameter is invalid throws malformedurl exception if the supplied requesturi isn t a valid freeneturi public identity string new requesturi string new nickname boolean does publish trust list throws invalid parameter exception malformedurl exception this new freeneturi new requesturi new nickname does publish trust list newrequesturi newnickname doespublishtrustlist trustlist invalidparameterexception malformedurlexception newrequesturi newnickname doespublishtrustlist invalidparameterexception malformedurlexception newrequesturi newnickname doespublishtrustlist gets this identity s id which is the routing key of the author encoded with the freenet variant of base64 we use this to identify identities and perform requests on the database return a unique identifier for this identity public string getid return mid generates a unique i dfrom a link freeneturi which is the routing key of the author encoded with the freenet variant of base64 we use this to identify identities and perform requests on the database param uri the requesturi of the identity return a string to uniquely identify the identity public static final string getid fromuri freeneturi uri warning when changing this also update freetalk wot wot identity getuid fromuri return base64 encode uri get routing key idfrom getidfromuri wotidentity getuidfromuri getroutingkey return the requesturi link freeneturi to fetch this identity public synchronized freeneturi get requesturi return m requesturi getrequesturi mrequesturi sets the requesturi of this identity the given link freeneturi is converted to usk and the document name is forced to wot param new requesturi the freeneturi used to fetch this identity throws illegal argument exception if the given freeneturi is neither a ssk nor a usk or if the keypair does not match the old one protected synchronized void set requesturi freeneturi new requesturi if m requesturi null new requesturi equals keypair m requesturi throw new illegal argument exception cannot change the request uri of an existing identity if new requesturi isusk new requesturi isssk throw new illegal argument exception identity uri keytype not supported new requesturi m requesturi new requesturi set key type usk set doc name wot set meta string null updated newrequesturi illegalargumentexception setrequesturi newrequesturi mrequesturi newrequesturi equalskeypair mrequesturi illegalargumentexception newrequesturi newrequesturi illegalargumentexception newrequesturi mrequesturi newrequesturi setkeytype setdocname setmetastring get the edition number of the request uri of this identity public synchronized long get edition return get requesturi get suggested edition getedition getrequesturi getsuggestededition sets the edition of the last fetched version of this identity that number is published in trust lists to limit the number of editions a newbie has to fetch before he actually gets ans identity param new edition a long representing the last fetched version of this identity throws invalid parameter exception if the new edition is less than the current one protected synchronized void set edition long new edition throws invalid parameter exception long current edition m requesturi get edition if new edition current edition throw new invalid parameter exception the edition of an identity cannot be lowered if new edition current edition m requesturi m requesturi set suggested edition new edition updated trustlists newedition invalidparameterexception setedition newedition invalidparameterexception currentedition mrequesturi getedition newedition currentedition invalidparameterexception newedition currentedition mrequesturi mrequesturi setsuggestededition newedition decrease the current edition by one called by the wot when the score of an identity changes from negative or 0 to 0 to make the identity fetcher re download it s current trust list this is necessary because we do not create the trusted identities of someone if he has a negative score protected synchronized void decrease edition long new edition get edition 1 if new edition 0 new edition 0 if the edition is 0 the fetcher decides via last fetched date whether to fetch current or next m last fetched date new date 0 m requesturi m requesturi set suggested edition new edition currentedition identityfetcher decreaseedition newedition getedition newedition newedition mlastfetcheddate mrequesturi mrequesturi setsuggestededition newedition return the date when this identity was first seen in a trust list of someone public date get added date return date m added date clone getaddeddate maddeddate return the date when the identity was fetched successfully for the first time equal to new date 0 if it was never fetched public date get first fetched date return date m first fetched date clone getfirstfetcheddate mfirstfetcheddate return the date of this identity s last modification public synchronized date get last fetched date return date m last fetched date clone getlastfetcheddate mlastfetcheddate return the date of this identity s last modification public synchronized date get last change date return date m last changed date clone getlastchangedate mlastchangeddate has to be called when the identity was fetched protected synchronized void on fetched if m first fetched date equals new date 0 m first fetched date current timeutc get m last fetched date current timeutc get updated onfetched mfirstfetcheddate mfirstfetcheddate currenttimeutc mlastfetcheddate currenttimeutc return the identity s nick name public synchronized string get nickname return m nickname nickname getnickname mnickname important this code is duplicated in plugins freetalk wot wot identity validate nickname please also modify it there if you modify it here public boolean is nickname valid string new nickname return new nickname length 0 new nickname length 50 string validity checker contains noidn blacklist characters new nickname wotidentity validatenickname isnicknamevalid newnickname newnickname newnickname stringvaliditychecker containsnoidnblacklistcharacters newnickname sets the nick name of this identity param m nickname a string containing this identity s nick name setting it to null means that it was not retrieved yet throws invalid parameter exception if the nick name s length is bigger than 50 or if it empty public synchronized void set nickname string new nickname throws invalid parameter exception if new nickname null new nickname new nickname trim if new nickname null if new nickname length 0 throw new invalid parameter exception blank nickname if new nickname length 50 throw new invalid parameter exception nickname is too long 50 chars max if is nickname valid new nickname throw new invalid parameter exception nickname contains illegal characters if m nickname null m nickname equals new nickname throw new invalid parameter exception changing the nickname of an identity is not allowed m nickname new nickname updated nickname mnickname nickname invalidparameterexception nickname setnickname newnickname invalidparameterexception newnickname newnickname newnickname newnickname newnickname invalidparameterexception newnickname invalidparameterexception isnicknamevalid newnickname invalidparameterexception mnickname mnickname newnickname invalidparameterexception mnickname newnickname checks whether this identity publishes a trust list return whether this identity publishes its trust list or not public synchronized boolean does publish trust list return m does publish trust list trustlist doespublishtrustlist mdoespublishtrustlist sets if this identity publishes its trust list or not public synchronized void set publish trust list boolean does publish trust list if m does publish trust list does publish trust list return m does publish trust list does publish trust list updated setpublishtrustlist doespublishtrustlist mdoespublishtrustlist doespublishtrustlist mdoespublishtrustlist doespublishtrustlist checks whether this identity offers the given contexts param context the context we want to know if this identity has it or not return whether this identity has that context or not public synchronized boolean has context string context return m contexts contains context trim hascontext mcontexts gets all this identity s contexts return a copy of the array list string of all contexts of this identity suppress warnings unchecked public synchronized array list string get contexts todo if this is used often which it probably is we might verify that no code corrupts the hash map and return the original one instead of a copy return array list string m contexts clone arraylist suppresswarnings arraylist getcontexts hashmap arraylist mcontexts adds a context to this identity a context is a string the identities contexts are a set of strings no context will be added more than once contexts are used by client applications to identify what identities are relevant for their use currently known contexts wot adds the introduction context if an identity publishes catpchas to allow other to get on it s trust list freetalk the messaging system for freenet adds the freetalk context to identities which use it param db a reference to the database param context name of the context throws invalid parameter exception if the context name is empty public synchronized void add context string new context throws invalid parameter exception new context new context trim if new context length 0 throw new invalid parameter exception a blank context cannot be added to an identity fixme limit the length of a context if m contexts contains new context fixme limit the amount of contexts m contexts add new context updated invalidparameterexception addcontext newcontext invalidparameterexception newcontext newcontext newcontext invalidparameterexception mcontexts newcontext mcontexts newcontext clears the list of contexts and sets it to the new list of contexts which was passed to the function duplicate contexts are ignored for invalid contexts an error is logged all valid ones will be added important this always marks the identity as updated so it should not be used on own identities because it would result in a re insert even if nothing was changed protected synchronized void set contexts list string new contexts m contexts clear for string context new contexts try add context context catch invalid parameter exception e logger error this set contexts add context failed e m contexts trim to size ownidentities setcontexts newcontexts mcontexts newcontexts addcontext invalidparameterexception setcontexts addcontext mcontexts trimtosize removes a context from this identity does nothing if it does not exist if this identity is no longer used by a client application the user can tell it and others won t try to fetch it anymore param db a reference to the database param context name of the context public synchronized void remove context string context throws invalid parameter exception context context trim if m contexts contains context m contexts remove context updated removecontext invalidparameterexception mcontexts mcontexts gets the value of one of this identity s properties param key the name of the requested custom property return the value of the requested custom property throws invalid parameter exception if this identity doesn t have the required property public synchronized string get property string key throws invalid parameter exception key key trim if m properties contains key key throw new invalid parameter exception the property key isn t set on this identity return m properties get key invalidparameterexception getproperty invalidparameterexception mproperties containskey invalidparameterexception mproperties gets all custom properties from this identity return a copy of the hash map string string referencing all this identity s custom properties suppress warnings unchecked public synchronized hash map string string get properties todo if this is used often we might verify that no code corrupts the hash map and return the original one instead of a copy return hash map string string m properties clone hashmap suppresswarnings hashmap getproperties hashmap hashmap mproperties sets a custom property on this identity custom properties keys have to be unique this can be used by client applications that need to store additional informations on their identities crypto keys avatar whatever the key is always trimmed before storage the value is stored as passed param db a reference to the database param key name of the custom property param value value of the custom property throws invalid parameter exception if the key or the value is empty public synchronized void set property string key string value throws invalid parameter exception key key trim if key length 0 value length 0 throw new invalid parameter exception blank key or value in this property fixme limit the length of key and value string old value m properties get key if old value null old value equals value false fixme limit the amount of properties m properties put key value updated invalidparameterexception setproperty invalidparameterexception invalidparameterexception oldvalue mproperties oldvalue oldvalue mproperties clears the list of properties and sets it to the new list of properties which was passed to the function for invalid properties an error is logged all valid ones will be added important this always marks the identity as updated so it should not be used on own identities because it would result in a re insert even if nothing was changed protected synchronized void set properties hash map string string new properties m properties new hash map string string for entry string string property new properties entry set try set property property get key property get value catch invalid parameter exception e logger error this set properties set property failed e ownidentities setproperties hashmap newproperties mproperties hashmap newproperties entryset setproperty getkey getvalue invalidparameterexception setproperties setproperty removes a custom property from this identity does nothing if it does not exist param db a reference to the database param key name of the custom property public synchronized void remove property string key throws invalid parameter exception key key trim if m properties remove key null updated removeproperty invalidparameterexception mproperties tell that this identity has been updated updated own identities will be reinserted by the identity inserter automatically public synchronized void updated m last changed date current timeutc get ownidentities identityinserter mlastchangeddate currenttimeutc static final byte db database format version byte 2 final int get bitmap page id int i return i db bitmap pages db bitmap id i header root 1 curr index bitmap extent i bitmap extent base dbdatabaseformatversion getbitmappageid dbbitmappages dbbitmapid currindex bitmapextent bitmapextentbase final long get pos int oid synchronized object cache if oid 0 oid curr index size throw new storage error storage error invalid oid page pg pool get page header root 1 curr index index long oid db handles per page bits page page size log long pos bytes unpack8 pg data oid db handles per page 1 3 pool unfix pg return pos getpos objectcache currindexsize storageerror storageerror invalid_oid getpage currindex dbhandlesperpagebits pagesizelog dbhandlesperpage final void set pos int oid long pos synchronized object cache dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 page pg pool put page header root 1 curr index index long oid db handles per page bits page page size log bytes pack8 pg data oid db handles per page 1 3 pos pool unfix pg setpos objectcache dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits putpage currindex dbhandlesperpagebits pagesizelog dbhandlesperpage final byte get int oid long pos get pos oid if pos db free handle flag db page object flag 0 throw new storage error storage error invalid oid return pool get pos db flags mask getpos dbfreehandleflag dbpageobjectflag storageerror storageerror invalid_oid dbflagsmask final page get page int oid long pos get pos oid if pos db free handle flag db page object flag db page object flag throw new storage error storage error deleted object return pool get page pos db flags mask getpage getpos dbfreehandleflag dbpageobjectflag dbpageobjectflag storageerror storageerror deleted_object getpage dbflagsmask final page put page int oid synchronized object cache long pos get pos oid if pos db free handle flag db page object flag db page object flag throw new storage error storage error deleted object if pos db modified flag 0 dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 allocate page page size oid clone bitmap pos db flags mask page page size pos get pos oid modified true return pool put page pos db flags mask putpage objectcache getpos dbfreehandleflag dbpageobjectflag dbpageobjectflag storageerror storageerror deleted_object dbmodifiedflag dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits pagesize clonebitmap dbflagsmask pagesize getpos putpage dbflagsmask int allocate page int oid allocate id set pos oid allocate page page size 0 db page object flag db modified flag return oid allocatepage allocateid setpos pagesize dbpageobjectflag dbmodifiedflag public protected synchronized void deallocate object i persistent obj synchronized object cache if obj get oid 0 return if use serializable transactions thread transaction context ctx get transaction context if ctx nested 0 serializable transaction ctx deleted add obj return deallocate object0 obj deallocateobject ipersistent objectcache getoid useserializabletransactions threadtransactioncontext gettransactioncontext deallocateobject0 public void throw object i persistent obj object cache remove obj get oid throwobject ipersistent objectcache getoid private void deallocate object0 i persistent obj int oid obj get oid long pos get pos oid object cache remove oid int offs int pos page page size 1 if offs db free handle flag db page object flag 0 throw new storage error storage error deleted object page pg pool get page pos offs offs db flags mask int size object header get size pg data offs pool unfix pg free id oid custom allocator allocator custom allocator map null get custom allocator obj get class null if allocator null allocator free pos db flags mask size else if pos db modified flag 0 free pos db flags mask size else clone bitmap pos size obj assign oid null 0 false deallocateobject0 ipersistent getoid getpos objectcache pagesize dbfreehandleflag dbpageobjectflag storageerror storageerror deleted_object getpage dbflagsmask objectheader getsize freeid customallocator customallocatormap getcustomallocator getclass dbflagsmask dbmodifiedflag dbflagsmask clonebitmap assignoid final void free page int oid long pos get pos oid assert that pos db free handle flag db page object flag db page object flag if pos db modified flag 0 free pos db flags mask page page size else clone bitmap pos db flags mask page page size free id oid freepage getpos dbfreehandleflag dbpageobjectflag dbpageobjectflag dbmodifiedflag dbflagsmask pagesize clonebitmap dbflagsmask pagesize freeid int allocate id synchronized object cache int oid int curr 1 curr index set dirty if oid header root curr free list 0 header root curr free list int get pos oid db flags bits assert that header root curr free list 0 dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 return oid if curr index size db max object oid throw new storage error storage error too much objects if curr index size header root curr index size int old index size header root curr index size int new index size old index size 1 if new index size old index size new index size integer max value db handles per page 1 if new index size old index size throw new storage error storage error not enough space long new index allocate new index size 8l 0 if curr index size header root curr index size long old index header root curr index pool copy new index old index curr index size 8l header root curr index new index header root curr index size new index size free old index old index size 8l else index was already reallocated free new index new index size 8l oid curr index size header root curr index used curr index size return oid allocateid objectcache currindex setdirty freelist freelist getpos dbflagsbits freelist dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits currindexsize dbmaxobjectoid storageerror storageerror too_much_objects currindexsize indexsize oldindexsize indexsize newindexsize oldindexsize newindexsize oldindexsize newindexsize max_value dbhandlesperpage newindexsize oldindexsize storageerror storageerror not_enough_space newindex newindexsize currindexsize indexsize oldindex newindex oldindex currindexsize newindex indexsize newindexsize oldindex oldindexsize newindex newindexsize currindexsize indexused currindexsize void free id int oid synchronized object cache set pos oid long header root 1 curr index free list db flags bits db free handle flag header root 1 curr index free list oid freeid objectcache setpos currindex freelist dbflagsbits dbfreehandleflag currindex freelist static final void memset page pg int offs int pattern int len byte arr pg data byte pat byte pattern while len 0 arr offs pat final void extend long size if size header root 1 curr index size header root 1 curr index size size currindex currindex public long get used size return used size getusedsize usedsize public long get database size return header root 1 curr index size getdatabasesize currindex final boolean was reserved long pos long size for location location reserved chain location null location location next if pos location pos pos location pos location size pos location pos location pos pos size return true return false wasreserved reservedchain final void reserve location long pos long size location location new location location pos pos location size size location next reserved chain reserved chain location reservelocation reservedchain reservedchain final void commit location reserved chain reserved chain next commitlocation reservedchain reservedchain final void set dirty modified true if header dirty header dirty true page pg pool put page 0 header pack pg data pool flush pool unfix pg setdirty putpage protected boolean is dirty return header dirty isdirty final page put bitmap page int i return put page get bitmap page id i putbitmappage putpage getbitmappageid final page get bitmap page int i return get page get bitmap page id i getbitmappage getpage getbitmappageid final long allocate long size int oid synchronized object cache set dirty size size db allocation quantum 1 db allocation quantum 1 assert that size 0 allocated delta size if allocated delta gc threshold gc0 int obj bit size int size db allocation quantum bits assert that obj bit size size db allocation quantum bits long pos int hole bit size 0 int alignment int size page page size 1 int offs first page last page i j int hole before free page 0 int free bitmap page 0 int curr 1 curr index page pg last page header root curr bitmap end db bitmap id used size size if alignment 0 first page currp bitmap page offs currp bitmap offs inc 1 inc 1 else first page currr bitmap page offs currr bitmap offs while true if alignment 0 allocate page object for i first page i last page i int space needed obj bit size hole bit size page bits obj bit size hole bit size page bits if bitmap page available space i space needed hole bit size 0 offs 0 continue pg get bitmap page i int start offs offs while offs page page size if pg data offs 0 offs offs inc 1 inc 1 hole bit size 0 else if hole bit size 8 obj bit size pos long i page page size offs 8 hole bit size db allocation quantum bits if was reserved pos size start offs offs offs inc 1 inc 1 hole bit size 0 continue reserve location pos size currp bitmap page i currp bitmap offs offs extend pos size if oid 0 long prev get pos oid int marker int prev db flags mask pool copy pos prev marker size set pos oid pos marker db modified flag pool unfix pg pg put bitmap page i int hole bytes hole bit size 3 if hole bytes offs memset pg 0 0xff offs hole bytes offs pool unfix pg pg put bitmap page i offs page page size while hole bytes page page size memset pg 0 0xff page page size hole bytes page page size bitmap page available space i 0 pool unfix pg pg put bitmap page i memset pg offs hole bytes 0xff hole bytes commit location pool unfix pg return pos if start offs 0 hole bit size 0 space needed bitmap page available space i bitmap page available space i space needed offs 0 pool unfix pg else for i first page i last page i int space needed obj bit size hole bit size page bits obj bit size hole bit size page bits if bitmap page available space i space needed hole bit size 0 offs 0 continue pg get bitmap page i int start offs offs while offs page page size int mask pg data offs 0xff if hole bit size bitmap first hole size mask obj bit size pos long i page page size offs 8 hole bit size db allocation quantum bits if was reserved pos size start offs offs 1 hole bit size 0 continue reserve location pos size currr bitmap page i currr bitmap offs offs extend pos size if oid 0 long prev get pos oid int marker int prev db flags mask pool copy pos prev marker size set pos oid pos marker db modified flag pool unfix pg pg put bitmap page i pg data offs byte 1 obj bit size hole bit size 1 if hole bit size 0 if hole bit size offs 8 memset pg 0 0xff offs hole bit size offs 8 pool unfix pg pg put bitmap page i offs page page size while hole bit size page bits memset pg 0 0xff page page size hole bit size page bits bitmap page available space i 0 pool unfix pg pg put bitmap page i while hole bit size 8 0 pg data offs byte 0xff pg data offs 1 byte 1 hole bit size 1 pool unfix pg commit location return pos else if bitmap max hole size mask obj bit size int hole bit offset bitmap max hole offset mask pos long i page page size offs 8 hole bit offset db allocation quantum bits if was reserved pos size start offs offs 1 hole bit size 0 continue reserve location pos size currr bitmap page i currr bitmap offs offs extend pos size if oid 0 long prev get pos oid int marker int prev db flags mask pool copy pos prev marker size set pos oid pos marker db modified flag pool unfix pg pg put bitmap page i pg data offs byte 1 obj bit size 1 hole bit offset pool unfix pg commit location return pos offs 1 if bitmap last hole size mask 8 hole bit size 8 else hole bit size bitmap last hole size mask if start offs 0 hole bit size 0 objectcache setdirty dballocationquantum dballocationquantum allocateddelta allocateddelta gcthreshold objbitsize dballocationquantumbits objbitsize dballocationquantumbits holebitsize pagesize firstpage lastpage holebeforefreepage freebitmappage currindex lastpage bitmapend dbbitmapid usedsize firstpage currpbitmappage currpbitmapoffs firstpage currrbitmappage currrbitmapoffs firstpage lastpage spaceneeded objbitsize holebitsize pagebits objbitsize holebitsize pagebits bitmappageavailablespace spaceneeded holebitsize getbitmappage startoffs pagesize holebitsize holebitsize objbitsize pagesize holebitsize dballocationquantumbits wasreserved startoffs holebitsize reservelocation currpbitmappage currpbitmapoffs getpos dbflagsmask setpos dbmodifiedflag putbitmappage holebytes holebitsize holebytes holebytes putbitmappage pagesize holebytes pagesize pagesize holebytes pagesize bitmappageavailablespace putbitmappage holebytes holebytes commitlocation startoffs holebitsize spaceneeded bitmappageavailablespace bitmappageavailablespace spaceneeded firstpage lastpage spaceneeded objbitsize holebitsize pagebits objbitsize holebitsize pagebits bitmappageavailablespace spaceneeded holebitsize getbitmappage startoffs pagesize holebitsize firstholesize objbitsize pagesize holebitsize dballocationquantumbits wasreserved startoffs holebitsize reservelocation currrbitmappage currrbitmapoffs getpos dbflagsmask setpos dbmodifiedflag putbitmappage objbitsize holebitsize holebitsize holebitsize holebitsize putbitmappage pagesize holebitsize pagebits pagesize holebitsize pagebits bitmappageavailablespace putbitmappage holebitsize holebitsize commitlocation maxholesize objbitsize holebitoffset maxholeoffset pagesize holebitoffset dballocationquantumbits wasreserved startoffs holebitsize reservelocation currrbitmappage currrbitmapoffs getpos dbflagsmask setpos dbmodifiedflag putbitmappage objbitsize holebitoffset commitlocation lastholesize holebitsize holebitsize lastholesize startoffs holebitsize final void fill bitmap long adr int len while true int off int adr page page size 1 page pg pool put page adr off if page page size off len memset pg off 0xff len pool unfix pg break else memset pg off 0xff page page size off pool unfix pg adr page page size off len page page size off fillbitmap pagesize putpage pagesize pagesize pagesize pagesize final void free long pos long size synchronized object cache assert that pos 0 pos db allocation quantum 1 0 long quant no pos db allocation quantum bits int obj bit size int size db allocation quantum 1 db allocation quantum bits int page id int quant no page page size log 3 int offs int quant no page page size 8 1 3 page pg put bitmap page page id int bit offs int quant no 7 allocated delta long obj bit size db allocation quantum bits used size long obj bit size db allocation quantum bits if pos page page size 1 0 size page page size if page id currp bitmap page offs currp bitmap offs currp bitmap offs offs if page id currr bitmap page offs currr bitmap offs currr bitmap offs offs bitmap page available space page id integer max value if obj bit size 8 bit offs obj bit size 8 bit offs pg data offs 1 bit offs 1 while obj bit size offs 8 page page size 8 memset pg offs 0 page page size offs pool unfix pg pg put bitmap page page id bitmap page available space page id integer max value obj bit size page page size offs 8 offs 0 while obj bit size 8 0 pg data offs byte 0 pg data offs byte 1 obj bit size 8 1 else pg data offs byte 1 obj bit size 1 bit offs pool unfix pg objectcache dballocationquantum quantno dballocationquantumbits objbitsize dballocationquantum dballocationquantumbits pageid quantno pagesizelog quantno pagesize putbitmappage pageid bitoffs quantno allocateddelta objbitsize dballocationquantumbits usedsize objbitsize dballocationquantumbits pagesize pagesize pageid currpbitmappage currpbitmapoffs currpbitmapoffs pageid currrbitmappage currrbitmapoffs currrbitmapoffs bitmappageavailablespace pageid max_value objbitsize bitoffs objbitsize bitoffs bitoffs objbitsize pagesize pagesize putbitmappage pageid bitmappageavailablespace pageid max_value objbitsize pagesize objbitsize objbitsize objbitsize bitoffs clone node next clone node long pos clone node list this pos pos this next list clonenode clonenode clonenode final void clone bitmap long pos long size synchronized object cache if inside clone bitmap assert that size page page size clone list new clone node pos clone list else inside clone bitmap true while true long quant no pos db allocation quantum bits int obj bit size int size db allocation quantum 1 db allocation quantum bits int page id int quant no page page size log 3 int offs int quant no page page size 8 1 3 int bit offs int quant no 7 int oid get bitmap page id page id pos get pos oid if pos db modified flag 0 dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 allocate page page size oid clone bitmap pos db flags mask page page size if obj bit size 8 bit offs obj bit size 8 bit offs offs 1 while obj bit size offs 8 page page size 8 oid get bitmap page id page id pos get pos oid if pos db modified flag 0 dirty pages map oid db handles per page bits 5 1 oid db handles per page bits 31 allocate page page size oid clone bitmap pos db flags mask page page size obj bit size page page size offs 8 offs 0 if clone list null break pos clone list pos size page page size clone list clone list next inside clone bitmap false clonebitmap objectcache insideclonebitmap pagesize clonelist clonenode clonelist insideclonebitmap quantno dballocationquantumbits objbitsize dballocationquantum dballocationquantumbits pageid quantno pagesizelog quantno pagesize bitoffs quantno getbitmappageid pageid getpos dbmodifiedflag dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits pagesize clonebitmap dbflagsmask pagesize objbitsize bitoffs objbitsize bitoffs objbitsize pagesize getbitmappageid pageid getpos dbmodifiedflag dirtypagesmap dbhandlesperpagebits dbhandlesperpagebits pagesize clonebitmap dbflagsmask pagesize objbitsize pagesize clonelist clonelist pagesize clonelist clonelist insideclonebitmap public void open string file path open file path default page pool size filepath filepath default_page_pool_size public void open i file file open file default page pool size ifile default_page_pool_size public synchronized void open string file path int page pool size i file file file path starts with i file new multi file file path substring 1 read only no flush i file new os file file path read only no flush try open file page pool size catch storage error ex file close throw ex filepath pagepoolsize ifile filepath startswith ifile multifile filepath readonly noflush ifile osfile filepath readonly noflush pagepoolsize storageerror public synchronized void open string file path int page pool size string crypt key rc4 file file new rc4 file file path read only no flush crypt key try open file page pool size catch storage error ex file close throw ex filepath pagepoolsize cryptkey rc4file rc4file filepath readonly noflush cryptkey pagepoolsize storageerror public void clear object cache object cache clear clearobjectcache objectcache protected oid hash table create object cache string kind int page pool size int object cache size if page pool size infinite page pool strong equals kind return new strong hash table object cache size if soft equals kind return new soft hash table object cache size if weak equals kind return new weak hash table object cache size if pinned equals kind return new pin weak hash table object cache size return new lru object cache object cache size oidhashtable createobjectcache pagepoolsize objectcachesize pagepoolsize infinite_page_pool stronghashtable objectcachesize softhashtable objectcachesize weakhashtable objectcachesize pinweakhashtable objectcachesize lruobjectcache objectcachesize protected void initialize i file file int page pool size this file file if lock file multiclient support if file try lock false throw new storage error storage error storage is used dirty pages map new int db dirty page bitmap size 4 1 gc threshold long max value background gc monitor new object background gc start monitor new object gc thread null gc active false gc done false allocated delta 0 reserved chain null clone list null inside clone bitmap false n nested transactions 0 n blocked transactions 0 n committed transactions 0 scheduled commit time long max value transaction monitor new object transaction lock new persistent resource modified false object cache create object cache cache kind page pool size object cache init size class desc map new hash map desc list null header new header pool new page pool page pool size page page size page pool lru limit pool open file ifile pagepoolsize lockfile multiclientsupport trylock storageerror storageerror storage_is_used dirtypagesmap dbdirtypagebitmapsize gcthreshold max_value backgroundgcmonitor backgroundgcstartmonitor gcthread gcactive gcdone allocateddelta reservedchain clonelist insideclonebitmap nnestedtransactions nblockedtransactions ncommittedtransactions scheduledcommittime max_value transactionmonitor transactionlock persistentresource objectcache createobjectcache cachekind pagepoolsize objectcacheinitsize classdescmap hashmap desclist pagepool pagepoolsize pagesize pagepoollrulimit public synchronized void open i file file int page pool size page pg int i if opened throw new storage error storage error storage already opened initialize file page pool size if multiclient support begin thread transaction read write transaction byte buf new byte header sizeof int rc file read 0 buf if rc 0 rc header sizeof throw new storage error storage error database corrupted header unpack buf if header curr 0 header curr 1 throw new storage error storage error database corrupted transaction id header transaction id if header database format version 0 database not initialized int index size init index size if index size db first user id index size db first user id index size index size db handles per page 1 db handles per page 1 bitmap extent base db bitmap pages header curr curr index 0 long used page page size header root 0 index used header root 0 index size index size header root 0 index used db first user id header root 0 free list 0 used index size 8l header root 1 index used header root 1 index size index size header root 1 index used db first user id header root 1 free list 0 used index size 8l header root 0 shadow index header root 1 index header root 1 shadow index header root 0 index header root 0 shadow index size index size header root 1 shadow index size index size int bitmap pages int used page page size db allocation quantum 8 1 1 page page size db allocation quantum 8 1 long bitmap size long bitmap pages page page size int used bitmap size int used bitmap size db allocation quantum bits 3 for i 0 i bitmap pages i pg pool put page used long i page page size byte bitmap pg data int n used bitmap size page page size page page size used bitmap size for int j 0 j n j bitmap j byte 0xff used bitmap size page page size pool unfix pg int bitmap index size db bitmap id db bitmap pages 8 page page size 1 page page size 1 byte index new byte bitmap index size bytes pack8 index db invalid id 8 db free handle flag for i 0 i bitmap pages i bytes pack8 index db bitmap id i 8 used db page object flag used page page size header root 0 bitmap end db bitmap id i header root 1 bitmap end db bitmap id i while i db bitmap pages bytes pack8 index db bitmap id i 8 db free handle flag i 1 header root 0 size used header root 1 size used used size used committed index size curr index size db first user id pool write header root 1 index index pool write header root 0 index index header dirty true header root 0 size header root 1 size pg pool put page 0 header pack pg data pool flush pool modify pg header database format version db database format version header pack pg data pool unfix pg pool flush else int curr header curr curr index curr if header root curr index size header root curr shadow index size throw new storage error storage error database corrupted bitmap extent base header database format version 2 0 db bitmap pages if is dirty if listener null listener database corrupted system err println database was not normally closed start recovery header root 1 curr size header root curr size header root 1 curr index used header root curr index used header root 1 curr free list header root curr free list header root 1 curr index header root curr shadow index header root 1 curr index size header root curr shadow index size header root 1 curr shadow index header root curr index header root 1 curr shadow index size header root curr index size header root 1 curr bitmap end header root curr bitmap end header root 1 curr root object header root curr root object header root 1 curr class desc list header root curr class desc list header root 1 curr bitmap extent header root curr bitmap extent pg pool put page 0 header pack pg data pool unfix pg pool copy header root 1 curr index header root curr index header root curr index used 8l page page size 1 page page size 1 if listener null listener recovery completed system err println recovery completed curr index size header root 1 curr index used committed index size curr index size used size header root curr size int bitmap size header root 1 curr index bitmap extent 0 db bitmap pages db large bitmap pages bitmap page available space new int bitmap size for i 0 i bitmap page available space length i bitmap page available space i integer max value currr bitmap page currp bitmap page 0 currr bitmap offs currp bitmap offs 0 opened true reload scheme if multiclient support end thread transaction ifile pagepoolsize storageerror storageerror storage_already_opened pagepoolsize multiclientsupport beginthreadtransaction read_write_transaction storageerror storageerror database_corrupted storageerror storageerror database_corrupted transactionid transactionid databaseformatversion indexsize initindexsize indexsize dbfirstuserid indexsize dbfirstuserid indexsize indexsize dbhandlesperpage dbhandlesperpage bitmapextentbase dbbitmappages currindex pagesize indexsize indexsize indexused dbfirstuserid freelist indexsize indexsize indexsize indexused dbfirstuserid freelist indexsize shadowindex shadowindex shadowindexsize indexsize shadowindexsize indexsize bitmappages pagesize dballocationquantum pagesize dballocationquantum bitmapsize bitmappages pagesize usedbitmapsize bitmapsize dballocationquantumbits bitmappages putpage pagesize usedbitmapsize pagesize pagesize usedbitmapsize usedbitmapsize pagesize bitmapindexsize dbbitmapid dbbitmappages pagesize pagesize bitmapindexsize dbinvalidid dbfreehandleflag bitmappages dbbitmapid dbpageobjectflag pagesize bitmapend dbbitmapid bitmapend dbbitmapid dbbitmappages dbbitmapid dbfreehandleflag usedsize committedindexsize currindexsize dbfirstuserid putpage databaseformatversion dbdatabaseformatversion currindex indexsize shadowindexsize storageerror storageerror database_corrupted bitmapextentbase databaseformatversion dbbitmappages isdirty databasecorrupted indexused indexused freelist freelist shadowindex indexsize shadowindexsize shadowindex shadowindexsize indexsize bitmapend bitmapend rootobject rootobject classdesclist classdesclist bitmapextent bitmapextent putpage indexused pagesize pagesize recoverycompleted currindexsize indexused committedindexsize currindexsize usedsize bitmapsize currindex bitmapextent dbbitmappages dblargebitmappages bitmappageavailablespace bitmapsize bitmappageavailablespace bitmappageavailablespace max_value currrbitmappage currpbitmappage currrbitmapoffs currpbitmapoffs reloadscheme multiclientsupport endthreadtransaction public boolean is opened return opened isopened static void check if final class descriptor desc class cls desc cls if cls null for class descriptor next desc next next null next next next next load if cls is assignable from next cls desc has subclasses true else if next cls is assignable from cls next has subclasses true checkiffinal classdescriptor classdescriptor isassignablefrom hassubclasses isassignablefrom hassubclasses void reload scheme class desc map clear custom allocator map null custom allocator list null default allocator new default allocator this int desc list oid header root 1 curr index class desc list class desc map put class descriptor class new class descriptor this class descriptor class class desc map put class descriptor field descriptor class new class descriptor this class descriptor field descriptor class if desc list oid 0 class descriptor desc desc list find class descriptor desc list oid for desc desc list desc null desc desc next desc load for desc desc list desc null desc desc next if find class descriptor desc cls desc desc resolve if desc allocator null if custom allocator map null custom allocator map new hash map custom allocator list new array list desc allocator load custom allocator map put desc cls desc allocator custom allocator list add desc allocator check if final desc else desc list null reloadscheme classdescmap customallocatormap customallocatorlist defaultallocator defaultallocator desclistoid currindex classdesclist classdescmap classdescriptor classdescriptor classdescriptor classdescmap classdescriptor fielddescriptor classdescriptor classdescriptor fielddescriptor desclistoid classdescriptor desclist findclassdescriptor desclistoid desclist desclist findclassdescriptor customallocatormap customallocatormap hashmap customallocatorlist arraylist customallocatormap customallocatorlist checkiffinal desclist final void assign oid i persistent obj int oid obj assign oid this oid false assignoid ipersistent assignoid final void register class descriptor class descriptor desc class desc map put desc cls desc desc next desc list desc list desc check if final desc store object0 desc false header root 1 curr index class desc list desc get oid modified true registerclassdescriptor classdescriptor classdescmap desclist desclist checkiffinal storeobject0 currindex classdesclist getoid final class descriptor find class descriptor class cls return class descriptor class desc map get cls classdescriptor findclassdescriptor classdescriptor classdescmap final class descriptor get class descriptor class cls class descriptor desc find class descriptor cls if desc null desc new class descriptor this cls register class descriptor desc return desc classdescriptor getclassdescriptor classdescriptor findclassdescriptor classdescriptor registerclassdescriptor public synchronized i persistent get root if opened throw new storage error storage error storage not opened int root oid header root 1 curr index root object return root oid 0 null lookup object root oid null ipersistent getroot storageerror storageerror storage_not_opened rootoid currindex rootobject rootoid lookupobject rootoid public synchronized void set root i persistent root if opened throw new storage error storage error storage not opened if root null header root 1 curr index root object 0 else if root is persistent store object0 root false header root 1 curr index root object root get oid modified true setroot ipersistent storageerror storageerror storage_not_opened currindex rootobject ispersistent storeobject0 currindex rootobject getoid public void commit synchronized background gc monitor synchronized this if opened throw new storage error storage error storage not opened object cache flush if custom allocator list null iterator iterator custom allocator list iterator while iterator has next custom allocator alloc custom allocator iterator next if alloc is modified alloc store alloc commit if modified return commit0 modified false backgroundgcmonitor storageerror storageerror storage_not_opened objectcache customallocatorlist customallocatorlist hasnext customallocator customallocator ismodified private final void commit0 int i j n int curr curr index int map dirty pages map int old index size header root curr index size int new index size header root 1 curr index size int n pages committed index size db handles per page bits page pg if new index size old index size clone bitmap header root curr index old index size 8l long new index while true new index allocate new index size 8l 0 if new index size header root 1 curr index size break free new index new index size 8l new index size header root 1 curr index size header root 1 curr shadow index new index header root 1 curr shadow index size new index size free header root curr index old index size 8l long curr size header root 1 curr size for i 0 i n pages i if map i 5 1 i 31 0 page src index pool get page header root 1 curr index long i page page size page dst index pool get page header root curr index long i page page size for j 0 j page page size j 8 long pos bytes unpack8 dst index data j if bytes unpack8 src index data j pos pos curr size if pos db free handle flag 0 if pos db page object flag 0 free pos db flags mask page page size else if pos 0 int offs int pos page page size 1 pg pool get page pos offs free pos object header get size pg data offs pool unfix pg pool unfix src index pool unfix dst index n committed index size db handles per page 1 if n 0 map i 5 1 i 31 0 page src index pool get page header root 1 curr index long i page page size page dst index pool get page header root curr index long i page page size j 0 do long pos bytes unpack8 dst index data j if bytes unpack8 src index data j pos pos curr size if pos db free handle flag 0 if pos db page object flag 0 free pos db flags mask page page size else if pos 0 int offs int pos page page size 1 pg pool get page pos offs free pos object header get size pg data offs pool unfix pg j 8 while n 0 pool unfix src index pool unfix dst index for i 0 i n pages i if map i 5 1 i 31 0 pg pool put page header root 1 curr index long i page page size for j 0 j page page size j 8 bytes pack8 pg data j bytes unpack8 pg data j db modified flag pool unfix pg if curr index size committed index size long page header root 1 curr index committed index size 8l page page size 1 long end header root 1 curr index page page size 1 curr index size 8l page page size 1 while page end pg pool put page page for j 0 j page page size j 8 bytes pack8 pg data j bytes unpack8 pg data j db modified flag pool unfix pg page page page size header root 1 curr used size used size pg pool put page 0 header pack pg data pool flush pool modify pg assert that header transaction id transaction id header transaction id transaction id header curr curr 1 header dirty true header pack pg data pool unfix pg pool flush header root 1 curr size header root curr size header root 1 curr index used curr index size header root 1 curr free list header root curr free list header root 1 curr bitmap end header root curr bitmap end header root 1 curr root object header root curr root object header root 1 curr class desc list header root curr class desc list header root 1 curr bitmap extent header root curr bitmap extent if curr index size 0 new index size old index size header root 1 curr index header root curr shadow index header root 1 curr index size header root curr shadow index size header root 1 curr shadow index header root curr index header root 1 curr shadow index size header root curr index size pool copy header root 1 curr index header root curr index curr index size 8l i curr index size db handles per page 32 1 db handles per page bits 5 while i 0 map i 0 else for i 0 i n pages i if map i 5 1 i 31 0 map i 5 1 i 31 pool copy header root 1 curr index long i page page size header root curr index long i page page size page page size if curr index size i db handles per page map i 5 1 i 31 0 curr index size committed index size pool copy header root 1 curr index long i page page size header root curr index long i page page size 8l curr index size long i page page size j i 5 n curr index size db handles per page 32 1 db handles per page bits 5 while j n map j 0 gc done false curr index curr committed index size curr index size if multiclient support pool flush pg pool put page 0 header dirty false header pack pg data pool unfix pg pool flush currindex dirtypagesmap oldindexsize indexsize newindexsize indexsize npages committedindexsize dbhandlesperpagebits newindexsize oldindexsize clonebitmap oldindexsize newindex newindex newindexsize newindexsize indexsize newindex newindexsize newindexsize indexsize shadowindex newindex shadowindexsize newindexsize oldindexsize currsize npages srcindex getpage pagesize dstindex getpage pagesize pagesize dstindex srcindex currsize dbfreehandleflag dbpageobjectflag dbflagsmask pagesize pagesize getpage objectheader getsize srcindex dstindex committedindexsize dbhandlesperpage srcindex getpage pagesize dstindex getpage pagesize dstindex srcindex currsize dbfreehandleflag dbpageobjectflag dbflagsmask pagesize pagesize getpage objectheader getsize srcindex dstindex npages putpage pagesize pagesize dbmodifiedflag currindexsize committedindexsize committedindexsize pagesize pagesize currindexsize pagesize putpage pagesize dbmodifiedflag pagesize usedsize usedsize putpage transactionid transactionid transactionid transactionid indexused currindexsize freelist freelist bitmapend bitmapend rootobject rootobject classdesclist classdesclist bitmapextent bitmapextent currindexsize newindexsize oldindexsize shadowindex indexsize shadowindexsize shadowindex shadowindexsize indexsize currindexsize currindexsize dbhandlesperpage dbhandlesperpagebits npages pagesize pagesize pagesize currindexsize dbhandlesperpage currindexsize committedindexsize pagesize pagesize currindexsize pagesize currindexsize dbhandlesperpage dbhandlesperpagebits gcdone currindex committedindexsize currindexsize multiclientsupport putpage public synchronized void rollback if opened throw new storage error storage error storage not opened object cache invalidate synchronized object cache if modified return rollback0 modified false storageerror storageerror storage_not_opened objectcache objectcache private final void rollback0 int curr curr index int map dirty pages map if header root 1 curr index header root curr shadow index pool copy header root curr shadow index header root curr index 8l committed index size else int n pages committed index size db handles per page 1 db handles per page bits for int i 0 i n pages i if map i 5 1 i 31 0 pool copy header root curr shadow index long i page page size header root curr index long i page page size page page size for int j curr index size db handles per page 32 1 db handles per page bits 5 j 0 map j 0 header root 1 curr index header root curr shadow index header root 1 curr index size header root curr shadow index size header root 1 curr index used committed index size header root 1 curr free list header root curr free list header root 1 curr bitmap end header root curr bitmap end header root 1 curr size header root curr size header root 1 curr root object header root curr root object header root 1 curr class desc list header root curr class desc list header root 1 curr bitmap extent header root curr bitmap extent used size header root curr size curr index size committed index size currr bitmap page currp bitmap page 0 currr bitmap offs currp bitmap offs 0 reload scheme currindex dirtypagesmap shadowindex shadowindex committedindexsize npages committedindexsize dbhandlesperpage dbhandlesperpagebits npages shadowindex pagesize pagesize pagesize currindexsize dbhandlesperpage dbhandlesperpagebits shadowindex indexsize shadowindexsize indexused committedindexsize freelist freelist bitmapend bitmapend rootobject rootobject classdesclist classdesclist bitmapextent bitmapextent usedsize currindexsize committedindexsize currrbitmappage currpbitmappage currrbitmapoffs currpbitmapoffs reloadscheme public synchronized void backup output stream out throws java io io exception if opened throw new storage error storage error storage not opened object cache flush int curr 1 curr index final int n objects header root curr index used long index offs header root curr index int i j k int n used index pages n objects db handles per page 1 db handles per page int n index pages int header root curr index size db handles per page 1 db handles per page long total records size 0 long n paged objects 0 int bitmap extent header root curr bitmap extent final long index new long n objects final int oids new int n objects if bitmap extent 0 bitmap extent integer max value for i 0 j 0 i n used index pages i page pg pool get page index offs long i page page size for k 0 k db handles per page j n objects k j long pos bytes unpack8 pg data k 8 index j pos oids j j if pos db free handle flag 0 if pos db page object flag 0 n paged objects 1 else if pos 0 int offs int pos page page size 1 page op pool get page pos offs int size object header get size op data offs db flags mask size size db allocation quantum 1 db allocation quantum 1 total records size size pool unfix op pool unfix pg header new header new header new header curr 0 new header dirty false new header database format version header database format version long new file size long n paged objects n index pages 2 1 page page size total records size new file size new file size page page size 1 page page size 1 new header root new root page 2 new header root 0 new root page new header root 1 new root page new header root 0 size new header root 1 size new file size new header root 0 index new header root 1 shadow index page page size new header root 0 shadow index new header root 1 index page page size long n index pages page page size new header root 0 shadow index size new header root 0 index size new header root 1 shadow index size new header root 1 index size n index pages db handles per page new header root 0 index used new header root 1 index used n objects new header root 0 free list new header root 1 free list header root curr free list new header root 0 bitmap end new header root 1 bitmap end header root curr bitmap end new header root 0 root object new header root 1 root object header root curr root object new header root 0 class desc list new header root 1 class desc list header root curr class desc list new header root 0 bitmap extent new header root 1 bitmap extent header root curr bitmap extent byte page new byte page page size new header pack page out write page long page offs long n index pages 2 1 page page size long rec offs long n paged objects n index pages 2 1 page page size generic sort sort new generic sort array public int size return n objects public int compare int i int j return index i index j 1 index i index j 0 1 public void swap int i int j long t1 index i index i index j index j t1 int t2 oids i oids i oids j oids j t2 byte new index new byte n index pages db handles per page 8 for i 0 i n objects i long pos index i int oid oids i if pos db free handle flag 0 if pos db page object flag 0 bytes pack8 new index oid 8 page offs db page object flag page offs page page size else if pos 0 bytes pack8 new index oid 8 rec offs int offs int pos page page size 1 page op pool get page pos offs int size object header get size op data offs db flags mask size size db allocation quantum 1 db allocation quantum 1 rec offs size pool unfix op else bytes pack8 new index oid 8 pos out write new index out write new index for i 0 i n objects i long pos index i if int pos db free handle flag db page object flag db page object flag if oids i db bitmap id db bitmap pages oids i bitmap extent oids i bitmap extent db large bitmap pages db bitmap pages int page id oids i db bitmap id db bitmap pages oids i db bitmap id oids i bitmap extent bitmap extent base long mapped space long page id page page size 8 db allocation quantum if mapped space new file size arrays fill page byte 0 else if mapped space page page size 8 db allocation quantum new file size arrays fill page byte 1 else int n bits int new file size mapped space db allocation quantum bits arrays fill page 0 n bits 3 byte 1 page n bits 3 byte 1 n bits 7 1 arrays fill page n bits 3 1 page page size byte 0 out write page else page pg pool get page pos db flags mask out write pg data pool unfix pg for i 0 i n objects i long pos index i if pos 0 int pos db free handle flag db page object flag 0 pos db flags mask int offs int pos page page size 1 page pg pool get page pos offs int size object header get size pg data offs size size db allocation quantum 1 db allocation quantum 1 while true if page page size offs size out write pg data offs size break out write pg data offs page page size offs size page page size offs pos page page size offs offs 0 pool unfix pg pg pool get page pos pool unfix pg if rec offs new file size assert that new file size rec offs page page size int align int new file size rec offs arrays fill page 0 align byte 0 out write page 0 align outputstream ioexception storageerror storageerror storage_not_opened objectcache currindex nobjects indexused indexoffs nusedindexpages nobjects dbhandlesperpage dbhandlesperpage nindexpages indexsize dbhandlesperpage dbhandlesperpage totalrecordssize npagedobjects bitmapextent bitmapextent nobjects nobjects bitmapextent bitmapextent max_value nusedindexpages getpage indexoffs pagesize dbhandlesperpage nobjects dbfreehandleflag dbpageobjectflag npagedobjects pagesize getpage objectheader getsize dbflagsmask dballocationquantum dballocationquantum totalrecordssize newheader newheader newheader newheader databaseformatversion databaseformatversion newfilesize npagedobjects nindexpages pagesize totalrecordssize newfilesize newfilesize pagesize pagesize newheader rootpage newheader rootpage newheader rootpage newheader newheader newfilesize newheader newheader shadowindex pagesize newheader shadowindex newheader pagesize nindexpages pagesize newheader shadowindexsize newheader indexsize newheader shadowindexsize newheader indexsize nindexpages dbhandlesperpage newheader indexused newheader indexused nobjects newheader freelist newheader freelist freelist newheader bitmapend newheader bitmapend bitmapend newheader rootobject newheader rootobject rootobject newheader classdesclist newheader classdesclist classdesclist newheader bitmapextent newheader bitmapextent bitmapextent pagesize newheader pageoffs nindexpages pagesize recoffs npagedobjects nindexpages pagesize genericsort genericsortarray nobjects newindex nindexpages dbhandlesperpage nobjects dbfreehandleflag dbpageobjectflag newindex pageoffs dbpageobjectflag pageoffs pagesize newindex recoffs pagesize getpage objectheader getsize dbflagsmask dballocationquantum dballocationquantum recoffs newindex newindex newindex nobjects dbfreehandleflag dbpageobjectflag dbpageobjectflag dbbitmapid dbbitmappages bitmapextent bitmapextent dblargebitmappages dbbitmappages pageid dbbitmapid dbbitmappages dbbitmapid bitmapextent bitmapextentbase mappedspace pageid pagesize dballocationquantum mappedspace newfilesize mappedspace pagesize dballocationquantum newfilesize nbits newfilesize mappedspace dballocationquantumbits nbits nbits nbits nbits pagesize getpage dbflagsmask nobjects dbfreehandleflag dbpageobjectflag dbflagsmask pagesize getpage objectheader getsize dballocationquantum dballocationquantum pagesize pagesize pagesize pagesize getpage recoffs newfilesize newfilesize recoffs pagesize newfilesize recoffs long rec offs long n paged objects n index pages 2 1 page page size generic sort sort new generic sort array public int size return n objects recoffs npagedobjects nindexpages pagesize genericsort genericsortarray nobjects return n objects public int compare int i int j return index i index j 1 index i index j 0 1 nobjects public void swap int i int j long t1 index i index i index j index j t1 int t2 oids i oids i oids j oids j t2 public t query t create query return new query impl t this createquery queryimpl public synchronized t extends i persistent i persistent set t create scalable set return create scalable set 8 ipersistent ipersistentset createscalableset createscalableset public synchronized t extends i persistent i persistent set t create scalable set int initial size if opened throw new storage error storage error storage not opened return new scalable set this initial size ipersistent ipersistentset createscalableset initialsize storageerror storageerror storage_not_opened scalableset initialsize public t extends i persistent i persistent list t create list if opened throw new storage error storage error storage not opened return new persistent list impl t this ipersistent ipersistentlist createlist storageerror storageerror storage_not_opened persistentlistimpl public t extends i persistent i persistent list t create scalable list return create scalable list 8 ipersistent ipersistentlist createscalablelist createscalablelist public t extends i persistent i persistent list t create scalable list int initial size if opened throw new storage error storage error storage not opened return new scalable list t this initial size ipersistent ipersistentlist createscalablelist initialsize storageerror storageerror storage_not_opened scalablelist initialsize public k extends comparable v extends i persistent i persistent map k v create map class key type return create map key type 4 ipersistent ipersistentmap createmap keytype createmap keytype public k extends comparable v extends i persistent i persistent map k v create map class key type int initial size if opened throw new storage error storage error storage not opened return new persistent map impl k v this key type initial size ipersistent ipersistentmap createmap keytype initialsize storageerror storageerror storage_not_opened persistentmapimpl keytype initialsize public synchronized t extends i persistent i persistent set t create set if opened throw new storage error storage error storage not opened i persistent set t set alternative btree i persistent set t new alt persistent set t i persistent set t new persistent set t set assign oid this 0 false return set ipersistent ipersistentset createset storageerror storageerror storage_not_opened ipersistentset alternativebtree ipersistentset altpersistentset ipersistentset persistentset assignoid public synchronized t extends i persistent bit index t create bit index if opened throw new storage error storage error storage not opened bit index index new bit index impl t index assign oid this 0 false return index ipersistent bitindex createbitindex storageerror storageerror storage_not_opened bitindex bitindeximpl assignoid public synchronized t extends i persistent index t create index class key type boolean unique if opened throw new storage error storage error storage not opened index t index alternative btree index t new alt btree t key type unique index t new btree t key type unique index assign oid this 0 false return index ipersistent createindex keytype storageerror storageerror storage_not_opened alternativebtree altbtree keytype keytype assignoid public synchronized t extends i persistent index t create index class key types boolean unique if opened throw new storage error storage error storage not opened index t index alternative btree index t new alt btree compound index t key types unique index t new btree compound index t key types unique index assign oid this 0 false return index ipersistent createindex keytypes storageerror storageerror storage_not_opened alternativebtree altbtreecompoundindex keytypes btreecompoundindex keytypes assignoid public synchronized t extends i persistent multidimensional index t create multidimensional index multidimensional comparator t comparator if opened throw new storage error storage error storage not opened return new kd tree t this comparator ipersistent multidimensionalindex createmultidimensionalindex multidimensionalcomparator storageerror storageerror storage_not_opened kdtree public synchronized t extends i persistent multidimensional index t create multidimensional index class type string field names boolean treate zero as undefined value if opened throw new storage error storage error storage not opened return new kd tree t this type field names treate zero as undefined value ipersistent multidimensionalindex createmultidimensionalindex fieldnames treatezeroasundefinedvalue storageerror storageerror storage_not_opened kdtree fieldnames treatezeroasundefinedvalue public synchronized t extends i persistent index t create thick index class key type if opened throw new storage error storage error storage not opened return new thick index t key type this ipersistent createthickindex keytype storageerror storageerror storage_not_opened thickindex keytype public synchronized t extends i persistent spatial index t create spatial index if opened throw new storage error storage error storage not opened return new rtree t ipersistent spatialindex createspatialindex storageerror storageerror storage_not_opened public synchronized t extends i persistent spatial indexr2 t create spatial indexr2 if opened throw new storage error storage error storage not opened return new rtreer2 t this ipersistent spatialindexr2 createspatialindexr2 storageerror storageerror storage_not_opened public t extends i persistent field index t create field index class type string field name boolean unique return this t create field index type field name unique false ipersistent fieldindex createfieldindex fieldname createfieldindex fieldname public synchronized t extends i persistent field index t create field index class type string field name boolean unique boolean case insensitive if opened throw new storage error storage error storage not opened field index t index case insensitive alternative btree field index t new alt btree case insensitive field index t type field name unique field index t new btree case insensitive field index t type field name unique alternative btree field index t new alt btree field index t type field name unique field index t new btree field index t type field name unique index assign oid this 0 false return index ipersistent fieldindex createfieldindex fieldname caseinsensitive storageerror storageerror storage_not_opened fieldindex caseinsensitive alternativebtree fieldindex altbtreecaseinsensitivefieldindex fieldname fieldindex btreecaseinsensitivefieldindex fieldname alternativebtree fieldindex altbtreefieldindex fieldname fieldindex btreefieldindex fieldname assignoid public t extends i persistent field index t create field index class type string field names boolean unique return this t create field index type field names unique false ipersistent fieldindex createfieldindex fieldnames createfieldindex fieldnames public synchronized t extends i persistent field index t create field index class type string field names boolean unique boolean case insensitive if opened throw new storage error storage error storage not opened field index t index case insensitive alternative btree field index t new alt btree case insensitive multi field index type field names unique field index t new btree case insensitive multi field index type field names unique alternative btree field index t new alt btree multi field index type field names unique field index t new btree multi field index type field names unique index assign oid this 0 false return index ipersistent fieldindex createfieldindex fieldnames caseinsensitive storageerror storageerror storage_not_opened fieldindex caseinsensitive alternativebtree fieldindex altbtreecaseinsensitivemultifieldindex fieldnames fieldindex btreecaseinsensitivemultifieldindex fieldnames alternativebtree fieldindex altbtreemultifieldindex fieldnames fieldindex btreemultifieldindex fieldnames assignoid public synchronized t extends i persistent index t create random access index class key type boolean unique if opened throw new storage error storage error storage not opened index t index new rnd btree t key type unique index assign oid this 0 false return index ipersistent createrandomaccessindex keytype storageerror storageerror storage_not_opened rndbtree keytype assignoid public synchronized t extends i persistent index t create random access index class key types boolean unique if opened throw new storage error storage error storage not opened index t index new rnd btree compound index t key types unique index assign oid this 0 false return index ipersistent createrandomaccessindex keytypes storageerror storageerror storage_not_opened rndbtreecompoundindex keytypes assignoid public t extends i persistent field index t create random access field index class type string field name boolean unique return this t create random access field index type field name unique false ipersistent fieldindex createrandomaccessfieldindex fieldname createrandomaccessfieldindex fieldname public synchronized t extends i persistent field index t create random access field index class type string field name boolean unique boolean case insensitive if opened throw new storage error storage error storage not opened field index t index case insensitive field index new rnd btree case insensitive field index t type field name unique field index new rnd btree field index t type field name unique index assign oid this 0 false return index ipersistent fieldindex createrandomaccessfieldindex fieldname caseinsensitive storageerror storageerror storage_not_opened fieldindex caseinsensitive fieldindex rndbtreecaseinsensitivefieldindex fieldname fieldindex rndbtreefieldindex fieldname assignoid public t extends i persistent field index t create random access field index class type string field names boolean unique return this t create random access field index type field names unique false ipersistent fieldindex createrandomaccessfieldindex fieldnames createrandomaccessfieldindex fieldnames public synchronized t extends i persistent field index t create random access field index class type string field names boolean unique boolean case insensitive if opened throw new storage error storage error storage not opened field index t index case insensitive field index new rnd btree case insensitive multi field index type field names unique field index new rnd btree multi field index type field names unique index assign oid this 0 false return index ipersistent fieldindex createrandomaccessfieldindex fieldnames caseinsensitive storageerror storageerror storage_not_opened fieldindex caseinsensitive fieldindex rndbtreecaseinsensitivemultifieldindex fieldnames fieldindex rndbtreemultifieldindex fieldnames assignoid public t extends i persistent sorted collection t create sorted collection persistent comparator t comparator boolean unique if opened throw new storage error storage error storage not opened return new ttree t comparator unique ipersistent sortedcollection createsortedcollection persistentcomparator storageerror storageerror storage_not_opened public t extends i persistent comparable sorted collection t create sorted collection boolean unique if opened throw new storage error storage error storage not opened return new ttree t new default persistent comparator t unique ipersistent sortedcollection createsortedcollection storageerror storageerror storage_not_opened defaultpersistentcomparator public t extends i persistent link t create link return create link 8 ipersistent createlink createlink public t extends i persistent link t create link int initial size return new link impl t initial size ipersistent createlink initialsize linkimpl initialsize public m extends i persistent o extends i persistent relation m o create relation o owner return new relation impl m o owner ipersistent ipersistent createrelation relationimpl public blob create blob return new blob impl this page page size blob impl header size createblob blobimpl pagesize blobimpl headersize public blob create random access blob return new random access blob impl this createrandomaccessblob randomaccessblobimpl public t extends time series tick time series t create time series class block class long max block time interval return new time series impl t this block class max block time interval timeseries timeseries createtimeseries blockclass maxblocktimeinterval timeseriesimpl blockclass maxblocktimeinterval public t extends i persistent patricia trie t create patricia trie return new p trie t ipersistent patriciatrie createpatriciatrie ptrie public full text index create full text index full text search helper helper return new full text index impl this helper fulltextindex createfulltextindex fulltextsearchhelper fulltextindeximpl public full text index create full text index return create full text index new full text search helper this fulltextindex createfulltextindex createfulltextindex fulltextsearchhelper final long getgc pos int oid page pg pool get page header root curr index index long oid db handles per page bits page page size log long pos bytes unpack8 pg data oid db handles per page 1 3 pool unfix pg return pos getgcpos getpage currindex dbhandlesperpagebits pagesizelog dbhandlesperpage final void mark oid int oid if oid 0 long pos getgc pos oid if pos db free handle flag db page object flag 0 throw new storage error storage error invalid oid if pos header root curr index size object was not allocated by custom allocator int bit int pos db allocation quantum bits if black bitmap bit 5 1 bit 31 0 grey bitmap bit 5 1 bit 31 markoid getgcpos dbfreehandleflag dbpageobjectflag storageerror storageerror invalid_oid currindex dballocationquantumbits blackbitmap greybitmap final page getgc page int oid return pool get page getgc pos oid db flags mask getgcpage getpage getgcpos dbflagsmask public void set gc threshold long max allocated delta gc threshold max allocated delta setgcthreshold maxallocateddelta gcthreshold maxallocateddelta private void mark int bitmap size int header root curr index size db allocation quantum bits 5 1 boolean exists not marked objects long pos int i j if listener null listener gc started grey bitmap new int bitmap size black bitmap new int bitmap size int root oid header root curr index root object if root oid 0 mark oid root oid do exists not marked objects false for i 0 i bitmap size i if grey bitmap i 0 exists not marked objects true for j 0 j 32 j if grey bitmap i 1 j 0 pos long i 5 j db allocation quantum bits grey bitmap i 1 j black bitmap i 1 j int offs int pos page page size 1 page pg pool get page pos offs int type oid object header get type pg data offs if type oid 0 class descriptor desc find class descriptor type oid if btree class is assignable from desc cls btree btree new btree pg data object header sizeof offs btree assign oid this 0 false btree mark tree else if desc has references mark object pool get pos object header sizeof desc pool unfix pg while exists not marked objects bitmapsize currindex dballocationquantumbits existsnotmarkedobjects gcstarted greybitmap bitmapsize blackbitmap bitmapsize rootoid currindex rootobject rootoid markoid rootoid existsnotmarkedobjects bitmapsize greybitmap existsnotmarkedobjects greybitmap dballocationquantumbits greybitmap blackbitmap pagesize getpage typeoid objectheader gettype typeoid classdescriptor findclassdescriptor typeoid isassignablefrom objectheader assignoid marktree hasreferences markobject objectheader existsnotmarkedobjects private int sweep int n deallocated 0 long pos gc done true for int i db first user id j committed index size i j i pos getgc pos i if pos 0 int pos db page object flag db free handle flag 0 int bit int pos db allocation quantum bits if black bitmap bit 5 1 bit 31 0 object is not accessible if get pos i pos int offs int pos page page size 1 page pg pool get page pos offs int type oid object header get type pg data offs if type oid 0 class descriptor desc find class descriptor type oid n deallocated 1 if btree class is assignable from desc cls btree btree new btree pg data object header sizeof offs pool unfix pg btree assign oid this i false btree deallocate else int size object header get size pg data offs pool unfix pg free id i object cache remove i clone bitmap pos size if listener null listener deallocate object desc cls i grey bitmap null black bitmap null allocated delta 0 gc active false if listener null listener gc completed n deallocated return n deallocated ndeallocated gcdone dbfirstuserid committedindexsize getgcpos dbpageobjectflag dbfreehandleflag dballocationquantumbits blackbitmap getpos pagesize getpage typeoid objectheader gettype typeoid classdescriptor findclassdescriptor typeoid ndeallocated isassignablefrom objectheader assignoid objectheader getsize freeid objectcache clonebitmap deallocateobject greybitmap blackbitmap allocateddelta gcactive gccompleted ndeallocated ndeallocated private boolean go gc thread start gcthread void activate synchronized background gc start monitor go true background gc start monitor notify backgroundgcstartmonitor backgroundgcstartmonitor public void run try while true synchronized background gc start monitor while go opened background gc start monitor wait if opened return go false synchronized background gc monitor if opened return mark synchronized storage impl this synchronized object cache sweep catch interrupted exception x backgroundgcstartmonitor backgroundgcstartmonitor backgroundgcmonitor storageimpl objectcache interruptedexception public synchronized int gc return gc0 private int gc0 synchronized object cache if opened throw new storage error storage error storage not opened if gc done gc active return 0 gc active true if background gc if gc thread null gc thread new gc thread gc thread activate return 0 system out println start gc allocated delta allocated delta header curr index size header root curr index size gc treshold gc threshold mark return sweep objectcache storageerror storageerror storage_not_opened gcdone gcactive gcactive backgroundgc gcthread gcthread gcthread gcthread allocateddelta allocateddelta currindex currindex gctreshold gcthreshold public synchronized hash map get memory dump synchronized object cache if opened throw new storage error storage error storage not opened int bitmap size int header root curr index size db allocation quantum bits 5 1 boolean exists not marked objects long pos int i j n mark grey bitmap new int bitmap size black bitmap new int bitmap size int root oid header root curr index root object hash map map new hash map if root oid 0 memory usage index usage new memory usage index class memory usage field index usage new memory usage field index class memory usage class usage new memory usage class class mark oid root oid do exists not marked objects false for i 0 i bitmap size i if grey bitmap i 0 exists not marked objects true for j 0 j 32 j if grey bitmap i 1 j 0 pos long i 5 j db allocation quantum bits grey bitmap i 1 j black bitmap i 1 j int offs int pos page page size 1 page pg pool get page pos offs int type oid object header get type pg data offs int obj size object header get size pg data offs int aligned size obj size db allocation quantum 1 db allocation quantum 1 if type oid 0 mark oid type oid class descriptor desc find class descriptor type oid if btree class is assignable from desc cls btree btree new btree pg data object header sizeof offs btree assign oid this 0 false int n pages btree mark tree if field index class is assignable from desc cls field index usage n instances 1 field index usage total size long n pages page page size obj size field index usage allocated size long n pages page page size aligned size else index usage n instances 1 index usage total size long n pages page page size obj size index usage allocated size long n pages page page size aligned size else memory usage usage memory usage map get desc cls if usage null usage new memory usage desc cls map put desc cls usage usage n instances 1 usage total size obj size usage allocated size aligned size if desc has references mark object pool get pos object header sizeof desc else class usage n instances 1 class usage total size obj size class usage allocated size aligned size pool unfix pg while exists not marked objects if index usage n instances 0 map put index class index usage if field index usage n instances 0 map put field index class field index usage if class usage n instances 0 map put class class class usage memory usage system new memory usage storage class system total size header root 0 index size 8l system total size header root 1 index size 8l system total size long header root curr index bitmap end db bitmap id page page size system total size page page size root page if header root curr index bitmap extent 0 system allocated size get bitmap used space db bitmap id db bitmap id db bitmap pages get bitmap used space header root curr index bitmap extent db bitmap pages bitmap extent base header root curr index bitmap extent header root curr index bitmap end db bitmap id bitmap extent base else system allocated size get bitmap used space db bitmap id header root curr index bitmap end system n instances header root curr index index size map put storage class system return map hashmap getmemorydump objectcache storageerror storageerror storage_not_opened bitmapsize currindex dballocationquantumbits existsnotmarkedobjects greybitmap bitmapsize blackbitmap bitmapsize rootoid currindex rootobject hashmap hashmap rootoid memoryusage indexusage memoryusage memoryusage fieldindexusage memoryusage fieldindex memoryusage classusage memoryusage markoid rootoid existsnotmarkedobjects bitmapsize greybitmap existsnotmarkedobjects greybitmap dballocationquantumbits greybitmap blackbitmap pagesize getpage typeoid objectheader gettype objsize objectheader getsize alignedsize objsize dballocationquantum dballocationquantum typeoid markoid typeoid classdescriptor findclassdescriptor typeoid isassignablefrom objectheader assignoid npages marktree fieldindex isassignablefrom fieldindexusage ninstances fieldindexusage totalsize npages pagesize objsize fieldindexusage allocatedsize npages pagesize alignedsize indexusage ninstances indexusage totalsize npages pagesize objsize indexusage allocatedsize npages pagesize alignedsize memoryusage memoryusage memoryusage ninstances totalsize objsize allocatedsize alignedsize hasreferences markobject objectheader classusage ninstances classusage totalsize objsize classusage allocatedsize alignedsize existsnotmarkedobjects indexusage ninstances indexusage fieldindexusage ninstances fieldindex fieldindexusage classusage ninstances classusage memoryusage memoryusage totalsize indexsize totalsize indexsize totalsize currindex bitmapend dbbitmapid pagesize totalsize pagesize currindex bitmapextent allocatedsize getbitmapusedspace dbbitmapid dbbitmapid dbbitmappages getbitmapusedspace currindex bitmapextent dbbitmappages bitmapextentbase currindex bitmapextent currindex bitmapend dbbitmapid bitmapextentbase allocatedsize getbitmapusedspace dbbitmapid currindex bitmapend ninstances currindex indexsize final long get bitmap used space int from int till long allocated 0 while from till page pg getgc page from for int j 0 j page page size j int mask pg data j 0xff while mask 0 if mask 1 0 allocated db allocation quantum mask 1 pool unfix pg from 1 return allocated getbitmapusedspace getgcpage pagesize dballocationquantum final int mark object byte obj int offs class descriptor desc class descriptor field descriptor all desc all fields for int i 0 n all length i n i class descriptor field descriptor fd all i switch fd type case class descriptor tp boolean case class descriptor tp byte offs 1 continue case class descriptor tp char case class descriptor tp short offs 2 continue case class descriptor tp int case class descriptor tp enum case class descriptor tp float offs 4 continue case class descriptor tp long case class descriptor tp double case class descriptor tp date offs 8 continue case class descriptor tp string int strlen bytes unpack4 obj offs offs 4 if strlen 0 offs strlen 2 else if strlen 1 offs strlen 2 continue case class descriptor tp object mark oid bytes unpack4 obj offs offs 4 continue case class descriptor tp value offs mark object obj offs fd value desc continue case class descriptor tp raw int len bytes unpack4 obj offs offs 4 if len 0 offs len else if len 2 class descriptor tp object mark oid bytes unpack4 obj offs offs 4 else if len 1 offs class descriptor sizeof 2 len continue case class descriptor tp custom try byte array input stream in new byte array input stream obj offs obj length offs serializer unpack in offs obj length in available catch io exception x throw new storage error storage error access violation x continue case class descriptor tp array of byte case class descriptor tp array of boolean int len bytes unpack4 obj offs offs 4 if len 0 offs len continue case class descriptor tp array of short case class descriptor tp array of char int len bytes unpack4 obj offs offs 4 if len 0 offs len 2 continue case class descriptor tp array of int case class descriptor tp array of enum case class descriptor tp array of float int len bytes unpack4 obj offs offs 4 if len 0 offs len 4 continue case class descriptor tp array of long case class descriptor tp array of double case class descriptor tp array of date int len bytes unpack4 obj offs offs 4 if len 0 offs len 8 continue case class descriptor tp array of string int len bytes unpack4 obj offs offs 4 while len 0 int strlen bytes unpack4 obj offs offs 4 if strlen 0 offs strlen 2 else if strlen 1 offs strlen 2 continue case class descriptor tp array of object case class descriptor tp link int len bytes unpack4 obj offs offs 4 while len 0 mark oid bytes unpack4 obj offs offs 4 continue case class descriptor tp array of value int len bytes unpack4 obj offs offs 4 class descriptor value desc fd value desc while len 0 offs mark object obj offs value desc continue case class descriptor tp array of raw int len bytes unpack4 obj offs offs 4 while len 0 int rawlen bytes unpack4 obj offs offs 4 if rawlen 0 offs rawlen else if rawlen 2 class descriptor tp object mark oid bytes unpack4 obj offs offs 4 else if rawlen 1 offs class descriptor sizeof 2 rawlen continue continue return offs markobject classdescriptor classdescriptor fielddescriptor allfields classdescriptor fielddescriptor classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tpenum classdescriptor tpfloat classdescriptor tplong classdescriptor tpdouble classdescriptor tpdate classdescriptor tpstring classdescriptor tpobject markoid classdescriptor tpvalue markobject valuedesc classdescriptor tpraw classdescriptor tpobject markoid classdescriptor classdescriptor tpcustom bytearrayinputstream bytearrayinputstream ioexception storageerror storageerror access_violation classdescriptor tparrayofbyte classdescriptor tparrayofboolean classdescriptor tparrayofshort classdescriptor tparrayofchar classdescriptor tparrayofint classdescriptor tparrayofenum classdescriptor tparrayoffloat classdescriptor tparrayoflong classdescriptor tparrayofdouble classdescriptor tparrayofdate classdescriptor tparrayofstring classdescriptor tparrayofobject classdescriptor tplink markoid classdescriptor tparrayofvalue classdescriptor valuedesc valuedesc markobject valuedesc classdescriptor tparrayofraw classdescriptor tpobject markoid classdescriptor this method is used internally by perst to get transaction context associated with current thread but it can be also used by application to get transaction context store it in some variable and use in another thread i will make it possible to share one transaction between multiple threads return transaction context associated with current thread public thread transaction context get transaction context return thread transaction context transaction context get threadtransactioncontext gettransactioncontext threadtransactioncontext transactioncontext associate transaction context with the thread this method can be used by application to share the same transaction between multiple threads param ctx new transaction context return transaction context previously associated with this thread public thread transaction context set transaction context thread transaction context ctx thread transaction context old ctx thread transaction context transaction context get transaction context set ctx return old ctx threadtransactioncontext settransactioncontext threadtransactioncontext threadtransactioncontext oldctx threadtransactioncontext transactioncontext transactioncontext oldctx public void begin thread transaction int mode switch mode case serializable transaction if multiclient support throw new illegal argument exception illegal transaction mode use serializable transactions true get transaction context nested 1 break case exclusive transaction case cooperative transaction if multiclient support if mode exclusive transaction transaction lock exclusive lock else transaction lock shared lock synchronized transaction monitor if n nested transactions 0 file lock mode read only transaction byte buf new byte header sizeof int rc file read 0 buf if rc 0 rc header sizeof throw new storage error storage error database corrupted header unpack buf int curr header curr curr index curr curr index size header root 1 curr index used committed index size curr index size used size header root curr size if header transaction id transaction id if bitmap page available space null for int i 0 i bitmap page available space length i bitmap page available space i integer max value object cache clear pool clear transaction id header transaction id else synchronized transaction monitor if scheduled commit time long max value n blocked transactions 1 while system current time millis scheduled commit time try transaction monitor wait catch interrupted exception x n blocked transactions 1 n nested transactions 1 if mode exclusive transaction transaction lock exclusive lock else transaction lock shared lock break default throw new illegal argument exception illegal transaction mode beginthreadtransaction serializable_transaction multiclientsupport illegalargumentexception useserializabletransactions gettransactioncontext exclusive_transaction cooperative_transaction multiclientsupport exclusive_transaction transactionlock exclusivelock transactionlock sharedlock transactionmonitor nnestedtransactions read_only_transaction storageerror storageerror database_corrupted currindex currindexsize indexused committedindexsize currindexsize usedsize transactionid transactionid bitmappageavailablespace bitmappageavailablespace bitmappageavailablespace max_value objectcache transactionid transactionid transactionmonitor scheduledcommittime max_value nblockedtransactions currenttimemillis scheduledcommittime transactionmonitor interruptedexception nblockedtransactions nnestedtransactions exclusive_transaction transactionlock exclusivelock transactionlock sharedlock illegalargumentexception public void end thread transaction end thread transaction integer max value endthreadtransaction endthreadtransaction max_value public void end thread transaction int max delay if multiclient support if max delay integer max value throw new illegal argument exception delay is not supported for global transactions synchronized transaction monitor transaction lock unlock if n nested transactions 0 may be everything is already aborted if n nested transactions 0 commit pool flush file unlock return thread transaction context ctx get transaction context if ctx nested 0 serializable transaction if ctx nested 0 array list modified ctx modified array list deleted ctx deleted map locked ctx locked synchronized background gc monitor synchronized this synchronized object cache for int i modified size i 0 i persistent modified get i store for int i deleted size i 0 deallocate object0 i persistent deleted get i if modified size deleted size 0 commit0 iterator iterator locked values iterator while iterator has next i resource iterator next reset modified clear deleted clear locked clear else exclusive or cooperative transaction synchronized transaction monitor transaction lock unlock if n nested transactions 0 may be everything is already aborted if n nested transactions 0 n committed transactions 1 commit scheduled commit time long max value if n blocked transactions 0 transaction monitor notify all else if max delay integer max value long next commit system current time millis max delay if next commit scheduled commit time scheduled commit time next commit if max delay 0 int n n committed transactions n blocked transactions 1 do try transaction monitor wait catch interrupted exception x while n committed transactions n n blocked transactions 1 endthreadtransaction maxdelay multiclientsupport maxdelay max_value illegalargumentexception transactionmonitor transactionlock nnestedtransactions nnestedtransactions threadtransactioncontext gettransactioncontext arraylist arraylist backgroundgcmonitor objectcache ipersistent deallocateobject0 ipersistent hasnext iresource transactionmonitor transactionlock nnestedtransactions nnestedtransactions ncommittedtransactions scheduledcommittime max_value nblockedtransactions transactionmonitor notifyall maxdelay max_value nextcommit currenttimemillis maxdelay nextcommit scheduledcommittime scheduledcommittime nextcommit maxdelay ncommittedtransactions nblockedtransactions transactionmonitor interruptedexception ncommittedtransactions nblockedtransactions public void rollback thread transaction if multiclient support synchronized transaction monitor transaction lock reset n nested transactions 0 rollback file unlock return thread transaction context ctx get transaction context if ctx nested 0 serializable transaction array list modified ctx modified map locked ctx locked synchronized this synchronized object cache int i modified size while i 0 i persistent obj i persistent modified get i int oid obj get oid if get pos oid 0 free id oid obj invalidate object cache clear dirty obj iterator iterator locked values iterator while iterator has next i resource iterator next reset ctx nested 0 modified clear ctx deleted clear locked clear else synchronized transaction monitor transaction lock reset n nested transactions 0 if n blocked transactions 0 transaction monitor notify all rollback rollbackthreadtransaction multiclientsupport transactionmonitor transactionlock nnestedtransactions threadtransactioncontext gettransactioncontext arraylist objectcache ipersistent ipersistent getoid getpos freeid objectcache cleardirty hasnext iresource transactionmonitor transactionlock nnestedtransactions nblockedtransactions transactionmonitor notifyall public protected boolean lock object i persistent obj if use serializable transactions thread transaction context ctx get transaction context if ctx nested 0 serializable transaction return ctx locked put obj obj null return true lockobject ipersistent useserializabletransactions threadtransactioncontext gettransactioncontext public void close synchronized background gc monitor commit opened false if gc thread null gc thread activate try gc thread join catch interrupted exception x if is dirty page pg pool put page 0 header pack pg data pool flush pool modify pg header dirty false header pack pg data pool unfix pg pool flush pool close make gc easier pool null object cache null class desc map null bitmap page available space null dirty pages map null desc list null backgroundgcmonitor gcthread gcthread gcthread interruptedexception isdirty putpage objectcache classdescmap bitmappageavailablespace dirtypagesmap desclist public synchronized void exportxml java io writer writer throws java io io exception if opened throw new storage error storage error storage not opened object cache flush int root oid header root 1 curr index root object if root oid 0 xml exporter xml exporter new xml exporter this writer xml exporter export database root oid ioexception storageerror storageerror storage_not_opened objectcache rootoid currindex rootobject rootoid xmlexporter xmlexporter xmlexporter xmlexporter exportdatabase rootoid public synchronized void importxml java io reader reader throws xml import exception if opened throw new storage error storage error storage not opened xml importer xml importer new xml importer this reader xml importer import database xmlimportexception storageerror storageerror storage_not_opened xmlimporter xmlimporter xmlimporter xmlimporter importdatabase private boolean get boolean value object value if value instanceof boolean return boolean value boolean value else if value instanceof string string s string value if true equals ignore case s t equals ignore case s 1 equals s return true else if false equals ignore case s f equals ignore case s 0 equals s return false throw new storage error storage error bad property value getbooleanvalue booleanvalue equalsignorecase equalsignorecase equalsignorecase equalsignorecase storageerror storageerror bad_property_value private long get integer value object value if value instanceof number return number value long value else if value instanceof string try return long parse long string value 10 catch number format exception x throw new storage error storage error bad property value getintegervalue longvalue parselong numberformatexception storageerror storageerror bad_property_value public void set properties properties props string value properties put all props if value props get property perst implicit values null class descriptor treate any non persistent object as value get boolean value value if value props get property perst serialize transient objects null class descriptor serialize non persistent objects get boolean value value if value props get property perst object cache init size null object cache init size int get integer value value if object cache init size 0 throw new illegal argument exception initial object cache size should be positive if value props get property perst object cache kind null cache kind value if value props get property perst object index init size null init index size int get integer value value if value props get property perst extension quantum null extension quantum get integer value value if value props get property perst gc threshold null gc threshold get integer value value if value props get property perst file readonly null read only get boolean value value if value props get property perst file noflush null no flush get boolean value value if value props get property perst alternative btree null alternative btree get boolean value value if value props get property perst background gc null background gc get boolean value value if value props get property perst string encoding null encoding value if value props get property perst lock file null lock file get boolean value value if value props get property perst replication ack null replication ack get boolean value value if value props get property perst concurrent iterator null concurrent iterator get boolean value value if value props get property perst slave connection timeout null slave connection timeout int get integer value value if value props get property perst force store null force store get boolean value value if value props get property perst page pool lru limit null page pool lru limit get integer value value if value props get property perst multiclient support null multiclient support get boolean value value if multiclient support background gc throw new illegal argument exception in mutliclient access mode bachround gc is not supported setproperties putall getproperty classdescriptor treateanynonpersistentobjectasvalue getbooleanvalue getproperty classdescriptor serializenonpersistentobjects getbooleanvalue getproperty objectcacheinitsize getintegervalue objectcacheinitsize illegalargumentexception getproperty cachekind getproperty initindexsize getintegervalue getproperty extensionquantum getintegervalue getproperty gcthreshold getintegervalue getproperty readonly getbooleanvalue getproperty noflush getbooleanvalue getproperty alternativebtree getbooleanvalue getproperty backgroundgc getbooleanvalue getproperty getproperty lockfile getbooleanvalue getproperty replicationack getbooleanvalue getproperty concurrentiterator getbooleanvalue getproperty slaveconnectiontimeout getintegervalue getproperty forcestore getbooleanvalue getproperty pagepoollrulimit getintegervalue getproperty multiclientsupport getbooleanvalue multiclientsupport backgroundgc illegalargumentexception public void set property string name object value properties put name value if name equals perst implicit values class descriptor treate any non persistent object as value get boolean value value else if name equals perst serialize transient objects class descriptor serialize non persistent objects get boolean value value else if name equals perst object cache init size object cache init size int get integer value value if object cache init size 0 throw new illegal argument exception initial object cache size should be positive else if name equals perst object cache kind cache kind string value else if name equals perst object index init size init index size int get integer value value else if name equals perst extension quantum extension quantum get integer value value else if name equals perst gc threshold gc threshold get integer value value else if name equals perst file readonly read only get boolean value value else if name equals perst file noflush no flush get boolean value value else if name equals perst alternative btree alternative btree get boolean value value else if name equals perst background gc background gc get boolean value value else if name equals perst string encoding encoding value null null value to string else if name equals perst lock file lock file get boolean value value else if name equals perst replication ack replication ack get boolean value value else if name equals perst concurrent iterator concurrent iterator get boolean value value else if name equals perst slave connection timeout slave connection timeout int get integer value value else if name equals perst force store force store get boolean value value else if name equals perst page pool lru limit page pool lru limit get integer value value else if name equals perst multiclient support multiclient support get boolean value value else throw new storage error storage error no such property if multiclient support background gc throw new illegal argument exception in mutliclient access mode bachround gc is not supported setproperty classdescriptor treateanynonpersistentobjectasvalue getbooleanvalue classdescriptor serializenonpersistentobjects getbooleanvalue objectcacheinitsize getintegervalue objectcacheinitsize illegalargumentexception cachekind initindexsize getintegervalue extensionquantum getintegervalue gcthreshold getintegervalue readonly getbooleanvalue noflush getbooleanvalue alternativebtree getbooleanvalue backgroundgc getbooleanvalue tostring lockfile getbooleanvalue replicationack getbooleanvalue concurrentiterator getbooleanvalue slaveconnectiontimeout getintegervalue forcestore getbooleanvalue pagepoollrulimit getintegervalue multiclientsupport getbooleanvalue storageerror storageerror no_such_property multiclientsupport backgroundgc illegalargumentexception public object get property string name return properties get name getproperty public properties get properties return properties getproperties public storage listener set listener storage listener listener storage listener prev listener this listener this listener listener return prev listener storagelistener setlistener storagelistener storagelistener prevlistener prevlistener public synchronized i persistent get object byoid int oid return oid 0 null lookup object oid null ipersistent getobjectbyoid lookupobject public protected synchronized void modify object i persistent obj synchronized object cache if obj is modified if use serializable transactions thread transaction context ctx get transaction context if ctx nested 0 serializable transaction ctx modified add obj return object cache set dirty obj modifyobject ipersistent objectcache ismodified useserializabletransactions threadtransactioncontext gettransactioncontext objectcache setdirty public protected synchronized void store object i persistent obj if opened throw new storage error storage error storage not opened synchronized object cache store object0 obj false storeobject ipersistent storageerror storageerror storage_not_opened objectcache storeobject0 public protected void store finalized object i persistent obj if opened synchronized object cache if obj get oid 0 store object0 obj true storefinalizedobject ipersistent objectcache getoid storeobject0 public synchronized int make persistent i persistent obj if opened throw new storage error storage error storage not opened if obj null return 0 int oid obj get oid if oid 0 return oid if force store use serializable transactions get transaction context nested 0 synchronized object cache store object0 obj false return obj get oid else synchronized object cache oid allocate id obj assign oid this oid false set pos oid 0 object cache put oid obj obj modify return oid makepersistent ipersistent storageerror storageerror storage_not_opened getoid forcestore useserializabletransactions gettransactioncontext objectcache storeobject0 getoid objectcache allocateid assignoid setpos objectcache private final custom allocator get custom allocator class cls object a custom allocator map get cls if a null return a default allocator null custom allocator a class superclass cls get superclass if superclass null custom allocator alloc get custom allocator superclass if alloc null custom allocator map put cls alloc return alloc class interfaces cls get interfaces for int i 0 i interfaces length i custom allocator alloc get custom allocator interfaces i if alloc null custom allocator map put cls alloc return alloc custom allocator map put cls default allocator return null customallocator getcustomallocator customallocatormap defaultallocator customallocator getsuperclass customallocator getcustomallocator customallocatormap getinterfaces customallocator getcustomallocator customallocatormap customallocatormap defaultallocator private final void store object0 i persistent obj boolean finalized obj on store int oid obj get oid boolean new object false if oid 0 oid allocate id if finalized object cache put oid obj obj assign oid this oid false new object true else if obj is modified object cache clear dirty obj byte data pack object obj finalized long pos int new size object header get size data 0 custom allocator allocator custom allocator map null get custom allocator obj get class null if new object pos get pos oid 0 pos allocator null allocator allocate new size allocate new size 0 set pos oid pos db modified flag else int offs int pos page page size 1 if offs db free handle flag db page object flag 0 throw new storage error storage error deleted object page pg pool get page pos offs int size object header get size pg data offs db flags mask pool unfix pg if pos db modified flag 0 if allocator null allocator free pos db flags mask size pos allocator allocate new size else clone bitmap pos db flags mask size pos allocate new size 0 set pos oid pos db modified flag else pos db flags mask if new size size if allocator null long new pos allocator reallocate pos size new size if new pos pos pos new pos set pos oid pos db modified flag else if new size size object header set size data 0 size else if new size db allocation quantum 1 db allocation quantum 1 size db allocation quantum 1 db allocation quantum 1 long new pos allocate new size 0 clone bitmap pos size free pos size pos new pos set pos oid pos db modified flag else if new size size object header set size data 0 size modified true pool put pos data new size storeobject0 ipersistent onstore getoid newobject allocateid objectcache assignoid newobject ismodified objectcache cleardirty packobject newsize objectheader getsize customallocator customallocatormap getcustomallocator getclass newobject getpos newsize newsize setpos dbmodifiedflag pagesize dbfreehandleflag dbpageobjectflag storageerror storageerror deleted_object getpage objectheader getsize dbflagsmask dbmodifiedflag dbflagsmask newsize clonebitmap dbflagsmask newsize setpos dbmodifiedflag dbflagsmask newsize newpos newsize newpos newpos setpos dbmodifiedflag newsize objectheader setsize newsize dballocationquantum dballocationquantum dballocationquantum dballocationquantum newpos newsize clonebitmap newpos setpos dbmodifiedflag newsize objectheader setsize newsize public protected synchronized void load object i persistent obj if obj is raw load stub obj get oid obj obj get class loadobject ipersistent israw loadstub getoid getclass final synchronized i persistent lookup object int oid class cls i persistent obj object cache get oid if obj null obj is raw obj load stub oid obj cls return obj ipersistent lookupobject ipersistent objectcache israw loadstub protected int swizzle i persistent obj boolean finalized int oid 0 if obj null if obj is persistent store object0 obj finalized oid obj get oid return oid ipersistent ispersistent storeobject0 getoid final class descriptor find class descriptor int oid return class descriptor lookup object oid class descriptor class classdescriptor findclassdescriptor classdescriptor lookupobject classdescriptor protected i persistent unswizzle int oid class cls boolean recursive loading if oid 0 return null if recursive loading return lookup object oid cls i persistent stub object cache get oid if stub null return stub class descriptor desc if cls persistent class desc find class descriptor cls null desc has subclasses long pos get pos oid int offs int pos page page size 1 if offs db free handle flag db page object flag 0 throw new storage error storage error deleted object page pg pool get page pos offs int type oid object header get type pg data offs db flags mask pool unfix pg desc find class descriptor type oid stub i persistent desc new instance stub assign oid this oid true object cache put oid stub return stub ipersistent recursiveloading recursiveloading lookupobject ipersistent objectcache classdescriptor findclassdescriptor hassubclasses getpos pagesize dbfreehandleflag dbpageobjectflag storageerror storageerror deleted_object getpage typeoid objectheader gettype dbflagsmask findclassdescriptor typeoid ipersistent newinstance assignoid objectcache final i persistent load stub int oid i persistent obj class cls long pos get pos oid if pos db free handle flag db page object flag 0 throw new storage error storage error deleted object byte body pool get pos db flags mask class descriptor desc int type oid object header get type body 0 if type oid 0 desc find class descriptor cls else desc find class descriptor type oid if obj null obj i persistent desc new instance object cache put oid obj obj assign oid this oid false if obj instanceof fast serializable fast serializable obj unpack body object header sizeof encoding else try unpack object obj desc obj recursive loading body object header sizeof obj catch exception x throw new storage error storage error access violation x obj on load return obj ipersistent loadstub ipersistent getpos dbfreehandleflag dbpageobjectflag storageerror storageerror deleted_object dbflagsmask classdescriptor typeoid objectheader gettype typeoid findclassdescriptor findclassdescriptor typeoid ipersistent newinstance objectcache assignoid fastserializable fastserializable objectheader unpackobject recursiveloading objectheader storageerror storageerror access_violation onload class persistent object input stream extends object input stream persistent object input stream input stream in throws io exception super in enable resolve object true persistentobjectinputstream objectinputstream persistentobjectinputstream inputstream ioexception enableresolveobject protected object resolve object object obj throws io exception if obj instanceof i persistent int oid i persistent obj get oid if oid 0 return lookup object oid obj get class return obj resolveobject ioexception ipersistent ipersistent getoid lookupobject getclass protected class resolve class object stream class desc throws io exception class not found exception string class loader name null if loader map null class loader name string read object class loader cl class loader name null find class loader class loader name loader if cl null try return class for name desc get name false cl catch class not found exception x return super resolve class desc resolveclass objectstreamclass ioexception classnotfoundexception classloadername loadermap classloadername readobject classloader classloadername findclassloader classloadername forname getname classnotfoundexception resolveclass public class persistent object output stream extends object output stream persistent object output stream output stream out throws io exception super out persistentobjectoutputstream objectoutputstream persistentobjectoutputstream outputstream ioexception public storage get storage return storage impl this getstorage storageimpl public class annotated persistent object output stream extends persistent object output stream annotated persistent object output stream output stream out throws io exception super out annotatedpersistentobjectoutputstream persistentobjectoutputstream annotatedpersistentobjectoutputstream outputstream ioexception protected void annotate class class cls throws io exception class loader loader cls get class loader write object loader instanceof i named class loader i named class loader loader get name null annotateclass ioexception classloader getclassloader writeobject inamedclassloader inamedclassloader getname final int unpack object object obj class descriptor desc boolean recursive loading byte body int offs i persistent po throws exception class descriptor field descriptor all desc all fields reflection provider provider class descriptor get reflection provider int len for int i 0 n all length i n i class descriptor field descriptor fd all i field f fd field if f null obj null switch fd type case class descriptor tp boolean case class descriptor tp byte offs 1 continue case class descriptor tp char case class descriptor tp short offs 2 continue case class descriptor tp int case class descriptor tp float case class descriptor tp object case class descriptor tp enum offs 4 continue case class descriptor tp long case class descriptor tp double case class descriptor tp date offs 8 continue case class descriptor tp string len bytes unpack4 body offs offs 4 if len 0 offs len 2 else if len 1 offs len 2 continue case class descriptor tp value offs unpack object null fd value desc recursive loading body offs po continue case class descriptor tp raw case class descriptor tp array of byte case class descriptor tp array of boolean len bytes unpack4 body offs offs 4 if len 0 offs len else if len 1 offs class descriptor sizeof 2 len continue case class descriptor tp custom byte array input stream in new byte array input stream body offs body length offs serializer unpack in offs body length in available continue case class descriptor tp array of short case class descriptor tp array of char len bytes unpack4 body offs offs 4 if len 0 offs len 2 continue case class descriptor tp array of int case class descriptor tp array of enum case class descriptor tp array of float case class descriptor tp array of object case class descriptor tp link len bytes unpack4 body offs offs 4 if len 0 offs len 4 continue case class descriptor tp array of long case class descriptor tp array of double case class descriptor tp array of date len bytes unpack4 body offs offs 4 if len 0 offs len 8 continue case class descriptor tp array of string len bytes unpack4 body offs offs 4 if len 0 for int j 0 j len j int strlen bytes unpack4 body offs offs 4 if strlen 0 offs strlen 2 else if strlen 1 offs strlen 2 continue case class descriptor tp array of value len bytes unpack4 body offs offs 4 if len 0 class descriptor value desc fd value desc for int j 0 j len j offs unpack object null value desc recursive loading body offs po continue case class descriptor tp array of raw len bytes unpack4 body offs offs 4 if len 0 for int j 0 j len j int rawlen bytes unpack4 body offs offs 4 if rawlen 0 offs rawlen else if rawlen 1 offs class descriptor sizeof 2 rawlen continue else if offs body length switch fd type case class descriptor tp boolean provider set boolean f obj body offs 0 continue case class descriptor tp byte provider set byte f obj body offs continue case class descriptor tp char provider set char f obj char bytes unpack2 body offs offs 2 continue case class descriptor tp short provider set short f obj bytes unpack2 body offs offs 2 continue case class descriptor tp int provider set int f obj bytes unpack4 body offs offs 4 continue case class descriptor tp long provider set long f obj bytes unpack8 body offs offs 8 continue case class descriptor tp float provider set float f obj float int bits to float bytes unpack4 body offs offs 4 continue case class descriptor tp double provider set double f obj double long bits to double bytes unpack8 body offs offs 8 continue case class descriptor tp enum int index bytes unpack4 body offs if index 0 provider set f obj fd field get type get enum constants index else provider set f obj null offs 4 continue case class descriptor tp string len bytes unpack4 body offs offs 4 string str null if len 0 char chars new char len for int j 0 j len j chars j char bytes unpack2 body offs offs 2 str new string chars else if len 1 if encoding null str new string body offs 2 len encoding else str new string body offs 2 len offs 2 len provider set f obj str continue case class descriptor tp date long msec bytes unpack8 body offs offs 8 date date null if msec 0 date new date msec provider set f obj date continue case class descriptor tp object provider set f obj unswizzle bytes unpack4 body offs f get type recursive loading offs 4 continue case class descriptor tp value object value fd value desc new instance offs unpack object value fd value desc recursive loading body offs po provider set f obj value continue case class descriptor tp raw len bytes unpack4 body offs offs 4 if len 0 byte array input stream bin new byte array input stream body offs len object input stream in new persistent object input stream bin provider set f obj in read object in close offs len else if len 0 object unpackobject classdescriptor recursiveloading ipersistent classdescriptor fielddescriptor allfields reflectionprovider classdescriptor getreflectionprovider classdescriptor fielddescriptor classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tpfloat classdescriptor tpobject classdescriptor tpenum classdescriptor tplong classdescriptor tpdouble classdescriptor tpdate classdescriptor tpstring classdescriptor tpvalue unpackobject valuedesc recursiveloading classdescriptor tpraw classdescriptor tparrayofbyte classdescriptor tparrayofboolean classdescriptor classdescriptor tpcustom bytearrayinputstream bytearrayinputstream classdescriptor tparrayofshort classdescriptor tparrayofchar classdescriptor tparrayofint classdescriptor tparrayofenum classdescriptor tparrayoffloat classdescriptor tparrayofobject classdescriptor tplink classdescriptor tparrayoflong classdescriptor tparrayofdouble classdescriptor tparrayofdate classdescriptor tparrayofstring classdescriptor tparrayofvalue classdescriptor valuedesc valuedesc unpackobject valuedesc recursiveloading classdescriptor tparrayofraw classdescriptor classdescriptor tpboolean setboolean classdescriptor tpbyte setbyte classdescriptor tpchar setchar classdescriptor tpshort setshort classdescriptor tpint setint classdescriptor tplong setlong classdescriptor tpfloat setfloat intbitstofloat classdescriptor tpdouble setdouble longbitstodouble classdescriptor tpenum gettype getenumconstants classdescriptor tpstring classdescriptor tpdate classdescriptor tpobject gettype recursiveloading classdescriptor tpvalue valuedesc newinstance unpackobject valuedesc recursiveloading classdescriptor tpraw bytearrayinputstream bytearrayinputstream objectinputstream persistentobjectinputstream readobject final byte pack object i persistent obj boolean finalized byte buffer buf new byte buffer int offs object header sizeof buf extend offs class descriptor desc get class descriptor obj get class if obj instanceof fast serializable offs fast serializable obj pack buf offs encoding else try offs pack object obj desc offs buf obj finalized catch exception x throw new storage error storage error access violation x object header set size buf arr 0 offs object header set type buf arr 0 desc get oid return buf arr packobject ipersistent bytebuffer bytebuffer objectheader classdescriptor getclassdescriptor getclass fastserializable fastserializable packobject storageerror storageerror access_violation objectheader setsize objectheader settype getoid final int pack value object value int offs byte buffer buf boolean finalized throws exception if value null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else if value instanceof i persistent buf extend offs 8 bytes pack4 buf arr offs 2 class descriptor tp object bytes pack4 buf arr offs 4 swizzle i persistent value finalized offs 8 else class c value get class if c boolean class buf extend offs 5 bytes pack4 buf arr offs 2 class descriptor tp boolean buf arr offs 4 byte boolean value boolean value 1 0 offs 5 else if c character class buf extend offs 6 bytes pack4 buf arr offs 2 class descriptor tp char bytes pack2 buf arr offs 4 short character value char value offs 6 else if c byte class buf extend offs 5 bytes pack4 buf arr offs 2 class descriptor tp byte buf arr offs 4 byte value byte value offs 5 else if c short class buf extend offs 6 bytes pack4 buf arr offs 2 class descriptor tp short bytes pack2 buf arr offs 4 short value short value offs 6 else if c integer class buf extend offs 8 bytes pack4 buf arr offs 2 class descriptor tp int bytes pack4 buf arr offs 4 integer value int value offs 8 else if c long class buf extend offs 12 bytes pack4 buf arr offs 2 class descriptor tp long bytes pack8 buf arr offs 4 long value long value offs 12 else if c float class buf extend offs 8 bytes pack4 buf arr offs 2 class descriptor tp float bytes pack4 buf arr offs 4 float float to int bits float value float value offs 8 else if c double class buf extend offs 12 bytes pack4 buf arr offs 2 class descriptor tp double bytes pack8 buf arr offs 4 double double to long bits double value double value offs 12 else if c date class buf extend offs 12 bytes pack4 buf arr offs 2 class descriptor tp date bytes pack8 buf arr offs 4 date value get time offs 12 else byte array output stream bout new byte array output stream object output stream out loader map null object output stream new annotated persistent object output stream bout object output stream new persistent object output stream bout out write object value out close byte arr bout to byte array int len arr length buf extend offs 4 len bytes pack4 buf arr offs len offs 4 system arraycopy arr 0 buf arr offs len offs len return offs packvalue bytebuffer ipersistent classdescriptor tpobject ipersistent getclass classdescriptor tpboolean booleanvalue classdescriptor tpchar charvalue classdescriptor tpbyte bytevalue classdescriptor tpshort shortvalue classdescriptor tpint intvalue classdescriptor tplong longvalue classdescriptor tpfloat floattointbits floatvalue classdescriptor tpdouble doubletolongbits doublevalue classdescriptor tpdate gettime bytearrayoutputstream bytearrayoutputstream objectoutputstream loadermap objectoutputstream annotatedpersistentobjectoutputstream objectoutputstream persistentobjectoutputstream writeobject tobytearray final int pack object object obj class descriptor desc int offs byte buffer buf i persistent po boolean finalized throws exception class descriptor field descriptor flds desc all fields for int i 0 n flds length i n i class descriptor field descriptor fd flds i field f fd field switch fd type case class descriptor tp byte buf extend offs 1 buf arr offs f get byte obj continue case class descriptor tp boolean buf extend offs 1 buf arr offs byte f get boolean obj 1 0 continue case class descriptor tp short buf extend offs 2 bytes pack2 buf arr offs f get short obj offs 2 continue case class descriptor tp char buf extend offs 2 bytes pack2 buf arr offs short f get char obj offs 2 continue case class descriptor tp int buf extend offs 4 bytes pack4 buf arr offs f get int obj offs 4 continue case class descriptor tp long buf extend offs 8 bytes pack8 buf arr offs f get long obj offs 8 continue case class descriptor tp float buf extend offs 4 bytes pack4 buf arr offs float float to int bits f get float obj offs 4 continue case class descriptor tp double buf extend offs 8 bytes pack8 buf arr offs double double to long bits f get double obj offs 8 continue case class descriptor tp enum enum e enum f get obj buf extend offs 4 if e null bytes pack4 buf arr offs 1 else bytes pack4 buf arr offs e ordinal offs 4 continue case class descriptor tp date buf extend offs 8 date d date f get obj long msec d null 1 d get time bytes pack8 buf arr offs msec offs 8 continue case class descriptor tp string offs buf pack string offs string f get obj encoding continue case class descriptor tp object buf extend offs 4 bytes pack4 buf arr offs swizzle i persistent f get obj finalized offs 4 continue case class descriptor tp value object value f get obj if value null throw new storage error storage error null value fd field name else if value instanceof i persistent throw new storage error storage error serialize persistent offs pack object value fd value desc offs buf po finalized continue case class descriptor tp raw offs pack value f get obj offs buf finalized continue case class descriptor tp custom serializer pack custom serializable f get obj buf get output stream offs buf size continue case class descriptor tp array of byte byte arr byte f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len bytes pack4 buf arr offs len offs 4 system arraycopy arr 0 buf arr offs len offs len continue case class descriptor tp array of boolean boolean arr boolean f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len bytes pack4 buf arr offs len offs 4 for int j 0 j len j offs buf arr offs byte arr j 1 0 continue case class descriptor tp array of short short arr short f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 2 bytes pack4 buf arr offs len offs 4 for int j 0 j len j bytes pack2 buf arr offs arr j offs 2 continue case class descriptor tp array of char char arr char f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 2 bytes pack4 buf arr offs len offs 4 for int j 0 j len j bytes pack2 buf arr offs short arr j offs 2 continue case class descriptor tp array of int int arr int f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 4 bytes pack4 buf arr offs len offs 4 for int j 0 j len j bytes pack4 buf arr offs arr j offs 4 continue case class descriptor tp array of enum enum arr enum f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 4 bytes pack4 buf arr offs len offs 4 for int j 0 j len j if arr j null bytes pack4 buf arr offs 1 else bytes pack4 buf arr offs arr j ordinal offs 4 continue case class descriptor tp array of long long arr long f get obj if arr null buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else int len arr length buf extend offs 4 len 8 bytes pack4 buf arr offs len offs 4 for int j 0 j len j bytes pack8 buf arr offs arr j offs 8 continue case class descriptor packobject classdescriptor bytebuffer ipersistent classdescriptor fielddescriptor allfields classdescriptor fielddescriptor classdescriptor tpbyte getbyte classdescriptor tpboolean getboolean classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tplong getlong classdescriptor tpfloat floattointbits getfloat classdescriptor tpdouble doubletolongbits getdouble classdescriptor tpenum classdescriptor tpdate gettime classdescriptor tpstring packstring classdescriptor tpobject ipersistent classdescriptor tpvalue storageerror storageerror null_value fieldname ipersistent storageerror storageerror serialize_persistent packobject valuedesc classdescriptor tpraw packvalue classdescriptor tpcustom customserializable getoutputstream classdescriptor tparrayofbyte classdescriptor tparrayofboolean classdescriptor tparrayofshort classdescriptor tparrayofchar classdescriptor tparrayofint classdescriptor tparrayofenum classdescriptor tparrayoflong classdescriptor public class loader set class loader class loader loader class loader prev loader this loader loader return prev classloader setclassloader classloader classloader public class loader get class loader return loader classloader getclassloader public void register class loader i named class loader loader if loader map null loader map new hash map loader map put loader get name loader registerclassloader inamedclassloader loadermap loadermap hashmap loadermap getname public class loader find class loader string name if loader map null return null return class loader loader map get name classloader findclassloader loadermap classloader loadermap public void set custom serializer custom serializer serializer this serializer serializer setcustomserializer customserializer iterator oids hash iterator hash set result oids result iterator hashiterator hashset public object next return lookup object next oid null lookupobject nextoid public int next oid return integer oids next int value nextoid intvalue public boolean has next return oids has next hasnext hasnext public void remove throw new unsupported operation exception unsupportedoperationexception public iterator merge iterator selections hash set result null for int i 0 i selections length i iterator iterator selections i hash set new result new hash set while iterator has next integer oid new integer persistent iterator iterator next oid if result null result contains oid new result add oid result new result if result size 0 break if result null result new hash set return new hash iterator result hashset hashset newresult hashset hasnext persistentiterator nextoid newresult newresult hashset hashiterator public iterator join iterator selections hash set result new hash set for int i 0 i selections length i iterator iterator selections i while iterator has next result add new integer persistent iterator iterator next oid return new hash iterator result hashset hashset hasnext persistentiterator nextoid hashiterator public synchronized void register custom allocator class cls custom allocator allocator synchronized object cache class descriptor desc get class descriptor cls desc allocator allocator store object0 desc false if custom allocator map null custom allocator map new hash map custom allocator list new array list custom allocator map put cls desc allocator custom allocator list add desc allocator registercustomallocator customallocator objectcache classdescriptor getclassdescriptor storeobject0 customallocatormap customallocatormap hashmap customallocatorlist arraylist customallocatormap customallocatorlist public custom allocator create bitmap allocator int quantum long base long extension long limit return new bitmap custom allocator this quantum base extension limit customallocator createbitmapallocator bitmapcustomallocator public int get database format version return header database format version getdatabaseformatversion databaseformatversion final thread local transaction context new thread local protected synchronized object initial value return new thread transaction context threadlocal transactioncontext threadlocal initialvalue threadtransactioncontext final void pack byte rec int offs 0 rec offs byte curr rec offs byte dirty 1 0 rec offs database format version for int i 0 i 2 i bytes pack8 rec offs root i size offs 8 bytes pack8 rec offs root i index offs 8 bytes pack8 rec offs root i shadow index offs 8 bytes pack8 rec offs root i used size offs 8 bytes pack4 rec offs root i index size offs 4 bytes pack4 rec offs root i shadow index size offs 4 bytes pack4 rec offs root i index used offs 4 bytes pack4 rec offs root i free list offs 4 bytes pack4 rec offs root i bitmap end offs 4 bytes pack4 rec offs root i root object offs 4 bytes pack4 rec offs root i class desc list offs 4 bytes pack4 rec offs root i bitmap extent offs 4 bytes pack8 rec offs transaction id offs 8 assert that offs sizeof databaseformatversion shadowindex usedsize indexsize shadowindexsize indexused freelist bitmapend rootobject classdesclist bitmapextent transactionid final void unpack byte rec int offs 0 curr rec offs dirty rec offs 0 database format version rec offs root new root page 2 for int i 0 i 2 i root i new root page root i size bytes unpack8 rec offs offs 8 root i index bytes unpack8 rec offs offs 8 root i shadow index bytes unpack8 rec offs offs 8 root i used size bytes unpack8 rec offs offs 8 root i index size bytes unpack4 rec offs offs 4 root i shadow index size bytes unpack4 rec offs offs 4 root i index used bytes unpack4 rec offs offs 4 root i free list bytes unpack4 rec offs offs 4 root i bitmap end bytes unpack4 rec offs offs 4 root i root object bytes unpack4 rec offs offs 4 root i class desc list bytes unpack4 rec offs offs 4 root i bitmap extent bytes unpack4 rec offs offs 4 transaction id bytes unpack8 rec offs offs 8 assert that offs sizeof databaseformatversion rootpage rootpage shadowindex usedsize indexsize shadowindexsize indexused freelist bitmapend rootobject classdesclist bitmapextent transactionid private final int interval private final nodeip detector detector public ip address detector int interval nodeip detector detector this interval interval this detector detector nodeipdetector ipaddressdetector nodeipdetector return our name public string get checkpoint name return autodetection of ip addresses getcheckpointname return next scheduling point public long next checkpoint return system current time millis interval we are pretty cheap nextcheckpoint currenttimemillis fetches the currently detected ip address if not detected yet a detection is forced return detected ip address public inet address get address return get address interval inetaddress getaddress getaddress get the ip address return detected ip address public inet address get address long recheck time if system current time millis last detected time recheck time checkpoint return last address list null new inet address 0 last address list inetaddress getaddress rechecktime currenttimemillis lastdetectedtime rechecktime lastaddresslist inetaddress lastaddresslist execute a checkpoint detect our internet ip address and log it param prefered address an address that for some reason is preferred above others might be null protected synchronized void checkpoint boolean logdebug logger should log logger debug this list inet address addrs new array list inet address enumeration java net network interface interfaces null try interfaces java net network interface get network interfaces catch socket exception e logger error this socket exception trying to detect network interfaces e e addrs add old detect old true if old while interfaces has more elements java net network interface iface interfaces next element if logdebug logger debug this scanning network interface iface get display name enumeration inet address ee iface get inet addresses while ee has more elements inet address addr ee next element addrs add addr if logdebug logger debug this adding address addr from iface get display name if logdebug logger debug this finished scanning interface iface get display name if logdebug logger debug this finished scanning interfaces fixme what are we doing here last inet address is always null inet address old address list last address list on get addresses addrs last detected time system current time millis if old address list last address list old address list null last address list null old address list null last address list null arrays equals old address list last address list something changed yes i know it could just have changed the order but this is unlikely hopefully fixme detector redetect address preferedaddress shouldlog inetaddress arraylist inetaddress networkinterface networkinterface getnetworkinterfaces socketexception socketexception networkinterfaces olddetect hasmoreelements networkinterface nextelement networkinterface getdisplayname inetaddress getinetaddresses hasmoreelements inetaddress nextelement getdisplayname getdisplayname lastinetaddress inetaddress oldaddresslist lastaddresslist ongetaddresses lastdetectedtime currenttimemillis oldaddresslist lastaddresslist oldaddresslist lastaddresslist oldaddresslist lastaddresslist oldaddresslist lastaddresslist redetectaddress protected inet address old detect boolean should log logger should log logger debug this if should log logger debug this running old style detection code datagram socket ds null try try ds new datagram socket catch socket exception e logger error this socket exception e return null this does not transfer any data the ip is a root servers net 53 is dns try ds connect inet address get by name 198 41 0 4 53 catch unknown host exception ex logger error this unknown host exception ex return null return ds get local address finally if ds null ds close inetaddress olddetect shouldlog shouldlog shouldlog datagramsocket datagramsocket socketexception socketexception inetaddress getbyname unknownhostexception unknownhostexception getlocaladdress do something with the list of detected ip addresses param addrs vector of inet addresses protected void on get addresses list inet address addrs list inet address output new array list inet address boolean logdebug logger should log logger debug this if logdebug logger debug this on get addresses found addrs size potential addresses if addrs size 0 logger error this no addresses found last address list null return else inet address last non valid address null for int x 0 x addrs size x if addrs get x null inet address i addrs get x if logdebug logger debug this address x i if i is any local address wildcard address 0 0 0 0 ignore else if i is link local address i is loopback address i is site local address will be filtered out later if necessary output add i else if i is multicast address ignore else ignore isatap addresses see http archives freenetproject org message 20071129 220955 ac2a2a36 en html if address identifier is anisatapi pv6 address i to string output add i last address list output to array new inet address output size inetaddresses ongetaddresses inetaddress inetaddress arraylist inetaddress shouldlog ongetaddresses lastaddresslist inetaddress lastnonvalidaddress inetaddress isanylocaladdress islinklocaladdress isloopbackaddress issitelocaladdress ismulticastaddress addressidentifier isanisatapipv6address tostring lastaddresslist toarray inetaddress public void run freenet support logger os thread logpid this while true try thread sleep interval catch interrupted exception e ignore try checkpoint catch throwable t logger error this caught t t osthread interruptedexception public void clear cached last address list null last detected time 1 clearcached lastaddresslist lastdetectedtime public class null bloom filter extends bloom filter protected null bloom filter int length int k super length k nullbloomfilter bloomfilter nullbloomfilter override public boolean check filter byte key return true checkfilter override public void add key byte key ignore addkey override public void remove key byte key ignore removekey override protected boolean get bit int offset ignore return true getbit override protected void set bit int offset ignore setbit override protected void unset bit int offset ignore unsetbit override public void fork int k return override public void discard return override public void merge return public class snmp bindto callback extends string callback public snmp bindto callback snmpbindtocallback stringcallback snmpbindtocallback public string get string bindto snmp agent getsnmp agent getsnm pbindto if bindto null return bindto return 127 0 0 1 snmpagent getsnmpagent getsnmpbindto public void set string val throws invalid config value exception if val equals get snmp agent setsnm pbindto val invalidconfigvalueexception snmpagent setsnmpbindto static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public announce sender message m long uid peer node source opennet manager om node node this source source this uid uid this msg m this om om this node node this only node null htl short math min m get short dmt htl node maxhtl target m get double dmt target location fixme validate cb null announcesender peernode opennetmanager onlynode getshort getdouble target_location public announce sender double target opennet manager om node node announcement callback cb peer node only node source null this uid node random next long msg null this om om this node node this htl node maxhtl this target target this cb cb this only node only node noderef buf om crypto my compressed full ref announcesender opennetmanager announcementcallback peernode onlynode nextlong onlynode onlynode noderefbuf mycompressedfullref public void run try real run catch throwable t logger error this caught t announcing uid from source t finally if source null source completed announce uid node completed uid if cb null cb completed realrun completedannounce private void real run boolean has forwarded false if source null try source send async dmt createfnp accepted uid null this catch not connected exception e return if transfer noderef return now route it hash set peer node nodes routed to new hash set peer node peer node next null while true if logminor logger minor this htl htl if we haven t routed to any node yet decrement according to the source if we have decrement according to the node which just failed because 1 if we always decrement according to source then we can be at max or min htl for a long time while we visit every peer node this is bad 2 the node which just failed can be seen as the requestor for our purposes decrement at this point so we can dnf immediately on reaching htl 0 htl node decrementhtl has forwarded next source htl if htl 0 no more nodes complete return if node is opennet enabled complete return if only node null route it next node peers closer peer source nodes routed to target true node is advanced mode enabled 1 null null else next only node if nodes routed to contains only node rnf only node return if next null backtrack rnf next return if logminor logger minor this routing request to next nodes routed to add next long xferuid send to next if xferuid 1 continue has forwarded true message msg null while true what are we waiting for fnp accepted continue fnp rejected loop go to another node fnp rejected overload go to another node message filter mf accepted message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp accepted message filter mf rejected loop message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected loop message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected overload message filter mf opennet disabled message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp opennet disabled mf rejected overload must be the last thing in the or so its or pointer remains null otherwise we need to recreate it below message filter mf mf accepted or mf rejected loop or mf rejected overload or mf opennet disabled try msg node usm wait for mf this if logminor logger minor this first part got msg catch disconnected exception e logger normal this disconnected from next while waiting for accepted on uid break if msg null if logminor logger minor this timeout waiting for accepted try next node msg null break if msg get spec dmt fnp rejected loop if logminor logger minor this rejected loop find another node to route to msg null break if msg get spec dmt fnp rejected overload if logminor logger minor this rejected overload give up on this one try another msg null break if msg get spec dmt fnp opennet disabled if logminor logger minor this opennet disabled msg null break if msg get spec dmt fnp accepted logger error this unrecognized message msg continue break if msg null msg get spec dmt fnp accepted try another node continue if logminor logger minor this got accepted send the rest try send rest next xferuid catch not connected exception e1 if logminor logger minor this not connected while sending noderef on next continue otherwise must be accepted so wait while true message filter mf announce completed message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp opennet announce completed message filter mf route not found message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp route not found message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp rejected overload message filter mf announce reply message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp opennet announce reply message filter mf opennet disabled message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp opennet disabled message filter mf not wanted message filter create set source next set field dmt uid uid set timeout announce timeout set type dmt fnp opennet announce node not wanted message filter mf opennet noderef rejected message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp opennet noderef rejected message filter mf mf announce completed or mf route not found or mf rejected overload or mf announce reply or mf opennet disabled or mf not wanted or mf opennet noderef rejected try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for announcement break if logminor logger minor this second part got msg if msg null fatal timeout must be terminal is local true timed out next return if msg get spec dmt fnp opennet noderef rejected int reason msg get int dmt reject code logger normal this announce rejected by next dmt get opennet rejected code reason msg null break if msg get spec dmt fnp opennet announce completed send the completion on immediately we don t want to accumulate 30 seconds per hop complete mf announce reply set timeout end timeout set timeout relative to creation true mf not wanted set timeout end timeout set timeout relative to creation true mf announce reply clear or mf not wanted clear or mf mf announce reply or mf not wanted while true try msg node usm wait for mf this catch disconnected exception e return if msg null return if msg get spec dmt fnp opennet announce reply validate forward reply msg next continue if msg get spec dmt fnp opennet announce node not wanted if cb null cb node not wanted if source null try send not wanted catch not connected exception e logger error this lost connection to source return continue if msg get spec dmt fnp route not found backtrack within available hops short new htl msg get short dmt htl if new htl htl htl new htl break if msg get spec dmt fnp rejected overload give up on this one try another break if msg get spec dmt fnp opennet disabled logger minor this opennet disabled msg null break if msg get spec dmt fnp opennet announce reply validate forward reply msg next continue there may be more realrun hasforwarded sendasync createfnpaccepted notconnectedexception transfernoderef hashset peernode nodesroutedto hashset peernode peernode hasforwarded isopennetenabled onlynode closerpeer nodesroutedto isadvancedmodeenabled onlynode nodesroutedto onlynode onlynode nodesroutedto sendto hasforwarded fnpaccepted fnprejectedloop fnprejectedoverload messagefilter mfaccepted messagefilter setsource setfield settimeout accepted_timeout settype fnpaccepted messagefilter mfrejectedloop messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedloop messagefilter mfrejectedoverload messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedoverload messagefilter mfopennetdisabled messagefilter setsource setfield settimeout accepted_timeout settype fnpopennetdisabled mfrejectedoverload messagefilter mfaccepted mfrejectedloop mfrejectedoverload mfopennetdisabled waitfor disconnectedexception getspec fnprejectedloop getspec fnprejectedoverload getspec fnpopennetdisabled getspec fnpaccepted getspec fnpaccepted sendrest notconnectedexception messagefilter mfannouncecompleted messagefilter setsource setfield settimeout announce_timeout settype fnpopennetannouncecompleted messagefilter mfroutenotfound messagefilter setsource setfield settimeout announce_timeout settype fnproutenotfound messagefilter mfrejectedoverload messagefilter setsource setfield settimeout announce_timeout settype fnprejectedoverload messagefilter mfannouncereply messagefilter setsource setfield settimeout announce_timeout settype fnpopennetannouncereply messagefilter mfopennetdisabled messagefilter setsource setfield settimeout announce_timeout settype fnpopennetdisabled messagefilter mfnotwanted messagefilter setsource setfield settimeout announce_timeout settype fnpopennetannouncenodenotwanted messagefilter mfopennetnoderefrejected messagefilter setsource setfield settimeout accepted_timeout settype fnpopennetnoderefrejected messagefilter mfannouncecompleted mfroutenotfound mfrejectedoverload mfannouncereply mfopennetdisabled mfnotwanted mfopennetnoderefrejected waitfor disconnectedexception is_local timedout getspec fnpopennetnoderefrejected getint reject_code getopennetrejectedcode getspec fnpopennetannouncecompleted mfannouncereply settimeout end_timeout settimeoutrelativetocreation mfnotwanted settimeout end_timeout settimeoutrelativetocreation mfannouncereply clearor mfnotwanted clearor mfannouncereply mfnotwanted waitfor disconnectedexception getspec fnpopennetannouncereply validateforwardreply getspec fnpopennetannouncenodenotwanted nodenotwanted sendnotwanted notconnectedexception getspec fnproutenotfound newhtl getshort newhtl newhtl getspec fnprejectedoverload getspec fnpopennetdisabled getspec fnpopennetannouncereply validateforwardreply validate a reply and relay it back to the source param msg2 the announcement reply message return true unless we lost the connection to our request source private boolean validate forward reply message msg peer node next long xferuid msg get long dmt transfer uid int noderef length msg get int dmt noderef length int padded length msg get int dmt padded length byte noderef buf om inner wait for opennet noderef xferuid padded length noderef length next false uid true this if noderef buf null return true don t relay simple field set fs om validate noderef noderef buf 0 noderef length next false if fs null if cb null cb bogus noderef invalid noderef return true don t relay if source null now relay it try om send announcement reply uid source noderef buf this catch not connected exception e hmmm return false else add it try opennet peer node pn node add new opennet node fs if pn null cb added node pn else cb node not added catch fs parse exception e logger normal this failed to parse reply e e if cb null cb bogus noderef parse failed e catch peer parse exception e logger normal this failed to parse reply e e if cb null cb bogus noderef parse failed e catch reference signature verification exception e logger normal this failed to parse reply e e if cb null cb bogus noderef parse failed e return true announcementreply validateforwardreply peernode getlong transfer_uid nodereflength getint noderef_length paddedlength getint padded_length noderefbuf innerwaitforopennetnoderef paddedlength nodereflength noderefbuf simplefieldset validatenoderef noderefbuf nodereflength bogusnoderef sendannouncementreply noderefbuf notconnectedexception opennetpeernode addnewopennetnode addednode nodenotadded fsparseexception bogusnoderef peerparseexception bogusnoderef referencesignatureverificationexception bogusnoderef send an announcement request param next the node to send the announcement to return true if the announcement was successfully sent private long send to peer node next try return om start send announcement request uid next noderef buf this target htl catch not connected exception e if logminor logger minor this disconnected return 1 announcementrequest sendto peernode startsendannouncementrequest noderefbuf notconnectedexception send an announcement request param next the node to send the announcement to return true if the announcement was successfully sent throws not connected exception private void send rest peer node next long xferuid throws not connected exception om finish sent announcement request next noderef buf this xferuid announcementrequest notconnectedexception sendrest peernode notconnectedexception finishsentannouncementrequest noderefbuf private void timed out peer node next message msg dmt createfnp rejected overload uid true if source null try source send async msg null this catch not connected exception e ok if cb null cb node failed next timed out timedout peernode createfnprejectedoverload sendasync notconnectedexception nodefailed private void rnf peer node next message msg dmt createfnp route not found uid htl if source null try source send async msg null this catch not connected exception e ok if cb null if next null cb node failed next route not found else cb no more nodes peernode createfnproutenotfound sendasync notconnectedexception nodefailed nomorenodes private void complete message msg dmt createfnp opennet announce completed uid if source null try source send async msg null this catch not connected exception e oh well createfnpopennetannouncecompleted sendasync notconnectedexception return true unless the noderef is bogus private boolean transfer noderef long xferuid msg get long dmt transfer uid noderef length msg get int dmt noderef length int padded length msg get int dmt padded length noderef buf om inner wait for opennet noderef xferuid padded length noderef length source false uid true this if noderef buf null return false simple field set fs om validate noderef noderef buf 0 noderef length source false if fs null om reject ref uid source dmt noderef rejected invalid this return false if we want it add it and send it try if om add new opennet node fs null send our ref source om crypto my compressed full ref else if logminor logger minor this don t need the node send not wanted okay just route it catch fs parse exception e if logminor logger minor this rejecting noderef e e om reject ref uid source dmt noderef rejected invalid this return false catch peer parse exception e if logminor logger minor this rejecting noderef e e om reject ref uid source dmt noderef rejected invalid this return false catch reference signature verification exception e if logminor logger minor this rejecting noderef e e om reject ref uid source dmt noderef rejected invalid this return false catch not connected exception e logger normal this could not receive noderef disconnected return false return true transfernoderef getlong transfer_uid nodereflength getint noderef_length paddedlength getint padded_length noderefbuf innerwaitforopennetnoderef paddedlength nodereflength noderefbuf simplefieldset validatenoderef noderefbuf nodereflength rejectref noderef_rejected_invalid addnewopennetnode sendourref mycompressedfullref sendnotwanted fsparseexception rejectref noderef_rejected_invalid peerparseexception rejectref noderef_rejected_invalid referencesignatureverificationexception rejectref noderef_rejected_invalid notconnectedexception private void send not wanted throws not connected exception message msg dmt createfnp opennet announce node not wanted uid source send async msg null this sendnotwanted notconnectedexception createfnpopennetannouncenodenotwanted sendasync private void send our ref peer node next byte ref throws not connected exception om send announcement reply uid next ref this sendourref peernode notconnectedexception sendannouncementreply public void sent bytes int x node node stats announce byte counter sent bytes x sentbytes nodestats announcebytecounter sentbytes public void received bytes int x node node stats announce byte counter received bytes x receivedbytes nodestats announcebytecounter receivedbytes public void sent payload int x doesn t count sentpayload public int get priority return native thread high priority getpriority nativethread high_priority public class ip undetected user alert extends abstract user alert public ip undetected user alert node n super true null null null null short 0 true l10n get string user alert hide false null this node n ipundetecteduseralert abstractuseralert ipundetecteduseralert getstring useralert final node node override public string get title return l10n unknown address title gettitle unknownaddresstitle override public string get text if node ip detector no detect plugins return l10n no detector plugins if node ip detector is detecting return l10n detecting else return l10n unknown address port integer to string node get darknet port number text port forward suggestion gettext ipdetector nodetectplugins nodetectorplugins ipdetector isdetecting unknownaddress tostring getdarknetportnumber textportforwardsuggestion private string l10n string key return l10n get string ip undetected user alert key getstring ipundetecteduseralert private string l10n string key string pattern string value return l10n get string ip undetected user alert key pattern value getstring ipundetecteduseralert private string l10n string key string patterns string values return l10n get string ip undetected user alert key patterns values getstring ipundetecteduseralert override public html node gethtml text if node ip detector no detect plugins html node p new html node p l10n addl10n substitution p ip undetected user alert load detect plugins new string plugins plugins config config new string a href plugins a a href config a return p html node text node new html node div sub config sc node config get node option o sc get option tempip address hint l10n addl10n substitution text node ip undetected user alert node ip detector is detecting detecting with config link unknown address with config link new string link link new string a href config a add port forward suggestion text node html node form node text node add child form new string action method new string config post form node add child input new string type name value new string hidden form password node client core form password html node list node form node add child ul class config html node item node list node add child li item node add child span class configshortdesc l10n get string o get short desc add child input new string type name value new string text sc get prefix tempip address hint o get value string item node add child span class configlongdesc l10n get string o get long desc form node add child input new string type value new string submit l10n get string user alert apply form node add child input new string type value new string reset l10n get string user alert reset return text node htmlnode gethtmltext ipdetector nodetectplugins htmlnode htmlnode addl10nsubstitution ipundetecteduseralert loaddetectplugins htmlnode textnode htmlnode subconfig getoption tempipaddresshint addl10nsubstitution textnode ipundetecteduseralert ipdetector isdetecting detectingwithconfiglink unknownaddresswithconfiglink addportforwardsuggestion textnode htmlnode formnode textnode addchild formnode addchild formpassword clientcore formpassword htmlnode listnode formnode addchild htmlnode itemnode listnode addchild itemnode addchild getstring getshortdesc addchild getprefix tempipaddresshint getvaluestring itemnode addchild getstring getlongdesc formnode addchild getstring useralert formnode addchild getstring useralert textnode private void add port forward suggestion html node text node fixme we should support any number of ports udp or tcp and pick them up from the node as we do with the forwarding plugin that would be a bit of a pain for l10n though int darknet port node get darknet port number int opennet port node get opennetfnp port if opennet port 0 text node add child l10n suggest forward port port integer to string darknet port else text node add child l10n suggest forward two ports new string port1 port2 new string integer to string darknet port integer to string opennet port addportforwardsuggestion htmlnode textnode darknetport getdarknetportnumber opennetport getopennetfnpport opennetport textnode addchild suggestforwardport tostring darknetport textnode addchild suggestforwardtwoports tostring darknetport tostring opennetport private string text port forward suggestion fixme we should support any number of ports udp or tcp and pick them up from the node as we do with the forwarding plugin that would be a bit of a pain for l10n though int darknet port node get darknet port number int opennet port node get opennetfnp port if opennet port 0 return l10n suggest forward port port integer to string darknet port else return l10n suggest forward two ports new string port1 port2 new string integer to string darknet port integer to string opennet port textportforwardsuggestion darknetport getdarknetportnumber opennetport getopennetfnpport opennetport suggestforwardport tostring darknetport suggestforwardtwoports tostring darknetport tostring opennetport override public short get priority class if node ip detector is detecting return user alert warning else return user alert error getpriorityclass ipdetector isdetecting useralert useralert override public string get short text if node ip detector no detect plugins return l10n no detector plugins if node ip detector is detecting return l10n detecting short else return l10n unknown address short getshorttext ipdetector nodetectplugins nodetectorplugins ipdetector isdetecting detectingshort unknownaddressshort public class gray filter extends point filter public gray filter can filter index color model true grayfilter pointfilter grayfilter canfilterindexcolormodel override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r r 255 2 g g 255 2 b b 255 2 return a r 16 g 8 b override public string to string return colors gray out tostring transient field field public int compare to object o return field name compare to field descriptor o field name compareto fieldname compareto fielddescriptor fieldname public boolean equals field descriptor fd return field name equals fd field name class name equals fd class name value desc fd value desc type fd type fielddescriptor fieldname fieldname classname classname valuedesc valuedesc static reflection provider get reflection provider if reflection provider null try class for name sun misc unsafe string cls plugins xml spider org garret perst impl sun14 sun14 reflection provider reflection provider reflection provider class for name cls new instance catch throwable x reflection provider new standard reflection provider return reflection provider reflectionprovider getreflectionprovider reflectionprovider forname xmlspider sun14reflectionprovider reflectionprovider reflectionprovider forname newinstance reflectionprovider standardreflectionprovider reflectionprovider public boolean equals class descriptor cd if cd null all fields length cd all fields length return false for int i 0 i all fields length i if all fields i equals cd all fields i return false return true classdescriptor allfields allfields allfields allfields allfields object new instance if factory null return factory create this else try return load constructor new instance constructor params catch exception x throw new storage error storage error constructor failure cls x newinstance loadconstructor newinstance constructorparams storageerror storageerror constructor_failure void build field list storage impl storage class cls array list list class superclass cls get superclass if superclass null build field list storage superclass list field flds cls get declared fields if storage get database format version 2 arrays sort flds new comparator field public int compare field f1 field f2 return f1 get name compare to f2 get name else preserve backward compatibility if class descriptor class equals cls for int i 0 i flds length i if flds i get modifiers modifier transient modifier static 0 if next equals flds i get name reverse members order true break if reverse members order for int i 0 n flds length i n 1 i field f flds i flds i flds n i 1 flds n i 1 f for int i 0 i flds length i field f flds i if f is synthetic f get modifiers modifier transient modifier static 0 try f set accessible true catch exception x field descriptor fd new field descriptor fd field f fd field name f get name fd class name cls get name int type get type code f get type switch type case tp object case tp link case tp array of object has references true break case tp value fd value desc storage get class descriptor f get type has references fd value desc has references break case tp array of value fd value desc storage get class descriptor f get type get component type has references fd value desc has references fd type type list add fd buildfieldlist storageimpl arraylist getsuperclass buildfieldlist getdeclaredfields getdatabaseformatversion getname compareto getname classdescriptor getmodifiers getname reversemembersorder reversemembersorder issynthetic getmodifiers setaccessible fielddescriptor fielddescriptor fieldname getname classname getname gettypecode gettype tpobject tplink tparrayofobject hasreferences tpvalue valuedesc getclassdescriptor gettype hasreferences valuedesc hasreferences tparrayofvalue valuedesc getclassdescriptor gettype getcomponenttype hasreferences valuedesc hasreferences field flds cls get declared fields if storage get database format version 2 arrays sort flds new comparator field public int compare field f1 field f2 return f1 get name compare to f2 get name getdeclaredfields getdatabaseformatversion getname compareto getname public static int get type code class c int type if c equals byte class type tp byte else if c equals short class type tp short else if c equals char class type tp char else if c equals int class type tp int else if c equals long class type tp long else if c equals float class type tp float else if c equals double class type tp double else if c equals string class type tp string else if c equals boolean class type tp boolean else if c is enum type tp enum else if c equals java util date class type tp date else if i persistent class is assignable from c type tp object else if i value class is assignable from c type tp value else if c equals link class type tp link else if c is array type get type code c get component type if type tp link throw new storage error storage error unsupported type c type tp array of boolean else if custom serializable class is assignable from c type tp custom else if c equals object class comparable class is assignable from c type tp raw else if serialize non persistent objects type tp raw else if treate any non persistent object as value if c equals object class throw new storage error storage error empty value type tp value else throw new storage error storage error unsupported type c return type gettypecode tpbyte tpshort tpchar tpint tplong tpfloat tpdouble tpstring tpboolean isenum tpenum tpdate ipersistent isassignablefrom tpobject ivalue isassignablefrom tpvalue tplink isarray gettypecode getcomponenttype tplink storageerror storageerror unsupported_type tparrayofboolean customserializable isassignablefrom tpcustom isassignablefrom tpraw serializenonpersistentobjects tpraw treateanynonpersistentobjectasvalue storageerror storageerror empty_value tpvalue storageerror storageerror unsupported_type static boolean serialize non persistent objects boolean get boolean perst serialize transient objects class descriptor serializenonpersistentobjects getboolean classdescriptor private static class load class string name throws class not found exception class loader loader thread current thread get context class loader if loader null return loader load class name else return class for name name loadclass classnotfoundexception classloader currentthread getcontextclassloader loadclass forname private void locate constructor try class c load class cls get name load factory factory load factory c new instance catch exception x1 try load constructor cls get declared constructor perst constructor profile constructor params new object this catch no such method exception x2 try load constructor get reflection provider get default constructor cls constructor params null catch exception x3 throw new storage error storage error descriptor failure cls x3 try load constructor set accessible true catch exception x locateconstructor loadclass getname loadfactory loadfactory newinstance loadconstructor getdeclaredconstructor perstconstructorprofile constructorparams nosuchmethodexception loadconstructor getreflectionprovider getdefaultconstructor constructorparams storageerror storageerror descriptor_failure loadconstructor setaccessible class descriptor storage impl storage class cls this cls cls name get class name cls array list list new array list build field list storage cls list all fields field descriptor list to array new field descriptor list size locate constructor resolved true classdescriptor storageimpl getclassname arraylist arraylist buildfieldlist allfields fielddescriptor toarray fielddescriptor locateconstructor protected static field locate field class scope string name try do try field fld scope get declared field name try fld set accessible true catch exception e return fld catch no such field exception x scope scope get superclass while scope null catch exception x throw new storage error storage error access violation scope get name name x return null locatefield getdeclaredfield setaccessible nosuchfieldexception getsuperclass storageerror storageerror access_violation getname public static string get class name class cls class loader loader cls get class loader return loader instanceof i named class loader i named class loader loader get name cls get name cls get name getclassname classloader getclassloader inamedclassloader inamedclassloader getname getname getname public static class load class storage storage string name if storage null int col name index of class loader loader if col 0 loader storage find class loader name substring 0 col if loader null just ignore this class return null name name substring col 1 else loader storage get class loader if loader null try return loader load class name catch class not found exception x try return load class name catch class not found exception x throw new storage error storage error class not found name x loadclass indexof classloader findclassloader getclassloader loadclass classnotfoundexception loadclass classnotfoundexception storageerror storageerror class_not_found public void on load cls load class get storage name class scope cls int n all fields length for int i n i 0 field descriptor fd all fields i fd load if fd class name equals scope get name for scope cls scope null scope scope get superclass if fd class name equals scope get name break if scope null try field f scope get declared field fd field name if f get modifiers modifier transient modifier static 0 try f set accessible true catch exception e fd field f catch no such field exception x else scope cls for int i n i 0 field descriptor fd all fields i if fd field null hierarchy loop for scope cls scope null scope scope get superclass try field f scope get declared field fd field name if f get modifiers modifier transient modifier static 0 for int j 0 j n j if all fields j field f continue hierarchy loop try f set accessible true catch exception e fd field f break catch no such field exception x locate constructor storage impl s storage impl get storage if s class desc map get cls null s class desc map put cls this onload loadclass getstorage allfields fielddescriptor allfields classname getname getsuperclass classname getname getdeclaredfield fieldname getmodifiers setaccessible nosuchfieldexception fielddescriptor allfields hierarchyloop getsuperclass getdeclaredfield fieldname getmodifiers allfields hierarchyloop setaccessible nosuchfieldexception locateconstructor storageimpl storageimpl getstorage classdescmap classdescmap void resolve if resolved storage impl class storage storage impl get storage class descriptor desc new class descriptor class storage cls resolved true if desc equals this class storage register class descriptor desc storageimpl classstorage storageimpl getstorage classdescriptor classdescriptor classstorage classstorage registerclassdescriptor public boolean recursive loading return false recursiveloading public static pcfb mode create block cipher c if c instanceof rijndael return new rijndaelpcfb mode rijndael c return new pcfb mode c pcfbmode blockcipher rijndaelpcfbmode pcfbmode public static pcfb mode create block cipher c byte iv if c instanceof rijndael return new rijndaelpcfb mode rijndael c iv return new pcfb mode c iv pcfbmode blockcipher rijndaelpcfbmode pcfbmode protected pcfb mode block cipher c this c c feedback register new byte c get block size 3 register pointer feedback register length pcfbmode blockcipher feedback_register getblocksize registerpointer feedback_register protected pcfb mode block cipher c byte iv this c system arraycopy iv 0 feedback register 0 feedback register length pcfbmode blockcipher feedback_register feedback_register resets the pcfb mode to an initial iv public final void reset byte iv system arraycopy iv 0 feedback register 0 feedback register length register pointer feedback register length pcfbmode feedback_register feedback_register registerpointer feedback_register resets the pcfb mode to an initial iv param iv the buffer containing the iv param offset the offset to start reading the iv at public final void reset byte iv int offset system arraycopy iv offset feedback register 0 feedback register length register pointer feedback register length pcfbmode feedback_register feedback_register registerpointer feedback_register writes the initialization vector to the stream though the iv is transmitted in the clear this gives the attacker no additional information because the register pointer is set so that the encrypted buffer is empty this causes an immediate encryption of the iv thus invalidating any information that the attacker had public void writeiv random source rs output stream out throws io exception rs next bytes feedback register out write feedback register registerpointer randomsource outputstream ioexception nextbytes feedback_register feedback_register reads the initialization vector from the given stream public void readiv input stream in throws io exception for int i 0 i feedback register length i feedback register i byte in read util read fully in feedback register inputstream ioexception feedback_register feedback_register readfully feedback_register returns the length of the iv public int lengthiv return feedback register length feedback_register deciphers one byte of data by xor ing the ciphertext byte with one byte from the encrypted buffer then places the received byte in the feedback register if no bytes are available in the encrypted buffer the feedback register is encrypted providing block size 8 new bytes for decryption public synchronized int decipher int b public int decipher int b if register pointer feedback register length refill buffer int rv feedback register register pointer byte b 0xff feedback register register pointer byte b return rv block_size registerpointer feedback_register refillbuffer feedback_register registerpointer feedback_register registerpointer note as a side effect this will decrypt the data in the array public synchronized byte block decipher byte buf int off int len public byte block decipher byte buf int off int len while len 0 if register pointer feedback register length refill buffer int n math min len feedback register length register pointer for int i off i off n i byte b buf i buf i feedback register register pointer feedback register register pointer b off n len n return buf blockdecipher blockdecipher registerpointer feedback_register refillbuffer feedback_register registerpointer feedback_register registerpointer feedback_register registerpointer enciphers one byte of data by xor ing the plaintext byte with one byte from the encrypted buffer then places the enciphered byte in the feedback register if no bytes are available in the encrypted buffer the feedback register is encrypted providing block size 8 new bytes for encryption public synchronized int encipher int b public int encipher int b if register pointer feedback register length refill buffer feedback register register pointer byte b return feedback register register pointer 0xff block_size registerpointer feedback_register refillbuffer feedback_register registerpointer feedback_register registerpointer note as a sideeffect this will encrypt the data in the array public synchronized byte block encipher byte buf int off int len public byte block encipher byte buf int off int len while len 0 if register pointer feedback register length refill buffer int n math min len feedback register length register pointer for int i off i off n i buf i feedback register register pointer buf i off n len n return buf blockencipher blockencipher registerpointer feedback_register refillbuffer feedback_register registerpointer feedback_register registerpointer private synchronized void refill buffer protected void refill buffer encrypt feedback into result c encipher feedback register feedback register register pointer 0 refillbuffer refillbuffer feedback_register feedback_register registerpointer public class chk encode exception extends key encode exception private static final long serial versionuid 1 public chk encode exception super chkencodeexception keyencodeexception serialversionuid chkencodeexception public chk encode exception string message super message chkencodeexception public chk encode exception string message throwable cause super message cause chkencodeexception public chk encode exception throwable cause super cause chkencodeexception final string encoded type public unknown content type exception string type name this type type name encoded type html encoder encode type encodedtype unknowncontenttypeexception typename typename encodedtype htmlencoder public string get type return type gettype override public string gethtml encoded title return l10n title type encoded type gethtmlencodedtitle encodedtype override public string get raw title return l10n title type type getrawtitle override public string get explanation return l10n explanation getexplanation override public html node gethtml explanation return new html node div l10n explanation htmlnode gethtmlexplanation htmlnode private static string l10n string key return l10n get string unknown content type exception key getstring unknowncontenttypeexception private static string l10n string key string pattern string value return l10n get string unknown content type exception key pattern value getstring unknowncontenttypeexception private int paint mode pixel utils normal public gradient filter paintmode pixelutils gradientfilter public gradient filter point p1 point p2 int color1 int color2 boolean repeat int type int interpolation this p1 p1 this p2 p2 this color1 color1 this color2 color2 this repeat repeat this type type this interpolation interpolation colormap new linear colormap color1 color2 gradientfilter linearcolormap public void set point1 point point1 this p1 point1 setpoint1 public point get point1 return p1 getpoint1 public void set point2 point point2 this p2 point2 setpoint2 public point get point2 return p2 getpoint2 public void set type int type this type type settype public int get type return type gettype public void set interpolation int interpolation this interpolation interpolation setinterpolation public int get interpolation return interpolation getinterpolation specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle p2 new point int 64 math cos angle int 64 math sin angle getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set paint mode int paint mode this paint mode paint mode setpaintmode paintmode paintmode paintmode public int get paint mode return paint mode getpaintmode paintmode public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int rgb1 rgb2 float x1 y1 x2 y2 x1 p1 x x2 p2 x if x1 x2 type radial y1 x1 x1 x2 x2 y1 y1 p2 y y2 p1 y rgb1 color2 rgb2 color1 else y1 p1 y y2 p2 y rgb1 color1 rgb2 color2 float dx x2 x1 float dy y2 y1 float len sq dx dx dy dy this x1 x1 this y1 y1 if len sq float min value dx dx len sq dy dy len sq if repeat dx dx 1 0f dy dy 1 0f this dx dx this dy dy int pixels new int width for int y 0 y height y getrgb src 0 y width 1 pixels switch type case linear case bilinear linear gradient pixels y width 1 break case radial radial gradient pixels y width 1 break case conical case biconical conical gradient pixels y width 1 break case square square gradient pixels y width 1 break setrgb dst 0 y width 1 pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage lensq lensq min_value lensq lensq lineargradient radialgradient conicalgradient squaregradient private void repeat gradient int pixels int w int h float rowrel float dx float dy int off 0 for int y 0 y h y float colrel rowrel int j w int rgb while j 0 if type bilinear rgb colormap get color map image math triangle colrel else rgb colormap get color map image math mod colrel 1 0f pixels off pixel utils combine pixels rgb pixels off paint mode off colrel dx rowrel dy repeatgradient getcolor imagemath getcolor imagemath pixelutils combinepixels paintmode private void single gradient int pixels int w int h float rowrel float dx float dy int off 0 for int y 0 y h y float colrel rowrel int j w int rgb if colrel 0 0 rgb colormap get color 0 do pixels off pixel utils combine pixels rgb pixels off paint mode off colrel dx while j 0 colrel 0 0 while colrel 1 0 j 0 if type bilinear rgb colormap get color map image math triangle colrel else rgb colormap get color map colrel pixels off pixel utils combine pixels rgb pixels off paint mode off colrel dx if j 0 if type bilinear rgb colormap get color 0 0f else rgb colormap get color 1 0f do pixels off pixel utils combine pixels rgb pixels off paint mode off while j 0 rowrel dy singlegradient getcolor pixelutils combinepixels paintmode getcolor imagemath getcolor pixelutils combinepixels paintmode getcolor getcolor pixelutils combinepixels paintmode private void linear gradient int pixels int y int w int h int x 0 float rowrel x x1 dx y y1 dy if repeat repeat gradient pixels w h rowrel dx dy else single gradient pixels w h rowrel dx dy lineargradient repeatgradient singlegradient private void radial gradient int pixels int y int w int h int off 0 float radius distance p2 x p1 x p2 y p1 y for int x 0 x w x float distance distance x p1 x y p1 y float ratio distance radius if repeat ratio ratio 2 else if ratio 1 0 ratio 1 0f int rgb colormap get color map ratio pixels off pixel utils combine pixels rgb pixels off paint mode off radialgradient getcolor pixelutils combinepixels paintmode private void square gradient int pixels int y int w int h int off 0 float radius math max math abs p2 x p1 x math abs p2 y p1 y for int x 0 x w x float distance math max math abs x p1 x math abs y p1 y float ratio distance radius if repeat ratio ratio 2 else if ratio 1 0 ratio 1 0f int rgb colormap get color map ratio pixels off pixel utils combine pixels rgb pixels off paint mode off squaregradient getcolor pixelutils combinepixels paintmode private void conical gradient int pixels int y int w int h int off 0 float angle0 float math atan2 p2 x p1 x p2 y p1 y for int x 0 x w x float angle float math atan2 x p1 x y p1 y angle0 image math two pi angle 1 0f angle 1 0f if type biconical angle image math triangle angle int rgb colormap get color map angle pixels off pixel utils combine pixels rgb pixels off paint mode off conicalgradient imagemath two_pi imagemath getcolor pixelutils combinepixels paintmode private float map float v if repeat v v 1 0 2 0f v v switch interpolation case int circle up v image math circle up image math clamp v 0 0f 1 0f break case int circle down v image math circle down image math clamp v 0 0f 1 0f break case int smooth v image math smooth step 0 1 v break return v int_circle_up imagemath circleup imagemath int_circle_down imagemath circledown imagemath int_smooth imagemath smoothstep private float distance float a float b return float math sqrt a a b b override public string to string return other gradient fill tostring private boolean read only public byte array random access thing byte padded this data padded readonly bytearrayrandomaccessthing public void close do nothing public void pread long file offset byte buf int buf offset int length throws io exception if file offset 0 throw new io exception cannot read before zero if file offset length data length throw new io exception cannot read after end trying to read from file offset to file offset length on block length data length system arraycopy data int file offset buf buf offset length fileoffset bufoffset ioexception fileoffset ioexception fileoffset ioexception fileoffset fileoffset fileoffset bufoffset public void pwrite long file offset byte buf int buf offset int length throws io exception if file offset 0 throw new io exception cannot write before zero if file offset length data length throw new io exception cannot write after end trying to write from file offset to file offset length on block length data length if read only throw new io exception read only system arraycopy buf buf offset data int file offset length fileoffset bufoffset ioexception fileoffset ioexception fileoffset ioexception fileoffset fileoffset readonly ioexception bufoffset fileoffset public long size throws io exception return data length ioexception public void set read only read only true setreadonly readonly public final string charset private unknown charset exception string warning string warning2 string string html node explanation string charset super warning warning2 string explanation this charset charset unknowncharsetexception htmlnode public static unknown charset exception create unsupported encoding exception e string charset html node explanation new html node p string expl title l10ndf unknown charset title string expl l10ndf unknown charset explanation add child b expl title explanation add child expl string warning l10ndf warning unknown charset title charset charset return new unknown charset exception warning warning expl title expl explanation charset unknowncharsetexception unsupportedencodingexception htmlnode htmlnode expltitle unknowncharsettitle unknowncharset addchild expltitle addchild warningunknowncharsettitle unknowncharsetexception expltitle private static string l10ndf string key all the strings here are generic return l10n get string content data filter key getstring contentdatafilter private static string l10ndf string key string pattern string value all the strings here are generic return l10n get string content data filter key pattern value getstring contentdatafilter public announcer jmdns impl jmdns impl this jmdns impl jmdns impl associate host to this if it needs announcing if this jmdns impl get state dns state announcing 1 this jmdns impl set task this associate services to this if they need announcing synchronized this jmdns impl for iterator s this jmdns impl get services values iterator s has next service info impl info service info impl s next if info get state dns state announcing 1 info set task this jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl getstate dnsstate announcing_1 jmdnsimpl settask jmdnsimpl jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl getstate dnsstate announcing_1 settask public void start timer timer timer schedule this dns constants announce wait interval dns constants announce wait interval dnsconstants announce_wait_interval dnsconstants announce_wait_interval public boolean cancel remove association from host to this if this jmdns impl get task this this jmdns impl set task null remove associations from services to this synchronized this jmdns impl for iterator i this jmdns impl get services values iterator i has next service info impl info service info impl i next if info get task this info set task null return super cancel jmdnsimpl gettask jmdnsimpl settask jmdnsimpl jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl gettask settask public void run dns outgoing out null try send probes for jmdns itself if this jmdns impl get state task state if out null out new dns outgoing dns constants flags qr response dns constants flags aa this jmdns impl get local host add address records out false this jmdns impl advance state send announces for services defensively copy the services into a local list to prevent race conditions with methods register service and unregister service list list synchronized this jmdns impl list new array list this jmdns impl get services values for iterator i list iterator i has next service info impl info service info impl i next synchronized info if info get state task state info get task this info advance state logger finer run jmdns announcing info get qualified name state info get state if out null out new dns outgoing dns constants flags qr response dns constants flags aa info add answers out dns constants dns ttl this jmdns impl get local host if out null logger finer run jmdns announcing task state this jmdns impl send out else if we have nothing to send another timer task state ahead of us has done the job for us we can cancel cancel catch throwable e logger log level warning run exception e this jmdns impl recover task state task state advance if task state is announcing cancel this jmdns impl start renewer dnsoutgoing jmdnsimpl getstate taskstate dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa jmdnsimpl getlocalhost addaddressrecords jmdnsimpl advancestate registerservice unregisterservice jmdnsimpl arraylist jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl getstate taskstate gettask advancestate getqualifiedname getstate dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa addanswers dnsconstants dns_ttl jmdnsimpl getlocalhost taskstate jmdnsimpl taskstate jmdnsimpl taskstate taskstate taskstate isannouncing jmdnsimpl startrenewer persistent blob temp bucket tag persistent blob temp bucket factory f long idx factory f index idx is free true persistentblobtempbuckettag persistentblobtempbucketfactory isfree static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public update over mandatory manager node update manager manager this update manager manager nodes say key revoked new hash set peer node nodes say key revoked failed transfer new hash set peer node nodes offered main jar new hash set peer node nodes offered ext jar new hash set peer node nodes asked send main jar new hash set peer node nodes asked send ext jar new hash set peer node nodes sending main jar new hash set peer node nodes sending ext jar new hash set peer node updateovermandatorymanager nodeupdatemanager updatemanager nodessaykeyrevoked hashset peernode nodessaykeyrevokedfailedtransfer hashset peernode nodesofferedmainjar hashset peernode nodesofferedextjar hashset peernode nodesaskedsendmainjar hashset peernode nodesaskedsendextjar hashset peernode nodessendingmainjar hashset peernode nodessendingextjar hashset peernode handle a uom announce message a node has sent us a message offering us use of its update over mandatory facilities in some way param m the message to handle param source the peer node which sent the message return true unless we don t want the message in this case always true public boolean handle announce message m final peer node source string main jar key m get string dmt main jar key string extra jar key m get string dmt extra jar key string revocation key m get string dmt revocation key boolean have revocation key m get boolean dmt have revocation key long main jar version m get long dmt main jar version long extra jar version m get long dmt extra jar version long revocation key last tried m get long dmt revocation key time last tried int revocation keydn fs m get int dmt revocation key dnf count long revocation key file length m get long dmt revocation key file length long main jar file length m get long dmt main jar file length long extra jar file length m get long dmt extra jar file length int ping time m get int dmt ping time int delay time m get int dmt bwlimit delay time log it if logminor logger minor this update over mandatory offer from node source get peer source user to string logger minor this main jar key main jar key version main jar version length main jar file length logger minor this extra jar key extra jar key version extra jar version length extra jar file length logger minor this revocation key revocation key found have revocation key length revocation key file length last had 3 dn fs revocation key last tried ms ago revocation keydn fs dn fs so far logger minor this load stats ping time ms ping delay time ms bwlimit delay time now the core logic first off if a node says it has the revocation key and its key is the same as ours we should 1 suspend any auto updates and tell the user 2 try to download it and 3 if the download fails move the notification if the download succeeds process it if have revocation key if update manager is blown return true we already know first is the key the same as ours try freeneturi revocationuri new freeneturi revocation key if revocationuri equals update manager revocationuri uh oh have to do this first to avoid race condition synchronized this nodes say key revoked add source disable the update update manager peer claims key blown source tell the user alert user system err println your peer source user to string says that the auto update key is blown system err println attempting to fetch it try to transfer it message msg dmt createuom request revocation update manager node random next long source send async msg new async message callback public void acknowledged ok public void disconnected system err println failed to send request for revocation key to source user to string because it disconnected synchronized update over mandatory manager this nodes say key revoked failed transfer add source public void fatal error not good system err println failed to send request for revocation key to source user to string because of a fatal error public void sent cool update manager ctr the reply message will start the transfer it includes the revocation uri so we can tell if anything wierd is happening else should probably also be a useralert logger normal this node source sent us a uom claiming that the auto update key was blown but it used a different key to us nour key update manager revocationuri nhis key revocationuri system err println node source user to string sent us a uom claiming that the revocation key was blown but it used a different key to us nour key update manager revocationuri nhis key revocationuri catch malformedurl exception e should maybe be a useralert logger error this node source sent us a uom announce claiming that the auto update key was blown but it had an invalid revocation uri revocation key e e system err println node source user to string sent us a uom announce claiming that the revocation key was blown but it had an invalid revocation uri revocation key e catch not connected exception e system err println node source says that the auto update key was blown but has now gone offline something bad may be happening logger error this node source says that the auto update key was blown but has now gone offline something bad may be happening synchronized update over mandatory manager this nodes say key revoked failed transfer add source if update manager is blown return true we already know if update manager is enabled return true don t care if not enabled except for the revocation uri long now system current time millis handle main jar offer now main jar file length main jar version source main jar key handle ext jar offer now extra jar file length extra jar version source extra jar key return true uomannounce peernode handleannounce peernode mainjarkey getstring main_jar_key extrajarkey getstring extra_jar_key revocationkey getstring revocation_key haverevocationkey getboolean have_revocation_key mainjarversion getlong main_jar_version extrajarversion getlong extra_jar_version revocationkeylasttried getlong revocation_key_time_last_tried revocationkeydnfs getint revocation_key_dnf_count revocationkeyfilelength getlong revocation_key_file_length mainjarfilelength getlong main_jar_file_length extrajarfilelength getlong extra_jar_file_length pingtime getint ping_time delaytime getint bwlimit_delay_time getpeer usertostring mainjarkey mainjarversion mainjarfilelength extrajarkey extrajarversion extrajarfilelength revocationkey haverevocationkey revocationkeyfilelength dnfs revocationkeylasttried revocationkeydnfs dnfs pingtime delaytime haverevocationkey updatemanager isblown revocationkey updatemanager nodessaykeyrevoked updatemanager peerclaimskeyblown alertuser usertostring createuomrequestrevocation updatemanager nextlong sendasync asyncmessagecallback usertostring updateovermandatorymanager nodessaykeyrevokedfailedtransfer fatalerror usertostring updatemanager updatemanager usertostring updatemanager malformedurlexception uomannounce revocationkey usertostring uomannounce revocationkey notconnectedexception updateovermandatorymanager nodessaykeyrevokedfailedtransfer updatemanager isblown updatemanager isenabled currenttimemillis handlemainjaroffer mainjarfilelength mainjarversion mainjarkey handleextjaroffer extrajarfilelength extrajarversion extrajarkey source send async msg new async message callback public void acknowledged ok sendasync asyncmessagecallback public void disconnected system err println failed to send request for revocation key to source user to string because it disconnected synchronized update over mandatory manager this nodes say key revoked failed transfer add source usertostring updateovermandatorymanager nodessaykeyrevokedfailedtransfer public void fatal error not good system err println failed to send request for revocation key to source user to string because of a fatal error fatalerror usertostring public void sent cool private void handle main jar offer long now long main jar file length long main jar version peer node source string jar key long started update manager get started fetching next main jar timestamp long when to take over the normal updater if started 0 when to take over the normal updater started grace time else when to take over the normal updater system current time millis grace time boolean is outdated update manager node is oudated if the new build is self mandatory or if the normal updater has been trying to update for more than one hour logger normal this we received a valid uom announce main is outdated is outdated version main jar version when to take over the normal updater time util format time when to take over the normal updater now file length main jar file length update manager version update manager new main jar version if main jar version version build number main jar file length 0 main jar version update manager new main jar version source set main jar offered version main jar version offer is valid if logminor logger minor this offer is valid if is outdated when to take over the normal updater now take up the offer subject to limits on number of simultaneous downloads if we have fetches running already then senduom request main will add the offer to nodes offered main jar so that if all our fetches fail we can fetch from this node if is outdated string how long time util format time now started logger error this the update process seems to have been stuck for how long let s switch to uom should not happen 1 system out println the update process seems to have been stuck for how long let s switch to uom should not happen 1 else if logminor logger minor this fetching via uom as our build is deprecated fetch it try freeneturi main jaruri new freeneturi jar key set suggested edition main jar version if main jaruri equals update manager updateuri set suggested edition main jar version senduom request source true false else system err println node source user to string offered us a new main jar version main jar version but his key was different to ours n our key update manager updateuri nhis key main jaruri catch malformedurl exception e should maybe be a useralert logger error this node source sent us a uom announce claiming to have a new ext jar but it had an invalid uri jar key e e system err println node source user to string sent us a uom announce claiming to have a new ext jar but it had an invalid uri jar key e else don t take up the offer add to nodes offered main jar so that we know where to fetch it from when we need it synchronized this nodes offered main jar add source update manager node get ticker queue timed job new runnable public void run if update manager is blown return if update manager is enabled return if update manager has new main jar return if update manager node is oudated logger error this the update process seems to have been stuck for too long let s switch to uom should not happen 2 ext system out println the update process seems to have been stuck for too long let s switch to uom should not happen 2 ext maybe request main jar when to take over the normal updater now handlemainjaroffer mainjarfilelength mainjarversion peernode jarkey updatemanager getstartedfetchingnextmainjartimestamp whentotakeoverthenormalupdater whentotakeoverthenormalupdater grace_time whentotakeoverthenormalupdater currenttimemillis grace_time isoutdated updatemanager isoudated uomannounce isoutdated isoutdated mainjarversion whentotakeoverthenormalupdater timeutil formattime whentotakeoverthenormalupdater mainjarfilelength updatemanager updatemanager newmainjarversion mainjarversion buildnumber mainjarfilelength mainjarversion updatemanager newmainjarversion setmainjarofferedversion mainjarversion isoutdated whentotakeoverthenormalupdater senduomrequestmain nodesofferedmainjar isoutdated howlong timeutil formattime howlong howlong mainjaruri jarkey setsuggestededition mainjarversion mainjaruri updatemanager setsuggestededition mainjarversion senduomrequest usertostring mainjarversion updatemanager mainjaruri malformedurlexception uomannounce jarkey usertostring uomannounce jarkey nodesofferedmainjar nodesofferedmainjar updatemanager getticker queuetimedjob updatemanager isblown updatemanager isenabled updatemanager hasnewmainjar updatemanager isoudated mayberequestmainjar whentotakeoverthenormalupdater public void run if update manager is blown return if update manager is enabled return if update manager has new main jar return if update manager node is oudated logger error this the update process seems to have been stuck for too long let s switch to uom should not happen 2 ext system out println the update process seems to have been stuck for too long let s switch to uom should not happen 2 ext maybe request main jar updatemanager isblown updatemanager isenabled updatemanager hasnewmainjar updatemanager isoudated mayberequestmainjar private void handle ext jar offer long now long ext jar file length long ext jar version peer node source string jar key long started update manager get started fetching next ext jar timestamp long when to take over the normal updater if started 0 when to take over the normal updater started grace time else when to take over the normal updater system current time millis grace time boolean is outdated update manager node is oudated if the new build is self mandatory or if the normal updater has been trying to update for more than one hour logger normal this we received a valid uom announce ext is outdated is outdated version ext jar version when to take over the normal updater time util format time when to take over the normal updater now file length ext jar file length update manager version update manager new ext jar version if ext jar version node starter ext build number ext jar file length 0 ext jar version update manager new ext jar version source set ext jar offered version ext jar version offer is valid if logminor logger minor this offer is valid if is outdated when to take over the normal updater now take up the offer subject to limits on number of simultaneous downloads if we have fetches running already then senduom request main will add the offer to nodes offered main jar so that if all our fetches fail we can fetch from this node if is outdated string how long time util format time now started logger error this the update process seems to have been stuck for how long let s switch to uom should not happen 1 ext system out println the update process seems to have been stuck for how long let s switch to uom should not happen 1 ext else if logminor logger minor this fetching via uom as our build is deprecated fetch it try freeneturi ext jaruri new freeneturi jar key set suggested edition ext jar version if ext jaruri equals update manager exturi set suggested edition ext jar version senduom request source true true else system err println node source user to string offered us a new ext jar version ext jar version but his key was different to ours n our key update manager exturi nhis key ext jaruri catch malformedurl exception e should maybe be a useralert logger error this node source sent us a uom announce claiming to have a new ext jar but it had an invalid uri jar key e e system err println node source user to string sent us a uom announce claiming to have a new jar but it had an invalid uri jar key e else don t take up the offer add to nodes offered main jar so that we know where to fetch it from when we need it synchronized this nodes offered ext jar add source update manager node get ticker queue timed job new runnable public void run if update manager is blown return if update manager is enabled return if update manager has new ext jar return if update manager node is oudated logger error this the update process seems to have been stuck for too long let s switch to uom should not happen 2 system out println the update process seems to have been stuck for too long let s switch to uom should not happen 2 maybe request ext jar when to take over the normal updater now handleextjaroffer extjarfilelength extjarversion peernode jarkey updatemanager getstartedfetchingnextextjartimestamp whentotakeoverthenormalupdater whentotakeoverthenormalupdater grace_time whentotakeoverthenormalupdater currenttimemillis grace_time isoutdated updatemanager isoudated uomannounce isoutdated isoutdated extjarversion whentotakeoverthenormalupdater timeutil formattime whentotakeoverthenormalupdater extjarfilelength updatemanager updatemanager newextjarversion extjarversion nodestarter extbuildnumber extjarfilelength extjarversion updatemanager newextjarversion setextjarofferedversion extjarversion isoutdated whentotakeoverthenormalupdater senduomrequestmain nodesofferedmainjar isoutdated howlong timeutil formattime howlong howlong extjaruri jarkey setsuggestededition extjarversion extjaruri updatemanager setsuggestededition extjarversion senduomrequest usertostring extjarversion updatemanager extjaruri malformedurlexception uomannounce jarkey usertostring uomannounce jarkey nodesofferedmainjar nodesofferedextjar updatemanager getticker queuetimedjob updatemanager isblown updatemanager isenabled updatemanager hasnewextjar updatemanager isoudated mayberequestextjar whentotakeoverthenormalupdater public void run if update manager is blown return if update manager is enabled return if update manager has new ext jar return if update manager node is oudated logger error this the update process seems to have been stuck for too long let s switch to uom should not happen 2 system out println the update process seems to have been stuck for too long let s switch to uom should not happen 2 maybe request ext jar updatemanager isblown updatemanager isenabled updatemanager hasnewextjar updatemanager isoudated mayberequestextjar private void senduom request final peer node source boolean add on fail final boolean is ext final string name is ext extra main string lname is ext ext main if logminor logger minor this senduom request name source add on fail if source is connected return final hash set peer node sending jar is ext nodes sending ext jar nodes sending main jar final hash set peer node asked send jar is ext nodes asked send ext jar nodes asked send main jar synchronized this long offered version is ext source get ext jar offered version source get main jar offered version long update version is ext update manager new ext jar version update manager new main jar version if offered version update version if offered version 0 logger error this not sending uom lname request to source because it hasn t offered anything else if logminor logger minor this not sending uom lname request to source because we already have its offered version offered version return int cur version is ext update manager get ext version update manager get main version if cur version offered version if logminor logger minor this not fetching from source because current lname jar version cur version is more recent than offered version return if asked send jar contains source if logminor logger minor this recently asked node source lname so not re asking yet return if add on fail asked send jar size sending jar size max nodes sending jar hash set peer node offered jar is ext nodes offered ext jar nodes offered main jar if offered jar add source system err println offered lname jar by source user to string already fetching from sending jar size but will use this offer if our current fetches fail return else if sending jar contains source if logminor logger minor this not fetching lname jar from source user to string because already fetching from that node return sending jar add source message msg is ext dmt createuom request extra update manager node random next long dmt createuom request main update manager node random next long try system err println fetching lname jar from source user to string source send async msg new async message callback public void acknowledged cool wait for the actual transfer public void disconnected logger normal this disconnected from source user to string after sending uom request name synchronized update over mandatory manager this sending jar remove source if is ext maybe request ext jar else maybe request main jar public void fatal error logger normal this fatal error from source user to string after sending uom request name synchronized update over mandatory manager this asked send jar remove source if is ext maybe request ext jar else maybe request main jar public void sent timeout update manager node ps queue timed job new runnable public void run synchronized update over mandatory manager this if asked send jar contains source return asked send jar remove source free up a slot if is ext maybe request ext jar else maybe request main jar request main jar timeout update manager ctr catch not connected exception e synchronized this asked send jar remove source if is ext maybe request ext jar else maybe request main jar senduomrequest peernode addonfail isext isext isext senduomrequest addonfail isconnected hashset peernode sendingjar isext nodessendingextjar nodessendingmainjar hashset peernode askedsendjar isext nodesaskedsendextjar nodesaskedsendmainjar offeredversion isext getextjarofferedversion getmainjarofferedversion updateversion isext updatemanager newextjarversion updatemanager newmainjarversion offeredversion updateversion offeredversion offeredversion curversion isext updatemanager getextversion updatemanager getmainversion curversion offeredversion curversion offeredversion askedsendjar addonfail askedsendjar sendingjar max_nodes_sending_jar hashset peernode offeredjar isext nodesofferedextjar nodesofferedmainjar offeredjar usertostring sendingjar sendingjar usertostring sendingjar isext createuomrequestextra updatemanager nextlong createuomrequestmain updatemanager nextlong usertostring sendasync asyncmessagecallback usertostring uomrequest updateovermandatorymanager sendingjar isext mayberequestextjar mayberequestmainjar fatalerror usertostring uomrequest updateovermandatorymanager askedsendjar isext mayberequestextjar mayberequestmainjar updatemanager queuetimedjob updateovermandatorymanager askedsendjar askedsendjar isext mayberequestextjar mayberequestmainjar request_main_jar_timeout updatemanager notconnectedexception askedsendjar isext mayberequestextjar mayberequestmainjar source send async msg new async message callback public void acknowledged cool wait for the actual transfer sendasync asyncmessagecallback public void disconnected logger normal this disconnected from source user to string after sending uom request name synchronized update over mandatory manager this sending jar remove source if is ext maybe request ext jar else maybe request main jar usertostring uomrequest updateovermandatorymanager sendingjar isext mayberequestextjar mayberequestmainjar public void fatal error logger normal this fatal error from source user to string after sending uom request name synchronized update over mandatory manager this asked send jar remove source if is ext maybe request ext jar else maybe request main jar fatalerror usertostring uomrequest updateovermandatorymanager askedsendjar isext mayberequestextjar mayberequestmainjar public void sent timeout update manager node ps queue timed job new runnable public void run synchronized update over mandatory manager this if asked send jar contains source return asked send jar remove source free up a slot if is ext maybe request ext jar else maybe request main jar request main jar timeout updatemanager queuetimedjob updateovermandatorymanager askedsendjar askedsendjar isext mayberequestextjar mayberequestmainjar request_main_jar_timeout public void run synchronized update over mandatory manager this if asked send jar contains source return asked send jar remove source free up a slot if is ext maybe request ext jar else maybe request main jar updateovermandatorymanager askedsendjar askedsendjar isext mayberequestextjar mayberequestmainjar protected void maybe request main jar peer node offers synchronized this if nodes asked send main jar size nodes sending main jar size max nodes sending jar return if nodes offered main jar is empty return offers nodes offered main jar to array new peer node nodes offered main jar size for int i 0 i offers length i if offers i is connected continue synchronized this if nodes asked send main jar size nodes sending main jar size max nodes sending jar return if nodes sending main jar contains offers i continue if nodes asked send main jar contains offers i continue senduom request offers i false false mayberequestmainjar peernode nodesaskedsendmainjar nodessendingmainjar max_nodes_sending_jar nodesofferedmainjar isempty nodesofferedmainjar toarray peernode nodesofferedmainjar isconnected nodesaskedsendmainjar nodessendingmainjar max_nodes_sending_jar nodessendingmainjar nodesaskedsendmainjar senduomrequest protected void maybe request ext jar peer node offers synchronized this if nodes asked send ext jar size nodes sending ext jar size max nodes sending jar return if nodes offered ext jar is empty return offers nodes offered ext jar to array new peer node nodes offered ext jar size for int i 0 i offers length i if offers i is connected continue synchronized this if nodes asked send ext jar size nodes sending ext jar size max nodes sending jar return if nodes sending ext jar contains offers i continue if nodes asked send ext jar contains offers i continue senduom request offers i false true mayberequestextjar peernode nodesaskedsendextjar nodessendingextjar max_nodes_sending_jar nodesofferedextjar isempty nodesofferedextjar toarray peernode nodesofferedextjar isconnected nodesaskedsendextjar nodessendingextjar max_nodes_sending_jar nodessendingextjar nodesaskedsendextjar senduomrequest private void alert user synchronized this if alert null return alert new peers say key blown alert update manager node client core alerts register alert alertuser peerssaykeyblownalert updatemanager clientcore private class peers say key blown alert extends abstract user alert public peers say key blown alert super false null null null null user alert critical error true null false null peerssaykeyblownalert abstractuseralert peerssaykeyblownalert useralert critical_error override public html node gethtml text html node div new html node div div add child p add child l10n intro peer node nodes get nodes say blown peer node nodes say blown connected nodes 0 peer node nodes say blown disconnected nodes 1 peer node nodes say blown failed transfer nodes 2 if nodes say blown connected length 0 div add child p add child l10n fetching else div add child p add child l10n failed fetch if nodes say blown connected length 0 div add child p add child l10n connected say blown label html node list div add child ul for int i 0 i nodes say blown connected length i list add child li nodes say blown connected i user to string nodes say blown connected i get peer if nodes say blown disconnected length 0 div add child p add child l10n disconnected say blown label html node list div add child ul for int i 0 i nodes say blown disconnected length i list add child li nodes say blown disconnected i user to string nodes say blown disconnected i get peer if nodes say blown failed transfer length 0 div add child p add child l10n failed transfer say blown label html node list div add child ul for int i 0 i nodes say blown failed transfer length i list add child li nodes say blown failed transfer i user to string nodes say blown failed transfer i get peer return div htmlnode gethtmltext htmlnode htmlnode addchild addchild peernode getnodessayblown peernode nodessayblownconnected peernode nodessayblowndisconnected peernode nodessayblownfailedtransfer nodessayblownconnected addchild addchild addchild addchild failedfetch nodessayblownconnected addchild addchild connectedsayblownlabel htmlnode addchild nodessayblownconnected addchild nodessayblownconnected usertostring nodessayblownconnected getpeer nodessayblowndisconnected addchild addchild disconnectedsayblownlabel htmlnode addchild nodessayblowndisconnected addchild nodessayblowndisconnected usertostring nodessayblowndisconnected getpeer nodessayblownfailedtransfer addchild addchild failedtransfersayblownlabel htmlnode addchild nodessayblownfailedtransfer addchild nodessayblownfailedtransfer usertostring nodessayblownfailedtransfer getpeer private string l10n string key return l10n get string peers say key blown alert key getstring peerssaykeyblownalert private string l10n string key string pattern string value return l10n get string peers say key blown alert key pattern value getstring peerssaykeyblownalert override public string get text string builder sb new string builder sb append l10n intro append n n peer node nodes get nodes say blown peer node nodes say blown connected nodes 0 peer node nodes say blown disconnected nodes 1 peer node nodes say blown failed transfer nodes 2 if nodes say blown connected length 0 sb append l10n fetching append n n else sb append l10n failed fetch append n n if nodes say blown connected length 0 sb append l10n connected say blown label append n n for int i 0 i nodes say blown connected length i sb append nodes say blown connected i user to string nodes say blown connected i get peer append n sb append n if nodes say blown disconnected length 0 sb append l10n disconnected say blown label for int i 0 i nodes say blown disconnected length i sb append nodes say blown disconnected i user to string nodes say blown disconnected i get peer append n sb append n if nodes say blown failed transfer length 0 sb append l10n failed transfer say blown label for int i 0 i nodes say blown failed transfer length i sb append nodes say blown failed transfer i user to string nodes say blown failed transfer i get peer append n sb append n return sb to string gettext stringbuilder stringbuilder peernode getnodessayblown peernode nodessayblownconnected peernode nodessayblowndisconnected peernode nodessayblownfailedtransfer nodessayblownconnected failedfetch nodessayblownconnected connectedsayblownlabel nodessayblownconnected nodessayblownconnected usertostring nodessayblownconnected getpeer nodessayblowndisconnected disconnectedsayblownlabel nodessayblowndisconnected nodessayblowndisconnected usertostring nodessayblowndisconnected getpeer nodessayblownfailedtransfer failedtransfersayblownlabel nodessayblownfailedtransfer nodessayblownfailedtransfer usertostring nodessayblownfailedtransfer getpeer tostring override public string get title return l10n title with count count integer to string nodes say key revoked size gettitle titlewithcount tostring nodessaykeyrevoked override public void is valid boolean validity do nothing isvalid override public string get short text return l10n short getshorttext public peer node get nodes say blown vector peer node nodes connected say revoked new vector peer node vector peer node nodes disconnected say revoked new vector peer node vector peer node nodes failed say revoked new vector peer node synchronized this peer node nodes say revoked nodes say key revoked to array new peer node nodes say key revoked size for int i 0 i nodes say revoked length i peer node pn nodes say revoked i if nodes say key revoked failed transfer contains pn nodes failed say revoked add pn else nodes connected say revoked add pn for int i 0 i nodes connected say revoked size i peer node pn nodes connected say revoked get i if pn is connected nodes disconnected say revoked add pn nodes connected say revoked remove i i continue return new peer node nodes connected say revoked to array new peer node nodes connected say revoked size nodes disconnected say revoked to array new peer node nodes disconnected say revoked size nodes failed say revoked to array new peer node nodes failed say revoked size peernode getnodessayblown peernode nodesconnectedsayrevoked peernode peernode nodesdisconnectedsayrevoked peernode peernode nodesfailedsayrevoked peernode peernode nodessayrevoked nodessaykeyrevoked toarray peernode nodessaykeyrevoked nodessayrevoked peernode nodessayrevoked nodessaykeyrevokedfailedtransfer nodesfailedsayrevoked nodesconnectedsayrevoked nodesconnectedsayrevoked peernode nodesconnectedsayrevoked isconnected nodesdisconnectedsayrevoked nodesconnectedsayrevoked peernode nodesconnectedsayrevoked toarray peernode nodesconnectedsayrevoked nodesdisconnectedsayrevoked toarray peernode nodesdisconnectedsayrevoked nodesfailedsayrevoked toarray peernode nodesfailedsayrevoked a peer node requests us to send the binary blob of the revocation key param m the message requesting the transfer param source the node requesting the transfer return true if we handled the message i e always public boolean handle request revocation message m final peer node source do we have the data file data update manager revocation checker get blob file if data null logger normal this peer source asked us for the blob file for the revocation key but we don t have it probably a race condition on reconnect hopefully we ll be asked again return true final long uid m get long dmt uid random access file wrapper raf try raf new random access file wrapper data r catch file not found exception e logger error this peer source asked us for the blob file for the revocation key we have downloaded it but don t have the file even though we did have it when we checked e e return true final partially received bulk prb long length try length raf size prb new partially received bulk update manager node getusm length node packet size raf true catch io exception e logger error this peer source asked us for the blob file for the revocation key we have downloaded it but we can t determine the file size e e return true final bulk transmitter bt try bt new bulk transmitter prb source uid false update manager ctr catch disconnected exception e logger error this peer source asked us for the blob file for the revocation key then disconnected e e return true final runnable r new runnable public void run if bt send logger error this failed to send revocation key blob to source user to string bt get cancel reason else logger normal this sent revocation key blob to source user to string message msg dmt createuom sending revocation uid length update manager revocationuri to string try source send async msg new async message callback public void acknowledged if logminor logger minor this sending data send the data update manager node executor execute r revocation key send for uid to source user to string public void disconnected argh logger error this peer source asked us for the blob file for the revocation key then disconnected when we tried to send the uom sending revocation public void fatal error argh logger error this peer source asked us for the blob file for the revocation key then got a fatal error when we tried to send the uom sending revocation public void sent if logminor logger minor this message sent data soon override public string to string return super to string uid source get peer update manager ctr catch not connected exception e logger error this peer source asked us for the blob file for the revocation key then disconnected when we tried to send the uom sending revocation e e return true return true handlerequestrevocation peernode updatemanager revocationchecker getblobfile getlong randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size ioexception bulktransmitter bulktransmitter updatemanager disconnectedexception usertostring getcancelreason usertostring createuomsendingrevocation updatemanager tostring sendasync asyncmessagecallback updatemanager usertostring uomsendingrevocation fatalerror uomsendingrevocation tostring tostring getpeer updatemanager notconnectedexception uomsendingrevocation public void run if bt send logger error this failed to send revocation key blob to source user to string bt get cancel reason else logger normal this sent revocation key blob to source user to string usertostring getcancelreason usertostring public void acknowledged if logminor logger minor this sending data send the data update manager node executor execute r revocation key send for uid to source user to string updatemanager usertostring public void disconnected argh logger error this peer source asked us for the blob file for the revocation key then disconnected when we tried to send the uom sending revocation uomsendingrevocation public void fatal error argh logger error this peer source asked us for the blob file for the revocation key then got a fatal error when we tried to send the uom sending revocation fatalerror uomsendingrevocation public void sent if logminor logger minor this message sent data soon override public string to string return super to string uid source get peer tostring tostring getpeer public boolean handle sending revocation message m final peer node source final long uid m get long dmt uid final long length m get long dmt file length string key m get string dmt revocation key freeneturi revocationuri try revocationuri new freeneturi key catch malformedurl exception e logger error this failed receiving recovation because uri not parsable e for key e system err println failed receiving recovation because uri not parsable e for key e print stack trace synchronized this wierd case of a failed transfer nodes say key revoked failed transfer add source cancel send source uid return true if revocationuri equals update manager revocationuri system err println node sending us a revocation certificate from the wrong uri n node source user to string n our uri update manager revocationuri n their uri revocationuri synchronized this wierd case of a failed transfer nodes say key revoked failed transfer add source cancel send source uid return true if update manager is blown if logminor logger minor this already blown so not receiving from source uid cancel send source uid return true if length node update manager max revocation key length system err println node source user to string offered us a revocation certificate size util format size length long this is unacceptably long so we have refused the transfer logger error this node source user to string offered us a revocation certificate size util format size length long this is unacceptably long so we have refused the transfer synchronized update over mandatory manager this nodes say key revoked failed transfer add source cancel send source uid return true okay we can receive it final file temp try temp file create temp file revocation fblob tmp update manager node client core get persistent temp dir temp delete on exit catch io exception e system err println cannot save revocation certificate to disk and therefore cannot fetch it from our peer e e print stack trace update manager blow cannot fetch the revocation certificate from our peer because we cannot write it to disk e cancel send source uid return true random access file wrapper raf try raf new random access file wrapper temp rw catch file not found exception e logger error this peer source asked us for the blob file for the revocation key we have downloaded it but don t have the file even though we did have it when we checked e e return true partially received bulk prb new partially received bulk update manager node getusm length node packet size raf false final bulk receiver br new bulk receiver prb source uid update manager ctr update manager node executor execute new runnable public void run if br receive success process revocation blob temp source else logger error this failed to transfer revocation certificate from source system err println failed to transfer revocation certificate from source synchronized update over mandatory manager this nodes say key revoked failed transfer add source revocation key receive for uid from source user to string return true handlesendingrevocation peernode getlong getlong file_length getstring revocation_key malformedurlexception printstacktrace nodessaykeyrevokedfailedtransfer cancelsend updatemanager usertostring updatemanager nodessaykeyrevokedfailedtransfer cancelsend updatemanager isblown cancelsend nodeupdatemanager max_revocation_key_length usertostring sizeutil formatsize usertostring sizeutil formatsize updateovermandatorymanager nodessaykeyrevokedfailedtransfer cancelsend createtempfile updatemanager clientcore getpersistenttempdir deleteonexit ioexception printstacktrace updatemanager cancelsend randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size bulkreceiver bulkreceiver updatemanager updatemanager processrevocationblob updateovermandatorymanager nodessaykeyrevokedfailedtransfer usertostring public void run if br receive success process revocation blob temp source else logger error this failed to transfer revocation certificate from source system err println failed to transfer revocation certificate from source synchronized update over mandatory manager this nodes say key revoked failed transfer add source processrevocationblob updateovermandatorymanager nodessaykeyrevokedfailedtransfer process a binary blob for a revocation certificate the revocation key param temp the file it was written to protected void process revocation blob final file temp final peer node source simple block set blocks new simple block set data input stream dis null try dis new data input stream new buffered input stream new file input stream temp binary blob read binary blob dis blocks true catch file not found exception e logger error this somebody deleted temp we lost the revocation certificate from source user to string system err println somebody deleted temp we lost the revocation certificate from source user to string update manager blow somebody deleted temp we lost the revocation certificate from source user to string return catch io exception e logger error this could not read revocation cert from temp file temp from node source user to string system err println could not read revocation cert from temp file temp from node source user to string update manager blow could not read revocation cert from temp file temp from node source user to string fixme will be kept until exit for debugging purposes return catch binary blob format exception e logger error this peer source user to string sent us an invalid revocation certificate e data in temp e system err println peer source user to string sent us an invalid revocation certificate e data in temp probably malicious might just be buggy either way it s not blown e print stack trace synchronized update over mandatory manager this nodes say key revoked failed transfer add source fixme file will be kept until exit for debugging purposes return finally if dis null try dis close catch io exception e ignore fetch our revocation key from the datastore plus the binary blob fetch context seed context update manager node client core make client short 0 true get fetch context fetch context temp context new fetch context seed context fetch context identical mask true blocks temp context local request only true file f file bucket b null try f file create temp file revocation fblob tmp update manager node client core get persistent temp dir b new file bucket f false false true true true catch io exception e logger error this cannot share revocation key from source user to string with our peers because cannot write the cleaned version to disk e e system err println cannot share revocation key from source user to string with our peers because cannot write the cleaned version to disk e e print stack trace b null f null final file bucket cleaned blob b final file cleaned blob file f client callback my callback new client callback public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of revocation certificate from source user to string system err println cancelled fetch from store blob of revocation certificate from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal blown somebody inserted a revocation message but it was corrupt as inserted however it had valid signatures etc system err println got revocation certificate from source user to string fatal error i e someone with the key inserted bad data blow the update and propagate the revocation certificate update manager revocation checker on failure e state cleaned blob file temp delete insert blob update manager revocation checker get blob file revocation else logger error this failed to fetch revocation certificate from blob from source user to string system err println failed to fetch revocation certificate from blob from source user to string synchronized update over mandatory manager this nodes say key revoked failed transfer add source public void on failure insert exception e base client putter state object container container ignore not possible public void on fetchable base client putter state object container container irrelevant public void on generateduri freeneturi uri base client putter state object container container ignore not possible public void on major progress object container container ignore public void on success fetch result result client getter state object container container system err println got revocation certificate from source user to string update manager revocation checker on success result state cleaned blob file temp delete insert blob update manager revocation checker get blob file revocation public void on success base client putter state object container container ignore not possible client getter cg new client getter my callback update manager revocationuri temp context short 0 this null cleaned blob try update manager node client core client context start cg catch fetch exception e1 system err println failed to decode uom blob e1 e1 print stack trace my callback on failure e1 cg null processrevocationblob peernode simpleblockset simpleblockset datainputstream datainputstream bufferedinputstream fileinputstream binaryblob readbinaryblob filenotfoundexception usertostring usertostring updatemanager usertostring ioexception usertostring usertostring updatemanager usertostring binaryblobformatexception usertostring usertostring printstacktrace updateovermandatorymanager nodessaykeyrevokedfailedtransfer ioexception fetchcontext seedcontext updatemanager clientcore makeclient getfetchcontext fetchcontext tempcontext fetchcontext seedcontext fetchcontext identical_mask tempcontext localrequestonly filebucket createtempfile updatemanager clientcore getpersistenttempdir filebucket ioexception usertostring usertostring printstacktrace filebucket cleanedblob cleanedblobfile clientcallback mycallback clientcallback onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring updatemanager revocationchecker onfailure cleanedblobfile insertblob updatemanager revocationchecker getblobfile usertostring usertostring updateovermandatorymanager nodessaykeyrevokedfailedtransfer onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer onsuccess fetchresult clientgetter objectcontainer usertostring updatemanager revocationchecker onsuccess cleanedblobfile insertblob updatemanager revocationchecker getblobfile onsuccess baseclientputter objectcontainer clientgetter clientgetter mycallback updatemanager tempcontext cleanedblob updatemanager clientcore clientcontext fetchexception printstacktrace mycallback onfailure public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of revocation certificate from source user to string system err println cancelled fetch from store blob of revocation certificate from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal blown somebody inserted a revocation message but it was corrupt as inserted however it had valid signatures etc system err println got revocation certificate from source user to string fatal error i e someone with the key inserted bad data blow the update and propagate the revocation certificate update manager revocation checker on failure e state cleaned blob file temp delete insert blob update manager revocation checker get blob file revocation else logger error this failed to fetch revocation certificate from blob from source user to string system err println failed to fetch revocation certificate from blob from source user to string synchronized update over mandatory manager this nodes say key revoked failed transfer add source onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring updatemanager revocationchecker onfailure cleanedblobfile insertblob updatemanager revocationchecker getblobfile usertostring usertostring updateovermandatorymanager nodessaykeyrevokedfailedtransfer public void on failure insert exception e base client putter state object container container ignore not possible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container irrelevant onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore not possible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container system err println got revocation certificate from source user to string update manager revocation checker on success result state cleaned blob file temp delete insert blob update manager revocation checker get blob file revocation onsuccess fetchresult clientgetter objectcontainer usertostring updatemanager revocationchecker onsuccess cleanedblobfile insertblob updatemanager revocationchecker getblobfile public void on success base client putter state object container container ignore not possible onsuccess baseclientputter objectcontainer protected void insert blob final file blob final string type client callback callback new client callback public void on failure fetch exception e client getter state object container container ignore can t happen public void on failure insert exception e base client putter state object container container logger error this failed to insert type binary blob e e public void on fetchable base client putter state object container container ignore public void on generateduri freeneturi uri base client putter state object container container ignore public void on major progress object container container ignore public void on success fetch result result client getter state object container container ignore can t happen public void on success base client putter state object container container all done cool logger normal this inserted type binary blob file bucket bucket new file bucket blob true false false false false client putter putter new client putter callback bucket freeneturi empty chk uri null update manager node client core make client request starter interactive priority class get insert context true request starter interactive priority class false false this null null true try update manager node client core client context start putter false catch insert exception e1 logger error this failed to start insert of type binary blob e1 e1 insertblob clientcallback clientcallback onfailure fetchexception clientgetter objectcontainer onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer onsuccess fetchresult clientgetter objectcontainer onsuccess baseclientputter objectcontainer filebucket filebucket clientputter clientputter empty_chk_uri updatemanager clientcore makeclient requeststarter interactive_priority_class getinsertcontext requeststarter interactive_priority_class updatemanager clientcore clientcontext insertexception client callback callback new client callback public void on failure fetch exception e client getter state object container container ignore can t happen clientcallback clientcallback onfailure fetchexception clientgetter objectcontainer public void on failure insert exception e base client putter state object container container logger error this failed to insert type binary blob e e onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container ignore onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container ignore can t happen onsuccess fetchresult clientgetter objectcontainer public void on success base client putter state object container container all done cool logger normal this inserted type binary blob onsuccess baseclientputter objectcontainer private void cancel send peer node source long uid message msg dmt createfnp bulk receive aborted uid try source send async msg null update manager ctr catch not connected exception e1 ignore cancelsend peernode createfnpbulkreceiveaborted sendasync updatemanager notconnectedexception public void kill alert update manager node client core alerts unregister alert killalert updatemanager clientcore public boolean handle request jar message m final peer node source boolean is ext do we have the data int version is ext update manager new ext jar version update manager new main jar version file data is ext update manager get ext blob version update manager get main blob version final string name is ext ext main if data null logger normal this peer source asked us for the blob file for the name jar but we don t have it probably a race condition on reconnect hopefully we ll be asked again return true final long uid m get long dmt uid random access file wrapper raf try raf new random access file wrapper data r catch file not found exception e logger error this peer source asked us for the blob file for the name jar we have downloaded it but don t have the file even though we did have it when we checked e e return true final partially received bulk prb long length try length raf size prb new partially received bulk update manager node getusm length node packet size raf true catch io exception e logger error this peer source asked us for the blob file for the name jar we have downloaded it but we can t determine the file size e e return true final bulk transmitter bt try bt new bulk transmitter prb source uid false update manager ctr catch disconnected exception e logger error this peer source asked us for the blob file for the name jar then disconnected e e return true final runnable r new runnable public void run if bt send logger error this failed to send name jar blob to source user to string bt get cancel reason else logger normal this sent name jar blob to source user to string message msg is ext dmt createuom sending extra uid length update manager exturi to string version dmt createuom sending main uid length update manager updateuri to string version try source send async msg new async message callback public void acknowledged if logminor logger minor this sending data send the data update manager node executor execute r name jar send for uid to source user to string public void disconnected argh logger error this peer source asked us for the blob file for the name jar then disconnected when we tried to send the uom sending main public void fatal error argh logger error this peer source asked us for the blob file for the name jar then got a fatal error when we tried to send the uom sending main public void sent if logminor logger minor this message sent data soon override public string to string return super to string uid source get peer update manager ctr catch not connected exception e logger error this peer source asked us for the blob file for the name jar then disconnected when we tried to send the uom sending ext e e return true return true handlerequestjar peernode isext isext updatemanager newextjarversion updatemanager newmainjarversion isext updatemanager getextblob updatemanager getmainblob isext getlong randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size ioexception bulktransmitter bulktransmitter updatemanager disconnectedexception usertostring getcancelreason usertostring isext createuomsendingextra updatemanager tostring createuomsendingmain updatemanager tostring sendasync asyncmessagecallback updatemanager usertostring uomsendingmain fatalerror uomsendingmain tostring tostring getpeer updatemanager notconnectedexception uomsendingext public void run if bt send logger error this failed to send name jar blob to source user to string bt get cancel reason else logger normal this sent name jar blob to source user to string usertostring getcancelreason usertostring public void acknowledged if logminor logger minor this sending data send the data update manager node executor execute r name jar send for uid to source user to string updatemanager usertostring public void disconnected argh logger error this peer source asked us for the blob file for the name jar then disconnected when we tried to send the uom sending main uomsendingmain public void fatal error argh logger error this peer source asked us for the blob file for the name jar then got a fatal error when we tried to send the uom sending main fatalerror uomsendingmain public void sent if logminor logger minor this message sent data soon override public string to string return super to string uid source get peer tostring tostring getpeer public boolean handle sending main message m final peer node source final long uid m get long dmt uid final long length m get long dmt file length string key m get string dmt main jar key final int version m get int dmt main jar version final freeneturi jaruri try jaruri new freeneturi key set suggested edition version catch malformedurl exception e logger error this failed receiving main jar version because uri not parsable e for key e system err println failed receiving main jar version because uri not parsable e for key e print stack trace cancel send source uid synchronized this this nodes asked send main jar remove source return true if jaruri equals update manager updateuri set suggested edition version system err println node sending us a main jar update version from the wrong uri n node source user to string n our uri update manager updateuri n their uri jaruri cancel send source uid synchronized this this nodes asked send main jar remove source return true if update manager is blown if logminor logger minor this key blown so not receiving main jar from source uid cancel send source uid synchronized this this nodes asked send main jar remove source return true if length node update manager max main jar length system err println node source user to string offered us a main jar version size util format size length long this is unacceptably long so we have refused the transfer logger error this node source user to string offered us a main jar version size util format size length long this is unacceptably long so we have refused the transfer if the transfer fails we don t try again cancel send source uid synchronized this this nodes asked send main jar remove source return true okay we can receive it final file temp try temp file create temp file main fblob tmp update manager node client core get persistent temp dir temp delete on exit catch io exception e system err println cannot save new main jar to disk and therefore cannot fetch it from our peer e e print stack trace cancel send source uid synchronized this this nodes asked send main jar remove source return true random access file wrapper raf try raf new random access file wrapper temp rw catch file not found exception e logger error this peer source sending us a main jar binary blob but we lost the temp file temp e e synchronized this this nodes asked send main jar remove source return true partially received bulk prb new partially received bulk update manager node getusm length node packet size raf false final bulk receiver br new bulk receiver prb source uid update manager ctr update manager node executor execute new runnable public void run try synchronized update over mandatory manager class nodes asked send main jar remove source nodes sending main jar add source if br receive success process main jar blob temp source version jaruri else logger error this failed to transfer main jar version from source system err println failed to transfer main jar version from source finally synchronized update over mandatory manager class nodes sending main jar remove source main jar version receive for uid from source user to string return true handlesendingmain peernode getlong getlong file_length getstring main_jar_key getint main_jar_version setsuggestededition malformedurlexception printstacktrace cancelsend nodesaskedsendmainjar updatemanager setsuggestededition usertostring updatemanager cancelsend nodesaskedsendmainjar updatemanager isblown cancelsend nodesaskedsendmainjar nodeupdatemanager max_main_jar_length usertostring sizeutil formatsize usertostring sizeutil formatsize cancelsend nodesaskedsendmainjar createtempfile updatemanager clientcore getpersistenttempdir deleteonexit ioexception printstacktrace cancelsend nodesaskedsendmainjar randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception nodesaskedsendmainjar partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size bulkreceiver bulkreceiver updatemanager updatemanager updateovermandatorymanager nodesaskedsendmainjar nodessendingmainjar processmainjarblob updateovermandatorymanager nodessendingmainjar usertostring public void run try synchronized update over mandatory manager class nodes asked send main jar remove source nodes sending main jar add source if br receive success process main jar blob temp source version jaruri else logger error this failed to transfer main jar version from source system err println failed to transfer main jar version from source finally synchronized update over mandatory manager class nodes sending main jar remove source updateovermandatorymanager nodesaskedsendmainjar nodessendingmainjar processmainjarblob updateovermandatorymanager nodessendingmainjar public boolean handle sending ext message m final peer node source final long uid m get long dmt uid final long length m get long dmt file length string key m get string dmt extra jar key final int version m get int dmt extra jar version final freeneturi jaruri try jaruri new freeneturi key set suggested edition version catch malformedurl exception e logger error this failed receiving ext jar version because uri not parsable e for key e system err println failed receiving ext jar version because uri not parsable e for key e print stack trace cancel send source uid synchronized this this nodes asked send ext jar remove source return true if jaruri equals update manager exturi set suggested edition version system err println node sending us a ext jar update version from the wrong uri n node source user to string n our uri update manager exturi n their uri jaruri cancel send source uid synchronized this this nodes asked send ext jar remove source return true if update manager is blown if logminor logger minor this key blown so not receiving main jar from source uid cancel send source uid synchronized this this nodes asked send ext jar remove source return true if length node update manager max main jar length system err println node source user to string offered us a ext jar version size util format size length long this is unacceptably long so we have refused the transfer logger error this node source user to string offered us a ext jar version size util format size length long this is unacceptably long so we have refused the transfer if the transfer fails we don t try again cancel send source uid synchronized this this nodes asked send ext jar remove source return true okay we can receive it final file temp try temp file create temp file ext fblob tmp update manager node client core get persistent temp dir temp delete on exit catch io exception e system err println cannot save new ext jar to disk and therefore cannot fetch it from our peer e e print stack trace cancel send source uid synchronized this this nodes asked send ext jar remove source return true random access file wrapper raf try raf new random access file wrapper temp rw catch file not found exception e logger error this peer source sending us a ext jar binary blob but we lost the temp file temp e e synchronized this this nodes asked send ext jar remove source return true partially received bulk prb new partially received bulk update manager node getusm length node packet size raf false final bulk receiver br new bulk receiver prb source uid update manager ctr update manager node executor execute new runnable public void run try synchronized update over mandatory manager class nodes asked send ext jar remove source nodes sending ext jar add source if br receive success process ext jar blob temp source version jaruri else logger error this failed to transfer ext jar version from source system err println failed to transfer ext jar version from source finally synchronized update over mandatory manager class nodes sending ext jar remove source ext jar version receive for uid from source user to string return true handlesendingext peernode getlong getlong file_length getstring extra_jar_key getint extra_jar_version setsuggestededition malformedurlexception printstacktrace cancelsend nodesaskedsendextjar updatemanager setsuggestededition usertostring updatemanager cancelsend nodesaskedsendextjar updatemanager isblown cancelsend nodesaskedsendextjar nodeupdatemanager max_main_jar_length usertostring sizeutil formatsize usertostring sizeutil formatsize cancelsend nodesaskedsendextjar createtempfile updatemanager clientcore getpersistenttempdir deleteonexit ioexception printstacktrace cancelsend nodesaskedsendextjar randomaccessfilewrapper randomaccessfilewrapper filenotfoundexception nodesaskedsendextjar partiallyreceivedbulk partiallyreceivedbulk updatemanager packet_size bulkreceiver bulkreceiver updatemanager updatemanager updateovermandatorymanager nodesaskedsendextjar nodessendingextjar processextjarblob updateovermandatorymanager nodessendingextjar usertostring public void run try synchronized update over mandatory manager class nodes asked send ext jar remove source nodes sending ext jar add source if br receive success process ext jar blob temp source version jaruri else logger error this failed to transfer ext jar version from source system err println failed to transfer ext jar version from source finally synchronized update over mandatory manager class nodes sending ext jar remove source updateovermandatorymanager nodesaskedsendextjar nodessendingextjar processextjarblob updateovermandatorymanager nodessendingextjar protected void process main jar blob final file temp final peer node source final int version freeneturi uri simple block set blocks new simple block set data input stream dis null try dis new data input stream new buffered input stream new file input stream temp binary blob read binary blob dis blocks true catch file not found exception e logger error this somebody deleted temp we lost the main jar version from source user to string system err println somebody deleted temp we lost the main jar version from source user to string return catch io exception e logger error this could not read main jar version from temp file temp from node source user to string system err println could not read main jar version from temp file temp from node source user to string fixme will be kept until exit for debugging purposes return catch binary blob format exception e logger error this peer source user to string sent us an invalid main jar version e e system err println peer source user to string sent us an invalid main jar version e e print stack trace fixme will be kept until exit for debugging purposes return finally if dis null try dis close catch io exception e ignore fetch the jar from the datastore plus the binary blob fetch context seed context update manager node client core make client short 0 true get fetch context fetch context temp context new fetch context seed context fetch context identical mask true blocks temp context local request only true file f file bucket b null try f file create temp file main fblob tmp update manager node client core get persistent temp dir f delete on exit b new file bucket f false false true true true catch io exception e logger error this cannot share main jar from source user to string with our peers because cannot write the cleaned version to disk e e system err println cannot share main jar from source user to string with our peers because cannot write the cleaned version to disk e e print stack trace b null f null final file bucket cleaned blob b final file cleaned blob file f client callback my callback new client callback public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of main jar version from source user to string system err println cancelled fetch from store blob of main jar version from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal bogus as inserted ignore temp delete logger error this failed to fetch main jar version from source user to string fatal error update was probably inserted badly e e system err println failed to fetch main jar version from source user to string fatal error update was probably inserted badly e else logger error this failed to fetch main jar version from blob from source user to string system err println failed to fetch main jar version from blob from source user to string public void on failure insert exception e base client putter state object container container ignore not possible public void on fetchable base client putter state object container container irrelevant public void on generateduri freeneturi uri base client putter state object container container ignore not possible public void on major progress object container container ignore public void on success fetch result result client getter state object container container system err println got main jar version version from source user to string if result size 0 system err println ignoring because 0 bytes long return node updater main updater update manager main updater if main updater null system err println not updating because updater is disabled return main updater on success result state cleaned blob file version temp delete insert blob main updater get blob file version main jar public void on success base client putter state object container container ignore not possible client getter cg new client getter my callback uri temp context short 0 this null cleaned blob try update manager node client core client context start cg catch fetch exception e1 my callback on failure e1 cg null processmainjarblob peernode simpleblockset simpleblockset datainputstream datainputstream bufferedinputstream fileinputstream binaryblob readbinaryblob filenotfoundexception usertostring usertostring ioexception usertostring usertostring binaryblobformatexception usertostring usertostring printstacktrace ioexception fetchcontext seedcontext updatemanager clientcore makeclient getfetchcontext fetchcontext tempcontext fetchcontext seedcontext fetchcontext identical_mask tempcontext localrequestonly filebucket createtempfile updatemanager clientcore getpersistenttempdir deleteonexit filebucket ioexception usertostring usertostring printstacktrace filebucket cleanedblob cleanedblobfile clientcallback mycallback clientcallback onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring usertostring usertostring usertostring onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer onsuccess fetchresult clientgetter objectcontainer usertostring nodeupdater mainupdater updatemanager mainupdater mainupdater mainupdater onsuccess cleanedblobfile insertblob mainupdater getblobfile onsuccess baseclientputter objectcontainer clientgetter clientgetter mycallback tempcontext cleanedblob updatemanager clientcore clientcontext fetchexception mycallback onfailure public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of main jar version from source user to string system err println cancelled fetch from store blob of main jar version from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal bogus as inserted ignore temp delete logger error this failed to fetch main jar version from source user to string fatal error update was probably inserted badly e e system err println failed to fetch main jar version from source user to string fatal error update was probably inserted badly e else logger error this failed to fetch main jar version from blob from source user to string system err println failed to fetch main jar version from blob from source user to string onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring usertostring usertostring usertostring public void on failure insert exception e base client putter state object container container ignore not possible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container irrelevant onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore not possible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container system err println got main jar version version from source user to string if result size 0 system err println ignoring because 0 bytes long return node updater main updater update manager main updater if main updater null system err println not updating because updater is disabled return main updater on success result state cleaned blob file version temp delete insert blob main updater get blob file version main jar onsuccess fetchresult clientgetter objectcontainer usertostring nodeupdater mainupdater updatemanager mainupdater mainupdater mainupdater onsuccess cleanedblobfile insertblob mainupdater getblobfile public void on success base client putter state object container container ignore not possible onsuccess baseclientputter objectcontainer protected void process ext jar blob final file temp final peer node source final int version freeneturi uri simple block set blocks new simple block set data input stream dis null try dis new data input stream new buffered input stream new file input stream temp binary blob read binary blob dis blocks true catch file not found exception e logger error this somebody deleted temp we lost the ext jar version from source user to string system err println somebody deleted temp we lost the ext jar version from source user to string return catch io exception e logger error this could not read ext jar version from temp file temp from node source user to string system err println could not read ext jar version from temp file temp from node source user to string fixme will be kept until exit for debugging purposes return catch binary blob format exception e logger error this peer source user to string sent us an invalid ext jar version e e system err println peer source user to string sent us an invalid ext jar version e e print stack trace fixme will be kept until exit for debugging purposes return finally if dis null try dis close catch io exception e ignore fetch the jar from the datastore plus the binary blob fetch context seed context update manager node client core make client short 0 true get fetch context fetch context temp context new fetch context seed context fetch context identical mask true blocks temp context local request only true file f file bucket b null try f file create temp file ext fblob tmp update manager node client core get persistent temp dir f delete on exit b new file bucket f false false true true true catch io exception e logger error this cannot share ext jar from source user to string with our peers because cannot write the cleaned version to disk e e system err println cannot share ext jar from source user to string with our peers because cannot write the cleaned version to disk e e print stack trace b null f null final file bucket cleaned blob b final file cleaned blob file f client callback my callback new client callback public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of ext jar version from source user to string system err println cancelled fetch from store blob of ext jar version from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal bogus as inserted ignore temp delete logger error this failed to fetch ext jar version from source user to string fatal error update was probably inserted badly e e system err println failed to fetch ext jar version from source user to string fatal error update was probably inserted badly e else logger error this failed to fetch ext jar version from blob from source user to string system err println failed to fetch ext jar version from blob from source user to string public void on failure insert exception e base client putter state object container container ignore not possible public void on fetchable base client putter state object container container irrelevant public void on generateduri freeneturi uri base client putter state object container container ignore not possible public void on major progress object container container ignore public void on success fetch result result client getter state object container container system err println got ext jar version version from source user to string if result size 0 system err println ignoring because 0 bytes long return node updater ext updater update manager ext updater if ext updater null system err println not updating because ext updater is disabled return ext updater on success result state cleaned blob file version temp delete insert blob ext updater get blob file version ext jar public void on success base client putter state object container container ignore not possible client getter cg new client getter my callback uri temp context short 0 this null cleaned blob try update manager node client core client context start cg catch fetch exception e1 my callback on failure e1 cg null processextjarblob peernode simpleblockset simpleblockset datainputstream datainputstream bufferedinputstream fileinputstream binaryblob readbinaryblob filenotfoundexception usertostring usertostring ioexception usertostring usertostring binaryblobformatexception usertostring usertostring printstacktrace ioexception fetchcontext seedcontext updatemanager clientcore makeclient getfetchcontext fetchcontext tempcontext fetchcontext seedcontext fetchcontext identical_mask tempcontext localrequestonly filebucket createtempfile updatemanager clientcore getpersistenttempdir deleteonexit filebucket ioexception usertostring usertostring printstacktrace filebucket cleanedblob cleanedblobfile clientcallback mycallback clientcallback onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring usertostring usertostring usertostring onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer onsuccess fetchresult clientgetter objectcontainer usertostring nodeupdater extupdater updatemanager extupdater extupdater extupdater onsuccess cleanedblobfile insertblob extupdater getblobfile onsuccess baseclientputter objectcontainer clientgetter clientgetter mycallback tempcontext cleanedblob updatemanager clientcore clientcontext fetchexception mycallback onfailure public void on failure fetch exception e client getter state object container container if e mode fetch exception cancelled eh logger error this cancelled fetch from store blob of ext jar version from source user to string system err println cancelled fetch from store blob of ext jar version from source user to string to temp please report to developers probably best to keep files around for now else if e is fatal bogus as inserted ignore temp delete logger error this failed to fetch ext jar version from source user to string fatal error update was probably inserted badly e e system err println failed to fetch ext jar version from source user to string fatal error update was probably inserted badly e else logger error this failed to fetch ext jar version from blob from source user to string system err println failed to fetch ext jar version from blob from source user to string onfailure fetchexception clientgetter objectcontainer fetchexception usertostring usertostring isfatal usertostring usertostring usertostring usertostring public void on failure insert exception e base client putter state object container container ignore not possible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container irrelevant onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore not possible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container system err println got ext jar version version from source user to string if result size 0 system err println ignoring because 0 bytes long return node updater ext updater update manager ext updater if ext updater null system err println not updating because ext updater is disabled return ext updater on success result state cleaned blob file version temp delete insert blob ext updater get blob file version ext jar onsuccess fetchresult clientgetter objectcontainer usertostring nodeupdater extupdater updatemanager extupdater extupdater extupdater onsuccess cleanedblobfile insertblob extupdater getblobfile public void on success base client putter state object container container ignore not possible onsuccess baseclientputter objectcontainer protected boolean remove old temp files file old temp files peer dir update manager node client core get persistent temp dir if old temp files peer dir exists return false if old temp files peer dir is directory logger error this persistent temporary files location is not a directory old temp files peer dir get path return false boolean got error false file old temp files old temp files peer dir list files new file filter private final int last good main build number version last good build private final int recommended ext build number node starter recommended ext build number public boolean accept file file string file name file get name if file name starts with revocation file name ends with fblob tmp return true string build number str int build number matcher ext build number matcher ext build number pattern matcher file name matcher main build number matcher main build number pattern matcher file name matcher ext temp build number matcher ext temp build number pattern matcher file name matcher main temp build number matcher main temp build number pattern matcher file name matcher revocation temp build number matcher revocation temp build number pattern matcher file name if main build number matcher matches try build number str main build number matcher group 1 build number integer parse int build number str if build number last good main build number return true catch number format exception e logger error this wierd file in persistent temp file name return false else if ext build number matcher matches try build number str ext build number matcher group 1 build number integer parse int build number str if build number recommended ext build number return true catch number format exception e logger error this wierd file in persistent temp file name return false else if main temp build number matcher matches ext temp build number matcher matches revocation temp build number matcher matches temporary file can be deleted return true return false for file file to delete old temp files string file to delete name file to delete get name if file to delete delete if file to delete exists logger error this cannot delete temporary persistent file file to delete name even though it exists must be too persistent else logger normal this temporary persistent file does not exist when deleting file to delete name got error true return got error removeoldtempfiles oldtempfilespeerdir updatemanager clientcore getpersistenttempdir oldtempfilespeerdir oldtempfilespeerdir isdirectory oldtempfilespeerdir getpath goterror oldtempfiles oldtempfilespeerdir listfiles filefilter lastgoodmainbuildnumber lastgoodbuild recommendedextbuildnumber nodestarter recommended_ext_build_number filename getname filename startswith filename endswith buildnumberstr buildnumber extbuildnumbermatcher extbuildnumberpattern filename mainbuildnumbermatcher mainbuildnumberpattern filename exttempbuildnumbermatcher exttempbuildnumberpattern filename maintempbuildnumbermatcher maintempbuildnumberpattern filename revocationtempbuildnumbermatcher revocationtempbuildnumberpattern filename mainbuildnumbermatcher buildnumberstr mainbuildnumbermatcher buildnumber parseint buildnumberstr buildnumber lastgoodmainbuildnumber numberformatexception filename extbuildnumbermatcher buildnumberstr extbuildnumbermatcher buildnumber parseint buildnumberstr buildnumber recommendedextbuildnumber numberformatexception filename maintempbuildnumbermatcher exttempbuildnumbermatcher revocationtempbuildnumbermatcher filetodelete oldtempfiles filetodeletename filetodelete getname filetodelete filetodelete filetodeletename filetodeletename goterror goterror public boolean accept file file string file name file get name if file name starts with revocation file name ends with fblob tmp return true string build number str int build number matcher ext build number matcher ext build number pattern matcher file name matcher main build number matcher main build number pattern matcher file name matcher ext temp build number matcher ext temp build number pattern matcher file name matcher main temp build number matcher main temp build number pattern matcher file name matcher revocation temp build number matcher revocation temp build number pattern matcher file name if main build number matcher matches try build number str main build number matcher group 1 build number integer parse int build number str if build number last good main build number return true catch number format exception e logger error this wierd file in persistent temp file name return false else if ext build number matcher matches try build number str ext build number matcher group 1 build number integer parse int build number str if build number recommended ext build number return true catch number format exception e logger error this wierd file in persistent temp file name return false else if main temp build number matcher matches ext temp build number matcher matches revocation temp build number matcher matches temporary file can be deleted return true return false filename getname filename startswith filename endswith buildnumberstr buildnumber extbuildnumbermatcher extbuildnumberpattern filename mainbuildnumbermatcher mainbuildnumberpattern filename exttempbuildnumbermatcher exttempbuildnumberpattern filename maintempbuildnumbermatcher maintempbuildnumberpattern filename revocationtempbuildnumbermatcher revocationtempbuildnumberpattern filename mainbuildnumbermatcher buildnumberstr mainbuildnumbermatcher buildnumber parseint buildnumberstr buildnumber lastgoodmainbuildnumber numberformatexception filename extbuildnumbermatcher buildnumberstr extbuildnumbermatcher buildnumber parseint buildnumberstr buildnumber recommendedextbuildnumber numberformatexception filename maintempbuildnumbermatcher exttempbuildnumbermatcher revocationtempbuildnumbermatcher public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public static void main string args throws exception system out println routing test using real nodes system out println string dir real node request insert test file wd new file dir if file util remove all wd system err println mass delete failed test may not be accurate system exit exit cannot delete old data wd mkdir note global test init returns in ignored random source node starter global test init dir false logger error true dummy random source random new dummy random source diffie hellman init random node nodes new node number of nodes logger normal real node routing test class creating nodes executor executor new pooled executor for int i 0 i number of nodes i system err println creating node i nodes i node starter create test node 5001 i 0 dir false true true max htl 0 no dropped packets random executor 500 number of nodes 65536 true enable swapping false false false enable swap queueing true 0 enable foaf false null logger normal real node routing test class created node i logger normal real node routing test class created number of nodes nodes now link them up make kleinberg network nodes start with ideal locations degree force neighbour connections logger normal real node routing test class added random links for int i 0 i number of nodes i system err println starting node i nodes i start false wait for all connected nodes wait for ping average 0 98 nodes random max pings 5000 realnoderequestinserttest fileutil removeall exit_cannot_delete_old_data globaltestinit nodestarter globaltestinit dummyrandomsource dummyrandomsource diffiehellman number_of_nodes realnoderoutingtest pooledexecutor number_of_nodes nodestarter createtestnode max_htl number_of_nodes enable_swapping enable_swap_queueing enable_foaf realnoderoutingtest realnoderoutingtest number_of_nodes makekleinbergnetwork start_with_ideal_locations force_neighbour_connections realnoderoutingtest number_of_nodes waitforallconnected waitforpingaverage max_pings static void wait for ping average double accuracy node nodes random source random int max tests int sleep time throws interrupted exception int total hops taken 0 int cycle number 0 int last swaps 0 int last no swaps 0 int failures 0 int successes 0 running average avg new simple running average 100 0 0 running average avg2 new bootstrapping decaying running average 0 0 0 0 1 0 100 null int pings 0 for int total 0 total max tests total cycle number try thread sleep sleep time catch interrupted exception e ignore for int i 0 i nodes length i system err println cycle cycle number node i nodes i get location int new swaps location manager swaps int total started location manager started swaps int no swaps location manager no swaps system err println swaps new swaps last swaps system err println n total swaps started 2 total started 2 succeeded new swaps last minute failures no swaps ratio double no swaps double new swaps early failures total started 2 no swaps new swaps system err println this cycle ratio double no swaps last no swaps double new swaps last swaps last no swaps no swaps system err println swaps rejected already locked location manager swaps rejected already locked system err println swaps rejected nowhere to go location manager swaps rejected nowhere to go system err println swaps rejected rate limit location manager swaps rejected rate limit system err println swaps rejected recognized id location manager swaps rejected recognizedid system err println swaps failed location manager no swaps system err println swaps succeeded location manager swaps double total swap interval 0 0 double total swap time 0 0 for int i 0 i nodes length i total swap interval nodes i lm get send swap interval total swap time nodes i lm get average swap time system err println average swap time total swap time nodes length system err println average swap sender interval total swap interval nodes length wait for all connected nodes last swaps new swaps do some routed test pings for int i 0 i 10 i try thread sleep sleep time catch interrupted exception e1 try node random node nodes random next int nodes length node random node2 random node while random node2 random node random node2 nodes random next int nodes length double loc2 random node2 get location logger normal real node routing test class pinging random node2 get darknet port number loc2 from random node get darknet port number random node get location int hops taken random node routed ping loc2 random node2 get darknet identity pings if hops taken 0 failures avg report 0 0 avg2 report 0 0 double ratio double successes double failures successes system err println routed ping pings failed from random node get darknet port number to random node2 get darknet port number long ratio short avg current value vague avg2 current value else total hops taken hops taken successes avg report 1 0 avg2 report 1 0 double ratio double successes double failures successes system err println routed ping pings success hops taken random node get darknet port number to random node2 get darknet port number long ratio short avg current value vague avg2 current value catch throwable t logger error real node routing test class caught t t if pings 10 avg current value accuracy double successes double failures successes accuracy system err println system err println reached accuracy 100 accuracy system err println system err println network size nodes length system err println maximum htl max htl system err println average path length for successful requests total hops taken successes system err println total started swaps location manager started swaps system err println total rejected swaps already locked location manager swaps rejected already locked system err println total swaps rejected nowhere to go location manager swaps rejected nowhere to go system err println total swaps rejected rate limit location manager swaps rejected rate limit system err println total swaps rejected recognized id location manager swaps rejected recognizedid system err println total swaps failed location manager no swaps system err println total swaps succeeded location manager swaps return system exit exit ping target not reached waitforpingaverage randomsource maxtests sleeptime interruptedexception totalhopstaken cyclenumber lastswaps lastnoswaps runningaverage simplerunningaverage runningaverage bootstrappingdecayingrunningaverage maxtests cyclenumber sleeptime interruptedexception cyclenumber getlocation newswaps locationmanager totalstarted locationmanager startedswaps noswaps locationmanager noswaps newswaps lastswaps ntotal totalstarted newswaps noswaps noswaps newswaps totalstarted noswaps newswaps noswaps lastnoswaps newswaps lastswaps lastnoswaps noswaps locationmanager swapsrejectedalreadylocked locationmanager swapsrejectednowheretogo locationmanager swapsrejectedratelimit locationmanager swapsrejectedrecognizedid locationmanager noswaps locationmanager totalswapinterval totalswaptime totalswapinterval getsendswapinterval totalswaptime getaverageswaptime totalswaptime totalswapinterval waitforallconnected lastswaps newswaps sleeptime interruptedexception randomnode nextint randomnode2 randomnode randomnode2 randomnode randomnode2 nextint randomnode2 getlocation realnoderoutingtest randomnode2 getdarknetportnumber randomnode getdarknetportnumber randomnode getlocation hopstaken randomnode routedping randomnode2 getdarknetidentity hopstaken randomnode getdarknetportnumber randomnode2 getdarknetportnumber currentvalue currentvalue totalhopstaken hopstaken hopstaken randomnode getdarknetportnumber randomnode2 getdarknetportnumber currentvalue currentvalue realnoderoutingtest currentvalue max_htl totalhopstaken locationmanager startedswaps locationmanager swapsrejectedalreadylocked locationmanager swapsrejectednowheretogo locationmanager swapsrejectedratelimit locationmanager swapsrejectedrecognizedid locationmanager noswaps locationmanager exit_ping_target_not_reached logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog create from serialized form on a data input stream public freenet inet address data input dis throws io exception int first byte dis read unsigned byte byte ba if first byte 255 if logminor logger minor this new format i pv6 address new format i pv6 address ba new byte 16 dis read fully ba else if first byte 0 if logminor logger minor this new format i pv4 address new format i pv4 address ba new byte 4 dis read fully ba else throw new io exception unknown type byte old form corrupt stream too short long prev field first byte address inet address get by address ba string name null string s dis readutf if s length 0 name s hostname name datainputstream freenetinetaddress datainput ioexception firstbyte readunsignedbyte firstbyte ipv6 ipv6 readfully firstbyte ipv4 ipv4 readfully ioexception firstbyte _address inetaddress getbyaddress create from serialized form on a data input stream public freenet inet address data input dis boolean check hostname orip syntax throws hostname syntax exception io exception int first byte dis read unsigned byte byte ba if first byte 255 if logminor logger minor this new format i pv6 address new format i pv6 address ba new byte 16 dis read fully ba else if first byte 0 if logminor logger minor this new format i pv4 address new format i pv4 address ba new byte 4 dis read fully ba else old format i pv4 address ba new byte 4 ba 0 byte first byte dis read fully ba 1 3 address inet address get by address ba string name null string s dis readutf if s length 0 name s hostname name if check hostname orip syntax null hostname if hostname util is valid hostname hostname true throw new hostname syntax exception datainputstream freenetinetaddress datainput checkhostnameoripsyntax hostnamesyntaxexception ioexception firstbyte readunsignedbyte firstbyte ipv6 ipv6 readfully firstbyte ipv4 ipv4 readfully ipv4 firstbyte readfully _address inetaddress getbyaddress checkhostnameoripsyntax hostnameutil isvalidhostname hostnamesyntaxexception create from an inet address the ip address is primary i e fixed the hostname either doesn t exist or is looked up public freenet inet address inet address address address address hostname null inetaddress freenetinetaddress inetaddress _address public freenet inet address string host boolean allow unknown throws unknown host exception inet address addr null if host null if host starts with host host substring 1 host host trim if we were created with an explicit ip address use it as such debugging log messages because address identifier doesn t appear to handle all i pv6 literals correctly such as fe80 204 1234 dead beef address identifier address type address type address identifier get address type host if logdebug logger debug this address type of host appears to be address type if address type address identifier address type other is an ip address addr inet address get by name host don t catch unknown host exception here if it happens there s a bug in address identifier if logdebug logger debug this host is host and addr get host address is addr get host address if addr null host null else addr null if addr null if logdebug logger debug this host does not look like an ip address this address addr this hostname host we re created with a hostname so delay the lookup of the address until it s needed to work better with dynamic dns hostnames freenetinetaddress allowunknown unknownhostexception inetaddress startswith addressidentifier ipv6 addressidentifier addresstype addresstype addressidentifier getaddresstype addresstype addresstype addressidentifier addresstype inetaddress getbyname unknownhostexception addressidentifier gethostaddress gethostaddress _address public freenet inet address string host boolean allow unknown boolean check hostname orip syntax throws hostname syntax exception unknown host exception inet address addr null if host null if host starts with host host substring 1 host host trim if we were created with an explicit ip address use it as such debugging log messages because address identifier doesn t appear to handle all i pv6 literals correctly such as fe80 204 1234 dead beef address identifier address type address type address identifier get address type host if logdebug logger debug this address type of host appears to be address type if address type address identifier address type other try addr inet address get by name host catch unknown host exception e if allow unknown throw e addr null if logdebug logger debug this host is host and addr get host address is addr null addr get host address if addr null addr get host address equals host if logdebug logger debug this host looks like an ip address host null else addr null if addr null if logdebug logger debug this host does not look like an ip address this address addr this hostname host if check hostname orip syntax null this hostname if hostname util is valid hostname this hostname true throw new hostname syntax exception we re created with a hostname so delay the lookup of the address until it s needed to work better with dynamic dns hostnames freenetinetaddress allowunknown checkhostnameoripsyntax hostnamesyntaxexception unknownhostexception inetaddress startswith addressidentifier ipv6 addressidentifier addresstype addresstype addressidentifier getaddresstype addresstype addresstype addressidentifier addresstype inetaddress getbyname unknownhostexception allowunknown gethostaddress gethostaddress gethostaddress _address checkhostnameoripsyntax hostnameutil isvalidhostname hostnamesyntaxexception override public boolean equals object o if o instanceof freenet inet address return false freenet inet address addr freenet inet address o if hostname null if addr hostname null return false if hostname equals ignore case addr hostname return false now that we know we have the same hostname we can propagate the ip if address null addr address null addr address address if addr address null address null address addr address except if we actually do have two different looked up i ps if addr address null address null addr address equals address return false equal return true if addr hostname null return false no hostname go by address if address equals addr address return false return true freenetinetaddress freenetinetaddress freenetinetaddress equalsignorecase _address _address _address _address _address _address _address _address ips _address _address _address _address _address _address public boolean strict equals freenet inet address addr if hostname null if addr hostname null return false if hostname equals ignore case addr hostname return false now that we know we have the same hostname we can propagate the ip if address null addr address null addr address address if addr address null address null address addr address except if we actually do have two different looked up i ps if addr address null address null addr address equals address return false equal return true no hostname go by address if get host name address equals ignore case get host name addr address logger minor this addresses do not match mine get host name address his get host name addr address return false return true strictequals freenetinetaddress equalsignorecase _address _address _address _address _address _address _address _address ips _address _address _address _address gethostname _address equalsignorecase gethostname _address gethostname _address gethostname _address get the ip address look it up if necessary but return the last value if it has ever been looked up before will not trigger a new lookup if it has been looked up before public inet address get address return get address true inetaddress getaddress getaddress get the ip address look it up only if allowed to but return the last value if it has ever been looked up before will not trigger a new lookup if it has been looked up before public inet address get address boolean dodns request if address null return address else if dodns request return null inet address addr get handshake address if addr null this address addr return addr inetaddress getaddress dodnsrequest _address _address dodnsrequest inetaddress gethandshakeaddress _address get the ip address looking up the hostname if the hostname is primary even if it has been looked up before typically called on a reconnect attempt when the dyndns address may have changed public inet address get handshake address since we re handshaking hostname to ip may have changed if address null hostname null if logminor logger minor this hostname is null returning address return address else if logminor logger minor this looking up hostname in dns new exception debug peers are constructed from an address once a handshake has been completed so this lookup will only be performed during a handshake this method should normally only be called from peer node get handshakei ps and once each connection from this get address otherwise it doesn t mean we perform a dns lookup with every packet we send try inet address addr inet address get by name hostname if logminor logger minor this look up got addr if addr null cache the answer since get handshake address doesn t use the cached value thus get handshakei ps should always get the latest value from dns minus java s caching this address inet address get by address addr get address if logminor logger minor this setting address to address return addr catch unknown host exception e if logminor logger minor this dns said hostname hostname is an unknown host returning null return null inetaddress gethandshakeaddress _address _address _address peernode gethandshakeips getaddress inetaddress inetaddress getbyname gethandshakeaddress gethandshakeips _address inetaddress getbyaddress getaddress _address unknownhostexception override public int hash code if hostname null return hostname hash code was set at creation so it can safely be used here else return address hash code can be null but if so hostname will be non null hashcode hashcode _address hashcode override public string to string if hostname null return hostname else return address get host address tostring _address gethostaddress public string to string pref numeric if address null return address get host address else return hostname tostringprefnumeric _address _address gethostaddress public void write to data output stream data output stream dos throws io exception inet address addr this get address if addr null throw new unknown host exception byte data addr get address if data length 4 dos write 0 else dos write 255 dos write data if hostname null dos writeutf hostname else dos writeutf writetodataoutputstream dataoutputstream ioexception inetaddress getaddress unknownhostexception getaddress return the hostname or the ip address of the given inet address does not attempt to do a reverse lookup if the hostname is known return it otherwise return the textual ip address public static string get host name inet address primaryip address if primaryip address null return null string s primaryip address to string string addr s substring 0 s index of trim if addr length 0 return primaryip address get host address else return addr inetaddress gethostname inetaddress primaryipaddress primaryipaddress primaryipaddress tostring indexof primaryipaddress gethostaddress public boolean is real internet address boolean lookup boolean default val boolean allow local addresses if address null return ip util is valid address address allow local addresses else if lookup inet address a get address if a null return ip util is valid address a allow local addresses return default val isrealinternetaddress defaultval allowlocaladdresses _address iputil isvalidaddress _address allowlocaladdresses inetaddress getaddress iputil isvalidaddress allowlocaladdresses defaultval get a new code freenet inet address code with host name removed return a new code freenet inet address code with host name removed or code null if no known ip address is associated with this object you may want to do a code get address true code before calling this public freenet inet address drop hostname if address null logger error this can t drop hostname if no address return null if hostname null return new freenet inet address address else return this freenetinetaddress freenetinetaddress getaddress freenetinetaddress drophostname _address drophostname freenetinetaddress _address public boolean has hostname noip return hostname null hostname length 0 address null hashostnamenoip _address construct an opacity filter with 50 opacity public opacity filter this 0x88 opacityfilter opacityfilter construct an opacity filter with the given opacity alpha param opacity the opacity alpha in the range 0 255 public opacity filter int opacity set opacity opacity opacityfilter opacityfilter setopacity set the opacity param opacity the opacity alpha in the range 0 255 see get opacity public void set opacity int opacity this opacity opacity opacity24 opacity 24 getopacity setopacity get the opacity setting return the opacity see set opacity public int get opacity return opacity setopacity getopacity override public int filterrgb int x int y int rgb if rgb 0xff000000 0 return rgb 0xffffff opacity24 return rgb override public string to string return colors transparency tostring public ssdp notify socket string bind addr string addr ssdp address usei pv6 address false if host interface isi pv6 address bind addr true addr ssdp geti pv6 address usei pv6 address true open addr ssdp port bind addr set control point null ssdpnotifysocket bindaddr useipv6address hostinterface isipv6address bindaddr getipv6address useipv6address bindaddr setcontrolpoint private control point control point null public void set control point control point ctrlp this control point ctrlp controlpoint controlpoint setcontrolpoint controlpoint controlpoint public control point get control point return control point controlpoint getcontrolpoint controlpoint public boolean post ssdp notify request req string ssdp addr ssdp address if usei pv6 address true ssdp addr ssdp geti pv6 address req set host ssdp addr ssdp port return post http request req ssdpnotifyrequest ssdpaddr useipv6address ssdpaddr getipv6address sethost ssdpaddr httprequest public void run thread this thread thread current thread control point ctrl point get control point while device notify thread this thread thread yield ssdp packet packet receive thanks for mikael hakman 04 20 05 if packet null continue thanks for inma 02 20 04 inet address maddr get multicast inet address inet address pmaddr packet get host inet address if maddr equals pmaddr false debug warning invalidate multicast recieved maddr pmaddr continue if ctrl point null ctrl point notify received packet thisthread currentthread controlpoint ctrlpoint getcontrolpoint devicenotifythread thisthread ssdppacket inetaddress getmulticastinetaddress inetaddress gethostinetaddress ctrlpoint ctrlpoint notifyreceived public void start device notify thread new thread this u pnp ssdp notify socket device notify thread set daemon true device notify thread start devicenotifythread upnp ssdpnotifysocket devicenotifythread setdaemon devicenotifythread public void stop thanks for mikael hakman 04 20 05 close device notify thread null devicenotifythread private final boolean global public persistent request removed message string identifier boolean global this ident identifier this global global persistentrequestremovedmessage override public simple field set get field set simple field set fs new simple field set true fs put single identifier ident if global fs put single global true return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle override public string get name return persistent request removed getname persistentrequestremoved override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message persistent request removed goes from server to client not the other way around ident global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message persistentrequestremoved override public void remove from object container container container delete this removefrom objectcontainer public error page web interface my web interface ft own identity viewer http request request string error title string error message super my web interface viewer request m error title error title m error message error message errorpage webinterface mywebinterface ftownidentity httprequest errortitle errormessage mywebinterface merrortitle errortitle merrormessage errormessage public final void make html node error box add alert box m error title error box add child m error message htmlnode errorbox addalertbox merrortitle errorbox addchild merrormessage private boolean m needs new wot public wot is missing page web interface my web interface http request request boolean wot is outdated super my web interface null request m needs new wot wot is outdated mneedsnewwot wotismissingpage webinterface mywebinterface httprequest wotisoutdated mywebinterface mneedsnewwot wotisoutdated public void make if m needs new wot html node box add alert box your web of trust plugin is outdated box add child this freetalk version is incompatible with the wot plugin version which you have installed please upgrade the wot plugin at box add child a href plugins add child your freenet node s plugin page box add child fixme add by going to the plugins page and pressing reload after we have wot in the official plugins list else html node box add alert box web of trust plugin is missing box add child freetalk needs the wot plugin to be loaded in your freenet node please go to box add child a href plugins add child your freenet node s plugin page box add child and load the wot plugin mneedsnewwot htmlnode addalertbox addchild addchild addchild addchild htmlnode addalertbox addchild addchild addchild addchild public static void fill byte array from ints int ints byte bytes int ic 0 for int i 0 i ints length i bytes ic byte ints i 24 bytes ic byte ints i 16 bytes ic byte ints i 8 bytes ic byte ints i fillbytearrayfromints public static void fill byte array from longs long ints byte bytes int ic 0 for int i 0 i ints length i bytes ic byte ints i 56 bytes ic byte ints i 48 bytes ic byte ints i 40 bytes ic byte ints i 32 bytes ic byte ints i 24 bytes ic byte ints i 16 bytes ic byte ints i 8 bytes ic byte ints i fillbytearrayfromlongs public static void fill int array from bytes byte bytes int ints int ic 0 for int i 0 i ints length 2 i 4 ints ic bytes i bytes i 1 8 bytes i 2 16 bytes i 3 24 fillintarrayfrombytes public static void fill long array from bytes byte bytes long longs int ic 0 for int i 0 i longs length 3 i 8 longs ic bytes i long bytes i 1 8 long bytes i 2 16 long bytes i 3 24 long bytes i 4 32 long bytes i 5 40 long bytes i 6 48 long bytes i 7 56 filllongarrayfrombytes public static byte mp ibytes big integer num int len num bit length byte bytes new byte 2 len 8 3 system arraycopy num to byte array 0 bytes 2 bytes length 2 bytes 0 byte len 8 bytes 1 byte len return bytes mpibytes biginteger bitlength tobytearray public static void writempi big integer num output stream out throws io exception out write mp ibytes num biginteger outputstream ioexception mpibytes public static big integer readmpi input stream in throws io exception int b1 in read int b2 in read if b1 1 b2 1 throw new eof exception byte data new byte b1 8 b2 8 3 read fully in data 0 data length new data input stream in read fully data 0 data length redflag this can t possibly be negative right return new native big integer 1 data biginteger inputstream ioexception eofexception readfully datainputstream readfully nativebiginteger creates a large random number big integer up to b bits b bits this differs from the big integer constructor in that it generates all numbers from the range 2 lower to 2 n rather than 2 n 1 to 2 n public static big integer generate large random int lower bound int upper bound random r if lower bound upper bound return new native big integer lower bound r int bl do bl r next int 0x7fffffff upper bound while bl lower bound return new native big integer bl r biginteger biginteger biginteger generatelargerandom lowerbound upperbound lowerbound upperbound nativebiginteger lowerbound nextint upperbound lowerbound nativebiginteger public static byte hash bytes message digest d byte b return hash bytes d b 0 b length hashbytes messagedigest hashbytes public static byte hash bytes message digest d byte b int offset int length d update b offset length return d digest hashbytes messagedigest hashes a string in a consistent manner public static byte hash string digest d string s try byte sbytes s get bytes utf 8 d update sbytes 0 sbytes length return d digest catch exception e e print stack trace return null hashstring getbytes printstacktrace public static byte xor byte b1 byte b2 int maxl math max b1 length b2 length byte rv new byte maxl int minl math min b1 length b2 length for int i 0 i minl i rv i byte b1 i b2 i return rv if you have two method if you have two equally sized arrays public static boolean byte array equal byte a byte b int offset int length int lim offset length if a length lim b length lim return false for int i offset i lim i if a i b i return false return true bytearrayequal public static void make key byte entropy byte key int offset int len synchronized ctx ctx digest reinitialize int ic 0 while len 0 ic for int i 0 i ic i ctx update byte 0 ctx update entropy 0 entropy length int bc if len 20 ctx digest true key offset bc 20 else byte hash ctx digest bc math min len hash length system arraycopy hash 0 key offset bc offset bc len bc arrays fill entropy byte 0 makekey public static block cipher get cipher by name string name throws unsupported cipher exception try return block cipher loader get instance freenet crypt ciphers name catch exception e throw new unsupported cipher exception e e print stack trace return null blockcipher getcipherbyname unsupportedcipherexception blockcipher getinstance unsupportedcipherexception printstacktrace public static block cipher get cipher by name string name int key size throws unsupported cipher exception try return block cipher loader get instance freenet crypt ciphers name new class integer class new object integer value of key size catch exception e throw new unsupported cipher exception e e print stack trace return null blockcipher getcipherbyname keysize unsupportedcipherexception blockcipher getinstance valueof keysize unsupportedcipherexception printstacktrace public static digest get digest by name string name throws unsupported digest exception try return digest loader get instance freenet crypt name catch exception e throw new unsupported digest exception e e print stack trace return null getdigestbyname unsupporteddigestexception getinstance unsupporteddigestexception printstacktrace public static void main string args throws exception if args length 0 args 0 equals write writempi new big integer 9 system out writempi new big integer 1234567890123456789 system out writempi new big integer 100200300400500600700800900 system out else if args 0 equals read system out println 9 system out println readmpi system in system out println 1234567890123456789 system out println readmpi system in system out println 100200300400500600700800900 system out println readmpi system in else if args 0 equals write mpi writempi new big integer args 1 system out else if args 0 equals read mpi system err println readmpi system in else if args 0 equals keygen byte entropy readmpi system in to byte array byte key new byte args length 1 integer parse int args 1 16 make key entropy key 0 key length system err println hex util bytes to hex key 0 key length else if args 0 equals shatest synchronized ctx ctx digest ctx update byte a ctx update byte b ctx update byte c system err println hex util bytes to hex ctx digest biginteger biginteger biginteger biginteger tobytearray parseint makekey hexutil bytestohex hexutil bytestohex return log2 of n rounded up to the nearest integer public static int log2 long n int log2 0 while log2 63 1l log2 n log2 return log2 public static void read fully input stream in byte b throws io exception read fully in b 0 b length readfully inputstream ioexception readfully public static void read fully input stream in byte b int off int length throws io exception int total 0 while total length int got in read b off total length total if got 1 throw new eof exception total got readfully inputstream ioexception eofexception public class assert check specified condition and raise code assertion failed code exception if it is not true param cond result of checked condition public static final void that boolean cond if cond throw new assertion failed assertionfailed assertionfailed check specified condition and raise code assertion failed code exception if it is not true param description string describing checked condition param cond result of checked condition public static final void that string description boolean cond if cond throw new assertion failed description assertionfailed assertionfailed throw assertion failed exception public static final void failed throw new assertion failed assertionfailed throw assertion failed exception with given description public static final void failed string description throw new assertion failed description assertionfailed private function2d basis public fbm filter set basis type noise fbmfilter setbasistype set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of texture return the amount see set amount public float get amount return amount setamount getamount public void set operation int operation this operation operation setoperation public int get operation return operation getoperation specifies the scale of the texture param scale the scale of the texture min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale specifies the stretch factor of the texture param stretch the stretch factor of the texture min value 1 max value 50 see get stretch public void set stretch float stretch this stretch stretch getstretch setstretch returns the stretch factor of the texture return the stretch factor of the texture see set stretch public float get stretch return stretch setstretch getstretch specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle float cos float math cos this angle float sin float math sin this angle m00 cos m01 sin m10 sin m11 cos getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle public void set octaves float octaves this octaves octaves setoctaves public float get octaves return octaves getoctaves public void seth float h this h h public float geth return h public void set lacunarity float lacunarity this lacunarity lacunarity setlacunarity public float get lacunarity return lacunarity getlacunarity public void set gain float gain this gain gain setgain public float get gain return gain getgain public void set bias float bias this bias bias setbias public float get bias return bias getbias set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set basis type int basis type this basis type basis type switch basis type default case noise basis new noise break case ridged basis new ridgedfbm break case vlnoise basis new vl noise break case scnoise basis new sc noise break case cellular basis new cellular function2d break setbasistype basistype basistype basistype basistype vlnoise scnoise cellularfunction2d public int get basis type return basis type getbasistype basistype public void set basis function2d basis this basis basis setbasis public function2d get basis return basis getbasis protected fbm makefbm float h float lacunarity float octaves fbm fbm new fbm h lacunarity octaves basis float minmax noise find range fbm null min minmax 0 max minmax 1 return fbm findrange override public buffered image filter buffered image src buffered image dst f bm makefbm h lacunarity octaves return super filter src dst bufferedimage bufferedimage bufferedimage fbm override public int filterrgb int x int y int rgb float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch float f f bm evaluate nx ny normalize to 0 1 f f min max min f image math gain f gain f image math bias f bias f amount int a rgb 0xff000000 int v if colormap null v colormap get color f else v pixel utils clamp int f 255 int r v 16 int g v 8 int b v v a r g b if operation pixel utils replace v pixel utils combine pixels rgb v operation return v fbm imagemath imagemath getcolor pixelutils pixelutils pixelutils combinepixels override public string to string return texture fractal brownian motion tostring override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog callbacks are told when the usk fetcher finishes and unless background poll is enabled they are only sent on found edition once on completion fixme don t allow callbacks if background poll is enabled param cb return public synchronized boolean add callback usk fetcher callback cb if completed return false callbacks add cb return true uskfetcher onfoundedition backgroundpoll addcallback uskfetchercallback boolean cancelled public usk attempt long i this number i this succeeded false this dnf false this checker new usk checker this origusk getssk i ctx maxusk retries ctx parent uskattempt uskchecker maxuskretries public void ondnf client context context checker null dnf true usk fetcher this ondnf this context clientcontext uskfetcher public void on success clientssk block block client context context checker null succeeded true usk fetcher this on success this false block context onsuccess clientsskblock clientcontext uskfetcher onsuccess public void on fatal author error client context context checker null counts as success except it doesn t update usk fetcher this on success this true null context onfatalauthorerror clientcontext uskfetcher onsuccess public void on network error client context context checker null not a dnf usk fetcher this on fail this context onnetworkerror clientcontext uskfetcher onfail public void on cancelled client context context checker null usk fetcher this on cancelled this context oncancelled clientcontext uskfetcher oncancelled public void cancel object container container client context context assert container null cancelled true if checker null checker cancel container context on cancelled context objectcontainer clientcontext oncancelled public void schedule object container container client context context assert container null if checker null if logminor logger minor this checker null in schedule for this new exception debug else assert checker persistent checker schedule container context objectcontainer clientcontext override public string to string return usk attempt for number for origusk geturi for usk fetcher this tostring uskattempt uskfetcher public short get priority if background poll if min failures orig min failures min failures max min failures either just started or just advanced either way boost the priority return progress poll priority else return normal poll priority else return parent get priority class getpriority backgroundpoll minfailures origminfailures minfailures maxminfailures progresspollpriority normalpollpriority getpriorityclass private short progress poll priority default progress poll priority usk fetcher usk origusk usk manager manager fetch context ctx client requester requester int min failures boolean poll forever boolean keep last data this origusk manager ctx requester min failures poll forever default max min failures keep last data progresspollpriority default_progress_poll_priority uskfetcher uskmanager fetchcontext clientrequester minfailures pollforever keeplastdata minfailures pollforever default_max_min_failures keeplastdata fixme use this usk fetcher usk origusk usk manager manager fetch context ctx client requester requester int min failures boolean poll forever long max probe editions boolean keep last data this parent requester this max min failures max probe editions this origusk origusk this usk manager manager this min failures this orig min failures min failures running attempts new vector usk attempt callbacks new linked list usk fetcher callback subscribers new hash set usk callback last fetched edition 1 last added edition 1 this ctx ctx this background poll poll forever this keep last data keep last data keys watching new array list clientssk attempts to start new array list usk attempt uskfetcher uskmanager fetchcontext clientrequester minfailures pollforever maxprobeeditions keeplastdata maxminfailures maxprobeeditions uskmanager minfailures origminfailures minfailures runningattempts uskattempt linkedlist uskfetchercallback hashset uskcallback lastfetchededition lastaddededition backgroundpoll pollforever keeplastdata keeplastdata keyswatching arraylist attemptstostart arraylist uskattempt void ondnf usk attempt att client context context if logminor logger minor this dnf att boolean finished false long cur latest usk manager lookup latest slot origusk synchronized this if completed cancelled return last fetched edition math max last fetched edition att number running attempts remove att if running attempts is empty if logminor logger minor this latest cur latest last fetched last fetched edition cur latest min failures cur latest min failures if started finished true else if logminor logger minor this remaining running attempts size if finished finish success context uskattempt clientcontext curlatest uskmanager lookuplatestslot lastfetchededition lastfetchededition runningattempts runningattempts isempty curlatest lastfetchededition curlatest min_failures curlatest minfailures runningattempts finishsuccess private void finish success client context context if background poll long val at end usk manager lookup latest slot origusk long end long now system current time millis synchronized this started false don t finish before have rescheduled find out when we should check next end in an increasing delay unless we make progress int new sleep time sleep time 2 if new sleep time max sleep time new sleep time max sleep time sleep time new sleep time end now context random next int sleep time if val at end value at schedule val at end origusk suggested edition we have advanced keep trying as if we just started only if we actually do advance not if we just confirm our suspicion value at schedule always starts at 0 min failures orig min failures sleep time orig sleep time end now if logminor logger minor this we have advanced at start value at schedule at end val at end else we have not found any new version increase exponentially but relatively slowly long new min failures math max int min failures 1 25 min failures 1 if new min failures max min failures new min failures max min failures min failures new min failures schedule end now null context else usk manager unsubscribe origusk this usk manager on finished this context get ssk fetch scheduler sched transient remove pending keys key listener this long ed usk manager lookup latest slot origusk usk fetcher callback cb synchronized this completed true cb callbacks to array new usk fetcher callback callbacks size byte data if last request data null data null else try data bucket tools to byte array last request data catch io exception e logger error this unable to turn last request data into byte caught i o exception e e data null for int i 0 i cb length i try cb i on found edition ed origusk copy ed null context last was metadata last compression codec data false false catch exception e logger error this an exception occured while dealing with a callback cb i to string n e get message e finishsuccess clientcontext backgroundpoll valatend uskmanager lookuplatestslot currenttimemillis newsleeptime sleeptime newsleeptime maxsleeptime newsleeptime maxsleeptime sleeptime newsleeptime nextint sleeptime valatend valueatschedule valatend suggestededition valueatschedule minfailures origminfailures sleeptime origsleeptime valueatschedule valatend newminfailures minfailures minfailures newminfailures maxminfailures newminfailures maxminfailures minfailures newminfailures uskmanager uskmanager onfinished getsskfetchscheduler schedtransient removependingkeys keylistener uskmanager lookuplatestslot uskfetchercallback toarray uskfetchercallback lastrequestdata buckettools tobytearray lastrequestdata ioexception lastrequestdata onfoundedition lastwasmetadata lastcompressioncodec tostring getmessage void on success usk attempt att boolean dont update clientssk block block final client context context final long last ed usk manager lookup latest slot origusk long cur latest boolean decode false vector usk attempt kill attempts synchronized this running attempts remove att cur latest att number if completed cancelled return decode cur latest last ed dont update block null cur latest math max last ed cur latest if logminor logger minor this latest cur latest long add to cur latest min failures long add from math max last added edition 1 cur latest 1 if logminor logger minor this adding from add from to add to for origusk if add to add from for long i add from i add to i if logminor logger minor this adding checker for edition i for origusk attempts to start add add i kill attempts cancel before cur latest context fill keys watching cur latest 1 context finish cancel before kill attempts context bucket data null if decode try data block decode context get bucket factory parent persistent 1025 it s an ssk true catch key decode exception e data null catch io exception e data null logger error this an ioe occured while decoding e get message e synchronized this if decode last compression codec block get compression codec last was metadata block is metadata if keep last data if last request data null last request data free last request data data else data free if dont update usk manager update slot origusk cur latest context onsuccess uskattempt dontupdate clientsskblock clientcontext lasted uskmanager lookuplatestslot curlatest uskattempt killattempts runningattempts curlatest curlatest lasted dontupdate curlatest lasted curlatest curlatest addto curlatest minfailures addfrom lastaddededition curlatest addfrom addto addto addfrom addfrom addto attemptstostart killattempts cancelbefore curlatest fillkeyswatching curlatest finishcancelbefore killattempts getbucketfactory keydecodeexception ioexception getmessage lastcompressioncodec getcompressioncodec lastwasmetadata ismetadata keeplastdata lastrequestdata lastrequestdata lastrequestdata dontupdate uskmanager updateslot curlatest void on cancelled usk attempt att client context context synchronized this running attempts remove att if running attempts is empty return if cancelled finish cancelled context oncancelled uskattempt clientcontext runningattempts runningattempts isempty finishcancelled private void finish cancelled client context context usk fetcher callback cb synchronized this completed true cb callbacks to array new usk fetcher callback callbacks size for int i 0 i cb length i cb i on cancelled null context finishcancelled clientcontext uskfetchercallback toarray uskfetchercallback oncancelled public void on fail usk attempt attempt client context context fixme what else can we do certainly we don t want to continue fetching indefinitely e g rn fs don t indicate we should try a later slot none of them really do ondnf attempt context onfail uskattempt clientcontext rnfs private vector usk attempt cancel before long cur latest client context context vector usk attempt v null int count 0 synchronized this for iterator usk attempt i running attempts iterator i has next usk attempt att i next if att number cur latest if v null v new vector usk attempt running attempts size count v add att i remove count return v uskattempt cancelbefore curlatest clientcontext uskattempt uskattempt runningattempts hasnext uskattempt curlatest uskattempt runningattempts private void finish cancel before vector usk attempt v client context context if v null for int i 0 i v size i usk attempt att v get i att cancel null context finishcancelbefore uskattempt clientcontext uskattempt add a usk attempt for another edition number caller is responsible for calling schedule private synchronized usk attempt add long i if cancelled return null if logminor logger minor this adding usk attempt for i for origusk geturi if running attempts is empty usk attempt last running attempts last element if last number i if logminor logger minor this returning because last number i for origusk geturi return null usk attempt a new usk attempt i running attempts add a last added edition i if logminor logger minor this added a for origusk return a uskattempt uskattempt uskattempt runningattempts isempty uskattempt runningattempts lastelement uskattempt uskattempt runningattempts lastaddededition public freeneturi geturi return origusk geturi public boolean is finished synchronized this return completed cancelled isfinished public usk get originalusk return origusk getoriginalusk public void schedule long delay object container container final client context context assert container null if delay 0 schedule container context else context ticker queue timed job new runnable public void run usk fetcher this schedule null context delay objectcontainer clientcontext queuetimedjob uskfetcher public void schedule object container container client context context context get ssk fetch scheduler sched transient add pending keys this update priorities usk manager subscribe origusk this false parent get client usk attempt attempts long looked up usk manager lookup latest slot origusk synchronized this value at schedule math max looked up value at schedule if cancelled return long start point math max origusk suggested edition value at schedule for long i start point i start point min failures i attempts to start add add i started true fill keys watching value at schedule context objectcontainer clientcontext getsskfetchscheduler schedtransient addpendingkeys updatepriorities uskmanager getclient uskattempt lookedup uskmanager lookuplatestslot valueatschedule lookedup valueatschedule startpoint suggestededition valueatschedule startpoint startpoint minfailures attemptstostart fillkeyswatching valueatschedule public void cancel object container container client context context usk manager unsubscribe origusk this context get ssk fetch scheduler sched transient remove pending keys key listener this assert container null usk attempt attempts usk manager on finished this synchronized this cancelled true attempts running attempts to array new usk attempt running attempts size for int i 0 i attempts length i attempts i cancel container context objectcontainer clientcontext uskmanager getsskfetchscheduler schedtransient removependingkeys keylistener uskattempt uskmanager onfinished runningattempts toarray uskattempt runningattempts add a subscriber subscribers are not directly sent on found edition s by the usk fetcher we just use them to determine the priority of our requests and whether we should continue to request param cb public void add subscriber usk callback cb synchronized this subscribers add cb update priorities onfoundedition uskfetcher addsubscriber uskcallback updatepriorities private void update priorities fixme should this be synchronized imho it doesn t matter that much if we get the priority wrong for a few requests also we avoid any possible deadlock this way if the callbacks take locks short normal prio request starter minimum priority class short progress prio request starter minimum priority class usk callback local callbacks synchronized this local callbacks subscribers to array new usk callback subscribers size if local callbacks length 0 normal poll priority default normal poll priority progress poll priority default progress poll priority return for int i 0 i local callbacks length i usk callback cb local callbacks i short prio cb get polling priority normal if logdebug logger debug this normal priority for cb prio if prio normal prio normal prio prio if logdebug logger debug this progress priority for cb prio prio cb get polling priority progress if prio progress prio progress prio prio if logminor logger minor this updating priorities normal normal prio progress progress prio for this for origusk synchronized this normal poll priority normal prio progress poll priority progress prio updatepriorities normalprio requeststarter minimum_priority_class progressprio requeststarter minimum_priority_class uskcallback localcallbacks localcallbacks toarray uskcallback localcallbacks normalpollpriority default_normal_poll_priority progresspollpriority default_progress_poll_priority localcallbacks uskcallback localcallbacks getpollingprioritynormal normalprio normalprio getpollingpriorityprogress progressprio progressprio normalprio progressprio normalpollpriority normalprio progresspollpriority progressprio public synchronized boolean has subscribers return subscribers is empty hassubscribers isempty public synchronized boolean has callbacks return callbacks is empty hascallbacks isempty public void remove subscriber usk callback cb client context context synchronized this subscribers remove cb update priorities removesubscriber uskcallback clientcontext updatepriorities public void remove callback usk callback cb synchronized this subscribers remove cb removecallback uskcallback public synchronized boolean has last data return this last request data null haslastdata lastrequestdata public synchronized boolean last content was metadata return this last was metadata lastcontentwasmetadata lastwasmetadata public synchronized short last compression codec return this last compression codec lastcompressioncodec lastcompressioncodec public synchronized bucket get last data return this last request data getlastdata lastrequestdata public synchronized void free last data if last request data null return last request data free usk fetcher s cannot be persistent so no need to remove from last request data null freelastdata lastrequestdata lastrequestdata uskfetcher removefrom lastrequestdata public synchronized void kill on lose subscribers this kill on lose subscribers true killonlosesubscribers killonlosesubscribers public long get token return 1 gettoken public void remove from object container container client context context throw new unsupported operation exception removefrom objectcontainer clientcontext unsupportedoperationexception public boolean object can new object container container logger error this not storing usk fetcher in database new exception error return false objectcannew objectcontainer uskfetcher public short get polling priority normal throw new unsupported operation exception getpollingprioritynormal unsupportedoperationexception public short get polling priority progress throw new unsupported operation exception getpollingpriorityprogress unsupportedoperationexception public void on found edition long ed usk key object container container final client context context boolean metadata short codec byte data boolean new known good boolean new slot too if new known good new slot too return only interested in slots because this is frequently run off thread it is actually possible that the looked up edition is not the same as the edition we are being notified of final long last ed usk manager lookup latest slot origusk boolean decode false vector usk attempt kill attempts synchronized this if completed cancelled return decode last ed ed data null ed math max last ed ed if logminor logger minor this latest ed long add to ed min failures long add from math max last added edition 1 ed 1 if logminor logger minor this adding from add from to add to for origusk if add to add from for long i add from i add to i if logminor logger minor this adding checker for edition i for origusk attempts to start add add i kill attempts cancel before ed context fill keys watching ed 1 context finish cancel before kill attempts context synchronized this if decode last compression codec codec last was metadata metadata if keep last data fixme inefficient to convert from bucket to byte to bucket if last request data null last request data free try last request data bucket tools make immutable bucket context temp bucket factory data catch io exception e logger error this caught e e onfoundedition objectcontainer clientcontext newknowngood newslottoo newknowngood newslottoo lasted uskmanager lookuplatestslot uskattempt killattempts lasted lasted addto minfailures addfrom lastaddededition addfrom addto addto addfrom addfrom addto attemptstostart killattempts cancelbefore fillkeyswatching finishcancelbefore killattempts lastcompressioncodec lastwasmetadata keeplastdata lastrequestdata lastrequestdata lastrequestdata buckettools makeimmutablebucket tempbucketfactory ioexception private synchronized void fill keys watching long ed client context context if logminor logger minor this fill keys watching from ed for this origusk new exception debug if first key watching 1 first key watching ed for int i 0 i watch keys i keys watching add origusk getssk ed i else long first first key watching long last first key watching keys watching size 1 if last ed keys watching clear for int i 0 i watch keys i keys watching add origusk getssk ed i else int drop int ed first clientssk keep new clientssk keys watching size drop for int i drop i keys watching size i keep i drop keys watching get i keys watching clear for clientssk ssk keep keys watching add ssk for long l last 1 l ed watch keys l keys watching add origusk getssk l first key watching ed if running store checker return long first check math max first key watching checked datastore up to 1 final long last check first key watching keys watching size 1 if logminor logger minor this first check first check last check last check if last check first check return int check count int last check first check 1 int offset int first check first key watching final key check store new key check count for int i 0 i check store length i check store i keys watching get i offset get node key assert offset check store length keys watching size assert keys watching get keys watching size 1 geturi usk forssk get suggested edition last check if logminor logger minor this checking from first check to last check for this origusk sendable get store checker new sendable get parent boolean done false override public boolean dont cache object container container return false override public fetch context get context return ctx override public long get cooldown wakeup object token object container container return 1 override public long get cooldown wakeup by key key key object container container return 1 override public client key get key object token object container container return null override public boolean ignore store return false override public key list keys object container container return check store override public void on failure low level get exception e object token object container container client context context ignore override public void requeue after cooldown key key long time object container container client context context ignore override public void reset cooldown times object container container ignore override public boolean has valid keys keys fetching locally fetching object container container client context context return true override public void pre register object container container client context context boolean to network unregister container context usk attempt attempts synchronized usk fetcher this if cancelled return running store checker false fixme should we only start the usk attempt s if the datastore check hasn t made progress attempts attempts to start to array new usk attempt attempts to start size attempts to start clear done true checked datastore up to last check if logminor logger minor this checked datastore finishing registration for attempts length checkers for usk fetcher this for origusk if attempts length 0 parent to network container context for int i 0 i attempts length i long last ed usk manager lookup latest slot origusk fixme not sure this condition works test it if keep last data last request data null last ed origusk suggested edition last ed if we want the data then get it for the known edition so we always get the data so usk inserter can compare it and return the old edition if it is identical if attempts i null continue if attempts i number last ed attempts i schedule container context else synchronized this running attempts remove attempts i long last ed usk manager lookup latest slot origusk do not check beyond watch keys after the current slot fill keys watching last ed context override public sendable request item choose key keys fetching locally keys object container container client context context return null override public long count all keys object container container client context context return keys watching size override public long count sendable keys object container container client context context return 0 override public request client get client object container container return usk fetcher this usk manager override public client requester get client request return parent override public short get priority class object container container return progress poll priority fixme override public int get retry count return 0 override public boolean is cancelled object container container return done override public boolean isssk return true override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context return null public boolean is empty object container container return done running store checker true try context get ssk fetch scheduler register null new sendable get store checker false false null null false catch key listener construction exception e1 impossible running store checker false catch throwable t running store checker false logger error this unable to start t t fillkeyswatching clientcontext fillkeyswatching firstkeywatching firstkeywatching watch_keys keyswatching firstkeywatching firstkeywatching keyswatching keyswatching watch_keys keyswatching keyswatching keyswatching keyswatching keyswatching keyswatching watch_keys keyswatching firstkeywatching runningstorechecker firstcheck firstkeywatching checkeddatastoreupto lastcheck firstkeywatching keyswatching firstcheck firstcheck lastcheck lastcheck lastcheck firstcheck checkcount lastcheck firstcheck firstcheck firstkeywatching checkstore checkcount checkstore checkstore keyswatching getnodekey checkstore keyswatching keyswatching keyswatching uskforssk getsuggestededition lastcheck firstcheck lastcheck sendableget storechecker sendableget dontcache objectcontainer fetchcontext getcontext getcooldownwakeup objectcontainer getcooldownwakeupbykey objectcontainer clientkey getkey objectcontainer ignorestore listkeys objectcontainer checkstore onfailure lowlevelgetexception objectcontainer clientcontext requeueaftercooldown objectcontainer clientcontext resetcooldowntimes objectcontainer hasvalidkeys keysfetchinglocally objectcontainer clientcontext preregister objectcontainer clientcontext tonetwork uskattempt uskfetcher runningstorechecker uskattempt attemptstostart toarray uskattempt attemptstostart attemptstostart checkeddatastoreupto lastcheck uskfetcher tonetwork lasted uskmanager lookuplatestslot keeplastdata lastrequestdata lasted suggestededition lasted uskinserter lasted runningattempts lasted uskmanager lookuplatestslot watch_keys fillkeyswatching lasted sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext countallkeys objectcontainer clientcontext keyswatching countsendablekeys objectcontainer clientcontext requestclient getclient objectcontainer uskfetcher uskmanager clientrequester getclientrequest getpriorityclass objectcontainer progresspollpriority getretrycount iscancelled objectcontainer persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext isempty objectcontainer runningstorechecker getsskfetchscheduler sendableget storechecker keylistenerconstructionexception runningstorechecker runningstorechecker boolean done false override public boolean dont cache object container container return false dontcache objectcontainer override public fetch context get context return ctx fetchcontext getcontext override public long get cooldown wakeup object token object container container return 1 getcooldownwakeup objectcontainer override public long get cooldown wakeup by key key key object container container return 1 getcooldownwakeupbykey objectcontainer override public client key get key object token object container container return null clientkey getkey objectcontainer override public boolean ignore store return false ignorestore override public key list keys object container container return check store listkeys objectcontainer checkstore override public void on failure low level get exception e object token object container container client context context ignore onfailure lowlevelgetexception objectcontainer clientcontext override public void requeue after cooldown key key long time object container container client context context ignore requeueaftercooldown objectcontainer clientcontext override public void reset cooldown times object container container ignore resetcooldowntimes objectcontainer override public boolean has valid keys keys fetching locally fetching object container container client context context return true hasvalidkeys keysfetchinglocally objectcontainer clientcontext override public void pre register object container container client context context boolean to network unregister container context usk attempt attempts synchronized usk fetcher this if cancelled return running store checker false fixme should we only start the usk attempt s if the datastore check hasn t made progress attempts attempts to start to array new usk attempt attempts to start size attempts to start clear done true checked datastore up to last check if logminor logger minor this checked datastore finishing registration for attempts length checkers for usk fetcher this for origusk if attempts length 0 parent to network container context for int i 0 i attempts length i long last ed usk manager lookup latest slot origusk fixme not sure this condition works test it if keep last data last request data null last ed origusk suggested edition last ed if we want the data then get it for the known edition so we always get the data so usk inserter can compare it and return the old edition if it is identical if attempts i null continue if attempts i number last ed attempts i schedule container context else synchronized this running attempts remove attempts i long last ed usk manager lookup latest slot origusk do not check beyond watch keys after the current slot fill keys watching last ed context preregister objectcontainer clientcontext tonetwork uskattempt uskfetcher runningstorechecker uskattempt attemptstostart toarray uskattempt attemptstostart attemptstostart checkeddatastoreupto lastcheck uskfetcher tonetwork lasted uskmanager lookuplatestslot keeplastdata lastrequestdata lasted suggestededition lasted uskinserter lasted runningattempts lasted uskmanager lookuplatestslot watch_keys fillkeyswatching lasted override public sendable request item choose key keys fetching locally keys object container container client context context return null sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext override public long count all keys object container container client context context return keys watching size countallkeys objectcontainer clientcontext keyswatching override public long count sendable keys object container container client context context return 0 countsendablekeys objectcontainer clientcontext override public request client get client object container container return usk fetcher this usk manager requestclient getclient objectcontainer uskfetcher uskmanager override public client requester get client request return parent clientrequester getclientrequest override public short get priority class object container container return progress poll priority fixme getpriorityclass objectcontainer progresspollpriority override public int get retry count return 0 getretrycount override public boolean is cancelled object container container return done iscancelled objectcontainer override public boolean isssk return true override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context return null persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext public boolean is empty object container container return done isempty objectcontainer public synchronized boolean is cancelled object container container return completed cancelled iscancelled objectcontainer public key listener make key listener object container container client context context throws key listener construction exception return this keylistener makekeylistener objectcontainer clientcontext keylistenerconstructionexception public void on failed key listener construction exception e object container container client context context logger error this failed to construct key listener on usk fetcher e e onfailed keylistenerconstructionexception objectcontainer clientcontext keylistener uskfetcher public synchronized long count keys return keys watching size countkeys keyswatching public synchronized short definitely want key key key byte salted key object container container client context context for clientssk ssk keys watching if ssk get node key equals key return progress poll priority return 1 definitelywantkey saltedkey objectcontainer clientcontext keyswatching getnodekey progresspollpriority public boolean dont cache return ctx cache local requests dontcache cachelocalrequests public has key listener get has key listener return this haskeylistener gethaskeylistener public short get priority class object container container return progress poll priority getpriorityclass objectcontainer progresspollpriority public sendable get get requests for key key key byte salted key object container container client context context return new sendable get 0 sendableget getrequestsforkey saltedkey objectcontainer clientcontext sendableget public boolean handle block key key byte salted key key block found object container container client context context if found instanceof ssk block return false clientssk real key null long edition 1 synchronized this for int i 0 i keys watching size i clientssk ssk keys watching get i if ssk get node key equals key real key ssk edition first key watching i break if real key null return false fixme remove assert edition real key geturi usk forssk get suggested edition on found edition edition origusk container context false short 1 null false false return true handleblock saltedkey keyblock objectcontainer clientcontext sskblock realkey keyswatching keyswatching getnodekey realkey firstkeywatching realkey realkey uskforssk getsuggestededition onfoundedition public synchronized boolean is empty return cancelled completed isempty public boolean isssk return true public void on remove ignore onremove public boolean persistent return false public synchronized boolean probably want key key key byte salted key for clientssk ssk keys watching if ssk get node key equals key return true return false probablywantkey saltedkey keyswatching getnodekey public class xml exporter public xml exporter storage impl storage writer writer this storage storage this writer writer xmlexporter xmlexporter storageimpl public void export database int root oid throws io exception if storage encoding null writer write xml version 1 0 encoding storage encoding n else writer write xml version 1 0 encoding utf 8 n writer write database root root oid n exported bitmap new int storage curr index size 31 32 marked bitmap new int storage curr index size 31 32 marked bitmap root oid 5 1 root oid 31 int n exported objects do n exported objects 0 for int i 0 i marked bitmap length i int mask marked bitmap i if mask 0 for int j 0 bit 1 j 32 j bit 1 if mask bit 0 int oid i 5 j exported bitmap i bit marked bitmap i bit try byte obj storage get oid int type oid object header get type obj 0 class descriptor desc storage find class descriptor type oid if desc cls btree class export index oid obj plugins xml spider org garret perst impl btree else if desc cls bit index impl class export index oid obj plugins xml spider org garret perst impl bit index impl else if desc cls persistent set class export set oid obj else if desc cls btree field index class export field index oid obj plugins xml spider org garret perst impl btree field index else if desc cls btree case insensitive field index class export field index oid obj plugins xml spider org garret perst impl btree case insensitive field index else if desc cls btree multi field index class export multi field index oid obj plugins xml spider org garret perst impl btree multi field index else if desc cls btree case insensitive multi field index class export multi field index oid obj plugins xml spider org garret perst impl btree case insensitive multi field index else if desc cls btree compound index class export compound index oid obj else string class name export identifier desc name writer write class name id oid n export object desc obj object header sizeof 2 writer write class name n n exported objects 1 catch storage error x if storage listener null storage listener object not exported oid x else system err println xml export failed for object oid x while n exported objects 0 writer write database n writer flush writer should be closed by calling code exportdatabase rootoid ioexception rootoid exportedbitmap currindexsize markedbitmap currindexsize markedbitmap rootoid rootoid nexportedobjects nexportedobjects markedbitmap markedbitmap exportedbitmap markedbitmap typeoid objectheader gettype classdescriptor findclassdescriptor typeoid exportindex xmlspider bitindeximpl exportindex xmlspider bitindeximpl persistentset exportset btreefieldindex exportfieldindex xmlspider btreefieldindex btreecaseinsensitivefieldindex exportfieldindex xmlspider btreecaseinsensitivefieldindex btreemultifieldindex exportmultifieldindex xmlspider btreemultifieldindex btreecaseinsensitivemultifieldindex exportmultifieldindex xmlspider btreecaseinsensitivemultifieldindex btreecompoundindex exportcompoundindex classname exportidentifier classname exportobject objectheader classname nexportedobjects storageerror objectnotexported nexportedobjects final string export identifier string name return name replace exportidentifier final void export set int oid byte data throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write plugins xml spider org garret perst impl persistent set id oid n btree export this writer write plugins xml spider org garret perst impl persistent set n exportset ioexception objectheader assignoid xmlspider persistentset xmlspider persistentset final void export index int oid byte data string name throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write name id oid unique btree unique 1 0 type class descriptor signature btree type n btree export this writer write name n exportindex ioexception objectheader assignoid classdescriptor final void export field index int oid byte data string name throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write name id oid unique btree unique 1 0 int offs btree sizeof writer write autoinc bytes unpack8 data offs offs 8 writer write class offs export string data offs writer write field offs export string data offs writer write n btree export this writer write name n exportfieldindex ioexception objectheader assignoid exportstring exportstring final void export multi field index int oid byte data string name throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write name id oid unique btree unique 1 0 class int offs export string data btree sizeof int n fields bytes unpack4 data offs offs 4 for int i 0 i n fields i writer write field i offs export string data offs writer write n int n types bytes unpack4 data offs offs 4 compound key types new int n types for int i 0 i n types i compound key types i bytes unpack4 data offs offs 4 btree export this compound key types null writer write name n exportmultifieldindex ioexception objectheader assignoid exportstring nfields nfields exportstring ntypes compoundkeytypes ntypes ntypes compoundkeytypes compoundkeytypes final void export compound index int oid byte data throws io exception btree btree new btree data object header sizeof storage assign oid btree oid writer write plugins xml spider org garret perst impl btree compound index id oid unique btree unique 1 0 int offs btree sizeof int n types bytes unpack4 data offs offs 4 compound key types new int n types for int i 0 i n types i int type bytes unpack4 data offs writer write type i class descriptor signature type compound key types i type offs 4 writer write n btree export this compound key types null writer write plugins xml spider org garret perst impl btree compound index n exportcompoundindex ioexception objectheader assignoid xmlspider btreecompoundindex ntypes compoundkeytypes ntypes ntypes classdescriptor compoundkeytypes compoundkeytypes xmlspider btreecompoundindex final int export key byte body int offs int size int type throws io exception switch type case class descriptor tp boolean writer write body offs 0 1 0 break case class descriptor tp byte writer write integer to string body offs break case class descriptor tp char writer write integer to string char bytes unpack2 body offs offs 2 break case class descriptor tp short writer write integer to string bytes unpack2 body offs offs 2 break case class descriptor tp int case class descriptor tp object case class descriptor tp enum writer write integer to string bytes unpack4 body offs offs 4 break case class descriptor tp long writer write long to string bytes unpack8 body offs offs 8 break case class descriptor tp float writer write float to string float int bits to float bytes unpack4 body offs offs 4 break case class descriptor tp double writer write double to string double long bits to double bytes unpack8 body offs offs 8 break case class descriptor tp string for int i 0 i size i export char char bytes unpack2 body offs offs 2 break case class descriptor tp array of byte for int i 0 i size i byte b body offs writer write hex digit b 4 0xf writer write hex digit b 0xf break case class descriptor tp date long msec bytes unpack8 body offs offs 8 if msec 0 writer write xml importer http formatter format new date msec else writer write null break default assert that false return offs exportkey ioexception classdescriptor tpboolean classdescriptor tpbyte tostring classdescriptor tpchar tostring classdescriptor tpshort tostring classdescriptor tpint classdescriptor tpobject classdescriptor tpenum tostring classdescriptor tplong tostring classdescriptor tpfloat tostring intbitstofloat classdescriptor tpdouble tostring longbitstodouble classdescriptor tpstring exportchar classdescriptor tparrayofbyte hexdigit hexdigit classdescriptor tpdate xmlimporter httpformatter final void export compound key byte body int offs int size int type throws io exception assert that type class descriptor tp array of byte int end offs size for int i 0 i compound key types length i type compound key types i if type class descriptor tp array of byte type class descriptor tp string size bytes unpack4 body offs offs 4 writer write key i offs export key body offs size type writer write assert that offs end exportcompoundkey ioexception classdescriptor tparrayofbyte compoundkeytypes compoundkeytypes classdescriptor tparrayofbyte classdescriptor tpstring exportkey final void export assoc int oid byte body int offs int size int type throws io exception writer write ref id oid if exported bitmap oid 5 1 oid 31 0 marked bitmap oid 5 1 oid 31 if compound key types null export compound key body offs size type else writer write key export key body offs size type writer write writer write n exportassoc ioexception exportedbitmap markedbitmap compoundkeytypes exportcompoundkey exportkey final void indentation int indent throws io exception while indent 0 writer write ioexception final void export char char ch throws io exception switch ch case writer write lt break case writer write gt break case writer write amp break case writer write quot break default writer write ch exportchar ioexception final int export string byte body int offs throws io exception int len bytes unpack4 body offs offs 4 if len 0 writer write while len 0 export char char bytes unpack2 body offs offs 2 writer write else if len 1 writer write string s if storage encoding null s new string body offs len 2 storage encoding else s new string body offs len 2 offs len 2 for int i 0 n s length i n i export char s char at i writer write else writer write null return offs exportstring ioexception exportchar exportchar charat final int export binary byte body int offs throws io exception int len bytes unpack4 body offs offs 4 if len 0 if len 2 class descriptor tp object export ref bytes unpack4 body offs offs 4 else if len 1 writer write writer write hex digit 2 len len class descriptor sizeof 2 len while len 0 byte b body offs writer write hex digit b 4 0xf writer write hex digit b 0xf writer write else writer write null else writer write while len 0 byte b body offs writer write hex digit b 4 0xf writer write hex digit b 0xf writer write return offs exportbinary ioexception classdescriptor tpobject exportref hexdigit classdescriptor hexdigit hexdigit hexdigit hexdigit final void export ref int oid throws io exception writer write ref id oid if oid 0 exported bitmap oid 5 1 oid 31 0 marked bitmap oid 5 1 oid 31 exportref ioexception exportedbitmap markedbitmap final int export object class descriptor desc byte body int offs int indent throws io exception class descriptor field descriptor all desc all fields for int i 0 n all length i n i class descriptor field descriptor fd all i indentation indent string field name export identifier fd field name writer write field name switch fd type case class descriptor tp boolean writer write body offs 0 1 0 break case class descriptor tp byte writer write integer to string body offs break case class descriptor tp char writer write integer to string char bytes unpack2 body offs offs 2 break case class descriptor tp short writer write integer to string bytes unpack2 body offs offs 2 break case class descriptor tp int writer write integer to string bytes unpack4 body offs offs 4 break case class descriptor tp long writer write long to string bytes unpack8 body offs offs 8 break case class descriptor tp float writer write float to string float int bits to float bytes unpack4 body offs offs 4 break case class descriptor tp double writer write double to string double long bits to double bytes unpack8 body offs offs 8 break case class descriptor tp enum int ordinal bytes unpack4 body offs if ordinal 0 writer write null else writer write enum fd field get type get enum constants ordinal name offs 4 break case class descriptor tp string offs export string body offs break case class descriptor tp date long msec bytes unpack8 body offs offs 8 if msec 0 writer write xml importer http formatter format new date msec else writer write null break case class descriptor tp object export ref bytes unpack4 body offs offs 4 break case class descriptor tp value writer write n offs export object fd value desc body offs indent 1 indentation indent break case class descriptor tp raw case class descriptor tp array of byte offs export binary body offs break case class descriptor tp custom byte array input stream in new byte array input stream body offs body length offs custom serializable obj storage serializer unpack in string str obj to string writer write for int j 0 len str length j len j export char str char at j writer write offs body length in available break case class descriptor tp array of boolean int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element body offs 0 1 0 element n indentation indent break case class descriptor tp array of char int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element bytes unpack2 body offs 0xffff element n offs 2 indentation indent break case class descriptor tp array of short int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element bytes unpack2 body offs element n offs 2 indentation indent break case class descriptor tp array of enum int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n enum enum constants enum fd field get type get enum constants while len 0 indentation indent 1 int ordinal bytes unpack4 body offs if ordinal 0 writer write null else writer write element enum constants ordinal name element n offs 4 indentation indent break case class descriptor tp array of int int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element bytes unpack4 body offs element n offs 4 indentation indent break case class descriptor tp array of long int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element bytes unpack8 body offs element n offs 8 indentation indent break case class descriptor tp array of float int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element float int bits to float bytes unpack4 body offs element n offs 4 indentation indent break case class descriptor tp array of double int len bytes unpack4 body offs offs 4 if len 0 writer write null else writer write n while len 0 indentation indent 1 writer write element double long bits to double bytes unpack8 body offs element n offs 8 exportobject classdescriptor ioexception classdescriptor fielddescriptor allfields classdescriptor fielddescriptor fieldname exportidentifier fieldname fieldname classdescriptor tpboolean classdescriptor tpbyte tostring classdescriptor tpchar tostring classdescriptor tpshort tostring classdescriptor tpint tostring classdescriptor tplong tostring classdescriptor tpfloat tostring intbitstofloat classdescriptor tpdouble tostring longbitstodouble classdescriptor tpenum gettype getenumconstants classdescriptor tpstring exportstring classdescriptor tpdate xmlimporter httpformatter classdescriptor tpobject exportref classdescriptor tpvalue exportobject valuedesc classdescriptor tpraw classdescriptor tparrayofbyte exportbinary classdescriptor tpcustom bytearrayinputstream bytearrayinputstream customserializable tostring exportchar charat classdescriptor tparrayofboolean classdescriptor tparrayofchar classdescriptor tparrayofshort classdescriptor tparrayofenum enumconstants gettype getenumconstants enumconstants classdescriptor tparrayofint classdescriptor tparrayoflong classdescriptor tparrayoffloat intbitstofloat classdescriptor tparrayofdouble longbitstodouble public service state table servicestatetable public state variable get state variable int n return state variable get n statevariable getstatevariable statevariable private static final long serial versionuid 1l public resume exception string msg super msg serialversionuid resumeexception public resume exception string msg cannot create from field set exception e super msg e e resumeexception cannotcreatefromfieldsetexception public final class dodge composite extends rgb composite public dodge composite float alpha super alpha dodgecomposite rgbcomposite dodgecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor clamp sr 8 256 dir dog clamp sg 8 256 dig dob clamp sb 8 256 dib float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac smallest y coordinate of the rectangle public final int get top return top gettop smallest x coordinate of the rectangle public final int get left return left getleft greatest y coordinate of the rectangle public final int get bottom return bottom getbottom greatest x coordinate of the rectangle public final int get right return right getright rectangle area public final long area return long bottom top right left area of covered rectangle for two sepcified rectangles public static long join area rectangle a rectangle b int left a left b left a left b left int right a right b right a right b right int top a top b top a top b top int bottom a bottom b bottom a bottom b bottom return long bottom top right left joinarea clone rectangle public object clone try rectangle r rectangle super clone r top this top r left this left r bottom this bottom r right this right return r catch clone not supported exception e this shouldn t happen since we are cloneable throw new internal error clonenotsupportedexception internalerror create copy of the rectangle public rectangle rectangle r this top r top this left r left this bottom r bottom this right r right construct rectangle with specified coordinates public rectangle int top int left int bottom int right assert that top bottom left right this top top this left left this bottom bottom this right right default constructor for perst public rectangle join two rectangles this rectangle is updates to contain cover of this and specified rectangle param r rectangle to be joined with this rectangle public final void join rectangle r if left r left left r left if right r right right r right if top r top top r top if bottom r bottom bottom r bottom non destructive join of two rectangles param a first joined rectangle param b second joined rectangle return rectangle containing cover of these two rectangles public static rectangle join rectangle a rectangle b rectangle r new rectangle a r join b return r checks if this rectangle intersects with specified rectangle public final boolean intersects rectangle r return left r right top r bottom right r left bottom r top checks if this rectangle contains the specified rectangle public final boolean contains rectangle r return left r left top r top right r right bottom r bottom check if two rectangles are equal public boolean equals object o if o instanceof rectangle rectangle r rectangle o return left r left top r top right r right bottom r bottom return false hash code consists of all rectangle coordinates public int hash code return top bottom 1 left 2 right 3 hashcode public string to string return top top left left bottom bottom right right tostring private ssdp search response socket list ssdp search response socket list private ssdp notify socket list getssdp notify socket list return ssdp notify socket list ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist ssdpnotifysocketlist getssdpnotifysocketlist ssdpnotifysocketlist private ssdp search response socket list getssdp search response socket list return ssdp search response socket list ssdpsearchresponsesocketlist getssdpsearchresponsesocketlist ssdpsearchresponsesocketlist public control point int ssdp port int http port ssdp notify socket list new ssdp notify socket list ssdp search response socket list new ssdp search response socket list setssdp port ssdp port sethttp port http port set device disposer null set expired device monitoring interval default expired device monitoring interval set renew subscriber null setnmpr mode false set renew subscriber null controlpoint ssdpport httpport ssdpnotifysocketlist ssdpnotifysocketlist ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist setssdpport ssdpport sethttpport httpport setdevicedisposer setexpireddevicemonitoringinterval default_expired_device_monitoring_interval setrenewsubscriber setnmprmode setrenewsubscriber public control point this default ssdp port default eventsub port controlpoint default_ssdp_port default_eventsub_port public void finalize stop private mutex mutex new mutex public void lock mutex lock public void unlock mutex unlock private int ssdp port 0 public int getssdp port return ssdp port ssdpport getssdpport ssdpport public void setssdp port int port ssdp port port setssdpport ssdpport private int http port 0 public int gethttp port return http port httpport gethttpport httpport public void sethttp port int port http port port sethttpport httpport private boolean nmpr mode public void setnmpr mode boolean flag nmpr mode flag nmprmode setnmprmode nmprmode public boolean isnmpr mode return nmpr mode isnmprmode nmprmode private node list dev node list new node list private void add device node root node dev node list add root node nodelist devnodelist nodelist adddevice rootnode devnodelist rootnode private synchronized void add device ssdp packet ssdp packet if ssdp packet is root device false return string usn ssdp packet getusn string udn usn getudn usn device dev get device udn if dev null dev setssdp packet ssdp packet return string location ssdp packet get location try url location url new url location parser parser u pnp getxml parser node root node parser parse location url device root dev get device root node if root dev null return root dev setssdp packet ssdp packet add device root node thanks for oliver newell 2004 10 16 after node is added invoke the add device listener to notify high level control point application that a new device has been added the control point application must implement the device change listener interface to receive the notifications perform add device listener root dev catch malformedurl exception me debug warning ssdp packet to string debug warning me catch parser exception pe debug warning ssdp packet to string debug warning pe adddevice ssdppacket ssdppacket ssdppacket isrootdevice ssdppacket getdevice setssdppacket ssdppacket ssdppacket getlocation locationurl upnp getxmlparser rootnode locationurl rootdev getdevice rootnode rootdev rootdev setssdppacket ssdppacket adddevice rootnode adddevicelistener devicechangelistener performadddevicelistener rootdev malformedurlexception ssdppacket tostring parserexception ssdppacket tostring private device get device node root node if root node null return null node dev node root node get node device elem name if dev node null return null return new device root node dev node getdevice rootnode rootnode devnode rootnode getnode elem_name devnode rootnode devnode public device list get device list device list dev list new device list int n roots dev node list size for int n 0 n n roots n node root node dev node list get node n device dev get device root node if dev null continue dev list add dev return dev list devicelist getdevicelist devicelist devlist devicelist nroots devnodelist nroots rootnode devnodelist getnode getdevice rootnode devlist devlist public device get device string name int n roots dev node list size for int n 0 n n roots n node root node dev node list get node n device dev get device root node if dev null continue if dev is device name true return dev device cdev dev get device name if cdev null return cdev return null getdevice nroots devnodelist nroots rootnode devnodelist getnode getdevice rootnode isdevice getdevice public boolean has device string name return get device name null true false hasdevice getdevice private void remove device node root node thanks for oliver newell 2004 10 16 invoke device removal listener prior to actual removal so device node remains valid for the duration of the listener application may want to access the node device dev get device root node if dev null dev is root device perform remove device listener dev dev node list remove root node removedevice rootnode getdevice rootnode isrootdevice performremovedevicelistener devnodelist rootnode private void remove device device dev if dev null return remove device dev get root node removedevice removedevice getrootnode private void remove device string name device dev get device name remove device dev removedevice getdevice removedevice private void remove device ssdp packet packet if packet is bye bye false return string usn packet getusn string udn usn getudn usn remove device udn removedevice ssdppacket isbyebye removedevice public void remove expired devices device list dev list get device list int dev cnt dev list size device dev new device dev cnt for int n 0 n dev cnt n dev n dev list get device n for int n 0 n dev cnt n if dev n is expired true debug message expired device dev n get friendly name remove device dev n removeexpireddevices devicelist devlist getdevicelist devcnt devlist devcnt devcnt devlist getdevice devcnt isexpired getfriendlyname removedevice public void set expired device monitoring interval long interval expired device monitoring interval interval setexpireddevicemonitoringinterval expireddevicemonitoringinterval public long get expired device monitoring interval return expired device monitoring interval getexpireddevicemonitoringinterval expireddevicemonitoringinterval public void set device disposer disposer disposer device disposer disposer setdevicedisposer devicedisposer public disposer get device disposer return device disposer getdevicedisposer devicedisposer private listener list device notify listener list new listener list public void add notify listener notify listener listener device notify listener list add listener listenerlist devicenotifylistenerlist listenerlist addnotifylistener notifylistener devicenotifylistenerlist public void remove notify listener notify listener listener device notify listener list remove listener removenotifylistener notifylistener devicenotifylistenerlist public void perform notify listener ssdp packet ssdp packet int listener size device notify listener list size for int n 0 n listener size n notify listener listener notify listener device notify listener list get n listener device notify received ssdp packet performnotifylistener ssdppacket ssdppacket listenersize devicenotifylistenerlist listenersize notifylistener notifylistener devicenotifylistenerlist devicenotifyreceived ssdppacket private listener list device search response listener list new listener list public void add search response listener search response listener listener device search response listener list add listener listenerlist devicesearchresponselistenerlist listenerlist addsearchresponselistener searchresponselistener devicesearchresponselistenerlist public void remove search response listener search response listener listener device search response listener list remove listener removesearchresponselistener searchresponselistener devicesearchresponselistenerlist public void perform search response listener ssdp packet ssdp packet int listener size device search response listener list size for int n 0 n listener size n search response listener listener search response listener device search response listener list get n listener device search response received ssdp packet performsearchresponselistener ssdppacket ssdppacket listenersize devicesearchresponselistenerlist listenersize searchresponselistener searchresponselistener devicesearchresponselistenerlist devicesearchresponsereceived ssdppacket listener list device change listener list new listener list public void add device change listener device change listener listener device change listener list add listener listenerlist devicechangelistenerlist listenerlist adddevicechangelistener devicechangelistener devicechangelistenerlist public void remove device change listener device change listener listener device change listener list remove listener removedevicechangelistener devicechangelistener devicechangelistenerlist public void perform add device listener device dev int listener size device change listener list size for int n 0 n listener size n device change listener listener device change listener device change listener list get n listener device added dev performadddevicelistener listenersize devicechangelistenerlist listenersize devicechangelistener devicechangelistener devicechangelistenerlist deviceadded public void perform remove device listener device dev int listener size device change listener list size for int n 0 n listener size n device change listener listener device change listener device change listener list get n listener device removed dev performremovedevicelistener listenersize devicechangelistenerlist listenersize devicechangelistener devicechangelistener devicechangelistenerlist deviceremoved public void notify received ssdp packet packet if packet is root device true if packet is alive true add device packet if packet is bye bye true remove device packet perform notify listener packet notifyreceived ssdppacket isrootdevice isalive adddevice isbyebye removedevice performnotifylistener public void search response received ssdp packet packet if packet is root device true add device packet perform search response listener packet searchresponsereceived ssdppacket isrootdevice adddevice performsearchresponselistener private int search mx ssdp default msearch mx public int get search mx return search mx searchmx default_msearch_mx getsearchmx searchmx public void set search mx int mx search mx mx setsearchmx searchmx public void search string target int mx ssdp search request ms req new ssdp search request target mx ssdp search response socket list ssdp search response socket list getssdp search response socket list ssdp search response socket list post ms req ssdpsearchrequest msreq ssdpsearchrequest ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist getssdpsearchresponsesocketlist ssdpsearchresponsesocketlist msreq public void search string target search target ssdp default msearch mx default_msearch_mx public void search search st root device ssdp default msearch mx root_device default_msearch_mx private http server list http server list new http server list private http server list gethttp server list return http server list httpserverlist httpserverlist httpserverlist httpserverlist gethttpserverlist httpserverlist public void http request recieved http request http req if debug is on true http req print thanks for giordano sassaroli sassarol cefriel it 09 08 03 if http req is notify request true notify request notify req new notify request http req string uuid notify req getsid long seq notify req getseq property list props notify req get property list int prop cnt props size for int n 0 n prop cnt n property prop props get property n string var name prop get name string var value prop get value perform event listener uuid seq var name var value http req returnok return http req return bad request httprequestrecieved httprequest httpreq ison httpreq httpreq isnotifyrequest notifyrequest notifyreq notifyrequest httpreq notifyreq notifyreq propertylist notifyreq getpropertylist propcnt propcnt getproperty varname getname varvalue getvalue performeventlistener varname varvalue httpreq httpreq returnbadrequest private listener list event listener list new listener list public void add event listener event listener listener event listener list add listener listenerlist eventlistenerlist listenerlist addeventlistener eventlistener eventlistenerlist public void remove event listener event listener listener event listener list remove listener removeeventlistener eventlistener eventlistenerlist public void perform event listener string uuid long seq string name string value int listener size event listener list size for int n 0 n listener size n event listener listener event listener event listener list get n listener event notify received uuid seq name value performeventlistener listenersize eventlistenerlist listenersize eventlistener eventlistener eventlistenerlist eventnotifyreceived private string event suburi default eventsub uri public string get event suburi return event suburi eventsuburi default_eventsub_uri geteventsuburi eventsuburi public void set event suburi string url event suburi url seteventsuburi eventsuburi private string get event sub callbackurl string host return host interface get hosturl host gethttp port get event suburi geteventsubcallbackurl hostinterface gethosturl gethttpport geteventsuburi public boolean subscribe service service long timeout if service is subscribed true string sid service getsid return subscribe service sid timeout device root dev service get root device if root dev null return false string if address root dev get interface address subscription request sub req new subscription request sub req set subscribe request service get event sub callbackurl if address timeout subscription response sub res sub req post if sub res is successful true service setsid sub res getsid service set timeout sub res get timeout return true service clearsid return false issubscribed rootdev getrootdevice rootdev ifaddress rootdev getinterfaceaddress subscriptionrequest subreq subscriptionrequest subreq setsubscriberequest geteventsubcallbackurl ifaddress subscriptionresponse subres subreq subres issuccessful subres settimeout subres gettimeout public boolean subscribe service service return subscribe service subscription infinite value infinite_value public boolean subscribe service service string uuid long timeout subscription request sub req new subscription request sub req set renew request service uuid timeout if debug is on true sub req print subscription response sub res sub req post if debug is on true sub res print if sub res is successful true service setsid sub res getsid service set timeout sub res get timeout return true service clearsid return false subscriptionrequest subreq subscriptionrequest subreq setrenewrequest ison subreq subscriptionresponse subres subreq ison subres subres issuccessful subres settimeout subres gettimeout public boolean subscribe service service string uuid return subscribe service uuid subscription infinite value infinite_value public boolean is subscribed service service if service null return false return service is subscribed issubscribed issubscribed public boolean unsubscribe service service subscription request sub req new subscription request sub req set unsubscribe request service subscription response sub res sub req post if sub res is successful true service clearsid return true return false subscriptionrequest subreq subscriptionrequest subreq setunsubscriberequest subscriptionresponse subres subreq subres issuccessful public void unsubscribe device device service list service list device get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service hassid true unsubscribe service device list child dev list device get device list int child dev cnt child dev list size for int n 0 n child dev cnt n device cdev child dev list get device n unsubscribe cdev servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice devicelist childdevlist getdevicelist childdevcnt childdevlist childdevcnt childdevlist getdevice public void unsubscribe device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n unsubscribe dev devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice public service get subscriber service string uuid device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get subscriber service uuid if service null return service return null getsubscriberservice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getsubscriberservice public void renew subscriber service device dev long timeout service list service list dev get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service is subscribed false continue string sid service getsid boolean is renewed subscribe service sid timeout if is renewed false subscribe service timeout device list cdev list dev get device list int cdev cnt cdev list size for int n 0 n cdev cnt n device cdev cdev list get device n renew subscriber service cdev timeout renewsubscriberservice servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice issubscribed isrenewed isrenewed devicelist cdevlist getdevicelist cdevcnt cdevlist cdevcnt cdevlist getdevice renewsubscriberservice public void renew subscriber service long timeout device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n renew subscriber service dev timeout renewsubscriberservice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice renewsubscriberservice public void renew subscriber service renew subscriber service subscription infinite value renewsubscriberservice renewsubscriberservice infinite_value private renew subscriber renew subscriber public void set renew subscriber renew subscriber sub renew subscriber sub renewsubscriber renewsubscriber setrenewsubscriber renewsubscriber renewsubscriber public renew subscriber get renew subscriber return renew subscriber renewsubscriber getrenewsubscriber renewsubscriber public boolean start string target int mx stop http server int retry cnt 0 int bind port gethttp port http server list http server list gethttp server list while http server list open bind port false retry cnt if u pnp server retry count retry cnt return false sethttp port bind port 1 bind port gethttp port http server list add request listener this http server list start notify socket ssdp notify socket list ssdp notify socket list getssdp notify socket list if ssdp notify socket list open false return false ssdp notify socket list set control point this ssdp notify socket list start seach response socket int ssdp port getssdp port retry cnt 0 ssdp search response socket list ssdp search response socket list getssdp search response socket list while ssdp search response socket list open ssdp port false retry cnt if u pnp server retry count retry cnt return false setssdp port ssdp port 1 ssdp port getssdp port ssdp search response socket list set control point this ssdp search response socket list start search root devices search target mx disposer disposer disposer new disposer this set device disposer disposer disposer start subscriber if isnmpr mode true renew subscriber renew sub new renew subscriber this set renew subscriber renew sub renew sub start return true retrycnt bindport gethttpport httpserverlist httpserverlist gethttpserverlist httpserverlist bindport retrycnt upnp server_retry_count retrycnt sethttpport bindport bindport gethttpport httpserverlist addrequestlistener httpserverlist ssdpnotifysocketlist ssdpnotifysocketlist getssdpnotifysocketlist ssdpnotifysocketlist ssdpnotifysocketlist setcontrolpoint ssdpnotifysocketlist seachresponse ssdpport getssdpport retrycnt ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist getssdpsearchresponsesocketlist ssdpsearchresponsesocketlist ssdpport retrycnt upnp server_retry_count retrycnt setssdpport ssdpport ssdpport getssdpport ssdpsearchresponsesocketlist setcontrolpoint ssdpsearchresponsesocketlist setdevicedisposer isnmprmode renewsubscriber renewsub renewsubscriber setrenewsubscriber renewsub renewsub public boolean start string target return start target ssdp default msearch mx default_msearch_mx public boolean start return start st root device ssdp default msearch mx root_device default_msearch_mx public boolean stop unsubscribe ssdp notify socket list ssdp notify socket list getssdp notify socket list ssdp notify socket list stop ssdp notify socket list close ssdp notify socket list clear ssdp search response socket list ssdp search response socket list getssdp search response socket list ssdp search response socket list stop ssdp search response socket list close ssdp search response socket list clear http server list http server list gethttp server list http server list stop http server list close http server list clear disposer disposer disposer get device disposer if disposer null disposer stop set device disposer null subscriber renew subscriber renew sub get renew subscriber if renew sub null renew sub stop set renew subscriber null return true ssdpnotifysocketlist ssdpnotifysocketlist getssdpnotifysocketlist ssdpnotifysocketlist ssdpnotifysocketlist ssdpnotifysocketlist ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist getssdpsearchresponsesocketlist ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist ssdpsearchresponsesocketlist httpserverlist httpserverlist gethttpserverlist httpserverlist httpserverlist httpserverlist getdevicedisposer setdevicedisposer renewsubscriber renewsub getrenewsubscriber renewsub renewsub setrenewsubscriber public void print device list dev list get device list int dev cnt dev list size debug message device num dev cnt for int n 0 n dev cnt n device dev dev list get device n debug message n dev get friendly name dev get lease time dev get elapsed time devicelist devlist getdevicelist devcnt devlist devcnt devcnt devlist getdevice getfriendlyname getleasetime getelapsedtime private string code description switch code case client hello must be first message return client hello must be first message case no late client hellos return no late client hello s accepted case message parse error return unknown message parsing error case freenet uri parse error return error parsing freenet uri case missing field return missing field case error parsing number return error parsing a numeric field case invalid message return don t know what to do with message case invalid field return invalid field value case file not found return file not found not a file or not readable case disk target exists return disk target exists refusing to overwrite for security reasons case filename and temp filename must be in same dir return filename and temp filename must be in same directory so can rename case could not create file return could not create file case could not write file return could not write file case could not rename file return could not rename file case no such identifier return no such identifier case not supported return not supported case internal error return internal error case shutting down return shutting down case no such node identifier unused return no such node identifier case url parse error return error parsing url case ref parse error return reference could not be parsed case file parse error return file could not be read case not a file error return filepath is not a file case access denied return access denied case direct disk access denied return direct disk access operation denied did you send a file hash field did you use testdda case could not read file return could not read file case ref signature invalid return reference signature failed to verify case cannot peer with self return node cannot peer with itself case duplicate peer ref return node already has a peer with that ref case opennet disabled return opennet is currently disabled in the node s configuration case darknet only return operation only available on a darknet peer case no such plugin return no such plugin default logger error this unknown error code code new exception debug return unknown codedescription client_hello_must_be_first_message clienthello no_late_client_hellos clienthello message_parse_error freenet_uri_parse_error missing_field error_parsing_number invalid_message invalid_field file_not_found disk_target_exists filename_and_temp_filename_must_be_in_same_dir could_not_create_file could_not_write_file could_not_rename_file no_such_identifier not_supported internal_error shutting_down no_such_node_identifier nodeidentifier url_parse_error ref_parse_error file_parse_error not_a_file_error access_denied direct_disk_access_denied filehash could_not_read_file ref_signature_invalid cannot_peer_with_self duplicate_peer_ref opennet_disabled darknet_only no_such_plugin public protocol error message int code boolean fatal string extra string ident boolean global this code code this extra extra this fatal fatal this ident ident this global global protocolerrormessage public protocol error message simple field set fs ident fs get identifier code integer parse int fs get code extra fs get extra description fatal fields string to bool fs get fatal false global fields string to bool fs get global false protocolerrormessage simplefieldset parseint extradescription stringtobool stringtobool override public simple field set get field set simple field set sfs new simple field set true if ident null sfs put single identifier ident sfs put code code sfs put single code description code description if extra null sfs put single extra description extra sfs put fatal fatal if global sfs put single global true return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle codedescription codedescription putsingle extradescription putsingle override public void run fcp connection handler handler node node logger error this client reported protocol error fcpconnectionhandler override public string get name return protocol error getname protocolerror override public void remove from object container container container delete this removefrom objectcontainer private float icentrex icentrey public flare filter set radius 50 0f flarefilter setradius public void set color int color this color color setcolor public int get color return color getcolor public void set ring width float ring width this ring width ring width setringwidth ringwidth ringwidth ringwidth public float get ring width return ring width getringwidth ringwidth public void set base amount float base amount this base amount base amount setbaseamount baseamount baseamount baseamount public float get base amount return base amount getbaseamount baseamount public void set ring amount float ring amount this ring amount ring amount setringamount ringamount ringamount ringamount public float get ring amount return ring amount getringamount ringamount public void set ray amount float ray amount this ray amount ray amount setrayamount rayamount rayamount rayamount public float get ray amount return ray amount getrayamount rayamount public void set centre point2d centre this centrex float centre getx this centrey float centre gety setcentre public point2d get centre return new point2d float centrex centrey getcentre set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius sigma radius 3 getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius override public void set dimensions int width int height this width width this height height icentrex centrex width icentrey centrey height super set dimensions width height setdimensions setdimensions override public int filterrgb int x int y int rgb float dx x icentrex float dy y icentrey float distance float math sqrt dx dx dy dy float a float math exp distance distance gauss mix float math exp distance linear 1 mix float ring a base amount if distance radius ring width a image math lerp distance radius ring width falloff a 0 if distance radius ring width distance radius ring width ring 0 else ring math abs distance radius ring width ring 1 ring ring 3 2 ring ring ring amount a ring float angle float math atan2 dx dy image math pi angle image math mod angle image math pi 17 1 0f noise noise1 angle 10 1 0f 0 5f 2 angle math abs angle angle float math pow angle 5 0 float b ray amount angle 1 distance 0 1f a b a image math clamp a 0 1 return image math mix colors a rgb color baseamount ringwidth imagemath ringwidth ringwidth ringwidth ringwidth ringamount imagemath imagemath imagemath rayamount imagemath imagemath mixcolors override public string to string return stylize flare tostring transient field fld rnd btree field index rndbtreefieldindex private final void locate field fld class descriptor locate field cls field name if fld null throw new storage error storage error indexed field not found class name field name locatefield classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return new field fld getkeyfields public void on load cls class descriptor load class get storage class name locate field onload classdescriptor loadclass getstorage classname locatefield rnd btree field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate field type check type fld get type rndbtreefieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefield checktype gettype private key extract key i persistent obj try field f fld key key null switch type case class descriptor tp boolean key new key f get boolean obj break case class descriptor tp byte key new key f get byte obj break case class descriptor tp short key new key f get short obj break case class descriptor tp char key new key f get char obj break case class descriptor tp int key new key f get int obj break case class descriptor tp object i persistent ptr i persistent f get obj if ptr null ptr is persistent get storage make persistent ptr key new key ptr break case class descriptor tp long key new key f get long obj break case class descriptor tp date key new key date f get obj break case class descriptor tp float key new key f get float obj break case class descriptor tp double key new key f get double obj break case class descriptor tp enum key new key enum f get obj break case class descriptor tp string key new key string f get obj break case class descriptor tp raw key new key comparable f get obj break default assert failed invalid type return key catch exception x throw new storage error storage error access violation x extractkey ipersistent classdescriptor tpboolean getboolean classdescriptor tpbyte getbyte classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tpobject ipersistent ipersistent ispersistent getstorage makepersistent classdescriptor tplong getlong classdescriptor tpdate classdescriptor tpfloat getfloat classdescriptor tpdouble getdouble classdescriptor tpenum classdescriptor tpstring classdescriptor tpraw storageerror storageerror access_violation public boolean put t obj return super insert extract key obj obj false null extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public synchronized void append t obj key key try switch type case class descriptor tp int key new key int autoinc count fld set int obj int autoinc count break case class descriptor tp long key new key autoinc count fld set long obj autoinc count break default throw new storage error storage error unsupported index type fld get type catch exception x throw new storage error storage error access violation x autoinc count 1 obj modify super insert key obj false classdescriptor tpint autoinccount setint autoinccount classdescriptor tplong autoinccount setlong autoinccount storageerror storageerror unsupported_index_type gettype storageerror storageerror access_violation autoinccount public t get prefix string prefix array list t list get list new key prefix true new key prefix character max value false return t list to array t array new instance cls list size getprefix arraylist getlist max_value toarray newinstance public t prefix search string key array list t list prefix search list key return t list to array t array new instance cls list size prefixsearch arraylist prefixsearchlist toarray newinstance public t get key from key till array list t list new array list if root null root find check key from check key till height list return t list to array t array new instance cls list size arraylist arraylist checkkey checkkey toarray newinstance public t to persistent array t arr t array new instance cls n elems if root null root traverse forward height arr 0 return arr topersistentarray newinstance nelems traverseforward public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class rnd btree case insensitive field index t extends i persistent extends rnd btree field index t rnd btree case insensitive field index rndbtreecaseinsensitivefieldindex ipersistent rndbtreefieldindex rndbtreecaseinsensitivefieldindex rnd btree case insensitive field index rnd btree case insensitive field index class cls string field name boolean unique super cls field name unique rndbtreecaseinsensitivefieldindex rndbtreecaseinsensitivefieldindex fieldname fieldname key check key key key if key null key oval instanceof string key new key string key oval to lower case key inclusion 0 return super check key key checkkey tolowercase checkkey public boolean is case insensitive return true iscaseinsensitive final string identifier public plugin reply sender string pluginname2 string identifier2 pluginname pluginname2 identifier identifier2 pluginreplysender public void send simple field set params throws plugin not found exception send params bucket null simplefieldset pluginnotfoundexception public void send simple field set params byte data throws plugin not found exception send params new array bucket data simplefieldset pluginnotfoundexception arraybucket public abstract void send simple field set params bucket bucket throws plugin not found exception simplefieldset pluginnotfoundexception private float width45 3 0f public emboss filter embossfilter public void set azimuth float azimuth this azimuth azimuth setazimuth public float get azimuth return azimuth getazimuth public void set elevation float elevation this elevation elevation setelevation public float get elevation return elevation getelevation public void set bump height float bump height this width45 3 bump height setbumpheight bumpheight bumpheight public float get bump height return width45 3 getbumpheight public void set emboss boolean emboss this emboss emboss setemboss public boolean get emboss return emboss getemboss override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height int bump pixels int bump map width bump map height bump map width width bump map height height bump pixels new int bump map width bump map height for int i 0 i in pixels length i bump pixels i pixel utils brightness in pixels i int nx ny nz lx ly lz nz2 nz lz ndotl int shade background lx int math cos azimuth math cos elevation pixel scale ly int math sin azimuth math cos elevation pixel scale lz int math sin elevation pixel scale nz int 6 255 width45 nz2 nz nz nz lz nz lz background lz int bump index 0 for int y 0 y height y bump index bump map width int s1 bump index int s2 s1 bump map width int s3 s2 bump map width for int x 0 x width x s1 s2 s3 if y 0 y height 2 x 0 x width 2 nx bump pixels s1 1 bump pixels s2 1 bump pixels s3 1 bump pixels s1 1 bump pixels s2 1 bump pixels s3 1 ny bump pixels s3 1 bump pixels s3 bump pixels s3 1 bump pixels s1 1 bump pixels s1 bump pixels s1 1 if nx 0 ny 0 shade background else if ndotl nx lx ny ly nz lz 0 shade 0 else shade int ndotl math sqrt nx nx ny ny nz2 else shade background if emboss int rgb in pixels index int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r r shade 8 g g shade 8 b b shade 8 out pixels index a r 16 g 8 b else out pixels index 0xff000000 shade 16 shade 8 shade return out pixels filterpixels inpixels transformedspace outpixels bumppixels bumpmapwidth bumpmapheight bumpmapwidth bumpmapheight bumppixels bumpmapwidth bumpmapheight inpixels bumppixels pixelutils inpixels nzlz pixelscale pixelscale pixelscale nzlz bumpindex bumpindex bumpmapwidth bumpindex bumpmapwidth bumpmapwidth bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels bumppixels nzlz inpixels outpixels outpixels outpixels override public string to string return stylize emboss tostring public final class wot own message list extends own message list public wot own message list ft own identity new author int new index super new author new index todo auto generated constructor stub wotownmessagelist ownmessagelist wotownmessagelist ftownidentity newauthor newindex newauthor newindex override protected freeneturi generateuri freeneturi baseuri int index return wot message list assembleuri baseuri index wotmessagelist public synchronized void increment insert index synchronized wot own message list class int free index wot message manager m message manager get free own message list index wot own identity m author m index math max m index 1 free index mid calculateid store incrementinsertindex wotownmessagelist freeindex wotmessagemanager mmessagemanager getfreeownmessagelistindex wotownidentity mauthor mindex mindex freeindex public wot own identity get author return wot own identity m author wotownidentity getauthor wotownidentity mauthor returns true if the xml of this message list fits into a single ssk block protected boolean fits into container fixme implement return true fitsintocontainer public pproxy toadlet high level simple client client node node node client core core super client this node node this core core pproxytoadlet highlevelsimpleclient nodeclientcore override public string supported methods return get post supportedmethods override public void handle post uri uri http request request toadlet context ctx throws toadlet context closed exception io exception multi value table string string headers new multi value table string string string pass request get part as string form password 32 if pass null pass equals core form password headers put location plugins ctx send reply headers 302 found headers null 0 return if ctx is allowed full access super send error page ctx 403 l10n unauthorized title l10n unauthorized return string path request get path remove leading and plugins from path if path starts with path path substring 1 if path starts with plugins path path substring plugins length if logger should log logger minor this logger minor this pproxy received post on path plugin manager pm node plugin manager if path length 0 try string plugin null split path into plugin class name and daa path for plugin int to path index of if to 1 plugin path else plugin path substring 0 to writehtml reply ctx 200 ok pm handlehttp post plugin request catch redirect pluginhttp exception e write temporary redirect ctx e message e new location catch not found pluginhttp exception e send error page ctx not found pluginhttp exception code e message e location catch access denied pluginhttp exception e send error page ctx access denied pluginhttp exception code e message e location catch download pluginhttp exception e fixme maybe it ought to be defined like send error page in toadlets multi value table string string head new multi value table string string head put content disposition attachment filename e filename ctx send reply headers download pluginhttp exception code found head e mime type e data length ctx write data e data catch pluginhttp exception e send error page ctx pluginhttp exception code e message e location catch throwable t write internal error t ctx else page maker page maker ctx get page maker if request is part set submit official string plugin name null plugin name request get part as string plugin name 40 pm start plugin official plugin name true headers put location ctx send reply headers 302 found headers null 0 return if request is part set submit other string plugin name null plugin name request get part as string plugin url 200 boolean fileonly on equals ignore case request get part as string fileonly 20 if fileonly pm start plugin file plugin name true else pm start pluginurl plugin name true headers put location ctx send reply headers 302 found headers null 0 return if request is part set submit freenet string plugin name null plugin name request get part as string plugin uri 300 pm start plugin freenet plugin name true headers put location ctx send reply headers 302 found headers null 0 return if request is part set dismiss user alert int user alert hash code request get int part disable 1 core alerts dismiss alert user alert hash code headers put location ctx send reply headers 302 found headers null 0 return if request is part set cancel headers put location plugins ctx send reply headers 302 found headers null 0 return if request get part as string unloadconfirm max plugin name length length 0 string plugin thread name request get part as string unloadconfirm max plugin name length string plugin specification get plugin specification pm plugin thread name pm kill plugin plugin thread name max threaded unload wait time if request is part set purge pm remove cached copy plugin specification html node page node page maker get page node l10n plugins ctx html node content node page maker get content node page node html node infobox content node add child div class infobox infobox success infobox add child div class infobox header l10n plugin unloaded html node infobox content infobox add child div class infobox content infobox content add child l10n plugin unloaded with name name plugin thread name infobox content add child br infobox content add child a href plugins l10n return to plugin page writehtml reply ctx 200 ok page node generate return if request get part as string unload max plugin name length length 0 html node page node page maker get page node l10n plugins ctx html node content node page maker get content node page node html node infobox content node add child div class infobox infobox query infobox add child div class infobox header l10n unload plugin title html node infobox content infobox add child div class infobox content infobox content add child l10n unload plugin with name name request get part as string unload max plugin name length html node unload form ctx add form child infobox content plugins unload plugin confirm form unload form add child input new string type name value new string hidden unloadconfirm request get part as string unload max plugin name length html node temp node unload form add child p temp node add child input new string type name new string checkbox purge temp node add child l10n unload purge temp node unload form add child p temp node add child input new string type name value new string submit confirm l10n unload temp node add child temp node add child input new string type name value new string submit cancel l10n get string toadlet cancel writehtml reply ctx 200 ok page node generate return else if request get part as string reload max plugin name length length 0 html node page node page maker get page node l10n plugins ctx html node content node page maker get content node page node html node reload box content node add child page maker get infobox infobox infobox query l10n reload plugin title html node reload content page maker get content node reload box reload content add child p l10n reload explanation reload content add child p l10n reload warning html node reload form ctx add form child reload content plugins reload plugin confirm form reload form add child input new string type name value new string hidden reloadconfirm request get part as string reload max plugin name length html node temp node reload form add child p temp node add child input new string type name new string checkbox purge temp node add child l10n reload purge warning temp node reload form add child p temp node add child input new string type name value new string submit confirm l10n reload temp node add child temp node add child input new string type name value new string submit cancel l10n get string toadlet cancel writehtml reply ctx 200 ok page node generate return else if request get part as string reloadconfirm max plugin name length length 0 boolean purge request is part set purge string plugin thread name request get part as string reloadconfirm max plugin name length string fn get plugin specification pm plugin thread name if fn null send error page ctx 404 l10n plugin not found reload title l10n get string plugin toadlet plugin not found reload else pm kill plugin plugin thread name max threaded unload wait time if purge pm remove cached copy fn fixme pm start plugin auto fn true headers put location ctx send reply headers 302 found headers null 0 return else ignore headers put location ctx send reply headers 302 found headers null 0 handlepost httprequest toadletcontext toadletcontextclosedexception ioexception multivaluetable multivaluetable getpartasstring formpassword formpassword sendreplyheaders isallowedfullaccess senderrorpage unauthorizedtitle getpath startswith startswith shouldlog pluginmanager pluginmanager indexof writehtmlreply handlehttppost redirectpluginhttpexception writetemporaryredirect newlocation notfoundpluginhttpexception senderrorpage notfoundpluginhttpexception accessdeniedpluginhttpexception senderrorpage accessdeniedpluginhttpexception downloadpluginhttpexception senderrorpage multivaluetable multivaluetable sendreplyheaders downloadpluginhttpexception mimetype writedata pluginhttpexception senderrorpage pluginhttpexception writeinternalerror pagemaker pagemaker getpagemaker ispartset pluginname pluginname getpartasstring startpluginofficial pluginname sendreplyheaders ispartset pluginname pluginname getpartasstring equalsignorecase getpartasstring startpluginfile pluginname startpluginurl pluginname sendreplyheaders ispartset pluginname pluginname getpartasstring startpluginfreenet pluginname sendreplyheaders ispartset useralerthashcode getintpart dismissalert useralerthashcode sendreplyheaders ispartset sendreplyheaders getpartasstring max_plugin_name_length pluginthreadname getpartasstring max_plugin_name_length pluginspecification getpluginspecification pluginthreadname killplugin pluginthreadname max_threaded_unload_wait_time ispartset removecachedcopy pluginspecification htmlnode pagenode pagemaker getpagenode htmlnode contentnode pagemaker getcontentnode pagenode htmlnode contentnode addchild addchild pluginunloaded htmlnode infoboxcontent addchild infoboxcontent addchild pluginunloadedwithname pluginthreadname infoboxcontent addchild infoboxcontent addchild returntopluginpage writehtmlreply pagenode getpartasstring max_plugin_name_length htmlnode pagenode pagemaker getpagenode htmlnode contentnode pagemaker getcontentnode pagenode htmlnode contentnode addchild addchild unloadplugintitle htmlnode infoboxcontent addchild infoboxcontent addchild unloadpluginwithname getpartasstring max_plugin_name_length htmlnode unloadform addformchild infoboxcontent unloadpluginconfirmform unloadform addchild getpartasstring max_plugin_name_length htmlnode tempnode unloadform addchild tempnode addchild tempnode addchild unloadpurge tempnode unloadform addchild tempnode addchild tempnode addchild tempnode addchild getstring writehtmlreply pagenode getpartasstring max_plugin_name_length htmlnode pagenode pagemaker getpagenode htmlnode contentnode pagemaker getcontentnode pagenode htmlnode reloadbox contentnode addchild pagemaker getinfobox reloadplugintitle htmlnode reloadcontent pagemaker getcontentnode reloadbox reloadcontent addchild reloadexplanation reloadcontent addchild reloadwarning htmlnode reloadform addformchild reloadcontent reloadpluginconfirmform reloadform addchild getpartasstring max_plugin_name_length htmlnode tempnode reloadform addchild tempnode addchild tempnode addchild reloadpurgewarning tempnode reloadform addchild tempnode addchild tempnode addchild tempnode addchild getstring writehtmlreply pagenode getpartasstring max_plugin_name_length ispartset pluginthreadname getpartasstring max_plugin_name_length getpluginspecification pluginthreadname senderrorpage pluginnotfoundreloadtitle getstring plugintoadlet pluginnotfoundreload killplugin pluginthreadname max_threaded_unload_wait_time removecachedcopy startpluginauto sendreplyheaders sendreplyheaders searches all plugins for the plugin with the given thread name and returns the plugin specification used to load the plugin param plugin manager the plugin manager param plugin thread name the thread name of the plugin return the plugin specification of the plugin or code null code if no plugin was found private string get plugin specification plugin manager plugin manager string plugin thread name iterator plugin info wrapper it plugin manager get plugins iterator while it has next plugin info wrapper pi it next if pi get thread name equals plugin thread name return pi get filename return null pluginmanager pluginthreadname getpluginspecification pluginmanager pluginmanager pluginthreadname plugininfowrapper pluginmanager getplugins hasnext plugininfowrapper getthreadname pluginthreadname getfilename private string l10n string key string pattern string value return l10n get string pproxy toadlet key new string pattern new string value getstring pproxytoadlet private string l10n string key return l10n get string pproxy toadlet key getstring pproxytoadlet override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception string basepath plugins string path request get path remove leading and plugins from path if path starts with path path substring 1 if path starts with plugins path path substring plugins length plugin manager pm node plugin manager if logger should log logger minor this logger minor this pproxy fetching path try if path equals if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return iterator plugin progress loading plugins pm get starting plugins iterator html node page node ctx get page maker get page node l10n plugins with node name name core get my name ctx if loading plugins has next okay add a refresh html node head node ctx get page maker get head node page node head node add child meta new string http equiv content new string refresh 10 url html node content node ctx get page maker get content node page node content node add child core alerts create summary user alert user alerts core alerts get alerts for int index 0 count user alerts length index count index user alert user alert user alerts index if user alert is valid user alert get user identifier plugin manager class content node add child core alerts render alert user alert find which plugins have already been loaded list string available plugins pm find available plugins iterator plugin info wrapper loaded plugins pm get plugins iterator while loaded plugins has next plugin info wrapper plugin info wrapper loaded plugins next string plugin name plugin info wrapper get plugin class name string short plugin name plugin name substring plugin name last index of 1 available plugins remove short plugin name while loading plugins has next plugin progress plugin progress loading plugins next string plugin name plugin progress get name available plugins remove plugin name show starting plugins pm content node show plugin list ctx pm content node show official plugin loader ctx content node available plugins show unofficial plugin loader ctx content node show freenet plugin loader ctx content node writehtml reply ctx 200 ok page node generate else split path into plugin class name and data path for plugin int to path index of string plugin if to 1 plugin path else plugin path substring 0 to plugin may need to know where it was accessed from so it can e g produce relative ur ls write reply ctx 200 text html ok mk page plugin pm handlehttp get plugin data writehtml reply ctx 200 ok pm handlehttp get plugin request fetch result result fetch key write reply ctx 200 result get mime type ok result as bucket catch redirect pluginhttp exception e write temporary redirect ctx e message e new location catch not found pluginhttp exception e send error page ctx not found pluginhttp exception code e message e location catch access denied pluginhttp exception e send error page ctx access denied pluginhttp exception code e message e location catch download pluginhttp exception e fixme maybe it ought to be defined like send error page in toadlets multi value table string string head new multi value table string string head put content disposition attachment filename e filename ctx send reply headers download pluginhttp exception code found head e mime type e data length ctx write data e data catch pluginhttp exception e send error page ctx pluginhttp exception code e message e location catch throwable t ctx force disconnect write internal error t ctx handleget httprequest toadletcontext toadletcontextclosedexception ioexception getpath startswith startswith pluginmanager pluginmanager shouldlog isallowedfullaccess senderrorpage getstring pluginprogress loadingplugins getstartingplugins htmlnode pagenode getpagemaker getpagenode pluginswithnodename getmyname loadingplugins hasnext htmlnode headnode getpagemaker getheadnode pagenode headnode addchild htmlnode contentnode getpagemaker getcontentnode pagenode contentnode addchild createsummary useralert useralerts getalerts useralerts useralert useralert useralerts useralert isvalid useralert getuseridentifier pluginmanager contentnode addchild renderalert useralert availableplugins findavailableplugins plugininfowrapper loadedplugins getplugins loadedplugins hasnext plugininfowrapper plugininfowrapper loadedplugins pluginname plugininfowrapper getpluginclassname shortpluginname pluginname pluginname lastindexof availableplugins shortpluginname loadingplugins hasnext pluginprogress pluginprogress loadingplugins pluginname pluginprogress getname availableplugins pluginname showstartingplugins contentnode showpluginlist contentnode showofficialpluginloader contentnode availableplugins showunofficialpluginloader contentnode showfreenetpluginloader contentnode writehtmlreply pagenode indexof urls writereply mkpage handlehttpget writehtmlreply handlehttpget fetchresult writereply getmimetype asbucket redirectpluginhttpexception writetemporaryredirect newlocation notfoundpluginhttpexception senderrorpage notfoundpluginhttpexception accessdeniedpluginhttpexception senderrorpage accessdeniedpluginhttpexception downloadpluginhttpexception senderrorpage multivaluetable multivaluetable sendreplyheaders downloadpluginhttpexception mimetype writedata pluginhttpexception senderrorpage pluginhttpexception forcedisconnect writeinternalerror shows a list of all currently loading plugins param plugin manager the plugin manager param content node the node to add content to private void show starting plugins plugin manager plugin manager html node content node set plugin progress starting plugins plugin manager get starting plugins if starting plugins is empty html node starting plugins box content node add child div class infobox infobox normal starting plugins box add child div class infobox header l10n starting plugins title html node starting plugins content starting plugins box add child div class infobox content html node starting plugins table starting plugins content add child table html node starting plugins header starting plugins table add child tr starting plugins header add child th l10n starting plugin name starting plugins header add child th l10n starting plugin status starting plugins header add child th l10n starting plugin time iterator plugin progress starting plugins iterator starting plugins iterator while starting plugins iterator has next plugin progress plugin progress starting plugins iterator next html node starting plugins row starting plugins table add child tr starting plugins row add child td plugin progress get name starting plugins row add child td l10n starting plugin status plugin progress get progress to string starting plugins row add child td aligh right time util format time plugin progress get time pluginmanager contentnode showstartingplugins pluginmanager pluginmanager htmlnode contentnode pluginprogress startingplugins pluginmanager getstartingplugins startingplugins isempty htmlnode startingpluginsbox contentnode addchild startingpluginsbox addchild startingpluginstitle htmlnode startingpluginscontent startingpluginsbox addchild htmlnode startingpluginstable startingpluginscontent addchild htmlnode startingpluginsheader startingpluginstable addchild startingpluginsheader addchild startingpluginname startingpluginsheader addchild startingpluginstatus startingpluginsheader addchild startingplugintime pluginprogress startingpluginsiterator startingplugins startingpluginsiterator hasnext pluginprogress pluginprogress startingpluginsiterator htmlnode startingpluginsrow startingpluginstable addchild startingpluginsrow addchild pluginprogress getname startingpluginsrow addchild startingpluginstatus pluginprogress getprogress tostring startingpluginsrow addchild timeutil formattime pluginprogress gettime private void show plugin list toadlet context ctx plugin manager pm html node content node throws toadlet context closed exception io exception html node infobox content node add child div class infobox infobox normal infobox add child div class infobox header l10n get string plugin toadlet plugin list title html node infobox content infobox add child div class infobox content if pm get plugins is empty infobox content add child div l10n no plugins else html node plugin table infobox content add child table class plugins html node header row plugin table add child tr header row add child th l10n class name title header row add child th l10n version title header row add child th l10n internalid title header row add child th l10n started at title header row add child th header row add child th header row add child th iterator plugin info wrapper it pm get plugins iterator while it has next plugin info wrapper pi it next html node plugin row plugin table add child tr plugin row add child td pi get plugin class name long ver pi get plugin long version if ver 1 plugin row add child td pi get plugin version ver else plugin row add child td pi get plugin version plugin row add child td pi get thread name plugin row add child td new date pi get started to string if pi is stopping plugin row add child td l10n plugin stopping add two empty cells plugin row add child td plugin row add child td else if pi is pproxy plugin html node visit form plugin row add child td add child form new string method action target new string get pi get plugin class name blank visit form add child input new string type name value new string hidden form password core form password visit form add child input new string type value new string submit l10n get string plugin toadlet visit html node unload form ctx add form child plugin row add child td unload plugin form unload form add child input new string type name value new string hidden unload pi get thread name unload form add child input new string type value new string submit l10n unload html node reload form ctx add form child plugin row add child td reload plugin form reload form add child input new string type name value new string hidden reload pi get thread name reload form add child input new string type value new string submit l10n reload showpluginlist toadletcontext pluginmanager htmlnode contentnode toadletcontextclosedexception ioexception htmlnode contentnode addchild addchild getstring plugintoadlet pluginlisttitle htmlnode infoboxcontent addchild getplugins isempty infoboxcontent addchild noplugins htmlnode plugintable infoboxcontent addchild htmlnode headerrow plugintable addchild headerrow addchild classnametitle headerrow addchild versiontitle headerrow addchild internalidtitle headerrow addchild startedattitle headerrow addchild headerrow addchild headerrow addchild plugininfowrapper getplugins hasnext plugininfowrapper htmlnode pluginrow plugintable addchild pluginrow addchild getpluginclassname getpluginlongversion pluginrow addchild getpluginversion pluginrow addchild getpluginversion pluginrow addchild getthreadname pluginrow addchild getstarted tostring isstopping pluginrow addchild pluginstopping pluginrow addchild pluginrow addchild ispproxyplugin htmlnode visitform pluginrow addchild addchild getpluginclassname _blank visitform addchild formpassword formpassword visitform addchild getstring plugintoadlet htmlnode unloadform addformchild pluginrow addchild unloadpluginform unloadform addchild getthreadname unloadform addchild htmlnode reloadform addformchild pluginrow addchild reloadpluginform reloadform addchild getthreadname reloadform addchild private void show official plugin loader toadlet context toadlet context html node content node list string available plugins box for official plugins html node add official plugin box content node add child div class infobox infobox normal add official plugin box add child div class infobox header l10n load official plugin html node add official plugin content add official plugin box add child div class infobox content html node add official form toadlet context add form child add official plugin content add official plugin form add official form add child div l10n load official plugin text fixme css ize this add official form add child p add child b add child font new string color new string red l10n load official plugin warning add official form add child l10n load official plugin label html node select node add official form add child select name plugin name iterator string available plugin iterator available plugins iterator while available plugin iterator has next string plugin name available plugin iterator next select node add child option value plugin name plugin name add official form add child add official form add child input new string type name value new string submit submit official l10n load showofficialpluginloader toadletcontext toadletcontext htmlnode contentnode availableplugins htmlnode addofficialpluginbox contentnode addchild addofficialpluginbox addchild loadofficialplugin htmlnode addofficialplugincontent addofficialpluginbox addchild htmlnode addofficialform toadletcontext addformchild addofficialplugincontent addofficialpluginform addofficialform addchild loadofficialplugintext addofficialform addchild addchild addchild loadofficialpluginwarning addofficialform addchild loadofficialpluginlabel htmlnode selectnode addofficialform addchild availablepluginiterator availableplugins availablepluginiterator hasnext pluginname availablepluginiterator selectnode addchild pluginname pluginname addofficialform addchild addofficialform addchild private void show unofficial plugin loader toadlet context toadlet context html node content node box for unofficial plugins html node add other plugin box content node add child div class infobox infobox normal add other plugin box add child div class infobox header l10n load other plugin html node add other plugin content add other plugin box add child div class infobox content html node add other form toadlet context add form child add other plugin content add other plugin form add other form add child div l10n load other plugin text add other form add child l10n load otherurl label add other form add child input new string type name size new string text plugin url 80 add other form add child add other form add child input new string type name value new string submit submit other l10n load add other form add child br add other form add child input new string type name checked new string checkbox fileonly checked add other form add child l10n fileonly showunofficialpluginloader toadletcontext toadletcontext htmlnode contentnode htmlnode addotherpluginbox contentnode addchild addotherpluginbox addchild loadotherplugin htmlnode addotherplugincontent addotherpluginbox addchild htmlnode addotherform toadletcontext addformchild addotherplugincontent addotherpluginform addotherform addchild loadotherplugintext addotherform addchild loadotherurllabel addotherform addchild addotherform addchild addotherform addchild addotherform addchild addotherform addchild addotherform addchild private void show freenet plugin loader toadlet context toadlet context html node content node box for freenet plugins html node add freenet plugin box content node add child div class infobox infobox normal add freenet plugin box add child div class infobox header l10n load freenet plugin html node add freenet plugin content add freenet plugin box add child div class infobox content html node add freenet form toadlet context add form child add freenet plugin content add freenet plugin form add freenet form add child div l10n load freenet plugin text add freenet form add child l10n load freeneturl label add freenet form add child input new string type name size new string text plugin uri 80 add freenet form add child add freenet form add child input new string type name value new string submit submit freenet l10n load showfreenetpluginloader toadletcontext toadletcontext htmlnode contentnode htmlnode addfreenetpluginbox contentnode addchild addfreenetpluginbox addchild loadfreenetplugin htmlnode addfreenetplugincontent addfreenetpluginbox addchild htmlnode addfreenetform toadletcontext addformchild addfreenetplugincontent addfreenetpluginform addfreenetform addchild loadfreenetplugintext addfreenetform addchild loadfreeneturllabel addfreenetform addchild addfreenetform addchild addfreenetform addchild private language string short code string full name string iso code this short code short code this full name full name this iso code iso code this l10n filename freenet l10n freenet l10n short code properties this l10n override filename freenet l10n short code override properties shortcode fullname isocode shortcode shortcode fullname fullname isocode isocode l10nfilename shortcode l10noverridefilename shortcode language language l this l short code l full name l iso code shortcode fullname isocode public static language map to language string whatever for language current language language values if current language short code equals ignore case whatever current language full name equals ignore case whatever current language iso code equals ignore case whatever current language to string equals ignore case whatever return current language return null maptolanguage currentlanguage currentlanguage shortcode equalsignorecase currentlanguage fullname equalsignorecase currentlanguage isocode equalsignorecase currentlanguage tostring equalsignorecase currentlanguage public static string values with full names language all values values string result new string all values length for int i 0 i all values length i result i all values i full name return result valueswithfullnames allvalues allvalues allvalues allvalues fullname public static language get default return english getdefault l10n language selected selected language selected try file tmp file new file selected l10n override filename if tmp file exists tmp file can read tmp file length 0 logger normal this override file detected let s try to load it translation override simple field set read from tmp file false false else try to restore a backup file backup new file tmp file get parent file tmp file get name bak if backup exists backup length 0 logger normal this override backup file detected let s try to load it translation override simple field set read from backup false false translation override null catch io exception e translation override null logger error this io error while accessing the file e get message e current translation load translation selected language if current translation null logger error this the translation file for selected language is invalid the node will load an empty template current translation null translation override new simple field set false selectedlanguage tmpfile l10noverridefilename tmpfile tmpfile canread tmpfile translationoverride simplefieldset readfrom tmpfile tmpfile getparentfile tmpfile getname translationoverride simplefieldset readfrom translationoverride ioexception translationoverride ioerror getmessage currenttranslation loadtranslation selectedlanguage currenttranslation selectedlanguage currenttranslation translationoverride simplefieldset set the default language used by the framework param selected language 2 letter code throws missing resource exception public static void set language string selected language throws missing resource exception synchronized sync logger normal class name changing the current language to selected language l10n old class current class language lang language map to language selected language if lang null current class old class null old class new l10n language get default logger error class name the requested translation is not available selected language throw new missing resource exception the requested translation selected language hasn t been found class name selected language else current class new l10n lang selectedlanguage missingresourceexception setlanguage selectedlanguage missingresourceexception class_name selectedlanguage oldclass currentclass maptolanguage selectedlanguage currentclass oldclass oldclass getdefault class_name selectedlanguage missingresourceexception selectedlanguage class_name selectedlanguage currentclass public static void set override string key string value key key trim value value trim synchronized sync is the override already declared if not create it if translation override null translation override new simple field set false if there is no need to keep it in the override remove it unless the original default is the same as the translation if equals value value equals current translation get key translation override remove value key else value value replace all r n t set the value of the override translation override put overwrite key value logger normal class name got a new translation key set the override save the file to disk savetranslationfile setoverride translationoverride translationoverride simplefieldset currenttranslation translationoverride removevalue replaceall translationoverride putoverwrite class_name _savetranslationfile private static void savetranslationfile file output stream fos null file final file new file get selected language l10n override filename try we don t set delete on exit on it if the save operation fails we want a backup fixme redflag not symlink race proof file temp file new file final file get parent file final file get name bak logger minor class name the temporary filename is temp file fos new file output stream temp file l10n translation override write to fos file util rename to temp file final file logger normal class name override file saved successfully catch io exception e logger error class name error while saving the translation override e get message e finally closer close fos _savetranslationfile fileoutputstream finalfile getselectedlanguage l10noverridefilename deleteonexit tempfile finalfile getparentfile finalfile getname class_name tempfile fileoutputstream tempfile translationoverride writeto fileutil renameto tempfile finalfile class_name ioexception class_name getmessage return a new copy of the current translation file return simple field set or null public static simple field set get current language translation synchronized sync return current translation null null new simple field set current translation simplefieldset simplefieldset getcurrentlanguagetranslation currenttranslation simplefieldset currenttranslation return a copy of the current translation override if it exists or null return simple field set or null public static simple field set get override for current language translation synchronized sync return translation override null null new simple field set translation override simplefieldset simplefieldset getoverrideforcurrentlanguagetranslation translationoverride simplefieldset translationoverride return a copy of the default translation file english one return simple field set public static simple field set get default language translation synchronized sync if fallback translation null fallback translation load translation language get default return new simple field set fallback translation simplefieldset simplefieldset getdefaultlanguagetranslation fallbacktranslation fallbacktranslation loadtranslation getdefault simplefieldset fallbacktranslation the real meat same thing as get string key false ensure it will always return a string value param key return the translated string or the default value from the default language or the key if nothing is found public static string get string string key return get string key false getstring getstring getstring you probably don t want to use that one directly see get string string public static string get string string key boolean return null if not found string result null synchronized sync if translation override null result translation override get key if result null return result synchronized sync if current translation null result current translation get key if result null return result else logger normal class name the translation for key hasn t been found get selected language please tell the maintainer return return null if not found null get default string key getstring getstring returnnullifnotfound translationoverride translationoverride currenttranslation currenttranslation class_name getselectedlanguage returnnullifnotfound getdefaultstring almost the same as get string string but it returns a html node and gives the user the ability to contribute to the translation though the translation toadlet param key return html node public static html node gethtml node string key string value get string key true if value null return new html node value html node translation field new html node span class translate it translation field add child get default string key translation field add child a href translation toadlet toadlet url translate key add child small translate it in your native language return translation field getstring htmlnode htmlnode htmlnode gethtmlnode getstring htmlnode htmlnode translationfield htmlnode translate_it translationfield addchild getdefaultstring translationfield addchild translationtoadlet toadlet_url addchild translationfield return the english translation of the key or the key itself if it doesn t exist param key return string public static string get default string string key string result null we instanciate it only if necessary synchronized sync if fallback translation null fallback translation load translation language get default result fallback translation get key if result null return result logger error class name the default translation for key hasn t been found system err println the default translation for key hasn t been found new exception print stack trace return key getdefaultstring fallbacktranslation fallbacktranslation loadtranslation getdefault fallbacktranslation class_name printstacktrace allows things like l10n get string testing test new string test1 test2 a b param key param patterns a list of patterns wich are matchable from the translation param values the values corresponding to the list return the translated string or the default value from the default language or the key if nothing is found public static string get string string key string patterns string values assert patterns length values length string result get string key for int i 0 i patterns length i result result replace all patterns i quote replacement values i return result getstring getstring getstring replaceall quotereplacement private static string quote replacement string s if s index of 1 s index of 1 return s string builder sb new string builder for int i 0 i s length i char c s char at i if c sb append sb append else if c sb append sb append else sb append c return sb to string quotereplacement indexof indexof stringbuilder stringbuilder charat tostring return the iso code of the language used by the framework return string public static language get selected language synchronized sync if current class null current class selected language null return language get default else return current class selected language getselectedlanguage currentclass currentclass selectedlanguage getdefault currentclass selectedlanguage load a translation file depending on the given name and using the prefix param lang the chosen language return the properties object or null if not found public static simple field set load translation language lang simple field set result null input stream in null try class loader loader class loader get system class loader returns null on lookup failures in loader get resource as stream lang l10n filename if in null result simple field set read from in false false catch exception e logger error class name error while loading the l10n file from lang l10n filename e get message e result null finally closer close in return result simplefieldset loadtranslation simplefieldset inputstream classloader classloader getsystemclassloader getresourceasstream l10nfilename simplefieldset readfrom class_name l10nfilename getmessage public static boolean is overridden string key synchronized sync if translation override null return false return translation override get key null isoverridden translationoverride translationoverride add a localised string with some raw html substitutions useful when some part of a sentence needs to be bold e g param key the l10n key param patterns the strings to search for param values the strings to substitute in public static void addl10n substitution html node node string key string patterns string values string result html encoder encode get string key assert patterns length values length for int i 0 i patterns length i result result replace all patterns i quote replacement values i node add child result addl10nsubstitution htmlnode htmlencoder getstring replaceall quotereplacement addchild public static string get string string key string pattern string value return get string key new string pattern new string value fixme code efficiently getstring getstring private static final long serial versionuid 1 public invalid parameter exception string message super message serialversionuid invalidparameterexception public abstract class sendable insert extends sendable request public sendable insert boolean persistent super persistent sendableinsert sendablerequest sendableinsert called when we successfully insert the data public abstract void on success object key num object container container client context context onsuccess keynum objectcontainer clientcontext public abstract void on success object key num object container container client context context called when we don t public abstract void on failure low level put exception e object key num object container container client context context onsuccess keynum objectcontainer clientcontext onfailure lowlevelputexception keynum objectcontainer clientcontext public abstract void on failure low level put exception e object key num object container container client context context override public void internal error throwable t request scheduler sched object container container client context context boolean persistent sched call failure this new low level put exception low level put exception internal error t get message t native thread max priority persistent onfailure lowlevelputexception keynum objectcontainer clientcontext internalerror requestscheduler objectcontainer clientcontext callfailure lowlevelputexception lowlevelputexception internal_error getmessage nativethread max_priority override public final boolean is insert return true isinsert override public client request scheduler get scheduler client context context if isssk return context get ssk insert scheduler else return context get chk insert scheduler clientrequestscheduler getscheduler clientcontext getsskinsertscheduler getchkinsertscheduler public abstract boolean cache inserts object container container cacheinserts objectcontainer public static final message create packet transmit long uid int packet no bit array sent buffer data message msg new message packet transmit msg set uid uid msg set packet no packet no msg set sent sent msg set data data return msg createpackettransmit packetno bitarray packettransmit packet_no packetno public static int packet transmit size int size int packets return size 8 uid 4 packet bit array serialized length packets 4 message header packettransmitsize _packets bitarray serializedlength _packets public static int bulk packet transmit size int size return size 8 uid 4 packet 4 message header bulkpackettransmitsize public static final message create all sent long uid message msg new message all sent msg set uid uid return msg createallsent allsent public static final message create missing packet notification long uid linked list integer missing message msg new message missing packet notification msg set uid uid msg set missing missing return msg createmissingpacketnotification linkedlist missingpacketnotification public static final message create all received long uid message msg new message all received msg set uid uid return msg createallreceived allreceived public static final message create send aborted long uid int reason string description message msg new message send aborted msg set uid uid msg set reason reason msg set description description return msg createsendaborted sendaborted public static final message createfnp bulk packet send long uid int packet no short buffer data message msg new message fnp bulk packet send msg set uid uid msg set packet no packet no msg set data data return msg createfnpbulkpacketsend packetno shortbuffer fnpbulkpacketsend packet_no packetno public static final message createfnp bulk packet send long uid int packet no byte data return createfnp bulk packet send uid packet no new short buffer data createfnpbulkpacketsend packetno createfnpbulkpacketsend packetno shortbuffer public static final message createfnp bulk send aborted long uid message msg new message fnp bulk send aborted msg set uid uid return msg createfnpbulksendaborted fnpbulksendaborted public static final message createfnp bulk receive aborted long uid message msg new message fnp bulk receive aborted msg set uid uid return msg createfnpbulkreceiveaborted fnpbulkreceiveaborted public static final message createfnp bulk received all long uid message msg new message fnp bulk received all msg set uid uid return msg createfnpbulkreceivedall fnpbulkreceivedall public static final message create test transfer send long uid message msg new message test transfer send msg set uid uid return msg createtesttransfersend testtransfersend public static final message create test transfer send ack long uid message msg new message test transfer send ack msg set uid uid return msg createtesttransfersendack testtransfersendack public static final message create test sendchk long uid string uri buffer header message msg new message test sendchk msg set uid uid msg set freenet uri uri msg set chk header header return msg createtestsendchk testsendchk freenet_uri chk_header public static final message create test request key key long id int htl message msg new message test request msg set uid id msg set freenet routing key key msg set htl htl return msg createtestrequest testrequest freenet_routing_key public static final message create test data not found long uid message msg new message test data not found msg set uid uid return msg createtestdatanotfound testdatanotfound public static final message create test data reply long uid byte headers message msg new message test data reply msg set uid uid msg set test chk headers new buffer headers return msg createtestdatareply testdatareply test_chk_headers public static final message create test sendchk ack long uid string key message msg new message test sendchk ack msg set uid uid msg set freenet uri key return msg createtestsendchkack testsendchkack freenet_uri public static final message create test data reply ack long id message msg new message test data reply ack msg set uid id return msg createtestdatareplyack testdatareplyack public static final message create test data not found ack long id message msg new message test data not found ack msg set uid id return msg createtestdatanotfoundack testdatanotfoundack public static final message create test receive completed long id boolean success string reason message msg new message test receive completed msg set uid id msg set success success msg set reason reason return msg createtestreceivecompleted testreceivecompleted public static final message create test send completed long id boolean success string reason message msg new message test send completed msg set uid id msg set success success msg set reason reason return msg createtestsendcompleted testsendcompleted public static final message create node to node message int type byte data message msg new message node to node message msg set node to node message type type msg set node to node message data new short buffer data return msg createnodetonodemessage nodetonodemessage node_to_node_message_type node_to_node_message_data shortbuffer public static final message createfnpchk data request long id short htl nodechk key message msg new message fnpchk data request msg set uid id msg set htl htl msg set freenet routing key key msg set nearest location 0 0 return msg createfnpchkdatarequest fnpchkdatarequest freenet_routing_key nearest_location public static final message createfnpssk data request long id short htl nodessk key boolean need pub key message msg new message fnpssk data request msg set uid id msg set htl htl msg set freenet routing key key msg set nearest location 0 0 msg set need pub key need pub key return msg createfnpsskdatarequest needpubkey fnpsskdatarequest freenet_routing_key nearest_location need_pub_key needpubkey public static final message createfnp rejected loop long id message msg new message fnp rejected loop msg set uid id return msg createfnprejectedloop fnprejectedloop public static final message createfnp rejected overload long id boolean is local message msg new message fnp rejected overload msg set uid id msg set is local is local return msg createfnprejectedoverload islocal fnprejectedoverload is_local islocal public static final message createfnp accepted long id message msg new message fnp accepted msg set uid id return msg createfnpaccepted fnpaccepted public static final message createfnp data not found long id message msg new message fnp data not found msg set uid id return msg createfnpdatanotfound fnpdatanotfound public static final message createfnp recently failed long id int time left message msg new message fnp recently failed msg set uid id msg set time left time left return msg createfnprecentlyfailed timeleft fnprecentlyfailed time_left timeleft public static final message createfnpchk data found long id byte buf message msg new message fnpchk data found msg set uid id msg set block headers new short buffer buf return msg createfnpchkdatafound fnpchkdatafound block_headers shortbuffer public static final message createfnp route not found long id short htl message msg new message fnp route not found msg set uid id msg set htl htl return msg createfnproutenotfound fnproutenotfound public static final message createfnp insert request long id short htl key key message msg new message fnp insert request msg set uid id msg set htl htl msg set freenet routing key key msg set nearest location 0 0 return msg createfnpinsertrequest fnpinsertrequest freenet_routing_key nearest_location public static final message createfnp insert reply long id message msg new message fnp insert reply msg set uid id return msg createfnpinsertreply fnpinsertreply public static final message createfnp data insert long uid byte headers message msg new message fnp data insert msg set uid uid msg set block headers new short buffer headers return msg createfnpdatainsert fnpdatainsert block_headers shortbuffer public static final message createfnp insert transfers completed long uid boolean any timed out message msg new message fnp insert transfers completed msg set uid uid msg set any timed out any timed out return msg createfnpinserttransferscompleted anytimedout fnpinserttransferscompleted any_timed_out anytimedout public static final message createfnp rejected timeout long uid message msg new message fnp rejected timeout msg set uid uid return msg createfnprejectedtimeout fnprejectedtimeout public static final message createfnp data insert rejected long uid short reason message msg new message fnp data insert rejected msg set uid uid msg set data insert rejected reason reason return msg createfnpdatainsertrejected fnpdatainsertrejected data_insert_rejected_reason public static final string get data insert rejected reason short reason if reason data insert rejected verify failed return verify failed else if reason data insert rejected receive failed return receive failed else if reason data insert rejected ssk error return ssk error return unknown reason code reason getdatainsertrejectedreason data_insert_rejected_verify_failed data_insert_rejected_receive_failed data_insert_rejected_ssk_error public static message createfnpssk insert request long uid short htl nodessk my key byte headers byte data byte pub key hash message msg new message fnpssk insert request msg set uid uid msg set htl htl msg set freenet routing key my key msg set nearest location 0 0 msg set block headers new short buffer headers msg set pubkey hash new short buffer pub key hash msg set data new short buffer data return msg createfnpsskinsertrequest mykey pubkeyhash fnpsskinsertrequest freenet_routing_key mykey nearest_location block_headers shortbuffer pubkey_hash shortbuffer pubkeyhash shortbuffer public static message createfnpssk insert request new long uid short htl nodessk my key message msg new message fnpssk insert request new msg set uid uid msg set htl htl msg set freenet routing key my key return msg createfnpsskinsertrequestnew mykey fnpsskinsertrequestnew freenet_routing_key mykey public static final message createfnpssk insert request headers long uid byte headers message msg new message fnpssk insert request headers msg set uid uid msg set block headers new short buffer headers return msg createfnpsskinsertrequestheaders fnpsskinsertrequestheaders block_headers shortbuffer public static final message createfnpssk insert request data long uid byte data message msg new message fnpssk insert request data msg set uid uid msg set data new short buffer data return msg createfnpsskinsertrequestdata fnpsskinsertrequestdata shortbuffer public static message createfnpssk data found headers long uid byte headers message msg new message fnpssk data found headers msg set uid uid msg set block headers new short buffer headers return msg createfnpsskdatafoundheaders fnpsskdatafoundheaders block_headers shortbuffer public static message createfnpssk data found data long uid byte data message msg new message fnpssk data found data msg set uid uid msg set data new short buffer data return msg createfnpsskdatafounddata fnpsskdatafounddata shortbuffer public static final message createfnpssk accepted long uid boolean need pub key message msg new message fnpssk accepted msg set uid uid msg set need pub key need pub key return msg createfnpsskaccepted needpubkey fnpsskaccepted need_pub_key needpubkey public static message createfnpssk pub key long uid dsa public key pubkey message msg new message fnpssk pub key msg set uid uid msg set pubkey as bytes new short buffer pubkey as padded bytes return msg createfnpsskpubkey dsapublickey fnpsskpubkey pubkey_as_bytes shortbuffer aspaddedbytes public static message createfnpssk pub key accepted long uid message msg new message fnpssk pub key accepted msg set uid uid return msg createfnpsskpubkeyaccepted fnpsskpubkeyaccepted public static message createfnp opennet completed ack long uid message msg new message fnp opennet completed ack msg set uid uid return msg createfnpopennetcompletedack fnpopennetcompletedack public static message createfnp opennet connect destination new long uid long transferuid int noderef length int padded length message msg new message fnp opennet connect destination new msg set uid uid msg set transfer uid transferuid msg set noderef length noderef length msg set padded length padded length return msg createfnpopennetconnectdestinationnew nodereflength paddedlength fnpopennetconnectdestinationnew transfer_uid noderef_length nodereflength padded_length paddedlength public static message createfnp opennet connect reply new long uid long transferuid int noderef length int padded length message msg new message fnp opennet connect reply new msg set uid uid msg set transfer uid transferuid msg set noderef length noderef length msg set padded length padded length return msg createfnpopennetconnectreplynew nodereflength paddedlength fnpopennetconnectreplynew transfer_uid noderef_length nodereflength padded_length paddedlength public static message createfnp opennet announce request long uid long transferuid int noderef length int padded length double target short htl message msg new message fnp opennet announce request msg set uid uid msg set transfer uid transferuid msg set noderef length noderef length msg set padded length padded length msg set htl htl msg set nearest location 0 0 msg set target location target return msg createfnpopennetannouncerequest nodereflength paddedlength fnpopennetannouncerequest transfer_uid noderef_length nodereflength padded_length paddedlength nearest_location target_location public static message createfnp opennet announce reply long uid long transferuid int noderef length int padded length message msg new message fnp opennet announce reply msg set uid uid msg set transfer uid transferuid msg set noderef length noderef length msg set padded length padded length return msg createfnpopennetannouncereply nodereflength paddedlength fnpopennetannouncereply transfer_uid noderef_length nodereflength padded_length paddedlength public static message createfnp opennet announce completed long uid message msg new message fnp opennet announce completed msg set uid uid return msg createfnpopennetannouncecompleted fnpopennetannouncecompleted public static message createfnp opennet disabled long uid message msg new message fnp opennet disabled msg set uid uid return msg createfnpopennetdisabled fnpopennetdisabled public static message createfnp opennet noderef rejected long uid int reject code message msg new message fnp opennet noderef rejected msg set uid uid msg set reject code reject code return msg createfnpopennetnoderefrejected rejectcode fnpopennetnoderefrejected reject_code rejectcode public static string get opennet rejected code int x switch x case noderef rejected too big return too big case noderef rejected real bigger than padded return real length bigger than padded length case noderef rejected transfer failed return transfer failed case noderef rejected invalid return invalid noderef default return unknown rejection code x getopennetrejectedcode noderef_rejected_too_big noderef_rejected_real_bigger_than_padded noderef_rejected_transfer_failed noderef_rejected_invalid public static message createfnp opennet announce node not wanted long uid message msg new message fnp opennet announce node not wanted msg set uid uid return msg createfnpopennetannouncenodenotwanted fnpopennetannouncenodenotwanted public static message createfnp offer key key key byte authenticator message msg new message fnp offer key msg set key key msg set offer authenticator new short buffer authenticator return msg createfnpofferkey fnpofferkey offer_authenticator shortbuffer public static message createfnp get offered key key key byte authenticator boolean need pubkey long uid message msg new message fnp get offered key msg set key key msg set offer authenticator new short buffer authenticator msg set need pub key need pubkey msg set uid uid return msg createfnpgetofferedkey needpubkey fnpgetofferedkey offer_authenticator shortbuffer need_pub_key needpubkey public static message createfnp get offered key invalid long uid short reason message msg new message fnp get offered key invalid msg set uid uid msg set reason reason return msg createfnpgetofferedkeyinvalid fnpgetofferedkeyinvalid public static final message createfnp ping int seq no message msg new message fnp ping msg set ping seqno seq no return msg createfnpping seqno fnpping ping_seqno seqno public static final message createfnp pong int seq no message msg new message fnp pong msg set ping seqno seq no return msg createfnppong seqno fnppong ping_seqno seqno public static final message createfnprh probe reply long uid double nearest double best short counter short unique counter short linear counter message msg new message fnprh probe reply msg set uid uid msg set nearest location nearest msg set best location best msg set counter counter msg set unique counter unique counter msg set linear counter linear counter return msg createfnprhprobereply uniquecounter linearcounter fnprhprobereply nearest_location best_location unique_counter uniquecounter linear_counter linearcounter public static final message createfnprh probe request long uid double target double nearest double best short htl message msg new message fnprh probe request msg set uid uid msg set target location target msg set nearest location nearest msg set best location best msg set htl htl return msg createfnprhproberequest fnprhproberequest target_location nearest_location best_location public static final message createfnprh return sub message double nearest double best short counter short unique counter short linear counter string reason message msg new message fnprh return sub message msg set nearest location nearest msg set best location best msg set counter counter msg set unique counter unique counter msg set linear counter linear counter msg set reason reason return msg createfnprhreturnsubmessage uniquecounter linearcounter fnprhreturnsubmessage nearest_location best_location unique_counter uniquecounter linear_counter linearcounter public static message createfnprh probe trace long uid double nearest double best short htl short counter short unique counter double my loc long swap identifier double peer locs long peerui ds short fork count short linear counter string reason long prevuid return createfnprh probe trace uid nearest best htl counter unique counter my loc swap identifier new short buffer fields doubles to bytes peer locs new short buffer fields longs to bytes peerui ds fork count linear counter reason prevuid createfnprhprobetrace uniquecounter myloc swapidentifier peerlocs peeruids forkcount linearcounter createfnprhprobetrace uniquecounter myloc swapidentifier shortbuffer doublestobytes peerlocs shortbuffer longstobytes peeruids forkcount linearcounter public static message createfnprh probe trace long uid double nearest double best short htl short counter short unique counter double my loc long swap identifier short buffer peer locs short buffer peerui ds short fork count short linear counter string reason long prevuid message msg new message fnprh probe trace msg set uid uid msg set nearest location nearest msg set best location best msg set htl htl msg set counter counter msg set unique counter unique counter msg set location my loc msg set my uid swap identifier msg set peer locations peer locs msg set peer uids peerui ds msg set fork count fork count msg set linear counter linear counter msg set reason reason msg set prev uid prevuid return msg createfnprhprobetrace uniquecounter myloc swapidentifier shortbuffer peerlocs shortbuffer peeruids forkcount linearcounter fnprhprobetrace nearest_location best_location unique_counter uniquecounter myloc my_uid swapidentifier peer_locations peerlocs peer_uids peeruids fork_count forkcount linear_counter linearcounter prev_uid public static final message createfnp swap request long uid byte buf int htl message msg new message fnp swap request msg set uid uid msg set hash new short buffer buf msg set htl htl return msg createfnpswaprequest fnpswaprequest shortbuffer public static final message createfnp swap rejected long uid message msg new message fnp swap rejected msg set uid uid return msg createfnpswaprejected fnpswaprejected public static final message createfnp swap reply long uid byte buf message msg new message fnp swap reply msg set uid uid msg set hash new short buffer buf return msg createfnpswapreply fnpswapreply shortbuffer public static final message createfnp swap commit long uid byte buf message msg new message fnp swap commit msg set uid uid msg set data new short buffer buf return msg createfnpswapcommit fnpswapcommit shortbuffer public static final message createfnp swap complete long uid byte buf message msg new message fnp swap complete msg set uid uid msg set data new short buffer buf return msg createfnpswapcomplete fnpswapcomplete shortbuffer public static final message createfnp loc change notification new double my location double locations message msg new message fnp loc change notification new short buffer dst new short buffer fields doubles to bytes locations msg set location my location msg set peer locations dst return msg createfnplocchangenotificationnew mylocation fnplocchangenotificationnew shortbuffer shortbuffer doublestobytes mylocation peer_locations public static final message createfnp routed ping long uid double target location short htl int counter byte node identity message msg new message fnp routed ping msg set routed to node fields uid target location htl node identity msg set counter counter return msg createfnproutedping targetlocation nodeidentity fnproutedping setroutedtonodefields targetlocation nodeidentity public static final message createfnp routed pong long uid int counter message msg new message fnp routed pong msg set uid uid msg set counter counter return msg createfnproutedpong fnproutedpong public static final message createfnp secret ping long uid double target location short htl short dawn htl int counter byte node identity message msg new message fnp secret ping msg set routed to node fields uid target location htl node identity msg set counter counter msg set dawn htl dawn htl return msg createfnpsecretping targetlocation dawnhtl nodeidentity fnpsecretping setroutedtonodefields targetlocation nodeidentity dawn_htl dawnhtl public static final message createfnp secret pong long uid int counter long secret message msg new message fnp secret pong msg set uid uid msg set counter counter msg set secret secret return msg createfnpsecretpong fnpsecretpong public static final message createfnp store secret long uid long secret message msg new message fnp store secret msg set uid uid msg set secret secret return msg createfnpstoresecret fnpstoresecret public static final message createfnp networkid int id message msg new message fnp networkid msg set uid id return msg createfnpnetworkid fnpnetworkid public static final message createfnp routed rejected long uid short htl message msg new message fnp routed rejected msg set uid uid msg set htl htl return msg createfnproutedrejected fnproutedrejected public static final message createfnp detectedip address peer peer message msg new message fnp detectedip address msg set external address peer return msg createfnpdetectedipaddress fnpdetectedipaddress external_address public static final message createfnp time long time message msg new message fnp time msg set time time return msg createfnptime fnptime public static final message createfnp uptime byte uptime percent message msg new message fnp uptime msg set uptime percent 48h uptime percent return msg createfnpuptime uptimepercent fnpuptime uptime_percent_48h uptimepercent public static final message createfnp sent packets int time deltas long hashes long base time message msg new message fnp sent packets msg set time deltas new short buffer fields ints to bytes time deltas msg set hashes new short buffer fields longs to bytes hashes msg set time base time return msg createfnpsentpackets timedeltas basetime fnpsentpackets time_deltas shortbuffer intstobytes timedeltas shortbuffer longstobytes basetime public static final message createfnp void message msg new message fnp void return msg createfnpvoid fnpvoid public static final message createfnp disconnect boolean remove boolean purge int message type short buffer message data message msg new message fnp disconnect msg set remove remove msg set purge purge msg set node to node message type message type msg set node to node message data message data return msg createfnpdisconnect messagetype shortbuffer messagedata fnpdisconnect node_to_node_message_type messagetype node_to_node_message_data messagedata public static final message createuom announce string main key string extra key string revocation key boolean have revocation long main jar version long extra jar version long time last tried revocation fetch int revocationdnf count long revocation key length long main jar length long extra jar length int ping time int bwlimit delay time message msg new message uom announce msg set main jar key main key msg set extra jar key extra key msg set revocation key revocation key msg set have revocation key have revocation msg set main jar version main jar version msg set extra jar version extra jar version msg set revocation key time last tried time last tried revocation fetch msg set revocation key dnf count revocationdnf count msg set revocation key file length revocation key length msg set main jar file length main jar length msg set extra jar file length extra jar length msg set ping time ping time msg set bwlimit delay time bwlimit delay time return msg createuomannounce mainkey extrakey revocationkey haverevocation mainjarversion extrajarversion timelasttriedrevocationfetch revocationdnfcount revocationkeylength mainjarlength extrajarlength pingtime bwlimitdelaytime uomannounce main_jar_key mainkey extra_jar_key extrakey revocation_key revocationkey have_revocation_key haverevocation main_jar_version mainjarversion extra_jar_version extrajarversion revocation_key_time_last_tried timelasttriedrevocationfetch revocation_key_dnf_count revocationdnfcount revocation_key_file_length revocationkeylength main_jar_file_length mainjarlength extra_jar_file_length extrajarlength ping_time pingtime bwlimit_delay_time bwlimitdelaytime public static final message createuom request revocation long uid message msg new message uom request revocation msg set uid uid return msg createuomrequestrevocation uomrequestrevocation public static final message createuom request main long uid message msg new message uom request main msg set uid uid return msg createuomrequestmain uomrequestmain public static final message createuom request extra long uid message msg new message uom request extra msg set uid uid return msg createuomrequestextra uomrequestextra public static final message createuom sending revocation long uid long length string key message msg new message uom sending revocation msg set uid uid msg set file length length msg set revocation key key return msg createuomsendingrevocation uomsendingrevocation file_length revocation_key public static final message createuom sending main long uid long length string key int version message msg new message uom sending main msg set uid uid msg set file length length msg set main jar key key msg set main jar version version return msg createuomsendingmain uomsendingmain file_length main_jar_key main_jar_version public static final message createuom sending extra long uid long length string key int version message msg new message uom sending extra msg set uid uid msg set file length length msg set extra jar key key msg set extra jar version version return msg createuomsendingextra uomsendingextra file_length extra_jar_key extra_jar_version public static final message createfnp swap locations long uids message msg new message fnp swap nodeui ds msg set node uids new short buffer fields longs to bytes uids return msg createfnpswaplocations fnpswapnodeuids node_uids shortbuffer longstobytes public static final message createfnp best routes not taken byte locs message msg new message fnp best routes not taken msg set best locations not visited new short buffer locs return msg createfnpbestroutesnottaken fnpbestroutesnottaken best_locations_not_visited shortbuffer public static final message createfnp best routes not taken double locs return createfnp best routes not taken fields doubles to bytes locs createfnpbestroutesnottaken createfnpbestroutesnottaken doublestobytes public static message createfnp best routes not taken double doubles double locs new double doubles length for int i 0 i locs length i locs i doubles i double value return createfnp best routes not taken locs createfnpbestroutesnottaken doublevalue createfnpbestroutesnottaken public static final message create routing status boolean route requests message msg new message fnp routing status msg set routing enabled route requests return msg createroutingstatus routerequests fnproutingstatus routing_enabled routerequests public static void init public single key listener key key base single file fetcher fetcher boolean dont cache short prio boolean persistent this key key this fetcher fetcher this dont cache dont cache this prio prio this persistent persistent singlekeylistener basesinglefilefetcher dontcache dontcache dontcache public long count keys if done return 0 else return 1 countkeys public short definitely want key key key byte salted key object container container client context context if key equals this key return 1 else return prio definitelywantkey saltedkey objectcontainer clientcontext public boolean dont cache return dont cache dontcache dontcache public has key listener get has key listener return fetcher haskeylistener gethaskeylistener public short get priority class object container container return prio getpriorityclass objectcontainer public sendable get get requests for key key key byte salted key object container container client context context if key equals this key return null return new sendable get fetcher sendableget getrequestsforkey saltedkey objectcontainer clientcontext sendableget public boolean handle block key key byte salted key key block found object container container client context context if key equals this key return false if persistent container activate fetcher 1 fetcher on got key key found container context if persistent container deactivate fetcher 1 synchronized this done true return true handleblock saltedkey keyblock objectcontainer clientcontext ongotkey public key list keys object container container return new key key listkeys objectcontainer public boolean persistent return persistent public boolean probably want key key key byte salted key if done return false return key equals this key probablywantkey saltedkey public synchronized void on remove done true onremove public boolean is empty return done isempty public boolean isssk return key instanceof nodessk private client context context public background block encoder queue new array list soft reference encodeable clientcontext backgroundblockencoder arraylist softreference public void set context client context context this context context setcontext clientcontext public void queue encodeable sbi object container container client context context if sbi persistent queue persistent sbi container context run persistent queue context else soft reference encodeable ref new soft reference encodeable sbi synchronized this queue add ref logger minor this queueing encode of sbi notify all objectcontainer clientcontext queuepersistent runpersistentqueue softreference softreference notifyall public void queue single block inserter sbis object container container client context context synchronized this for int i 0 i sbis length i single block inserter inserter sbis i if inserter null continue if inserter is cancelled container continue if inserter resultinguri null continue if inserter persistent continue logger minor this queueing encode of inserter soft reference encodeable ref new soft reference encodeable inserter queue add ref notify all boolean any persistent false for int i 0 i sbis length i single block inserter inserter sbis i if inserter null continue if inserter is cancelled container continue if inserter resultinguri null continue if inserter persistent continue any persistent true queue persistent inserter container context if any persistent run persistent queue context singleblockinserter objectcontainer clientcontext singleblockinserter iscancelled softreference softreference notifyall anypersistent singleblockinserter iscancelled anypersistent queuepersistent anypersistent runpersistentqueue public void run persistent queue client context context context job runner queue runner native thread low priority true runpersistentqueue clientcontext jobrunner nativethread low_priority private void queue persistent encodeable sbi object container container client context context background block encoder tag tag new background block encoder tag sbi sbi get priority class container context container store tag queuepersistent objectcontainer clientcontext backgroundblockencodertag backgroundblockencodertag getpriorityclass public void run freenet support logger os thread logpid this while true encodeable sbi null synchronized this while queue is empty try wait 100 1000 catch interrupted exception e ignore while queue is empty soft reference encodeable ref queue remove queue size 1 sbi ref get if sbi null break logger minor this encoding sbi sbi try encode null context osthread isempty interruptedexception isempty softreference tryencode public int get priority return native thread min priority getpriority nativethread min_priority public void run object container container client context context query query container query query constrain background block encoder tag class query descend nodedb handle constrain long value of context nodedb handle query descend priority order ascending query descend added time order ascending object set results query execute for int x 0 x jobs per slot results has next x background block encoder tag tag background block encoder tag results next try encodeable sbi tag inserter if sbi null continue container activate sbi 1 sbi try encode container context container deactivate sbi 1 catch throwable t logger error this caught t t finally container delete tag if results has next run persistent queue context objectcontainer clientcontext backgroundblockencodertag nodedbhandle valueof nodedbhandle orderascending addedtime orderascending objectset jobs_per_slot hasnext backgroundblockencodertag backgroundblockencodertag tryencode hasnext runpersistentqueue background block encoder tag encodeable inserter short prio client context context this inserter inserter this nodedb handle context nodedb handle this added time system current time millis this priority prio backgroundblockencodertag clientcontext nodedbhandle nodedbhandle addedtime currenttimemillis public message item message msg2 async message callback cb2 byte counter ctr peer node pn this msg msg2 this cb cb2 formatted false this ctr callback ctr this submitted system current time millis priority msg2 get spec get priority buf msg encode to packet pn messageitem asyncmessagecallback bytecounter peernode ctrcallback currenttimemillis getspec getpriority encodetopacket public message item byte data async message callback cb2 boolean formatted byte counter ctr short priority this cb cb2 this msg null this buf data this formatted formatted if formatted buf null throw new null pointer exception this ctr callback ctr this submitted system current time millis this priority priority messageitem asyncmessagecallback bytecounter nullpointerexception ctrcallback currenttimemillis return the data contents of this message item public byte get data return buf messageitem getdata public int get length return buf length getlength param length the actual number of bytes sent to send this message including our share of the packet overheads and including already reported bytes which is only used when deciding how many bytes to report to the throttle public void on sent int length nb the fact that the bytes are counted before callback notifications is important for load management if ctr callback null try ctr callback sent bytes length catch throwable t logger error this caught t reporting length sent bytes on this t if cb null for int i 0 i cb length i try cb i sent catch throwable t logger error this caught t calling sent on cb i for this t alreadyreportedbytes onsent ctrcallback ctrcallback sentbytes public short get priority return priority getpriority override public string to string return super to string formatted formatted msg msg tostring tostring public void on disconnect if cb null for int i 0 i cb length i try cb i disconnected catch throwable t logger error this caught t calling sent on cb i for this t ondisconnect private iterator t iterator public iterator wrapper iterator t iterator this iterator iterator iteratorwrapper public boolean has next return iterator has next hasnext hasnext public t next return iterator next public void remove iterator remove public class plugin down loader file extends plugin down loader file override public file check source string source return new file source plugindownloaderfile plugindownloader checksource override input stream get input stream throws io exception return new file input stream get source inputstream getinputstream ioexception fileinputstream getsource override string get plugin name string source throws plugin not found exception int slash index source last index of if slash index 1 slash index source last index of return source substring slash index 1 getpluginname pluginnotfoundexception slashindex lastindexof slashindex slashindex lastindexof slashindex override string getsha1sum throws plugin not found exception return null pluginnotfoundexception override string getsha256sum throws plugin not found exception return null pluginnotfoundexception public class async replication master file extends replication master file constructor of replication master file param storage replication storage param file local file used to store data locally param async buf size size of asynchronous buffer public async replication master file replication master storage impl storage i file file int async buf size super storage file this async buf size async buf size start asyncreplicationmasterfile replicationmasterfile asyncbufsize asyncreplicationmasterfile replicationmasterstorageimpl ifile asyncbufsize asyncbufsize asyncbufsize constructor of replication master file param file local file used to store data locally param hosts slave node hosts to which replicastion will be performed param async buf size size of asynchronous buffer param ack whether master should wait acknowledgment from slave node during trasanction commit public async replication master file i file file string hosts int async buf size boolean ack super file hosts ack this async buf size async buf size start asyncbufsize asyncreplicationmasterfile ifile asyncbufsize asyncbufsize asyncbufsize class write thread extends thread public void run async write writethread asyncwrite private void start go new object async new object thread new write thread thread start writethread public void write long pos byte buf file write pos buf for int i 0 i out length i if out i null byte data new byte 8 buf length bytes pack8 data 0 pos system arraycopy buf 0 data 8 buf length parcel p new parcel p data data p pos pos p host i try synchronized async buffered data length while buffered async buf size async wait catch interrupted exception x synchronized go if head null head tail p else tail tail next p go notify asyncbufsize interruptedexception public void async write try while true parcel p synchronized go while head null if closed return go wait p head head p next synchronized async if buffered async buf size async notify all buffered p data length int i p host while out i null try out i write p data if ack p pos 0 in i read rc buf 1 break catch io exception x out i null sockets i null n hosts 1 if handle error hosts i connect i else break catch interrupted exception x asyncwrite asyncbufsize notifyall rcbuf ioexception nhosts handleerror interruptedexception public void close try synchronized go closed true go notify thread join catch interrupted exception x super close interruptedexception private static final long serial versionuid 6026765325018137641l public parameter list serialversionuid parameterlist public parameter at int n return parameter get n public parameter get parameter int n return parameter get n getparameter public parameter get parameter string name if name null return null int n lists size for int n 0 n n lists n parameter param at n if name compare to param get name 0 return param return null getparameter nlists nlists compareto getname public string get value string name parameter param get parameter name if param null return return param get value getvalue getparameter getvalue public ssdp search request string serach target int mx set method http m search seturi set header http st serach target set header http mx integer to string mx set header http man man discover ssdpsearchrequest serachtarget setmethod m_search setheader serachtarget setheader tostring setheader public ssdp search request string serach target this serach target ssdp default msearch mx ssdpsearchrequest serachtarget serachtarget default_msearch_mx public ssdp search request this st root device ssdpsearchrequest root_device public void set local address string bind addr string ssdp addr ssdp address if host interface isi pv6 address bind addr true ssdp addr ssdp geti pv6 address set host ssdp addr ssdp port setlocaladdress bindaddr ssdpaddr hostinterface isipv6address bindaddr ssdpaddr getipv6address sethost ssdpaddr private running average avg free memory public memory checker packet sender ps int modificator this ps ps this aggressivegc modificator modificator runningaverage avgfreememory memorychecker packetsender aggressivegcmodificator protected synchronized void terminate goon false logger normal this terminating memory checker public boolean is running return goon isrunning public synchronized void start goon true logger normal this starting memory checker run public void run freenet support logger os thread logpid this if goon logger normal this goon is false killing memory checker return runtime r runtime get runtime long total memory r total memory long free memory r free memory long max memory r max memory logger normal this memory in use size util format size total memory free memory if total memory max memory max memory long max value jvm have allocated maximum memory total memory never decrease so check it only for once if avg free memory null avg free memory new simple running average 3 free memory else avg free memory report free memory if avg free memory count reports 3 avg free memory current value 4 1024 1024 average free memory 4 mb logger normal this reached threshold checking for low memory system gc system run finalization try thread sleep 10 force a context switch finalization need a cs to complete catch interrupted exception e free memory r free memory avg free memory report free memory if free memory 4 1024 1024 current free memory 4 mb logger error this memory too low trying to free some oom handler low memory int sleeptime aggressivegc modificator if sleeptime 0 we are done ps queue timed job this 120 250 30 sec return else ps queue timed job this 120l sleeptime fixme do not remove until all known memory issues fixed especially 66 this probably reduces performance but it makes memory usage more predictable this will make tracking down the sort of nasty unpredictable oo ms we are getting much easier if aggressivegc modificator 0 boolean logminor logger should log logger minor this long beforegc used memory r total memory r free memory if logminor logger minor this memory in use before gc beforegc used memory long beforegc time system current time millis system gc system run finalization long aftergc time system current time millis long aftergc used memory r total memory r free memory if logminor logger minor this memory in use after gc aftergc used memory logger minor this gc completed after aftergc time beforegc time ms and recovered beforegc used memory aftergc used memory bytes leaving aftergc used memory bytes used osthread memorychecker getruntime totalmemory totalmemory freememory freememory maxmemory maxmemory sizeutil formatsize totalmemory freememory totalmemory maxmemory maxmemory max_value totalmemory avgfreememory avgfreememory simplerunningaverage freememory avgfreememory freememory avgfreememory countreports avgfreememory currentvalue runfinalization interruptedexception freememory freememory avgfreememory freememory freememory oomhandler lowmemory aggressivegcmodificator queuetimedjob queuetimedjob ooms aggressivegcmodificator shouldlog beforegcusedmemory totalmemory freememory beforegcusedmemory beforegctime currenttimemillis runfinalization aftergctime currenttimemillis aftergcusedmemory totalmemory freememory aftergcusedmemory aftergctime beforegctime beforegcusedmemory aftergcusedmemory aftergcusedmemory public static void main string args system err println ds agroup biga to string t ds agroup biga fingerprint to string system err println d hgroupa to string t d hgroupa fingerprint to string dsagroupbiga tostring dsagroupbiga fingerprinttostring dhgroupa tostring dhgroupa fingerprinttostring public static dsa group get group int group index if group index group index big a return ds agroup biga return null dsagroup getgroup groupindex groupindex group_index_big_a dsagroupbiga protected i persistent map string term position term pos map public page ipersistentmap termposition termposmap page string uri string comment storage storage this uri uri this comment comment this status status queued this last change system current time millis storage make persistent this lastchange currenttimemillis makepersistent public synchronized void set status status status pre modify this status status post modify setstatus premodify postmodify public status get status return status getstatus public synchronized void set comment string comment pre modify this comment comment post modify setcomment premodify postmodify public string get comment return comment getcomment public string geturi return uri public long get id return id getid public void set page title string page title pre modify this page title page title post modify setpagetitle pagetitle premodify pagetitle pagetitle postmodify public string get page title return page title getpagetitle pagetitle public synchronized term position get term position term term boolean create if term pos map null term pos map get storage create map string class modify term position tp term pos map get term md5 if tp null create tp new term position get storage term pos map put term md5 tp term page set add this return tp termposition gettermposition termposmap termposmap getstorage createmap termposition termposmap termposition getstorage termposmap pageset public synchronized void clear term position term pos map null modify cleartermposition termposmap override public int hash code return int id id 32 hashcode override public boolean equals object obj if this obj return true if obj null return false if get class obj get class return false return id page obj id getclass getclass override public string to string return page id id title page title uri uri status status comment comment tostring pagetitle public int compare to page o return new long id compare to o id compareto compareto private void pre modify storage storage get storage if storage null perst root root perst root storage get root field index page coll root get page index status coll exclusive lock try coll remove this finally coll unlock premodify getstorage perstroot perstroot getroot fieldindex getpageindex exclusivelock private void post modify last change system current time millis modify storage storage get storage if storage null perst root root perst root storage get root field index page coll root get page index status coll exclusive lock try coll put this finally coll unlock postmodify lastchange currenttimemillis getstorage perstroot perstroot getroot fieldindex getpageindex exclusivelock private float m11 1 0f public check filter checkfilter set the foreground color param foreground the color see get foreground public void set foreground int foreground this foreground foreground getforeground setforeground get the foreground color return the color see set foreground public int get foreground return foreground setforeground getforeground set the background color param background the color see get background public void set background int background this background background getbackground setbackground get the background color return the color see set background public int get background return background setbackground getbackground set the x scale of the texture param x scale the scale see getx scale public void setx scale int x scale this x scale x scale xscale getxscale setxscale xscale xscale xscale get the x scale of the texture return the scale see setx scale public int getx scale return x scale setxscale getxscale xscale set the y scale of the texture param y scale the scale see gety scale public void sety scale int y scale this y scale y scale yscale getyscale setyscale yscale yscale yscale get the y scale of the texture return the scale see sety scale public int gety scale return y scale setyscale getyscale yscale set the fuzziness of the texture param fuzziness the fuzziness see get fuzziness public void set fuzziness int fuzziness this fuzziness fuzziness getfuzziness setfuzziness get the fuzziness of the texture return the fuzziness see set fuzziness public int get fuzziness return fuzziness setfuzziness getfuzziness set the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos getangle setangle get the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle override public int filterrgb int x int y int rgb float nx m00 x m01 y x scale float ny m10 x m11 y y scale float f int nx 100000 2 int ny 100000 2 1 0f 0 0f if fuzziness 0 float fuzz fuzziness 100 0f float fx image math smooth pulse 0 fuzz 1 fuzz 1 image math mod nx 1 float fy image math smooth pulse 0 fuzz 1 fuzz 1 image math mod ny 1 f fx fy return image math mix colors f foreground background xscale yscale imagemath smoothpulse imagemath imagemath smoothpulse imagemath imagemath mixcolors override public string to string return texture checkerboard tostring class compression output public compression output bucket best compressed data compressor type best codec2 this data best compressed data this best codec best codec2 compressionoutput compressionoutput bestcompresseddata compressor_type bestcodec2 bestcompresseddata bestcodec bestcodec2 public static string encode string s string builder output new string builder s length 2 for int i 0 i s length i char c s char at i if allowed chars index of c 0 output append c else string tmp c try byte utf tmp get bytes utf 8 for int j 0 j utf length j int x utf j 0xff output append if x 16 output append 0 output append integer to hex string x catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e return output to string stringbuilder stringbuilder charat allowedchars indexof getbytes tohexstring unsupportedencodingexception tostring create a new uri from a string which may contain characters which should have been encoded throws uri syntax exception if the string does not represent a valid uri even after encoding public static uri encodeuri string s throws uri syntax exception return new uri encode s urisyntaxexception urisyntaxexception private static final long serial versionuid 1 public persistence parse exception string string super string serialversionuid persistenceparseexception public persistence parse exception string string exception reason super string reason persistenceparseexception public class jsql no such field exception extends jsql runtime exception constructor of exception param target class of the target object in which field was not found param field name name of the locate field public jsql no such field exception class target string field name super dynamic lookup failed for field target field name jsqlnosuchfieldexception jsqlruntimeexception fieldname jsqlnosuchfieldexception fieldname fieldname public client hello message simple field set fs throws message invalid exception client name fs get name client expected version fs get expected version if client name null throw new message invalid exception protocol error message missing field client hello must contain a name field null false if client expected version null throw new message invalid exception protocol error message missing field client hello must contain a expected version field null false fixme check the expected version clienthellomessage simplefieldset messageinvalidexception clientname clientexpectedversion expectedversion clientname messageinvalidexception protocolerrormessage missing_field clienthello clientexpectedversion messageinvalidexception protocolerrormessage missing_field clienthello expectedversion override public simple field set get field set simple field set sfs new simple field set true sfs put single name client name sfs put single expected version client expected version return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle clientname putsingle expectedversion clientexpectedversion override public string get name return name getname override public void run fcp connection handler handler node node we know the hello is valid fcp message msg new node hello message node handler connection identifier handler output handler queue msg handler set client name client name fcpconnectionhandler fcpmessage nodehellomessage connectionidentifier outputhandler setclientname clientname override public void remove from object container container container delete this removefrom objectcontainer override protected void set up throws exception super set up identity new identity uri test true identity add context bleh m wot store and commit identity setup setup addcontext mwot storeandcommit public void test identity stored object set identity result m wot get all identities assert equals 1 result size assert equals identity result next testidentitystored objectset mwot getallidentities assertequals assertequals public void test get byuri throws malformedurl exception unknown identity exception assert equals identity m wot get identity byuri uri testgetbyuri malformedurlexception unknownidentityexception assertequals mwot getidentitybyuri public void test contexts throws invalid parameter exception assert false identity has context foo identity add context test assert true identity has context test identity remove context test assert false identity has context test todo obtain the identity from the db between each line testcontexts invalidparameterexception assertfalse hascontext addcontext asserttrue hascontext removecontext assertfalse hascontext public void test properties throws invalid parameter exception identity set property foo bar assert equals bar identity get property foo identity remove property foo try identity get property foo fail catch invalid parameter exception e testproperties invalidparameterexception setproperty assertequals getproperty removeproperty getproperty invalidparameterexception public void test persistence throws malformedurl exception unknown identity exception m wot terminate m wot null system gc system run finalization m wot new wot get database filename assert equals 1 m wot get all identities size identity stored m wot get identity byuri uri assert equals identity getid stored getid assert equals identity get requesturi stored get requesturi assert equals identity get edition stored get edition assert equals identity get nickname stored get nickname assert equals identity get added date stored get added date assert equals identity get last change date stored get last change date fixme check contexts properties testpersistence malformedurlexception unknownidentityexception mwot mwot runfinalization mwot getdatabasefilename assertequals mwot getallidentities mwot getidentitybyuri assertequals assertequals getrequesturi getrequesturi assertequals getedition getedition assertequals getnickname getnickname assertequals getaddeddate getaddeddate assertequals getlastchangedate getlastchangedate logger register log threshold callback new log threshold callback override public void should update logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public static final string get message int reason switch reason case decode failed return decode of data failed probably was bogus at source case data not found in store return data was not in store and request was local only case internal error return internal error probably a bug case data not found return could not find the data case route not found return could not find enough nodes to be sure that the data is not out there somewhere case rejected overload return a node downstream either timed out or was overloaded retry case transfer failed return started to transfer data then failed should be rare case verify failed return node sent us invalid data case cancelled return request cancelled case recently failed return request killed by failure table due to recently dn fing on a downstream node default return unknown error code reason getmessage decode_failed data_not_found_in_store internal_error data_not_found route_not_found rejected_overload transfer_failed verify_failed recently_failed dnfing public final int code public low level get exception int code string message throwable t super message t this code code lowlevelgetexception public low level get exception int reason super get message reason this code reason lowlevelgetexception getmessage override public string to string return super to string get message code tostring tostring getmessage override public final synchronized throwable fill in stack trace if logdebug code internal error code decode failed code verify failed return super fill in stack trace return null fillinstacktrace internal_error decode_failed verify_failed fillinstacktrace get a list of fields which the database should create an index on protected static string get indexed fields return new string m truster m trustee getindexedfields mtruster mtrustee creates a trust from given parameters only for being used by the wot package and unit tests not for user interfaces param truster identity that gives the trust param trustee identity that receives the trust param value numeric value of the trust param comment a comment to explain the numeric trust value throws invalid parameter exception if the trust value is not between 100 and 100 public trust identity truster identity trustee byte value string comment throws invalid parameter exception if truster null throw new null pointer exception if trustee null throw new null pointer exception m truster truster m trustee trustee set value value set comment comment m truster trust list edition truster get edition invalidparameterexception invalidparameterexception nullpointerexception nullpointerexception mtruster mtrustee setvalue setcomment mtrustertrustlistedition getedition override public synchronized string to string return get truster get nickname trusts get trustee get nickname get value get comment tostring gettruster getnickname gettrustee getnickname getvalue getcomment return the identity that gives this trust public identity get truster return m truster gettruster mtruster return trustee the identity that receives this trust public identity get trustee return m trustee gettrustee mtrustee return value numeric value of this trust relationship public synchronized byte get value return m value getvalue mvalue param m value numeric value of this trust relationship 100 100 throws invalid parameter exception if value isn t in the range protected synchronized void set value byte new value throws invalid parameter exception if new value 100 new value 100 throw new invalid parameter exception invalid trust value m value m value new value mvalue invalidparameterexception setvalue newvalue invalidparameterexception newvalue newvalue invalidparameterexception mvalue mvalue newvalue return the comment associated to this trust relationship public synchronized string get comment return m comment getcomment mcomment param new comment comment on this trust relationship protected synchronized void set comment string new comment throws invalid parameter exception assert new comment null if new comment null new comment length 256 throw new invalid parameter exception comment is too long maximum is 256 characters m comment new comment null new comment newcomment setcomment newcomment invalidparameterexception newcomment newcomment newcomment invalidparameterexception mcomment newcomment newcomment protected synchronized void truster edition updated m truster trust list edition m truster get edition trustereditionupdated mtrustertrustlistedition mtruster getedition private boolean ismetadata public very simple get client key key2 int max retries2 fetch context ctx2 client requester parent2 super key2 max retries2 ctx2 parent2 true verysimpleget clientkey maxretries2 fetchcontext clientrequester maxretries2 override public void on failure low level get exception e object token object container container client context context boolean logminor logger should log logger minor this if logminor logger minor this on failure e e if is fatal error e code if retry container context if logminor logger minor this retrying new error debug return error e finished true synchronized waiter waiter notify all onfailure lowlevelgetexception objectcontainer clientcontext shouldlog onfailure isfatalerror notifyall override public void on success client key block block boolean from store object token object container container client context context data extract block context ismetadata block is metadata if data null return failed finished true synchronized waiter waiter notify all onsuccess clientkeyblock fromstore objectcontainer clientcontext ismetadata notifyall public bucket wait for completion throws low level get exception while finished try synchronized waiter waiter wait catch interrupted exception e ignore if error null throw error return data waitforcompletion lowlevelgetexception interruptedexception private bucket extract client key block block client context context bucket tempdata try todo this make max size a parameter 4mb hardcoded for now todo key explorer ask warn the user before displaying browser bombs fixme what is the maximum size of an decompressed 32k chunk hah 2gb is the max insertsize for a compressed single chunk its a memory browser bomb the hexdump can be 4x in size 8gb a few k for surrounding html tempdata block decode context temp bucket factory 4 1024 1024 false catch key decode exception e1 if logger should log logger minor this logger minor this decode failure e1 e1 on failure new low level get exception low level get exception decode failed null null context return null catch too big exception e logger error this should never happens e e on failure new low level get exception low level get exception internal error null null context return null catch io exception e logger error this could not capture data disk full e e on failure new low level get exception low level get exception decode failed null null context return null return tempdata clientkeyblock clientcontext keyexplorer tempbucketfactory keydecodeexception shouldlog onfailure lowlevelgetexception lowlevelgetexception decode_failed toobigexception onfailure lowlevelgetexception lowlevelgetexception internal_error ioexception onfailure lowlevelgetexception lowlevelgetexception decode_failed public boolean is metadata return ismetadata ismetadata public static boolean is fatal error int mode switch mode low level errors can be retried case low level get exception data not found case low level get exception route not found case low level get exception rejected overload case low level get exception transfer failed case low level get exception recently failed wait a bit but fine return false case low level get exception internal error maybe fatal return false wierd ones case low level get exception cancelled return true default logger error very simple get class do not know if error code mode is fatal low level get exception get message mode return false assume it isn t isfatalerror lowlevelgetexception data_not_found lowlevelgetexception route_not_found lowlevelgetexception rejected_overload lowlevelgetexception transfer_failed lowlevelgetexception recently_failed lowlevelgetexception internal_error lowlevelgetexception verysimpleget lowlevelgetexception getmessage public void on failed key listener construction exception e object container container client context context logger error this todo e e onfailed keylistenerconstructionexception objectcontainer clientcontext public final class screen composite extends rgb composite public screen composite float alpha super alpha screencomposite rgbcomposite screencomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob int t 255 dir 255 sr 0x80 dor 255 t 8 t 8 t 255 dig 255 sg 0x80 dog 255 t 8 t 8 t 255 dib 255 sb 0x80 dob 255 t 8 t 8 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public class log threshold callback public log threshold callback logthresholdcallback logthresholdcallback public void should update shouldupdate public void schedule object container container client context context throws insert exception caller calls schedule schedule calls schedule fetcher schedule fetcher creates a fetcher set up to tell us about author errors as well as valid inserts and starts it when this completes on found edition calls schedule insert schedule insert starts a single block inserter if that succeeds we complete if that fails we increment our index and try again in the callback if that continues to fail 5 times we go back to schedule fetcher schedule fetcher container context objectcontainer clientcontext insertexception schedulefetcher schedulefetcher onfoundedition scheduleinsert scheduleinsert singleblockinserter schedulefetcher schedulefetcher schedule a fetcher to find us the latest inserted key of the usk the fetcher must be insert mode in other words it must know that we want the latest edition including author errors and so on private void schedule fetcher object container container client context context if persistent container activate pubusk 5 synchronized this if logger should log logger minor this logger minor this scheduling fetcher for pubusk geturi if finished return fetcher context usk manager get fetcher for insert dont schedule persistent pubusk clone pubusk parent priority class this parent get client container context persistent if logger should log logger minor this logger minor this scheduled fetcher if persistent container store fetcher container store this fetcher schedule container context schedulefetcher objectcontainer clientcontext shouldlog uskmanager getfetcherforinsertdontschedule priorityclass getclient shouldlog public void on found edition long l usk key object container container client context context boolean last content was metadata short codec byte his data boolean new known good boolean new slot too boolean already inserted false synchronized this edition math max l edition consecutive collisions 0 if last content was metadata is metadata his data null codec compression codec try if persistent container activate data 1 byte my data bucket tools to byte array data if arrays equals my data his data success already inserted true finished true sbi null catch io exception e logger error this could not decode e e if persistent container activate fetcher 1 container activate fetcher ctx 1 fetcher remove from container context fetcher ctx remove from container fetcher null container store this if already inserted if persistent container activate parent 1 success parent add must succeed blocks 1 container parent completed block true container context if persistent container activate cb 1 container activate pubusk 5 cb on encode pubusk copy edition this container context cb on success this container context if free data data free if persistent data remove from container else schedule insert container context onfoundedition objectcontainer clientcontext lastcontentwasmetadata hisdata newknowngood newslottoo alreadyinserted consecutivecollisions lastcontentwasmetadata ismetadata hisdata compressioncodec mydata buckettools tobytearray mydata hisdata alreadyinserted ioexception removefrom removefrom alreadyinserted addmustsucceedblocks completedblock onencode onsuccess freedata removefrom scheduleinsert private void schedule insert object container container client context context long ed no math max edition context usk manager lookup latest slot pubusk 1 if persistent container activate privusk 5 container activate pubusk 5 synchronized this if finished return edition ed no if logger should log logger minor this logger minor this scheduling insert for pubusk geturi edition sbi new single block inserter parent data compression codec privusk get insertablessk edition get inserturi ctx this is metadata source length token getchk only false true we don t use it token object container context persistent false try sbi schedule container context if persistent container store this catch insert exception e synchronized this finished true if free data if persistent container activate data 1 data free data remove from container synchronized this data null if persistent container store this cb on failure e this container context scheduleinsert objectcontainer clientcontext edno uskmanager lookuplatestslot edno shouldlog singleblockinserter compressioncodec getinsertablessk getinserturi ismetadata sourcelength getchkonly tokenobject insertexception freedata removefrom onfailure public synchronized void on success client put state state object container container client context context if persistent container activate pubusk 5 usk new edition pubusk copy edition finished true sbi null freeneturi targeturi pubusk getssk edition geturi freeneturi realuri single block inserter state geturi container context if targeturi equals realuri logger error this uri should be targeturi actually is realuri else if logger should log logger minor this logger minor this uri should be targeturi actually is realuri context usk manager update known good pubusk edition context if persistent state remove from container context if free data if persistent container activate data 1 data free if persistent data remove from container synchronized this data null if persistent container store this if persistent container activate cb 1 container store this cb on encode new edition this container context cb on success this container context finished yay onsuccess clientputstate objectcontainer clientcontext newedition singleblockinserter shouldlog uskmanager updateknowngood removefrom freedata removefrom onencode newedition onsuccess public void on failure insert exception e client put state state object container container client context context client put state oldsbi synchronized this oldsbi sbi sbi null if e get mode insert exception collision try the next slot edition consecutive collisions if persistent container store this if consecutive collisions max tried slots schedule fetcher container context else schedule insert container context else if free data if persistent container activate data 1 data free data remove from container synchronized this data null if persistent container store this if persistent container activate cb 1 cb on failure e state container context if state null persistent state remove from container context if oldsbi null oldsbi state container activate oldsbi 1 oldsbi remove from container context onfailure insertexception clientputstate objectcontainer clientcontext clientputstate getmode insertexception consecutivecollisions consecutivecollisions max_tried_slots schedulefetcher scheduleinsert freedata removefrom onfailure removefrom removefrom override public int hash code return hash code hashcode hashcode public usk inserter base client putter parent bucket data short compression codec freeneturi uri insert context ctx put completion callback cb boolean is metadata int source length int token boolean getchk only boolean add to parent object token object object container container client context context boolean free data boolean persistent throws malformedurl exception this hash code super hash code this token object token object this persistent persistent this parent parent this data data this compression codec compression codec this ctx ctx this cb cb this is metadata is metadata this source length source length this token token this getchk only getchk only if add to parent parent add block container parent add must succeed blocks 1 container parent notify clients container context privusk insertableusk create insertable uri persistent pubusk privusk getusk edition pubusk suggested edition this free data free data uskinserter baseclientputter compressioncodec insertcontext putcompletioncallback ismetadata sourcelength getchkonly addtoparent tokenobject objectcontainer clientcontext freedata malformedurlexception hashcode hashcode tokenobject tokenobject compressioncodec compressioncodec ismetadata ismetadata sourcelength sourcelength getchkonly getchkonly addtoparent addblock addmustsucceedblocks notifyclients createinsertable suggestededition freedata freedata public base client putter get parent return parent baseclientputter getparent public void cancel object container container client context context usk fetcher tag tag boolean persist persistent synchronized this if finished return finished true tag fetcher fetcher null if persistent container store this if tag null tag cancel container context if persist container activate this 1 may have been deactivated by callbacks if sbi null sbi cancel container context will call on failure which will remove from if persist container activate this 1 may have been deactivated by callbacks if free data if persistent container activate data 1 data free if persistent data remove from container synchronized this data null if persistent container store this if persistent container activate cb 1 cb on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext uskfetchertag onfailure removefrom freedata removefrom onfailure insertexception insertexception public void on failure object container container client context context logger error this fetcher failed new exception debug schedule insert container context onfailure objectcontainer clientcontext scheduleinsert public synchronized void on cancelled object container container client context context if fetcher null if persistent container activate fetcher 1 container activate fetcher ctx 1 fetcher ctx remove from container fetcher remove from container context fetcher null if finished return logger error this unexpected on cancelled new exception error cancel container context oncancelled objectcontainer clientcontext removefrom removefrom oncancelled public void on encode base client key key client put state state object container container client context context ignore onencode baseclientkey clientputstate objectcontainer clientcontext public void on transition client put state old state client put state new state object container container shouldn t happen logger error this got on transition old state new state ontransition clientputstate oldstate clientputstate newstate objectcontainer ontransition oldstate newstate public void on metadata metadata m client put state state object container container client context context shouldn t happen logger error this got on metadata m state onmetadata clientputstate objectcontainer clientcontext onmetadata public void on block set finished client put state state object container container client context context ignore onblocksetfinished clientputstate objectcontainer clientcontext public object get token return token object gettoken tokenobject public void on fetchable client put state state object container container ignore onfetchable clientputstate objectcontainer public short get polling priority normal return parent get priority class getpollingprioritynormal getpriorityclass public short get polling priority progress return parent get priority class getpollingpriorityprogress getpriorityclass public void remove from object container container client context context if logger should log logger minor this logger minor this removing from database this new exception debug parent will remove self if free data data null container ext is stored data try data free catch throwable t logger error this already freed caught in remove from on this data t t data remove from container ctx is passed in cb will deal with cb will remove self token object will be removed by creator container activate privusk 5 privusk remove from container container activate pubusk 5 pubusk remove from container if fetcher null logger error this fetcher tag still present fetcher in remove from for this new exception debug container activate fetcher 1 container activate fetcher ctx 1 fetcher ctx remove from container fetcher remove from container context if sbi null logger error this sbi still present sbi in remove from for this container activate sbi 1 sbi remove from container context container delete this removefrom objectcontainer clientcontext shouldlog freedata isstored removefrom removefrom tokenobject removefrom removefrom removefrom removefrom removefrom removefrom removefrom public device list devicelist public device get device int n return device get n getdevice png filter boolean delete text boolean delete timestamp boolean checkcr cs this delete text delete text this delete timestamp delete timestamp this checkcr cs checkcr cs pngfilter deletetext deletetimestamp checkcrcs deletetext deletetext deletetimestamp deletetimestamp checkcrcs checkcrcs public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception bucket output read filter data bf charset other params cb delete text delete timestamp checkcr cs null if output null return output if logger should log logger minor this logger minor this need to modify png bucket filtered bf make bucket 1 output stream os new buffered output stream filtered get output stream try read filter data bf charset other params cb delete text delete timestamp checkcr cs os os flush os close os null finally closer close os return filtered readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception readfilter otherparams deletetext deletetimestamp checkcrcs shouldlog makebucket outputstream bufferedoutputstream getoutputstream readfilter otherparams deletetext deletetimestamp checkcrcs public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb boolean delete text boolean delete timestamp boolean checkcr cs output stream output throws data filter exception io exception boolean logminor logger should log logger minor this boolean logdebug logger should log logger debug this input stream is null buffered input stream bis null data input stream dis null try is data get input stream bis new buffered input stream is dis new data input stream bis check the header byte header check new byte png header length dis read fully header check if arrays equals header check png header throw an exception string message l10n invalid header string title l10n invalid header title throw new data filter exception title title p message p new html node p add child message byte array output stream baos null data output stream dos null if output null baos new byte array output stream dos new data output stream baos output write png header if logminor logger minor this writing the png header to the output bucket check the chunks see http www libpng org pub png spec 1 2 png chunks html c summary of standard chunks boolean finished false boolean has seenihdr false boolean has seeniend false boolean has seenidat false string last chunk type while finished boolean skip false if baos null baos reset string chunk type string null length of the chunk byte length bytes new byte 4 dis read fully length bytes int length length bytes 0 0xff 24 length bytes 1 0xff 16 length bytes 2 0xff 8 length bytes 3 0xff if logminor logger minor this length length if dos null dos write length bytes type of the chunk should match a za z 4 dis read fully length bytes string builder sb new string builder byte chunk type bytes new byte 4 for int i 0 i 4 i char val char length bytes i if val 65 val 99 val 97 val 122 chunk type bytes i length bytes i sb append val else string chunk name hex util bytes to hex length bytes 0 4 throw error unknown chunk the name of the chunk is invalid chunk name chunk type string sb to string if logminor logger minor this name chunk type string content of the chunk byte chunk data new byte length dis read fully chunk data 0 length if logminor if logdebug logger minor this data chunk data length 0 null hex util bytes to hex chunk data else logger minor this data chunk data length if dos null dos write chunk type bytes if dos null dos write chunk data crc of the chunk byte crc length bytes new byte 4 dis read fully crc length bytes if dos null dos write crc length bytes if checkcr cs long readcrc crc length bytes 0 0xff 24 crc length bytes 1 0xff 16 crc length bytes 2 0xff 8 crc length bytes 3 0xff 0x00000000ffffffffl crc32 crc new crc32 crc update chunk type bytes crc update chunk data long computedcrc crc get value if readcrc computedcrc skip true if logminor logger minor this crc of the chunk chunk type string doesn t match long to hex string readcrc but should be long to hex string computedcrc boolean valid chunk type false if skip ihdr equals chunk type string if has seenihdr throw error duplicate ihdr two ihdr chunks detected has seenihdr true valid chunk type true if has seenihdr throw error no ihdr chunk no ihdr chunk if skip iend equals chunk type string if has seeniend xxx impossible code path it should have throwed as iend not last chunk throw error two iend chunks detected two iend chunks detected has seeniend true valid chunk type true if skip plte equals ignore case chunk type string if has seenidat throw error plte must be before idat plte must be before idat valid chunk type true if skip idat equals ignore case chunk type string if has seenidat idat equals ignore case last chunk type throw error multiple idat chunks must be consecutive multiple idat chunks must be consecutive has seenidat true valid chunk type true if valid chunk type for int i 0 i harmless chunk types length i if harmless chunk types i equals chunk type string valid chunk type true if dis available 1 if has seeniend has seenihdr throw error missing iend or ihdr missing iend or ihdr finished true if text equals ignore case chunk type string itxt equals ignore case chunk type string ztxt equals ignore case chunk type string if delete text skip true else valid chunk type true else if delete timestamp time equals ignore case chunk type string if delete timestamp skip true else valid chunk type true if valid chunk type if logminor logger minor this skipping unknown chunk type chunk type string if output null return null skip true if skip output null return null else if skip output null if logminor logger minor this writing chunk type string baos size to the output bucket baos write to output baos flush last chunk type chunk type string if has seeniend dis available 0 throw error iend not last chunk iend not last chunk dis close catch array index out of bounds exception e throw error array index out of bounds exception while filtering array index out of bounds exception while filtering catch negative array size exception e throw error negative array size exception while filtering negative array size exception while filtering catch eof exception e throw error eof exception while filtering eof exception while filtering finally closer close dis closer close bis closer close is return data readfilter bucketfactory hashmap otherparams filtercallback deletetext deletetimestamp checkcrcs outputstream datafilterexception ioexception shouldlog shouldlog inputstream bufferedinputstream datainputstream getinputstream bufferedinputstream datainputstream headercheck pngheader readfully headercheck headercheck pngheader invalidheader invalidheadertitle datafilterexception htmlnode addchild bytearrayoutputstream dataoutputstream bytearrayoutputstream dataoutputstream pngheader hasseenihdr hasseeniend hasseenidat lastchunktype chunktypestring lengthbytes readfully lengthbytes lengthbytes lengthbytes lengthbytes lengthbytes lengthbytes readfully lengthbytes stringbuilder stringbuilder chunktypebytes lengthbytes chunktypebytes lengthbytes chunkname hexutil bytestohex lengthbytes throwerror chunkname chunktypestring tostring chunktypestring chunkdata readfully chunkdata chunkdata hexutil bytestohex chunkdata chunkdata chunktypebytes chunkdata crclengthbytes readfully crclengthbytes crclengthbytes checkcrcs crclengthbytes crclengthbytes crclengthbytes crclengthbytes chunktypebytes chunkdata getvalue chunktypestring tohexstring tohexstring validchunktype chunktypestring hasseenihdr throwerror hasseenihdr validchunktype hasseenihdr throwerror chunktypestring hasseeniend throwerror hasseeniend validchunktype equalsignorecase chunktypestring hasseenidat throwerror validchunktype equalsignorecase chunktypestring hasseenidat equalsignorecase lastchunktype throwerror hasseenidat validchunktype validchunktype harmless_chunk_types harmless_chunk_types chunktypestring validchunktype hasseeniend hasseenihdr throwerror equalsignorecase chunktypestring equalsignorecase chunktypestring equalsignorecase chunktypestring deletetext validchunktype deletetimestamp equalsignorecase chunktypestring deletetimestamp validchunktype validchunktype chunktypestring chunktypestring writeto lastchunktype chunktypestring hasseeniend throwerror arrayindexoutofboundsexception throwerror arrayindexoutofboundsexception arrayindexoutofboundsexception negativearraysizeexception throwerror negativearraysizeexception negativearraysizeexception eofexception throwerror private string l10n string key return l10n get string png filter key getstring pngfilter public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception todo auto generated method stub return null writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception public static void main string arg final file fin new file tmp test png final file fout new file tmp test2 png fout delete final bucket data new file bucket fin true false false false false final bucket out new file bucket fout false true false false false try logger setup stdout logging logger minor content filter filter output output content filter filter data new array bucket factory image png new uri http 127 0 0 1 8888 null bucket tools copy output data out catch io exception e system out println bucket error e get message catch uri syntax exception e system out println internal error e get message catch invalid threshold exception e finally data free filebucket filebucket setupstdoutlogging contentfilter filteroutput contentfilter arraybucketfactory buckettools ioexception getmessage urisyntaxexception getmessage invalidthresholdexception private void throw error string short reason string reason throws data filter exception throw an exception string message invalid png if reason null message reason if short reason null message short reason data filter exception e new data filter exception short reason short reason p message p new html node p add child message if logger should log logger normal this logger normal this throwing e e throw e throwerror shortreason datafilterexception shortreason shortreason datafilterexception datafilterexception shortreason shortreason htmlnode addchild shouldlog public add peer simple field set fs this fs fs this identifier fs get identifier fs remove value identifier addpeer simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied add peer requires full access identifier false string url string fs get url string file string fs get file string builder ref null buffered reader in if url string null try url url new url url string url connection uc url open connection fixme get charset from uc get content type in new buffered reader new input stream reader uc get input stream ref new string builder 1024 string line while line in read line null line line trim ref append line append n in close catch malformedurl exception e throw new message invalid exception protocol error message url parse error error parsing ref url url string e get message identifier false catch io exception e throw new message invalid exception protocol error message url parse error io error while retrieving ref url url string e get message identifier false ref new string builder ref to string trim if ref null throw new message invalid exception protocol error message ref parse error error parsing ref from url url string identifier false if equals ref to string throw new message invalid exception protocol error message ref parse error error parsing ref from url url string identifier false try fs new simple field set ref to string false true catch io exception e throw new message invalid exception protocol error message ref parse error error parsing ref from url url string e get message identifier false else if file string null file f new file file string if f is file throw new message invalid exception protocol error message not a file error the given ref file path file string is not a file identifier false try in new buffered reader new file reader f ref new string builder 1024 string line while line in read line null line line trim ref append line append n in close catch file not found exception e throw new message invalid exception protocol error message file not found file not found when retrieving ref file file string e get message identifier false catch io exception e throw new message invalid exception protocol error message file parse error io error while retrieving ref file file string e get message identifier false ref new string builder ref to string trim if ref null throw new message invalid exception protocol error message ref parse error error parsing ref from file file string identifier false if equals ref to string throw new message invalid exception protocol error message ref parse error error parsing ref from file file string identifier false try fs new simple field set ref to string false true catch io exception e throw new message invalid exception protocol error message ref parse error error parsing ref from file file string e get message identifier false fs set end marker end peer node pn boolean is opennet ref fields string to bool fs get opennet false if is opennet ref try pn node create new opennet node fs catch fs parse exception e throw new message invalid exception protocol error message ref parse error error parsing ref e get message identifier false catch opennet disabled exception e throw new message invalid exception protocol error message opennet disabled error adding ref e get message identifier false catch peer parse exception e throw new message invalid exception protocol error message ref parse error error parsing ref e get message identifier false catch reference signature verification exception e throw new message invalid exception protocol error message ref signature invalid error adding ref e get message identifier false if arrays equals pn get identity node get opennet identity throw new message invalid exception protocol error message cannot peer with self node cannot peer with itself identifier false if node add peer connection pn throw new message invalid exception protocol error message duplicate peer ref node already has a peer with that identity identifier false system out println added opennet peer pn else try pn node create new darknet node fs catch fs parse exception e throw new message invalid exception protocol error message ref parse error error parsing ref e get message identifier false catch peer parse exception e throw new message invalid exception protocol error message ref parse error error parsing ref e get message identifier false catch reference signature verification exception e throw new message invalid exception protocol error message ref signature invalid error adding ref e get message identifier false if arrays equals pn get identity node get darknet identity throw new message invalid exception protocol error message cannot peer with self node cannot peer with itself identifier false if node add peer connection pn throw new message invalid exception protocol error message duplicate peer ref node already has a peer with that identity identifier false system out println added darknet peer pn handler output handler queue new peer message pn true true identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied addpeer urlstring filestring stringbuilder bufferedreader urlstring urlstring urlconnection openconnection getcontenttype bufferedreader inputstreamreader getinputstream stringbuilder readline malformedurlexception messageinvalidexception protocolerrormessage url_parse_error urlstring getmessage ioexception messageinvalidexception protocolerrormessage url_parse_error urlstring getmessage stringbuilder tostring messageinvalidexception protocolerrormessage ref_parse_error urlstring tostring messageinvalidexception protocolerrormessage ref_parse_error urlstring simplefieldset tostring ioexception messageinvalidexception protocolerrormessage ref_parse_error urlstring getmessage filestring filestring isfile messageinvalidexception protocolerrormessage not_a_file_error filestring bufferedreader filereader stringbuilder readline filenotfoundexception messageinvalidexception protocolerrormessage file_not_found filestring getmessage ioexception messageinvalidexception protocolerrormessage file_parse_error filestring getmessage stringbuilder tostring messageinvalidexception protocolerrormessage ref_parse_error filestring tostring messageinvalidexception protocolerrormessage ref_parse_error filestring simplefieldset tostring ioexception messageinvalidexception protocolerrormessage ref_parse_error filestring getmessage setendmarker peernode isopennetref stringtobool isopennetref createnewopennetnode fsparseexception messageinvalidexception protocolerrormessage ref_parse_error getmessage opennetdisabledexception messageinvalidexception protocolerrormessage opennet_disabled getmessage peerparseexception messageinvalidexception protocolerrormessage ref_parse_error getmessage referencesignatureverificationexception messageinvalidexception protocolerrormessage ref_signature_invalid getmessage getidentity getopennetidentity messageinvalidexception protocolerrormessage cannot_peer_with_self addpeerconnection messageinvalidexception protocolerrormessage duplicate_peer_ref createnewdarknetnode fsparseexception messageinvalidexception protocolerrormessage ref_parse_error getmessage peerparseexception messageinvalidexception protocolerrormessage ref_parse_error getmessage referencesignatureverificationexception messageinvalidexception protocolerrormessage ref_signature_invalid getmessage getidentity getdarknetidentity messageinvalidexception protocolerrormessage cannot_peer_with_self addpeerconnection messageinvalidexception protocolerrormessage duplicate_peer_ref outputhandler peermessage override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private float height public pinch filter pinchfilter set the angle of twirl in radians 0 means no distortion param angle the angle of twirl this is the angle by which pixels at the nearest edge of the image will move see get angle public void set angle float angle this angle angle getangle setangle get the angle of twist return the angle in radians see set angle public float get angle return angle setangle getangle set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius set the amount of pinch param amount the amount min value 1 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of pinch return the amount see set amount public float get amount return amount setamount getamount override public buffered image filter buffered image src buffered image dst width src get width height src get height icentrex width centrex icentrey height centrey if radius 0 radius math min icentrex icentrey radius2 radius radius return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight override protected void transform inverse int x int y float out float dx x icentrex float dy y icentrey float distance dx dx dy dy if distance radius2 distance 0 out 0 x out 1 y else float d float math sqrt distance radius2 float t float math pow math sin math pi 0 5 d amount dx t dy t float e 1 d float a angle e e float s float math sin a float c float math cos a out 0 icentrex c dx s dy out 1 icentrey s dx c dy transforminverse override public string to string return distort pinch tostring public address tracker item long time definitely no packets received long time definitely no packets sent time first received packet 1 time first sent packet 1 time last received packet 1 time last sent packet 1 packets sent 0 packets received 0 this time definitely no packets received time definitely no packets received this time definitely no packets sent time definitely no packets sent gap lengths new long track gaps gap length recv times new long track gaps addresstrackeritem timedefinitelynopacketsreceived timedefinitelynopacketssent timefirstreceivedpacket timefirstsentpacket timelastreceivedpacket timelastsentpacket packetssent packetsreceived timedefinitelynopacketsreceived timedefinitelynopacketsreceived timedefinitelynopacketssent timedefinitelynopacketssent gaplengths track_gaps gaplengthrecvtimes track_gaps public address tracker item simple field set fs throws fs parse exception time first received packet fs get long time first received packet time first sent packet fs get long time first sent packet time definitely no packets sent fs get long time definitely no packets sent time definitely no packets received fs get long time definitely no packets received time last received packet fs get long time last received packet time last sent packet fs get long time last sent packet packets sent fs get long packets sent packets received fs get long packets received simple field set gaps fs get subset gaps gap lengths new long track gaps gap length recv times new long track gaps for int i 0 i track gaps i simple field set gap gaps subset integer to string i if gap null logger normal this no more gaps at i i track gaps changed break gap lengths i gap get long length gap length recv times i gap get long received addresstrackeritem simplefieldset fsparseexception timefirstreceivedpacket getlong timefirstreceivedpacket timefirstsentpacket getlong timefirstsentpacket timedefinitelynopacketssent getlong timedefinitelynopacketssent timedefinitelynopacketsreceived getlong timedefinitelynopacketsreceived timelastreceivedpacket getlong timelastreceivedpacket timelastsentpacket getlong timelastsentpacket packetssent getlong packetssent packetsreceived getlong packetsreceived simplefieldset getsubset gaplengths track_gaps gaplengthrecvtimes track_gaps track_gaps simplefieldset tostring track_gaps gaplengths getlong gaplengthrecvtimes getlong public synchronized void sent packet long now packets sent if time first sent packet 0 time first sent packet now time last sent packet now sentpacket packetssent timefirstsentpacket timefirstsentpacket timelastsentpacket public synchronized void received packet long now packets received if time first received packet 0 time first received packet now long old time last received packet time last received packet time last received packet now establish the interval long start time start time time last sent packet start time math max start time time definitely no packets sent if include received packets start time math max start time old time last received packet start time math max start time time definitely no packets received if start time 0 return no information if now start time gap threshold not necessarily a new gap if no packets sent since last one just replace it if time last sent packet gap length recv times 0 rotate gaps array for int i track gaps 1 i 1 i gap lengths i gap lengths i 1 gap length recv times i gap length recv times i 1 else else overwrite 0 gap lengths 0 now start time gap length recv times 0 now receivedpacket packetsreceived timefirstreceivedpacket timefirstreceivedpacket oldtimelastreceivedpacket timelastreceivedpacket timelastreceivedpacket starttime starttime timelastsentpacket starttime starttime timedefinitelynopacketssent include_received_packets starttime starttime oldtimelastreceivedpacket starttime starttime timedefinitelynopacketsreceived starttime starttime gap_threshold timelastsentpacket gaplengthrecvtimes track_gaps gaplengths gaplengths gaplengthrecvtimes gaplengthrecvtimes gaplengths starttime gaplengthrecvtimes public synchronized boolean has long tunnel long horizon return gap length recv times 0 system current time millis horizon haslongtunnel gaplengthrecvtimes currenttimemillis public long longest gap long horizon long now long longest gap 0 for int i 0 i track gaps i if gap length recv times 0 now horizon continue longest gap math max longest gap gap lengths i return longest gap longestgap longestgap track_gaps gaplengthrecvtimes longestgap longestgap gaplengths longestgap public final long gap length public final long received packet at gap long gap length long received packet at this gap length gap length this received packet at received packet at gaplength receivedpacketat gaplength receivedpacketat gaplength gaplength receivedpacketat receivedpacketat public synchronized gap get gaps gap gaps new gap track gaps for int i 0 i track gaps i gaps i new gap gap lengths i gap length recv times i return gaps getgaps track_gaps track_gaps gaplengths gaplengthrecvtimes public synchronized long first received packet return time first received packet firstreceivedpacket timefirstreceivedpacket public synchronized long first sent packet return time first sent packet firstsentpacket timefirstsentpacket public synchronized long last received packet return time last received packet lastreceivedpacket timelastreceivedpacket public synchronized long last sent packet return time last sent packet lastsentpacket timelastsentpacket public synchronized long time definitely no packets sent return time definitely no packets sent timedefinitelynopacketssent timedefinitelynopacketssent public synchronized long time definitely no packets received return time definitely no packets received timedefinitelynopacketsreceived timedefinitelynopacketsreceived public synchronized long packets sent return packets sent packetssent packetssent public synchronized long packets received return packets received packetsreceived packetsreceived public synchronized boolean we sent first if time first received packet 1 return true if time first sent packet 1 return false return time first sent packet time first received packet wesentfirst timefirstreceivedpacket timefirstsentpacket timefirstsentpacket timefirstreceivedpacket public synchronized long time from startup to first sent packet if packets sent 0 return 1 return time first sent packet time definitely no packets sent timefromstartuptofirstsentpacket packetssent timefirstsentpacket timedefinitelynopacketssent public synchronized long time from startup to first received packet if packets received 0 return 1 return time first received packet time definitely no packets received timefromstartuptofirstreceivedpacket packetsreceived timefirstreceivedpacket timedefinitelynopacketsreceived public simple field set to field set simple field set fs new simple field set true fs put time first received packet time first received packet fs put time first sent packet time first sent packet fs put time definitely no packets sent time definitely no packets sent fs put time definitely no packets received time definitely no packets received fs put time last received packet time last received packet fs put time last sent packet time last sent packet fs put packets sent packets sent fs put packets received packets received simple field set gaps new simple field set true for int i 0 i track gaps i simple field set gap new simple field set true gap put length gap lengths i gap put received gap length recv times i gaps put integer to string i gap fs put gaps gaps return fs simplefieldset tofieldset simplefieldset simplefieldset timefirstreceivedpacket timefirstreceivedpacket timefirstsentpacket timefirstsentpacket timedefinitelynopacketssent timedefinitelynopacketssent timedefinitelynopacketsreceived timedefinitelynopacketsreceived timelastreceivedpacket timelastreceivedpacket timelastsentpacket timelastsentpacket packetssent packetssent packetsreceived packetsreceived simplefieldset simplefieldset track_gaps simplefieldset simplefieldset gaplengths gaplengthrecvtimes tostring private int threshold 2 public dilate filter dilatefilter set the threshold the number of neighbouring pixels for dilation to occur param threshold the new threshold see get threshold public void set threshold int threshold this threshold threshold getthreshold setthreshold return the threshold the number of neighbouring pixels for dilation to occur return the current threshold see set threshold public int get threshold return threshold setthreshold getthreshold override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height for int i 0 i iterations i int index 0 if i 0 int t in pixels in pixels out pixels out pixels t for int y 0 y height y for int x 0 x width x int pixel in pixels y width x if black function is black pixel int neighbours 0 for int dy 1 dy 1 dy int iy y dy int ioffset if 0 iy iy height ioffset iy width for int dx 1 dx 1 dx int ix x dx if dy 0 dx 0 0 ix ix width int rgb in pixels ioffset ix if black function is black rgb neighbours if neighbours threshold if colormap null pixel colormap get color float i iterations else pixel new color out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels outpixels outpixels inpixels blackfunction isblack inpixels blackfunction isblack getcolor newcolor outpixels outpixels override public string to string return binary dilate tostring public httpmu socket httpmusocket public httpmu socket string addr int port string bind addr open addr port bind addr httpmusocket bindaddr bindaddr protected void finalize close public string get local address inet address mcast addr ssdp multi group get address enumeration addrs ssdp multi if get inet addresses while addrs has more elements inet address addr inet address addrs next element if mcast addr instanceof inet6 address addr instanceof inet6 address return addr get host address if mcast addr instanceof inet4 address addr instanceof inet4 address return addr get host address return getlocaladdress inetaddress mcastaddr ssdpmultigroup getaddress ssdpmultiif getinetaddresses hasmoreelements inetaddress inetaddress nextelement mcastaddr inet6address inet6address gethostaddress mcastaddr inet4address inet4address gethostaddress public inet address get multicast inet address return ssdp multi group get address inetaddress getmulticastinetaddress ssdpmultigroup getaddress public string get multicast address return get multicast inet address get host address getmulticastaddress getmulticastinetaddress gethostaddress public boolean open string addr int port string bind addr try ssdp multi sock new multicast socket null ssdp multi sock set reuse address true inet socket address bind sock addr new inet socket address port ssdp multi sock bind bind sock addr ssdp multi group new inet socket address inet address get by name addr port ssdp multi if network interface get by inet address inet address get by name bind addr ssdp multi sock join group ssdp multi group ssdp multi if catch exception e debug warning e return false return true bindaddr ssdpmultisock multicastsocket ssdpmultisock setreuseaddress inetsocketaddress bindsockaddr inetsocketaddress ssdpmultisock bindsockaddr ssdpmultigroup inetsocketaddress inetaddress getbyname ssdpmultiif networkinterface getbyinetaddress inetaddress getbyname bindaddr ssdpmultisock joingroup ssdpmultigroup ssdpmultiif public boolean close if ssdp multi sock null return true try ssdp multi sock leave group ssdp multi group ssdp multi if ssdp multi sock null catch exception e debug warning e return false return true ssdpmultisock ssdpmultisock leavegroup ssdpmultigroup ssdpmultiif ssdpmultisock public boolean send string msg string bind addr int bind port try multicast socket msock if bind addr null 0 bind port msock new multicast socket null msock bind new inet socket address bind addr bind port else msock new multicast socket datagram packet dgm packet new datagram packet msg get bytes msg length ssdp multi group thnaks for tho beisch 11 09 04 msock set time to live 4 msock send dgm packet msock close catch exception e debug warning e return false return true bindaddr bindport multicastsocket bindaddr bindport multicastsocket inetsocketaddress bindaddr bindport multicastsocket datagrampacket dgmpacket datagrampacket getbytes ssdpmultigroup settimetolive dgmpacket public boolean send string msg return send msg null 1 public boolean post http request req string bind addr int bind port return send req to string bind addr bind port httprequest bindaddr bindport tostring bindaddr bindport public boolean post http request req return send req to string null 1 httprequest tostring public ssdp packet receive byte ssdv recv buf new byte ssdp recv message bufsize ssdp packet recv packet new ssdp packet ssdv recv buf ssdv recv buf length recv packet set local address get local address try ssdp multi sock receive recv packet get datagram packet recv packet set time stamp system current time millis catch exception e debug warning e return recv packet ssdppacket ssdvrecvbuf recv_message_bufsize ssdppacket recvpacket ssdppacket ssdvrecvbuf ssdvrecvbuf recvpacket setlocaladdress getlocaladdress ssdpmultisock recvpacket getdatagrampacket recvpacket settimestamp currenttimemillis recvpacket public final static boolean is root device string usn value if usn value null return false return usn value ends with rootdevice isrootdevice usnvalue usnvalue usnvalue endswith public final static string getudn string usn value if usn value null return int idx usn value index of if idx 0 return usn value trim string udn value new string usn value get bytes 0 idx return udn value trim usnvalue usnvalue usnvalue indexof usnvalue udnvalue usnvalue getbytes udnvalue public static void main string args throws invalid threshold exception io exception node init exception interrupted exception node node null node second node null try string ip override null if args length 0 ip override args 0 file dir new file bootstrap push pull test file util remove all dir random source random node starter global test init dir get path false logger error false file seednodes new file seednodes fref if seednodes exists seednodes length 0 seednodes can read system err println unable to read seednodes fref it doesn t exist or is empty system exit exit no seednodes file inner dir new file dir 5000 inner dir mkdir file input stream fis new file input stream seednodes file util write to fis new file inner dir seednodes fref fis close create one node executor executor new pooled executor node node starter create test node 5000 5001 dir get path true false false node default max htl 0 random executor 1000 5 1024 1024 true true true true true true true 12 1024 false true ip override node crypto disable group strip true logger setup stdout logging logger minor freenet normal freenet node node dispatcher minor freenet node fnp packet mangler minor logger get chain set threshold logger error kill logging start it node start true wait for ten nodes node system out println creating test data test size bytes bucket data node client core temp bucket factory make bucket test size output stream os data get output stream byte buf new byte 4096 for long written 0 written test size node fast weak random next bytes buf int to write int math min test size written buf length os write buf 0 to write written to write os close system out println inserting test data high level simple client client node client core make client short 0 insert block block new insert block data new client metadata freeneturi empty chk uri long start insert time system current time millis freeneturi uri try uri client insert block false null catch insert exception e system err println insert failed e e print stack trace system exit exit insert failed return long end insert time system current time millis system out println result insert took end insert time start insert time ms time util format time end insert time start insert time to uri node park bootstrap a second node file second inner dir new file dir 5002 second inner dir mkdir fis new file input stream seednodes file util write to fis new file second inner dir seednodes fref fis close executor new pooled executor second node node starter create test node 5002 5003 dir get path true false false node default max htl 0 random executor 1000 5 1024 1024 true true true true true true true 12 1024 false true ip override second node start true wait for ten nodes second node fetch the data long start fetch time system current time millis client second node client core make client short 0 try client fetch uri catch fetch exception e system err println fetch failed e e print stack trace system exit exit fetch failed return long end fetch time system current time millis system out println result fetch took end fetch time start fetch time ms time util format time end fetch time start fetch time of uri second node park system exit 0 catch throwable t system err println caught t t print stack trace try if node null node park catch throwable t1 try if second node null second node park catch throwable t1 system exit exit threw something invalidthresholdexception ioexception nodeinitexception interruptedexception secondnode ipoverride ipoverride fileutil removeall randomsource nodestarter globaltestinit getpath canread exit_no_seednodes innerdir innerdir fileinputstream fileinputstream fileutil writeto innerdir pooledexecutor nodestarter createtestnode getpath default_max_htl ipoverride nodecrypto disable_group_strip setupstdoutlogging nodedispatcher fnppacketmangler getchain setthreshold waitfortennodes test_size clientcore tempbucketfactory makebucket test_size outputstream getoutputstream test_size fastweakrandom nextbytes towrite test_size towrite towrite highlevelsimpleclient clientcore makeclient insertblock insertblock clientmetadata empty_chk_uri startinserttime currenttimemillis insertexception printstacktrace exit_insert_failed endinserttime currenttimemillis endinserttime startinserttime timeutil formattime endinserttime startinserttime secondinnerdir secondinnerdir fileinputstream fileutil writeto secondinnerdir pooledexecutor secondnode nodestarter createtestnode getpath default_max_htl ipoverride secondnode waitfortennodes secondnode startfetchtime currenttimemillis secondnode clientcore makeclient fetchexception printstacktrace exit_fetch_failed endfetchtime currenttimemillis endfetchtime startfetchtime timeutil formattime endfetchtime startfetchtime secondnode printstacktrace secondnode secondnode exit_threw_something private static void wait for ten nodes node node throws interrupted exception long start time system current time millis wait until we have 10 connected nodes int seconds 0 boolean success false while seconds 600 thread sleep 1000 int seeds node peers count seednodes int seed conns node peers get connected seed server peers vector null size int opennet peers node peers count valid peers int opennet conns node peers count connected opennet peers system err println seconds seeds seeds connected seed conns opennet peers opennet peers connected opennet conns seconds if opennet conns target peers long time taken system current time millis start time system out println result completed bootstrap target peers peers in time taken ms time util format time time taken success true break if success system err println failed to reach target peers count target peers in 10 minutes node park system exit exit failed target waitfortennodes interruptedexception starttime currenttimemillis countseednodes seedconns getconnectedseedserverpeersvector opennetpeers countvalidpeers opennetconns countconnectedopennetpeers seedconns opennetpeers opennetconns opennetconns target_peers timetaken currenttimemillis starttime target_peers timetaken timeutil formattime timetaken target_peers exit_failed_target protected n2ntm toadlet node n node client core core high level simple client client super client this node n this core core n2ntmtoadlet nodeclientcore highlevelsimpleclient override public string supported methods return get post supportedmethods override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return if request is parameter set peernode hashcode html node page node ctx get page maker get page node l10n send message ctx html node content node ctx get page maker get content node page node string peernode name null string input hashcode string request get param peernode hashcode int input hashcode 1 try input hashcode integer value of input hashcode string int value catch number format exception e ignore here handle below if input hashcode 1 darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i int peer hashcode peer nodes i hash code if peer hashcode input hashcode peernode name peer nodes i get name break if peernode name null content node add child create peer infobox infobox error l10n peer not found title l10n peer not found with hash hash input hashcode string this writehtml reply ctx 200 ok page node generate return hash map string string peers new hash map string string peers put input hashcode string peernode name createn2ntm send form page node content node ctx peers this writehtml reply ctx 200 ok page node generate return multi value table string string headers new multi value table string string headers put location friends ctx send reply headers 302 found headers null 0 handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception isallowedfullaccess senderrorpage getstring isparameterset peernode_hashcode htmlnode pagenode getpagemaker getpagenode sendmessage htmlnode contentnode getpagemaker getcontentnode pagenode peernode_name input_hashcode_string getparam peernode_hashcode input_hashcode input_hashcode valueof input_hashcode_string intvalue numberformatexception input_hashcode darknetpeernode peernodes getdarknetconnections peernodes peer_hashcode peernodes hashcode peer_hashcode input_hashcode peernode_name peernodes getname peernode_name contentnode addchild createpeerinfobox peernotfoundtitle peernotfoundwithhash input_hashcode_string writehtmlreply pagenode hashmap hashmap input_hashcode_string peernode_name createn2ntmsendform pagenode contentnode writehtmlreply pagenode multivaluetable multivaluetable sendreplyheaders private string l10n string key string pattern string value return l10n get string n2ntm toadlet key new string pattern new string value getstring n2ntmtoadlet private static string l10n string key return l10n get string n2ntm toadlet key getstring n2ntmtoadlet private static html node create peer infobox string infobox type string header string message html node infobox new html node div class infobox infobox type infobox add child div class infobox header header html node infobox content infobox add child div class infobox content infobox content add child message html node list infobox content add child ul toadlet add homepage link list list add child li add child a new string href title new string friends l10n return to friends l10n friends return infobox htmlnode createpeerinfobox infoboxtype htmlnode htmlnode infoboxtype addchild htmlnode infoboxcontent addchild infoboxcontent addchild htmlnode infoboxcontent addchild addhomepagelink addchild addchild returntofriends override public void handle post uri uri http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception string pass request get part as string form password 32 if pass null pass equals core form password multi value table string string headers new multi value table string string headers put location send n2ntm ctx send reply headers 302 found headers null 0 return if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return if request is part set send string message request get part as string message 5 1024 message message trim if message length 1024 this write text reply ctx 400 bad request l10n too long return html node page node ctx get page maker get page node l10n processing send ctx html node content node ctx get page maker get content node page node html node peer table infobox content node add child div class infobox infobox normal darknet peer node peer nodes node get darknet connections string fnam request get part as string filename 1024 file filename null if fnam null fnam length 0 filename new file fnam if filename exists filename can read peer table infobox add child l10n no such file or cannot read toadlet add homepage link peer table infobox this writehtml reply ctx 400 ok page node generate return html node peer table peer table infobox add child table class n2ntm send statuses html node peer table header row peer table add child tr peer table header row add child th l10n peer name peer table header row add child th l10n send status for int i 0 i peer nodes length i if request is part set node peer nodes i hash code darknet peer node pn peer nodes i int status if filename null try status pn send file offer filename message catch io exception e peer table infobox add child l10n no such file or cannot read toadlet add homepage link peer table infobox this writehtml reply ctx 200 ok page node generate return else status pn send text message message string send status short string send status long string send status class if status peer manager peer node status routing backed off send status short l10n delayed title send status long l10n delayed send status class n2ntm send delayed logger normal this sent n2ntm to pn get name message else if status peer manager peer node status connected send status short l10n sent title send status long l10n sent send status class n2ntm send sent logger normal this sent n2ntm to pn get name message else send status short l10n queued title send status long l10n queued send status class n2ntm send queued logger normal this queued n2ntm to pn get name message html node peer row peer table add child tr peer row add child td class peer name add child pn get name peer row add child td class send status class add child span new string title style new string send status long border bottom 1px dotted cursor help send status short html node infobox content peer table infobox add child div class n2ntm message text infobox content add child message html node list peer table infobox add child ul toadlet add homepage link list list add child li add child a new string href title new string friends l10n return to friends l10n friends this writehtml reply ctx 200 ok page node generate return multi value table string string headers new multi value table string string headers put location friends ctx send reply headers 302 found headers null 0 handlepost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception getpartasstring formpassword formpassword multivaluetable multivaluetable send_n2ntm sendreplyheaders isallowedfullaccess senderrorpage getstring ispartset getpartasstring writetextreply toolong htmlnode pagenode getpagemaker getpagenode processingsend htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode peertableinfobox contentnode addchild darknetpeernode peernodes getdarknetconnections getpartasstring canread peertableinfobox addchild nosuchfileorcannotread addhomepagelink peertableinfobox writehtmlreply pagenode htmlnode peertable peertableinfobox addchild htmlnode peertableheaderrow peertable addchild peertableheaderrow addchild peername peertableheaderrow addchild sendstatus peernodes ispartset node_ peernodes hashcode darknetpeernode peernodes sendfileoffer ioexception peertableinfobox addchild nosuchfileorcannotread addhomepagelink peertableinfobox writehtmlreply pagenode sendtextmessage sendstatusshort sendstatuslong sendstatusclass peermanager peer_node_status_routing_backed_off sendstatusshort delayedtitle sendstatuslong sendstatusclass getname peermanager peer_node_status_connected sendstatusshort senttitle sendstatuslong sendstatusclass getname sendstatusshort queuedtitle sendstatuslong sendstatusclass getname htmlnode peerrow peertable addchild peerrow addchild addchild getname peerrow addchild sendstatusclass addchild sendstatuslong sendstatusshort htmlnode infoboxcontent peertableinfobox addchild infoboxcontent addchild htmlnode peertableinfobox addchild addhomepagelink addchild addchild returntofriends writehtmlreply pagenode multivaluetable multivaluetable sendreplyheaders public static void createn2ntm send form html node page node html node content node toadlet context ctx hash map string string peers throws toadlet context closed exception io exception html node infobox content node add child div new string class id new string infobox n2nbox infobox add child div class infobox header l10n send message html node message targets infobox add child div class infobox content message targets add child p l10n composing message label html node message target list message targets add child ul iterate peers for string peer name peers values message target list add child li peer name html node infobox content infobox add child div class infobox content html node message form ctx add form child infobox content send n2ntm sendn2ntm form iterate peers for string peer node hash peers key set message form add child input new string type name value new string hidden node peer node hash 1 message form add child textarea new string id name rows cols new string n2ntmtext message 8 74 message form add child br message form add child you may attach a file message form add child input new string type name value new string text filename message form add child input new string type name value new string submit send l10n send message short createn2ntmsendform htmlnode pagenode htmlnode contentnode toadletcontext hashmap toadletcontextclosedexception ioexception htmlnode contentnode addchild addchild sendmessage htmlnode messagetargets addchild messagetargets addchild composingmessagelabel htmlnode messagetargetlist messagetargets addchild peer_name messagetargetlist addchild peer_name htmlnode infoboxcontent addchild htmlnode messageform addformchild infoboxcontent send_n2ntm sendn2ntmform peernodehash keyset messageform addchild node_ peernodehash messageform addchild messageform addchild messageform addchild messageform addchild messageform addchild sendmessageshort public color get color string param name string param value color default color color color if equals param value param value null color default color else if param value index of 0 color create color from comma separated values param name param value else color create color from field value param name param value return color getcolor paramname paramvalue defaultcolor paramvalue paramvalue defaultcolor paramvalue indexof createcolorfromcommaseparatedvalues paramname paramvalue createcolorfromfieldvalue paramname paramvalue public color create color from comma separated values string param name string param value color color string color values param value split try int r integer parse int color values 0 int g integer parse int color values 1 int b integer parse int color values 2 if color values length 4 int a integer parse int color values 3 color new color r g b a else if color values length 3 color new color r g b else throw new config exception param name param value color can only have 3 rgb or 4 rgb with alpha values catch number format exception nfe throw new config exception param name param value nfe catch array index out of bounds exception aie throw new config exception param name param value aie catch illegal argument exception iae throw new config exception param name param value iae return color createcolorfromcommaseparatedvalues paramname paramvalue colorvalues paramvalue parseint colorvalues parseint colorvalues parseint colorvalues colorvalues parseint colorvalues colorvalues configexception paramname paramvalue numberformatexception configexception paramname paramvalue arrayindexoutofboundsexception configexception paramname paramvalue illegalargumentexception configexception paramname paramvalue public color create color from field value string param name string param value color color try field field class for name java awt color get field param value color color field get null catch no such field exception nsfe throw new config exception param name param value nsfe catch class not found exception cnfe throw new config exception param name param value cnfe catch illegal access exception iae throw new config exception param name param value iae return color createcolorfromfieldvalue paramname paramvalue forname getfield paramvalue nosuchfieldexception configexception paramname paramvalue classnotfoundexception configexception paramname paramvalue illegalaccessexception configexception paramname paramvalue public object get class instance string param name string param value object default instance config config object instance if equals param value param value null instance default instance else try instance class for name param value new instance catch illegal access exception iae throw new config exception param name param value iae catch class not found exception cnfe throw new config exception param name param value cnfe catch instantiation exception ie throw new config exception param name param value ie set configurable instance config return instance getclassinstance paramname paramvalue defaultinstance paramvalue paramvalue defaultinstance forname paramvalue newinstance illegalaccessexception configexception paramname paramvalue classnotfoundexception configexception paramname paramvalue instantiationexception configexception paramname paramvalue setconfigurable public font get fonts string param name string param value int font size font default fonts font fonts if equals param value param value null fonts default fonts else string font names param value split fonts new font font names length for int i 0 i font names length i fonts i new font font names i font bold font size return fonts getfonts paramname paramvalue fontsize defaultfonts paramvalue paramvalue defaultfonts fontnames paramvalue fontnames fontnames fontnames fontsize public int get positive int string param name string param value int default int int int value if equals param value param value null int value default int else try int value integer parse int param value if int value 1 throw new config exception param name param value value must be greater than or equals to 1 catch number format exception nfe throw new config exception param name param value nfe return int value getpositiveint paramname paramvalue defaultint intvalue paramvalue paramvalue intvalue defaultint intvalue parseint paramvalue intvalue configexception paramname paramvalue numberformatexception configexception paramname paramvalue intvalue public char get chars string param name string param value char default chars char chars if equals param value param value null chars default chars else chars param value to char array return chars getchars paramname paramvalue defaultchars paramvalue paramvalue defaultchars paramvalue tochararray public boolean get boolean string param name string param value boolean default value boolean boolean value if yes equals param value equals param value param value null boolean value default value else if no equals param value boolean value false else throw new config exception param name param value value must be either yes or no return boolean value getboolean paramname paramvalue defaultvalue booleanvalue paramvalue paramvalue paramvalue booleanvalue defaultvalue paramvalue booleanvalue configexception paramname paramvalue booleanvalue private void set configurable object object config config if object instanceof configurable configurable object set config config setconfigurable setconfig override public string to string string builder sb new string builder sb append super to string sb append my exponent sb append my exponent to hex string sb append my exponential sb append my exponential to hex string return sb to string tostring stringbuilder stringbuilder tostring myexponent myexponent tohexstring myexponential myexponential tohexstring tostring public diffie hellman light context native big integer my exponent native big integer my exponential this my exponent my exponent this my exponential my exponential this last used time system current time millis this logminor logger should log logger minor this diffiehellmanlightcontext nativebiginteger myexponent nativebiginteger myexponential myexponent myexponent myexponential myexponential lastusedtime currenttimemillis shouldlog public void set signature dsa signature sig this signature sig setsignature dsasignature public native big integer gethmac key native big integer peer exponential dh group group last used time system current time millis big integer p group getp native big integer shared secret native big integer peer exponential mod pow my exponent p if logminor logger minor this p hex util bi to hex p logger minor this my exponent my exponent to hex string logger minor this my exponential my exponential to hex string logger minor this peer s exponential peer exponential to hex string logger minor this g ir mod p shared secret to hex string return shared secret nativebiginteger gethmackey nativebiginteger peerexponential dhgroup lastusedtime currenttimemillis biginteger nativebiginteger sharedsecret nativebiginteger peerexponential modpow myexponent hexutil bitohex myexponent tohexstring myexponential tohexstring peerexponential tohexstring sharedsecret tohexstring sharedsecret public static boolean is valid hostname string hn boolean allowip address if allowip address debugging log messages because address identifier doesn t appear to handle all i pv6 literals correctly such as fe80 204 1234 dead beef address identifier address type address type address identifier get address type hn true logger debug null address type of hn appears to be address type if address type to string equals other the address typer thinks it s either an i pv4 or i pv6 ip address return true note it is believed that this code supports punycode based ascii compatible encoding ace idna labels as described in rfc3490 such an assertion has not be thoroughly tested if hn matches 0 9 a z a z a za z 2 6 system err println failed to match hn as a hostname or i pv4 i pv6 ip address return false return true isvalidhostname allowipaddress allowipaddress addressidentifier ipv6 addressidentifier addresstype addresstype addressidentifier getaddresstype addresstype addresstype tostring ipv4 ipv6 _ ipv4 ipv6 public final class value composite extends rgb composite public value composite float alpha super alpha valuecomposite rgbcomposite valuecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel private float dhsb new float 3 public context float alpha color model src color model color model dst color model super alpha src color model dst color model colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob color rg btohsb sr sg sb shsb color rg btohsb dir dig dib dhsb dhsb 2 shsb 2 int dorgb color hs btorgb dhsb 0 dhsb 1 dhsb 2 dor dorgb 0xff0000 16 dog dorgb 0xff00 8 dob dorgb 0xff float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac rgbtohsb rgbtohsb hsbtorgb public final class new board page extends web page impl public new board page web interface my web interface ft own identity viewer http request request super my web interface viewer request newboardpage webpageimpl newboardpage webinterface mywebinterface ftownidentity httprequest mywebinterface public void make if m request is part set create board final int board language length 8 final int max board name length board max boardname text length board language length 1 1 for the string board language m request get part as string board language board language length string board name m request get part as string board name max board name length try board board m freetalk get message manager get or create board board language board name html node success box add content box board was created success box add child div the board todo i have no idea how to make this text appear in one line without removing the u success box add child u add child new html node a href self uri show board identity m own identity getuid name board get name board get name success box add child div was successfully created make new board page en catch invalid parameter exception e html node alert box add alert box the board could not be created alert box add child div e get message make new board page board language board name else make new board page en mrequest ispartset createboard boardlanguagelength maxboardnamelength max_boardname_text_length boardlanguagelength boardlanguage mrequest getpartasstring boardlanguage boardlanguagelength boardname mrequest getpartasstring boardname maxboardnamelength mfreetalk getmessagemanager getorcreateboard boardlanguage boardname htmlnode successbox addcontentbox successbox addchild successbox addchild addchild htmlnode self_uri showboard mownidentity getname getname successbox addchild makenewboardpage invalidparameterexception htmlnode alertbox addalertbox alertbox addchild getmessage makenewboardpage boardlanguage boardname makenewboardpage private void make new board page string board language string board name html node new board box add content box create a new board html node new board form add form child new board box self uri new board new board new board form add child input new string type name value new string hidden own identityid m own identity getuid html node language box new board form add child get content box language language box add child p the board name will be prefixed with the following language code todo locale getiso languages only returns the abbreviations figure out how to get the full names add some function to board java for getting them and use them here for that you will also need to modify get combo box to take display names and values instead of only values and using them as display names language box add child get combo box board language board get allowed language codes board language html node name box new board form add child get content box board name name box add child p please try to make the name as self explantory as possible you should split the name in categories separated by dots whenever possible for example freenet support instead of just suppport name box add child input new string type size name value new string text 128 board name board name fixme chose a resonable max board name length specify it here and in board java new board form add child input new string type name value new string submit create board create the board makenewboardpage boardlanguage boardname htmlnode newboardbox addcontentbox htmlnode newboardform addformchild newboardbox self_uri newboard newboard newboardform addchild ownidentityid mownidentity htmlnode languagebox newboardform addchild getcontentbox languagebox addchild getisolanguages getcombobox languagebox addchild getcombobox boardlanguage getallowedlanguagecodes boardlanguage htmlnode namebox newboardform addchild getcontentbox namebox addchild namebox addchild boardname boardname newboardform addchild createboard public class revocation key found user alert extends abstract user alert public revocation key found user alert string msg super false l10n get string revocation key found user alert title l10n get string revocation key found user alert text message msg l10n get string revocation key found user alert text message msg new html node l10n get string revocation key found user alert text message msg user alert critical error true null false null revocationkeyfounduseralert abstractuseralert revocationkeyfounduseralert getstring revocationkeyfounduseralert getstring revocationkeyfounduseralert getstring revocationkeyfounduseralert htmlnode getstring revocationkeyfounduseralert useralert critical_error override public void is valid boolean b we ignore it it s always valid isvalid public static base client key get base key freeneturi origuri throws malformedurl exception string key type origuri get key type if chk equals key type return new clientchk origuri if ssk equals key type return new clientssk origuri if ksk equals key type return clientksk create origuri get doc name if usk equals key type return usk create origuri throw new malformedurl exception unknown keytype from origuri baseclientkey getbasekey malformedurlexception keytype getkeytype keytype keytype keytype getdocname keytype malformedurlexception public abstract freeneturi geturi public io statistic collector targets new linked hash map string statistic entry todo only for testing this should only happen once snmp agent create snmp starter initialize logdebug logger should log logger debug this iostatisticcollector linkedhashmap statisticentry snmpagent snmpstarter shouldlog public void add info string key int inbytes int outbytes try synchronized this addinfo key inbytes outbytes catch throwable t t print stack trace addinfo _addinfo printstacktrace private void addinfo string key int inbytes int outbytes rotate if enable per address tracking statistic entry entry targets get key if entry null entry new statistic entry targets put key entry entry add data inbytes 0 inbytes 0 outbytes 0 outbytes 0 synchronized this totalbytesout outbytes 0 outbytes 0 totalbytesin inbytes 0 inbytes 0 if logdebug logger debug io statistic collector class add key inbytes outbytes totalbytesin totalbytesout _addinfo enable_per_address_tracking statisticentry statisticentry adddata iostatisticcollector public void dump info synchronized this dumpinfo dumpinfo _dumpinfo public long get totalio synchronized this return gettotalio gettotalio _gettotalio private long gettotalio long ret new long 2 synchronized this ret 0 totalbytesout ret 1 totalbytesin return ret _gettotalio public int get total statistics synchronized this return gettotalstatistics gettotalstatistics _gettotalstatistics private int gettotalstatistics string keys string targets key set to array int ret new int statistics entries 2 for int i 0 i statistics entries i ret i 0 ret i 1 0 for map entry string statistic entry entry targets entry set int inres entry get value get recieved int outres entry get value get sent for int i 0 i statistics entries i ret i 1 inres i ret i 0 outres i return ret _gettotalstatistics keyset toarray statistics_entries statistics_entries statisticentry entryset getvalue getrecieved getvalue getsent statistics_entries private void dumpinfo rotate date format df date format get date instance date format long locale france system err println date format get date instance format new date system err println new date final double divby statistics duration s 1024 for map entry string statistic entry entry targets entry set string key entry get key int inres entry get value get recieved int outres entry get value get sent system err print key substring 0 22 int tin 0 int tout 0 for int i 0 i inres length i in out in 102 4 bytes hecto bytes tin inres i tout outres i int in int tin 10 0 divby i 1 int out int tout 10 0 divby i 1 system err print i in 10 in 10 system err print o out 10 out 10 system err print t system err println system err println _dumpinfo dateformat dateformat getdateinstance dateformat dateformat getdateinstance statistics_duration_s statisticentry entryset getkey getvalue getrecieved getvalue getsent private void rotate long now system current time millis if now lastrotate statistics duration lastrotate now object keys targets key set to array if keys null return why aren t we iterating there for int i 0 i keys length i object key keys i if targets get key rotate false targets remove key fixme debugging dumpinfo currenttimemillis statistics_duration keyset toarray _dumpinfo public statistic entry create a new array and clear it recieved new int io statistic collector statistics entries 1 sent new int io statistic collector statistics entries 1 for int i 0 i recieved length i recieved i sent i 0 statisticentry iostatisticcollector statistics_entries iostatisticcollector statistics_entries public void add data int inbytes int outbytes recieved 0 inbytes sent 0 outbytes adddata public boolean rotate boolean hasdata false for int i recieved length 1 i 0 i recieved i recieved i 1 sent i sent i 1 hasdata recieved i 0 sent i 0 recieved 0 sent 0 0 return hasdata public int get recieved int retint new int io statistic collector statistics entries system arraycopy recieved 1 retint 0 io statistic collector statistics entries return retint getrecieved iostatisticcollector statistics_entries iostatisticcollector statistics_entries public int get sent int retint new int io statistic collector statistics entries system arraycopy sent 1 retint 0 io statistic collector statistics entries return retint getsent iostatisticcollector statistics_entries iostatisticcollector statistics_entries public partially received block int packets int packet size byte data if data length packets packet size throw new runtime exception length of data data length doesn t match packet number and size data data received new boolean packets for int x 0 x received length x received x true receivedcount packets packets packets packetsize packet size partiallyreceivedblock packetsize packetsize runtimeexception _data _received _received _received _receivedcount _packets _packetsize packetsize public partially received block int packets int packet size data new byte packets packet size received new boolean packets packets packets packetsize packet size partiallyreceivedblock packetsize _data packetsize _received _packets _packetsize packetsize public synchronized linked list integer add listener packet received listener listener throws aborted exception if aborted throw new aborted exception adding listener to aborted prb packetreceivedlisteners add listener linked list integer ret new linked list integer for int x 0 x packets x if received x ret add last x return ret linkedlist addlistener packetreceivedlistener abortedexception _aborted abortedexception _packetreceivedlisteners linkedlist linkedlist _packets _received addlast public synchronized boolean is received int packet no throws aborted exception if aborted throw new aborted exception prb is aborted return received packet no isreceived packetno abortedexception _aborted abortedexception _received packetno public synchronized int get num packets throws aborted exception if aborted throw new aborted exception prb is aborted return packets getnumpackets abortedexception _aborted abortedexception _packets public synchronized int get packet size throws aborted exception if aborted throw new aborted exception prb is aborted return packetsize getpacketsize abortedexception _aborted abortedexception _packetsize public void add packet int position buffer packet throws aborted exception packet received listener prls synchronized this if aborted throw new aborted exception prb is aborted if packet get length packetsize throw new runtime exception new packet size packet get length but expecting packet of size packetsize if received position return receivedcount packet copy to data position packetsize received position true fixme keep it as as an array prls packetreceivedlisteners to array new packet received listener packetreceivedlisteners size for int i 0 i prls length i packet received listener prl prls i prl packet received position addpacket abortedexception packetreceivedlistener _aborted abortedexception getlength _packetsize runtimeexception getlength _packetsize _received _receivedcount copyto _data _packetsize _received _packetreceivedlisteners toarray packetreceivedlistener _packetreceivedlisteners packetreceivedlistener packetreceived public synchronized boolean all received throws aborted exception if aborted throw new aborted exception prb is aborted return receivedcount packets allreceived abortedexception _aborted abortedexception _receivedcount _packets public synchronized byte get block throws aborted exception if aborted throw new aborted exception prb is aborted if all received throw new runtime exception tried to get block before all packets received return data getblock abortedexception _aborted abortedexception allreceived runtimeexception _data public synchronized buffer get packet int x throws aborted exception if aborted throw new aborted exception prb is aborted if received x throw new illegal state exception that packet is not received return new buffer data x packetsize packetsize getpacket abortedexception _aborted abortedexception _received illegalstateexception _data _packetsize _packetsize public synchronized void remove listener packet received listener listener packetreceivedlisteners remove listener removelistener packetreceivedlistener _packetreceivedlisteners public synchronized void abort int reason string description aborted true abortreason reason abortdescription description for packet received listener prl packetreceivedlisteners prl receive aborted reason description _aborted _abortreason _abortdescription packetreceivedlistener _packetreceivedlisteners receiveaborted public synchronized boolean is aborted return aborted isaborted _aborted public synchronized int get abort reason return abortreason getabortreason _abortreason public synchronized string get abort description return abortdescription getabortdescription _abortdescription public static interface packet received listener public void packet received int packet no packetreceivedlistener packetreceived packetno public void packet received int packet no public void receive aborted int reason string description packetreceived packetno receiveaborted will get all needed info from the plugin put it into the wrapper then the pluginstarter will be greated and the plugin fedto it starting the plugin the plugin info wrapper will then be returned param plug public static plugin info wrapper start plugin plugin manager pm string filename fred plugin plug plugin respirator pr final plugin info wrapper pi new plugin info wrapper pr plug filename final plugin starter ps new plugin starter pr pi ps set plugin pm plug class loader old class loader thread current thread get context class loader class loader plugin class loader plug get class get class loader thread current thread set context class loader plugin class loader try we must start the plugin after startup has finished runnable job if pi is threadless plugin final thread t new thread ps t set daemon true pi set thread t job new runnable public void run t start pm get ticker queue timed job job 0 else avoid np es let it init then register it plug run plugin pr pm register plug pi finally thread current thread set context class loader old class loader return pi plugininfowrapper plugininfowrapper startplugin pluginmanager fredplugin pluginrespirator plugininfowrapper plugininfowrapper pluginstarter pluginstarter setplugin classloader oldclassloader currentthread getcontextclassloader classloader pluginclassloader getclass getclassloader currentthread setcontextclassloader pluginclassloader isthreadlessplugin setdaemon setthread getticker queuetimedjob npes runplugin currentthread setcontextclassloader oldclassloader pi set thread t job new runnable public void run t start setthread final plugin info wrapper pi public plugin starter plugin respirator pr plugin info wrapper pi this pr pr this pi pi plugininfowrapper pluginstarter pluginrespirator plugininfowrapper public void set plugin plugin manager pm fred plugin plugin this plugin plugin this pm pm setplugin pluginmanager fredplugin public void run try pm register plugin pi plugin run plugin pr catch out of memory error e oom handler handleoom e catch throwable t logger normal this caught throwable while running plugin t t system err println caught throwable while running plugin t t print stack trace pi unregister pm if not already unregistered pm remove plugin pi runplugin outofmemoryerror oomhandler printstacktrace removeplugin public static salted hash freenet store construct file base dir string name store callback callback random random long max keys int bloom filter size boolean bloom counting semi ordered shutdown hook shutdown hook boolean preallocate boolean resize on start throws io exception return new salted hash freenet store base dir name callback random max keys bloom filter size bloom counting shutdown hook preallocate resize on start saltedhashfreenetstore basedir storecallback maxkeys bloomfiltersize bloomcounting semiorderedshutdownhook shutdownhook resizeonstart ioexception saltedhashfreenetstore basedir maxkeys bloomfiltersize bloomcounting shutdownhook resizeonstart private salted hash freenet store file base dir string name store callback callback random random long max keys int bloom filter size boolean bloom counting semi ordered shutdown hook shutdown hook boolean preallocate boolean resize on start throws io exception logminor logger should log logger minor this logdebug logger should log logger debug this this base dir base dir this name name this callback callback collision possible callback collision possible header block length callback header length full key length callback full key length data block length callback data length hd padding header block length data block length 512 0 0 512 header block length data block length 512 this random random store size max keys this bloom filter size bloom filter size this preallocate preallocate lock manager new lock manager create a directory it not exist this base dir mkdirs config file new file this base dir name config boolean new store load config file new store open store files base dir name file bloom file new file this base dir name bloom bloom filter bloom filter create filter bloom file bloom filter size bloom filterk bloom counting system err println bloomfilter bloom filter for name is loaded if flags flag dirty 0 system err println datastore name is dirty flags flag dirty datastore is now dirty until flush and close write config file if max keys store size if prev store size 0 store size math max prev store size store size prev store size 0 set max keys max keys true callback set store this shutdown hook add early job new thread new shutdowndb cleaner thread new cleaner cleaner status user alert new cleaner status user alert cleaner thread finish all resizing before continue if resize on start prev store size 0 cleaner global lock try lock system out println resizing datastore name try cleaner thread resize store prev store size false finally cleaner global lock unlock write config file if bloom filter need rebuild new store bloom filter resized flags flag rebuild bloom check bloom false if cleaner global lock try lock system out println bloom filter for datastore name missing mismatch rebuilding try cleaner thread rebuild bloom false finally cleaner global lock unlock write config file system err println check bloom check bloom flags flags bloom size bloom filter size keys max keys cleaner thread start saltedhashfreenetstore basedir storecallback maxkeys bloomfiltersize bloomcounting semiorderedshutdownhook shutdownhook resizeonstart ioexception shouldlog shouldlog basedir basedir collisionpossible collisionpossible headerblocklength headerlength fullkeylength fullkeylength datablocklength datalength hdpadding headerblocklength datablocklength headerblocklength datablocklength storesize maxkeys bloomfiltersize bloomfiltersize lockmanager lockmanager basedir configfile basedir newstore loadconfigfile newstore openstorefiles basedir bloomfile basedir bloomfilter bloomfilter createfilter bloomfile bloomfiltersize bloomfilterk bloomcounting bloomfilter flag_dirty flag_dirty flushandclose writeconfigfile maxkeys storesize prevstoresize storesize prevstoresize storesize prevstoresize setmaxkeys maxkeys setstore shutdownhook addearlyjob cleanerthread cleanerstatususeralert cleanerstatususeralert cleanerthread resizeonstart prevstoresize cleanergloballock trylock cleanerthread resizestore prevstoresize cleanergloballock writeconfigfile bloomfilter needrebuild newstore flag_rebuild_bloom checkbloom cleanergloballock trylock cleanerthread rebuildbloom cleanergloballock writeconfigfile checkbloom checkbloom bloomfiltersize maxkeys cleanerthread public storable block fetch byte routing key byte full key boolean dont promote throws io exception if logminor logger minor this fetch hex util bytes to hex routing key for callback try int retry 0 while config lock read lock try lock 2 time unit seconds if shutdown return null if retry 10 throw new io exception lock timeout 20s catch interrupted exception e throw new io exception interrupted e try map long condition lock map lock plain key routing key true if lock map null if logdebug logger debug this cannot lock key hex util bytes to hex routing key shutting down return null try entry entry probe entry routing key true if entry null misses increment and get return null try storable block block entry get storable block routing key full key if block null misses increment and get return null hits increment and get return block catch key verify exception e logger minor this key verification exception e misses increment and get return null finally unlock plain key routing key true lock map finally config lock read lock unlock storableblock routingkey fullkey dontpromote ioexception hexutil bytestohex routingkey configlock readlock trylock timeunit ioexception interruptedexception ioexception lockmap lockplainkey routingkey lockmap hexutil bytestohex routingkey probeentry routingkey incrementandget storableblock getstorableblock routingkey fullkey incrementandget incrementandget keyverifyexception incrementandget unlockplainkey routingkey lockmap configlock readlock find and lock an entry with a specific routing key this function would strong not strong lock the entries param routing key param with data return code entry code object throws io exception private entry probe entry byte routing key boolean with data throws io exception if check bloom if bloom filter check filter cipher manager get digested key routing key return null entry entry probe entry0 routing key store size with data if entry null prev store size 0 entry probe entry0 routing key prev store size with data if check bloom entry null bloom false pos increment and get return entry routingkey withdata ioexception probeentry routingkey withdata ioexception checkbloom bloomfilter checkfilter ciphermanager getdigestedkey routingkey probeentry0 routingkey storesize withdata prevstoresize probeentry0 routingkey prevstoresize withdata checkbloom bloomfalsepos incrementandget private entry probe entry0 byte routing key long probe store size boolean with data throws io exception entry entry null long offset get offset from plain key routing key probe store size for int i 0 i offset length i if logdebug logger debug this probing for i i offset offset i try entry read entry offset i routing key with data if entry null return entry catch eof exception e if prev store size 0 may occur on store shrinking logger error this eof exception on probe entry e continue return null probeentry0 routingkey probestoresize withdata ioexception getoffsetfromplainkey routingkey probestoresize readentry routingkey withdata eofexception prevstoresize eofexception probeentry public void put storable block block byte routing key byte full key byte data byte header boolean overwrite throws io exception key collision exception if logminor logger minor this putting hex util bytes to hex routing key name try int retry 0 while config lock read lock try lock 2 time unit seconds if shutdown return if retry 10 throw new io exception lock timeout 20s catch interrupted exception e throw new io exception interrupted e try map long condition lock map lock plain key routing key false if lock map null if logdebug logger debug this cannot lock key hex util bytes to hex routing key shutting down return try use lazy loading here this may lost data if digested routing key collide but collision possible is false should be very rare as digested routing key is a sha 256 hash entry old entry probe entry routing key false if old entry null old entry is free long old offset old entry cur offset try if collision possible return old entry sethd readhd old offset read from disk storable block old block old entry get storable block routing key full key if block equals old block return already in store else if overwrite throw new key collision exception catch key verify exception e ignore overwrite old offset with same key entry entry new entry routing key header data write entry entry old offset writes increment and get if old entry generation generation key count increment and get return entry entry new entry routing key header data long offset entry get offset for int i 0 i offset length i if offset i store file size ready is free offset i write to free block if logdebug logger debug this probing write to i i offset offset i bloom filter add key cipher manager get digested key routing key write entry entry offset i writes increment and get key count increment and get return no free blocks overwrite the first one if logdebug logger debug this collision write to i 0 offset offset 0 bloom filter add key cipher manager get digested key routing key old entry read entry offset 0 null false write entry entry offset 0 writes increment and get if old entry generation generation bloom filter remove key old entry get digested routing key else key count increment and get finally unlock plain key routing key false lock map finally config lock read lock unlock storableblock routingkey fullkey ioexception keycollisionexception hexutil bytestohex routingkey configlock readlock trylock timeunit ioexception interruptedexception ioexception lockmap lockplainkey routingkey lockmap hexutil bytestohex routingkey digestedroutingkey collisionpossible digestedroutingkey oldentry probeentry routingkey oldentry oldentry isfree oldoffset oldentry curoffset collisionpossible oldentry oldoffset storableblock oldblock oldentry getstorableblock routingkey fullkey oldblock keycollisionexception keyverifyexception routingkey writeentry oldoffset incrementandget oldentry keycount incrementandget routingkey getoffset storefilesizeready isfree bloomfilter addkey ciphermanager getdigestedkey routingkey writeentry incrementandget keycount incrementandget bloomfilter addkey ciphermanager getdigestedkey routingkey oldentry readentry writeentry incrementandget oldentry bloomfilter removekey oldentry getdigestedroutingkey keycount incrementandget unlockplainkey routingkey lockmap configlock readlock private long cur offset 1 private entry curoffset private entry byte buffer meta data buf byte buffer hd buf assert meta data buf remaining metadata length digested routing key new byte 0x20 meta data buf get digested routing key data encryptiv new byte 0x10 meta data buf get data encryptiv flag meta data buf get long store size meta data buf get long if flag entry flag plainkey 0 plain routing key new byte 0x20 meta data buf get plain routing key meta data buf position 0x60 generation meta data buf get int is encrypted true if hd buf null sethd hd buf bytebuffer metadatabuf bytebuffer hdbuf metadatabuf metadata_length digestedroutingkey metadatabuf digestedroutingkey dataencryptiv metadatabuf dataencryptiv metadatabuf getlong storesize metadatabuf getlong entry_flag_plainkey plainroutingkey metadatabuf plainroutingkey metadatabuf metadatabuf getint isencrypted hdbuf hdbuf set header data after construction param store buf param store private void sethd byte buffer hd buf assert hd buf remaining header block length data block length hd padding assert is encrypted header new byte header block length hd buf get header data new byte data block length hd buf get data storebuf bytebuffer hdbuf hdbuf headerblocklength datablocklength hdpadding isencrypted headerblocklength hdbuf datablocklength hdbuf create a new entry param plain routing key param header param data private entry byte plain routing key byte header byte data this plain routing key plain routing key flag entry flag occupied this store size salted hash freenet store this store size this generation salted hash freenet store this generation header data will be overwritten in encrypt decrypt let s make a copy here this header new byte header block length system arraycopy header 0 this header 0 header block length this data new byte data block length system arraycopy data 0 this data 0 data block length if option save plainkey flag entry flag plainkey is encrypted false plainroutingkey plainroutingkey plainroutingkey plainroutingkey entry_flag_occupied storesize saltedhashfreenetstore storesize saltedhashfreenetstore headerblocklength headerblocklength datablocklength datablocklength option_save_plainkey entry_flag_plainkey isencrypted private byte buffer to meta data buffer byte buffer out byte buffer allocate metadata length cipher manager encrypt this random out put get digested routing key out put data encryptiv out put long flag out put long store size if flag entry flag plainkey 0 plain routing key null assert plain routing key length 0x20 out put plain routing key out position 0x60 out put int generation out position 0 return out bytebuffer tometadatabuffer bytebuffer bytebuffer metadata_length ciphermanager getdigestedroutingkey dataencryptiv putlong putlong storesize entry_flag_plainkey plainroutingkey plainroutingkey plainroutingkey putint private byte buffer tohd buffer assert is encrypted should have encrypted to get data encryptiv in control buffer assert header length header block length assert data length data block length if header null data null return null byte buffer out byte buffer allocate header block length data block length hd padding out put header out put data out position 0 return out bytebuffer tohdbuffer isencrypted dataencryptiv headerblocklength datablocklength bytebuffer bytebuffer headerblocklength datablocklength hdpadding private storable block get storable block byte routing key byte full key throws key verify exception if is free header null data null return null this is a free block if cipher manager decrypt this routing key return null storable block block callback construct data header routing key full key byte block routing key block get routing key if arrays equals block routing key routing key can t recover as decrypt depends on a correct route key return null return block storableblock getstorableblock routingkey fullkey keyverifyexception isfree ciphermanager routingkey storableblock routingkey fullkey blockroutingkey getroutingkey blockroutingkey routingkey private long get offset if digested routing key null return get offset from digested key digested routing key store size else return get offset from plain key plain routing key store size getoffset digestedroutingkey getoffsetfromdigestedkey digestedroutingkey storesize getoffsetfromplainkey plainroutingkey storesize private boolean is free return flag entry flag occupied 0 isfree entry_flag_occupied byte get digested routing key if digested routing key null if plain routing key null return null else digested routing key cipher manager get digested key plain routing key return digested routing key getdigestedroutingkey digestedroutingkey plainroutingkey digestedroutingkey ciphermanager getdigestedkey plainroutingkey digestedroutingkey open all store files param base dir param name throws io exception return code true code iff this is a new datastore private boolean open store files file base dir string name throws io exception meta file new file base dir name metadata hd file new file base dir name hd boolean new store meta file exists hd file exists metaraf new random access file meta file rw metafc metaraf get channel metafc lock hdraf new random access file hd file rw hdfc hdraf get channel hdfc lock long store file size math max store size prev store size wrapper manager signal starting 10 60 1000 10minutes for filesystem that support no sparse file set store file size store file size true return new store basedir ioexception openstorefiles basedir ioexception metafile basedir hdfile basedir newstore metafile hdfile randomaccessfile metafile getchannel randomaccessfile hdfile getchannel storefilesize storesize prevstoresize wrappermanager signalstarting setstorefilesize storefilesize newstore read entry from disk before calling this function you should acquire all required locks return code null code if and only if code routing key code is not code null code and the key does not match the entry private entry read entry long offset byte routing key boolean with data throws io exception byte buffer mbf byte buffer allocate entry metadata length do int status metafc read mbf entry metadata length offset mbf position if status 1 throw new eof exception while mbf has remaining mbf flip entry entry new entry mbf null entry cur offset offset if routing key null if entry is free return null if arrays equals cipher manager get digested key routing key entry digested routing key return null if with data byte buffer hd buf readhd offset entry sethd hd buf boolean decrypted cipher manager decrypt entry routing key if decrypted return null return entry routingkey readentry routingkey withdata ioexception bytebuffer bytebuffer metadata_length metadata_length eofexception hasremaining curoffset routingkey isfree ciphermanager getdigestedkey routingkey digestedroutingkey withdata bytebuffer hdbuf hdbuf ciphermanager routingkey read header data from disk param offset throws io exception private byte buffer readhd long offset throws io exception byte buffer buf byte buffer allocate header block length data block length hd padding long pos header block length data block length hd padding offset do int status hdfc read buf pos buf position if status 1 throw new eof exception while buf has remaining buf flip return buf ioexception bytebuffer ioexception bytebuffer bytebuffer headerblocklength datablocklength hdpadding headerblocklength datablocklength hdpadding eofexception hasremaining private boolean is free long offset throws io exception entry entry read entry offset null false return entry is free isfree ioexception readentry isfree private byte get digested key from offset long offset throws io exception entry entry read entry offset null false return entry get digested routing key getdigestedkeyfromoffset ioexception readentry getdigestedroutingkey write entry to disk before calling this function you should ul li acquire all required locks li li update the entry with latest store size li ul private void write entry entry entry long offset throws io exception cipher manager encrypt entry random byte buffer bf entry to meta data buffer do int status metafc write bf entry metadata length offset bf position if status 1 throw new eof exception while bf has remaining bf entry tohd buffer if bf null long pos header block length data block length hd padding offset do int status hdfc write bf pos bf position if status 1 throw new eof exception while bf has remaining entry cur offset offset writeentry ioexception ciphermanager bytebuffer tometadatabuffer metadata_length eofexception hasremaining tohdbuffer headerblocklength datablocklength hdpadding eofexception hasremaining curoffset private void flush and close logger normal this flush and closing this store name try metafc force true metafc close catch exception e logger error this error flusing store e try hdfc force true hdfc close catch exception e logger error this error flusing store e bloom filter force flushandclose bloomfilter set preallocate storage space param preallocate public void set preallocate boolean preallocate this preallocate preallocate setpreallocate change on disk store file size param store file size private void set store file size long store file size boolean starting try long old meta len metaraf length long old hd len hdraf length final long new meta len entry metadata length store file size final long new hd len header block length data block length hd padding store file size if preallocate fill the store file with random data this won t be compressed unlike filling it with zeros so the disk space usage of the node will not change apart from temp files note that mersenne twister is not cryptographically secure in fact from 2 4kb of output you can predict the rest of the stream this is okay because an attacker knows which blocks are occupied anyway it is essential to label them to get good data retention on resizing etc on my test system phenom 2 2g hz this does approx 80mb sec if i reseed every 2kb from an aes ctr which is pointless as i just explained it does 40mb sec byte b new byte 4096 byte buffer bf byte buffer wrap b start from next 4kb boundary align to x86 page size if old meta len 4096 0 old meta len 4096 old meta len 4096 if old hd len 4096 0 old hd len 4096 old hd len 4096 this may write excess the size the set length would fix it while old meta len new meta len never write random byte to meta data this would screw up the is free function bf rewind metafc write bf old meta len old meta len 4096 byte seed new byte 64 random next bytes seed random mt new mersenne twister seed int x 0 while old hd len new hd len mt next bytes b bf rewind hdfc write bf old hd len old hd len 4096 if old hd len 1024 1024 1024l 0 random next bytes seed mt new mersenne twister seed if starting wrapper manager signal starting 5 60 1000 if x 32 0 system err println preallocating space for name old hd len new hd len store file size ready old hd len header block length data block length hd padding store file size ready store file size metaraf set length new meta len hdraf set length new hd len catch io exception e logger error this error resizing store file e storefilesize setstorefilesize storefilesize oldmetalen oldhdlen newmetalen metadata_length storefilesize newhdlen headerblocklength datablocklength hdpadding storefilesize mersennetwister 2ghz bytebuffer bytebuffer oldmetalen oldmetalen oldmetalen oldhdlen oldhdlen oldhdlen setlength oldmetalen newmetalen isfree oldmetalen oldmetalen nextbytes mersennetwister oldhdlen newhdlen nextbytes oldhdlen oldhdlen oldhdlen nextbytes mersennetwister wrappermanager signalstarting oldhdlen newhdlen storefilesizeready oldhdlen headerblocklength datablocklength hdpadding storefilesizeready storefilesize setlength newmetalen setlength newhdlen ioexception load config file return code true code iff this is a new datastore private boolean load config file throws io exception assert cipher manager null never load the configuration twice if config file exists create new byte newsalt new byte 0x10 random next bytes newsalt cipher manager new cipher manager newsalt bloom filterk bloom filter optimialk bloom filter size store size write config file return true else try try to load random access file raf new random access file config file r try byte salt new byte 0x10 raf read fully salt cipher manager new cipher manager salt store size raf read long prev store size raf read long key count set raf read long generation raf read int flags raf read int if flags flag dirty 0 flags flag rebuild bloom try bloom filterk raf read int if bloom filterk 0 bloom filterk bloom filter optimialk bloom filter size store size flags flag rebuild bloom check bloom false catch io exception e flags flag rebuild bloom return false finally closer close raf catch io exception e corrupted delete it and try again logger error this config file corrupted trying to create a new store name e system err println config file corrupted trying to create a new store name if config file exists config file delete file meta file new file base dir name metadata meta file delete return load config file last restore logger error this can t delete config file please delete the store manually name e system err println can t delete config file please delete the store manually name throw e loadconfigfile ioexception ciphermanager configfile nextbytes ciphermanager ciphermanager bloomfilterk bloomfilter bloomfiltersize storesize writeconfigfile randomaccessfile randomaccessfile configfile readfully ciphermanager ciphermanager storesize readlong prevstoresize readlong keycount readlong readint readint flag_dirty flag_rebuild_bloom bloomfilterk readint bloomfilterk bloomfilterk bloomfilter bloomfiltersize storesize flag_rebuild_bloom checkbloom ioexception flag_rebuild_bloom ioexception configfile configfile metafile basedir metafile loadconfigfile write config file private void write config file config lock write lock lock try file temp config new file config file get path tmp random access file raf new random access file temp config rw raf seek 0 raf write cipher manager get salt raf write long store size raf write long prev store size raf write long key count get raf write int generation raf write int flags raf write int bloom filterk raf write int 0 raf write long 0 raf getfd sync raf close file util rename to temp config config file catch io exception ioe logger error this error writing config file for name ioe finally config lock write lock unlock writeconfigfile configlock writelock tempconfig configfile getpath randomaccessfile randomaccessfile tempconfig ciphermanager getsalt writelong storesize writelong prevstoresize writelong keycount writeint writeint writeint bloomfilterk writeint writelong fileutil renameto tempconfig configfile ioexception configlock writelock private interface batch processor initialize void init batchprocessor call this after reading resize memory entries entries return false to abort boolean batch long entries left resize_memory_entries entriesleft call this on abort e g node shutdown void abort void abort void finish return code null code to free the entry return not modified to keep the old entry entry process entry entry not_modified public cleaner super store name cleaner native thread low priority false set priority min priority set daemon true nativethread low_priority setpriority min_priority setdaemon override public void run super run try thread sleep int cleaner period 2 cleaner period math random catch interrupted exception e if shutdown return int loop 0 while shutdown loop cleaner lock lock try long prevstoresize config lock read lock lock try prevstoresize prev store size finally config lock read lock unlock if prevstoresize 0 cleaner global lock try lock try is resizing true resize store prevstoresize true finally is resizing false cleaner global lock unlock boolean rebuildbloom config lock read lock lock try rebuildbloom flags flag rebuild bloom 0 finally config lock read lock unlock if rebuildbloom prev store size 0 cleaner global lock try lock try is rebuilding true rebuild bloom false finally is rebuilding false cleaner global lock unlock try if loop 6 0 bloom filter force catch exception e may throw io exception even if it is not defined logger error this can t force bloom filter e write config file try cleaner condition await cleaner period time unit milliseconds catch interrupted exception e logger debug this interrupted e finally cleaner lock unlock cleaner_period cleaner_period interruptedexception cleanerlock _prevstoresize configlock readlock _prevstoresize prevstoresize configlock readlock _prevstoresize cleanergloballock trylock isresizing resizestore _prevstoresize isresizing cleanergloballock _rebuildbloom configlock readlock _rebuildbloom flag_rebuild_bloom configlock readlock _rebuildbloom prevstoresize cleanergloballock trylock isrebuilding rebuildbloom isrebuilding cleanergloballock bloomfilter ioexception writeconfigfile cleanercondition cleaner_period timeunit interruptedexception cleanerlock move old entries to new location and resize store private void resize store final long prevstoresize final boolean sleep logger normal this starting datastore resize batch processor resize processer new batch processor list entry old entry list new linked list entry int optimialk public void init if store size prevstoresize set store file size store size false optimialk bloom filter optimialk bloom filter size store size config lock write lock lock try generation bloom filter fork optimialk key count set 0 finally config lock write lock unlock wrapper manager signal starting resize memory entries 30 1000 1000 public entry process entry entry int old generation entry generation if old generation generation entry generation generation key count increment and get if entry store size store size new size don t have to relocate if entry generation generation update filter bloom filter add key forked entry get digested routing key return entry else return not modified remove from store prepare for relocation if old generation generation should be impossible logger error this new generation object with wrong store size digested routing key hex util bytes to hex entry get digested routing key offset entry cur offset bloom filter remove key entry get digested routing key try entry sethd readhd entry cur offset old entry list add entry if old entry list size resize memory entries old entry list remove 0 catch io exception e logger error this error reading entry offset entry cur offset e return null int i 0 public boolean batch long entries left wrapper manager signal starting resize memory entries 30 1000 1000 if i 16 0 write config file shrink data file to current size if store size prevstoresize set store file size math max store size entries left false try to resolve the list list iterator entry it old entry list list iterator while it has next if resolve old entry it next it remove return prevstoresize prev store size public void abort bloom filter discard public void finish config lock write lock lock try if prevstoresize prev store size return bloom filter merge prev store size 0 flags flag rebuild bloom check bloom true bloom filterk optimialk finally config lock write lock unlock logger normal this finish resizing name batch process entries resize processer prevstoresize true sleep resizestore _prevstoresize batchprocessor resizeprocesser batchprocessor oldentrylist linkedlist storesize _prevstoresize setstorefilesize storesize bloomfilter bloomfiltersize storesize configlock writelock bloomfilter keycount configlock writelock wrappermanager signalstarting resize_memory_entries oldgeneration oldgeneration keycount incrementandget storesize storesize bloomfilter addkeyforked getdigestedroutingkey not_modified oldgeneration storesize digestedroutingkey hexutil bytestohex getdigestedroutingkey curoffset bloomfilter removekey getdigestedroutingkey curoffset oldentrylist oldentrylist resize_memory_entries oldentrylist ioexception curoffset entriesleft wrappermanager signalstarting resize_memory_entries writeconfigfile storesize _prevstoresize setstorefilesize storesize entriesleft listiterator oldentrylist listiterator hasnext resolveoldentry _prevstoresize prevstoresize bloomfilter configlock writelock _prevstoresize prevstoresize bloomfilter prevstoresize flag_rebuild_bloom checkbloom bloomfilterk configlock writelock batchprocessentries resizeprocesser _prevstoresize public void init if store size prevstoresize set store file size store size false optimialk bloom filter optimialk bloom filter size store size config lock write lock lock try generation bloom filter fork optimialk key count set 0 finally config lock write lock unlock wrapper manager signal starting resize memory entries 30 1000 1000 storesize _prevstoresize setstorefilesize storesize bloomfilter bloomfiltersize storesize configlock writelock bloomfilter keycount configlock writelock wrappermanager signalstarting resize_memory_entries public entry process entry entry int old generation entry generation if old generation generation entry generation generation key count increment and get if entry store size store size new size don t have to relocate if entry generation generation update filter bloom filter add key forked entry get digested routing key return entry else return not modified remove from store prepare for relocation if old generation generation should be impossible logger error this new generation object with wrong store size digested routing key hex util bytes to hex entry get digested routing key offset entry cur offset bloom filter remove key entry get digested routing key try entry sethd readhd entry cur offset old entry list add entry if old entry list size resize memory entries old entry list remove 0 catch io exception e logger error this error reading entry offset entry cur offset e return null oldgeneration oldgeneration keycount incrementandget storesize storesize bloomfilter addkeyforked getdigestedroutingkey not_modified oldgeneration storesize digestedroutingkey hexutil bytestohex getdigestedroutingkey curoffset bloomfilter removekey getdigestedroutingkey curoffset oldentrylist oldentrylist resize_memory_entries oldentrylist ioexception curoffset int i 0 public boolean batch long entries left wrapper manager signal starting resize memory entries 30 1000 1000 if i 16 0 write config file shrink data file to current size if store size prevstoresize set store file size math max store size entries left false try to resolve the list list iterator entry it old entry list list iterator while it has next if resolve old entry it next it remove return prevstoresize prev store size entriesleft wrappermanager signalstarting resize_memory_entries writeconfigfile storesize _prevstoresize setstorefilesize storesize entriesleft listiterator oldentrylist listiterator hasnext resolveoldentry _prevstoresize prevstoresize public void abort bloom filter discard bloomfilter public void finish config lock write lock lock try if prevstoresize prev store size return bloom filter merge prev store size 0 flags flag rebuild bloom check bloom true bloom filterk optimialk finally config lock write lock unlock logger normal this finish resizing name configlock writelock _prevstoresize prevstoresize bloomfilter prevstoresize flag_rebuild_bloom checkbloom bloomfilterk configlock writelock rebuild bloom filter private void rebuild bloom boolean sleep if bloom filter null return logger normal this start rebuilding bloom filter name batch processor rebuild bloom processor new batch processor int optimialk public void init optimialk bloom filter optimialk bloom filter size store size config lock write lock lock try generation bloom filter fork bloom filterk key count set 0 finally config lock write lock unlock wrapper manager signal starting resize memory entries 5 1000 1000 public entry process entry entry if entry generation generation bloom filter add key forked entry get digested routing key key count increment and get entry generation generation return entry return not modified int i 0 public boolean batch long entries left wrapper manager signal starting resize memory entries 5 1000 1000 if i 16 0 write config file return prev store size 0 public void abort bloom filter discard public void finish bloom filter merge config lock write lock lock try flags flag rebuild bloom check bloom true bloom filterk optimialk finally config lock write lock unlock logger normal this finish rebuilding bloom filter name batch process entries rebuild bloom processor store size false sleep rebuildbloom bloomfilter batchprocessor rebuildbloomprocessor batchprocessor bloomfilter bloomfiltersize storesize configlock writelock bloomfilter bloomfilterk keycount configlock writelock wrappermanager signalstarting resize_memory_entries bloomfilter addkeyforked getdigestedroutingkey keycount incrementandget not_modified entriesleft wrappermanager signalstarting resize_memory_entries writeconfigfile prevstoresize bloomfilter bloomfilter configlock writelock flag_rebuild_bloom checkbloom bloomfilterk configlock writelock batchprocessentries rebuildbloomprocessor storesize public void init optimialk bloom filter optimialk bloom filter size store size config lock write lock lock try generation bloom filter fork bloom filterk key count set 0 finally config lock write lock unlock wrapper manager signal starting resize memory entries 5 1000 1000 bloomfilter bloomfiltersize storesize configlock writelock bloomfilter bloomfilterk keycount configlock writelock wrappermanager signalstarting resize_memory_entries public entry process entry entry if entry generation generation bloom filter add key forked entry get digested routing key key count increment and get entry generation generation return entry return not modified bloomfilter addkeyforked getdigestedroutingkey keycount incrementandget not_modified int i 0 public boolean batch long entries left wrapper manager signal starting resize memory entries 5 1000 1000 if i 16 0 write config file return prev store size 0 entriesleft wrappermanager signalstarting resize_memory_entries writeconfigfile prevstoresize public void abort bloom filter discard bloomfilter public void finish bloom filter merge config lock write lock lock try flags flag rebuild bloom check bloom true bloom filterk optimialk finally config lock write lock unlock logger normal this finish rebuilding bloom filter name bloomfilter configlock writelock flag_rebuild_bloom checkbloom bloomfilterk configlock writelock private void batch process entries batch processor processor long store size boolean reverse boolean sleep entries left entries total store size long start offset step if reverse start offset 0 step resize memory entries else start offset store size 1 resize memory entries resize memory entries step resize memory entries int i 0 processor init try for long cur offset start offset cur offset 0 cur offset store size cur offset step if shutdown processor abort return if i 64 0 system err println name cleaner in progress entries total entries left entries total batch process entries cur offset resize memory entries processor entries left reverse cur offset math max store size cur offset resize memory entries 0 if processor batch entries left processor abort return try if sleep thread sleep 100 catch interrupted exception e processor abort return processor finish catch exception e processor abort batchprocessentries batchprocessor storesize entriesleft entriestotal storesize startoffset startoffset resize_memory_entries startoffset storesize resize_memory_entries resize_memory_entries resize_memory_entries curoffset startoffset curoffset curoffset storesize curoffset entriestotal entriesleft entriestotal batchprocessentries curoffset resize_memory_entries entriesleft curoffset storesize curoffset resize_memory_entries entriesleft interruptedexception read a list of items from store param offset start offset must be multiple of link file split param length number of items to read must be multiple of link file split if this excess store size read as much as possible param processor batch processor return code true code if operation complete successfully code false code otherwise e g can t acquire locks node shutting down private boolean batch process entries long offset int length batch processor processor condition locked new condition length try acquire all locks in the region will unlock in the finally block for int i 0 i length i locked i lock manager lock entry offset i if locked i null return false long start file offset offset entry metadata length long entries to read length long buf len entry metadata length entries to read byte buffer buf byte buffer allocate int buf len boolean dirty false try while buf has remaining int status metafc read buf start file offset buf position if status 1 break catch io exception ioe if shutdown return false logger error this unexpected io exception ioe buf flip try for int j 0 shutdown buf limit j entry metadata length j buf position j entry metadata length if buf remaining entry metadata length eof break byte buffer en buf buf slice en buf limit entry metadata length entry entry new entry en buf null entry cur offset offset j if entry is free continue not occupied entry new entry processor process entry if new entry null free the offset buf position j entry metadata length buf put byte buffer allocate entry metadata length key count decrement and get dirty true else if new entry not modified else write back buf position j entry metadata length buf put new entry to meta data buffer assert new entry header null not supported assert new entry data null not supported dirty true finally write back if dirty buf flip try while buf has remaining metafc write buf start file offset buf position catch io exception ioe logger error this unexpected io exception ioe return true finally unlock for int i 0 i length i if locked i null lock manager unlock entry offset i locked i file_split file_split batchprocessentries batchprocessor lockmanager lockentry startfileoffset metadata_length entriestoread buflen metadata_length entriestoread bytebuffer bytebuffer buflen hasremaining startfileoffset ioexception ioexception metadata_length metadata_length metadata_length bytebuffer enbuf enbuf metadata_length enbuf curoffset isfree newentry newentry metadata_length bytebuffer metadata_length keycount decrementandget newentry not_modified metadata_length newentry tometadatabuffer newentry newentry hasremaining startfileoffset ioexception ioexception lockmanager unlockentry put back an old entry to store file param entry return code true code if the entry have put back successfully private boolean resolve old entry entry entry map long condition lock map lock digested key entry get digested routing key false if lock map null return false try entry store size store size long offsets entry get offset check for occupied entry with same key for long offset offsets try if is free offset arrays equals get digested key from offset offset entry get digested routing key do nothing return true catch io exception e logger debug this io excception on resolve old entry e check for free entry for long offset offsets try if is free offset write entry entry offset bloom filter add key forked entry get digested routing key key count increment and get return true catch io exception e logger debug this io excception on resolve old entry e return false finally unlock digested key entry get digested routing key false lock map resolveoldentry lockmap lockdigestedkey getdigestedroutingkey lockmap storesize storesize getoffset isfree getdigestedkeyfromoffset getdigestedroutingkey ioexception ioexcception resolveoldentry isfree writeentry bloomfilter addkeyforked getdigestedroutingkey keycount incrementandget ioexception ioexcception resolveoldentry unlockdigestedkey getdigestedroutingkey lockmap private cleaner cleaner private cleaner status user alert cleaner cleaner this cleaner cleaner cleanerstatususeralert public string anchor return store cleaner name public string dismiss button text return l10n get string user alert hide dismissbuttontext getstring useralert public html node gethtml text return new html node get text htmlnode gethtmltext htmlnode gettext public short get priority class return user alert minor getpriorityclass useralert public string get short text if cleaner is resizing return l10n get string salted hash freenet store short resize progress new string name processed total new string name cleaner entries total cleaner entries left cleaner entries total else return l10n get string salted hash freenet store short rebuild progress new string name processed total new string name cleaner entries total cleaner entries left cleaner entries total getshorttext isresizing getstring saltedhashfreenetstore shortresizeprogress entriestotal entriesleft entriestotal getstring saltedhashfreenetstore shortrebuildprogress entriestotal entriesleft entriestotal public string get text if cleaner is resizing return l10n get string salted hash freenet store long resize progress new string name processed total new string name cleaner entries total cleaner entries left cleaner entries total else return l10n get string salted hash freenet store long rebuild progress new string name processed total new string name cleaner entries total cleaner entries left cleaner entries total gettext isresizing getstring saltedhashfreenetstore longresizeprogress entriestotal entriesleft entriestotal getstring saltedhashfreenetstore longrebuildprogress entriestotal entriesleft entriestotal public string get title return l10n get string salted hash freenet store cleaner alert title new string name new string name gettitle getstring saltedhashfreenetstore cleaneralerttitle public object get user identifier return null getuseridentifier public boolean is valid return cleaner is rebuilding cleaner is resizing isvalid isrebuilding isresizing public void is valid boolean validity ignore isvalid public void on dismiss ignore ondismiss public boolean should unregister on dismiss return true shouldunregisterondismiss public boolean user can dismiss return false usercandismiss public boolean is event notification return false iseventnotification public void set user alert manager user alert manager user alert manager if cleaner status user alert null user alert manager register cleaner status user alert setuseralertmanager useralertmanager useralertmanager cleanerstatususeralert useralertmanager cleanerstatususeralert public void set max keys long new store size boolean shrink now throws io exception logger normal this name resize new store size new store size shink now shrink now config lock write lock lock try if new store size this store size return if prev store size 0 logger normal this name resize already in progress ignore resize request return prev store size store size store size new store size write config file finally config lock write lock unlock if cleaner lock try lock cleaner condition signal cleaner lock unlock setmaxkeys newstoresize shrinknow ioexception newstoresize newstoresize shinknow shrinknow configlock writelock newstoresize storesize prevstoresize prevstoresize storesize storesize newstoresize writeconfigfile configlock writelock cleanerlock trylock cleanercondition cleanerlock lock all possible offsets of a key this method would release the locks if any locking operation failed param plain key return code true code if all the offsets are locked private map long condition lock plain key byte plain key boolean use prev store size return lock digested key cipher manager get digested key plain key use prev store size plainkey lockplainkey plainkey useprevstoresize lockdigestedkey ciphermanager getdigestedkey plainkey useprevstoresize private void unlock plain key byte plain key boolean use prev store size map long condition lock map unlock digested key cipher manager get digested key plain key use prev store size lock map unlockplainkey plainkey useprevstoresize lockmap unlockdigestedkey ciphermanager getdigestedkey plainkey useprevstoresize lockmap lock all possible offsets of a key this method would release the locks if any locking operation failed param digested key return code true code if all the offsets are locked private map long condition lock digested key byte digested key boolean use prev store size use a set to prevent duplicated offsets a sorted set to prevent deadlocks sorted set long offsets new tree set long long offset array get offset from digested key digested key store size for long offset offset array offsets add offset if use prev store size prev store size 0 offset array get offset from digested key digested key prev store size for long offset offset array offsets add offset map long condition locked new tree map long condition for long offset offsets condition condition lock manager lock entry offset if condition null break locked put offset condition if locked size offsets size return locked else failed remove the locks for map entry long condition e locked entry set lock manager unlock entry e get key e get value return null digestedkey lockdigestedkey digestedkey useprevstoresize sortedset treeset offsetarray getoffsetfromdigestedkey digestedkey storesize offsetarray useprevstoresize prevstoresize offsetarray getoffsetfromdigestedkey digestedkey prevstoresize offsetarray treemap lockmanager lockentry entryset lockmanager unlockentry getkey getvalue private void unlock digested key byte digested key boolean use prev store size map long condition lock map use a set to prevent duplicated offsets sorted set long offsets new tree set long long offset array get offset from digested key digested key store size for long offset offset array offsets add offset if use prev store size prev store size 0 offset array get offset from digested key digested key prev store size for long offset offset array offsets add offset for long offset offsets lock manager unlock entry offset lock map get offset lock map remove offset unlockdigestedkey digestedkey useprevstoresize lockmap sortedset treeset offsetarray getoffsetfromdigestedkey digestedkey storesize offsetarray useprevstoresize prevstoresize offsetarray getoffsetfromdigestedkey digestedkey prevstoresize offsetarray lockmanager unlockentry lockmap lockmap public class shutdowndb implements runnable public void run shutdown true lock manager shutdown cleaner lock lock try cleaner condition signal all cleaner thread interrupt finally cleaner lock unlock config lock write lock lock try flush and close flags flag dirty clean shutdown write config file finally config lock write lock unlock system out println successfully closed store name lockmanager cleanerlock cleanercondition signalall cleanerthread cleanerlock configlock writelock flushandclose flag_dirty writeconfigfile configlock writelock get offset in the hash table given a plain routing key param plain key param store size return private long get offset from plain key byte plain key long store size return get offset from digested key cipher manager get digested key plain key store size plainkey storesize getoffsetfromplainkey plainkey storesize getoffsetfromdigestedkey ciphermanager getdigestedkey plainkey storesize get offset in the hash table given a digested routing key param digested key param store size return private long get offset from digested key byte digested key long store size long key value fields bytes to long digested key long offsets new long option max probe for int i 0 i option max probe i h 141 i 2 13 i offsets i key value 141 i i 13 i long max value store size return offsets digestedkey storesize getoffsetfromdigestedkey digestedkey storesize keyvalue bytestolong digestedkey option_max_probe option_max_probe keyvalue max_value storesize private atomic long bloom false pos new atomic long public long hits return hits get atomiclong bloomfalsepos atomiclong public long misses return misses get public long writes return writes get public long key count return key count get keycount keycount public long get max keys config lock read lock lock long storesize store size config lock read lock unlock return storesize getmaxkeys configlock readlock _storesize storesize configlock readlock _storesize public long get bloom false positive return bloom false pos get getbloomfalsepositive bloomfalsepos migration public void migration from file store file file key file try system out println migrating from store file random access file storeraf new random access file store file r random access file keyraf key file exists new random access file key file r null byte header new byte header block length byte data new byte data block length byte key new byte full key length long max key storeraf length header block length data block length for int l 0 l max key l if l 1024 0 system out println migrating key l max key wrapper manager signal starting 10 60 1000 max 10 minutes for every 1024 keys boolean key read false storeraf read fully header storeraf read fully data try if keyraf null keyraf read fully key key read true catch io exception e try storable block b callback construct data header null key read key null put b b get routing key b get full key data header true catch key verify exception e system out println kve at block l catch key collision exception e system out println kce at block l catch eof exception eof done catch io exception e e print stack trace migrationfrom storefile keyfile storefile randomaccessfile randomaccessfile storefile randomaccessfile keyfile randomaccessfile keyfile headerblocklength datablocklength fullkeylength maxkey headerblocklength datablocklength maxkey maxkey wrappermanager signalstarting keyread readfully readfully readfully keyread ioexception storableblock keyread getroutingkey getfullkey keyverifyexception keycollisionexception eofexception ioexception printstacktrace public boolean probably in store byte routing key config lock read lock lock try if check bloom return true return bloom filter check filter cipher manager get digested key routing key finally config lock read lock unlock probablyinstore routingkey configlock readlock checkbloom bloomfilter checkfilter ciphermanager getdigestedkey routingkey configlock readlock public class time sorted hashtable t extends comparable t public time sorted hashtable this elements new tree set element t this value to element new hash map t element t timesortedhashtable timesortedhashtable treeset valuetoelement hashmap private static class element t extends comparable t implements comparable element t element long t t v time t value v public int compare to element t o if time o time return 1 if time o time return 1 if value null o value null return 0 if value null o value null return 1 if value null o value null return 1 return value compare to o value compareto compareto push ing an object that is already in the queue moves that object to the most recently used position but doesn t add a duplicate entry in the queue param now public final synchronized void push t value long now assert elements size value to element size if value null throw new null pointer exception element t e value to element get value if e null e new element t now value elements add e value to element put value e else elements remove e e time now elements add e assert elements size value to element size valuetoelement nullpointerexception valuetoelement valuetoelement valuetoelement public final int size return elements size public final synchronized boolean remove value t value assert elements size value to element size element t e value to element remove value if e null return false elements remove e assert elements size value to element size return true removevalue valuetoelement valuetoelement valuetoelement public final synchronized boolean contains value t key return value to element contains key key containsvalue valuetoelement containskey note that this does not automatically promote the key you have to do that by hand with push key value public final synchronized long get time t value element t e value to element remove value if e null return 1 return e time gettime valuetoelement count the number of values after specified timestamp param timestamp return value count public synchronized int count values after long t set element t s elements tail set new element t t null return s size countvaluesafter tailset remove all entries on or before the given time public final synchronized void remove before long t assert elements size value to element size set element t s elements head set new element t t null for iterator element t i s iterator i has next element t e i next value to element remove e value i remove assert elements size value to element size removebefore valuetoelement headset hasnext valuetoelement valuetoelement fixme this is broken if timestamp 1 public final synchronized e object pairs after long timestamp e values array set element t s elements tail set new element t timestamp null long time array new long s size int i 0 for element t e s time array i e time values array i e e value i return new object values array time array pairsafter valuesarray tailset timearray timearray valuesarray valuesarray timearray public class time series impl t extends time series tick extends persistent collection t implements time series t public array list t elements return new array list t this timeseriesimpl timeseries persistentcollection timeseries arraylist arraylist public object to array return elements to array toarray toarray public e e to array e arr return elements to array arr toarray toarray public boolean add t tick long time tick get time iterator iterator index iterator new key time max block time interval new key time index descent order if iterator has next insert in block block iterator next tick else add new block tick return true gettime maxblocktimeinterval descent_order hasnext insertinblock addnewblock class time series iterator extends iterable iterator t time series iterator long from long till pos 1 this till till block iterator index iterator new key from max block time interval new key till index ascent order while block iterator has next block block block block iterator next int n block used tick e block get ticks int l 0 r n while l r int i l r 1 if from e i get time l i 1 else r i assert that l r l n e l get time from if l n if e l get time till pos l curr block block return timeseriesiterator iterableiterator timeseriesiterator blockiterator maxblocktimeinterval ascent_order blockiterator hasnext blockiterator getticks gettime gettime gettime currblock public boolean has next return pos 0 hasnext public t next if pos 0 throw new no such element exception t tick t curr block get ticks pos if pos curr block used if block iterator has next curr block block block iterator next pos 0 else pos 1 return tick if curr block get ticks pos get time till pos 1 return tick nosuchelementexception currblock getticks currblock blockiterator hasnext currblock blockiterator currblock getticks gettime public void remove throw new unsupported operation exception unsupportedoperationexception class time series reverse iterator extends iterable iterator t time series reverse iterator long from long till pos 1 this from from block iterator index iterator new key from max block time interval new key till index descent order while block iterator has next block block block block iterator next int n block used tick e block get ticks int l 0 r n while l r int i l r 1 if till e i get time l i 1 else r i assert that l r l n e l get time till if l 0 if e l 1 get time from pos l 1 curr block block return timeseriesreverseiterator iterableiterator timeseriesreverseiterator blockiterator maxblocktimeinterval descent_order blockiterator hasnext blockiterator getticks gettime gettime gettime currblock public boolean has next return pos 0 hasnext public t next if pos 0 throw new no such element exception t tick t curr block get ticks pos if pos 0 if block iterator has next curr block block block iterator next pos curr block used 1 else pos 1 return tick if curr block get ticks pos get time from pos 1 return tick nosuchelementexception currblock getticks blockiterator hasnext currblock blockiterator currblock currblock getticks gettime public void remove throw new unsupported operation exception unsupportedoperationexception public iterator t iterator return iterator null null true public iterable iterator t iterator date from date till return iterator from till true iterableiterator public iterable iterator t iterator boolean ascent return iterator null null ascent iterableiterator public iterable iterator t iterator date from date till boolean ascent long low from null 0 from get time long high till null long max value till get time return ascent iterable iterator t new time series iterator low high iterable iterator t new time series reverse iterator low high iterableiterator gettime max_value gettime iterableiterator timeseriesiterator iterableiterator timeseriesreverseiterator public date get first time iterator block iterator index iterator if block iterator has next block block block block iterator next return new date block timestamp return null getfirsttime blockiterator blockiterator hasnext blockiterator public date get last time iterator block iterator index iterator null null index descent order if block iterator has next block block block block iterator next return new date block get ticks block used 1 get time return null getlasttime blockiterator descent_order blockiterator hasnext blockiterator getticks gettime public int size return int count ticks countticks public long count ticks long n 0 iterator block iterator index iterator while block iterator has next block block block block iterator next n block used return n countticks blockiterator blockiterator hasnext blockiterator public t get tick date timestamp long time timestamp get time iterator block iterator index iterator new key time max block time interval new key time index ascent order while block iterator has next block block block block iterator next int n block used tick e block get ticks int l 0 r n while l r int i l r 1 if time e i get time l i 1 else r i assert that l r l n e l get time time if l n e l get time time return t e l return null gettick gettime blockiterator maxblocktimeinterval ascent_order blockiterator hasnext blockiterator getticks gettime gettime gettime public boolean has date timestamp return get tick timestamp null gettick public int remove date from date till long low from null 0 from get time long high till null long max value till get time int n removed 0 key from key new key low max block time interval key till key new key high iterator block iterator index iterator from key till key index ascent order while block iterator has next block block block block iterator next int n block used tick e block get ticks int l 0 r n while l r int i l r 1 if low e i get time l i 1 else r i assert that l r l n e l get time low while r n e r get time high r 1 n removed 1 if l 0 r n index remove new key block timestamp block block iterator index iterator from key till key index ascent order block deallocate else if l n l r if l 0 index remove new key block timestamp block block timestamp e r get time index put new key block timestamp block block iterator index iterator from key till key index ascent order while r n e l e r block used l block modify return n removed gettime max_value gettime nremoved fromkey maxblocktimeinterval tillkey blockiterator fromkey tillkey ascent_order blockiterator hasnext blockiterator getticks gettime gettime gettime nremoved blockiterator fromkey tillkey ascent_order gettime blockiterator fromkey tillkey ascent_order nremoved private void add new block tick t block block try block block block class new instance catch exception x throw new storage error storage error constructor failure block class x block timestamp t get time block used 1 block get ticks 0 t index put new key block timestamp block addnewblock blockclass newinstance storageerror storageerror constructor_failure blockclass gettime getticks void insert in block block block tick tick long t tick get time int i n block used tick e block get ticks int l 0 r n while l r i l r 1 if t e i get time l i 1 else r i assert that l r l n e l get time t if r 0 if e n 1 get time t max block time interval n e length add new block tick return if block timestamp t index remove new key block timestamp block block timestamp t index put new key block timestamp block else if r n if t e 0 get time max block time interval n e length add new block tick return if n e length add new block e n 1 for i n i r e i e i 1 else for i n i r i e i e i 1 block used 1 e r tick block modify insertinblock gettime getticks gettime gettime gettime maxblocktimeinterval addnewblock gettime maxblocktimeinterval addnewblock addnewblock time series impl storage storage class block class long max block time interval this block class block class this max block time interval max block time interval block class name class descriptor get class name block class index storage create index long class false timeseriesimpl blockclass maxblocktimeinterval blockclass blockclass maxblocktimeinterval maxblocktimeinterval blockclassname classdescriptor getclassname blockclass createindex time series impl timeseriesimpl time series impl public void on load block class class descriptor load class get storage block class name timeseriesimpl onload blockclass classdescriptor loadclass getstorage blockclassname public void clear iterator block iterator index iterator while block iterator has next block block block block iterator next block deallocate index clear blockiterator blockiterator hasnext blockiterator public void deallocate clear index deallocate super deallocate ssk insert handler nodessk key byte data byte headers short htl peer node source long id node node long start time insert tag tag this node node this uid id this source source this start time start time this key key this htl htl this data data this headers headers this tag tag if htl 0 htl 1 byte pub key hash key get pub key hash pub key node get key pub key hash can commit false logminor logger should log logger minor this sskinserthandler peernode starttime inserttag starttime starttime pubkeyhash getpubkeyhash pubkey getkey pubkeyhash cancommit shouldlog override public string to string return super to string for uid tostring tostring public void run freenet support logger os thread logpid this try real run catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t finally if logminor logger minor this exiting insert handler run for uid node unlockuid uid true true false false false tag osthread realrun outofmemoryerror oomhandler inserthandler private void real run send accepted message accepted dmt createfnpssk accepted uid pub key null try source send async accepted null this catch not connected exception e1 if logminor logger minor this lost connection to source return if headers null try message filter mf message filter create set type dmt fnpssk insert request headers set field dmt uid uid set source source set timeout data insert timeout message msg node usm wait for mf this if msg null logger normal this failed to receive fnpssk insert request headers for uid return headers short buffer msg get object dmt block headers get data catch disconnected exception e if logminor logger minor this lost connection to source on uid return if data null try message filter mf message filter create set type dmt fnpssk insert request data set field dmt uid uid set source source set timeout data insert timeout message msg node usm wait for mf this if msg null logger normal this failed to receive fnpssk insert request data for uid return data short buffer msg get object dmt data get data catch disconnected exception e if logminor logger minor this lost connection to source on uid return if pub key null wait for pub key if logminor logger minor this waiting for pubkey on uid message filter mfpk message filter create set type dmt fnpssk pub key set field dmt uid uid set source source set timeout pubkey timeout try message pk node usm wait for mfpk this if pk null logger normal this failed to receive fnpssk pub key for uid return byte pubkey as bytes short buffer pk get object dmt pubkey as bytes get data try pub key dsa public key create pubkey as bytes if logminor logger minor this got pubkey on uid pub key message confirm dmt createfnpssk pub key accepted uid try source send async confirm null this catch not connected exception e if logminor logger minor this lost connection to source on uid return catch crypt format exception e logger error this invalid pubkey from source on uid message msg dmt createfnp data insert rejected uid dmt data insert rejected ssk error try source send sync msg this catch not connected exception ee ignore return catch disconnected exception e if logminor logger minor this lost connection to source on uid return try key set pub key pub key block new ssk block data headers key false catch ssk verify exception e1 logger error this invalid ssk from source e1 message msg dmt createfnp data insert rejected uid dmt data insert rejected ssk error try source send sync msg this catch not connected exception e ignore return ssk block stored block node fetch key false if stored block null stored block equals block try request handler sendssk stored block get raw headers stored block get raw data false pub key source uid this catch not connected exception e1 if logminor logger minor this lost connection to source on uid return catch waited too long exception e1 logger error this took too long to send ssk datareply to uid because of throttling return block stored block if logminor logger minor this got block for key for uid if htl 0 message msg dmt createfnp insert reply uid try source send sync msg this catch not connected exception e ignore can commit true finish ssk insert sender success return if htl 0 sender node make insert sender block htl uid source false true boolean received rejected overload false while true synchronized sender try if sender get status ssk insert sender not finished sender wait 5000 catch interrupted exception e ignore if received rejected overload sender received rejected overload received rejected overload true forward it message m dmt createfnp rejected overload uid false try source send sync m this catch not connected exception e if logminor logger minor this lost connection to source return if sender has recently collided forward collision data sender get data headers sender get headers try block new ssk block data headers key true catch ssk verify exception e1 is verified elsewhere throw new error impossible e1 e1 try request handler sendssk headers data false pub key source uid this catch not connected exception e1 if logminor logger minor this lost connection to source on uid return catch waited too long exception e1 logger error this took too long to send ssk datareply to uid because of bwlimiting return int status sender get status if status ssk insert sender not finished continue local rejected overload s fatal internal error counts as overload it d only create a timeout otherwise which is the same thing anyway we really need a good way to deal with nodes that constantly r o if status ssk insert sender timed out status ssk insert sender generated rejected overload status ssk insert sender internal error message msg dmt createfnp rejected overload uid true try source send sync msg this catch not connected exception e if logminor logger minor this lost connection to source return might as well store it anyway if status ssk insert sender timed out status ssk insert sender generated rejected overload can commit true finish status return if status ssk insert sender route not found status ssk insert sender route really not found message msg dmt createfnp route not found uid sender gethtl try source send sync msg this catch not connected exception e if logminor logger minor this lost connection to source return can commit true finish status return if status ssk insert sender success message msg dmt createfnp insert reply uid try source send sync msg this catch not connected exception e if logminor logger minor this lost connection to source return can commit true finish status return otherwise logger error this unknown status code sender get status string message msg dmt createfnp rejected overload uid true try source send sync msg this catch not connected exception e ignore finish status return realrun createfnpsskaccepted pubkey sendasync notconnectedexception messagefilter messagefilter settype fnpsskinsertrequestheaders setfield setsource settimeout data_insert_timeout waitfor fnpsskinsertrequestheaders shortbuffer getobject block_headers getdata disconnectedexception messagefilter messagefilter settype fnpsskinsertrequestdata setfield setsource settimeout data_insert_timeout waitfor fnpsskinsertrequestdata shortbuffer getobject getdata disconnectedexception pubkey messagefilter messagefilter settype fnpsskpubkey setfield setsource settimeout pubkey_timeout waitfor fnpsskpubkey pubkeyasbytes shortbuffer getobject pubkey_as_bytes getdata pubkey dsapublickey pubkeyasbytes pubkey createfnpsskpubkeyaccepted sendasync notconnectedexception cryptformatexception createfnpdatainsertrejected data_insert_rejected_ssk_error sendsync notconnectedexception disconnectedexception setpubkey pubkey sskblock sskverifyexception createfnpdatainsertrejected data_insert_rejected_ssk_error sendsync notconnectedexception sskblock storedblock storedblock storedblock requesthandler storedblock getrawheaders storedblock getrawdata pubkey notconnectedexception waitedtoolongexception storedblock createfnpinsertreply sendsync notconnectedexception cancommit sskinsertsender makeinsertsender receivedrejectedoverload getstatus sskinsertsender not_finished interruptedexception receivedrejectedoverload receivedrejectedoverload receivedrejectedoverload createfnprejectedoverload sendsync notconnectedexception hasrecentlycollided getdata getheaders sskblock sskverifyexception requesthandler pubkey notconnectedexception waitedtoolongexception getstatus sskinsertsender not_finished rejectedoverload r_o sskinsertsender timed_out sskinsertsender generated_rejected_overload sskinsertsender internal_error createfnprejectedoverload sendsync notconnectedexception sskinsertsender timed_out sskinsertsender generated_rejected_overload cancommit sskinsertsender route_not_found sskinsertsender route_really_not_found createfnproutenotfound sendsync notconnectedexception cancommit sskinsertsender createfnpinsertreply sendsync notconnectedexception cancommit getstatusstring createfnprejectedoverload sendsync notconnectedexception if can commit and we have received all the data and it verifies then commit it private void finish int code if logminor logger minor this finishing if can commit try node store block block get key to normalized double catch key collision exception e logger normal this collision on this if code ssk insert sender timed out code ssk insert sender generated rejected overload code ssk insert sender internal error code ssk insert sender route really not found int total sent get total sent bytes int total received get total received bytes if sender null total sent sender get total sent bytes total received sender get total received bytes if logminor logger minor this remote ssk insert cost total sent total received bytes code node node stats remote ssk insert bytes sent average report total sent node node stats remote ssk insert bytes received average report total received if code ssk insert sender success can report both sides node node stats successful ssk insert bytes sent average report total sent node node stats successful ssk insert bytes received average report total received cancommit cancommit getkey tonormalizeddouble keycollisionexception sskinsertsender timed_out sskinsertsender generated_rejected_overload sskinsertsender internal_error sskinsertsender route_really_not_found totalsent gettotalsentbytes totalreceived gettotalreceivedbytes totalsent gettotalsentbytes totalreceived gettotalreceivedbytes totalsent totalreceived nodestats remotesskinsertbytessentaverage totalsent nodestats remotesskinsertbytesreceivedaverage totalreceived sskinsertsender nodestats successfulsskinsertbytessentaverage totalsent nodestats successfulsskinsertbytesreceivedaverage totalreceived public void sent bytes int x synchronized total bytes sync total bytes sent x node node stats insert sent bytes true x sentbytes totalbytessync totalbytessent nodestats insertsentbytes public void received bytes int x synchronized total bytes sync total bytes received x node node stats insert received bytes true x receivedbytes totalbytessync totalbytesreceived nodestats insertreceivedbytes public int get total sent bytes return total bytes sent gettotalsentbytes totalbytessent public int get total received bytes return total bytes received gettotalreceivedbytes totalbytesreceived public void sent payload int x node sent payload x node node stats insert sent bytes true x sentpayload sentpayload nodestats insertsentbytes public int get priority return native thread high priority getpriority nativethread high_priority construct a feedback filter public feedback filter feedbackfilter feedbackfilter construct a feedback filter param distance the distance to move on each iteration param angle the angle to move on each iteration param rotation the amount to rotate on each iteration param zoom the amount to scale on each iteration public feedback filter float distance float angle float rotation float zoom this distance distance this angle angle this rotation rotation this zoom zoom feedbackfilter feedbackfilter specifies the angle of each iteration param angle the angle of each iteration angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of each iteration return the angle of each iteration see set angle public float get angle return angle setangle getangle specifies the distance to move on each iteration param distance the distance see get distance public void set distance float distance this distance distance getdistance setdistance get the distance to move on each iteration return the distance see set distance public float get distance return distance setdistance getdistance specifies the amount of rotation on each iteration param rotation the angle of rotation angle see get rotation public void set rotation float rotation this rotation rotation getrotation setrotation returns the amount of rotation on each iteration return the angle of rotation angle see set rotation public float get rotation return rotation setrotation getrotation specifies the amount to scale on each iteration param zoom the zoom factor see get zoom public void set zoom float zoom this zoom zoom getzoom setzoom returns the amount to scale on each iteration return the zoom factor see set zoom public float get zoom return zoom setzoom getzoom set the alpha value at the first iteration param start alpha the alpha value min value 0 max value 1 see get start alpha public void set start alpha float start alpha this start alpha start alpha startalpha getstartalpha setstartalpha startalpha startalpha startalpha get the alpha value at the first iteration return the alpha value see set start alpha public float get start alpha return start alpha setstartalpha getstartalpha startalpha set the alpha value at the last iteration param end alpha the alpha value min value 0 max value 1 see get end alpha public void set end alpha float end alpha this end alpha end alpha endalpha getendalpha setendalpha endalpha endalpha endalpha get the alpha value at the last iteration return the alpha value see set end alpha public float get end alpha return end alpha setendalpha getendalpha endalpha set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre set the number of iterations param iterations the number of iterations min value 0 see get iterations public void set iterations int iterations this iterations iterations getiterations setiterations get the number of iterations return the number of iterations see set iterations public int get iterations return iterations setiterations getiterations public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null float cx float src get width centrex float cy float src get height centrey float image radius float math sqrt cx cx cy cy float translatex float distance math cos angle float translatey float distance math sin angle float scale float math exp zoom float rotate rotation if iterations 0 graphics2d g dst create graphics g draw rendered image src null g dispose return dst graphics2d g dst create graphics g draw image src null null for int i 0 i iterations i g set rendering hint rendering hints key antialiasing rendering hints value antialias on g set rendering hint rendering hints key interpolation rendering hints value interpolation bilinear g set composite alpha composite get instance alpha composite src over image math lerp float i iterations 1 start alpha end alpha g translate cx translatex cy translatey g scale scale scale the 0001 works round a bug on windows where draw image throws an array index outof bound exception if rotation 0 g rotate rotate g translate cx cy g draw image src null null g dispose return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage getwidth getheight imageradius creategraphics drawrenderedimage creategraphics drawimage setrenderinghint renderinghints key_antialiasing renderinghints value_antialias_on setrenderinghint renderinghints key_interpolation renderinghints value_interpolation_bilinear setcomposite alphacomposite getinstance alphacomposite src_over imagemath startalpha endalpha drawimage arrayindexoutofboundexception drawimage override public string to string return effects feedback tostring public testnet handler node node2 int testnet port this node node2 this testnet port testnet port logger error this starting testnet server logger error this anonymity mode off system err println starting testnet server system err println anonymity mode off system err println you have no anonymity thank you for running a testnet node this will help the developers to efficiently debug freenet by letting them and anyone else who knows how automatically fetch your log files system err println we repeat you have no anonymity whatsoever do not post anything you do not want to be associated with system err println if you want a real freenet node with anonymity turn off testnet mode system err println note this node will not connect to non testnet nodes for security reasons you can of course run a testnet node and a non testnet node separately uploader new testnet status uploader node 180000 testnethandler testnetport testnetport testnetport testnetstatusuploader public void start node executor execute this testnet handler thread uploader start system err println started testnet handler on port testnet port testnetport public void run freenet support logger os thread logpid this while true set up server socket try server new server socket testnet port logger normal this starting testnet server on port testnet port catch io exception e logger error this could not bind to testnet port testnet port node exit node init exception exit testnet failed return while server is closed try socket s server accept new testnet socket handler s start catch io exception e logger error this testnet failed to accept socket e e logger normal this testnet handler has been stopped restarting osthread serversocket testnetport testnetport ioexception testnetport nodeinitexception exit_testnet_failed isclosed testnetsockethandler ioexception public void rebind int port synchronized server try if server is closed server is bound server close this testnet port port catch io exception e logger error this error while stopping the testnet handler node exit node init exception exit testnet failed return isclosed isbound testnetport ioexception nodeinitexception exit_testnet_failed public int get port return testnet port getport testnetport private socket s public testnet socket handler socket s2 this s s2 testnetsockethandler void start node executor execute this testnet handler for s get inet address at system current time millis getinetaddress currenttimemillis public void run freenet support logger os thread logpid this boolean logminor logger should log logger minor this input stream is null output stream os null try is s get input stream os s get output stream read command input stream reader isr new input stream reader is iso 8859 1 buffered reader br new buffered reader isr string command br read line if command null return if logminor logger minor this command command file logger hook logger hook logger hook node log config handler get file logger hook if logger hook null logger error this could not serve testnet command because no file logger hook output stream writer osw new output stream writer os osw write error could not serve testnet command because no file logger hook return if command equals ignore case list if logminor logger minor this listing available logs output stream writer osw new output stream writer os iso 8859 1 logger hook list available logs osw osw close else if command starts with get if logminor logger minor this sending log command string date command substring get length date format df date format get date time instance date format short date format short locale english df set time zone time zone get time zone gmt date d try d df parse date catch parse exception e if logminor logger minor this cannot parse e for date return logger hook send log by contained date d get time os else if command equals ignore case status if logminor logger minor this sending status output stream writer osw new output stream writer os iso 8859 1 osw write node get status osw close else if command equals ignore case peers if logminor logger minor this sending references output stream writer osw new output stream writer os iso 8859 1 buffered writer bw new buffered writer osw bw write my darknet ref n n simple field set fs node export darknet public field set fs write to bw if node is opennet enabled bw write my opennet ref n n fs node export opennet public field set fs write to bw bw write n n my peers n bw write node peers get darknet peers string to string bw close else logger error this unknown testnet command command catch io exception e logger normal this failure handling testnet connection e finally if is null try is close catch io exception e ignore if os null try os close catch io exception e ignore osthread shouldlog inputstream outputstream getinputstream getoutputstream inputstreamreader inputstreamreader bufferedreader bufferedreader readline fileloggerhook loggerhook loggerhook logconfighandler getfileloggerhook loggerhook fileloggerhook outputstreamwriter outputstreamwriter fileloggerhook equalsignorecase outputstreamwriter outputstreamwriter loggerhook listavailablelogs startswith dateformat dateformat getdatetimeinstance dateformat dateformat settimezone timezone gettimezone parseexception loggerhook sendlogbycontaineddate gettime equalsignorecase outputstreamwriter outputstreamwriter getstatus equalsignorecase outputstreamwriter outputstreamwriter bufferedwriter bufferedwriter simplefieldset exportdarknetpublicfieldset writeto isopennetenabled exportopennetpublicfieldset writeto nmy getdarknetpeersstring tostring ioexception ioexception ioexception final node node testnet enabled callback node node this node node testnetenabledcallback override public boolean get return node testnet enabled testnetenabled override public void set boolean val throws invalid config value exception if node testnet enabled val return throw new invalid config value exception l10n get string testnet handler cannot enable disable on the fly invalidconfigvalueexception testnetenabled invalidconfigvalueexception getstring testnethandler cannotenabledisableonthefly override public boolean is read only return true isreadonly node node testnet port number callback node n this node n testnetportnumbercallback override public integer get return node testnet handler get port testnethandler getport override public void set integer val throws invalid config value exception if get equals val return node testnet handler rebind val invalidconfigvalueexception testnethandler public static testnet handler maybe create node node config config throws node init exception sub config testnet config new sub config node testnet config testnet config register enabled false 1 true switch it to false if we want large scale testing true testnet handler enable testnet handler enable long new testnet enabled callback node boolean enabled testnet config get boolean enabled if enabled get the testnet port testnet config register port node get darknet port number 1000 2 true false testnet handler port testnet handler port long new testnet port number callback node false int port testnet config get int port testnet config finished initialization return new testnet handler node port else testnet config finished initialization return null testnethandler maybecreate nodeinitexception subconfig testnetconfig subconfig testnetconfig testnethandler testnethandler enablelong testnetenabledcallback testnetconfig getboolean testnetconfig getdarknetportnumber testnethandler testnethandler portlong testnetportnumbercallback testnetconfig getint testnetconfig finishedinitialization testnethandler testnetconfig finishedinitialization public final static node create envelope body node envelope node env node new node soap xmlns soap delim soap envelope env node set attribute xmlns soap delim soap xmlns soap xmlns url env node set attribute soap xmlns soap delim encoding style soap encstyle url body node body node new node soap xmlns soap delim soap body env node add node body node return env node createenvelopebodynode envnode envnode setattribute xmlns_url envnode setattribute encodingstyle encstyle_url bodynode envnode addnode bodynode envnode private static parser xml parser public final static void setxml parser parser parser xml parser parser xmlparser setxmlparser xmlparser public final static parser getxml parser return xml parser getxmlparser xmlparser public int message count st message count string message name int message count this message name message name this message count message count messagecount stmessagecount messagename messagecount messagename messagename messagecount messagecount protected statistics toadlet node n node client core core high level simple client client super client this node n this core core stats node node stats peers node peers statisticstoadlet nodeclientcore highlevelsimpleclient nodestats override public string supported methods return get supportedmethods counts the peers in code peer nodes code that have the specified status param peer node statuses the peer nodes statuses param status the status to count return the number of peers that have the specified status private int get peer status count peer node status peer node statuses int status int count 0 for int peer index 0 peer count peer node statuses length peer index peer count peer index if peer node statuses peer index record status continue if peer node statuses peer index get status value status count return count peernodes peernodestatuses getpeerstatuscount peernodestatus peernodestatuses peerindex peercount peernodestatuses peerindex peercount peerindex peernodestatuses peerindex recordstatus peernodestatuses peerindex getstatusvalue private int get count seed servers peer node status peer node statuses int count 0 for int peer index 0 peer index peer node statuses length peer index if peer node statuses peer index is seed server count return count getcountseedservers peernodestatus peernodestatuses peerindex peerindex peernodestatuses peerindex peernodestatuses peerindex isseedserver private int get count seed clients peer node status peer node statuses int count 0 for int peer index 0 peer index peer node statuses length peer index if peer node statuses peer index is seed client count return count getcountseedclients peernodestatus peernodestatuses peerindex peerindex peernodestatuses peerindex peernodestatuses peerindex isseedclient override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return final sub config node config node config get node gather connection statistics peer node status peer node statuses peers get peer node statuses true arrays sort peer node statuses new comparator peer node status public int compare peer node status first node peer node status second node int status difference first node get status value second node get status value if status difference 0 return status difference return 0 int number of connected get peer status count peer node statuses peer manager peer node status connected int number of routing backed off get peer status count peer node statuses peer manager peer node status routing backed off int number of too new get peer status count peer node statuses peer manager peer node status too new int number of too old get peer status count peer node statuses peer manager peer node status too old int number of disconnected get peer status count peer node statuses peer manager peer node status disconnected int number of never connected get peer status count peer node statuses peer manager peer node status never connected int number of disabled get peer status count peer node statuses peer manager peer node status disabled int number of bursting get peer status count peer node statuses peer manager peer node status bursting int number of listening get peer status count peer node statuses peer manager peer node status listening int number of listen only get peer status count peer node statuses peer manager peer node status listen only int number of seed servers get count seed servers peer node statuses int number of seed clients get count seed clients peer node statuses int number of routing disabled get peer status count peer node statuses peer manager peer node status routing disabled int number of clock problem get peer status count peer node statuses peer manager peer node status clock problem int number of conn error get peer status count peer node statuses peer manager peer node status conn error int number of disconnecting peer node status get peer status count peer node statuses peer manager peer node status disconnecting html node page node ctx get page maker get page node l10n full title new string name new string node get my name ctx html node content node ctx get page maker get content node page node fixme we need some nice images final long now system current time millis double my location node get location final long node uptime seconds now node startup time 1000 if ctx is allowed full access content node add child core alerts create summary final int mode ctx get page maker draw mode selection array core request content node double swaps node get swaps double no swaps node get no swaps html node overview table content node add child table class column html node overview table row overview table add child tr html node next table cell overview table row add child td class first node version information box html node version infobox next table cell add child div class infobox draw node version box version infobox jvm stats box html node jvm stats infobox next table cell add child div class infobox drawjvm stats box jvm stats infobox statistic gathering box html node stat gathering box next table cell add child ctx get page maker get infobox l10n statistic gathering title html node stat gathering content ctx get page maker get content node stat gathering box generate a thread dump if node is using wrapper html node thread dump form ctx add form child stat gathering content thread dump form thread dump form add child input new string type name value new string submit get thread dump l10n thread dump button bdb statistics dump html node je stats form ctx add form child stat gathering content je stats form je stats form add child input new string type name value new string submit getje stats dump l10n je dump button get logs html node logs list stat gathering content add child ul if node config config get logger get boolean enabled logs list add child li add child a new string href target new string latestlog blank l10n get logs logs list add child li add child a href translation toadlet toadlet url get override tranlation file add child l10n get string translation toadlet download translations file if mode page maker mode advanced store size box html node store size infobox next table cell add child div class infobox draw store size box store size infobox my location node uptime seconds if number of connected number of routing backed off 0 load balancing box include overall window and rt ts for each request starter group starters core request starters double window starters get window double real window starters get real window html node load stats infobox next table cell add child div class infobox load stats infobox add child div class infobox header load limiting html node load stats content load stats infobox add child div class infobox content html node load stats list load stats content add child ul load stats list add child li global window window load stats list add child li real global window real window load stats list add child li starters stats page line false false load stats list add child li starters stats page line true false load stats list add child li starters stats page line false true load stats list add child li starters stats page line true true load stats list add child li starters diagnostic throttles line false load stats list add child li starters diagnostic throttles line true psuccess box html node success rate box next table cell add child div class infobox success rate box add child div class infobox header success rates html node success rate content success rate box add child div class infobox content stats fill success rate box success rate content html node time detail box next table cell add child div class infobox time detail box add child div class infobox header detailed timings local chk fetches html node timings content time detail box add child div class infobox content stats fill detailed timings box timings content if mode page maker mode advanced number of connected number of routing backed off 0 activity box next table cell overview table row add child td class last html node activity infobox next table cell add child div class infobox draw activity box activity infobox mode page maker mode advanced node status overview box if mode page maker mode advanced html node overview infobox next table cell add child div class infobox draw overview box overview infobox node uptime seconds now swaps no swaps peer statistics box html node peer stats infobox next table cell add child div class infobox draw peer stats box peer stats infobox mode page maker mode advanced number of connected number of routing backed off number of too new number of too old number of disconnected number of never connected number of disabled number of bursting number of listening number of listen only number of seed servers number of seed clients number of routing disabled number of clock problem number of conn error number of disconnecting bandwidth box html node bandwidth infobox next table cell add child div class infobox draw bandwidth box bandwidth infobox node uptime seconds mode page maker mode advanced if mode page maker mode advanced peer routing backoff reason box html node backoff reason infobox next table cell add child div class infobox backoff reason infobox add child div class infobox header peer backoff reasons html node backoff reason content backoff reason infobox add child div class infobox content string routing backoff reasons peers get peer node routing backoff reasons if routing backoff reasons length 0 backoff reason content add child good your node is not backed off from any peers else html node reason list backoff reason content add child ul for int i 0 i routing backoff reasons length i int reason count peers get peer node routing backoff reason size routing backoff reasons i if reason count 0 reason list add child li routing backoff reasons i u00a0 reason count swap statistics box html node location swap infobox next table cell add child div class infobox draw swap stats box location swap infobox my location node uptime seconds swaps no swaps unclaimedfifo message counts box html node unclaimedfifo message counts infobox next table cell add child div class infobox draw unclaimedfifo message counts box unclaimedfifo message counts infobox html node threads priority infobox next table cell add child div class infobox draw thread priority stats box threads priority infobox next table cell overview table row add child td thread usage box html node thread usage infobox next table cell add child div class infobox thread usage infobox add child div class infobox header thread usage html node thread usag handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring subconfig nodeconfig peernodestatus peernodestatuses getpeernodestatuses peernodestatuses peernodestatus peernodestatus firstnode peernodestatus secondnode statusdifference firstnode getstatusvalue secondnode getstatusvalue statusdifference statusdifference numberofconnected getpeerstatuscount peernodestatuses peermanager peer_node_status_connected numberofroutingbackedoff getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_backed_off numberoftoonew getpeerstatuscount peernodestatuses peermanager peer_node_status_too_new numberoftooold getpeerstatuscount peernodestatuses peermanager peer_node_status_too_old numberofdisconnected getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnected numberofneverconnected getpeerstatuscount peernodestatuses peermanager peer_node_status_never_connected numberofdisabled getpeerstatuscount peernodestatuses peermanager peer_node_status_disabled numberofbursting getpeerstatuscount peernodestatuses peermanager peer_node_status_bursting numberoflistening getpeerstatuscount peernodestatuses peermanager peer_node_status_listening numberoflistenonly getpeerstatuscount peernodestatuses peermanager peer_node_status_listen_only numberofseedservers getcountseedservers peernodestatuses numberofseedclients getcountseedclients peernodestatuses numberofroutingdisabled getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_disabled numberofclockproblem getpeerstatuscount peernodestatuses peermanager peer_node_status_clock_problem numberofconnerror getpeerstatuscount peernodestatuses peermanager peer_node_status_conn_error numberofdisconnecting peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnecting htmlnode pagenode getpagemaker getpagenode fulltitle getmyname htmlnode contentnode getpagemaker getcontentnode pagenode currenttimemillis mylocation getlocation nodeuptimeseconds startuptime isallowedfullaccess contentnode addchild createsummary getpagemaker drawmodeselectionarray contentnode getswaps noswaps getnoswaps htmlnode overviewtable contentnode addchild htmlnode overviewtablerow overviewtable addchild htmlnode nexttablecell overviewtablerow addchild htmlnode versioninfobox nexttablecell addchild drawnodeversionbox versioninfobox htmlnode jvmstatsinfobox nexttablecell addchild drawjvmstatsbox jvmstatsinfobox htmlnode statgatheringbox nexttablecell addchild getpagemaker getinfobox statisticgatheringtitle htmlnode statgatheringcontent getpagemaker getcontentnode statgatheringbox isusingwrapper htmlnode threaddumpform addformchild statgatheringcontent threaddumpform threaddumpform addchild getthreaddump threaddumpbutton htmlnode jestatsform addformchild statgatheringcontent jestatsform jestatsform addchild getjestatsdump jedumpbutton htmlnode logslist statgatheringcontent addchild nodeconfig getboolean logslist addchild addchild _blank getlogs logslist addchild addchild translationtoadlet toadlet_url getoverridetranlationfile addchild getstring translationtoadlet downloadtranslationsfile pagemaker mode_advanced htmlnode storesizeinfobox nexttablecell addchild drawstoresizebox storesizeinfobox mylocation nodeuptimeseconds numberofconnected numberofroutingbackedoff rtts requeststartergroup requeststarters getwindow realwindow getrealwindow htmlnode loadstatsinfobox nexttablecell addchild loadstatsinfobox addchild htmlnode loadstatscontent loadstatsinfobox addchild htmlnode loadstatslist loadstatscontent addchild loadstatslist addchild loadstatslist addchild realwindow loadstatslist addchild statspageline loadstatslist addchild statspageline loadstatslist addchild statspageline loadstatslist addchild statspageline loadstatslist addchild diagnosticthrottlesline loadstatslist addchild diagnosticthrottlesline htmlnode successratebox nexttablecell addchild successratebox addchild htmlnode successratecontent successratebox addchild fillsuccessratebox successratecontent htmlnode timedetailbox nexttablecell addchild timedetailbox addchild htmlnode timingscontent timedetailbox addchild filldetailedtimingsbox timingscontent pagemaker mode_advanced numberofconnected numberofroutingbackedoff nexttablecell overviewtablerow addchild htmlnode activityinfobox nexttablecell addchild drawactivitybox activityinfobox pagemaker mode_advanced pagemaker mode_advanced htmlnode overviewinfobox nexttablecell addchild drawoverviewbox overviewinfobox nodeuptimeseconds noswaps htmlnode peerstatsinfobox nexttablecell addchild drawpeerstatsbox peerstatsinfobox pagemaker mode_advanced numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofseedservers numberofseedclients numberofroutingdisabled numberofclockproblem numberofconnerror numberofdisconnecting htmlnode bandwidthinfobox nexttablecell addchild drawbandwidthbox bandwidthinfobox nodeuptimeseconds pagemaker mode_advanced pagemaker mode_advanced htmlnode backoffreasoninfobox nexttablecell addchild backoffreasoninfobox addchild htmlnode backoffreasoncontent backoffreasoninfobox addchild routingbackoffreasons getpeernoderoutingbackoffreasons routingbackoffreasons backoffreasoncontent addchild htmlnode reasonlist backoffreasoncontent addchild routingbackoffreasons reasoncount getpeernoderoutingbackoffreasonsize routingbackoffreasons reasoncount reasonlist addchild routingbackoffreasons reasoncount htmlnode locationswapinfobox nexttablecell addchild drawswapstatsbox locationswapinfobox mylocation nodeuptimeseconds noswaps unclaimedfifomessagecounts htmlnode unclaimedfifomessagecountsinfobox nexttablecell addchild drawunclaimedfifomessagecountsbox unclaimedfifomessagecountsinfobox htmlnode threadspriorityinfobox nexttablecell addchild drawthreadprioritystatsbox threadspriorityinfobox nexttablecell overviewtablerow addchild htmlnode threadusageinfobox nexttablecell addchild threadusageinfobox addchild htmlnode threadusag arrays sort peer node statuses new comparator peer node status public int compare peer node status first node peer node status second node int status difference first node get status value second node get status value if status difference 0 return status difference return 0 peernodestatuses peernodestatus peernodestatus firstnode peernodestatus secondnode statusdifference firstnode getstatusvalue secondnode getstatusvalue statusdifference statusdifference private void draw reject reasons box html node next table cell boolean local html node reject reasons table new html node table node stats stats node node stats boolean success local stats get local reject reasons table reject reasons table stats get reject reasons table reject reasons table if success return html node reject reasons infobox next table cell add child div class infobox reject reasons infobox add child div class infobox header local local preemptive rejection reasons reject reasons infobox add child div class infobox content add child reject reasons table drawrejectreasonsbox htmlnode nexttablecell htmlnode rejectreasonstable htmlnode nodestats nodestats getlocalrejectreasonstable rejectreasonstable getrejectreasonstable rejectreasonstable htmlnode rejectreasonsinfobox nexttablecell addchild rejectreasonsinfobox addchild rejectreasonsinfobox addchild addchild rejectreasonstable private void draw node version box html node version infobox version infobox add child div class infobox header l10n version title html node version infobox content version infobox add child div class infobox content html node version infobox list version infobox content add child ul version infobox list add child li l10n get string welcome toadlet version new string full version build rev new string version node version integer to string version build number version cvs revision if node starter ext build number node starter recommended ext build number version infobox list add child li l10n get string welcome toadlet ext version with recommended new string build recbuild rev new string integer to string node starter ext build number integer to string node starter recommended ext build number node starter ext revision number else version infobox list add child li l10n get string welcome toadlet ext version new string build rev new string integer to string node starter ext build number node starter ext revision number drawnodeversionbox htmlnode versioninfobox versioninfobox addchild versiontitle htmlnode versioninfoboxcontent versioninfobox addchild htmlnode versioninfoboxlist versioninfoboxcontent addchild versioninfoboxlist addchild getstring welcometoadlet fullversion nodeversion tostring buildnumber cvsrevision nodestarter extbuildnumber nodestarter recommended_ext_build_number versioninfoboxlist addchild getstring welcometoadlet extversionwithrecommended tostring nodestarter extbuildnumber tostring nodestarter recommended_ext_build_number nodestarter extrevisionnumber versioninfoboxlist addchild getstring welcometoadlet extversion tostring nodestarter extbuildnumber nodestarter extrevisionnumber private void drawjvm stats box html node jvm stats infobox jvm stats infobox add child div class infobox header l10n jvm info title html node jvm stats infobox content jvm stats infobox add child div class infobox content html node jvm stats list jvm stats infobox content add child ul runtime rt runtime get runtime long free memory rt free memory long total memory rt total memory long max memory rt max memory long used java mem total memory free memory long allocated java mem total memory long max java mem max memory int available cpus rt available processors int thread count stats get active thread count jvm stats list add child li l10n used memory memory size util format size used java mem true jvm stats list add child li l10n alloc memory memory size util format size allocated java mem true jvm stats list add child li l10n max memory memory size util format size max java mem true jvm stats list add child li l10n threads new string running max new string thousend point format thread count integer to string stats get thread limit jvm stats list add child li l10n cpus count integer to string available cpus jvm stats list add child li l10n java version version system get property java version jvm stats list add child li l10n jvm vendor vendor system get property java vendor jvm stats list add child li l10n jvm version version system get property java vm version jvm stats list add child li l10n os name name system get property os name jvm stats list add child li l10n os version version system get property os version jvm stats list add child li l10n os arch arch system get property os arch drawjvmstatsbox htmlnode jvmstatsinfobox jvmstatsinfobox addchild jvminfotitle htmlnode jvmstatsinfoboxcontent jvmstatsinfobox addchild htmlnode jvmstatslist jvmstatsinfoboxcontent addchild getruntime freememory freememory totalmemory totalmemory maxmemory maxmemory usedjavamem totalmemory freememory allocatedjavamem totalmemory maxjavamem maxmemory availablecpus availableprocessors threadcount getactivethreadcount jvmstatslist addchild usedmemory sizeutil formatsize usedjavamem jvmstatslist addchild allocmemory sizeutil formatsize allocatedjavamem jvmstatslist addchild maxmemory sizeutil formatsize maxjavamem jvmstatslist addchild thousendpoint threadcount tostring getthreadlimit jvmstatslist addchild tostring availablecpus jvmstatslist addchild javaversion getproperty jvmstatslist addchild jvmvendor getproperty jvmstatslist addchild jvmversion getproperty jvmstatslist addchild osname getproperty jvmstatslist addchild osversion getproperty jvmstatslist addchild osarch getproperty private void draw thread priority stats box html node node node add child div class infobox header l10n threads by priority html node threads infobox content node add child div class infobox content int active threads by priority stats get active threads by priority int waiting threads by priority stats get waiting threads by priority html node threads by priority table threads infobox content add child table border 0 html node row threads by priority table add child tr row add child th l10n priority row add child th l10n running row add child th l10n waiting for int i 0 i active threads by priority length i row threads by priority table add child tr row add child td string value of i 1 row add child td string value of active threads by priority i row add child td string value of waiting threads by priority i drawthreadprioritystatsbox htmlnode addchild threadsbypriority htmlnode threadsinfoboxcontent addchild activethreadsbypriority getactivethreadsbypriority waitingthreadsbypriority getwaitingthreadsbypriority htmlnode threadsbyprioritytable threadsinfoboxcontent addchild htmlnode threadsbyprioritytable addchild addchild addchild addchild activethreadsbypriority threadsbyprioritytable addchild addchild valueof addchild valueof activethreadsbypriority addchild valueof waitingthreadsbypriority private void draw database jobs box html node node node add child div class infobox header l10n database jobs by priority html node threads infobox content node add child div class infobox content int jobs by priority core client database executor queued jobs html node threads by priority table threads infobox content add child table border 0 html node row threads by priority table add child tr row add child th l10n priority row add child th l10n waiting for int i 0 i jobs by priority length i row threads by priority table add child tr row add child td string value of i row add child td string value of jobs by priority i drawdatabasejobsbox htmlnode addchild databasejobsbypriority htmlnode threadsinfoboxcontent addchild jobsbypriority clientdatabaseexecutor queuedjobs htmlnode threadsbyprioritytable threadsinfoboxcontent addchild htmlnode threadsbyprioritytable addchild addchild addchild jobsbypriority threadsbyprioritytable addchild addchild valueof addchild valueof jobsbypriority private void draw store size box html node store size infobox double loc long node uptime seconds store size infobox add child div class infobox header datastore html node store size infobox content store size infobox add child div class infobox content html node store size table store size infobox content add child table border 0 html node row store size table add child tr fixme non breaking space stat name row add child th row add child th store row add child th cache final long fix32kb 32 1024 long cached keys node get chk datacache key count long cached size cached keys fix32kb long store keys node get chk datastore key count long store size store keys fix32kb long max cached keys node get chk datacache get max keys long max store keys node get chk datastore get max keys long cache hits node get chk datacache hits long cache misses node get chk datacache misses long cache accesses cache hits cache misses long store hits node get chk datastore hits long store misses node get chk datastore misses long store accesses store hits store misses long cache writes node get chk datacache writes long store writes node get chk datastore writes long cache false pos node get chk datacache get bloom false positive long store false pos node get chk datastore get bloom false positive redflag don t show database version because it s not possible to get it accurately it s a public static constant so it will use the version from compile time of freenet jar row store size table add child tr row add child td keys row add child td thousend point format store keys row add child td thousend point format cached keys row store size table add child tr row add child td capacity row add child td thousend point format max store keys row add child td thousend point format max cached keys row store size table add child tr row add child td data size row add child td size util format size store size true row add child td size util format size cached size true row store size table add child tr row add child td utilization row add child td fix3p1pct format 1 0 store keys max store keys row add child td fix3p1pct format 1 0 cached keys max cached keys row store size table add child tr row add child td read requests row add child td thousend point format store accesses row add child td thousend point format cache accesses row store size table add child tr row add child td successful reads if store accesses 0 row add child td thousend point format store hits else row add child td 0 if cache accesses 0 row add child td thousend point format cache hits else row add child td 0 row store size table add child tr row add child td success rate if store accesses 0 row add child td fix1p4 format 100 0 store hits store accesses else row add child td n a if cache accesses 0 row add child td fix1p4 format 100 0 cache hits cache accesses else row add child td n a row store size table add child tr row add child td writes row add child td thousend point format store writes row add child td thousend point format cache writes overall utilization is not preserved in the new table layout store size list add child li overall size u00a0 thousend point format overall keys u00a0 u00a0 thousend point format max overall keys u00a0 size util format size overall size true u00a0 u00a0 size util format size max overall size true u00a0 overall keys 100 max overall keys row store size table add child tr row add child td access rate row add child td fix1p2 format 1 0 store accesses node uptime seconds sec row add child td fix1p2 format 1 0 cache accesses node uptime seconds sec row store size table add child tr row add child td write rate row add child td fix1p2 format 1 0 store writes node uptime seconds sec row add child td fix1p2 format 1 0 cache writes node uptime seconds sec if store false pos 1 cache false pos 1 row store size table add child tr row add child td false pos row add child td thousend point format store false pos row add child td thousend point format cache false pos location based stats double node loc 0 0 double avg cache location node node stats avg cache location current value double avg store location node node stats avg store location current value double avg cache success node node stats avg cache success current value double avg store success node node stats avg store success current value double furthest cache success node node stats furthest cache success double furthest store success node node stats furthest store success double store dist location distance node loc avg store location double cache dist location distance node loc avg cache location row store size table add child tr row add child td avg location row add child td fix1p4 format avg store location row add child td fix1p4 format avg cache location row store size table add child tr row add child td avg success loc row add child td fix1p4 format avg store success row add child td fix1p4 format avg cache success row store size table add child tr row add child td furthest success row add child td fix1p4 format furthest store success row add child td fix1p4 format furthest cache success row store size table add child tr row add child td avg distance row add child td fix1p4 format store dist row add child td fix1p4 format cache dist long cache location reports node node stats avg cache location count reports long store location reports node node stats avg store location count reports double store percent 1 0 store location reports store keys double cache percent 1 0 cache location reports cached keys cap the reported value at 100 as the decaying average does not account beyond that anyway if store percent 1 0 store percent 1 0 if cache percent 1 0 cache percent 1 0 row store size table add child tr row add child td distance stats row add child td fix3p1pct format store percent row add child td fix3p1pct format cache percent drawstoresizebox htmlnode storesizeinfobox nodeuptimeseconds storesizeinfobox addchild htmlnode storesizeinfoboxcontent storesizeinfobox addchild htmlnode storesizetable storesizeinfoboxcontent addchild htmlnode storesizetable addchild addchild addchild addchild cachedkeys getchkdatacache keycount cachedsize cachedkeys storekeys getchkdatastore keycount storesize storekeys maxcachedkeys getchkdatacache getmaxkeys maxstorekeys getchkdatastore getmaxkeys cachehits getchkdatacache cachemisses getchkdatacache cacheaccesses cachehits cachemisses storehits getchkdatastore storemisses getchkdatastore storeaccesses storehits storemisses cachewrites getchkdatacache storewrites getchkdatastore cachefalsepos getchkdatacache getbloomfalsepositive storefalsepos getchkdatastore getbloomfalsepositive storesizetable addchild addchild addchild thousendpoint storekeys addchild thousendpoint cachedkeys storesizetable addchild addchild addchild thousendpoint maxstorekeys addchild thousendpoint maxcachedkeys storesizetable addchild addchild addchild sizeutil formatsize storesize addchild sizeutil formatsize cachedsize storesizetable addchild addchild addchild storekeys maxstorekeys addchild cachedkeys maxcachedkeys storesizetable addchild addchild addchild thousendpoint storeaccesses addchild thousendpoint cacheaccesses storesizetable addchild addchild storeaccesses addchild thousendpoint storehits addchild cacheaccesses addchild thousendpoint cachehits addchild storesizetable addchild addchild storeaccesses addchild storehits storeaccesses addchild cacheaccesses addchild cachehits cacheaccesses addchild storesizetable addchild addchild addchild thousendpoint storewrites addchild thousendpoint cachewrites storesizelist addchild thousendpoint overallkeys thousendpoint maxoverallkeys sizeutil formatsize overallsize sizeutil formatsize maxoverallsize overallkeys maxoverallkeys storesizetable addchild addchild addchild storeaccesses nodeuptimeseconds addchild cacheaccesses nodeuptimeseconds storesizetable addchild addchild addchild storewrites nodeuptimeseconds addchild cachewrites nodeuptimeseconds storefalsepos cachefalsepos storesizetable addchild addchild addchild thousendpoint storefalsepos addchild thousendpoint cachefalsepos nodeloc avgcachelocation nodestats avgcachelocation currentvalue avgstorelocation nodestats avgstorelocation currentvalue avgcachesuccess nodestats avgcachesuccess currentvalue avgstoresuccess nodestats avgstoresuccess currentvalue furthestcachesuccess nodestats furthestcachesuccess furtheststoresuccess nodestats furtheststoresuccess storedist nodeloc avgstorelocation cachedist nodeloc avgcachelocation storesizetable addchild addchild addchild avgstorelocation addchild avgcachelocation storesizetable addchild addchild addchild avgstoresuccess addchild avgcachesuccess storesizetable addchild addchild addchild furtheststoresuccess addchild furthestcachesuccess storesizetable addchild addchild addchild storedist addchild cachedist cachelocationreports nodestats avgcachelocation countreports storelocationreports nodestats avgstorelocation countreports storepercent storelocationreports storekeys cachepercent cachelocationreports cachedkeys storepercent storepercent cachepercent cachepercent storesizetable addchild addchild addchild storepercent addchild cachepercent private void draw unclaimedfifo message counts box html node unclaimedfifo message counts infobox unclaimedfifo message counts infobox add child div class infobox header unclaimedfifo message counts html node unclaimedfifo message counts infobox content unclaimedfifo message counts infobox add child div class infobox content html node unclaimedfifo message counts list unclaimedfifo message counts infobox content add child ul map string integer unclaimedfifo message counts map node getusm get unclaimedfifo message counts st message count unclaimedfifo message counts array new st message count unclaimedfifo message counts map size int i 0 int total count 0 for map entry string integer e unclaimedfifo message counts map entry set string message name e get key int message count e get value total count total count message count unclaimedfifo message counts array i new st message count message name message count arrays sort unclaimedfifo message counts array new comparator st message count public int compare st message count first count st message count second count return second count message count first count message count sort in descending order for int counts array index 0 counts array count unclaimedfifo message counts array length counts array index counts array count counts array index st message count message count item unclaimedfifo message counts array counts array index int this message count message count item message count double this message percent of total double this message count double total count unclaimedfifo message counts list add child li message count item message name u00a0 this message count u00a0 fix3p1pct format this message percent of total unclaimedfifo message counts list add child li unclaimed messages considered u00a0 total count drawunclaimedfifomessagecountsbox htmlnode unclaimedfifomessagecountsinfobox unclaimedfifomessagecountsinfobox addchild htmlnode unclaimedfifomessagecountsinfoboxcontent unclaimedfifomessagecountsinfobox addchild htmlnode unclaimedfifomessagecountslist unclaimedfifomessagecountsinfoboxcontent addchild unclaimedfifomessagecountsmap getunclaimedfifomessagecounts stmessagecount unclaimedfifomessagecountsarray stmessagecount unclaimedfifomessagecountsmap totalcount unclaimedfifomessagecountsmap entryset messagename getkey messagecount getvalue totalcount totalcount messagecount unclaimedfifomessagecountsarray stmessagecount messagename messagecount unclaimedfifomessagecountsarray stmessagecount stmessagecount firstcount stmessagecount secondcount secondcount messagecount firstcount messagecount countsarrayindex countsarraycount unclaimedfifomessagecountsarray countsarrayindex countsarraycount countsarrayindex stmessagecount messagecountitem unclaimedfifomessagecountsarray countsarrayindex thismessagecount messagecountitem messagecount thismessagepercentoftotal thismessagecount totalcount unclaimedfifomessagecountslist addchild messagecountitem messagename thismessagecount thismessagepercentoftotal unclaimedfifomessagecountslist addchild totalcount arrays sort unclaimedfifo message counts array new comparator st message count public int compare st message count first count st message count second count return second count message count first count message count sort in descending order unclaimedfifomessagecountsarray stmessagecount stmessagecount firstcount stmessagecount secondcount secondcount messagecount firstcount messagecount private void draw swap stats box html node location swap infobox double location long node uptime seconds double swaps double no swaps location swap infobox add child div class infobox header location swaps int started swaps node get started swaps int swaps rejected already locked node get swaps rejected already locked int swaps rejected nowhere to go node get swaps rejected nowhere to go int swaps rejected rate limit node get swaps rejected rate limit int swaps rejected recognizedid node get swaps rejected recognizedid double loc change session node get location change session int average swap time node get average outgoing swap time int send swap interval node get send swap interval html node location swap infobox content location swap infobox add child div class infobox content html node location swap list location swap infobox content add child ul location swap list add child li location u00a0 location if swaps 0 0 location swap list add child li loc change session u00a0 fix1p6sci format loc change session location swap list add child li loc change per swap u00a0 fix1p6sci format loc change session swaps if swaps 0 0 node uptime seconds 60 location swap list add child li loc change per minute u00a0 fix1p6sci format loc change session node uptime seconds 60 0 if swaps 0 0 node uptime seconds 60 location swap list add child li swaps per minute u00a0 fix1p6sci format swaps node uptime seconds 60 0 if no swaps 0 0 node uptime seconds 60 location swap list add child li no swaps per minute u00a0 fix1p6sci format no swaps node uptime seconds 60 0 if swaps 0 0 no swaps 0 0 location swap list add child li swaps per no swaps u00a0 fix1p6sci format swaps no swaps if swaps 0 0 location swap list add child li swaps u00a0 int swaps if no swaps 0 0 location swap list add child li no swaps u00a0 int no swaps if started swaps 0 location swap list add child li started swaps u00a0 started swaps if swaps rejected already locked 0 location swap list add child li swaps rejected already locked u00a0 swaps rejected already locked if swaps rejected nowhere to go 0 location swap list add child li swaps rejected nowhere to go u00a0 swaps rejected nowhere to go if swaps rejected rate limit 0 location swap list add child li swaps rejected rate limit u00a0 swaps rejected rate limit if swaps rejected recognizedid 0 location swap list add child li swaps rejected recognizedid u00a0 swaps rejected recognizedid location swap list add child li average swap time u00a0 time util format time average swap time 2 true location swap list add child li send swap interval u00a0 time util format time send swap interval 2 true drawswapstatsbox htmlnode locationswapinfobox nodeuptimeseconds noswaps locationswapinfobox addchild startedswaps getstartedswaps swapsrejectedalreadylocked getswapsrejectedalreadylocked swapsrejectednowheretogo getswapsrejectednowheretogo swapsrejectedratelimit getswapsrejectedratelimit swapsrejectedrecognizedid getswapsrejectedrecognizedid locchangesession getlocationchangesession averageswaptime getaverageoutgoingswaptime sendswapinterval getsendswapinterval htmlnode locationswapinfoboxcontent locationswapinfobox addchild htmlnode locationswaplist locationswapinfoboxcontent addchild locationswaplist addchild locationswaplist addchild locchangesession locchangesession locationswaplist addchild locchangeperswap locchangesession nodeuptimeseconds locationswaplist addchild locchangeperminute locchangesession nodeuptimeseconds nodeuptimeseconds locationswaplist addchild swapsperminute nodeuptimeseconds noswaps nodeuptimeseconds locationswaplist addchild noswapsperminute noswaps nodeuptimeseconds noswaps locationswaplist addchild swapspernoswaps noswaps locationswaplist addchild noswaps locationswaplist addchild noswaps noswaps startedswaps locationswaplist addchild startedswaps startedswaps swapsrejectedalreadylocked locationswaplist addchild swapsrejectedalreadylocked swapsrejectedalreadylocked swapsrejectednowheretogo locationswaplist addchild swapsrejectednowheretogo swapsrejectednowheretogo swapsrejectedratelimit locationswaplist addchild swapsrejectedratelimit swapsrejectedratelimit swapsrejectedrecognizedid locationswaplist addchild swapsrejectedrecognizedid swapsrejectedrecognizedid locationswaplist addchild averageswaptime timeutil formattime averageswaptime locationswaplist addchild sendswapinterval timeutil formattime sendswapinterval protected static void draw peer stats box html node peer stats infobox boolean advanced mode enabled int number of connected int number of routing backed off int number of too new int number of too old int number of disconnected int number of never connected int number of disabled int number of bursting int number of listening int number of listen only int number of seed servers int number of seed clients int number of routing disabled int number of clock problem int number of conn error int number of disconnecting peer stats infobox add child div class infobox header l10n peer stats title html node peer stats content peer stats infobox add child div class infobox content html node peer stats list peer stats content add child ul if number of connected 0 html node peer stats connected list item peer stats list add child li add child span peer stats connected list item add child span new string class title style new string peer connected l10n dark connected border bottom 1px dotted cursor help l10n dark connected short peer stats connected list item add child span u00a0 number of connected if number of routing backed off 0 html node peer stats routing backed off list item peer stats list add child li add child span peer stats routing backed off list item add child span new string class title style new string peer backed off l10n dark advanced mode enabled backed off busy border bottom 1px dotted cursor help l10n dark advanced mode enabled backed off busy short peer stats routing backed off list item add child span u00a0 number of routing backed off if number of too new 0 html node peer stats too new list item peer stats list add child li add child span peer stats too new list item add child span new string class title style new string peer too new l10n dark too new border bottom 1px dotted cursor help l10n dark too new short peer stats too new list item add child span u00a0 number of too new if number of too old 0 html node peer stats too old list item peer stats list add child li add child span peer stats too old list item add child span new string class title style new string peer too old l10n dark too old border bottom 1px dotted cursor help l10n dark too old short peer stats too old list item add child span u00a0 number of too old if number of disconnected 0 html node peer stats disconnected list item peer stats list add child li add child span peer stats disconnected list item add child span new string class title style new string peer disconnected l10n dark not connected border bottom 1px dotted cursor help l10n dark not connected short peer stats disconnected list item add child span u00a0 number of disconnected if number of never connected 0 html node peer stats never connected list item peer stats list add child li add child span peer stats never connected list item add child span new string class title style new string peer never connected l10n dark never connected border bottom 1px dotted cursor help l10n dark never connected short peer stats never connected list item add child span u00a0 number of never connected if number of disabled 0 html node peer stats disabled list item peer stats list add child li add child span peer stats disabled list item add child span new string class title style new string peer disabled l10n dark disabled border bottom 1px dotted cursor help l10n dark disabled short peer stats disabled list item add child span u00a0 number of disabled if number of bursting 0 html node peer stats bursting list item peer stats list add child li add child span peer stats bursting list item add child span new string class title style new string peer bursting l10n dark bursting border bottom 1px dotted cursor help l10n dark bursting short peer stats bursting list item add child span u00a0 number of bursting if number of listening 0 html node peer stats listening list item peer stats list add child li add child span peer stats listening list item add child span new string class title style new string peer listening l10n dark listening border bottom 1px dotted cursor help l10n dark listening short peer stats listening list item add child span u00a0 number of listening if number of listen only 0 html node peer stats listen only list item peer stats list add child li add child span peer stats listen only list item add child span new string class title style new string peer listen only l10n dark listen only border bottom 1px dotted cursor help l10n dark listen only short peer stats listen only list item add child span u00a0 number of listen only if number of clock problem 0 html node peer stats routing disabled list item peer stats list add child li add child span peer stats routing disabled list item add child span new string class title style new string peer clock problem l10n dark clock problem border bottom 1px dotted cursor help l10n dark clock problem short peer stats routing disabled list item add child span u00a0 number of clock problem if number of conn error 0 html node peer stats routing disabled list item peer stats list add child li add child span peer stats routing disabled list item add child span new string class title style new string peer routing disabled l10n dark conn error border bottom 1px dotted cursor help l10n dark conn error short peer stats routing disabled list item add child span u00a0 number of clock problem if number of disconnecting 0 html node peer stats listen only list item peer stats list add child li add child span peer stats listen only list item add child span new string class title style new string peer disconnecting l10n dark disconnecting border bottom 1px dotted cursor help l10n dark disconnecting short peer stats listen only list item add child span u00a0 number of disconnecting if number of seed servers 0 html node peer stats seed servers list item peer stats list add child li add child span peer stats seed servers list item add child span new string class title style new string peer listening fixme l10n dark seed servers border bottom 1px dotted cursor help l10n dark seed servers short peer stats seed servers list item add child span u00a0 number of seed servers if number of seed clients 0 html node peer stats seed clients list item peer stats list add child li add child span peer stats seed clients list item add child span new string class title style new string peer listening fixme l10n dark seed clients border bottom 1px dotted cursor help l10n dark seed clients short peer stats seed clients list item add child span u00a0 number of seed clients if number of routing disabled 0 html node peer stats routing disabled list item peer stats list add child li add child span peer stats routing disabled list item add child span new string class title style new string peer routing disabled l10n dark routing disabled border bottom 1px dotted cursor help l10n dark routing disabled short peer stats routing disabled list item add child span u00a0 number of routing disabled drawpeerstatsbox htmlnode peerstatsinfobox advancedmodeenabled numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofseedservers numberofseedclients numberofroutingdisabled numberofclockproblem numberofconnerror numberofdisconnecting peerstatsinfobox addchild peerstatstitle htmlnode peerstatscontent peerstatsinfobox addchild htmlnode peerstatslist peerstatscontent addchild numberofconnected htmlnode peerstatsconnectedlistitem peerstatslist addchild addchild peerstatsconnectedlistitem addchild peer_connected l10ndark l10ndark connectedshort peerstatsconnectedlistitem addchild numberofconnected numberofroutingbackedoff htmlnode peerstatsroutingbackedofflistitem peerstatslist addchild addchild peerstatsroutingbackedofflistitem addchild peer_backed_off l10ndark advancedmodeenabled backedoff l10ndark advancedmodeenabled backedoff peerstatsroutingbackedofflistitem addchild numberofroutingbackedoff numberoftoonew htmlnode peerstatstoonewlistitem peerstatslist addchild addchild peerstatstoonewlistitem addchild peer_too_new l10ndark toonew l10ndark toonewshort peerstatstoonewlistitem addchild numberoftoonew numberoftooold htmlnode peerstatstoooldlistitem peerstatslist addchild addchild peerstatstoooldlistitem addchild peer_too_old l10ndark tooold l10ndark toooldshort peerstatstoooldlistitem addchild numberoftooold numberofdisconnected htmlnode peerstatsdisconnectedlistitem peerstatslist addchild addchild peerstatsdisconnectedlistitem addchild peer_disconnected l10ndark notconnected l10ndark notconnectedshort peerstatsdisconnectedlistitem addchild numberofdisconnected numberofneverconnected htmlnode peerstatsneverconnectedlistitem peerstatslist addchild addchild peerstatsneverconnectedlistitem addchild peer_never_connected l10ndark neverconnected l10ndark neverconnectedshort peerstatsneverconnectedlistitem addchild numberofneverconnected numberofdisabled htmlnode peerstatsdisabledlistitem peerstatslist addchild addchild peerstatsdisabledlistitem addchild peer_disabled l10ndark l10ndark disabledshort peerstatsdisabledlistitem addchild numberofdisabled numberofbursting htmlnode peerstatsburstinglistitem peerstatslist addchild addchild peerstatsburstinglistitem addchild peer_bursting l10ndark l10ndark burstingshort peerstatsburstinglistitem addchild numberofbursting numberoflistening htmlnode peerstatslisteninglistitem peerstatslist addchild addchild peerstatslisteninglistitem addchild peer_listening l10ndark l10ndark listeningshort peerstatslisteninglistitem addchild numberoflistening numberoflistenonly htmlnode peerstatslistenonlylistitem peerstatslist addchild addchild peerstatslistenonlylistitem addchild peer_listen_only l10ndark listenonly l10ndark listenonlyshort peerstatslistenonlylistitem addchild numberoflistenonly numberofclockproblem htmlnode peerstatsroutingdisabledlistitem peerstatslist addchild addchild peerstatsroutingdisabledlistitem addchild peer_clock_problem l10ndark clockproblem l10ndark clockproblemshort peerstatsroutingdisabledlistitem addchild numberofclockproblem numberofconnerror htmlnode peerstatsroutingdisabledlistitem peerstatslist addchild addchild peerstatsroutingdisabledlistitem addchild peer_routing_disabled l10ndark connerror l10ndark connerrorshort peerstatsroutingdisabledlistitem addchild numberofclockproblem numberofdisconnecting htmlnode peerstatslistenonlylistitem peerstatslist addchild addchild peerstatslistenonlylistitem addchild peer_disconnecting l10ndark l10ndark disconnectingshort peerstatslistenonlylistitem addchild numberofdisconnecting numberofseedservers htmlnode peerstatsseedserverslistitem peerstatslist addchild addchild peerstatsseedserverslistitem addchild peer_listening l10ndark seedservers l10ndark seedserversshort peerstatsseedserverslistitem addchild numberofseedservers numberofseedclients htmlnode peerstatsseedclientslistitem peerstatslist addchild addchild peerstatsseedclientslistitem addchild peer_listening l10ndark seedclients l10ndark seedclientsshort peerstatsseedclientslistitem addchild numberofseedclients numberofroutingdisabled htmlnode peerstatsroutingdisabledlistitem peerstatslist addchild addchild peerstatsroutingdisabledlistitem addchild peer_routing_disabled l10ndark routingdisabled l10ndark routingdisabledshort peerstatsroutingdisabledlistitem addchild numberofroutingdisabled private static string l10n string key return l10n get string statistics toadlet key getstring statisticstoadlet private static string l10n dark string key return l10n get string darknet connections toadlet key l10ndark getstring darknetconnectionstoadlet private static string l10n string key string pattern string value return l10n get string statistics toadlet key new string pattern new string value getstring statisticstoadlet private static string l10n string key string patterns string values return l10n get string statistics toadlet key patterns values getstring statisticstoadlet private void draw activity box html node activity infobox boolean advanced mode enabled activity infobox add child div class infobox header l10n dark activity title html node activity infobox content activity infobox add child div class infobox content html node activity list draw activity activity infobox content node int numark fetchers node get numark fetchers if advanced mode enabled activity list null if numark fetchers 0 activity list add child li ark u00a0 fetch u00a0 requests u00a0 numark fetchers activity list add child li fetcher byusk size u00a0 node client core usk manager get fetcher byusk size activity list add child li background fetcher byusk size u00a0 node client core usk manager get background fetcher byusk size activity list add child li temporary background fetcherslru size u00a0 node client core usk manager get temporary background fetcherslru drawactivitybox htmlnode activityinfobox advancedmodeenabled activityinfobox addchild l10ndark activitytitle htmlnode activityinfoboxcontent activityinfobox addchild htmlnode activitylist drawactivity activityinfoboxcontent numarkfetchers getnumarkfetchers advancedmodeenabled activitylist numarkfetchers activitylist addchild u00a0fetch u00a0requests numarkfetchers activitylist addchild fetcherbyusksize clientcore uskmanager getfetcherbyusksize activitylist addchild backgroundfetcherbyusksize clientcore uskmanager getbackgroundfetcherbyusksize activitylist addchild temporarybackgroundfetcherslrusize clientcore uskmanager gettemporarybackgroundfetcherslru static void draw bandwidth html node activity list node node long node uptime seconds boolean is advanced mode enabled long total node collector get totalio if total 0 0 total 1 0 return long total output rate total 0 node uptime seconds long total input rate total 1 node uptime seconds long total payload node get total payload sent long total payload rate total payload node uptime seconds int percent int 100 total payload total 0 long rate node node stats get nodeio stats long delta rate 5 rate 2 1000 if delta 0 long output rate rate 3 rate 0 delta long input rate rate 4 rate 1 delta sub config node config node config get node int output bandwidth limit node config get int output bandwidth limit int input bandwidth limit node config get int input bandwidth limit if input bandwidth limit 1 input bandwidth limit output bandwidth limit 4 activity list add child li l10n input rate new string rate max new string size util format size input rate true size util format size input bandwidth limit true activity list add child li l10n output rate new string rate max new string size util format size output rate true size util format size output bandwidth limit true activity list add child li l10n total input new string total rate new string size util format size total 1 true size util format size total input rate true activity list add child li l10n total output new string total rate new string size util format size total 0 true size util format size total output rate true activity list add child li l10n payload output new string total rate percent new string size util format size total payload true size util format size total payload rate true integer to string percent if is advanced mode enabled long total bytes sentchk requests node node stats getchk request total bytes sent long total bytes sentssk requests node node stats getssk request total bytes sent long total bytes sentchk inserts node node stats getchk insert total bytes sent long total bytes sentssk inserts node node stats getssk insert total bytes sent long total bytes sent offered keys node node stats get offered keys total bytes sent long total bytes send offers node node stats get offers sent bytes sent long total bytes sent swap output node node stats get swapping total bytes sent long total bytes sent auth node node stats get total auth bytes sent long total bytes sent ack only node node stats get notification only packets sent bytes long total bytes sent resends node node stats get resend bytes sent long total bytes sentuom node node stats getuom bytes sent long total bytes sent announce node node stats get announce bytes sent long total bytes sent routing status node node stats get routing status bytes long total bytes sent network coloring node node stats get network coloring sent bytes long total bytes sent ping node node stats get ping sent bytes long total bytes sent probe request node node stats get probe request sent bytes long total bytes sent routed node node stats get routed message sent bytes long total bytes sent disconn node node stats get disconn bytes sent long total bytes sent initial node node stats get initial messages bytes sent long total bytes sent changedip node node stats get changedip bytes sent long total bytes sent node to node node node stats get node to node bytes sent long total bytes sent remaining total 0 total payload total bytes sentchk requests total bytes sentssk requests total bytes sentchk inserts total bytes sentssk inserts total bytes sent offered keys total bytes send offers total bytes sent swap output total bytes sent auth total bytes sent ack only total bytes sent resends total bytes sentuom total bytes sent announce total bytes sent routing status total bytes sent network coloring total bytes sent ping total bytes sent probe request total bytes sent routed total bytes sent disconn total bytes sent initial total bytes sent changedip total bytes sent node to node activity list add child li l10n request output new string chk ssk new string size util format size total bytes sentchk requests true size util format size total bytes sentssk requests true activity list add child li l10n insert output new string chk ssk new string size util format size total bytes sentchk inserts true size util format size total bytes sentssk inserts true activity list add child li l10n offered key output new string total offered new string size util format size total bytes sent offered keys true size util format size total bytes send offers true activity list add child li l10n swap output total size util format size total bytes sent swap output true activity list add child li l10n auth bytes total size util format size total bytes sent auth true activity list add child li l10n ack only bytes total size util format size total bytes sent ack only true activity list add child li l10n resend bytes total size util format size total bytes sent resends true activity list add child li l10n uom bytes total size util format size total bytes sentuom true activity list add child li l10n announce bytes total size util format size total bytes sent announce true activity list add child li l10n admin bytes new string routing status disconn initial changedip new string size util format size total bytes sent routing status true size util format size total bytes sent disconn true size util format size total bytes sent initial true size util format size total bytes sent changedip true activity list add child li l10n debugging bytes new string net coloring ping probe routed new string size util format size total bytes sent network coloring true size util format size total bytes sent ping true size util format size total bytes sent probe request true size util format size total bytes sent routed true activity list add child li l10n node to node bytes total size util format size total bytes sent node to node true activity list add child li l10n unaccounted bytes new string total percent new string size util format size total bytes sent remaining true integer to string int total bytes sent remaining 100 total 0 double sent overhead per second node node stats get sent overhead per second activity list add child li l10n total overhead new string rate percent new string size util format size long sent overhead per second integer to string int 100 sent overhead per second total output rate drawbandwidth htmlnode activitylist nodeuptimeseconds isadvancedmodeenabled gettotalio total_output_rate nodeuptimeseconds total_input_rate nodeuptimeseconds totalpayload gettotalpayloadsent total_payload_rate totalpayload nodeuptimeseconds totalpayload nodestats getnodeiostats output_rate input_rate subconfig nodeconfig outputbandwidthlimit nodeconfig getint outputbandwidthlimit inputbandwidthlimit nodeconfig getint inputbandwidthlimit inputbandwidthlimit inputbandwidthlimit outputbandwidthlimit activitylist addchild inputrate sizeutil formatsize input_rate sizeutil formatsize inputbandwidthlimit activitylist addchild outputrate sizeutil formatsize output_rate sizeutil formatsize outputbandwidthlimit activitylist addchild totalinput sizeutil formatsize sizeutil formatsize total_input_rate activitylist addchild totaloutput sizeutil formatsize sizeutil formatsize total_output_rate activitylist addchild payloadoutput sizeutil formatsize totalpayload sizeutil formatsize total_payload_rate tostring isadvancedmodeenabled totalbytessentchkrequests nodestats getchkrequesttotalbytessent totalbytessentsskrequests nodestats getsskrequesttotalbytessent totalbytessentchkinserts nodestats getchkinserttotalbytessent totalbytessentsskinserts nodestats getsskinserttotalbytessent totalbytessentofferedkeys nodestats getofferedkeystotalbytessent totalbytessendoffers nodestats getofferssentbytessent totalbytessentswapoutput nodestats getswappingtotalbytessent totalbytessentauth nodestats gettotalauthbytessent totalbytessentackonly nodestats getnotificationonlypacketssentbytes totalbytessentresends nodestats getresendbytessent totalbytessentuom nodestats getuombytessent totalbytessentannounce nodestats getannouncebytessent totalbytessentroutingstatus nodestats getroutingstatusbytes totalbytessentnetworkcoloring nodestats getnetworkcoloringsentbytes totalbytessentping nodestats getpingsentbytes totalbytessentproberequest nodestats getproberequestsentbytes totalbytessentrouted nodestats getroutedmessagesentbytes totalbytessentdisconn nodestats getdisconnbytessent totalbytessentinitial nodestats getinitialmessagesbytessent totalbytessentchangedip nodestats getchangedipbytessent totalbytessentnodetonode nodestats getnodetonodebytessent totalbytessentremaining totalpayload totalbytessentchkrequests totalbytessentsskrequests totalbytessentchkinserts totalbytessentsskinserts totalbytessentofferedkeys totalbytessendoffers totalbytessentswapoutput totalbytessentauth totalbytessentackonly totalbytessentresends totalbytessentuom totalbytessentannounce totalbytessentroutingstatus totalbytessentnetworkcoloring totalbytessentping totalbytessentproberequest totalbytessentrouted totalbytessentdisconn totalbytessentinitial totalbytessentchangedip totalbytessentnodetonode activitylist addchild requestoutput sizeutil formatsize totalbytessentchkrequests sizeutil formatsize totalbytessentsskrequests activitylist addchild insertoutput sizeutil formatsize totalbytessentchkinserts sizeutil formatsize totalbytessentsskinserts activitylist addchild offeredkeyoutput sizeutil formatsize totalbytessentofferedkeys sizeutil formatsize totalbytessendoffers activitylist addchild swapoutput sizeutil formatsize totalbytessentswapoutput activitylist addchild authbytes sizeutil formatsize totalbytessentauth activitylist addchild ackonlybytes sizeutil formatsize totalbytessentackonly activitylist addchild resendbytes sizeutil formatsize totalbytessentresends activitylist addchild uombytes sizeutil formatsize totalbytessentuom activitylist addchild announcebytes sizeutil formatsize totalbytessentannounce activitylist addchild adminbytes routingstatus sizeutil formatsize totalbytessentroutingstatus sizeutil formatsize totalbytessentdisconn sizeutil formatsize totalbytessentinitial sizeutil formatsize totalbytessentchangedip activitylist addchild debuggingbytes netcoloring sizeutil formatsize totalbytessentnetworkcoloring sizeutil formatsize totalbytessentping sizeutil formatsize totalbytessentproberequest sizeutil formatsize totalbytessentrouted activitylist addchild nodetonodebytes sizeutil formatsize totalbytessentnodetonode activitylist addchild unaccountedbytes sizeutil formatsize totalbytessentremaining tostring totalbytessentremaining sentoverheadpersecond nodestats getsentoverheadpersecond activitylist addchild totaloverhead sizeutil formatsize sentoverheadpersecond tostring sentoverheadpersecond total_output_rate static html node draw activity html node activity infobox content node node int num inserts node get num insert senders int num localchk inserts node get num localchk inserts int num remotechk inserts node get num remotechk inserts int num localssk inserts node get num localssk inserts int num remotessk inserts node get num remotessk inserts int num requests node get num request senders int num localchk requests node get num localchk requests int num remotechk requests node get num remotechk requests int num localssk requests node get num localssk requests int num remotessk requests node get num remotessk requests int num transferring requests node get num transferring request senders int num transferring request handlers node get num transferring request handlers int numchk offer replys node get numchk offer replies int numssk offer replys node get numssk offer replies int numchk requests num localchk requests num remotechk requests int numssk requests num localssk requests num remotessk requests int numchk inserts num localchk inserts num remotechk inserts int numssk inserts num localssk inserts num remotessk inserts int num incoming turtles node get num incoming turtles if num inserts 0 num requests 0 num transferring requests 0 numchk requests 0 numssk requests 0 numchk inserts 0 numssk inserts 0 num transferring request handlers 0 numchk offer replys 0 numssk offer replys 0 activity infobox content add child l10n no requests return null else html node activity list activity infobox content add child ul if num inserts 0 numchk inserts 0 numssk inserts 0 activity list add child li l10n get string statistics toadlet activity inserts new string total senders ch khandlers ss khandlers local new string integer to string num inserts integer to string numchk inserts integer to string numssk inserts integer to string num localchk inserts num localssk inserts if num requests 0 numchk requests 0 numssk requests 0 activity list add child li l10n get string statistics toadlet activity requests new string total senders ch khandlers ss khandlers local new string integer to string num requests integer to string numchk requests integer to string numssk requests integer to string num localchk requests num localssk requests if num transferring requests 0 num transferring request handlers 0 num incoming turtles 0 activity list add child li l10n get string statistics toadlet transferring requests new string senders receivers turtles new string integer to string num transferring requests integer to string num transferring request handlers integer to string num incoming turtles if numchk offer replys 0 numssk offer replys 0 activity list add child li l10n get string statistics toadlet offer replys new string chk ssk new string integer to string numchk offer replys integer to string numssk offer replys return activity list htmlnode drawactivity htmlnode activityinfoboxcontent numinserts getnuminsertsenders numlocalchkinserts getnumlocalchkinserts numremotechkinserts getnumremotechkinserts numlocalsskinserts getnumlocalsskinserts numremotesskinserts getnumremotesskinserts numrequests getnumrequestsenders numlocalchkrequests getnumlocalchkrequests numremotechkrequests getnumremotechkrequests numlocalsskrequests getnumlocalsskrequests numremotesskrequests getnumremotesskrequests numtransferringrequests getnumtransferringrequestsenders numtransferringrequesthandlers getnumtransferringrequesthandlers numchkofferreplys getnumchkofferreplies numsskofferreplys getnumsskofferreplies numchkrequests numlocalchkrequests numremotechkrequests numsskrequests numlocalsskrequests numremotesskrequests numchkinserts numlocalchkinserts numremotechkinserts numsskinserts numlocalsskinserts numremotesskinserts numincomingturtles getnumincomingturtles numinserts numrequests numtransferringrequests numchkrequests numsskrequests numchkinserts numsskinserts numtransferringrequesthandlers numchkofferreplys numsskofferreplys activityinfoboxcontent addchild norequests htmlnode activitylist activityinfoboxcontent addchild numinserts numchkinserts numsskinserts activitylist addchild getstring statisticstoadlet activityinserts totalsenders chkhandlers sskhandlers tostring numinserts tostring numchkinserts tostring numsskinserts tostring numlocalchkinserts numlocalsskinserts numrequests numchkrequests numsskrequests activitylist addchild getstring statisticstoadlet activityrequests totalsenders chkhandlers sskhandlers tostring numrequests tostring numchkrequests tostring numsskrequests tostring numlocalchkrequests numlocalsskrequests numtransferringrequests numtransferringrequesthandlers numincomingturtles activitylist addchild getstring statisticstoadlet transferringrequests tostring numtransferringrequests tostring numtransferringrequesthandlers tostring numincomingturtles numchkofferreplys numsskofferreplys activitylist addchild getstring statisticstoadlet offerreplys tostring numchkofferreplys tostring numsskofferreplys activitylist private void draw overview box html node overview infobox long node uptime seconds long now double swaps double no swaps overview infobox add child div class infobox header node status overview html node overview infobox content overview infobox add child div class infobox content html node overview list overview infobox content add child ul node status values int bwlimit delay time int stats get bwlimit delay time int node average ping time int stats get node average ping time double number of remote peer locations seen in swaps node get number of remote peer locations seen in swaps darknet int darknet size estimate session stats get darknet size estimate 1 int darknet size estimate24h 0 int darknet size estimate48h 0 if node uptime seconds 24 60 60 24 hours darknet size estimate24h stats get darknet size estimate now 24 60 60 1000 48 hours if node uptime seconds 48 60 60 48 hours darknet size estimate48h stats get darknet size estimate now 48 60 60 1000 48 hours opennet int opennet size estimate session stats get opennet size estimate 1 int opennet size estimate24h 0 int opennet size estimate48h 0 if node uptime seconds 24 60 60 24 hours opennet size estimate24h stats get opennet size estimate now 24 60 60 1000 48 hours if node uptime seconds 48 60 60 48 hours opennet size estimate48h stats get opennet size estimate now 48 60 60 1000 48 hours double routing miss distance stats routing miss distance current value double backed off percent stats backed off percent current value string node uptime string time util format time node uptime seconds 1000 1000 to convert to milliseconds overview list add child li bwlimit delay time u00a0 bwlimit delay time ms overview list add child li node average ping time u00a0 node average ping time ms overview list add child li darknet size estimate session u00a0 darknet size estimate session u00a0nodes if node uptime seconds 24 60 60 24 hours overview list add child li darknet size estimate24h u00a0 darknet size estimate24h u00a0nodes if node uptime seconds 48 60 60 48 hours overview list add child li darknet size estimate48h u00a0 darknet size estimate48h u00a0nodes overview list add child li opennet size estimate session u00a0 opennet size estimate session u00a0nodes if node uptime seconds 24 60 60 24 hours overview list add child li opennet size estimate24h u00a0 opennet size estimate24h u00a0nodes if node uptime seconds 48 60 60 48 hours overview list add child li opennet size estimate48h u00a0 opennet size estimate48h u00a0nodes if number of remote peer locations seen in swaps 0 0 swaps 0 0 no swaps 0 0 overview list add child li avr conn peers per node u00a0 fix6p6 format number of remote peer locations seen in swaps swaps no swaps u00a0peers overview list add child li node uptime u00a0 node uptime string overview list add child li routing miss distance u00a0 fix1p4 format routing miss distance overview list add child li backed off percent u00a0 fix3p1pct format backed off percent overview list add child li p instant reject u00a0 fix3p1pct format stats p reject incoming instantly overview list add child li unclaimedfifo size u00a0 node get unclaimedfifo size overview list add child li ram bucket pool size u00a0 size util format size core temp bucket factory get ram used size util format size core temp bucket factory get max ram used overview list add child li uptime average u00a0 fix3p1pct format node uptime get uptime drawoverviewbox htmlnode overviewinfobox nodeuptimeseconds noswaps overviewinfobox addchild htmlnode overviewinfoboxcontent overviewinfobox addchild htmlnode overviewlist overviewinfoboxcontent addchild bwlimitdelaytime getbwlimitdelaytime nodeaveragepingtime getnodeaveragepingtime numberofremotepeerlocationsseeninswaps getnumberofremotepeerlocationsseeninswaps darknetsizeestimatesession getdarknetsizeestimate darknetsizeestimate24h darknetsizeestimate48h nodeuptimeseconds darknetsizeestimate24h getdarknetsizeestimate nodeuptimeseconds darknetsizeestimate48h getdarknetsizeestimate opennetsizeestimatesession getopennetsizeestimate opennetsizeestimate24h opennetsizeestimate48h nodeuptimeseconds opennetsizeestimate24h getopennetsizeestimate nodeuptimeseconds opennetsizeestimate48h getopennetsizeestimate routingmissdistance routingmissdistance currentvalue backedoffpercent backedoffpercent currentvalue nodeuptimestring timeutil formattime nodeuptimeseconds overviewlist addchild bwlimitdelaytime bwlimitdelaytime overviewlist addchild nodeaveragepingtime nodeaveragepingtime overviewlist addchild darknetsizeestimatesession darknetsizeestimatesession nodeuptimeseconds overviewlist addchild darknetsizeestimate24h darknetsizeestimate24h nodeuptimeseconds overviewlist addchild darknetsizeestimate48h darknetsizeestimate48h overviewlist addchild opennetsizeestimatesession opennetsizeestimatesession nodeuptimeseconds overviewlist addchild opennetsizeestimate24h opennetsizeestimate24h nodeuptimeseconds overviewlist addchild opennetsizeestimate48h opennetsizeestimate48h numberofremotepeerlocationsseeninswaps noswaps overviewlist addchild avrconnpeerspernode numberofremotepeerlocationsseeninswaps noswaps overviewlist addchild nodeuptime nodeuptimestring overviewlist addchild routingmissdistance routingmissdistance overviewlist addchild backedoffpercent backedoffpercent overviewlist addchild pinstantreject prejectincominginstantly overviewlist addchild unclaimedfifosize getunclaimedfifosize overviewlist addchild rambucketpoolsize sizeutil formatsize tempbucketfactory getramused sizeutil formatsize tempbucketfactory getmaxramused overviewlist addchild uptimeaverage getuptime private void draw bandwidth box html node bandwidth infobox long node uptime seconds boolean is advanced mode enabled bandwidth infobox add child div class infobox header l10n bandwidth title html node bandwidth infobox content bandwidth infobox add child div class infobox content html node bandwidth list bandwidth infobox content add child ul draw bandwidth bandwidth list node node uptime seconds is advanced mode enabled drawbandwidthbox htmlnode bandwidthinfobox nodeuptimeseconds isadvancedmodeenabled bandwidthinfobox addchild bandwidthtitle htmlnode bandwidthinfoboxcontent bandwidthinfobox addchild htmlnode bandwidthlist bandwidthinfoboxcontent addchild drawbandwidth bandwidthlist nodeuptimeseconds isadvancedmodeenabled fixme this should probably be moved to nodestats so it can be used by fcp would have to make thread bunch public private void get thread names html node thread usage list int count 0 thread threads while true count math max stats root thread group active count count threads new thread count 2 50 stats root thread group enumerate threads if threads threads length 1 null break linked hash map string thread bunch map new linked hash map string thread bunch int total count 0 for int i 0 i threads length i if threads i null break string name threads i get name if name index of for 1 name name substring 0 name index of for if name index of 1 name name substring 0 name index of if name index of 1 name name substring 0 name index of thread bunch bunch map get name if bunch null bunch count else map put name new thread bunch name 1 total count thread bunch bunches map values to array new thread bunch map size arrays sort bunches new comparator thread bunch public int compare thread bunch b0 thread bunch b1 if b0 count b1 count return 1 if b0 count b1 count return 1 return b0 name compare to b1 name double this thread percent of total for int i 0 i bunches length i this thread percent of total double bunches i count double total count thread usage list add child li bunches i name u00a0 integer to string bunches i count u00a0 fix3p1pct format this thread percent of total threadbunch getthreadnames htmlnode threadusagelist rootthreadgroup activecount rootthreadgroup linkedhashmap threadbunch linkedhashmap threadbunch totalcount getname indexof indexof indexof indexof indexof indexof threadbunch threadbunch totalcount threadbunch toarray threadbunch threadbunch threadbunch threadbunch compareto thisthreadpercentoftotal thisthreadpercentoftotal totalcount threadusagelist addchild tostring thisthreadpercentoftotal arrays sort bunches new comparator thread bunch public int compare thread bunch b0 thread bunch b1 if b0 count b1 count return 1 if b0 count b1 count return 1 return b0 name compare to b1 name threadbunch threadbunch threadbunch compareto private static class thread bunch public thread bunch string name2 int i this name name2 this count i threadbunch threadbunch private void add node circle html node circle table double my location int histogram new int histogram length for int i 0 i histogram length i histogram i 0 html node node circle table row circle table add child tr html node node histogram legend table row circle table add child tr html node node histogram graph table row circle table add child tr html node node circle table cell node circle table row add child td new string class colspan new string first 10 html node node histogram legend cell html node node histogram graph cell html node node circle infobox content node circle table cell add child div new string style class new string position relative height peer circle radius peer circle additional free space 2 px width peer circle radius peer circle additional free space 2 px peercircle node circle infobox content add child span new string style class new string generate peer circle style string 0 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 125 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 25 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 375 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 5 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 625 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 75 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 875 false 1 0 mark node circle infobox content add child span new string style class new string generate peer circle style string 0 875 false 1 0 mark node circle infobox content add child span new string style class new string position absolute top peer circle radius px left peer circle radius peer circle additional free space px mark final object known locs copy stats get known locations 1 final double locations double known locs copy 0 final long timestamps long known locs copy 1 double location long location time double strength 1 0 long now system current time millis long age 1 int histogram index int node count 0 for int i 0 i locations length i node count 1 location locations i location time timestamps i age now location time long value if age max circle age threshold age max circle age threshold strength 1 double age max circle age threshold histogram index int math floor location double value histogram length histogram histogram index node circle infobox content add child span new string style class new string generate peer circle style string location double value false strength connected x node circle infobox content add child span new string style class new string generate peer circle style string my location true 1 0 me x double histogram percent for int i 0 i histogram length i node histogram legend cell node histogram legend table row add child td node histogram graph cell node histogram graph table row add child td style height 100px node histogram legend cell add child div class histogram label add child fix1p1 format double i histogram length histogram percent double histogram i node count don t use html node here to speed things up node histogram graph cell add child div class histogram connected style height fix3pctus format histogram percent width 100 u00a0 div addnodecircle htmlnode circletable mylocation histogram_length histogram_length htmlnode nodecircletablerow circletable addchild htmlnode nodehistogramlegendtablerow circletable addchild htmlnode nodehistogramgraphtablerow circletable addchild htmlnode nodecircletablecell nodecircletablerow addchild htmlnode nodehistogramlegendcell htmlnode nodehistogramgraphcell htmlnode nodecircleinfoboxcontent nodecircletablecell addchild peer_circle_radius peer_circle_additional_free_space peer_circle_radius peer_circle_additional_free_space nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild generatepeercirclestylestring nodecircleinfoboxcontent addchild peer_circle_radius peer_circle_radius peer_circle_additional_free_space knownlocscopy getknownlocations knownlocscopy knownlocscopy locationtime currenttimemillis histogramindex nodecount nodecount locationtime locationtime longvalue max_circle_age_threshold max_circle_age_threshold max_circle_age_threshold histogramindex doublevalue histogram_length histogramindex nodecircleinfoboxcontent addchild generatepeercirclestylestring doublevalue nodecircleinfoboxcontent addchild generatepeercirclestylestring mylocation histogrampercent histogram_length nodehistogramlegendcell nodehistogramlegendtablerow addchild nodehistogramgraphcell nodehistogramgraphtablerow addchild nodehistogramlegendcell addchild histogramlabel addchild histogram_length histogrampercent nodecount htmlnode nodehistogramgraphcell addchild histogramconnected histogrampercent private void add specialisation html node table double peer location int incoming requests count int incoming request location html node node histogram legend table row table add child tr html node node histogram graph table row table add child tr int my index int peer location incoming request location length for int i 0 i incoming request location length i html node node histogram legend cell node histogram legend table row add child td html node node histogram graph cell node histogram graph table row add child td style height 100px html node node histogram graph cell2 node histogram legend cell add child div class histogram label if i my index node histogram graph cell2 node histogram graph cell2 add child span class me node histogram graph cell2 add child fix1p1 format double i incoming request location length node histogram graph cell add child div new string class style new string histogram connected height fix3pctus format double incoming request location i incoming requests count width 100 u00a0 addspecialisation htmlnode peerlocation incomingrequestscount incomingrequestlocation htmlnode nodehistogramlegendtablerow addchild htmlnode nodehistogramgraphtablerow addchild myindex peerlocation incomingrequestlocation incomingrequestlocation htmlnode nodehistogramlegendcell nodehistogramlegendtablerow addchild htmlnode nodehistogramgraphcell nodehistogramgraphtablerow addchild htmlnode nodehistogramgraphcell2 nodehistogramlegendcell addchild histogramlabel myindex nodehistogramgraphcell2 nodehistogramgraphcell2 addchild nodehistogramgraphcell2 addchild incomingrequestlocation nodehistogramgraphcell addchild histogramconnected incomingrequestlocation incomingrequestscount private void add combined specialisation html node table double peer location int locally originating requests count int locally originating requests int remotely originating requests count int remotely originating requests assert locally originating requests length remotely originating requests length html node node histogram legend table row table add child tr html node node histogram graph table row table add child tr int my index int peer location locally originating requests length for int i 0 i locally originating requests length i html node node histogram legend cell node histogram legend table row add child td html node node histogram graph cell node histogram graph table row add child td style height 100px html node node histogram graph cell2 node histogram legend cell add child div class histogram label if i my index node histogram graph cell2 node histogram graph cell2 add child span class me node histogram graph cell2 add child fix1p1 format double i locally originating requests length node histogram graph cell add child div new string class style new string histogram connected height fix3pctus format double locally originating requests i locally originating requests count width 100 u00a0 node histogram graph cell add child div new string class style new string histogram disconnected height fix3pctus format double remotely originating requests i remotely originating requests count width 100 u00a0 addcombinedspecialisation htmlnode peerlocation locallyoriginatingrequestscount locallyoriginatingrequests remotelyoriginatingrequestscount remotelyoriginatingrequests locallyoriginatingrequests remotelyoriginatingrequests htmlnode nodehistogramlegendtablerow addchild htmlnode nodehistogramgraphtablerow addchild myindex peerlocation locallyoriginatingrequests locallyoriginatingrequests htmlnode nodehistogramlegendcell nodehistogramlegendtablerow addchild htmlnode nodehistogramgraphcell nodehistogramgraphtablerow addchild htmlnode nodehistogramgraphcell2 nodehistogramlegendcell addchild histogramlabel myindex nodehistogramgraphcell2 nodehistogramgraphcell2 addchild nodehistogramgraphcell2 addchild locallyoriginatingrequests nodehistogramgraphcell addchild histogramconnected locallyoriginatingrequests locallyoriginatingrequestscount nodehistogramgraphcell addchild histogramdisconnected remotelyoriginatingrequests remotelyoriginatingrequestscount private void add peer circle html node circle table peer node status peer node statuses double my location int histogram connected new int histogram length int histogram disconnected new int histogram length for int i 0 i histogram length i histogram connected i 0 histogram disconnected i 0 html node peer circle table row circle table add child tr html node peer histogram legend table row circle table add child tr html node peer histogram graph table row circle table add child tr html node peer circle table cell peer circle table row add child td new string class colspan new string first 10 html node peer histogram legend cell html node peer histogram graph cell html node peer circle infobox content peer circle table cell add child div new string style class new string position relative height peer circle radius peer circle additional free space 2 px width peer circle radius peer circle additional free space 2 px peercircle peer circle infobox content add child span new string style class new string generate peer circle style string 0 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 125 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 25 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 375 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 5 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 625 false 1 0 mark peer circle infobox content add child span new string style class new string generate peer circle style string 0 75 false 1 0 mark peer circle infobox content add child span new string style class new string position absolute top peer circle radius px left peer circle radius peer circle additional free space px mark peer node status peer node status double peer location double peer distance int histogram index int peer count peer node statuses length int new peer count 0 for int peer index 0 peer index peer count peer index peer node status peer node statuses peer index peer location peer node status get location if peer node status is searchable continue if peer location 0 0 peer location 1 0 continue new peer count peer distance location distance my location peer location histogram index int math floor peer distance histogram length 2 if peer node status is connected histogram connected histogram index else histogram disconnected histogram index peer circle infobox content add child span new string style class new string generate peer circle style string peer location false 1 0 peer node status getp reject peer node status is connected connected disconnected peer node status is opennet o x peer circle infobox content add child span new string style class new string generate peer circle style string my location true 1 0 me x double histogram percent for int i 0 i histogram length i peer histogram legend cell peer histogram legend table row add child td peer histogram graph cell peer histogram graph table row add child td style height 100px peer histogram legend cell add child div class histogram label add child fix1p2 format double i histogram length 2 histogram percent double histogram connected i new peer count peer histogram graph cell add child div new string class style new string histogram connected height fix3pctus format histogram percent width 100 u00a0 histogram percent double histogram disconnected i new peer count peer histogram graph cell add child div new string class style new string histogram disconnected height fix3pctus format histogram percent width 100 u00a0 addpeercircle htmlnode circletable peernodestatus peernodestatuses mylocation histogramconnected histogram_length histogramdisconnected histogram_length histogram_length histogramconnected histogramdisconnected htmlnode peercircletablerow circletable addchild htmlnode peerhistogramlegendtablerow circletable addchild htmlnode peerhistogramgraphtablerow circletable addchild htmlnode peercircletablecell peercircletablerow addchild htmlnode peerhistogramlegendcell htmlnode peerhistogramgraphcell htmlnode peercircleinfoboxcontent peercircletablecell addchild peer_circle_radius peer_circle_additional_free_space peer_circle_radius peer_circle_additional_free_space peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild generatepeercirclestylestring peercircleinfoboxcontent addchild peer_circle_radius peer_circle_radius peer_circle_additional_free_space peernodestatus peernodestatus peerlocation peerdistance histogramindex peercount peernodestatuses newpeercount peerindex peerindex peercount peerindex peernodestatus peernodestatuses peerindex peerlocation peernodestatus getlocation peernodestatus issearchable peerlocation peerlocation newpeercount peerdistance mylocation peerlocation histogramindex peerdistance histogram_length peernodestatus isconnected histogramconnected histogramindex histogramdisconnected histogramindex peercircleinfoboxcontent addchild generatepeercirclestylestring peerlocation peernodestatus getpreject peernodestatus isconnected peernodestatus isopennet peercircleinfoboxcontent addchild generatepeercirclestylestring mylocation histogrampercent histogram_length peerhistogramlegendcell peerhistogramlegendtablerow addchild peerhistogramgraphcell peerhistogramgraphtablerow addchild peerhistogramlegendcell addchild histogramlabel addchild histogram_length histogrampercent histogramconnected newpeercount peerhistogramgraphcell addchild histogramconnected histogrampercent histogrampercent histogramdisconnected newpeercount peerhistogramgraphcell addchild histogramdisconnected histogrampercent private string generate peer circle style string double peer location boolean offset me double strength peer location math pi 2 int offset 0 if offset me make our own peer stand out from the crowd better so we can see it easier offset 10 else offset int peer circle inner radius 1 0 strength double x peer circle additional free space peer circle radius math sin peer location peer circle radius offset double y peer circle radius math cos peer location peer circle radius offset no peer circle additional free space for y disposition return position absolute top fix3p1us format y px left fix3p1us format x px generatepeercirclestylestring peerlocation offsetme peerlocation offsetme peer_circle_inner_radius peer_circle_additional_free_space peer_circle_radius peerlocation peer_circle_radius peer_circle_radius peerlocation peer_circle_radius peer_circle_additional_free_space boolean really removed public boolean to free return freed reallyremoved tofree public boolean to remove return removed toremove public delayed free bucket persistent temp bucket factory factory bucket bucket this factory factory this bucket bucket if bucket null throw new null pointer exception delayedfreebucket persistenttempbucketfactory nullpointerexception public delayed free bucket simple field set fs random source random persistent file tracker f throws cannot create from field set exception factory f freed false bucket serializable to field set bucket util create fs subset underlying random f delayedfreebucket simplefieldset randomsource persistentfiletracker cannotcreatefromfieldsetexception serializabletofieldsetbucketutil public output stream get output stream throws io exception if freed throw new io exception already freed return bucket get output stream outputstream getoutputstream ioexception ioexception getoutputstream public input stream get input stream throws io exception if freed throw new io exception already freed return bucket get input stream inputstream getinputstream ioexception ioexception getinputstream public string get name return bucket get name getname getname public long size return bucket size public boolean is read only return bucket is read only isreadonly isreadonly public void set read only bucket set read only setreadonly setreadonly public bucket get underlying if freed return null return bucket getunderlying public void free synchronized this mutex on just this method make a separate lock if necessary to lock the above if freed return if logger should log logger minor this logger minor this freeing this underlying bucket new exception debug this factory delayed free bucket this freed true shouldlog delayedfreebucket public simple field set to field set if freed logger error this cannot serialize because already freed this return null simple field set fs new simple field set false fs put single type delayed free bucket if bucket instanceof serializable to field set bucket fs put underlying serializable to field set bucket bucket to field set else logger error this cannot serialize underlying bucket bucket return null return fs simplefieldset tofieldset simplefieldset simplefieldset putsingle delayedfreebucket serializabletofieldsetbucket serializabletofieldsetbucket tofieldset public void store to object container container bucket store to container container store this storeto objectcontainer storeto public void remove from object container container if logger should log logger minor this logger minor this removing from database this synchronized this boolean was queued freed removed if freed logger error this asking to remove from database but not freed this new exception error removed true if was queued this factory delayed free bucket this removefrom objectcontainer shouldlog wasqueued wasqueued delayedfreebucket override public string to string return super to string bucket tostring tostring public void object on activate object container container stack trace element elements thread current thread get stack trace if elements null elements length 100 system err println infinite recursion in progress if logger should log logger minor this logger minor this activating super to string bucket get class if bucket this logger error this object on activate on delayed free bucket wrapping self return cascading activation of dependancies container activate bucket 1 objectonactivate objectcontainer stacktraceelement currentthread getstacktrace shouldlog tostring getclass objectonactivate delayedfreebucket public bucket create shadow throws io exception return bucket create shadow createshadow ioexception createshadow public void real free bucket free realfree public void real remove from object container container synchronized this if really removed logger error this calling real remove from twice on this really removed true bucket remove from container container delete this realremovefrom objectcontainer reallyremoved realremovefrom reallyremoved removefrom public boolean object can new object container container if really removed logger error this object can new on this but really removed really removed already freed freed removed removed new exception debug return false return true objectcannew objectcontainer reallyremoved objectcannew reallyremoved public boolean object can update object container container if really removed logger error this object can update on this but really removed really removed already freed freed removed removed new exception debug return false return true objectcanupdate objectcontainer reallyremoved objectcanupdate reallyremoved long seek long pos curr seg 0 while pos segment curr seg size pos segment curr seg size curr seg 1 return pos currseg currseg currseg currseg public void write long pos byte b pos seek pos segment curr seg f write pos b currseg public int read long pos byte b pos seek pos return segment curr seg f read pos b currseg public void sync if no flush for int i segment length i 0 segment i f sync noflush public boolean try lock boolean shared return segment 0 f try lock shared trylock trylock public void lock boolean shared segment 0 f lock shared public void unlock segment 0 f unlock public void close for int i segment length i 0 segment i f close public multi file string segment path long segment size boolean read only boolean no flush this no flush no flush segment new multi file segment segment path length for int i 0 i segment length i multi file segment seg new multi file segment seg f new os file segment path i read only no flush seg size segment size i fixed size seg size segment i seg fixed size segment segment length 1 size segment segment length 1 size long max value multifile segmentpath segmentsize readonly noflush noflush noflush multifilesegment segmentpath multifilesegment multifilesegment osfile segmentpath readonly noflush segmentsize fixedsize fixedsize max_value public multi file multi file segment segments segment segments for int i 0 i segments length i fixed size segments i size fixed size segment segment length 1 size segment segment length 1 size long max value multifile multifilesegment fixedsize fixedsize max_value public multi file string file path boolean read only boolean no flush try stream tokenizer in new stream tokenizer new buffered reader new file reader file path file dir new file file path get parent file this no flush no flush segment new multi file segment 0 int tkn in next token do multi file segment seg new multi file segment if tkn stream tokenizer tt word tkn throw new storage error storage error file access error multifile segment name expected string path in sval tkn in next token if tkn stream tokenizer tt eof if tkn stream tokenizer tt number throw new storage error storage error file access error multifile segment size expected seg size long in nval 1024 kilobytes tkn in next token fixed size seg size if dir null file f new file path if f is absolute f new file dir path path f get path seg f new os file path read only no flush multi file segment new segment new multi file segment segment length 1 system arraycopy segment 0 new segment 0 segment length new segment segment length seg segment new segment while tkn stream tokenizer tt eof fixed size segment segment length 1 size segment segment length 1 size long max value catch io exception x throw new storage error storage error file access error multifile filepath readonly noflush streamtokenizer streamtokenizer bufferedreader filereader filepath filepath getparentfile noflush noflush multifilesegment nexttoken multifilesegment multifilesegment streamtokenizer tt_word storageerror storageerror file_access_error nexttoken streamtokenizer tt_eof streamtokenizer tt_number storageerror storageerror file_access_error nexttoken fixedsize isabsolute getpath osfile readonly noflush multifilesegment newsegment multifilesegment newsegment newsegment newsegment streamtokenizer tt_eof fixedsize max_value ioexception storageerror storageerror file_access_error public long length return fixed size segment segment length 1 f length fixedsize public class persistent resource extends persistent implements i resource public synchronized void shared lock thread curr thread thread current thread try while true if owner curr thread n writers 1 break else if n writers 0 if storage null storage lock object this n readers 1 break else wait catch interrupted exception x throw new storage error storage error lock failed persistentresource iresource sharedlock currthread currentthread currthread nwriters nwriters lockobject nreaders interruptedexception storageerror storageerror lock_failed public boolean shared lock long timeout thread curr thread thread current thread long start time system current time millis synchronized this try while true if owner curr thread n writers 1 return true else if n writers 0 if storage null storage lock object this n readers 1 return true else long curr time system current time millis if curr time start time curr time start time if start time timeout curr time return false wait start time timeout curr time catch interrupted exception x return false sharedlock currthread currentthread starttime currenttimemillis currthread nwriters nwriters lockobject nreaders currtime currenttimemillis currtime starttime currtime starttime starttime currtime starttime currtime interruptedexception public synchronized void exclusive lock thread curr thread thread current thread try while true if owner curr thread n writers 1 break else if n readers 0 n writers 0 n writers 1 owner curr thread if storage null storage lock object this break else wait catch interrupted exception x throw new storage error storage error lock failed exclusivelock currthread currentthread currthread nwriters nreaders nwriters nwriters currthread lockobject interruptedexception storageerror storageerror lock_failed public boolean exclusive lock long timeout thread curr thread thread current thread long start time system current time millis synchronized this try while true if owner curr thread n writers 1 return true else if n readers 0 n writers 0 n writers 1 owner curr thread if storage null storage lock object this return true else long curr time system current time millis if curr time start time curr time start time if start time timeout curr time return false wait start time timeout curr time catch interrupted exception x return false exclusivelock currthread currentthread starttime currenttimemillis currthread nwriters nreaders nwriters nwriters currthread lockobject currtime currenttimemillis currtime starttime currtime starttime starttime currtime starttime currtime interruptedexception public synchronized void unlock if n writers 0 if n writers 0 owner null notify all else if n readers 0 if n readers 0 notify all nwriters nwriters notifyall nreaders nreaders notifyall public synchronized void reset if n writers 0 n writers 0 n readers 0 owner null else if n readers 0 n readers 1 notify all nwriters nwriters nreaders nreaders nreaders notifyall public persistent resource persistentresource public persistent resource public persistent resource storage storage super storage persistentresource persistentresource call this function before ask server socket return true is ssl is available public static boolean available return ssf null serversocket configure ssl support param ssl config public static void init sub config ssl config int config item order 0 tracks config parameters related to a ssl ssl config register ssl enable false config item order true true ssl enable ssl enable long new boolean callback override public boolean get return enable override public void set boolean new value throws invalid config value exception if get equals new value enable new value if enable try load key store createssl context catch exception e enable false e print stack trace system out throw new invalid config value exception cannot enabled ssl config error else ssf null key store null ssl config register ssl key store datastore certs config item order true true ssl key store ssl key store long new string callback override public string get return key store override public void set string new key store throws invalid config value exception if new key store equals get string old key store key store key store new key store try load key store catch exception e key store old key store e print stack trace system out throw new invalid config value exception cannot change keystore file ssl config register ssl key store pass freenet config item order true true ssl key store pass ssl key store pass long new string callback override public string get return key store pass override public void set string new key store pass throws invalid config value exception if new key store pass equals get string old key store pass key store pass key store pass new key store pass try store key store catch exception e key store pass old key store pass e print stack trace system out throw new invalid config value exception cannot change keystore password ssl config register ssl key pass freenet config item order true true ssl key pass ssl key pass long new string callback override public string get return key pass override public void set string new key pass throws invalid config value exception if new key pass equals get string old key pass key pass key pass new key pass try certificate chain keystore get certificate chain freenet key priv key keystore get key freenet old key pass to char array keystore set key entry freenet priv key key pass to char array chain createssl context catch exception e key pass old key pass e print stack trace system out throw new invalid config value exception cannot change private key password ssl config register ssl version ss lv3 config item order true true ssl version ssl version long new string callback override public string get return version override public void set string new version throws invalid config value exception if new version equals get string old version version version new version try createssl context catch exception e version old version e print stack trace system out throw new invalid config value exception cannot change ssl version wrong value enable ssl config get boolean ssl enable key store ssl config get string ssl key store key store pass ssl config get string ssl key store pass key pass ssl config get string ssl key pass version ssl config get string ssl version try keystore key store get instance pkcs12 load key store createssl context catch exception e logger error ssl class cannot load keystore ssl is disable e sslconfig subconfig sslconfig configitemorder sslconfig sslenable configitemorder enablelong booleancallback newvalue invalidconfigvalueexception newvalue newvalue loadkeystore createsslcontext printstacktrace invalidconfigvalueexception keystore sslconfig sslkeystore configitemorder keystore keystorelong stringcallback keystore newkeystore invalidconfigvalueexception newkeystore oldkeystore keystore keystore newkeystore loadkeystore keystore oldkeystore printstacktrace invalidconfigvalueexception sslconfig sslkeystorepass configitemorder keystorepass keystorepasslong stringcallback keystorepass newkeystorepass invalidconfigvalueexception newkeystorepass oldkeystorepass keystorepass keystorepass newkeystorepass storekeystore keystorepass oldkeystorepass printstacktrace invalidconfigvalueexception sslconfig sslkeypass configitemorder keypass keypasslong stringcallback keypass newkeypass invalidconfigvalueexception newkeypass oldkeypass keypass keypass newkeypass getcertificatechain privkey getkey oldkeypass tochararray setkeyentry privkey keypass tochararray createsslcontext keypass oldkeypass printstacktrace invalidconfigvalueexception sslconfig sslversion sslv3 configitemorder versionlong stringcallback newversion invalidconfigvalueexception newversion oldversion newversion createsslcontext oldversion printstacktrace invalidconfigvalueexception sslconfig getboolean sslenable keystore sslconfig getstring sslkeystore keystorepass sslconfig getstring sslkeystorepass keypass sslconfig getstring sslkeypass sslconfig getstring sslversion keystore getinstance loadkeystore createsslcontext new boolean callback override public boolean get return enable booleancallback override public void set boolean new value throws invalid config value exception if get equals new value enable new value if enable try load key store createssl context catch exception e enable false e print stack trace system out throw new invalid config value exception cannot enabled ssl config error else ssf null key store null newvalue invalidconfigvalueexception newvalue newvalue loadkeystore createsslcontext printstacktrace invalidconfigvalueexception keystore new string callback override public string get return key store stringcallback keystore override public void set string new key store throws invalid config value exception if new key store equals get string old key store key store key store new key store try load key store catch exception e key store old key store e print stack trace system out throw new invalid config value exception cannot change keystore file newkeystore invalidconfigvalueexception newkeystore oldkeystore keystore keystore newkeystore loadkeystore keystore oldkeystore printstacktrace invalidconfigvalueexception new string callback override public string get return key store pass stringcallback keystorepass override public void set string new key store pass throws invalid config value exception if new key store pass equals get string old key store pass key store pass key store pass new key store pass try store key store catch exception e key store pass old key store pass e print stack trace system out throw new invalid config value exception cannot change keystore password newkeystorepass invalidconfigvalueexception newkeystorepass oldkeystorepass keystorepass keystorepass newkeystorepass storekeystore keystorepass oldkeystorepass printstacktrace invalidconfigvalueexception new string callback override public string get return key pass stringcallback keypass override public void set string new key pass throws invalid config value exception if new key pass equals get string old key pass key pass key pass new key pass try certificate chain keystore get certificate chain freenet key priv key keystore get key freenet old key pass to char array keystore set key entry freenet priv key key pass to char array chain createssl context catch exception e key pass old key pass e print stack trace system out throw new invalid config value exception cannot change private key password newkeypass invalidconfigvalueexception newkeypass oldkeypass keypass keypass newkeypass getcertificatechain privkey getkey oldkeypass tochararray setkeyentry privkey keypass tochararray createsslcontext keypass oldkeypass printstacktrace invalidconfigvalueexception new string callback override public string get return version stringcallback override public void set string new version throws invalid config value exception if new version equals get string old version version version new version try createssl context catch exception e version old version e print stack trace system out throw new invalid config value exception cannot change ssl version wrong value newversion invalidconfigvalueexception newversion oldversion newversion createsslcontext oldversion printstacktrace invalidconfigvalueexception create server socket with ssl support return server socket with ssl support throws io exception public static server socket create server socket throws io exception if ssf null throw new io exception ssl not initialized return ssf create server socket serversocket serversocket ioexception serversocket createserversocket ioexception ioexception createserversocket private static void load key store throws exception if enable a keystore is where keys and certificates are kept both the keystore and individual private keys should be password protected file input stream fis null try fis new file input stream key store keystore load fis key store pass to char array catch file not found exception fnfe if keystore not exist create keystore and server certificate keystore load null key store pass to char array try class cert and key gen clazz class for name sun security x509 cert and key gen constructor cert and key gen ctor cert and key gen clazz get constructor string class string class object keypair cert and key gen ctor new instance dsa sha1 withdsa class x500 name clazz class for name sun security x509 x500 name constructor x500 name ctor x500 name clazz get constructor string class string class string class string class string class string class object x500 name x500 name ctor new instance freenet freenet freenet method cert and key gen generate cert and key gen clazz get method generate int class cert and key gen generate invoke keypair 1024 method cert and key get private key cert and key gen clazz get method get private key private key priv key private key cert and key get private key invoke keypair certificate chain new certificate 1 method cert and key gen get self certificate cert and key gen clazz get method get self certificate x500 name clazz long class chain 0 certificate cert and key gen get self certificate invoke keypair x500 name 1l 365 24 60 60 keystore set key entry freenet priv key key pass to char array chain store key store createssl context catch class not found exception cnfe throw new unsupported operation exception the jvm you are using is not supported cnfe catch no such method exception nsme throw new unsupported operation exception the jvm you are using is not supported nsme finally closer close fis loadkeystore fileinputstream fileinputstream keystore keystorepass tochararray filenotfoundexception keystorepass tochararray certandkeygenclazz forname certandkeygen certandkeygenctor certandkeygenclazz getconstructor certandkeygenctor newinstance sha1withdsa x500nameclazz forname x500name x500namector x500nameclazz getconstructor x500name x500namector newinstance certandkeygengenerate certandkeygenclazz getmethod certandkeygengenerate certandkeygetprivatekey certandkeygenclazz getmethod getprivatekey privatekey privkey privatekey certandkeygetprivatekey certandkeygengetselfcertificate certandkeygenclazz getmethod getselfcertificate x500nameclazz certandkeygengetselfcertificate x500name setkeyentry privkey keypass tochararray storekeystore createsslcontext classnotfoundexception unsupportedoperationexception nosuchmethodexception unsupportedoperationexception private static void store key store throws exception if enable file output stream fos null try fos new file output stream key store keystore store fos key store pass to char array finally closer close fos storekeystore fileoutputstream fileoutputstream keystore keystorepass tochararray private static void createssl context throws exception if enable a key manager factory is used to create key managers key manager factory kmf key manager factory get instance sunx509 initialize the key manager factory to work with our keystore kmf init keystore key pass to char array an ssl context is an environment for implementing jsse it is used to create a server socket factory ssl context sslc ssl context get instance version initialize the ssl context to work with our key managers sslc init kmf get key managers null null ssf sslc get server socket factory createsslcontext keymanagerfactory keymanagerfactory keymanagerfactory getinstance keymanagerfactory keypass tochararray sslcontext serversocketfactory sslcontext sslcontext getinstance sslcontext getkeymanagers getserversocketfactory encode a string for inclusion in a uri param url string to encode param force list of characters in the form of a string which must be encoded as well as the built in param ascii if true encode all foreign letters if false leave them as is set to true if you are passing to something that needs ascii e g http headers set to false if you are using in an html page return encoded version of string public final static string encode string url string force boolean ascii string builder enc new string builder url length for int i 0 i url length i char c url char at i if safeurl characters index of c 0 ascii c 0200 force null force index of c 0 enc append c else try byte encoded c get bytes utf 8 for int j 0 j encoded length j byte b encoded j int x b 0xff if x 16 enc append 0 else enc append enc append integer to hex string x catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e return enc to string stringbuilder stringbuilder charat safeurlcharacters indexof indexof getbytes tohexstring unsupportedencodingexception tostring encode a string for inclusion in a uri param url string to encode param ascii if true encode all foreign letters if false leave them as is set to true if you are passing to something that needs ascii e g http headers set to false if you are using in an html page return encoded version of string public static string encode string s boolean ascii return encode s null ascii protected connectivity toadlet high level simple client client node node node client core core super client this node node this core core connectivitytoadlet highlevelsimpleclient nodeclientcore override public string supported methods return get supportedmethods override public void handle get uri uri final http request request toadlet context ctx throws toadlet context closed exception io exception page maker page maker ctx get page maker html node page node page maker get page node l10n get string connectivity toadlet title new string node name new string core get my name ctx html node content node page maker get content node page node add alert summary box if ctx is allowed full access content node add child core alerts create summary final int mode ctx get page maker draw mode selection array core request content node add connection type box node ip detector add connection type box content node udp socket handler handlers node get packet socket handlers html node summary box page maker get infobox l10n get string connectivity toadlet summary title content node add child summary box html node summary content page maker get content node summary box html node table summary content add child table border 0 for int i 0 i handlers length i udp socket handler handler handlers i address tracker tracker handlers i get address tracker html node row table add child tr row add child td handler get title row add child td address tracker status string tracker get port forward status if mode page maker mode advanced one box per port string noreply l10n noreply string local l10n local string remote l10n remote long now system current time millis for int i 0 i handlers length i peers address tracker tracker handlers i get address tracker html node ports box page maker get infobox l10n get string connectivity toadlet by port title new string port status tunnel length new string handlers i get title address tracker status string tracker get port forward status time util format time tracker get longest send receive gap content node add child ports box html node ports content page maker get content node ports box peer address tracker item items tracker get peer address tracker items table ports content add child table html node row table add child tr row add child th l10n address title row add child th l10n sent received title row add child th l10n local remote title row add child th l10n first send lead time row add child th l10n first receive lead time for int j 0 j address tracker item track gaps j row add child th fixme is th valid for int j 0 j items length j row table add child tr peer address tracker item item items j address row add child td item peer to string sent received packets row add child td item packets sent item packets received initiator local remote fixme something more graphical e g colored cells row add child td item packets received 0 noreply item we sent first local remote lead in time to first packet sent row add child td time util format time item time from startup to first sent packet lead in time to first packet received row add child td time util format time item time from startup to first received packet gap gaps item get gaps for int k 0 k address tracker item track gaps k row add child td gaps k received packet at 0 time util format time gaps k gap length time util format time now gaps k received packet at ago fixme l10n i ps ports box page maker get infobox l10n get string connectivity toadlet byip title new string ip status tunnel length new string handlers i get title address tracker status string tracker get port forward status time util format time tracker get longest send receive gap content node add child ports box ports content page maker get content node ports box inet address address tracker item ip items tracker get inet address tracker items table ports content add child table row table add child tr row add child th l10n address title row add child th l10n sent received title row add child th l10n local remote title row add child th l10n first send lead time row add child th l10n first receive lead time for int j 0 j address tracker item track gaps j row add child th fixme is th valid for int j 0 j ip items length j row table add child tr inet address address tracker item item ip items j address row add child td item addr to string sent received packets row add child td item packets sent item packets received initiator local remote fixme something more graphical e g colored cells row add child td item packets received 0 noreply item we sent first local remote lead in time to first packet sent row add child td time util format time item time from startup to first sent packet lead in time to first packet received row add child td time util format time item time from startup to first received packet gap gaps item get gaps for int k 0 k address tracker item track gaps k row add child td gaps k received packet at 0 time util format time gaps k gap length time util format time now gaps k received packet at ago fixme l10n writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception pagemaker pagemaker getpagemaker htmlnode pagenode pagemaker getpagenode getstring connectivitytoadlet nodename getmyname htmlnode contentnode pagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary getpagemaker drawmodeselectionarray contentnode ipdetector addconnectiontypebox contentnode udpsockethandler getpacketsockethandlers htmlnode summarybox pagemaker getinfobox getstring connectivitytoadlet summarytitle contentnode addchild summarybox htmlnode summarycontent pagemaker getcontentnode summarybox htmlnode summarycontent addchild udpsockethandler addresstracker getaddresstracker htmlnode addchild addchild gettitle addchild addresstracker statusstring getportforwardstatus pagemaker mode_advanced currenttimemillis addresstracker getaddresstracker htmlnode portsbox pagemaker getinfobox getstring connectivitytoadlet byporttitle tunnellength gettitle addresstracker statusstring getportforwardstatus timeutil formattime getlongestsendreceivegap contentnode addchild portsbox htmlnode portscontent pagemaker getcontentnode portsbox peeraddresstrackeritem getpeeraddresstrackeritems portscontent addchild htmlnode addchild addchild addresstitle addchild sentreceivedtitle addchild localremotetitle addchild firstsendleadtime addchild firstreceiveleadtime addresstrackeritem track_gaps addchild addchild peeraddresstrackeritem addchild tostring addchild packetssent packetsreceived addchild packetsreceived wesentfirst addchild timeutil formattime timefromstartuptofirstsentpacket addchild timeutil formattime timefromstartuptofirstreceivedpacket getgaps addresstrackeritem track_gaps addchild receivedpacketat timeutil formattime gaplength timeutil formattime receivedpacketat ips portsbox pagemaker getinfobox getstring connectivitytoadlet byiptitle tunnellength gettitle addresstracker statusstring getportforwardstatus timeutil formattime getlongestsendreceivegap contentnode addchild portsbox portscontent pagemaker getcontentnode portsbox inetaddressaddresstrackeritem ipitems getinetaddresstrackeritems portscontent addchild addchild addchild addresstitle addchild sentreceivedtitle addchild localremotetitle addchild firstsendleadtime addchild firstreceiveleadtime addresstrackeritem track_gaps addchild ipitems addchild inetaddressaddresstrackeritem ipitems addchild tostring addchild packetssent packetsreceived addchild packetsreceived wesentfirst addchild timeutil formattime timefromstartuptofirstsentpacket addchild timeutil formattime timefromstartuptofirstreceivedpacket getgaps addresstrackeritem track_gaps addchild receivedpacketat timeutil formattime gaplength timeutil formattime receivedpacketat writehtmlreply pagenode private string l10n string key return l10n get string connectivity toadlet key getstring connectivitytoadlet css parser reader r writer w boolean paranoid string check filter callback cb super r w paranoid string check this cb cb this delete errors super delete errors cssparser paranoidstringcheck filtercallback paranoidstringcheck deleteerrors deleteerrors override void throw error string s throws data filter exception html filter throw filter exception s throwerror datafilterexception htmlfilter throwfilterexception override string process importurl string s throws comment exception return html filter sanitizeuri html filter strip quotes s text css null cb true processimporturl commentexception htmlfilter htmlfilter stripquotes override string processurl string s throws comment exception return html filter sanitizeuri html filter strip quotes s null null cb true commentexception htmlfilter htmlfilter stripquotes override void log string s if logger should log logger debug this logger debug this s shouldlog override void log error string s logger error this s logerror public final class boards page extends web page impl public boards page web interface my web interface ft own identity viewer http request request super my web interface viewer request todo auto generated constructor stub boardspage webpageimpl boardspage webinterface mywebinterface ftownidentity httprequest mywebinterface public final void make make boards list makeboardslist private void make boards list html node boards box add content box boards html node new board form add form child boards box self uri new board new board page new board form add child input new string type name value new string hidden own identityid m own identity getuid new board form add child input new string type name value new string submit submit new board display the list of known identities html node boards table boards box add child table border 0 html node row boards table add child tr row add child th name row add child th description row add child th messages row add child th latest message date format date format date format get instance fixme currently we show all boards we should rather show the boards which the identity has selected synchronized m freetalk get message manager iterator board boards m freetalk get message manager board iterator while boards has next board board boards next row boards table add child tr html node name cell row add child th new string align new string left name cell add child new html node a href self uri show board identity m own identity getuid name board get name board get name description row add child td new string align new string center not implemented yet message count row add child td new string align new string center integer to string board message count date of latest message row add child td new string align new string center board get latest message date null date format format board get latest message date makeboardslist htmlnode boardsbox addcontentbox htmlnode newboardform addformchild boardsbox self_uri newboard newboardpage newboardform addchild ownidentityid mownidentity newboardform addchild htmlnode boardstable boardsbox addchild htmlnode boardstable addchild addchild addchild addchild addchild dateformat dateformat dateformat getinstance mfreetalk getmessagemanager mfreetalk getmessagemanager boarditerator hasnext boardstable addchild htmlnode namecell addchild namecell addchild htmlnode self_uri showboard mownidentity getname getname addchild addchild tostring messagecount addchild getlatestmessagedate dateformat getlatestmessagedate public static void main string args throws fs parse exception peer parse exception chk encode exception invalid threshold exception node init exception reference signature verification exception interrupted exception unsupported encoding exception chk verify exception chk decode exception string name real node request insert test file wd new file name if file util remove all wd system err println mass delete failed test may not be accurate system exit exit cannot delete old data wd mkdir note global test init returns in ignored random source node starter global test init name false logger error freenet node location normal freenet node simulator real node minor freenet node insert minor freenet node request minor freenet node node minor node starter global test init name false logger error freenet node location minor freenet io comm minor freenet node node dispatcher minor freenet node simulator minor freenet node peer manager minor freenet node request sender minor node starter global test init name false logger error freenet node fnp minor freenet node packet minor freenet io comm minor freenet node peer node minor freenet node darknet peer node minor node starter global test init name false logger error true system out println busy network test inserts retrieves in quantity stress test system out println dummy random source random new dummy random source diffie hellman init random node nodes new node number of nodes logger normal real node routing test class creating nodes executor executor new pooled executor for int i 0 i number of nodes i nodes i node starter create test node 5001 i 0 name false true false max htl 20 5 random executor 500 number of nodes chk block data length chk block total headers length 100 true enable swapping false enable ulprs enable per node failure tables enable swap queueing enable packet coalescing 8000 enable foaf false null logger normal real node routing test class created node i now link them up make kleinberg network nodes start with ideal locations degree force neighbour connections logger normal real node routing test class added random links for int i 0 i number of nodes i nodes i start false system err println started node i nodes length wait for all connected nodes wait for ping average 0 95 nodes random max pings 1000 system out println system out println ping average 95 lets do some inserts requests system out println high level simple client clients new high level simple client nodes length for int i 0 i clients length i clients i nodes i client core make client request starter immediate splitfile priority class insert 100 keys into random nodes clientchk keys new clientchk insert keys string base string system current time millis for int i 0 i insert keys i system err println inserting i of insert keys int node1 random next int number of nodes node random node nodes node1 string data string base string i byte data data string get bytes utf 8 clientchk block block block clientchk block encode data false false short 1 0 clientchk chk clientchk block get client key byte enc data block get data byte enc headers block get headers clientchk block new block new clientchk block enc data enc headers chk true keys i chk logger minor real node request insert test class decoded new string new block memory decode logger normal real node request insert test class chk chk geturi logger minor real node request insert test class headers hex util bytes to hex block get headers insert it try random node client core real put block true logger error real node request insert test class inserted to node1 logger minor real node request insert test class data fields hash code enc data headers fields hash code enc headers catch freenet node low level put exception put ex logger error real node request insert test class insert failed put ex system err println insert failed put ex system exit exit insert failed now queue requests for each key on every node for int i 0 i insert keys i clientchk key keys i system err println queueing requests for i of insert keys for int j 0 j nodes length j clients j prefetch key geturi 24 60 60 1000 32768 null long total running requests 0 for int j 0 j nodes length j total running requests nodes j client core count transient queued requests system err println running requests total running requests now wait until finished how while true long total running requests 0 for int i 0 i nodes length i total running requests nodes i client core count transient queued requests system err println running requests total running requests if total running requests 0 break thread sleep 1000 system exit 0 fsparseexception peerparseexception chkencodeexception invalidthresholdexception nodeinitexception referencesignatureverificationexception interruptedexception unsupportedencodingexception chkverifyexception chkdecodeexception realnoderequestinserttest fileutil removeall exit_cannot_delete_old_data globaltestinit nodestarter globaltestinit realnode nodestarter globaltestinit nodedispatcher peermanager requestsender nodestarter globaltestinit peernode darknetpeernode nodestarter globaltestinit dummyrandomsource dummyrandomsource diffiehellman number_of_nodes realnoderoutingtest pooledexecutor number_of_nodes nodestarter createtestnode max_htl number_of_nodes chkblock data_length chkblock total_headers_length enable_swapping enable_ulprs enable_per_node_failure_tables enable_swap_queueing enable_packet_coalescing enable_foaf realnoderoutingtest makekleinbergnetwork start_with_ideal_locations force_neighbour_connections realnoderoutingtest number_of_nodes waitforallconnected waitforpingaverage max_pings highlevelsimpleclient highlevelsimpleclient clientcore makeclient requeststarter immediate_splitfile_priority_class insert_keys basestring currenttimemillis insert_keys insert_keys nextint number_of_nodes randomnode datastring basestring datastring getbytes clientchkblock clientchkblock getclientkey encdata getdata encheaders getheaders clientchkblock newblock clientchkblock encdata encheaders realnoderequestinserttest newblock memorydecode realnoderequestinserttest realnoderequestinserttest hexutil bytestohex getheaders randomnode clientcore realput realnoderequestinserttest realnoderequestinserttest hashcode encdata hashcode encheaders lowlevelputexception putex realnoderequestinserttest putex putex exit_insert_failed insert_keys insert_keys totalrunningrequests totalrunningrequests clientcore counttransientqueuedrequests totalrunningrequests totalrunningrequests totalrunningrequests clientcore counttransientqueuedrequests totalrunningrequests totalrunningrequests public abstract class storage listener this metod is called during database open when database was not close normally and has to be recovered storagelistener public void database corrupted this method is called after completion of recovery public void recovery completed databasecorrupted recoverycompleted this method is called when garbage collection is started ether explicitly by invocation of storage gc method either implicitly after allocation of some amount of memory this method is called when unreferenced object is deallocated from database it is possible to get instance of the object using code storage get object by oid code method param cls class of deallocated object param oid object identifier of deallocated object getobjectbyoid this method is called when garbage collection is completed param n deallocated objects number of deallocated objects ndeallocatedobjects handle replication error param host address of host replication to which is failed null if error jappens at slave node return code true code if host should be reconnected and attempt to send data to it should be repeated code false code if no more attmpts to communicate with this host should be performed public boolean replication error string host return false replicationerror this method is called when runtime error happen during execution of jsql query public void jsql runtime error jsql runtime exception x jsqlruntimeerror jsqlruntimeexception sequential search is performed for query execution param query execfuted query public void sequential search performed string query sequentialsearchperformed this method is called by xml exporter if database correuption or some other reasons makes export of the object not possible param oid object identified param x catched exception public class grayscale colormap implements colormap public grayscale colormap grayscalecolormap grayscalecolormap convert a value in the range 0 1 to an rgb color param v a value in the range 0 1 return an rgb color public int get color float v int n int v 255 if n 0 n 0 else if n 255 n 255 return 0xff000000 n 16 n 8 n getcolor public persistent put string identifier freeneturi uri int verbosity short priority class short upload from freeneturi targeturi short persistence type file orig filename string mime type boolean global long size string client token boolean started int max retries string target filename boolean binary blob this identifier identifier this uri uri this verbosity verbosity this priority class priority class this upload from upload from this targeturi targeturi this persistence type persistence type this orig filename orig filename this mime type mime type this global global this size size this token client token this started started this max retries max retries this target filename target filename this binary blob binary blob persistentput priorityclass uploadfrom persistencetype origfilename mimetype clienttoken maxretries targetfilename binaryblob priorityclass priorityclass uploadfrom uploadfrom persistencetype persistencetype origfilename origfilename mimetype mimetype clienttoken maxretries maxretries targetfilename targetfilename binaryblob binaryblob override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put single uri uri to string false false fs put verbosity verbosity fs put priority class priority class fs put single upload from client put message upload from string upload from fs put single persistence client request persistence type string persistence type if orig filename null fs put single filename orig filename get absolute path if targeturi null fs put single targeturi targeturi to string if mime type null fs put single metadata content type mime type fs put global global if size 1 fs put data length size if token null fs put single client token token fs put started started fs put max retries max retries if target filename null fs put single target filename target filename if binary blob fs put binary blob binary blob return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring priorityclass priorityclass putsingle uploadfrom clientputmessage uploadfromstring uploadfrom putsingle clientrequest persistencetypestring persistencetype origfilename putsingle origfilename getabsolutepath putsingle tostring mimetype putsingle contenttype mimetype datalength putsingle clienttoken maxretries maxretries targetfilename putsingle targetfilename targetfilename binaryblob binaryblob binaryblob override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message persistent put goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message persistentput override public void remove from object container container container activate uri 5 uri remove from container container activate orig filename 5 container delete orig filename container activate targeturi 5 targeturi remove from container container delete this removefrom objectcontainer removefrom origfilename origfilename removefrom public sub config string prefix config config this config config this prefix prefix map new linked hash map string option has initialized false config register this subconfig linkedhashmap hasinitialized return all the options registered each includes its name used by e g webconfig public synchronized option get options return map values to array new option map size getoptions toarray public synchronized option get option string option return map get option getoption public void register option o synchronized this if o name index of simple field set multi level char 1 throw new illegal argument exception option names must not contain simple field set multi level char if map contains key o name throw new illegal argument exception already registered o name on this map put o name o config on register this o indexof simplefieldset multi_level_char illegalargumentexception simplefieldset multi_level_char containskey illegalargumentexception onregister public void register string option name int default value int sort order boolean expert boolean force write string short desc string long desc int callback cb boolean is size if cb null cb new null int callback register new int option this option name default value sort order expert force write short desc long desc cb is size optionname defaultvalue sortorder forcewrite shortdesc longdesc intcallback issize nullintcallback intoption optionname defaultvalue sortorder forcewrite shortdesc longdesc issize public void register string option name long default value int sort order boolean expert boolean force write string short desc string long desc long callback cb boolean is size if cb null cb new null long callback register new long option this option name default value sort order expert force write short desc long desc cb is size optionname defaultvalue sortorder forcewrite shortdesc longdesc longcallback issize nulllongcallback longoption optionname defaultvalue sortorder forcewrite shortdesc longdesc issize public void register string option name string default value string int sort order boolean expert boolean force write string short desc string long desc int callback cb boolean is size if cb null cb new null int callback register new int option this option name default value string sort order expert force write short desc long desc cb is size optionname defaultvaluestring sortorder forcewrite shortdesc longdesc intcallback issize nullintcallback intoption optionname defaultvaluestring sortorder forcewrite shortdesc longdesc issize public void register string option name string default value string int sort order boolean expert boolean force write string short desc string long desc long callback cb boolean is size if cb null cb new null long callback register new long option this option name default value string sort order expert force write short desc long desc cb is size optionname defaultvaluestring sortorder forcewrite shortdesc longdesc longcallback issize nulllongcallback longoption optionname defaultvaluestring sortorder forcewrite shortdesc longdesc issize public void register string option name boolean default value int sort order boolean expert boolean force write string short desc string long desc boolean callback cb if cb null cb new null boolean callback register new boolean option this option name default value sort order expert force write short desc long desc cb optionname defaultvalue sortorder forcewrite shortdesc longdesc booleancallback nullbooleancallback booleanoption optionname defaultvalue sortorder forcewrite shortdesc longdesc public void register string option name string default value int sort order boolean expert boolean force write string short desc string long desc string callback cb if cb null cb new null string callback register new string option this option name default value sort order expert force write short desc long desc cb optionname defaultvalue sortorder forcewrite shortdesc longdesc stringcallback nullstringcallback stringoption optionname defaultvalue sortorder forcewrite shortdesc longdesc public void register string option name short default value int sort order boolean expert boolean force write string short desc string long desc short callback cb boolean is size if cb null cb new null short callback register new short option this option name default value sort order expert force write short desc long desc cb is size optionname defaultvalue sortorder forcewrite shortdesc longdesc shortcallback issize nullshortcallback shortoption optionname defaultvalue sortorder forcewrite shortdesc longdesc issize public void register string option name string default value int sort order boolean expert boolean force write string short desc string long desc string arr callback cb register new string arr option this option name default value sort order expert force write short desc long desc cb optionname defaultvalue sortorder forcewrite shortdesc longdesc stringarrcallback stringarroption optionname defaultvalue sortorder forcewrite shortdesc longdesc public int get int string option name int option o synchronized this o int option map get option name return o get value getint optionname intoption intoption optionname getvalue public long get long string option name long option o synchronized this o long option map get option name return o get value getlong optionname longoption longoption optionname getvalue public boolean get boolean string option name boolean option o synchronized this o boolean option map get option name return o get value getboolean optionname booleanoption booleanoption optionname getvalue public string get string string option name string option o synchronized this o string option map get option name return o get value trim getstring optionname stringoption stringoption optionname getvalue public string get string arr string option name string arr option o synchronized this o string arr option map get option name return o get value getstringarr optionname stringarroption stringarroption optionname getvalue public short get short string option name short option o synchronized this o short option map get option name return o get value getshort optionname shortoption shortoption optionname getvalue has the object we are attached to finished initialization public boolean has finished initialization return has initialized hasfinishedinitialization hasinitialized called when the object we are attached to has finished init after this point the callbacks are authoritative for values of config variables and will be called when values are changed by the user public void finished initialization has initialized true if logger should log logger minor this logger minor this finished initialization on this prefix finishedinitialization hasinitialized shouldlog set options from a simple field set once we process an option we must remove it public void set options simple field set sfs set map entry string option entry set map entry set iterator entry string option i entry set iterator while i has next entry string option entry i next string key entry get key option o entry get value string val sfs get key if val null try o set value val catch invalid config value exception e string msg invalid config value prefix simple field set multi level char key val error e logger error this msg e system err println msg might be about logging catch node need restart exception e impossible string msg impossible prefix simple field set multi level char key val error e logger error this msg e simplefieldset setoptions simplefieldset entryset entryset entryset hasnext getkey getvalue setvalue invalidconfigvalueexception simplefieldset multi_level_char nodeneedrestartexception simplefieldset multi_level_char public simple field set export field set return export field set false simplefieldset exportfieldset exportfieldset public simple field set export field set boolean with defaults return export field set config request type current settings with defaults simplefieldset exportfieldset withdefaults exportfieldset requesttype current_settings withdefaults public simple field set export field set config request type config request type boolean with defaults simple field set fs new simple field set true suppress warnings unchecked map entry string option entries new map entry map size fixme is any locking at all necessary here after it has finished init it s constant synchronized this entries map entry set to array entries boolean logminor logger should log logger minor this if logminor logger minor this prefix prefix for int i 0 i entries length i map entry string option entry entries i string key entry get key option o entry get value if logminor logger minor this key key value o get value string default o is default if config request type config request type current settings with defaults o is default o force write if logminor logger minor this skipping key o is default continue switch config request type case current settings fs put single key o get value string break case default settings fs put single key o get default break case sort order fs put key o get sort order break case expert flag fs put key o is expert break case force write flag fs put key o is forced write break case short description fs put single key l10n get string o get short desc break case long description fs put single key l10n get string o get long desc break case data type fs put single key o get data type str break default logger error this unknown config request type value config request type break if logminor logger minor this key prefix key value o get value string return fs simplefieldset exportfieldset requesttype configrequesttype withdefaults simplefieldset simplefieldset suppresswarnings entryset toarray shouldlog getkey getvalue getvaluestring isdefault configrequesttype requesttype current_settings withdefaults isdefault forcewrite isdefault configrequesttype current_settings putsingle getvaluestring default_settings putsingle getdefault sort_order getsortorder expert_flag isexpert force_write_flag isforcedwrite short_description putsingle getstring getshortdesc long_description putsingle getstring getlongdesc data_type putsingle getdatatypestr configrequesttype getvaluestring force an option to be updated even if it hasn t changed throws invalid config value exception throws node need restart exception public void force update string option name throws invalid config value exception node need restart exception option o map get option name o force update invalidconfigvalueexception nodeneedrestartexception forceupdate optionname invalidconfigvalueexception nodeneedrestartexception optionname forceupdate public void set string name string value throws invalid config value exception node need restart exception option o map get name o set value value invalidconfigvalueexception nodeneedrestartexception setvalue public void set string name boolean value throws invalid config value exception node need restart exception boolean option o boolean option map get name o set value invalidconfigvalueexception nodeneedrestartexception booleanoption booleanoption if the option s value is equal to the provided old default then set it to the new default used to deal with changes to important options where this is not handled automatically because the option s value is written to the ini param name the name of the option param value the value of the option public void fix old default string name string value option o map get name if o get value string equals value o set default fixolddefault getvaluestring setdefault if the option s value matches the provided old default regex then set it to the new default used to deal with changes to important options where this is not handled automatically because the option s value is written to the ini param name the name of the option param value the value of the option public void fix old default regex string name string value option o map get name if o get value string matches value o set default fixolddefaultregex getvaluestring setdefault public string get prefix return prefix getprefix public int compare to sub config second if this get prefix compare to second get prefix 0 return 1 else return 1 compareto subconfig getprefix compareto getprefix public string get raw option string name if config instanceof persistent config persistent config pc persistent config config if pc finished init throw new illegal state exception get raw option name on this but persistent config has been finished init already simple field set fs pc orig config file contents if fs null return null return fs get prefix simple field set multi level char name else return null getrawoption persistentconfig persistentconfig persistentconfig finishedinit illegalstateexception getrawoption finishedinit simplefieldset origconfigfilecontents simplefieldset multi_level_char public node update manager node node config config throws invalid config value exception logminor logger should log logger minor this this node node this has been blown false should update ext node starter ext build number node starter recommended ext build number this alert new updated version available user alert this alert is valid false sub config updater config new sub config node updater config updater config register enabled wrapper manager is controlled by native wrapper 1 true false node update manager enabled node update manager enabled long new updater enabled callback was enabled on startup updater config get boolean enabled is the auto update allowed updater config register autoupdate false 2 false true node update manager install new versions node update manager install new versions long new auto update allowed callback is auto update allowed updater config get boolean autoupdate updater config register uri update uri 3 true false node update manager updateuri node update manager updateuri long new updateuri callback false try updateuri new freeneturi updater config get string uri long ver updateuri get suggested edition if ver version build number ver version build number updateuri updateuri set suggested edition ver catch malformedurl exception e throw new invalid config value exception l10n invalid updateuri error e get localized message updater config register revocationuri revocation uri 4 true false node update manager revocationuri node update manager revocationuri long new update revocationuri callback try revocationuri new freeneturi updater config get string revocationuri catch malformedurl exception e throw new invalid config value exception l10n invalid revocationuri error e get localized message updater config register exturi ext uri 5 true false node update manager exturi node update manager exturi long new updateuri callback true try exturi new freeneturi updater config get string exturi long ver exturi get suggested edition if ver node starter ext build number ver node starter ext build number exturi exturi set suggested edition ver catch malformedurl exception e throw new invalid config value exception l10n invalid exturi error e get localized message updater config finished initialization this revocation checker new revocation checker this new file node client core get persistent temp dir revocation key fblob this uom new update over mandatory manager this this uom remove old temp files max ext version node starter recommended ext build number min ext version node starter required ext build number nodeupdatemanager invalidconfigvalueexception shouldlog hasbeenblown shouldupdateext nodestarter extbuildnumber nodestarter recommended_ext_build_number updatedversionavailableuseralert isvalid subconfig updaterconfig subconfig updaterconfig wrappermanager iscontrolledbynativewrapper nodeupdatemanager nodeupdatemanager enabledlong updaterenabledcallback wasenabledonstartup updaterconfig getboolean updaterconfig nodeupdatemanager installnewversions nodeupdatemanager installnewversionslong autoupdateallowedcallback isautoupdateallowed updaterconfig getboolean updaterconfig update_uri nodeupdatemanager nodeupdatemanager updateurilong updateuricallback updaterconfig getstring getsuggestededition buildnumber buildnumber setsuggestededition malformedurlexception invalidconfigvalueexception invalidupdateuri getlocalizedmessage updaterconfig revocation_uri nodeupdatemanager nodeupdatemanager revocationurilong updaterevocationuricallback updaterconfig getstring malformedurlexception invalidconfigvalueexception invalidrevocationuri getlocalizedmessage updaterconfig ext_uri nodeupdatemanager nodeupdatemanager exturilong updateuricallback updaterconfig getstring getsuggestededition nodestarter extbuildnumber nodestarter extbuildnumber setsuggestededition malformedurlexception invalidconfigvalueexception invalidexturi getlocalizedmessage updaterconfig finishedinitialization revocationchecker revocationchecker clientcore getpersistenttempdir updateovermandatorymanager removeoldtempfiles maxextversion nodestarter recommended_ext_build_number minextversion nodestarter required_ext_build_number public void start throws invalid config value exception node client core alerts register alert enable was enabled on startup invalidconfigvalueexception clientcore wasenabledonstartup void broadcastuom announces message msg synchronized broadcastuom announces sync msg getuom announcement broadcastuom announces true node peers local broadcast msg true true ctr broadcastuomannounces broadcastuomannouncessync getuomannouncement broadcastuomannounces localbroadcast private message getuom announcement return dmt createuom announce updateuri to string exturi to string revocationuri to string has been blown main updater null 1 main updater get fetched version ext updater null 1 ext updater get fetched version revocation checker last succeeded delta revocation checker get revocationdnf counter revocation checker get blob size main updater null 1 main updater get blob size ext updater null 1 ext updater get blob size int node node stats get node average ping time int node node stats get bwlimit delay time getuomannouncement createuomannounce tostring tostring tostring hasbeenblown mainupdater mainupdater getfetchedversion extupdater extupdater getfetchedversion revocationchecker lastsucceededdelta revocationchecker getrevocationdnfcounter revocationchecker getblobsize mainupdater mainupdater getblobsize extupdater extupdater getblobsize nodestats getnodeaveragepingtime nodestats getbwlimitdelaytime public void maybe senduom announce peer node peer synchronized broadcastuom announces sync if broadcastuom announces return nothing worth announcing yet synchronized this if has been blown main updater null main updater get fetched version 0 return try peer send async getuom announcement null ctr catch not connected exception e sad but ignore it maybesenduomannounce peernode broadcastuomannouncessync broadcastuomannounces hasbeenblown mainupdater mainupdater getfetchedversion sendasync getuomannouncement notconnectedexception is auto update enabled public synchronized boolean is enabled return main updater null isenabled mainupdater enable or disable auto update param enable whether auto update should be enabled throws invalid config value exception if enable true and we are not running under the wrapper void enable boolean enable throws invalid config value exception logminor logger should log logger minor this if node is using wrapper logger normal this don t try to start the updater as we are not running under the wrapper return node updater main null ext null synchronized this boolean enabled main updater null if enabled enable return if enable kill it main updater pre kill main main updater main updater null if ext updater null ext updater pre kill ext ext updater ext updater null else if wrapper manager is controlled by native wrapper node starter ext build number 1 logger error this cannot update because not running under wrapper throw new invalid config value exception l10n no update without wrapper start it main updater new node updater this updateuri false version build number 1 integer max value main jar ext updater new node updater this exturi true node starter ext build number node starter required ext build number node starter recommended ext build number ext jar if enable if main null main kill if ext null ext kill revocation checker kill else main updater start if ext updater null ext updater start revocation checker start false invalidconfigvalueexception invalidconfigvalueexception shouldlog isusingwrapper nodeupdater mainupdater mainupdater prekill mainupdater mainupdater extupdater extupdater prekill extupdater extupdater wrappermanager iscontrolledbynativewrapper nodestarter extbuildnumber invalidconfigvalueexception noupdatewithoutwrapper mainupdater nodeupdater buildnumber max_value extupdater nodeupdater nodestarter extbuildnumber nodestarter required_ext_build_number nodestarter recommended_ext_build_number revocationchecker mainupdater extupdater extupdater revocationchecker create a node update manager called by node constructor param node the node object param config the global config object options will be added to a subconfig called node updater return a new node update manager throws invalid config value exception if there is an error in the config public static node update manager maybe create node node config config throws invalid config value exception return new node update manager node config nodeupdatemanager nodeupdatemanager invalidconfigvalueexception nodeupdatemanager maybecreate invalidconfigvalueexception nodeupdatemanager get the uri for either the freenet jar updater or the freenet ext jar updater param is ext if true return the freenet ext jar update uri if false return the freenet jar uri return see above public synchronized freeneturi geturi boolean is ext return is ext exturi updateuri isext isext isext set the uri for either the freenet jar updater or the freenet ext jar updater param is ext if true set the freenet ext jar update uri if false set the freenet jar update uri param uri the uri to set public void seturi boolean is ext freeneturi uri node updater updater synchronized this if is ext if exturi equals uri return exturi uri updater ext updater else if updateuri equals uri return updateuri uri updater main updater if updater null return updater on changeuri uri isext isext nodeupdater isext extupdater mainupdater onchangeuri return the revocation uri public synchronized freeneturi get revocationuri return revocationuri getrevocationuri set the revocation uri param uri the new revocation uri public void set revocationuri freeneturi uri synchronized this if revocationuri equals uri return this revocationuri uri revocation checker on change revocationuri setrevocationuri revocationchecker onchangerevocationuri return is auto update currently enabled public boolean is auto update allowed return is auto update allowed isautoupdateallowed isautoupdateallowed enable or disable auto update param val if true enable auto update and immediately update if an update is ready if false disable it public void set auto update allowed boolean val synchronized this if val is auto update allowed return is auto update allowed val if val if is ready to deploy update false return else return deploy off thread 0 setautoupdateallowed isautoupdateallowed isautoupdateallowed isreadytodeployupdate deployoffthread does the updater have an update ready to deploy may be called synchronized this private boolean is ready to deploy update boolean ignore revocation long now system current time millis long started millis ago synchronized this if has new main jar has new ext jar if logminor logger minor this has new main jar has new main jar has new ext jar has new ext jar return false no jar if has been blown return false duh if peers say blown return false don t immediately deploy if still fetching started millis ago now math max started fetching next main jar started fetching next ext jar if started millis ago wait for second fetch to complete if logminor logger minor this not ready still fetching return false wait for running fetch to complete int ext ver get ready ext if ext ver min ext version ext ver max ext version if logminor logger minor this invalid ext current ext ver must be between min ext version and max ext version return false if ignore revocation if now revocation checker last succeeded recent revocation interval return true if got jar time 0 now got jar time revocation fetch timeout return true if logminor logger minor this still here in is ready to deploy update apparently everything is ready except the revocation fetch so start it revocation checker start true if ignore revocation if logminor logger minor this returning true because of ignore revocation return true deploy off thread wait for second fetch to complete started millis ago return false isreadytodeployupdate ignorerevocation currenttimemillis startedmillisago hasnewmainjar hasnewextjar hasnewmainjar hasnewmainjar hasnewextjar hasnewextjar hasbeenblown peerssayblown startedmillisago startedfetchingnextmainjar startedfetchingnextextjar startedmillisago wait_for_second_fetch_to_complete extver getreadyext extver minextversion extver maxextversion extver minextversion maxextversion ignorerevocation revocationchecker lastsucceeded recent_revocation_interval gotjartime gotjartime revocation_fetch_timeout isreadytodeployupdate revocationchecker ignorerevocation ignorerevocation deployoffthread wait_for_second_fetch_to_complete startedmillisago check whether there is an update to deploy if there is do it private void deploy update logminor logger should log logger minor this try synchronized this if disabled this session string msg not deploying update because disabled for this session bad java version logger error this msg system err println msg return if has been blown string msg trying to update but key has been blown not updating message was revocation message logger error this msg system err println msg return if peers say blown string msg trying to update but at least one peer says the key has been blown not updating logger error this msg system err println msg return if is enabled if logminor logger minor this not enabled return if is auto update allowed armed if logminor logger minor this not armed return if is ready to deploy update false if logminor logger minor this not ready to deploy update return int ext ver get ready ext if ext ver min ext version ext ver max ext version if logminor logger minor this invalid ext current ext ver must be between min ext version and max ext version return if is deploying update if logminor logger minor this already deploying update return is deploying update true inner deploy update catch throwable t synchronized this is deploying update false deployupdate shouldlog disabledthissession hasbeenblown revocationmessage peerssayblown isenabled isautoupdateallowed isreadytodeployupdate extver getreadyext extver minextversion extver maxextversion extver minextversion maxextversion isdeployingupdate isdeployingupdate innerdeployupdate isdeployingupdate deploy the update inner method doesn t check anything just does it private void inner deploy update write the jars config etc then restart update deploy context ctx try ctx new update deploy context catch updater parser exception e fail update could not determine which jars are in use e get message return if write jars ctx restart ctx else if logminor logger minor this did not write jars innerdeployupdate updatedeploycontext updatedeploycontext updaterparserexception failupdate getmessage writejars write the updated jars if necessary rewrite the wrapper conf return true if this part of the update succeeded private boolean write jars update deploy context ctx what do we want to do here 1 if we have a new main jar if on windows write it to a new jar file update the wrapper conf to point to it otherwise write to a new jar file then move the new jar file over the old jar file 2 if we have a new ext jar write it to a new jar file update the wrapper conf to point to it boolean written new jar false boolean written new ext false boolean try easy way file path separator char has new ext jar file main jar ctx get main jar file new main jar ctx get new main jar if has new main jar written new jar true boolean written to temp file false try if new main jar exists if new main jar delete if new main jar exists system err println cannot write to preferred new jar location new main jar if try easy way try new main jar file create temp file freenet jar main jar get parent file catch io exception e fail update cannot write to any other location either disk full e return false try writing to it try main updater write jar to new main jar written to temp file true catch io exception e new main jar delete fail update cannot write new jar disk full e return false else try writing it to the new one even though we can t delete it main updater write jar to new main jar else main updater write jar to new main jar else if logminor logger minor this deleted old jar new main jar main updater write jar to new main jar else main updater write jar to new main jar catch io exception e fail update cannot update cannot write to try easy way temp file new jar new main jar return false if try easy way do it the easy way just rewrite the main jar if new main jar rename to main jar logger error this cannot rename temp file new main jar over original jar main jar if written to temp file fail the update otherwise we will leak disk space new main jar delete fail update cannot write to preferred new jar location and cannot rename temp file over old jar update failed return false try the hard way else system err println written new freenet jar main updater get written version return true easy way didn t work or we can t do the easy way try the hard way if has new ext jar written new ext true write the new ext jar file new ext jar ctx get new ext jar try ext updater write jar to new ext jar catch io exception e fail update cannot write new ext jar to new ext jar return false try ctx rewrite wrapper conf written new jar written new ext catch io exception e fail update cannot rewrite wrapper conf e return false catch update catastrophe exception e fail update e get message node client core alerts register new simple user alert false l10n update catastrophe title e get message l10n update catastrophe title user alert critical error return false catch updater parser exception e node client core alerts register new simple user alert false l10n update failed title e get message l10n update failed short reason e get message user alert critical error return false return true writejars updatedeploycontext writtennewjar writtennewext tryeasyway pathseparatorchar hasnewextjar mainjar getmainjar newmainjar getnewmainjar hasnewmainjar writtennewjar writtentotempfile newmainjar newmainjar newmainjar newmainjar tryeasyway newmainjar createtempfile mainjar getparentfile ioexception failupdate mainupdater writejarto newmainjar writtentotempfile ioexception newmainjar failupdate mainupdater writejarto newmainjar mainupdater writejarto newmainjar newmainjar mainupdater writejarto newmainjar mainupdater writejarto newmainjar ioexception failupdate tryeasyway newmainjar tryeasyway newmainjar renameto mainjar newmainjar mainjar writtentotempfile newmainjar failupdate mainupdater getwrittenversion hasnewextjar writtennewext newextjar getnewextjar extupdater writejarto newextjar ioexception failupdate newextjar rewritewrapperconf writtennewjar writtennewext ioexception failupdate updatecatastropheexception failupdate getmessage clientcore simpleuseralert updatecatastrophetitle getmessage updatecatastrophetitle useralert critical_error updaterparserexception clientcore simpleuseralert updatefailedtitle getmessage updatefailedshort getmessage useralert critical_error restart the node does not return private void restart update deploy context ctx if logminor logger minor this restarting node get node starter restart try thread sleep 5 60 1000 catch interrupted exception e break in case it s still restarting system err println failed to restart exiting please restart the node system exit node init exception exit restart failed updatedeploycontext getnodestarter interruptedexception nodeinitexception exit_restart_failed private void fail update string reason logger error this update failed reason system err println update failed reason this kill update alerts node client core alerts register new simple user alert true l10n update failed title l10n update failed reason reason l10n update failed short reason reason user alert error failupdate killupdatealerts clientcore simpleuseralert updatefailedtitle updatefailed updatefailedshort useralert private string l10n string key return l10n get string node update manager key getstring nodeupdatemanager private string l10n string key string pattern string value return l10n get string node update manager key pattern value getstring nodeupdatemanager called when a new jar has been downloaded param is ext if true the new jar is the ext jar if false it is the main jar param recommended ext if is ext is false the recommended ext version upper bound for the new jar or 1 if it was not specified or the parse failed param required ext if is ext is false the required ext version lower bound for the new jar or 1 if it was not specified or the parse failed void on downloaded new jar boolean is ext int required ext int recommended ext synchronized this if is ext if ext updater get fetched version node starter ext build number has new ext jar true started fetching next ext jar 1 got jar time system current time millis if logminor logger minor this got ext jar ext updater get fetched version else if main updater get fetched version version build number has new main jar true started fetching next main jar 1 got jar time system current time millis if logminor logger minor this got main jar main updater get fetched version if is ext if required ext 1 min ext version required ext if recommended ext 1 max ext version recommended ext if is ext required ext 1 recommended ext 1 ext updater set min max required ext recommended ext revocation checker start true deploy off thread revocation fetch timeout if is auto update allowed broadcastuom announces isext recommendedext isext requiredext isext ondownloadednewjar isext requiredext recommendedext isext extupdater getfetchedversion nodestarter extbuildnumber hasnewextjar startedfetchingnextextjar gotjartime currenttimemillis extupdater getfetchedversion mainupdater getfetchedversion buildnumber hasnewmainjar startedfetchingnextmainjar gotjartime currenttimemillis mainupdater getfetchedversion isext requiredext minextversion requiredext recommendedext maxextversion recommendedext isext requiredext recommendedext extupdater setminmax requiredext recommendedext revocationchecker deployoffthread revocation_fetch_timeout isautoupdateallowed broadcastuomannounces private int get ready ext int ver node starter ext build number int fetched ext updater get fetched version if fetched 0 ver fetched return ver getreadyext nodestarter extbuildnumber extupdater getfetchedversion called when the node updater starts to fetch a new version of the jar param is ext if true the new jar is the ext jar if false it is the main jar void on start fetching boolean is ext long now system current time millis synchronized this if is ext started fetching next ext jar now else started fetching next main jar now nodeupdater isext onstartfetching isext currenttimemillis isext startedfetchingnextextjar startedfetchingnextmainjar public void blow string msg node updater main ext synchronized this if has been blown logger error this the key has already been marked as blown message was revocation message new message msg return else this revocation message msg this has been blown true we must get to the lower part and show the user the message try system err println the auto updating system has been compromized system err println the auto updating system revocation key has been inserted it says revocation message catch throwable t try logger error this caught t t catch throwable t1 main main updater ext ext updater if main null main pre kill if ext null ext pre kill main updater null ext updater null if main null main kill if ext null ext kill if revocation alert null revocation alert new revocation key found user alert msg node client core alerts register revocation alert we don t need to advertize updates we are not going to do them kill update alerts uom kill alert broadcastuom announces nodeupdater hasbeenblown revocationmessage revocationmessage hasbeenblown revocationmessage mainupdater extupdater prekill prekill mainupdater extupdater revocationalert revocationalert revocationkeyfounduseralert clientcore revocationalert killupdatealerts killalert broadcastuomannounces kill all user alerts asking the user whether he wants to update private void kill update alerts node client core alerts unregister alert useralerts killupdatealerts clientcore called when the revocation checker has got 3 dn fs on the revocation key public void no revocation found deploy update may have been waiting for the revocation if we re still here we didn t update broadcastuom announces node ps queue timed job new runnable public void run revocation checker start false node random next int 24 60 60 1000 revocationchecker dnfs norevocationfound deployupdate broadcastuomannounces queuetimedjob revocationchecker nextint broadcastuom announces node ps queue timed job new runnable public void run revocation checker start false broadcastuomannounces queuetimedjob revocationchecker public void arm armed true deploy off thread 0 deployoffthread void deploy off thread long delay node ps queue timed job new runnable public void run if logminor logger minor this running deploy off thread try deploy update catch throwable t logger error this caught t trying to deploy off thread t if logminor logger minor this run deploy off thread delay deployoffthread queuetimedjob deployoffthread deployupdate deployoffthread deployoffthread node ps queue timed job new runnable public void run if logminor logger minor this running deploy off thread try deploy update catch throwable t logger error this caught t trying to deploy off thread t if logminor logger minor this run deploy off thread queuetimedjob deployoffthread deployupdate deployoffthread deployoffthread has the private key been revoked public boolean is blown return has been blown isblown hasbeenblown public boolean has new main jar return has new main jar hasnewmainjar hasnewmainjar public boolean has new ext jar return has new ext jar hasnewextjar hasnewextjar what version has been fetched this includes jar s fetched via uom because the uom code feeds its results through the main updater public int new main jar version if main updater null return 1 return main updater get fetched version mainupdater newmainjarversion mainupdater mainupdater getfetchedversion public int new ext jar version if ext updater null return 1 return ext updater get fetched version newextjarversion extupdater extupdater getfetchedversion public boolean fetching new main jar return main updater null main updater is fetching fetchingnewmainjar mainupdater mainupdater isfetching public boolean fetching new ext jar return ext updater null ext updater is fetching fetchingnewextjar extupdater extupdater isfetching public int fetching new main jar version if main updater null return 1 return main updater fetching version fetchingnewmainjarversion mainupdater mainupdater fetchingversion public int fetching new ext jar version if ext updater null return 1 return ext updater fetching version fetchingnewextjarversion extupdater extupdater fetchingversion public boolean in final check return is ready to deploy update true is ready to deploy update false infinalcheck isreadytodeployupdate isreadytodeployupdate public int get revocationdnf counter return revocation checker get revocationdnf counter getrevocationdnfcounter revocationchecker getrevocationdnfcounter what version is the node currently running public int get main version return version build number getmainversion buildnumber public int get ext version return node starter ext build number getextversion nodestarter extbuildnumber public boolean is armed return armed is auto update allowed isarmed isautoupdateallowed is the node able to update as soon as the revocation fetch has been completed public boolean can update now return is ready to deploy update true canupdatenow isreadytodeployupdate is the node able to update immediately i e not only is it ready in every other sense but also a revocation fetch has completed recently enough not to need another one public boolean can update immediately return is ready to deploy update false canupdateimmediately isreadytodeployupdate class updater enabled callback extends boolean callback override public boolean get return is enabled updaterenabledcallback booleancallback isenabled override public void set boolean val throws invalid config value exception enable val invalidconfigvalueexception class auto update allowed callback extends boolean callback override public boolean get return is auto update allowed autoupdateallowedcallback booleancallback isautoupdateallowed override public void set boolean val throws invalid config value exception set auto update allowed val invalidconfigvalueexception setautoupdateallowed boolean is ext updateuri callback boolean is ext this is ext is ext isext updateuricallback isext isext isext override public string get return geturi is ext to string false false isext tostring override public void set string val throws invalid config value exception freeneturi uri try uri new freeneturi val catch malformedurl exception e throw new invalid config value exception l10n is ext invalid exturi invalid updateuri error e get localized message seturi is ext uri invalidconfigvalueexception malformedurlexception invalidconfigvalueexception isext invalidexturi invalidupdateuri getlocalizedmessage isext public class update revocationuri callback extends string callback override public string get return get revocationuri to string false false updaterevocationuricallback stringcallback getrevocationuri tostring override public void set string val throws invalid config value exception freeneturi uri try uri new freeneturi val catch malformedurl exception e throw new invalid config value exception l10n invalid revocationuri error e get localized message set revocationuri uri invalidconfigvalueexception malformedurlexception invalidconfigvalueexception invalidrevocationuri getlocalizedmessage setrevocationuri called when a peer indicates in its uom announce that it has fetched the revocation key or failed to do so in a way suggesting that somebody knows the key param source the node which is claiming this void peer claims key blown peer node source note that update over mandatory manager manages the list of peers who think this all we have to do is cancel the update synchronized this peers say blown false armed false uomannounce peerclaimskeyblown peernode updateovermandatorymanager peerssayblown public file get main blob int version node updater updater synchronized this if has been blown return null updater main updater if updater null return null return updater get blob file version getmainblob nodeupdater hasbeenblown mainupdater getblobfile public file get ext blob int version node updater updater synchronized this if has been blown return null updater ext updater if updater null return null return updater get blob file version getextblob nodeupdater hasbeenblown extupdater getblobfile public synchronized long time remaining on check long now system current time millis return math max 0 revocation fetch timeout now got jar time timeremainingoncheck currenttimemillis revocation_fetch_timeout gotjartime final byte counter ctr new byte counter public void received bytes int x fixme bytecounter bytecounter receivedbytes public void sent bytes int x node node stats reportuom bytes sent x sentbytes nodestats reportuombytessent public void sent payload int x ignore it will be reported to sent bytes as well sentpayload sentbytes public void disable this session disabled this session true disablethissession disabledthissession protected long get started fetching next main jar timestamp return started fetching next main jar getstartedfetchingnextmainjartimestamp startedfetchingnextmainjar protected long get started fetching next ext jar timestamp return started fetching next ext jar getstartedfetchingnextextjartimestamp startedfetchingnextextjar public boolean object can new object container container logger error this not storing node update manager in database new exception error return false objectcannew objectcontainer nodeupdatemanager public static final short minor 0 public static string get version return major minor getversion public static long get real version return major 10000 minor getrealversion public static string get svn revision return svn revision getsvnrevision svnrevision public class default persistent comparator t extends i persistent comparable extends persistent comparator t public int compare members t m1 t m2 return m1 compare to m2 defaultpersistentcomparator ipersistent persistentcomparator comparemembers compareto public int compare member with key t mbr object key return mbr compare to key comparememberwithkey compareto private boolean wrap public offset filter this 0 0 true offsetfilter public offset filter int x offset int y offset boolean wrap this x offset x offset this y offset y offset this wrap wrap set edge action zero offsetfilter xoffset yoffset xoffset xoffset yoffset yoffset setedgeaction public void setx offset int x offset this x offset x offset setxoffset xoffset xoffset xoffset public int getx offset return x offset getxoffset xoffset public void sety offset int y offset this y offset y offset setyoffset yoffset yoffset yoffset public int gety offset return y offset getyoffset yoffset public void set wrap boolean wrap this wrap wrap setwrap public boolean get wrap return wrap getwrap override protected void transform inverse int x int y float out if wrap out 0 x width x offset width out 1 y height y offset height else out 0 x x offset out 1 y y offset transforminverse xoffset yoffset xoffset yoffset override public buffered image filter buffered image src buffered image dst this width src get width this height src get height if wrap while x offset 0 x offset width while y offset 0 y offset height x offset width y offset height return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight xoffset xoffset yoffset yoffset xoffset yoffset override public string to string return distort offset tostring public class xml import exception extends exception public xml import exception int line int column string message super in line line column column message this line line this column column this message message xmlimportexception xmlimportexception public string get message text return message getmessagetext public int get line return line getline public int get column return column getcolumn public node get root node if root node null return root node if device node null return null return device node get root node getrootnode rootnode rootnode devicenode devicenode getrootnode public node get device node return device node getdevicenode devicenode public void set root node node node root node node setrootnode rootnode public void set device node node node device node node setdevicenode devicenode public device node root node device root node root device node device setuuid u pnp createuuid set wireless mode false rootnode devicenode upnp setwirelessmode public device this null null public device node device this null device public device file description file throws invalid description exception this null null load description description file descriptionfile invaliddescriptionexception loaddescription descriptionfile public device string description file name throws invalid description exception this new file description file name descriptionfilename invaliddescriptionexception descriptionfilename private mutex mutex new mutex public void lock mutex lock public void unlock mutex unlock public void setnmpr mode boolean flag node dev node get device node if dev node null return if flag true dev node set node u pnp inmpr03 u pnp inmpr03 version dev node remove node device urlbase name else dev node remove node u pnp inmpr03 setnmprmode devnode getdevicenode devnode devnode setnode upnp upnp inmpr03_version devnode removenode urlbase_name devnode removenode upnp public boolean isnmpr mode node dev node get device node if dev node null return false return dev node get node u pnp inmpr03 null true false isnmprmode devnode getdevicenode devnode devnode getnode upnp private boolean wireless mode public void set wireless mode boolean flag wireless mode flag wirelessmode setwirelessmode wirelessmode public boolean is wireless mode return wireless mode iswirelessmode wirelessmode public int getssdp announce count if isnmpr mode true is wireless mode true return u pnp inmpr03 discovery over wireless count return 1 getssdpannouncecount isnmprmode iswirelessmode upnp inmpr03_discovery_over_wireless_count private string devuuid private void setuuid string uuid devuuid uuid private string getuuid return devuuid private void updateudn setudn uuid getuuid public device get root device node root node get root node if root node null return null node dev node root node get node device elem name if dev node null return null return new device root node dev node getrootdevice rootnode getrootnode rootnode devnode rootnode getnode elem_name devnode rootnode devnode public device get parent device if is root device return null node dev node get device node device device list device dev node dev node get parent node get parent node get node device elem name return new device dev node getparentdevice isrootdevice devnode getdevicenode devicelist devnode devnode getparentnode getparentnode getnode elem_name devnode private device data get device data node node get device node device data user data device data node get user data if user data null user data new device data node set user data user data user data set node node return user data devicedata getdevicedata getdevicenode devicedata userdata devicedata getuserdata userdata userdata devicedata setuserdata userdata userdata setnode userdata private void set description file file file get device data set description file file setdescriptionfile getdevicedata setdescriptionfile public file get description file return get device data get description file getdescriptionfile getdevicedata getdescriptionfile private void set descriptionuri string uri get device data set descriptionuri uri setdescriptionuri getdevicedata setdescriptionuri private string get descriptionuri return get device data get descriptionuri getdescriptionuri getdevicedata getdescriptionuri private boolean is descriptionuri string uri string descriptionuri get descriptionuri if uri null descriptionuri null return false return descriptionuri equals uri isdescriptionuri getdescriptionuri public string get description file path file description file get description file if description file null return return description file get absolute file get parent getdescriptionfilepath descriptionfile getdescriptionfile descriptionfile descriptionfile getabsolutefile getparent public boolean load description string desc string throws invalid description exception try parser parser u pnp getxml parser root node parser parse desc string if root node null throw new invalid description exception description noroot exception device node root node get node device elem name if device node null throw new invalid description exception description norootdevice exception catch parser exception e throw new invalid description exception e if initialize loaded description false return false set description file null return true loaddescription descstring invaliddescriptionexception upnp getxmlparser rootnode descstring rootnode invaliddescriptionexception noroot_exception devicenode rootnode getnode elem_name devicenode invaliddescriptionexception norootdevice_exception parserexception invaliddescriptionexception initializeloadeddescription setdescriptionfile public boolean load description file file throws invalid description exception try parser parser u pnp getxml parser root node parser parse file if root node null throw new invalid description exception description noroot exception file device node root node get node device elem name if device node null throw new invalid description exception description norootdevice exception file catch parser exception e throw new invalid description exception e if initialize loaded description false return false set description file file return true loaddescription invaliddescriptionexception upnp getxmlparser rootnode rootnode invaliddescriptionexception noroot_exception devicenode rootnode getnode elem_name devicenode invaliddescriptionexception norootdevice_exception parserexception invaliddescriptionexception initializeloadeddescription setdescriptionfile private boolean initialize loaded description set descriptionuri default description uri set lease time default lease time sethttp port http default port thanks for oliver newell 03 23 04 if hasudn false updateudn return true initializeloadeddescription setdescriptionuri default_description_uri setleasetime default_lease_time sethttpport http_default_port public static boolean is device node node node return device elem name equals node get name isdevicenode elem_name getname public boolean is root device return get root node null true false isrootdevice getrootnode public void setssdp packet ssdp packet packet get device data setssdp packet packet setssdppacket ssdppacket getdevicedata setssdppacket public ssdp packet getssdp packet if is root device false return null return get device data getssdp packet ssdppacket getssdppacket isrootdevice getdevicedata getssdppacket public void set location string value get device data set location value setlocation getdevicedata setlocation public string get location ssdp packet packet getssdp packet if packet null return packet get location return get device data get location getlocation ssdppacket getssdppacket getlocation getdevicedata getlocation public void set lease time int value get device data set lease time value advertiser adv get advertiser if adv null announce adv restart setleasetime getdevicedata setleasetime getadvertiser public int get lease time ssdp packet packet getssdp packet if packet null return packet get lease time return get device data get lease time getleasetime ssdppacket getssdppacket getleasetime getdevicedata getleasetime public long get time stamp ssdp packet packet getssdp packet if packet null return packet get time stamp return 0 gettimestamp ssdppacket getssdppacket gettimestamp public long get elapsed time return system current time millis get time stamp 1000 getelapsedtime currenttimemillis gettimestamp public boolean is expired long elipsed time get elapsed time long lease time get lease time u pnp default expired device extra time if lease time elipsed time return true return false isexpired elipsedtime getelapsedtime leasetime getleasetime upnp default_expired_device_extra_time leasetime elipsedtime private void seturl base string value if is root device true node node get root node get node urlbase name if node null node set value value return node new node urlbase name node set value value int index 1 if get root node has nodes false index 1 get root node insert node node index seturlbase isrootdevice getrootnode getnode urlbase_name setvalue urlbase_name setvalue getrootnode hasnodes getrootnode insertnode private void updateurl base string host string url base host interface get hosturl host gethttp port seturl base url base updateurlbase urlbase hostinterface gethosturl gethttpport seturlbase urlbase public string geturl base if is root device true return get root node get node value urlbase name return geturlbase isrootdevice getrootnode getnodevalue urlbase_name private final static string device type device type public void set device type string value get device node set node device type value device_type devicetype setdevicetype getdevicenode setnode device_type public string get device type return get device node get node value device type getdevicetype getdevicenode getnodevalue device_type public boolean is device type string value if value null return false return value equals get device type isdevicetype getdevicetype private final static string friendly name friendly name public void set friendly name string value get device node set node friendly name value friendly_name friendlyname setfriendlyname getdevicenode setnode friendly_name public string get friendly name return get device node get node value friendly name getfriendlyname getdevicenode getnodevalue friendly_name private final static string manufacture manufacture public void set manufacture string value get device node set node manufacture value setmanufacture getdevicenode setnode public string get manufacture return get device node get node value manufacture getmanufacture getdevicenode getnodevalue private final static string manufacture url manufactureurl public void set manufactureurl string value get device node set node manufacture url value manufacture_url setmanufactureurl getdevicenode setnode manufacture_url public string get manufactureurl return get device node get node value manufacture url getmanufactureurl getdevicenode getnodevalue manufacture_url private final static string model description model description public void set model description string value get device node set node model description value model_description modeldescription setmodeldescription getdevicenode setnode model_description public string get model description return get device node get node value model description getmodeldescription getdevicenode getnodevalue model_description private final static string model name model name public void set model name string value get device node set node model name value model_name modelname setmodelname getdevicenode setnode model_name public string get model name return get device node get node value model name getmodelname getdevicenode getnodevalue model_name private final static string model number model number public void set model number string value get device node set node model number value model_number modelnumber setmodelnumber getdevicenode setnode model_number public string get model number return get device node get node value model number getmodelnumber getdevicenode getnodevalue model_number private final static string model url modelurl public void set modelurl string value get device node set node model url value model_url setmodelurl getdevicenode setnode model_url public string get modelurl return get device node get node value model url getmodelurl getdevicenode getnodevalue model_url private final static string serial number serial number public void set serial number string value get device node set node serial number value serial_number serialnumber setserialnumber getdevicenode setnode serial_number public string get serial number return get device node get node value serial number getserialnumber getdevicenode getnodevalue serial_number private final static string udn udn public void setudn string value get device node set node udn value getdevicenode setnode public string getudn return get device node get node value udn getdevicenode getnodevalue public boolean hasudn string udn getudn if udn null udn length 0 return false return true private final static string upc upc public void setupc string value get device node set node upc value getdevicenode setnode public string getupc return get device node get node value upc getdevicenode getnodevalue private final static string presentationurl presentationurl public void set presentationurl string value get device node set node presentationurl value setpresentationurl getdevicenode setnode public string get presentationurl return get device node get node value presentationurl getpresentationurl getdevicenode getnodevalue public device list get device list device list dev list new device list node dev list node get device node get node device list elem name if dev list node null return dev list int n node dev list node getn nodes for int n 0 n n node n node node dev list node get node n if device is device node node false continue device dev new device node dev list add dev return dev list devicelist getdevicelist devicelist devlist devicelist devlistnode getdevicenode getnode devicelist elem_name devlistnode devlist nnode devlistnode getnnodes nnode devlistnode getnode isdevicenode devlist devlist public boolean is device string name if name null return false if name ends with getudn true return true if name equals get friendly name true return true if name ends with get device type true return true return false isdevice endswith getfriendlyname endswith getdevicetype public device get device string name device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n if dev is device name true return dev device cdev dev get device name if cdev null return cdev return null getdevice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice isdevice getdevice public device get device by descriptionuri string uri device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n if dev is descriptionuri uri true return dev device cdev dev get device by descriptionuri uri if cdev null return cdev return null getdevicebydescriptionuri devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice isdescriptionuri getdevicebydescriptionuri public service list get service list service list service list new service list node service list node get device node get node service list elem name if service list node null return service list int n node service list node getn nodes for int n 0 n n node n node node service list node get node n if service is service node node false continue service service new service node service list add service return service list servicelist getservicelist servicelist servicelist servicelist servicelistnode getdevicenode getnode servicelist elem_name servicelistnode servicelist nnode servicelistnode getnnodes nnode servicelistnode getnode isservicenode servicelist servicelist public service get service string name service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service is service name true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get service name if service null return service return null getservice servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice isservice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getservice public service get service byscpdurl string search url service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service isscpdurl search url true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get service byscpdurl search url if service null return service return null getservicebyscpdurl searchurl servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice searchurl devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getservicebyscpdurl searchurl public service get service by controlurl string search url service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service is controlurl search url true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get service by controlurl search url if service null return service return null getservicebycontrolurl searchurl servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice iscontrolurl searchurl devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getservicebycontrolurl searchurl public service get service by event suburl string search url service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n if service is event suburl search url true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get service by event suburl search url if service null return service return null getservicebyeventsuburl searchurl servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice iseventsuburl searchurl devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getservicebyeventsuburl searchurl public service get subscriber service string uuid service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n string sid service getsid if uuid equals sid true return service device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n service service dev get subscriber service uuid if service null return service return null getsubscriberservice servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getsubscriberservice public state variable get state variable string service type string name if service type null name null return null service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n thanks for theo beisch 11 09 04 if service type null if service get service type equals service type false continue state variable state var service get state variable name if state var null return state var device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n state variable state var dev get state variable service type name if state var null return state var return null statevariable getstatevariable servicetype servicetype servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice servicetype getservicetype servicetype statevariable statevar getstatevariable statevar statevar devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice statevariable statevar getstatevariable servicetype statevar statevar public state variable get state variable string name return get state variable null name statevariable getstatevariable getstatevariable public action get action string name service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n action list action list service get action list int action cnt action list size for int i 0 i action cnt i action action action action list get action i string action name action get name if action name null continue if action name equals name true return action device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n action action dev get action name if action null return action return null getaction servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice actionlist actionlist getactionlist actioncnt actionlist actioncnt actionlist getaction actionname getname actionname actionname devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice getaction public icon list get icon list icon list icon list new icon list node icon list node get device node get node icon list elem name if icon list node null return icon list int n node icon list node getn nodes for int n 0 n n node n node node icon list node get node n if icon is icon node node false continue icon icon new icon node icon list add icon return icon list iconlist geticonlist iconlist iconlist iconlist iconlistnode getdevicenode getnode iconlist elem_name iconlistnode iconlist nnode iconlistnode getnnodes nnode iconlistnode getnode isiconnode iconlist iconlist public icon get icon int n icon list icon list get icon list if n 0 icon list size 1 n return null return icon list get icon n geticon iconlist iconlist geticonlist iconlist iconlist geticon public string get locationurl string host return host interface get hosturl host gethttp port get descriptionuri getlocationurl hostinterface gethosturl gethttpport getdescriptionuri private string get notify devicent if is root device false return getudn return upnp rootdevice getnotifydevicent isrootdevice upnp_rootdevice private string get notify deviceusn if is root device false return getudn return getudn upnp rootdevice getnotifydeviceusn isrootdevice upnp_rootdevice private string get notify device typent return get device type getnotifydevicetypent getdevicetype private string get notify device typeusn return getudn get device type getnotifydevicetypeusn getdevicetype public final static void notify wait timer util wait random default discovery wait time notifywait timerutil waitrandom default_discovery_wait_time public void announce string bind addr string dev location get locationurl bind addr ssdp notify socket ssdp sock new ssdp notify socket bind addr ssdp notify request ssdp req new ssdp notify request ssdp req set server u pnp get server name ssdp req set lease time get lease time ssdp req set location dev location ssdp req setnts nts alive uuid device uuid upnp rootdevice if is root device true string devnt get notify devicent string devusn get notify deviceusn ssdp req setnt devnt ssdp req setusn devusn ssdp sock post ssdp req uuid device uuid urn schemas upnp org device device type v string devnt get notify device typent string devusn get notify device typeusn ssdp req setnt devnt ssdp req setusn devusn ssdp sock post ssdp req thanks for mikael hakman 04 25 05 ssdp sock close service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n service announce bind addr device list child device list get device list int child device cnt child device list size for int n 0 n child device cnt n device child device child device list get device n child device announce bind addr bindaddr devlocation getlocationurl bindaddr ssdpnotifysocket ssdpsock ssdpnotifysocket bindaddr ssdpnotifyrequest ssdpreq ssdpnotifyrequest ssdpreq setserver upnp getservername ssdpreq setleasetime getleasetime ssdpreq setlocation devlocation ssdpreq isrootdevice getnotifydevicent getnotifydeviceusn ssdpreq ssdpreq ssdpsock ssdpreq devicetype getnotifydevicetypent getnotifydevicetypeusn ssdpreq ssdpreq ssdpsock ssdpreq ssdpsock servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice bindaddr devicelist childdevicelist getdevicelist childdevicecnt childdevicelist childdevicecnt childdevice childdevicelist getdevice childdevice bindaddr public void announce notify wait int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n if bind addr null bind addr length 0 continue int ssdp count getssdp announce count for int i 0 i ssdp count i announce bind addr notifywait nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress bindaddr bindaddr ssdpcount getssdpannouncecount ssdpcount bindaddr public void byebye string bind addr ssdp notify socket ssdp sock new ssdp notify socket bind addr ssdp notify request ssdp req new ssdp notify request ssdp req setnts nts byebye uuid device uuid upnp rootdevice if is root device true string devnt get notify devicent string devusn get notify deviceusn ssdp req setnt devnt ssdp req setusn devusn ssdp sock post ssdp req uuid device uuid urn schemas upnp org device device type v string devnt get notify device typent string devusn get notify device typeusn ssdp req setnt devnt ssdp req setusn devusn ssdp sock post ssdp req thanks for mikael hakman 04 25 05 ssdp sock close service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n service byebye bind addr device list child device list get device list int child device cnt child device list size for int n 0 n child device cnt n device child device child device list get device n child device byebye bind addr bindaddr ssdpnotifysocket ssdpsock ssdpnotifysocket bindaddr ssdpnotifyrequest ssdpreq ssdpnotifyrequest ssdpreq isrootdevice getnotifydevicent getnotifydeviceusn ssdpreq ssdpreq ssdpsock ssdpreq devicetype getnotifydevicetypent getnotifydevicetypeusn ssdpreq ssdpreq ssdpsock ssdpreq ssdpsock servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice bindaddr devicelist childdevicelist getdevicelist childdevicecnt childdevicelist childdevicecnt childdevice childdevicelist getdevice childdevice bindaddr public void byebye int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n if bind addr null bind addr length 0 continue int ssdp count getssdp announce count for int i 0 i ssdp count i byebye bind addr nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress bindaddr bindaddr ssdpcount getssdpannouncecount ssdpcount bindaddr public boolean post search response ssdp packet ssdp packet string st string usn string local addr ssdp packet get local address device root dev get root device string root dev location root dev get locationurl local addr ssdp search response ssdp res new ssdp search response ssdp res set lease time get lease time ssdp res set date calendar get instance ssdp res setst st ssdp res setusn usn ssdp res set location root dev location thanks for brent hills 10 20 04 ssdp res setmyname get friendly name int mx ssdp packet getmx timer util wait random mx 1000 string remote addr ssdp packet get remote address int remote port ssdp packet get remote port ssdp search response socket ssdp res sock new ssdp search response socket if debug is on true ssdp res print int ssdp count getssdp announce count for int i 0 i ssdp count i ssdp res sock post remote addr remote port ssdp res return true postsearchresponse ssdppacket ssdppacket localaddr ssdppacket getlocaladdress rootdev getrootdevice rootdevlocation rootdev getlocationurl localaddr ssdpsearchresponse ssdpres ssdpsearchresponse ssdpres setleasetime getleasetime ssdpres setdate getinstance ssdpres ssdpres ssdpres setlocation rootdevlocation ssdpres getfriendlyname ssdppacket timerutil waitrandom remoteaddr ssdppacket getremoteaddress remoteport ssdppacket getremoteport ssdpsearchresponsesocket ssdpressock ssdpsearchresponsesocket ison ssdpres ssdpcount getssdpannouncecount ssdpcount ssdpressock remoteaddr remoteport ssdpres public void device search response ssdp packet ssdp packet string ssdpst ssdp packet getst if ssdpst null return boolean is root device is root device string devusn getudn if is root device true devusn usn rootdevice if st is all device ssdpst true string devnt get notify devicent int repeat cnt is root device true 3 2 for int n 0 n repeat cnt n post search response ssdp packet devnt devusn else if st is root device ssdpst true if is root device true post search response ssdp packet st root device devusn else if st isuuid device ssdpst true string devudn getudn if ssdpst equals devudn true post search response ssdp packet devudn devusn else if st isurn device ssdpst true string dev type get device type if ssdpst equals dev type true thanks for mikael hakman 04 25 05 devusn getudn dev type post search response ssdp packet dev type devusn service list service list get service list int service cnt service list size for int n 0 n service cnt n service service service list get service n service service search response ssdp packet device list child device list get device list int child device cnt child device list size for int n 0 n child device cnt n device child device child device list get device n child device device search response ssdp packet devicesearchresponse ssdppacket ssdppacket ssdppacket isrootdevice isrootdevice isrootdevice isalldevice getnotifydevicent repeatcnt isrootdevice repeatcnt postsearchresponse ssdppacket isrootdevice isrootdevice postsearchresponse ssdppacket root_device isuuiddevice postsearchresponse ssdppacket isurndevice devtype getdevicetype devtype devtype postsearchresponse ssdppacket devtype servicelist servicelist getservicelist servicecnt servicelist servicecnt servicelist getservice servicesearchresponse ssdppacket devicelist childdevicelist getdevicelist childdevicecnt childdevicelist childdevicecnt childdevice childdevicelist getdevice childdevice devicesearchresponse ssdppacket public void device search received ssdp packet ssdp packet device search response ssdp packet devicesearchreceived ssdppacket ssdppacket devicesearchresponse ssdppacket public void sethttp port int port get device data sethttp port port sethttpport getdevicedata sethttpport public int gethttp port return get device data gethttp port gethttpport getdevicedata gethttpport public void http request recieved http request http req if debug is on true http req print if http req is get request true http get request recieved http req return if http req is post request true http post request recieved http req return if http req is subscribe request true http req is unsubscribe request true subscription request sub req new subscription request http req device event subscription recieved sub req return http req return bad request httprequestrecieved httprequest httpreq ison httpreq httpreq isgetrequest httpgetrequestrecieved httpreq httpreq ispostrequest httppostrequestrecieved httpreq httpreq issubscriberequest httpreq isunsubscriberequest subscriptionrequest subreq subscriptionrequest httpreq deviceeventsubscriptionrecieved subreq httpreq returnbadrequest private synchronized byte get description data string host if isnmpr mode false updateurl base host node root node get root node if root node null return new byte 0 thanks for mikael hakman 04 25 05 string desc new string desc u pnp xml declaration desc n desc root node to string return desc get bytes getdescriptiondata isnmprmode updateurlbase rootnode getrootnode rootnode upnp xml_declaration rootnode tostring getbytes private void http get request recieved http request http req string uri http req geturi debug message http get request recieved uri if uri null http req return bad request return device emb dev service emb service byte file byte new byte 0 if is descriptionuri uri true string local addr http req get local address file byte get description data local addr else if emb dev get device by descriptionuri uri null string local addr http req get local address file byte emb dev get description data local addr else if emb service get service byscpdurl uri null file byte emb service getscpd data else http req return bad request return http response http res new http response if file util isxml file name uri true http res set content type xml content type http res set status code http status ok http res set content file byte http req post http res httpgetrequestrecieved httprequest httpreq httpreq httpgetrequestrecieved httpreq returnbadrequest embdev embservice filebyte isdescriptionuri localaddr httpreq getlocaladdress filebyte getdescriptiondata localaddr embdev getdevicebydescriptionuri localaddr httpreq getlocaladdress filebyte embdev getdescriptiondata localaddr embservice getservicebyscpdurl filebyte embservice getscpddata httpreq returnbadrequest httpresponse httpres httpresponse fileutil isxmlfilename httpres setcontenttype content_type httpres setstatuscode httpstatus httpres setcontent filebyte httpreq httpres private void http post request recieved http request http req if http req issoap action true soap request soap req new soap request http req soap action recieved http req return http req return bad request httppostrequestrecieved httprequest httpreq httpreq issoapaction soaprequest soapreq soaprequest httpreq soapactionrecieved httpreq httpreq returnbadrequest private void soap bad action recieved http request soap req soap response soap res new soap response soap res set status code http status bad request soap req post soap res soapbadactionrecieved httprequest soapreq soapresponse soapres soapresponse soapres setstatuscode httpstatus bad_request soapreq soapres private void soap action recieved http request soap req string uri soap req geturi service ctl service get service by controlurl uri if ctl service null action request crl req new action request soap req device control request recieved crl req ctl service return soap bad action recieved soap req soapactionrecieved httprequest soapreq soapreq ctlservice getservicebycontrolurl ctlservice actionrequest crlreq actionrequest soapreq devicecontrolrequestrecieved crlreq ctlservice soapbadactionrecieved soapreq private void device control request recieved control request ctl req service service if ctl req is query control true device query control recieved new query request ctl req service else device action control recieved new action request ctl req service devicecontrolrequestrecieved controlrequest ctlreq ctlreq isquerycontrol devicequerycontrolrecieved queryrequest ctlreq deviceactioncontrolrecieved actionrequest ctlreq private void invalid action control recieved control request ctl req control response act res new action response act res set fault response u pnp status invalid action ctl req post act res invalidactioncontrolrecieved controlrequest ctlreq controlresponse actres actionresponse actres setfaultresponse upnpstatus invalid_action ctlreq actres private void device action control recieved action request ctl req service service if debug is on true ctl req print string action name ctl req get action name action action service get action action name if action null invalid action control recieved ctl req return argument list action arg list action get argument list argument list req arg list ctl req get argument list action arg list set req arg list if action perform action listener ctl req false invalid action control recieved ctl req deviceactioncontrolrecieved actionrequest ctlreq ison ctlreq actionname ctlreq getactionname getaction actionname invalidactioncontrolrecieved ctlreq argumentlist actionarglist getargumentlist argumentlist reqarglist ctlreq getargumentlist actionarglist reqarglist performactionlistener ctlreq invalidactioncontrolrecieved ctlreq private void device query control recieved query request ctl req service service if debug is on true ctl req print string var name ctl req get var name if service has state variable var name false invalid action control recieved ctl req return state variable state var get state variable var name if state var perform query listener ctl req false invalid action control recieved ctl req devicequerycontrolrecieved queryrequest ctlreq ison ctlreq varname ctlreq getvarname hasstatevariable varname invalidactioncontrolrecieved ctlreq statevariable statevar getstatevariable varname statevar performquerylistener ctlreq invalidactioncontrolrecieved ctlreq private void upnp bad subscription recieved subscription request sub req int code subscription response sub res new subscription response sub res set error response code sub req post sub res upnpbadsubscriptionrecieved subscriptionrequest subreq subscriptionresponse subres subscriptionresponse subres seterrorresponse subreq subres private void device event subscription recieved subscription request sub req string uri sub req geturi service service get service by event suburl uri if service null sub req return bad request return if sub req has callback false sub req hassid false upnp bad subscription recieved sub req http status precondition failed return unsubscribe if sub req is unsubscribe request true device event unsubscription recieved service sub req return subscribe new if sub req has callback true device event new subscription recieved service sub req return subscribe renew if sub req hassid true device event renew subscription recieved service sub req return upnp bad subscription recieved sub req http status precondition failed deviceeventsubscriptionrecieved subscriptionrequest subreq subreq getservicebyeventsuburl subreq returnbadrequest subreq hascallback subreq upnpbadsubscriptionrecieved subreq httpstatus precondition_failed subreq isunsubscriberequest deviceeventunsubscriptionrecieved subreq subreq hascallback deviceeventnewsubscriptionrecieved subreq subreq deviceeventrenewsubscriptionrecieved subreq upnpbadsubscriptionrecieved subreq httpstatus precondition_failed private void device event new subscription recieved service service subscription request sub req string callback sub req get callback try new url callback catch exception e upnp bad subscription recieved sub req http status precondition failed return long time out sub req get timeout string sid subscription createsid subscriber sub new subscriber sub set deliveryurl callback sub set time out time out sub setsid sid service add subscriber sub subscription response sub res new subscription response sub res set status code http status ok sub res setsid sid sub res set timeout time out if debug is on true sub res print sub req post sub res if debug is on true sub res print service notify all state variables deviceeventnewsubscriptionrecieved subscriptionrequest subreq subreq getcallback upnpbadsubscriptionrecieved subreq httpstatus precondition_failed timeout subreq gettimeout setdeliveryurl settimeout timeout addsubscriber subscriptionresponse subres subscriptionresponse subres setstatuscode httpstatus subres subres settimeout timeout ison subres subreq subres ison subres notifyallstatevariables private void device event renew subscription recieved service service subscription request sub req string sid sub req getsid subscriber sub service get subscriber sid if sub null upnp bad subscription recieved sub req http status precondition failed return long time out sub req get timeout sub set time out time out sub renew subscription response sub res new subscription response sub res set status code http status ok sub res setsid sid sub res set timeout time out sub req post sub res if debug is on true sub res print deviceeventrenewsubscriptionrecieved subscriptionrequest subreq subreq getsubscriber upnpbadsubscriptionrecieved subreq httpstatus precondition_failed timeout subreq gettimeout settimeout timeout subscriptionresponse subres subscriptionresponse subres setstatuscode httpstatus subres subres settimeout timeout subreq subres ison subres private void device event unsubscription recieved service service subscription request sub req string sid sub req getsid subscriber sub service get subscriber sid if sub null upnp bad subscription recieved sub req http status precondition failed return service remove subscriber sub subscription response sub res new subscription response sub res set status code http status ok sub req post sub res if debug is on true sub res print deviceeventunsubscriptionrecieved subscriptionrequest subreq subreq getsubscriber upnpbadsubscriptionrecieved subreq httpstatus precondition_failed removesubscriber subscriptionresponse subres subscriptionresponse subres setstatuscode httpstatus subreq subres ison subres private http server list gethttp server list return get device data gethttp server list httpserverlist gethttpserverlist getdevicedata gethttpserverlist private ssdp search socket list getssdp search socket list return get device data getssdp search socket list ssdpsearchsocketlist getssdpsearchsocketlist getdevicedata getssdpsearchsocketlist private void set advertiser advertiser adv get device data set advertiser adv setadvertiser getdevicedata setadvertiser private advertiser get advertiser return get device data get advertiser getadvertiser getdevicedata getadvertiser public boolean start stop true http server int retry cnt 0 int bind port gethttp port http server list http server list gethttp server list while http server list open bind port false retry cnt if u pnp server retry count retry cnt return false sethttp port bind port 1 bind port gethttp port http server list add request listener this http server list start ssdp seach socket ssdp search socket list ssdp search sock list getssdp search socket list if ssdp search sock list open false return false ssdp search sock list add search listener this ssdp search sock list start announce announce advertiser advertiser adv new advertiser this set advertiser adv adv start return true retrycnt bindport gethttpport httpserverlist httpserverlist gethttpserverlist httpserverlist bindport retrycnt upnp server_retry_count retrycnt sethttpport bindport bindport gethttpport httpserverlist addrequestlistener httpserverlist ssdpsearchsocketlist ssdpsearchsocklist getssdpsearchsocketlist ssdpsearchsocklist ssdpsearchsocklist addsearchlistener ssdpsearchsocklist setadvertiser private boolean stop boolean do bye bye if do bye bye true byebye http server list http server list gethttp server list http server list stop http server list close http server list clear ssdp search socket list ssdp search sock list getssdp search socket list ssdp search sock list stop ssdp search sock list close ssdp search sock list clear advertiser adv get advertiser if adv null adv stop set advertiser null return true dobyebye dobyebye httpserverlist httpserverlist gethttpserverlist httpserverlist httpserverlist httpserverlist ssdpsearchsocketlist ssdpsearchsocklist getssdpsearchsocketlist ssdpsearchsocklist ssdpsearchsocklist ssdpsearchsocklist getadvertiser setadvertiser public boolean stop return stop true public string get interface address ssdp packet ssdp packet getssdp packet if ssdp packet null return return ssdp packet get local address getinterfaceaddress ssdppacket ssdppacket getssdppacket ssdppacket ssdppacket getlocaladdress public void set action listener action listener listener service list service list get service list int n services service list size for int n 0 n n services n service service service list get service n service set action listener listener setactionlistener actionlistener servicelist servicelist getservicelist nservices servicelist nservices servicelist getservice setactionlistener public void set query listener query listener listener service list service list get service list int n services service list size for int n 0 n n services n service service service list get service n service set query listener listener setquerylistener querylistener servicelist servicelist getservicelist nservices servicelist nservices servicelist getservice setquerylistener thanks for mikael hakman 04 25 05 public void set action listener action listener listener boolean include sub devices set action listener listener if include sub devices true device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n dev set action listener listener true setactionlistener actionlistener includesubdevices setactionlistener includesubdevices devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice setactionlistener thanks for mikael hakman 04 25 05 public void set query listener query listener listener boolean include sub devices set query listener listener if include sub devices true device list dev list get device list int dev cnt dev list size for int n 0 n dev cnt n device dev dev list get device n dev set query listener listener true setquerylistener querylistener includesubdevices setquerylistener includesubdevices devicelist devlist getdevicelist devcnt devlist devcnt devlist getdevice setquerylistener create an instance of jmdns public jmdns impl throws io exception logger finer jmdns instance created try final inet address addr inet address get local host init addr is loopback address null addr addr get host name pjyf oct 14 2004 why do we disallow the loopback address catch final io exception e init null computer jmdnsimpl ioexception inetaddress inetaddress getlocalhost isloopbackaddress gethostname ioexception create an instance of jmdns and bind it to a specific network interface given its ip address public jmdns impl inet address addr throws io exception try init addr addr get host name catch final io exception e init null computer jmdnsimpl inetaddress ioexception gethostname ioexception initialize everything param address the interface to which jmdns binds to param name the host name of the interface private void init inet address address string name throws io exception a host name with is illegal so strip off everything and append local final int idx name index of if idx 0 name name substring 0 idx name local local host to ip address binding local host new host info address name cache new dns cache 100 listeners collections synchronized list new array list service listeners new hash map type listeners new array list services new hashtable 20 service types new hashtable 20 remind if i could pass in a name for the timer thread i would pass jmdns timer timer new timer new record reaper this start timer shutdown new thread new shutdown jmdns shutdown runtime get runtime add shutdown hook shutdown incoming listener new thread new socket listener this jmdns socket listener bind to multicast socket open multicast socket get local host start get services values inetaddress ioexception indexof localhost localhost hostinfo dnscache synchronizedlist arraylist servicelisteners hashmap typelisteners arraylist servicetypes recordreaper getruntime addshutdownhook incominglistener socketlistener socketlistener openmulticastsocket getlocalhost getservices private void start collection service infos set state dns state probing 1 incoming listener start new prober this start timer for final iterator iterator service infos iterator iterator has next try register service new service info impl service info impl iterator next catch final exception exception logger log level warning start registration exception exception serviceinfos setstate dnsstate probing_1 incominglistener serviceinfos hasnext registerservice serviceinfoimpl serviceinfoimpl private void open multicast socket host info host info throws io exception if group null group inet address get by name dns constants mdns group if socket null this close multicast socket socket new multicast socket dns constants mdns port if host info null local host get interface null socket set network interface host info get interface socket set time to live 255 socket join group group openmulticastsocket hostinfo hostinfo ioexception inetaddress getbyname dnsconstants mdns_group closemulticastsocket multicastsocket dnsconstants mdns_port hostinfo localhost getinterface setnetworkinterface hostinfo getinterface settimetolive joingroup private void close multicast socket logger finer close multicast socket if socket null close socket try socket leave group group socket close if incoming listener null incoming listener join catch final exception exception logger log level warning close multicast socket close socket exception exception socket null closemulticastsocket closemulticastsocket leavegroup incominglistener incominglistener closemulticastsocket state machine sets the state and notifies all objects that wait on jmdns public synchronized void advance state set state get state advance notify all advancestate setstate getstate notifyall sets the state and notifies all objects that wait on jmdns synchronized void revert state set state get state revert notify all revertstate setstate getstate notifyall sets the state and notifies all objects that wait on jmdns synchronized void cancel set state dns state canceled notify all setstate dnsstate notifyall returns the current state of this info public dns state get state return state dnsstate getstate return the dns cache associated with the cache variable public dns cache get cache return cache dnscache dnscache getcache see plugins mdns discovery javax jmdns jmdns get host name public string get host name return local host get name mdnsdiscovery gethostname gethostname localhost getname public host info get local host return local host hostinfo getlocalhost localhost see plugins mdns discovery javax jmdns jmdns get interface public inet address get interface throws io exception return socket get interface mdnsdiscovery getinterface inetaddress getinterface ioexception getinterface see plugins mdns discovery javax jmdns jmdns get service info java lang string java lang string public service info get service info string type string name return get service info type name 3 1000 mdnsdiscovery getserviceinfo serviceinfo getserviceinfo getserviceinfo see plugins mdns discovery javax jmdns jmdns get service info java lang string java lang string int public service info get service info string type string name int timeout final service info impl info new service info impl type name new service info resolver this info start timer try final long end system current time millis timeout long delay synchronized info while info has data delay end system current time millis 0 info wait delay catch final interrupted exception e empty return info has data info null mdnsdiscovery getserviceinfo serviceinfo getserviceinfo serviceinfoimpl serviceinfoimpl serviceinforesolver currenttimemillis hasdata currenttimemillis interruptedexception hasdata see plugins mdns discovery javax jmdns jmdns request service info java lang string java lang string public void request service info string type string name request service info type name 3 1000 mdnsdiscovery requestserviceinfo requestserviceinfo requestserviceinfo see plugins mdns discovery javax jmdns jmdns request service info java lang string java lang string int public void request service info string type string name int timeout register service type type final service info impl info new service info impl type name new service info resolver this info start timer try final long end system current time millis timeout long delay synchronized info while info has data delay end system current time millis 0 info wait delay catch final interrupted exception e empty mdnsdiscovery requestserviceinfo requestserviceinfo registerservicetype serviceinfoimpl serviceinfoimpl serviceinforesolver currenttimemillis hasdata currenttimemillis interruptedexception void handle service resolved service info impl info list list null array list list copy null synchronized service listeners list list service listeners get info type to lower case if list null list copy new array list list if list copy null final service event event new service event impl this info type info get name info for final iterator iterator list copy iterator iterator has next service listener iterator next service resolved event handleserviceresolved serviceinfoimpl arraylist listcopy servicelisteners servicelisteners tolowercase listcopy arraylist listcopy serviceevent serviceeventimpl getname listcopy hasnext servicelistener serviceresolved see plugins mdns discovery javax jmdns jmdns add service type listener plugins mdns discovery javax jmdns service type listener public void add service type listener service type listener listener throws io exception synchronized this type listeners remove listener type listeners add listener report cached service types for final iterator iterator service types values iterator iterator has next listener service type added new service event impl this string iterator next null null new type resolver this start timer mdnsdiscovery addservicetypelistener mdnsdiscovery servicetypelistener addservicetypelistener servicetypelistener ioexception typelisteners typelisteners servicetypes hasnext servicetypeadded serviceeventimpl typeresolver see plugins mdns discovery javax jmdns jmdns remove service type listener plugins mdns discovery javax jmdns service type listener public void remove service type listener service type listener listener synchronized this type listeners remove listener mdnsdiscovery removeservicetypelistener mdnsdiscovery servicetypelistener removeservicetypelistener servicetypelistener typelisteners see plugins mdns discovery javax jmdns jmdns add service listener java lang string plugins mdns discovery javax jmdns service listener public void add service listener string type service listener listener final string lotype type to lower case remove service listener lotype listener list list null synchronized service listeners list list service listeners get lotype if list null list collections synchronized list new linked list service listeners put lotype list list add listener report cached service types final list service events new array list synchronized cache for final iterator i cache iterator i has next for dns cache cache node n dns cache cache node i next n null n n next final dns record rec dns record n get value if rec type dns constants type srv if rec name ends with type service events add new service event impl this type to unqualified name type rec name null actually call listener with all service events added above for final iterator i service events iterator i has next listener service added service event impl i next create start service resolver new service resolver this type start timer mdnsdiscovery addservicelistener mdnsdiscovery servicelistener addservicelistener servicelistener tolowercase removeservicelistener servicelisteners servicelisteners synchronizedlist linkedlist servicelisteners serviceevents arraylist hasnext dnscache cachenode dnscache cachenode dnsrecord dnsrecord getvalue dnsconstants type_srv endswith serviceevents serviceeventimpl tounqualifiedname serviceevents hasnext serviceadded serviceeventimpl serviceresolver serviceresolver see plugins mdns discovery javax jmdns jmdns remove service listener java lang string plugins mdns discovery javax jmdns service listener public void remove service listener string type service listener listener type type to lower case list list null synchronized service listeners list list service listeners get type if list null list remove listener if list size 0 service listeners remove type mdnsdiscovery removeservicelistener mdnsdiscovery servicelistener removeservicelistener servicelistener tolowercase servicelisteners servicelisteners servicelisteners see plugins mdns discovery javax jmdns jmdns register service plugins mdns discovery javax jmdns service info public void register service service info info abstract throws io exception final service info impl info service info impl info abstract register service type info type bind the service to this address info server local host get name info addr local host get address synchronized this make service name unique info services put info get qualified name to lower case info new service prober this start timer try synchronized info while info get state compare to dns state announced 0 info wait catch final interrupted exception e empty logger fine register service jmdns registered service as info mdnsdiscovery registerservice mdnsdiscovery serviceinfo registerservice serviceinfo infoabstract ioexception serviceinfoimpl serviceinfoimpl infoabstract registerservicetype localhost getname localhost getaddress makeservicenameunique getqualifiedname tolowercase getstate compareto dnsstate interruptedexception registerservice see plugins mdns discovery javax jmdns jmdns unregister service plugins mdns discovery javax jmdns service info public void unregister service service info info abstract final service info impl info service info impl info abstract synchronized this services remove info get qualified name to lower case info cancel note we use this lock object to synchronize on it synchronizing on another object e g the service info does not make sense because the sole purpose of the lock is to wait until the canceler has finished if we synchronized on the service info or on the canceler we would block all accesses to synchronized methods on that object this is not what we want final object lock new object new canceler this info lock start timer remind we get a deadlock here if the canceler does not run try synchronized lock lock wait catch final interrupted exception e empty mdnsdiscovery unregisterservice mdnsdiscovery serviceinfo unregisterservice serviceinfo infoabstract serviceinfoimpl serviceinfoimpl infoabstract getqualifiedname tolowercase serviceinfo serviceinfo interruptedexception see plugins mdns discovery javax jmdns jmdns unregister all services public void unregister all services logger finer unregister all services if services size 0 return collection list synchronized this list new linked list services values services clear for final iterator iterator list iterator iterator has next service info impl iterator next cancel final object lock new object new canceler this list lock start timer remind we get a livelock here if the canceler does not run try synchronized lock if closed lock wait catch final interrupted exception e empty mdnsdiscovery unregisterallservices unregisterallservices unregisterallservices linkedlist hasnext serviceinfoimpl interruptedexception see plugins mdns discovery javax jmdns jmdns register service type java lang string public void register service type string type final string name type to lower case if service types get name null if type index of dns sd udp 0 type ends with in addr arpa collection list synchronized this service types put name type list new linked list type listeners for final iterator iterator list iterator iterator has next service type listener iterator next service type added new service event impl this type null null mdnsdiscovery registerservicetype registerservicetype tolowercase servicetypes indexof _dns _udp endswith servicetypes linkedlist typelisteners hasnext servicetypelistener servicetypeadded serviceeventimpl generate a possibly unique name for a host using the information we have in the cache return returns true if the name of the host had to be changed private boolean make host name unique dns record address host final string original name host get name system current time millis boolean collision do collision false check for collision in cache for dns cache cache node j cache find host get name to lower case j null j j next if false host name increment name host get name collision true break while collision if original name equals host get name return false else return true makehostnameunique dnsrecord originalname getname currenttimemillis dnscache cachenode getname tolowercase incrementname getname originalname getname generate a possibly unique name for a service using the information we have in the cache return returns true if the name of the service info had to be changed private boolean make service name unique service info impl info final string original qualified name info get qualified name final long now system current time millis boolean collision do collision false check for collision in cache for dns cache cache node j cache find info get qualified name to lower case j null j j next final dns record a dns record j get value if a type dns constants type srv a is expired now final dns record service s dns record service a if s port info port s server equals local host get name logger finer make service name unique jmdns make service name unique srv collision a s server s server local host get name equals s server equals local host get name info set name increment name info get name collision true break check for collision with other service infos published by jmdns final object self service services get info get qualified name to lower case if self service null self service info info set name increment name info get name collision true while collision return original qualified name equals info get qualified name makeservicenameunique serviceinfoimpl originalqualifiedname getqualifiedname currenttimemillis dnscache cachenode getqualifiedname tolowercase dnsrecord dnsrecord getvalue dnsconstants type_srv isexpired dnsrecord dnsrecord localhost getname makeservicenameunique makeservicenameunique localhost getname localhost getname setname incrementname getname selfservice getqualifiedname tolowercase selfservice selfservice setname incrementname getname originalqualifiedname getqualifiedname string increment name string name try final int l name last index of final int r name last index of if l 0 l r name name substring 0 l integer parse int name substring l 1 r 1 else name 2 catch final number format exception e name 2 return name incrementname lastindexof lastindexof parseint numberformatexception add a listener for a question the listener will receive updates of answers to the question as they arrive or from the cache if they are already available public void add listener dns listener listener dns question question final long now system current time millis add the new listener synchronized this listeners add listener report existing matched records if question null for dns cache cache node i cache find question name i null i i next final dns record c dns record i get value if question answered by c c is expired now listener update record this now c addlistener dnslistener dnsquestion currenttimemillis dnscache cachenode dnsrecord dnsrecord getvalue answeredby isexpired updaterecord remove a listener from all outstanding questions the listener will no longer receive any updates public void remove listener dns listener listener synchronized this listeners remove listener removelistener dnslistener remind method update record should receive a better name notify all listeners that a record was updated public void update record long now dns record rec we do not want to block the entire dns while we are updating the record for each listener service info list listener list null synchronized this listener list new array list listeners for final iterator iterator listener list iterator iterator has next final dns listener listener dns listener iterator next listener update record this now rec if rec type dns constants type ptr rec type dns constants type srv list service listener list null synchronized service listeners service listener list list service listeners get rec name to lower case iterate on a copy in case listeners will modify it if service listener list null service listener list new array list service listener list if service listener list null final boolean expired rec is expired now final string type rec get name final string name dns record pointer rec get alias dns record old dns record services get name to lower case if expired new record final service event event new service event impl this type to unqualified name type name null for final iterator iterator service listener list iterator iterator has next service listener iterator next service added event else expire record final service event event new service event impl this type to unqualified name type name null for final iterator iterator service listener list iterator iterator has next service listener iterator next service removed event updaterecord updaterecord dnsrecord listenerlist listenerlist arraylist listenerlist hasnext dnslistener dnslistener updaterecord dnsconstants type_ptr dnsconstants type_srv servicelistenerlist servicelisteners servicelistenerlist servicelisteners tolowercase servicelistenerlist servicelistenerlist arraylist servicelistenerlist servicelistenerlist isexpired getname dnsrecord getalias dnsrecord dnsrecord tolowercase serviceevent serviceeventimpl tounqualifiedname servicelistenerlist hasnext servicelistener serviceadded serviceevent serviceeventimpl tounqualifiedname servicelistenerlist hasnext servicelistener serviceremoved handle an incoming response cache answers and pass them on to the appropriate questions void handle response dns incoming msg throws io exception final long now system current time millis boolean host conflict detected false boolean service conflict detected false for final iterator i msg answers iterator i has next boolean is informative false dns record rec dns record i next final boolean expired rec is expired now update the cache final dns record c dns record cache get rec if c null if expired is informative true cache remove c else c resetttl rec rec c else if expired is informative true cache add rec switch rec type case dns constants type ptr handle mdns udp records if rec get name index of dns sd udp 0 if expired rec name starts with services mdns udp is informative true register service type dns record pointer rec alias continue register service type rec name break if rec get type dns constants type a rec get type dns constants type aaaa host conflict detected rec handle response this else service conflict detected rec handle response this notify the listeners if is informative update record now rec if host conflict detected service conflict detected new prober this start timer handleresponse dnsincoming ioexception currenttimemillis hostconflictdetected serviceconflictdetected hasnext isinformative dnsrecord dnsrecord isexpired dnsrecord dnsrecord isinformative isinformative dnsconstants type_ptr _mdns _udp getname indexof _dns _udp startswith _services _mdns _udp isinformative registerservicetype dnsrecord registerservicetype gettype dnsconstants type_a gettype dnsconstants type_aaaa hostconflictdetected handleresponse serviceconflictdetected handleresponse isinformative updaterecord hostconflictdetected serviceconflictdetected handle an incoming query see if we can answer any part of it given our service infos void handle query dns incoming in inet address addr int port throws io exception track known answers boolean host conflict detected false boolean service conflict detected false final long expiration time system current time millis dns constants known answer ttl for final iterator i in answers iterator i has next final dns record answer dns record i next if answer get type dns constants type a answer get type dns constants type aaaa host conflict detected answer handle query this expiration time else service conflict detected answer handle query this expiration time if planned answer null planned answer append in else if in is truncated planned answer in new responder this in addr port start if host conflict detected service conflict detected new prober this start timer handlequery dnsincoming inetaddress ioexception hostconflictdetected serviceconflictdetected expirationtime currenttimemillis dnsconstants known_answer_ttl hasnext dnsrecord dnsrecord gettype dnsconstants type_a gettype dnsconstants type_aaaa hostconflictdetected handlequery expirationtime serviceconflictdetected handlequery expirationtime plannedanswer plannedanswer istruncated plannedanswer hostconflictdetected serviceconflictdetected add an answer to a question deal with the case when the outgoing packet overflows public dns outgoing add answer dns incoming in inet address addr int port dns outgoing out dns record rec throws io exception if out null out new dns outgoing dns constants flags qr response dns constants flags aa try out add answer in rec catch final io exception e out flags dns constants flags tc out id in id out finish send out out new dns outgoing dns constants flags qr response dns constants flags aa out add answer in rec return out dnsoutgoing addanswer dnsincoming inetaddress dnsoutgoing dnsrecord ioexception dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa addanswer ioexception dnsconstants flags_tc dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa addanswer send an outgoing multicast dns message public void send dns outgoing out throws io exception out finish if out is empty final datagram packet packet new datagram packet out data out off group dns constants mdns port try final dns incoming msg new dns incoming packet logger finest send jmdns out msg print true catch final io exception e logger throwing get class to string send dns outgoing jmdns can not parse what it sends e final multicast socket ms socket if ms null ms is closed ms send packet dnsoutgoing ioexception isempty datagrampacket datagrampacket dnsconstants mdns_port dnsincoming dnsincoming ioexception getclass tostring dnsoutgoing multicastsocket isclosed public void start announcer new announcer this start timer startannouncer public void start renewer new renewer this start timer startrenewer public void schedule timer task task int delay timer schedule task delay timertask public void run shutdown null close recover jmdns when there is an error public void recover logger finer recover we have an io error so lets try to recover if anything happens lets close it this should cover the case of the ip address changing under our feet if dns state canceled get state synchronized this synchronize only if we are not already in process to prevent dead locks logger finer recover cleanning up stop jmdns set state dns state canceled this protects against recursive calls we need to keep a copy for reregistration final collection old service infos new array list get services values cancel all services unregister all services dispose service collectors close multicast socket close multicast socket cache clear logger finer recover all is clean all is clear now start the services try open multicast socket get local host start old service infos catch final exception exception logger log level warning recover start services exception exception logger log level warning recover we are back dnsstate getstate setstate dnsstate oldserviceinfos arraylist getservices unregisterallservices disposeservicecollectors closemulticastsocket openmulticastsocket getlocalhost oldserviceinfos see plugins mdns discovery javax jmdns jmdns close public void close if get state dns state canceled synchronized this synchronize only if we are not already in process to prevent dead locks stop jmdns set state dns state canceled this protects against recursive calls unregister all services dispose service collectors close socket close multicast socket stop the timer timer cancel remove the shutdown hook if shutdown null runtime get runtime remove shutdown hook shutdown mdnsdiscovery getstate dnsstate setstate dnsstate unregisterallservices disposeservicecollectors closemulticastsocket getruntime removeshutdownhook list cache entries for debugging only void print system out println cache cache print system out println see plugins mdns discovery javax jmdns jmdns print services public void print services system err println to string mdnsdiscovery printservices printservices tostring public string to string final string buffer a log new string buffer a log append t services if services null for final iterator k services key set iterator k has next final object key k next a log append n t t service key services get key a log append n a log append t types if service types null for final iterator k service types key set iterator k has next final object key k next a log append n t t type key service types get key a log append n a log append cache to string a log append n a log append t service collectors if service collectors null synchronized service collectors for final iterator k service collectors key set iterator k has next final object key k next a log append n t t service collector key service collectors get key service collectors clear return a log to string tostring stringbuffer alog stringbuffer alog keyset hasnext alog tservice alog alog servicetypes servicetypes keyset hasnext alog ttype servicetypes alog alog tostring alog alog servicecollectors servicecollectors servicecollectors keyset hasnext alog tservice servicecollectors servicecollectors alog tostring see plugins mdns discovery javax jmdns jmdns list java lang string public service info list string type implementation note the first time a list for a given type is requested a service collector is created which collects service infos this greatly speeds up the performance of subsequent calls to this method the caveats are that 1 the first call to this method for a given type is slow and 2 we spawn a service collector instance for each service type which increases network traffic a little service collector collector boolean new collector created synchronized service collectors collector service collector service collectors get type if collector null collector new service collector type service collectors put type collector add service listener type collector new collector created true else new collector created false after creating a new service collector we collect service infos for 200 milliseconds this should be enough time to get some service infos from the network if new collector created try thread sleep 200 catch final interrupted exception e return collector list mdnsdiscovery serviceinfo servicecollector servicecollector servicecollector newcollectorcreated servicecollectors servicecollector servicecollectors servicecollector servicecollectors addservicelistener newcollectorcreated newcollectorcreated servicecollector newcollectorcreated interruptedexception this method disposes all service collector instances which have been created by calls to method code list type code see list private void dispose service collectors logger finer dispose service collectors synchronized service collectors for final iterator i service collectors values iterator i has next final service collector collector service collector i next remove service listener collector type collector service collectors clear servicecollector disposeservicecollectors disposeservicecollectors servicecollectors servicecollectors hasnext servicecollector servicecollector removeservicelistener servicecollectors public string type public service collector string type this type type servicecollector a service has been added public void service added service event event synchronized infos event getdns request service info event get type event get name 0 serviceadded serviceevent requestserviceinfo gettype getname a service has been removed public void service removed service event event synchronized infos infos remove event get name serviceremoved serviceevent getname a service hase been resolved its details are now available in the service info record public void service resolved service event event synchronized infos infos put event get name event get info serviceinfo serviceresolved serviceevent getname getinfo returns an array of all service infos which have been collected by this service collector public service info impl list synchronized infos return service info impl infos values to array new service info impl infos size servicecollector serviceinfoimpl serviceinfoimpl toarray serviceinfoimpl public string to string final string buffer a log new string buffer synchronized infos for final iterator k infos key set iterator k has next final object key k next a log append n t t service key infos get key return a log to string tostring stringbuffer alog stringbuffer keyset hasnext alog tservice alog tostring private static string to unqualified name string type string qualified name if qualified name ends with type return qualified name substring 0 qualified name length type length 1 else return qualified name tounqualifiedname qualifiedname qualifiedname endswith qualifiedname qualifiedname qualifiedname public void set state dns state state this state state setstate dnsstate public void set task timer task task this task task settask timertask public timer task get task return task timertask gettask public map get services return services getservices public void set last throttle increment long last throttle increment this last throttle increment last throttle increment setlastthrottleincrement lastthrottleincrement lastthrottleincrement lastthrottleincrement public long get last throttle increment return last throttle increment getlastthrottleincrement lastthrottleincrement public void set throttle int throttle this throttle throttle setthrottle public int get throttle return throttle getthrottle public static random get random return random getrandom public void set io lock object io lock this io lock io lock setiolock iolock iolock iolock public object get io lock return io lock getiolock iolock public void set planned answer dns incoming planned answer this planned answer planned answer setplannedanswer dnsincoming plannedanswer plannedanswer plannedanswer public dns incoming get planned answer return planned answer dnsincoming getplannedanswer plannedanswer void set local host host info local host this local host local host setlocalhost hostinfo localhost localhost localhost public map get service types return service types getservicetypes servicetypes public void set closed boolean closed this closed closed setclosed public boolean is closed return closed isclosed public multicast socket get socket return socket multicastsocket getsocket public inet address get group return group inetaddress getgroup constructor of replication master file param storage replication storage param file local file used to store data locally public replication master file replication master storage impl storage i file file this storage file storage port storage hosts storage replication ack replicationmasterfile replicationmasterstorageimpl ifile replicationack constructor of replication master file param file local file used to store data locally param hosts slave node hosts to which replicastion will be performed param ack whether master should wait acknowledgment from slave node during trasanction commit public replication master file i file file string hosts boolean ack this null file 1 hosts ack replicationmasterfile ifile private replication master file replication master storage impl storage i file file int port string hosts boolean ack this storage storage this file file this hosts hosts this ack ack this port port mutex new object sockets new socket hosts length out new output stream hosts length if ack in new input stream hosts length rc buf new byte 1 tx buf new byte 8 page page size n hosts 0 for int i 0 i hosts length i connect i if port 0 try listen socket new server socket port catch io exception x throw new storage error storage error bad replication port listening true listen thread new thread this listen thread start replicationmasterfile replicationmasterstorageimpl ifile outputstream inputstream rcbuf txbuf pagesize nhosts listensocket serversocket ioexception storageerror storageerror bad_replication_port listenthread listenthread public void run while true socket s null try s listen socket accept catch io exception x x print stack trace synchronized mutex if listening return if s null try s set so linger true linger time catch exception x try s set tcp no delay true catch exception x add connection s listensocket ioexception printstacktrace setsolinger linger_time settcpnodelay addconnection private void add connection socket s output stream os null input stream is null try os s get output stream if ack is s get input stream catch io exception x x print stack trace return synchronized mutex int n hosts length string new hosts new string n 1 system arraycopy hosts 0 new hosts 0 n new hosts n s get remote socket address to string hosts new hosts output stream new out new output stream n 1 system arraycopy out 0 new out 0 n new out n os out new out if ack input stream new in new input stream n 1 system arraycopy in 0 new in 0 n new in n is in new in socket new sockets new socket n 1 system arraycopy sockets 0 new sockets 0 n new sockets n s sockets new sockets n hosts 1 thread sync thread new synchronize thread n sync thread run sync thread start addconnection outputstream inputstream getoutputstream getinputstream ioexception printstacktrace newhosts newhosts newhosts getremotesocketaddress tostring newhosts outputstream newout outputstream newout newout newout inputstream newin inputstream newin newin newin newsockets newsockets newsockets newsockets nhosts syncthread synchronizethread syncthread syncthread int i synchronize thread int i this i i set priority thread norm priority 1 synchronizethread setpriority norm_priority public void run long size storage get database size socket s output stream os null input stream is null synchronized mutex s sockets i if s null return os out i if ack is in i for long pos 0 pos size pos page page size page pg storage pool get page pos try synchronized s bytes pack8 tx buf 0 pos system arraycopy pg data 0 tx buf 8 page page size storage pool unfix pg os write tx buf if ack pos 0 is read rc buf 1 continue catch io exception x x print stack trace synchronized mutex if sockets i null handle error hosts i sockets i null out i null n hosts 1 return synchronized s bytes pack8 tx buf 0 replication slave storage impl repl sync try os write tx buf end of sycnhronization catch io exception x x print stack trace getdatabasesize outputstream inputstream pagesize getpage txbuf txbuf pagesize txbuf rcbuf ioexception printstacktrace handleerror nhosts txbuf replicationslavestorageimpl repl_sync txbuf ioexception printstacktrace public int get number of available hosts return n hosts getnumberofavailablehosts nhosts protected void connect int i string host hosts i int colon host index of int port integer parse int host substring colon 1 host host substring 0 colon socket socket null try int max attempts storage null storage slave connection timeout max connect attempts for int j 0 j max attempts j try socket new socket inet address get by name host port if socket null break thread sleep connection timeout catch io exception x catch interrupted exception x if socket null try try socket set so linger true linger time catch no such method error er try socket set tcp no delay true catch exception x sockets i socket out i socket get output stream if ack in i socket get input stream n hosts 1 catch io exception x handle error hosts i sockets i null out i null indexof parseint maxattempts slaveconnectiontimeout max_connect_attempts maxattempts inetaddress getbyname connection_timeout ioexception interruptedexception setsolinger linger_time nosuchmethoderror settcpnodelay getoutputstream getinputstream nhosts ioexception handleerror when overriden by base class this method perfroms socket error handling return code true code if host should be reconnected and attempt to send data to it should be repeated code false code if no more attmpts to communicate with this host should be performed public boolean handle error string host system err println failed to establish connection with host host return storage null storage listener null storage listener replication error host false handleerror replicationerror public void write long pos byte buf synchronized mutex for int i 0 i out length i while out i null try synchronized sockets i bytes pack8 tx buf 0 pos system arraycopy buf 0 tx buf 8 buf length out i write tx buf if ack pos 0 in i read rc buf 1 break catch io exception x out i null sockets i null n hosts 1 if handle error hosts i connect i else break file write pos buf txbuf txbuf txbuf rcbuf ioexception nhosts handleerror public int read long pos byte buf return file read pos buf public void sync file sync public boolean try lock boolean shared return file try lock shared trylock trylock public void lock boolean shared file lock shared public void unlock file unlock public void close if listen thread null synchronized mutex listening false try socket s new socket localhost port s close catch io exception x try listen thread join catch interrupted exception x try listen socket close catch io exception x file close bytes pack8 tx buf 0 replication slave storage impl repl close for int i 0 i out length i if sockets i null try out i write tx buf out i close if in null in i close sockets i close catch io exception x listenthread ioexception listenthread interruptedexception listensocket ioexception txbuf replicationslavestorageimpl repl_close txbuf ioexception public long length return file length private int value public data constant int string oid int value this oid oid this value value dataconstantint public string getsnmpoid return oid public object getsnmp data return new integer value getsnmpdata logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog create a new single file fetcher and register self called when following a redirect or direct from client get fixme many times where this is called internally we might be better off using a copy constructor public single file fetcher client requester parent get completion callback cb client metadata metadata client key key list string meta strings freeneturi origuri int added meta strings fetch context ctx boolean delete fetch context archive context actx archive handler ah metadata archive metadata int max retries int recursion level boolean dont tell client get long l boolean is essential bucket return bucket boolean is final object container container client context context throws fetch exception super key max retries ctx parent cb is essential false l container context delete fetch context if logminor logger minor this creating single file fetcher for key from origuri meta meta strings to string persistent persistent new exception debug this is final is final this cancelled false this return bucket return bucket this dont tell client get dont tell client get if persistent ah null ah ah clone handler this ah ah this archive metadata archive metadata this uri uri this key client key get base key uri meta strings uri list meta strings if meta strings instanceof array list persistent this meta strings array list string meta strings else always copy if persistent this meta strings new array list string meta strings this added meta strings added meta strings this client metadata metadata null metadata clone new client metadata this key key geturi if origuri null throw new null pointer exception this uri persistent origuri clone origuri this actx actx this recursion level recursion level 1 if recursion level ctx max recursion level throw new fetch exception fetch exception too much recursion too much recursion recursion level ctx max recursion level this decompressors new linked list compressor type singlefilefetcher clientget singlefilefetcher clientrequester getcompletioncallback clientmetadata clientkey metastrings addedmetastrings fetchcontext deletefetchcontext archivecontext archivehandler archivemetadata maxretries recursionlevel donttellclientget isessential returnbucket isfinal objectcontainer clientcontext fetchexception maxretries isessential deletefetchcontext singlefilefetcher metastrings tostring isfinal isfinal returnbucket returnbucket donttellclientget donttellclientget clonehandler archivemetadata archivemetadata clientkey getbasekey metastrings listmetastrings metastrings arraylist metastrings arraylist metastrings metastrings arraylist metastrings addedmetastrings addedmetastrings clientmetadata clientmetadata thiskey nullpointerexception recursionlevel recursionlevel recursionlevel maxrecursionlevel fetchexception fetchexception too_much_recursion recursionlevel maxrecursionlevel linkedlist compressor_type copy constructor modifies a few given fields don t call schedule used for things like slave fetchers for multi level metadata therefore does not remember return bucket meta strings etc public single file fetcher single file fetcher fetcher boolean persistent boolean delete fetch context metadata new meta array list string meta strings2 get completion callback callback fetch context ctx2 object container container client context context throws fetch exception don t add a block we have already fetched the data we are just handling the metadata in a different fetcher super persistent fetcher key clone key fetcher key fetcher max retries ctx2 fetcher parent callback false true fetcher token container context delete fetch context if logminor logger minor this creating single file fetcher for fetcher key meta fetcher meta strings to string new exception debug this return bucket null we expect significant further processing in the parent this is final false this dont tell client get fetcher dont tell client get this actx fetcher actx if persistent ah null ah ah clone handler this ah fetcher ah this archive metadata null this client metadata fetcher client metadata null fetcher client metadata clone new client metadata this metadata new meta this meta strings meta strings2 this added meta strings 0 this recursion level fetcher recursion level 1 if recursion level ctx max recursion level throw new fetch exception fetch exception too much recursion this this key persistent fetcher this key clone fetcher this key copy the decompressors just because a multi level metadata splitfile is compressed that doesn t mean that the data we are eventually going to fetch is this decompressors new linked list compressor type fetcher decompressors if fetcher uri null throw new null pointer exception this uri persistent fetcher uri clone fetcher uri multilevelmetadata returnbucket metastrings singlefilefetcher singlefilefetcher deletefetchcontext newmeta arraylist metastrings2 getcompletioncallback fetchcontext objectcontainer clientcontext fetchexception clonekey maxretries deletefetchcontext singlefilefetcher metastrings tostring returnbucket isfinal donttellclientget donttellclientget clonehandler archivemetadata clientmetadata clientmetadata clientmetadata clientmetadata newmeta metastrings metastrings2 addedmetastrings recursionlevel recursionlevel recursionlevel maxrecursionlevel fetchexception fetchexception too_much_recursion thiskey thiskey thiskey linkedlist compressor_type nullpointerexception splitfile or another single file fetcher etc override public void on success client key block block boolean from store object token object container container client context context if persistent container activate parent 1 container activate ctx 1 if parent instanceof client getter client getter parent add key to binary blob block container context parent completed block from store container context extract data if block null logger error this block is null from store from store token token new exception error return if key instanceof clientssk try if uri isssk uri isssk forusk if persistent container activate uri 5 freeneturi uu uri set meta string null usk forssk usk usk usk create uu context usk manager update known good usk uu get suggested edition context catch malformedurl exception e logger error this caught e e catch throwable t don t let the usk hint cause us to not succeed on the block logger error this caught t t bucket data extract block container context if data null if logminor logger minor this no data already failed if extract returns null it will call on failure first return if logminor logger minor this block block is metadata is metadata is not metadata on this if block is metadata on success new fetch result client metadata data container context else if ctx follow redirects on failure new fetch exception fetch exception invalid metadata told me not to follow redirects splitfile block false container context data free if persistent data remove from container return if parent is cancelled on failure new fetch exception fetch exception cancelled false container context data free if persistent data remove from container return if data size ctx max metadata size on failure new fetch exception fetch exception too big metadata false container context data free if persistent data remove from container return parse metadata try remove metadata container metadata metadata construct data if persistent container store this wrap handle metadata false container context data free if persistent data remove from container catch metadata parse exception e on failure new fetch exception fetch exception invalid metadata e false container context data free if persistent data remove from container return catch io exception e bucket error on failure new fetch exception fetch exception bucket error e false container context data free if persistent data remove from container return singlefilefetcher onsuccess clientkeyblock fromstore objectcontainer clientcontext clientgetter clientgetter addkeytobinaryblob completedblock fromstore fromstore fromstore issskforusk setmetastring uskforssk uskmanager updateknowngood getsuggestededition malformedurlexception onfailure ismetadata ismetadata onsuccess fetchresult clientmetadata followredirects onfailure fetchexception fetchexception invalid_metadata removefrom iscancelled onfailure fetchexception fetchexception removefrom maxmetadatasize onfailure fetchexception fetchexception too_big_metadata removefrom removemetadata wraphandlemetadata removefrom metadataparseexception onfailure fetchexception fetchexception invalid_metadata removefrom ioexception onfailure fetchexception fetchexception bucket_error removefrom override protected void on success fetch result result object container container client context context if persistent container activate decompressors 1 container activate parent 1 container activate ctx 1 container activate rcb 1 remove metadata container remove archive metadata container synchronized this so a single key listener isn t created finished true if parent is cancelled if logminor logger minor this parent is cancelled result as bucket free if persistent result as bucket remove from container on failure new fetch exception fetch exception cancelled false container context return if decompressors is empty bucket data result as bucket while decompressors is empty compressor type c decompressors remove last try long max len math max ctx max temp length ctx max output length if logminor logger minor this decompressing data size data size max length max len bucket out decompressors is empty return bucket null data c decompress data context get bucket factory parent persistent max len max len 4 out if logminor logger minor this decompressed to data size data size catch io exception e on failure new fetch exception fetch exception bucket error e false container context return catch compression output size exception e if logminor logger minor this too big limit ctx max output length temp ctx max temp length on failure new fetch exception fetch exception too big e estimated size rcb parent result get mime type false container context return result new fetch result result data if persistent container store this container store decompressors if ctx ignore too many path components meta strings is empty is final some meta strings left if added meta strings 0 should this be an error it would be useful to be able to fetch the data on the other hand such inserts could cause unpredictable results would be useful to make a redirect to the key we actually fetched rcb on failure new fetch exception fetch exception invalid metadata invalid metadata too many path components in redirects this key this container context else too many path components report to user if logminor logger minor this too many path components for uri meta meta strings to string freeneturi tryuri uri tryuri tryuri drop last meta strings meta strings size rcb on failure new fetch exception fetch exception too many path components result size rcb parent result get mime type tryuri this container context result as bucket free if persistent result as bucket remove from container return else if result size ctx max output length rcb on failure new fetch exception fetch exception too big result size rcb parent result get mime type this container context result as bucket free if persistent result as bucket remove from container else rcb on success result this container context onsuccess fetchresult objectcontainer clientcontext removemetadata removearchivemetadata singlekeylistener iscancelled asbucket asbucket removefrom onfailure fetchexception fetchexception isempty asbucket isempty compressor_type removelast maxlen maxtemplength maxoutputlength maxlen isempty returnbucket getbucketfactory maxlen maxlen ioexception onfailure fetchexception fetchexception bucket_error compressionoutputsizeexception maxoutputlength maxtemplength onfailure fetchexception fetchexception too_big estimatedsize getmimetype fetchresult ignoretoomanypathcomponents metastrings isempty isfinal addedmetastrings onfailure fetchexception fetchexception invalid_metadata thiskey too_many_path_components metastrings tostring droplastmetastrings metastrings onfailure fetchexception fetchexception too_many_path_components getmimetype asbucket asbucket removefrom maxoutputlength onfailure fetchexception fetchexception too_big getmimetype asbucket asbucket removefrom onsuccess handle the current metadata i e do something with it transition to a splitfile look up a manifest etc locking synchronized as it changes so many variables if we want to write the structure to disk we don t want this running at the same time throws fetch exception throws metadata parse exception throws archive failure exception throws archive restart exception private synchronized void handle metadata final object container container final client context context throws fetch exception metadata parse exception archive failure exception archive restart exception if persistent container activate this 2 1 s are probably redundant container activate metadata 100 container activate meta strings integer max value container activate this key 5 container activate ctx 2 for event producer and allowed mime types if ah null ah activate for execution container container activate parent 1 container activate actx 5 container activate client metadata 5 container activate rcb 1 container activate return bucket 5 if uri null if container null if container ext is active this throw new null pointer exception sfi this is active and uri is null else throw new null pointer exception sfi this is not active else throw new null pointer exception uri null on transient sfi this synchronized this if cancelled return so a single key listener isn t created finished true while true if metadata is simple manifest if logminor logger minor this is simple manifest string name if meta strings is empty throw new fetch exception fetch exception not enough path components 1 false null uri add meta strings new string else name remove meta string since metadata is a document we just replace metadata here if logminor logger minor this next meta string name length name length for this if name null if persistent metadata metadata get default document else metadata new meta metadata grab default document metadata remove from container metadata new meta container store this container store meta strings if metadata null throw new fetch exception fetch exception not enough path components 1 false null uri add meta strings new string else if persistent metadata metadata get document name this key this key push meta string name else metadata new meta metadata grab document name metadata remove from container metadata new meta freeneturi old this key this key this key this key push meta string name container store this container store meta strings container store this key old this key remove from container if metadata null throw new fetch exception fetch exception not in archive can t find name continue loop else if metadata is archive manifest if logminor logger minor this is archive manifest type metadata get archive type codec metadata get compression codec if meta strings is empty ctx returnzip manifests just return the archive whole metadata set simple redirect if persistent container store metadata continue first we need the archive metadata then parse it then we may need to fetch something from inside the archive it s more efficient to keep the existing ah if we can and it is vital in the case of binary blobs if ah null ah get key equals this key ah context archive manager make handler this key metadata get archive type metadata get compression codec parent instanceof client getter client getter parent collecting binary blob false persistent archive metadata metadata metadata null copied to archive metadata so do not need to clear it ah is set this means we are currently handling an archive bucket metadata bucket metadata bucket ah get metadata actx context archive manager if metadata bucket null try metadata metadata construct metadata bucket metadata bucket free catch io exception e bucket error throw new fetch exception fetch exception bucket error e if persistent container store this else final boolean persistent this persistent fetch archive false archive metadata archive manager metadata name new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this got bucket on single file fetcher this persistent persistent try metadata metadata construct data data free if persistent data remove from container wrap handle metadata true container context catch metadata parse exception e invalid metadata on failure new fetch exception fetch exception invalid metadata e false container context return catch io exception e bucket error on failure new fetch exception fetch exception bucket error e false container context return if persistent container deactivate single file fetcher this 1 public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception internal error no metadata in container cannot happen as archive manager should synthesise some false container context if persistent container deactivate single file fetcher this 1 public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 public void on failed archive failure exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 public void remove from object container container container delete this container context will result in this function being called again if persistent container store this return metadata bucket free continue else if metadata is archive metadata redirect if logminor logger minor this is archive metadata fetch it from the archive if ah null throw new fetch exception fetch exception unknown metadata archive redirect not in an archive manifest string filename metadata get archive internal name if logminor logger minor this fetching filename bucket data bucket ah get filename actx context archive manager if data bucket null if logminor logger minor this returning data final metadata new metadata try new metadata metadata construct data bucket data bucket free catch io exception e throw new fetch exception fetch exception bucket error continue with new metadata new metadata this rcb container context return else if logminor logger minor this fetching archive this key this key metadata cannot contain pointers to files which don t exist we enforce this in archive handler therefore the archive needs to be fetched final boolean persistent this persistent fetch archive true archive metadata filename new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this returning data final metadata new metadata try new metadata metadata construct data continue with new metadata new metadata single file fetcher this rcb container context catch io exception e on failure new fetch exception fetch exception bucket error false container context catch metadata parse exception e on failure new fetch exception fetch exception invalid metadata false container context catch fetch exception e on failure e false container context finally data free if persistent container deactivate single file fetcher this 1 public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception not in archive false container context if persistent container deactivate single file fetcher this 1 public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fe fetchexception metadataparseexception archivefailureexception archiverestartexception handlemetadata objectcontainer clientcontext fetchexception metadataparseexception archivefailureexception archiverestartexception metastrings max_value thiskey activateforexecution clientmetadata returnbucket isactive nullpointerexception nullpointerexception nullpointerexception singlekeylistener issimplemanifest metastrings isempty fetchexception fetchexception not_enough_path_components addmetastrings removemetastring getdefaultdocument newmeta grabdefaultdocument removefrom newmeta metastrings fetchexception fetchexception not_enough_path_components addmetastrings getdocument thiskey thiskey pushmetastring newmeta grabdocument removefrom newmeta oldthiskey thiskey thiskey thiskey pushmetastring metastrings thiskey oldthiskey removefrom fetchexception fetchexception not_in_archive isarchivemanifest getarchivetype getcompressioncodec metastrings isempty returnzipmanifests setsimpleredirect getkey thiskey archivemanager makehandler thiskey getarchivetype getcompressioncodec clientgetter clientgetter collectingbinaryblob archivemetadata archivemetadata metadatabucket metadatabucket getmetadata archivemanager metadatabucket metadatabucket metadatabucket ioexception fetchexception fetchexception bucket_error fetcharchive archivemetadata archivemanager metadata_name archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher gotbucket singlefilefetcher removefrom wraphandlemetadata metadataparseexception onfailure fetchexception fetchexception invalid_metadata ioexception onfailure fetchexception fetchexception bucket_error singlefilefetcher notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception internal_error archivemanager singlefilefetcher onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher onfailed archivefailureexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher removefrom objectcontainer metadatabucket isarchivemetadataredirect fetchexception fetchexception unknown_metadata getarchiveinternalname databucket archivemanager databucket newmetadata newmetadata databucket databucket ioexception fetchexception fetchexception bucket_error continuewithnewmetadata newmetadata thiskey thiskey archivehandler fetcharchive archivemetadata archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher newmetadata newmetadata continuewithnewmetadata newmetadata singlefilefetcher ioexception onfailure fetchexception fetchexception bucket_error metadataparseexception onfailure fetchexception fetchexception invalid_metadata fetchexception onfailure singlefilefetcher notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception not_in_archive singlefilefetcher onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefe fetch archive false archive metadata archive manager metadata name new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this got bucket on single file fetcher this persistent persistent try metadata metadata construct data data free if persistent data remove from container wrap handle metadata true container context catch metadata parse exception e invalid metadata on failure new fetch exception fetch exception invalid metadata e false container context return catch io exception e bucket error on failure new fetch exception fetch exception bucket error e false container context return if persistent container deactivate single file fetcher this 1 fetcharchive archivemetadata archivemanager metadata_name archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher gotbucket singlefilefetcher removefrom wraphandlemetadata metadataparseexception onfailure fetchexception fetchexception invalid_metadata ioexception onfailure fetchexception fetchexception bucket_error singlefilefetcher public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception internal error no metadata in container cannot happen as archive manager should synthesise some false container context if persistent container deactivate single file fetcher this 1 notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception internal_error archivemanager singlefilefetcher public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher public void on failed archive failure exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archivefailureexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher container deactivate single file fetcher this 1 public void remove from object container container container delete this singlefilefetcher removefrom objectcontainer fetch archive true archive metadata filename new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this returning data final metadata new metadata try new metadata metadata construct data continue with new metadata new metadata single file fetcher this rcb container context catch io exception e on failure new fetch exception fetch exception bucket error false container context catch metadata parse exception e on failure new fetch exception fetch exception invalid metadata false container context catch fetch exception e on failure e false container context finally data free if persistent container deactivate single file fetcher this 1 fetcharchive archivemetadata archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher newmetadata newmetadata continuewithnewmetadata newmetadata singlefilefetcher ioexception onfailure fetchexception fetchexception bucket_error metadataparseexception onfailure fetchexception fetchexception invalid_metadata fetchexception onfailure singlefilefetcher public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception not in archive false container context if persistent container deactivate single file fetcher this 1 notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception not_in_archive singlefilefetcher public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher public void on failed archive failure exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archivefailureexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher container deactivate single file fetcher this 1 public void remove from object container container container delete this singlefilefetcher removefrom objectcontainer fetch archive true archive metadata filename new archive extract callback public void got bucket bucket data object container container client context context if persistent container activate single file fetcher this 1 if logminor logger minor this returning data bucket out try data will not be freed until client is finished with it if return bucket null if persistent container activate return bucket 5 out return bucket bucket tools copy data out data free if persistent data remove from container else out data catch io exception e on failure new fetch exception fetch exception bucket error false container context return return the data on success new fetch result client metadata out container context if persistent container deactivate single file fetcher this 1 fetcharchive archivemetadata archiveextractcallback gotbucket objectcontainer clientcontext singlefilefetcher returnbucket returnbucket returnbucket buckettools removefrom ioexception onfailure fetchexception fetchexception bucket_error onsuccess fetchresult clientmetadata singlefilefetcher public void not in archive object container container client context context if persistent container activate single file fetcher this 1 on failure new fetch exception fetch exception not in archive false container context if persistent container deactivate single file fetcher this 1 notinarchive objectcontainer clientcontext singlefilefetcher onfailure fetchexception fetchexception not_in_archive singlefilefetcher public void on failed archive restart exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archiverestartexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher public void on failed archive failure exception e object container container client context context if persistent container activate single file fetcher this 1 single file fetcher this on failure new fetch exception e false container context if persistent container deactivate single file fetcher this 1 onfailed archivefailureexception objectcontainer clientcontext singlefilefetcher singlefilefetcher onfailure fetchexception singlefilefetcher container deactivate single file fetcher this 1 public void remove from object container container container delete this singlefilefetcher removefrom objectcontainer private void continue with new metadata metadata new metadata get completion callback callback object container container client context context throws fetch exception final single file fetcher f new single file fetcher this persistent false new metadata new array list string meta strings callback ctx container context clear our own metadata so it can be garbage collected it will be replaced by whatever is fetched the new fetcher has our metadata so we don t need to remove metadata metadata null if persistent container store this if persistent container store f we must transition to the sub fetcher so that if the request is cancelled it will get deleted parent on transition this f container f wrap handle metadata true container context if persistent container deactivate f 1 return continuewithnewmetadata newmetadata getcompletioncallback objectcontainer clientcontext fetchexception singlefilefetcher singlefilefetcher newmetadata arraylist metastrings removemetadata ontransition wraphandlemetadata private string remove meta string string name meta strings remove 0 if added meta strings 0 added meta strings return name removemetastring metastrings addedmetastrings addedmetastrings private void add decompressor compressor type codec if logminor logger minor this adding decompressor codec on this new exception debug decompressors add codec adddecompressor compressor_type private void fetch archive boolean for data metadata meta string element archive extract callback callback final object container container client context context throws fetch exception metadata parse exception archive failure exception archive restart exception if logminor logger minor this fetch archive fetch the archive how spawn a separate single file fetcher which fetches the archive then calls our callback which unpacks the archive then reschedules us metadata new meta metadata meta clone new meta set simple redirect final single file fetcher f f new single file fetcher this persistent true new meta new array list string new archive fetcher callback for data element callback new fetch context ctx fetch context set return archives true null container context if persistent container store f if logminor logger minor this fetch archive f fetch the archive the archive fetcher callback will unpack it and either call the element callback or just go back around handle metadata on this which will see that the data is now available we need to transition here so that everything gets deleted if we are cancelled during the archive fetch phase if persistent container activate parent 1 parent on transition this f container f wrap handle metadata true container context if persistent container deactivate f 1 fetcharchive fordata archiveextractcallback objectcontainer clientcontext fetchexception metadataparseexception archivefailureexception archiverestartexception fetcharchive singlefilefetcher newmeta newmeta setsimpleredirect singlefilefetcher singlefilefetcher newmeta arraylist archivefetchercallback fordata fetchcontext fetchcontext set_return_archives fetcharchive handlemetadata ontransition wraphandlemetadata call handle metadata and deal with any resulting exceptions private void wrap handle metadata final boolean not finalized size object container container final client context context if persistent inner wrap handle metadata not finalized size container context else if context job runner on database thread context job runner queue new db job public void run object container container client context context if container ext is active single file fetcher this logger error this already active in sff callback single file fetcher this container activate single file fetcher this 1 inner wrap handle metadata not finalized size container context container deactivate single file fetcher this 1 parent get priority class false else inner wrap handle metadata not finalized size container context handlemetadata wraphandlemetadata notfinalizedsize objectcontainer clientcontext innerwraphandlemetadata notfinalizedsize jobrunner ondatabasethread jobrunner dbjob objectcontainer clientcontext isactive singlefilefetcher singlefilefetcher singlefilefetcher innerwraphandlemetadata notfinalizedsize singlefilefetcher getpriorityclass innerwraphandlemetadata notfinalizedsize context job runner queue new db job public void run object container container client context context if container ext is active single file fetcher this logger error this already active in sff callback single file fetcher this container activate single file fetcher this 1 inner wrap handle metadata not finalized size container context container deactivate single file fetcher this 1 jobrunner dbjob objectcontainer clientcontext isactive singlefilefetcher singlefilefetcher singlefilefetcher innerwraphandlemetadata notfinalizedsize singlefilefetcher protected void inner wrap handle metadata boolean not finalized size object container container client context context try handle metadata container context catch metadata parse exception e on failure new fetch exception fetch exception invalid metadata e false container context catch fetch exception e if not finalized size e set not finalized size on failure e false container context catch archive failure exception e on failure new fetch exception e false container context catch archive restart exception e on failure new fetch exception e false container context innerwraphandlemetadata notfinalizedsize objectcontainer clientcontext handlemetadata metadataparseexception onfailure fetchexception fetchexception invalid_metadata fetchexception notfinalizedsize setnotfinalizedsize onfailure archivefailureexception onfailure fetchexception archiverestartexception onfailure fetchexception archive fetcher callback boolean was fetching final data string element archive extract callback cb this was fetching final data was fetching final data this element element this callback cb this persistent single file fetcher this persistent archivefetchercallback wasfetchingfinaldata archiveextractcallback wasfetchingfinaldata wasfetchingfinaldata singlefilefetcher public void on success fetch result result client get state state object container container client context context if persistent run directly we are running on some thread somewhere don t worry about it inner success result container context else boolean was active we are running on the database thread add a tag unpack on a separate thread copy the data to a persistent bucket then schedule on the database thread remove the tag and call the callback was active container ext is active single file fetcher this if was active container activate single file fetcher this 1 container activate parent 1 parent on transition state single file fetcher this container if persistent container activate actx 1 ah activate for execution container ah extract persistent off thread result as bucket true actx element callback container context if was active container deactivate single file fetcher this 1 if state null state remove from container context container delete this onsuccess fetchresult clientgetstate objectcontainer clientcontext innersuccess wasactive wasactive isactive singlefilefetcher wasactive singlefilefetcher ontransition singlefilefetcher activateforexecution extractpersistentoffthread asbucket wasactive singlefilefetcher removefrom private void inner success fetch result result object container container client context context try ah extract to cache result as bucket actx element callback context archive manager container context catch archive failure exception e single file fetcher this on failure new fetch exception e false container context return catch archive restart exception e single file fetcher this on failure new fetch exception e false container context return finally result as bucket free if persistent result as bucket remove from container if callback null return wrap handle metadata true container context innersuccess fetchresult objectcontainer clientcontext extracttocache asbucket archivemanager archivefailureexception singlefilefetcher onfailure fetchexception archiverestartexception singlefilefetcher onfailure fetchexception asbucket asbucket removefrom wraphandlemetadata public void on failure fetch exception e client get state state object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this if was active container activate single file fetcher this 1 force fatal as the fetcher is presumed to have made a reasonable effort single file fetcher this on failure e true container context if was active container deactivate single file fetcher this 1 if persistent if state null state remove from container context container delete this callback remove from container onfailure fetchexception clientgetstate objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher wasactive singlefilefetcher singlefilefetcher onfailure wasactive singlefilefetcher removefrom removefrom public void on block set finished client get state state object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this if was active container activate single file fetcher this 1 if persistent container activate rcb 1 if was fetching final data rcb on block set finished single file fetcher this container context if was active container deactivate single file fetcher this 1 onblocksetfinished clientgetstate objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher wasactive singlefilefetcher wasfetchingfinaldata onblocksetfinished singlefilefetcher wasactive singlefilefetcher public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void on expectedmime string mime object container container client context context ignore onexpectedmime objectcontainer clientcontext public void on expected size long size object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this if was active container activate single file fetcher this 1 if persistent container activate rcb 1 rcb on expected size size container context if was active container deactivate single file fetcher this 1 onexpectedsize objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher wasactive singlefilefetcher onexpectedsize wasactive singlefilefetcher public void on finalized metadata object container container ignore onfinalizedmetadata objectcontainer private final boolean persistent multi level metadata callback this persistent single file fetcher this persistent multilevelmetadatacallback singlefilefetcher public void on success fetch result result client get state state object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this container activate single file fetcher this 1 container activate parent 1 try parent on transition state single file fetcher this container metadata meta metadata construct result as bucket remove metadata container synchronized single file fetcher this metadata meta if persistent container store meta container store single file fetcher this wrap handle metadata true container context catch metadata parse exception e single file fetcher this on failure new fetch exception fetch exception invalid metadata e false container context catch io exception e bucket error single file fetcher this on failure new fetch exception fetch exception bucket error e false container context finally result as bucket free if persistent result as bucket remove from container if was active container deactivate single file fetcher this 1 if persistent if state null state remove from container context container delete this onsuccess fetchresult clientgetstate objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher singlefilefetcher ontransition singlefilefetcher asbucket removemetadata singlefilefetcher singlefilefetcher wraphandlemetadata metadataparseexception singlefilefetcher onfailure fetchexception fetchexception invalid_metadata ioexception singlefilefetcher onfailure fetchexception fetchexception bucket_error asbucket asbucket removefrom wasactive singlefilefetcher removefrom public void on failure fetch exception e client get state state object container container client context context boolean was active true if persistent was active container ext is active single file fetcher this container activate single file fetcher this 1 pass it on fetcher is assumed to have retried as appropriate already so this is fatal single file fetcher this on failure e true container context if was active container deactivate single file fetcher this 1 if persistent if state null state remove from container context conceivably remove from could deactivate this so don t recheck container delete this onfailure fetchexception clientgetstate objectcontainer clientcontext wasactive wasactive isactive singlefilefetcher singlefilefetcher singlefilefetcher onfailure wasactive singlefilefetcher removefrom removefrom public void on block set finished client get state state object container container client context context ignore as we are fetching metadata here onblocksetfinished clientgetstate objectcontainer clientcontext public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void on expectedmime string mime object container container client context context ignore onexpectedmime objectcontainer clientcontext public void on expected size long size object container container client context context boolean was active true boolean cb was active true if persistent was active container ext is active single file fetcher this container activate single file fetcher this 1 cb was active container ext is active rcb container activate rcb 1 rcb on expected size size container context if was active container deactivate single file fetcher this 1 if cb was active container deactivate rcb 1 onexpectedsize objectcontainer clientcontext wasactive cbwasactive wasactive isactive singlefilefetcher singlefilefetcher cbwasactive isactive onexpectedsize wasactive singlefilefetcher cbwasactive public void on finalized metadata object container container ignore onfinalizedmetadata objectcontainer override public boolean ignore store return ctx ignore store ignorestore ignorestore create a fetcher for a key public static client get state create client requester requester get completion callback cb freeneturi uri fetch context ctx archive context actx int max retries int recursion level boolean dont tell client get long l boolean is essential bucket return bucket boolean is final object container container client context context throws malformedurl exception fetch exception base client key key base client key get base key uri if uri has meta strings ctx allow splitfiles false ctx follow redirects false return bucket null key instanceof client key return new simple single file fetcher client key key max retries ctx requester cb is essential false l container context false if key instanceof client key return new single file fetcher requester cb null client key key new array list string uri list meta strings uri 0 ctx false actx null null max retries recursion level dont tell client get l is essential return bucket is final container context else return usk create requester cb usk key new array list string uri list meta strings ctx actx max retries recursion level dont tell client get l is essential return bucket is final container context clientgetstate clientrequester getcompletioncallback fetchcontext archivecontext maxretries recursionlevel donttellclientget isessential returnbucket isfinal objectcontainer clientcontext malformedurlexception fetchexception baseclientkey baseclientkey getbasekey hasmetastrings allowsplitfiles followredirects returnbucket clientkey simplesinglefilefetcher clientkey maxretries isessential clientkey singlefilefetcher clientkey arraylist listmetastrings maxretries recursionlevel donttellclientget isessential returnbucket isfinal uskcreate arraylist listmetastrings maxretries recursionlevel donttellclientget isessential returnbucket isfinal private static client get state usk create client requester requester get completion callback cb usk usk array list string meta strings fetch context ctx archive context actx int max retries int recursion level boolean dont tell client get long l boolean is essential bucket return bucket boolean is final object container container client context context throws fetch exception if usk suggested edition 0 return the latest known version but at least suggested edition long edition context usk manager lookup known good usk if edition usk suggested edition background fetch start background fetch first so can pick up updates in the datastore during registration context usk manager start temporary background fetcher usk context ctx true edition context usk manager lookup known good usk if edition usk suggested edition if logminor logger minor single file fetcher class redirecting to edition edition cb on failure new fetch exception fetch exception permanent redirect usk copy edition geturi add meta strings meta strings null container context return null else transition to single file fetcher get completion callback mycb new usk proxy completion callback usk cb requester persistent want to update the latest known good iff the fetch succeeds single file fetcher sf new single file fetcher requester mycb null usk getssk meta strings usk geturi add meta strings meta strings 0 ctx false actx null null max retries recursion level dont tell client get l is essential return bucket is final container context return sf else cb on failure new fetch exception fetch exception permanent redirect usk copy edition geturi add meta strings meta strings null container context return null else do a thorough blocking search usk fetcher tag tag context usk manager get fetcher usk copy usk suggested edition ctx false requester persistent new myusk fetcher callback requester cb usk meta strings ctx actx max retries recursion level dont tell client get l return bucket requester persistent false container context if is essential requester add must succeed blocks 1 container return tag clientgetstate uskcreate clientrequester getcompletioncallback arraylist metastrings fetchcontext archivecontext maxretries recursionlevel donttellclientget isessential returnbucket isfinal objectcontainer clientcontext fetchexception suggestededition suggestededition uskmanager lookupknowngood suggestededition uskmanager starttemporarybackgroundfetcher uskmanager lookupknowngood suggestededition singlefilefetcher onfailure fetchexception fetchexception permanent_redirect addmetastrings metastrings singlefilefetcher getcompletioncallback uskproxycompletioncallback singlefilefetcher singlefilefetcher metastrings addmetastrings metastrings maxretries recursionlevel donttellclientget isessential returnbucket isfinal onfailure fetchexception fetchexception permanent_redirect addmetastrings metastrings uskfetchertag uskmanager getfetcher suggestededition myuskfetchercallback metastrings maxretries recursionlevel donttellclientget returnbucket isessential addmustsucceedblocks public myusk fetcher callback client requester requester get completion callback cb usk usk array list string meta strings fetch context ctx archive context actx int max retries int recursion level boolean dont tell client get long l bucket return bucket boolean persistent this parent requester this cb cb this usk usk this meta strings meta strings this ctx ctx this actx actx this max retries max retries this recursion level recursion level this dont tell client get dont tell client get this token l this return bucket return bucket this persistent persistent myuskfetchercallback clientrequester getcompletioncallback arraylist metastrings fetchcontext archivecontext maxretries recursionlevel donttellclientget returnbucket metastrings metastrings maxretries maxretries recursionlevel recursionlevel donttellclientget donttellclientget returnbucket returnbucket public void on found edition long l usk newusk object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too if persistent container activate this 2 clientssk key usk getssk l try if l usk suggested edition single file fetcher sf new single file fetcher parent cb null key meta strings key geturi add meta strings meta strings 0 ctx false actx null null max retries recursion level 1 dont tell client get token false return bucket true container context sf schedule container context if persistent remove from container else cb on failure new fetch exception fetch exception permanent redirect newusk geturi add meta strings meta strings null container context if persistent remove from container catch fetch exception e cb on failure e null container context if persistent remove from container onfoundedition objectcontainer clientcontext newknowngood newslottoo suggestededition singlefilefetcher singlefilefetcher metastrings addmetastrings metastrings maxretries recursionlevel donttellclientget returnbucket removefrom onfailure fetchexception fetchexception permanent_redirect addmetastrings metastrings removefrom fetchexception onfailure removefrom private void remove from object container container container delete meta strings container delete this container activate usk 5 usk remove from container removefrom objectcontainer metastrings removefrom public void on failure object container container client context context if persistent container activate this 2 cb on failure new fetch exception fetch exception data not found no usk found null container context if persistent remove from container onfailure objectcontainer clientcontext onfailure fetchexception fetchexception data_not_found removefrom public void on cancelled object container container client context context if persistent container activate this 2 cb on failure new fetch exception fetch exception cancelled string null null container context if persistent remove from container oncancelled objectcontainer clientcontext onfailure fetchexception fetchexception removefrom public short get polling priority normal return parent get priority class getpollingprioritynormal getpriorityclass public short get polling priority progress return parent get priority class getpollingpriorityprogress getpriorityclass override public void remove from object container container client context context if logminor logger minor this remove from on this container activate uri 5 uri remove from container if this key null container activate this key 5 this key remove from container if ah null ah activate for execution container ah remove from container container activate meta strings 1 meta strings clear container delete meta strings container activate client metadata 1 client metadata remove from container actx is global to the client request not our problem container activate decompressors 1 decompressors clear remove metadata container remove archive metadata container container delete decompressors super remove from container context removefrom objectcontainer clientcontext removefrom removefrom thiskey thiskey thiskey removefrom activateforexecution removefrom metastrings metastrings metastrings clientmetadata clientmetadata removefrom clientrequest removemetadata removearchivemetadata removefrom private void remove metadata object container container if persistent return if logminor logger minor this remove metadata on this if metadata null return container activate metadata 1 metadata remove from container metadata null removemetadata objectcontainer removemetadata removefrom private void remove archive metadata object container container if persistent return if logminor logger minor this remove archive metadata on this if archive metadata null return container activate archive metadata 1 archive metadata remove from container archive metadata null removearchivemetadata objectcontainer removearchivemetadata archivemetadata archivemetadata archivemetadata removefrom archivemetadata public message type string name short priority this name priority false messagetype public message type string name short priority boolean internal name name this priority priority internal only internal integer id integer value of name hash code if specs contains key id throw new runtime exception a message type by the name of name already exists specs put id this messagetype _name internalonly valueof hashcode _specs containskey runtimeexception _specs public void unregister specs remove integer value of name hash code _specs valueof _name hashcode public void add linked list field string name class parameter linkedlisttypes put name parameter add field name linked list class addlinkedlistfield _linkedlisttypes addfield linkedlist public void add field string name class type fields put name type orderedfields add last name addfield _fields _orderedfields addlast public void add routed to node message fields add field dmt uid long class add field dmt target location double class add field dmt htl short class add field dmt node identity short buffer class addroutedtonodemessagefields addfield addfield target_location addfield addfield node_identity shortbuffer public boolean check type string field name object field value if field value null return false class def class fields get field name class value class field value get class if def class value class return true if def class is assignable from value class return true return false checktype fieldname fieldvalue fieldvalue defclass _fields fieldname valueclass fieldvalue getclass defclass valueclass defclass isassignablefrom valueclass public class type of string field return fields get field typeof _fields override public boolean equals object o if o instanceof message type return false we can only register one message type for each name so we can do here return message type o name name messagetype messagetype messagetype _name _name override public int hash code return name hash code hashcode _name hashcode public static message type get spec integer specid if specs contains key specid logger error message type class unrecognised message type received specid return null return specs get specid messagetype getspec _specs containskey messagetype _specs public string get name return name getname _name public map string class get fields return fields getfields _fields public linked list string get ordered fields return orderedfields linkedlist getorderedfields _orderedfields public map string class get linked list types return linkedlisttypes getlinkedlisttypes _linkedlisttypes return true if this message is internal only if this is the case any incoming messages in udp form of this spec will be silently discarded public boolean is internal only return internal only isinternalonly internalonly public short get priority return priority getpriority get current version in version history current version can be explicitely set by set version or result of last check out is used as current version public synchronized v get current return current setversion checkout getcurrent set new current version in version history param version new current version in version history it must belong to version history public synchronized void set current v version current version modify setcurrent checkout current version create successor of the current version this version has to be checked in in order to be placed in version history return checked out version public synchronized v checkout assert that current is checked in return v current new version ischeckedin newversion get root version return root version in this version history public synchronized v get root return versions get 0 getroot get latest version before specified date param timestamp deadline if code null code then the latest version in version history will be returned return version with the largest timestamp less than or equal to specified code timestamp code public synchronized v get latest before date timestamp if timestamp null return versions get versions size 1 int l 0 n versions size r n long t timestamp get time 1 while l r int m l r 1 if versions get m get date get time t l m 1 else r m return r 0 versions get r 1 null getlatestbefore gettime getdate gettime get earliest version after specified date param timestamp deadline if code null code then root version will be returned return version with the smallest timestamp greater than or equal to specified code timestamp code public synchronized v get earliest after date timestamp if timestamp null return versions get 0 int l 0 n versions size r n long t timestamp get time while l r int m l r 1 if versions get m get date get time t l m 1 else r m return r n versions get r null getearliestafter gettime getdate gettime get version with specified label if there are more than one version marked with this label then the latest one will be returned param label version label return latest version with specified label public synchronized v get version by label string label for int i versions size i 0 v v versions get i if v has label label return v return null getversionbylabel haslabel get version with specified id param id version id return version with specified id public synchronized v get version by id string id for int i versions size i 0 v v versions get i if v get id equals id return v return null getversionbyid getid get all versions in version history return array of versions sorted by date public synchronized version get all versions return versions to array new version versions size getallversions toarray get iterator through all version in version history iteration is started from the root version and performed in direction of increaing version timestamp this iterator supports remove method return version iterator public synchronized iterator v iterator return versions iterator create new version history param root root version public version history v root versions root get storage v create link 1 versions add root current root current history this versionhistory getstorage createlink construct a fill filter public fill filter this 0xff000000 fillfilter fillfilter construct a fill filter param color the fill color public fill filter int color this fill color color fillfilter fillfilter fillcolor set the fill color param fill color the fill color see get fill color public void set fill color int fill color this fill color fill color fillcolor getfillcolor setfillcolor fillcolor fillcolor fillcolor get the fill color return the fill color see set fill color public int get fill color return fill color setfillcolor getfillcolor fillcolor override public int filterrgb int x int y int rgb return fill color fillcolor public security levels node node persistent config config this node node sub config my config new sub config security levels config int sort order 0 network threat level callback new my callback network threat level override public string get synchronized security levels this return network threat level name public string get possible values network threat level values network threat level values string names new string values length for int i 0 i names length i names i values i name return names override protected network threat level get value return network threat level override protected void set value string val throws invalid config value exception network threat level new value parse network threat level val if new value null throw new invalid config value exception invalid value for network threat level val synchronized security levels this network threat level new value my config register network threat level high sort order false true security levels network threat level short security levels network threat level network threat level callback network threat level net level network threat level value of my config get string network threat level if my config get raw option network threat level null network threat level net level else call all the callbacks so that the config is consistent with the threat level set threat level net level friends threat level callback new my callback friends threat level override public string get synchronized security levels this return friends threat level name public string get possible values friends threat level values friends threat level values string names new string values length for int i 0 i names length i names i values i name return names override protected friends threat level get value return friends threat level override protected void set value string val throws invalid config value exception friends threat level new value friends threat level value of val if new value null throw new invalid config value exception invalid value for friends threat level val synchronized security levels this friends threat level new value my config register friends threat level normal sort order false true security levels friends threat level short security levels friends threat level friends threat level callback friends threat level friends level friends threat level value of my config get string friends threat level if my config get raw option friends threat level null friends threat level friends level else call all the callbacks so that the config is consistent with the threat level set threat level friends level physical threat level callback new my callback physical threat level override public string get synchronized security levels this return physical threat level name public string get possible values physical threat level values physical threat level values string names new string values length for int i 0 i names length i names i values i name return names override protected physical threat level get value return physical threat level override protected void set value string val throws invalid config value exception physical threat level new value physical threat level value of val if new value null throw new invalid config value exception invalid value for physical threat level val synchronized security levels this physical threat level new value my config register physical threat level normal sort order false true security levels physical threat level short security levels physical threat level physical threat level callback physical threat level phys level physical threat level value of my config get string physical threat level if my config get raw option physical threat level null physical threat level phys level else call all the callbacks so that the config is consistent with the threat level set threat level phys level my config finished initialization securitylevels persistentconfig subconfig myconfig subconfig sortorder networkthreatlevelcallback mycallback network_threat_level securitylevels networkthreatlevel getpossiblevalues network_threat_level network_threat_level network_threat_level getvalue networkthreatlevel setvalue invalidconfigvalueexception network_threat_level newvalue parsenetworkthreatlevel newvalue invalidconfigvalueexception securitylevels networkthreatlevel newvalue myconfig networkthreatlevel sortorder securitylevels networkthreatlevelshort securitylevels networkthreatlevel networkthreatlevelcallback network_threat_level netlevel network_threat_level valueof myconfig getstring networkthreatlevel myconfig getrawoption networkthreatlevel networkthreatlevel netlevel setthreatlevel netlevel friendsthreatlevelcallback mycallback friends_threat_level securitylevels friendsthreatlevel getpossiblevalues friends_threat_level friends_threat_level friends_threat_level getvalue friendsthreatlevel setvalue invalidconfigvalueexception friends_threat_level newvalue friends_threat_level valueof newvalue invalidconfigvalueexception securitylevels friendsthreatlevel newvalue myconfig friendsthreatlevel sortorder securitylevels friendsthreatlevelshort securitylevels friendsthreatlevel friendsthreatlevelcallback friends_threat_level friendslevel friends_threat_level valueof myconfig getstring friendsthreatlevel myconfig getrawoption friendsthreatlevel friendsthreatlevel friendslevel setthreatlevel friendslevel physicalthreatlevelcallback mycallback physical_threat_level securitylevels physicalthreatlevel getpossiblevalues physical_threat_level physical_threat_level physical_threat_level getvalue physicalthreatlevel setvalue invalidconfigvalueexception physical_threat_level newvalue physical_threat_level valueof newvalue invalidconfigvalueexception securitylevels physicalthreatlevel newvalue myconfig physicalthreatlevel sortorder securitylevels physicalthreatlevelshort securitylevels physicalthreatlevel physicalthreatlevelcallback physical_threat_level physlevel physical_threat_level valueof myconfig getstring physicalthreatlevel myconfig getrawoption physicalthreatlevel physicalthreatlevel physlevel setthreatlevel physlevel myconfig finishedinitialization override public string get synchronized security levels this return network threat level name securitylevels networkthreatlevel public string get possible values network threat level values network threat level values string names new string values length for int i 0 i names length i names i values i name return names getpossiblevalues network_threat_level network_threat_level override protected network threat level get value return network threat level network_threat_level getvalue networkthreatlevel override protected void set value string val throws invalid config value exception network threat level new value parse network threat level val if new value null throw new invalid config value exception invalid value for network threat level val synchronized security levels this network threat level new value setvalue invalidconfigvalueexception network_threat_level newvalue parsenetworkthreatlevel newvalue invalidconfigvalueexception securitylevels networkthreatlevel newvalue override public string get synchronized security levels this return friends threat level name securitylevels friendsthreatlevel public string get possible values friends threat level values friends threat level values string names new string values length for int i 0 i names length i names i values i name return names getpossiblevalues friends_threat_level friends_threat_level override protected friends threat level get value return friends threat level friends_threat_level getvalue friendsthreatlevel override protected void set value string val throws invalid config value exception friends threat level new value friends threat level value of val if new value null throw new invalid config value exception invalid value for friends threat level val synchronized security levels this friends threat level new value setvalue invalidconfigvalueexception friends_threat_level newvalue friends_threat_level valueof newvalue invalidconfigvalueexception securitylevels friendsthreatlevel newvalue override public string get synchronized security levels this return physical threat level name securitylevels physicalthreatlevel public string get possible values physical threat level values physical threat level values string names new string values length for int i 0 i names length i names i values i name return names getpossiblevalues physical_threat_level physical_threat_level override protected physical threat level get value return physical threat level physical_threat_level getvalue physicalthreatlevel override protected void set value string val throws invalid config value exception physical threat level new value physical threat level value of val if new value null throw new invalid config value exception invalid value for physical threat level val synchronized security levels this physical threat level new value setvalue invalidconfigvalueexception physical_threat_level newvalue physical_threat_level valueof newvalue invalidconfigvalueexception securitylevels physicalthreatlevel newvalue public synchronized void add network threat level listener security level listener network threat level listener network threat level callback add listener listener addnetworkthreatlevellistener securitylevellistener network_threat_level networkthreatlevelcallback addlistener public synchronized void add friends threat level listener security level listener friends threat level listener friends threat level callback add listener listener addfriendsthreatlevellistener securitylevellistener friends_threat_level friendsthreatlevelcallback addlistener public synchronized void add physical threat level listener security level listener physical threat level listener physical threat level callback add listener listener addphysicalthreatlevellistener securitylevellistener physical_threat_level physicalthreatlevelcallback addlistener private final array list security level listener t listeners my callback listeners new array list security level listener t arraylist securitylevellistener mycallback arraylist securitylevellistener public void add listener security level listener t listener if listeners contains listener logger error this already have listener listener in this return listeners add listener addlistener securitylevellistener override public void set string val throws invalid config value exception node need restart exception t old level get value set value val t new level get value on set old level new level invalidconfigvalueexception nodeneedrestartexception oldlevel getvalue setvalue newlevel getvalue onset oldlevel newlevel void on set t old level t new level for security level listener t listener listeners listener on change old level new level onset oldlevel newlevel securitylevellistener onchange oldlevel newlevel protected abstract void set value string val throws invalid config value exception setvalue invalidconfigvalueexception protected abstract void set value string val throws invalid config value exception protected abstract t get value setvalue invalidconfigvalueexception getvalue public network threat level get network threat level return network threat level network_threat_level getnetworkthreatlevel networkthreatlevel public friends threat level get friends threat level return friends threat level friends_threat_level getfriendsthreatlevel friendsthreatlevel public physical threat level get physical threat level return physical threat level physical_threat_level getphysicalthreatlevel physicalthreatlevel public static network threat level parse network threat level string arg try return network threat level value of arg catch illegal argument exception e return null network_threat_level parsenetworkthreatlevel network_threat_level valueof illegalargumentexception public static friends threat level parse friends threat level string arg try return friends threat level value of arg catch illegal argument exception e return null friends_threat_level parsefriendsthreatlevel friends_threat_level valueof illegalargumentexception public static physical threat level parse physical threat level string arg try return physical threat level value of arg catch illegal argument exception e return null physical_threat_level parsephysicalthreatlevel physical_threat_level valueof illegalargumentexception if changing to the new threat level is a potential problem warn the user and include a checkbox for confirmation param new threat level return public html node get confirm warning network threat level new threat level string checkbox name if new threat level network threat level return null not going to be changed html node parent new html node div if new threat level network threat level high network threat level network threat level maximum new threat level network threat level maximum if node peers get darknet peers length 0 parent add child p l10n no friends warning if new threat level network threat level maximum html node p parent add child p l10n addl10n substitution p security levels maximum network threat level warning new string bold bold new string b b parent add child input new string type name value new string checkbox checkbox name off l10n no friends checkbox return parent else if node peers count connected darknet peers 0 parent add child p l10n no connected friends warning added integer to string node peers get darknet peers length if new threat level network threat level maximum html node p parent add child p l10n addl10n substitution p security levels maximum network threat level warning new string bold bold new string b b parent add child input new string type name value new string checkbox checkbox name off l10n no connected friends checkbox return parent else if node peers count connected darknet peers 10 parent add child p l10n few connected friends warning new string connected added new string integer to string node peers count connected darknet peers integer to string node peers get darknet peers length if new threat level network threat level maximum html node p parent add child p l10n addl10n substitution p security levels maximum network threat level warning new string bold bold new string b b parent add child input new string type name value new string checkbox checkbox name off l10n few connected friends checkbox return parent else if new threat level network threat level low parent add child p l10n network threat level low warning parent add child input new string type name value new string checkbox checkbox name off l10n network threat level low checkbox return parent don t warn on switching to normal if new threat level network threat level maximum html node p parent add child p l10n addl10n substitution p security levels maximum network threat level warning new string bold bold new string b b p add child l10n addl10n substitution p security levels max security you need friends new string bold bold new string b b parent add child input new string type name value new string checkbox checkbox name off l10n maximum network threat level checkbox return parent return null newthreatlevel htmlnode getconfirmwarning network_threat_level newthreatlevel checkboxname newthreatlevel networkthreatlevel htmlnode htmlnode newthreatlevel network_threat_level networkthreatlevel network_threat_level newthreatlevel network_threat_level getdarknetpeers addchild nofriendswarning newthreatlevel network_threat_level htmlnode addchild addl10nsubstitution securitylevels maximumnetworkthreatlevelwarning addchild checkboxname nofriendscheckbox countconnecteddarknetpeers addchild noconnectedfriendswarning tostring getdarknetpeers newthreatlevel network_threat_level htmlnode addchild addl10nsubstitution securitylevels maximumnetworkthreatlevelwarning addchild checkboxname noconnectedfriendscheckbox countconnecteddarknetpeers addchild fewconnectedfriendswarning tostring countconnecteddarknetpeers tostring getdarknetpeers newthreatlevel network_threat_level htmlnode addchild addl10nsubstitution securitylevels maximumnetworkthreatlevelwarning addchild checkboxname fewconnectedfriendscheckbox newthreatlevel network_threat_level addchild networkthreatlevellowwarning addchild checkboxname networkthreatlevellowcheckbox newthreatlevel network_threat_level htmlnode addchild addl10nsubstitution securitylevels maximumnetworkthreatlevelwarning addchild addl10nsubstitution securitylevels maxsecurityyouneedfriends addchild checkboxname maximumnetworkthreatlevelcheckbox public html node get confirm warning friends threat level new friends level string checkbox name if new friends level friends threat level return null not going to be changed if new friends level friends threat level high html node parent new html node div parent add child p l10n high friends threat level warning parent add child input new string type name value new string checkbox checkbox name off l10n high friends threat level checkbox return parent return null htmlnode getconfirmwarning friends_threat_level newfriendslevel checkboxname newfriendslevel friendsthreatlevel newfriendslevel friends_threat_level htmlnode htmlnode addchild highfriendsthreatlevelwarning addchild checkboxname highfriendsthreatlevelcheckbox private string l10n string string return l10n get string security levels string getstring securitylevels private string l10n string string string pattern string value return l10n get string security levels string pattern value getstring securitylevels private string l10n string string string patterns string values return l10n get string security levels string patterns values getstring securitylevels public void set threat level network threat level new threat level if new threat level null throw new null pointer exception network threat level old level synchronized this old level network threat level network threat level new threat level network threat level callback on set old level new threat level setthreatlevel network_threat_level newthreatlevel newthreatlevel nullpointerexception network_threat_level oldlevel oldlevel networkthreatlevel networkthreatlevel newthreatlevel networkthreatlevelcallback onset oldlevel newthreatlevel public void set threat level friends threat level new threat level if new threat level null throw new null pointer exception friends threat level old level synchronized this old level friends threat level friends threat level new threat level friends threat level callback on set old level new threat level setthreatlevel friends_threat_level newthreatlevel newthreatlevel nullpointerexception friends_threat_level oldlevel oldlevel friendsthreatlevel friendsthreatlevel newthreatlevel friendsthreatlevelcallback onset oldlevel newthreatlevel public void set threat level physical threat level new threat level if new threat level null throw new null pointer exception physical threat level old level synchronized this old level physical threat level physical threat level new threat level physical threat level callback on set old level new threat level setthreatlevel physical_threat_level newthreatlevel newthreatlevel nullpointerexception physical_threat_level oldlevel oldlevel physicalthreatlevel physicalthreatlevel newthreatlevel physicalthreatlevelcallback onset oldlevel newthreatlevel public static string localised name network threat level new threat level return l10n get string security levels network threat level name new threat level name localisedname network_threat_level newthreatlevel getstring securitylevels networkthreatlevel newthreatlevel public static string localised name friends threat level new friends level return l10n get string security levels friends threat level name new friends level name localisedname friends_threat_level newfriendslevel getstring securitylevels friendsthreatlevel newfriendslevel public static string localised name physical threat level new physical level return l10n get string security levels physical threat level name new physical level name localisedname physical_threat_level newphysicallevel getstring securitylevels physicalthreatlevel newphysicallevel public void register user alert user alert manager alerts alerts register new user alert public string anchor return seclevels public string dismiss button text return l10n get string user alert hide public html node gethtml text html node div new html node div html node ul div add child ul ul add child li l10n user alert network threat level level localised name network threat level ul add child li l10n user alert friends threat level level localised name friends threat level ul add child li l10n user alert physical threat level level localised name physical threat level div add child br l10n addl10n substitution div security levels user alert extro new string link link new string a href config mode config toadlet mode security levels a return div public short get priority class return user alert warning public string get short text return l10n user alert short text new string network friends physical new string localised name network threat level localised name friends threat level localised name physical threat level public string get text return gethtml text get content public string get title return l10n title public object get user identifier return null public boolean is event notification return false public boolean is valid return true public void is valid boolean validity ignore public void on dismiss ignore public boolean should unregister on dismiss return true public boolean user can dismiss return true registeruseralert useralertmanager useralert dismissbuttontext getstring useralert htmlnode gethtmltext htmlnode htmlnode htmlnode addchild addchild useralertnetworkthreatlevel localisedname networkthreatlevel addchild useralertfriendsthreatlevel localisedname friendsthreatlevel addchild useralertphysicalthreatlevel localisedname physicalthreatlevel addchild addl10nsubstitution securitylevels useralertextro configtoadlet mode_security_levels getpriorityclass useralert getshorttext useralertshorttext localisedname networkthreatlevel localisedname friendsthreatlevel localisedname physicalthreatlevel gettext gethtmltext getcontent gettitle getuseridentifier iseventnotification isvalid isvalid ondismiss shouldunregisterondismiss usercandismiss alerts register new user alert public string anchor return seclevels useralert public string dismiss button text return l10n get string user alert hide dismissbuttontext getstring useralert public html node gethtml text html node div new html node div html node ul div add child ul ul add child li l10n user alert network threat level level localised name network threat level ul add child li l10n user alert friends threat level level localised name friends threat level ul add child li l10n user alert physical threat level level localised name physical threat level div add child br l10n addl10n substitution div security levels user alert extro new string link link new string a href config mode config toadlet mode security levels a return div htmlnode gethtmltext htmlnode htmlnode htmlnode addchild addchild useralertnetworkthreatlevel localisedname networkthreatlevel addchild useralertfriendsthreatlevel localisedname friendsthreatlevel addchild useralertphysicalthreatlevel localisedname physicalthreatlevel addchild addl10nsubstitution securitylevels useralertextro configtoadlet mode_security_levels public short get priority class return user alert warning getpriorityclass useralert public string get short text return l10n user alert short text new string network friends physical new string localised name network threat level localised name friends threat level localised name physical threat level getshorttext useralertshorttext localisedname networkthreatlevel localisedname friendsthreatlevel localisedname physicalthreatlevel public string get text return gethtml text get content gettext gethtmltext getcontent public string get title return l10n title gettitle public object get user identifier return null getuseridentifier public boolean is event notification return false iseventnotification public boolean is valid return true isvalid public void is valid boolean validity ignore isvalid public void on dismiss ignore ondismiss public boolean should unregister on dismiss return true shouldunregisterondismiss public boolean user can dismiss return true usercandismiss private static final long serial versionuid 1 public duplicate identity exception string message super message serialversionuid duplicateidentityexception override public own introduction puzzle generate puzzle introduction puzzle store store own identity inserter throws io exception byte array output stream out new byte array output stream 10 1024 todo find out the maximum size of the captchas and put it here try buffered image img captcha create image text imageio write img jpg out date date of insertion current timeutc get synchronized store own introduction puzzle puzzle new own introduction puzzle inserter puzzle type captcha image jpeg out to byte array text date of insertion store get free index inserter date of insertion store store and commit puzzle return puzzle return null finally closer close out ownintroductionpuzzle generatepuzzle introductionpuzzlestore ownidentity ioexception bytearrayoutputstream bytearrayoutputstream bufferedimage createimage dateofinsertion currenttimeutc ownintroductionpuzzle ownintroductionpuzzle puzzletype tobytearray dateofinsertion getfreeindex dateofinsertion storeandcommit public udp socket handler int listen port inet address bindto node node long startup time string title io statistic collector collector throws socket exception this node node this collector collector this title title bindto bindto keep the updater code in just commented out for now we may want to be able to do on line updates if updater has resource sock datagram socket updater get resource else this listen port listen port sock new datagram socket listen port bindto int sz sock get receive buffer size if sz 65536 sock set receive buffer size 65536 try exit reasonably quickly sock set reuse address true catch socket exception e throw new runtime exception e only used for debugging no need to seed from yarrow drop random node fast weak random logminor logger should log logger minor this logdebug logger should log logger debug this tracker address tracker create node last bootid node get node dir listen port tracker start send startup time udpsockethandler listenport inetaddress startuptime iostatisticcollector socketexception _bindto hasresource _sock datagramsocket getresource listenport listenport _sock datagramsocket listenport _sock getreceivebuffersize _sock setreceivebuffersize _sock setreuseaddress socketexception runtimeexception droprandom fastweakrandom shouldlog shouldlog addresstracker lastbootid getnodedir listenport startsend startuptime must be called or we will npe in run public void set low level filter incoming packet filter f low level filter f setlowlevelfilter incomingpacketfilter lowlevelfilter public inet address get bind to return bindto inetaddress getbindto _bindto public string get title return title gettitle public void run listen for packets synchronized this thread thread current thread tracker start receive system current time millis try run loop catch throwable t impossible it keeps on exiting we get the below but not this try system err print t get class get name system err println catch throwable tt try system err print t get message system err println catch throwable tt try system gc system run finalization system gc system run finalization catch throwable tt try runtime r runtime get runtime system err print r free memory system err println system err print r total memory system err println catch throwable tt try t print stack trace catch throwable tt finally system err println run exiting for udp socket handler on port sock get local port logger error this run exiting for udp socket handler on port sock get local port synchronized this isdone true thread null notify all _thread currentthread startreceive currenttimemillis runloop getclass getname getmessage runfinalization runfinalization getruntime freememory totalmemory printstacktrace udpsockethandler _sock getlocalport udpsockethandler _sock getlocalport _isdone _thread notifyall private void run loop byte buf new byte max receive size datagram packet packet new datagram packet buf buf length while active true synchronized this if active return finished try real run packet catch out of memory error e oom handler handleoom e system err println will retry above failed operation catch throwable t system err println caught t t print stack trace system err logger error this caught t t runloop max_receive_size datagrampacket datagrampacket _active _active realrun outofmemoryerror oomhandler printstacktrace private void real run datagram packet packet single receiving thread boolean got packet get packet packet long now system current time millis if got packet long start time system current time millis peer peer new peer packet get address packet get port tracker received packet from peer long end time system current time millis if end time start time 50 if end time start time 3000 logger error this packet creation took end time start time ms else if logminor logger minor this packet creation took end time start time ms byte data packet get data int offset packet get offset int length packet get length try if logminor logger minor this processing packet of length length from peer start time system current time millis low level filter process data offset length peer now end time system current time millis if end time start time 50 if end time start time 3000 logger error this processing packet took end time start time ms else if logminor logger minor this processing packet took end time start time ms if logminor logger minor this successfully handled packet length length catch throwable t logger error this caught t from low level filter t else if logdebug logger debug this no packet received realrun datagrampacket gotpacket getpacket currenttimemillis gotpacket starttime currenttimemillis getaddress getport receivedpacketfrom endtime currenttimemillis endtime starttime endtime starttime endtime starttime endtime starttime getdata getoffset getlength starttime currenttimemillis lowlevelfilter endtime currenttimemillis endtime starttime endtime starttime endtime starttime endtime starttime lowlevelfilter private boolean get packet datagram packet packet try sock receive packet collector add info packet get address packet get port packet get length 0 fixme use packet get length udp headers length catch socket timeout exception e1 return false catch io exception e2 if active closed just return silently return false else throw new runtime exception e2 if logminor logger minor this received packet return true getpacket datagrampacket _sock addinfo getaddress getport getlength getlength udp_headers_length sockettimeoutexception ioexception _active runtimeexception send a block of encoded bytes to a peer this is called by send and by incoming packet filter process outgoing param block to send the data block to send param destination the peer to send it to public void send packet byte block to send peer destination boolean allow local addresses throws local address exception assert block to send null if active logger error this trying to send packet but no longer active it is essential that for recording accurate address tracker data that we don t send any more packets after shutdown return there should be no dns needed here but go ahead if we can but complain doing it if destination get address false allow local addresses null logger error this tried sending to destination without pre looked up ip address needs a real peer get hostname null destination get port new exception error if destination get address true allow local addresses null logger error this tried sending to bad destination address null destination get port new exception error return if dropprobability 0 if drop random next int dropprobability 0 if logminor logger minor this dropped sock get local port destination get port return inet address address destination get address false allow local addresses assert address null int port destination get port datagram packet packet new datagram packet block to send block to send length packet set address address packet set port port try sock send packet tracker sent packet to destination collector add info address port 0 block to send length udp headers length if logminor logger minor this sent packet length block to send length to address port catch io exception e if packet get address instanceof inet6 address logger normal this error while sending packet to i pv6 address destination e e else logger error this error while sending packet to destination e e incomingpacketfilter processoutgoing blocktosend sendpacket blocktosend allowlocaladdresses localaddressexception blocktosend _active addresstracker getaddress allowlocaladdresses gethostname getport getaddress allowlocaladdresses getport _dropprobability droprandom nextint _dropprobability _sock getlocalport getport inetaddress getaddress allowlocaladdresses getport datagrampacket datagrampacket blocktosend blocktosend setaddress setport _sock sentpacketto addinfo blocktosend udp_headers_length blocktosend ioexception getaddress inet6address ipv6 return the maximum packet size supported by this socket manager not including transport udp ip headers public int get max packet size fixme what about passing a peer node though and doing it on a per peer basis how pmtu would require jni although it might be worth it final int min advertisedmtu node ip detector get minimum detectedmtu we don t want the mtu detection thingy to prevent us to send packet transmits if disablemtu detection min advertisedmtu min mtu if disablemtu detection logger error this it shouldn t happen we disabled the mtu detection algorithm because the advertised mtu is smallish node ip detector get minimum detectedmtu disablemtu detection true return max allowed mtu udp headers length else return math min max allowed mtu min advertisedmtu udp headers length udp ip header is 28 bytes socketmanager getmaxpacketsize peernode minadvertisedmtu ipdetector getminimumdetectedmtu packettransmits disablemtudetection minadvertisedmtu min_mtu disablemtudetection ipdetector getminimumdetectedmtu disablemtudetection max_allowed_mtu udp_headers_length max_allowed_mtu minadvertisedmtu udp_headers_length public int get packet send threshold return get max packet size 100 getpacketsendthreshold getmaxpacketsize public void start synchronized this if active return started true start time system current time millis node executor execute this udp socket handler for port listen port _active _started starttime currenttimemillis udpsockethandler listenport public void close logger normal this closing new exception error synchronized this active false sock close if started return while isdone try wait 2000 catch interrupted exception e e print stack trace tracker store data node bootid node get node dir listen port _active _sock _started _isdone interruptedexception printstacktrace storedata getnodedir listenport public int get drop probability return dropprobability getdropprobability _dropprobability public void set drop probability int drop probability dropprobability drop probability setdropprobability dropprobability _dropprobability dropprobability public int get port number return sock get local port getportnumber _sock getlocalport override public string to string return sock get local address sock get local port tostring _sock getlocaladdress _sock getlocalport public int get headers length return udp headers length getheaderslength udp_headers_length public address tracker get address tracker return tracker addresstracker getaddresstracker public void rescan port forward tracker rescan rescanportforward public int get detected connectivity status return tracker get port forward status getdetectedconnectivitystatus getportforwardstatus public int get priority return native thread max priority getpriority nativethread max_priority public long get start time return start time getstarttime starttime private final boolean delete on free public temp file bucket long id filename generator generator this id generator true true deleteonfree tempfilebucket filenamegenerator constructor for the temp file bucket object subclasses can call this constructor param delete on exit set if you want the bucket deleted on shutdown passed to the parent base file bucket you must also override delete on exit and implement your own create shadow param delete on free true for a normal temp bucket false for a shadow protected temp file bucket long id filename generator generator boolean delete on exit boolean delete on free super generator get filename id delete on exit this filenameid id this generator generator this delete on free delete on free synchronized this log debug logger should log logger debug this system err println f proxy servlet temp file bucket created f get absolute path synchronized this if log debug logger debug this initializing temp file bucket get file delete on exit delete on exit tempfilebucket deleteonexit basefilebucket deleteonexit createshadow deleteonfree tempfilebucket filenamegenerator deleteonexit deleteonfree getfilename deleteonexit deleteonfree deleteonfree logdebug shouldlog fproxyservlet tempfilebucket getabsolutepath logdebug tempfilebucket getfile deleteonexit deleteonexit override protected boolean delete on finalize make sure finalize wacks temp file if it is not explictly freed return delete on free not if shadow deleteonfinalize deleteonfree override public simple field set to field set if delete on finalize return null not persistent for subclasses i e persistent temp file bucket return super to field set simplefieldset tofieldset deleteonfinalize persistenttempfilebucket tofieldset override protected boolean create file only return false createfileonly override protected boolean delete on free return delete on free deleteonfree deleteonfree override public file get file return generator get filename filenameid getfile getfilename public boolean is read only return read only isreadonly readonly public void set read only read only true setreadonly readonly override protected boolean delete on exit return true deleteonexit public void store to object container container container store generator container store this storeto objectcontainer public void remove from object container container if logger should log logger minor this logger minor this removing from database this filename generator is a global we don t need to worry about it container delete this removefrom objectcontainer shouldlog filenamegenerator public bucket create shadow throws io exception temp file bucket ret new temp file bucket filenameid generator true false ret set read only if get file exists logger error this file does not exist when creating shadow get file return ret createshadow ioexception tempfilebucket tempfilebucket setreadonly getfile getfile public ssdp packet byte buf int length dgm packet new datagram packet buf length ssdppacket dgmpacket datagrampacket private datagram packet dgm packet null public datagram packet get datagram packet return dgm packet datagrampacket dgmpacket datagrampacket getdatagrampacket dgmpacket private string local addr public void set local address string addr local addr addr localaddr setlocaladdress localaddr public string get local address return local addr getlocaladdress localaddr private long time stamp public void set time stamp long value time stamp value timestamp settimestamp timestamp public long get time stamp return time stamp gettimestamp timestamp public inet address get remote inet address return get datagram packet get address inetaddress getremoteinetaddress getdatagrampacket getaddress public string get remote address thanks for theo beisch 11 09 04 return get datagram packet get address get host address getremoteaddress getdatagrampacket getaddress gethostaddress public int get remote port return get datagram packet get port getremoteport getdatagrampacket getport public byte get data if packet bytes null return packet bytes datagram packet packet get datagram packet int packet len packet get length string packet data new string packet get data 0 packet len packet bytes packet data get bytes return packet bytes getdata packetbytes packetbytes datagrampacket getdatagrampacket packetlen getlength packetdata getdata packetlen packetbytes packetdata getbytes packetbytes public string get host return http header get value get data http host gethost httpheader getvalue getdata public string get cache control return http header get value get data http cache control getcachecontrol httpheader getvalue getdata cache_control public string get location return http header get value get data http location getlocation httpheader getvalue getdata public string getman return http header get value get data http man httpheader getvalue getdata public string getst return http header get value get data http st httpheader getvalue getdata public string getnt return http header get value get data http nt httpheader getvalue getdata public string getnts return http header get value get data http nts httpheader getvalue getdata public string get server return http header get value get data http server getserver httpheader getvalue getdata public string getusn return http header get value get data http usn httpheader getvalue getdata public int getmx return http header get integer value get data http mx httpheader getintegervalue getdata public inet address get host inet address string addr str 127 0 0 1 string host get host int canma idx host last index of if 0 canma idx addr str host substring 0 canma idx if addr str char at 0 addr str addr str substring 1 addr str length if addr str char at addr str length 1 addr str addr str substring 0 addr str length 1 inet socket address isockaddr new inet socket address addr str 0 return isockaddr get address inetaddress gethostinetaddress addrstr gethost canmaidx lastindexof canmaidx addrstr canmaidx addrstr charat addrstr addrstr addrstr addrstr charat addrstr addrstr addrstr addrstr inetsocketaddress inetsocketaddress addrstr getaddress public boolean is root device if nt is root device getnt true return true thanks for theo beisch 11 01 04 if st is root device getst true return true return usn is root device getusn isrootdevice isrootdevice isrootdevice isrootdevice public boolean is discover return man is discover getman isdiscover isdiscover public boolean is alive return nts is alive getnts isalive isalive public boolean is bye bye return nts is bye bye getnts isbyebye isbyebye public int get lease time return ssdp get lease time get cache control getleasetime getleasetime getcachecontrol public string to string return new string get data tostring getdata get a list of fields which the database should create an index on public static string get indexed fields fixme find out whether indexes are sorted if not remove the date and valid until time return new string mid m inserter m date of insertion m valid until time m was solved m was inserted getindexedfields validuntiltime minserter mdateofinsertion mvaliduntiltime mwassolved mwasinserted for construction from a received puzzle param new type param new data suppress warnings deprecation public introduction puzzle identity new inserter string newid puzzle type new type string new mime type byte new data long my valid until time date my date of insertion int my index assert new inserter null newid null new type null new mime type null new mime type equals new data null new data length 0 my valid until time current timeutc get in millis my date of insertion null my date of insertion get time current timeutc get in millis my index 0 mid newid m inserter new inserter m type new type m mime type new mime type m date of insertion new date my date of insertion get year my date of insertion get month my date of insertion get date m valid until time my valid until time m index my index m data new data m was solved false m solution null m solver null m was inserted false if check consistency false throw new illegal argument exception corrupted puzzle received newtype newdata suppresswarnings introductionpuzzle newinserter puzzletype newtype newmimetype newdata myvaliduntiltime mydateofinsertion myindex newinserter newtype newmimetype newmimetype newdata newdata myvaliduntiltime currenttimeutc getinmillis mydateofinsertion mydateofinsertion gettime currenttimeutc getinmillis myindex minserter newinserter mtype newtype mmimetype newmimetype mdateofinsertion mydateofinsertion getyear mydateofinsertion getmonth mydateofinsertion getdate mvaliduntiltime myvaliduntiltime mindex myindex mdata newdata mwassolved msolution msolver mwasinserted checkconsistency illegalargumentexception used by the introduction client for guessing the request ur is of puzzles to be able to download them public static freeneturi generate requesturi identity inserter date date of insertion int index assert date of insertion before current timeutc get assert index 0 fixme i did not really understand the javadoc of freeneturi please verify that the following code actually creates an uri which looks like the one i specified in the javadoc above this function thanks string day of insertion synchronized m date format day of insertion m date format format date of insertion freeneturi baseuri inserter get requesturi set key type ssk baseuri baseuri set doc name wot wot name introduction context day of insertion index return baseuri set meta string null introductionclient uris generaterequesturi dateofinsertion dateofinsertion currenttimeutc dayofinsertion mdateformat dayofinsertion mdateformat dateofinsertion getrequesturi setkeytype setdocname wot_name introduction_context dayofinsertion setmetastring get the uri where this puzzle was downloaded from public freeneturi get requesturi return generate requesturi m inserter m date of insertion m index getrequesturi generaterequesturi minserter mdateofinsertion mindex get the date of a puzzle from it s uri used for being able to query the database for an existing introduction puzzle object when a new one was downloaded public static date get date from requesturi freeneturi requesturi throws parse exception string tokens requesturi get doc name split synchronized m date format return m date format parse tokens 2 introductionpuzzleobject getdatefromrequesturi parseexception getdocname mdateformat mdateformat get the index of a puzzle from it s uri used for being able to query the database for an existing introduction puzzle object when a new one was downloaded public static int get index from requesturi freeneturi requesturi string tokens requesturi get doc name split return integer parse int tokens 3 introductionpuzzleobject getindexfromrequesturi getdocname parseint get the id of a puzzle from the uri of it s solution used for querying the database for the associated puzzle after a solution was fetched or inserted successfully public static string getid from solutionuri freeneturi uri return uri get doc name split 2 getidfromsolutionuri getdocname public string getid return mid public puzzle type get type return m type puzzletype gettype mtype public string get mime type return m mime type getmimetype mmimetype public byte get data return m data getdata mdata public identity get inserter return m inserter getinserter minserter public date get date of insertion return m date of insertion getdateofinsertion mdateofinsertion public long get valid until time return m valid until time getvaliduntiltime mvaliduntiltime public int get index return m index getindex mindex however if one only knows this class and not how it is used by the rest its logical to synchronize it used by the introduction client to mark a puzzle as solved param solver the identity which solved the puzzle correctly param solution the solution which was passed by the solver throws invalid parameter exception if the puzzle was already solved public synchronized void set solved own identity solver string solution throws invalid parameter exception if m was solved throw new invalid parameter exception puzzle is already solved todo create a special exception for that m was solved true m solver solver m solution solution introductionclient invalidparameterexception setsolved ownidentity invalidparameterexception mwassolved invalidparameterexception mwassolved msolver msolution public synchronized boolean was solved return m was solved wassolved mwassolved however if one only knows this class and not how it is used by the rest its logical to synchronize it get the own identity which solved this puzzle used by the introduction client for inserting identity introductions public synchronized own identity get solver assert m was solved return m solver ownidentity introductionclient ownidentity getsolver mwassolved msolver get the uri at which to insert the solution of this puzzle if you have solved it at which the solution is trying to be fetched format ksk wot introduction id guess of solution id the id of the puzzle which itself contains the uuid of the puzzle and the id of the inserter guess of solution the guess of the solution which is passed to the function public synchronized freeneturi get solutionuri if m solution null throw new runtime exception the puzzle is not solved return new freeneturi ksk wot wot name introduction context mid m solution guessofsolution guessofsolution getsolutionuri msolution runtimeexception wot_name introduction_context msolution public synchronized boolean was inserted return m was inserted wasinserted mwasinserted public synchronized void set inserted if m was inserted throw new runtime exception the puzzle was already inserted m was inserted true setinserted mwasinserted runtimeexception mwasinserted fixme check for validity of the jpeg suppress warnings deprecation public boolean check consistency boolean result true if mid null logger error this mid null result false else verify the uid if m inserter null string inserterid m inserter getid if mid ends with inserterid false logger error this mid does not start with inserterid mid result false verification that the rest of the id is an uuid is not necessary if a client inserts a puzzle with the id just being his identity id or other bogus stuff he will just shoot himself in the foot by possibly only allowing 1 puzzle of him to be available because the databases of the downloaders check whether the id already exists if m type null logger error this m type null result false if m mime type null m mime type equals image jpeg logger error this m mime type m mime type result false if new date m valid until time before new date 2008 1900 10 10 logger error this m valid until time new date m valid until time result false if m data null m data length 100 logger error this m data m data result false if m inserter null logger error this m inserter null result false if m date of insertion null m date of insertion before new date 2008 1900 10 10 m date of insertion after current timeutc get logger error this m date of insertion m date of insertion current time current timeutc get result false if m index 0 logger error this m index m index result false return result suppresswarnings checkconsistency minserter minserter endswith mtype mtype mmimetype mmimetype mmimetype mmimetype mvaliduntiltime mvaliduntiltime mvaliduntiltime mdata mdata mdata mdata minserter minserter mdateofinsertion mdateofinsertion mdateofinsertion currenttimeutc mdateofinsertion mdateofinsertion currenttime currenttimeutc mindex mindex mindex private float scale 4 public diffuse filter set edge action clamp diffusefilter setedgeaction specifies the scale of the texture param scale the scale of the texture min value 1 max value 100 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale override protected void transform inverse int x int y float out int angle int math random 255 float distance float math random out 0 x distance sin table angle out 1 y distance cos table angle transforminverse sintable costable override public buffered image filter buffered image src buffered image dst sin table new float 256 cos table new float 256 for int i 0 i 256 i float angle image math two pi i 256f sin table i float scale math sin angle cos table i float scale math cos angle return super filter src dst bufferedimage bufferedimage bufferedimage sintable costable imagemath two_pi sintable costable override public string to string return distort diffuse tostring public persistent blob temp bucket factory long block size2 long nodedb handle2 file storage file2 block size block size2 nodedb handle nodedb handle2 storage file storage file2 persistentblobtempbucketfactory blocksize2 nodedbhandle2 storagefile2 blocksize blocksize2 nodedbhandle nodedbhandle2 storagefile storagefile2 void on init object container container db job runner job runner2 random fast weak random file storage file2 long block size2 ticker ticker throws io exception container activate storage file 100 file old file file util get canonical file new file storage file get path db4o argh file new file file util get canonical file new file storage file2 get path if block size block size2 throw new illegal state exception my block size is block size2 but stored block size is block size for same file storage file if old file equals new file file separator char old file get path to lower case equals new file get path to lower case old file get path equals new file get path if file util move to storage file storage file2 false throw new io exception unable to move temp blob file from storage file to storage file2 raf new random access file storage file rw channel raf get channel not committed blobs new tree map long persistent blob temp bucket free slots new tree map long persistent blob temp bucket tag almost free slots new tree map long persistent blob temp bucket tag shadows new tree map long persistent blob temp bucket job runner job runner2 weak random source fast weak random free jobs new hash set db job this ticker ticker maybe shrink container diagnostics long size try size channel size catch io exception e1 logger error this unable to find size of temp blob storage file e1 e1 return size size block size long blocks size block size long ptr blocks 1 long used 0 long range start long min value persistent blob temp bucket tag first in range null for long l 0 l ptr l synchronized this if free slots contains key l continue if not committed blobs contains key l continue if almost free slots contains key l continue query query container query query constrain persistent blob temp bucket tag class query descend index constrain l object set persistent blob temp bucket tag tags query execute if tags has next persistent blob temp bucket tag tag tags next if tag is free used if tag bucket null tag is free logger error this no bucket but flagged as not free index l tag bucket if tag bucket null tag is free logger error this has bucket but flagged as free index l tag bucket if tag is free if range start long min value range start l first in range tag else if range start long min value system out println range range start to l 1 first is first in range range start long min value first in range null continue logger error this found empty slot l when scanning the blob file because tags in database length of file persistent blob temp bucket tag tag new persistent blob temp bucket tag persistent blob temp bucket factory this l container store tag synchronized this free slots put ptr tag if range start long min value system out println range range start to ptr 1 system err println persistent blobs blocks blocks used used oninit objectcontainer dbjobrunner jobrunner2 fastweakrandom storagefile2 blocksize2 ioexception storagefile oldfile fileutil getcanonicalfile storagefile getpath newfile fileutil getcanonicalfile storagefile2 getpath blocksize blocksize2 illegalstateexception blocksize2 blocksize storagefile oldfile newfile separatorchar oldfile getpath tolowercase newfile getpath tolowercase oldfile getpath newfile getpath fileutil moveto storagefile storagefile2 ioexception storagefile storagefile2 randomaccessfile storagefile getchannel notcommittedblobs treemap persistentblobtempbucket freeslots treemap persistentblobtempbuckettag almostfreeslots treemap persistentblobtempbuckettag treemap persistentblobtempbucket jobrunner jobrunner2 weakrandomsource fastweakrandom freejobs hashset dbjob maybeshrink ioexception blocksize blocksize rangestart min_value persistentblobtempbuckettag firstinrange freeslots containskey notcommittedblobs containskey almostfreeslots containskey persistentblobtempbuckettag objectset persistentblobtempbuckettag hasnext persistentblobtempbuckettag isfree isfree isfree isfree rangestart min_value rangestart firstinrange rangestart min_value rangestart firstinrange rangestart min_value firstinrange persistentblobtempbuckettag persistentblobtempbuckettag persistentblobtempbucketfactory freeslots rangestart min_value rangestart public string get name return storage file get path getname storagefile getpath public void run object container container client context context int added 0 while true boolean logminor logger should log logger minor this synchronized persistent blob temp bucket factory this if free slots size max free return long size try size channel size catch io exception e1 logger error this unable to find size of temp blob storage file e1 e1 return size size block size long blocks size block size long ptr blocks 1 for long l 0 l block size 16383 l 16384 query query container query query constrain persistent blob temp bucket tag class query descend is free constrain true and query descend index constrain l smaller object set persistent blob temp bucket tag tags query execute long not committed synchronized persistent blob temp bucket factory this while tags has next persistent blob temp bucket tag tag tags next if tag is free logger error this tag not free tag index if tag bucket null logger error this tag flagged non free yet has no bucket for index tag index tag is free true else continue if tag bucket null logger error this query returned tag with valid bucket continue if tag factory persistent blob temp bucket factory this continue if not committed blobs contains key tag index continue if almost free slots contains key tag index continue if free slots contains key tag index continue if tag bucket null logger error this bucket is occupied but not in not committed blobs tag tag bucket continue if logminor logger minor this adding slot tag index to free slots has a free tag and no taken tag free slots put tag index tag added if added max free return fixme the issue below has been marked as fixed in the db4o bugtracker can this be resolved now checking for slots marked occupied with bucket null is nontrivial because constraining to null doesn t work causes an oom with a large database because it does not use the index and therefore instantiates every object and oo ms see http tracker db4o com browse cor 1446 check that the number of tags is equal to the size of the file if logminor logger minor this checking number of tags against file size query query container query query constrain persistent blob temp bucket tag class object set persistent blob temp bucket tag tags query execute long indb tags size if logminor logger minor this checked size tags null if indb ptr logger error this tags in database indb but size of file allows ptr recover exhaustive index search this can cause very long pauses but should only happen if there is a bug for long l 0 l ptr l synchronized this if free slots contains key l continue if not committed blobs contains key l continue if almost free slots contains key l continue query container query query constrain persistent blob temp bucket tag class query descend index constrain l tags query execute if tags has next continue logger error this found empty slot l when scanning the blob file because tags in database length of file persistent blob temp bucket tag tag new persistent blob temp bucket tag persistent blob temp bucket factory this l container store tag synchronized this free slots put ptr tag added if added max free return db job free job null synchronized this if free jobs is empty free job free jobs iterator next free jobs remove free job if free job null container activate free job 1 system err println freeing some space by running free job logger minor this freeing some space by running free job free job run container context continue lets extend the file fixme if physical security is low just set the length possibly padding will nonrandom nulls on unix long add blocks math min 8192 blocks 10 32 long extend by add blocks block size long written 0 byte buf new byte 4096 byte buffer buffer byte buffer wrap buf while written extend by weak random source next bytes buf int bytes left int math min extend by written integer max value if bytes left buf length buffer limit bytes left try written channel write buffer size written buffer clear catch io exception e break query container query query constrain persistent blob temp bucket tag class query descend index constrain blocks 1 greater and query descend factory constrain persistent blob temp bucket factory this hash set long taken null object set persistent blob temp bucket tag results query execute while results has next persistent blob temp bucket tag tag results next if tag is free logger error this block already exists beyond the end of the file yet is occupied block tag index if taken null taken new hash set long taken add tag index for int i 0 i add blocks i ptr blocks i if taken null taken contains ptr continue persistent blob temp bucket tag tag new persistent blob temp bucket tag persistent blob temp bucket factory this ptr container store tag synchronized persistent blob temp bucket factory this if logminor logger minor this adding slot ptr to free slots while extending storage file free slots put ptr tag return objectcontainer clientcontext shouldlog persistentblobtempbucketfactory freeslots max_free ioexception blocksize blocksize blocksize persistentblobtempbuckettag isfree objectset persistentblobtempbuckettag notcommitted persistentblobtempbucketfactory hasnext persistentblobtempbuckettag isfree isfree persistentblobtempbucketfactory notcommittedblobs containskey almostfreeslots containskey freeslots containskey notcommittedblobs freeslots freeslots max_free ooms persistentblobtempbuckettag objectset persistentblobtempbuckettag freeslots containskey notcommittedblobs containskey almostfreeslots containskey persistentblobtempbuckettag hasnext persistentblobtempbuckettag persistentblobtempbuckettag persistentblobtempbucketfactory freeslots max_free dbjob freejob freejobs isempty freejob freejobs freejobs freejob freejob freejob freejob freejob freejob addblocks extendby addblocks blocksize bytebuffer bytebuffer extendby weakrandomsource nextbytes bytesleft extendby max_value bytesleft bytesleft ioexception persistentblobtempbuckettag persistentblobtempbucketfactory hashset objectset persistentblobtempbuckettag hasnext persistentblobtempbuckettag isfree hashset addblocks persistentblobtempbuckettag persistentblobtempbuckettag persistentblobtempbucketfactory persistentblobtempbucketfactory freeslots freeslots return a bucket or null in various failure cases public persistent blob temp bucket make bucket find a free slot synchronized this if free slots is empty long slot free slots first key persistent blob temp bucket tag tag free slots remove slot if not committed blobs get slot null almost free slots get slot null logger error this slot slot already occupied by a not committed blob despite being in free slots return null persistent blob temp bucket bucket new persistent blob temp bucket this block size slot tag false not committed blobs put slot bucket if logger should log logger minor this logger minor this using slot slot for bucket return bucket job runner run blocking slot finder native thread high priority synchronized this if free slots is empty long slot free slots first key persistent blob temp bucket tag tag free slots remove slot if not committed blobs get slot null almost free slots get slot null logger error this slot slot already occupied by a not committed blob despite being in free slots return null persistent blob temp bucket bucket new persistent blob temp bucket this block size slot tag false not committed blobs put slot bucket if logger should log logger minor this logger minor this using slot slot for bucket after waiting return bucket logger error this returning null unable to create a bucket for some reason node will fallback to file based buckets return null persistentblobtempbucket makebucket freeslots isempty freeslots firstkey persistentblobtempbuckettag freeslots notcommittedblobs almostfreeslots freeslots persistentblobtempbucket persistentblobtempbucket blocksize notcommittedblobs shouldlog jobrunner runblocking slotfinder nativethread high_priority freeslots isempty freeslots firstkey persistentblobtempbuckettag freeslots notcommittedblobs almostfreeslots freeslots persistentblobtempbucket persistentblobtempbucket blocksize notcommittedblobs shouldlog public synchronized void free bucket long index persistent blob temp bucket bucket if logger should log logger minor this logger minor this freeing index index for bucket new exception debug not committed blobs remove index bucket on free if bucket persisted if it hasn t been written to the database it doesn t need to be removed so remove from won t be called free slots put index bucket tag persistent blob temp bucket shadow shadows get index if shadow null shadow freed freebucket persistentblobtempbucket shouldlog notcommittedblobs onfree removefrom freeslots persistentblobtempbucket public synchronized void remove persistent blob temp bucket bucket object container container if logger should log logger minor this logger minor this removing bucket bucket for slot bucket index from database new exception debug long index bucket index persistent blob temp bucket tag tag bucket tag if tag null if container ext is active bucket logger error this bucket not active in remove bucket new exception error container activate bucket 1 tag bucket tag index bucket index else this is impossible yet saces has seen it in practice lets get some detail logger error this no tag on bucket removing bucket index index new exception error query query container query query constrain persistent blob temp bucket tag class query descend index constrain index object set persistent blob temp bucket tag results query execute if results has next logger error this tag does not exist for index index else tag results next if tag index index crazy things are happening may as well check the impossible logger error this invalid index should be index but is tag index if tag is free logger error this found tag but is free tag if tag bucket null logger error this found tag but no bucket tag else if tag bucket bucket logger error this tag links to bucket but bucket doesn t link to tag else tag bucket bucket logger error this serious error tag belongs to a different bucket container activate tag 1 if bucket persisted maybe shrink container return if bucket freed logger error this removing bucket bucket for slot bucket index but not freed new exception debug not committed blobs put index bucket else almost free slots put index tag tag bucket null tag is free true container store tag container delete bucket bucket on remove maybe shrink container persistentblobtempbucket objectcontainer shouldlog persistentblobtempbuckettag isactive persistentblobtempbuckettag objectset persistentblobtempbuckettag hasnext isfree maybeshrink notcommittedblobs almostfreeslots isfree onremove maybeshrink void maybe shrink object container container boolean logminor logger should log logger minor this if logminor logger minor this maybe shrink long now system current time millis long new blocks synchronized this if now last checked end 60 1000 if logminor logger minor this maybe shrink inner check whether there is a big white space at the end of the file long size try size channel size catch io exception e1 logger error this unable to find size of temp blob storage file e1 e1 return size size block size long blocks size block size if blocks 32 if logminor logger minor this not shrinking blob file not larger than a megabyte last checked end now queue maybe shrink return long last not committed not committed blobs is empty 0 not committed blobs last key long last almost freed almost free slots is empty 0 almost free slots last key if last not committed last almost freed if logminor logger minor this last almost freed last almost freed replacing last not committed last not committed last not committed last almost freed double full double last not committed double blocks if full 0 8 if logminor logger minor this not shrinking last not committed block is at full 100 last not committed of blocks last checked end now queue maybe shrink return query for the non free tag with the highest value this query can return a vast number of objects and it s all kept in ram in immediate mode fixme lazy query mode may help but would likely require changes to other code in the meantime lets try from the end going backwards by a manageable number of slots at a time long last committed 1 for long threshold blocks 4096 threshold 4095 threshold 4096 query query container query query constrain persistent blob temp bucket tag class query descend is free constrain false query descend index order descending query descend index constrain threshold greater object set persistent blob temp bucket tag tags query execute if tags is empty no used slots after threshold continue else last committed tags next index logger normal this last committed block is last committed break if last committed 1 no used slots at all there may be some not committed though logger normal this no used slots in persistent temp file but last not committed last not committed last committed 0 full double last committed double blocks if full 0 8 if logminor logger minor this not shrinking last committed block is at full 100 last checked end now queue maybe shrink return long last block math max last committed last not committed must be 10 free at end new blocks long last block 32 1 1 new blocks math max new blocks 32 if new blocks blocks if logminor logger minor this not shrinking would shrink from blocks to new blocks last checked end now queue maybe shrink return system err println shrinking blob file from blocks to new blocks for long l new blocks l blocks l free slots remove l for long l free slots key set if l new blocks logger error this removing free slot l over the current block limit last checked end now queue maybe shrink else return try channel truncate new blocks block size catch io exception e system err println shrinking blob file failed system err println e e print stack trace logger error this shrinking blob file failed e e query query container query query constrain persistent blob temp bucket tag class query descend index constrain new blocks greater object set persistent blob temp bucket tag tags query execute while tags has next container delete tags next maybeshrink objectcontainer shouldlog maybeshrink currenttimemillis newblocks lastcheckedend maybeshrink ioexception blocksize blocksize lastcheckedend queuemaybeshrink lastnotcommitted notcommittedblobs isempty notcommittedblobs lastkey lastalmostfreed almostfreeslots isempty almostfreeslots lastkey lastnotcommitted lastalmostfreed lastalmostfreed lastnotcommitted lastnotcommitted lastalmostfreed lastnotcommitted lastnotcommitted lastcheckedend queuemaybeshrink lastcommitted persistentblobtempbuckettag isfree orderdescending objectset persistentblobtempbuckettag isempty lastcommitted lastcommitted lastcommitted lastnotcommitted lastcommitted lastcommitted lastcheckedend queuemaybeshrink lastblock lastcommitted lastnotcommitted newblocks lastblock newblocks newblocks newblocks newblocks lastcheckedend queuemaybeshrink newblocks newblocks freeslots freeslots keyset newblocks lastcheckedend queuemaybeshrink newblocks blocksize ioexception printstacktrace persistentblobtempbuckettag newblocks objectset persistentblobtempbuckettag hasnext private void queue maybe shrink ticker queue timed job new runnable public void run job runner queue new db job public void run object container container client context context maybe shrink container native thread norm priority 1 true 61 1000 queuemaybeshrink queuetimedjob jobrunner dbjob objectcontainer clientcontext maybeshrink nativethread norm_priority public void run job runner queue new db job public void run object container container client context context maybe shrink container native thread norm priority 1 true jobrunner dbjob objectcontainer clientcontext maybeshrink nativethread norm_priority job runner queue new db job public void run object container container client context context maybe shrink container jobrunner dbjob objectcontainer clientcontext maybeshrink public void store persistent blob temp bucket bucket object container container if logger should log logger minor this logger minor this storing bucket bucket for slot bucket index to database long index bucket index persistent blob temp bucket tag tag bucket tag container activate tag 1 if tag bucket null tag bucket bucket logger error this slot index already occupied tag bucket for tag index throw new illegal state exception slot index already occupied tag bucket bucket tag is free false container store tag container store bucket synchronized this not committed blobs remove index persistentblobtempbucket objectcontainer shouldlog persistentblobtempbuckettag illegalstateexception isfree notcommittedblobs public synchronized void post commit int free now free slots size int sz free now almost free slots size if sz max free iterator map entry long persistent blob temp bucket tag it almost free slots entry set iterator for int i free now i max free it has next i map entry long persistent blob temp bucket tag entry it next free slots put entry get key entry get value else free slots put all almost free slots almost free slots clear postcommit freenow freeslots freenow almostfreeslots max_free persistentblobtempbuckettag almostfreeslots entryset freenow max_free hasnext persistentblobtempbuckettag freeslots getkey getvalue freeslots putall almostfreeslots almostfreeslots public bucket create shadow persistent blob temp bucket bucket long index bucket index long i index synchronized this if shadows contains key i return null persistent blob temp bucket shadow new persistent blob temp bucket this block size index null true shadow size bucket size shadows put i shadow return shadow createshadow persistentblobtempbucket containskey persistentblobtempbucket persistentblobtempbucket blocksize public synchronized void free shadow long index persistent blob temp bucket bucket persistent blob temp bucket temp shadows remove index if temp bucket logger error this freed wrong shadow temp should be bucket shadows put index temp freeshadow persistentblobtempbucket persistentblobtempbucket public void add blob free callback db job job synchronized this free jobs add job addblobfreecallback dbjob freejobs public void remove blob free callback db job job synchronized this free jobs remove job removeblobfreecallback dbjob freejobs public service info resolver jmdns impl jmdns impl service info impl info this jmdns impl jmdns impl this info info info set dns this jmdns impl this jmdns impl add listener info new dns question info get qualified name dns constants type any dns constants class in serviceinforesolver jmdnsimpl jmdnsimpl serviceinfoimpl jmdnsimpl jmdnsimpl setdns jmdnsimpl jmdnsimpl addlistener dnsquestion getqualifiedname dnsconstants type_any dnsconstants class_in public void start timer timer timer schedule this dns constants query wait interval dns constants query wait interval dnsconstants query_wait_interval dnsconstants query_wait_interval public void run try if this jmdns impl get state dns state announced if count 3 info has data long now system current time millis dns outgoing out new dns outgoing dns constants flags qr query out add question new dns question info get qualified name dns constants type srv dns constants class in out add question new dns question info get qualified name dns constants type txt dns constants class in if info get server null out add question new dns question info get server dns constants type a dns constants class in out add answer dns record this jmdns impl get cache get info get qualified name dns constants type srv dns constants class in now out add answer dns record this jmdns impl get cache get info get qualified name dns constants type txt dns constants class in now if info get server null out add answer dns record this jmdns impl get cache get info get server dns constants type a dns constants class in now this jmdns impl send out else after three queries we can quit this cancel this jmdns impl remove listener info else if this jmdns impl get state dns state canceled this cancel this jmdns impl remove listener info catch throwable e logger log level warning run exception e this jmdns impl recover jmdnsimpl getstate dnsstate hasdata currenttimemillis dnsoutgoing dnsoutgoing dnsconstants flags_qr_query addquestion dnsquestion getqualifiedname dnsconstants type_srv dnsconstants class_in addquestion dnsquestion getqualifiedname dnsconstants type_txt dnsconstants class_in getserver addquestion dnsquestion getserver dnsconstants type_a dnsconstants class_in addanswer dnsrecord jmdnsimpl getcache getqualifiedname dnsconstants type_srv dnsconstants class_in addanswer dnsrecord jmdnsimpl getcache getqualifiedname dnsconstants type_txt dnsconstants class_in getserver addanswer dnsrecord jmdnsimpl getcache getserver dnsconstants type_a dnsconstants class_in jmdnsimpl jmdnsimpl removelistener jmdnsimpl getstate dnsstate jmdnsimpl removelistener jmdnsimpl protected volatile boolean finished init public persistent config simple field set initial contents this orig config file contents initial contents finishedinit persistentconfig simplefieldset initialcontents origconfigfilecontents initialcontents finished initialization so any remaining options must be invalid override public synchronized void finished init finished init true if orig config file contents null return iterator string i orig config file contents key iterator while i has next string key i next logger error this unknown option key value orig config file contents get key orig config file contents null finishedinit finishedinit origconfigfilecontents origconfigfilecontents keyiterator hasnext origconfigfilecontents origconfigfilecontents public simple field set export field set return export field set false simplefieldset exportfieldset exportfieldset public simple field set export field set boolean with defaults return export field set config request type current settings with defaults simplefieldset exportfieldset withdefaults exportfieldset requesttype current_settings withdefaults public simple field set export field set config request type config request type boolean with defaults simple field set fs new simple field set true sub config configs synchronized this fixme maybe keep a cache of this configs configs by prefix values to array new sub config configs by prefix size sub config current for int i 0 i configs length i current configs i simple field set scfs current export field set config request type with defaults fs tput current prefix scfs return fs simplefieldset exportfieldset requesttype configrequesttype withdefaults simplefieldset simplefieldset subconfig configsbyprefix toarray subconfig configsbyprefix subconfig simplefieldset exportfieldset configrequesttype withdefaults override public void on register sub config config option o string val name synchronized this if finished init throw new illegal state exception on register config o called after finished init if orig config file contents null return name config prefix simple field set multi level char o name val orig config file contents get name orig config file contents remove value name if val null return try o set initial value val trim catch invalid config value exception e logger error this could not parse config option name e e onregister subconfig finishedinit illegalstateexception onregister finishedinit origconfigfilecontents simplefieldset multi_level_char origconfigfilecontents origconfigfilecontents removevalue setinitialvalue invalidconfigvalueexception return a copy of the sfs as read by the config framework return a sfs or null if initialization is finished public synchronized simple field set get simple field set return orig config file contents null null new simple field set orig config file contents simplefieldset getsimplefieldset origconfigfilecontents simplefieldset origconfigfilecontents final string keyword private clientksk string keyword byte pub key hash dsa public key pub key dsa private key priv key byte keyword hash throws malformedurl exception super keyword pub key hash pub key priv key keyword hash key algo aes pcfb 256 sha256 this keyword keyword pubkeyhash dsapublickey pubkey dsaprivatekey privkey keywordhash malformedurlexception pubkeyhash pubkey privkey keywordhash algo_aes_pcfb_256_sha256 override public freeneturi geturi return new freeneturi ksk keyword public static insertable clientssk create freeneturi uri if uri get key type equals ksk throw new illegal argument exception return create uri get doc name insertableclientssk getkeytype illegalargumentexception getdocname public static clientksk create string keyword message digest md256 sha256 get message digest try byte keyword hash try keyword hash md256 digest keyword get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e mersenne twister mt new mersenne twister keyword hash dsa private key priv key new dsa private key global ds agroup biga mt dsa public key pub key new dsa public key global ds agroup biga priv key byte pub key hash md256 digest pub key as bytes try return new clientksk keyword pub key hash pub key priv key keyword hash catch malformedurl exception e throw new error e finally sha256 return message digest md256 messagedigest getmessagedigest keywordhash keywordhash getbytes unsupportedencodingexception mersennetwister mersennetwister keywordhash dsaprivatekey privkey dsaprivatekey dsagroupbiga dsapublickey pubkey dsapublickey dsagroupbiga privkey pubkeyhash pubkey asbytes pubkeyhash pubkey privkey keywordhash malformedurlexception returnmessagedigest private int seed 0 public scratch filter scratchfilter public void set angle float angle this angle angle setangle public float get angle return angle getangle public void set angle variation float angle variation this angle variation angle variation setanglevariation anglevariation anglevariation anglevariation public float get angle variation return angle variation getanglevariation anglevariation public void set density float density this density density setdensity public float get density return density getdensity public void set length float length this length length setlength public float get length return length getlength public void set width float width this width width setwidth public float get width return width getwidth public void set color int color this color color setcolor public int get color return color getcolor public void set seed int seed this seed seed setseed public int get seed return seed getseed public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null int width src get width int height src get height int num scratches int density width height 100 array list lines new array list float l length width random random new random seed graphics2d g dst create graphics g set rendering hint rendering hints key antialiasing rendering hints value antialias on g set color new color color g set stroke new basic stroke this width for int i 0 i num scratches i float x width random next float float y height random next float float a angle image math two pi angle variation random next float 0 5f float s float math sin a l float c float math cos a l float x1 x c float y1 y s float x2 x c float y2 y s g draw line int x1 int y1 int x2 int y2 lines add new line2d float x1 y1 x2 y2 g dispose if false int in pixels getrgb src 0 0 width height null int in pixels new int width height int index 0 for int y 0 y height y for int x 0 x width x float sx x sy y for int i 0 i num scratches i line2d float l line2d float lines get i float dot l x2 l x1 sx l x1 l y2 l y1 sy l y1 if dot 0 in pixels index 1 i index colormap colormap new linear colormap index 0 for int y 0 y height y for int x 0 x width x float f float in pixels index 0x7fffffff 0x7fffffff in pixels index colormap get color f index setrgb dst 0 0 width height in pixels return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage getwidth getheight numscratches arraylist arraylist creategraphics setrenderinghint renderinghints key_antialiasing renderinghints value_antialias_on setcolor setstroke basicstroke numscratches nextfloat nextfloat imagemath two_pi anglevariation nextfloat drawline inpixels inpixels numscratches inpixels linearcolormap inpixels inpixels getcolor inpixels override public string to string return render scratches tostring public static void setup plugin respirator pr xml librarian xl search pr pr search xl xl pluginrespirator xmllibrarian searches for the string in the specified index in case of a folder searches in all included indices param out param search string to be searched param indexuri param stylesheet public static void search str string builder out string search string indexuri throws exception search search to lower case if search equals out append give a valid string to search n return try get search result string search words search split p l n return results in order list uri wrapper hs null search for each string in the search list only the common results to all words are returned as final result try index idx new index indexuri pr idx fetch hs idx search search words catch fetch exception e out append p could not fetch sub index for html encoder encode search e get message p n logger normal xl p could not fetch sub index for html encoder encode search in html encoder encode indexuri e to string p n e catch exception e out append p could not complete search for html encoder encode search e to string p n out append string value of e get stack trace logger error xl could not complete search for search in indexuri e to string e output results int results 0 out append table class librarian results tr n iterator uri wrapper it hs iterator try while it has next uri wrapper o it next string showurl o uri string showtitle o descr if showtitle trim length 0 showtitle not available if showtitle equals not available showtitle showurl string description html encoder encode o descr if description equals not available description description replace all n lt b b r r gt br description description replace all nbsp description description replace all lt a za z gt showurl html encoder encode showurl if showurl length 60 showurl showurl substring 0 15 hellip showurl replace first string realurl o uri starts with o uri realurl html encoder encode realurl out append p n table class librarian result width 100 border 1 tr td align center bgcolor d0d0d0 class librarian result url n out append a href append realurl append title append o uri append append showtitle append a n out append td tr tr td align left class librarian result summary n out append td tr table n results catch exception e out append could not display results for search e to string logger error xl could not display search results for search e to string e out append tr table n out append p span class librarian summary found text found span span class librarian summary found number append results append results span p n catch exception e logger error xl could not complete search for search in indexuri e to string e e print stack trace searchstr stringbuilder tolowercase searchwords uriwrapper searchwords fetchexception htmlencoder getmessage htmlencoder htmlencoder tostring htmlencoder tostring valueof getstacktrace tostring uriwrapper hasnext uriwrapper htmlencoder replaceall replaceall replaceall htmlencoder replacefirst startswith htmlencoder tostring tostring tostring printstacktrace searches for the string in the specified index in case of a folder searches in all included indices param out param search string to be searched param indexuri this function will be made to only return placeholder with xmlhttp request callbacks it will start a separate thread to search and all out append s will act on progress public static void search str async string builder out string search string indexuri progress progress logs append searching with progress on search br check search term is valid search search to lower case if search equals out append give a valid string to search n logs append give a valid string to search br return need to put xml http callback for loading results out append div id librarian search results n div n search searcher new search search indexuri progress searcher start xmlhttprequest searchstrasync stringbuilder tolowercase xmlhttp progress progress private search string search string indexuri progress progress this search search this indexuri indexuri this progress progress public void run try string search words search split p l n return results in order list uri wrapper hs null search for each string in the search list only the common results to all words are returned as final result try index idx new index indexuri pr progress set fetching index logs append fetching index br n idx fetch progress progress set searching in index logs append searching in index br n hs idx search search words progress progress set formatting results catch fetch exception e progress done could not fetch sub index for html encoder encode search html encoder encode e get message n logger normal xl could not fetch sub index for search in indexuri e to string n e return catch exception e progress done could not complete search for html encoder encode search html encoder encode e to string n html encoder encode string value of e get stack trace logger error xl could not complete search for search in indexuri e to string e return output results int results 0 string builder out new string builder out append table class librarian results tr n iterator uri wrapper it hs iterator try while it has next uri wrapper o it next string showurl o uri string showtitle o descr if showtitle trim length 0 showtitle not available if showtitle equals not available showtitle showurl string description html encoder encode o descr if description equals not available description description replace all n lt b b r r gt br description description replace all nbsp description description replace all lt a za z gt showurl html encoder encode showurl if showurl length 60 showurl showurl substring 0 15 hellip showurl replace first string realurl o uri starts with o uri realurl html encoder encode realurl out append p n table class librarian result width 100 border 1 tr td align center bgcolor d0d0d0 class librarian result url n out append a href append realurl append title append o uri append append showtitle append a n out append td tr tr td align left class librarian result summary n out append td tr table n results catch exception e progress done could not display results for search e to string logger error xl could not display search results for search e to string e out append tr table n out append p span class librarian summary found text found span span class librarian summary found number append results append results span p n progress done complete out to string catch exception e progress done could not complete search for search in indexuri e to string logger error xl could not complete search for search in indexuri e to string e e print stack trace searchwords uriwrapper searchwords fetchexception htmlencoder htmlencoder getmessage tostring htmlencoder htmlencoder tostring htmlencoder valueof getstacktrace tostring stringbuilder stringbuilder uriwrapper hasnext uriwrapper htmlencoder replaceall replaceall replaceall htmlencoder replacefirst startswith htmlencoder tostring tostring tostring tostring tostring printstacktrace private long written public counted output stream output stream arg0 super arg0 countedoutputstream outputstream override public void write int x throws io exception super write x written ioexception override public void write byte buf throws io exception write buf 0 buf length ioexception override public void write byte buf int offset int length throws io exception out write buf offset length written length ioexception public long written return written public librarian handler string word list uri wrapper fileuris throws exception this fileuris fileuris this word word md5 xml librarian md5 word librarianhandler uriwrapper xmllibrarian public void set document locator locator value setdocumentlocator public void end document throws sax exception enddocument saxexception public void start document throws sax exception found match false uris new hash map string string titles new hash map string string startdocument saxexception found_match hashmap hashmap public void start element string name spaceuri string local name string raw name attributes attrs throws sax exception if raw name null raw name local name string elt name raw name gives the maximum number of digits of md5 used for creating subindices if elt name equals prefix prefix integer parse int attrs get value value if elt name equals sub index try here we need to match and see if any of the subindices match the required substring of the word for int i 0 i prefix i if md5 substring 0 prefix i equals attrs get value key prefix match md5 substring 0 prefix i logger normal this match found prefix match logger minor this word searched word prefix matcheed prefix match break catch exception e logger error this md5 of the word word could not be calculated e to string e if elt name equals files processing word false if elt name equals keywords processing word true looks for the word in the given subindex file if the word is found then the parser fetches the corresponding file elements if elt name equals word try found match false string match attrs get value v if match equals word found match true if attrs get value v equals word found match true logger minor this word searched word matched catch exception e logger error this word key doesn t match e to string e if elt name equals file try file writer outp new file writer logfile true outp write word searched word found match found match processing word processing word n outp close catch exception e if processing word true found match true uri wrapper uri new uri wrapper try uri uri uris get attrs get value id logger minor this word searched word file id uri uri uri descr not available synchronized this if titles contains key attrs get value id uri descr titles get attrs get value id if uri uri equals uri descr uri descr not available else uri descr not available if fileuris null fileuris add uri catch exception e logger error this index format may be outdated e to string e else if processing word false try string id attrs get value id string key attrs get value key int l attrs get length string title synchronized this if l 3 try title attrs get value title file writer outp new file writer logfile true outp write found title title n outp close titles put id title catch exception e logger error this index format not compatible e to string e uris put id key string words string uris values to array new string uris size catch exception e logger error this file id and key could not be retrieved may be due to format clash e startelement namespaceuri localname rawname saxexception rawname rawname localname elt_name rawname elt_name parseint getvalue elt_name subindex getvalue prefixmatch prefixmatch prefixmatch tostring elt_name processingword elt_name processingword fileelements elt_name found_match getvalue found_match getvalue found_match tostring elt_name filewriter filewriter found_match found_match processingword processingword processingword found_match uriwrapper uriwrapper getvalue containskey getvalue getvalue tostring processingword getvalue getvalue getlength getvalue filewriter filewriter tostring toarray public string get prefix match return prefix match getprefixmatch prefixmatch link occurrences document document storage storage i persistent obj super storage this obj obj occurrences storage create link ipersistent createlink inverse list storage db int oid document occurrences doc super int class true docs db create link 1 docs add doc oids new int 1 oids 0 oid assign oid db 0 false inverselist documentoccurrences createlink assignoid inverse list inverselist inverse list public int size return oids null oids length super size inverselist int first if oids null return oids 0 map entry entry map entry entry iterator null null index ascent order next return integer entry get key int value entryiterator ascent_order getkey intvalue int last if oids null return oids oids length 1 map entry entry map entry entry iterator null null index descent order next return integer entry get key int value entryiterator descent_order getkey intvalue int i inverst list iterator int pos i pos inverstlistiterator public boolean has next return i oids length hasnext public object next final int j i return new map entry public object get key return new integer oids j public object get value return docs get j public object set value object value return null public object set key object key return null getkey getvalue setvalue setkey final int j i return new map entry public object get key return new integer oids j getkey return new map entry public object get key return new integer oids j public object get value return docs get j getkey getvalue public object get key return new integer oids j public object get value return docs get j public object set value object value return null getkey getvalue setvalue public object get value return docs get j public object set value object value return null public object set key object key return null getvalue setvalue setkey public void remove iterator iterator int oid int os oids if os null int l 0 r os length while l r int m l r 1 if os m oid l m 1 else r m return new inverst list iterator r else return entry iterator new key oid null index ascent order inverstlistiterator entryiterator ascent_order void add int oid document occurrences doc int os oids if os null os length btree threshold if os null for int i 0 i os length i super put new key os i docs get i oids null docs null super put new key oid doc else int l 0 n os length r n while l r int m l r 1 if os m oid l m 1 else r m os new int n 1 system arraycopy oids 0 os 0 r os r oid system arraycopy oids r os r 1 n r docs insert r doc documentoccurrences btree_threshold void remove int oid int os oids if os null int l 0 n os length r n while l r int m l r 1 if os m oid l m 1 else r m assert that r n os r oid docs remove r oids new int n 1 system arraycopy os 0 oids 0 r system arraycopy os r 1 oids r n r 1 else super remove new key oid public void add full text searchable obj add obj obj get text obj get language fulltextsearchable gettext getlanguage public void add i persistent obj reader text string language occurrence occurrences try occurrences helper parse text text catch io exception x throw new storage error storage error full text index error x delete obj if occurrences length 0 document doc new document get storage obj documents put new key obj doc arrays sort occurrences string word occurrences 0 word int i 0 for int j 1 j occurrences length j occurrence occ occurrences j if occ word equals word add reference doc word occurrences i j language word occ word i j add reference doc word occurrences i occurrences length language ipersistent parsetext ioexception storageerror storageerror full_text_index_error getstorage addreference addreference private final void add reference document doc string word occurrence occurrences int from int till document occurrences d new document occurrences d occurrences new int till from d n words in document occurrences length for int i from i till i d occurrences i from occurrences i position occurrences i kind occ kind offset int oid doc obj get oid inverse list list inverse list inverse index get word if list null list new inverse list get storage oid d inverse index put word list else list add oid d d list list doc occurrences add d addreference documentoccurrences documentoccurrences nwordsindocument occ_kind_offset getoid inverselist inverselist inverseindex inverselist getstorage inverseindex private final void add reference document doc string word occurrence occurrences int from int till string language string normal forms helper get normal forms word language boolean is normal form false for int i 0 i normal forms length i if word equals normal forms i is normal form true add reference doc normal forms i occurrences from till if is normal form add reference doc word occurrences from till addreference normalforms getnormalforms isnormalform normalforms normalforms isnormalform addreference normalforms isnormalform addreference public void delete i persistent obj key key new key obj document doc document documents get key if doc null for int i 0 n doc occurrences size i n i document occurrences d document occurrences doc occurrences get i d list remove obj get oid d deallocate documents remove key doc deallocate ipersistent documentoccurrences documentoccurrences getoid public int get number of words return inverse index size getnumberofwords inverseindex public int get number of documents return documents size getnumberofdocuments public full text search result search string query string language int max results int time limit return search helper parse query query language max results time limit fulltextsearchresult maxresults timelimit parsequery maxresults timelimit keyword list string word this word word kwd len word length same as 1 keywordlist kwdlen sameas full text query expr public int compare to object o return weight expression weight o weight fulltextquery compareto expressionweight public void visit full text query match op q q wno kwd list size keyword list kwd new keyword list q word kwd list inverse list inverse index get q word kwd list add kwd fulltextquerymatchop kwdlist keywordlist keywordlist inverselist inverseindex kwdlist int calculate weight full text query query switch query op case full text query and return calculate weight full text query binary op query left case full text query near int shift strict match bonus for full text query q full text query binary op query right q op full text query near q full text query binary op q right shift strict match bonus return shift 32 0 calculate weight full text query binary op query left shift case full text query or int left weight calculate weight full text query binary op query left int right weight calculate weight full text query binary op query right return left weight right weight left weight right weight case full text query match case full text query strict match inverse list list kwds full text query match op query wno list return list null 0 list size default return integer max value calculateweight fulltextquery fulltextquery calculateweight fulltextquerybinaryop fulltextquery strict_match_bonus fulltextquery fulltextquerybinaryop fulltextquery fulltextquerybinaryop strict_match_bonus calculateweight fulltextquerybinaryop fulltextquery leftweight calculateweight fulltextquerybinaryop rightweight calculateweight fulltextquerybinaryop leftweight rightweight leftweight rightweight fulltextquery fulltextquery strict_match inverselist fulltextquerymatchop max_value full text query optimize full text query query switch query op case full text query and case full text query near int op query op int n conjuncts 1 full text query q query while q full text query binary op q right op op n conjuncts 1 expression weight conjuncts new expression weight n conjuncts 1 q query for int i 0 i n conjuncts i full text query binary op and full text query binary op q conjuncts i new expression weight conjuncts i expr optimize and left conjuncts i weight calculate weight conjuncts i expr q and right conjuncts n conjuncts new expression weight conjuncts n conjuncts expr optimize q conjuncts n conjuncts weight calculate weight conjuncts n conjuncts expr arrays sort conjuncts if op full text query and eliminate duplicates int n 0 j 1 inverse list list null for int i 0 i n conjuncts i q conjuncts i expr if q instanceof full text query match op full text query match op match full text query match op q if n 0 kwds match wno list list j match wno list kwds j list conjuncts n conjuncts i else kwds match wno same as j else conjuncts n conjuncts i n conjuncts n 1 else calculate distance between keywords int kwd pos 0 for int i 0 i n conjuncts i q conjuncts i expr if q instanceof full text query match op full text query match op match full text query match op q kwds match wno kwd offset match pos kwd pos kwd pos match pos if n conjuncts 0 return conjuncts 0 expr else q query int i 0 while true full text query binary op and full text query binary op q and left conjuncts i expr if i n conjuncts q and right else and right conjuncts i expr break break case full text query or full text query binary op or full text query binary op query or left optimize or left or right optimize or right break case full text query not full text query unary op not full text query unary op query not opd optimize not opd break default return query fulltextquery fulltextquery fulltextquery fulltextquery nconjuncts fulltextquery fulltextquerybinaryop nconjuncts expressionweight expressionweight nconjuncts nconjuncts fulltextquerybinaryop fulltextquerybinaryop expressionweight calculateweight nconjuncts expressionweight nconjuncts nconjuncts calculateweight nconjuncts fulltextquery inverselist nconjuncts fulltextquerymatchop fulltextquerymatchop fulltextquerymatchop sameas nconjuncts kwdpos nconjuncts fulltextquerymatchop fulltextquerymatchop fulltextquerymatchop kwdoffset kwdpos kwdpos nconjuncts fulltextquerybinaryop fulltextquerybinaryop nconjuncts fulltextquery fulltextquerybinaryop fulltextquerybinaryop fulltextquery fulltextqueryunaryop fulltextqueryunaryop int intersect int doc full text query query int left right switch query op case full text query and case full text query near do left intersect doc full text query binary op query left if left integer max value return left doc intersect left full text query binary op query right while left doc doc integer max value return doc case full text query or left intersect doc full text query binary op query left right intersect doc full text query binary op query right return left right left right case full text query match case full text query strict match keyword list kwd kwds full text query match op query wno if kwd curr doc doc return kwd curr doc iterator iterator kwd iterator if iterator null if iterator has next map entry entry map entry iterator next int next doc integer entry get key int value if next doc doc kwd curr entry entry kwd curr doc next doc return next doc else kwd curr entry null kwd curr doc 0 return integer max value if kwd list null kwd iterator iterator kwd list iterator doc if iterator has next map entry entry map entry iterator next doc integer entry get key int value kwd curr entry entry kwd curr doc doc return doc kwd curr entry null kwd curr doc 0 return integer max value case full text query not int next doc intersect doc full text query unary op query opd if next doc doc doc 1 return doc default return doc fulltextquery fulltextquery fulltextquery fulltextquerybinaryop max_value fulltextquerybinaryop max_value fulltextquery fulltextquerybinaryop fulltextquerybinaryop fulltextquery fulltextquery strict_match keywordlist fulltextquerymatchop currdoc currdoc hasnext nextdoc getkey intvalue nextdoc currentry currdoc nextdoc nextdoc currentry currdoc max_value hasnext getkey intvalue currentry currdoc currentry currdoc max_value fulltextquery nextdoc fulltextqueryunaryop nextdoc int calculate estimation full text query query int n results switch query op case full text query and case full text query near int left calculate estimation full text query binary op query left n results int right calculate estimation full text query binary op query right n results return left right left right case full text query or int left calculate estimation full text query binary op query left n results int right calculate estimation full text query binary op query right n results return left right left right case full text query match case full text query strict match keyword list kwd kwds full text query match op query wno if kwd curr doc 0 return 0 else int curr kwd curr doc int first kwd list first int last kwd list last int estimation n results last first 1 curr first 1 if estimation kwd list size estimation kwd list size return estimation case full text query not return documents size return 0 calculateestimation fulltextquery nresults fulltextquery fulltextquery calculateestimation fulltextquerybinaryop nresults calculateestimation fulltextquerybinaryop nresults fulltextquery calculateestimation fulltextquerybinaryop nresults calculateestimation fulltextquerybinaryop nresults fulltextquery fulltextquery strict_match keywordlist fulltextquerymatchop currdoc currdoc nresults fulltextquery double evaluate int doc full text query query double left right switch query op case full text query near case full text query and left evaluate doc full text query binary op query left right evaluate doc full text query binary op query right n occurrences 0 return left 0 right 0 1 left right case full text query or left evaluate doc full text query binary op query left right evaluate doc full text query binary op query right return left right left right case full text query match case full text query strict match keyword list kwd kwds full text query match op query wno if kwd curr doc doc return 1 document occurrences d document occurrences kwd curr entry get value int occ d occurrences kwd occ occ int frequency occ length if query op full text query strict match if n occurrences 0 n occurrences frequency if occurrences null occurrences length frequency occurrences new int frequency for int i 0 i frequency i occurrences i occ i occ position mask else int n pairs 0 int dst occurrences int occ1 dst 0 int occ2 occ 0 occ position mask int i 0 j 0 int offs kwd kwd offset while true if occ1 offs occ2 if occ1 offs 1 occ2 dst n pairs occ2 if j n occurrences break occ1 dst j else if i frequency break occ2 occ i occ position mask n occurrences n pairs if n pairs 0 return 1 int total number of documents documents size int n relevant documents kwd list size int total number of words inverse index size double idf math log double total number of documents n relevant documents double average words double total number of words total number of documents double density frequency math log 1 density magic average words d n words in document double word weight density idf double word score 1 for int i 0 i frequency i word score word weight occurrence kind weight occ i occ kind offset return math log word score case full text query not double rank evaluate doc full text query unary op query opd return rank 0 1 0 default return 1 fulltextquery fulltextquery fulltextquery fulltextquerybinaryop fulltextquerybinaryop noccurrences fulltextquery fulltextquerybinaryop fulltextquerybinaryop fulltextquery fulltextquery strict_match keywordlist fulltextquerymatchop currdoc documentoccurrences documentoccurrences currentry getvalue fulltextquery strict_match noccurrences noccurrences occ_position_mask npairs occ_position_mask kwdoffset npairs noccurrences occ_position_mask noccurrences npairs npairs totalnumberofdocuments nrelevantdocuments totalnumberofwords inverseindex totalnumberofdocuments nrelevantdocuments averagewords totalnumberofwords totalnumberofdocuments density_magic averagewords nwordsindocument wordweight wordscore wordscore wordweight occurrencekindweight occ_kind_offset wordscore fulltextquery fulltextqueryunaryop void build occurrence kind weight table occurrence kind weight new float 256 float weights helper get occurrence kind weights occurrence kind weight 0 1 0f for int i 1 i 256 i float weight 0 for int j 0 j weights length j if i 1 j 0 weight weights j occurrence kind weight i weight buildoccurrencekindweighttable occurrencekindweight getoccurrencekindweights occurrencekindweight occurrencekindweight double calculate nearness keyword list kwds this kwds int n kwds kwds length if n kwds 2 return 0 for int i 0 i n kwds i if kwds i occ null int j kwds i same as if j 0 kwds j occ null kwds i occ kwds j occ else return 0 kwds i occ pos 0 double max nearness 0 int swap penalty helper get word swap penalty while true int min pos integer max value double nearness 0 keyword list first null keyword list prev null for int i 0 i n kwds i keyword list curr kwds i if curr occ pos curr occ length if prev null int offset curr occ curr occ pos prev occ prev occ pos if offset 0 offset offset curr kwd len swap penalty else offset prev kwd len if offset 2 offset 1 nearness 1 math sqrt offset if curr occ curr occ pos min pos min pos curr occ curr occ pos first curr prev curr if first null break first occ pos 1 if nearness max nearness max nearness nearness return max nearness calculatenearness keywordlist nkwds nkwds nkwds sameas occpos maxnearness swappenalty getwordswappenalty minpos max_value keywordlist keywordlist nkwds keywordlist occpos occpos occpos kwdlen swappenalty kwdlen occpos minpos minpos occpos occpos maxnearness maxnearness maxnearness void reset n occurrences 0 for int i 0 i kwds length i kwds i occ null noccurrences full text search result search full text query query int max results int time limit if query null query is constrained return null long start system current time millis build occurrence kind weight table kwd list new array list query visit this kwds keyword list kwd list to array new keyword list kwd list size query optimize query system out println query to string full text search hit hits new full text search hit max results int curr doc 1 int n results 0 float nearness weight helper get nearness weight boolean no more matches false while n results max results system current time millis start time limit curr doc intersect curr doc query if curr doc integer max value no more matches true break reset double kwd rank evaluate curr doc query if kwd rank 0 double nearness calculate nearness float rank float kwd rank 1 calculate nearness nearness weight system out println kwd rank kwd rank nearness nearness total rank rank hits n results new full text search hit get storage curr doc rank curr doc 1 int estimation if n results max results full text search hit real hits new full text search hit n results system arraycopy hits 0 real hits 0 n results hits real hits if no more matches estimation n results else if query instanceof full text query match op estimation kwds 0 list size else estimation calculate estimation query n results arrays sort hits return new full text search result hits estimation fulltextsearchresult fulltextquery maxresults timelimit isconstrained currenttimemillis buildoccurrencekindweighttable kwdlist arraylist keywordlist kwdlist toarray keywordlist kwdlist tostring fulltextsearchhit fulltextsearchhit maxresults currdoc nresults nearnessweight getnearnessweight nomorematches nresults maxresults currenttimemillis timelimit currdoc currdoc currdoc max_value nomorematches kwdrank currdoc kwdrank calculatenearness kwdrank calculatenearness nearnessweight kwdrank kwdrank nresults fulltextsearchhit getstorage currdoc currdoc nresults maxresults fulltextsearchhit realhits fulltextsearchhit nresults realhits nresults realhits nomorematches nresults fulltextquerymatchop calculateestimation nresults fulltextsearchresult public full text search result search full text query query int max results int time limit full text search engine engine new full text search engine return engine search query max results time limit fulltextsearchresult fulltextquery maxresults timelimit fulltextsearchengine fulltextsearchengine maxresults timelimit public full text search helper get helper return helper fulltextsearchhelper gethelper public full text index impl storage storage full text search helper helper super storage this helper helper inverse index storage create index string class true documents storage create index i persistent class true fulltextindeximpl fulltextsearchhelper inverseindex createindex createindex ipersistent private full text index impl fulltextindeximpl public toadlet context impl socket sock multi value table string string headers bucket factory bf page maker page maker toadlet container container throws io exception this headers headers this closed false sock output stream sock get output stream remote addr sock get inet address if logger should log logger debug this logger debug this connection from remote addr this bf bf this pagemaker page maker this container container toadletcontextimpl multivaluetable bucketfactory pagemaker pagemaker toadletcontainer ioexception sockoutputstream getoutputstream remoteaddr getinetaddress shouldlog remoteaddr pagemaker private void close closed true private void send method not allowed string method boolean should disconnect throws toadlet context closed exception io exception if closed throw new toadlet context closed exception multi value table string string mvt new multi value table string string mvt put allow get put send error sock output stream 405 method not allowed l10n method not allowed should disconnect mvt sendmethodnotallowed shoulddisconnect toadletcontextclosedexception ioexception toadletcontextclosedexception multivaluetable multivaluetable senderror sockoutputstream methodnotallowed shoulddisconnect private static string l10n string key return l10n get string toadlet context impl key getstring toadletcontextimpl private static string l10n string key string pattern string value return l10n get string toadlet context impl key new string pattern new string value getstring toadletcontextimpl send an error message caller provides the http code reason string and a message which will become the title and the h1 ed contents of the error page private static void send error output stream os int code string http reason string message boolean should disconnect multi value table string string mvt throws io exception sendhtml error os code http reason html head title message title head body h1 message h1 body should disconnect mvt senderror outputstream httpreason shoulddisconnect multivaluetable ioexception sendhtmlerror httpreason shoulddisconnect send an error message containing full html from a string param os the output stream to send the message to param code the http status code param http reason the http reason string for the http status code do not make stuff up use the official reason string or some browsers may break param html message the html string to send param disconnect whether to disconnect from the client afterwards param mvt any additional headers throws io exception if we could not send the error message private static void sendhtml error output stream os int code string http reason string html message boolean disconnect multi value table string string mvt throws io exception if mvt null mvt new multi value table string string byte message bytes html message get bytes utf 8 send reply headers os code http reason mvt text html charset utf 8 message bytes length null disconnect os write message bytes outputstream httpreason htmlmessage ioexception sendhtmlerror outputstream httpreason htmlmessage multivaluetable ioexception multivaluetable messagebytes htmlmessage getbytes sendreplyheaders httpreason messagebytes messagebytes private void send no toadlet error boolean should disconnect throws toadlet context closed exception io exception if closed throw new toadlet context closed exception send error sock output stream 404 not found l10n no such toadlet should disconnect null sendnotoadleterror shoulddisconnect toadletcontextclosedexception ioexception toadletcontextclosedexception senderror sockoutputstream nosuchtoadlet shoulddisconnect private static void senduri parse error output stream os boolean should disconnect throwable e throws io exception string writer sw new string writer print writer pw new print writer sw e print stack trace pw pw close string message html head title l10n uri parse error title title head body p html encoder encode e get message p pre n sw to string sendhtml error os 400 bad request message should disconnect null senduriparseerror outputstream shoulddisconnect ioexception stringwriter stringwriter printwriter printwriter printstacktrace uriparseerrortitle htmlencoder getmessage tostring sendhtmlerror shoulddisconnect public void send reply headers int reply code string reply description multi value table string string mvt string mime type long content length throws toadlet context closed exception io exception send reply headers reply code reply description mvt mime type content length null sendreplyheaders replycode replydescription multivaluetable mimetype contentlength toadletcontextclosedexception ioexception sendreplyheaders replycode replydescription mimetype contentlength public void send reply headers int reply code string reply description multi value table string string mvt string mime type long content length date m time throws toadlet context closed exception io exception if closed throw new toadlet context closed exception if sent reply headers throw new illegal state exception already sent headers sent reply headers true send reply headers sock output stream reply code reply description mvt mime type content length m time should disconnect sendreplyheaders replycode replydescription multivaluetable mimetype contentlength mtime toadletcontextclosedexception ioexception toadletcontextclosedexception sentreplyheaders illegalstateexception sentreplyheaders sendreplyheaders sockoutputstream replycode replydescription mimetype contentlength mtime shoulddisconnect public page maker get page maker return pagemaker pagemaker getpagemaker public multi value table string string get headers return headers multivaluetable getheaders static void send reply headers output stream sock output stream int reply code string reply description multi value table string string mvt string mime type long content length date m time boolean disconnect throws io exception construct headers if mvt null mvt new multi value table string string if mime type null if mime type equals ignore case text html mvt put content type mime type charset utf 8 else mvt put content type mime type if content length 0 mvt put content length long to string content length string expires time if m time null expires time thu 01 jan 1970 00 00 00 gmt else use an expiry time of 1 day somewhat arbitrarily expires time makehttp date m time get time 24 60 60 1000 mvt put expires expires time string now string makehttp date system current time millis string last mod string if m time null last mod string now string else last mod string makehttp date m time get time mvt put last modified last mod string mvt put date now string if m time null mvt put pragma no cache mvt put cache control max age 0 must revalidate no cache no store post check 0 pre check 0 if disconnect mvt put connection close else mvt put connection keep alive string builder buf new string builder 1024 buf append http 1 1 buf append reply code buf append buf append reply description buf append r n for enumeration string e mvt keys e has more elements string key e next element object list mvt get array key key fix key key for int i 0 i list length i string val string list i buf append key buf append buf append val buf append r n buf append r n sock output stream write buf to string get bytes us ascii sendreplyheaders outputstream sockoutputstream replycode replydescription multivaluetable mimetype contentlength mtime ioexception multivaluetable mimetype mimetype equalsignorecase mimetype mimetype contentlength tostring contentlength expirestime mtime expirestime expirestime makehttpdate mtime gettime expirestime nowstring makehttpdate currenttimemillis lastmodstring mtime lastmodstring nowstring lastmodstring makehttpdate mtime gettime lastmodstring nowstring mtime stringbuilder stringbuilder replycode replydescription hasmoreelements nextelement getarray fixkey sockoutputstream tostring getbytes private static string makehttp date long time for http gmt utc simple date format sdf new simple date format eee dd mmm yyyy hh mm ss gmt locale us sdf set time zone tz utc return sdf format new date time makehttpdate simpledateformat simpledateformat settimezone tz_utc fix key case to be conformant to http expectations note that http is case insensitive on header names but we may as well send something as close to the spec as possible in case of broken clients private static string fix key string key string builder sb new string builder key length char prev 0 for int i 0 i key length i char c key char at i if i 0 prev c character to upper case c sb append c prev c return sb to string fixkey stringbuilder stringbuilder charat touppercase tostring handle an incoming connection blocking obviously public static void handle socket sock toadlet container container page maker page maker try input stream is new buffered input stream sock get input stream 4096 line reading input stream lis new line reading input stream is while true string first line lis read line 32768 128 false iso 8859 1 or us ascii not utf 8 if first line null sock close return else if first line equals continue boolean logminor logger should log logger minor toadlet context impl class if logminor logger minor toadlet context impl class first line first line string split first line split if split length 3 throw new parse exception could not parse request line split length split length first line if split 2 starts with http 1 throw new parse exception unrecognized protocol split 2 uri uri try uri uri pre encoder encodeuri split 1 normalize if logminor logger minor toadlet context impl class uri uri path uri get path host uri get host frag uri get fragment port uri get port query uri get query scheme uri get scheme catch uri syntax exception e senduri parse error sock get output stream true e return string method split 0 multi value table string string headers new multi value table string string while true string line lis read line 32768 128 false iso 8859 or us ascii not utf 8 if line null sock close return system out println length line length line if line length 0 break int index line index of if index 0 throw new parse exception missing in request header field string before line substring 0 index to lower case string after line substring index 1 after after trim headers put before after boolean disconnect should disconnect after handled split 2 equals http 1 0 headers container enable persistent connections boolean allow post container allow posts bucket factory bf container get bucket factory toadlet context impl ctx new toadlet context impl sock headers bf page maker container ctx should disconnect disconnect if we re handling a post copy the data into a bucket now before we go into the redirect loop bucket data if method equals post string slen headers get content length if slen null send error sock get output stream 400 bad request l10n no content length inpost true null return long len try len integer parse int slen if len 0 throw new number format exception content length less than 0 catch number format exception e send error sock get output stream 400 bad request l10n cannot parse content length with error error e to string true null return if allow post container public gateway mode ctx is allowed full access data bf make bucket len bucket tools copy from data is len else file util skip fully is len ctx send method not allowed post true ctx close return else we re not doing to use it but we have to keep the compiler happy data null handle it try boolean redirect true while redirect don t go around the loop unless set explicitly redirect false toadlet t try t container find toadlet uri catch permanent redirect exception e toadlet write permanent redirect ctx found elsewhere e newuri toascii string break if t null ctx send no toadlet error ctx should disconnect break http request impl req new http request impl uri data ctx try if method equals get t handle get uri req ctx ctx close else if method equals post t handle post uri req ctx else ctx send method not allowed method ctx should disconnect ctx close catch redirect exception re uri re newuri redirect true finally req free parts if ctx should disconnect sock close return finally if data null data free catch parse exception e try send error sock get output stream 400 bad request l10n parse error with error error e get message true null catch io exception e1 ignore catch too long exception e try send error sock get output stream 400 bad request l10n headers line too long true null catch io exception e1 ignore catch io exception e return catch toadlet context closed exception e logger error toadlet context impl class toadlet context closed exception while handling connection return catch throwable t logger error toadlet context impl class caught error t handling socket t toadletcontainer pagemaker pagemaker inputstream bufferedinputstream getinputstream linereadinginputstream linereadinginputstream firstline readline _not_ firstline firstline shouldlog toadletcontextimpl toadletcontextimpl firstline firstline parseexception firstline startswith parseexception uripreencoder toadletcontextimpl getpath gethost getfragment getport getquery getscheme urisyntaxexception senduriparseerror getoutputstream multivaluetable multivaluetable readline indexof parseexception tolowercase shoulddisconnectafterhandled enablepersistentconnections allowpost allowposts bucketfactory getbucketfactory toadletcontextimpl toadletcontextimpl pagemaker shoulddisconnect senderror getoutputstream nocontentlengthinpost parseint numberformatexception numberformatexception senderror getoutputstream cannotparsecontentlengthwitherror tostring allowpost publicgatewaymode isallowedfullaccess makebucket buckettools copyfrom fileutil skipfully sendmethodnotallowed findtoadlet permanentredirectexception writepermanentredirect toasciistring sendnotoadleterror shoulddisconnect httprequestimpl httprequestimpl handleget handlepost sendmethodnotallowed shoulddisconnect redirectexception freeparts shoulddisconnect parseexception senderror getoutputstream parseerrorwitherror getmessage ioexception toolongexception senderror getoutputstream headerslinetoolong ioexception ioexception toadletcontextclosedexception toadletcontextimpl toadletcontextclosedexception toadletcontextimpl should the connection be closed after handling this request param ishttp10 did the client specify http 1 0 param headers client headers return true if the connection should be closed private static boolean should disconnect after handled boolean ishttp10 multi value table string string headers string connection headers get connection if connection null if connection equals ignore case close return true if connection equals ignore case keep alive return false if ishttp10 true return true else http 1 1 return false shoulddisconnectafterhandled multivaluetable equalsignorecase equalsignorecase private static final long serial versionuid 1 parse exception string string super string serialversionuid parseexception public void write data byte data int offset int length throws toadlet context closed exception io exception if closed throw new toadlet context closed exception sock output stream write data offset length writedata toadletcontextclosedexception ioexception toadletcontextclosedexception sockoutputstream public void write data byte data throws toadlet context closed exception io exception write data data 0 data length writedata toadletcontextclosedexception ioexception writedata public void write data bucket data throws toadlet context closed exception io exception if closed throw new toadlet context closed exception bucket tools copy to data sock output stream long max value writedata toadletcontextclosedexception ioexception toadletcontextclosedexception buckettools copyto sockoutputstream max_value public bucket factory get bucket factory return bf bucketfactory getbucketfactory public html node add form child html node parent node string target string name return container add form child parent node target name htmlnode addformchild htmlnode parentnode addformchild parentnode public boolean is allowed full access return container is allowed full access remote addr isallowedfullaccess isallowedfullaccess remoteaddr public boolean do robots return container do robots dorobots dorobots public void force disconnect this should disconnect true forcedisconnect shoulddisconnect public toadlet container get container return container toadletcontainer getcontainer public static long version 1 static string get svn revision return svn revision getsvnrevision svnrevision static long get version return version getversion public static void main string args system out println system out println svn revision system out println system out println get version svnrevision getversion public static boolean is valid address inet address i boolean include local addresses in noderefs if i is any local address wildcard address 0 0 0 0 ignore return false else if i is link local address i is loopback address i is site local address if include local addresses in noderefs return true else return false else if i is multicast address ignore return false else byte ip address bytes i get address if ip address bytes length 4 ip address bytes 0 0 return false first octet of i pv4 address cannot be zero as 0 0 0 0 8 has been reserved since at least rfc790 also java throws an io exception when they re used return true isvalidaddress inetaddress includelocaladdressesinnoderefs isanylocaladdress islinklocaladdress isloopbackaddress issitelocaladdress includelocaladdressesinnoderefs ismulticastaddress ipaddressbytes getaddress ipaddressbytes ipaddressbytes ipv4 ioexception public class persistent stub implements i persistent public void load throw new storage error storage error access to stub persistentstub ipersistent storageerror storageerror access_to_stub public void load and modify load modify loadandmodify public final boolean is raw return true israw public final boolean is modified return false ismodified public final boolean is deleted return false isdeleted public final boolean is persistent return true ispersistent public void make persistent storage storage throw new storage error storage error access to stub makepersistent storageerror storageerror access_to_stub public void store throw new storage error storage error access to stub storageerror storageerror access_to_stub public void modify throw new storage error storage error access to stub storageerror storageerror access_to_stub public persistent stub storage storage int oid this storage storage this oid oid persistentstub public final int get oid return oid getoid public void deallocate throw new storage error storage error access to stub storageerror storageerror access_to_stub public boolean recursive loading return true recursiveloading public final storage get storage return storage getstorage public boolean equals object o return o instanceof i persistent i persistent o get oid oid ipersistent ipersistent getoid public int hash code return oid hashcode public void on load onload public void on store onstore public void invalidate throw new storage error storage error access to stub storageerror storageerror access_to_stub transient int oid public void assign oid storage storage int oid boolean raw throw new storage error storage error access to stub assignoid storageerror storageerror access_to_stub public object clone throws clone not supported exception persistent stub p persistent stub super clone p oid 0 return p clonenotsupportedexception persistentstub persistentstub public void read external java io object input s throws java io io exception class not found exception oid s read int readexternal objectinput ioexception classnotfoundexception readint public void write external java io object output s throws java io io exception s write int oid writeexternal objectoutput ioexception writeint public class invalid address override user alert extends abstract user alert public invalid address override user alert node n super false null null null null short 0 true null false null this node n invalidaddressoverrideuseralert abstractuseralert invalidaddressoverrideuseralert final node node override public string get title return l10n unknown address title gettitle unknownaddresstitle override public string get text return l10n unknown address gettext unknownaddress private string l10n string key return l10n get string invalid address override user alert key getstring invalidaddressoverrideuseralert override public html node gethtml text sub config sc node config get node option o sc get option ip address override html node text node new html node div l10n addl10n substitution text node invalid address override user alert unknown address with config link new string link link new string a href config a html node form node text node add child form new string action method new string config post form node add child input new string type name value new string hidden form password node client core form password html node list node form node add child ul class config html node item node list node add child li item node add child span class configshortdesc l10n get string o get short desc add child input new string type name value new string text sc get prefix ip address override o get value string item node add child span class configlongdesc l10n get string o get long desc form node add child input new string type value new string submit l10n get string user alert apply form node add child input new string type value new string reset l10n get string user alert reset return text node htmlnode gethtmltext subconfig getoption ipaddressoverride htmlnode textnode htmlnode addl10nsubstitution textnode invalidaddressoverrideuseralert unknownaddresswithconfiglink htmlnode formnode textnode addchild formnode addchild formpassword clientcore formpassword htmlnode listnode formnode addchild htmlnode itemnode listnode addchild itemnode addchild getstring getshortdesc addchild getprefix ipaddressoverride getvaluestring itemnode addchild getstring getlongdesc formnode addchild getstring useralert formnode addchild getstring useralert textnode override public short get priority class return user alert error getpriorityclass useralert override public string get short text return l10n unknown address short getshorttext unknownaddressshort public class argument data extends node data public argument data argumentdata nodedata argumentdata private string value public string get value return value getvalue public void set value string value this value value setvalue public dsa public key dsa group g big integer y if y signum 1 throw new illegal argument exception this y y this group g if y compare to g getp 0 throw new illegal argument exception y must be p but y y p g getp dsapublickey dsagroup biginteger illegalargumentexception compareto illegalargumentexception use this constructor if you have a hex ed version of y already available will save some conversions and string allocations public dsa public key dsa group g string y as hex string throws number format exception this y new native big integer y as hex string 16 if y signum 1 throw new illegal argument exception this group g if g null throw new null pointer exception dsapublickey dsagroup yashexstring numberformatexception nativebiginteger yashexstring illegalargumentexception nullpointerexception public dsa public key dsa group g dsa private key p this g g getg mod pow p getx g getp dsapublickey dsagroup dsaprivatekey modpow public dsa public key input stream is throws io exception crypt format exception group dsa group dsa group read is y util readmpi is if y compare to group getp 0 throw new illegal argument exception y must be p but y y p group getp dsapublickey inputstream ioexception cryptformatexception dsagroup dsagroup compareto illegalargumentexception public dsa public key byte pubkey bytes throws io exception crypt format exception this new byte array input stream pubkey bytes dsapublickey pubkeybytes ioexception cryptformatexception bytearrayinputstream pubkeybytes private dsa public key dsa public key key fingerprint null regen when needed this y new native big integer 1 key y to byte array this group key group clone key dsapublickey dsapublickey nativebiginteger tobytearray clonekey public static dsa public key create byte pubkey as bytes throws crypt format exception try return new dsa public key new byte array input stream pubkey as bytes catch io exception e throw new crypt format exception e dsapublickey pubkeyasbytes cryptformatexception dsapublickey bytearrayinputstream pubkeyasbytes ioexception cryptformatexception public big integer gety return y biginteger public big integer getp return group getp biginteger public big integer getq return group getq biginteger public big integer getg return group getg biginteger override public string key type return dsa p keytype nope this is fine public dsa group get group return group dsagroup getgroup public static crypto key read input stream i throws io exception crypt format exception return new dsa public key i cryptokey inputstream ioexception cryptformatexception dsapublickey public int key id return y int value keyid intvalue public string to long string return y hex util bi to hex y tolongstring hexutil bitohex override public byte as bytes byte group bytes group as bytes byte ybytes util mp ibytes y byte bytes new byte group bytes length ybytes length system arraycopy group bytes 0 bytes 0 group bytes length system arraycopy ybytes 0 bytes group bytes length ybytes length return bytes asbytes groupbytes asbytes mpibytes groupbytes groupbytes groupbytes groupbytes public byte as bytes hash byte hash sha256 digest as bytes return hash asbyteshash asbytes public byte as padded bytes byte as bytes as bytes if as bytes length padded size return as bytes if as bytes length padded size throw new error cannot fit key in padded size real size is as bytes length byte padded new byte padded size system arraycopy as bytes 0 padded 0 as bytes length return padded aspaddedbytes asbytes asbytes asbytes padded_size asbytes asbytes padded_size padded_size asbytes padded_size asbytes asbytes override public byte fingerprint synchronized this if fingerprint null fingerprint fingerprint new big integer y return fingerprint biginteger public boolean equals dsa public key o if this o not necessary but a very cheap optimization return true return y equals o y group equals o group dsapublickey override public int hash code return y hash code group hash code hashcode hashcode hashcode override public boolean equals object o if this o not necessary but a very cheap optimization return true else if o null o get class this get class return false return y equals dsa public key o y group equals dsa public key o group getclass getclass dsapublickey dsapublickey public int compare to object other if other instanceof dsa public key return gety compare to dsa public key other gety else return 1 compareto dsapublickey compareto dsapublickey public simple field set as field set simple field set fs new simple field set true fs put single y base64 encode y to byte array return fs simplefieldset asfieldset simplefieldset simplefieldset putsingle tobytearray public static dsa public key create simple field set set dsa group group throws illegal base64 exception native big integer x new native big integer 1 base64 decode set get y return new dsa public key group x dsapublickey simplefieldset dsagroup illegalbase64exception nativebiginteger nativebiginteger dsapublickey public byte get full key return as bytes hash getfullkey asbyteshash public byte get routing key return as bytes hash getroutingkey asbyteshash public dsa public key clone key return new dsa public key this dsapublickey clonekey dsapublickey public void remove from object container container container delete y group remove from container container delete this removefrom objectcontainer removefrom public final class lighten composite extends rgb composite public lighten composite float alpha super alpha lightencomposite rgbcomposite lightencomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr dir sr dog dig sg dig sg dob dib sb dib sb float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public synchronized void load if oid 0 state raw 0 storage load object this loadobject public synchronized void load and modify load modify loadandmodify public final boolean is raw return state raw 0 israw public final boolean is modified return state dirty 0 ismodified public final boolean is deleted return state deleted 0 isdeleted public final boolean is persistent return oid 0 ispersistent public void make persistent storage storage if oid 0 storage make persistent this makepersistent makepersistent public void store if state raw 0 throw new storage error storage error access to stub if storage null storage store object this state dirty storageerror storageerror access_to_stub storeobject public void modify if state dirty 0 oid 0 if state raw 0 throw new storage error storage error access to stub assert that state deleted 0 storage modify object this state dirty storageerror storageerror access_to_stub modifyobject public persistent public persistent public persistent storage storage this storage storage public final int get oid return oid getoid public void deallocate if oid 0 storage deallocate object this deallocateobject public boolean recursive loading return true recursiveloading public final storage get storage return storage getstorage public boolean equals object o if oid 0 return super equals o return o instanceof i persistent i persistent o get oid oid ipersistent ipersistent getoid public int hash code return oid hashcode public void on load onload public void on store onstore public void invalidate state dirty state raw protected void finalize if state dirty 0 oid 0 storage store finalized object this state deleted storefinalizedobject public void assign oid storage storage int oid boolean raw this oid oid this storage storage if raw state raw else state raw assignoid protected void clear state state 0 oid 0 clearstate public object clone throws clone not supported exception persistent p persistent super clone p oid 0 p state 0 return p clonenotsupportedexception public void read external java io object input s throws java io io exception class not found exception oid s read int readexternal objectinput ioexception classnotfoundexception readint public void write external java io object output s throws java io io exception if s instanceof storage impl persistent object output stream make persistent storage impl persistent object output stream s get storage s write int oid writeexternal objectoutput ioexception storageimpl persistentobjectoutputstream makepersistent storageimpl persistentobjectoutputstream getstorage writeint public final class negation composite extends rgb composite public negation composite float alpha super alpha negationcomposite rgbcomposite negationcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor 255 math abs 255 sr dir dog 255 math abs 255 sg dig dob 255 math abs 255 sb dib float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac no point having an identifier really public shutdown message throws message invalid exception shutdownmessage messageinvalidexception override public simple field set get field set return null simplefieldset getfieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied shutdown requires full access null false fcp message msg new protocol error message protocol error message shutting down true the node is shutting down node false handler output handler queue msg node exit received fcp shutdown message fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied fcpmessage protocolerrormessage protocolerrormessage shutting_down outputhandler override public void remove from object container container container delete this removefrom objectcontainer param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public configuration page web interface my web interface http request my request super my web interface my request todo auto generated constructor stub mywebinterface webinterface myrequest configurationpage webinterface mywebinterface httprequest myrequest mywebinterface myrequest fixme maybe use or steal freenet clients http config toadlet public void make html node list1 new html node ul html node list2 new html node ul config config wot get config synchronized config string int keys config get all int keys string string keys config get all string keys arrays sort int keys arrays sort string keys for string key int keys list1 add child new html node li key config get int key for string key string keys list1 add child new html node li key config get string key html node box add content box configuration box add child list1 box add child list2 configtoadlet htmlnode htmlnode htmlnode htmlnode getconfig intkeys getallintkeys stringkeys getallstringkeys intkeys stringkeys intkeys addchild htmlnode getint stringkeys addchild htmlnode getstring htmlnode addcontentbox addchild addchild private volatile boolean isprng ready false public startup toadlet static toadlet static toadlet super null this static toadlet static toadlet isprngready startuptoadlet statictoadlet statictoadlet statictoadlet statictoadlet override public void handle get uri uri http request req toadlet context ctx throws toadlet context closed exception io exception redirect exception if we don t disconnect we will have pipelining issues ctx force disconnect string path uri get path if path starts with static toadlet root url static toadlet null static toadlet handle get uri req ctx else string desc l10n get string startup toadlet title html node page node ctx get page maker get page node desc false ctx html node head node ctx get page maker get head node page node head node add child meta new string http equiv content new string refresh 20 url html node content node ctx get page maker get content node page node if isprng ready html node prng infobox content node add child ctx get page maker get infobox infobox error l10n get string startup toadlet entropy error title html node prng infobox content ctx get page maker get content node prng infobox prng infobox content add child l10n get string startup toadlet entropy error content html node infobox content node add child ctx get page maker get infobox infobox error desc html node infobox content ctx get page maker get content node infobox infobox content add child l10n get string startup toadlet is starting up welcome toadlet maybe display wrapper logfile ctx content node todo send a retry after header writehtml reply ctx 503 desc page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception forcedisconnect getpath startswith statictoadlet root_url statictoadlet statictoadlet handleget getstring startuptoadlet htmlnode pagenode getpagemaker getpagenode htmlnode headnode getpagemaker getheadnode pagenode headnode addchild htmlnode contentnode getpagemaker getcontentnode pagenode isprngready htmlnode prnginfobox contentnode addchild getpagemaker getinfobox getstring startuptoadlet entropyerrortitle htmlnode prnginfoboxcontent getpagemaker getcontentnode prnginfobox prnginfoboxcontent addchild getstring startuptoadlet entropyerrorcontent htmlnode contentnode addchild getpagemaker getinfobox htmlnode infoboxcontent getpagemaker getcontentnode infoboxcontent addchild getstring startuptoadlet isstartingup welcometoadlet maybedisplaywrapperlogfile contentnode writehtmlreply pagenode override public string supported methods return get supportedmethods public void set isprng ready isprng ready true setisprngready isprngready public class ridgedfbm implements function2d public float evaluate float x float y return 1 math abs noise noise2 x y public inet address address tracker item long time definitely no packets received long time definitely no packets sent inet address addr super time definitely no packets received time definitely no packets sent this addr addr inetaddressaddresstrackeritem timedefinitelynopacketsreceived timedefinitelynopacketssent inetaddress timedefinitelynopacketsreceived timedefinitelynopacketssent override public simple field set to field set simple field set fs super to field set fs put overwrite address addr get host address return fs simplefieldset tofieldset simplefieldset tofieldset putoverwrite gethostaddress public inet address address tracker item simple field set fs throws fs parse exception super fs try addr inet address get by name fs get string address catch unknown host exception e fs parse exception ex new fs parse exception unknown domain name in address e ex init cause e throw ex inetaddressaddresstrackeritem simplefieldset fsparseexception inetaddress getbyname getstring unknownhostexception fsparseexception fsparseexception initcause public void test init trust tree throws malformedurl exception invalid parameter exception unknown identity exception not in trust tree exception m wot create own identity uria uria a true test this also initializes the trust tree assert true m wot get all non own identities size 0 assert true m wot get all own identities size 1 assert true m wot get all trusts size 0 assert true m wot get all scores size 1 own identity a m wot get own identity byuri uria score score m wot get score a a assert true score get score 100 assert true score get rank 0 assert true score get capacity 100 assert true score get tree owner a assert true score get target a empty the database fixme this is not needed because database based test does that in set up right object set object all db query by example new object while all has next db delete all next testinittrusttree malformedurlexception invalidparameterexception unknownidentityexception notintrusttreeexception mwot createownidentity asserttrue mwot getallnonownidentities asserttrue mwot getallownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores ownidentity mwot getownidentitybyuri mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity asserttrue gettreeowner asserttrue gettarget databasebasedtest setup objectset querybyexample hasnext public void test set trust1 throws invalid parameter exception malformedurl exception own identity a new own identity uria uria a true identity b new identity urib b true we store them manually so that the wot does not initialize the trust tree m wot getdb store a 5 m wot getdb store b 5 with a s trust tree not initialized b shouldn t get a score m wot set trust a b byte 10 foo assert true m wot get all non own identities size 1 assert true m wot get all own identities size 1 assert true m wot get all trusts size 1 assert true m wot get all scores size 0 testsettrust1 invalidparameterexception malformedurlexception ownidentity ownidentity mwot mwot mwot settrust asserttrue mwot getallnonownidentities asserttrue mwot getallownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores public void test set trust2 throws malformedurl exception invalid parameter exception duplicate trust exception not trusted exception not in trust tree exception own identity a m wot create own identity uria uria a true test initializes it s trust tree identity b new identity urib b true m wot getdb store b 5 m wot set trust a b byte 100 foo check we have the correct number of objects assert true m wot get all non own identities size 1 assert true m wot get all own identities size 1 assert true m wot get all trusts size 1 assert true m wot get all scores size 2 check the trust object trust t m wot get trust a b assert true t get truster a assert true t get trustee b assert true t get value 100 assert true t get comment equals foo check a s score object score scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object score scoreb m wot get score a b assert true scoreb get score 100 assert true scoreb get rank 1 assert true scoreb get capacity 40 change the trust value and comment m wot set trust a b byte 50 bar check we have the correct number of objects assert true m wot get all non own identities size 1 assert true m wot get all own identities size 1 assert true m wot get all trusts size 1 assert true m wot get all scores size 2 check the trust object t m wot get trust a b assert true t get truster a assert true t get trustee b assert true t get value 50 assert true t get comment equals bar check a s score object scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object scoreb m wot get score a b assert true scoreb get score 50 assert true scoreb get rank 1 assert true scoreb get capacity 40 empty the database fixme this is not needed because database based test does that in set up right object set object all db query by example new object while all has next db delete all next testsettrust2 malformedurlexception invalidparameterexception duplicatetrustexception nottrustedexception notintrusttreeexception ownidentity mwot createownidentity mwot mwot settrust asserttrue mwot getallnonownidentities asserttrue mwot getallownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot gettrust asserttrue gettruster asserttrue gettrustee asserttrue getvalue asserttrue getcomment mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot settrust asserttrue mwot getallnonownidentities asserttrue mwot getallownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot gettrust asserttrue gettruster asserttrue gettrustee asserttrue getvalue asserttrue getcomment mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity databasebasedtest setup objectset querybyexample hasnext public void test remove trust throws malformedurl exception invalid parameter exception unknown identity exception not in trust tree exception ext object container db m wot getdb own identity a m wot create own identity uria uria a true test identity b new identity urib b true do not init the trust tree identity c new identity uric c true do not init the trust tree db store b db store c m wot set trust a b byte 100 foo m wot set trust b c byte 50 bar check we have the correct number of objects assert true m wot get all own identities size 1 assert true m wot get all non own identities size 2 assert true m wot get all trusts size 2 assert true m wot get all scores size 3 check a s score object score scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object score scoreb m wot get score a b assert true scoreb get score 100 assert true scoreb get rank 1 assert true scoreb get capacity 40 check c s score object score scorec m wot get score a c assert true scorec get score 20 assert true scorec get rank 2 assert true scorec get capacity 16 m wot set trust a b byte 1 bastard check we have the correct number of objects assert true m wot get all own identities size 1 assert true m wot get all non own identities size 2 assert true m wot get all trusts size 2 assert true m wot get all scores size 2 check a s score object scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object scoreb m wot get score a b assert true scoreb get score 1 assert true scoreb get rank 1 assert true scoreb get capacity 0 c should not have a score anymore try m wot get score a c fail catch not in trust tree exception e empty the database fixme this is not needed because database based test does that in set up right object set object all db query by example new object while all has next db delete all next testremovetrust malformedurlexception invalidparameterexception unknownidentityexception notintrusttreeexception extobjectcontainer mwot ownidentity mwot createownidentity mwot settrust mwot settrust asserttrue mwot getallownidentities asserttrue mwot getallnonownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot settrust asserttrue mwot getallownidentities asserttrue mwot getallnonownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore notintrusttreeexception databasebasedtest setup objectset querybyexample hasnext public void test trust loop throws malformedurl exception invalid parameter exception not in trust tree exception ext object container db m wot getdb own identity a m wot create own identity uria uria a true test identity b new identity urib b true do not init the trust tree identity c new identity uric c true do not init the trust tree db store b db store c m wot set trust a b byte 100 foo m wot set trust b c byte 50 bar m wot set trust c a byte 100 bleh m wot set trust c b byte 50 oops check we have the correct number of objects assert true m wot get all own identities size 1 assert true m wot get all non own identities size 2 assert true m wot get all trusts size 4 assert true m wot get all scores size 3 check a s score object score scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check b s score object score scoreb m wot get score a b assert true scoreb get score 108 assert true scoreb get rank 1 assert true scoreb get capacity 40 check c s score object score scorec m wot get score a c assert true scorec get score 20 assert true scorec get rank 2 assert true scorec get capacity 16 testtrustloop malformedurlexception invalidparameterexception notintrusttreeexception extobjectcontainer mwot ownidentity mwot createownidentity mwot settrust mwot settrust mwot settrust mwot settrust asserttrue mwot getallownidentities asserttrue mwot getallnonownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity public void test own indentities trust throws malformedurl exception invalid parameter exception not in trust tree exception own identity a m wot create own identity uria uria a true test own identity b m wot create own identity urib urib b true test m wot set trust a b byte 100 foo m wot set trust b a byte 100 bar check we have the correct number of objects assert true m wot get all own identities size 2 assert true m wot get all non own identities size 0 assert true m wot get all trusts size 2 assert true m wot get all scores size 4 check a s own score object score scorea m wot get score a a assert true scorea get score 100 assert true scorea get rank 0 assert true scorea get capacity 100 check a s score object score score afromb m wot get score b a assert true score afromb get score 100 assert true score afromb get rank 1 assert true score afromb get capacity 40 check b s own score object score scoreb m wot get score a a assert true scoreb get score 100 assert true scoreb get rank 0 assert true scoreb get capacity 100 check b s score object score score bfroma m wot get score b a assert true score bfroma get score 100 assert true score bfroma get rank 1 assert true score bfroma get capacity 40 testownindentitiestrust malformedurlexception invalidparameterexception notintrusttreeexception ownidentity mwot createownidentity ownidentity mwot createownidentity mwot settrust mwot settrust asserttrue mwot getallownidentities asserttrue mwot getallnonownidentities asserttrue mwot getalltrusts asserttrue mwot getallscores mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity scoreafromb mwot getscore asserttrue scoreafromb getscore asserttrue scoreafromb getrank asserttrue scoreafromb getcapacity mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity scorebfroma mwot getscore asserttrue scorebfroma getscore asserttrue scorebfroma getrank asserttrue scorebfroma getcapacity final boolean ssk public offer reply tag boolean isssk super ssk isssk offerreplytag override public void log still present long uid string buffer sb new string buffer sb append still present after append time util format time age sb append ssk append ssk logger error this sb to string logstillpresent stringbuffer stringbuffer timeutil formattime tostring public configurable persister persistable t sub config node config string option name string default filename int sort order boolean expert boolean force write string short desc string long desc packet sender ps file base dir throws node init exception super t ps node config register option name new file base dir default filename to string sort order expert force write short desc long desc new string callback override public string get return persist target to string override public void set string val throws invalid config value exception set throttles val string throttle file node config get string option name try set throttles throttle file catch invalid config value exception e2 throw new node init exception node init exception exit throttle file error e2 get message configurablepersister subconfig nodeconfig optionname defaultfilename sortorder forcewrite shortdesc longdesc packetsender basedir nodeinitexception nodeconfig optionname basedir defaultfilename tostring sortorder forcewrite shortdesc longdesc stringcallback persisttarget tostring invalidconfigvalueexception setthrottles throttlefile nodeconfig getstring optionname setthrottles throttlefile invalidconfigvalueexception nodeinitexception nodeinitexception exit_throttle_file_error getmessage node config register option name new file base dir default filename to string sort order expert force write short desc long desc new string callback override public string get return persist target to string nodeconfig optionname basedir defaultfilename tostring sortorder forcewrite shortdesc longdesc stringcallback persisttarget tostring override public void set string val throws invalid config value exception set throttles val invalidconfigvalueexception setthrottles private void set throttles string val throws invalid config value exception file f new file val file tmp new file f to string tmp while true if f exists if f can read f can write throw new invalid config value exception l10n exists cannot read write tmp break else try if f create new file if f exists continue throw new invalid config value exception l10n does not exist cannot create tmp catch io exception e throw new invalid config value exception l10n does not exist cannot create tmp while true if tmp exists if tmp can read tmp can write throw new invalid config value exception l10n exists cannot read write tmp break else try tmp create new file catch io exception e throw new invalid config value exception l10n does not exist cannot create tmp synchronized this persist target f persist temp tmp setthrottles invalidconfigvalueexception tostring canread canwrite invalidconfigvalueexception existscannotreadwrite createnewfile invalidconfigvalueexception doesnotexistcannotcreate ioexception invalidconfigvalueexception doesnotexistcannotcreate canread canwrite invalidconfigvalueexception existscannotreadwrite createnewfile ioexception invalidconfigvalueexception doesnotexistcannotcreate persisttarget persisttemp private string l10n string key return l10n get string configurable persister key getstring configurablepersister private static int adjust float color float factor float gamma if color 0 0 return 0 return int math round 255 math pow color factor gamma convert a wavelength to an rgb value param wavelength wavelength in nanometres return the rgb value public static int wavelength torgb float wavelength float gamma 0 80f float r g b factor int w int wavelength if w 380 r 0 0f g 0 0f b 0 0f else if w 440 r wavelength 440 440 380 g 0 0f b 1 0f else if w 490 r 0 0f g wavelength 440 490 440 b 1 0f else if w 510 r 0 0f g 1 0f b wavelength 510 510 490 else if w 580 r wavelength 510 580 510 g 1 0f b 0 0f else if w 645 r 1 0f g wavelength 645 645 580 b 0 0f else if w 780 r 1 0f g 0 0f b 0 0f else r 0 0f g 0 0f b 0 0f let the intensity fall off near the vision limits if 380 w w 419 factor 0 3f 0 7f wavelength 380 420 380 else if 420 w w 700 factor 1 0f else if 701 w w 780 factor 0 3f 0 7f 780 wavelength 780 700 else factor 0 0f int ir adjust r factor gamma int ig adjust g factor gamma int ib adjust b factor gamma return 0xff000000 ir 16 ig 8 ib wavelengthtorgb public static file persistent config construct file persistent config file f throws io exception file filename f file temp filename new file f get path tmp return new file persistent config load filename temp filename filename temp filename filepersistentconfig constructfilepersistentconfig ioexception tempfilename getpath filepersistentconfig tempfilename tempfilename static simple field set load file filename file temp filename throws io exception boolean filename exists filename exists boolean temp filename exists temp filename exists if filename exists filename can write logger error file persistent config class warning cannot write to config file filename system err println warning cannot write to config file filename if temp filename exists temp filename can write logger error file persistent config class warning cannot write to config tempfile temp filename system err println warning cannot write to config tempfile temp filename if filename exists if filename can read filename length 0 try return initial load filename catch file not found exception e system err println cannot open config file filename e checking for temp file temp filename catch eof exception e system err println empty config file filename end of file other ioe s indicate a more serious problem else we probably won t be able to write it either system err println cannot read config file filename if temp filename exists if temp filename can read temp filename length 0 try return initial load temp filename catch file not found exception e system err println cannot open temp config file either temp filename e other ioe s indicate a more serious problem else system err println cannot read temp config file temp filename throw new io exception cannot read temp config file temp filename system err println no config file found creating new filename return null simplefieldset tempfilename ioexception filenameexists tempfilenameexists tempfilename filenameexists canwrite filepersistentconfig tempfilenameexists tempfilename canwrite filepersistentconfig tempfilename tempfilename filenameexists canread initialload filenotfoundexception tempfilename eofexception tempfilename tempfilename canread tempfilename initialload tempfilename filenotfoundexception tempfilename tempfilename ioexception tempfilename protected file persistent config simple field set origfs file fnam file temp throws io exception super origfs this filename fnam this temp filename temp filepersistentconfig simplefieldset ioexception tempfilename load the config file into a simple field set throws io exception private static simple field set initial load file to read throws io exception if to read null return null file input stream fis null buffered input stream bis null line reading input stream lis null try fis new file input stream to read bis new buffered input stream fis lis new line reading input stream bis config file is utf 8 too return new simple field set lis 1024 1024 128 true true true true fixme advanced users may edit the config file hence true finally closer close lis closer close bis closer close fis simplefieldset ioexception simplefieldset initialload toread ioexception toread fileinputstream bufferedinputstream linereadinginputstream fileinputstream toread bufferedinputstream linereadinginputstream simplefieldset override public void register sub config sc super register sc subconfig override public void store if finished init logger minor this initialization not finished refusing to write config new exception error return try synchronized store sync inner store catch io exception e string err cannot store config e logger error this err e system err println err e print stack trace finishedinit storesync innerstore ioexception printstacktrace don t call without taking store sync first protected final void inner store throws io exception if finished init throw new illegal state exception should not happen simple field set fs export field set if logger should log logger minor this logger minor this fs fs file output stream fos null try fos new file output stream temp filename synchronized this fs write to fos file util rename to temp filename filename finally closer close fos storesync innerstore ioexception finishedinit illegalstateexception simplefieldset exportfieldset shouldlog fileoutputstream fileoutputstream tempfilename writeto fileutil renameto tempfilename public class hex util private static boolean logdebug logger logger instance should log logger debug hex util class private hex util hexutil instanceshouldlog hexutil hexutil converts a byte array into a string of lower case hex chars param bs a byte array param off the index of the first byte to read param length the number of bytes to read return the string of hex chars public static final string bytes to hex byte bs int off int length if bs length off bs length off length throw new illegal argument exception string builder sb new string builder length 2 bytes to hex append bs off length sb return sb to string bytestohex illegalargumentexception stringbuilder stringbuilder bytestohexappend tostring public static final void bytes to hex append byte bs int off int length string builder sb if bs length off bs length off length throw new illegal argument exception sb ensure capacity sb length length 2 for int i off i off length i sb append character for digit bs i 4 0xf 16 sb append character for digit bs i 0xf 16 bytestohexappend stringbuilder illegalargumentexception ensurecapacity fordigit fordigit public static final string bytes to hex byte bs return bytes to hex bs 0 bs length bytestohex bytestohex public static final byte hex to bytes string s return hex to bytes s 0 hextobytes hextobytes public static final byte hex to bytes string s int off byte bs new byte off 1 s length 2 hex to bytes s bs off return bs hextobytes hextobytes converts a string of hex characters into an array of bytes param s a string of hex characters upper case or lower of even length param out a byte array of length at least s length 2 off param off the first byte to write of the array public static final void hex to bytes string s byte out int off throws number format exception index out of bounds exception int slen s length if slen 2 0 s 0 s if out length off slen 2 throw new index out of bounds exception output buffer too small for input out length off slen 2 safe to assume the string is even length byte b1 b2 for int i 0 i slen i 2 b1 byte character digit s char at i 16 b2 byte character digit s char at i 1 16 if b1 0 b2 0 throw new number format exception out off i 2 byte b1 4 b2 hextobytes numberformatexception indexoutofboundsexception indexoutofboundsexception charat charat numberformatexception pack the bits in ba into a byte param ba the bit set param size how many bits shall be taken into account starting from the lsb public final static byte bits to bytes bit set ba int size int bytes alloc count bytes for bits size byte b new byte bytes alloc string builder sb null if logdebug sb new string builder 8 bytes alloc todo should it be 2 8 bytes alloc here for int i 0 i b length i short s 0 for int j 0 j 8 j int idx i 8 j boolean val idx size 1 false ba get idx s val 1 j 0 if logdebug sb append val 1 0 if s 255 throw new illegal state exception wtf s s b i byte s if logdebug logger debug hex util class bytes bytes alloc returned from bits to bytes ba size bytes to hex b for sb to string return b bitset bitstobytes bitset bytesalloc countbytesforbits bytesalloc stringbuilder stringbuilder bytesalloc bytesalloc illegalstateexception hexutil bytesalloc bitstobytes bytestohex tostring pack the bits in ba into a byte then convert that to a hex string and return it public final static string bits to hex string bit set ba int size return bytes to hex bits to bytes ba size bitstohexstring bitset bytestohex bitstobytes return the number of bytes required to represent the bitset public static int count bytes for bits int size brackets matter here takes precedence over the rest return size 8 size 8 0 0 1 countbytesforbits read bits from a byte array into a bitset param b the byte to read from param ba the bitset to write to public static void bytes to bits byte b bit set ba int max size if logdebug logger debug hex util class bytes to bits bytes to hex b ba max size int x 0 for int i 0 i b length i for int j 0 j 8 j if x max size break int mask 1 j boolean value mask b i 0 ba set x value x bytestobits bitset maxsize hexutil bytestobits bytestohex maxsize maxsize read a hex string of bits and write it into a bitset param s hex string of the stored bits param ba the bitset to store the bits in param length the maximum number of bits to store public static void hex to bits string s bit set ba int length byte b hex to bytes s bytes to bits b ba length hextobits bitset hextobytes bytestobits write a reasonably short big integer to a stream param integer the big integer to write param out the stream to write it to public static void write big integer big integer integer data output stream out throws io exception if integer signum 1 dump negative big integer logger error true throw new illegal state exception negative big integer byte buf integer to byte array if buf length short max value throw new illegal state exception too long buf length out write short short buf length out write buf biginteger biginteger writebiginteger biginteger dataoutputstream ioexception biginteger illegalstateexception biginteger tobytearray max_value illegalstateexception writeshort read a reasonably short big integer from a data input stream param dis the stream to read from return a big integer public static big integer read big integer data input stream dis throws io exception short i dis read short if i 0 throw new io exception invalid big integer length i byte buf new byte i dis read fully buf return new big integer 1 buf biginteger datainputstream biginteger biginteger readbiginteger datainputstream ioexception readshort ioexception biginteger readfully biginteger turn a big integer into a hex string big integer to string 16 np es on sun jdk 1 4 2 05 the bugs in their big are getting seriously irritating public static string bi to hex big integer bi return bytes to hex bi to byte array biginteger biginteger tostring npes 2_05 bitohex biginteger bytestohex tobytearray public splitfile progress event int total blocks int succeed blocks int failed blocks int fatally failed blocks int min successful blocks boolean finalized total this total blocks total blocks this succeed blocks succeed blocks this failed blocks failed blocks this fatally failed blocks fatally failed blocks this min successful blocks min successful blocks this finalized total finalized total if logger should log logger minor this logger minor this created splitfile progress event total total blocks succeed succeed blocks failed failed blocks fatally fatally failed blocks min success min successful blocks finalized finalized total splitfileprogressevent totalblocks succeedblocks failedblocks fatallyfailedblocks minsuccessfulblocks finalizedtotal totalblocks totalblocks succeedblocks succeedblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks minsuccessfulblocks minsuccessfulblocks finalizedtotal finalizedtotal shouldlog splitfileprogressevent totalblocks succeedblocks failedblocks fatallyfailedblocks minsuccessfulblocks finalizedtotal public string get description string builder sb new string builder sb append completed if min successful blocks 0 succeed blocks 0 min successful blocks 1 if min successful blocks 0 if logger global get threshold logger minor logger error this min successful blocks 0 succeed blocks succeed blocks total blocks total blocks failed blocks failed blocks fatally failed blocks fatally failed blocks finalized total finalized total else logger error this min successful blocks 0 succeed blocks succeed blocks total blocks total blocks failed blocks failed blocks fatally failed blocks fatally failed blocks finalized total finalized total new exception debug else sb append 100 succeed blocks min successful blocks sb append sb append sb append succeed blocks sb append sb append min successful blocks sb append failed sb append failed blocks sb append fatally sb append fatally failed blocks sb append total sb append total blocks sb append sb append finalized total finalized total return sb to string getdescription stringbuilder stringbuilder minsuccessfulblocks succeedblocks minsuccessfulblocks minsuccessfulblocks globalgetthreshold minsuccessfulblocks succeedblocks succeedblocks totalblocks totalblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks finalizedtotal finalizedtotal minsuccessfulblocks succeedblocks succeedblocks totalblocks totalblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks finalizedtotal finalizedtotal succeedblocks minsuccessfulblocks succeedblocks minsuccessfulblocks failedblocks fatallyfailedblocks totalblocks finalizedtotal tostring public int get code return code getcode public void remove from object container container container delete this removefrom objectcontainer public uri generated message freeneturi uri string identifier boolean global this uri uri this identifier identifier this global global urigeneratedmessage override public simple field set get field set simple field set fs new simple field set true fs put single uri uri to string fs put single identifier identifier fs put global global return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle override public string get name return uri generated getname urigenerated override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message uri generated goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message urigenerated override public void remove from object container container container activate uri 5 uri remove from container container delete this removefrom objectcontainer removefrom public static long allocate byte bitmap int begin int end long obj bit size long hole bit size 0 for int i begin i end i int mask bitmap i 0xff if hole bit size first hole size mask obj bit size bitmap i byte 1 int obj bit size hole bit size 1 long pos long i 8 hole bit size if hole bit size 0 while hole bit size 8 0 bitmap i byte 0xff bitmap i 1 byte 1 int hole bit size 1 return pos else if bitmap max hole size mask obj bit size int hole bit offset max hole offset mask bitmap i byte 1 int obj bit size 1 hole bit offset return long i 8 hole bit offset else if last hole size mask 8 hole bit size 8 else hole bit size last hole size mask return 1 objbitsize holebitsize holebitsize firstholesize objbitsize objbitsize holebitsize holebitsize holebitsize holebitsize holebitsize maxholesize objbitsize holebitoffset maxholeoffset objbitsize holebitoffset holebitoffset lastholesize holebitsize holebitsize lastholesize public static int locate bitmap end byte bitmap int offs while offs 0 bitmap offs 0 return offs locatebitmapend public static int locate hole end byte bitmap int offs while offs bitmap length bitmap offs 1 return offs bitmap length offs bitmap length locateholeend public static void free byte bitmap long obj bit pos long obj bit size int bit offs int obj bit pos 7 int offs int obj bit pos 3 if obj bit size 8 bit offs obj bit size 8 bit offs bitmap offs 1 bit offs 1 while obj bit size 8 0 bitmap offs byte 0 bitmap offs byte 1 int obj bit size 8 1 else bitmap offs byte 1 int obj bit size 1 bit offs objbitpos objbitsize bitoffs objbitpos objbitpos objbitsize bitoffs objbitsize bitoffs bitoffs objbitsize objbitsize objbitsize bitoffs public static void reserve byte bitmap long obj bit pos long obj bit size while obj bit size 0 bitmap int obj bit pos 3 1 int obj bit pos 7 obj bit pos 1 objbitpos objbitsize objbitsize objbitpos objbitpos objbitpos protected final boolean reversed comparator by status string sort by boolean reversed this sort by sort by this reversed reversed comparatorbystatus sortby sortby sortby public int compare peer node status first node peer node status second node int result 0 boolean is set true if sort by null result custom compare first node second node sort by is set result 0 else is set false if is set int status difference first node get status value second node get status value if status difference 0 result status difference 0 1 1 else result last resort compare first node second node if result 0 return 0 else if reversed is reversed true return result 0 1 1 else is reversed false return result 0 1 1 peernodestatus firstnode peernodestatus secondnode isset sortby customcompare firstnode secondnode sortby isset isset isset statusdifference firstnode getstatusvalue secondnode getstatusvalue statusdifference statusdifference lastresortcompare firstnode secondnode isreversed isreversed j16sdiz long max value 1 would overflow and become negative private int compare longs long long1 long long2 int diff long value of long1 compare to long2 if diff 0 return 0 else return diff 0 1 1 max_value comparelongs valueof compareto private int compare ints int int1 int int2 int diff integer value of int1 compare to int2 if diff 0 return 0 else return diff 0 1 1 compareints valueof compareto protected int custom compare peer node status first node peer node status second node string sort by2 if sort by equals address return first node get peer address compare to ignore case second node get peer address else if sort by equals location return compare locations first node second node else if sort by equals version return version get arbitrary build number first node get version 1 version get arbitrary build number second node get version 1 else if sort by equals backoff return double compare first node get backed off percent second node get backed off percent else if sort by equals overload p return double compare first node getp reject second node getp reject else if sort by equals idle return compare longs first node get time last connection completed second node get time last connection completed else if sort by equals time routable return double compare first node get percent time routable connection second node get percent time routable connection else if sort by equals total traffic long total1 first node get total input bytes first node get total output bytes long total2 second node get total input bytes second node get total output bytes return compare longs total1 total2 else if sort by equals total traffic since startup long total1 first node get total input since startup first node get total output since startup long total2 second node get total input since startup second node get total output since startup return compare longs total1 total2 else if sort by equals selection percentage return double compare first node get selection rate second node get selection rate else if sort by equals time delta return compare longs first node get clock delta second node get clock delta else if sort by equals uptime return compare ints first node get reported uptime percentage second node get reported uptime percentage else return 0 customcompare peernodestatus firstnode peernodestatus secondnode sortby2 sortby firstnode getpeeraddress comparetoignorecase secondnode getpeeraddress sortby comparelocations firstnode secondnode sortby getarbitrarybuildnumber firstnode getversion getarbitrarybuildnumber secondnode getversion sortby firstnode getbackedoffpercent secondnode getbackedoffpercent sortby overload_p firstnode getpreject secondnode getpreject sortby comparelongs firstnode gettimelastconnectioncompleted secondnode gettimelastconnectioncompleted sortby time_routable firstnode getpercenttimeroutableconnection secondnode getpercenttimeroutableconnection sortby total_traffic firstnode gettotalinputbytes firstnode gettotaloutputbytes secondnode gettotalinputbytes secondnode gettotaloutputbytes comparelongs sortby total_traffic_since_startup firstnode gettotalinputsincestartup firstnode gettotaloutputsincestartup secondnode gettotalinputsincestartup secondnode gettotaloutputsincestartup comparelongs sortby selection_percentage firstnode getselectionrate secondnode getselectionrate sortby time_delta comparelongs firstnode getclockdelta secondnode getclockdelta sortby compareints firstnode getreporteduptimepercentage secondnode getreporteduptimepercentage private int compare locations peer node status first node peer node status second node double diff first node get location second node get location can occasionally be the same and we must have a consistent sort order if double min value 2 math abs diff return 0 return diff 0 1 1 comparelocations peernodestatus firstnode peernodestatus secondnode firstnode getlocation secondnode getlocation min_value default comparison after taking into account status protected int last resort compare peer node status first node peer node status second node return compare locations first node second node lastresortcompare peernodestatus firstnode peernodestatus secondnode comparelocations firstnode secondnode override public string supported methods if this accept ref posts return get post else return get supportedmethods acceptrefposts protected connections toadlet node n node client core core high level simple client client super client this node n this core core this stats n node stats this peers n peers connectionstoadlet nodeclientcore highlevelsimpleclient nodestats abstract simple column end column headers boolean advanced mode enabled simplecolumn endcolumnheaders advancedmodeenabled abstract class simple column abstract protected void draw column html node peer row peer node status peer node status simplecolumn drawcolumn htmlnode peerrow peernodestatus peernodestatus abstract class simple column abstract protected void draw column html node peer row peer node status peer node status abstract public string get sort string simplecolumn drawcolumn htmlnode peerrow peernodestatus peernodestatus getsortstring abstract protected void draw column html node peer row peer node status peer node status abstract public string get sort string abstract public string get title key drawcolumn htmlnode peerrow peernodestatus peernodestatus getsortstring gettitlekey abstract public string get sort string abstract public string get title key abstract public string get explanation key getsortstring gettitlekey getexplanationkey override public void handle get uri uri final http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception string path uri get path if path ends with myref fref simple field set fs get noderef string writer sw new string writer fs write to sw multi value table string string extra headers new multi value table string string force download to disk extra headers put content disposition attachment filename myref fref this write reply ctx 200 application x freenet reference ok extra headers sw to string return if path ends with myref txt simple field set fs get noderef string writer sw new string writer fs write to sw this write text reply ctx 200 ok sw to string return if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return final boolean f proxy javascript enabled node isf proxy javascript enabled boolean draw message types path ends with displaymessagetypes html gather connection statistics peer node status peer node statuses get peer node statuses draw message types arrays sort peer node statuses comparator request get param sort by null request is parameter set reversed int number of connected peer node status get peer status count peer node statuses peer manager peer node status connected int number of routing backed off peer node status get peer status count peer node statuses peer manager peer node status routing backed off int number of too new peer node status get peer status count peer node statuses peer manager peer node status too new int number of too old peer node status get peer status count peer node statuses peer manager peer node status too old int number of disconnected peer node status get peer status count peer node statuses peer manager peer node status disconnected int number of never connected peer node status get peer status count peer node statuses peer manager peer node status never connected int number of disabled peer node status get peer status count peer node statuses peer manager peer node status disabled int number of bursting peer node status get peer status count peer node statuses peer manager peer node status bursting int number of listening peer node status get peer status count peer node statuses peer manager peer node status listening int number of listen only peer node status get peer status count peer node statuses peer manager peer node status listen only int number of clock problem peer node status get peer status count peer node statuses peer manager peer node status clock problem int number of conn error peer node status get peer status count peer node statuses peer manager peer node status conn error int number of disconnecting peer node status get peer status count peer node statuses peer manager peer node status disconnecting int number of routing disabled peer node status get peer status count peer node statuses peer manager peer node status routing disabled int number of simple connected number of connected number of routing backed off int number of not connected number of too new number of too old number of disconnected number of never connected number of disabled number of bursting number of listening number of listen only number of clock problem number of conn error string title count string null if node is advanced mode enabled title count string number of connected number of routing backed off number of too new number of too old number of routing disabled number of not connected else title count string number of not connected number of simple connected 0 string value of number of simple connected html node page node ctx get page maker get page node get page title title count string node get my name ctx html node content node ctx get page maker get content node page node fixme we need some nice images long now system current time millis if ctx is allowed full access content node add child core alerts create summary final int mode ctx get page maker draw mode selection array core request content node if peer node statuses length 0 node status values long node uptime seconds now node startup time 1000 int bwlimit delay time int stats get bwlimit delay time int node average ping time int stats get node average ping time int network size estimate session stats get darknet size estimate 1 int network size estimate recent 0 if node uptime seconds 48 60 60 48 hours network size estimate recent stats get darknet size estimate now 48 60 60 1000 48 hours decimal format fix4 new decimal format 0 0000 double routing miss distance stats routing miss distance current value double backed off percent stats backed off percent current value string node uptime string time util format time node uptime seconds 1000 1000 to convert to milliseconds begin overview table html node overview table content node add child table class column html node overview table row overview table add child tr html node next table cell overview table row add child td class first node status overview box if mode page maker mode advanced html node overview infobox next table cell add child div class infobox overview infobox add child div class infobox header node status overview html node overview infobox content overview infobox add child div class infobox content html node overview list overview infobox content add child ul overview list add child li bwlimit delay time u00a0 bwlimit delay time ms overview list add child li node average ping time u00a0 node average ping time ms overview list add child li darknet size estimate session u00a0 network size estimate session u00a0nodes if node uptime seconds 48 60 60 48 hours overview list add child li darknet size estimate recent u00a0 network size estimate recent u00a0nodes overview list add child li node uptime u00a0 node uptime string overview list add child li routing miss distance u00a0 fix4 format routing miss distance overview list add child li backed off percent u00a0 fix1 format backed off percent overview list add child li p instant reject u00a0 fix1 format stats p reject incoming instantly next table cell overview table row add child td activity box int numark fetchers node get numark fetchers html node activity infobox next table cell add child div class infobox activity infobox add child div class infobox header l10n activity title html node activity infobox content activity infobox add child div class infobox content html node activity list statistics toadlet draw activity activity infobox content node if mode page maker mode advanced activity list null if numark fetchers 0 activity list add child li ark u00a0 fetch u00a0 requests u00a0 numark fetchers statistics toadlet draw bandwidth activity list node node uptime seconds mode page maker mode advanced next table cell mode page maker mode advanced overview table row add child td overview table row add child td class last peer statistics box html node peer stats infobox next table cell add child div class infobox statistics toadlet draw peer stats box peer stats infobox mode page maker mode advanced number of connected number of routing backed off number of too new number of too old number of disconnected number of never connected number of disabled number of bursting number of listening number of listen only 0 0 number of routing disabled number of clock problem number of conn error number of disconnecting peer routing backoff reason box if mode page maker mode advanced next table cell overview table row add child td class last html node backoff reason infobox next table cell add child div class infobox backoff reason infobox add child div class infobox header peer backoff reasons html node backoff reason content backoff reason infobox add child div class infobox content string routing backoff reasons peers get peer node routing backoff reasons if routing backoff reasons length 0 backoff reason content add child good your node is not backed off from any peers else html node reason list backoff reason content add child ul for int i 0 i routing backoff reasons length i int reason count peers get peer node routing backoff reason size routing backoff reasons i if reason count 0 reason list add child li routing backoff reasons i u00a0 reason count end overview table boolean enable peer actions show peer actions box begin peer table if f proxy javascript enabled string builder js buf new string builder fixme there s probably some icky javascript in here this is the first thing that worked for me feel free to fix up to javascript guru standards js buf append function peer note change n js buf append var theobj document get element by id action n js buf append var length theobj options length n js buf append for var i 0 i length i n js buf append if theobj options i update notes n js buf append theobj options i select true n js buf append else n js buf append theobj options i select false n js buf append n js buf append n js buf append theobj value update handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception getpath endswith simplefieldset getnoderef stringwriter stringwriter writeto multivaluetable extraheaders multivaluetable extraheaders writereply extraheaders tostring endswith simplefieldset getnoderef stringwriter stringwriter writeto writetextreply tostring isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring fproxyjavascriptenabled isfproxyjavascriptenabled drawmessagetypes endswith peernodestatus peernodestatuses getpeernodestatuses drawmessagetypes peernodestatuses getparam sortby isparameterset numberofconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_connected numberofroutingbackedoff peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_backed_off numberoftoonew peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_too_new numberoftooold peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_too_old numberofdisconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnected numberofneverconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_never_connected numberofdisabled peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disabled numberofbursting peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_bursting numberoflistening peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_listening numberoflistenonly peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_listen_only numberofclockproblem peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_clock_problem numberofconnerror peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_conn_error numberofdisconnecting peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnecting numberofroutingdisabled peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_disabled numberofsimpleconnected numberofconnected numberofroutingbackedoff numberofnotconnected numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofclockproblem numberofconnerror titlecountstring isadvancedmodeenabled titlecountstring numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofroutingdisabled numberofnotconnected titlecountstring numberofnotconnected numberofsimpleconnected valueof numberofsimpleconnected htmlnode pagenode getpagemaker getpagenode getpagetitle titlecountstring getmyname htmlnode contentnode getpagemaker getcontentnode pagenode currenttimemillis isallowedfullaccess contentnode addchild createsummary getpagemaker drawmodeselectionarray contentnode peernodestatuses nodeuptimeseconds startuptime bwlimitdelaytime getbwlimitdelaytime nodeaveragepingtime getnodeaveragepingtime networksizeestimatesession getdarknetsizeestimate networksizeestimaterecent nodeuptimeseconds networksizeestimaterecent getdarknetsizeestimate decimalformat decimalformat routingmissdistance routingmissdistance currentvalue backedoffpercent backedoffpercent currentvalue nodeuptimestring timeutil formattime nodeuptimeseconds htmlnode overviewtable contentnode addchild htmlnode overviewtablerow overviewtable addchild htmlnode nexttablecell overviewtablerow addchild pagemaker mode_advanced htmlnode overviewinfobox nexttablecell addchild overviewinfobox addchild htmlnode overviewinfoboxcontent overviewinfobox addchild htmlnode overviewlist overviewinfoboxcontent addchild overviewlist addchild bwlimitdelaytime bwlimitdelaytime overviewlist addchild nodeaveragepingtime nodeaveragepingtime overviewlist addchild darknetsizeestimatesession networksizeestimatesession nodeuptimeseconds overviewlist addchild darknetsizeestimaterecent networksizeestimaterecent overviewlist addchild nodeuptime nodeuptimestring overviewlist addchild routingmissdistance routingmissdistance overviewlist addchild backedoffpercent backedoffpercent overviewlist addchild pinstantreject prejectincominginstantly nexttablecell overviewtablerow addchild numarkfetchers getnumarkfetchers htmlnode activityinfobox nexttablecell addchild activityinfobox addchild activitytitle htmlnode activityinfoboxcontent activityinfobox addchild htmlnode activitylist statisticstoadlet drawactivity activityinfoboxcontent pagemaker mode_advanced activitylist numarkfetchers activitylist addchild u00a0fetch u00a0requests numarkfetchers statisticstoadlet drawbandwidth activitylist nodeuptimeseconds pagemaker mode_advanced nexttablecell pagemaker mode_advanced overviewtablerow addchild overviewtablerow addchild htmlnode peerstatsinfobox nexttablecell addchild statisticstoadlet drawpeerstatsbox peerstatsinfobox pagemaker mode_advanced numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofroutingdisabled numberofclockproblem numberofconnerror numberofdisconnecting pagemaker mode_advanced nexttablecell overviewtablerow addchild htmlnode backoffreasoninfobox nexttablecell addchild backoffreasoninfobox addchild htmlnode backoffreasoncontent backoffreasoninfobox addchild routingbackoffreasons getpeernoderoutingbackoffreasons routingbackoffreasons backoffreasoncontent addchild htmlnode reasonlist backoffreasoncontent addchild routingbackoffreasons reasoncount getpeernoderoutingbackoffreasonsize routingbackoffreasons reasoncount reasonlist addchild routingbackoffreasons reasoncount enablepeeractions showpeeractionsbox fproxyjavascriptenabled stringbuilder jsbuf stringbuilder jsbuf peernotechange jsbuf getelementbyid jsbuf jsbuf jsbuf update_notes jsbuf jsbuf jsbuf jsbuf jsbuf jsbuf update_ protected abstract boolean accept ref posts acceptrefposts protected abstract boolean accept ref posts where to redirect to if there is an error protected abstract string default redirect location acceptrefposts defaultredirectlocation override public void handle post uri uri final http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception boolean logminor logger should log logger minor this if accept ref posts super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return string pass request get part as string form password 32 if pass null pass equals core form password multi value table string string headers new multi value table string string headers put location default redirect location ctx send reply headers 302 found headers null 0 if logminor logger minor this no password pass should be core form password return if request is part set add add a new node string urltext request get part as string url 200 urltext urltext trim string reftext request get part as string ref integer max value reftext reftext trim if reftext length 200 reftext request get part as string reffile integer max value reftext reftext trim string private comment null if is opennet private comment request get part as string peer private note 250 trim string builder ref new string builder 1024 if urltext length 0 fetch reference from a url buffered reader in null try url url new url urltext url connection uc url open connection fixme get charset encoding from uc get content type in new buffered reader new input stream reader uc get input stream string line while line in read line null ref append line append n catch io exception e this send error page ctx 200 l10n failed to add node title l10n get string darknet connections toadlet cant fetch noderefurl new string url new string urltext return finally if in null in close else if reftext length 0 read from post data or file upload this slightly scary looking regexp chops any extra characters off the beginning or ends of lines and removes extra line breaks ref new string builder reftext replace all w r n end t r n 1 n else this send error page ctx 200 l10n failed to add node title l10n no ref orurl request free parts return ref new string builder ref to string trim request free parts split the references string because the peers are added individually string nodes to add ref to string split end the peer s additions results map peer addition return codes integer results new hash map peer addition return codes integer for int i 0 i nodes to add length i we need to trim then concat end to the node s reference this way we have a normal reference the split removes the end s peer addition return codes result add new node nodes to add i trim concat n end private comment store the result if results contains key result false results put result integer value of 0 results put result results get result 1 html node page node ctx get page maker get page node l10n report of node addition ctx html node content node ctx get page maker get content node page node we create a table to show the results html node detailed status box new html node table header of the table detailed status box add child new html node tr add children new html node new html node th l10n result name new html node th l10n num of results html node status box table detailed status box add child new html node tbody iterate through the return codes for peer addition return codes return code peer addition return codes values if results contains key return code add a tr and 2 td with the name of the code and the number of occasions it happened if the code is ok we use green red elsewhere status box table add child new html node tr style color return code peer addition return codes ok green red add children new html node new html node td l10n peer addition code return code to string new html node td results get return code to string html node infobox content node add child ctx get page maker get infobox infobox l10n report of node addition html node infobox content ctx get page maker get content node infobox infobox content add child detailed status box infobox content add child br infobox content add child a href l10n return to prev page infobox content add child br add homepage link infobox content writehtml reply ctx 500 l10n report of node addition page node generate multi value table string string headers new multi value table string string headers put location default redirect location ctx send reply headers 302 found headers null 0 return else handle alt post uri request ctx logminor handlepost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception shouldlog acceptrefposts senderrorpage getstring isallowedfullaccess senderrorpage getstring getpartasstring formpassword formpassword multivaluetable multivaluetable defaultredirectlocation sendreplyheaders formpassword ispartset getpartasstring getpartasstring max_value getpartasstring max_value privatecomment isopennet privatecomment getpartasstring peerprivatenote stringbuilder stringbuilder bufferedreader urlconnection openconnection getcontenttype bufferedreader inputstreamreader getinputstream readline ioexception senderrorpage failedtoaddnodetitle getstring darknetconnectionstoadlet cantfetchnoderefurl stringbuilder replaceall senderrorpage failedtoaddnodetitle noreforurl freeparts stringbuilder tostring freeparts nodestoadd tostring peeradditionreturncodes hashmap peeradditionreturncodes nodestoadd peeradditionreturncodes addnewnode nodestoadd nend privatecomment containskey valueof htmlnode pagenode getpagemaker getpagenode reportofnodeaddition htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode detailedstatusbox htmlnode detailedstatusbox addchild htmlnode addchildren htmlnode htmlnode resultname htmlnode numofresults htmlnode statusboxtable detailedstatusbox addchild htmlnode peeradditionreturncodes returncode peeradditionreturncodes containskey returncode statusboxtable addchild htmlnode returncode peeradditionreturncodes addchildren htmlnode htmlnode peeradditioncode returncode tostring htmlnode returncode tostring htmlnode contentnode addchild getpagemaker getinfobox reportofnodeaddition htmlnode infoboxcontent getpagemaker getcontentnode infoboxcontent addchild detailedstatusbox infoboxcontent addchild infoboxcontent addchild returntoprevpage infoboxcontent addchild addhomepagelink infoboxcontent writehtmlreply reportofnodeaddition pagenode multivaluetable multivaluetable defaultredirectlocation sendreplyheaders handlealtpost adds a new node if any error arises it returns the appropriate return code param node reference the reference to the new node param private comment the private comment when adding a darknet node return the result of the addition private peer addition return codes add new node string node reference string private comment simple field set fs try fs new simple field set node reference to string false true if fs get end marker ends with end return peer addition return codes wrong encoding fs set end marker end it s always end the regex above doesn t always grok this catch io exception e return peer addition return codes cant parse catch throwable t return peer addition return codes internal error peer node pn try if is opennet pn node create new opennet node fs else pn node create new darknet node fs darknet peer node pn set private darknet comment note private comment catch fs parse exception e1 return peer addition return codes cant parse catch peer parse exception e1 return peer addition return codes cant parse catch reference signature verification exception e1 return peer addition return codes invalid signature catch throwable t return peer addition return codes internal error if arrays equals pn get identity node get darknet identity return peer addition return codes try to add self if this node add peer connection pn return peer addition return codes already in reference return peer addition return codes ok nodereference privatecomment peeradditionreturncodes addnewnode nodereference privatecomment simplefieldset simplefieldset nodereference tostring getendmarker endswith peeradditionreturncodes wrong_encoding setendmarker ioexception peeradditionreturncodes cant_parse peeradditionreturncodes internal_error peernode isopennet createnewopennetnode createnewdarknetnode darknetpeernode setprivatedarknetcommentnote privatecomment fsparseexception peeradditionreturncodes cant_parse peerparseexception peeradditionreturncodes cant_parse referencesignatureverificationexception peeradditionreturncodes invalid_signature peeradditionreturncodes internal_error getidentity getdarknetidentity peeradditionreturncodes try_to_add_self addpeerconnection peeradditionreturncodes already_in_reference peeradditionreturncodes adding a darknet node or an opennet node protected abstract boolean is opennet isopennet rest of handle post method supplied by subclass throws io exception throws toadlet context closed exception throws redirect exception protected void handle alt post uri uri http request request toadlet context ctx boolean logminor throws toadlet context closed exception io exception redirect exception do nothing we only support adding nodes handle get uri new http request impl uri ctx handlepost ioexception toadletcontextclosedexception redirectexception handlealtpost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception handleget httprequestimpl what should the heading before more detailed be on the peers table protected abstract string get peer list title getpeerlisttitle protected abstract string get peer list title should there be a checkbox for each peer and draw peer action select box be called directly after drawing the peers list protected abstract boolean show peer actions box getpeerlisttitle drawpeeractionselectbox showpeeractionsbox if show peer actions box is true this will be called directly after drawing the peers table a form has been added and checkboxes added for each peer this function should draw the rest of the form any additional controls and one or more submit buttons showpeeractionsbox protected abstract void draw peer action select box html node peer form boolean advanced mode enabled protected abstract boolean should draw noderef box boolean advanced mode enabled drawpeeractionselectbox htmlnode peerform advancedmodeenabled shoulddrawnoderefbox advancedmodeenabled private void draw noderef box html node content node toadlet context ctx html node reference infobox content node add child div class infobox infobox normal html node header reference infobox reference infobox add child div class infobox header fixme better way to deal with this sort of thing l10n addl10n substitution header reference infobox darknet connections toadlet my reference header new string linkref linkref linktext linktext new string a href myref fref a a href myref txt a html node reference infobox content reference infobox add child div class infobox content html node warning sentence reference infobox content add child p l10n addl10n substitution warning sentence darknet connections toadlet reference copy warning new string bold bold new string b b reference infobox content add child pre id reference get noderef to string n drawnoderefbox htmlnode contentnode toadletcontext htmlnode referenceinfobox contentnode addchild htmlnode headerreferenceinfobox referenceinfobox addchild addl10nsubstitution headerreferenceinfobox darknetconnectionstoadlet myreferenceheader htmlnode referenceinfoboxcontent referenceinfobox addchild htmlnode warningsentence referenceinfoboxcontent addchild addl10nsubstitution warningsentence darknetconnectionstoadlet referencecopywarning referenceinfoboxcontent addchild getnoderef tostring protected abstract string get page title string title count string string my name getpagetitle titlecountstring myname draw the add a peer box this comes immediately after the main peers table and before the noderef box implementors may skip it by not doing anything in this method protected void draw add peer box html node content node toadlet context ctx begin peer addition box html node peer addition infobox content node add child div class infobox infobox normal peer addition infobox add child div class infobox header l10n add peer title html node peer addition content peer addition infobox add child div class infobox content html node peer addition form ctx add form child peer addition content add peer form peer addition form add child l10n paste reference peer addition form add child br peer addition form add child textarea new string id name rows cols new string reftext ref 8 74 peer addition form add child br peer addition form add child l10n url reference peer addition form add child input new string id type name new string refurl text url peer addition form add child br peer addition form add child l10n file reference peer addition form add child input new string id type name new string reffile file reffile peer addition form add child br if is opennet peer addition form add child l10n enter description peer addition form add child input new string id type name size maxlength value new string peer private note text peer private note 16 250 peer addition form add child br peer addition form add child input new string type name value new string submit add l10n add drawaddpeerbox htmlnode contentnode toadletcontext htmlnode peeradditioninfobox contentnode addchild peeradditioninfobox addchild addpeertitle htmlnode peeradditioncontent peeradditioninfobox addchild htmlnode peeradditionform addformchild peeradditioncontent addpeerform peeradditionform addchild pastereference peeradditionform addchild peeradditionform addchild peeradditionform addchild peeradditionform addchild urlreference peeradditionform addchild peeradditionform addchild peeradditionform addchild filereference peeradditionform addchild peeradditionform addchild isopennet peeradditionform addchild enterdescription peeradditionform addchild peerprivatenote peerprivatenote peeradditionform addchild peeradditionform addchild protected comparator peer node status comparator string sort by boolean reversed return new comparator by status sort by reversed peernodestatus sortby comparatorbystatus sortby abstract protected peer node status get peer node statuses boolean no heavy peernodestatus getpeernodestatuses noheavy abstract protected peer node status get peer node statuses boolean no heavy abstract protected simple field set get noderef peernodestatus getpeernodestatuses noheavy simplefieldset getnoderef private void draw row html node peer table peer node status peer node status boolean advanced mode enabled boolean f proxy javascript enabled long now string path boolean enable peer actions simple column end cols boolean draw message types double total selection rate double selection rate peer node status get selection rate int peer selection percentage 0 if total selection rate 0 peer selection percentage int selection rate 100 total selection rate html node peer row peer table add child tr class darknet connections peer selection percentage peer node selection percentage warning warning normal if enable peer actions check box column peer row add child td class peer marker add child input new string type name new string checkbox node peer node status hash code status column string status string peer node status get status name if advanced mode enabled peer node status get status value peer manager peer node status routing backed off status string busy peer row add child td class peer status add child span class peer node status get statuscss name l10n get string connections toadlet node status status string peer node status is fetchingark draw name column peer row peer node status address column if advanced mode enabled string ping time if peer node status is connected ping time int peer node status get average ping time ms peer row add child td class peer address add child peer node status get peer address null peer node status get peer address peer node status get peer port l10n unknown address ping time version column if peer node status get status value peer manager peer node status never connected peer node status is public invalid version peer node status is public reverse invalid version don t draw attention to a version problem if never connected peer row add child td class peer version add child span class peer version problem integer to string peer node status get simple version else peer row add child td class peer version add child integer to string peer node status get simple version location column if advanced mode enabled html node location node peer row add child td class peer location location node add child b string value of peer node status get location location node add child br double peers loc peer node status get peers location if peers loc null for double loc peers loc location node add child i string value of loc add child br if advanced mode enabled backoff column html node backoff cell peer row add child td class peer backoff backoff cell add child fix1 format peer node status get backed off percent int backoff int math max peer node status get routing backed off until now 0 don t list the backoff as zero before it s actually zero if backoff 0 backoff 1000 backoff 1000 backoff cell add child string value of backoff 1000 string value of peer node status get routing backoff length 1000 backoff cell add child peer node status get last backoff reason null peer node status get last backoff reason overload probability column html node p reject cell peer row add child td class peer backoff fixme p reject cell add child fix1 format peer node status getp reject idle column long idle peer node status get time last routable if peer node status is routable idle peer node status get time last connection completed else if peer node status get status value peer manager peer node status never connected idle peer node status get peer added time if peer node status is connected now idle 2 7 24 60 60 long 1000 2 weeks peer row add child td class peer idle add child span class peer idle old idle to string now idle else peer row add child td class peer idle idle to string now idle if has private note column draw private note column peer row peer node status f proxy javascript enabled if advanced mode enabled percent of time connected column peer row add child td class peer idle fixme add child fix1 format peer node status get percent time routable connection selection stats peer row add child td class peer idle fixme add child total selection rate 0 peer selection percentage n a total traffic column peer row add child td class peer idle fixme add child size util format size peer node status get total input bytes size util format size peer node status get total output bytes size util format size peer node status get resend bytes sent total traffic column startup peer row add child td class peer idle fixme add child size util format size peer node status get total input since startup size util format size peer node status get total output since startup congestion control packet throttle t peer node status get throttle string val if t null val none else val int 1000 0 t get delay 1024 0 b sec delay t get delay ms rtt t get round trip time ms window t get window size peer row add child td class peer idle fixme add child val time delta peer row add child td class peer idle fixme add child time util format time peer node status get clock delta peer row add child td class peer idle fixme add child peer node status get reported uptime percentage if end cols null for int i 0 i end cols length i end cols i draw column peer row peer node status if draw message types draw message types peer table peer node status drawrow htmlnode peertable peernodestatus peernodestatus advancedmodeenabled fproxyjavascriptenabled enablepeeractions simplecolumn endcols drawmessagetypes totalselectionrate selectionrate peernodestatus getselectionrate peerselectionpercentage totalselectionrate peerselectionpercentage selectionrate totalselectionrate htmlnode peerrow peertable addchild darknet_connections_ peerselectionpercentage peernode selection_percentage_warning enablepeeractions peerrow addchild addchild node_ peernodestatus hashcode statusstring peernodestatus getstatusname advancedmodeenabled peernodestatus getstatusvalue peermanager peer_node_status_routing_backed_off statusstring peerrow addchild addchild peernodestatus getstatuscssname getstring connectionstoadlet nodestatus statusstring peernodestatus isfetchingark drawnamecolumn peerrow peernodestatus advancedmodeenabled pingtime peernodestatus isconnected pingtime peernodestatus getaveragepingtime peerrow addchild addchild peernodestatus getpeeraddress peernodestatus getpeeraddress peernodestatus getpeerport unknownaddress pingtime peernodestatus getstatusvalue peermanager peer_node_status_never_connected peernodestatus ispublicinvalidversion peernodestatus ispublicreverseinvalidversion peerrow addchild addchild peer_version_problem tostring peernodestatus getsimpleversion peerrow addchild addchild tostring peernodestatus getsimpleversion advancedmodeenabled htmlnode locationnode peerrow addchild locationnode addchild valueof peernodestatus getlocation locationnode addchild peersloc peernodestatus getpeerslocation peersloc peersloc locationnode addchild valueof addchild advancedmodeenabled htmlnode backoffcell peerrow addchild backoffcell addchild peernodestatus getbackedoffpercent peernodestatus getroutingbackedoffuntil backoffcell addchild valueof valueof peernodestatus getroutingbackofflength backoffcell addchild peernodestatus getlastbackoffreason peernodestatus getlastbackoffreason htmlnode prejectcell peerrow addchild prejectcell addchild peernodestatus getpreject peernodestatus gettimelastroutable peernodestatus isroutable peernodestatus gettimelastconnectioncompleted peernodestatus getstatusvalue peermanager peer_node_status_never_connected peernodestatus getpeeraddedtime peernodestatus isconnected peerrow addchild addchild peer_idle_old idletostring peerrow addchild idletostring hasprivatenotecolumn drawprivatenotecolumn peerrow peernodestatus fproxyjavascriptenabled advancedmodeenabled peerrow addchild addchild peernodestatus getpercenttimeroutableconnection peerrow addchild addchild totalselectionrate peerselectionpercentage peerrow addchild addchild sizeutil formatsize peernodestatus gettotalinputbytes sizeutil formatsize peernodestatus gettotaloutputbytes sizeutil formatsize peernodestatus getresendbytessent peerrow addchild addchild sizeutil formatsize peernodestatus gettotalinputsincestartup sizeutil formatsize peernodestatus gettotaloutputsincestartup packetthrottle peernodestatus getthrottle getdelay getdelay getroundtriptime getwindowsize peerrow addchild addchild peerrow addchild addchild timeutil formattime peernodestatus getclockdelta peerrow addchild addchild peernodestatus getreporteduptimepercentage endcols endcols endcols drawcolumn peerrow peernodestatus drawmessagetypes drawmessagetypes peertable peernodestatus is there a name column abstract protected boolean has name column hasnamecolumn abstract protected boolean has name column draw the name column if there is one this will be directly after the status column abstract protected void draw name column html node peer row peer node status peer node status hasnamecolumn drawnamecolumn htmlnode peerrow peernodestatus peernodestatus abstract protected void draw name column html node peer row peer node status peer node status is there a private note column abstract protected boolean has private note column drawnamecolumn htmlnode peerrow peernodestatus peernodestatus hasprivatenotecolumn abstract protected boolean has private note column draw the private note column abstract protected void draw private note column html node peer row peer node status peer node status boolean f proxy javascript enabled hasprivatenotecolumn drawprivatenotecolumn htmlnode peerrow peernodestatus peernodestatus fproxyjavascriptenabled private void draw message types html node peer table peer node status peer node status html node message count row peer table add child tr class message status message count row add child td colspan 2 html node message count cell message count row add child td colspan 9 total table row width 2 from above colspan html node message count table message count cell add child table class message count html node count header row message count table add child tr count header row add child th message count header row add child th incoming count header row add child th outgoing list string message names new array list string map string long message counts new hash map string long for map entry string long entry peer node status get local messages received entry set string message name entry get key long message count entry get value message names add message name message counts put message name new long message count long value of 0 for map entry string long entry peer node status get local messages sent entry set string message name entry get key long message count entry get value if message names contains message name message names add message name long existing counts message counts get message name if existing counts null message counts put message name new long long value of 0 message count else existing counts 1 message count collections sort message names new comparator string public int compare string first string second return first compare to ignore case second for iterator string message names iterator message names iterator message names iterator has next string message name message names iterator next long message count message counts get message name html node message row message count table add child tr message row add child td message name message row add child td class right align string value of message count 0 message row add child td class right align string value of message count 1 drawmessagetypes htmlnode peertable peernodestatus peernodestatus htmlnode messagecountrow peertable addchild messagecountrow addchild htmlnode messagecountcell messagecountrow addchild htmlnode messagecounttable messagecountcell addchild htmlnode countheaderrow messagecounttable addchild countheaderrow addchild countheaderrow addchild countheaderrow addchild messagenames arraylist messagecounts hashmap peernodestatus getlocalmessagesreceived entryset messagename getkey messagecount getvalue messagenames messagename messagecounts messagename messagecount valueof peernodestatus getlocalmessagessent entryset messagename getkey messagecount getvalue messagenames messagename messagenames messagename existingcounts messagecounts messagename existingcounts messagecounts messagename valueof messagecount existingcounts messagecount messagenames comparetoignorecase messagenamesiterator messagenames messagenamesiterator hasnext messagename messagenamesiterator messagecount messagecounts messagename htmlnode messagerow messagecounttable addchild messagerow addchild messagename messagerow addchild valueof messagecount messagerow addchild valueof messagecount collections sort message names new comparator string public int compare string first string second return first compare to ignore case second messagenames comparetoignorecase private string idle to string long now long idle if idle 0 return long idle milliseconds now idle return time util format time idle milliseconds idletostring idlemilliseconds timeutil formattime idlemilliseconds private static string l10n string string return l10n get string darknet connections toadlet string getstring darknetconnectionstoadlet private string sort string boolean is reversed string type return is reversed sort by type sort by type reversed sortstring isreversed isreversed sortby sortby public final class pin light composite extends rgb composite public pin light composite float alpha super alpha pinlightcomposite rgbcomposite pinlightcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor sr 127 math max sr dir math min sr dir dog sg 127 math max sg dig math min sg dig dob sb 127 math max sb dib math min sb dib float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public symlinker toadlet high level simple client client final node node super client this node node tslconfig new sub config toadletsymlinker node config tslconfig register symlinks null 9 true false symlinker toadlet symlinks symlinker toadlet symlinks long new string arr callback override public string get return get config load string override public void set string val throws invalid config value exception if store dir equals new file val return fixme throw new invalid config value exception cannot set the plugins that s loaded override public boolean is read only return true string fns tslconfig get string arr symlinks if fns null for string fn fns string tuple fn split if tuple length 2 add link tuple 0 tuple 1 false tslconfig finished initialization add link sl search plugins plugins librarian false add link sl gallery plugins plugins test gallery false symlinkertoadlet highlevelsimpleclient subconfig symlinkertoadlet symlinkertoadlet symlinkslong stringarrcallback getconfigloadstring invalidconfigvalueexception storedir invalidconfigvalueexception isreadonly getstringarr addlink finishedinitialization addlink addlink testgallery tslconfig register symlinks null 9 true false symlinker toadlet symlinks symlinker toadlet symlinks long new string arr callback override public string get return get config load string symlinkertoadlet symlinkertoadlet symlinkslong stringarrcallback getconfigloadstring override public void set string val throws invalid config value exception if store dir equals new file val return fixme throw new invalid config value exception cannot set the plugins that s loaded invalidconfigvalueexception storedir invalidconfigvalueexception override public boolean is read only return true isreadonly public boolean add link string alias string target boolean store boolean ret synchronized link map if link map put alias target alias ret true else ret false logger normal this adding link alias target if store node client core store config return ret addlink linkmap linkmap clientcore storeconfig public boolean remove link string alias boolean store boolean ret synchronized link map object o if o link map remove alias null ret true else ret false logger normal this removing link alias o if store node client core store config return ret removelink linkmap linkmap clientcore storeconfig private string get config load string string retarr new string link map size synchronized link map int i 0 for map entry string string entry link map entry set retarr i entry get key entry get value return retarr getconfigloadstring linkmap linkmap linkmap entryset getkey getvalue override public string supported methods return get supportedmethods override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception redirect exception string path uri get path string foundkey null string foundtarget null synchronized link map for map entry string string entry link map entry set string key entry get key if path starts with key foundkey key foundtarget entry get value todo redirect to errorpage if foundtarget null foundkey null write text reply ctx 404 not found l10n get string static toadlet path not found return path foundtarget path substring foundkey length uri outuri null try outuri new uri null null path uri get query uri get fragment catch uri syntax exception e todo handle error somehow writehtml reply ctx 200 ok e get message return uri get raw query throw new redirect exception outuri handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception getpath linkmap linkmap entryset getkey startswith getvalue writetextreply getstring statictoadlet pathnotfound getquery getfragment urisyntaxexception writehtmlreply getmessage getrawquery redirectexception private static final long serial versionuid 1 public key encode exception string string super string serialversionuid keyencodeexception public key encode exception super keyencodeexception public key encode exception string message throwable cause super message cause keyencodeexception public key encode exception throwable cause super cause keyencodeexception transient field fld btree multi field index btreemultifieldindex btree multi field index class cls string field name boolean unique this cls cls this unique unique this field name field name this class name class descriptor get class name cls locate fields type class descriptor tp array of byte types new int field name length for int i 0 i types length i types i check type fld i get type btreemultifieldindex fieldname fieldname fieldname classname classdescriptor getclassname locatefields classdescriptor tparrayofbyte fieldname checktype gettype private final void locate fields fld new field field name length for int i 0 i field name length i fld i class descriptor locate field cls field name i if fld i null throw new storage error storage error indexed field not found class name field name i locatefields fieldname fieldname classdescriptor locatefield fieldname storageerror storageerror indexed_field_not_found classname fieldname public class get indexed class return cls getindexedclass public field get key fields return fld getkeyfields public void on load cls class descriptor load class get storage class name locate fields onload classdescriptor loadclass getstorage classname locatefields int compare byte arrays byte key byte item int offs int lengtn int o1 0 int o2 offs byte a1 key byte a2 item for int i 0 i fld length o1 key length i int diff 0 switch types i case class descriptor tp boolean case class descriptor tp byte diff a1 o1 a2 o2 break case class descriptor tp short diff bytes unpack2 a1 o1 bytes unpack2 a2 o2 o1 2 o2 2 break case class descriptor tp char diff char bytes unpack2 a1 o1 char bytes unpack2 a2 o2 o1 2 o2 2 break case class descriptor tp int case class descriptor tp object case class descriptor tp enum int i1 bytes unpack4 a1 o1 int i2 bytes unpack4 a2 o2 diff i1 i2 1 i1 i2 0 1 o1 4 o2 4 break case class descriptor tp long case class descriptor tp date long l1 bytes unpack8 a1 o1 long l2 bytes unpack8 a2 o2 diff l1 l2 1 l1 l2 0 1 o1 8 o2 8 break case class descriptor tp float float f1 float int bits to float bytes unpack4 a1 o1 float f2 float int bits to float bytes unpack4 a2 o2 diff f1 f2 1 f1 f2 0 1 o1 4 o2 4 break case class descriptor tp double double d1 double long bits to double bytes unpack8 a1 o1 double d2 double long bits to double bytes unpack8 a2 o2 diff d1 d2 1 d1 d2 0 1 o1 8 o2 8 break case class descriptor tp string int len1 bytes unpack4 a1 o1 int len2 bytes unpack4 a2 o2 o1 4 o2 4 int len len1 len2 len1 len2 while len 0 diff char bytes unpack2 a1 o1 char bytes unpack2 a2 o2 if diff 0 return diff o1 2 o2 2 diff len1 len2 break case class descriptor tp array of byte int len1 bytes unpack4 a1 o1 int len2 bytes unpack4 a2 o2 o1 4 o2 4 int len len1 len2 len1 len2 while len 0 diff a1 o1 a2 o2 if diff 0 return diff diff len1 len2 break default assert failed invalid type if diff 0 return diff return 0 comparebytearrays classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpshort classdescriptor tpchar classdescriptor tpint classdescriptor tpobject classdescriptor tpenum classdescriptor tplong classdescriptor tpdate classdescriptor tpfloat intbitstofloat intbitstofloat classdescriptor tpdouble longbitstodouble longbitstodouble classdescriptor tpstring classdescriptor tparrayofbyte string convert string object s return string s convertstring object unpack byte array key page pg int pos int offs btree page first key offs btree page get key str offs pg pos byte data pg data object values new object fld length for int i 0 i fld length i object v null switch types i case class descriptor tp boolean v boolean value of data offs 0 break case class descriptor tp byte v new byte data offs break case class descriptor tp short v short value of bytes unpack2 data offs offs 2 break case class descriptor tp char v new character char bytes unpack2 data offs offs 2 break case class descriptor tp int v new integer bytes unpack4 data offs offs 4 break case class descriptor tp object int oid bytes unpack4 data offs v oid 0 null storage impl get storage lookup object oid null offs 4 break case class descriptor tp long v new long bytes unpack8 data offs offs 8 break case class descriptor tp enum v fld i get type get enum constants bytes unpack4 data offs offs 4 break case class descriptor tp date long msec bytes unpack8 data offs v msec 1 null new date msec offs 8 break case class descriptor tp float v new float float int bits to float bytes unpack4 data offs offs 4 break case class descriptor tp double v new double double long bits to double bytes unpack8 data offs offs 8 break case class descriptor tp string int len bytes unpack4 data offs offs 4 char sval new char len for int j 0 j len j sval j char bytes unpack2 data offs offs 2 v new string sval break case class descriptor tp array of byte int len bytes unpack4 data offs offs 4 byte bval new byte len system arraycopy data offs bval 0 len offs len break default assert failed invalid type values i v return values unpackbytearraykey btreepage firstkeyoffs btreepage getkeystroffs classdescriptor tpboolean valueof classdescriptor tpbyte classdescriptor tpshort valueof classdescriptor tpchar classdescriptor tpint classdescriptor tpobject storageimpl getstorage lookupobject classdescriptor tplong classdescriptor tpenum gettype getenumconstants classdescriptor tpdate classdescriptor tpfloat intbitstofloat classdescriptor tpdouble longbitstodouble classdescriptor tpstring classdescriptor tparrayofbyte private key extract key i persistent obj try byte buffer buf new byte buffer int dst 0 for int i 0 i fld length i field f field fld i switch types i case class descriptor tp boolean buf extend dst 1 buf arr dst byte f get boolean obj 1 0 break case class descriptor tp byte buf extend dst 1 buf arr dst f get byte obj break case class descriptor tp short buf extend dst 2 bytes pack2 buf arr dst f get short obj dst 2 break case class descriptor tp char buf extend dst 2 bytes pack2 buf arr dst short f get char obj dst 2 break case class descriptor tp int buf extend dst 4 bytes pack4 buf arr dst f get int obj dst 4 break case class descriptor tp object i persistent p i persistent f get obj buf extend dst 4 if p null if p is persistent get storage make persistent p bytes pack4 buf arr dst p get oid else bytes pack4 buf arr dst 0 dst 4 break case class descriptor tp long buf extend dst 8 bytes pack8 buf arr dst f get long obj dst 8 break case class descriptor tp date date d date f get obj buf extend dst 8 bytes pack8 buf arr dst d null 1 d get time dst 8 break case class descriptor tp float buf extend dst 4 bytes pack4 buf arr dst float float to int bits f get float obj dst 4 break case class descriptor tp double buf extend dst 8 bytes pack8 buf arr dst double double to long bits f get double obj dst 8 break case class descriptor tp enum buf extend dst 4 bytes pack4 buf arr dst enum f get obj ordinal dst 4 break case class descriptor tp string buf extend dst 4 string str convert string f get obj if str null int len str length bytes pack4 buf arr dst len dst 4 buf extend dst len 2 for int j 0 j len j bytes pack2 buf arr dst short str char at j dst 2 else bytes pack4 buf arr dst 0 dst 4 break case class descriptor tp array of byte buf extend dst 4 byte arr byte f get obj if arr null int len arr length bytes pack4 buf arr dst len dst 4 buf extend dst len system arraycopy arr 0 buf arr dst len dst len else bytes pack4 buf arr dst 0 dst 4 break default assert failed invalid type return new key buf to array catch exception x throw new storage error storage error access violation x extractkey ipersistent bytebuffer bytebuffer classdescriptor tpboolean getboolean classdescriptor tpbyte getbyte classdescriptor tpshort getshort classdescriptor tpchar getchar classdescriptor tpint getint classdescriptor tpobject ipersistent ipersistent ispersistent getstorage makepersistent getoid classdescriptor tplong getlong classdescriptor tpdate gettime classdescriptor tpfloat floattointbits getfloat classdescriptor tpdouble doubletolongbits getdouble classdescriptor tpenum classdescriptor tpstring convertstring charat classdescriptor tparrayofbyte toarray storageerror storageerror access_violation private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type object values object key oval byte buffer buf new byte buffer int dst 0 for int i 0 i values length i object v values i switch types i case class descriptor tp boolean buf extend dst 1 buf arr dst byte boolean v boolean value 1 0 break case class descriptor tp byte buf extend dst 1 buf arr dst number v byte value break case class descriptor tp short buf extend dst 2 bytes pack2 buf arr dst number v short value dst 2 break case class descriptor tp char buf extend dst 2 bytes pack2 buf arr dst v instanceof number number v short value short character v char value dst 2 break case class descriptor tp int buf extend dst 4 bytes pack4 buf arr dst number v int value dst 4 break case class descriptor tp object buf extend dst 4 bytes pack4 buf arr dst v null 0 i persistent v get oid dst 4 break case class descriptor tp long buf extend dst 8 bytes pack8 buf arr dst number v long value dst 8 break case class descriptor tp date buf extend dst 8 bytes pack8 buf arr dst v null 1 date v get time dst 8 break case class descriptor tp float buf extend dst 4 bytes pack4 buf arr dst float float to int bits number v float value dst 4 break case class descriptor tp double buf extend dst 8 bytes pack8 buf arr dst double double to long bits number v double value dst 8 break case class descriptor tp enum buf extend dst 4 bytes pack4 buf arr dst enum v ordinal dst 4 break case class descriptor tp string buf extend dst 4 if v null string str convert string v int len str length bytes pack4 buf arr dst len dst 4 buf extend dst len 2 for int j 0 j len j bytes pack2 buf arr dst short str char at j dst 2 else bytes pack4 buf arr dst 0 dst 4 break case class descriptor tp array of byte buf extend dst 4 if v null byte arr byte v int len arr length bytes pack4 buf arr dst len dst 4 buf extend dst len system arraycopy arr 0 buf arr dst len dst len else bytes pack4 buf arr dst 0 dst 4 break default assert failed invalid type return new key buf to array key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type bytebuffer bytebuffer classdescriptor tpboolean booleanvalue classdescriptor tpbyte bytevalue classdescriptor tpshort shortvalue classdescriptor tpchar shortvalue charvalue classdescriptor tpint intvalue classdescriptor tpobject ipersistent getoid classdescriptor tplong longvalue classdescriptor tpdate gettime classdescriptor tpfloat floattointbits floatvalue classdescriptor tpdouble doubletolongbits doublevalue classdescriptor tpenum classdescriptor tpstring convertstring charat classdescriptor tparrayofbyte toarray public boolean put t obj return super put extract key obj obj extractkey public t set t obj return super set extract key obj obj extractkey public void remove t obj super remove extract key obj obj extractkey public t remove key key return super remove convert key key convertkey public boolean contains object t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i obj return true return false containsobject extractkey ipersistent public boolean contains t obj key key extract key obj if unique return super get key null else i persistent mbrs get key key for int i 0 i mbrs length i if mbrs i equals obj return true return false extractkey ipersistent public void append t obj throw new storage error storage error unsupported index type storageerror storageerror unsupported_index_type public t get key from key till array list list new array list if root 0 btree page find storage impl get storage root convert key from convert key till this height list return t list to array t array new instance cls list size arraylist arraylist btreepage storageimpl getstorage convertkey convertkey toarray newinstance public t get prefix string prefix throw new storage error storage error incompatible key type getprefix storageerror storageerror incompatible_key_type public t prefix search string key throw new storage error storage error incompatible key type prefixsearch storageerror storageerror incompatible_key_type public t to persistent array t arr t array new instance cls n elems if root 0 btree page traverse forward storage impl get storage root type height arr 0 return arr topersistentarray newinstance nelems btreepage traverseforward storageimpl getstorage public t get key key return super get convert key key convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey public iterable iterator t query by example t obj key key extract key obj return iterator key key ascent order iterableiterator querybyexample extractkey ascent_order public iterable iterator t select string predicate query t query new query impl t get storage return query select cls iterator predicate iterableiterator queryimpl getstorage public boolean is case insensitive return false iscaseinsensitive class btree case insensitive multi field index t extends i persistent extends btree multi field index t btree case insensitive multi field index btreecaseinsensitivemultifieldindex ipersistent btreemultifieldindex btreecaseinsensitivemultifieldindex btree case insensitive multi field index btree case insensitive multi field index class cls string field names boolean unique super cls field names unique btreecaseinsensitivemultifieldindex btreecaseinsensitivemultifieldindex fieldnames fieldnames string convert string object s return string s to lower case convertstring tolowercase public boolean is case insensitive return true iscaseinsensitive mime type type public known unsafe content type exception mime type type this type type mimetype knownunsafecontenttypeexception mimetype override public string get explanation string builder sb new string builder sb append p b sb append type read description sb append b p n p l10n known unsafe ul if type dangerous inlines sb append li font color red b l10n dangerous inlines label b font l10n dangerous inline li if type dangerous links sb append li font color red b l10n dangerous links label b font l10n dangerous links li if type dangerous scripting sb append li font color red b l10n dangerous scripts label b font l10n dangerous scripts li if type dangerous read metadata sb append li font color red b l10n dangerous metadata label b font l10n dangerous metadata li sb append ul l10n no filter return sb to string getexplanation stringbuilder stringbuilder readdescription knownunsafe dangerousinlines dangerousinlineslabel dangerousinline dangerouslinks dangerouslinkslabel dangerouslinks dangerousscripting dangerousscriptslabel dangerousscripts dangerousreadmetadata dangerousmetadatalabel dangerousmetadata nofilter tostring override public html node gethtml explanation html node explanation new html node div explanation add child p add child b type read description explanation add child p l10n known unsafe html node list explanation add child ul html node reason list add child li reason add child span class warning l10n dangerous inlines label reason add child l10n dangerous inlines reason list add child li reason add child span class warning l10n dangerous links label reason add child l10n dangerous links reason list add child li reason add child span class warning l10n dangerous scripts label reason add child l10n dangerous scripts reason list add child li reason add child span class warning l10n dangerous metadata label reason add child l10n dangerous metadata explanation add child p l10n no filter return explanation htmlnode gethtmlexplanation htmlnode htmlnode addchild addchild readdescription addchild knownunsafe htmlnode addchild htmlnode addchild addchild dangerousinlineslabel addchild dangerousinlines addchild addchild dangerouslinkslabel addchild dangerouslinks addchild addchild dangerousscriptslabel addchild dangerousscripts addchild addchild dangerousmetadatalabel addchild dangerousmetadata addchild nofilter override public string gethtml encoded title return l10n title type html encoder encode type primary mime type gethtmlencodedtitle htmlencoder primarymimetype override public string get raw title return l10n title type type primary mime type getrawtitle primarymimetype private static string l10n string key return l10n get string known unsafe content type exception key getstring knownunsafecontenttypeexception private static string l10n string key string pattern string value return l10n get string known unsafe content type exception key pattern value getstring knownunsafecontenttypeexception private function2d y map function public map filter ymapfunction mapfilter public void setx map function function2d x map function this x map function x map function setxmapfunction xmapfunction xmapfunction xmapfunction public function2d getx map function return x map function getxmapfunction xmapfunction public void sety map function function2d y map function this y map function y map function setymapfunction ymapfunction ymapfunction ymapfunction public function2d gety map function return y map function getymapfunction ymapfunction override protected void transform inverse int x int y float out float x map y map x map x map function evaluate x y y map y map function evaluate x y out 0 x map transformed space width out 1 y map transformed space height transforminverse xmap ymap xmap xmapfunction ymap ymapfunction xmap transformedspace ymap transformedspace override public string to string return distort map coordinates tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog private long started time public synchronized long get started time return started time startedtime getstartedtime startedtime public message core timedoutfilters new vector message filter 32 messagecore _timedoutfilters messagefilter decode a packet from data and a peer can be called by incoming packet filter s param data param offset param length param peer public message decode single message byte data int offset int length peer context peer int overhead try return message decode message from packet data offset length peer overhead catch throwable t logger error this could not decode packet t t return null incomingpacketfilter decodesinglemessage peercontext decodemessagefrompacket public void start final ticker ticker synchronized this started time system current time millis ticker queue timed job new runnable public void run try remove timed out filters catch throwable t logger error this failed to remove timed out filters t t finally ticker queue timed job this filter remove time filter remove time startedtime currenttimemillis queuetimedjob removetimedoutfilters queuetimedjob filter_remove_time filter_remove_time public void run try remove timed out filters catch throwable t logger error this failed to remove timed out filters t t finally ticker queue timed job this filter remove time removetimedoutfilters queuetimedjob filter_remove_time remove timed out filters void remove timed out filters long t start system current time millis 1 extra millisecond to give wait for a chance to remove the filter avoids exhaustive and unsuccessful search in wait for removal of a timed out filter if logminor logger minor this removing timed out filters synchronized filters for list iterator message filter i filters list iterator i has next message filter f i next if f timed out t start if logminor logger minor this removing f i remove timedoutfilters add f do not break after finding a non timed out filter because some filters may be timed out because their client callbacks say they should be also simplifies the logic significantly we ve had some major bugs here see also the end of wait for for another weird case for message filter f timedoutfilters f set message null f on timed out timedoutfilters clear long t end system current time millis if t end t start 50 if t end t start 3000 logger error this remove timed out filters took t end t start ms else if logminor logger minor this remove timed out filters took t end t start ms removetimedoutfilters tstart currenttimemillis waitfor waitfor _filters listiterator messagefilter _filters listiterator hasnext messagefilter timedout tstart _timedoutfilters waitfor messagefilter _timedoutfilters setmessage ontimedout _timedoutfilters tend currenttimemillis tend tstart tend tstart removetimedoutfilters tend tstart removetimedoutfilters tend tstart dispatch a message to a waiting filter or feed it to the dispatcher if none are found param m the message to dispatch public void check filters message m packet socket handler from long t start system current time millis if logminor logger minor this check filters m from m get source if m get source instanceof peer node peer node m get source add to local node received messages from statistic m boolean matched false if m get spec equals dmt packet transmit if logminor logger minor this system current time millis 60000 from m get source m message filter match null synchronized filters for list iterator message filter i filters list iterator i has next message filter f i next if f matched logger error this removed pre matched message filter found in filters f i remove continue if f match m matched true i remove match f if logminor logger minor this matched f break only one match permitted per message if match null match set message m match on matched feed unmatched messages to the dispatcher if matched dispatcher null try if logminor logger minor this feeding to dispatcher m matched dispatcher handle message m catch throwable t logger error this dispatcher threw t t keep the last few unclaimed messages around in case the intended receiver isn t receiving yet if matched if logminor logger minor this unclaimed m check filters and then add to unmatched is atomic it has to be atomic because otherwise we can get a race condition that results in timeouts on m fs specifically thread a receives packet thread a checks filters it doesn t match any thread a feeds to dispatcher thread b creates filter thread b checks unmatched thread b adds filter thread b sleeps thread a returns from dispatcher which didn t match thread a adds to unmatched oops the only way to fix this is to have checking the filters and unmatched be a single atomic operation another race is possible if we merely recheck the filters after we return from dispatcher for example synchronized filters if logminor logger minor this rechecking filters and adding message for list iterator message filter i filters list iterator i has next message filter f i next if f match m matched true match f i remove if logminor logger minor this matched f break only one match permitted per message if matched while unclaimed size max unmatched fifo size message removed unclaimed remove first long message life time system current time millis removed local instantiation time if removed get source instanceof peer node logger normal this dropping unclaimed from removed get source get peer lived time util format time message life time 2 true quantity removed else logger normal this dropping unclaimed lived time util format time message life time 2 true quantity removed unclaimed add last m if logminor logger minor this done if match null match set message m match on matched long t end system current time millis if t end t start 50 if t end t start 3000 logger error this check filters took t end t start ms with unclaimedfifo size of unclaimed size for matched matched else if logminor logger minor this check filters took t end t start ms with unclaimedfifo size of unclaimed size for matched matched checkfilters packetsockethandler tstart currenttimemillis checkfilters getsource getsource peernode peernode getsource addtolocalnodereceivedmessagesfromstatistic getspec packettransmit currenttimemillis getsource messagefilter _filters listiterator messagefilter _filters listiterator hasnext messagefilter _filters setmessage onmatched _dispatcher _dispatcher handlemessage _unclaimed _unmatched mfs _unmatched _unmatched _filters listiterator messagefilter _filters listiterator hasnext messagefilter _unclaimed max_unmatched_fifo_size _unclaimed removefirst messagelifetime currenttimemillis localinstantiationtime getsource peernode getsource getpeer timeutil formattime messagelifetime timeutil formattime messagelifetime _unclaimed addlast setmessage onmatched tend currenttimemillis tend tstart tend tstart checkfilters tend tstart unclaimedfifosize _unclaimed checkfilters tend tstart unclaimedfifosize _unclaimed incoming packet filter should call this when a node is disconnected public void on disconnect peer context ctx array list message filter dropped filters null rare operation we can waste objects for better locking synchronized filters list iterator message filter i filters list iterator while i has next message filter f i next if f matches dropped connection ctx if dropped filters null dropped filters new array list message filter dropped filters add f i remove if dropped filters null for message filter mf dropped filters mf on dropped connection ctx incomingpacketfilter ondisconnect peercontext arraylist messagefilter droppedfilters _filters listiterator messagefilter _filters listiterator hasnext messagefilter matchesdroppedconnection droppedfilters droppedfilters arraylist messagefilter droppedfilters droppedfilters messagefilter droppedfilters ondroppedconnection incoming packet filter should call this when a node connects with a new boot id public void on restart peer context ctx array list message filter dropped filters null rare operation we can waste objects for better locking synchronized filters list iterator message filter i filters list iterator while i has next message filter f i next if f matches restarted connection ctx if dropped filters null dropped filters new array list message filter dropped filters add f i remove if dropped filters null for message filter mf dropped filters mf on restarted connection ctx incomingpacketfilter onrestart peercontext arraylist messagefilter droppedfilters _filters listiterator messagefilter _filters listiterator hasnext messagefilter matchesrestartedconnection droppedfilters droppedfilters arraylist messagefilter droppedfilters droppedfilters messagefilter droppedfilters onrestartedconnection public void add async filter message filter filter async message filter callback callback throws disconnected exception filter set async callback callback if filter matched logger error this add async filter on a filter which is already matched filter new exception error filter clear matched filter on start waiting false if logminor logger minor this adding async filter filter for callback message ret null if filter any connections dropped throw new disconnected exception or filter on dropped connection filter dropped connection check to see whether the filter matches any of the recently unclaimed messages drop any unclaimed messages that the filter doesn t match that are also older than max unclaimed fifo item lifetime long now system current time millis long message drop time now max unclaimed fifo item lifetime long message life time 0 synchronized filters once in the list it is up to the callback system to trigger the disconnection however we may have disconnected between check above and locking so we must check again if filter any connections dropped throw new disconnected exception or filter on dropped connection filter dropped connection but we are holding the filters lock if logminor logger minor this checking unclaimed for list iterator message i unclaimed list iterator i has next message m i next if filter match m i remove ret m if logminor logger debug this matching from unclaimed break else if m local instantiation time message drop time i remove message life time now m local instantiation time if m get source instanceof peer node logger normal this dropping unclaimed from m get source get peer lived time util format time message life time 2 true age m else logger normal this dropping unclaimed lived time util format time message life time 2 true age m if ret null if logminor logger minor this not in unclaimed insert filter into filter list in order of timeout list iterator message filter i filters list iterator while true if i has next i add filter if logminor logger minor this added at end break message filter mf i next if mf get timeout filter get timeout i previous i add filter if logminor logger minor this added in middle mf timeout mf get timeout my timeout filter get timeout break if ret null filter set message ret filter on matched filter clear matched addasyncfilter messagefilter asyncmessagefiltercallback disconnectedexception setasynccallback addasyncfilter clearmatched onstartwaiting anyconnectionsdropped disconnectedexception ondroppedconnection droppedconnection _unclaimed _unclaimed max_unclaimed_fifo_item_lifetime currenttimemillis messagedroptime max_unclaimed_fifo_item_lifetime messagelifetime _filters anyconnectionsdropped disconnectedexception ondroppedconnection droppedconnection _filters _unclaimed listiterator _unclaimed listiterator hasnext _unclaimed localinstantiationtime messagedroptime messagelifetime localinstantiationtime getsource peernode getsource getpeer timeutil formattime messagelifetime timeutil formattime messagelifetime _unclaimed listiterator messagefilter _filters listiterator hasnext messagefilter gettimeout gettimeout gettimeout gettimeout setmessage onmatched clearmatched wait for a filter to trigger or timeout blocks until either the trigger is activated or it times out or the peer is disconnected param filter the filter to wait for param ctr byte counter to add bytes from the message to return either a message or null if the filter timed out throws disconnected exception if the single peer being waited for disconnects public message wait for message filter filter byte counter ctr throws disconnected exception if logdebug logger debug this waiting for filter long start time system current time millis if filter matched logger error this wait for on a filter which is already matched filter new exception error filter clear matched filter on start waiting true message ret null if filter any connections dropped filter on dropped connection filter dropped connection throw new disconnected exception check to see whether the filter matches any of the recently unclaimed messages drop any unclaimed messages that the filter doesn t match that are also older than max unclaimed fifo item lifetime long now system current time millis long message drop time now max unclaimed fifo item lifetime long message life time 0 synchronized filters if logminor logger minor this checking unclaimed for list iterator message i unclaimed list iterator i has next message m i next if filter match m i remove ret m if logminor logger minor this matching from unclaimed break else if m local instantiation time message drop time i remove message life time now m local instantiation time if m get source instanceof peer node logger normal this dropping unclaimed from m get source get peer lived time util format time message life time 2 true age m else logger normal this dropping unclaimed lived time util format time message life time 2 true age m if ret null if logminor logger minor this not in unclaimed insert filter into filter list in order of timeout list iterator message filter i filters list iterator while true if i has next i add filter if logminor logger minor this added at end break message filter mf i next if mf get timeout filter get timeout i previous i add filter if logminor logger minor this added in middle mf timeout mf get timeout my timeout filter get timeout break long t end system current time millis if t end now 50 if t end now 3000 logger error this wait for unclaimed iteration took t end now ms with unclaimedfifo size of unclaimed size for ret of ret else if logminor logger minor this wait for unclaimed iteration took t end now ms with unclaimedfifo size of unclaimed size for ret of ret unlock to wait on filter waiting on the filter won t release the outer lock so we have to release it here if ret null if logminor logger minor this waiting synchronized filter try precaution against filter getting matched between being added to filters and here bug discovered by mason check really timed out too a for paranoia b for filters with a callback we could conceivably wait for them while filter matched filter dropped connection null filter really timed out now system current time millis long wait filter get timeout now if wait 0 break filter wait wait if filter dropped connection null throw new disconnected exception catch interrupted exception e ret filter get message if logdebug logger debug this returning ret from filter if filter matched we must remove it from filters before we return or when it is re added it will be in the list twice and potentially many more times than twice synchronized filters fortunately it will be close to the beginning of the filters list having just timed out that is assuming it hasn t already been removed in that case this will be slower filters remove filter matched a packet unclaimed or after wait filter set message ret filter on matched filter clear matched probably get rid if dijjer get dijjer get dump message wait times null dijjer get dijjer get dump message wait times println filter to string t filter get initial timeout t system current time millis start time dijjer get dijjer get dump message wait times flush long end time system current time millis if logdebug logger debug this returning in end time start time ms if ctr null ret null ctr received bytes ret receivedbytecount return ret disconnectedexception waitfor messagefilter bytecounter disconnectedexception starttime currenttimemillis waitfor clearmatched onstartwaiting anyconnectionsdropped ondroppedconnection droppedconnection disconnectedexception _unclaimed _unclaimed max_unclaimed_fifo_item_lifetime currenttimemillis messagedroptime max_unclaimed_fifo_item_lifetime messagelifetime _filters _unclaimed listiterator _unclaimed listiterator hasnext _unclaimed localinstantiationtime messagedroptime messagelifetime localinstantiationtime getsource peernode getsource getpeer timeutil formattime messagelifetime timeutil formattime messagelifetime _unclaimed listiterator messagefilter _filters listiterator hasnext messagefilter gettimeout gettimeout gettimeout gettimeout tend currenttimemillis tend tend waitfor _unclaimed tend unclaimedfifosize _unclaimed waitfor _unclaimed tend unclaimedfifosize _unclaimed _filters reallytimedout waitfor droppedconnection reallytimedout currenttimemillis gettimeout droppedconnection disconnectedexception interruptedexception getmessage _filters _filters _filters setmessage onmatched clearmatched getdijjer getdumpmessagewaittimes getdijjer getdumpmessagewaittimes tostring getinitialtimeout currenttimemillis starttime getdijjer getdumpmessagewaittimes endtime currenttimemillis endtime starttime receivedbytes _receivedbytecount send a message to a peer context throws not connected exception if we are not currently connected to the node public void send peer context destination message m byte counter ctr throws not connected exception if m get spec is internal only logger error this trying to send internal only message m of spec m get spec new exception debug return destination send async m null ctr peercontext notconnectedexception peercontext bytecounter notconnectedexception getspec isinternalonly getspec sendasync public void set dispatcher dispatcher d dispatcher d setdispatcher _dispatcher return the number of received messages that are currently unclaimed public int get unclaimedfifo size synchronized filters return unclaimed size getunclaimedfifosize _filters _unclaimed public map string integer get unclaimedfifo message counts map string integer message counts new hash map string integer synchronized filters for list iterator message i unclaimed list iterator i has next message m i next string message name m get spec get name integer message count message counts get message name if message count null message counts put message name integer value of 1 else message count integer value of message count int value 1 message counts put message name message count return message counts getunclaimedfifomessagecounts messagecounts hashmap _filters listiterator _unclaimed listiterator hasnext messagename getspec getname messagecount messagecounts messagename messagecount messagecounts messagename valueof messagecount valueof messagecount intvalue messagecounts messagename messagecount messagecounts public class opennet connections toadlet extends connections toadlet implements link enabled callback protected opennet connections toadlet node n node client core core high level simple client client super n core client opennetconnectionstoadlet connectionstoadlet linkenabledcallback opennetconnectionstoadlet nodeclientcore highlevelsimpleclient override protected void draw name column html node peer row peer node status peer node status do nothing no names on opennet drawnamecolumn htmlnode peerrow peernodestatus peernodestatus override protected void draw private note column html node peer row peer node status peer node status boolean f proxy javascript enabled do nothing no private notes either no such thing as negative trust in cyberspace drawprivatenotecolumn htmlnode peerrow peernodestatus peernodestatus fproxyjavascriptenabled override protected boolean has name column return false hasnamecolumn override protected boolean has private note column return false hasprivatenotecolumn override protected simple field set get noderef return node export opennet public field set simplefieldset getnoderef exportopennetpublicfieldset override protected peer node status get peer node statuses boolean no heavy return node peers get opennet peer node statuses no heavy peernodestatus getpeernodestatuses noheavy getopennetpeernodestatuses noheavy public boolean is enabled toadlet context ctx return node is opennet enabled isenabled toadletcontext isopennetenabled override protected string get page title string title count string string my name return l10n get string opennet connections toadlet full title new string counts name new string title count string node get my name getpagetitle titlecountstring myname getstring opennetconnectionstoadlet fulltitle titlecountstring getmyname override protected boolean should draw noderef box boolean advanced mode enabled return advanced mode enabled shoulddrawnoderefbox advancedmodeenabled advancedmodeenabled override protected boolean show peer actions box no per peer actions supported on opennet there s no point they ll only reconnect possibly as a different identity and we don t want to be able to send n2ntm spam either return false showpeeractionsbox override protected void draw peer action select box html node peer form boolean advanced mode enabled do nothing see show peer actions box drawpeeractionselectbox htmlnode peerform advancedmodeenabled showpeeractionsbox override protected string get peer list title return l10n get string opennet connections toadlet peers list title getpeerlisttitle getstring opennetconnectionstoadlet peerslisttitle override protected boolean accept ref posts return true acceptrefposts override protected string default redirect location return opennet defaultredirectlocation override protected boolean is opennet return true isopennet protected class opennet comparator extends comparator by status opennet comparator string sort by boolean reversed super sort by reversed opennetcomparator comparatorbystatus opennetcomparator sortby sortby override protected int custom compare peer node status first node peer node status second node string sort by if sort by equals success time long t1 opennet peer node status first node time last success long t2 opennet peer node status second node time last success if t1 t2 return reversed 1 1 else if t2 t1 return reversed 1 1 return super custom compare first node second node sort by customcompare peernodestatus firstnode peernodestatus secondnode sortby sortby successtime opennetpeernodestatus firstnode timelastsuccess opennetpeernodestatus secondnode timelastsuccess customcompare firstnode secondnode sortby override protected comparator peer node status comparator string sort by boolean reversed return new opennet comparator sort by reversed peernodestatus sortby opennetcomparator sortby override simple column end column headers boolean advanced mode if advanced mode return null return new simple column new simple column override protected void draw column html node peer row peer node status peer node status opennet peer node status status opennet peer node status peer node status long t last success status time last success peer row add child td class peer last success t last success 0 time util format time system current time millis t last success never override public string get explanation key return opennet connections toadlet success time override public string get sort string return success time override public string get title key return opennet connections toadlet success time title simplecolumn endcolumnheaders advancedmode advancedmode simplecolumn simplecolumn drawcolumn htmlnode peerrow peernodestatus peernodestatus opennetpeernodestatus opennetpeernodestatus peernodestatus tlastsuccess timelastsuccess peerrow addchild tlastsuccess timeutil formattime currenttimemillis tlastsuccess getexplanationkey opennetconnectionstoadlet successtime getsortstring successtime gettitlekey opennetconnectionstoadlet successtimetitle override protected void draw column html node peer row peer node status peer node status opennet peer node status status opennet peer node status peer node status long t last success status time last success peer row add child td class peer last success t last success 0 time util format time system current time millis t last success never drawcolumn htmlnode peerrow peernodestatus peernodestatus opennetpeernodestatus opennetpeernodestatus peernodestatus tlastsuccess timelastsuccess peerrow addchild tlastsuccess timeutil formattime currenttimemillis tlastsuccess peer row add child td class peer last success t last success 0 time util format time system current time millis t last success never override public string get explanation key return opennet connections toadlet success time peerrow addchild tlastsuccess timeutil formattime currenttimemillis tlastsuccess getexplanationkey opennetconnectionstoadlet successtime return opennet connections toadlet success time override public string get sort string return success time opennetconnectionstoadlet successtime getsortstring successtime return success time override public string get title key return opennet connections toadlet success time title successtime gettitlekey opennetconnectionstoadlet successtimetitle creates a new web page impl it is abstract because only a subclass can run the desired make method to generate the content param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public web page impl web interface my web interface http request my request wot my web interface get wot uri my web interface geturi pr wot get plugin respirator this pm my web interface get page maker this page node pm get page node web of trust null this request my request this content boxes new array list html node webpageimpl mywebinterface webinterface myrequest webpageimpl webinterface mywebinterface httprequest myrequest mywebinterface getwot mywebinterface getpluginrespirator mywebinterface getpagemaker pagenode getpagenode myrequest contentboxes arraylist htmlnode generates the html code that will be sent to the browser return html code of the page public string tohtml html node content node pm get content node page node we add every content boxes iterator html node content box content boxes iterator while content box has next content node add child content box next fixme this code does seem to get executed but the test box is invisible why html node test pm get infobox infobox alert test test add child test page node add child test generate the html output return page node generate htmlnode contentnode getcontentnode pagenode contentboxes htmlnode contentbox contentboxes contentbox hasnext contentnode addchild contentbox htmlnode getinfobox addchild pagenode addchild pagenode adds an error box to the web page param title the title of the desired error box public html node add error box string title html node error box pm get infobox infobox alert title content boxes add error box return pm get content node error box errorbox webpage errorbox htmlnode adderrorbox htmlnode errorbox getinfobox contentboxes errorbox getcontentnode errorbox adds an error box to the web page param title the title of the desired error box param message the error message that will be displayed public html node add error box string title string message html node error box pm get infobox infobox alert title error box add child p message content boxes add error box return pm get content node error box errorbox webpage errorbox htmlnode adderrorbox htmlnode errorbox getinfobox errorbox addchild contentboxes errorbox getcontentnode errorbox adds a new info box to the web page param title the title of the desired info box return the content node of the newly created info box protected html node add content box string title html node box pm get infobox title content boxes add box return pm get content node box infobox webpage infobox contentnode infobox htmlnode addcontentbox htmlnode getinfobox contentboxes getcontentnode public class opennet peer node status extends peer node status opennet peer node status peer node peer node boolean no heavy super peer node no heavy time last success opennet peer node peer node time last success opennetpeernodestatus peernodestatus opennetpeernodestatus peernode peernode noheavy peernode noheavy timelastsuccess opennetpeernode peernode timelastsuccess private static final long serial versionuid 1 public duplicate trust exception string message super message serialversionuid duplicatetrustexception creates a new known identities page param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public known identities page web interface my web interface http request my request super my web interface my request knownidentitiespage mywebinterface webinterface myrequest knownidentitiespage webinterface mywebinterface httprequest myrequest mywebinterface myrequest public void make if request is part set add identity try wot add identity request get part as string identityuri 1024 html node success box add content box success success box add child the identity was added and is now being downloaded catch exception e add error box adding the identity failed e get message if request is part set set trust string trusterid request get part as string ownerid 128 string trusteeid request is part set trustee request get part as string trustee 128 null string value request get part as string value 4 string comment request get part as string comment 256 fixme store max length as a constant in class identity try if trusteeid null for add identity trusteeid identity getid fromuri new freeneturi request get part as string identityuri 1024 if value trim equals wot remove trust trusterid trusteeid else wot set trust trusterid trusteeid byte parse byte value comment catch exception e add error box setting trust failed e get message own identity tree owner null object container db wot getdb plugin respirator pr wot get plugin respirator int nb own identities 1 string ownerid request get part as string ownerid 128 if ownerid equals try tree owner wot get own identity byid ownerid catch exception e logger error this error while selecting the own identity e add error box error while selecting the own identity e get message else synchronized wot object set own identity all own identities wot get all own identities nb own identities all own identities size if nb own identities 1 tree owner all own identities next make add identity form pr tree owner if tree owner null try make known identities list tree owner db pr catch exception e logger error this e get message add error box error e get class e get message else if nb own identities 1 make select tree owner form db pr else make no own identity warning ispartset addidentity addidentity getpartasstring htmlnode successbox addcontentbox successbox addchild adderrorbox getmessage ispartset settrust getpartasstring ispartset getpartasstring getpartasstring getpartasstring addidentity getidfromuri getpartasstring removetrust settrust parsebyte adderrorbox getmessage ownidentity treeowner objectcontainer pluginrespirator getpluginrespirator nbownidentities getpartasstring treeowner getownidentitybyid ownidentity adderrorbox ownidentity getmessage objectset ownidentity allownidentities getallownidentities nbownidentities allownidentities nbownidentities treeowner allownidentities makeaddidentityform treeowner treeowner makeknownidentitieslist treeowner getmessage adderrorbox getclass getmessage nbownidentities makeselecttreeownerform makenoownidentitywarning makes a form where the user can enter the requesturi of an identity he knows param pr a reference to the link plugin respirator param tree owner the owner of the known identity list not used for adding the identity but for showing the known identity list properly after adding private void make add identity form plugin respirator pr own identity tree owner todo add trust value and comment fields and make them mandatory the user should only add an identity he trusts html node add box content add content box add an identity html node create form pr add form child add box content uri add identity if tree owner null create form add child input new string type name value new string hidden ownerid tree owner getid create form add child input new string type name value new string hidden page add identity create form add child span new string title style new string this must be a valid freenet uri border bottom 1px dotted cursor help identity uri create form add child input new string type name size new string text identityuri 70 create form add child br if tree owner null create form add child input new string type name value new string hidden set trust true create form add child span trust add child input new string type name size value new string text value 4 create form add child span comment add child input new string type name size value new string text comment 20 create form add child br create form add child input new string type name value new string submit add identity add pluginrespirator treeowner makeaddidentityform pluginrespirator ownidentity treeowner htmlnode addboxcontent addcontentbox htmlnode createform addformchild addboxcontent addidentity treeowner createform addchild treeowner createform addchild addidentity createform addchild createform addchild createform addchild treeowner createform addchild settrust createform addchild addchild createform addchild addchild createform addchild createform addchild addidentity private void make no own identity warning add error box no own identity found you should create an identity first makenoownidentitywarning adderrorbox private void make select tree owner form object container db plugin respirator pr html node list box content add content box select the trust tree owner html node select form pr add form child list box content uri view tree select form add child input new string type name value new string hidden page view tree html node select box select form add child select name ownerid synchronized wot for own identity own identity wot get all own identities select box add child option value own identity getid own identity get nickname select form add child input new string type name value new string submit select view this identity s web of trust makeselecttreeownerform objectcontainer pluginrespirator htmlnode listboxcontent addcontentbox htmlnode selectform addformchild listboxcontent viewtree selectform addchild viewtree htmlnode selectbox selectform addchild ownidentity ownidentity getallownidentities selectbox addchild ownidentity ownidentity getnickname selectform addchild makes the list of identities known by the tree owner param db a reference to the database param pr a reference to the link plugin respirator param tree owner owner of the trust tree we want to display private void make known identities list own identity tree owner object container db plugin respirator pr throws duplicate score exception duplicate trust exception html node list box content add content box known identities display the list of known identities html node identities table list box content add child table border 0 html node row identities table add child tr row add child th nickname row add child th fetched row add child th trustlist row add child th score rank row add child th trust comment row add child th trusters row add child th trustees synchronized wot for identity id wot get all identities if id tree owner continue row identities table add child tr nick name row add child td new string title style new string id get requesturi to string cursor help add child a href show identity id id getid id get nickname date last fetched id get last fetched date if last fetched equals new date 0 synchronized m date format m date format set time zone time zone get default simple date format format date in utc does convert to the configured time zone interesting eh row add child td m date format format last fetched else row add child td never publish trust list row add child td new string align new string center id does publish trust list yes no score try row add child td new string align new string center integer to string wot get score own identity tree owner id get score wot get score own identity tree owner id get rank catch not in trust tree exception e this only happen with identities added manually by the user todo maybe we should give the opportunity to trust it at creation time row add child td null own trust row add child get received trust form tree owner id nb trusters html node trusters cell row add child td new string align new string center trusters cell add child new html node a href uri show identity id id getid long to string wot get received trusts id size nb trustees html node trustees cell row add child td new string align new string center trustees cell add child new html node a href uri show identity id id getid long to string wot get given trusts id size pluginrespirator treeowner makeknownidentitieslist ownidentity treeowner objectcontainer pluginrespirator duplicatescoreexception duplicatetrustexception htmlnode listboxcontent addcontentbox htmlnode identitiestable listboxcontent addchild htmlnode identitiestable addchild addchild addchild addchild addchild addchild addchild addchild getallidentities treeowner identitiestable addchild nickname addchild getrequesturi tostring addchild showidentity getnickname lastfetched getlastfetcheddate lastfetched mdateformat mdateformat settimezone timezone getdefault simpledateformat timezone addchild mdateformat lastfetched addchild trustlist addchild doespublishtrustlist addchild tostring getscore ownidentity treeowner getscore getscore ownidentity treeowner getrank notintrusttreeexception addchild addchild getreceivedtrustform treeowner htmlnode trusterscell addchild trusterscell addchild htmlnode showidentity tostring getreceivedtrusts htmlnode trusteescell addchild trusteescell addchild htmlnode showidentity tostring getgiventrusts private html node get received trust form own identity truster identity trustee throws duplicate trust exception string trust value string trust comment trust trust try trust wot get trust truster trustee trust value string value of trust get value trust comment trust get comment catch not trusted exception e logger debug this truster get nickname does not trust trustee get nickname html node cell new html node td html node trust form pr add form child cell uri set trust trust form add child input new string type name value new string hidden page set trust trust form add child input new string type name value new string hidden ownerid truster getid trust form add child input new string type name value new string hidden trustee trustee getid trust form add child input new string type name size value new string text value 2 trust value trust form add child input new string type name size value new string text comment 50 trust comment trust form add child input new string type name value new string submit set trust update return cell htmlnode getreceivedtrustform ownidentity duplicatetrustexception trustvalue trustcomment gettrust trustvalue valueof getvalue trustcomment getcomment nottrustedexception getnickname getnickname htmlnode htmlnode htmlnode trustform addformchild settrust trustform addchild settrust trustform addchild trustform addchild trustform addchild trustvalue trustform addchild trustcomment trustform addchild settrust creates a new file bucket param file the file to read and write to param create file only if true create the file if it doesn t exist but if it does exist throw a file exists exception on any write operation this is safe against symlink attacks because we write to a temp file and then rename it is technically possible that the rename will clobber an existing file if there is a race condition but since it will not write over a symlink this is probably not dangerous user supplied filenames should in any case be restricted by higher levels param read only if true any attempt to write to the bucket will result in an io exception can be set later irreversible see is read only set read only param delete on finalize if true delete the file on finalization reversible param delete on exit if true delete the file on a clean exit of the jvm irreversible use with care public file bucket file file boolean read only boolean create file only boolean delete on finalize boolean delete on exit boolean delete on free super file delete on exit if file null throw new null pointer exception file orig file file file file get absolute file copy it so we can safely delete it if orig file file file new file file get path this read only read only this create file only create file only this file file this delete on finalize delete on finalize this delete on free delete on free this delete on exit delete on exit useful for finding temp file leaks system err println file bucket ctr 0 file get absolute path new exception get stack print stack trace file restart counter 0 filebucket createfileonly fileexistsexception readonly ioexception isreadonly setreadonly deleteonfinalize deleteonexit filebucket readonly createfileonly deleteonfinalize deleteonexit deleteonfree deleteonexit nullpointerexception origfile getabsolutefile origfile getpath readonly readonly createfileonly createfileonly deleteonfinalize deleteonfinalize deleteonfree deleteonfree deleteonexit deleteonexit filebucket getabsolutepath printstacktrace filerestartcounter returns the file object this buckets data is kept in override public synchronized file get file return file getfile public synchronized boolean is read only return read only isreadonly readonly public synchronized void set read only read only true setreadonly readonly turn off delete file on finalize flag note that if you have already set delete file on exit there is little that you can do to recover it delete file on finalize on the other hand is reversible public synchronized void dont delete on finalize delete on finalize false dontdeleteonfinalize deleteonfinalize override protected boolean create file only return create file only createfileonly createfileonly override protected boolean delete on exit return delete on exit deleteonexit deleteonexit override protected boolean delete on finalize return delete on finalize deleteonfinalize deleteonfinalize override protected boolean delete on free return delete on free deleteonfree deleteonfree public void store to object container container container store this storeto objectcontainer public void remove from object container container logger minor this removing this container activate file 5 container delete file container delete this removefrom objectcontainer public void object on activate object container container container activate file 5 objectonactivate objectcontainer public bucket create shadow throws io exception string fnam file get path file new file new file fnam return new file bucket new file true false false false false createshadow ioexception getpath newfile filebucket newfile public nodechk byte routing key2 byte crypto algorithm super routing key2 if routing key2 length key length throw new illegal argument exception wrong length routing key2 length should be key length this crypto algorithm crypto algorithm routingkey2 cryptoalgorithm routingkey2 routingkey2 key_length illegalargumentexception routingkey2 key_length cryptoalgorithm cryptoalgorithm private nodechk nodechk key super key this crypto algorithm key crypto algorithm cryptoalgorithm cryptoalgorithm override public key clone key return new nodechk this clonekey public static final byte base type 1 public final void write to data output stream data output stream stream throws io exception write stream base_type writetodataoutputstream dataoutputstream ioexception override public string to string return super to string base64 encode routing key integer to hex string hash tostring tostring routingkey tohexstring override public final void write data output index throws io exception index write short get type index write routing key dataoutput _index ioexception _index writeshort gettype _index routingkey public static key readchk data input raf byte algo throws io exception byte buf new byte key length raf read fully buf return new nodechk buf algo datainput ioexception key_length readfully override public boolean equals object key if key this return true if key instanceof nodechk nodechk chk nodechk key return java util arrays equals chk routing key routing key crypto algorithm chk crypto algorithm return false routingkey routingkey cryptoalgorithm cryptoalgorithm override public int hash code return super hash code hashcode hashcode override public short get type return short 0x100 crypto algorithm 0xff gettype cryptoalgorithm override public byte get routing key return routing key getroutingkey routingkey override public byte get full key byte buf new byte full key length short type get type buf 0 byte type 8 buf 1 byte type 0xff system arraycopy routing key 0 buf 2 routing key length return buf getfullkey full_key_length gettype routingkey routingkey public static byte routing key from full key byte key buf if key buf length key length return key buf if key buf length full key length logger error nodechk class routing key from full key on key buf length bytes return null if key buf 0 1 key buf 1 key algo aes pcfb 256 sha256 if key buf key buf length 1 0 key buf key buf length 2 0 we are certain it s a routing key logger minor nodechk class recovering routing key stored wrong as full key two nulls at end else it might be a routing key or it might be random data logger error nodechk class maybe recovering routing key stored wrong as full key byte out new byte key length system arraycopy key buf 0 out 0 key length return out byte out new byte key length system arraycopy key buf 2 out 0 key length return out routingkeyfromfullkey keybuf keybuf key_length keybuf keybuf full_key_length routingkeyfromfullkey keybuf keybuf keybuf algo_aes_pcfb_256_sha256 keybuf keybuf keybuf keybuf key_length keybuf key_length key_length keybuf key_length public int compare to object arg0 if arg0 instanceof nodessk return 1 nodechk key nodechk arg0 return fields compare bytes routing key key routing key compareto comparebytes routingkey routingkey override public void remove from object container container container delete this removefrom objectcontainer public class java lnf filter extends point filter public java lnf filter javalnffilter pointfilter javalnffilter override public int filterrgb int x int y int rgb if x 1 y 1 return rgb return image math mix colors 0 25f 0xff999999 rgb imagemath mixcolors override public string to string return stylize java l f stipple tostring public list peers message simple field set fs with metadata fields string to bool fs get with metadata false with volatile fields string to bool fs get with volatile false this identifier fs get identifier fs remove value identifier listpeersmessage simplefieldset withmetadata stringtobool withmetadata withvolatile stringtobool withvolatile removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied list peers requires full access identifier false peer node nodes node get peer nodes for int i 0 i nodes length i peer node pn nodes i handler output handler queue new peer message pn with metadata with volatile identifier handler output handler queue new end list peers message identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied listpeers peernode getpeernodes peernode outputhandler peermessage withmetadata withvolatile outputhandler endlistpeersmessage override public void remove from object container container container delete this removefrom objectcontainer public service event object source super source todo auto generated constructor stub serviceevent returns the jmdns instance which originated the event public abstract jmdns getdns public abstract jmdns getdns returns the fully qualified type of the service public abstract string get type gettype returns the instance name of the service always returns null if the event is sent to a service type listener always returns null if the event is sent to a service type listener see plugins mdns discovery javax jmdns service event get info public abstract service info get info mdnsdiscovery serviceevent getinfo serviceinfo getinfo public parser public abstract node parse input stream in stream throws parser exception inputstream instream parserexception public node parse url locationurl throws parser exception try httpurl connection url con httpurl connection locationurl open connection url con set request method get input stream url in url con get input stream node root elem parse url in url in close url con disconnect return root elem catch exception e throw new parser exception e string host locationurl get host int port locationurl get port string uri locationurl get path http request http req new http request http req set method http get http req seturi uri http response http res http req post host port if http res is successful false throw new parser exception locationurl to string string content new string http res get content string buffer input stream str buf new string buffer input stream content return parse str buf parserexception httpurlconnection urlcon httpurlconnection openconnection urlcon setrequestmethod inputstream urlin urlcon getinputstream rootelem urlin urlin urlcon rootelem parserexception gethost getport getpath httprequest httpreq httprequest httpreq setmethod httpreq httpresponse httpres httpreq httpres issuccessful parserexception tostring httpres getcontent stringbufferinputstream strbuf stringbufferinputstream strbuf public node parse file description file throws parser exception try input stream file in new file input stream description file node root parse file in file in close return root catch exception e throw new parser exception e descriptionfile parserexception inputstream filein fileinputstream descriptionfile filein filein parserexception public node parse string descr throws parser exception try string buffer input stream decr in new string buffer input stream descr node root parse decr in return root catch exception e throw new parser exception e parserexception stringbufferinputstream decrin stringbufferinputstream decrin parserexception public fft int logn prepare the weighting factors w1 new float logn w2 new float logn w3 new float logn int n 1 for int k 0 k logn k n 1 double angle 2 0 math pi n w1 k float math sin 0 5 angle w2 k 2 0f w1 k w1 k w3 k float math sin angle private void scramble int n float real float imag int j 0 for int i 0 i n i if i j float t t real j real j real i real i t t imag j imag j imag i imag i t int m n 1 while j m m 2 j m m 1 j m private void butterflies int n int logn int direction float real float imag int n 1 for int k 0 k logn k float w re w im wp re wp im temp re temp im wt int half n n n 1 wt direction w1 k wp re w2 k wp im direction w3 k w re 1 0f w im 0 0f for int offset 0 offset half n offset for int i offset i n i n int j i half n float re real j float im imag j temp re w re re w im im temp im w im re w re im real j real i temp re real i temp re imag j imag i temp im imag i temp im wt w re w re wt wp re w im wp im w re w im w im wp re wt wp im w im if direction 1 float nr 1 0f n for int i 0 i n i real i nr imag i nr w_re w_im wp_re wp_im temp_re temp_im half_n wp_re wp_im w_re w_im half_n half_n temp_re w_re w_im temp_im w_im w_re temp_re temp_re temp_im temp_im w_re w_re wp_re w_im wp_im w_re w_im w_im wp_re wp_im w_im public void transform1d float real float imag int logn int n boolean forward scramble n real imag butterflies n logn forward 1 1 real imag public void transform2d float real float imag int cols int rows boolean forward int log2cols log2 cols int log2rows log2 rows int n math max rows cols float rtemp new float n float itemp new float n fft the rows for int y 0 y rows y int offset y cols system arraycopy real offset rtemp 0 cols system arraycopy imag offset itemp 0 cols transform1d rtemp itemp log2cols cols forward system arraycopy rtemp 0 real offset cols system arraycopy itemp 0 imag offset cols fft the columns for int x 0 x cols x int index x for int y 0 y rows y rtemp y real index itemp y imag index index cols transform1d rtemp itemp log2rows rows forward index x for int y 0 y rows y real index rtemp y imag index itemp y index cols private int log2 int n int m 1 int log2n 0 while m n m 2 log2n return m n log2n 1 parse a message from a datagram packet dns incoming datagram packet packet throws io exception this packet packet inet address source packet get address this data packet get data this len packet get length this off packet get offset this questions collections empty list this answers collections empty list this received time system current time millis try id read unsigned short flags read unsigned short num questions read unsigned short num answers read unsigned short num authorities read unsigned short num additionals read unsigned short parse questions if num questions 0 questions collections synchronized list new array list num questions for int i 0 i num questions i dns question question new dns question read name read unsigned short read unsigned short questions add question parse answers int n num answers num authorities num additionals if n 0 answers collections synchronized list new array list n for int i 0 i n i string domain read name int type read unsigned short int clazz read unsigned short int ttl read int int len read unsigned short int end off len dns record rec null switch type case dns constants type a i pv4 case dns constants type aaaa i pv6 fixme pjyf oct 14 2004 this has not been tested rec new dns record address domain type clazz ttl read bytes off len break case dns constants type cname case dns constants type ptr string service try service read name catch io exception e there was a problem reading the service name e print stack trace rec new dns record pointer domain type clazz ttl service break case dns constants type txt rec new dns record text domain type clazz ttl read bytes off len break case dns constants type srv int priority read unsigned short int weight read unsigned short int port read unsigned short string target try this is a hack to handle a bug in the bonjour conformance test it is sending out target strings that don t follow the domain name format if use domain name format for srv target target read name else target read non name string catch io exception e this can happen if the type of the label cannot be handled down below the offset gets advanced to the end of the record e print stack trace rec new dns record service domain type clazz ttl priority weight port target break case dns constants type hinfo maybe we should do something with those break default logger finer dns incoming unknown type type break if rec null rec set record source source add a record if we were able to create one answers add rec else addjust the numbers for the skipped record if answers size num answers num answers else if answers size num answers num authorities num authorities else if answers size num answers num authorities num additionals num additionals off end catch io exception e logger log level warning dns incoming dump print true n exception e throw e dnsincoming datagrampacket ioexception inetaddress getaddress getdata getlength getoffset empty_list empty_list receivedtime currenttimemillis readunsignedshort readunsignedshort numquestions readunsignedshort numanswers readunsignedshort numauthorities readunsignedshort numadditionals readunsignedshort numquestions synchronizedlist arraylist numquestions numquestions dnsquestion dnsquestion readname readunsignedshort readunsignedshort numanswers numauthorities numadditionals synchronizedlist arraylist readname readunsignedshort readunsignedshort readint readunsignedshort dnsrecord dnsconstants type_a ipv4 dnsconstants type_aaaa ipv6 dnsrecord readbytes dnsconstants type_cname dnsconstants type_ptr readname ioexception printstacktrace dnsrecord dnsconstants type_txt dnsrecord readbytes dnsconstants type_srv readunsignedshort readunsignedshort readunsignedshort bonjourconformancetest use_domain_name_format_for_srv_target readname readnonnamestring ioexception printstacktrace dnsrecord dnsconstants type_hinfo dnsincoming setrecordsource numanswers numanswers numanswers numauthorities numauthorities numanswers numauthorities numadditionals numadditionals ioexception dnsincoming check if the message is a query boolean is query return flags dns constants flags qr mask dns constants flags qr query isquery dnsconstants flags_qr_mask dnsconstants flags_qr_query check if the message is truncated public boolean is truncated return flags dns constants flags tc 0 istruncated dnsconstants flags_tc check if the message is a response boolean is response return flags dns constants flags qr mask dns constants flags qr response isresponse dnsconstants flags_qr_mask dnsconstants flags_qr_response private int get int off throws io exception if off 0 off len throw new io exception parser error offset off return data off 0xff ioexception ioexception private int read unsigned short throws io exception return get off 8 get off readunsignedshort ioexception private int read int throws io exception return read unsigned short 16 read unsigned short readint ioexception readunsignedshort readunsignedshort private byte read bytes int off int len throws io exception byte bytes new byte len system arraycopy data off bytes 0 len return bytes readbytes ioexception private void readutf string buffer buf int off int len throws io exception for int end off len off end int ch get off switch ch 4 case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 0xxxxxxx break case 12 case 13 110x xxxx 10xx xxxx ch ch 0x1f 6 get off 0x3f break case 14 1110 xxxx 10xx xxxx 10xx xxxx ch ch 0x0f 12 get off 0x3f 6 get off 0x3f break default 10xx xxxx 1111 xxxx ch ch 0x3f 4 get off 0x0f break buf append char ch stringbuffer ioexception private string read non name string throws io exception string buffer buf new string buffer int off this off int len get off readutf buf off len return buf to string readnonnamestring ioexception stringbuffer stringbuffer tostring private string read name throws io exception string buffer buf new string buffer int off this off int next 1 int first off while true int len get off if len 0 break switch len 0xc0 case 0x00 buf append off readutf buf off len off len buf append break case 0xc0 buf append off 1 if next 0 next off 1 off len 0x3f 8 get off if off first throw new io exception bad domain name possible circular name detected name start first bad offset 0x integer to hex string off first off break default throw new io exception unsupported dns label type integer to hex string len 0xc0 at off 1 this off next 0 next off return buf to string readname ioexception stringbuffer stringbuffer ioexception tohexstring ioexception tohexstring tostring debugging string print boolean dump string buffer buf new string buffer buf append to string n for iterator iterator questions iterator iterator has next buf append ques iterator next n int count 0 for iterator iterator answers iterator iterator has next count if count num answers buf append answ else if count num answers num authorities buf append auth else buf append addi buf append iterator next n if dump for int off 0 len packet get length off len off 32 int n math min 32 len off if off 10 buf append if off 100 buf append buf append off buf append for int i 0 i n i if i 8 0 buf append buf append integer to hex string data off i 0xf0 4 buf append integer to hex string data off i 0x0f 0 buf append n buf append for int i 0 i n i if i 8 0 buf append buf append int ch data off i 0xff buf append ch ch 127 char ch buf append n limit message size if off 32 256 buf append n break return buf to string stringbuffer stringbuffer tostring hasnext hasnext numanswers numanswers numauthorities getlength tohexstring tohexstring tostring public string to string string buffer buf new string buffer buf append is query dns query dns response if packet get address null buf append packet get address get host address buf append buf append packet get port buf append len buf append packet get length buf append id 0x buf append integer to hex string id if flags 0 buf append flags 0x buf append integer to hex string flags if flags dns constants flags qr response 0 buf append r if flags dns constants flags aa 0 buf append aa if flags dns constants flags tc 0 buf append tc if num questions 0 buf append questions buf append num questions if num answers 0 buf append answers buf append num answers if num authorities 0 buf append authorities buf append num authorities if num additionals 0 buf append additionals buf append num additionals buf append return buf to string tostring stringbuffer stringbuffer isquery getaddress getaddress gethostaddress getport getlength tohexstring tohexstring dnsconstants flags_qr_response dnsconstants flags_aa dnsconstants flags_tc numquestions numquestions numanswers numanswers numauthorities numauthorities numadditionals numadditionals tostring appends answers to this incoming throws illegal argument exception if not a query or if truncated void append dns incoming that if this is query this is truncated that is query if that num questions 0 if collections empty list equals this questions this questions collections synchronized list new array list that num questions this questions add all that questions this num questions that num questions if collections empty list equals answers answers collections synchronized list new array list if that num answers 0 this answers add all this num answers that answers sub list 0 that num answers this num answers that num answers if that num authorities 0 this answers add all this num answers this num authorities that answers sub list that num answers that num answers that num authorities this num authorities that num authorities if that num additionals 0 this answers add all that answers sub list that num answers that num authorities that num answers that num authorities that num additionals this num additionals that num additionals else throw new illegal argument exception illegalargumentexception dnsincoming isquery istruncated isquery numquestions empty_list synchronizedlist arraylist numquestions addall numquestions numquestions empty_list synchronizedlist arraylist numanswers addall numanswers sublist numanswers numanswers numanswers numauthorities addall numanswers numauthorities sublist numanswers numanswers numauthorities numauthorities numauthorities numadditionals addall sublist numanswers numauthorities numanswers numauthorities numadditionals numadditionals numadditionals illegalargumentexception public int elapse since arrival return int system current time millis received time elapsesincearrival currenttimemillis receivedtime public list get questions return questions getquestions public list get answers return answers getanswers creates an identity inserter param db a reference to the database param client a reference to an link high level simple client to perform inserts param tbf needed to create buckets from identities before insert public identity inserter wot my wot super my wot get plugin respirator get node my wot get plugin respirator gethl simple client wot identity inserter m wot my wot m random m wot get plugin respirator get node fast weak random start identityinserter highlevelsimpleclient identityinserter mywot mywot getpluginrespirator getnode mywot getpluginrespirator gethlsimpleclient mwot mywot mrandom mwot getpluginrespirator getnode fastweakrandom override protected collection client getter create fetch storage return null clientgetter createfetchstorage override protected collection base client putter create insert storage return new array list base client putter 10 10 identities should be much baseclientputter createinsertstorage arraylist baseclientputter override public int get priority return native thread low priority getpriority nativethread low_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period override protected void iterate abort inserts synchronized m wot for own identity identity m wot get all own identities if identity needs insert try long min delayed insert time identity get last change date get time min delay before insert long max delayed insert time identity get last insert date get time max delay before insert if current timeutc get in millis math min min delayed insert time max delayed insert time logger debug this starting insert of identity get nickname identity get inserturi insert identity else long last change before current timeutc get in millis identity get last change date get time 60 1000 long last insert before current timeutc get in millis identity get last insert date get time 60 1000 logger debug this delaying insert of identity get nickname identity get inserturi last change last change before min ago last insert last insert before min ago catch exception e logger error this identity insert failed e get message e abortinserts mwot ownidentity mwot getallownidentities needsinsert mindelayedinserttime getlastchangedate gettime min_delay_before_insert maxdelayedinserttime getlastinsertdate gettime max_delay_before_insert currenttimeutc getinmillis mindelayedinserttime maxdelayedinserttime getnickname getinserturi lastchangebefore currenttimeutc getinmillis getlastchangedate gettime lastinsertbefore currenttimeutc getinmillis getlastinsertdate gettime getnickname getinserturi lastchangebefore lastinsertbefore getmessage inserts an own identity throws io exception private void insert own identity identity throws io exception bucket tempb mtbf make bucket 64 1024 fixme tweak output stream os null try os tempb get output stream m wot getxml transformer export own identity identity os os close os null tempb set read only long edition identity get edition if identity get last insert date after new date 0 edition fixme toad are these parameters correct insert block ib new insert block tempb null identity get inserturi set suggested edition edition insert context ictx m client get insert context true fixme are these parameters correct client putter pu m client insert ib false null false ictx this fixme set to a reasonable value before release plugin manager default is interactive priority pu set priority class request starter update priority class add insert pu tempb null logger debug this started insert of identity identity get nickname catch exception e logger error this error during insert of identity identity get nickname e finally if tempb null tempb free closer close os ownidentity ioexception ownidentity ioexception makebucket outputstream getoutputstream mwot getxmltransformer exportownidentity setreadonly getedition getlastinsertdate insertblock insertblock getinserturi setsuggestededition insertcontext mclient getinsertcontext clientputter mclient pluginmanager setpriorityclass requeststarter update_priority_class addinsert getnickname getnickname public void on success base client putter state object container container logger debug this successful insert of identity state geturi try synchronized m wot own identity identity m wot get own identity byuri state geturi identity set edition state geturi get edition identity update last insert date m wot store and commit identity catch exception e logger error this error e finally remove insert state onsuccess baseclientputter objectcontainer mwot ownidentity mwot getownidentitybyuri setedition getedition updatelastinsertdate mwot storeandcommit removeinsert public void on failure insert exception e base client putter state object container container if e get mode insert exception cancelled logger debug this insert cancelled state geturi return try logger error this error during insert of identity state geturi e we do not increase the edition of the identity if there is a collision because the fetcher will fetch the new edition and the inserter will insert it with that edition in the next run finally remove insert state onfailure insertexception baseclientputter objectcontainer getmode insertexception removeinsert not needed functions from the client callback interface public void on failure fetch exception e client getter state object container container todo auto generated method stub clientcallback onfailure fetchexception clientgetter objectcontainer public void on fetchable base client putter state object container container todo auto generated method stub onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container todo auto generated method stub ongenerateduri baseclientputter objectcontainer public void on major progress object container container todo auto generated method stub onmajorprogress objectcontainer public void on success fetch result result client getter state object container container todo auto generated method stub onsuccess fetchresult clientgetter objectcontainer final string identifier generatessk message simple field set fs identifier fs get identifier generatesskmessage simplefieldset override public simple field set get field set simple field set fs new simple field set true if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception insertable clientssk key insertable clientssk create random node random freeneturi inserturi key get inserturi freeneturi requesturi key geturi ssk keypair message msg new ssk keypair message inserturi requesturi identifier handler output handler queue msg fcpconnectionhandler messageinvalidexception insertableclientssk insertableclientssk createrandom getinserturi sskkeypairmessage sskkeypairmessage outputhandler override public void remove from object container container container delete this removefrom objectcontainer called upon plugin unloading we unregister advertised services public synchronized void terminate jmdns close goon false notify all notifyall public void run plugin plugin respirator pr this pr pr wait until the node is initialised while pr get node null pr get node is has started try thread sleep 1000 catch interrupted exception e node config pr get node config our advertised services new linked list our disabled services new linked list found nodes new linked list final service info fproxy info tmci info fcp info node info try create the multicast listener jmdns jmdns create final string address server pr get node get my name watch out for other nodes jmdns add service listener mdns discovery freenet service type new nodemdns listener this advertise fproxy fproxy info service info create http tcp local truncate and sanitize freenet 0 7 fproxy address node config get fproxy get int port 0 0 path if node config get fproxy get boolean enabled node config get fproxy get option bind to is default jmdns register service fproxy info our advertised services add fproxy info else our disabled services add fproxy info advertise fcp fcp info service info create fcp tcp local truncate and sanitize freenet 0 7 fcp address node config get fcp get int port 0 0 if node config get fcp get boolean enabled node config get fcp get option bind to is default jmdns register service fcp info our advertised services add fcp info else our disabled services add fcp info advertise tmci tmci info service info create telnet tcp local truncate and sanitize freenet 0 7 tmci address node config get console get int port 0 0 if node config get console get boolean enabled node config get console get option bind to is default jmdns register service tmci info our advertised services add tmci info else our disabled services add tmci info advertise the node node info service info create mdns discovery freenet service type truncate and sanitize freenet 0 7 node address node config get node get int listen port 0 0 jmdns register service node info our advertised services add node info catch io exception e e print stack trace while goon synchronized this try wait long max value catch interrupted exception e runplugin pluginrespirator getnode getnode ishasstarted interruptedexception nodeconfig getnode ouradvertisedservices linkedlist ourdisabledservices linkedlist foundnodes linkedlist serviceinfo fproxyinfo tmciinfo fcpinfo nodeinfo getnode getmyname addservicelistener mdnsdiscovery freenetservicetype nodemdnslistener fproxyinfo serviceinfo _http _tcp truncateandsanitize nodeconfig getint nodeconfig getboolean nodeconfig getoption bindto isdefault registerservice fproxyinfo ouradvertisedservices fproxyinfo ourdisabledservices fproxyinfo fcpinfo serviceinfo _fcp _tcp truncateandsanitize nodeconfig getint nodeconfig getboolean nodeconfig getoption bindto isdefault registerservice fcpinfo ouradvertisedservices fcpinfo ourdisabledservices fcpinfo tmciinfo serviceinfo _telnet _tcp truncateandsanitize nodeconfig getint nodeconfig getboolean nodeconfig getoption bindto isdefault registerservice tmciinfo ouradvertisedservices tmciinfo ourdisabledservices tmciinfo nodeinfo serviceinfo mdnsdiscovery freenetservicetype truncateandsanitize nodeconfig getint listenport registerservice nodeinfo ouradvertisedservices nodeinfo ioexception printstacktrace max_value interruptedexception final mdns discovery plugin public nodemdns listener mdns discovery plugin this plugin plugin mdnsdiscovery nodemdnslistener mdnsdiscovery public void service added service event event system out println service added event get name event get type force the gathering of informations jmdns get service info mdns discovery freenet service type event get name synchronized plugin plugin notify serviceadded serviceevent getname gettype getserviceinfo mdnsdiscovery freenetservicetype getname public void service removed service event event system out println service removed event get name event get type if mdns discovery freenet service type equals event get type synchronized found nodes iterator it found nodes iterator service info to remove event get info while it has next service info si service info it next if to remove equals si found nodes remove si synchronized plugin plugin notify serviceremoved serviceevent getname gettype mdnsdiscovery freenetservicetype gettype foundnodes foundnodes serviceinfo toremove getinfo hasnext serviceinfo serviceinfo toremove foundnodes public void service resolved service event event system out println service resolved event get info if mdns discovery freenet service type equals event get type synchronized found nodes found nodes add event get info synchronized plugin plugin notify serviceresolved serviceevent getinfo mdnsdiscovery freenetservicetype gettype foundnodes foundnodes getinfo private void print services html node content node string description service info services html node peer table infobox content node add child div class infobox infobox services length 0 normal warning html node peer table infobox header peer table infobox add child div class infobox header html node peer table infobox content peer table infobox add child div class infobox content if services null services length 0 peer table infobox header add child description html node peer table peer table infobox content add child table class darknet connections html node peer table header row peer table add child tr peer table header row add child th add child span new string title style new string the name or the service border bottom 1px dotted cursor help service name peer table header row add child th add child span new string title style new string the name of the machine hosting the service border bottom 1px dotted cursor help machine peer table header row add child th add child span new string title style new string the node s network address as ip port border bottom 1px dotted cursor help address peer table header row add child th add child span new string title style new string service parameters border bottom 1px dotted cursor help parameters html node peer row string mdns service mdns server mdns host mdns port mdns description for int i 0 i services length i peer row peer table add child tr service info info services i mdns service info get name mdns server info get server mdns host info get host address mdns port integer to string info get port mdns description info get text string peer row add child td class peer name add child mdns service null null mdns service peer row add child td class peer machine add child mdns server null null mdns server peer row add child td class peer address add child mdns host null null mdns host mdns port null null mdns port peer row add child td class peer private darknet comment note add child mdns description null mdns description else peer table infobox header add child description peer table infobox content add child no freenet resources found on the local subnet sorry printservices htmlnode contentnode serviceinfo htmlnode peertableinfobox contentnode addchild htmlnode peertableinfoboxheader peertableinfobox addchild htmlnode peertableinfoboxcontent peertableinfobox addchild peertableinfoboxheader addchild htmlnode peertable peertableinfoboxcontent addchild darknet_connections htmlnode peertableheaderrow peertable addchild peertableheaderrow addchild addchild peertableheaderrow addchild addchild peertableheaderrow addchild addchild peertableheaderrow addchild addchild htmlnode peerrow mdnsservice mdnsserver mdnshost mdnsport mdnsdescription peerrow peertable addchild serviceinfo mdnsservice getname mdnsserver getserver mdnshost gethostaddress mdnsport tostring getport mdnsdescription gettextstring peerrow addchild addchild mdnsservice mdnsservice peerrow addchild addchild mdnsserver mdnsserver peerrow addchild addchild mdnshost mdnshost mdnsport mdnsport peerrow addchild addchild mdnsdescription mdnsdescription peertableinfoboxheader addchild peertableinfoboxcontent addchild public string handlehttp get http request request throws pluginhttp exception html node page node pr get page maker get page node mdns discovery plugin configuration page false null html node content node pr get page maker get content node page node print services content node the following services are being broadcast from this node service info our advertised services to array new service info our advertised services size synchronized found nodes if found nodes size 0 print services content node the following nodes have been found on the local subnet service info found nodes to array new service info found nodes size if our advertised services size 3 html node disabled services infobox content node add child div class infobox infobox normal html node disabled services infobox header disabled services infobox add child div class infobox header html node disabled services infobox content disabled services infobox add child div class infobox content disabled services infobox header add child disabled services disabled services infobox content add child the following services won t be advertised on the local network because they are either disabled ot bound to the local interface html node disabled services list disabled services infobox content add child ul id disabled service list for int i 0 i our disabled services size i disabled services list add child li add child service info our disabled services get i get name return page node generate handlehttpget httprequest pluginhttpexception htmlnode pagenode getpagemaker getpagenode mdnsdiscovery htmlnode contentnode getpagemaker getcontentnode pagenode printservices contentnode serviceinfo ouradvertisedservices toarray serviceinfo ouradvertisedservices foundnodes foundnodes printservices contentnode serviceinfo foundnodes toarray serviceinfo foundnodes ouradvertisedservices htmlnode disabledservicesinfobox contentnode addchild htmlnode disabledservicesinfoboxheader disabledservicesinfobox addchild htmlnode disabledservicesinfoboxcontent disabledservicesinfobox addchild disabledservicesinfoboxheader addchild disabledservicesinfoboxcontent addchild htmlnode disabledserviceslist disabledservicesinfoboxcontent addchild ourdisabledservices disabledserviceslist addchild addchild serviceinfo ourdisabledservices getname pagenode public string handlehttp post http request request throws pluginhttp exception return null handlehttppost httprequest pluginhttpexception function used to sanitize a service name it ought to be less than 63 char long and shouldn t contain param the string to sanitize return a sanitized string private string truncate and sanitize string str int index of dot do index of dot str index of if index of dot 1 break str str substring 0 index of dot str substring index of dot 1 while true if str length 62 str str substring 0 62 return str truncateandsanitize indexofdot indexofdot indexof indexofdot indexofdot indexofdot public long get real version return version getrealversion public list peer notes message simple field set fs this fs fs this identifier fs get identifier fs remove value identifier listpeernotesmessage simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied list peer notes requires full access identifier false string node identifier fs get node identifier if node identifier null throw new message invalid exception protocol error message missing field error node identifier field missing identifier false peer node pn node get peer node node identifier if pn null fcp message msg new unknown node identifier message node identifier identifier handler output handler queue msg return if pn instanceof darknet peer node throw new message invalid exception protocol error message darknet only modify peer only available for darknet peers identifier false darknet peer node dpn darknet peer node pn fixme this should be generalized for multiple peer notes per peer after peer node is similarly generalized string note text dpn get private darknet comment note handler output handler queue new peer note node identifier note text node peer note type private darknet comment identifier handler output handler queue new end list peer notes message node identifier identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied listpeernotes nodeidentifier nodeidentifier nodeidentifier messageinvalidexception protocolerrormessage missing_field nodeidentifier peernode getpeernode nodeidentifier fcpmessage unknownnodeidentifiermessage nodeidentifier outputhandler darknetpeernode messageinvalidexception protocolerrormessage darknet_only modifypeer darknetpeernode darknetpeernode peernode notetext getprivatedarknetcommentnote outputhandler peernote nodeidentifier notetext peer_note_type_private_darknet_comment outputhandler endlistpeernotesmessage nodeidentifier override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private node service node public node get service node return service node servicenode getservicenode servicenode public service get service node service node get service node if service node null return null return new service service node getservice servicenode getservicenode servicenode servicenode public node get state variable node return state variable node getstatevariablenode statevariablenode public state variable this service node null this state variable node new node statevariable servicenode statevariablenode public state variable node service node node state var node this service node service node this state variable node state var node statevariable servicenode statevarnode servicenode servicenode statevariablenode statevarnode public static boolean is state variable node node node return state variable elem name equals node get name isstatevariablenode statevariable elem_name getname private final static string name name public void set name string value get state variable node set node name value setname getstatevariablenode setnode public string get name return get state variable node get node value name getname getstatevariablenode getnodevalue private final static string datatype data type public void set data type string value get state variable node set node datatype value datatype setdatatype getstatevariablenode setnode public string get data type return get state variable node get node value datatype getdatatype getstatevariablenode getnodevalue private final static string sendevents no no public void set send events boolean state get state variable node set attribute sendevents state true sendevents yes sendevents no sendevents_no setsendevents getstatevariablenode setattribute sendevents_yes sendevents_no public boolean is send events string state get state variable node get attribute value sendevents if state null return false if state equals ignore case sendevents yes true return true return false issendevents getstatevariablenode getattributevalue equalsignorecase sendevents_yes public void set state variable state var set name state var get name set value state var get value set data type state var get data type set send events state var is send events statevariable statevar setname statevar getname setvalue statevar getvalue setdatatype statevar getdatatype setsendevents statevar issendevents public state variable data get state variable data node node get state variable node state variable data user data state variable data node get user data if user data null user data new state variable data node set user data user data user data set node node return user data statevariabledata getstatevariabledata getstatevariablenode statevariabledata userdata statevariabledata getuserdata userdata userdata statevariabledata setuserdata userdata userdata setnode userdata public void set value string value thnaks for tho beisch 11 09 04 string curr value get state variable data get value thnaks for tho rick keiner 11 18 04 if curr value null curr value equals value true return get state variable data set value value notify event service service get service if service null return if is send events false return service notify this setvalue currvalue getstatevariabledata getvalue currvalue currvalue getstatevariabledata setvalue getservice issendevents public void set value int value set value integer to string value setvalue setvalue tostring public void set value long value set value long to string value setvalue setvalue tostring public string get value return get state variable data get value getvalue getstatevariabledata getvalue public allowed value list get allowed value list allowed value list value list new allowed value list node value list node get state variable node get node allowed value list elem name if value list node null return value list int n node value list node getn nodes for int n 0 n n node n node node value list node get node n if allowed value is allowed value node node false continue allowed value allowed val new allowed value node value list add allowed val return value list allowedvaluelist getallowedvaluelist allowedvaluelist valuelist allowedvaluelist valuelistnode getstatevariablenode getnode allowedvaluelist elem_name valuelistnode valuelist nnode valuelistnode getnnodes nnode valuelistnode getnode allowedvalue isallowedvaluenode allowedvalue allowedval allowedvalue valuelist allowedval valuelist public boolean has allowed value list allowed value list value list get allowed value list return 0 value list size true false hasallowedvaluelist allowedvaluelist valuelist getallowedvaluelist valuelist public allowed value range get allowed value range node value range node get state variable node get node allowed value range elem name if value range node null return null return new allowed value range value range node allowedvaluerange getallowedvaluerange valuerangenode getstatevariablenode getnode allowedvaluerange elem_name valuerangenode allowedvaluerange valuerangenode public boolean has allowed value range return get allowed value range null true false hasallowedvaluerange getallowedvaluerange public query listener get query listener return get state variable data get query listener querylistener getquerylistener getstatevariabledata getquerylistener public void set query listener query listener listener get state variable data set query listener listener setquerylistener querylistener getstatevariabledata setquerylistener public boolean perform query listener query request query req query listener listener get query listener if listener null return false query response query res new query response state variable ret var new state variable ret var set this ret var set value ret var set status u pnp status invalid var if listener query control received ret var true query res set response ret var else u pnp status upnp status ret var get status query res set fault response upnp status get code upnp status get description query req post query res return true performquerylistener queryrequest queryreq querylistener getquerylistener queryresponse queryres queryresponse statevariable retvar statevariable retvar retvar setvalue retvar setstatus upnpstatus invalid_var querycontrolreceived retvar queryres setresponse retvar upnpstatus upnpstatus retvar getstatus queryres setfaultresponse upnpstatus getcode upnpstatus getdescription queryreq queryres public query response get query response return get state variable data get query response queryresponse getqueryresponse getstatevariabledata getqueryresponse private void set query response query response res get state variable data set query response res setqueryresponse queryresponse getstatevariabledata setqueryresponse public u pnp status get query status return get query response getu pnp error upnpstatus getquerystatus getqueryresponse getupnperror public boolean post queryl action query request query req new query request query req set request this if debug is on true query req print query response query res query req post if debug is on true query res print set query response query res thanks for dimas cyberrate users sourceforge net and stefano lenzi kismet sl users sourceforge net 07 09 04 if query res is successful false set value query res get return value return false set value query res get return value return true postquerylaction queryrequest queryreq queryrequest queryreq setrequest ison queryreq queryresponse queryres queryreq ison queryres setqueryresponse queryres queryres issuccessful setvalue queryres getreturnvalue setvalue queryres getreturnvalue public void set status int code string descr upnp status set code code upnp status set description descr setstatus upnpstatus setcode upnpstatus setdescription public void set status int code set status code u pnp status code2 string code setstatus setstatus upnpstatus code2string public u pnp status get status return upnp status upnpstatus getstatus upnpstatus private final byte bits public bit array byte data bits data size data length 8 _bits bitarray _bits _size this constructor does not check for unacceptable sizes and should only be used on trusted data public bit array data input dis throws io exception size dis read int bits new byte size 8 size 8 0 0 1 dis read fully bits bitarray datainput ioexception _size readint _bits _size _size readfully _bits public bit array data input dis int max size throws io exception size dis read int if size 0 size max size throw new io exception unacceptable bitarray size size bits new byte size 8 size 8 0 0 1 dis read fully bits bitarray datainput maxsize ioexception _size readint _size _size maxsize ioexception _size _bits _size _size readfully _bits public bit array int size size size bits new byte size 8 size 8 0 0 1 bitarray _size _bits public bit array bit array src this size src size this bits new byte src bits length system arraycopy src bits 0 bits 0 src bits length bitarray bitarray _size _size _bits _bits _bits _bits _bits public void set bit int pos boolean f int b unsigned byte to int bits pos 8 int mask 1 pos 8 if f bits pos 8 byte b mask else bits pos 8 byte b mask setbit unsignedbytetoint _bits _bits _bits public boolean bit at int pos int b unsigned byte to int bits pos 8 int mask 1 pos 8 return b mask 0 bitat unsignedbytetoint _bits public static int unsigned byte to int byte b return b 0xff unsignedbytetoint override public string to string string builder sb new string builder this size for int x 0 x size x if bit at x sb append 1 else sb append 0 return sb to string tostring stringbuilder stringbuilder _size _size bitat tostring public void write to data output stream data output stream dos throws io exception dos write int size dos write bits writetodataoutputstream dataoutputstream ioexception writeint _size _bits public static int serialized length int size return size 8 size 8 0 0 1 4 serializedlength public int get size return size getsize _size override public boolean equals object o if o instanceof bit array return false bit array ba bit array o if ba get size get size return false for int x 0 x get size x if ba bit at x bit at x return false return true bitarray bitarray bitarray getsize getsize getsize bitat bitat override public int hash code return fields hash code bits hashcode hashcode _bits public void set all ones for int i 0 i bits length i bits i byte 0xff setallones _bits _bits public int first one for int i 0 i bits length i byte b bits i if b 0 continue for int j 0 j 8 j int mask 1 j if b mask 0 int x i 8 j if x size return 1 return x return 1 firstone _bits _bits _size public int compare to object o long po page o offs return offs po 1 offs po 0 1 compareto page data new byte page size pagesize public void run plugin plugin respirator pr2 logger error this start pr pr2 pm pr get page maker pm add navigation link fproxy back to fpoxy false null client pr gethl simple client fcp pr get node client core getfcp server runplugin pluginrespirator getpagemaker addnavigationlink gethlsimpleclient getnode clientcore getfcpserver public void terminate private html node create error box string title string errmsg html node error box pm get infobox infobox alert title error box add child errmsg return error box htmlnode createerrorbox htmlnode errorbox getinfobox errorbox addchild errorbox public string handlehttp get http request request throws pluginhttp exception string uri request get param key if uri trim length 0 return make uri page return make index page uri false handlehttpget httprequest pluginhttpexception getparam makeuripage makeindexpage public string handlehttp post http request request throws pluginhttp exception string pass request get part as string form password 32 if pass length 0 pass equals pr get node client core form password return make error page buh invalid form password string uri request get part as string key 1024 if uri trim length 0 return make uri page if request get part as string add 128 length 0 string downloadkey request get part as string uri 1024 try try add to queue new freeneturi downloadkey catch malformedurl exception e logger error this todo e todo better handling an error page return make index page uri false else return make index page uri request get part as string addall 128 length 0 handlehttppost httprequest pluginhttpexception getpartasstring formpassword getnode clientcore formpassword makeerrorpage getpartasstring makeuripage getpartasstring getpartasstring tryaddtoqueue malformedurlexception makeindexpage makeindexpage getpartasstring pages private string make uri page html node page node get page node html node content node pm get content node page node content node add child create uri box return page node generate makeuripage htmlnode pagenode getpagenode htmlnode contentnode getcontentnode pagenode contentnode addchild createuribox pagenode private string make error page string error return make error page error error makeerrorpage makeerrorpage private string make error page string title string error html node page node get page node html node content node pm get content node page node content node add child create error box title error content node add child create uri box return page node generate makeerrorpage htmlnode pagenode getpagenode htmlnode contentnode getcontentnode pagenode contentnode addchild createerrorbox contentnode addchild createuribox pagenode private string make error page string title string error string new uri html node page node get page node html node content node pm get content node page node html node error box create error box title error error box add child br error box add child new html node a href self uri key new uri new uri content node add child error box content node add child create uri box return page node generate makeerrorpage newuri htmlnode pagenode getpagenode htmlnode contentnode getcontentnode pagenode htmlnode errorbox createerrorbox errorbox addchild errorbox addchild htmlnode self_uri newuri newuri contentnode addchild errorbox contentnode addchild createuribox pagenode private html node get page node return pm get page node thaw index browser null htmlnode getpagenode getpagenode private string make index page string index boolean add try freeneturi uri new freeneturi index fetch result content client fetch uri 90000 string mime content get mime type if application x freenet index equals mime return make error page wrong mime type mime expected mime type application x freenet index but found mime data here parse xml xml element xmldoc new xml element xmldoc parse from reader new input stream reader content as bucket get input stream now print the result return print index page uri xmldoc add catch malformedurl exception e logger error this invalid uri index e return make error page invalid uri index the given freenet key is invalid catch fetch exception e logger error this fetch failed for index e switch e mode case fetch exception permanent redirect case fetch exception too many path components return make error page fetch failed for index code e mode e get localized message e newuri to string case fetch exception data not found case fetch exception route not found case fetch exception rejected overload case fetch exception all data not found return make error page fetch failed for index code e mode e get localized message index default return make error page fetch failed for index code e mode e get localized message catch io exception e logger error this io error e return make error page io error io error while processing index e get localized message catch xml parse exception e logger error this debug e return make error page parser error error while processing index e get localized message catch exception e logger error this debug e return make error page error while processing index e get localized message makeindexpage fetchresult getmimetype makeerrorpage xmlelement xmlelement parsefromreader inputstreamreader asbucket getinputstream printindexpage malformedurlexception makeerrorpage fetchexception fetchexception permanent_redirect fetchexception too_many_path_components makeerrorpage getlocalizedmessage tostring fetchexception data_not_found fetchexception route_not_found fetchexception rejected_overload fetchexception all_data_not_found makeerrorpage getlocalizedmessage makeerrorpage getlocalizedmessage ioexception ioerror makeerrorpage ioerror ioerror getlocalizedmessage xmlparseexception makeerrorpage getlocalizedmessage makeerrorpage getlocalizedmessage page utils private html node create uri box html node browse box pm get infobox open an index html node browse content pm get content node browse box browse content add child display the top level chunk as hexprint html node browse form pr add form child browse content self uri uri form browse form add child index to explore u00a0 browse form add child input new string type name size new string text key 70 browse form add child u00a0 browse form add child input new string type name value new string submit debug explore return browse box htmlnode createuribox htmlnode browsebox getinfobox htmlnode browsecontent getcontentnode browsebox browsecontent addchild htmlnode browseform addformchild browsecontent self_uri uriform browseform addchild browseform addchild browseform addchild browseform addchild browsebox private string print index page freeneturi uri xml element doc boolean add html node page node get page node html node content node pm get content node page node xml element root doc html node title box pm get infobox index uri html node index box pm get infobox links html node file box pm get infobox files html node table new html node table class requests html node header row table add child tr class table header header row add child th header row add child th key name header row add child th mimetype header row add child th size boolean hasfiles false enumeration rootchilds root enumerate children while rootchilds has more elements xml element rc xml element rootchilds next element string name rc get name if header equals name enumeration headerchilds rc enumerate children string titel null string clientname null string date null string category null while headerchilds has more elements xml element he xml element headerchilds next element string hename he get name if title equals hename titel he get content else if client equals hename clientname he get content else if date equals hename date he get content else if category equals hename category he get content else logger error this unexpected xml element hename at line rc get line nr new error debug if titel null title box add child titel u00a0 titel title box add child br if clientname null title box add child client u00a0 clientname title box add child br if date null title box add child date u00a0 date title box add child br if category null title box add child category u00a0 category title box add child br else if indexes equals name enumeration indexchilds rc enumerate children while indexchilds has more elements xml element ie xml element indexchilds next element index box add child new html node a href self uri key ie get string attribute key ie get string attribute key index box add child br else if files equals name enumeration filechilds rc enumerate children hasfiles rc count children 0 while filechilds has more elements xml element fe xml element filechilds next element html node file row table add child tr string s fe get string attribute key string s1 try freeneturi u new freeneturi s if add try add to queue u if s length 100 s1 s substring 0 12 s1 s1 s substring 85 s s1 else s1 s file row add child create add cell s uri to string file row add child create cell new html node a href key s s1 catch malformedurl exception e1 file row add child new html node td file row add child create cell new html node s file row add child create cell new html node fe get string attribute mime file row add child create cell new html node fe get string attribute size html node all row table add child tr all row add child create add all cell uri to string file box add child table else if comments equals name else logger error this unexpected xml element name at line rc get line nr new error debug content node add child title box content node add child index box if hasfiles content node add child file box content node add child create uri box return page node generate printindexpage xmlelement htmlnode pagenode getpagenode htmlnode contentnode getcontentnode pagenode xmlelement htmlnode titlebox getinfobox htmlnode indexbox getinfobox htmlnode filebox getinfobox htmlnode htmlnode htmlnode headerrow addchild headerrow addchild headerrow addchild headerrow addchild headerrow addchild enumeratechildren hasmoreelements xmlelement xmlelement nextelement getname enumeratechildren hasmoreelements xmlelement xmlelement nextelement getname getcontent getcontent getcontent getcontent getlinenr titlebox addchild titlebox addchild titlebox addchild titlebox addchild titlebox addchild titlebox addchild titlebox addchild titlebox addchild enumeratechildren hasmoreelements xmlelement xmlelement nextelement indexbox addchild htmlnode self_uri getstringattribute getstringattribute indexbox addchild enumeratechildren countchildren hasmoreelements xmlelement xmlelement nextelement htmlnode filerow addchild getstringattribute tryaddtoqueue filerow addchild createaddcell tostring filerow addchild createcell htmlnode malformedurlexception filerow addchild htmlnode filerow addchild createcell htmlnode filerow addchild createcell htmlnode getstringattribute filerow addchild createcell htmlnode getstringattribute htmlnode allrow addchild allrow addchild createaddallcell tostring filebox addchild getlinenr contentnode addchild titlebox contentnode addchild indexbox contentnode addchild filebox contentnode addchild createuribox pagenode private void try add to queue final freeneturi fetchuri pr get node client core client context job runner queue new db job public void run object container container client context context try fcp make persistent global request fetchuri null forever disk container catch not allowed exception e logger normal this failed to make persistent request e e catch io exception e logger normal this failed to make persistent request e e catch throwable t unexpected and severe might even be oom just log it logger error this failed to make persistent request t t native thread high priority false tryaddtoqueue getnode clientcore clientcontext jobrunner dbjob objectcontainer clientcontext makepersistentglobalrequest notallowedexception ioexception nativethread high_priority public void run object container container client context context try fcp make persistent global request fetchuri null forever disk container catch not allowed exception e logger normal this failed to make persistent request e e catch io exception e logger normal this failed to make persistent request e e catch throwable t unexpected and severe might even be oom just log it logger error this failed to make persistent request t t objectcontainer clientcontext makepersistentglobalrequest notallowedexception ioexception private html node create add cell string key string uri html node delete node new html node td html node delete form pr add form child delete node self uri add form key hash code delete form add child input new string type name value new string hidden uri key delete form add child input new string type name value new string hidden key uri delete form add child input new string type name value new string submit add download return delete node htmlnode createaddcell htmlnode deletenode htmlnode htmlnode deleteform addformchild deletenode self_uri addform hashcode deleteform addchild deleteform addchild deleteform addchild deletenode private html node create add all cell string uri html node delete node new html node td html node delete form pr add form child delete node self uri add form all delete form add child input new string type name value new string hidden key uri delete form add child input new string type name value new string submit addall download all return delete node htmlnode createaddallcell htmlnode deletenode htmlnode htmlnode deleteform addformchild deletenode self_uri addform deleteform addchild deleteform addchild deletenode private html node create cell html node node html node cell new html node td cell add child node return cell htmlnode createcell htmlnode htmlnode htmlnode addchild public string get version return 0 1 r version get svn revision getversion getsvnrevision public long get real version return version get version getrealversion getversion public static void main string args thaw index browser tib new thaw index browser system out println system out println tib get version system out println thawindexbrowser thawindexbrowser getversion public string get string string key todo return key getstring public void set language language new language todo setlanguage newlanguage create a buffer by reading a data input stream param dis throws io exception public short buffer data input dis throws io exception data new byte dis read short length short data length start 0 dis read fully data datainputstream ioexception shortbuffer datainput ioexception _data readshort _length _data _start readfully _data create a buffer from a byte array param data public short buffer byte data start 0 if data length short max value throw new illegal argument exception too big data length length short data length data data shortbuffer _start max_value illegalargumentexception _length _data public short buffer byte data int start int length start start data data if length short max value throw new illegal argument exception length short length shortbuffer _start _data max_value illegalargumentexception _length retrieve a byte array containing the data in this buffer may be copied so don t rely on it being the internal buffer return the byte array public byte get data if start 0 length data length return data else byte r new byte length system arraycopy data start r 0 length return r getdata _start _length _data _data _length _data _start _length copy the data to a byte array param array param position public void copy to byte array int position system arraycopy data start array position length copyto _data _start _length public byte byte at int pos if pos length throw new array index out of bounds exception return data pos start byteat _length arrayindexoutofboundsexception _data _start public void write to data output stream data output stream stream throws io exception stream write short length stream write data start length writetodataoutputstream dataoutputstream ioexception writeshort _length _data _start _length override public string to string if this length 50 return buffer this length else string builder b new string builder this length 3 b append append this length append for int x 0 x this length x b append byte at x b append return b to string tostring _length _length stringbuilder stringbuilder _length _length _length byteat tostring override public boolean equals object o if this o return true if o instanceof short buffer return false final short buffer buffer short buffer o if length buffer length return false if start buffer start return false if arrays equals data buffer data return false return true shortbuffer shortbuffer shortbuffer _length _length _start _start _data _data override public int hash code return fields hash code data start length 16 hashcode hashcode _data _start _length public int get length return length getlength _length private theme string code string name string description this code code this name name this description description public static theme theme from name string css name for theme t theme values if t code equals ignore case css name t name equals ignore case css name return t return get default themefromname cssname equalsignorecase cssname equalsignorecase cssname getdefault public static theme get default return theme clean getdefault public page maker fred pluginl10n plug theme t set theme t plugin plug plugin mode true pagemaker fredpluginl10n settheme pluginmode protected page maker theme t set theme t plugin null plugin mode false pagemaker settheme pluginmode void set override file f this override f setoverride public void set theme theme theme2 if theme2 null this theme theme get default else url themeurl get class get resource staticfiles themes theme2 code theme css if themeurl null this theme theme get default else this theme theme2 settheme getdefault getclass getresource getdefault public void add navigation link string path string name string title boolean full only link enabled callback cb if plugin mode plugin null fixme invent a check on compile time log only logger error this deprecated way to use pagemaker from plugin your plugin need to implement fred pluginl10n to do so new error fixme navigation link texts add name if full only navigation link texts non full add name navigation link titles put name title navigation links put name path if cb null navigation link callbacks put name cb addnavigationlink fullonly linkenabledcallback pluginmode fredpluginl10n navigationlinktexts fullonly navigationlinktextsnonfull navigationlinktitles navigationlinks navigationlinkcallbacks fixme implement a proper way for chosing what the menu looks like upon handlehttp get post deprecated public void remove navigation link string name navigation link texts remove name navigation link texts non full remove name navigation link titles remove name navigation links remove name handlehttpget removenavigationlink navigationlinktexts navigationlinktextsnonfull navigationlinktitles navigationlinks public html node create back link toadlet context toadlet context string name string referer toadlet context get headers get referer if referer null return new html node a new string href title new string referer name name return new html node a new string href title new string javascript back name name htmlnode createbacklink toadletcontext toadletcontext toadletcontext getheaders htmlnode htmlnode public html node get page node string title toadlet context ctx return get page node title true ctx htmlnode getpagenode toadletcontext getpagenode public html node get page node string title boolean render navigation links toadlet context ctx boolean full access ctx null false ctx is allowed full access html node page node new html node html doctype html w3c dtd xhtml 1 1 en html node html node page node add child html xml lang l10n get selected language iso code html node head node html node add child head head node add child meta new string http equiv content new string content type text html charset utf 8 head node add child title title freenet if override null head node add child link new string rel href type title new string stylesheet static themes theme code theme css text css theme code else head node add child get override content for theme t theme values string theme name t code head node add child link new string rel href type media title new string alternate stylesheet static themes theme name theme css text css screen theme name html node body node html node add child body html node page div body node add child div id page html node top bar div page div add child div id topbar top bar div add child h1 title if render navigation links html node navbar div page div add child div id navbar html node navbar ul navbar div add child ul id navlist for string navigation link full access navigation link texts navigation link texts non full link enabled callback cb navigation link callbacks get navigation link if cb null cb is enabled ctx continue string navigation title navigation link titles get navigation link string navigation path navigation links get navigation link html node list item navbar ul add child li if plugin null list item add child a new string href title new string navigation path plugin get string navigation title plugin get string navigation link else list item add child a new string href title new string navigation path l10n get string navigation title l10n get string navigation link html node content div page div add child div id content head nodes put page node head node content nodes put page node content div return page node htmlnode getpagenode rendernavigationlinks toadletcontext fullaccess isallowedfullaccess htmlnode pagenode htmlnode htmldoctype htmlnode htmlnode pagenode addchild getselectedlanguage isocode htmlnode headnode htmlnode addchild headnode addchild headnode addchild headnode addchild headnode addchild getoverridecontent themename headnode addchild themename themename htmlnode bodynode htmlnode addchild htmlnode pagediv bodynode addchild htmlnode topbardiv pagediv addchild topbardiv addchild rendernavigationlinks htmlnode navbardiv pagediv addchild htmlnode navbarul navbardiv addchild navigationlink fullaccess navigationlinktexts navigationlinktextsnonfull linkenabledcallback navigationlinkcallbacks navigationlink isenabled navigationtitle navigationlinktitles navigationlink navigationpath navigationlinks navigationlink htmlnode listitem navbarul addchild listitem addchild navigationpath getstring navigationtitle getstring navigationlink listitem addchild navigationpath getstring navigationtitle getstring navigationlink htmlnode contentdiv pagediv addchild headnodes pagenode headnode contentnodes pagenode contentdiv pagenode returns the head node belonging to the given page node this method has to be called before link get content node html node param page node the page node to retrieve the head node for return the head node or code null code if code page node code is not a valid page node or link get content node html node has already been called public html node get head node html node page node return head nodes remove page node getcontentnode htmlnode pagenode pagenode getcontentnode htmlnode htmlnode getheadnode htmlnode pagenode headnodes pagenode returns the content node that belongs to the specified node the node has to be a node that was earlier retrieved by a call to one of the link get page node string toadlet context or link get infobox string string methods p strong warning strong this method can only be called once param node the page node to get the content node for return the content node for the specified page node public html node get content node html node node head nodes remove node return content nodes remove node getpagenode toadletcontext getinfobox htmlnode getcontentnode htmlnode headnodes contentnodes public html node get infobox string header if header null throw new null pointer exception return get infobox new html node header htmlnode getinfobox nullpointerexception getinfobox htmlnode public html node get infobox html node header if header null throw new null pointer exception return get infobox null header htmlnode getinfobox htmlnode nullpointerexception getinfobox public html node get infobox string category string header if header null throw new null pointer exception return get infobox category new html node header htmlnode getinfobox nullpointerexception getinfobox htmlnode returns an infobox with the given style and header if you retrieve an infobox from this method be sure to retrieve the matching content node with link get content node html node otherwise your layout will be destroyed and you will get memory leaks param category the css styles separated by a space param header the header html node return the infobox public html node get infobox string category html node header if header null throw new null pointer exception html node infobox new html node div class infobox category null category infobox add child div class infobox header add child header content nodes put infobox infobox add child div class infobox content return infobox getcontentnode htmlnode htmlnode getinfobox htmlnode nullpointerexception htmlnode htmlnode addchild addchild contentnodes addchild private html node get override content html node result new html node style type text css try result add child file util readutf override catch io exception e logger error this got an ioe e get message e return result htmlnode getoverridecontent htmlnode htmlnode addchild fileutil ioexception getmessage protected int draw mode selection array node client core core http request req html node content node return draw mode selection array core req content node 1 null null drawmodeselectionarray nodeclientcore httprequest htmlnode contentnode drawmodeselectionarray contentnode protected int draw mode selection array node client core core http request req html node content node int alternate mode string alternate mode title key string alternate mode tooltip key mode can be changed by a link not just by the default int mode core is advanced mode enabled mode advanced mode simple if req is parameter set mode mode req get int param mode mode fixme style this properly html node table content node add child table border 1 html node row table add child tr html node cell row add child td if alternate mode 1 if mode alternate mode cell add child a new string href title new string mode alternate mode l10n get string alternate mode tooltip key l10n get string alternate mode title key else cell add child b title l10n get string alternate mode tooltip key l10n get string alternate mode title key cell row add child td if mode mode simple cell add child a new string href title new string mode 1 l10n mode simple tooltip l10n mode simple else cell add child b title l10n mode simple tooltip l10n mode simple cell row add child td if mode mode advanced cell add child a new string href title new string mode 2 l10n mode advanced tooltip l10n mode advanced else cell add child b title l10n mode advanced tooltip l10n mode advanced return mode drawmodeselectionarray nodeclientcore httprequest htmlnode contentnode alternatemode alternatemodetitlekey alternatemodetooltipkey isadvancedmodeenabled mode_advanced mode_simple isparameterset getintparam htmlnode contentnode addchild htmlnode addchild htmlnode addchild alternatemode alternatemode addchild alternatemode getstring alternatemodetooltipkey getstring alternatemodetitlekey addchild getstring alternatemodetooltipkey getstring alternatemodetitlekey addchild mode_simple addchild modesimpletooltip modesimple addchild modesimpletooltip modesimple addchild mode_advanced addchild modeadvancedtooltip modeadvanced addchild modeadvancedtooltip modeadvanced private static final string l10n string string return l10n get string page maker string getstring pagemaker create a new puzzle for curren timeutc get with an index set to a free index of the given inserter the free index shall be queried from the given introduction puzzle store store it in the puzzle store and return it param store the introduction puzzle store where the puzzle shall be stored param inserter the inserter of the puzzle return the new puzzle throws io exception currentimeutc introductionpuzzlestore introductionpuzzlestore ioexception protected boolean initialized false public transfer filter can filter index color model true transferfilter canfilterindexcolormodel override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r r table r g g table g b b table b return a r 16 g 8 b rtable gtable btable override public buffered image filter buffered image src buffered image dst if initialized initialize return super filter src dst bufferedimage bufferedimage bufferedimage protected void initialize initialized true r table g table b table make table rtable gtable btable maketable protected int make table int table new int 256 for int i 0 i 256 i table i pixel utils clamp int 255 transfer function i 255 0f return table maketable pixelutils transferfunction protected float transfer function float v return 0 transferfunction public int getlut if initialized initialize int lut new int 256 for int i 0 i 256 i lut i filterrgb 0 0 i 24 i 16 i 8 i return lut public detectedip inet address addr short type this public address addr this nat type type this mtu 1500 inetaddress publicaddress nattype override public boolean equals object o if o instanceof detectedip return false detectedip d detectedip o return d nat type nat type d public address equals public address nattype nattype publicaddress publicaddress override public int hash code return public address hash code nat type hashcode publicaddress hashcode nattype override public string to string return public address to string nat type mtu tostring publicaddress tostring nattype public class not connected exception extends exception private static final long serial versionuid 1 public not connected exception string string super string notconnectedexception serialversionuid notconnectedexception public not connected exception super notconnectedexception public not connected exception disconnected exception e super e to string init cause e notconnectedexception disconnectedexception tostring initcause override public final synchronized throwable fill in stack trace return null fillinstacktrace public simple healing queue insert context context short prio int max running super prio new request client public boolean persistent return false public void remove from object container container throw new unsupported operation exception this ctx context this running inserters new hash map this max running max running simplehealingqueue insertcontext maxrunning requestclient removefrom objectcontainer unsupportedoperationexception runninginserters hashmap maxrunning maxrunning public simple healing queue insert context context short prio int max running super prio new request client public boolean persistent return false simplehealingqueue insertcontext maxrunning requestclient return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public boolean inner queue bucket data client context context single block inserter sbi int ctr synchronized this ctr counter if running inserters size max running return false try sbi new single block inserter this data short 1 freeneturi empty chk uri ctx this false chk block data length ctr false false false data null context false true catch throwable e logger error this caught trying to insert healing block e e return false running inserters put data sbi try sbi schedule null context if logger should log logger minor this logger minor this started healing insert ctr for data return true catch throwable e logger error this caught trying to insert healing block e e return false innerqueue clientcontext singleblockinserter runninginserters maxrunning singleblockinserter empty_chk_uri chkblock data_length runninginserters shouldlog public void queue bucket data client context context if inner queue data context data free clientcontext innerqueue override public void on major progress object container container ignore onmajorprogress objectcontainer override public freeneturi geturi return freeneturi empty chk uri empty_chk_uri override public boolean is finished return false isfinished override public void notify clients object container container client context context do nothing notifyclients objectcontainer clientcontext public void on success client put state state object container container client context context single block inserter sbi single block inserter state bucket data bucket sbi get token synchronized this running inserters remove data if logger should log logger minor this logger minor this successfully inserted healing block sbi geturi no encode for data sbi token data free onsuccess clientputstate objectcontainer clientcontext singleblockinserter singleblockinserter gettoken runninginserters shouldlog geturinoencode public void on failure insert exception e client put state state object container container client context context single block inserter sbi single block inserter state bucket data bucket sbi get token synchronized this running inserters remove data if logger should log logger minor this logger minor this failed to insert healing block sbi geturi no encode e for data sbi token e data free onfailure insertexception clientputstate objectcontainer clientcontext singleblockinserter singleblockinserter gettoken runninginserters shouldlog geturinoencode public void on encode base client key usk client put state state object container container client context context ignore onencode baseclientkey clientputstate objectcontainer clientcontext public void on transition client put state old state client put state new state object container container should never happen logger error this impossible on transition on simple healing queue from old state to new state new exception debug ontransition clientputstate oldstate clientputstate newstate objectcontainer ontransition simplehealingqueue oldstate newstate public void on metadata metadata m client put state state object container container client context context should never happen logger error this got metadata on simple healing queue from state m new exception debug onmetadata clientputstate objectcontainer clientcontext simplehealingqueue public void on block set finished client put state state object container container client context context ignore onblocksetfinished clientputstate objectcontainer clientcontext public void on fetchable client put state state object container container ignore onfetchable clientputstate objectcontainer override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext override public void cancel object container container client context context super cancel objectcontainer clientcontext public class null string callback extends string callback override public string get return nullstringcallback stringcallback override public void set string val throws invalid config value exception ignore invalidconfigvalueexception creates a new identity fetcher param db a reference to the database param client a reference to a link high level simple client protected identity fetcher wot my wot m wot my wot client context m wot get plugin respirator get node client core client context client m wot get plugin respirator gethl simple client request client m wot get request client identityfetcher highlevelsimpleclient identityfetcher mywot mwot mywot clientcontext mwot getpluginrespirator getnode clientcore clientcontext mwot getpluginrespirator gethlsimpleclient requestclient mwot getrequestclient fetches an identity from freenet sets next edition to false by default if not specified param identity the identity to fetch public void fetch identity identity fetch identity false nextedition fetches an identity from freenet sets next edition to false by default if not specified param identity the identity to fetch param next edition whether we want to check current edition or the next one public synchronized void fetch identity identity boolean next edition todo check whether we should increase the edition in the associated client getter and restart the request or rather wait for it to finish if identities contains identity return try if next edition identity get first fetched date equals new date 0 fetch identity get requesturi set suggested edition identity get requesturi get suggested edition 1 else fetch identity get requesturi identities add identity catch fetch exception e logger error this request restart failed e e nextedition nextedition nextedition clientgetter nextedition getfirstfetcheddate getrequesturi setsuggestededition getrequesturi getsuggestededition getrequesturi fetchexception fetches a file from freenet by its uri param uri the link freeneturi we want to fetch throws fetch exception if the node encounters a problem public synchronized void fetch freeneturi uri throws fetch exception todo check whether we are downloading the uri already probably only as debug code to see if it actually happens fetch context fetch context client get fetch context fetch context max splitfile block retries 1 retry forever fetch context max non splitfile retries 1 retry forever logger debug this trying to start fetching uri uri to string client getter g client fetch uri 1 request client this fetch context fixme set to a reasonable value before release plugin manager default is interactive priority g set priority class request starter update priority class client context null requests add g fetchexception fetchexception fetchcontext fetchcontext getfetchcontext fetchcontext maxsplitfileblockretries fetchcontext maxnonsplitfileretries tostring clientgetter requestclient fetchcontext pluginmanager setpriorityclass requeststarter update_priority_class clientcontext stops all running requests protected synchronized void stop logger debug this trying to stop all requests iterator client getter i requests iterator int counter 0 while i has next i next cancel i remove counter logger debug this stopped counter current requests clientgetter hasnext private synchronized void remove request client getter g requests remove g logger debug this removed request for g geturi removerequest clientgetter private synchronized void remove identity client getter state try identities remove m wot get identity byuri state geturi catch unknown identity exception ex assert false removeidentity clientgetter mwot getidentitybyuri unknownidentityexception called when the node can t fetch a file or when there is a newer edition if this is the later we restart the request public synchronized void on failure fetch exception e client getter state object container container if e get mode fetch exception cancelled logger debug this fetch cancelled state geturi return if e mode fetch exception permanent redirect e mode fetch exception too many path components try state restart e newuri null client context catch fetch exception e1 logger error this request restart failed e1 e1 else errors we can t want deal with logger error this fetch failed for state geturi e remove request state remove identity state onfailure fetchexception clientgetter objectcontainer getmode fetchexception fetchexception permanent_redirect fetchexception too_many_path_components clientcontext fetchexception removerequest removeidentity called when a file is successfully fetched we then create an link identity parser and give it the file content public synchronized void on success fetch result result client getter state object container container logger debug this fetched identity state geturi try m wot getxml transformer import identity state geturi result as bucket get input stream catch exception e logger error this parsing failed for state geturi e try state restart state geturi set suggested edition state geturi get edition 1 null client context catch exception e logger error this error fetching next edition for state geturi identityparser onsuccess fetchresult clientgetter objectcontainer mwot getxmltransformer importidentity asbucket getinputstream setsuggestededition getedition clientcontext only called by inserts public void on success base client putter state object container container onsuccess baseclientputter objectcontainer only called by inserts public void on failure insert exception e base client putter state object container container onfailure insertexception baseclientputter objectcontainer only called by inserts public void on fetchable base client putter state object container container onfetchable baseclientputter objectcontainer only called by inserts public void on generateduri freeneturi uri base client putter state object container container ongenerateduri baseclientputter objectcontainer called when freenet async thinks that the request should be serialized to disk if it is a persistent request public void on major progress object container container onmajorprogress objectcontainer construct a lookup filter public lookup filter can filter index color model true lookupfilter lookupfilter canfilterindexcolormodel construct a lookup filter param colormap the color map public lookup filter colormap colormap can filter index color model true this colormap colormap lookupfilter lookupfilter canfilterindexcolormodel set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff rgb r g b 3 return colormap get color rgb 255 0f getcolor override public string to string return colors lookup tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog final fcp connection handler handler fcp connection input handler fcp connection handler handler this handler handler fcpconnectionhandler fcpconnectioninputhandler fcpconnectionhandler void start handler server node executor execute this fcp input handler for handler sock get remote socket address getremotesocketaddress public void run freenet support logger os thread logpid this try real run catch too long exception e logger normal this caught e get message e catch io exception e if logminor logger minor this caught e e catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t t print stack trace handler close handler closed input osthread realrun toolongexception getmessage ioexception outofmemoryerror oomhandler printstacktrace closedinput public void real run throws io exception input stream is new buffered input stream handler sock get input stream 4096 line reading input stream lis new line reading input stream is boolean first message true while true simple field set fs if wrapper manager has shutdown hook been triggered fcp message msg new protocol error message protocol error message shutting down true the node is shutting down node false handler output handler queue msg closer close is return read a message string message type lis read line 128 128 true if message type null closer close is return if message type equals continue fs new simple field set lis 4096 128 true true true true check for valid endmarker if first message fs get end marker null fs get end marker starts with end data equals fs get end marker fcp message err new protocol error message protocol error message message parse error false invalid end marker fs get end marker fs get identifer fs get boolean global false handler output handler queue err continue fcp message msg try if logdebug logger debug this incoming fcp message n message type n fs to string msg fcp message create message type fs handler bf handler server core persistent temp bucket factory if msg null continue catch message invalid exception e if first message fcp message err new protocol error message protocol error message client hello must be first message true null null false handler output handler queue err handler close closer close is return else fcp message err new protocol error message e protocol code false e get message e ident e global handler output handler queue err continue if first message msg instanceof client hello message fcp message err new protocol error message protocol error message client hello must be first message true null null false handler output handler queue err handler close closer close is return if msg instanceof base data carrying message fixme tidy up coalesce with above and below try catch mie s try base data carrying message msg read from lis handler bf handler server catch message invalid exception e fcp message err new protocol error message e protocol code false e get message e ident e global handler output handler queue err continue if first message msg instanceof client hello message fcp message err new protocol error message protocol error message no late client hellos false null null false handler output handler queue err continue try if logdebug logger debug this parsed message msg for handler msg run handler handler server node catch message invalid exception e fcp message err new protocol error message e protocol code false e get message e ident e global handler output handler queue err continue first message false if handler is closed closer close is return realrun ioexception inputstream bufferedinputstream getinputstream linereadinginputstream linereadinginputstream firstmessage simplefieldset wrappermanager hasshutdownhookbeentriggered fcpmessage protocolerrormessage protocolerrormessage shutting_down outputhandler messagetype readline messagetype messagetype simplefieldset firstmessage getendmarker getendmarker startswith getendmarker fcpmessage protocolerrormessage protocolerrormessage message_parse_error getendmarker getboolean outputhandler fcpmessage messagetype tostring fcpmessage messagetype persistenttempbucketfactory messageinvalidexception firstmessage fcpmessage protocolerrormessage protocolerrormessage client_hello_must_be_first_message outputhandler fcpmessage protocolerrormessage protocolcode getmessage outputhandler firstmessage clienthellomessage fcpmessage protocolerrormessage protocolerrormessage client_hello_must_be_first_message outputhandler basedatacarryingmessage basedatacarryingmessage readfrom messageinvalidexception fcpmessage protocolerrormessage protocolcode getmessage outputhandler firstmessage clienthellomessage fcpmessage protocolerrormessage protocolerrormessage no_late_client_hellos outputhandler messageinvalidexception fcpmessage protocolerrormessage protocolcode getmessage outputhandler firstmessage isclosed public boolean object can new object container container throw new unsupported operation exception fcp connection input handler storage in database not supported objectcannew objectcontainer unsupportedoperationexception fcpconnectioninputhandler public message reference string new messageid freeneturi newuri board my board if new messageid null newuri null my board null this instanceof own message list own message reference throw new illegal argument exception todo be more verbose m messageid new messageid muri newuri m board my board messagereference newmessageid myboard newmessageid myboard ownmessagelist ownmessagereference illegalargumentexception mmessageid newmessageid mboard myboard private transient ext object container db public void initialize transient ext object container mydb db mydb extobjectcontainer initializetransient extobjectcontainer public synchronized void store synchronized db lock if db ext is stored this db ext is active this throw new runtime exception trying to store a non active message list object db store muri db store this db commit isstored isactive runtimeexception messagelist returns null implemented only in own message list own message reference public string get messageid return m messageid ownmessagelist ownmessagereference getmessageid mmessageid public freeneturi geturi return muri public board get board return m board getboard mboard public synchronized boolean was message downloaded return i was downloaded wasmessagedownloaded iwasdownloaded marks the message reference as downloaded and stores the change in the database public synchronized void set message was downloaded flag assert i was downloaded false i was downloaded true store messagereference setmessagewasdownloadedflag iwasdownloaded iwasdownloaded public message list get message list db activate this 3 return m message list messagelist getmessagelist mmessagelist called by it s parent code message list code to store the reference to it does not call store protected void set message list message list my message list m message list my message list messagelist setmessagelist messagelist mymessagelist mmessagelist mymessagelist public message list fetch failed reference message list my message list reason my reason if my message list null my reason null throw new illegal argument exception m message list my message list m reason my reason messagelistfetchfailedreference messagelist mymessagelist myreason mymessagelist myreason illegalargumentexception mmessagelist mymessagelist mreason myreason private transient ext object container db public void initialize transient ext object container mydb db mydb extobjectcontainer initializetransient extobjectcontainer not synchronized because this class only has final members public void store db store this public message list get message list return m message list messagelist getmessagelist mmessagelist public reason get reason return m reason getreason mreason public message fetch failed reference message reference my message reference reason my reason if my message reference null my reason null throw new illegal argument exception m message reference my message reference m reason my reason messagefetchfailedreference messagereference mymessagereference myreason mymessagereference myreason illegalargumentexception mmessagereference mymessagereference mreason myreason private transient ext object container db public void initialize transient ext object container mydb db mydb extobjectcontainer initializetransient extobjectcontainer not synchronized because this class only has final members public void store db store this public message reference get message reference return m message reference messagereference getmessagereference mmessagereference public reason get reason return m reason getreason mreason param identity manager param myuri param new messages a list of the messages if a message is posted to multiple boards the list should contain one code message reference code object for each board throws invalid parameter exception throws no such identity exception public message list ft identity my author freeneturi myuri list message reference new messages throws invalid parameter exception no such identity exception this my author myuri new array list message reference new messages if m messages size 1 throw new illegal argument exception trying to construct a message list with no messages hashtable string freeneturi messageur is new hashtable string freeneturi new messages size fixme 1 limit the amount of message references 2 limit the amount of boards a single message can be posted to by counting the number of occurrences of a single freeneturi in the message reference list 3 ensure that no freeneturi board pair is twice or more in the list this would be a dos attempt see also the constraints list at the top of this file note currently wot message listxml ensures 3 by using a hash set board for message reference ref m messages ref set message list this try message verifyid m author ref get messageid catch invalid parameter exception e throw new illegal argument exception trying to create a message list which contains a message with an id which does not belong to the author of the message list freeneturi previousuri messageur is put ref get messageid ref geturi if previousuri null previousuri equals ref geturi false throw new illegal argument exception trying to create a message list which maps one message id to multiple ur is identitymanager newmessages messagereference invalidparameterexception nosuchidentityexception messagelist ftidentity myauthor messagereference newmessages invalidparameterexception nosuchidentityexception myauthor arraylist messagereference newmessages mmessages illegalargumentexception messageuris newmessages messagereferences messagereference wotmessagelistxml hashset messagereference mmessages setmessagelist mauthor getmessageid invalidparameterexception illegalargumentexception messagelist messagelist messageuris getmessageid illegalargumentexception messagelist uris for constructing an empty dummy message list when the download of message list failed param my author param myuri public message list ft identity my author freeneturi myuri this my author myuri new array list message reference 0 myauthor messagelist ftidentity myauthor myauthor arraylist messagereference general constructor for being used by public constructors protected message list ft identity my author freeneturi myuri array list message reference new messages if myuri null throw new illegal argument exception trying to construct a message list with null uri m index int myuri get edition if m index 0 throw new illegal argument exception trying to construct a message list with invalid index m index if my author null arrays equals my author get requesturi get routing key myuri get routing key false throw new illegal argument exception trying to construct a message list with a wrong author my author m author my author mid calculateid m messages new messages m message count m messages size messagelist ftidentity myauthor arraylist messagereference newmessages illegalargumentexception messagelist mindex getedition mindex illegalargumentexception mindex myauthor myauthor getrequesturi getroutingkey getroutingkey illegalargumentexception myauthor mauthor myauthor mmessages newmessages mmessagecount mmessages protected message list ft own identity my author int new index if my author null throw new illegal argument exception trying to construct a message list with no author if new index 0 throw new illegal argument exception trying to construct a message list with invalid index new index m author my author m index new index mid calculateid m messages new array list message reference 16 todo find a reasonable value messagelist ftownidentity myauthor newindex myauthor illegalargumentexception messagelist newindex illegalargumentexception newindex mauthor myauthor mindex newindex mmessages arraylist messagereference protected transient message manager m message manager public void initialize transient ext object container mydb message manager my message manager db mydb m message manager my message manager messagemanager mmessagemanager initializetransient extobjectcontainer messagemanager mymessagemanager mmessagemanager mymessagemanager public synchronized void store fixme check for duplicates synchronized db lock for message reference ref m messages ref initialize transient db ref store db store this db commit messagereference mmessages initializetransient protected string calculateid return calculateid m author m index mauthor mindex public static string calculateid ft identity author int index return index base64 encode author get requesturi get routing key ftidentity getrequesturi getroutingkey public static string getid fromuri freeneturi uri return uri get edition base64 encode uri get routing key getidfromuri getedition getroutingkey public string getid return mid get the ssk uri of this message list return public freeneturi geturi return generateuri m author get requesturi m index ssk forusk mauthor getrequesturi mindex sskforusk get the usk uri of a message list with the given base uri and index param baseuri param index return protected abstract freeneturi generateuri freeneturi baseuri int index public ft identity get author return m author ftidentity getauthor mauthor public int get index return m index getindex mindex you have to synchronize on the code message list code when using this method public iterator message reference iterator return m messages iterator messagelist messagereference mmessages public synchronized message reference get reference freeneturi messageuri throws no such message exception for message reference ref this if ref geturi equals messageuri return ref throw new no such message exception messagereference getreference nosuchmessageexception messagereference nosuchmessageexception private static final long serial versionuid 1 public unknown identity exception string message super message serialversionuid unknownidentityexception private int intor intog intob public channel mix filter can filter index color model true channelmixfilter canfilterindexcolormodel public void set blue green int blue green this blue green blue green setbluegreen bluegreen bluegreen bluegreen public int get blue green return blue green getbluegreen bluegreen public void set red blue int red blue this red blue red blue setredblue redblue redblue redblue public int get red blue return red blue getredblue redblue public void set green red int green red this green red green red setgreenred greenred greenred greenred public int get green red return green red getgreenred greenred public void set intor int intor this intor intor setintor public int get intor return intor getintor public void set intog int intog this intog intog setintog public int get intog return intog getintog public void set intob int intob this intob intob setintob public int get intob return intob getintob override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int nr pixel utils clamp intor blue green g 255 blue green b 255 255 intor r 255 int ng pixel utils clamp intog red blue b 255 red blue r 255 255 intog g 255 int nb pixel utils clamp intob green red r 255 green red g 255 255 intob b 255 return a nr 16 ng 8 nb pixelutils bluegreen bluegreen pixelutils redblue redblue pixelutils greenred greenred override public string to string return colors mix channels tostring public responder jmdns impl jmdns impl dns incoming in inet address addr int port this jmdns impl jmdns impl this in in this addr addr this port port jmdnsimpl jmdnsimpl dnsincoming inetaddress jmdnsimpl jmdnsimpl public void start according to draft cheshire dnsext multicastdns txt chapter 8 responding we respond immediately if we know for sure that we are the only one who can respond to the query in all other cases we respond within 20 120 ms according to draft cheshire dnsext multicastdns txt chapter 7 2 multi packet known answer suppression we respond after 20 120 ms if the query is truncated boolean i am the only one true for iterator i in get questions iterator i has next dns entry entry dns entry i next if entry instanceof dns question dns question q dns question entry logger finest start question q i am the only one q get type dns constants type srv q get type dns constants type txt q get type dns constants type a q get type dns constants type aaaa this jmdns impl get local host get name equals ignore case q get name this jmdns impl get services contains key q get name to lower case if i am the only one break int delay i am the only one in is truncated 0 dns constants response min wait interval jmdns impl get random next int dns constants response max wait interval dns constants response min wait interval 1 in elapse since arrival if delay 0 delay 0 logger finest start responder chosen delay delay this jmdns impl schedule this delay iamtheonlyone getquestions hasnext dnsentry dnsentry dnsquestion dnsquestion dnsquestion iamtheonlyone gettype dnsconstants type_srv gettype dnsconstants type_txt gettype dnsconstants type_a gettype dnsconstants type_aaaa jmdnsimpl getlocalhost getname equalsignorecase getname jmdnsimpl getservices containskey getname tolowercase iamtheonlyone iamtheonlyone istruncated dnsconstants response_min_wait_interval jmdnsimpl getrandom nextint dnsconstants response_max_wait_interval dnsconstants response_min_wait_interval elapsesincearrival jmdnsimpl public void run synchronized this jmdns impl get io lock if this jmdns impl get planned answer in this jmdns impl set planned answer null we use these sets to prevent duplicate records fixme this should be moved into dns outgoing hash set questions new hash set hash set answers new hash set if this jmdns impl get state dns state announced try boolean is unicast port dns constants mdns port answer questions for iterator iterator in get questions iterator iterator has next dns entry entry dns entry iterator next if entry instanceof dns question dns question q dns question entry for unicast responses the question must be included if is unicast out add question q questions add q int type q get type if type dns constants type any type dns constants type srv i ama not sure of why there is a special case here pjyf oct 15 2004 if this jmdns impl get local host get name equals ignore case q get name type dns constants type a dns record answer this jmdns impl get local host getdns4 address record if answer null answers add answer answer this jmdns impl get local host getdns6 address record if answer null answers add answer type dns constants type ignore else if this jmdns impl get service types contains key q get name to lower case type dns constants type ptr switch type case dns constants type a answer a query for a domain name out add answer in addr port out host dns record answer this jmdns impl get local host getdns4 address record if answer null answers add answer break case dns constants type aaaa answer a query for a domain name dns record answer this jmdns impl get local host getdns6 address record if answer null answers add answer break case dns constants type ptr answer a query for services of a given type find matching services for iterator service iterator this jmdns impl get services values iterator service iterator has next service info impl info service info impl service iterator next if info get state dns state announced if q get name equals ignore case info get type dns record answer this jmdns impl get local host getdns4 address record if answer null answers add answer answer this jmdns impl get local host getdns6 address record if answer null answers add answer answers add new dns record pointer info get type dns constants type ptr dns constants class in dns constants dns ttl info get qualified name answers add new dns record service info get qualified name dns constants type srv dns constants class in dns constants class unique dns constants dns ttl info get priority info get weight info get port this jmdns impl get local host get name answers add new dns record text info get qualified name dns constants type txt dns constants class in dns constants class unique dns constants dns ttl info get text if q get name equals ignore case services dns sd udp local for iterator service type iterator this jmdns impl get service types values iterator service type iterator has next answers add new dns record pointer services dns sd udp local dns constants type ptr dns constants class in dns constants dns ttl string service type iterator next break case dns constants type srv case dns constants type any case dns constants type txt service info impl info service info impl this jmdns impl get services get q get name to lower case if info null info get state dns state announced dns record answer this jmdns impl get local host getdns4 address record if answer null answers add answer answer this jmdns impl get local host getdns6 address record if answer null answers add answer answers add new dns record pointer info get type dns constants type ptr dns constants class in dns constants dns ttl info get qualified name answers add new dns record service info get qualified name dns constants type srv dns constants class in dns constants class unique dns constants dns ttl info get priority info get weight info get port this jmdns impl get local host get name answers add new dns record text info get qualified name dns constants type txt dns constants class in dns constants class unique dns constants dns ttl info get text break default system out println jmdns responder unhandled query q break remove known answers if the ttl is at least half of jmdnsimpl getiolock jmdnsimpl getplannedanswer jmdnsimpl setplannedanswer dnsoutgoing hashset hashset hashset hashset jmdnsimpl getstate dnsstate isunicast dnsconstants mdns_port getquestions hasnext dnsentry dnsentry dnsquestion dnsquestion dnsquestion isunicast addquestion gettype dnsconstants type_any dnsconstants type_srv jmdnsimpl getlocalhost getname equalsignorecase getname dnsconstants type_a dnsrecord jmdnsimpl getlocalhost getdns4addressrecord jmdnsimpl getlocalhost getdns6addressrecord dnsconstants type_ignore jmdnsimpl getservicetypes containskey getname tolowercase dnsconstants type_ptr dnsconstants type_a addanswer dnsrecord jmdnsimpl getlocalhost getdns4addressrecord dnsconstants type_aaaa dnsrecord jmdnsimpl getlocalhost getdns6addressrecord dnsconstants type_ptr serviceiterator jmdnsimpl getservices serviceiterator hasnext serviceinfoimpl serviceinfoimpl serviceiterator getstate dnsstate getname equalsignorecase gettype dnsrecord jmdnsimpl getlocalhost getdns4addressrecord jmdnsimpl getlocalhost getdns6addressrecord dnsrecord gettype dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl getqualifiedname dnsrecord getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl getpriority getweight getport jmdnsimpl getlocalhost getname dnsrecord getqualifiedname dnsconstants type_txt dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl gettext getname equalsignorecase _services _dns _udp servicetypeiterator jmdnsimpl getservicetypes servicetypeiterator hasnext dnsrecord _services _dns _udp dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl servicetypeiterator dnsconstants type_srv dnsconstants type_any dnsconstants type_txt serviceinfoimpl serviceinfoimpl jmdnsimpl getservices getname tolowercase getstate dnsstate dnsrecord jmdnsimpl getlocalhost getdns4addressrecord jmdnsimpl getlocalhost getdns6addressrecord dnsrecord gettype dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl getqualifiedname dnsrecord getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl getpriority getweight getport jmdnsimpl getlocalhost getname dnsrecord getqualifiedname dnsconstants type_txt dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl gettext jmdnsresponder public class null bucket factory implements bucket factory public bucket make bucket long size throws io exception return new null bucket nullbucketfactory bucketfactory makebucket ioexception nullbucket public class null short callback extends short callback override public short get return 0 nullshortcallback shortcallback override public void set short val throws invalid config value exception ignore invalidconfigvalueexception private function1d f1 f2 public composite function1d function1d f1 function1d f2 this f1 f1 this f2 f2 compositefunction1d public float evaluate float v return f1 evaluate f2 evaluate v public wot message inserter node my node high level simple client my client string my name wot identity manager my identity manager wot message manager my message manager super my node my client my name my identity manager my message manager m message manager my message manager m random m node fast weak random m request client m message manager request client start wotmessageinserter mynode highlevelsimpleclient myclient myname wotidentitymanager myidentitymanager wotmessagemanager mymessagemanager mynode myclient myname myidentitymanager mymessagemanager mmessagemanager mymessagemanager mrandom mnode fastweakrandom mrequestclient mmessagemanager requestclient override protected collection client getter create fetch storage return null clientgetter createfetchstorage override protected collection base client putter create insert storage return new array list base client putter estimated parallel message insert count baseclientputter createinsertstorage arraylist baseclientputter estimated_parallel_message_insert_count override public int get priority return native thread norm priority getpriority nativethread norm_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period override protected synchronized void iterate abort all transfers synchronized m message manager for wot own message message m message manager get not inserted own messages try fixme delay the messages and set their date to reflect the delay insert message message catch exception e logger error this insert of message failed e abortalltransfers mmessagemanager wotownmessage mmessagemanager getnotinsertedownmessages insertmessage you have to synchronize on this code wot message inserter code when using this function protected void insert message own message m throws insert exception io exception transformer exception parser configuration exception bucket tempb mtbf make bucket 2048 m get text length todo set to a reasonable value output stream os null try os tempb get output stream wot messagexml encode m os os close os null tempb set read only we do not specifiy a client meta data with mimetype because that would result in the insertion of an additional chk insert block ib new insert block tempb null m get inserturi insert context ictx m client get insert context true client putter pu m client insert ib false null false ictx this pu set priority class request starter update priority class pluginmanager defaults to interactive priority add insert pu m messagei ds put pu m getid tempb null logger debug this started insert of message from m get author get nickname finally if tempb null tempb free closer close os wotmessageinserter insertmessage ownmessage insertexception ioexception transformerexception parserconfigurationexception makebucket gettext outputstream getoutputstream wotmessagexml setreadonly clientmetadata insertblock insertblock getinserturi insertcontext mclient getinsertcontext clientputter mclient setpriorityclass requeststarter update_priority_class addinsert mmessageids getauthor getnickname override public synchronized void on success base client putter state object container container try wot own message m wot own message m message manager get own message m messagei ds get state m mark as inserted state geturi m message manager add message to message list m logger debug this successful insert of m get realuri catch exception e logger error this message insert finished but on success failed e finally remove insert state onsuccess baseclientputter objectcontainer wotownmessage wotownmessage mmessagemanager getownmessage mmessageids markasinserted mmessagemanager addmessagetomessagelist getrealuri onsuccess removeinsert override public synchronized void on failure insert exception e base client putter state object container container try logger error this message insert failed e finally remove insert state onfailure insertexception baseclientputter objectcontainer removeinsert you have to synchronize on this code wot message inserter code when using this function override protected void abort all transfers super abort all transfers m messagei ds clear wotmessageinserter abortalltransfers abortalltransfers mmessageids you have to synchronize on this code wot message inserter code when using this function override protected void remove insert base client putter p super remove insert p m messagei ds remove p wotmessageinserter removeinsert baseclientputter removeinsert mmessageids not needed functions override public void on success fetch result result client getter state object container container onsuccess fetchresult clientgetter objectcontainer public void on success fetch result result client getter state object container container override public void on failure fetch exception e client getter state object container container onsuccess fetchresult clientgetter objectcontainer onfailure fetchexception clientgetter objectcontainer public void on failure fetch exception e client getter state object container container override public void on generateduri freeneturi uri base client putter state object container container onfailure fetchexception clientgetter objectcontainer ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container override public void on fetchable base client putter state object container container ongenerateduri baseclientputter objectcontainer onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container override public void on major progress object container container onfetchable baseclientputter objectcontainer onmajorprogress objectcontainer public weave filter weavefilter public void setx gap float x gap this x gap x gap setxgap xgap xgap xgap public void setx width float x width this x width x width setxwidth xwidth xwidth xwidth public float getx width return x width getxwidth xwidth public void sety width float y width this y width y width setywidth ywidth ywidth ywidth public float gety width return y width getywidth ywidth public float getx gap return x gap getxgap xgap public void sety gap float y gap this y gap y gap setygap ygap ygap ygap public float gety gap return y gap getygap ygap public void set crossings int matrix this matrix matrix setcrossings public int get crossings return matrix getcrossings public void set use image colors boolean use image colors this use image colors use image colors setuseimagecolors useimagecolors useimagecolors useimagecolors public boolean get use image colors return use image colors getuseimagecolors useimagecolors public void set round threads boolean round threads this round threads round threads setroundthreads roundthreads roundthreads roundthreads public boolean get round threads return round threads getroundthreads roundthreads public void set shade crossings boolean shade crossings this shade crossings shade crossings setshadecrossings shadecrossings shadecrossings shadecrossings public boolean get shade crossings return shade crossings getshadecrossings shadecrossings override public int filterrgb int x int y int rgb x x width x gap 2 y y width y gap 2 float nx image math mod x x width x gap float ny image math mod y y width y gap int ix int x x width x gap int iy int y y width y gap boolean inx nx x width boolean iny ny y width float dx dy float cx cy int lrgbx lrgby if round threads dx math abs x width 2 nx x width 2 dy math abs y width 2 ny y width 2 else dx dy 0 if shade crossings cx image math smooth step x width 2 x width 2 x gap math abs x width 2 nx cy image math smooth step y width 2 y width 2 y gap math abs y width 2 ny else cx cy 0 if use image colors lrgbx lrgby rgb else lrgbx rgbx lrgby rgby int v int ixc ix cols int iyr iy rows int m matrix iyr ixc if inx if iny v m 1 lrgbx lrgby v image math mix colors 2 m 1 dx dy v 0xff000000 else if shade crossings if m matrix iy 1 rows ixc if m 0 cy 1 cy cy 0 5f lrgbx image math mix colors cy lrgbx 0xff000000 else if m 0 lrgbx image math mix colors 0 5f lrgbx 0xff000000 v image math mix colors 2 dx lrgbx 0xff000000 else if iny if shade crossings if m matrix iyr ix 1 cols if m 1 cx 1 cx cx 0 5f lrgby image math mix colors cx lrgby 0xff000000 else if m 1 lrgby image math mix colors 0 5f lrgby 0xff000000 v image math mix colors 2 dy lrgby 0xff000000 else v 0x00000000 return v xwidth xgap ywidth ygap imagemath xwidth xgap imagemath ywidth ygap xwidth xgap ywidth ygap xwidth ywidth roundthreads xwidth xwidth ywidth ywidth shadecrossings imagemath smoothstep xwidth xwidth xgap xwidth imagemath smoothstep ywidth ywidth ygap ywidth useimagecolors imagemath mixcolors shadecrossings imagemath mixcolors imagemath mixcolors imagemath mixcolors shadecrossings imagemath mixcolors imagemath mixcolors imagemath mixcolors override public string to string return texture weave tostring private final node update manager updater public updated version available user alert node update manager updater super false null null null null short 0 false l10n get string user alert hide false null this updater updater nodeupdatemanager updatedversionavailableuseralert nodeupdatemanager getstring useralert override public string get title return l10n title gettitle private string l10n string key return l10n get string updated version available user alert key getstring updatedversionavailableuseralert private string l10n string key string pattern string value return l10n get string updated version available user alert key pattern value getstring updatedversionavailableuseralert private string l10n string key string patterns string values return l10n get string updated version available user alert key patterns values getstring updatedversionavailableuseralert override public string get text update thingy ut create update thingy string builder sb new string builder sb append ut first bit if ut form text null sb append form action method post input type submit name update value sb append ut form text sb append form return sb to string gettext updatethingy createupdatethingy stringbuilder stringbuilder firstbit formtext formtext tostring override public string get short text if updater is armed if updater can update now return l10n short ready not armed else return l10n short not ready not armed else return l10n short armed getshorttext isarmed canupdatenow shortreadynotarmed shortnotreadynotarmed shortarmed private static class update thingy public update thingy string first string form this first bit first this form text form updatethingy updatethingy firstbit formtext override public html node gethtml text update thingy ut create update thingy html node alert node new html node div alert node add child ut first bit if ut form text null alert node add child form new string action method new string post add child input new string type name value new string submit update ut form text return alert node htmlnode gethtmltext updatethingy createupdatethingy htmlnode alertnode htmlnode alertnode addchild firstbit formtext alertnode addchild addchild formtext alertnode private update thingy create update thingy string builder sb new string builder sb append l10n not latest sb append if updater is armed updater in final check sb append l10n final check new string count max time new string integer to string updater get revocationdnf counter integer to string revocation checker revocation dnf min time util format time updater time remaining on check sb append else if updater is armed sb append l10n armed else string form text if updater can update now boolean b false if updater has new main jar sb append l10n downloaded new jar version integer to string updater new main jar version sb append b true if updater has new ext jar sb append l10n b also downloaded new ext jar downloaded new ext jar version integer to string updater new ext jar version sb append if updater can update immediately sb append l10n click to update now form text l10n update now button else sb append l10n click to updateasap form text l10n updateasap button else boolean fetching new updater fetching new main jar boolean fetching new ext updater fetching new ext jar if fetching new if fetching new ext sb append l10n fetching new both new string node version ext version new string integer to string updater fetching new main jar version integer to string updater fetching new ext jar version else sb append l10n fetching new node node version integer to string updater fetching new main jar version else if fetching new ext sb append l10n fetching new ext ext version integer to string updater fetching new ext jar version sb append l10n updateasap question form text l10n updateasap button return new update thingy sb to string form text return new update thingy sb to string null updatethingy createupdatethingy stringbuilder stringbuilder notlatest isarmed infinalcheck finalcheck tostring getrevocationdnfcounter tostring revocationchecker revocation_dnf_min timeutil formattime timeremainingoncheck isarmed formtext canupdatenow hasnewmainjar downloadednewjar tostring newmainjarversion hasnewextjar alsodownloadednewextjar downloadednewextjar tostring newextjarversion canupdateimmediately clicktoupdatenow formtext updatenowbutton clicktoupdateasap formtext updateasapbutton fetchingnew fetchingnewmainjar fetchingnewext fetchingnewextjar fetchingnew fetchingnewext fetchingnewboth nodeversion extversion tostring fetchingnewmainjarversion tostring fetchingnewextjarversion fetchingnewnode nodeversion tostring fetchingnewmainjarversion fetchingnewext fetchingnewext extversion tostring fetchingnewextjarversion updateasapquestion formtext updateasapbutton updatethingy tostring formtext updatethingy tostring override public short get priority class if updater in final check return user alert warning else return user alert minor getpriorityclass infinalcheck useralert useralert override public boolean is valid return updater is enabled updater is blown updater fetching new ext jar updater fetching new main jar updater has new ext jar updater has new main jar isvalid isenabled isblown fetchingnewextjar fetchingnewmainjar hasnewextjar hasnewmainjar override public void is valid boolean b ignore isvalid create a logger threshhold set to normal public logger hook chain this normal loggerhookchain create a logger param threshold suppress all log calls with lower priority then this public logger hook chain int threshold super threshold hooks new logger hook 0 loggerhookchain loggerhook hooks new logger hook 0 public logger hook chain string threshold throws invalid threshold exception super threshold hooks new logger hook 0 loggerhook loggerhookchain invalidthresholdexception loggerhook this is the implementation of logger hook method which allows one logger receive events from another implements logger hook log override public synchronized void log object o class c string msg throwable e int priority logger hook my hooks hooks for int i 0 i my hooks length i my hooks i log o c msg e priority loggerhook loggerhook loggerhook myhooks myhooks myhooks add a hook which will be called every time a message is logged public synchronized void add hook logger hook lh logger hook new hooks new logger hook hooks length 1 system arraycopy new hooks 0 hooks 0 hooks length new hooks hooks length lh hooks new hooks addhook loggerhook loggerhook newhooks loggerhook newhooks newhooks newhooks remove a hook from the logger public synchronized void remove hook logger hook lh final int hooks length hooks length logger hook new hooks new logger hook hooks length 1 hooks length 1 0 int x 0 boolean removed false for int i 0 i hooks length i if hooks i lh removed true else new hooks x hooks i if removed return if x new hooks length hooks new hooks else logger hook final hooks new logger hook x system arraycopy new hooks 0 final hooks 0 x hooks final hooks removehook loggerhook hookslength loggerhook newhooks loggerhook hookslength hookslength hookslength newhooks newhooks newhooks loggerhook finalhooks loggerhook newhooks finalhooks finalhooks returns all the current hooks public synchronized logger hook get hooks return hooks loggerhook gethooks override public long min flags return 0 minflags override public long not flags return 0 notflags override public long any flags return 2 error 1 threshold 1 anyflags override public void set detailed thresholds string details throws invalid threshold exception super set detailed thresholds details no need to tell subordinates we will do the filtering logger hook h get hooks for int i 0 i h length i h i set detailed thresholds details setdetailedthresholds invalidthresholdexception setdetailedthresholds loggerhook gethooks setdetailedthresholds override public void set threshold int thresh super set threshold thresh logger hook h get hooks for int i 0 i h length i h i set threshold thresh setthreshold setthreshold loggerhook gethooks setthreshold public class reduce noise filter extends whole image filter public reduce noise filter reducenoisefilter wholeimagefilter reducenoisefilter private int smooth int v int minindex 0 maxindex 0 min integer max value max integer min value for int i 0 i 9 i if i 4 if v i min min v i minindex i if v i max max v i maxindex i if v 4 min return v minindex if v 4 max return v maxindex return v 4 max_value min_value override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int r new int 9 int g new int 9 int b new int 9 int out pixels new int width height for int y 0 y height y for int x 0 x width x int k 0 int irgb in pixels index int ir irgb 16 0xff int ig irgb 8 0xff int ib irgb 0xff for int dy 1 dy 1 dy int iy y dy if 0 iy iy height int ioffset iy width for int dx 1 dx 1 dx int ix x dx if 0 ix ix width int rgb in pixels ioffset ix r k rgb 16 0xff g k rgb 8 0xff b k rgb 0xff else r k ir g k ig b k ib k else for int dx 1 dx 1 dx r k ir g k ig b k ib k out pixels index in pixels index 0xff000000 smooth r 16 smooth g 8 smooth b index return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels outpixels inpixels outpixels override public string to string return blur smooth tostring public class minimum filter extends whole image filter public minimum filter minimumfilter wholeimagefilter minimumfilter override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int pixel 0xffffffff for int dy 1 dy 1 dy int iy y dy int ioffset if 0 iy iy height ioffset iy width for int dx 1 dx 1 dx int ix x dx if 0 ix ix width pixel pixel utils combine pixels pixel in pixels ioffset ix pixel utils min out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels pixelutils combinepixels inpixels pixelutils outpixels outpixels override public string to string return blur minimum tostring private final hash map key key block blocks by key new hash map key key block public synchronized void add key block block blocks by key put block get key block hashmap keyblock blocksbykey hashmap keyblock keyblock blocksbykey getkey public synchronized key block get key key return blocks by key get key keyblock blocksbykey public synchronized set keys return blocks by key key set blocksbykey keyset public client key block get client key key key block block get key get node key if block null return null try return key create key block key block catch key verify exception e logger error this caught decoding block with key e e return null clientkeyblock clientkey keyblock getnodekey createkeyblock keyverifyexception public boolean object can new object container container storing a block set is not supported there are some complications so lets not implement this until fcp supports it currently we can t do fetch from blob we can only do fetch to blob and insert blob the major problems are in both chk block and ssk block who is responsible for deleting the node keys we have to have them in the objects in ssk block who is responsible for deleting the dsa public key and the dsa group a group might be unique or might be shared between very many ss ks especially in the second case we don t want to just copy every time even for transient uses the best solution may be to copy in object can new but even then callers to the relevant getter methods may be a worry throw new unsupported operation exception block set storage in database not supported objectcannew objectcontainer blockset chkblock sskblock sskblock dsapublickey dsagroup ssks objectcannew unsupportedoperationexception string cause public retrieval exception int reason reason reason cause get err string reason _cause retrievalexception _reason _cause geterrstring public retrieval exception int reason string cause reason reason cause cause if cause null cause length 0 cause equals null cause get err string reason retrievalexception _reason _cause _cause geterrstring public int get reason return reason getreason _reason override public string to string return get err string reason cause tostring geterrstring _reason _cause guaranteed not to have any spaces in it public string get err string return get err string reason geterrstring geterrstring _reason public static string get err string int reason switch reason case premature eof return premature eof case io error return io error case sender died return sender died case timed out return timed out case already cached return already cached case sender disconnected return sender disconnected case no datainsert return no datainsert case cancelled by receiver return cancelled by receiver case unknown return unknown case unable to send block within timeout return unable to send block within timeout case gone to turtle mode return gone to turtle mode case turtle killed return turtle killed default return unknown reason geterrstring premature_eof premature_eof io_error io_error sender_died sender_died timed_out timed_out already_cached already_cached sender_disconnected sender_disconnected no_datainsert no_datainsert cancelled_by_receiver cancelled_by_receiver unable_to_send_block_within_timeout unable_to_send_block_within_timeout gone_to_turtle_mode gone_to_turtle_mode turtle_killed turtle_killed override public string get message return to string getmessage tostring override public final synchronized throwable fill in stack trace return null fillinstacktrace public class grayscale filter extends point filter public grayscale filter can filter index color model true grayscalefilter pointfilter grayscalefilter canfilterindexcolormodel override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff rgb r g b 3 simple average rgb r 77 g 151 b 28 8 ntsc luma return a rgb 16 rgb 8 rgb override public string to string return colors grayscale tostring static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog push ing an object that is already in the queue moves that object to the most recently used position but doesn t add a duplicate entry in the queue public final synchronized void push k key v value q item k v insert hash get key if insert null insert new q item k v key value hash put key insert else insert value value list remove insert if logminor logger minor this pushed insert key value list unshift insert qitem qitem return least recently pushed key public final synchronized k pop key if list size 0 return hash remove list pop obj obj else return null popkey return least recently pushed value public final synchronized v pop value if list size 0 return hash remove list pop obj value else return null popvalue public final synchronized v peek value if list size 0 return hash get list tail obj value else return null peekvalue public final int size return list size public final synchronized boolean remove key k key q item k v i hash remove key if i null list remove i return true else return false removekey qitem check if this queue contains obj param obj object to match return true if this queue contains obj public final synchronized boolean contains key k key return hash contains key key containskey containskey note that this does not automatically promote the key you have to do that by hand with push key value public final synchronized v get k key q item k v q hash get key if q null return null return q value qitem public enumeration k keys return new item enumeration itemenumeration public enumeration v values return new values enumeration valuesenumeration private enumeration q item k v source list reverse elements public boolean has more elements return source has more elements qitem reverseelements hasmoreelements hasmoreelements public k next element return source next element obj nextelement nextelement private enumeration q item k v source list reverse elements public boolean has more elements return source has more elements qitem reverseelements hasmoreelements hasmoreelements public v next element return source next element value nextelement nextelement public v value public q item k key v val this obj key this value val qitem override public string to string return super to string obj value tostring tostring public boolean is empty return list is empty isempty isempty note that unlike the java util versions this will not reallocate hence it doesn t return so pass in an appropriately big array and make sure you hold the lock param entries return public synchronized void values to array v entries enumeration v values values int i 0 while values has more elements entries i values next element valuestoarray hasmoreelements nextelement public synchronized void clear list clear hash clear private static final long serial versionuid 1l public pubkey verify exception crypt format exception e super e serialversionuid pubkeyverifyexception cryptformatexception public pubkey verify exception string msg super msg pubkeyverifyexception override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog private final int hash code override public int hash code return hash code hashcode hashcode hashcode public split file inserter base client putter put put completion callback cb bucket data compressor type best codec long decompressed length client metadata client metadata insert context ctx boolean getchk only boolean is metadata object token archive type archive type boolean free data boolean persistent object container container client context context throws insert exception hash code super hash code this parent put this archive type archive type this compression codec best codec this token token this finished false this is metadata is metadata this cm client metadata this getchk only getchk only this cb cb this ctx ctx this decompressed length decompressed length this data length data size bucket data buckets try data buckets bucket tools split data chk block data length persistent ctx persistent bucket factory context temp bucket factory free data persistent container if data buckets data buckets length 1 size chk block data length bucket old data data buckets data buckets length 1 data buckets data buckets length 1 bucket tools pad old data chk block data length context persistent bucket factory int old data size if persistent data buckets data buckets length 1 store to container old data free if persistent old data remove from container if logminor logger minor this data size data size buckets data buckets length catch io exception e throw new insert exception insert exception bucket error e null count data blocks data buckets length encoding is done by segments this splitfile algorithm ctx splitfile algorithm segment size ctx splitfile segment data blocks check segment size splitfile algorithm metadata splitfile nonredundant 0 ctx splitfile segment check blocks this persistent persistent if persistent container activate parent 1 create segments segments split into segments segment size data buckets context main executor container context persistent put if persistent deactivate all buckets and let data buckets be gc ed for int i 0 i data buckets length i if we don t set them now they will be set when the segment is set which means they will be set deactivated and cause np es data buckets i store to container container deactivate data buckets i 1 if data buckets length segment size otherwise we are nulling out within the segment data buckets i null data buckets null int count 0 for int i 0 i segments length i count segments i count check blocks count check blocks count save progress to disk don t want to do all that again probably includes compression in caller parent on major progress container if persistent for int i 0 i segments length i container store segments i container deactivate segments i 1 splitfileinserter baseclientputter putcompletioncallback compressor_type bestcodec decompressedlength clientmetadata clientmetadata insertcontext getchkonly ismetadata archive_type archivetype freedata objectcontainer clientcontext insertexception hashcode hashcode archivetype archivetype compressioncodec bestcodec ismetadata ismetadata clientmetadata getchkonly getchkonly decompressedlength decompressedlength datalength databuckets databuckets buckettools chkblock data_length persistentbucketfactory tempbucketfactory freedata databuckets databuckets chkblock data_length olddata databuckets databuckets databuckets databuckets buckettools olddata chkblock data_length persistentbucketfactory olddata databuckets databuckets storeto olddata olddata removefrom databuckets ioexception insertexception insertexception bucket_error countdatablocks databuckets splitfilealgorithm splitfilealgorithm segmentsize splitfilesegmentdatablocks checksegmentsize splitfilealgorithm splitfile_nonredundant splitfilesegmentcheckblocks splitintosegments segmentsize databuckets mainexecutor databuckets databuckets npes databuckets storeto databuckets databuckets segmentsize databuckets databuckets countcheckblocks countcheckblocks onmajorprogress public split file inserter base client putter parent put completion callback cb client metadata client metadata insert context ctx boolean getchk only boolean metadata object token archive type archive type simple field set fs object container container client context context throws resume exception hash code super hash code this parent parent this archive type archive type this token token this finished false this is metadata metadata this cm client metadata this getchk only getchk only this cb cb this ctx ctx this persistent parent persistent don t read finished wait for the segment finished s string length fs get data length if length null throw new resume exception no data length try data length long parse long length catch number format exception e throw new resume exception corrupt data length e length length fs get decompressed length long dl 0 back compat if length null try dl long parse long length catch number format exception e dl 1 decompressed length dl string tmp fs get segment size if length null throw new resume exception no segment size try segment size integer parse int tmp catch number format exception e throw new resume exception corrupt segment size e length tmp fs get check segment size if length null throw new resume exception no check segment size try check segment size integer parse int tmp catch number format exception e throw new resume exception corrupt check segment size e length string ccodec fs get compression codec compressor type compressor null if ccodec null try compressor compressor type value of ccodec catch throwable t try short codec no short parse short ccodec compressor compressor type get compressor by metadataid codec no catch number format exception nfe throw new resume exception invalid compression codec ccodec compression codec compressor string scodec fs get splitfile codec if scodec null throw new resume exception no splitfile codec try splitfile algorithm short parse short scodec catch number format exception e throw new resume exception corrupt splitfile codec e scodec simple field set segfs fs subset segments if segfs null throw new resume exception no segments string segc segfs get count if segc null throw new resume exception no segment count int segment count try segment count integer parse int segc catch number format exception e throw new resume exception corrupt segment count e segc segments new split file inserter segment segment count int data blocks 0 int check blocks 0 for int i 0 i segments length i string index integer to string i simple field set segment segfs subset index segfs remove subset index if segment null throw new resume exception no segment i segments i new split file inserter segment this persistent parent segment splitfile algorithm ctx getchk only i context container data blocks segments i count data blocks check blocks segments i count check blocks this count data blocks data blocks this count check blocks check blocks splitfileinserter baseclientputter putcompletioncallback clientmetadata clientmetadata insertcontext getchkonly archive_type archivetype simplefieldset objectcontainer clientcontext resumeexception hashcode hashcode archivetype archivetype ismetadata clientmetadata getchkonly getchkonly segmentfinished datalength resumeexception datalength datalength parselong numberformatexception resumeexception datalength decompressedlength parselong numberformatexception decompressedlength segmentsize resumeexception segmentsize segmentsize parseint numberformatexception resumeexception segmentsize checksegmentsize resumeexception checksegmentsize checksegmentsize parseint numberformatexception resumeexception checksegmentsize compressioncodec compressor_type compressor_type valueof codecno parseshort compressor_type getcompressorbymetadataid codecno numberformatexception resumeexception compressioncodec splitfilecodec resumeexception splitfilealgorithm parseshort numberformatexception resumeexception splitfilecodec simplefieldset resumeexception resumeexception segmentcount segmentcount parseint numberformatexception resumeexception splitfileinsertersegment segmentcount datablocks checkblocks tostring simplefieldset removesubset resumeexception splitfileinsertersegment splitfilealgorithm getchkonly datablocks countdatablocks checkblocks countcheckblocks countdatablocks datablocks countcheckblocks checkblocks group the blocks into segments private split file inserter segment split into segments int segment size bucket orig data blocks executor executor object container container client context context boolean persistent base client putter putter int data blocks orig data blocks length vector segs new vector first split the data up if data blocks segment size segment size 1 single segment split file inserter segment only seg new split file inserter segment this persistent putter splitfile algorithm fec codec get check blocks splitfile algorithm orig data blocks length orig data blocks ctx getchk only 0 container segs add only seg else int j 0 int seg no 0 for int i segment size i segment size if i data blocks i data blocks bucket seg new bucket i j system arraycopy orig data blocks j seg 0 i j j i for int x 0 x seg length x if seg x null throw new null pointer exception in split into segs x is null of seg length of seg no split file inserter segment s new split file inserter segment this persistent putter splitfile algorithm fec codec get check blocks splitfile algorithm seg length seg ctx getchk only seg no container segs add s if i data blocks break seg no if persistent container activate parent 1 parent notify clients container context return split file inserter segment segs to array new split file inserter segment segs size splitfileinsertersegment splitintosegments segmentsize origdatablocks objectcontainer clientcontext baseclientputter datablocks origdatablocks datablocks segmentsize segmentsize splitfileinsertersegment onlyseg splitfileinsertersegment splitfilealgorithm feccodec getcheckblocks splitfilealgorithm origdatablocks origdatablocks getchkonly onlyseg segno segmentsize segmentsize datablocks datablocks origdatablocks nullpointerexception splitintosegs segno splitfileinsertersegment splitfileinsertersegment splitfilealgorithm feccodec getcheckblocks splitfilealgorithm getchkonly segno datablocks segno notifyclients splitfileinsertersegment toarray splitfileinsertersegment public void start object container container final client context context throws insert exception for int i 0 i segments length i if persistent container activate segments i 1 segments i start container context if persistent container deactivate segments i 1 if persistent container activate parent 1 if count data blocks 32 parent on major progress container parent notify clients container context objectcontainer clientcontext insertexception countdatablocks onmajorprogress notifyclients public void encoded segment split file inserter segment segment object container container client context context if logminor logger minor this encoded segment segment seg no of this boolean ret false boolean encode synchronized this encode force encode for int i 0 i segments length i if segments i segment if persistent container activate segments i 1 if segments i null segments i is encoded ret true if segments i segment persistent container deactivate segments i 1 break if segments i segment persistent container deactivate segments i 1 if encode segment force encode container context if ret return if persistent container activate cb 1 cb on block set finished this container context if persistent container deactivate cb 1 if count data blocks 32 if persistent container activate parent 1 parent on major progress container encodedsegment splitfileinsertersegment objectcontainer clientcontext segno forceencode isencoded forceencode onblocksetfinished countdatablocks onmajorprogress public void segment hasur is split file inserter segment segment object container container client context context if logminor logger minor this segment has ur is segment synchronized this if have sent metadata return for int i 0 i segments length i if persistent container activate segments i 1 boolean hasur is segments i hasur is if persistent segments i segment container deactivate segments i 1 if hasur is if logminor logger minor this segment does not have ur is segments i return if logminor logger minor this have ur is from all segments encode metadata container context segment segmenthasuris splitfileinsertersegment objectcontainer clientcontext uris havesentmetadata hasuris hasuris hasuris uris uris encodemetadata private void encode metadata object container container client context context split file inserter segment dont deactivate segment boolean missingur is metadata m null clientchk dataur is new clientchk count data blocks clientchk checkur is new clientchk count check blocks synchronized this int dpos 0 int cpos 0 for int i 0 i segments length i if persistent container activate segments i 1 clientchk data segments i get datach ks system arraycopy data 0 dataur is dpos data length dpos data length clientchk check segments i get checkch ks system arraycopy check 0 checkur is cpos check length cpos check length if persistent segments i dont deactivate segment container deactivate segments i 1 create metadata if logminor logger minor this data ur is dataur is length check ur is checkur is length missingur is any nulls dataur is any nulls checkur is if persistent copy the ur is we don t know what the callee wants the metadata for he might well ignore it as in simple manifest putter on metadata this way he doesn t need to worry about removing them for int i 0 i dataur is length i container activate dataur is i 5 dataur is i dataur is i clone key for int i 0 i checkur is length i container activate checkur is i 5 checkur is i checkur is i clone key if missingur is create metadata if persistent container activate cm 5 client metadata meta cm if persistent meta meta null null meta clone m new metadata splitfile algorithm dataur is checkur is segment size check segment size meta data length archive type compression codec decompressed length is metadata have sent metadata true if missingur is if logminor logger minor this missing ur is error fail new insert exception insert exception internal error missing ur is after encoding null container context return else if persistent container activate cb 1 cb on metadata m this container context if persistent container deactivate cb 1 encodemetadata objectcontainer clientcontext splitfileinsertersegment dontdeactivatesegment missinguris datauris countdatablocks checkuris countcheckblocks getdatachks datauris getcheckchks checkuris dontdeactivatesegment uris datauris uris checkuris missinguris anynulls datauris anynulls checkuris uris simplemanifestputter onmetadata datauris datauris datauris datauris clonekey checkuris checkuris checkuris checkuris clonekey missinguris clientmetadata splitfilealgorithm datauris checkuris segmentsize checksegmentsize datalength archivetype compressioncodec decompressedlength ismetadata havesentmetadata missinguris uris insertexception insertexception internal_error uris onmetadata private void fail insert exception e object container container client context context synchronized this if finished return finished true if persistent container store this container activate cb 1 cb on failure e this container context if persistent container deactivate cb 1 insertexception objectcontainer clientcontext onfailure fixme move this to somewhere private static boolean any nulls object array for int i 0 i array length i if array i null return true return false anynulls public base client putter get parent return parent baseclientputter getparent public void segment finished split file inserter segment segment object container container client context context if logminor logger minor this segment finished segment new exception debug boolean all gone true if count data blocks 32 if persistent container activate parent 1 parent on major progress container synchronized this if finished if logminor logger minor this finished already return for int i 0 i segments length i if persistent segments i segment container activate segments i 1 if segments i is finished if logminor logger minor this segment not finished i segments i all gone false if persistent segments i segment container deactivate segments i 1 break if persistent segments i segment container deactivate segments i 1 insert exception e segment get exception if e null e is fatal cancel container context else if all gone return finished true if persistent container store this on all finished container context segmentfinished splitfileinsertersegment objectcontainer clientcontext allgone countdatablocks onmajorprogress isfinished allgone insertexception getexception isfatal allgone onallfinished public void segment fetchable split file inserter segment segment object container container if logminor logger minor this segment fetchable segment synchronized this if finished return if fetchable return for int i 0 i segments length i if persistent segments i segment container activate segments i 1 if segments i is fetchable if logminor logger minor this segment not fetchable i segments i if persistent segments i segment container deactivate segments i 1 return if persistent segments i segment container deactivate segments i 1 fetchable true if persistent container activate cb 1 container store this cb on fetchable this container segmentfetchable splitfileinsertersegment objectcontainer isfetchable onfetchable private void on all finished object container container client context context if logminor logger minor this all finished try finished failure code tracker tracker new failure code tracker true boolean all succeeded true for int i 0 i segments length i if persistent container activate segments i 1 insert exception e segments i get exception if e null continue if logminor logger minor this failure on segment i segments i e e all succeeded false if e error codes null tracker merge e error codes tracker inc e get mode if persistent container activate cb 1 if all succeeded cb on success this container context else cb on failure insert exception construct tracker this container context catch throwable t we must tell the parent something logger error this caught t t cb on failure new insert exception insert exception internal error this container context onallfinished objectcontainer clientcontext failurecodetracker failurecodetracker allsucceeded insertexception getexception allsucceeded errorcodes errorcodes getmode allsucceeded onsuccess onfailure insertexception onfailure insertexception insertexception internal_error public void cancel object container container client context context if logminor logger minor this cancelling this synchronized this if finished return finished true if persistent container store this for int i 0 i segments length i if persistent container activate segments i 1 segments i cancel container context the segments will call segment finished but it will ignore them because finished true hence we need to call the callback here since the caller expects us to if persistent container activate cb 1 cb on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext segmentfinished onfailure insertexception insertexception public void schedule object container container client context context throws insert exception start container context objectcontainer clientcontext insertexception public object get token return token gettoken public long get length return data length getlength datalength force the remaining blocks which haven t been encoded so far to be encoded asap public void force encode object container container client context context if persistent container activate this 1 logger minor this forcing encode on this synchronized this force encode true for int i 0 i segments length i if persistent container activate segments i 1 segments i force encode container context if persistent container deactivate segments i 1 forceencode objectcontainer clientcontext forceencode forceencode public void remove from object container container client context context parent can remove itself ctx will be removed by parent cb will remove itself cm will be removed by parent token setter can remove token for split file inserter segment segment segments container activate segment 1 segment remove from container context container delete this removefrom objectcontainer clientcontext splitfileinsertersegment removefrom public boolean object can update object container container if logdebug logger debug this object can update on this new exception debug return true objectcanupdate objectcontainer objectcanupdate public boolean object can new object container container if finished logger error this object can new but finished on this new exception error else if logdebug logger debug this object can new on this new exception debug return true objectcannew objectcontainer objectcannew objectcannew public insertable clientssk string doc name byte pub key hash dsa public key pub key dsa private key priv key byte crypto key byte crypto algorithm throws malformedurl exception super doc name pub key hash get extra bytes crypto algorithm pub key crypto key if pub key null throw new null pointer exception this priv key priv key insertableclientssk docname pubkeyhash dsapublickey pubkey dsaprivatekey privkey cryptokey cryptoalgorithm malformedurlexception docname pubkeyhash getextrabytes cryptoalgorithm pubkey cryptokey pubkey nullpointerexception privkey privkey public static insertable clientssk create freeneturi uri throws malformedurl exception if uri get key type equals ignore case ksk return clientksk create uri if uri get routing key null throw new malformedurl exception insertable ssk ur is must have a private key uri if uri get crypto key null throw new malformedurl exception insertable ssk ur is must have a private key uri byte key type byte extra uri get extra if uri get key type equals ssk if extra null throw new malformedurl exception inserting pre 1010 keys not supported formatted exactly as extra on fetching if extra length 5 throw new malformedurl exception ssk private key extra too short if extra 1 1 throw new malformedurl exception ssk not a private key key type extra 2 if key type key algo aes pcfb 256 sha256 throw new malformedurl exception unrecognized crypto type in ssk private key else throw new malformedurl exception not a valid ssk insert uri type uri get key type if uri get doc name null uri get doc name length 0 throw new malformedurl exception ssk ur is must have a document name to avoid ambiguity dsa group g global ds agroup biga dsa private key priv key new dsa private key new native big integer 1 uri get routing key g dsa public key pub key new dsa public key g priv key byte pk hash pub key as bytes hash return new insertable clientssk uri get doc name pk hash pub key priv key uri get crypto key key type insertableclientssk malformedurlexception getkeytype equalsignorecase getroutingkey malformedurlexception uris getcryptokey malformedurlexception uris keytype getextra getkeytype malformedurlexception malformedurlexception malformedurlexception keytype keytype algo_aes_pcfb_256_sha256 malformedurlexception malformedurlexception getkeytype getdocname getdocname malformedurlexception uris dsagroup dsagroupbiga dsaprivatekey privkey dsaprivatekey nativebiginteger getroutingkey dsapublickey pubkey dsapublickey privkey pkhash pubkey asbyteshash insertableclientssk getdocname pkhash pubkey privkey getcryptokey keytype public clientssk block encode bucket source data boolean as metadata boolean dont compress short already compressed codec long source length random source r throws ssk encode exception io exception byte compressed data short compression algo try compressed comp key compress source data dont compress already compressed codec source length clientssk block max decompressed data length ssk block data length true compressed data comp compressed data compression algo comp compression algorithm catch key encode exception e throw new ssk encode exception e get message e pad it message digest md256 sha256 get message digest try byte data first pad it if compressed data length ssk block data length hash the data if compressed data length 0 md256 update compressed data byte digest md256 digest mersenne twister mt new mersenne twister digest data new byte ssk block data length if compressed data length data length throw new runtime exception compressed data length compressed data length but data length data length system arraycopy compressed data 0 data 0 compressed data length byte random bytes new byte ssk block data length compressed data length mt next bytes random bytes system arraycopy random bytes 0 data compressed data length ssk block data length compressed data length else data compressed data implicit hash of data byte orig data hash md256 digest data rijndael aes try aes new rijndael 256 256 catch unsupported cipher exception e throw new error 256 256 rijndael not supported encrypt data data encryption key h plaintext data aes initialize orig data hash pcfb mode pcfb pcfb mode create aes pcfb reset orig data hash pcfb block encipher data 0 data length byte encrypted data hash md256 digest data create headers byte headers new byte ssk block total headers length first two bytes hash id int x 0 headers x byte key block hash sha256 8 headers x byte key block hash sha256 then crypto id headers x byte key algo aes pcfb 256 sha256 8 headers x key algo aes pcfb 256 sha256 then e h docname copy to headers system arraycopy eh docname 0 headers x eh docname length x eh docname length now the encrypted headers byte encrypted headers new byte ssk block encrypted headers length system arraycopy orig data hash 0 encrypted headers 0 orig data hash length int y orig data hash length short len short compressed data length if as metadata len 32768 encrypted headers y byte len 8 encrypted headers y byte len encrypted headers y byte compression algo 8 encrypted headers y byte compression algo if encrypted headers length y throw new illegal state exception have more bytes to generate encoding ssk aes initialize crypto key pcfb reset eh docname pcfb block encipher encrypted headers 0 encrypted headers length system arraycopy encrypted headers 0 headers x encrypted headers length x encrypted headers length generate implicit overall hash md256 update headers 0 x md256 update encrypted data hash byte overall hash md256 digest now sign it dsa signature sig dsa sign pub key get group priv key new native big integer 1 overall hash r pack r and s into 32 bytes each and copy to headers then create and return the clientssk block byte r buf truncate sig getr to byte array ssk block sig r length byte s buf truncate sig gets to byte array ssk block sig s length system arraycopy r buf 0 headers x r buf length x r buf length system arraycopy s buf 0 headers x s buf length x s buf length if x ssk block total headers length throw new illegal state exception too long try return new clientssk block data headers this false fixme set last arg to true to not verify catch ssk verify exception e illegal state exception exception new illegal state exception impossible encoding error e get message exception init cause e throw exception finally sha256 return message digest md256 clientsskblock sourcedata asmetadata dontcompress alreadycompressedcodec sourcelength randomsource sskencodeexception ioexception compresseddata compressionalgo sourcedata dontcompress alreadycompressedcodec sourcelength clientsskblock max_decompressed_data_length sskblock data_length compresseddata compresseddata compressionalgo compressionalgorithm keyencodeexception sskencodeexception getmessage messagedigest getmessagedigest compresseddata sskblock data_length compresseddata compresseddata mersennetwister mersennetwister sskblock data_length compresseddata runtimeexception compresseddata compresseddata compresseddata compresseddata randombytes sskblock data_length compresseddata nextbytes randombytes randombytes compresseddata sskblock data_length compresseddata compresseddata origdatahash unsupportedcipherexception origdatahash pcfbmode pcfbmode origdatahash blockencipher encrypteddatahash sskblock total_headers_length keyblock hash_sha256 keyblock hash_sha256 algo_aes_pcfb_256_sha256 algo_aes_pcfb_256_sha256 ehdocname ehdocname ehdocname encryptedheaders sskblock encrypted_headers_length origdatahash encryptedheaders origdatahash origdatahash compresseddata asmetadata encryptedheaders encryptedheaders encryptedheaders compressionalgo encryptedheaders compressionalgo encryptedheaders illegalstateexception cryptokey ehdocname blockencipher encryptedheaders encryptedheaders encryptedheaders encryptedheaders encryptedheaders encrypteddatahash overallhash dsasignature pubkey getgroup privkey nativebiginteger overallhash clientsskblock rbuf tobytearray sskblock sig_r_length sbuf tobytearray sskblock sig_s_length rbuf rbuf rbuf sbuf sbuf sbuf sskblock total_headers_length illegalstateexception clientsskblock sskverifyexception illegalstateexception illegalstateexception getmessage initcause returnmessagedigest private byte truncate byte bs int len if bs length len return bs else if bs length len byte buf new byte len system arraycopy bs 0 buf len bs length bs length return buf else if bs length len for int i 0 i bs length len i if bs i 0 throw new illegal state exception cannot truncate byte buf new byte len system arraycopy bs bs length len buf 0 len return buf illegalstateexception public static insertable clientssk create random random source r string doc name byte ckey new byte crypto key length r next bytes ckey dsa group g global ds agroup biga dsa private key priv key new dsa private key g r dsa public key pub key new dsa public key g priv key try byte pk hash sha256 digest pub key as bytes return new insertable clientssk doc name pk hash pub key priv key ckey key algo aes pcfb 256 sha256 catch malformedurl exception e throw new error e insertableclientssk createrandom randomsource docname crypto_key_length nextbytes dsagroup dsagroupbiga dsaprivatekey privkey dsaprivatekey dsapublickey pubkey dsapublickey privkey pkhash pubkey asbytes insertableclientssk docname pkhash pubkey privkey algo_aes_pcfb_256_sha256 malformedurlexception public freeneturi get inserturi return new freeneturi ssk doc name priv key getx to byte array crypto key get insert extra bytes getinserturi docname privkey tobytearray cryptokey getinsertextrabytes private byte get insert extra bytes byte extra get extra bytes extra 1 1 insert return extra getinsertextrabytes getextrabytes public dsa group get crypto group return global ds agroup biga dsagroup getcryptogroup dsagroupbiga override public void remove from object container container container activate priv key 5 priv key remove from container super remove from container removefrom objectcontainer privkey privkey removefrom removefrom public class not enough nice levels user alert extends abstract user alert public not enough nice levels user alert super true null null null null user alert warning true l10n get string user alert hide true null notenoughnicelevelsuseralert abstractuseralert notenoughnicelevelsuseralert useralert getstring useralert override public string get title return l10n get string not enough nice levels user alert title gettitle getstring notenoughnicelevelsuseralert override public string get text return l10n get string not enough nice levels user alert content new string available required new string string value of native thread native priority range string value of native thread enough nice levels gettext getstring notenoughnicelevelsuseralert valueof nativethread native_priority_range valueof nativethread enough_nice_levels override public string get short text return l10n get string not enough nice levels user alert short getshorttext getstring notenoughnicelevelsuseralert override public html node gethtml text return new html node div get text htmlnode gethtmltext htmlnode gettext public forward port string name boolean isip6 int protocol int port number this name name this isip6 isip6 this protocol protocol this port number port number hash code name hash code isip6 1 0 protocol port number forwardport portnumber portnumber portnumber hashcode hashcode portnumber override public int hash code return hash code hashcode hashcode override public boolean equals object o if o this return true if o instanceof forward port return false forward port f forward port o return f name equals name f isip6 isip6 f protocol protocol f port number port number forwardport forwardport forwardport portnumber portnumber create an instance of jmdns public static jmdns create throws io exception return new jmdns impl ioexception jmdnsimpl create an instance of jmdns and bind it to a specific network interface given its ip address public static jmdns create inet address addr throws io exception return new jmdns impl addr inetaddress ioexception jmdnsimpl return the host name associated with this jmdns instance note may not be the same as what started the host name is subject to negotiation hostname return the address of the interface to which this instance of jmdns is bound get service information if the information is not cached the method will block until updated information is received p usage note do not call this method from the awt event dispatcher thread you will make the user interface unresponsive param type fully qualified service type such as code http tcp local code param name unqualified service name such as code foobar code return null if the service information cannot be obtained _http _tcp get service information if the information is not cached the method will block for the given timeout until updated information is received p usage note if you call this method from the awt event dispatcher thread use a small timeout or you will make the user interface unresponsive param type full qualified service type such as code http tcp local code param name unqualified service name such as code foobar code param timeout timeout in milliseconds return null if the service information cannot be obtained _http _tcp request service information the information about the service is requested and the service listener resolve service method is called as soon as it is available p usage note do not call this method from the awt event dispatcher thread you will make the user interface unresponsive param type full qualified service type such as code http tcp local code param name unqualified service name such as code foobar code servicelistener resolveservice _http _tcp request service information the information about the service is requested and the service listener resolve service method is called as soon as it is available param type full qualified service type such as code http tcp local code param name unqualified service name such as code foobar code param timeout timeout in milliseconds servicelistener resolveservice _http _tcp listen for service types param listener listener for service types remove listener for service types param listener listener for service types listen for services of a given type the type has to be a fully qualified type name such as code http tcp local code param type full qualified service type such as code http tcp local code param listener listener for service updates _http _tcp _http _tcp remove listener for services of a given type param listener listener for service updates register a service the service is registered for access by other jmdns clients the name of the service may be changed to make it unique public abstract void register service service info info throws io exception unregister a service the service should have been registered public abstract void unregister service service info info registerservice serviceinfo ioexception unregisterservice serviceinfo public abstract void unregister service service info info unregister all services public abstract void unregister all services unregisterservice serviceinfo unregisterallservices register a service type if this service type was not already known all service listeners will be notified of the new service type service types are automatically registered as they are discovered public abstract void register service type string type close down jmdns release all resources and unregister all services public abstract void close registerservicetype list services and service types debugging only servicetypes returns a list of service infos of the specified type param type service type name such as code http tcp local code return an array of service instance names _http _tcp construct a bicubic scale filter which resizes to 32x32 pixels public bicubic scale filter this 32 32 bicubicscalefilter bicubicscalefilter constructor for a filter which scales the input image to the given width and height using bicubic interpolation unfortunately it appears that bicubic actually looks worse than bilinear interpolation on most java implementations but you can be the judge param width the width of the output image param height the height of the output image public bicubic scale filter int width int height this width width this height height bicubicscalefilter public buffered image filter buffered image src buffered image dst int w src get width int h src get height if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster width height dstcm is alpha premultiplied null graphics2d g dst create graphics g set rendering hint rendering hints key interpolation rendering hints value interpolation bicubic g draw image src 0 0 width height null g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight colormodel getcolormodel bufferedimage createcompatiblewritableraster isalphapremultiplied creategraphics setrenderinghint renderinghints key_interpolation renderinghints value_interpolation_bicubic drawimage override public string to string return distort bicubic scale tostring private final wot m wot public fcp interface final wot my wot m wot my wot mwot fcpinterface mywot mwot mywot public void handle final plugin reply sender replysender final simple field set params final bucket data final int accesstype try final string message params get message if message equals create identity replysender send handle create identity params data else if message equals set trust replysender send handle set trust params data else if message equals add identity replysender send handle add identity params data else if message equals get identity replysender send handle get identity params data else if message equals get own identities replysender send handle get own identities params data else if message equals get identities by score replysender send handle get identities by score params data else if message equals get trusters replysender send handle get trusters params data else if message equals get trustees replysender send handle get trustees params data else if message equals add context replysender send handle add context params data else if message equals remove context replysender send handle remove context params data else if message equals set property replysender send handle set property params data else if message equals get property replysender send handle get property params data else if message equals remove property replysender send handle remove property params data else throw new exception unknown message message catch final exception e logger error this e to string try replysender send error messagefcp params get message e data catch final plugin not found exception e1 logger normal this connection to request sender lost e1 pluginreplysender simplefieldset createidentity handlecreateidentity settrust handlesettrust addidentity handleaddidentity getidentity handlegetidentity getownidentities handlegetownidentities getidentitiesbyscore handlegetidentitiesbyscore gettrusters handlegettrusters gettrustees handlegettrustees addcontext handleaddcontext removecontext handleremovecontext setproperty handlesetproperty getproperty handlegetproperty removeproperty handleremoveproperty tostring errormessagefcp pluginnotfoundexception private string get mandatory parameter final simple field set sfs final string name throws invalid parameter exception final string result sfs get name if result null throw new illegal argument exception missing mandatory parameter name return result getmandatoryparameter simplefieldset invalidparameterexception illegalargumentexception private simple field set handle create identity final simple field set params throws invalid parameter exception fs parse exception malformedurl exception own identity identity final string identity nickname get mandatory parameter params nickname final string identity context get mandatory parameter params context final string identity publishes trust list str get mandatory parameter params publish trust list final boolean identity publishes trust list identity publishes trust list str equals true identity publishes trust list str equals yes final string identity requesturi params get requesturi final string identity inserturi params get inserturi the constructor will throw for us if one is missing do not use because that would lead to creation of a new uri if the user forgot one of the ur is and the user would not get notified about that synchronized m wot preserve the locking order to prevent future deadlocks if identity requesturi null identity inserturi null identity m wot create own identity identity nickname identity publishes trust list identity context else identity m wot create own identity identity inserturi identity requesturi identity nickname identity publishes trust list identity context if params get publish introduction puzzles null params get boolean publish introduction puzzles if identity publishes trust list throw new invalid parameter exception an identity cannot publish introduction puzzles if it does not publish its trust list synchronized identity todo create a function for those try identity add context introduction puzzle introduction context identity set property introduction server puzzle count property integer to string introduction server default puzzle count m wot store and commit identity catch runtime exception e m wot delete identity identity throw e final simple field set sfs new simple field set true sfs put overwrite message identity created sfs put overwrite id identity getid sfs put overwrite inserturi identity get inserturi to string sfs put overwrite requesturi identity get requesturi to string return sfs simplefieldset handlecreateidentity simplefieldset invalidparameterexception fsparseexception malformedurlexception ownidentity identitynickname getmandatoryparameter identitycontext getmandatoryparameter identitypublishestrustliststr getmandatoryparameter publishtrustlist identitypublishestrustlist identitypublishestrustliststr identitypublishestrustliststr identityrequesturi identityinserturi uris mwot identityrequesturi identityinserturi mwot createownidentity identitynickname identitypublishestrustlist identitycontext mwot createownidentity identityinserturi identityrequesturi identitynickname identitypublishestrustlist identitycontext publishintroductionpuzzles getboolean publishintroductionpuzzles identitypublishestrustlist invalidparameterexception addcontext introductionpuzzle introduction_context setproperty introductionserver puzzle_count_property tostring introductionserver default_puzzle_count mwot storeandcommit runtimeexception mwot deleteidentity simplefieldset simplefieldset putoverwrite identitycreated putoverwrite putoverwrite getinserturi tostring putoverwrite getrequesturi tostring private simple field set handle set trust final simple field set params throws invalid parameter exception number format exception unknown identity exception final string trusterid get mandatory parameter params truster final string trusteeid get mandatory parameter params trustee final string trust value get mandatory parameter params value final string trust comment get mandatory parameter params comment m wot set trust trusterid trusteeid byte parse byte trust value trust comment final simple field set sfs new simple field set true sfs put overwrite message trust set return sfs simplefieldset handlesettrust simplefieldset invalidparameterexception numberformatexception unknownidentityexception getmandatoryparameter getmandatoryparameter trustvalue getmandatoryparameter trustcomment getmandatoryparameter mwot settrust parsebyte trustvalue trustcomment simplefieldset simplefieldset putoverwrite trustset private simple field set handle add identity final simple field set params throws invalid parameter exception malformedurl exception final string requesturi get mandatory parameter params requesturi final identity identity m wot add identity requesturi final simple field set sfs new simple field set true sfs put overwrite message identity added sfs put overwrite id identity getid return sfs simplefieldset handleaddidentity simplefieldset invalidparameterexception malformedurlexception getmandatoryparameter mwot addidentity simplefieldset simplefieldset putoverwrite identityadded putoverwrite private simple field set handle get identity final simple field set params throws invalid parameter exception unknown identity exception final string tree ownerid get mandatory parameter params tree owner final string identityid get mandatory parameter params identity final simple field set sfs new simple field set true sfs put overwrite message identity synchronized m wot final own identity tree owner m wot get own identity byid tree ownerid final identity identity m wot get identity byid identityid try final trust trust m wot get trust tree owner identity sfs put overwrite trust byte to string trust get value catch final not trusted exception e1 sfs put overwrite trust null try final score score m wot get score tree owner identity sfs put overwrite score integer to string score get score sfs put overwrite rank integer to string score get rank catch final not in trust tree exception e sfs put overwrite score null sfs put overwrite rank null final iterator string contexts identity get contexts iterator for int i 1 contexts has next i sfs put overwrite context i contexts next return sfs simplefieldset handlegetidentity simplefieldset invalidparameterexception unknownidentityexception treeownerid getmandatoryparameter treeowner getmandatoryparameter simplefieldset simplefieldset putoverwrite mwot ownidentity treeowner mwot getownidentitybyid treeownerid mwot getidentitybyid mwot gettrust treeowner putoverwrite tostring getvalue nottrustedexception putoverwrite mwot getscore treeowner putoverwrite tostring getscore putoverwrite tostring getrank notintrusttreeexception putoverwrite putoverwrite getcontexts hasnext putoverwrite private simple field set handle get own identities final simple field set params final simple field set sfs new simple field set true sfs put overwrite message own identities synchronized m wot final object set own identity result m wot get all own identities for int i 1 result has next final own identity oid result next sfs put overwrite identity i oid getid sfs put overwrite requesturi i oid get requesturi to string sfs put overwrite inserturi i oid get inserturi to string sfs put overwrite nickname i oid get nickname todo allow the client to select what data he wants this is here so you do not forget to do it in the if if you add an if around the put statements to allow selection i return sfs simplefieldset handlegetownidentities simplefieldset simplefieldset simplefieldset putoverwrite ownidentities mwot objectset ownidentity mwot getallownidentities hasnext ownidentity putoverwrite putoverwrite getrequesturi tostring putoverwrite getinserturi tostring putoverwrite getnickname private simple field set handle get identities by score final simple field set params throws invalid parameter exception unknown identity exception final string tree ownerid params get tree owner final string selection get mandatory parameter params selection final string context get mandatory parameter params context final string select string selection trim int select 0 todo decide about the default value if select string equals select 1 else if select string equals select 1 else if select string equals 0 select 0 else throw new invalid parameter exception unhandled selection value select final simple field set sfs new simple field set true sfs put overwrite message identities synchronized m wot final own identity tree owner tree ownerid null m wot get own identity byid tree ownerid null final object set score result m wot get identities by score tree owner select final boolean get all context equals for int i 1 result has next final score score result next if get all score get target has context context final identity identity score get target sfs put overwrite identity i identity getid sfs put overwrite requesturi i identity get requesturi to string sfs put overwrite nickname i identity get nickname null identity get nickname i todo allow the client to select what data he wants return sfs simplefieldset handlegetidentitiesbyscore simplefieldset invalidparameterexception unknownidentityexception treeownerid treeowner getmandatoryparameter getmandatoryparameter selectstring selectstring selectstring selectstring invalidparameterexception simplefieldset simplefieldset putoverwrite mwot ownidentity treeowner treeownerid mwot getownidentitybyid treeownerid objectset mwot getidentitiesbyscore treeowner getall hasnext getall gettarget hascontext gettarget putoverwrite putoverwrite getrequesturi tostring putoverwrite getnickname getnickname private simple field set handle get trusters final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string context get mandatory parameter params context final simple field set sfs new simple field set true sfs put overwrite message identities final boolean get all context equals synchronized m wot final object set trust received trusts m wot get received trusts m wot get identity byid identityid for int i 1 received trusts has next final trust trust received trusts next if get all trust get truster has context params get context sfs put overwrite identity i trust get truster getid sfs put overwrite value i byte to string trust get value sfs put overwrite comment i trust get comment todo allow the client to select what data he wants i return sfs simplefieldset handlegettrusters simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter getmandatoryparameter simplefieldset simplefieldset putoverwrite getall mwot objectset receivedtrusts mwot getreceivedtrusts mwot getidentitybyid receivedtrusts hasnext receivedtrusts getall gettruster hascontext putoverwrite gettruster putoverwrite tostring getvalue putoverwrite getcomment private simple field set handle get trustees final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string context get mandatory parameter params context final simple field set sfs new simple field set true sfs put overwrite message identities final boolean get all context equals synchronized m wot final object set trust given trusts m wot get given trusts m wot get identity byid identityid for int i 1 given trusts has next final trust trust given trusts next if get all trust get truster has context params get context sfs put overwrite identity i trust get truster getid sfs put overwrite value i byte to string trust get value sfs put overwrite comment i trust get comment todo allow the client to select what data he wants i return sfs simplefieldset handlegettrustees simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter getmandatoryparameter simplefieldset simplefieldset putoverwrite getall mwot objectset giventrusts mwot getgiventrusts mwot getidentitybyid giventrusts hasnext giventrusts getall gettruster hascontext putoverwrite gettruster putoverwrite tostring getvalue putoverwrite getcomment private simple field set handle add context final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string context get mandatory parameter params context m wot add context identityid context final simple field set sfs new simple field set true sfs put overwrite message context added return sfs simplefieldset handleaddcontext simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter getmandatoryparameter mwot addcontext simplefieldset simplefieldset putoverwrite contextadded private simple field set handle remove context final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string context get mandatory parameter params context m wot remove context identityid context final simple field set sfs new simple field set true sfs put overwrite message context removed return sfs simplefieldset handleremovecontext simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter getmandatoryparameter mwot removecontext simplefieldset simplefieldset putoverwrite contextremoved private simple field set handle set property final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string property name get mandatory parameter params property final string property value get mandatory parameter params value m wot set property identityid property name property value final simple field set sfs new simple field set true sfs put overwrite message property added return sfs simplefieldset handlesetproperty simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter propertyname getmandatoryparameter propertyvalue getmandatoryparameter mwot setproperty propertyname propertyvalue simplefieldset simplefieldset putoverwrite propertyadded private simple field set handle get property final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string property name get mandatory parameter params property final simple field set sfs new simple field set true sfs put overwrite message property value sfs put overwrite property m wot get property identityid property name return sfs simplefieldset handlegetproperty simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter propertyname getmandatoryparameter simplefieldset simplefieldset putoverwrite propertyvalue putoverwrite mwot getproperty propertyname private simple field set handle remove property final simple field set params throws invalid parameter exception unknown identity exception final string identityid get mandatory parameter params identity final string property name get mandatory parameter params property m wot remove property identityid property name final simple field set sfs new simple field set true sfs put overwrite message property removed return sfs simplefieldset handleremoveproperty simplefieldset invalidparameterexception unknownidentityexception getmandatoryparameter propertyname getmandatoryparameter mwot removeproperty propertyname simplefieldset simplefieldset putoverwrite propertyremoved private simple field set error messagefcp final string original message final exception e final simple field set sfs new simple field set true sfs put overwrite message error sfs put overwrite original message original message sfs put overwrite description e to string return sfs simplefieldset errormessagefcp originalmessage simplefieldset simplefieldset putoverwrite putoverwrite originalmessage originalmessage putoverwrite tostring private static final long serial versionuid 3144583349586910509l public invalid description exception super serialversionuid invaliddescriptionexception public invalid description exception string s super s invaliddescriptionexception public invalid description exception string s file file super s file to string invaliddescriptionexception tostring public invalid description exception exception e super e get message invaliddescriptionexception getmessage protected static final digest shactx sha1 get instance crypto key getinstance cryptokey public static crypto key read input stream i throws io exception crypt format exception data input stream dis new data input stream i string type dis readutf try class key class class for name type method m key class get method read new class input stream class return crypto key m invoke null new object dis catch exception e e print stack trace if e instanceof crypt format exception throw crypt format exception e if e instanceof io exception throw io exception e logger error crypto key class unknown exception while reading crypto key e return null cryptokey inputstream ioexception cryptformatexception datainputstream datainputstream keyclass forname keyclass getmethod inputstream cryptokey printstacktrace cryptformatexception cryptformatexception ioexception ioexception cryptokey cryptokey public abstract void write output stream o throws io exception public abstract string key type outputstream ioexception keytype public abstract string key type public abstract byte fingerprint keytype public abstract string key type public abstract byte fingerprint public abstract byte as bytes keytype asbytes protected byte fingerprint big integer quantities synchronized shactx for int i 0 i quantities length i byte mpi util mp ibytes quantities i shactx update mpi 0 mpi length return shactx digest biginteger mpibytes public string verbose to string string builder b new string builder b append to string append t append fingerprint to string return b to string verbosetostring stringbuilder stringbuilder tostring fingerprinttostring tostring override public string to string string builder b new string builder key type length 1 4 b append key type append hex util bytes to hex append fingerprint 16 4 b return b to string tostring stringbuilder stringbuilder keytype keytype hexutil bytestohexappend tostring public string fingerprint to string string fphex hex util bytes to hex fingerprint string builder b new string builder 40 10 b append fphex substring 0 4 append append fphex substring 4 8 append append fphex substring 8 12 append append fphex substring 12 16 append append fphex substring 16 20 append append fphex substring 20 24 append append fphex substring 24 28 append append fphex substring 28 32 append append fphex substring 32 36 append append fphex substring 36 40 return b to string fingerprinttostring hexutil bytestohex stringbuilder stringbuilder tostring public static void main string args throws exception for crypto key kp crypto key read system in system err println kp verbose to string cryptokey cryptokey verbosetostring public host info inet address address string name super this address address this name name if address null try interfaze network interface get by inet address address catch exception exception fixme shouldn t we take an action here logger log level warning local host info exception exception hostinfo inetaddress networkinterface getbyinetaddress localhostinfo public string get name return name getname public inet address get address return address inetaddress getaddress public network interface get interface return interfaze networkinterface getinterface synchronized string increment host name host name count int plocal name index of local int punder name last index of name name substring 0 punder 1 plocal punder host name count local return name incrementhostname hostnamecount indexof lastindexof hostnamecount boolean should ignore packet datagram packet packet boolean result false if get address null inet address from packet get address if from null if from is link local address get address is link local address ignore linklocal packets on regular interfaces unless this is also a linklocal interface this is to avoid duplicates this is a terrible hack caused by the lack of an api to get the address of the interface on which the packet was received result true if from is loopback address get address is loopback address ignore loopback packets on a regular interface unless this is also a loopback interface result true return result shouldignorepacket datagrampacket getaddress inetaddress getaddress islinklocaladdress getaddress islinklocaladdress isloopbackaddress getaddress isloopbackaddress dns record address getdns address record dns record address address return dns constants type aaaa address type getdns6 address record getdns4 address record dnsrecord getdnsaddressrecord dnsrecord dnsconstants type_aaaa getdns6addressrecord getdns4addressrecord public dns record address getdns4 address record if get address null get address instanceof inet4 address get address instanceof inet6 address inet6 address get address isi pv4 compatible address return new dns record address get name dns constants type a dns constants class in dns constants dns ttl get address return null dnsrecord getdns4addressrecord getaddress getaddress inet4address getaddress inet6address inet6address getaddress isipv4compatibleaddress dnsrecord getname dnsconstants type_a dnsconstants class_in dnsconstants dns_ttl getaddress public dns record address getdns6 address record if get address null get address instanceof inet6 address return new dns record address get name dns constants type aaaa dns constants class in dns constants dns ttl get address return null dnsrecord getdns6addressrecord getaddress getaddress inet6address dnsrecord getname dnsconstants type_aaaa dnsconstants class_in dnsconstants dns_ttl getaddress public string to string string buffer buf new string buffer buf append local host info buf append get name null get name no name buf append buf append get interface null get interface get display name buf append buf append get address null get address get host address no address buf append return buf to string tostring stringbuffer stringbuffer getname getname getinterface getinterface getdisplayname getaddress getaddress gethostaddress tostring public void add address records dns outgoing out boolean authoritative throws io exception dns record answer getdns4 address record if answer null if authoritative out add authorative answer answer else out add answer answer 0 answer getdns6 address record if answer null if authoritative out add authorative answer answer else out add answer answer 0 addaddressrecords dnsoutgoing ioexception dnsrecord getdns4addressrecord addauthorativeanswer addanswer getdns6addressrecord addauthorativeanswer addanswer private random random numbers new random public sparkle filter randomnumbers sparklefilter public void set color int color this color color setcolor public int get color return color getcolor public void set randomness int randomness this randomness randomness setrandomness public int get randomness return randomness getrandomness set the amount of sparkle param amount the amount min value 0 max value 1 see get amount public void set amount int amount this amount amount getamount setamount get the amount of sparkle return the amount see set amount public int get amount return amount setamount getamount public void set rays int rays this rays rays setrays public int get rays return rays getrays set the radius of the effect param radius the radius min value 0 see get radius public void set radius int radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public int get radius return radius setradius getradius override public void set dimensions int width int height this width width this height height centrex width 2 centrey height 2 super set dimensions width height random numbers set seed seed ray lengths new float rays for int i 0 i rays i ray lengths i radius randomness 100 0f radius float random numbers next gaussian setdimensions setdimensions randomnumbers setseed raylengths raylengths randomnumbers nextgaussian override public int filterrgb int x int y int rgb float dx x centrex float dy y centrey float distance dx dx dy dy float angle float math atan2 dy dx float d angle image math pi image math two pi rays int i int d float f d i if radius 0 float length image math lerp f ray lengths i rays ray lengths i 1 rays float g length length distance 0 0001f g float math pow g 100 amount 50 0 f 0 5f f amount 50 0f f 1 f f f g f image math clamp f 0 1 return image math mix colors f rgb color imagemath imagemath two_pi imagemath raylengths raylengths imagemath imagemath mixcolors override public string to string return stylize sparkle tostring persistent cooldown queue item sendable get client key key long time persistent cooldown queue parent this client client this key key this key as bytes hex util bytes to hex key get full key this time time this parent parent persistentcooldownqueueitem sendableget persistentcooldownqueue keyasbytes hexutil bytestohex getfullkey public void delete object container container client not our problem parent not our problem key remove from container container delete this objectcontainer removefrom public wot message list ft identity my author freeneturi myuri list message reference new messages throws invalid parameter exception no such identity exception super my author myuri new messages todo auto generated constructor stub wotmessagelist ftidentity myauthor messagereference newmessages invalidparameterexception nosuchidentityexception myauthor newmessages public wot message list ft identity my author freeneturi myuri super my author myuri wotmessagelist ftidentity myauthor myauthor public wot identity get author return wot identity m author wotidentity getauthor wotidentity mauthor public freeneturi geturi return assembleuri m author get requesturi m index ssk forusk mauthor getrequesturi mindex sskforusk protected freeneturi generateuri freeneturi baseuri int index return assembleuri baseuri index get the usk uri of a message list with the given identity and index param identity param index return public static freeneturi generateuri wot identity identity int index return assembleuri identity get requesturi index wotidentity getrequesturi public static freeneturi assembleuri freeneturi baseuri int index baseuri baseuri set key type usk baseuri baseuri set doc name freetalk plugin title message list baseuri baseuri set suggested edition index baseuri baseuri set meta string null return baseuri setkeytype setdocname plugin_title messagelist setsuggestededition setmetastring creates a new redirect exception param message the message to put in the reply param new location the location to redirect to public redirect pluginhttp exception string message string new location super message null this new location new location newlocation redirectpluginhttpexception newlocation newlocation newlocation creates a new redirect exception param message the message to put in the reply param location unsued param new location the location to redirect to deprecated use link redirect pluginhttp exception string string instead deprecated public redirect pluginhttp exception string message string location string new location super message location this new location new location newlocation redirectpluginhttpexception redirectpluginhttpexception newlocation newlocation newlocation public client put complex dir message simple field set fs bucket factory bf temp persistent temp bucket factory bf persistent throws message invalid exception parse the standard client put dir headers uri etc super fs files by name new hash map string object files to read new linked list dir put file long total bytes 0 now parse the meat simple field set files fs subset files if files null throw new message invalid exception protocol error message missing field missing files section identifier global boolean logminor logger should log logger minor this for int i 0 i simple field set subset files subset integer to string i if subset null break dir put file f dir put file create subset identifier global persistence type client request persist forever bf persistent bf temp add file f if logminor logger minor this adding f if f instanceof direct dir put file total bytes direct dir put file f bytes to read files to read add last f if logminor logger minor this total bytes now total bytes attached bytes total bytes clientputcomplexdirmessage simplefieldset bucketfactory bftemp persistenttempbucketfactory bfpersistent messageinvalidexception clientputdir filesbyname hashmap filestoread linkedlist dirputfile totalbytes simplefieldset messageinvalidexception protocolerrormessage missing_field shouldlog simplefieldset tostring dirputfile dirputfile persistencetype clientrequest persist_forever bfpersistent bftemp addfile directdirputfile totalbytes directdirputfile bytestoread filestoread addlast totalbytes totalbytes attachedbytes totalbytes add a file to the files by name throws message invalid exception private void add file dir put file f throws message invalid exception add file files by name f get name f filesbyname messageinvalidexception addfile dirputfile messageinvalidexception addfile filesbyname getname suppress warnings unchecked private void add file hash map string object by name string name dir put file f throws message invalid exception int idx name index of if idx 1 by name put name f else string before name substring 0 idx string after name substring idx 1 object o by name get before if o null if o instanceof hash map add file hash map string object o after f return else throw new message invalid exception protocol error message invalid message cannot be both a file and a directory before identifier global else o new hash map object object by name put before o add file hash map string object o after f suppresswarnings addfile hashmap byname dirputfile messageinvalidexception indexof byname byname hashmap addfile hashmap messageinvalidexception protocolerrormessage invalid_message hashmap byname addfile hashmap static final string name client put complex dir override public string get name return name clientputcomplexdir getname override long data length return attached bytes datalength attachedbytes string get identifier return identifier getidentifier override public void read from input stream is bucket factory bf fcp server server throws io exception message invalid exception iterator dir put file i files to read iterator while i has next direct dir put file f direct dir put file i next f read is readfrom inputstream bucketfactory fcpserver ioexception messageinvalidexception dirputfile filestoread hasnext directdirputfile directdirputfile override protected void write data output stream os throws io exception iterator dir put file i files to read iterator while i has next direct dir put file f direct dir put file i next f write os writedata outputstream ioexception dirputfile filestoread hasnext directdirputfile directdirputfile override public void run fcp connection handler handler node node throws message invalid exception convert the hierarchical hashmap s of dir put file s to hierarchical hashmap s of manifest element s then simply create the client put dir hash map string object manifest elements new hash map string object convert files by name to manifest elements files by name manifest elements node handler start client put dir this manifest elements false fcpconnectionhandler messageinvalidexception dirputfile manifestelement clientputdir hashmap manifestelements hashmap convertfilesbynametomanifestelements filesbyname manifestelements startclientputdir manifestelements convert a hierarchy of hash map s containing dir put file s into a hierarchy of hash map s containing manifest element s suppress warnings unchecked private void convert files by name to manifest elements hash map string object files by name hash map string object manifest elements node node throws message invalid exception for map entry string object entry files by name entry set string temp name entry get key object val entry get value if val instanceof hash map hash map string object h hash map string object val hash map string object manifests new hash map string object manifest elements put temp name manifests convert files by name to manifest elements h manifests node else dir put file f dir put file val if f instanceof disk dir put file node client core allow upload from disk dir put file f get file throw new message invalid exception protocol error message access denied not allowed to upload disk dir put file f get file identifier global manifest element e f get element manifest elements put temp name e hashmap dirputfile hashmap manifestelement suppresswarnings convertfilesbynametomanifestelements hashmap filesbyname hashmap manifestelements messageinvalidexception filesbyname entryset tempname getkey getvalue hashmap hashmap hashmap hashmap hashmap manifestelements tempname convertfilesbynametomanifestelements dirputfile dirputfile diskdirputfile clientcore allowuploadfrom diskdirputfile getfile messageinvalidexception protocolerrormessage access_denied diskdirputfile getfile manifestelement getelement manifestelements tempname override public void remove from object container container files to read clear container activate files by name integer max value remove from container files by name container delete this removefrom objectcontainer filestoread filesbyname max_value removefrom filesbyname private void remove from object container container hash map files by name iterator i files by name values iterator while i has next object val i next if val instanceof hash map remove from container hash map val else dir put file val remove from container container delete files by name removefrom objectcontainer hashmap filesbyname filesbyname hasnext hashmap removefrom hashmap dirputfile removefrom filesbyname public final runnable thread new runnable public void run synchronized this while has node started try wait 1000 catch interrupted exception e try inner store catch io exception e string err cannot store config e logger error this err e system err println err e print stack trace synchronized store sync is writing config false hasnodestarted interruptedexception innerstore ioexception printstacktrace storesync iswritingconfig public freenet file persistent config simple field set set file filename file temp filename throws io exception super set filename temp filename freenetfilepersistentconfig simplefieldset tempfilename ioexception tempfilename public static freenet file persistent config construct freenet file persistent config file f throws io exception file filename f file temp filename new file f get path tmp return new freenet file persistent config load filename temp filename filename temp filename freenetfilepersistentconfig constructfreenetfilepersistentconfig ioexception tempfilename getpath freenetfilepersistentconfig tempfilename tempfilename override public void store synchronized this if finished init logger minor this initialization not finished refusing to write config new exception error return synchronized store sync if is writing config ticker null logger normal this already writing the config file to disk or the node object hasn t been set refusing to proceed return is writing config true ticker queue timed job thread 0 finishedinit storesync iswritingconfig iswritingconfig queuetimedjob public void finished init ticker ticker super finished init this ticker ticker finishedinit finishedinit public void set has node started synchronized this if has node started logger error this it has already been called that shouldn t happen this has node started true notify all sethasnodestarted hasnodestarted hasnodestarted notifyall public service resolver jmdns impl jmdns impl string type this jmdns impl jmdns impl this type type serviceresolver jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl public void start timer timer timer schedule this dns constants query wait interval dns constants query wait interval dnsconstants query_wait_interval dnsconstants query_wait_interval public void run try if this jmdns impl get state dns state announced if count 3 logger finer run jmdns querying service long now system current time millis dns outgoing out new dns outgoing dns constants flags qr query out add question new dns question type dns constants type ptr dns constants class in for iterator s this jmdns impl get services values iterator s has next final service info impl info service info impl s next try out add answer new dns record pointer info get type dns constants type ptr dns constants class in dns constants dns ttl info get qualified name now catch io exception ee break this jmdns impl send out else after three queries we can quit this cancel else if this jmdns impl get state dns state canceled this cancel catch throwable e logger log level warning run exception e this jmdns impl recover jmdnsimpl getstate dnsstate currenttimemillis dnsoutgoing dnsoutgoing dnsconstants flags_qr_query addquestion dnsquestion dnsconstants type_ptr dnsconstants class_in jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl addanswer dnsrecord gettype dnsconstants type_ptr dnsconstants class_in dnsconstants dns_ttl getqualifiedname ioexception jmdnsimpl jmdnsimpl getstate dnsstate jmdnsimpl private final int hash code sendable request boolean persistent this persistent persistent this hash code super hash code hashcode sendablerequest hashcode hashcode override public final int hash code return hash code hashcode hashcode protected final boolean persistent get the priority class of the request public abstract short get priority class object container container getpriorityclass objectcontainer public abstract short get priority class object container container public abstract int get retry count getpriorityclass objectcontainer getretrycount choose a key to fetch removes the block number from any internal queues but not the key itself implementors must have a separate queue of block numbers and mapping of block numbers to keys return an object identifying a specific key null indicates no keys available public abstract sendable request item choose key keys fetching locally keys object container container client context context all key identifiers including those not currently eligible to be sent because they are on a cooldown queue requests for them are in progress etc public abstract long count all keys object container container client context context sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext countallkeys objectcontainer clientcontext public abstract long count all keys object container container client context context all key identifiers currently eligible to be sent does not include those currently running on the cooldown queue etc public abstract long count sendable keys object container container client context context countallkeys objectcontainer clientcontext countsendablekeys objectcontainer clientcontext get or create a sendable request sender for this object this is a non persistent object used to send the requests see sendable get get sender param container a database handle may be necessary for creating it param context a client context may also be necessary return sendablerequestsender sendableget getsender public abstract sendable request sender get sender object container container client context context if true the request has been cancelled or has completed either way it need not be registered any more is empty on the other hand means there are no queued blocks public abstract boolean is cancelled object container container sendablerequestsender getsender objectcontainer clientcontext isempty iscancelled objectcontainer public abstract boolean is cancelled object container container get client context object this isn t called as frequently as you might expect once on registration and then when there is an error so it doesn t need to be stored on the request itself hence we pass in a container public abstract request client get client object container container iscancelled objectcontainer requestclient getclient objectcontainer public abstract request client get client object container container is this request persistent must not change public final boolean persistent return persistent requestclient getclient objectcontainer get the client request this does need to be cached on the request itself public abstract client requester get client request clientrequest clientrequester getclientrequest public abstract client requester get client request public synchronized random grab array get parent grab array return parent grab array clientrequester getclientrequest randomgrabarray getparentgrabarray parentgrabarray public boolean knows parent grab array return true knowsparentgrabarray public synchronized void set parent grab array random grab array parent object container container parent grab array parent if persistent container store this setparentgrabarray randomgrabarray objectcontainer parentgrabarray public void unregister object container container client context context random grab array arr get parent grab array if arr null if persistent container activate arr 1 arr remove this container else should this be a higher priority if logger should log logger minor this logger minor this cannot unregister this not registered new exception debug client requester cr get client request if persistent container activate cr 1 get scheduler context remove from all requests by client request cr this true container fixme should we deactivate if persistent container deactivate cr 1 objectcontainer clientcontext randomgrabarray getparentgrabarray shouldlog clientrequester getclientrequest getscheduler removefromallrequestsbyclientrequest public abstract client request scheduler get scheduler client context context clientrequestscheduler getscheduler clientcontext public abstract client request scheduler get scheduler client context context is this an ssk for purposes of determining which scheduler to use public abstract boolean isssk clientrequestscheduler getscheduler clientcontext public abstract boolean isssk is this an insert for purposes of determining which scheduler to use public abstract boolean is insert isinsert public abstract boolean is insert requeue after an internal error public abstract void internal error throwable t request scheduler sched object container container client context context boolean persistent isinsert internalerror requestscheduler objectcontainer clientcontext public abstract void internal error throwable t request scheduler sched object container container client context context boolean persistent construct a full set of chosen block s for a persistent request these are transient so we will need to clone keys etc public abstract list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context internalerror requestscheduler objectcontainer clientcontext chosenblock persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext public class darknet connections toadlet extends connections toadlet darknet connections toadlet node n node client core core high level simple client client super n core client darknetconnectionstoadlet connectionstoadlet darknetconnectionstoadlet nodeclientcore highlevelsimpleclient override public string supported methods return get post supportedmethods private static string l10n string string return l10n get string darknet connections toadlet string getstring darknetconnectionstoadlet protected class darknet comparator extends comparator by status darknet comparator string sort by boolean reversed super sort by reversed darknetcomparator comparatorbystatus darknetcomparator sortby sortby override protected int custom compare peer node status first node peer node status second node string sort by if sort by equals name return darknet peer node status first node get name compare to ignore case darknet peer node status second node get name else if sort by equals privnote return darknet peer node status first node get private darknet comment note compare to ignore case darknet peer node status second node get private darknet comment note else return super custom compare first node second node sort by customcompare peernodestatus firstnode peernodestatus secondnode sortby sortby darknetpeernodestatus firstnode getname comparetoignorecase darknetpeernodestatus secondnode getname sortby darknetpeernodestatus firstnode getprivatedarknetcommentnote comparetoignorecase darknetpeernodestatus secondnode getprivatedarknetcommentnote customcompare firstnode secondnode sortby default comparison after taking into account status override protected int last resort compare peer node status first node peer node status second node return darknet peer node status first node get name compare to ignore case darknet peer node status second node get name lastresortcompare peernodestatus firstnode peernodestatus secondnode darknetpeernodestatus firstnode getname comparetoignorecase darknetpeernodestatus secondnode getname override protected comparator peer node status comparator string sort by boolean reversed return new darknet comparator sort by reversed peernodestatus sortby darknetcomparator sortby override protected boolean has name column return true hasnamecolumn override protected void draw name column html node peer row peer node status peer node status name column peer row add child td class peer name add child a href send n2ntm peernode hashcode peer node status hash code darknet peer node status peer node status get name drawnamecolumn htmlnode peerrow peernodestatus peernodestatus peerrow addchild addchild send_n2ntm peernode_hashcode peernodestatus hashcode darknetpeernodestatus peernodestatus getname override protected boolean has private note column return true hasprivatenotecolumn override protected void draw private note column html node peer row peer node status peer node status boolean f proxy javascript enabled private darknet node comment note column darknet peer node status status darknet peer node status peer node status if f proxy javascript enabled peer row add child td class peer private darknet comment note add child input new string type name size maxlength on blur on change value new string text peerprivatenote peer node status hash code 16 250 peer note blur peer note change status get private darknet comment note else peer row add child td class peer private darknet comment note add child input new string type name size maxlength value new string text peerprivatenote peer node status hash code 16 250 status get private darknet comment note drawprivatenotecolumn htmlnode peerrow peernodestatus peernodestatus fproxyjavascriptenabled darknetpeernodestatus darknetpeernodestatus peernodestatus fproxyjavascriptenabled peerrow addchild addchild onblur onchange peerprivatenote_ peernodestatus hashcode peernoteblur peernotechange getprivatedarknetcommentnote peerrow addchild addchild peerprivatenote_ peernodestatus hashcode getprivatedarknetcommentnote override protected simple field set get noderef return node export darknet public field set simplefieldset getnoderef exportdarknetpublicfieldset override protected peer node status get peer node statuses boolean no heavy return node peers get darknet peer node statuses no heavy peernodestatus getpeernodestatuses noheavy getdarknetpeernodestatuses noheavy override protected string get page title string title count string string my name return l10n get string darknet connections toadlet full title new string counts name new string title count string node get my name getpagetitle titlecountstring myname getstring darknetconnectionstoadlet fulltitle titlecountstring getmyname override protected boolean should draw noderef box boolean advanced mode enabled return true shoulddrawnoderefbox advancedmodeenabled override protected boolean show peer actions box return true showpeeractionsbox override protected void draw peer action select box html node peer form boolean advanced mode enabled html node action select peer form add child select new string id name new string action action action select add child option value l10n select action action select add child option value send n2ntm l10n send message to peers action select add child option value update notes l10n update changed privnotes if advanced mode enabled action select add child option value enable enable selected peers action select add child option value disable disable selected peers action select add child option value set burst only on selected peers set burst only only set this if you have a static ip and are not na ted and neither is the peer action select add child option value clear burst only on selected peers clear burst only action select add child option value set listen only on selected peers set listen only not recommended action select add child option value clear listen only on selected peers clear listen only action select add child option value set allow local on selected peers set allow local addresses useful if you are connecting to another node on the same lan action select add child option value clear allow local on selected peers clear allow local addresses action select add child option value set ignore source port on selected peers set ignore source port try this if behind an evil corporate firewall otherwise not recommended action select add child option value clear ignore source port on selected peers clear ignore source port action select add child option value set dont route on selected peers set dont route you shouldn t use that unless you know what you re doing really action select add child option value clear dont route on selected peers clear dont route action select add child option value l10n separator action select add child option value remove l10n remove peers peer form add child input new string type name value new string submit do action l10n go drawpeeractionselectbox htmlnode peerform advancedmodeenabled htmlnode actionselect peerform addchild actionselect addchild selectaction actionselect addchild send_n2ntm sendmessagetopeers actionselect addchild update_notes updatechangedprivnotes advancedmodeenabled actionselect addchild actionselect addchild actionselect addchild set_burst_only burstonly nated actionselect addchild clear_burst_only burstonly actionselect addchild set_listen_only listenonly actionselect addchild clear_listen_only listenonly actionselect addchild set_allow_local allowlocaladdresses actionselect addchild clear_allow_local allowlocaladdresses actionselect addchild set_ignore_source_port ignoresourceport actionselect addchild clear_ignore_source_port ignoresourceport actionselect addchild set_dont_route dontroute actionselect addchild clear_dont_route dontroute actionselect addchild actionselect addchild removepeers peerform addchild doaction override protected string get peer list title return l10n my friends getpeerlisttitle myfriends override protected boolean accept ref posts return true acceptrefposts override protected string default redirect location return friends fixme defaultredirectlocation implement other post actions than adding nodes throws io exception throws toadlet context closed exception throws redirect exception override protected void handle alt post uri uri http request request toadlet context ctx boolean logminor throws toadlet context closed exception io exception redirect exception if request is part set do action request get part as string action 25 equals send n2ntm html node page node ctx get page maker get page node l10n send message title ctx html node content node ctx get page maker get content node page node darknet peer node peer nodes node get darknet connections hash map string string peers new hash map string string for darknet peer node pn peer nodes if request is part set node pn hash code string peer name pn get name string peer hash pn hash code if peers contains key peer hash peers put peer hash peer name n2ntm toadlet createn2ntm send form page node content node ctx peers writehtml reply ctx 200 ok page node generate return else if request is part set do action request get part as string action 25 equals update notes int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set peerprivatenote peer nodes i hash code if request get part as string peerprivatenote peer nodes i hash code 250 equals peer nodes i get private darknet comment note peer nodes i set private darknet comment note request get part as string peerprivatenote peer nodes i hash code 250 redirect here ctx return else if request is part set do action request get part as string action 25 equals enable int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i enable peer redirect here ctx return else if request is part set do action request get part as string action 25 equals disable int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i disable peer redirect here ctx return else if request is part set do action request get part as string action 25 equals set burst only int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set burst only true redirect here ctx return else if request is part set do action request get part as string action 25 equals clear burst only int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set burst only false redirect here ctx return else if request is part set do action request get part as string action 25 equals set ignore source port int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set ignore source port true redirect here ctx return else if request is part set do action request get part as string action 25 equals clear ignore source port int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set ignore source port false redirect here ctx return else if request is part set do action request get part as string action 25 equals clear dont route darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set routing status true true redirect here ctx return else if request is part set do action request get part as string action 25 equals set dont route darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set routing status false true redirect here ctx return else if request is part set do action request get part as string action 25 equals set listen only int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set listen only true redirect here ctx return else if request is part set do action request get part as string action 25 equals clear listen only int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set listen only false redirect here ctx return else if request is part set do action request get part as string action 25 equals set allow local int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set allow local addresses true redirect here ctx return else if request is part set do action request get part as string action 25 equals clear allow local int hashcode integer decode request get param node int value darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code peer nodes i set allow local addresses false redirect here ctx return else if request is part set remove request is part set do action request get part as string action 25 equals remove if logminor logger minor this remove node darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code if peer nodes i time last connection completed system current time millis 1000 60 60 24 7 one week peer nodes i peer node status peer manager peer node status never connected request is part set forceit this node remove peer connection peer nodes i if logminor logger minor this removed node node peer nodes i hash code else if logminor logger minor this refusing to remove node peer nodes i hash code trying to prevent network churn let s display the warning message html node page node ctx get page maker get page node l10n confirm remove node title ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox warning l10n confirm remove node warning title html node content ctx get page maker get content node infobox content add child p add child l10n get string darknet connections toadlet confirm remove node new string name new string peer nodes i get name html node remove form ctx add form child content friends remove confirm form remove form add child input new string type name value new string hidden node peer nodes i hash code remove remove form add child input new string type name value new string submit cancel l10n get string toadlet cancel remove form add child input new string type name value new string submit remove l10n remove remove form add child input new string type name value new string hidden forceit l10n force remove writehtml reply ctx 200 ok page node generate return fixme maybe it breaks multi node removing else if logminor logger minor this part not set node peer nodes i hash code redirect here ctx return else if request is part set accept transfer fixme this is ugly should probably move both this code and the peer node code somewhere darknet peer node peer nodes node get darknet connections for int i 0 i peer nodes length i if request is part set node peer nodes i hash code long id long parse long request get part as string id 32 fixme handle number format exception peer nodes i accept transfer id break redirect here ctx return else if request is part set reject transfer ioexception toadletcontextclosedexception redirectexception handlealtpost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception ispartset doaction getpartasstring send_n2ntm htmlnode pagenode getpagemaker getpagenode sendmessagetitle htmlnode contentnode getpagemaker getcontentnode pagenode darknetpeernode peernodes getdarknetconnections hashmap hashmap darknetpeernode peernodes ispartset node_ hashcode peer_name getname peer_hash hashcode containskey peer_hash peer_hash peer_name n2ntmtoadlet createn2ntmsendform pagenode contentnode writehtmlreply pagenode ispartset doaction getpartasstring update_notes getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset peerprivatenote_ peernodes hashcode getpartasstring peerprivatenote_ peernodes hashcode peernodes getprivatedarknetcommentnote peernodes setprivatedarknetcommentnote getpartasstring peerprivatenote_ peernodes hashcode redirecthere ispartset doaction getpartasstring getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes enablepeer redirecthere ispartset doaction getpartasstring getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes disablepeer redirecthere ispartset doaction getpartasstring set_burst_only getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setburstonly redirecthere ispartset doaction getpartasstring clear_burst_only getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setburstonly redirecthere ispartset doaction getpartasstring set_ignore_source_port getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setignoresourceport redirecthere ispartset doaction getpartasstring clear_ignore_source_port getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setignoresourceport redirecthere ispartset doaction getpartasstring clear_dont_route darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setroutingstatus redirecthere ispartset doaction getpartasstring set_dont_route darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setroutingstatus redirecthere ispartset doaction getpartasstring set_listen_only getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setlistenonly redirecthere ispartset doaction getpartasstring clear_listen_only getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setlistenonly redirecthere ispartset doaction getpartasstring set_allow_local getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setallowlocaladdresses redirecthere ispartset doaction getpartasstring clear_allow_local getparam intvalue darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes setallowlocaladdresses redirecthere ispartset ispartset doaction getpartasstring darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode peernodes timelastconnectioncompleted currenttimemillis peernodes peernodestatus peermanager peer_node_status_never_connected ispartset removepeerconnection peernodes node_ peernodes hashcode node_ peernodes hashcode htmlnode pagenode getpagemaker getpagenode confirmremovenodetitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox confirmremovenodewarningtitle htmlnode getpagemaker getcontentnode addchild addchild getstring darknetconnectionstoadlet confirmremovenode peernodes getname htmlnode removeform addformchild removeconfirmform removeform addchild node_ peernodes hashcode removeform addchild getstring removeform addchild removeform addchild forceremove writehtmlreply pagenode node_ peernodes hashcode redirecthere ispartset accepttransfer peernode darknetpeernode peernodes getdarknetconnections peernodes ispartset node_ peernodes hashcode parselong getpartasstring numberformatexception peernodes accepttransfer redirecthere ispartset rejecttransfer private void redirect here toadlet context ctx throws toadlet context closed exception io exception multi value table string string headers new multi value table string string headers put location friends ctx send reply headers 302 found headers null 0 redirecthere toadletcontext toadletcontextclosedexception ioexception multivaluetable multivaluetable sendreplyheaders override protected boolean is opennet return false isopennet override simple column end column headers boolean advanced mode return null simplecolumn endcolumnheaders advancedmode private int threshold 2 public erode filter new color 0xffffffff erodefilter newcolor set the threshold the number of neighbouring pixels for dilation to occur param threshold the new threshold see get threshold public void set threshold int threshold this threshold threshold getthreshold setthreshold return the threshold the number of neighbouring pixels for dilation to occur return the current threshold see set threshold public int get threshold return threshold setthreshold getthreshold override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height for int i 0 i iterations i int index 0 if i 0 int t in pixels in pixels out pixels out pixels t for int y 0 y height y for int x 0 x width x int pixel in pixels y width x if black function is black pixel int neighbours 0 for int dy 1 dy 1 dy int iy y dy int ioffset if 0 iy iy height ioffset iy width for int dx 1 dx 1 dx int ix x dx if dy 0 dx 0 0 ix ix width int rgb in pixels ioffset ix if black function is black rgb neighbours if neighbours threshold if colormap null pixel colormap get color float i iterations else pixel new color out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels outpixels outpixels inpixels blackfunction isblack inpixels blackfunction isblack getcolor newcolor outpixels outpixels override public string to string return binary erode tostring public static final int max compressed data length data length 4 override public string to string return super to string chk chk max_compressed_data_length data_length tostring tostring return the header for this key do not modify this data public byte get headers return headers getheaders return the actual data for this key do not modify this data public byte get data return data getdata public static chk block construct byte data byte header throws chk verify exception return new chk block data header null true key algo aes pcfb 256 sha256 chkblock chkverifyexception chkblock algo_aes_pcfb_256_sha256 public chk block byte data2 byte header2 nodechk key throws chk verify exception this data2 header2 key key crypto algorithm chkblock chkverifyexception cryptoalgorithm public chk block byte data2 byte header2 nodechk key byte crypto algorithm throws chk verify exception this data2 header2 key true crypto algorithm chkblock cryptoalgorithm chkverifyexception cryptoalgorithm public chk block byte data2 byte header2 nodechk key boolean verify byte crypto algorithm throws chk verify exception data data2 headers header2 if headers length total headers length throw new illegal argument exception wrong length headers length should be total headers length hash identifier short headers 0 0xff 8 headers 1 0xff logger debug chk block class data length data length header length header length if key null verify this chk key hash code key hash code fields hash code data fields hash code headers crypto algorithm return minimal verification check the hash if hash identifier hash sha256 throw new chk verify exception hash not sha 256 message digest md sha256 get message digest md update headers md update data byte hash md digest sha256 return message digest md if key null chk new nodechk hash crypto algorithm else chk key byte check chk routing key if java util arrays equals hash check throw new chk verify exception hash does not verify otherwise it checks out hash code chk hash code fields hash code data fields hash code headers crypto algorithm chkblock cryptoalgorithm chkverifyexception total_headers_length illegalargumentexception total_headers_length hashidentifier chkblock hashcode hashcode hashcode hashcode cryptoalgorithm hashidentifier hash_sha256 chkverifyexception messagedigest getmessagedigest returnmessagedigest cryptoalgorithm routingkey chkverifyexception hashcode hashcode hashcode hashcode cryptoalgorithm public key get key return chk getkey public byte get raw headers return headers getrawheaders public byte get raw data return data getrawdata public byte get pubkey bytes return null getpubkeybytes public byte get full key return get key get full key getfullkey getkey getfullkey public byte get routing key return get key get routing key getroutingkey getkey getroutingkey override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof chk block return false chk block block chk block o if chk equals block chk return false if arrays equals data block data return false if arrays equals headers block headers return false if hash identifier block hash identifier return false return true chkblock chkblock chkblock hashidentifier hashidentifier public boolean object can new object container container storing an ssk block is not supported there are some complications so lets not implement this since we don t actually use the functionality atm the major problems are in both chk block and ssk block who is responsible for deleting the node keys we have to have them in the objects in ssk block who is responsible for deleting the dsa public key and the dsa group a group might be unique or might be shared between very many ss ks especially in the second case we don t want to just copy every time even for transient uses the best solution may be to copy in object can new but even then callers to the relevant getter methods may be a worry throw new unsupported operation exception block set storage in database not supported objectcannew objectcontainer sskblock chkblock sskblock sskblock dsapublickey dsagroup ssks objectcannew unsupportedoperationexception final random access file raf public random access file wrapper random access file raf this raf raf randomaccessfile randomaccessfilewrapper randomaccessfile public random access file wrapper file filename string mode throws file not found exception raf new random access file filename mode randomaccessfilewrapper filenotfoundexception randomaccessfile public void pread long file offset byte buf int buf offset int length throws io exception synchronized this raf seek file offset raf read fully buf buf offset length fileoffset bufoffset ioexception fileoffset readfully bufoffset public void pwrite long file offset byte buf int buf offset int length throws io exception synchronized this raf seek file offset raf write buf buf offset length fileoffset bufoffset ioexception fileoffset bufoffset public long size throws io exception return raf length ioexception public void close try raf close catch io exception e logger error this could not close raf e for this e ioexception public bookmark item freeneturi k string n string d boolean has an activelink user alert manager uam throws malformedurl exception this key k this name n this desc d this has an activelink has an activelink this alerts uam alert new bookmark updated user alert assert name null assert key null bookmarkitem hasanactivelink useralertmanager malformedurlexception hasanactivelink hasanactivelink bookmarkupdateduseralert public bookmark item string line user alert manager uam throws malformedurl exception string result line split this name result 0 this desc result 1 this has an activelink fields string to bool result 2 false this key new freeneturi result 3 this alerts uam this alert new bookmark updated user alert assert name null assert key null bookmarkitem useralertmanager malformedurlexception hasanactivelink stringtobool bookmarkupdateduseralert public bookmark item simple field set sfs user alert manager uam throws fs parse exception malformedurl exception this name sfs get name if name null name this desc sfs get description if desc null desc this has an activelink sfs get boolean has an activelink this key new freeneturi sfs get uri this alerts uam this alert new bookmark updated user alert bookmarkitem simplefieldset useralertmanager fsparseexception malformedurlexception hasanactivelink getboolean hasanactivelink bookmarkupdateduseralert private class bookmark updated user alert extends abstract user alert public bookmark updated user alert super true null null null null user alert minor false null true null bookmarkupdateduseralert abstractuseralert bookmarkupdateduseralert useralert override public string get title return l10n bookmark updated title name name gettitle bookmarkupdatedtitle override public string get text return l10n bookmark updated new string name edition new string name long to string key get suggested edition gettext bookmarkupdated tostring getsuggestededition override public html node gethtml text html node n new html node div l10n addl10n substitution n bookmark item bookmark updated with link new string link link name edition new string a href key to string a html encoder encode name long to string key get suggested edition return n htmlnode gethtmltext htmlnode htmlnode addl10nsubstitution bookmarkitem bookmarkupdatedwithlink tostring htmlencoder tostring getsuggestededition override public boolean is valid synchronized bookmark item this return updated isvalid bookmarkitem override public void is valid boolean validity if validity return disable bookmark isvalid disablebookmark override public string dismiss button text return l10n delete bookmark update notification dismissbuttontext deletebookmarkupdatenotification override public void on dismiss disable bookmark ondismiss disablebookmark override public string get short text return l10n bookmark updated short name name getshorttext bookmarkupdatedshort override public boolean is event notification return true iseventnotification private synchronized void disable bookmark updated false alerts unregister alert disablebookmark private string l10n string key return l10n get string bookmark item key getstring bookmarkitem private string l10n string key string pattern string value return l10n get string bookmark item key new string pattern new string value getstring bookmarkitem private string l10n string key string patterns string values return l10n get string bookmark item key patterns values getstring bookmarkitem private synchronized void enable bookmark if updated return updated true alerts register alert enablebookmark public string get key return key to string getkey tostring public synchronized freeneturi geturi return key public synchronized void update freeneturi uri boolean has an activelink string description this key uri this desc description this has an activelink has an activelink hasanactivelink hasanactivelink hasanactivelink public synchronized string get key type return key get key type getkeytype getkeytype override public string get name return equals name l10n unnamed bookmark name getname unnamedbookmark override public string to string return this name this desc null this desc this has an activelink this key to string tostring hasanactivelink tostring public synchronized void set edition long ed node client core node if key get suggested edition ed return key key set suggested edition ed enable bookmark setedition nodeclientcore getsuggestededition setsuggestededition enablebookmark public usk getusk throws malformedurl exception return usk create key malformedurlexception override public int hash code int hash super hash code hash 31 hash this key set suggested edition 0 hash code hash 31 hash this has an activelink 1 0 hash 31 hash this desc null this desc hash code 0 return hash hashcode hashcode setsuggestededition hashcode hasanactivelink hashcode override public boolean equals object o if o this return true if o instanceof bookmark item bookmark item b bookmark item o if super equals o return false if b key equals key if b key get key type equals usk if b key set suggested edition key get suggested edition equals key return false else return false if b alerts alerts return false belongs to a different node if b has an activelink has an activelink return false if b desc desc return true if b desc null desc null return false if b desc equals desc return false return true else return false bookmarkitem bookmarkitem bookmarkitem getkeytype setsuggestededition getsuggestededition hasanactivelink hasanactivelink public boolean has an activelink return has an activelink hasanactivelink hasanactivelink public string get description return desc null desc getdescription override public simple field set get simple field set simple field set sfs new simple field set true sfs put single name name sfs put single description desc sfs put has an activelink has an activelink sfs put single uri key to string return sfs simplefieldset getsimplefieldset simplefieldset simplefieldset putsingle putsingle hasanactivelink hasanactivelink putsingle tostring split file fetcher sub segment split file fetcher segment segment client requester parent int retry count super parent this segment segment this retry count retry count if parent null throw new null pointer exception ctx segment block fetch context block nums new vector integer logminor logger should log logger minor this splitfilefetchersubsegment splitfilefetchersegment clientrequester retrycount retrycount retrycount nullpointerexception blockfetchcontext blocknums shouldlog override public boolean dont cache object container container if persistent container activate ctx 1 if ctx null if segment null logger error this ctx null but segment null else logger error this ctx null and segment null on this return ctx cache local requests dontcache objectcontainer cachelocalrequests override public fetch context get context return ctx fetchcontext getcontext override public sendable request item choose key keys fetching locally keys object container container client context context if cancelled return null return get random block num keys context container sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext getrandomblocknum override public client key get key object token object container container if persistent container activate this 1 container activate segment 1 synchronized segment if cancelled if logminor logger minor this segment is finishing when getting key token on this return null client key key segment get block key my sendable request item token x container if key null if segment is finished container logger error this segment finished but didn t tell us this else if segment is finishing container logger error this segment finishing but didn t tell us this else logger error this segment not finishing yet still returns null for get key token for this new exception debug return key clientkey getkey objectcontainer clientkey getblockkey mysendablerequestitem isfinished isfinishing getkey fetch the array from the segment because we need to include all keys especially those on cooldown queues this is important when unregistering override public long count all keys object container container client context context if persistent container activate this 1 container activate segment 1 j16sdiz 22 dec 2008 client request schedular remove pending keys call this to get a list of request to be removed fixme client request schedular remove pending keys is leaking what s missing here return segment get key numbers at retry level retry count length countallkeys objectcontainer clientcontext clientrequestschedular removependingkeys clientrequestschedular removependingkeys getkeynumbersatretrylevel retrycount just those keys which are eligible to be started now override public long count sendable keys object container container client context context if persistent container activate this 1 container activate block nums 1 clean block nums container return block nums size countsendablekeys objectcontainer clientcontext blocknums cleanblocknums blocknums private void clean block nums object container container synchronized segment int init size block nums size integer prev null for int i 0 i block nums size i integer x block nums get i if x prev x equals prev block nums remove i i if persistent container delete x else prev x if block nums size init size logger error this cleaned block number list duplicates was init size now block nums size cleanblocknums objectcontainer initsize blocknums blocknums blocknums blocknums blocknums initsize initsize blocknums private sendable request item get random block num keys fetching locally keys client context context object container container if persistent container activate this 1 container activate block nums 1 container activate segment 1 logminor logger should log logger minor this synchronized segment if block nums is empty if logminor logger minor this no blocks to remove return null for int i 0 i 10 i integer ret int x if block nums size 0 return null x context random next int block nums size ret block nums get x int num ret key key segment get block node key num container if key null if segment is finishing container segment is finished container return null if segment have block num container logger error this already have block ret but was in block nums on this else logger error this key is null for block ret for this continue if keys has key key continue if logminor logger minor this removing block x of block nums size 1 ret on this return new my sendable request item num return null sendablerequestitem getrandomblocknum keysfetchinglocally clientcontext objectcontainer blocknums shouldlog blocknums isempty blocknums nextint blocknums blocknums getblocknodekey isfinishing isfinished haveblock blocknums haskey blocknums mysendablerequestitem private static class my sendable request item implements sendable request item final int x my sendable request item int x this x x mysendablerequestitem sendablerequestitem mysendablerequestitem this x x public void dump ignore we will be gc ed override public boolean has valid keys keys fetching locally keys object container container client context context if persistent container activate this 1 container activate block nums 1 container activate segment 1 boolean has set false boolean retval false synchronized segment for int i 0 i 10 i integer ret int x if block nums is empty break x context random next int block nums size ret block nums get x int block ret key key segment get block node key block container if key null if segment is finishing container segment is finished container return false if segment have block block container logger error this already have block ret but was in block nums on this in has valid keys else logger error this key is null for block ret for this in has valid keys block nums remove x if persistent container delete ret if has set has set true container store block nums continue if keys has key key continue retval true break if persistent container deactivate block nums 5 container deactivate segment 1 return retval hasvalidkeys keysfetchinglocally objectcontainer clientcontext blocknums hasset blocknums isempty nextint blocknums blocknums getblocknodekey isfinishing isfinished haveblock blocknums hasvalidkeys hasvalidkeys blocknums hasset hasset blocknums haskey blocknums override public boolean ignore store return ctx ignore store ignorestore ignorestore public void on failure bulk call failure item items object container container client context context fetch exception fetch exceptions new fetch exception items length int count fatal 0 if persistent container activate block nums 2 for int i 0 i items length i fetch exceptions i translate exception items i e if fetch exceptions i is fatal count fatal remove block num my sendable request item items i token x container true if persistent container store block nums container deactivate block nums 2 container activate segment 1 container activate parent 1 container activate segment errors 1 if parent is cancelled if logger should log logger minor this logger minor this failing cancelled fail the segment segment fail new fetch exception fetch exception cancelled container context false fixme do we need to free the key num s or will that happen later anyway return for int i 0 i fetch exceptions length i segment errors inc fetch exceptions i get mode int non fatal exceptions items length count fatal int block numbers new int non fatal exceptions if count fatal 0 fetch exception new fetch exceptions new fetch exception items length count fatal call the fatal callbacks directly int x 0 for int i 0 i items length i int block num my sendable request item items i token x if fetch exceptions i is fatal segment on fatal failure fetch exceptions i block num this container context else block numbers x block num new fetch exceptions x fetch exceptions i x fetch exceptions new fetch exceptions else for int i 0 i block numbers length i block numbers i my sendable request item items i token x segment on non fatal failure fetch exceptions block numbers this container context if persistent container deactivate segment 1 container deactivate parent 1 container deactivate segment errors 1 onfailure bulkcallfailureitem objectcontainer clientcontext fetchexception fetchexceptions fetchexception countfatal blocknums fetchexceptions translateexception fetchexceptions isfatal countfatal removeblocknum mysendablerequestitem blocknums blocknums iscancelled shouldlog fetchexception fetchexception keynum fetchexceptions fetchexceptions getmode nonfatalexceptions countfatal blocknumbers nonfatalexceptions countfatal fetchexception newfetchexceptions fetchexception countfatal blocknum mysendablerequestitem fetchexceptions isfatal onfatalfailure fetchexceptions blocknum blocknumbers blocknum newfetchexceptions fetchexceptions fetchexceptions newfetchexceptions blocknumbers blocknumbers mysendablerequestitem onnonfatalfailure fetchexceptions blocknumbers fixme refactor this out to a common method see simple single file fetcher private fetch exception translate exception low level get exception e switch e code case low level get exception data not found case low level get exception data not found in store return new fetch exception fetch exception data not found case low level get exception recently failed return new fetch exception fetch exception recently failed case low level get exception decode failed return new fetch exception fetch exception block decode error case low level get exception internal error return new fetch exception fetch exception internal error case low level get exception rejected overload return new fetch exception fetch exception rejected overload case low level get exception route not found return new fetch exception fetch exception route not found case low level get exception transfer failed return new fetch exception fetch exception transfer failed case low level get exception verify failed return new fetch exception fetch exception block decode error case low level get exception cancelled return new fetch exception fetch exception cancelled default logger error this unknown low level get exception code e code return new fetch exception fetch exception internal error unknown error code e code simplesinglefilefetcher fetchexception translateexception lowlevelgetexception lowlevelgetexception data_not_found lowlevelgetexception data_not_found_in_store fetchexception fetchexception data_not_found lowlevelgetexception recently_failed fetchexception fetchexception recently_failed lowlevelgetexception decode_failed fetchexception fetchexception block_decode_error lowlevelgetexception internal_error fetchexception fetchexception internal_error lowlevelgetexception rejected_overload fetchexception fetchexception rejected_overload lowlevelgetexception route_not_found fetchexception fetchexception route_not_found lowlevelgetexception transfer_failed fetchexception fetchexception transfer_failed lowlevelgetexception verify_failed fetchexception fetchexception block_decode_error lowlevelgetexception fetchexception fetchexception lowlevelgetexception fetchexception fetchexception internal_error translate it then call the real on failure override public void on failure low level get exception e object token object container container client context context if logminor logger minor this on failure e token on this on failure translate exception e token container context onfailure onfailure lowlevelgetexception objectcontainer clientcontext onfailure onfailure translateexception real on failure protected void on failure fetch exception e object token object container container client context context if persistent container activate segment 1 container activate parent 1 container activate segment errors 1 boolean force fatal false if parent is cancelled if logger should log logger minor this logger minor this failing cancelled e new fetch exception fetch exception cancelled force fatal true segment errors inc e get mode if e is fatal token null segment fail e container context false else if e is fatal force fatal segment on fatal failure e my sendable request item token x this container context else segment on non fatal failure e my sendable request item token x this container context remove block num my sendable request item token x container false if persistent container deactivate segment 1 container deactivate parent 1 container deactivate segment errors 1 onfailure onfailure fetchexception objectcontainer clientcontext forcefatal iscancelled shouldlog fetchexception fetchexception forcefatal getmode isfatal isfatal forcefatal onfatalfailure mysendablerequestitem onnonfatalfailure mysendablerequestitem removeblocknum mysendablerequestitem protected void on success bucket data boolean from store integer token int block no client key block block object container container client context context if persistent container activate this 1 container activate segment 1 container activate parent 1 if parent is cancelled data free if persistent data remove from container on failure new fetch exception fetch exception cancelled token container context return segment on success data block no block container context this onsuccess fromstore blockno clientkeyblock objectcontainer clientcontext iscancelled removefrom onfailure fetchexception fetchexception onsuccess blockno convert a client key block to a bucket if an error occurs report it via on failure and return null protected bucket extract client key block block object token object container container client context context bucket data try data block decode context get bucket factory persistent int math min ctx max output length integer max value false catch key decode exception e1 if logger should log logger minor this logger minor this decode failure e1 e1 on failure new fetch exception fetch exception block decode error e1 get message token container context return null catch too big exception e on failure new fetch exception fetch exception too big e get message token container context return null catch io exception e logger error this could not capture data disk full e e on failure new fetch exception fetch exception bucket error e token container context return null if logger should log logger minor this logger minor this data null could not decode null decoded data size bytes return data clientkeyblock onfailure clientkeyblock objectcontainer clientcontext getbucketfactory maxoutputlength max_value keydecodeexception shouldlog onfailure fetchexception fetchexception block_decode_error getmessage toobigexception onfailure fetchexception fetchexception too_big getmessage ioexception onfailure fetchexception fetchexception bucket_error shouldlog override public request client get client object container container if persistent container activate parent 1 return parent get client requestclient getclient objectcontainer getclient override public client requester get client request return parent clientrequester getclientrequest override public short get priority class object container container if persistent container activate parent 1 return parent priority class getpriorityclass objectcontainer priorityclass override public int get retry count return retry count getretrycount retrycount override public boolean is cancelled object container container if persistent container activate parent 1 container activate segment 1 synchronized segment return parent cancelled iscancelled objectcontainer public boolean is empty object container container if persistent container activate this 1 container activate block nums 1 synchronized segment return cancelled block nums is empty isempty objectcontainer blocknums blocknums isempty override public boolean isssk not allowed in splitfiles return false public void add all int blocks object container container client context context boolean dont complain on dupes int list new int blocks for int i 0 i blocks i list i i add all list container context dont complain on dupes addall objectcontainer clientcontext dontcomplainondupes addall dontcomplainondupes public void add all int blocks object container container client context context boolean dont complain on dupes if persistent container activate segment 1 container activate block nums 1 boolean logminor logger should log logger minor this if logminor logger minor this adding blocks blocks to this synchronized segment if cancelled throw new illegal state exception adding blocks to already cancelled this for int x 0 x blocks length x int i blocks x integer ii integer value of i if block nums contains ii if dont complain on dupes logger error this block numbers already contain block i else if logminor logger minor this block numbers already contain block i else block nums add ii if persistent container store block nums addall objectcontainer clientcontext dontcomplainondupes blocknums shouldlog illegalstateexception valueof blocknums dontcomplainondupes blocknums blocknums return true if the caller should schedule public boolean add int block no object container container client context context boolean dont complain on dupes if persistent container activate segment 1 container activate block nums 1 boolean logminor logger should log logger minor this if logminor logger minor this adding block block no to this if block no 0 throw new illegal argument exception integer i integer value of block no boolean schedule true synchronized segment if cancelled throw new illegal state exception adding block block no to already cancelled this if block nums contains i if dont complain on dupes logger error this block numbers already contain block block no else if logminor logger minor this block numbers already contain block block no else block nums add i race condition starter thread sees there is only one block on us so removes us another thread adds a block we don t schedule as we now have two blocks starter thread removes us other blocks may be added later but we are never rescheduled fixing this by only removing the sendable request after we ve removed the block is nontrivial with the current code so what we do here is simply check whether we are registered instead of checking whether block nums size 1 as we used to if schedule get parent grab array null if logminor logger minor this already registered not scheduling block nums size block nums schedule false if persistent container store block nums return schedule blockno objectcontainer clientcontext dontcomplainondupes blocknums shouldlog blockno blockno illegalargumentexception valueof blockno illegalstateexception blockno blocknums dontcomplainondupes blockno blockno blocknums sendablerequest blocknums getparentgrabarray blocknums blocknums blocknums override public string to string return super to string retry count segment block nums null null string value of block nums size tempid object hash tostring tostring retrycount blocknums valueof blocknums objecthash if there are no more blocks cancel the sub segment remove it from the segment and return true the caller must call kill true true else return false param container param context return public boolean possibly remove from parent object container container client context context if persistent container activate this 1 container activate segment 1 container activate block nums 1 if logminor logger minor this possibly removing from parent this synchronized segment if block nums is empty if persistent container deactivate block nums 1 return false if logminor logger minor this definitely removing from parent this if segment maybe remove seg this container if persistent container deactivate block nums 1 return false cancelled true return true subsegment possiblyremovefromparent objectcontainer clientcontext blocknums blocknums isempty blocknums mayberemoveseg blocknums public void on got key key key key block block object container container client context context if persistent container activate this 1 container activate segment 1 container activate block nums 1 if logminor logger minor this on got key key find and remove block if it is on this subsegment however it may have been removed already int block no synchronized segment for int i 0 i block nums size i integer token block nums get i int num token key k segment get block node key num container if k null k equals key block nums remove i if persistent container delete token break block no segment get block number key container if block no 1 logger minor this no block found for key key on this return integer token integer value of block no clientchk ckey segment get block key block no container clientchk block cb try cb new clientchk block chk block block ckey catch chk verify exception e on failure new fetch exception fetch exception block decode error e token container context return bucket data extract cb token container context if data null return if cb is metadata on success data false token token int value cb container context else on failure new fetch exception fetch exception invalid metadata metadata where expected data token container context ongotkey keyblock objectcontainer clientcontext blocknums ongotkey blockno blocknums blocknums getblocknodekey blocknums blockno getblocknumber blockno valueof blockno getblockkey blockno clientchkblock clientchkblock chkblock chkverifyexception onfailure fetchexception fetchexception block_decode_error ismetadata onsuccess intvalue onfailure fetchexception fetchexception invalid_metadata terminate a subsegment called by the segment which will have already removed the subsegment from the list will delete the object from the database if persistent public void kill object container container client context context boolean dont deactivate seg boolean cancelled already if persistent container activate segment 1 container activate block nums 1 if logminor logger minor this killing this do unregister first so can get and unregister each key and avoid a memory leak unregister container context integer old nums null synchronized segment if cancelled already if cancelled logger error this should be cancelled already this new exception error cancelled true if block nums is empty logger error this block nums not empty on this block nums new exception error else if cancelled return cancelled true if persistent old nums block nums to array new integer block nums size block nums clear if persistent old nums null old nums length 0 for integer i old nums container delete i if persistent remove from container context dont deactivate seg objectcontainer clientcontext dontdeactivateseg cancelledalready blocknums oldnums cancelledalready blocknums isempty blocknums oldnums blocknums toarray blocknums blocknums oldnums oldnums oldnums removefrom dontdeactivateseg public void remove from object container container client context context boolean dont deactivate seg container activate segment 1 container activate block nums 1 synchronized segment if cancelled logger error this removing when not cancelled on this new exception error cancelled true if block nums is empty logger error this removing when block nums not empty on this new exception error for integer i block nums container delete i block nums clear container delete block nums container delete this if dont deactivate seg container deactivate segment 1 we do not need to call sendable get as it has no internal data structures that need deleting removefrom objectcontainer clientcontext dontdeactivateseg blocknums blocknums isempty blocknums blocknums blocknums blocknums dontdeactivateseg sendableget override public long get cooldown wakeup object token object container container if persistent container activate this 1 container activate segment 1 long ret segment get cooldown wakeup my sendable request item token x return ret getcooldownwakeup objectcontainer getcooldownwakeup mysendablerequestitem override public void requeue after cooldown key key long time object container container client context context if persistent container activate segment 1 if logger should log logger minor this logger minor this requeueing after cooldown key for this if segment requeue after cooldown key time container context this logger error this key was not wanted after cooldown key for this in requeue after cooldown if persistent container deactivate segment 1 requeueaftercooldown objectcontainer clientcontext shouldlog requeueaftercooldown requeueaftercooldown override public long get cooldown wakeup by key key key object container container only deactivate if was deactivated in the first place see the remove pending key stack trace segment is the listener getter boolean activated false if persistent activated container ext is active segment if activated container activate segment 1 long ret segment get cooldown wakeup by key key container if persistent if activated container deactivate segment 1 return ret getcooldownwakeupbykey objectcontainer removependingkey isactive getcooldownwakeupbykey override public void reset cooldown times object container container if persistent container activate this 1 container activate segment 1 synchronized segment segment reset cooldown times block nums to array new integer block nums size resetcooldowntimes objectcontainer resetcooldowntimes blocknums toarray blocknums public void reschedule object container container client context context try get scheduler context register null new sendable get this persistent true container segment block fetch context blocks true catch key listener construction exception e logger error this impossible e on this e objectcontainer clientcontext getscheduler sendableget blockfetchcontext keylistenerconstructionexception public boolean remove block num int block num object container container boolean caller activates and sets if logminor logger minor this removing block block num from this if persistent caller activates and sets container activate block nums 2 boolean found false synchronized segment for int i 0 i block nums size i integer token block nums get i int num token if num block num block nums remove i if persistent container delete token if logminor logger minor this removed block block num from this found true break if persistent caller activates and sets container store block nums container deactivate block nums 2 return found removeblocknum blocknum objectcontainer calleractivatesandsets blocknum calleractivatesandsets blocknums blocknums blocknums blocknum blocknums blocknum calleractivatesandsets blocknums blocknums public void remove block nums int block nos object container container if persistent container activate block nums 2 boolean store false for int i 0 i block nos length i store remove block num block nos i container true if persistent if store container store block nums container deactivate block nums 2 removeblocknums blocknos objectcontainer blocknums blocknos removeblocknum blocknos blocknums blocknums override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context if persistent container activate segment 1 container activate block nums 1 integer block numbers synchronized this block numbers block nums to array new integer block nums size array list persistent chosen block blocks new array list persistent chosen block arrays sort block numbers int prev block number 1 for int i 0 i block numbers length i int block number block numbers i if block number prev block number logger error this duplicate block number in make blocks in this two copies of block number continue prev block number block number client key key segment get block key block number container if key null if logminor logger minor this block block number is null maybe race condition continue key key clone key key k key get node key persistent chosen block block new persistent chosen block false request new my sendable request item block number k key sched if logminor logger minor this created block block for block number block number on this blocks add block blocks trim to size if persistent container deactivate segment 1 container deactivate block nums 1 return blocks persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext blocknums blocknumbers blocknumbers blocknums toarray blocknums arraylist persistentchosenblock arraylist persistentchosenblock blocknumbers prevblocknumber blocknumbers blocknumber blocknumbers blocknumber prevblocknumber makeblocks blocknumber prevblocknumber blocknumber clientkey getblockkey blocknumber blocknumber clonekey getnodekey persistentchosenblock persistentchosenblock mysendablerequestitem blocknumber blocknumber trimtosize blocknums override public key list keys object container container boolean activated false if persistent activated container ext is active segment if activated container activate segment 1 key keys segment list keys container if persistent activated container deactivate segment 1 return keys listkeys objectcontainer isactive listkeys public int object hash return super hash code objecthash hashcode public boolean object can store object container container if block nums null throw new null pointer exception storing this but block nums null return true objectcanstore objectcontainer blocknums nullpointerexception blocknums override public void pre register object container container client context context boolean to network if to network return boolean deactivate false if persistent deactivate container ext is active parent container activate parent 1 parent to network container context if deactivate container deactivate parent 1 preregister objectcontainer clientcontext tonetwork tonetwork isactive tonetwork static boolean disable false dns requester node node this node node dnsrequester void start logger normal this starting dns requester system out println starting dns requester node executor execute this dns requester thread for node get darknet port number dnsrequester dnsrequester dnsrequester getdarknetportnumber public void run freenet support logger os thread logpid this while true try real run catch out of memory error e oom handler handleoom e system err println will retry above failed operation catch throwable t logger error this caught in dns requester t t osthread realrun outofmemoryerror oomhandler dnsrequester private void real run peer node nodes node peers my peers long now system current time millis if now last log time 1000 if logger should log logger minor this logger minor this processing dns requests log rate limited last log time now for int i 0 i nodes length i logger minor this node nodes i if nodes i is connected not connected try new dns lookup logger minor this doing lookup on nodes i of nodes length nodes i maybe update handshakei ps false try synchronized this wait 10000 sleep 10s catch interrupted exception e ignore just wake up just sleeping to not busy wait anyway realrun peernode mypeers currenttimemillis lastlogtime shouldlog lastlogtime isconnected maybeupdatehandshakeips interruptedexception public void force run synchronized this notify all forcerun notifyall public void run if should write peers should write peers false write peers inner node ps queue timed job write peers runnable min writepeers delay shouldwritepeers shouldwritepeers writepeersinner queuetimedjob writepeersrunnable min_writepeers_delay create a peer manager by reading a list of peers from a file param node param filename public peer manager node node logger normal this creating peer manager logminor logger should log logger minor this peer node statuses new hash map integer hash set peer node peer node statuses darknet new hash map integer hash set peer node peer node routing backoff reasons new hash map string hash set peer node system out println creating peer manager my peers new peer node 0 connected peers new peer node 0 this node node peermanager peermanager peermanager shouldlog peernodestatuses hashmap hashset peernode peernodestatusesdarknet hashmap hashset peernode peernoderoutingbackoffreasons hashmap hashset peernode peermanager mypeers peernode connectedpeers peernode attempt to read a file full of noderefs try the file as named first then the bak if it is empty or otherwise doesn t work param filename the filename to read from if this doesn t work we try the bak file param crypto the cryptographic identity which these nodes are connected to param opennet the opennet manager for the nodes only needed for constructing the nodes if is opennet param is opennet whether the file contains opennet peers param old opennet peers if true don t add the nodes to the routing table pass them to the opennet manager as old peers i e inactive nodes which may try to reconnect void try read peers string filename node crypto crypto opennet manager opennet boolean is opennet boolean old opennet peers synchronized write peers sync if old opennet peers if is opennet open filename filename else dark filename filename outgoing packet mangler mangler crypto packet mangler file peers file new file filename file backup file new file filename bak try to read the node list from disk if peers file exists if read peers peers file mangler crypto opennet old opennet peers string msg if old opennet peers msg read opennet count old opennet peers old opennet peers from peers file else if is opennet msg read get opennet peers length opennet peers from peers file else msg read get darknet peers length darknet peers from peers file logger normal this msg system out println msg return try the backup if backup file exists if read peers backup file mangler crypto opennet old opennet peers string msg if old opennet peers msg read opennet count old opennet peers old opennet peers from peers file else if is opennet msg read get opennet peers length opennet peers from peers file else msg read get darknet peers length darknet peers from peers file logger normal this msg system out println msg else logger error this no readable peers file with peers in it found system err println no readable peers file with peers in it found isopennet isopennet oldopennetpeers tryreadpeers nodecrypto opennetmanager isopennet oldopennetpeers writepeerssync oldopennetpeers isopennet openfilename darkfilename outgoingpacketmangler packetmangler peersfile backupfile peersfile readpeers peersfile oldopennetpeers oldopennetpeers countoldopennetpeers peersfile isopennet getopennetpeers peersfile getdarknetpeers peersfile backupfile readpeers backupfile oldopennetpeers oldopennetpeers countoldopennetpeers peersfile isopennet getopennetpeers peersfile getdarknetpeers peersfile private boolean read peers file peers file outgoing packet mangler mangler node crypto crypto opennet manager opennet boolean old opennet peers boolean got some false file input stream fis try fis new file input stream peers file catch file not found exception e4 logger normal this peers file not found peers file return false input stream reader ris try ris new input stream reader fis utf 8 catch unsupported encoding exception e4 throw new error impossible jvm doesn t support utf 8 e4 e4 buffered reader br new buffered reader ris try fixme no better way while true read a single node peer simple field set fs fs new simple field set br false true peer node pn try pn peer node create fs node crypto opennet this true mangler catch fs parse exception e2 logger error this could not parse peer e2 n fs to string e2 continue catch peer parse exception e2 logger error this could not parse peer e2 n fs to string e2 continue catch reference signature verification exception e2 logger error this could not parse peer e2 n fs to string e2 continue if old opennet peers opennet add old opennet node pn else add peer pn true false got some true catch eof exception e end of file fine catch io exception e1 logger error this could not read peers file e1 e1 try br close catch io exception e3 logger error this ignoring e3 caught reading peers file e3 return got some readpeers peersfile outgoingpacketmangler nodecrypto opennetmanager oldopennetpeers gotsome fileinputstream fileinputstream peersfile filenotfoundexception peersfile inputstreamreader inputstreamreader unsupportedencodingexception bufferedreader bufferedreader nodepeer simplefieldset simplefieldset peernode peernode fsparseexception tostring peerparseexception tostring referencesignatureverificationexception tostring oldopennetpeers addoldopennetnode addpeer gotsome eofexception ioexception ioexception peersfile gotsome public boolean add peer peer node pn return add peer pn false false addpeer peernode addpeer add a peer param pn the node to add to the routing table param ignore opennet if true don t check for opennet peers if false check for opennet peers and if so if opennet is enabled auto add them to the opennet lru otherwise fail param reactivate if true re enable the peer if it is in state disconnecting before re adding it return true if the node was successfully added false if it was already present or if we tried to add an opennet peer when opennet was disabled boolean add peer peer node pn boolean ignore opennet boolean reactivate assert pn null if reactivate pn force cancel disconnecting synchronized this for int i 0 i my peers length i if my peers i equals pn if logminor logger minor this can t add peer pn because already have my peers i new exception debug return false peer node new my peers new peer node my peers length 1 system arraycopy my peers 0 new my peers 0 my peers length new my peers my peers length pn my peers new my peers logger normal this added pn if pn record status add peer node status pn get peer node status pn false pn set peer node status system current time millis updatepm user alert if ignore opennet pn instanceof opennet peer node opennet manager opennet node get opennet if opennet null opennet force add peer pn true else logger error this adding opennet peer when no opennet enabled pn removing remove peer pn return false return true ignoreopennet addpeer peernode ignoreopennet forcecanceldisconnecting mypeers mypeers mypeers peernode newmypeers peernode mypeers mypeers newmypeers mypeers newmypeers mypeers mypeers newmypeers recordstatus addpeernodestatus getpeernodestatus setpeernodestatus currenttimemillis updatepmuseralert ignoreopennet opennetpeernode opennetmanager getopennet forceaddpeer removepeer synchronized boolean have peer peer node pn for int i 0 i my peers length i if my peers i pn return true return false havepeer peernode mypeers mypeers private boolean remove peer peer node pn if logminor logger minor this removing pn boolean is in peers false synchronized this for int i 0 i my peers length i if my peers i pn is in peers true if pn instanceof darknet peer node darknet peer node pn remove extra peer data dir if is in peers int peer node status pn get peer node status if pn record status remove peer node status peer node status pn is in peers string peer node previous routing backoff reason pn get previous backoff reason if peer node previous routing backoff reason null remove peer node routing backoff reason peer node previous routing backoff reason pn removing from connected peers array list peer node a new array list peer node for peer node mp my peers if mp pn mp is connected mp is real connection a add mp peer node new connected peers new peer node a size new connected peers a to array new connected peers connected peers new connected peers removing from my peers peer node new my peers new peer node my peers length 1 int position in new array 0 for peer node mp my peers if mp pn new my peers position in new array mp position in new array my peers new my peers logger normal this removed pn pn on remove if is in peers updatepm user alert return true removepeer peernode isinpeers mypeers mypeers isinpeers darknetpeernode darknetpeernode removeextrapeerdatadir isinpeers peernodestatus getpeernodestatus recordstatus removepeernodestatus peernodestatus isinpeers peernodepreviousroutingbackoffreason getpreviousbackoffreason peernodepreviousroutingbackoffreason removepeernoderoutingbackoffreason peernodepreviousroutingbackoffreason connectedpeers arraylist peernode arraylist peernode peernode mypeers isconnected isrealconnection peernode newconnectedpeers peernode newconnectedpeers toarray newconnectedpeers connectedpeers newconnectedpeers mypeers peernode newmypeers peernode mypeers positioninnewarray peernode mypeers newmypeers positioninnewarray positioninnewarray mypeers newmypeers onremove isinpeers updatepmuseralert public boolean remove all peers logger normal this remove all peers peer node old peers synchronized this old peers my peers my peers new peer node 0 connected peers new peer node 0 for int i 0 i old peers length i old peers i on remove return true removeallpeers removeallpeers peernode oldpeers oldpeers mypeers mypeers peernode connectedpeers peernode oldpeers oldpeers onremove public boolean disconnected peer node pn synchronized this boolean is in peers false for int i 0 i connected peers length i if connected peers i pn is in peers true if is in peers return false removing from connected peers array list peer node a new array list peer node for peer node mp my peers if mp pn mp is routable a add mp peer node new connected peers new peer node a size new connected peers a to array new connected peers connected peers new connected peers updatepm user alert node lm announce loc change return true peernode isinpeers connectedpeers connectedpeers isinpeers isinpeers connectedpeers arraylist peernode arraylist peernode peernode mypeers isroutable peernode newconnectedpeers peernode newconnectedpeers toarray newconnectedpeers connectedpeers newconnectedpeers updatepmuseralert announcelocchange long time first any connections 0 public long get time first any connections return time first any connections timefirstanyconnections gettimefirstanyconnections timefirstanyconnections public void add connected peer peer node pn logminor logger should log logger minor this if pn is real connection if logminor logger minor this not a real connection pn return if pn is connected if logminor logger minor this not connected pn return long now system current time millis synchronized this if time first any connections 0 time first any connections now for int i 0 i connected peers length i if connected peers i pn if logminor logger minor this already connected pn return boolean in my peers false for int i 0 i my peers length i if my peers i pn in my peers true break if in my peers logger error this connecting to pn but not in peers add peer pn if logminor logger minor this connecting pn peer node new connected peers new peer node connected peers length 1 system arraycopy connected peers 0 new connected peers 0 connected peers length new connected peers connected peers length pn connected peers new connected peers if logminor logger minor this connected peers connected peers length updatepm user alert node lm announce loc change addconnectedpeer peernode shouldlog isrealconnection isconnected currenttimemillis timefirstanyconnections timefirstanyconnections connectedpeers connectedpeers inmypeers mypeers mypeers inmypeers inmypeers addpeer peernode newconnectedpeers peernode connectedpeers connectedpeers newconnectedpeers connectedpeers newconnectedpeers connectedpeers connectedpeers newconnectedpeers connectedpeers updatepmuseralert announcelocchange find the node with the given peer address public peer node get by peer peer peer for int i 0 i my peers length i if my peers i is real connection continue if peer equals my peers i get peer return my peers i return null peernode getbypeer mypeers mypeers isrealconnection mypeers getpeer mypeers connect to a node provided the fieldset representing it public void connect simple field set noderef outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception peer node pn node create new darknet node noderef for int i 0 i my peers length i if arrays equals my peers i identity pn identity return add peer pn simplefieldset outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception peernode createnewdarknetnode mypeers mypeers addpeer disconnect from a specified node public void disconnect final peer node pn boolean send disconnect message final boolean wait for ack boolean purge if logminor logger minor this disconnecting pn short to string synchronized this if have peer pn return pn notify disconnecting if send disconnect message message msg dmt createfnp disconnect true purge 1 new short buffer new byte 0 try pn send async msg new async message callback boolean done false public void acknowledged done public void disconnected done public void fatal error done public void sent if wait for ack done void done synchronized this if done return done true if remove peer pn write peers ctr disconn catch not connected exception e if pn is disconnecting remove peer pn write peers return node get ticker queue timed job new runnable public void run if pn is disconnecting remove peer pn write peers node max peer inactivity else if remove peer pn write peers peernode senddisconnectmessage waitforack shorttostring havepeer notifydisconnecting senddisconnectmessage createfnpdisconnect shortbuffer sendasync asyncmessagecallback fatalerror waitforack removepeer writepeers ctrdisconn notconnectedexception isdisconnecting removepeer writepeers getticker queuetimedjob isdisconnecting removepeer writepeers max_peer_inactivity removepeer writepeers boolean done false public void acknowledged done public void disconnected done public void fatal error done fatalerror public void sent if wait for ack done waitforack void done synchronized this if done return done true if remove peer pn write peers removepeer writepeers node get ticker queue timed job new runnable public void run if pn is disconnecting remove peer pn write peers getticker queuetimedjob isdisconnecting removepeer writepeers final byte counter ctr disconn new byte counter public void received bytes int x node node stats disconn bytes received x bytecounter ctrdisconn bytecounter receivedbytes nodestats disconnbytesreceived public void sent bytes int x node node stats disconn bytes sent x sentbytes nodestats disconnbytessent public void sent payload int x ignore sentpayload long uid locationuid pair peer node pn location pn get location uid pn swap identifier locationuidpair peernode getlocation swapidentifier public int compare to locationuid pair p compare purely on location so result is the same as get peer location doubles if p location location return 1 if p location location return 1 return 0 compareto locationuidpair getpeerlocationdoubles return an array of the current locations as doubles of all our connected peers or double 0 if node shall we publish our peers location is false public double get peer location doubles boolean prune backed off peers double locs if node shall we publish our peers location return new double 0 peer node conns synchronized this conns connected peers locs new double conns length int x 0 for int i 0 i conns length i if conns i is routable if prune backed off peers conns i should be excluded from peer list locs x conns i get location wipe out any information contained in the order java util arrays sort locs 0 x if x locs length double new locs new double x system arraycopy locs 0 new locs 0 x return new locs else return locs shallwepublishourpeerslocation getpeerlocationdoubles prunebackedoffpeers shallwepublishourpeerslocation peernode connectedpeers isroutable prunebackedoffpeers shouldbeexcludedfrompeerlist getlocation newlocs newlocs newlocs just like get peer location doubles except it also returns the uid for each node public locationuid pair get peer locations andui ds peer node conns locationuid pair loc pairs synchronized this conns my peers loc pairs new locationuid pair conns length int x 0 for int i 0 i conns length i if conns i is routable loc pairs x new locationuid pair conns i sort it arrays sort loc pairs 0 x if x loc pairs length locationuid pair new locs new locationuid pair x system arraycopy loc pairs 0 new locs 0 x return new locs else return loc pairs getpeerlocationdoubles locationuidpair getpeerlocationsanduids peernode locationuidpair locpairs mypeers locpairs locationuidpair isroutable locpairs locationuidpair locpairs locpairs locationuidpair newlocs locationuidpair locpairs newlocs newlocs locpairs return a random routable connected peer fixme should this take performance into account do not remove the synchronized see below for why public synchronized peer node get random peer peer node exclude if connected peers length 0 return null for int i 0 i 5 i peer node pn connected peers node random next int connected peers length if pn exclude continue if pn is routable return pn none of them worked move the un connected ones out this is safe as they will add themselves when they reconnect and they can t do it yet as we are synchronized array list peer node v new array list peer node connected peers length logminor logger should log logger minor this for peer node pn my peers if pn exclude continue if pn is routable v add pn else if logminor logger minor this excluding pn because is disconnected int length without excluded v size if exclude null exclude is routable v add exclude peer node new connected peers new peer node v size new connected peers v to array new connected peers if logminor logger minor this connected peers in get random peer new connected peers length was connected peers length connected peers new connected peers if length without excluded 0 return null return connected peers node random next int length without excluded peernode getrandompeer peernode connectedpeers peernode connectedpeers nextint connectedpeers isroutable arraylist peernode arraylist peernode connectedpeers shouldlog peernode mypeers isroutable lengthwithoutexcluded isroutable peernode newconnectedpeers peernode newconnectedpeers toarray newconnectedpeers getrandompeer newconnectedpeers connectedpeers connectedpeers newconnectedpeers lengthwithoutexcluded connectedpeers nextint lengthwithoutexcluded asynchronously send this message to every connected peer public void local broadcast message msg boolean ignore routability boolean only real connections byte counter ctr peer node peers synchronized this my peers not connected peers as connected peers only contains routable peers and we may want to send to non routable peers peers my peers for int i 0 i peers length i if ignore routability if peers i is connected continue else if peers i is routable continue if only real connections peers i is real connection continue try peers i send async msg null ctr catch not connected exception e ignore localbroadcast ignoreroutability onlyrealconnections bytecounter peernode mypeers connectedpeers connectedpeers mypeers ignoreroutability isconnected isroutable onlyrealconnections isrealconnection sendasync notconnectedexception asynchronously send a differential node reference to every is connected peer public void locally broadcast diff node ref simple field set fs boolean to darknet only boolean to opennet only peer node peers synchronized this my peers not connected peers as connected peers only contains routable peers and we want to also send to non routable peers peers my peers for int i 0 i peers length i if peers i is connected continue if to darknet only peers i is darknet continue if to opennet only peers i is opennet continue peers i send node to node message fs node n2n message type diffnoderef false 0 false isconnected locallybroadcastdiffnoderef simplefieldset todarknetonly toopennetonly peernode mypeers connectedpeers connectedpeers mypeers isconnected todarknetonly isdarknet toopennetonly isopennet sendnodetonodemessage n2n_message_type_diffnoderef public peer node get random peer return get random peer null peernode getrandompeer getrandompeer public double closest peer location double loc double ignore loc int min uptime percent peer node peers synchronized this peers connected peers double best diff 1 0 double best loc double max value boolean found one false for int i 0 i peers length i peer node p peers i if p is routable continue if p is routing backed off continue if p get uptime min uptime percent continue double peerloc p get location if math abs peerloc ignore loc double min value 2 continue double diff location distance peerloc loc if diff best diff found one true best diff diff best loc peerloc if found one for int i 0 i peers length i peer node p peers i if p is routable continue if p get uptime min uptime percent continue ignore backoff state double peerloc p get location if math abs peerloc ignore loc double min value 2 continue double diff location distance peerloc loc if diff best diff found one true best diff diff best loc peerloc return best loc closestpeerlocation ignoreloc minuptimepercent peernode connectedpeers bestdiff bestloc max_value foundone peernode isroutable isroutingbackedoff getuptime minuptimepercent getlocation ignoreloc min_value bestdiff foundone bestdiff bestloc foundone peernode isroutable getuptime minuptimepercent getlocation ignoreloc min_value bestdiff foundone bestdiff bestloc bestloc public boolean is closer location double loc int min uptime percent double node loc node lm get location double node dist location distance node loc loc double closest closest peer location loc node loc min uptime percent if closest 1 0 no peers found return false double closest dist location distance closest loc return closest dist node dist iscloserlocation minuptimepercent nodeloc getlocation nodedist nodeloc closestpeerlocation nodeloc minuptimepercent closestdist closestdist nodedist public peer node closer peer peer node pn set peer node routed to double loc boolean ignore self boolean calculate misrouting int min version list double add unpicked locs to key key return closer peer pn routed to loc ignore self calculate misrouting min version add unpicked locs to 2 0 key peernode closerpeer peernode peernode routedto ignoreself calculatemisrouting minversion addunpickedlocsto closerpeer routedto ignoreself calculatemisrouting minversion addunpickedlocsto find the peer if any which is closer to the target location than we are and is not included in the provided set if ignore self false and we are closer to the target than any peers this function returns null this function returns two values the closest such peer which is backed off and the same which is not backed off it is possible for either to be null independent of the other closest is the closer of the two in either case and will not be null if any of the other two return values is not null param add unpicked locs to add all locations we didn t choose which we could have routed to to this array remove the location of the peer we pick from it param max distance if a node is further away from the target than this distance ignore it param key the original key if we have it and if we want to consult with the failure table to avoid routing to nodes which have recently failed for the same key public peer node closer peer peer node pn set peer node routed to double target boolean ignore self boolean calculate misrouting int min version list double add unpicked locs to double max distance key key peer node peers synchronized this peers connected peers if node enable per node failure tables key null if logminor logger minor this choosing closest peer connected peers peers length double max diff double max value if ignore self max diff location distance node lm get location target routing order non timed out non backed off peers in order of closeness to the target timed out non backed off peers least recently timed out first non timed out backed off peers in order of closeness to the target timed out backed off peers least recently timed out first peer node closest null double closest distance double max value peer node closest backed off null double closest backed off distance double max value peer node closest not backed off null double closest not backed off distance double max value peer node least recently timed out null long time least recently timed out long max value peer node least recently timed out backed off null long time least recently timed out backed off long max value timed out nodes list entry null if key null entry node failure table get timed out nodes list key long now system current time millis int count 0 double selection rates new double peers length double total selection rate 0 0 for int i 0 i peers length i selection rates i peers i selection rate total selection rate selection rates i boolean enablefoaf mitigation hack peers length peer node selection min peers total selection rate 0 0 for int i 0 i peers length i peer node p peers i if routed to contains p if logminor logger minor this skipping already routed to p get peer continue if p pn if logminor logger minor this skipping req came from p get peer continue if p is routable if logminor logger minor this skipping not connected p get peer continue if key null p is turtling key if logminor logger minor this skipping already turtling key p get peer if min version 0 version get arbitrary build number p get version 1 min version if logminor logger minor this skipping old version p get peer continue if enablefoaf mitigation hack double selection rate selection rates i double selection samples percentage selection rate total selection rate if peer node selection percentage warning selection samples percentage if logminor logger minor this skipping over selectionned peer selection samples percentage p get peer continue long timeout 1 if entry null timeout entry get timeout time p boolean timed out timeout now to help avoid odd race conditions get the location only once and use it for all calculations double loc p get location double diff location distance loc target double peers location p get peers location if peers location null node shall we route according to our peers location for double l peers location double new diff location distance l target if new diff diff loc l diff new diff if logminor logger minor this the peer p has published his peer s locations and the closest we have found to the target is diff away if diff max distance continue if ignore self diff max diff if logminor logger minor this ignoring further than self max diff max diff continue count if logminor logger minor this p loc loc target target d location distance loc target usedd diff timed out timed out for p get peer boolean chosen false if diff closest distance closest distance diff closest p chosen true if logminor logger minor this new best diff loc for p get peer boolean backed off p is routing backed off if backed off diff closest backed off distance timed out closest backed off distance diff closest backed off p chosen true if logminor logger minor this new best backed off diff loc for p get peer if backed off diff closest not backed off distance timed out closest not backed off distance diff closest not backed off p chosen true if logminor logger minor this new best not backed off diff loc for p get peer if timed out if backed off if timeout time least recently timed out time least recently timed out timeout least recently timed out p else if timeout time least recently timed out backed off time least recently timed out backed off timeout least recently timed out backed off p if add unpicked locs to null chosen double d new double loc here we can directly compare double s because they aren t processed in any way and are finite and probably nonzero if add unpicked locs to contains d add unpicked locs to add d peer node best closest not backed off various things are advisory i e they are taken into account but do not cause a request not to be routed at all backoff a node is backed off for a period after it rejects a request this is randomised and increases exponentially if no requests are accepted a longer period is imposed for timeouts after a request has been accepted and transfer failures recent failures after various kinds of failures we impose a timeout until when we will try to avoid sending the same key to that node this is part of per node failure tables combining these if there are nodes which are both not backed off and not timed out we route to whichever of those nodes is closest to the target location if we are still here all nodes are either backed off or timed out if there are nodes which are timed out but not backed off choose the node whose timeout expires soonest hence if a single key is requested continually we round robin between nodes if we still don t have a winner we know all nodes are backed off if there are nodes which are backed off but not timed out choose the node which is closest to the target but is not backed off if we still don t have a winner all nodes are backed off and timed out choose the backed off node whose timeout expires soonest if best null if least recently timed out null fixme downgrade to debug best least recently timed out if logminor logger minor this using least recently failed in timeout period peer for key best short to string for key else if closest backed off null best closest backed off if logminor logger minor this using best backed off peer for key best short to string else if least recently timed out backed off null best least recently timed out backed off if logminor logger minor this using least recently failed in timeout period backed off peer for key best short to string for key do not put a else here we need to re check the value if best null racy get location could have changed if calculate misrouting node node stats routing miss distance report location distance best closest get location int number of connected get peer node status size peer node status connected false int number of routing backed off get peer node status size peer node status routing backed off false if number of routing backed off number of connected 0 node node stats backed off percent report double number of routing backed off double number of routing backed off number of connected racy get location could have changed if add unpicked locs to null add the location which we did not pick if it exists if closest not backed off null closest backed off null add unpicked locs to add new double closest backed off get location increment selection samples now best return best ignoreself addunpickedlocsto maxdistance failuretable peernode closerpeer peernode peernode routedto ignoreself calculatemisrouting minversion addunpickedlocsto maxdistance peernode connectedpeers enablepernodefailuretables connectedpeers maxdiff max_value ignoreself maxdiff getlocation peernode closestdistance max_value peernode closestbackedoff closestbackedoffdistance max_value peernode closestnotbackedoff closestnotbackedoffdistance max_value peernode leastrecentlytimedout timeleastrecentlytimedout max_value peernode leastrecentlytimedoutbackedoff timeleastrecentlytimedoutbackedoff max_value timedoutnodeslist failuretable gettimedoutnodeslist currenttimemillis selectionrates totalselectionrate selectionrates selectionrate totalselectionrate selectionrates enablefoafmitigationhack peernode selection_min_peers totalselectionrate peernode routedto getpeer getpeer isroutable getpeer isturtling getpeer minversion getarbitrarybuildnumber getversion minversion getpeer enablefoafmitigationhack selectionrate selectionrates selectionsamplespercentage selectionrate totalselectionrate peernode selection_percentage_warning selectionsamplespercentage selectionsamplespercentage getpeer gettimeouttime timedout getlocation peerslocation getpeerslocation peerslocation shallwerouteaccordingtoourpeerslocation peerslocation newdiff newdiff newdiff maxdistance ignoreself maxdiff maxdiff maxdiff timedout timedout getpeer closestdistance closestdistance getpeer backedoff isroutingbackedoff backedoff closestbackedoffdistance timedout closestbackedoffdistance closestbackedoff getpeer backedoff closestnotbackedoffdistance timedout closestnotbackedoffdistance closestnotbackedoff getpeer timedout backedoff timeleastrecentlytimedout timeleastrecentlytimedout leastrecentlytimedout timeleastrecentlytimedoutbackedoff timeleastrecentlytimedoutbackedoff leastrecentlytimedoutbackedoff addunpickedlocsto addunpickedlocsto addunpickedlocsto peernode closestnotbackedoff leastrecentlytimedout leastrecentlytimedout shorttostring closestbackedoff closestbackedoff shorttostring leastrecentlytimedoutbackedoff leastrecentlytimedoutbackedoff shorttostring getlocation calculatemisrouting nodestats routingmissdistance getlocation numberofconnected getpeernodestatussize peer_node_status_connected numberofroutingbackedoff getpeernodestatussize peer_node_status_routing_backed_off numberofroutingbackedoff numberofconnected nodestats backedoffpercent numberofroutingbackedoff numberofroutingbackedoff numberofconnected getlocation addunpickedlocsto closestnotbackedoff closestbackedoff addunpickedlocsto closestbackedoff getlocation incrementselectionsamples return some status information public string get status string builder sb new string builder peer node peers synchronized this peers my peers string status new string peers length for int i 0 i peers length i peer node pn peers i status i pn get status true to string arrays sort status for int i 0 i status length i sb append status i sb append n return sb to string getstatus stringbuilder stringbuilder peernode mypeers peernode getstatus tostring tostring return tmci peer list public string gettmci peer list string builder sb new string builder peer node peers synchronized this peers my peers string peer list new string peers length for int i 0 i peers length i peer node pn peers i peer list i pn gettmci peer info arrays sort peer list for int i 0 i peer list length i sb append peer list i sb append n return sb to string gettmcipeerlist stringbuilder stringbuilder peernode mypeers peerlist peernode peerlist gettmcipeerinfo peerlist peerlist peerlist tostring public string get freeviz output string builder sb new string builder peer node peers synchronized this peers my peers string identity new string peers length for int i 0 i peers length i peer node pn peers i identity i pn get freeviz output arrays sort identity for int i 0 i identity length i sb append identity i sb append n return sb to string getfreevizoutput stringbuilder stringbuilder peernode mypeers peernode getfreevizoutput tostring private final object write peer file sync new object void write peers should write peers true writepeerfilesync writepeers shouldwritepeers protected string get darknet peers string string builder sb new string builder peer node peers synchronized this peers my peers for peer node pn peers if pn instanceof darknet peer node sb append pn export disk field set return sb to string getdarknetpeersstring stringbuilder stringbuilder peernode mypeers peernode darknetpeernode exportdiskfieldset tostring protected string get opennet peers string string builder sb new string builder peer node peers synchronized this peers my peers for peer node pn peers if pn instanceof opennet peer node sb append pn export disk field set return sb to string getopennetpeersstring stringbuilder stringbuilder peernode mypeers peernode opennetpeernode exportdiskfieldset tostring protected string get old opennet peers string opennet manager om string builder sb new string builder for peer node pn om get old peers if pn instanceof opennet peer node sb append pn export disk field set return sb to string getoldopennetpeersstring opennetmanager stringbuilder stringbuilder peernode getoldpeers opennetpeernode exportdiskfieldset tostring private void write peers inner string darknet null string opennet null string old opennet peers null string old opennet peers filename null synchronized write peers sync if dark filename null darknet get darknet peers string opennet manager om node get opennet if om null if open filename null opennet get opennet peers string old opennet peers filename om get old peers filename old opennet peers get old opennet peers string om synchronized write peer file sync if darknet null write peers inner dark filename darknet if old opennet peers null if opennet null write peers inner open filename opennet write peers inner old opennet peers filename old opennet peers writepeersinner oldopennetpeers oldopennetpeersfilename writepeerssync darkfilename getdarknetpeersstring opennetmanager getopennet openfilename getopennetpeersstring oldopennetpeersfilename getoldpeersfilename oldopennetpeers getoldopennetpeersstring writepeerfilesync writepeersinner darkfilename oldopennetpeers writepeersinner openfilename writepeersinner oldopennetpeersfilename oldopennetpeers write the peers file to disk private void write peers inner string filename string sb synchronized write peer file sync file output stream fos null string f filename bak try fos new file output stream f catch file not found exception e2 logger error this cannot write peers to disk cannot create f e2 e2 closer close fos return output stream writer w null try w new output stream writer fos utf 8 catch unsupported encoding exception e2 closer close w throw new error impossible jvm doesn t support utf 8 e2 e2 try w write sb w flush w close w null file fnam new file filename file util rename to new file f fnam catch io exception e try fos close catch io exception e1 logger error this cannot close peers file e e logger error this cannot write file e e return don t overwrite old file finally closer close w closer close fos writepeersinner writepeerfilesync fileoutputstream fileoutputstream filenotfoundexception outputstreamwriter outputstreamwriter unsupportedencodingexception fileutil renameto ioexception ioexception update the numbers needed by our peer manager user alert on the uam also run the node s on connected peers method if applicable public void updatepm user alert if ua null return int peers darknet peers opennet peers synchronized this darknet peers this get darknet peers length opennet peers this get opennet peers length peers darknet peers opennet peers seednodes don t count opennet manager om node get opennet boolean opennet definitely port forwarded boolean opennet enabled boolean opennet assumenat if om null opennet enabled true opennet definitely port forwarded om crypto definitely port forwarded opennet assumenat om crypto config always handshake aggressively else opennet enabled false opennet definitely port forwarded false opennet assumenat false boolean darknet definitely port forwarded node darknet definitely port forwarded boolean darknet assumenat node darknet crypto config always handshake aggressively synchronized ua ua opennet definitely port forwarded opennet definitely port forwarded ua darknet definitely port forwarded darknet definitely port forwarded ua opennet assumenat opennet assumenat ua darknet assumenat darknet assumenat ua darknet conns get peer node status size peer node status connected true get peer node status size peer node status routing backed off true ua conns get peer node status size peer node status connected false get peer node status size peer node status routing backed off false ua darknet peers darknet peers ua disconn darknet peers darknet peers ua darknet conns ua peers peers ua never conn get peer node status size peer node status never connected true ua clock problem get peer node status size peer node status clock problem false ua conn error get peer node status size peer node status conn error true ua is opennet enabled opennet enabled if any connected peers node on connected peer peermanageruseralert onconnectedpeers updatepmuseralert darknetpeers opennetpeers darknetpeers getdarknetpeers opennetpeers getopennetpeers darknetpeers opennetpeers opennetmanager getopennet opennetdefinitelyportforwarded opennetenabled opennetassumenat opennetenabled opennetdefinitelyportforwarded definitelyportforwarded opennetassumenat alwayshandshakeaggressively opennetenabled opennetdefinitelyportforwarded opennetassumenat darknetdefinitelyportforwarded darknetdefinitelyportforwarded darknetassumenat darknetcrypto alwayshandshakeaggressively opennetdefinitelyportforwarded opennetdefinitelyportforwarded darknetdefinitelyportforwarded darknetdefinitelyportforwarded opennetassumenat opennetassumenat darknetassumenat darknetassumenat darknetconns getpeernodestatussize peer_node_status_connected getpeernodestatussize peer_node_status_routing_backed_off getpeernodestatussize peer_node_status_connected getpeernodestatussize peer_node_status_routing_backed_off darknetpeers darknetpeers disconndarknetpeers darknetpeers darknetconns neverconn getpeernodestatussize peer_node_status_never_connected clockproblem getpeernodestatussize peer_node_status_clock_problem connerror getpeernodestatussize peer_node_status_conn_error isopennetenabled opennetenabled anyconnectedpeers onconnectedpeer public boolean any connected peers peer node conns synchronized this conns connected peers for int i 0 i conns length i if conns i is routable return true return false anyconnectedpeers peernode connectedpeers isroutable public boolean any darknet peers peer node conns synchronized this conns connected peers for peer node p conns if p is darknet return true return false anydarknetpeers peernode connectedpeers peernode isdarknet ask each peer node to read in it s extra peer data public void read extra peer data darknet peer node peers get darknet peers for int i 0 i peers length i try peers i read extra peer data catch exception e logger error this got exception while reading extra peer data e string msg extra peer data reading and processing completed logger normal this msg system out println msg peernode readextrapeerdata darknetpeernode getdarknetpeers readextrapeerdata public void start ua new peer manager user alert node node stats updatepm user alert node client core alerts register ua node ps queue timed job write peers runnable 0 peermanageruseralert nodestats updatepmuseralert clientcore queuetimedjob writepeersrunnable public int count non backed off peers peer node peers synchronized this peers connected peers even if my peers peers are connected they won t be routed to int count no backoff 0 for int i 0 i peers length i if peers i is routable if peers i is routing backed off count no backoff return count no backoff countnonbackedoffpeers peernode connectedpeers mypeers countnobackoff isroutable isroutingbackedoff countnobackoff countnobackoff stats stuff update oldest never connected peer age if the timer has expired public void maybe update oldest never connected peer age long now synchronized this if now next oldest never connected peer age update time return next oldest never connected peer age update time now oldest never connected peer age update interval oldest never connected peer age 0 peer node peer list my peers for int i 0 i peer list length i peer node pn peer list i if pn get peer node status peer node status never connected if now pn get peer added time oldest never connected peer age oldest never connected peer age now pn get peer added time if oldest never connected peer age 0 logminor logger minor this oldest never connected peer is oldest never connected peer age ms old next oldest never connected peer age update time now oldest never connected peer age update interval oldestneverconnectedpeerage maybeupdateoldestneverconnectedpeerage nextoldestneverconnectedpeerageupdatetime nextoldestneverconnectedpeerageupdatetime oldestneverconnectedpeerageupdateinterval oldestneverconnectedpeerage peernode peerlist mypeers peerlist peernode peerlist getpeernodestatus peer_node_status_never_connected getpeeraddedtime oldestneverconnectedpeerage oldestneverconnectedpeerage getpeeraddedtime oldestneverconnectedpeerage oldestneverconnectedpeerage nextoldestneverconnectedpeerageupdatetime oldestneverconnectedpeerageupdateinterval public long get oldest never connected peer age return oldest never connected peer age getoldestneverconnectedpeerage oldestneverconnectedpeerage log the current peer node status summary if the timer has expired public void maybe log peer node status summary long now if now next peer node status log time if now next peer node status log time 10 1000 next peer node status log time 0 logger error this maybe log peer node status summary not called for more than 10 seconds now next peer node status log time packet sender getting bogged down or something int number of connected 0 int number of routing backed off 0 int number of too new 0 int number of too old 0 int number of disconnected 0 int number of never connected 0 int number of disabled 0 int number of listen only 0 int number of listening 0 int number of bursting 0 int number of clock problem 0 int number of conn error 0 int number of disconnecting 0 int number of routing disabled 0 peer node status pns get peer node statuses true for int i 0 i pns length i if pns i null logger error this get peer node statuses true i null continue switch pns i get status value case peer node status connected number of connected break case peer node status routing backed off number of routing backed off break case peer node status too new number of too new break case peer node status too old number of too old break case peer node status disconnected number of disconnected break case peer node status never connected number of never connected break case peer node status disabled number of disabled break case peer node status listen only number of listen only break case peer node status listening number of listening break case peer node status bursting number of bursting break case peer node status clock problem number of clock problem break case peer node status conn error number of conn error break case peer node status disconnecting number of disconnecting break case peer node status routing disabled number of routing disabled break default logger error this unknown peer status value pns i get status value break logger normal this connected number of connected routing backed off number of routing backed off too new number of too new too old number of too old disconnected number of disconnected never connected number of never connected disabled number of disabled bursting number of bursting listening number of listening listen only number of listen only clock problem number of clock problem connection problem number of conn error disconnecting number of disconnecting next peer node status log time now peer node status log interval node display clock problem user alert number of clock problem 2 peernode maybelogpeernodestatussummary nextpeernodestatuslogtime nextpeernodestatuslogtime nextpeernodestatuslogtime maybelogpeernodestatussummary nextpeernodestatuslogtime packetsender numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberoflistenonly numberoflistening numberofbursting numberofclockproblem numberofconnerror numberofdisconnecting numberofroutingdisabled peernodestatus getpeernodestatuses getpeernodestatuses getstatusvalue peer_node_status_connected numberofconnected peer_node_status_routing_backed_off numberofroutingbackedoff peer_node_status_too_new numberoftoonew peer_node_status_too_old numberoftooold peer_node_status_disconnected numberofdisconnected peer_node_status_never_connected numberofneverconnected peer_node_status_disabled numberofdisabled peer_node_status_listen_only numberoflistenonly peer_node_status_listening numberoflistening peer_node_status_bursting numberofbursting peer_node_status_clock_problem numberofclockproblem peer_node_status_conn_error numberofconnerror peer_node_status_disconnecting numberofdisconnecting peer_node_status_routing_disabled numberofroutingdisabled getstatusvalue numberofconnected numberofroutingbackedoff numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofclockproblem numberofconnerror numberofdisconnecting nextpeernodestatuslogtime peernodestatusloginterval displayclockproblemuseralert numberofclockproblem add a peer node status to the map public void add peer node status int pn status peer node peer node boolean no log integer peer node status integer value of pn status add peer node statuses pn status peer node peer node status peer node statuses no log if peer node is opennet add peer node statuses pn status peer node peer node status peer node statuses darknet no log peernode addpeernodestatus pnstatus peernode peernode nolog peernodestatus valueof pnstatus addpeernodestatuses pnstatus peernode peernodestatus peernodestatuses nolog peernode isopennet addpeernodestatuses pnstatus peernode peernodestatus peernodestatusesdarknet nolog private void add peer node statuses int pn status peer node peer node integer peer node status hash map integer hash set peer node statuses boolean no log hash set peer node status set null synchronized statuses if statuses contains key peer node status status set statuses get peer node status if status set contains peer node if no log logger error this add peer node status node already in peer node statuses peer node status peer node get peer node status string peer node status int value return statuses remove peer node status else status set new hash set peer node if logminor logger minor this add peer node status adding peer node for peer node get identity string with status peer node get peer node status string peer node status int value status set add peer node statuses put peer node status status set addpeernodestatuses pnstatus peernode peernode peernodestatus hashmap hashset peernode nolog hashset peernode statusset containskey peernodestatus statusset peernodestatus statusset peernode nolog addpeernodestatus peernodestatuses peernode peernode getpeernodestatusstring peernodestatus intvalue peernodestatus statusset hashset peernode addpeernodestatus peernode peernode getidentitystring peernode getpeernodestatusstring peernodestatus intvalue statusset peernode peernodestatus statusset how many peer nodes have a particular status param darknet if true only count darknet nodes if false count all nodes public int get peer node status size int pn status boolean darknet integer peer node status integer value of pn status hash set peer node status set null hash map integer hash set peer node statuses darknet peer node statuses darknet this peer node statuses synchronized statuses if statuses contains key peer node status status set statuses get peer node status else status set new hash set peer node return status set size peernodes getpeernodestatussize pnstatus peernodestatus valueof pnstatus hashset peernode statusset hashmap hashset peernode peernodestatusesdarknet peernodestatuses containskey peernodestatus statusset peernodestatus statusset hashset peernode statusset remove a peer node status from the map param is in peers if true complain if the node is not in the peers list if false complain if it is public void remove peer node status int pn status peer node peer node boolean no log integer peer node status integer value of pn status remove peer node status pn status peer node status peer node peer node statuses no log if peer node is opennet remove peer node status pn status peer node status peer node peer node statuses darknet no log peernode isinpeers removepeernodestatus pnstatus peernode peernode nolog peernodestatus valueof pnstatus removepeernodestatus pnstatus peernodestatus peernode peernodestatuses nolog peernode isopennet removepeernodestatus pnstatus peernodestatus peernode peernodestatusesdarknet nolog private void remove peer node status int pn status integer peer node status peer node peer node hash map integer hash set peer node statuses boolean no log hash set peer node status set null synchronized statuses if statuses contains key peer node status status set statuses get peer node status if status set contains peer node if no log logger error this remove peer node status identity peer node get identity string for peer node short to string not in peer node statuses with status peer node get peer node status string peer node status int value new exception debug return if statuses is empty statuses remove peer node status else status set new hash set peer node if logminor logger minor this remove peer node status removing peer node for peer node get identity string with status peer node get peer node status string peer node status int value if status set contains peer node status set remove peer node removepeernodestatus pnstatus peernodestatus peernode peernode hashmap hashset peernode nolog hashset peernode statusset containskey peernodestatus statusset peernodestatus statusset peernode nolog removepeernodestatus peernode getidentitystring peernode shorttostring peernodestatuses peernode getpeernodestatusstring peernodestatus intvalue isempty peernodestatus statusset hashset peernode removepeernodestatus peernode peernode getidentitystring peernode getpeernodestatusstring peernodestatus intvalue statusset peernode statusset peernode add a peer node routing backoff reason to the map public void add peer node routing backoff reason string peer node routing backoff reason peer node peer node synchronized peer node routing backoff reasons hash set peer node reason set null if peer node routing backoff reasons contains key peer node routing backoff reason reason set peer node routing backoff reasons get peer node routing backoff reason if reason set contains peer node logger error this add peer node routing backoff reason identity peer node get identity string already in peer node routing backoff reasons as peer node get peer with status code peer node routing backoff reason return peer node routing backoff reasons remove peer node routing backoff reason else reason set new hash set peer node if logminor logger minor this add peer node routing backoff reason adding peer node for peer node get identity string with status code peer node routing backoff reason reason set add peer node peer node routing backoff reasons put peer node routing backoff reason reason set peernode addpeernoderoutingbackoffreason peernoderoutingbackoffreason peernode peernode peernoderoutingbackoffreasons hashset peernode reasonset peernoderoutingbackoffreasons containskey peernoderoutingbackoffreason reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset peernode addpeernoderoutingbackoffreason peernode getidentitystring peernoderoutingbackoffreasons peernode getpeer peernoderoutingbackoffreason peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset hashset peernode addpeernoderoutingbackoffreason peernode peernode getidentitystring peernoderoutingbackoffreason reasonset peernode peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset what are the currently tracked peer node routing backoff reasons public string get peer node routing backoff reasons string reason strings synchronized peer node routing backoff reasons reason strings peer node routing backoff reasons key set to array new string peer node routing backoff reasons size arrays sort reason strings return reason strings peernode getpeernoderoutingbackoffreasons reasonstrings peernoderoutingbackoffreasons reasonstrings peernoderoutingbackoffreasons keyset toarray peernoderoutingbackoffreasons reasonstrings reasonstrings how many peer nodes have a particular routing backoff reason public int get peer node routing backoff reason size string peer node routing backoff reason hash set peer node reason set null synchronized peer node routing backoff reasons if peer node routing backoff reasons contains key peer node routing backoff reason reason set peer node routing backoff reasons get peer node routing backoff reason return reason set size else return 0 peernodes getpeernoderoutingbackoffreasonsize peernoderoutingbackoffreason hashset peernode reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreasons containskey peernoderoutingbackoffreason reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset remove a peer node routing backoff reason from the map public void remove peer node routing backoff reason string peer node routing backoff reason peer node peer node hash set peer node reason set null synchronized peer node routing backoff reasons if peer node routing backoff reasons contains key peer node routing backoff reason reason set peer node routing backoff reasons get peer node routing backoff reason if reason set contains peer node logger error this remove peer node routing backoff reason identity peer node get identity string not in peer node routing backoff reasons with status code peer node routing backoff reason new exception debug return peer node routing backoff reasons remove peer node routing backoff reason else reason set new hash set peer node if logminor logger minor this remove peer node routing backoff reason removing peer node for peer node get identity string with status code peer node routing backoff reason if reason set contains peer node reason set remove peer node if reason set size 0 peer node routing backoff reasons put peer node routing backoff reason reason set peernode removepeernoderoutingbackoffreason peernoderoutingbackoffreason peernode peernode hashset peernode reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreasons containskey peernoderoutingbackoffreason reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset peernode removepeernoderoutingbackoffreason peernode getidentitystring peernoderoutingbackoffreasons peernoderoutingbackoffreason peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset hashset peernode removepeernoderoutingbackoffreason peernode peernode getidentitystring peernoderoutingbackoffreason reasonset peernode reasonset peernode reasonset peernoderoutingbackoffreasons peernoderoutingbackoffreason reasonset public peer node status get peer node statuses boolean no heavy peer node peers synchronized this peers my peers peer node status peernodestatuses new peer node status peers length for int peer index 0 peer count peers length peer index peer count peer index peernodestatuses peer index peers peer index get status no heavy return peernodestatuses peernodestatus getpeernodestatuses noheavy peernode mypeers peernodestatus _peernodestatuses peernodestatus peerindex peercount peerindex peercount peerindex _peernodestatuses peerindex peerindex getstatus noheavy _peernodestatuses public darknet peer node status get darknet peer node statuses boolean no heavy darknet peer node peers get darknet peers darknet peer node status peernodestatuses new darknet peer node status peers length for int peer index 0 peer count peers length peer index peer count peer index peernodestatuses peer index darknet peer node status peers peer index get status no heavy return peernodestatuses darknetpeernodestatus getdarknetpeernodestatuses noheavy darknetpeernode getdarknetpeers darknetpeernodestatus _peernodestatuses darknetpeernodestatus peerindex peercount peerindex peercount peerindex _peernodestatuses peerindex darknetpeernodestatus peerindex getstatus noheavy _peernodestatuses public opennet peer node status get opennet peer node statuses boolean no heavy opennet peer node peers get opennet peers opennet peer node status peernodestatuses new opennet peer node status peers length for int peer index 0 peer count peers length peer index peer count peer index peernodestatuses peer index opennet peer node status peers peer index get status no heavy return peernodestatuses opennetpeernodestatus getopennetpeernodestatuses noheavy opennetpeernode getopennetpeers opennetpeernodestatus _peernodestatuses opennetpeernodestatus peerindex peercount peerindex peercount peerindex _peernodestatuses peerindex opennetpeernodestatus peerindex getstatus noheavy _peernodestatuses update had routable connection count routable connection check count on peers if the timer has expired public void maybe update peer node routable connection stats long now synchronized this if now next routable connection stats update time return next routable connection stats update time now routable connection stats update interval if 1 next routable connection stats update time peer node peer list my peers for int i 0 i peer list length i peer node pn peer list i pn check routable connection status hadroutableconnectioncount routableconnectioncheckcount maybeupdatepeernoderoutableconnectionstats nextroutableconnectionstatsupdatetime nextroutableconnectionstatsupdatetime routableconnectionstatsupdateinterval nextroutableconnectionstatsupdatetime peernode peerlist mypeers peerlist peernode peerlist checkroutableconnectionstatus get the darknet peers list fixme optimise public darknet peer node get darknet peers peer node peers synchronized this peers my peers fixme optimise maybe maintain as a separate list vector peer node v new vector peer node my peers length for int i 0 i peers length i if peers i instanceof darknet peer node v add peers i return v to array new darknet peer node v size darknetpeernode getdarknetpeers peernode mypeers peernode peernode mypeers darknetpeernode toarray darknetpeernode public vector seed server peer node get connected seed server peers vector hash set byte array wrapper exclude peer node peers synchronized this peers my peers fixme optimise maybe maintain as a separate list vector seed server peer node v new vector seed server peer node my peers length for peer node p peers if p instanceof seed server peer node seed server peer node sspn seed server peer node p if exclude null exclude contains new byte array wrapper sspn get identity if logminor logger minor this not including in get connected seed server peers vector as in exclude set sspn user to string continue if sspn is connected if logminor logger minor this not including in get connected seed server peers vector as disconnected sspn user to string continue v add sspn return v seedserverpeernode getconnectedseedserverpeersvector hashset bytearraywrapper peernode mypeers seedserverpeernode seedserverpeernode mypeers peernode seedserverpeernode seedserverpeernode seedserverpeernode bytearraywrapper getidentity getconnectedseedserverpeersvector usertostring isconnected getconnectedseedserverpeersvector usertostring public list seed server peer node get seed server peers vector peer node peers synchronized this peers my peers fixme optimise maybe maintain as a separate list list seed server peer node v new array list seed server peer node my peers length for peer node peer peers if peer instanceof seed server peer node v add seed server peer node peer return v seedserverpeernode getseedserverpeersvector peernode mypeers seedserverpeernode arraylist seedserverpeernode mypeers peernode seedserverpeernode seedserverpeernode get the opennet peers list public opennet peer node get opennet peers peer node peers synchronized this peers my peers fixme optimise maybe maintain as a separate list vector peer node v new vector peer node my peers length for int i 0 i peers length i if peers i instanceof opennet peer node v add peers i return v to array new opennet peer node v size opennetpeernode getopennetpeers peernode mypeers peernode peernode mypeers opennetpeernode toarray opennetpeernode public boolean any connected peer has address freenet inet address addr peer node pn peer node peers synchronized this peers my peers for int i 0 i peers length i if peers i pn continue if peers i is connected continue if peers i is real connection continue ignore non searchable peers i e bootstrapping peers if get peer is null then presumably is connected if peers i get peer get freenet address equals addr return true return false anyconnectedpeerhasaddress freenetinetaddress peernode peernode mypeers isconnected isrealconnection getpeer isconnected getpeer getfreenetaddress public void remove opennet peers synchronized this array list peer node keep new array list peer node array list peer node conn new array list peer node for peer node pn my peers if pn instanceof opennet peer node continue keep add pn if pn is connected conn add pn my peers keep to array new peer node keep size connected peers keep to array new peer node conn size updatepm user alert removeopennetpeers arraylist peernode arraylist peernode arraylist peernode arraylist peernode peernode mypeers opennetpeernode isconnected mypeers toarray peernode connectedpeers toarray peernode updatepmuseralert public peer node contains peer peer node pn peer node peers pn is opennet peer node get opennet peers peer node get darknet peers for int i 0 i peers length i if arrays equals pn get identity peers i get identity return peers i return null peernode containspeer peernode peernode isopennet peernode getopennetpeers peernode getdarknetpeers getidentity getidentity public int quick count connected peers peer node conns connected peers if conns null return 0 return connected peers length quickcountconnectedpeers peernode connectedpeers connectedpeers public int count connected darknet peers int count 0 peer node peers my peers for int i 0 i peers length i if peers i null continue if peers i instanceof darknet peer node continue if peers i is opennet continue if peers i is routable continue count if logminor logger minor this count connected darknet peers returning count return count countconnecteddarknetpeers peernode mypeers darknetpeernode isopennet isroutable countconnecteddarknetpeers public int count connected peers int count 0 peer node peers my peers for int i 0 i peers length i if peers i null continue if peers i is routable continue count return count countconnectedpeers peernode mypeers isroutable public int count almost connected darknet peers int count 0 peer node peers my peers for int i 0 i peers length i if peers i null continue if peers i instanceof darknet peer node continue if peers i is opennet continue if peers i is connected continue count return count countalmostconnecteddarknetpeers peernode mypeers darknetpeernode isopennet isconnected public int count compatible darknet peers int count 0 peer node peers my peers for int i 0 i peers length i if peers i null continue if peers i instanceof darknet peer node continue if peers i is opennet continue if peers i is connected continue if peers i is routing compatible continue count return count countcompatibledarknetpeers peernode mypeers darknetpeernode isopennet isconnected isroutingcompatible public int count connected opennet peers int count 0 peer node peers connected peers for int i 0 i peers length i if peers i null continue if peers i instanceof opennet peer node continue if peers i is routable continue count return count countconnectedopennetpeers peernode connectedpeers opennetpeernode isroutable how many peers do we have that actually may connect don t include seednodes disabled nodes etc public int count valid peers peer node peers my peers int count 0 for int i 0 i peers length i if peers i is real connection continue if peers i is disabled continue count return count countvalidpeers peernode mypeers isrealconnection isdisabled public int count seednodes int count 0 for peer node peer my peers if peer instanceof seed server peer node peer instanceof seed client peer node count return count countseednodes peernode mypeers seedserverpeernode seedclientpeernode public int count backed off peers peer node peers my peers int count 0 for int i 0 i peers length i if peers i is real connection continue if peers i is disabled continue if peers i is routing backed off count return count countbackedoffpeers peernode mypeers isrealconnection isdisabled isroutingbackedoff public peer node get by identity byte identity peer node peers my peers for int i 0 i peers length i if arrays equals peers i get identity identity return peers i return null peernode getbyidentity peernode mypeers getidentity private void increment selection samples long now peer node pn todo reimplement with a bit field to spare memory pn increment number of selections now incrementselectionsamples peernode incrementnumberofselections private static final long serial versionuid 5516389508555401104l public attribute list serialversionuid attributelist public attribute get attribute int n return attribute get n getattribute public attribute get attribute string name if name null return null int n lists size for int n 0 n n lists n attribute elem get attribute n if name compare to elem get name 0 return elem return null getattribute nlists nlists getattribute compareto getname public ssdp request set version http version 11 ssdprequest setversion version_11 public void setnt string value set header http nt value setheader public string getnt return get header value http nt getheadervalue public void setnts string value set header http nts value setheader public string getnts return get header value http nts getheadervalue public void set location string value set header http location value setlocation setheader public string get location return get header value http location getlocation getheadervalue public void setusn string value set header http usn value setheader public string getusn return get header value http usn getheadervalue public void set lease time int len set header http cache control max age integer to string len setleasetime setheader cache_control tostring public int get lease time string cache ctrl get header value http cache control return ssdp get lease time cache ctrl getleasetime cachectrl getheadervalue cache_control getleasetime cachectrl public class assertion failed extends error public assertion failed super assertion failed assertionfailed assertionfailed public assertion failed string description super assertion description failed assertionfailed private float m11 1 0f public marble tex filter marbletexfilter public void set scale float scale this scale scale setscale public float get scale return scale getscale public void set stretch float stretch this stretch stretch setstretch public float get stretch return stretch getstretch public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos setangle public float get angle return angle getangle public void set turbulence float turbulence this turbulence turbulence setturbulence public float get turbulence return turbulence getturbulence public void set turbulence factor float turbulence factor this turbulence factor turbulence factor setturbulencefactor turbulencefactor turbulencefactor turbulencefactor public float get turbulence factor return turbulence factor getturbulencefactor turbulencefactor public void set colormap colormap colormap this colormap colormap setcolormap public colormap get colormap return colormap getcolormap override public int filterrgb int x int y int rgb float nx m00 x m01 y float ny m10 x m11 y nx scale stretch ny scale int a rgb 0xff000000 if colormap null float f noise turbulence2 nx ny turbulence f 3 turbulence factor f ny f math sin f math pi float chaos turbulence factor noise turbulence2 nx ny turbulence float f math sin math sin 8 chaos 7 nx 3 ny float f 3 turbulence factor chaos ny f float math sin f math pi float perturb float math sin 40 chaos f 2 perturb return colormap get color f else float red grn blu float chaos brown layer green layer float perturb brown perturb green perturb grn perturb float t chaos turbulence factor noise turbulence2 nx ny turbulence t float math sin math sin 8 chaos 7 nx 3 ny green layer brown layer math abs t perturb float math sin 40 chaos perturb float math abs perturb brown perturb 6f perturb 0 3f green perturb 2f perturb 0 8f grn perturb 15f perturb 0 85f grn 0 5f float math pow math abs brown layer 0 3 brown layer float math pow 0 5 brown layer 1 0 0 6 brown perturb green layer float math pow 0 5 green layer 1 0 0 6 green perturb red 0 5f brown layer 0 35f green layer 2 0f grn blu 0 25f brown layer 0 35f green layer 2 0f grn grn math max brown layer green layer grn perturb int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r pixel utils clamp int r red g pixel utils clamp int g grn b pixel utils clamp int b blu return rgb 0xff000000 r 16 g 8 b turbulencefactor turbulencefactor turbulencefactor getcolor brownlayer greenlayer brownperturb greenperturb grnperturb turbulencefactor greenlayer brownlayer brownperturb greenperturb grnperturb brownlayer brownlayer brownlayer brownperturb greenlayer greenlayer greenperturb brownlayer greenlayer brownlayer greenlayer brownlayer greenlayer grnperturb pixelutils pixelutils pixelutils override public string to string return texture marble texture tostring create a question public dns question string name int type int clazz super name type clazz dnsquestion check if this question is answered by a given dns record boolean answered by dns record rec return clazz rec clazz type rec type type dns constants type any name equals rec name answeredby dnsrecord dnsconstants type_any for debugging only public string to string return to string question null tostring tostring public line int x1 int y1 int x2 int y2 this x1 x1 this y1 y1 this x2 x2 this y2 y2 public void setup dx x2 x1 dy y2 y1 length squared dx dx dy dy length float math sqrt length squared lengthsquared lengthsquared private float width height public field warp filter fieldwarpfilter set the amount of warp param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of warp return the amount see set amount public float get amount return amount setamount getamount public void set power float power this power power setpower public float get power return power getpower public void set strength float strength this strength strength setstrength public float get strength return strength getstrength public void set in lines line in lines this in lines in lines setinlines inlines inlines inlines public line get in lines return in lines getinlines inlines public void set out lines line out lines this out lines out lines setoutlines outlines outlines outlines public line get out lines return out lines getoutlines outlines protected void transform int x int y point out override protected void transform inverse int x int y float out float u 0 v 0 float fraction 0 float distance float fdist float weight float a 0 001f float b 1 5f strength 0 5f float p power float total weight 0 0f float sumx 0 0f float sumy 0 0f for int line 0 line in lines length line line l1 in lines line line l intermediate lines line float dx x l x1 float dy y l y1 fraction dx l dx dy l dy l length squared fdist dy l dx dx l dy l length if fraction 0 distance float math sqrt dx dx dy dy else if fraction 1 dx x l x2 dy y l y2 distance float math sqrt dx dx dy dy else if fdist 0 distance fdist else distance fdist u l1 x1 fraction l1 dx fdist l1 dy l1 length v l1 y1 fraction l1 dy fdist l1 dx l1 length weight float math pow math pow l length p a distance b sumx u x weight sumy v y weight if x 10 0 y 20 system out println distance distance weight weight sumx sumx sumy sumy u u v v total weight weight out 0 image math clamp x sumx total weight 0 5f 0 width 1 out 1 image math clamp y sumy total weight 0 5f 0 height 1 out 0 x sumx total weight 0 5f out 1 y sumy total weight 0 5f transforminverse totalweight inlines inlines intermediatelines lengthsquared totalweight imagemath totalweight imagemath totalweight totalweight totalweight override public buffered image filter buffered image src buffered image dst this width width this height height if in lines null out lines null intermediate lines new line in lines length for int line 0 line in lines length line line l intermediate lines line new line image math lerp amount in lines line x1 out lines line x1 image math lerp amount in lines line y1 out lines line y1 image math lerp amount in lines line x2 out lines line x2 image math lerp amount in lines line y2 out lines line y2 l setup in lines line setup dst super filter src dst intermediate lines null return dst return src bufferedimage bufferedimage bufferedimage inlines outlines intermediatelines inlines inlines intermediatelines imagemath inlines outlines imagemath inlines outlines imagemath inlines outlines imagemath inlines outlines inlines intermediatelines override public string to string return distort field warp tostring override public url check source string source throws plugin not found exception return super check source https checksums freenetproject org latest source jar checksource pluginnotfoundexception checksource override string get plugin name string source throws plugin not found exception return source jar getpluginname pluginnotfoundexception override string getsha1sum throws plugin not found exception try url sha1url new url get source to string sha1 url connection url connection sha1url open connection url connection set use caches false url connection set allow user interaction false input stream is open connection check redirects url connection byte array output stream bos new byte array output stream byte buffer new byte 1024 int read while read is read buffer 1 bos write buffer 0 read return new string bos to byte array split 0 catch malformedurl exception e throw new plugin not found exception impossible e e catch io exception e throw new plugin not found exception error while fetching sha1 for plugin e e pluginnotfoundexception getsource tostring urlconnection urlconnection openconnection urlconnection setusecaches urlconnection setallowuserinteraction inputstream openconnectioncheckredirects urlconnection bytearrayoutputstream bytearrayoutputstream tobytearray malformedurlexception pluginnotfoundexception ioexception pluginnotfoundexception override input stream get input stream throws io exception file tmp keystore null file input stream fis null input stream is null try tmp keystore file create temp file keystore tmp tmp keystore delete on exit key store ks key store get instance jks ks load null new char 0 is get cert certificate factory cf certificate factory get instance x 509 collection extends certificate c cf generate certificates is iterator extends certificate it c iterator while it has next certificate cert it next ks set certificate entry cert get public key to string cert file output stream tmpfos new file output stream tmp keystore try ks store tmpfos new char 0 finally closer close tmpfos system out println the ca has been imported into the trust store catch exception e system err println error while handling the ca e get message throw new io exception error while handling the ca e finally closer close fis system set property javax net ssl trust store tmp keystore to string return super get input stream inputstream getinputstream ioexception tmp_keystore fileinputstream inputstream tmp_keystore createtempfile tmp_keystore deleteonexit keystore keystore getinstance getcert certificatefactory certificatefactory getinstance generatecertificates hasnext setcertificateentry getpublickey tostring fileoutputstream fileoutputstream tmp_keystore truststore getmessage ioexception setproperty truststore tmp_keystore tostring getinputstream private input stream get cert throws io exception normal the file should be here left by installer or update script file cert file new file certfile get absolute file if cert file exists return new file input stream cert file try to create pem file class loader loader class loader get system class loader input stream in loader get resource as stream certurl if in null file util write to in cert file if cert file exists system err println nodes certfile created use it return new file input stream cert file system err println nodes certfile couldnt created try direct couldnt write the file maybe paranoid selinux or hardware node return in system err println certficate file certfile not found on disk nor buildin throw new io exception certficate file certfile not found on disk nor buildin inputstream getcert ioexception certfile getabsolutefile certfile fileinputstream certfile classloader classloader getsystemclassloader inputstream getresourceasstream fileutil writeto certfile certfile fileinputstream certfile ioexception public static void init register known mime types plain text register new mime type text plain txt new string 0 new string text pot true true null null false false false false false false l10n text plain read advice l10n text plain write advice true us ascii null gif has a filter register new mime type image gif gif new string 0 new string 0 true false new gif filter null false false false false false false l10n image gif read advice l10n image gif write advice false null null jpeg has a filter register new mime type image jpeg jpeg new string 0 new string jpg true false new jpeg filter true true null false false false false false false l10n image jpeg read advice l10n image jpeg write advice false null null png has a filter register new mime type image png png new string 0 new string 0 true false new png filter true true true null false false false false true false l10n image png read advice l10n image png write advice false null null ico probably safe fixme check this out write filters register new mime type image x icon ico new string image vnd microsoft icon image ico application ico new string 0 true false null null false false false false false false l10n image ico read advice l10n image ico write advice false null null pdf very dangerous fixme ideally we would have a filter this is such a common format register new mime type application pdf pdf new string application x pdf new string 0 false false null null true true true false true true l10n application pdf read advice l10n application pdf write advice false null null html dangerous if not filtered register new mime type text html html new string text xhtml text xml xhtml application xhtml xml new string htm false false maybe new html filter null fixme true true true true true true l10n text html read advice l10n text html write advice true iso 8859 1 new html filter css danagerous if not filtered not sure about the filter register new mime type text css css new string 0 new string 0 false false unknown new css read filter null true true true true true false l10n text css read advice l10n text css write advice true utf 8 new css read filter mimetype textplainreadadvice textplainwriteadvice mimetype giffilter imagegifreadadvice imagegifwriteadvice mimetype jpegfilter imagejpegreadadvice imagejpegwriteadvice mimetype pngfilter imagepngreadadvice imagepngwriteadvice mimetype imageicoreadadvice imageicowriteadvice mimetype applicationpdfreadadvice applicationpdfwriteadvice mimetype htmlfilter texthtmlreadadvice texthtmlwriteadvice htmlfilter mimetype cssreadfilter textcssreadadvice textcsswriteadvice cssreadfilter private static string l10n string key return l10n get string content filter key getstring contentfilter public static void register mime type mime type synchronized mime types by name mime types by name put mime type primary mime type mime type string alt mime type alternate mime types if alt null alt length 0 for int i 0 i alt length i mime types by name put alt i mime type mimetype mimetype mimetypesbyname mimetypesbyname mimetype primarymimetype mimetype mimetype alternatemimetypes mimetypesbyname mimetype public static mime type getmime type string mime type return mime types by name get mime type mimetype getmimetype mimetype mimetypesbyname mimetype public final string type filter output bucket data string type this data data this type type filteroutput filter some data param data input data param bf the bucket factory used to create the bucket to return the filtered data in param type name mime type for input data throws io exception if an internal error involving buckets occurred throws unsafe content type exception if the mime type is declared unsafe e g pdf files throws illegal state exception if data is invalid e g corrupted file and the filter have no way to recover public static filter output filter bucket data bucket factory bf string type name uri baseuri founduri callback cb throws unsafe content type exception io exception if logger should log logger minor content filter class logger minor content filter class filter data size data size type name type name string type type name string options string charset null hash map string string other params null first parse the mime type int idx type index of if idx 1 options type substring idx 1 type type substring 0 idx parse options format type subtype optional white space optional white space param value param2 value2 string raw opts options split for int i 0 i raw opts length i string raw raw opts i idx raw index of if idx 1 logger error content filter class idx 1 for on option raw from type name continue string before raw substring 0 idx trim string after raw substring idx 1 trim if before equals charset charset after else if other params null other params new hash map string string other params put before after now look for a mime type handler mime type handler getmime type type if handler null throw new unknown content type exception type name else run the read filter if there is one if handler read filter null if handler takesa charset charset null charset length 0 charset detect charset data handler bucket output data handler read filter read filter data bf charset other params new generic read filter callback baseuri cb if charset null type type charset charset return new filter output output data type if handler safe to read return new filter output data type name handler throw unsafe content type exception return null typename ioexception unsafecontenttypeexception illegalstateexception filteroutput bucketfactory typename founduricallback unsafecontenttypeexception ioexception shouldlog contentfilter contentfilter typename typename typename hashmap otherparams indexof rawopts rawopts rawopts indexof contentfilter typename otherparams otherparams hashmap otherparams mimetype mimetype getmimetype unknowncontenttypeexception typename readfilter takesacharset detectcharset outputdata readfilter readfilter otherparams genericreadfiltercallback filteroutput outputdata safetoread filteroutput typename throwunsafecontenttypeexception private static string detect charset bucket data mime type handler throws io exception detect charset string charset detectbom data if charset null handler charset extractor null obviously this is slow this is why we need to detect on insert if handler default charset null try if charset handler charset extractor get charset data handler default charset null if logger should log logger minor content filter class logger minor content filter class returning charset charset return charset catch data filter exception e ignore try if charset handler charset extractor get charset data iso 8859 1 null return charset catch data filter exception e ignore try if charset handler charset extractor get charset data utf 8 null return charset catch data filter exception e ignore try if charset handler charset extractor get charset data utf 16 null return charset catch data filter exception e ignore try if charset handler charset extractor get charset data utf 32 null return charset catch unsupported encoding exception e doesn t seem to be supported by prior to 1 6 if logger should log logger minor content filter class logger minor content filter class utf 32 not supported catch data filter exception e ignore if it doesn t have a bom then it s probably safe to use as default return handler default charset detectcharset mimetype ioexception charsetextractor defaultcharset charsetextractor getcharset defaultcharset shouldlog contentfilter contentfilter datafilterexception charsetextractor getcharset datafilterexception charsetextractor getcharset datafilterexception charsetextractor getcharset datafilterexception charsetextractor getcharset unsupportedencodingexception shouldlog contentfilter contentfilter datafilterexception defaultcharset detect a byte order mark a sequence of bytes which identifies a document as encoded with a specific charset throws io exception private static string detectbom bucket bucket throws io exception input stream is null try byte data new byte 5 is new buffered input stream bucket get input stream int read 0 while read data length int x try x is read data read data length read catch eof exception e x 1 if x 0 break if starts with data bom utf8 return utf 8 if starts with data bom utf16 be starts with data bom utf16 le return utf 16 if starts with data bom utf32 be starts with data bom utf32 le return utf 32 if starts with data bom scsu return scsu if starts with data bom utf7 1 starts with data bom utf7 2 starts with data bom utf7 3 starts with data bom utf7 4 starts with data bom utf7 5 return utf 7 if starts with data bom utf ebcdic return utf ebcdic if starts with data bom bocu 1 return bocu 1 is close return null finally closer close is ioexception ioexception inputstream bufferedinputstream getinputstream eofexception startswith bom_utf8 startswith bom_utf16_be startswith bom_utf16_le startswith bom_utf32_be startswith bom_utf32_le startswith bom_scsu startswith bom_utf7_1 startswith bom_utf7_2 startswith bom_utf7_3 startswith bom_utf7_4 startswith bom_utf7_5 startswith bom_utf_ebcdic startswith bom_bocu_1 private static boolean starts with byte data byte cmp for int i 0 i cmp length i if data i cmp i return false return true startswith public static final long max oldest never connected peer age alert threshold long 2 7 24 60 60 1000 2 weeks public peer manager user alert node stats n super false null null null null short 0 true l10n get string user alert hide false null this n n max_oldest_never_connected_peer_age_alert_threshold peermanageruseralert nodestats getstring useralert override public string get title if is opennet enabled if peers 0 return l10n no peers title if conns 0 return l10n no conns title if conns min conn alert threshold return l10n only few conns title count integer to string conns if n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold return l10n too high bwlimit delay time title if n node average ping alert relevant node average ping time node stats max node average ping time alert threshold return l10n too high ping time title if clock problem min clock problem peer alert threshold return l10n clock problem title if never conn max never connected peer alert threshold return l10n too many never connected title if conn error min conn error alert threshold return l10n conn error title if disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat return l10n too many disconnected title if conns max conn alert threshold return l10n too many conns title if peers max peer alert threshold return l10n too many peers title if oldest never connected peer age max oldest never connected peer age alert threshold return l10n too old never connected peers title else throw new illegal argument exception not valid gettitle isopennetenabled nopeerstitle noconnstitle min_conn_alert_threshold onlyfewconnstitle tostring bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold toohighbwlimitdelaytimetitle nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold toohighpingtimetitle clockproblem min_clock_problem_peer_alert_threshold clockproblemtitle neverconn max_never_connected_peer_alert_threshold toomanyneverconnectedtitle connerror min_conn_error_alert_threshold connerrortitle disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat toomanydisconnectedtitle max_conn_alert_threshold toomanyconnstitle max_peer_alert_threshold toomanypeerstitle oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold toooldneverconnectedpeerstitle illegalargumentexception override public string get short text return get title getshorttext gettitle private string l10n string key string pattern string value return l10n get string peer manager user alert key pattern value getstring peermanageruseralert private string l10n string key string pattern string value return l10n get string peer manager user alert key pattern value getstring peermanageruseralert private string l10n string key return l10n get string peer manager user alert key getstring peermanageruseralert override public string get text string s if peers 0 is opennet enabled if n is testnet enabled return l10n no peers testnet else return l10n no peers darknet else if conns 3 clock problem min clock problem peer alert threshold s l10n clock problem count integer to string clock problem else if conns 3 conn error min conn error alert threshold is opennet enabled s l10n conn error count integer to string conn error else if conns 0 is opennet enabled return l10n no conns else if conns 1 is opennet enabled return l10n one conn else if conns 2 is opennet enabled return l10n two conns else if n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold s l10n too high bwlimit delay time new string delay max new string integer to string bwlimit delay time long to string node stats max bwlimit delay time alert threshold fixme i m not convinced about the next one else if n node average ping alert relevant node average ping time node stats max node average ping time alert threshold s l10n too high ping time new string ping max new string integer to string node average ping time long to string node stats max node average ping time alert threshold else if clock problem min clock problem peer alert threshold s l10n clock problem count integer to string clock problem else if never conn max never connected peer alert threshold s l10n too many never connected count integer to string never conn else if conn error min conn error alert threshold s l10n conn error count integer to string conn error else if disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat s l10n too many disconnected new string count max new string integer to string disconn darknet peers integer to string max disconn peer alert threshold else if conns max conn alert threshold s l10n too many conns new string count max new string integer to string conns integer to string max conn alert threshold else if peers max peer alert threshold s l10n too many peers new string count max new string integer to string peers integer to string max peer alert threshold else if oldest never connected peer age max oldest never connected peer age alert threshold return l10n too old never connected peers else throw new illegal argument exception not valid return s gettext isopennetenabled istestnetenabled nopeerstestnet nopeersdarknet clockproblem min_clock_problem_peer_alert_threshold clockproblem tostring clockproblem connerror min_conn_error_alert_threshold isopennetenabled connerror tostring connerror isopennetenabled noconns isopennetenabled oneconn isopennetenabled twoconns bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold toohighbwlimitdelaytime tostring bwlimitdelaytime tostring nodestats max_bwlimit_delay_time_alert_threshold nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold toohighpingtime tostring nodeaveragepingtime tostring nodestats max_node_average_ping_time_alert_threshold clockproblem min_clock_problem_peer_alert_threshold clockproblem tostring clockproblem neverconn max_never_connected_peer_alert_threshold toomanyneverconnected tostring neverconn connerror min_conn_error_alert_threshold connerror tostring connerror disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat toomanydisconnected tostring disconndarknetpeers tostring max_disconn_peer_alert_threshold max_conn_alert_threshold toomanyconns tostring tostring max_conn_alert_threshold max_peer_alert_threshold toomanypeers tostring tostring max_peer_alert_threshold oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold toooldneverconnectedpeers illegalargumentexception static final public string replace string text string find string replace return replace careful text find replace replacecareful static public string replace all string text string find string replace int i while i text index of find 0 text text substring 0 i replace text substring i find length return text replaceall indexof static public string replace careful string text string find string replace string split text split find 1 string builder sb new string builder text length split length 1 replace length find length for int i 0 i split length i sb append split i if i split length 1 sb append replace return sb to string replacecareful stringbuilder stringbuilder tostring override public html node gethtml text html node alert node new html node div if peers 0 is opennet enabled if n is testnet enabled alert node add child l10n no peers testnet else alert node add child l10n no peers darknet else if conns 3 clock problem min clock problem peer alert threshold alert node add child l10n clock problem count integer to string clock problem else if conns 3 conn error min conn error alert threshold alert node add child l10n conn error count integer to string conn error else if conns 0 is opennet enabled alert node add child l10n no conns else if conns 1 is opennet enabled alert node add child l10n one conn else if conns 2 is opennet enabled alert node add child l10n two conns else if n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold alert node add child l10n too high bwlimit delay time new string delay max new string integer to string bwlimit delay time long to string node stats max bwlimit delay time alert threshold else if n node average ping alert relevant node average ping time node stats max node average ping time alert threshold alert node add child l10n too high ping time new string ping max new string integer to string node average ping time long to string node stats max node average ping time alert threshold else if clock problem min clock problem peer alert threshold alert node add child l10n clock problem count integer to string clock problem else if never conn max never connected peer alert threshold l10n addl10n substitution alert node peer manager user alert too many never connected with link new string link link count new string a href friends myref fref a integer to string never conn else if conn error min conn error alert threshold alert node add child l10n conn error count integer to string conn error else if disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat alert node add child l10n too many disconnected new string count max new string integer to string disconn darknet peers integer to string max disconn peer alert threshold else if conns max conn alert threshold alert node add child l10n too many conns new string count max new string integer to string conns integer to string max conn alert threshold else if peers max peer alert threshold alert node add child l10n too many peers new string count max new string integer to string peers integer to string max peer alert threshold else if oldest never connected peer age max oldest never connected peer age alert threshold alert node add child l10n too old never connected peers else throw new illegal argument exception not valid return alert node htmlnode gethtmltext htmlnode alertnode htmlnode isopennetenabled istestnetenabled alertnode addchild nopeerstestnet alertnode addchild nopeersdarknet clockproblem min_clock_problem_peer_alert_threshold alertnode addchild clockproblem tostring clockproblem connerror min_conn_error_alert_threshold alertnode addchild connerror tostring connerror isopennetenabled alertnode addchild noconns isopennetenabled alertnode addchild oneconn isopennetenabled alertnode addchild twoconns bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold alertnode addchild toohighbwlimitdelaytime tostring bwlimitdelaytime tostring nodestats max_bwlimit_delay_time_alert_threshold nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold alertnode addchild toohighpingtime tostring nodeaveragepingtime tostring nodestats max_node_average_ping_time_alert_threshold clockproblem min_clock_problem_peer_alert_threshold alertnode addchild clockproblem tostring clockproblem neverconn max_never_connected_peer_alert_threshold addl10nsubstitution alertnode peermanageruseralert toomanyneverconnectedwithlink tostring neverconn connerror min_conn_error_alert_threshold alertnode addchild connerror tostring connerror disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat alertnode addchild toomanydisconnected tostring disconndarknetpeers tostring max_disconn_peer_alert_threshold max_conn_alert_threshold alertnode addchild toomanyconns tostring tostring max_conn_alert_threshold max_peer_alert_threshold alertnode addchild toomanypeers tostring tostring max_peer_alert_threshold oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold alertnode addchild toooldneverconnectedpeers illegalargumentexception alertnode override public short get priority class if peers 0 is opennet enabled return user alert critical error if conns 0 is opennet enabled return user alert error if conns 3 clock problem min clock problem peer alert threshold return error if conns 3 conn error min conn error alert threshold return error if conns 3 is opennet enabled return error if n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold return error if n node average ping alert relevant node average ping time node stats max node average ping time alert threshold return error if clock problem min clock problem peer alert threshold return error if never conn max never connected peer alert threshold return warning if conn error min conn error alert threshold return warning if disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat return warning if conns max conn alert threshold return warning if peers max peer alert threshold return warning if oldest never connected peer age max oldest never connected peer age alert threshold return warning return error getpriorityclass isopennetenabled useralert critical_error isopennetenabled useralert clockproblem min_clock_problem_peer_alert_threshold connerror min_conn_error_alert_threshold isopennetenabled bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold clockproblem min_clock_problem_peer_alert_threshold neverconn max_never_connected_peer_alert_threshold connerror min_conn_error_alert_threshold disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat max_conn_alert_threshold max_peer_alert_threshold oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold override public boolean is valid only update here so we don t get odd behavior with it fluctuating bwlimit delay time int n get bwlimit delay time node average ping time int n get node average ping time oldest never connected peer age int n peers get oldest never connected peer age return peers 0 is opennet enabled conns 3 is opennet enabled never conn max never connected peer alert threshold disconn darknet peers max disconn peer alert threshold darknet definitely port forwarded darknet assumenat conns max conn alert threshold peers max peer alert threshold clock problem min clock problem peer alert threshold conn error min conn error alert threshold n bwlimit delay alert relevant bwlimit delay time node stats max bwlimit delay time alert threshold n node average ping alert relevant node average ping time node stats max node average ping time alert threshold oldest never connected peer age max oldest never connected peer age alert threshold super is valid isvalid bwlimitdelaytime getbwlimitdelaytime nodeaveragepingtime getnodeaveragepingtime oldestneverconnectedpeerage getoldestneverconnectedpeerage isopennetenabled isopennetenabled neverconn max_never_connected_peer_alert_threshold disconndarknetpeers max_disconn_peer_alert_threshold darknetdefinitelyportforwarded darknetassumenat max_conn_alert_threshold max_peer_alert_threshold clockproblem min_clock_problem_peer_alert_threshold connerror min_conn_error_alert_threshold bwlimitdelayalertrelevant bwlimitdelaytime nodestats max_bwlimit_delay_time_alert_threshold nodeaveragepingalertrelevant nodeaveragepingtime nodestats max_node_average_ping_time_alert_threshold oldestneverconnectedpeerage max_oldest_never_connected_peer_age_alert_threshold isvalid logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public static final double crazy max ping time 365 25 24 60 60 1000 node pinger node n this node n crazy_max_ping_time nodepinger void start run public void run try peer node peers null synchronized node peers if node peers connected peers null node peers connected peers length 0 return peers new peer node node peers connected peers length system arraycopy node peers connected peers 0 peers 0 node peers connected peers length now we don t have to care about synchronization anymore recalculate mean peers finally requeue after to avoid exacerbating overload node ps queue timed job this 200 peernode connectedpeers connectedpeers peernode connectedpeers connectedpeers connectedpeers recalculatemean queuetimedjob recalculate the mean ping time private void recalculate mean peer node peers if peers length 0 return mean ping calculate median ping peers if logminor logger minor this median ping mean ping recalculatemean peernode meanping calculatemedianping meanping private double calculate median ping peer node peers double all peers new double peers length for int i 0 i peers length i peer node peer peers i all peers i peer average ping time arrays sort all peers return all peers peers length 2 calculatemedianping peernode allpeers peernode allpeers averagepingtime allpeers allpeers public double average ping time return mean ping averagepingtime meanping private static final long serial versionuid 7443033796560597360l public parser exception exception e super e serialversionuid parserexception public parser exception string s super s parserexception consutrctor of perisstent string param str java string public persistent string string str this str str persistentstring private persistent string persistentstring get java string return java string public string to string return str tostring append string to the current string value of persistent string param tail appended string public void append string tail modify str str tail persistentstring assign new string value to the persistent string param str new string value public void set string str modify this str str persistentstring get current string value return java string public string get return str private class need restart user alert extends abstract user alert override public string get title return l10n need restart title needrestartuseralert abstractuseralert gettitle needrestarttitle override public string get text return gethtml text to string gettext gethtmltext tostring override public string get short text return l10n need restart short getshorttext needrestartshort override public html node gethtml text html node alert node new html node div alert node add child l10n need restart if node is using wrapper alert node add child br html node restart form alert node add child form new string action method enctype id accept charset new string post multipart form data restart form utf 8 add child div restart form add child input new string type name value new string hidden form password node client core form password restart form add child div restart form add child input new string type name new string hidden restart restart form add child input new string type name value new string submit restart2 l10n restart node return alert node htmlnode gethtmltext htmlnode alertnode htmlnode alertnode addchild needrestart isusingwrapper alertnode addchild htmlnode restartform alertnode addchild restartform addchild restartform addchild formpassword clientcore formpassword restartform addchild restartform addchild restartform addchild restartnode alertnode override public short get priority class return user alert warning getpriorityclass useralert override public boolean is valid return need restart isvalid needrestart override public boolean user can dismiss return false usercandismiss config toadlet high level simple client client config conf node node node client core core super client config conf this core core this node node configtoadlet highlevelsimpleclient nodeclientcore override public void handle post uri uri http request request toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return string pass request get part as string form password 32 if pass null pass equals core form password multi value table string string headers new multi value table string string headers put location config ctx send reply headers 302 found headers null 0 return if request is part set seclevels handle the security level changes html node page node null html node content null html node ul null html node form node null boolean changed anything false string config name security levels network threat level string confirm security levels network threat level confirm string try confirm security levels network threat level try confirm string network threat level request get part as string config name 128 network threat level new threat level security levels parse network threat level network threat level if new threat level null if new threat level node security levels get network threat level if request is part set confirm request is part set try confirm html node warning node security levels get confirm warning new threat level confirm if warning null if page node null page node ctx get page maker get page node l10n get string config toadlet full title new string name new string node get my name ctx content ctx get page maker get content node page node form node ctx add form child content config form sec levels ul form node add child ul class config html node seclevel group ul add child li seclevel group add child input new string type name value new string hidden config name network threat level html node infobox seclevel group add child div class infobox infobox information infobox add child div class infobox header l10n sec network threat level confirm title mode security levels localised name new threat level html node infobox content infobox add child div class infobox content infobox content add child warning infobox content add child input new string type name value new string hidden try confirm on else apply immediately no confirm needed node security levels set threat level new threat level changed anything true else if request is part set confirm apply immediately user confirmed it node security levels set threat level new threat level changed anything true config name security levels friends threat level confirm security levels friends threat level confirm try confirm security levels friends threat level try confirm string friends threat level request get part as string config name 128 friends threat level new friends level security levels parse friends threat level friends threat level if new friends level null if new friends level node security levels get friends threat level if request is part set confirm request is part set try confirm html node warning node security levels get confirm warning new friends level confirm if warning null if page node null page node ctx get page maker get page node l10n get string config toadlet full title new string name new string node get my name ctx content ctx get page maker get content node page node form node ctx add form child content config form sec levels ul form node add child ul class config html node seclevel group ul add child li seclevel group add child input new string type name value new string hidden config name friends threat level html node infobox seclevel group add child div class infobox infobox information infobox add child div class infobox header l10n sec friends threat level confirm title mode security levels localised name new friends level html node infobox content infobox add child div class infobox content infobox content add child warning infobox content add child input new string type name value new string hidden try confirm on else apply immediately no confirm needed node security levels set threat level new friends level changed anything true else if request is part set confirm apply immediately user confirmed it node security levels set threat level new friends level changed anything true config name security levels physical threat level confirm security levels physical threat level confirm try confirm security levels physical threat level try confirm string physical threat level request get part as string config name 128 physical threat level new physical level security levels parse physical threat level physical threat level if new physical level null if new physical level node security levels get physical threat level no confirmation for changes to physical threat level node security levels set threat level new physical level changed anything true if changed anything core store config if page node null form node add child input new string type name value new string hidden seclevels on form node add child input new string type value new string submit l10n apply form node add child input new string type value new string reset l10n reset writehtml reply ctx 200 ok page node generate return else multi value table string string headers new multi value table string string headers put location config mode mode security levels ctx send reply headers 302 found headers null 0 return other setting not security level goes here sub config sc config get configs string builder errbuf new string builder boolean logminor logger should log logger minor this for int i 0 i sc length i option o sc i get options string prefix sc i get prefix string config name for int j 0 j o length j config name o j get name if logminor logger minor this setting prefix config name we ignore unreconized parameters if request is part set prefix config name string value request get part as string prefix config name max param value size if o j get value string equals value if logminor logger minor this setting prefix config name to value try o j set value value catch invalid config value exception e errbuf append o j get name append append e get message append n catch node need restart exception e need restart true catch exception e errbuf append o j get name append append e append n logger error this caught e e wrapper params string wrapper config name wrapper java maxmemory if request is part set wrapper config name string value request get part as string wrapper config name max param value size if wrapper config get wrapper property wrapper config name equals value if logminor logger minor this setting wrapper config name to value wrapper config set wrapper property wrapper config name value core store config html node page node ctx get page maker get page node l10n applied title ctx html node content node ctx get page maker get content node page node if errbuf length 0 html node infobox content node add child ctx get page maker get infobox infobox success l10n applied title html node content ctx get page maker get content node infobox content add child l10n applied success if need restart content add child br content add child l10n need restart if node is using wrapper content add child br html node restart form ctx add form child content restart form restart form add child input new string type name new string hidden restart restart form add child input new string type name value new string submit restart2 l10n restart node if need restart user alert null need restart user alert new need restart user alert node client core alerts register need restart user alert else html node infobox content node add child ctx get page maker get infobox infobox error l10n applied failure title html node content ctx get page maker get content node infobox add child div class infobox content content add child l10n applied failure exceptions content add child br content add child errbuf to string html node infobox content node add child ctx get page maker get infobox infobox normal l10n possibilities title html node content ctx get page maker get content node infobox content add child a new string href title new string l10n short title handlepost httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring getpartasstring formpassword formpassword multivaluetable multivaluetable sendreplyheaders ispartset htmlnode pagenode htmlnode htmlnode htmlnode formnode changedanything configname networkthreatlevel networkthreatlevel tryconfirm networkthreatlevel tryconfirm networkthreatlevel getpartasstring configname network_threat_level newthreatlevel securitylevels parsenetworkthreatlevel networkthreatlevel newthreatlevel newthreatlevel securitylevels getnetworkthreatlevel ispartset ispartset tryconfirm htmlnode securitylevels getconfirmwarning newthreatlevel pagenode pagenode getpagemaker getpagenode getstring configtoadlet fulltitle getmyname getpagemaker getcontentnode pagenode formnode addformchild configformseclevels formnode addchild htmlnode seclevelgroup addchild seclevelgroup addchild configname networkthreatlevel htmlnode seclevelgroup addchild addchild l10nsec networkthreatlevelconfirmtitle securitylevels localisedname newthreatlevel htmlnode infoboxcontent addchild infoboxcontent addchild infoboxcontent addchild tryconfirm securitylevels setthreatlevel newthreatlevel changedanything ispartset securitylevels setthreatlevel newthreatlevel changedanything configname friendsthreatlevel friendsthreatlevel tryconfirm friendsthreatlevel tryconfirm friendsthreatlevel getpartasstring configname friends_threat_level newfriendslevel securitylevels parsefriendsthreatlevel friendsthreatlevel newfriendslevel newfriendslevel securitylevels getfriendsthreatlevel ispartset ispartset tryconfirm htmlnode securitylevels getconfirmwarning newfriendslevel pagenode pagenode getpagemaker getpagenode getstring configtoadlet fulltitle getmyname getpagemaker getcontentnode pagenode formnode addformchild configformseclevels formnode addchild htmlnode seclevelgroup addchild seclevelgroup addchild configname friendsthreatlevel htmlnode seclevelgroup addchild addchild l10nsec friendsthreatlevelconfirmtitle securitylevels localisedname newfriendslevel htmlnode infoboxcontent addchild infoboxcontent addchild infoboxcontent addchild tryconfirm securitylevels setthreatlevel newfriendslevel changedanything ispartset securitylevels setthreatlevel newfriendslevel changedanything configname physicalthreatlevel physicalthreatlevel tryconfirm physicalthreatlevel tryconfirm physicalthreatlevel getpartasstring configname physical_threat_level newphysicallevel securitylevels parsephysicalthreatlevel physicalthreatlevel newphysicallevel newphysicallevel securitylevels getphysicalthreatlevel securitylevels setthreatlevel newphysicallevel changedanything changedanything storeconfig pagenode formnode addchild formnode addchild formnode addchild writehtmlreply pagenode multivaluetable multivaluetable mode_security_levels sendreplyheaders subconfig getconfigs stringbuilder stringbuilder shouldlog getoptions getprefix configname configname getname configname ispartset configname getpartasstring configname max_param_value_size getvaluestring configname setvalue invalidconfigvalueexception getname getmessage nodeneedrestartexception needrestart getname wrapperconfigname ispartset wrapperconfigname getpartasstring wrapperconfigname max_param_value_size wrapperconfig getwrapperproperty wrapperconfigname wrapperconfigname wrapperconfig setwrapperproperty wrapperconfigname storeconfig htmlnode pagenode getpagemaker getpagenode appliedtitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox appliedtitle htmlnode getpagemaker getcontentnode addchild appliedsuccess needrestart addchild addchild needrestart isusingwrapper addchild htmlnode restartform addformchild restartform restartform addchild restartform addchild restartnode needrestartuseralert needrestartuseralert needrestartuseralert clientcore needrestartuseralert htmlnode contentnode addchild getpagemaker getinfobox appliedfailuretitle htmlnode getpagemaker getcontentnode addchild addchild appliedfailureexceptions addchild addchild tostring htmlnode contentnode addchild getpagemaker getinfobox possibilitiestitle htmlnode getpagemaker getcontentnode addchild shorttitle private static final string l10n string string return l10n get string config toadlet string getstring configtoadlet override public void handle get uri uri http request req toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 l10n get string toadlet unauthorized title l10n get string toadlet unauthorized return sub config sc config get configs arrays sort sc html node page node ctx get page maker get page node l10n get string config toadlet full title new string name new string node get my name ctx html node content node ctx get page maker get content node page node content node add child core alerts create summary final int mode ctx get page maker draw mode selection array core req content node mode security levels security levels title security levels tooltip if mode mode security levels draw security levels page content node ctx else if mode page maker mode advanced html node navigation bar ctx get page maker get infobox navbar l10n config nav title html node navigation content ctx get page maker get content node navigation bar add child ul if l10n get selected language equals l10n language get default navigation content add child a href translation toadlet toadlet url l10n contribute translation html node navigation table navigation content add child table class config navigation html node navigation table row navigation table add child tr html node next table cell navigation table row for int i 0 i sc length i if sc i get prefix equals security levels continue next table cell add child td class config navigation add child li add child a href sc i get prefix l10n sc i get prefix content node add child navigation bar html node infobox content node add child div class infobox infobox normal infobox add child div class infobox header l10n title html node config node infobox add child div class infobox content html node form node ctx add form child config node config form if wrapper config can change properties string config name wrapper java maxmemory string cur value wrapper config get wrapper property config name if cur value null form node add child div class configprefix l10n wrapper html node list form node add child ul class config html node item list add child li fixme how to get the real default string default value 128 item add child span new string class title style new string configshortdesc l10n get string config toadlet default is new string default new string default value cursor help add child l10n gethtml node wrapper config config name short item add child span class config add child input new string type class name value new string text config config name cur value item add child span class configlongdesc add child l10n gethtml node wrapper config config name long for int i 0 i sc length i short displayed config elements 0 if sc i get prefix equals security levels continue option o sc i get options html node config group ul node new html node ul class config for int j 0 j o length j if mode page maker mode simple o j is expert displayed config elements string config name o j get name html node config item node config group ul node add child li config item node add child span new string class title style new string configshortdesc l10n get string config toadlet default is new string default new string o j get default mode page maker mode advanced sc i get prefix o j get name cursor help add child l10n gethtml node o j get short desc html node config item value node config item node add child span class config if o j get value string null logger error this sc i get prefix config name has returned null from config continue config callback callback o j get callback if callback instanceof enumerable option callback config item value node add child add combo box enumerable option callback callback sc i config name callback is read only else if callback instanceof boolean callback config item value node add child add boolean combo box boolean option o j get value sc i config name callback is read only else if callback is read only config item value node add child input new string type class disabled alt name value new string text config disabled o j get short desc sc i get prefix config name o j get value string else config item value node add child input new string type class alt name value new string text config o j get short desc sc i get prefix config name o j get value string config item node add child span class configlongdesc add child l10n gethtml node o j get long desc if displayed config elements 0 form node add child div class configprefix l10n sc i get prefix form node add child a id sc i get prefix form node add child config group ul node form node add child input new string type value new string submit l10n apply form node add child input new string type value new string reset l10n reset this writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring unauthorizedtitle getstring subconfig getconfigs htmlnode pagenode getpagemaker getpagenode getstring configtoadlet fulltitle getmyname htmlnode contentnode getpagemaker getcontentnode pagenode contentnode addchild createsummary getpagemaker drawmodeselectionarray contentnode mode_security_levels securitylevels securitylevels mode_security_levels drawsecuritylevelspage contentnode pagemaker mode_advanced htmlnode navigationbar getpagemaker getinfobox confignavtitle htmlnode navigationcontent getpagemaker getcontentnode navigationbar addchild getselectedlanguage getdefault navigationcontent addchild translationtoadlet toadlet_url contributetranslation htmlnode navigationtable navigationcontent addchild config_navigation htmlnode navigationtablerow navigationtable addchild htmlnode nexttablecell navigationtablerow getprefix nexttablecell addchild config_navigation addchild addchild getprefix getprefix contentnode addchild navigationbar htmlnode contentnode addchild addchild htmlnode confignode addchild htmlnode formnode addformchild confignode configform wrapperconfig canchangeproperties configname curvalue wrapperconfig getwrapperproperty configname curvalue formnode addchild htmlnode formnode addchild htmlnode addchild defaultvalue addchild getstring configtoadlet defaultis defaultvalue addchild gethtmlnode wrapperconfig configname addchild addchild configname curvalue addchild addchild gethtmlnode wrapperconfig configname displayedconfigelements getprefix getoptions htmlnode configgroupulnode htmlnode pagemaker mode_simple isexpert displayedconfigelements configname getname htmlnode configitemnode configgroupulnode addchild configitemnode addchild getstring configtoadlet defaultis getdefault pagemaker mode_advanced getprefix getname addchild gethtmlnode getshortdesc htmlnode configitemvaluenode configitemnode addchild getvaluestring getprefix configname configcallback getcallback enumerableoptioncallback configitemvaluenode addchild addcombobox enumerableoptioncallback configname isreadonly booleancallback configitemvaluenode addchild addbooleancombobox booleanoption getvalue configname isreadonly isreadonly configitemvaluenode addchild getshortdesc getprefix configname getvaluestring configitemvaluenode addchild getshortdesc getprefix configname getvaluestring configitemnode addchild addchild gethtmlnode getlongdesc displayedconfigelements formnode addchild getprefix formnode addchild getprefix formnode addchild configgroupulnode formnode addchild formnode addchild writehtmlreply pagenode private void draw security levels page html node content node toadlet context ctx html node infobox content node add child div class infobox infobox normal infobox add child div class infobox header l10n sec title html node config node infobox add child div class infobox content html node form node ctx add form child config node config form sec levels network security level form node add child div class configprefix l10n sec network threat level short html node ul form node add child ul class config html node seclevel group ul add child li seclevel group add child l10n sec network threat level network threat level network level node security levels get network threat level string control name security levels network threat level for network threat level level network threat level values html node input if level network level input seclevel group add child p add child input new string type checked name value new string radio on control name level name else input seclevel group add child p add child input new string type name value new string radio control name level name input add child b l10n sec network threat level name level input add child l10n addl10n substitution input security levels network threat level choice level new string bold bold new string b b html node inner input add child p add child i l10n addl10n substitution inner security levels network threat level desc level new string bold bold new string b b friends security level form node add child div class configprefix l10n sec friends threat level short ul form node add child ul class config seclevel group ul add child li seclevel group add child l10n sec friends threat level friends threat level friends level node security levels get friends threat level control name security levels friends threat level for friends threat level level friends threat level values html node input if level friends level input seclevel group add child p add child input new string type checked name value new string radio on control name level name else input seclevel group add child p add child input new string type name value new string radio control name level name input add child b l10n sec friends threat level name level input add child l10n addl10n substitution input security levels friends threat level choice level new string bold bold new string b b html node inner input add child p add child i l10n addl10n substitution inner security levels friends threat level desc level new string bold bold new string b b physical security level form node add child div class configprefix l10n sec physical threat level short ul form node add child ul class config seclevel group ul add child li seclevel group add child l10n sec physical threat level physical threat level physical level node security levels get physical threat level control name security levels physical threat level for physical threat level level physical threat level values html node input if level physical level input seclevel group add child p add child input new string type checked name value new string radio on control name level name else input seclevel group add child p add child input new string type name value new string radio control name level name input add child b l10n sec physical threat level name level input add child l10n addl10n substitution input security levels physical threat level choice level new string bold bold new string b b html node inner input add child p add child i l10n addl10n substitution inner security levels physical threat level desc level new string bold bold new string b b fixme implement the rest it should be very similar to the above form node add child input new string type name value new string hidden seclevels on form node add child input new string type value new string submit l10n apply form node add child input new string type value new string reset l10n reset drawsecuritylevelspage htmlnode contentnode toadletcontext htmlnode contentnode addchild addchild l10nsec htmlnode confignode addchild htmlnode formnode addformchild confignode configformseclevels formnode addchild l10nsec networkthreatlevelshort htmlnode formnode addchild htmlnode seclevelgroup addchild seclevelgroup addchild l10nsec networkthreatlevel network_threat_level networklevel securitylevels getnetworkthreatlevel controlname networkthreatlevel network_threat_level network_threat_level htmlnode networklevel seclevelgroup addchild addchild controlname seclevelgroup addchild addchild controlname addchild l10nsec networkthreatlevel addchild addl10nsubstitution securitylevels networkthreatlevel htmlnode addchild addchild addl10nsubstitution securitylevels networkthreatlevel formnode addchild l10nsec friendsthreatlevelshort formnode addchild seclevelgroup addchild seclevelgroup addchild l10nsec friendsthreatlevel friends_threat_level friendslevel securitylevels getfriendsthreatlevel controlname friendsthreatlevel friends_threat_level friends_threat_level htmlnode friendslevel seclevelgroup addchild addchild controlname seclevelgroup addchild addchild controlname addchild l10nsec friendsthreatlevel addchild addl10nsubstitution securitylevels friendsthreatlevel htmlnode addchild addchild addl10nsubstitution securitylevels friendsthreatlevel formnode addchild l10nsec physicalthreatlevelshort formnode addchild seclevelgroup addchild seclevelgroup addchild l10nsec physicalthreatlevel physical_threat_level physicallevel securitylevels getphysicalthreatlevel controlname physicalthreatlevel physical_threat_level physical_threat_level htmlnode physicallevel seclevelgroup addchild addchild controlname seclevelgroup addchild addchild controlname addchild l10nsec physicalthreatlevel addchild addl10nsubstitution securitylevels physicalthreatlevel htmlnode addchild addchild addl10nsubstitution securitylevels physicalthreatlevel formnode addchild formnode addchild formnode addchild private string l10n sec string key return l10n get string security levels key l10nsec getstring securitylevels private string l10n sec string key string pattern string value return l10n get string security levels key pattern value l10nsec getstring securitylevels override public string supported methods return get post supportedmethods private html node add combo box enumerable option callback o sub config sc string name boolean disabled html node result if disabled result new html node select new string name disabled new string sc get prefix name disabled else result new html node select name sc get prefix name string possible values o get possible values for int i 0 i possible values length i if possible values i equals o get result add child option new string value selected new string possible values i selected possible values i else result add child option value possible values i possible values i return result htmlnode addcombobox enumerableoptioncallback subconfig htmlnode htmlnode getprefix htmlnode getprefix possiblevalues getpossiblevalues possiblevalues possiblevalues addchild possiblevalues possiblevalues addchild possiblevalues possiblevalues private html node add boolean combo box boolean value sub config sc string name boolean disabled html node result if disabled result new html node select new string name disabled new string sc get prefix name disabled else result new html node select name sc get prefix name if value result add child option new string value selected new string true selected l10n true result add child option value false l10n false else result add child option value true l10n true result add child option new string value selected new string false selected l10n false return result htmlnode addbooleancombobox subconfig htmlnode htmlnode getprefix htmlnode getprefix addchild addchild addchild addchild final dda check job check job testdda reply message dda check job job this check job job ddacheckjob checkjob testddareplymessage ddacheckjob checkjob override public simple field set get field set simple field set sfs new simple field set true sfs put single testdda request message directory check job directory to string if check job read filename null sfs put single read filename check job read filename to string if check job write filename null sfs put single write filename check job write filename to string sfs put single content to write check job write content return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle testddarequestmessage checkjob tostring checkjob readfilename putsingle read_filename checkjob readfilename tostring checkjob writefilename putsingle write_filename checkjob writefilename tostring putsingle content_to_write checkjob writecontent override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message name goes from server to client not the other way around name false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception protected float h edge matrix sobel h public edge filter hedgematrix sobel_h edgefilter public void setv edge matrix float v edge matrix this v edge matrix v edge matrix setvedgematrix vedgematrix vedgematrix vedgematrix public float getv edge matrix return v edge matrix getvedgematrix vedgematrix public void seth edge matrix float h edge matrix this h edge matrix h edge matrix sethedgematrix hedgematrix hedgematrix hedgematrix public float geth edge matrix return h edge matrix gethedgematrix hedgematrix override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int r 0 g 0 b 0 int rh 0 gh 0 bh 0 int rv 0 gv 0 bv 0 int a in pixels y width x 0xff000000 for int row 1 row 1 row int iy y row int ioffset if 0 iy iy height ioffset iy width else ioffset y width int moffset 3 row 1 1 for int col 1 col 1 col int ix x col if 0 ix ix width ix x int rgb in pixels ioffset ix float h h edge matrix moffset col float v v edge matrix moffset col r rgb 0xff0000 16 g rgb 0x00ff00 8 b rgb 0x0000ff rh int h r gh int h g bh int h b rv int v r gv int v g bv int v b r int math sqrt rh rh rv rv 1 8 g int math sqrt gh gh gv gv 1 8 b int math sqrt bh bh bv bv 1 8 r pixel utils clamp r g pixel utils clamp g b pixel utils clamp b out pixels index a r 16 g 8 b return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels hedgematrix vedgematrix pixelutils pixelutils pixelutils outpixels outpixels override public string to string return blur detect edges tostring public class static toadlet extends toadlet static toadlet super null statictoadlet statictoadlet override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception string path uri get path if path starts with root url we should never get any other path anyway return try path path substring root url length catch index out of bounds exception ioobe this send error page ctx 404 l10n path not found title l10n path not found return be very strict about what characters we allow in the path since if path matches a za z0 9 path index of 1 this send error page ctx 404 l10n path not found title l10n path invalid chars return input stream strm get class get resource as stream root path path if strm null this send error page ctx 404 l10n path not found title l10n path not found return bucket data ctx get bucket factory make bucket strm available output stream os data get output stream byte cbuf new byte 4096 while true int r strm read cbuf if r 1 break os write cbuf 0 r strm close os close url url get class get resource root path path date m time get urlm time url ctx send reply headers 200 ok null defaultmime types guessmime type path false data size m time ctx write data data data free handleget httprequest toadletcontext toadletcontextclosedexception ioexception getpath startswith root_url root_url indexoutofboundsexception senderrorpage pathnotfoundtitle pathnotfound _ indexof senderrorpage pathnotfoundtitle pathinvalidchars inputstream getclass getresourceasstream root_path senderrorpage pathnotfoundtitle pathnotfound getbucketfactory makebucket outputstream getoutputstream getclass getresource root_path mtime geturlmtime sendreplyheaders defaultmimetypes guessmimetype mtime writedata try to find the modification time for a url or return null if not possible we usually load our resources from the jar or possibly from a file in some setups so we check the modification time of the jar for resources in a jar and the mtime for files private date get urlm time url url if url get protocol equals jar file f new file url get path substring 0 url get path index of return new date f last modified else if url get protocol equals file file f new file url get path return new date f last modified else return null geturlmtime getprotocol getpath getpath indexof lastmodified getprotocol getpath lastmodified private string l10n string key return l10n get string static toadlet key getstring statictoadlet override public string supported methods return get supportedmethods public renew subscriber control point ctrlp set control point ctrlp renewsubscriber controlpoint setcontrolpoint private control point ctrl point public void set control point control point ctrlp ctrl point ctrlp controlpoint ctrlpoint setcontrolpoint controlpoint ctrlpoint public control point get control point return ctrl point controlpoint getcontrolpoint ctrlpoint public void run control point ctrlp get control point long renew interval interval 1000 while is runnable true try thread sleep renew interval catch interrupted exception e ctrlp renew subscriber service controlpoint getcontrolpoint renewinterval isrunnable renewinterval interruptedexception renewsubscriberservice applies distortion by adding water ripple effect param base image the base image return the distorted image public buffered image get distorted image buffered image base image noise producer noise producer get config get noise impl buffered image distorted image new buffered image base image get width base image get height buffered image type int argb graphics2d graphics graphics2d distorted image get graphics ripple filter ripple filter new ripple filter ripple filter set wave type ripple filter sine ripple filter setx amplitude 2 6f ripple filter sety amplitude 1 7f ripple filter setx wavelength 15 ripple filter sety wavelength 5 ripple filter set edge action transform filter nearest neighbour water filter water filter new water filter water filter set amplitude 1 5f water filter set phase 10 water filter set wavelength 2 buffered image effect image water filter filter base image null effect image ripple filter filter effect image null graphics draw image effect image 0 0 null null graphics dispose noise producer make noise distorted image 1f 1f 25f 25f noise producer make noise distorted image 1f 25f 5f 9f return distorted image baseimage bufferedimage getdistortedimage bufferedimage baseimage noiseproducer noiseproducer getconfig getnoiseimpl bufferedimage distortedimage bufferedimage baseimage getwidth baseimage getheight bufferedimage type_int_argb distortedimage getgraphics ripplefilter ripplefilter ripplefilter ripplefilter setwavetype ripplefilter ripplefilter setxamplitude ripplefilter setyamplitude ripplefilter setxwavelength ripplefilter setywavelength ripplefilter setedgeaction transformfilter nearest_neighbour waterfilter waterfilter waterfilter waterfilter setamplitude waterfilter setphase waterfilter setwavelength bufferedimage effectimage waterfilter baseimage effectimage ripplefilter effectimage drawimage effectimage noiseproducer makenoise distortedimage noiseproducer makenoise distortedimage distortedimage public class color4f extends tuple4f public color4f this 0 0 0 0 public color4f float x this x x 0 this y x 1 this z x 2 this w x 3 public color4f float x float y float z float w this x x this y y this z z this w w public color4f color4f t this x t x this y t y this z t z this w t w public color4f tuple4f t this x t x this y t y this z t z this w t w public color4f color c set c public void set color c set c getrgb components null getrgbcomponents public color get return new color x y z w create a dns record with a name type clazz and ttl dns record string name int type int clazz int ttl super name type clazz this ttl ttl this created system current time millis dnsrecord dnsrecord currenttimemillis true if this record is the same as some other record public boolean equals object other return other instanceof dns record same as dns record other dnsrecord sameas dnsrecord true if this record is the same as some other record boolean same as dns record other return super equals other same value dns record other sameas dnsrecord samevalue dnsrecord true if this record has the same value as some other record abstract boolean same value dns record other samevalue dnsrecord true if this record has the same type as some other record boolean same type dns record other return type other type sametype dnsrecord handles a query represented by this record return returns true if a conflict with one of the services registered with jmdns or with the hostname occured handles a responserepresented by this record return returns true if a conflict with one of the services registered with jmdns or with the hostname occured abstract boolean handle response jmdns impl dns adds this as an answer to the provided outgoing datagram abstract dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception handleresponse jmdnsimpl dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception true if this record is suppressed by the answers in a message boolean suppressed by dns incoming msg try for int i msg num answers i 0 if suppressed by dns record msg answers get i return true return false catch array index out of bounds exception e logger log level warning suppressed by message msg exception e msg print true return false suppressedby dnsincoming numanswers suppressedby dnsrecord arrayindexoutofboundsexception suppressedby true if this record would be supressed by an answer this is the case if this record would not have a significantly longer ttl boolean suppressed by dns record other if same as other other ttl ttl 2 return true return false suppressedby dnsrecord sameas get the expiration time of this record long get expiration time int percent return created percent ttl 10l getexpirationtime get the remaining ttl for this record int get remainingttl long now return int math max 0 get expiration time 100 now 1000 getremainingttl getexpirationtime check if the record is expired public boolean is expired long now return get expiration time 100 now isexpired getexpirationtime check if the record is stale ie it has outlived more than half of its ttl boolean is stale long now return get expiration time 50 now isstale getexpirationtime reset the ttl of a record this avoids having to update the entire record in the cache void resetttl dns record other created other created ttl other ttl dnsrecord write this record into an outgoing message abstract void write dns outgoing out throws io exception dnsoutgoing ioexception address string name int type int clazz int ttl inet address addr super name type clazz ttl this addr addr inetaddress address string name int type int clazz int ttl byte raw address super name type clazz ttl try this addr inet address get by address raw address catch unknown host exception exception logger log level warning address exception exception rawaddress inetaddress getbyaddress rawaddress unknownhostexception void write dns outgoing out throws io exception if addr null byte buffer addr get address if dns constants type a type if we have a type a records we should answer with a i pv4 address if addr instanceof inet4 address all is good else get the last four bytes byte tempbuffer buffer buffer new byte 4 system arraycopy tempbuffer 12 buffer 0 4 else if we have a type aaaa records we should answer with a i pv6 address if addr instanceof inet4 address byte tempbuffer buffer buffer new byte 16 for int i 0 i 16 i if i 11 buffer i tempbuffer i 12 else buffer i 0 int length buffer length out write bytes buffer 0 length dnsoutgoing ioexception getaddress dnsconstants type_a ipv4 inet4address ipv6 inet4address writebytes boolean same dns record other return same name other same value other dnsrecord samename samevalue boolean same name dns record other return name equals ignore case address other name samename dnsrecord equalsignorecase boolean same value dns record other return addr equals address other get address samevalue dnsrecord getaddress inet address get address return addr inetaddress getaddress creates a byte array representation of this record this is needed for tie break tests according to draft cheshire dnsext multicastdns 04 txt chapter 9 2 private byte to byte array try byte array output stream bout new byte array output stream data output stream dout new data output stream bout dout write name get bytes utf8 dout write short type dout write short clazz dout write int len byte buffer addr get address for int i 0 i buffer length i dout write byte buffer i dout close return bout to byte array catch io exception e throw new internal error tobytearray bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream getbytes writeshort writeshort writeint getaddress writebyte tobytearray ioexception internalerror does a lexicographic comparison of the byte array representation of this record and that record this is needed for tie break tests according to draft cheshire dnsext multicastdns 04 txt chapter 9 2 private int lex compare dns record address that byte this bytes this to byte array byte that bytes that to byte array for int i 0 n math min this bytes length that bytes length i n i if this bytes i that bytes i return 1 else if this bytes i that bytes i return 1 return this bytes length that bytes length lexcompare dnsrecord thisbytes tobytearray thatbytes tobytearray thisbytes thatbytes thisbytes thatbytes thisbytes thatbytes thisbytes thatbytes does the necessary actions when this as a query boolean handle query jmdns impl dns long expiration time dns record address dns address dns get local host getdns address record this if dns address null if dns address same type this dns address same name this dns address same value this logger finer handle query conflicting probe detected dns state dns get state lex compare lex compare dns address tie breaker test if dns get state is probing lex compare dns address 0 we lost the tie break we have to choose a different name dns get local host increment host name dns get cache clear for iterator i dns get services values iterator i has next service info impl info service info impl i next info revert state dns revert state return true return false handlequery jmdnsimpl expirationtime dnsrecord dnsaddress getlocalhost getdnsaddressrecord dnsaddress dnsaddress sametype dnsaddress samename dnsaddress samevalue handlequery getstate lexcompare dnsaddress getstate isprobing lexcompare dnsaddress getlocalhost incrementhostname getcache getservices hasnext serviceinfoimpl serviceinfoimpl revertstate revertstate does the necessary actions when this as a response boolean handle response jmdns impl dns dns record address dns address dns get local host getdns address record this if dns address null if dns address same type this dns address same name this dns address same value this logger finer handle response denial detected if dns get state is probing dns get local host increment host name dns get cache clear for iterator i dns get services values iterator i has next service info impl info service info impl i next info revert state dns revert state return true return false handleresponse jmdnsimpl dnsrecord dnsaddress getlocalhost getdnsaddressrecord dnsaddress dnsaddress sametype dnsaddress samename dnsaddress samevalue handleresponse getstate isprobing getlocalhost incrementhostname getcache getservices hasnext serviceinfoimpl serviceinfoimpl revertstate revertstate dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception return out dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception public string to string return to string address addr null addr get host address null tostring tostring gethostaddress public pointer string name int type int clazz int ttl string alias super name type clazz ttl this alias alias void write dns outgoing out throws io exception out write name alias dnsoutgoing ioexception writename boolean same value dns record other return alias equals pointer other alias samevalue dnsrecord boolean handle query jmdns impl dns long expiration time nothing to do i think there is no possibility for conflicts for this record type return false handlequery jmdnsimpl expirationtime boolean handle response jmdns impl dns nothing to do i think there is no possibility for conflicts for this record type return false handleresponse jmdnsimpl string get alias return alias getalias dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception return out dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception public string to string return to string alias tostring tostring public text string name int type int clazz int ttl byte text super name type clazz ttl this text text void write dns outgoing out throws io exception out write bytes text 0 text length dnsoutgoing ioexception writebytes boolean same value dns record other text txt text other if txt text length text length return false for int i text length i 0 if txt text i text i return false return true samevalue dnsrecord boolean handle query jmdns impl dns long expiration time nothing to do i think there is no possibility for conflicts for this record type return false handlequery jmdnsimpl expirationtime boolean handle response jmdns impl dns nothing to do shouldn t we care if we get a conflict at this level service info info service info dns services get name to lower case if info null if arrays equals text info text info revert state return true return false handleresponse jmdnsimpl serviceinfo serviceinfo tolowercase revertstate dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception return out dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception public string to string return to string text length 10 new string text 0 7 new string text tostring tostring public service string name int type int clazz int ttl int priority int weight int port string server super name type clazz ttl this priority priority this weight weight this port port this server server void write dns outgoing out throws io exception out write short priority out write short weight out write short port if dns incoming use domain name format for srv target out write name server false else out writeutf server 0 server length add a zero byte to the end just to be safe this is the strange form used by the bonjour conformance test out write byte 0 dnsoutgoing ioexception writeshort writeshort writeshort dnsincoming use_domain_name_format_for_srv_target writename bonjourconformancetest writebyte private byte to byte array try byte array output stream bout new byte array output stream data output stream dout new data output stream bout dout write name get bytes utf8 dout write short type dout write short clazz dout write int len dout write short priority dout write short weight dout write short port dout write server get bytes utf8 dout close return bout to byte array catch io exception e throw new internal error tobytearray bytearrayoutputstream bytearrayoutputstream dataoutputstream dataoutputstream getbytes writeshort writeshort writeint writeshort writeshort writeshort getbytes tobytearray ioexception internalerror private int lex compare dns record service that byte this bytes this to byte array byte that bytes that to byte array for int i 0 n math min this bytes length that bytes length i n i if this bytes i that bytes i return 1 else if this bytes i that bytes i return 1 return this bytes length that bytes length lexcompare dnsrecord thisbytes tobytearray thatbytes tobytearray thisbytes thatbytes thisbytes thatbytes thisbytes thatbytes thisbytes thatbytes boolean same value dns record other service s service other return priority s priority weight s weight port s port server equals s server samevalue dnsrecord boolean handle query jmdns impl dns long expiration time service info impl info service info impl dns get services get name to lower case if info null port info port server equals ignore case dns get local host get name logger finer handle query conflicting probe detected from get record source dns record service local service new dns record service info get qualified name dns constants type srv dns constants class in dns constants class unique dns constants dns ttl info priority info weight info port dns get local host get name this block is useful for debugging race conditions when jmdns is respoding to itself try if dns get interface equals get record source logger warning got conflicting probe from ourselves n incoming this to string n local local service to string catch io exception e e print stack trace int comparison lex compare local service if comparison 0 the 2 records are identical this probably means we are seeing our own record with mutliple interfaces on a single computer it is possible to see our own records come in on different interfaces than the ones they were sent on see section 10 conflict resolution of mdns draft spec logger finer handle query ignoring a identical service query return false tie breaker test if info get state is probing comparison 0 we lost the tie break string old name info get qualified name to lower case info set name dns increment name info get name dns get services remove old name dns get services put info get qualified name to lower case info logger finer handle query lost tie break new unique name chosen info get name we revert the state to start probing again with the new name info revert state else we won the tie break so this conflicting probe should be ignored see paragraph 3 of section 9 2 in mdns draft spec return false return true return false handlequery jmdnsimpl expirationtime serviceinfoimpl serviceinfoimpl getservices tolowercase equalsignorecase getlocalhost getname handlequery getrecordsource dnsrecord localservice dnsrecord getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl getlocalhost getname getinterface getrecordsource tostring localservice tostring ioexception printstacktrace lexcompare localservice handlequery getstate isprobing oldname getqualifiedname tolowercase setname incrementname getname getservices oldname getservices getqualifiedname tolowercase handlequery getname revertstate boolean handle response jmdns impl dns service info impl info service info impl dns get services get name to lower case if info null port info port server equals ignore case dns get local host get name logger finer handle response denial detected if info get state is probing string old name info get qualified name to lower case info set name dns increment name info get name dns get services remove old name dns get services put info get qualified name to lower case info logger finer handle response new unique name chose info get name info revert state return true return false handleresponse jmdnsimpl serviceinfoimpl serviceinfoimpl getservices tolowercase equalsignorecase getlocalhost getname handleresponse getstate isprobing oldname getqualifiedname tolowercase setname incrementname getname getservices oldname getservices getqualifiedname tolowercase handleresponse getname revertstate dns outgoing add answer jmdns impl dns dns incoming in inet address addr int port dns outgoing out throws io exception service info impl info service info impl dns get services get name to lower case if info null if this port info port server equals dns get local host get name return dns add answer in addr port out new dns record service info get qualified name dns constants type srv dns constants class in dns constants class unique dns constants dns ttl info priority info weight info port dns get local host get name return out dnsoutgoing addanswer jmdnsimpl dnsincoming inetaddress dnsoutgoing ioexception serviceinfoimpl serviceinfoimpl getservices tolowercase getlocalhost getname addanswer dnsrecord getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants class_unique dnsconstants dns_ttl getlocalhost getname public string to string return to string server port tostring tostring public void set record source inet address source this source source setrecordsource inetaddress public inet address get record source return source inetaddress getrecordsource public string to string string other return to string record ttl get remainingttl system current time millis other tostring tostring getremainingttl currenttimemillis public void set ttl int ttl this ttl ttl setttl public int get ttl return ttl getttl boolean flushing public pin weak hash table int initial capacity threshold int initial capacity load factor table new entry initial capacity pinweakhashtable initialcapacity initialcapacity loadfactor initialcapacity public synchronized boolean remove int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index prev null e null prev e e e next if e oid oid if prev null prev next e next else tab index e next e clear count 1 return true return false protected reference create reference object obj return new weak reference obj createreference weakreference public synchronized void put int oid i persistent obj reference ref create reference obj entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e ref ref return if count threshold flushing rehash the table if the threshold is exceeded rehash tab table index oid 0x7fffffff tab length creates the new entry tab index new entry oid ref tab index count 1 ipersistent createreference public synchronized i persistent get int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid if e pin null return e pin return i persistent e ref get return null ipersistent ipersistent public synchronized void flush flushing true for int i 0 i table length i for entry e table i e null e e next i persistent obj e pin if obj null obj store e pin null flushing false if count threshold rehash the table if the threshold is exceeded rehash return ipersistent public synchronized void invalidate for int i 0 i table length i for entry e table i e null e e next i persistent obj e pin if obj null e pin null obj invalidate table i null count 0 ipersistent public synchronized void clear entry tab table for int i 0 i tab length i tab i null count 0 void rehash int old capacity table length entry old map table int i for i old capacity i 0 entry e next prev for prev null e old map i e null e next next e next i persistent obj i persistent e ref get if obj null obj is deleted e pin null count 1 e clear if prev null old map i next else prev next next else prev e if count threshold 1 return int new capacity old capacity 2 1 entry new map new entry new capacity threshold int new capacity load factor table new map for i old capacity i 0 for entry old old map i old null entry e old old old next int index e oid 0x7fffffff new capacity e next new map index new map index e oldcapacity oldmap oldcapacity oldmap ipersistent ipersistent isdeleted oldmap newcapacity oldcapacity newmap newcapacity newcapacity loadfactor newmap oldcapacity oldmap newcapacity newmap newmap public synchronized void set dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e pin obj return setdirty ipersistent getoid public synchronized void clear dirty i persistent obj int oid obj get oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e pin null return cleardirty ipersistent getoid public int size return count void clear ref clear ref null pin null next null entry int oid reference ref entry chain next chain this oid oid this ref ref public class replication static slave storage impl extends replication slave storage impl public replication static slave storage impl int port this port port replicationstaticslavestorageimpl replicationslavestorageimpl replicationstaticslavestorageimpl public void open i file file int page pool size try acceptor new server socket port catch io exception x throw new storage error storage error bad replication port byte root page new byte page page size int rc file read 0 root page if rc page page size prev index root page db hdr curr index offset initialized root page db hdr initialized offset 0 else initialized false prev index 1 out of sync false super open file page pool size ifile pagepoolsize serversocket ioexception storageerror storageerror bad_replication_port rootpage pagesize rootpage pagesize previndex rootpage db_hdr_curr_index_offset rootpage db_hdr_initialized_offset previndex outofsync pagepoolsize socket get socket throws io exception return acceptor accept getsocket ioexception cancel accept void cancelio try socket s new socket localhost port s close catch io exception x ioexception creates an introduction client public introduction client wot my wot super my wot get plugin respirator get node my wot get plugin respirator gethl simple client wot introduction client m wot my wot m puzzle store m wot get introduction puzzle store m random m wot get plugin respirator get node fast weak random start introductionclient introductionclient mywot mywot getpluginrespirator getnode mywot getpluginrespirator gethlsimpleclient mwot mywot mpuzzlestore mwot getintroductionpuzzlestore mrandom mwot getpluginrespirator getnode fastweakrandom override protected collection client getter create fetch storage return new hash set client getter puzzle request count 2 todo profile tweak clientgetter createfetchstorage hashset clientgetter puzzle_request_count override protected collection base client putter create insert storage return new hash set base client putter puzzle request count 2 todo profile tweak baseclientputter createinsertstorage hashset baseclientputter puzzle_request_count public int get priority return native thread low priority getpriority nativethread low_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period called by the superclass transfer thread after get startup delay milliseconds and then after each get sleep time milliseconds deletes old puzzles fetches new ones and inserts solutions of the user override protected void iterate m puzzle store delete expired puzzles download puzzles insert solutions transferthread getstartupdelay getsleeptime mpuzzlestore deleteexpiredpuzzles downloadpuzzles insertsolutions use this function in the ui to get a list of puzzles for the user to solve fixme is it okay if we do not require users to lock the puzzle store while parsing the returned list because they would have to also lock the wot first to prevent deadlocks the worst thing which can happen is that they display a puzzle which has been deleted already it should be save to parse object containers while the database is being modified shouldn t it public list introduction puzzle get puzzles own identity user puzzle type puzzle type int count deadlocks could occur without the lock on wot because the loop calls functions which lock the wot if something else started to execute while we have already locked the puzzle store which locks the wot and waits for the puzzle store to become available until it releases the wot synchronized m wot synchronized m puzzle store list introduction puzzle puzzles m puzzle store get unsolved puzzles puzzle type array list introduction puzzle result new array list introduction puzzle count 1 hash set identity result has puzzle from new hash set identity count 2 have some room so we do not hit the load factor for introduction puzzle puzzle puzzles try todo maybe also check whether the user has already solved puzzles of the identity which inserted this one if result has puzzle from contains puzzle get inserter int score m wot get score user puzzle get inserter get score if score minimum score for puzzle display try m wot get trust puzzle get inserter user we are already on this identity s trust list so there is no use in solving another puzzle from it catch not trusted exception e result add puzzle result has puzzle from add puzzle get inserter if result size count break catch not in trust tree exception e logger error this wtf e return result puzzlestore objectcontainers introductionpuzzle getpuzzles ownidentity puzzletype puzzletype mwot mpuzzlestore introductionpuzzle mpuzzlestore getunsolvedpuzzles puzzletype arraylist introductionpuzzle arraylist introductionpuzzle hashset resulthaspuzzlefrom hashset introductionpuzzle resulthaspuzzlefrom getinserter mwot getscore getinserter getscore minimum_score_for_puzzle_display mwot gettrust getinserter nottrustedexception resulthaspuzzlefrom getinserter notintrusttreeexception use this function to store the solution of a puzzle and upload it throws invalid parameter exception if the puzzle was already solved public void solve puzzle own identity solver introduction puzzle puzzle string solution throws invalid parameter exception synchronized m puzzle store synchronized puzzle puzzle set solved solver solution m puzzle store store and commit puzzle try insert puzzle solution puzzle catch exception e logger error this insert puzzle solution failed e invalidparameterexception solvepuzzle ownidentity introductionpuzzle invalidparameterexception mpuzzlestore setsolved mpuzzlestore storeandcommit insertpuzzlesolution insertpuzzlesolution private synchronized void download puzzles normally we would lock the whole wot here because we iterate over a list returned by it but because it is not a severe problem if we download a puzzle of an identity which has been deleted or so we do not do that object set identity all identities m wot get all non own identities sorted by modification array list identity identities to download from new array list identity puzzle pool size download puzzles from identities from which we have not downloaded for a certain period this is ensured by keeping the last few hundred identities stored in a fifo with fixed length named m identities normally we would have to lock the wot here first so that no deadlock happens if something else locks the m identities and waits for the wot until it unlocks them but nothing else in this class locks m identities and then the wot synchronized m identities for identity i all identities todo create a boolean provides introduction in identity to use a database query instead of this if i has context introduction puzzle introduction context m identities contains i m wot get best score i minimum score for puzzle download identities to download from add i if identities to download from size puzzle request count break if we run out of identities to download from be less restrictive if identities to download from size 0 m identities clear we probably have less updated identities today than the size of the lru queue empty it for identity i all identities todo create a boolean provides introduction in identity to use a database query instead of this if i has context introduction puzzle introduction context m wot get best score i minimum score for puzzle download identities to download from add i if identities to download from size puzzle request count break i suppose its a good idea to restart downloading the puzzles from the latest updated identities every time the thread iterates this prevents denial of service because people will usually get very new puzzles abort fetches for identity i identities to download from try download puzzle i catch exception e logger error this starting puzzle download failed e downloadpuzzles objectset allidentities mwot getallnonownidentitiessortedbymodification arraylist identitiestodownloadfrom arraylist puzzle_pool_size midentities midentities midentities midentities allidentities providesintroduction hascontext introductionpuzzle introduction_context midentities mwot getbestscore minimum_score_for_puzzle_download identitiestodownloadfrom identitiestodownloadfrom puzzle_request_count identitiestodownloadfrom midentities lruqueue allidentities providesintroduction hascontext introductionpuzzle introduction_context mwot getbestscore minimum_score_for_puzzle_download identitiestodownloadfrom identitiestodownloadfrom puzzle_request_count abortfetches identitiestodownloadfrom downloadpuzzle private void insert solutions abort inserts synchronized m puzzle store object set introduction puzzle puzzles m puzzle store get uninserted solved puzzles for introduction puzzle p puzzles try insert puzzle solution p catch exception e logger error this inserting solution for p failed insertsolutions abortinserts mpuzzlestore objectset introductionpuzzle mpuzzlestore getuninsertedsolvedpuzzles introductionpuzzle insertpuzzlesolution not synchronized because its caller is synchronized already private void insert puzzle solution introduction puzzle puzzle throws io exception transformer exception insert exception assert puzzle was inserted bucket tempb mtbf make bucket 1024 todo set to a reasonable value output stream os null try os tempb get output stream m wot getxml transformer export introduction puzzle get solver os os close os null tempb set read only freeneturi solutionuri puzzle get solutionuri insert block ib new insert block tempb null solutionuri insert context ictx m client get insert context true fixme toad are these parameters correct client putter pu m client insert ib false null false ictx this fixme set to a reasonable value before release plugin manager default is interactive priority pu set priority class request starter update priority class m wot get plugin respirator get node client core client context null add insert pu tempb null logger debug this started to insert puzzle solution of puzzle get solver get nickname at solutionuri finally if tempb null tempb free closer close os insertpuzzlesolution introductionpuzzle ioexception transformerexception insertexception wasinserted makebucket outputstream getoutputstream mwot getxmltransformer exportintroduction getsolver setreadonly getsolutionuri insertblock insertblock insertcontext mclient getinsertcontext clientputter mclient pluginmanager setpriorityclass requeststarter update_priority_class mwot getpluginrespirator getnode clientcore clientcontext addinsert getsolver getnickname finds a random index of a puzzle from the inserter which we did not download yet and downloads it not synchronized because its caller is synchronized already private void download puzzle identity inserter throws fetch exception download puzzle inserter m random next int introduction server get identity puzzle count inserter downloadpuzzle fetchexception downloadpuzzle mrandom nextint introductionserver getidentitypuzzlecount not synchronized because its caller is synchronized already private void download puzzle identity inserter int index throws fetch exception int inserter puzzle count introduction server get identity puzzle count inserter assert index inserter puzzle count 1 we do that so that on success can just call this function with the index increased by 1 index inserter puzzle count date date current timeutc get freeneturi uri synchronized m puzzle store if m puzzle store get of today by inserter inserter size max puzzles per identity return find a free index int count 0 while m puzzle store get by inserter date index inserter date index null count inserter puzzle count index index 1 inserter puzzle count count todo maybe also use the above loop which finds a free index for counting the recent puzzles accurately if count max puzzles per identity we have all puzzles of this identity logger error this should not happen get of today by inserter returned less puzzles than get by inerter day index return uri introduction puzzle generate requesturi inserter date index fetch context fetch context m client get fetch context fixme toad are these parameters correct fetch context max splitfile block retries 1 retry forever fetch context max non splitfile retries 1 retry forever client getter g m client fetch uri xml transformer max introductionpuzzle byte size m wot get request client this fetch context fixme set to a reasonable value before release plugin manager default is interactive priority g set priority class request starter update priority class add fetch g attention do not lock the wot here before locking m identities because there is another synchronized m identities in this class which locks the wot inside the m identities lock synchronized m identities if m identities contains inserter the oldest identity falls out of the fifo and therefore puzzle downloads from that one are allowed again it is only checked in download puzzles whether puzzle downloads are allowed because we download up to max puzzles per identity puzzles per identity the on success starts download of the next one usually m identities poll try m identities put inserter put this identity at the beginning of the fifo catch interrupted exception e logger debug this trying to fetch puzzle from uri to string downloadpuzzle fetchexception inserterpuzzlecount introductionserver getidentitypuzzlecount inserterpuzzlecount onsuccess inserterpuzzlecount currenttimeutc mpuzzlestore mpuzzlestore getoftodaybyinserter max_puzzles_per_identity mpuzzlestore getbyinserterdateindex inserterpuzzlecount inserterpuzzlecount max_puzzles_per_identity getoftodaybyinserter getbyinerterdayindex introductionpuzzle generaterequesturi fetchcontext fetchcontext mclient getfetchcontext fetchcontext maxsplitfileblockretries fetchcontext maxnonsplitfileretries clientgetter mclient xmltransformer max_introductionpuzzle_byte_size mwot getrequestclient fetchcontext pluginmanager setpriorityclass requeststarter update_priority_class addfetch midentities midentities midentities midentities midentities downloadpuzzles max_puzzles_per_identity onsuccess midentities midentities interruptedexception tostring called when a puzzle is successfully fetched public void on success fetch result result client getter state object container container logger debug this fetched puzzle state geturi try introduction puzzle puzzle m wot getxml transformer import introduction puzzle state geturi result as bucket get input stream fixme add logic to call this only once for every few puzzles fetched not for every single one m puzzle store delete oldest unsolved puzzles puzzle pool size download puzzle puzzle get inserter puzzle get index 1 todo also download a random index here maybe catch exception e logger error this parsing failed for state geturi e finally remove fetch state onsuccess fetchresult clientgetter objectcontainer introductionpuzzle mwot getxmltransformer importintroductionpuzzle asbucket getinputstream mpuzzlestore deleteoldestunsolvedpuzzles puzzle_pool_size downloadpuzzle getinserter getindex removefetch called when the node can t fetch a file or when there is a newer edition in our case called when there is no puzzle available public void on failure fetch exception e client getter state object container container if e get mode fetch exception cancelled logger debug this fetch cancelled state geturi return if e get mode fetch exception data not found this is the normal case there is no puzzle available of today because the inserter is offline and has not inserted any we do nothing here the identity stays in the fifo though so we do not try to fetch puzzzle from it again soon try logger debug this downloading puzzle failed state geturi e finally remove fetch state onfailure fetchexception clientgetter objectcontainer getmode fetchexception getmode fetchexception data_not_found removefetch called when a puzzle solution is successfully inserted public void on success base client putter state object container container logger debug this successful insert of puzzle solution state geturi try synchronized m wot get puzzle by requesturi requires this synchronized m puzzle store introduction puzzle puzzle m puzzle store get puzzle by solutionuri state geturi puzzle set inserted m puzzle store store and commit puzzle catch exception e logger error this error e finally remove insert state onsuccess baseclientputter objectcontainer mwot getpuzzlebyrequesturi mpuzzlestore introductionpuzzle mpuzzlestore getpuzzlebysolutionuri setinserted mpuzzlestore storeandcommit removeinsert calling when inserting a puzzle solution failed public void on failure insert exception e base client putter state object container container no synchronization because the worst thing which can happen is that we insert it again if e get mode insert exception cancelled logger debug this insert cancelled state geturi return try logger minor this insert of puzzle solution failed state geturi e finally remove insert state onfailure insertexception baseclientputter objectcontainer getmode insertexception removeinsert not needed functions from the client callback interface only called by inserts public void on fetchable base client putter state object container container clientcallback onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container only called by inserts public void on generateduri freeneturi uri base client putter state object container container onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container called when freenet async thinks that the request should be serialized to disk if it is a persistent request public void on major progress object container container ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer private long cooldown time void set cooldown time long time cooldown time time cooldowntime setcooldowntime cooldowntime public long add key key sendable get client object container container assert cooldown time 0 long remove time system current time millis cooldown time container activate key 5 persistent cooldown queue item persistent cooldown queue item new persistent cooldown queue item client key clone key remove time this container store persistent cooldown queue item return remove time sendableget objectcontainer cooldowntime removetime currenttimemillis cooldowntime persistentcooldownqueueitem persistentcooldownqueueitem persistentcooldownqueueitem clonekey removetime persistentcooldownqueueitem removetime public boolean remove key final key key final sendable get client final long time object container container boolean found false final string key as bytes hex util bytes to hex key get full key query query container query query constrain persistent cooldown queue item class query descend key as bytes constrain key as bytes the result from parent will be huge and client may be huge too don t bother with a join just check in the evaluation query descend client constrain client query descend parent constrain this evaluation eval new evaluation public void evaluate candidate candidate persistent cooldown queue item item persistent cooldown queue item candidate get object if item client client candidate include false return if item parent persistent cooldown queue this candidate include false return key k item key candidate object container activate k 5 if k equals key candidate include true else candidate include false candidate object container deactivate k 5 query constrain eval object set results query execute while results has next found true persistent cooldown queue item i persistent cooldown queue item results next i delete container return found removekey sendableget objectcontainer keyasbytes hexutil bytestohex getfullkey persistentcooldownqueueitem keyasbytes keyasbytes persistentcooldownqueueitem persistentcooldownqueueitem getobject persistentcooldownqueue objectcontainer objectcontainer objectset hasnext persistentcooldownqueueitem persistentcooldownqueueitem public void evaluate candidate candidate persistent cooldown queue item item persistent cooldown queue item candidate get object if item client client candidate include false return if item parent persistent cooldown queue this candidate include false return key k item key candidate object container activate k 5 if k equals key candidate include true else candidate include false candidate object container deactivate k 5 persistentcooldownqueueitem persistentcooldownqueueitem getobject persistentcooldownqueue objectcontainer objectcontainer public object remove key before final long now long dont care after millis object container container int max count will be called repeatedly until no more keys are returned so it doesn t matter very much if they re not in order this query returns bogus results cooldown items with times in the future object set results container query new predicate public boolean match persistent cooldown queue item persistent cooldown queue item if persistent cooldown queue item time now return false if persistent cooldown queue item parent persistent cooldown queue this return false return true lets re code it in soda long t start system current time millis query query container query query constrain persistent cooldown queue item class query descend time constrain long value of now smaller and query descend parent constrain this identity object set results query execute if results has next long t end system current time millis if t end t start 1000 logger error this query took t end t start else if logger should log logger minor this logger minor this query took t end t start array list v new array list math min max count results size while results has next v size max count persistent cooldown queue item i persistent cooldown queue item results next if i time now logger error this remove key before time now diff now i time continue if i parent this logger error this parent i parent but should be this continue container activate i key 5 if i client null container ext is stored i client logger normal this client has been removed but not the persistent cooldown queue item time i time for key i key else v add i key clone key i key remove from container i delete container if v is empty return v to array new key v size else query container query query descend time order ascending constrain long value of now dont care after millis smaller and query descend parent constrain this identity results query execute if results has next return persistent cooldown queue item results next time else return null else long t end system current time millis if t end t start 1000 logger error this query took t end t start else if logger should log logger minor this logger minor this query took t end t start return null removekeybefore dontcareaftermillis objectcontainer maxcount objectset persistentcooldownqueueitem persistentcooldownqueueitem persistentcooldownqueueitem persistentcooldownqueueitem persistentcooldownqueue tstart currenttimemillis persistentcooldownqueueitem valueof objectset hasnext tend currenttimemillis tend tstart tend tstart shouldlog tend tstart arraylist arraylist maxcount hasnext maxcount persistentcooldownqueueitem persistentcooldownqueueitem removekeybefore isstored clonekey removefrom isempty toarray orderascending valueof dontcareaftermillis hasnext persistentcooldownqueueitem tend currenttimemillis tend tstart tend tstart shouldlog tend tstart public long size object container container query query container query query constrain persistent cooldown queue item class query descend parent constrain this identity object set results query execute return results size objectcontainer persistentcooldownqueueitem objectset public usk manager node client core core high level simple client client core make client request starter update priority class client set max intermediate length f proxy toadlet max length client set max length f proxy toadlet max length background fetch context client get fetch context background fetch context follow redirects false real fetch context client get fetch context latest known good by clearusk new hash map usk long latest slot by clearusk new hash map usk long subscribers by clearusk new hash map usk usk callback fetchers byusk new hash map usk usk fetcher background fetchers by clearusk new hash map usk usk fetcher temporary background fetcherslru new lru hashtable usk usk fetcher executor core get executor uskmanager nodeclientcore highlevelsimpleclient makeclient requeststarter update_priority_class setmaxintermediatelength fproxytoadlet max_length setmaxlength fproxytoadlet max_length backgroundfetchcontext getfetchcontext backgroundfetchcontext followredirects realfetchcontext getfetchcontext latestknowngoodbyclearusk hashmap latestslotbyclearusk hashmap subscribersbyclearusk hashmap uskcallback fetchersbyusk hashmap uskfetcher backgroundfetchersbyclearusk hashmap uskfetcher temporarybackgroundfetcherslru lruhashtable uskfetcher getexecutor public void init object container container client context context this context context usk manager persistent init this container context objectcontainer clientcontext uskmanagerpersistent look up the latest known working version of the given usk return the latest known edition number or 1 public synchronized long lookup known good usk usk long l latest known good by clearusk get usk clear copy if l null return l long value else return 1 lookupknowngood latestknowngoodbyclearusk clearcopy longvalue look up the latest ssk slot whether the data it links to has been successfully fetched or not of the given usk return the latest known edition number or 1 public synchronized long lookup latest slot usk usk long l latest slot by clearusk get usk clear copy if l null return l long value else return 1 lookuplatestslot latestslotbyclearusk clearcopy longvalue public usk fetcher tag get fetcher usk usk fetch context ctx boolean keep last boolean persistent usk fetcher callback callback boolean own fetch context object container container client context context return usk fetcher tag create usk callback context nodedb handle persistent container ctx keep last 0 own fetch context uskfetchertag getfetcher fetchcontext keeplast uskfetchercallback ownfetchcontext objectcontainer clientcontext uskfetchertag nodedbhandle keeplast ownfetchcontext synchronized usk fetcher get fetcher usk usk fetch context ctx client requester requester boolean keep last data usk fetcher f fetchers byusk get usk if f null if f parent priority class requester priority class f ctx equals ctx f keep last data keep last data return f f new usk fetcher usk this ctx requester 3 false keep last data fetchers byusk put usk f return f uskfetcher getfetcher fetchcontext clientrequester keeplastdata uskfetcher fetchersbyusk priorityclass priorityclass keeplastdata keeplastdata uskfetcher keeplastdata fetchersbyusk public usk fetcher tag get fetcher for insert dont schedule usk usk short prio class usk fetcher callback cb request client client object container container client context context boolean persistent return get fetcher usk persistent new fetch context background fetch context fetch context identical mask false null background fetch context true client persistent cb true container context uskfetchertag getfetcherforinsertdontschedule prioclass uskfetchercallback requestclient objectcontainer clientcontext getfetcher fetchcontext backgroundfetchcontext fetchcontext identical_mask backgroundfetchcontext a non authoritative hint that a specific edition might exist at the moment we just fetch the block we do not fetch the contents and it is possible that usk fetcher s are also fetching the block fixme would it be more efficient to pass it along to a usk fetcher param usk param edition param context public void hint update usk usk long edition client context context if edition lookup latest slot usk return freeneturi uri usk copy edition geturi final client getter get new client getter new null client callback uri new fetch context background fetch context fetch context identical mask false null request starter update priority class usk manager this new null bucket null try get start null context catch fetch exception e ignore uskfetcher uskfetcher hintupdate clientcontext lookuplatestslot clientgetter clientgetter nullclientcallback fetchcontext backgroundfetchcontext fetchcontext identical_mask requeststarter update_priority_class uskmanager nullbucket fetchexception a non authoritative hint that a specific edition might exist at the moment we just fetch the block we do not fetch the contents and it is possible that usk fetcher s are also fetching the block fixme would it be more efficient to pass it along to a usk fetcher param context throws malformedurl exception if the uri passed in is not a usk public void hint update freeneturi uri client context context throws malformedurl exception if uri get suggested edition lookup latest slot usk create uri return final client getter get new client getter new null client callback uri new fetch context background fetch context fetch context identical mask false null request starter update priority class usk manager this new null bucket null try get start null context catch fetch exception e ignore uskfetcher uskfetcher malformedurlexception hintupdate clientcontext malformedurlexception getsuggestededition lookuplatestslot clientgetter clientgetter nullclientcallback fetchcontext backgroundfetchcontext fetchcontext identical_mask requeststarter update_priority_class uskmanager nullbucket fetchexception public void start temporary background fetcher usk usk client context context final fetch context fctx boolean prefetch content usk clear usk clear copy usk fetcher sched null vector usk fetcher to cancel null synchronized this java util iterator i background fetchers by clearusk key set iterator int x 0 while i has next system err println fetcher x i next x usk fetcher f temporary background fetcherslru get clear if f null f new usk fetcher usk this background fetch context new usk fetcher wrapper usk request starter update priority class this 3 false false sched f temporary background fetcherslru push clear f if prefetch content final long min lookup known good usk f add callback new usk fetcher callback public void on cancelled object container container client context context ok public void on failure object container container client context context ok public void on found edition long l usk key object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too if l min return freeneturi uri key copy l geturi final client getter get new client getter new null client callback uri new fetch context fctx fetch context identical mask false null request starter update priority class usk manager this new null bucket null try get start null context catch fetch exception e ignore public short get polling priority normal return request starter update priority class public short get polling priority progress return request starter update priority class temporary background fetcherslru push clear f while temporary background fetcherslru size node client core max backgroundusk fetchers usk fetcher fetcher temporary background fetcherslru pop value if fetcher has subscribers if to cancel null to cancel new vector usk fetcher 2 to cancel add fetcher else if logger should log logger minor this logger minor this allowing temporary background fetcher to continue as it has subscribers fetcher it will burn itself out anyway as it s a temp fetcher so no big harm here fetcher kill on lose subscribers if to cancel null for int i 0 i to cancel size i usk fetcher fetcher to cancel get i fetcher cancel null context if sched null sched schedule null context starttemporarybackgroundfetcher clientcontext fetchcontext prefetchcontent clearcopy uskfetcher uskfetcher tocancel backgroundfetchersbyclearusk keyset hasnext uskfetcher temporarybackgroundfetcherslru uskfetcher backgroundfetchcontext uskfetcherwrapper requeststarter update_priority_class temporarybackgroundfetcherslru prefetchcontent lookupknowngood addcallback uskfetchercallback oncancelled objectcontainer clientcontext onfailure objectcontainer clientcontext onfoundedition objectcontainer clientcontext newknowngood newslottoo clientgetter clientgetter nullclientcallback fetchcontext fetchcontext identical_mask requeststarter update_priority_class uskmanager nullbucket fetchexception getpollingprioritynormal requeststarter update_priority_class getpollingpriorityprogress requeststarter update_priority_class temporarybackgroundfetcherslru temporarybackgroundfetcherslru nodeclientcore maxbackgrounduskfetchers uskfetcher temporarybackgroundfetcherslru popvalue hassubscribers tocancel tocancel uskfetcher tocancel shouldlog killonlosesubscribers tocancel tocancel uskfetcher tocancel f add callback new usk fetcher callback public void on cancelled object container container client context context ok addcallback uskfetchercallback oncancelled objectcontainer clientcontext public void on failure object container container client context context ok onfailure objectcontainer clientcontext public void on found edition long l usk key object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too if l min return freeneturi uri key copy l geturi final client getter get new client getter new null client callback uri new fetch context fctx fetch context identical mask false null request starter update priority class usk manager this new null bucket null try get start null context catch fetch exception e ignore onfoundedition objectcontainer clientcontext newknowngood newslottoo clientgetter clientgetter nullclientcallback fetchcontext fetchcontext identical_mask requeststarter update_priority_class uskmanager nullbucket fetchexception public short get polling priority normal return request starter update priority class getpollingprioritynormal requeststarter update_priority_class public short get polling priority progress return request starter update priority class getpollingpriorityprogress requeststarter update_priority_class void update known good final usk origusk final long number final client context context boolean logminor logger should log logger minor this if logminor logger minor this updating origusk geturi number usk clear origusk clear copy final usk callback callbacks boolean new slot false synchronized this long l latest known good by clearusk get clear if logminor logger minor this old known good l if l null number l long value l long value of number latest known good by clearusk put clear l if logminor logger minor this put number else return if it s in known good it will also be in slot l latest slot by clearusk get clear if logminor logger minor this old slot l if l null number l long value l long value of number latest slot by clearusk put clear l if logminor logger minor this put number new slot true callbacks subscribers by clearusk get clear if callbacks null run off thread because of locking and because client callbacks may take some time final usk usk origusk copy number final boolean new slot too new slot for final usk callback callback callbacks context main executor execute new runnable public void run callback on found edition number usk null non persistent context false short 1 null true new slot too usk manager callback executor for callback updateknowngood clientcontext shouldlog clearcopy uskcallback newslot latestknowngoodbyclearusk longvalue valueof latestknowngoodbyclearusk knowngood latestslotbyclearusk longvalue valueof latestslotbyclearusk newslot subscribersbyclearusk newslottoo newslot uskcallback mainexecutor onfoundedition newslottoo uskmanager for final usk callback callback callbacks context main executor execute new runnable public void run callback on found edition number usk null non persistent context false short 1 null true new slot too uskcallback mainexecutor onfoundedition newslottoo void update slot final usk origusk final long number final client context context boolean logminor logger should log logger minor this if logminor logger minor this updating origusk geturi number usk clear origusk clear copy final usk callback callbacks synchronized this long l latest slot by clearusk get clear if logminor logger minor this old slot l if l null number l long value l long value of number latest slot by clearusk put clear l if logminor logger minor this put number else return callbacks subscribers by clearusk get clear if callbacks null run off thread because of locking and because client callbacks may take some time final usk usk origusk copy number for final usk callback callback callbacks context main executor execute new runnable public void run callback on found edition number usk null non persistent context false short 1 null false false usk manager callback executor for callback updateslot clientcontext shouldlog clearcopy uskcallback latestslotbyclearusk longvalue valueof latestslotbyclearusk subscribersbyclearusk uskcallback mainexecutor onfoundedition uskmanager for final usk callback callback callbacks context main executor execute new runnable public void run callback on found edition number usk null non persistent context false short 1 null false false uskcallback mainexecutor onfoundedition subscribe to a given usk callback will be notified when it is updated note that this does not imply that the usk will be checked on a regular basis unless run background fetch true public void subscribe usk origusk usk callback cb boolean run background fetch request client client if logger should log logger minor this logger minor this subscribing to origusk for cb if client persistent throw new unsupported operation exception usk manager subscriptions cannot be persistent usk fetcher sched null long ed origusk suggested edition if ed 0 logger error this subscribing to usk with negative edition number ed ed ed long cur ed cur ed lookup latest slot origusk long good ed good ed lookup known good origusk synchronized this usk clear origusk clear copy usk callback callbacks subscribers by clearusk get clear if callbacks null callbacks new usk callback 1 else for int i 0 i callbacks length i if callbacks i cb return usk callback new callbacks new usk callback callbacks length 1 system arraycopy callbacks 0 new callbacks 0 callbacks length callbacks new callbacks callbacks callbacks length 1 cb subscribers by clearusk put clear callbacks if run background fetch usk fetcher f background fetchers by clearusk get clear if f null f new usk fetcher origusk this background fetch context new usk fetcher wrapper origusk request starter update priority class client 10 true false sched f background fetchers by clearusk put clear f f add subscriber cb if good ed ed cb on found edition good ed origusk copy cur ed null context false short 1 null true cur ed ed else if cur ed ed cb on found edition cur ed origusk copy cur ed null context false short 1 null false false final usk fetcher fetcher sched if fetcher null executor execute new runnable public void run fetcher schedule null context usk manager schedule for fetcher runbackgroundfetch uskcallback runbackgroundfetch requestclient shouldlog unsupportedoperationexception uskmanager uskfetcher suggestededition cured cured lookuplatestslot gooded gooded lookupknowngood clearcopy uskcallback subscribersbyclearusk uskcallback uskcallback newcallbacks uskcallback newcallbacks newcallbacks subscribersbyclearusk runbackgroundfetch uskfetcher backgroundfetchersbyclearusk uskfetcher backgroundfetchcontext uskfetcherwrapper requeststarter update_priority_class backgroundfetchersbyclearusk addsubscriber gooded onfoundedition gooded cured cured cured onfoundedition cured cured uskfetcher uskmanager if fetcher null executor execute new runnable public void run fetcher schedule null context public void unsubscribe usk origusk usk callback cb usk fetcher to cancel null usk fetcher to cancel alt null synchronized this usk clear origusk clear copy usk callback callbacks subscribers by clearusk get clear if callbacks null maybe we should throw something shall we allow multiple unsubscriptions logger error this the callback is null it has been already unsubscribed hasn t it new exception debug return int j 0 for int i 0 i callbacks length i usk callback c callbacks i if c null c cb callbacks j c usk callback new callbacks new usk callback j system arraycopy callbacks 0 new callbacks 0 j if new callbacks length 0 subscribers by clearusk put clear callbacks else subscribers by clearusk remove clear fetchers byusk remove origusk usk fetcher f background fetchers by clearusk get clear if f null f remove subscriber cb context if f has subscribers to cancel f background fetchers by clearusk remove clear f temporary background fetcherslru get clear if f null f remove callback cb if f has callbacks if to cancel null to cancel alt f logger error this subscribed in both background fetchers and temporary background fetchers cb for origusk else to cancel f temporary background fetcherslru remove key clear if to cancel null to cancel cancel null context if to cancel alt null to cancel alt cancel null context uskcallback uskfetcher tocancel uskfetcher tocancelalt clearcopy uskcallback subscribersbyclearusk uskcallback uskcallback newcallbacks uskcallback newcallbacks newcallbacks subscribersbyclearusk subscribersbyclearusk fetchersbyusk uskfetcher backgroundfetchersbyclearusk removesubscriber hassubscribers tocancel backgroundfetchersbyclearusk temporarybackgroundfetcherslru removecallback hascallbacks tocancel tocancelalt backgroundfetchers temporarybackgroundfetchers tocancel temporarybackgroundfetcherslru removekey tocancel tocancel tocancelalt tocancelalt subscribe to a usk when it is updated the content will be fetched subject to the limits in fctx and returned to the callback param origusk the usk to poll param cb callback called when we have downloaded a new key param run background fetch if true start a background fetcher for the key which will run forever until we unsubscribe param fctx fetcher context for actually fetching the keys not used by the usk polling return public usk retriever subscribe content usk origusk usk retriever callback cb boolean run background fetch fetch context fctx short prio request client client usk retriever ret new usk retriever fctx prio client cb origusk subscribe origusk ret run background fetch client return ret runbackgroundfetch uskretriever subscribecontent uskretrievercallback runbackgroundfetch fetchcontext requestclient uskretriever uskretriever runbackgroundfetch public void unsubscribe content usk origusk usk retriever ret boolean run background fetch unsubscribe origusk ret unsubscribecontent uskretriever runbackgroundfetch remove do not synchronize debugging only the result of that method will be displayed on the statistic toadlet it will help catching 1147 afterwards it should be removed it s not usefull return the number of fetchers started by usk manager public int get fetcher byusk size return fetchers byusk size uskmanager getfetcherbyusksize fetchersbyusk the result of that method will be displayed on the statistic toadlet it will help catching 1147 afterwards it should be removed it s not usefull return the number of background fetchers started by usk manager public int get background fetcher byusk size return background fetchers by clearusk size backgroundfetchers uskmanager getbackgroundfetcherbyusksize backgroundfetchersbyclearusk the result of that method will be displayed on the statistic toadlet it will help catching 1147 afterwards it should be removed it s not usefull return the size of temporary background fetcherslru public int get temporary background fetcherslru return temporary background fetcherslru size temporarybackgroundfetcherslru gettemporarybackgroundfetcherslru temporarybackgroundfetcherslru public void on finished usk fetcher fetcher usk orig fetcher get originalusk usk clear orig clear copy synchronized this if background fetchers by clearusk get clear fetcher background fetchers by clearusk remove clear this shouldn t happen it s a sanity check the only way we get cancelled is from usk manager which removes us before calling cancel logger error this on cancelled for fetcher was still registered how did this happen new exception debug if temporary background fetcherslru get clear fetcher temporary background fetcherslru remove key clear if fetchers byusk get orig fetcher fetchers byusk remove clear onfinished uskfetcher getoriginalusk clearcopy backgroundfetchersbyclearusk backgroundfetchersbyclearusk uskmanager oncancelled temporarybackgroundfetcherslru temporarybackgroundfetcherslru removekey fetchersbyusk fetchersbyusk public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception override protected void set up throws exception super set up a new identity uria a true b new identity urib b true trust trust new trust a b byte 100 test ext object container db m wot getdb db store a 5 db store b 5 db store trust db commit setup setup extobjectcontainer mwot public void test trust throws duplicate trust exception not trusted exception trust trust m wot get trust a b assert true trust get truster a assert true trust get trustee b assert true trust get value 100 assert equals test trust get comment testtrust duplicatetrustexception nottrustedexception mwot gettrust asserttrue gettruster asserttrue gettrustee asserttrue getvalue assertequals getcomment public void test trust persistence throws malformedurl exception unknown identity exception duplicate trust exception not trusted exception m wot terminate m wot null system gc system run finalization m wot new wot get database filename a m wot get identity byuri uria b m wot get identity byuri urib trust trust m wot get trust a b assert true trust get truster a assert true trust get trustee b assert true trust get value 100 assert equals test trust get comment testtrustpersistence malformedurlexception unknownidentityexception duplicatetrustexception nottrustedexception mwot mwot runfinalization mwot getdatabasefilename mwot getidentitybyuri mwot getidentitybyuri mwot gettrust asserttrue gettruster asserttrue gettrustee asserttrue getvalue assertequals getcomment public class jsql arithmetic exception extends jsql runtime exception constructor of exception public jsql arithmetic exception string msg super msg null null jsqlarithmeticexception jsqlruntimeexception jsqlarithmeticexception logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public f proxy fetch in progress f proxy fetch tracker tracker freeneturi key long max size2 long identifier client context context fetch context fctx request client rc this tracker tracker this uri key this max size max size2 this time started system current time millis this identifier identifier fctx new fetch context fctx fetch context identical mask false null fctx max output length fctx max temp length max size fctx event producer add event listener this waiters new array list f proxy fetch waiter results new array list f proxy fetch result getter new client getter this uri fctx f proxy toadlet priority rc null null fproxyfetchinprogress fproxyfetchtracker maxsize2 clientcontext fetchcontext requestclient maxsize maxsize2 timestarted currenttimemillis fetchcontext fetchcontext identical_mask maxoutputlength maxtemplength maxsize eventproducer addeventlistener arraylist fproxyfetchwaiter arraylist fproxyfetchresult clientgetter fproxytoadlet public synchronized f proxy fetch waiter get waiter last touched system current time millis f proxy fetch waiter waiter new f proxy fetch waiter this waiters add waiter return waiter fproxyfetchwaiter getwaiter lasttouched currenttimemillis fproxyfetchwaiter fproxyfetchwaiter synchronized f proxy fetch result inner get result boolean has waited last touched system current time millis f proxy fetch result res if data null res new f proxy fetch result this data mime type time started gone to network geteta has waited else res new f proxy fetch result this mime type size time started gone to network total blocks required blocks fetched blocks failed blocks fatally failed blocks finalized blocks failed geteta has waited results add res return res fproxyfetchresult innergetresult haswaited lasttouched currenttimemillis fproxyfetchresult fproxyfetchresult mimetype timestarted gonetonetwork haswaited fproxyfetchresult mimetype timestarted gonetonetwork totalblocks requiredblocks fetchedblocks failedblocks fatallyfailedblocks finalizedblocks haswaited public void start client context context throws fetch exception try context start getter catch fetch exception e synchronized this this failed e this finished true clientcontext fetchexception fetchexception public void on remove event producer object container container impossible onremoveeventproducer objectcontainer public void receive client event ce object container maybe container client context context if ce instanceof splitfile progress event splitfile progress event split splitfile progress event ce synchronized this int old req required blocks fetched blocks failed blocks fatally failed blocks total blocks split total blocks fetched blocks split succeed blocks required blocks split min successful blocks failed blocks split failed blocks fatally failed blocks split fatally failed blocks finalized blocks split finalized total int req required blocks fetched blocks failed blocks fatally failed blocks if req 1024 old req 1024 return else if ce instanceof sending to network event synchronized this if gone to network return gone to network true fetched blocks pre network fetched blocks else if ce instanceof expectedmime event synchronized this this mime type expectedmime event ce expectedmime type else if ce instanceof expected file size event synchronized this this size expected file size event ce expected size else return wake waiters false clientevent objectcontainer maybecontainer clientcontext splitfileprogressevent splitfileprogressevent splitfileprogressevent oldreq requiredblocks fetchedblocks failedblocks fatallyfailedblocks totalblocks totalblocks fetchedblocks succeedblocks requiredblocks minsuccessfulblocks failedblocks failedblocks fatallyfailedblocks fatallyfailedblocks finalizedblocks finalizedtotal requiredblocks fetchedblocks failedblocks fatallyfailedblocks oldreq sendingtonetworkevent gonetonetwork gonetonetwork fetchedblocksprenetwork fetchedblocks expectedmimeevent mimetype expectedmimeevent expectedmimetype expectedfilesizeevent expectedfilesizeevent expectedsize wakewaiters private void wake waiters boolean finished f proxy fetch waiter waiting synchronized this waiting waiters to array new f proxy fetch waiter waiters size for f proxy fetch waiter w waiting w wake up finished wakewaiters fproxyfetchwaiter toarray fproxyfetchwaiter fproxyfetchwaiter wakeup public void on failure fetch exception e client getter state object container container synchronized this this failed e this finished true wake waiters true onfailure fetchexception clientgetter objectcontainer wakewaiters public void on failure insert exception e base client putter state object container container impossible onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container impossible onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container impossible ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success fetch result result client getter state object container container synchronized this this data result as bucket this mime type result get mime type this finished true wake waiters true onsuccess fetchresult clientgetter objectcontainer asbucket mimetype getmimetype wakewaiters public void on success base client putter state object container container ignore onsuccess baseclientputter objectcontainer public boolean has data return data null hasdata public boolean finished return finished public void close f proxy fetch waiter waiter synchronized this waiters remove waiter if results is empty return if waiters is empty return tracker queue cancel this fproxyfetchwaiter isempty isempty queuecancel caller should take the lock on f proxy toadlet fetchers then call this function if it returns true then finish the cancel outside the lock public synchronized boolean can cancel if waiters is empty return false if results is empty return false if last touched lifetime system current time millis if logminor logger minor this not able to cancel for this uri max size return false if logminor logger minor this can cancel for this uri max size return true fproxytoadlet cancancel isempty isempty lasttouched currenttimemillis maxsize maxsize public void finish cancel if logminor logger minor this finishing cancel for this uri max size if data null try data free catch throwable t ensure we get to the next bit logger error this failed to free t t try getter cancel catch throwable t ensure we get to the next bit logger error this failed to cancel t t finishcancel maxsize public void close f proxy fetch result result synchronized this results remove result if results is empty return if waiters is empty return tracker queue cancel this fproxyfetchresult isempty isempty queuecancel public synchronized long geteta if gone to network return 1 if required blocks 0 return 1 if fetched blocks required blocks return 1 if fetched blocks fetched blocks pre network 5 return 1 return system current time millis time started required blocks fetched blocks pre network fetched blocks fetched blocks pre network gonetonetwork requiredblocks fetchedblocks requiredblocks fetchedblocks fetchedblocksprenetwork currenttimemillis timestarted requiredblocks fetchedblocksprenetwork fetchedblocks fetchedblocksprenetwork public synchronized boolean not finished or fatally finished if data null failed null return true if failed null failed is fatal return true if failed null has notified failure has notified failure true return true return false notfinishedorfatallyfinished isfatal hasnotifiedfailure hasnotifiedfailure public synchronized boolean has notified failure return true hasnotifiedfailure private final node node public meaningful node name user alert node n super true null null null null user alert warning true l10n get string user alert hide false null this node n meaningfulnodenameuseralert useralert getstring useralert override public string get title return l10n no node nick title gettitle nonodenicktitle private string l10n string key return l10n get string meaningful node name user alert key getstring meaningfulnodenameuseralert override public string get text return l10n no node nick gettext nonodenick override public string get short text return l10n no node nick short getshorttext nonodenickshort override public html node gethtml text sub config sc node config get node option o sc get option name html node alert node new html node div html node text node alert node add child div text node add child l10n no node nick html node form node alert node add child form new string action method new string config post form node add child input new string type name value new string hidden form password node client core form password html node list node form node add child ul class config html node item node list node add child li item node add child span new string class title style new string configshortdesc l10n get string config toadlet default is new string default new string o get default cursor help add child l10n gethtml node o get short desc item node add child input new string type class alt name value new string text config o get short desc node name o get value string item node add child span class configlongdesc add child l10n gethtml node o get long desc form node add child input new string type value new string submit l10n get string user alert apply form node add child input new string type value new string reset l10n get string user alert reset return alert node htmlnode gethtmltext subconfig getoption htmlnode alertnode htmlnode htmlnode textnode alertnode addchild textnode addchild nonodenick htmlnode formnode alertnode addchild formnode addchild formpassword clientcore formpassword htmlnode listnode formnode addchild htmlnode itemnode listnode addchild itemnode addchild getstring configtoadlet defaultis getdefault addchild gethtmlnode getshortdesc itemnode addchild getshortdesc getvaluestring itemnode addchild addchild gethtmlnode getlongdesc formnode addchild getstring useralert formnode addchild getstring useralert alertnode override public boolean is valid return node peers any darknet peers isvalid anydarknetpeers public class outline filter extends binary filter public outline filter new color 0xffffffff outlinefilter binaryfilter outlinefilter newcolor override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int pixel in pixels y width x if black function is black pixel int neighbours 0 for int dy 1 dy 1 dy int iy y dy int ioffset if 0 iy iy height ioffset iy width for int dx 1 dx 1 dx int ix x dx if dy 0 dx 0 0 ix ix width int rgb in pixels ioffset ix if black function is black rgb neighbours else neighbours if neighbours 9 pixel new color out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels inpixels blackfunction isblack inpixels blackfunction isblack newcolor outpixels outpixels override public string to string return binary outline tostring public void object on activate object container container only activate the arrays container activate waiting for 1 container activate waiting for block set 1 container activate waiting for fetchable 1 objectonactivate objectcontainer waitingfor waitingforblockset waitingforfetchable public multi put completion callback put completion callback cb base client putter parent object token boolean persistent this cb cb waiting for new vector client put state waiting for block set new vector client put state waiting for fetchable new vector client put state this parent parent this token token finished false this persistent persistent multiputcompletioncallback putcompletioncallback baseclientputter waitingfor clientputstate waitingforblockset clientputstate waitingforfetchable clientputstate public void on success client put state state object container container client context context on block set finished state container context on fetchable state container if persistent container activate waiting for 2 boolean complete true synchronized this if finished logger error this already finished but got on success for state on this return waiting for remove state waiting for block set remove state waiting for fetchable remove state if waiting for is empty started if persistent container ext store waiting for 1 complete false if state generator generator null if persistent container store this if persistent container ext store waiting for 2 container ext store waiting for block set 2 container ext store waiting for fetchable 2 state remove from container context if complete logger minor this completing complete null container context onsuccess clientputstate objectcontainer clientcontext onblocksetfinished onfetchable waitingfor onsuccess waitingfor waitingforblockset waitingforfetchable waitingfor isempty waitingfor waitingfor waitingforblockset waitingforfetchable removefrom public void on failure insert exception e client put state state object container container client context context boolean complete true synchronized this if finished logger error this already finished but got on failure for state on this return waiting for remove state waiting for block set remove state waiting for fetchable remove state if waiting for is empty started if this e null if persistent container activate this e 10 this e remove from container this e e if persistent container store this complete false if state generator generator null if persistent container store this if persistent container ext store waiting for 2 container ext store waiting for block set 2 container ext store waiting for fetchable 2 state remove from container context if complete complete e container context onfailure insertexception clientputstate objectcontainer clientcontext onfailure waitingfor waitingforblockset waitingforfetchable waitingfor isempty removefrom waitingfor waitingforblockset waitingforfetchable removefrom private void complete insert exception e object container container client context context synchronized this if finished return finished true if e null this e null this e e if persistent container activate this e 10 if e get mode insert exception cancelled cancelled is okay ignore it we cancel after failure sometimes ignore the new failure mode use the old one e this e if persistent e e clone since we will remove it we can t pass it on else delete the old failure mode use the new one this e remove from container this e e if e null e this e if persistent e null container activate e 10 e e clone since we will remove it we can t pass it on if persistent container store this container activate cb 1 if e null cb on failure e this container context else cb on success this container context insertexception objectcontainer clientcontext getmode insertexception removefrom onfailure onsuccess public synchronized void adduri generator client put state ps object container container add ps container generator ps if persistent container store this addurigenerator clientputstate objectcontainer public synchronized void add client put state ps object container container if finished return waiting for add ps waiting for block set add ps waiting for fetchable add ps if persistent container store ps container ext store waiting for 2 container ext store waiting for block set 2 container ext store waiting for fetchable 2 clientputstate objectcontainer waitingfor waitingforblockset waitingforfetchable waitingfor waitingforblockset waitingforfetchable public void arm object container container client context context boolean all done boolean all got blocks synchronized this started true all done waiting for is empty all got blocks waiting for block set is empty if persistent container store this container activate cb 1 if all got blocks cb on block set finished this container context if all done complete e container context objectcontainer clientcontext alldone allgotblocks alldone waitingfor isempty allgotblocks waitingforblockset isempty allgotblocks onblocksetfinished alldone public base client putter get parent return parent baseclientputter getparent public void on encode base client key key client put state state object container container client context context synchronized this if state generator return if persistent container activate cb 1 cb on encode key this container context onencode baseclientkey clientputstate objectcontainer clientcontext onencode public void cancel object container container client context context client put state states new client put state waiting for size synchronized this states waiting for to array states boolean logdebug logger should log logger debug this for int i 0 i states length i if persistent container activate states i 1 if logdebug logger minor this cancelling state i of states length states i states i cancel container context objectcontainer clientcontext clientputstate clientputstate waitingfor waitingfor toarray shouldlog public synchronized void on transition client put state old state client put state new state object container container if generator old state generator new state if old state new state return for int i 0 i waiting for size i if waiting for get i old state waiting for set i new state container ext store waiting for 2 for int i 0 i waiting for block set size i if waiting for block set get i old state waiting for block set set i new state container ext store waiting for 2 for int i 0 i waiting for fetchable size i if waiting for fetchable get i old state waiting for fetchable set i new state container ext store waiting for 2 if persistent container store this ontransition clientputstate oldstate clientputstate newstate objectcontainer oldstate newstate oldstate newstate waitingfor waitingfor oldstate waitingfor newstate waitingfor waitingforblockset waitingforblockset oldstate waitingforblockset newstate waitingfor waitingforfetchable waitingforfetchable oldstate waitingforfetchable newstate waitingfor public synchronized void on metadata metadata m client put state state object container container client context context if persistent container activate cb 1 if generator state cb on metadata m this container context else logger error this got metadata for state onmetadata clientputstate objectcontainer clientcontext onmetadata public void on block set finished client put state state object container container client context context if persistent container activate waiting for block set 2 synchronized this this waiting for block set remove state if persistent container ext store waiting for block set 2 if started return if waiting for block set is empty return if persistent container activate cb 1 cb on block set finished this container context onblocksetfinished clientputstate objectcontainer clientcontext waitingforblockset waitingforblockset waitingforblockset waitingforblockset isempty onblocksetfinished public void schedule object container container client context context throws insert exception do nothing objectcontainer clientcontext insertexception public object get token return token gettoken public void on fetchable client put state state object container container if persistent container activate waiting for fetchable 2 synchronized this this waiting for fetchable remove state if persistent container ext store waiting for fetchable 2 if started return if waiting for fetchable is empty return if persistent container activate cb 1 cb on fetchable this container onfetchable clientputstate objectcontainer waitingforfetchable waitingforfetchable waitingforfetchable waitingforfetchable isempty onfetchable public void remove from object container container client context context container activate waiting for 2 container activate waiting for block set 2 container activate waiting for fetchable 2 should have been cleared by now if waiting for is empty logger error this waiting for not empty in remove from on this waiting for if waiting for block set is empty logger error this waiting for block set not empty in remove from on this waiting for if waiting for fetchable is empty logger error this waiting for fetchable not empty in remove from on this waiting for container delete waiting for container delete waiting for block set container delete waiting for fetchable cb is at a higher level we don t remove that it removes itself generator is just a reference to one of the waiting for s parent removes itself if e null container activate e 5 e remove from container whoever set the token is responsible for removing it container delete this removefrom objectcontainer clientcontext waitingfor waitingforblockset waitingforfetchable waitingfor isempty waitingfor removefrom waitingfor waitingforblockset isempty waitingforblockset removefrom waitingfor waitingforfetchable isempty waitingforfetchable removefrom waitingfor waitingfor waitingforblockset waitingforfetchable waitingfor removefrom public final class average composite extends rgb composite public average composite float alpha super alpha averagecomposite rgbcomposite averagecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr 2 dog dig sg 2 dob dib sb 2 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac compare i th component of two objects param m1 first object param m2 second object param i component index return left undefined if value of i th component of m1 is null and value of i th component of m2 is not null right undefined if value of i th component of m1 is not null and value of i th component of m2 is null eq if both values are null otherwise lt eq or gt depending on result of their comparison left_undefined right_undefined get number of dimensions return number of dimensions create clone of the specified object contining copy of the specified field param obj original object param i component index return clone of the object public abstract t clone field t obj int i protected multidimensional comparator storage storage super storage clonefield multidimensionalcomparator protected multidimensional comparator multidimensionalcomparator public fcp server string ip to bind to string allowed hosts string allowed hosts full access int port node node node client core core boolean persistent downloads enabled string persistent downloads dir boolean is enabled boolean assumedda download allowed boolean assumedda upload allowed object container container throws io exception invalid config value exception this bind to ip to bind to this allowed hosts allowed hosts this allowed hosts full access new allowed hosts allowed hosts full access this port port this enabled is enabled this enable persistent downloads persistent downloads enabled set persistent downloads file new file persistent downloads dir this node node this core core this assume downloaddda is allowed assumedda download allowed this assume uploaddda is allowed assumedda upload allowed reboot clients by name new weak hash map string fcp client this one is only used to get the default settings individual fcp conns will make their own high level simple client client core make client short 0 default fetch context client get fetch context default insert context client get insert context false global reboot client new fcp client global queue null true null client request persist reboot null null logminor logger should log logger minor this persistent root fcp persistent root create node nodedb handle container global forever client persistent root global forever client if enabled enable persistent downloads logger error this persistent downloads enabled attempting to migrate old persistent downloads to database logger error this note that we will not write to downloads dat gz we will read from it and rename it if migration is successful load persistent requests container else logger error this not loading persistent requests enabled enabled enable persistent downloads enable persistent downloads fcpserver iptobindto allowedhosts allowedhostsfullaccess nodeclientcore persistentdownloadsenabled persistentdownloadsdir isenabled assumeddadownloadallowed assumeddauploadallowed objectcontainer ioexception invalidconfigvalueexception bindto iptobindto allowedhosts allowedhosts allowedhostsfullaccess allowedhosts allowedhostsfullaccess isenabled enablepersistentdownloads persistentdownloadsenabled setpersistentdownloadsfile persistentdownloadsdir assumedownloadddaisallowed assumeddadownloadallowed assumeuploadddaisallowed assumeddauploadallowed rebootclientsbyname weakhashmap fcpclient highlevelsimpleclient makeclient defaultfetchcontext getfetchcontext defaultinsertcontext getinsertcontext globalrebootclient fcpclient clientrequest persist_reboot shouldlog persistentroot fcppersistentroot nodedbhandle globalforeverclient persistentroot globalforeverclient enablepersistentdownloads loadpersistentrequests enablepersistentdownloads private void maybe get network interface if this network interface null return network interface temp network interface null try if ssl temp network interface ssl network interface create port bind to allowed hosts node executor true else temp network interface network interface create port bind to allowed hosts node executor true catch io exception be logger error this couldn t bind to fcp port bind to port fcp server not started be system out println couldn t bind to fcp port bind to port fcp server not started this network interface temp network interface maybegetnetworkinterface networkinterface networkinterface tempnetworkinterface tempnetworkinterface sslnetworkinterface bindto allowedhosts tempnetworkinterface networkinterface bindto allowedhosts ioexception bindto bindto networkinterface tempnetworkinterface public void maybe start if this enabled maybe get network interface logger normal this starting fcp server on bind to port system out println starting fcp server on bind to port if this network interface null thread t new thread this fcp server t set daemon true t start else logger normal this not starting fcp server as it s disabled system out println not starting fcp server as it s disabled this network interface null maybestart maybegetnetworkinterface bindto bindto networkinterface setdaemon networkinterface public void run freenet support logger os thread logpid this while true try real run catch io exception e if logminor logger minor this caught e e catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t if wrapper manager has shutdown hook been triggered return try thread sleep 2000 catch interrupted exception e osthread realrun ioexception outofmemoryerror oomhandler wrappermanager hasshutdownhookbeentriggered interruptedexception private void real run throws io exception if node is has started return accept a connection socket s network interface accept fcp connection handler ch new fcp connection handler s this ch start realrun ioexception ishasstarted networkinterface fcpconnectionhandler fcpconnectionhandler private final node client core node fcp port number callback node client core node this node node nodeclientcore fcpportnumbercallback nodeclientcore override public integer get return node getfcp server port getfcpserver override public void set integer val throws invalid config value exception if get equals val throw new invalid config value exception cannot change fcp port number on the fly invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly final node client core node fcp enabled callback node client core node this node node nodeclientcore fcpenabledcallback nodeclientcore override public boolean get return node getfcp server enabled getfcpserver todo allow it override public void set boolean val throws invalid config value exception if get equals val throw new invalid config value exception l10n cannot start or stop on the fly invalidconfigvalueexception invalidconfigvalueexception cannotstartorstoponthefly override public boolean is read only return true isreadonly static class fcpssl callback extends boolean callback override public boolean get return ssl fcpsslcallback booleancallback override public void set boolean val throws invalid config value exception if get equals val return if ssl available throw new invalid config value exception enable ssl support before use ssl with fcp ssl val throw new invalid config value exception cannot change ssl on the fly please restart freenet invalidconfigvalueexception invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly final node client core node fcp bindto callback node client core node this node node nodeclientcore fcpbindtocallback nodeclientcore override public string get return node getfcp server bind to getfcpserver bindto override public void set string val throws invalid config value exception if val equals get try node getfcp server network interface set bind to val true node getfcp server bind to val catch io exception e this is an advanced option for reasons of reducing clutter but it is expected to be used by regular users not devs so we translate the error messages throw new invalid config value exception l10n could not change bind to error e get localized message invalidconfigvalueexception getfcpserver networkinterface setbindto getfcpserver bindto ioexception invalidconfigvalueexception couldnotchangebindto getlocalizedmessage private final node client core node public fcp allowed hosts callback node client core node this node node nodeclientcore fcpallowedhostscallback nodeclientcore override public string get fcp server server node getfcp server if server null return network interface default bind to network interface net iface server network interface return net iface null network interface default bind to net iface get allowed hosts fcpserver getfcpserver networkinterface default_bind_to networkinterface netiface networkinterface netiface networkinterface default_bind_to netiface getallowedhosts override public void set string val if val equals get node getfcp server network interface set allowed hosts val getfcpserver networkinterface setallowedhosts boolean enabled override public boolean get return enabled override public void set boolean set throws invalid config value exception this option will be removed completely soon so there is little point in translating it fixme remove if set boolean value enabled throw new invalid config value exception cannot disable enable persistent download loading support on the fly invalidconfigvalueexception booleanvalue invalidconfigvalueexception private final node client core node public fcp allowed hosts full access callback node client core node this node node nodeclientcore fcpallowedhostsfullaccesscallback nodeclientcore override public string get return node getfcp server allowed hosts full access get allowed hosts getfcpserver allowedhostsfullaccess getallowedhosts override public void set string val if val equals get node getfcp server allowed hosts full access set allowed hosts val getfcpserver allowedhostsfullaccess setallowedhosts fcp server server override public string get return server persistent downloads file to string fcpserver persistentdownloadsfile tostring override public void set string val throws invalid config value exception file f new file val if f equals server persistent downloads file return server set persistent downloads file f invalidconfigvalueexception persistentdownloadsfile setpersistentdownloadsfile fcp server server override public boolean get return server assume downloaddda is allowed fcpserver assumedownloadddaisallowed override public void set boolean val throws invalid config value exception if get equals val return server assume downloaddda is allowed val invalidconfigvalueexception assumedownloadddaisallowed fcp server server override public boolean get return server assume uploaddda is allowed fcpserver assumeuploadddaisallowed override public void set boolean val throws invalid config value exception if get equals val return server assume uploaddda is allowed val invalidconfigvalueexception assumeuploadddaisallowed public static fcp server maybe create node node node client core core config config object container container throws io exception invalid config value exception sub config fcp config new sub config fcp config short sort order 0 fcp config register enabled true sort order true false fcp server is enabled fcp server is enabled long new fcp enabled callback core fcp config register ssl false sort order true true fcp server ssl fcp server ssl long new fcpssl callback fcp config register port fcp server default fcp port anagram of 1984 and 1000 up from old number 2 true true fcp server port number fcp server port number long new fcp port number callback core false fcp config register bind to network interface default bind to sort order true true fcp server bind to fcp server bind to long new fcp bindto callback core fcp config register allowed hosts network interface default bind to sort order true true fcp server allowed hosts fcp server allowed hosts long new fcp allowed hosts callback core fcp config register allowed hosts full access network interface default bind to sort order true true fcp server allowed hosts full access fcp server allowed hosts full access long new fcp allowed hosts full access callback core persistent downloads file callback cb2 persistent downloads enabled callback enabledcb new persistent downloads enabled callback fcp config register persistent downloads enabled true sort order true true fcp server enable persistent download fcp server enable persistent download long enabledcb fcp config register persistent downloads file downloads dat sort order true false fcp server filename to storep data fcp server filename to storep data long cb2 new persistent downloads file callback fcp config register persistent downloads interval 5 60 1000 sort order true false fcp server interval between writes fcp server interval between writes long int callback null false string persistent downloads dir fcp config get string persistent downloads file boolean persistent downloads enabled fcp config get boolean persistent downloads enabled enabledcb enabled persistent downloads enabled assumedda download is allowed callback cb4 assumedda upload is allowed callback cb5 fcp config register assume downloaddda is allowed false sort order true false fcp server assume downloaddda is allowed fcp server assume downloaddda is allowed long cb4 new assumedda download is allowed callback fcp config register assume uploaddda is allowed false sort order true false fcp server assume uploaddda is allowed fcp server assume uploaddda is allowed long cb5 new assumedda upload is allowed callback if ssl available ssl fcp config get boolean ssl fcp server fcp new fcp server fcp config get string bind to fcp config get string allowed hosts fcp config get string allowed hosts full access fcp config get int port node core persistent downloads enabled persistent downloads dir fcp config get boolean enabled fcp config get boolean assume downloaddda is allowed fcp config get boolean assume uploaddda is allowed container if fcp null cb2 server fcp cb4 server fcp cb5 server fcp fcp config finished initialization return fcp fcpserver maybecreate nodeclientcore objectcontainer ioexception invalidconfigvalueexception subconfig fcpconfig subconfig sortorder fcpconfig sortorder fcpserver isenabled fcpserver isenabledlong fcpenabledcallback fcpconfig sortorder fcpserver fcpserver ssllong fcpsslcallback fcpconfig fcpserver default_fcp_port fcpserver portnumber fcpserver portnumberlong fcpportnumbercallback fcpconfig bindto networkinterface default_bind_to sortorder fcpserver bindto fcpserver bindtolong fcpbindtocallback fcpconfig allowedhosts networkinterface default_bind_to sortorder fcpserver allowedhosts fcpserver allowedhostslong fcpallowedhostscallback fcpconfig allowedhostsfullaccess networkinterface default_bind_to sortorder fcpserver allowedhostsfullaccess fcpserver allowedhostsfullaccesslong fcpallowedhostsfullaccesscallback persistentdownloadsfilecallback persistentdownloadsenabledcallback persistentdownloadsenabledcallback fcpconfig persistentdownloadsenabled sortorder fcpserver enablepersistentdownload fcpserver enablepersistentdownloadlong fcpconfig persistentdownloadsfile sortorder fcpserver filenametostorepdata fcpserver filenametostorepdatalong persistentdownloadsfilecallback fcpconfig persistentdownloadsinterval sortorder fcpserver intervalbetweenwrites fcpserver intervalbetweenwriteslong intcallback persistentdownloadsdir fcpconfig getstring persistentdownloadsfile persistentdownloadsenabled fcpconfig getboolean persistentdownloadsenabled persistentdownloadsenabled assumeddadownloadisallowedcallback assumeddauploadisallowedcallback fcpconfig assumedownloadddaisallowed sortorder fcpserver assumedownloadddaisallowed fcpserver assumedownloadddaisallowedlong assumeddadownloadisallowedcallback fcpconfig assumeuploadddaisallowed sortorder fcpserver assumeuploadddaisallowed fcpserver assumeuploadddaisallowedlong assumeddauploadisallowedcallback fcpconfig getboolean fcpserver fcpserver fcpconfig getstring bindto fcpconfig getstring allowedhosts fcpconfig getstring allowedhostsfullaccess fcpconfig getint persistentdownloadsenabled persistentdownloadsdir fcpconfig getboolean fcpconfig getboolean assumedownloadddaisallowed fcpconfig getboolean assumeuploadddaisallowed fcpconfig finishedinitialization public void set persistent downloads file file f throws invalid config value exception synchronized persistence sync check file f file temp new file f get path tmp check file temp else is ok persistent downloads file f persistent downloads temp file temp setpersistentdownloadsfile invalidconfigvalueexception persistencesync checkfile getpath checkfile persistentdownloadsfile persistentdownloadstempfile private void check file file f throws invalid config value exception if f is directory throw new invalid config value exception l10n downloads file is directory if f is file f can read f can write throw new invalid config value exception l10n downloads file unreadable file parent f get parent file if parent null parent exists throw new invalid config value exception l10n downloads file parent does not exist if f exists try if f create new file if f exists if f can read f can write throw new invalid config value exception l10n downloads file exists cannot read or write else ok else throw new invalid config value exception l10n downloads file does not exist cannot create else if f can read f can write throw new invalid config value exception l10n downloads file can create cannot read or write catch io exception e throw new invalid config value exception l10n downloads file does not exist cannot create e get localized message finally must be deleted otherwise we will read from it and ignore the temp file lose the queue f delete checkfile invalidconfigvalueexception isdirectory invalidconfigvalueexception downloadsfileisdirectory isfile canread canwrite invalidconfigvalueexception downloadsfileunreadable getparentfile invalidconfigvalueexception downloadsfileparentdoesnotexist createnewfile canread canwrite invalidconfigvalueexception downloadsfileexistscannotreadorwrite invalidconfigvalueexception downloadsfiledoesnotexistcannotcreate canread canwrite invalidconfigvalueexception downloadsfilecancreatecannotreadorwrite ioexception invalidconfigvalueexception downloadsfiledoesnotexistcannotcreate getlocalizedmessage private static string l10n string key return l10n get string fcp server key getstring fcpserver private static string l10n string key string pattern string value return l10n get string fcp server key pattern value getstring fcpserver public fcp client register reboot client string name node client core core fcp connection handler handler fcp client old client synchronized this old client reboot clients by name get name if old client null create new client fcp client client new fcp client name handler false null client request persist reboot null null reboot clients by name put name client return client else fcp connection handler old conn old client get connection have existing client if old conn null easy old client set connection handler return old client else kill old connection old conn set killed dupe old conn output handler queue new close connection duplicate client name message old conn close old client set connection handler return old client fcpclient registerrebootclient nodeclientcore fcpconnectionhandler fcpclient oldclient oldclient rebootclientsbyname oldclient fcpclient fcpclient clientrequest persist_reboot rebootclientsbyname fcpconnectionhandler oldconn oldclient getconnection oldconn oldclient setconnection oldclient oldconn setkilleddupe oldconn outputhandler closeconnectionduplicateclientnamemessage oldconn oldclient setconnection oldclient public fcp client register forever client string name node client core core fcp connection handler handler object container container return persistent root register forever client name core handler this container fcpclient registerforeverclient nodeclientcore fcpconnectionhandler objectcontainer persistentroot registerforeverclient public void unregister client fcp client client object container container if client persistence type client request persist reboot assert container null synchronized this string name client name reboot clients by name remove name else persistent root maybe unregister client client container unregisterclient fcpclient objectcontainer persistencetype clientrequest persist_reboot rebootclientsbyname persistentroot maybeunregisterclient private void load persistent requests object container container logger normal this loading persistent requests file input stream fis null buffered input stream bis null gzip input stream gis null try file file new file persistent downloads file gz fis new file input stream file gis new gzip input stream fis bis new buffered input stream gis logger normal this loading persistent requests from file if file length 0 load persistent requests bis container else throw new io exception file empty if it s empty try the temp file catch io exception e logger error this ioe e get message e file file new file persistent downloads temp file gz logger normal this let s try to load file then closer close bis closer close gis closer close fis try fis new file input stream file bis new buffered input stream fis load persistent requests bis container catch io exception e1 logger normal this it s corrupted too not reading any persistent requests from disk e1 return finally closer close bis closer close gis closer close fis loadpersistentrequests objectcontainer fileinputstream bufferedinputstream gzipinputstream persistentdownloadsfile fileinputstream gzipinputstream bufferedinputstream loadpersistentrequests ioexception ioexception getmessage persistentdownloadstempfile fileinputstream bufferedinputstream loadpersistentrequests ioexception private void load persistent requests input stream is object container container throws io exception synchronized persistence sync input stream reader ris new input stream reader is utf 8 buffered reader br new buffered reader ris try string r br read line int count try count integer parse int r catch number format exception e logger error this corrupt persistent downloads file cannot parse r as integer throw new io exception e to string for int i 0 i count i wrapper manager signal starting 20 60 1000 20 minutes per request must be ds lock timeout 10 minutes system out println loading persistent request i 1 of count humans count from 1 client request read and register br this container core client context logger normal this loaded count persistent requests finally closer close br closer close ris loadpersistentrequests inputstream objectcontainer ioexception persistencesync inputstreamreader inputstreamreader bufferedreader bufferedreader readline parseint numberformatexception ioexception tostring wrappermanager signalstarting clientrequest readandregister clientcontext public client request get global requests object container container list client request v new array list client request global reboot client add persistent requests v false null if container ext is active global forever client logger error this somebody deactivated the global queue container activate global forever client 2 global forever client add persistent requests v false container return v to array new client request v size clientrequest getglobalrequests objectcontainer clientrequest arraylist clientrequest globalrebootclient addpersistentrequests isactive globalforeverclient globalforeverclient globalforeverclient addpersistentrequests toarray clientrequest public boolean remove global request blocking final string identifier throws message invalid exception if global reboot client remove by identifier identifier true this null core client context final object sync new object final mutable boolean done new mutable boolean final mutable boolean success new mutable boolean done value false core client context job runner queue new db job public void run object container container client context context boolean succeeded false try succeeded global forever client remove by identifier identifier true fcp server this container core client context catch throwable t logger error this caught removing identifier identifier t t finally synchronized sync success value succeeded done value true sync notify all native thread high priority false synchronized sync while done value try sync wait catch interrupted exception e ignore return success value else return true removeglobalrequestblocking messageinvalidexception globalrebootclient removebyidentifier clientcontext mutableboolean mutableboolean mutableboolean mutableboolean clientcontext jobrunner dbjob objectcontainer clientcontext globalforeverclient removebyidentifier fcpserver clientcontext notifyall nativethread high_priority interruptedexception public void run object container container client context context boolean succeeded false try succeeded global forever client remove by identifier identifier true fcp server this container core client context catch throwable t logger error this caught removing identifier identifier t t finally synchronized sync success value succeeded done value true sync notify all objectcontainer clientcontext globalforeverclient removebyidentifier fcpserver clientcontext notifyall public boolean remove all global requests blocking global reboot client remove all null core client context final object sync new object final mutable boolean done new mutable boolean final mutable boolean success new mutable boolean done value false core client context job runner queue new db job public void run object container container client context context boolean succeeded false try global forever client remove all container core client context succeeded true catch throwable t logger error this caught while processing panic t t system err println panic incomplete caught t t print stack trace system err println your requests have not been deleted finally synchronized sync success value succeeded done value true sync notify all native thread high priority false synchronized sync while done value try sync wait catch interrupted exception e ignore return success value removeallglobalrequestsblocking globalrebootclient removeall clientcontext mutableboolean mutableboolean mutableboolean mutableboolean clientcontext jobrunner dbjob objectcontainer clientcontext globalforeverclient removeall clientcontext printstacktrace notifyall nativethread high_priority interruptedexception public void run object container container client context context boolean succeeded false try global forever client remove all container core client context succeeded true catch throwable t logger error this caught while processing panic t t system err println panic incomplete caught t t print stack trace system err println your requests have not been deleted finally synchronized sync success value succeeded done value true sync notify all objectcontainer clientcontext globalforeverclient removeall clientcontext printstacktrace notifyall public void make persistent global request blocking final freeneturi fetchuri final string expected mime type final string persistence type string final string return type string throws not allowed exception io exception class output wrapper not allowed exception ne io exception ioe boolean done final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context not allowed exception ne null io exception ioe null try make persistent global request fetchuri expected mime type persistence type string return type string container catch not allowed exception e ne e catch io exception e ioe e catch throwable t unexpected and severe might even be oom just log it logger error this failed to make persistent request t t finally synchronized ow ow ne ne ow ioe ioe ow done true ow notify all native thread high priority false synchronized ow while true if ow done try ow wait catch interrupted exception e ignore continue if ow ioe null throw ow ioe if ow ne null throw ow ne return makepersistentglobalrequestblocking expectedmimetype persistencetypestring returntypestring notallowedexception ioexception outputwrapper notallowedexception ioexception outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext notallowedexception ioexception makepersistentglobalrequest expectedmimetype persistencetypestring returntypestring notallowedexception ioexception notifyall nativethread high_priority interruptedexception public void run object container container client context context not allowed exception ne null io exception ioe null try make persistent global request fetchuri expected mime type persistence type string return type string container catch not allowed exception e ne e catch io exception e ioe e catch throwable t unexpected and severe might even be oom just log it logger error this failed to make persistent request t t finally synchronized ow ow ne ne ow ioe ioe ow done true ow notify all objectcontainer clientcontext notallowedexception ioexception makepersistentglobalrequest expectedmimetype persistencetypestring returntypestring notallowedexception ioexception notifyall public boolean modify global request blocking final string identifier final string new token final short new priority client request req this global reboot client get request identifier null if req null req modify request new token new priority this null return true else class output wrapper boolean success boolean done final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context boolean success false try client request req global forever client get request identifier container container activate req 1 if req null req modify request new token new priority fcp server this container container deactivate req 1 success true finally synchronized ow ow success success ow done true ow notify all native thread high priority false synchronized ow while true if ow done try ow wait catch interrupted exception e ignore continue return ow success modifyglobalrequestblocking newtoken newpriority clientrequest globalrebootclient getrequest modifyrequest newtoken newpriority outputwrapper outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext clientrequest globalforeverclient getrequest modifyrequest newtoken newpriority fcpserver notifyall nativethread high_priority interruptedexception public void run object container container client context context boolean success false try client request req global forever client get request identifier container container activate req 1 if req null req modify request new token new priority fcp server this container container deactivate req 1 success true finally synchronized ow ow success success ow done true ow notify all objectcontainer clientcontext clientrequest globalforeverclient getrequest modifyrequest newtoken newpriority fcpserver notifyall create a persistent globally queued request for a file param fetchuri the file to fetch param persistence the persistence type param return type the return type throws not allowed exception throws io exception public void make persistent global request freeneturi fetchuri string expected mime type string persistence type string string return type string object container container throws not allowed exception io exception boolean persistence persistence type string equals ignore case reboot short return type client get message parse return type return type string file return filename null return temp filename null if return type client get message return type disk return filename make return filename fetchuri expected mime type return temp filename make temp return filename return filename public client get fcp client global client freeneturi uri boolean ds only boolean ignoreds int max splitfile retries int max non splitfile retries long max output length short return type boolean persist reboot only string identifier int verbosity short prio class file return filename file return temp filename throws identifier collision exception try inner make persistent global request fetchuri persistence return type f proxy fetchuri get preferred filename return filename return temp filename container return catch identifier collision exception ee try inner make persistent global request fetchuri persistence return type f proxy fetchuri get doc name return filename return temp filename container return catch identifier collision exception e try inner make persistent global request fetchuri persistence return type f proxy fetchuri to string false false return filename return temp filename container return catch identifier collision exception e1 fixme maybe use date format try inner make persistent global request fetchuri persistence return type f proxy system current time millis return filename return temp filename container return catch identifier collision exception e2 while true byte buf new byte 8 try core random next bytes buf string id f proxy base64 encode buf inner make persistent global request fetchuri persistence return type id return filename return temp filename container return catch identifier collision exception e3 returntype notallowedexception ioexception makepersistentglobalrequest expectedmimetype persistencetypestring returntypestring objectcontainer notallowedexception ioexception persistencetypestring equalsignorecase returntype clientgetmessage parsereturntype returntypestring returnfilename returntempfilename returntype clientgetmessage return_type_disk returnfilename makereturnfilename expectedmimetype returntempfilename maketempreturnfilename returnfilename clientget fcpclient globalclient dsonly maxsplitfileretries maxnonsplitfileretries maxoutputlength returntype persistrebootonly prioclass returnfilename returntempfilename identifiercollisionexception innermakepersistentglobalrequest returntype fproxy getpreferredfilename returnfilename returntempfilename identifiercollisionexception innermakepersistentglobalrequest returntype fproxy getdocname returnfilename returntempfilename identifiercollisionexception innermakepersistentglobalrequest returntype fproxy tostring returnfilename returntempfilename identifiercollisionexception dateformat innermakepersistentglobalrequest returntype fproxy currenttimemillis returnfilename returntempfilename identifiercollisionexception nextbytes fproxy innermakepersistentglobalrequest returntype returnfilename returntempfilename identifiercollisionexception private file make temp return filename file return filename return new file return filename to string freenet tmp maketempreturnfilename returnfilename returnfilename tostring private file make return filename freeneturi uri string expected mime type string ext if expected mime type null expected mime type length 0 expected mime type equals defaultmime types default mime type ext defaultmime types get extension expected mime type else ext null string ext add ext null ext string preferred uri get preferred filename string preferred with ext preferred if ext null preferred with ext ends with ext preferred with ext ext add file f new file core get download dir preferred with ext file f1 new file core get download dir preferred with ext freenet tmp int x 0 string builder sb new string builder for f exists f1 exists sb set length 0 sb append preferred sb append sb append x sb append ext add f new file core get download dir sb to string f1 new file core get download dir sb append freenet tmp to string x return f makereturnfilename expectedmimetype expectedmimetype expectedmimetype expectedmimetype defaultmimetypes default_mime_type defaultmimetypes getextension expectedmimetype extadd getpreferredfilename preferredwithext preferredwithext endswith preferredwithext extadd getdownloaddir preferredwithext getdownloaddir preferredwithext stringbuilder stringbuilder setlength extadd getdownloaddir tostring getdownloaddir tostring private void inner make persistent global request freeneturi fetchuri boolean persist reboot only short return type string id file return filename file return temp filename object container container throws identifier collision exception not allowed exception io exception final client get cg new client get persist reboot only global reboot client global forever client fetchuri default fetch context local request only default fetch context ignore store queue max retries queue max retries queue max data size return type persist reboot only id integer max value request starter bulk splitfile priority class return filename return temp filename this container cg register container false false cg start container core client context innermakepersistentglobalrequest persistrebootonly returntype returnfilename returntempfilename objectcontainer identifiercollisionexception notallowedexception ioexception clientget clientget persistrebootonly globalrebootclient globalforeverclient defaultfetchcontext localrequestonly defaultfetchcontext ignorestore queue_max_retries queue_max_retries queue_max_data_size returntype persistrebootonly max_value requeststarter bulk_splitfile_priority_class returnfilename returntempfilename clientcontext start requests which were not started immediately because it might have taken some time to start them public void finish start if enable persistent downloads boolean moved main false if logminor logger minor this persistent downloads file should be persistent downloads file logger minor this persistent downloads temp file should be persistent downloads temp file file from new file persistent downloads file get path gz file from temp new file persistent downloads temp file get path gz rename if from exists file target new file from get path old pre db4o if logminor logger minor this trying to move persistent downloads file to target if from rename to target logger error this successfully migrated persistent downloads and renamed from get name to target get name moved main true if from temp exists file target new file from temp get path old pre db4o if logminor logger minor this trying to move from temp to target if from temp rename to target moved main logger error this successfully migrated persistent downloads and renamed from temp get name to target get name has finished start true finishstart enablepersistentdownloads movedmain persistentdownloadsfile persistentdownloadstempfile persistentdownloadsfile getpath fromtemp persistentdownloadstempfile getpath getpath persistentdownloadsfile renameto getname getname movedmain fromtemp fromtemp getpath fromtemp fromtemp renameto movedmain fromtemp getname getname hasfinishedstart returns the global fcp client return the global fcp client public fcp client get global forever client return global forever client fcpclient getglobalforeverclient globalforeverclient public client request get global request string identifier object container container client request req global reboot client get request identifier null if req null req global forever client get request identifier container return req clientrequest getglobalrequest objectcontainer clientrequest globalrebootclient getrequest globalforeverclient getrequest protected boolean is downloaddda always allowed return assume downloaddda is allowed isdownloadddaalwaysallowed assumedownloadddaisallowed protected boolean is uploaddda always allowed return assume uploaddda is allowed isuploadddaalwaysallowed assumeuploadddaisallowed public boolean has finished start return has finished start hasfinishedstart hasfinishedstart public void set completion callback request completion callback cb if global forever client set request completion callback cb null logger error this replacing request completion callback cb new exception error if global reboot client set request completion callback cb null logger error this replacing request completion callback cb new exception error setcompletioncallback requestcompletioncallback globalforeverclient setrequestcompletioncallback globalrebootclient setrequestcompletioncallback public void start blocking final client request req object container container client context context throws identifier collision exception if req persistence type client request persist reboot req start null core client context else class output wrapper boolean done identifier collision exception collided if container null don t activate it may not be stored yet req register container false false req start container context container deactivate req 1 else final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context don t activate it may not be stored yet try req register container false false req start container context catch identifier collision exception e ow collided e finally synchronized ow ow done true ow notify all container deactivate req 1 native thread high priority false synchronized ow while true if ow done try ow wait catch interrupted exception e ignore else if ow collided null throw ow collided return startblocking clientrequest objectcontainer clientcontext identifiercollisionexception persistencetype clientrequest persist_reboot clientcontext outputwrapper identifiercollisionexception outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext identifiercollisionexception notifyall nativethread high_priority interruptedexception public boolean restart blocking final string identifier client request req global reboot client get request identifier null if req null req restart null core client context return true else class output wrapper boolean done boolean success final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context boolean success false try client request req global forever client get request identifier container if req null req restart container context success true finally synchronized ow ow success success ow done true ow notify all native thread high priority false synchronized ow while true if ow done return ow success try ow wait catch interrupted exception e ignore restartblocking clientrequest globalrebootclient getrequest clientcontext outputwrapper outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext clientrequest globalforeverclient getrequest notifyall nativethread high_priority interruptedexception public void run object container container client context context boolean success false try client request req global forever client get request identifier container if req null req restart container context success true finally synchronized ow ow success success ow done true ow notify all objectcontainer clientcontext clientrequest globalforeverclient getrequest notifyall public temp fetch result get completed request blocking final freeneturi key client get get global reboot client get completed request key null if get null fixme race condition with free arrange refcounting for the data to prevent this return new temp fetch result new client metadata get getmime type null get get bucket null false class output wrapper temp fetch result result boolean done final output wrapper ow new output wrapper core client context job runner queue new db job public void run object container container client context context temp fetch result result null try client get get global forever client get completed request key container container activate get 1 if get null bucket orig data get get bucket container container activate orig data 5 boolean copied false bucket new data try new data orig data create shadow catch io exception e logger error this caught error e trying to create shallow copy copying data e new data null if new data null try new data core temp bucket factory make bucket orig data size bucket tools copy orig data new data catch io exception e logger error this unable to copy data e e result null return copied true result new temp fetch result new client metadata get getmime type container new data copied container deactivate get 1 finally synchronized ow ow result result ow done true ow notify all native thread high priority false synchronized ow while true if ow done return ow result else try ow wait catch interrupted exception e ignore tempfetchresult getcompletedrequestblocking clientget globalrebootclient getcompletedrequest tempfetchresult clientmetadata getmimetype getbucket outputwrapper tempfetchresult outputwrapper outputwrapper clientcontext jobrunner dbjob objectcontainer clientcontext tempfetchresult clientget globalforeverclient getcompletedrequest origdata getbucket origdata newdata newdata origdata createshadow ioexception newdata newdata newdata tempbucketfactory makebucket origdata buckettools origdata newdata ioexception tempfetchresult clientmetadata getmimetype newdata notifyall nativethread high_priority interruptedexception public void run object container container client context context temp fetch result result null try client get get global forever client get completed request key container container activate get 1 if get null bucket orig data get get bucket container container activate orig data 5 boolean copied false bucket new data try new data orig data create shadow catch io exception e logger error this caught error e trying to create shallow copy copying data e new data null if new data null try new data core temp bucket factory make bucket orig data size bucket tools copy orig data new data catch io exception e logger error this unable to copy data e e result null return copied true result new temp fetch result new client metadata get getmime type container new data copied container deactivate get 1 finally synchronized ow ow result result ow done true ow notify all objectcontainer clientcontext tempfetchresult clientget globalforeverclient getcompletedrequest origdata getbucket origdata newdata newdata origdata createshadow ioexception newdata newdata newdata tempbucketfactory makebucket origdata buckettools origdata newdata ioexception tempfetchresult clientmetadata getmimetype newdata notifyall public boolean object can new object container container logger error this not storing fcp server in database new exception error return false objectcannew objectcontainer fcpserver public quoted printable encoding string extra quoted chars boolean space as underscore boolean literalcrlf this extra quoted chars extra quoted chars get bytes this space as underscore space as underscore this literalcrlf literalcrlf ignore errors false quotedprintableencoding extraquotedchars spaceasunderscore extraquotedchars extraquotedchars getbytes spaceasunderscore spaceasunderscore ignoreerrors public void set ignore errors boolean ignore ignore errors ignore setignoreerrors ignoreerrors output a soft line break one the reader should ignore private void put soft break output buffer append byte output buffer byte output buffer append byte output buffer byte r output buffer append byte output buffer byte n output line width 0 putsoftbreak outputbuffer appendbyte outputbuffer outputbuffer appendbyte outputbuffer outputbuffer appendbyte outputbuffer outputlinewidth output a literal byte private void put char byte b if output line width 74 put soft break output buffer append byte output buffer b output line width putchar outputlinewidth putsoftbreak outputbuffer appendbyte outputbuffer outputlinewidth convert a value 0 15 to an ascii hex digit private byte hex digit int v if v 10 return byte 0x30 v else return byte 0x41 v 10 hexdigit output a byte in hex encoding private void put encoded byte b if output line width 72 put soft break output buffer append byte output buffer byte output buffer append byte output buffer hex digit b 4 0xf output buffer append byte output buffer hex digit b 0xf output line width 3 putencoded outputlinewidth putsoftbreak outputbuffer appendbyte outputbuffer outputbuffer appendbyte outputbuffer hexdigit outputbuffer appendbyte outputbuffer hexdigit outputlinewidth determine if this byte value must be quoted private boolean must quote byte byte b if b 0x7e b 0x20 b byte return true if space as underscore b byte return true for int i 0 i extra quoted chars length i if b extra quoted chars i return true return false mustquotebyte spaceasunderscore _ extraquotedchars extraquotedchars public synchronized byte buffer encode byte buffer input boolean cr false output buffer byte buffer allocate 100 output line width 0 while input has remaining byte b input get if cr b 10 put encoded byte 13 if literalcrlf b 13 cr true else if literalcrlf cr b 10 put char byte 13 put char byte 10 output line width 0 cr false else if must quote byte b put encoded b cr false else put char b cr false output buffer flip return output buffer bytebuffer bytebuffer outputbuffer bytebuffer outputlinewidth hasremaining putencoded putchar putchar outputlinewidth mustquotebyte putencoded putchar outputbuffer outputbuffer private int hex value byte b if b 0x30 b 0x39 return b 0x30 else if b 0x41 b 0x46 return b 0x41 10 else if b 0x61 b 0x66 return b 0x61 10 else throw new illegal argument exception hexvalue illegalargumentexception public byte buffer decode byte buffer input throws invalid encoded text exception byte buffer result byte buffer allocate 100 while input has remaining byte b input get if b byte space as underscore result append byte result byte else if b byte result append byte result b else byte c d if input has remaining if ignore errors result append byte result b break else throw new invalid encoded text exception quoted printable data ends prematurely c input get check for soft newline if c 13 if input has remaining d input get if d 10 input position input position 1 else if c 10 if input has remaining if ignore errors result append byte result b result append byte result c break else throw new invalid encoded text exception quoted printable data ends prematurely d input get try int high hex value c int low hex value d result append byte result byte high 4 low catch illegal argument exception e if ignore errors result append byte result b input position input position 2 else throw new invalid encoded text exception invalid quote sequence in quoted printable data result flip return result bytebuffer bytebuffer invalidencodedtextexception bytebuffer bytebuffer hasremaining _ spaceasunderscore appendbyte appendbyte hasremaining ignoreerrors appendbyte invalidencodedtextexception hasremaining hasremaining ignoreerrors appendbyte appendbyte invalidencodedtextexception hexvalue hexvalue appendbyte illegalargumentexception ignoreerrors appendbyte invalidencodedtextexception private float octaves 1 0f public fractal sum function function2d basis super basis fractalsumfunction public float evaluate float x float y float t 0 0f for float f 1 0f f octaves f 2 t basis evaluate f x f y f return t public short option sub config conf string option name short default value int sort order boolean expert boolean force write string short desc string long desc short callback cb boolean is size super conf option name cb sort order expert force write short desc long desc option data type number this default value default value this current value default value this is size is size shortoption subconfig optionname defaultvalue sortorder forcewrite shortdesc longdesc shortcallback issize optionname sortorder forcewrite shortdesc longdesc datatype defaultvalue defaultvalue currentvalue defaultvalue issize issize private string l10n string key string pattern string value return l10n get string short option key pattern value getstring shortoption override protected short parse string string val throws invalid config value exception short x try x fields parse short val catch number format exception e throw new invalid config value exception l10n unrecognised short val val return x parsestring invalidconfigvalueexception parseshort numberformatexception invalidconfigvalueexception unrecognisedshort override protected string to string short val return fields short to string val is size tostring shorttostring issize override public void should update logminor logger should log logger minor this logdebug logger should log logger minor this shouldupdate shouldlog shouldlog private final int hash code override public int hash code return hash code hashcode hashcode hashcode param parent param cb param block param metadata param ctx param dont compress param getchk only param report metadata only if true don t insert the metadata just report it param insert as archive manifest if true insert the metadata as an archive manifest param free data if true free the data when possible param target filename param early encode if true try to get a uri as quickly as possible throws insert exception single file inserter base client putter parent put completion callback cb insert block block boolean metadata insert context ctx boolean dont compress boolean getchk only boolean report metadata only object token archive type archive type boolean free data string target filename boolean early encode hash code super hash code this early encode early encode this report metadata only report metadata only this token token this parent parent this block block this ctx ctx this metadata metadata this cb cb this getchk only getchk only this archive type archive type this free data free data this target filename target filename this persistent parent persistent if logminor logger minor this created this persistent persistent free data free data dontcompress getchkonly reportmetadataonly insertasarchivemanifest freedata targetfilename earlyencode insertexception singlefileinserter baseclientputter putcompletioncallback insertblock insertcontext dontcompress getchkonly reportmetadataonly archive_type archivetype freedata targetfilename earlyencode hashcode hashcode earlyencode earlyencode reportmetadataonly reportmetadataonly getchkonly getchkonly archivetype archivetype freedata freedata targetfilename targetfilename freedata freedata public void start simple field set fs object container container client context context throws insert exception if fs null string type fs get type if type equals split handler try to reconstruct split handler if we succeed we bypass both compression and fec encoding try split handler sh new split handler sh start fs false container context boolean was active true if persistent was active container ext is active cb if was active container activate cb 1 cb on transition this sh container sh schedule container context if was active container deactivate cb 1 return catch resume exception e logger error this failed to restore e e if persistent container activate block 1 will cascade try compress container context simplefieldset objectcontainer clientcontext insertexception splithandler splithandler splithandler splithandler wasactive wasactive isactive wasactive ontransition wasactive resumeexception trycompress void on compressed compression output output object container container client context context boolean cb active true if persistent cb active container ext is active cb if cb active container activate cb 1 if started logger error this already started not starting again new exception error return if cancelled logger error this already cancelled not starting return if persistent container activate block 1 try on compressed inner output container context catch insert exception e cb on failure e single file inserter this container context catch out of memory error e oom handler handleoom e system err println off thread compressor thread above failed might not be heap so try anyway cb on failure new insert exception insert exception internal error e null single file inserter this container context catch throwable t logger error this caught in off thread compressor t t system err println caught in off thread compressor t t print stack trace try to fail gracefully cb on failure new insert exception insert exception internal error t null single file inserter this container context if cb active container deactivate cb 1 oncompressed compressionoutput objectcontainer clientcontext cbactive cbactive isactive cbactive oncompressedinner insertexception onfailure singlefileinserter outofmemoryerror oomhandler offthreadcompressor onfailure insertexception insertexception internal_error singlefileinserter offthreadcompressor offthreadcompressor printstacktrace onfailure insertexception insertexception internal_error singlefileinserter cbactive void on compressed inner compression output output object container container client context context throws insert exception boolean parent was active true if container null container activate block 2 parent was active container ext is active parent if parent was active container activate parent 1 long orig size block get data size bucket best compressed data output data long best compressed data size best compressed data size bucket data best compressed data compressor type best codec output best codec boolean should free data free data if best codec null if logminor logger minor this the best compression algorithm is best codec we have gained 100 best compressed data size 100 orig size orig size best compressed data size should free data true must be freed regardless of whether the original data was to be freed if free data block get data free if persistent block get data remove from container block null data if persistent container store block else data block get data int block size int one block compressed size boolean ischk false if persistent container activate block desireduri 5 string type block desireduri get key type if type equals ssk type equals ksk type equals usk block size ssk block data length one block compressed size ssk block max compressed data length else if type equals chk block size chk block data length one block compressed size chk block max compressed data length ischk true else throw new insert exception insert exception invalid uri unknown key type type null compressed data now insert it we do not need to switch threads here the actual compression is done by insert compressor on the real compressor thread which then switches either to the database thread or to a new executable to run this method if parent cb if persistent container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new finished compression event best codec null 1 best codec metadataid orig size data size container context if logminor logger minor this compressed orig size to data size on this insert it short codec number best codec null 1 best codec metadataid long compressed data size data size boolean fits in one block as is best codec null compressed data size block size compressed data size one block compressed size boolean fits in onechk best codec null compressed data size chk block data length compressed data size chk block max compressed data length if fits in one block as is fits in onechk orig size integer max value throw new insert exception insert exception internal error 2gb should not encode to one block null boolean no metadata block client metadata null block client metadata is trivial target filename null if no metadata archive type null if fits in one block as is if persistent data instanceof not persistent bucket data fix not persistent data context just insert it client put state bi create inserter parent data codec number ctx cb metadata int orig size 1 getchk only true container context should free data if logminor logger minor this inserting without metadata bi for this cb on transition this bi container if early encode bi instanceof single block inserter ischk single block inserter bi get block container context true bi schedule container context cb on block set finished this container context started true if persistent if parent was active container deactivate parent 1 block null data block remove from container block null remove from container context return if fits in onechk insert single block then insert pointer to it if persistent data instanceof not persistent bucket data fix not persistent data context if report metadata only single block inserter data putter new single block inserter parent data codec number persistent freeneturi empty chk uri clone freeneturi empty chk uri ctx cb metadata int orig size 1 getchk only true true token container context persistent should free data if logminor logger minor this inserting with metadata data putter for this metadata meta make metadata archive type data putter geturi container context cb on metadata meta this container context cb on transition this data putter container data putter schedule container context cb on block set finished this container context else multi put completion callback mcb new multi put completion callback cb parent token persistent single block inserter data putter new single block inserter parent data codec number persistent freeneturi empty chk uri clone freeneturi empty chk uri ctx mcb metadata int orig size 1 getchk only true false token container context persistent should free data if logminor logger minor this inserting data data putter for this metadata meta make metadata archive type data putter geturi container context bucket metadata bucket try metadata bucket bucket tools make immutable bucket context get bucket factory persistent meta write to byte array catch io exception e logger error this caught e e throw new insert exception insert exception bucket error e null catch metadata unresolved exception e impossible we re not inserting a manifest logger error this caught e e throw new insert exception insert exception internal error got metadata unresolved exception in single file inserter e to string null client put state meta putter create inserter parent metadata bucket short 1 ctx mcb true int orig size 1 getchk only true container context true if logminor logger minor this inserting metadata meta putter for this mcb adduri generator meta putter container mcb add data putter container cb on transition this mcb container logger minor this mcb data data putter meta meta putter mcb arm container context data putter schedule container context if early encode meta putter instanceof single block inserter single block inserter meta putter get block container context true meta putter schedule container context cb on block set finished this container context started true if persistent if parent was active container deactivate parent 1 block null data block remove from container block null remove from container context return otherwise the file is too big to fit into one block we therefore must make a splitfile job of split handler when the splitinserter has the metadata insert it then when the splitinserter has finished and the metadata insert has finished too tell the master callback if report metadata only split file inserter sfi new split file inserter parent cb data best codec orig size block client metadata ctx getchk only metadata token archive type should free data persistent container context if logminor logger minor this inserting as splitfile sfi for this cb on transition this sfi container sfi start container context if early encode sfi force encode container context if persistent container store sfi container deactivate sfi 1 block null data block null metadata if persistent remove from container context else split handler sh new split handler split file inserter sfi new split file inserter parent sh data best codec orig size block client metadata ctx getchk only metadata token archive type should free data persistent container context sh sfi sfi if logminor logger minor this inserting as splitfile sfi for sh for this if persistent container store sh cb on transition this sh container sfi start container context if early encode sfi force encode container context if persistent container store sfi container deactivate sfi 1 started true if persistent container store this if persistent if parent was active container deactivate parent 1 oncompressedinner compressionoutput objectcontainer clientcontext insertexception parentwasactive parentwasactive isactive parentwasactive origsize getdata bestcompresseddata bestcompresseddatasize bestcompresseddata bestcompresseddata compressor_type bestcodec bestcodec shouldfreedata freedata bestcodec bestcodec bestcompresseddatasize origsize origsize bestcompresseddatasize shouldfreedata freedata getdata getdata removefrom nulldata getdata blocksize oneblockcompressedsize getkeytype blocksize sskblock data_length oneblockcompressedsize sskblock max_compressed_data_length blocksize chkblock data_length oneblockcompressedsize chkblock max_compressed_data_length insertexception insertexception invalid_uri insertcompressor realcompressor eventproducer eventproducer produceevent finishedcompressionevent bestcodec bestcodec origsize origsize codecnumber bestcodec bestcodec compresseddatasize fitsinoneblockasis bestcodec compresseddatasize blocksize compresseddatasize oneblockcompressedsize fitsinonechk bestcodec compresseddatasize chkblock data_length compresseddatasize chkblock max_compressed_data_length fitsinoneblockasis fitsinonechk origsize max_value insertexception insertexception internal_error nometadata clientmetadata clientmetadata istrivial targetfilename nometadata archivetype fitsinoneblockasis notpersistentbucket fixnotpersistent clientputstate createinserter codecnumber origsize getchkonly shouldfreedata ontransition earlyencode singleblockinserter singleblockinserter getblock onblocksetfinished parentwasactive nulldata removefrom removefrom fitsinonechk notpersistentbucket fixnotpersistent reportmetadataonly singleblockinserter dataputter singleblockinserter codecnumber empty_chk_uri empty_chk_uri origsize getchkonly shouldfreedata dataputter makemetadata archivetype dataputter onmetadata ontransition dataputter dataputter onblocksetfinished multiputcompletioncallback multiputcompletioncallback singleblockinserter dataputter singleblockinserter codecnumber empty_chk_uri empty_chk_uri origsize getchkonly shouldfreedata dataputter makemetadata archivetype dataputter metadatabucket metadatabucket buckettools makeimmutablebucket getbucketfactory writetobytearray ioexception insertexception insertexception bucket_error metadataunresolvedexception insertexception insertexception internal_error metadataunresolvedexception singlefileinserter tostring clientputstate metaputter createinserter metadatabucket origsize getchkonly metaputter addurigenerator metaputter dataputter ontransition dataputter metaputter dataputter earlyencode metaputter singleblockinserter singleblockinserter metaputter getblock metaputter onblocksetfinished parentwasactive nulldata removefrom removefrom splithandler reportmetadataonly splitfileinserter splitfileinserter bestcodec origsize clientmetadata getchkonly archivetype shouldfreedata ontransition earlyencode forceencode nulldata nullmetadata removefrom splithandler splithandler splitfileinserter splitfileinserter bestcodec origsize clientmetadata getchkonly archivetype shouldfreedata ontransition earlyencode forceencode parentwasactive private bucket fix not persistent bucket data client context context throws insert exception boolean skip false if data instanceof segmented bucket chain bucket segmented bucket chain bucket seg segmented bucket chain bucket data bucket buckets seg get buckets if buckets length 1 seg clear data buckets 0 skip true if logminor logger minor this using bucket 0 of segmented bucket chain bucket try if skip if logminor logger minor this copying data from data length data size bucket new data context persistent bucket factory make bucket data size bucket tools copy data new data data free data new data catch io exception e logger error this caught e while copying non persistent data e throw new insert exception insert exception bucket error e null note that segmentedbcb does support splitting so we don t need to do anything to the data if it doesn t fit in a single block return data fixnotpersistent clientcontext insertexception segmentedbucketchainbucket segmentedbucketchainbucket segmentedbucketchainbucket getbuckets segmentedbucketchainbucket newdata persistentbucketfactory makebucket buckettools newdata newdata ioexception insertexception insertexception bucket_error private void try compress object container container client context context throws insert exception first determine how small it needs to be bucket orig data block get data bucket data orig data int block size int one block compressed size boolean dont compress ctx dont compress long orig size data size if persistent container activate block desireduri 5 string type block desireduri get key type to upper case if type equals ssk type equals ksk type equals usk block size ssk block data length one block compressed size ssk block max compressed data length else if type equals chk block size chk block data length one block compressed size chk block max compressed data length else throw new insert exception insert exception invalid uri unknown key type type null boolean try compress orig size block size ctx dont compress dont compress if try compress insert compressor start container context this orig data one block compressed size context get bucket factory persistent persistent else compression output output new compression output data null on compressed output container context trycompress objectcontainer clientcontext insertexception origdata getdata origdata blocksize oneblockcompressedsize dontcompress dontcompress origsize getkeytype touppercase blocksize sskblock data_length oneblockcompressedsize sskblock max_compressed_data_length blocksize chkblock data_length oneblockcompressedsize chkblock max_compressed_data_length insertexception insertexception invalid_uri trycompress origsize blocksize dontcompress dontcompress trycompress insertcompressor origdata oneblockcompressedsize getbucketfactory compressionoutput compressionoutput oncompressed private metadata make metadata archive type archive type freeneturi uri metadata meta null if archive type null meta new metadata metadata archive manifest archive type null uri block client metadata else redirect meta new metadata metadata simple redirect archive type null uri block client metadata if target filename null hash map string object hm new hash map string object hm put target filename meta meta metadata mk redirection manifest with metadata hm return meta makemetadata archive_type archivetype archivetype archive_manifest archivetype clientmetadata simple_redirect archivetype clientmetadata targetfilename hashmap hashmap targetfilename mkredirectionmanifestwithmetadata private client put state create inserter base client putter parent bucket data short compression codec insert context ctx put completion callback cb boolean is metadata int source length int token boolean getchk only boolean add to parent object container container client context context boolean free data throws insert exception freeneturi uri block desireduri uri check inserturi will throw an exception if needed if uri get key type equals usk try return new usk inserter parent data compression codec uri ctx cb is metadata source length token getchk only add to parent this token container context free data persistent catch malformedurl exception e throw new insert exception insert exception invalid uri e null else single block inserter sbi new single block inserter parent data compression codec uri ctx cb is metadata source length token getchk only add to parent false this token container context persistent free data pass uri to sbi block nulluri if persistent container store block return sbi clientputstate createinserter baseclientputter compressioncodec insertcontext putcompletioncallback ismetadata sourcelength getchkonly addtoparent objectcontainer clientcontext freedata insertexception checkinserturi getkeytype uskinserter compressioncodec ismetadata sourcelength getchkonly addtoparent freedata malformedurlexception insertexception insertexception invalid_uri singleblockinserter singleblockinserter compressioncodec ismetadata sourcelength getchkonly addtoparent freedata private final int hash code override public int hash code return hash code hashcode hashcode hashcode create a split handler from a stored progress simple field set param force metadata if true the insert is metadata regardless of what the encompassing split file inserter says i e it s multi level metadata throws resume exception thrown if the resume fails throws insert exception thrown if some other error prevents the insert from starting void start simple field set fs boolean force metadata object container container client context context throws resume exception insert exception boolean parent was active true if persistent parent was active container ext is active parent if parent was active container activate parent 1 boolean meta metadata force metadata don t include the booleans wait for the callback simple field set sfifs fs subset split file inserter if sfifs null throw new resume exception no split file inserter client put state newsfi new meta putter null newsfi new split file inserter parent this force metadata null block client metadata ctx getchk only meta token archive type sfifs container context if logminor logger minor this starting newsfi for this fs remove subset split file inserter simple field set metafs fs subset metadata putter if metafs null try string type metafs get type if type equals split file inserter fixme insert as archive manifest new meta putter new split file inserter parent this null ctx getchk only true token archive type metafs container context else if type equals split handler new meta putter new split handler split handler new meta putter start metafs true container context catch resume exception e new meta putter null logger error this caught e e will be reconstructed later if logminor logger minor this metadata putter metadata putter for this fs remove subset metadata putter synchronized this sfi newsfi metadata putter new meta putter if persistent container store this if parent was active container deactivate parent 1 splithandler simplefieldset forcemetadata splitfileinserter resumeexception insertexception simplefieldset forcemetadata objectcontainer clientcontext resumeexception insertexception parentwasactive parentwasactive isactive parentwasactive forcemetadata simplefieldset splitfileinserter resumeexception splitfileinserter clientputstate newmetaputter splitfileinserter forcemetadata clientmetadata getchkonly archivetype removesubset splitfileinserter simplefieldset metadataputter splitfileinserter insertasarchivemanifest newmetaputter splitfileinserter getchkonly archivetype splithandler newmetaputter splithandler splithandler newmetaputter resumeexception newmetaputter metadataputter removesubset metadataputter metadataputter newmetaputter parentwasactive public split handler default constructor this persistent single file inserter this persistent this hash code super hash code splithandler singlefileinserter hashcode hashcode public synchronized void on transition client put state old state client put state new state object container container if persistent fixme debug point if logminor logger minor this transition old state new state if old state sfi sfi new state if old state metadata putter metadata putter new state if persistent container store this ontransition clientputstate oldstate clientputstate newstate objectcontainer oldstate newstate oldstate newstate oldstate metadataputter metadataputter newstate public void on success client put state state object container container client context context if persistent container activate block 2 if logminor logger minor this on success state for this boolean late start false client put state to remove null synchronized this if finished return if state sfi if logminor logger minor this splitfile insert succeeded for this state split insert success true if meta insert success meta insert started late start true else if logminor logger minor this metadata already started for this success meta insert success started meta insert started sfi null to remove state else if state metadata putter if logminor logger minor this metadata insert succeeded for this state meta insert success true metadata putter null to remove state else logger error this unknown state for this new exception debug if split insert success meta insert success if logminor logger minor this both succeeded for this finished true if free data block free container else block null data if persistent container store block if to remove null persistent to remove remove from container context if persistent container store this if late start start metadata container context else if finished if persistent container activate cb 1 cb on success this container context if persistent container deactivate cb 1 onsuccess clientputstate objectcontainer clientcontext onsuccess latestart clientputstate toremove splitinsertsuccess metainsertsuccess metainsertstarted latestart metainsertsuccess metainsertstarted toremove metadataputter metainsertsuccess metadataputter toremove splitinsertsuccess metainsertsuccess freedata nulldata toremove toremove removefrom latestart startmetadata onsuccess public void on failure insert exception e client put state state object container container client context context if persistent container activate block 1 boolean to fail true boolean to remove false synchronized this if state sfi to remove true sfi null if metadata putter null if persistent container store this else if state metadata putter to remove true metadata putter null if sfi null if persistent container store this else logger error this on failure on unknown state state on this new exception debug if finished to fail false already failed if to remove persistent state remove from container context fail will cancel the other one so we don t need to when it does it will come back here and we won t call fail because fail has already set finished true if to fail fail e container context onfailure insertexception clientputstate objectcontainer clientcontext tofail toremove toremove metadataputter metadataputter toremove metadataputter onfailure tofail toremove removefrom tofail public void on metadata metadata meta client put state state object container container client context context if persistent container activate cb 1 container activate block 2 insert exception e null synchronized this if finished return if report metadata only if state sfi logger error this got metadata from unknown object state when expecting to report metadata return meta insert success true else if state metadata putter logger error this got metadata for metadata e new insert exception insert exception internal error did not expect to get metadata for metadata inserter null else if state sfi logger error this got metadata from unknown state state sfi sfi metadata putter metadata putter on this persistent persistent new exception debug e new insert exception insert exception internal error got metadata from unknown state null else already started metadata putter in which case we ve got the metadata twice if metadata putter null return if report metadata only if persistent container store this cb on metadata meta this container context return if e null on failure e state container context return byte meta bytes if persistent load keys container activate meta 100 try meta bytes meta write to byte array catch metadata unresolved exception e1 logger error this impossible e1 e1 insert exception ex new insert exception insert exception internal error metadata unresolved exception in single file inserter split handler e1 null ex init cause e1 fail ex container context return string meta putter target filename target filename if target filename null if meta bytes length short max value hash map string object hm new hash map string object hm put target filename meta meta metadata mk redirection manifest with metadata hm meta putter target filename null try meta bytes meta write to byte array catch metadata unresolved exception e1 logger error this impossible 2 e1 e1 insert exception ex new insert exception insert exception internal error metadata unresolved exception in single file inserter split handler 2 e1 null ex init cause e1 fail ex container context return bucket metadata bucket try metadata bucket bucket tools make immutable bucket context get bucket factory persistent meta bytes catch io exception e1 insert exception ex new insert exception insert exception bucket error e1 null fail ex container context return insert block new block new insert block metadata bucket null block desireduri synchronized this metadata putter new single file inserter parent this new block true ctx false getchk only false token archive type true meta putter target filename early encode if early encode then start the metadata insert asap to get the key otherwise wait until the data is fetchable to improve persistence if logminor logger minor this created metadata putter for this metadata putter bucket metadata bucket size metadata bucket size if persistent container store this if early encode split insert success return if logminor logger minor this putting metadata on metadata putter from sfi split file inserter sfi get length start metadata container context onmetadata clientputstate objectcontainer clientcontext insertexception reportmetadataonly metainsertsuccess metadataputter insertexception insertexception internal_error metadataputter metadataputter insertexception insertexception internal_error metadataputter reportmetadataonly onmetadata onfailure metabytes metabytes writetobytearray metadataunresolvedexception insertexception insertexception insertexception internal_error metadataunresolvedexception singlefileinserter splithandler initcause metaputtertargetfilename targetfilename targetfilename metabytes max_value hashmap hashmap targetfilename mkredirectionmanifestwithmetadata metaputtertargetfilename metabytes writetobytearray metadataunresolvedexception insertexception insertexception insertexception internal_error metadataunresolvedexception singlefileinserter splithandler initcause metadatabucket metadatabucket buckettools makeimmutablebucket getbucketfactory metabytes ioexception insertexception insertexception insertexception bucket_error insertblock newblock insertblock metadatabucket metadataputter singlefileinserter newblock getchkonly archivetype metaputtertargetfilename earlyencode earlyencode metadataputter metadatabucket metadatabucket earlyencode splitinsertsuccess metadataputter splitfileinserter getlength startmetadata private void fail insert exception e object container container client context context if logminor logger minor this failing e e client put state oldsfi null client put state old metadata putter null synchronized this if finished return finished true oldsfi sfi old metadata putter metadata putter if persistent container store this if oldsfi null container activate oldsfi 1 if old metadata putter null container activate old metadata putter 1 if oldsfi null oldsfi cancel container context if old metadata putter null old metadata putter cancel container context if persistent container activate block 2 container activate cb 1 synchronized this if free data block free container else block null data if persistent container store block cb on failure e this container context insertexception objectcontainer clientcontext clientputstate clientputstate oldmetadataputter oldmetadataputter metadataputter oldmetadataputter oldmetadataputter oldmetadataputter oldmetadataputter freedata nulldata onfailure public base client putter get parent return parent baseclientputter getparent public void on encode base client key key client put state state object container container client context context if persistent fixme debug point if logminor logger minor this on encode for this state key synchronized this if state metadata putter if logminor logger minor this ignored on encode for this state return if persistent container activate cb 1 cb on encode key this container context onencode baseclientkey clientputstate objectcontainer clientcontext onencode metadataputter onencode onencode public void cancel object container container client context context if logminor logger minor this cancelling this client put state oldsfi null client put state old metadata putter null synchronized this oldsfi sfi old metadata putter metadata putter if persistent container store this if oldsfi null container activate oldsfi 1 if old metadata putter null container activate old metadata putter 1 if oldsfi null oldsfi cancel container context if old metadata putter null old metadata putter cancel container context fixme in the other cases fail and on success we only free when we set finished but we haven t set finished here can we rely on the callback and not do anything here note that it is in fact safe to double free it s not safe to not free if free data if persistent container activate block 2 block free container else block null data if persistent container store block objectcontainer clientcontext clientputstate clientputstate oldmetadataputter oldmetadataputter metadataputter oldmetadataputter oldmetadataputter oldmetadataputter oldmetadataputter onsuccess freedata nulldata public void on block set finished client put state state object container container client context context synchronized this if state sfi split insert set blocks true else if state metadata putter meta insert set blocks true if persistent container store this if split insert set blocks meta insert set blocks return if persistent container activate cb 1 cb on block set finished this container context onblocksetfinished clientputstate objectcontainer clientcontext splitinsertsetblocks metadataputter metainsertsetblocks splitinsertsetblocks metainsertsetblocks onblocksetfinished public void schedule object container container client context context throws insert exception if persistent container activate sfi 1 sfi schedule container context objectcontainer clientcontext insertexception public object get token return token gettoken public void on fetchable client put state state object container container if persistent fixme debug point if logminor logger minor this on fetchable on this if logminor logger minor this on fetchable state boolean meta synchronized this meta state metadata putter if meta if meta insert started logger error this metadata insert not started yet got on fetchable for it state on this if logminor logger minor this metadata fetchable meta fetchable already if meta fetchable return meta fetchable true if persistent container store this else if state sfi logger error this on fetchable for unknown state state return if persistent container store this if logminor logger minor this data fetchable if meta insert started return if meta if persistent container activate cb 1 cb on fetchable this container onfetchable clientputstate objectcontainer onfetchable onfetchable metadataputter metainsertstarted onfetchable metafetchable metafetchable metafetchable onfetchable metainsertstarted onfetchable private void start metadata object container container client context context if persistent fixme debug point if logminor logger minor this start metadata on this try client put state putter client put state split inserter synchronized this if meta insert started return if persistent metadata putter null container activate metadata putter 1 putter metadata putter if putter null if logminor logger minor this cannot start metadata yet no metadata putter else meta insert started true split inserter sfi if persistent container store this if putter null if logminor logger minor this starting metadata inserter putter for this putter schedule container context if logminor logger minor this started metadata inserter putter for this else get all the ur is asap so we can start to insert the metadata if persistent container activate split inserter 1 split file inserter split inserter force encode container context catch insert exception e1 logger error this failing this e1 e1 fail e1 container context return startmetadata objectcontainer clientcontext startmetadata clientputstate clientputstate splitinserter metainsertstarted metadataputter metadataputter metadataputter metadataputter metainsertstarted splitinserter uris splitinserter splitfileinserter splitinserter forceencode insertexception public void object on activate object container container chain to containing class since we use its members extensively container activate single file inserter this 1 objectonactivate objectcontainer singlefileinserter public void remove from object container container client context context if logminor logger minor this remove from on this container delete this remove parent as well since we always transition from parent to sh i e it will not get a remove from single file inserter this remove from container context removefrom objectcontainer clientcontext removefrom removefrom singlefileinserter removefrom public boolean object can update object container container if logdebug logger debug this object can update on this new exception debug return true objectcanupdate objectcontainer objectcanupdate public boolean object can new object container container if finished logger error this object can new but finished on this new exception error else if logdebug logger debug this object can new on this new exception debug return true objectcannew objectcontainer objectcannew objectcannew public base client putter get parent return parent baseclientputter getparent public void cancel object container container client context context if logminor logger minor this cancel this synchronized this if cancelled return cancelled true if free data if persistent container activate block 1 block free container if persistent container store this if persistent container activate cb 1 must call on failure so get remove from ed cb on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext freedata onfailure removefrom onfailure insertexception insertexception public void schedule object container container client context context throws insert exception start null container context objectcontainer clientcontext insertexception public object get token return token gettoken public void on start compression compressor type ctype object container container client context context if persistent container activate ctx 2 if parent cb if ctx null throw new null pointer exception if ctx event producer null throw new null pointer exception ctx event producer produce event new started compression event ctype container context onstartcompression compressor_type objectcontainer clientcontext nullpointerexception eventproducer nullpointerexception eventproducer produceevent startedcompressionevent boolean cancelled return cancelled boolean started return started public void remove from object container container client context context if logminor logger minor this remove from on this new exception debug parent removes self token is passed in creator of token is responsible for removing it if block null container activate block 1 block remove from container ctx is passed in creator is responsible for removing it cb removes itself container delete this removefrom objectcontainer clientcontext removefrom removefrom public boolean object can update object container container if logminor logger minor this object can update on this new exception debug return true objectcanupdate objectcontainer objectcanupdate public boolean object can new object container container if logminor logger minor this object can new on this new exception debug return true objectcannew objectcontainer objectcannew protected abstract user alert this user can dismiss false this title null this text null this html text null this priority class 0 this valid true this dismiss button text null this should unregister on dismiss false this user identifier null this short text null abstractuseralert usercandismiss htmltext priorityclass dismissbuttontext shouldunregisterondismiss useridentifier shorttext protected abstract user alert boolean user can dismiss string title string text string short text html node html text short priority class boolean valid string dismiss button text boolean should unregister on dismiss object user identifier this user can dismiss user can dismiss this title title this text text this short text short text this html text html text this priority class priority class this valid valid this dismiss button text dismiss button text this should unregister on dismiss should unregister on dismiss this user identifier user identifier abstractuseralert usercandismiss shorttext htmlnode htmltext priorityclass dismissbuttontext shouldunregisterondismiss useridentifier usercandismiss usercandismiss shorttext shorttext htmltext htmltext priorityclass priorityclass dismissbuttontext dismissbuttontext shouldunregisterondismiss shouldunregisterondismiss useridentifier useridentifier inherit doc public boolean user can dismiss return user can dismiss inheritdoc usercandismiss usercandismiss inherit doc public string get title return title inheritdoc gettitle inherit doc public string get text return text inheritdoc gettext public string get short text return short text getshorttext shorttext inherit doc public html node gethtml text return html text inheritdoc htmlnode gethtmltext htmltext inherit doc public short get priority class return priority class inheritdoc getpriorityclass priorityclass inherit doc public boolean is valid return valid inheritdoc isvalid inherit doc public void is valid boolean valid if user can dismiss this valid valid inheritdoc isvalid usercandismiss inherit doc public string dismiss button text return dismiss button text inheritdoc dismissbuttontext dismissbuttontext inherit doc public boolean should unregister on dismiss return should unregister on dismiss inheritdoc shouldunregisterondismiss shouldunregisterondismiss inherit doc public void on dismiss inheritdoc ondismiss inherit doc public object get user identifier return user identifier inheritdoc getuseridentifier useridentifier public string anchor return integer to string hash code tostring hashcode public boolean is event notification return false iseventnotification final string section final int d threshold public detailed threshold string section int thresh this section section this d threshold thresh dthreshold detailedthreshold dthreshold logger hook int thresh this threshold thresh loggerhook logger hook string thresh throws invalid threshold exception this threshold priority of thresh loggerhook invalidthresholdexception priorityof log a message param o the object where this message was generated param source the class where this message was generated param message a clear and verbose message describing the event param e logs this exception with the message param priority the priority of the mesage one of logger error logger normal logger minor or logger debug override public abstract void log object o class source string message throwable e log a message param source the source object where this message was generated param message a clear and verbose message describing the event param priority the priority of the mesage one of logger error logger normal logger minor or logger debug override public void log object source string message int priority if instance should log priority source return log source source null null source get class message null priority instanceshouldlog getclass log a message with an exception param o the source object where this message was generated param message a clear and verbose message describing the event param e logs this exception with the message param priority the priority of the mesage one of logger error logger normal logger minor or logger debug see log object o string message int priority override public void log object o string message throwable e int priority if instance should log priority o return log o o null null o get class message e priority instanceshouldlog getclass log a message from static code param c the class where this message was generated param message a clear and verbose message describing the event param priority the priority of the mesage one of logger error logger normal logger minor or logger debug override public void log class c string message int priority if instance should log priority c return log null c message null priority instanceshouldlog override public void log class c string message throwable e int priority if instance should log priority c return log null c message e priority instanceshouldlog public boolean accept priority int prio return prio threshold acceptpriority override public void set threshold int thresh this threshold thresh notify log threshold callbacks setthreshold notifylogthresholdcallbacks override public int get threshold return threshold getthreshold override public void set threshold string symbolic threshold throws invalid threshold exception set threshold priority of symbolic threshold setthreshold symbolicthreshold invalidthresholdexception setthreshold priorityof symbolicthreshold override public void set detailed thresholds string details throws invalid threshold exception if details null details length 0 return string tokenizer st new string tokenizer details false array list detailed threshold stuff new array list detailed threshold while st has more tokens string token st next token if token length 0 continue int x token index of if x 0 continue if x token length 1 continue string section token substring 0 x string value token substring x 1 token length int thresh logger hook priority of value stuff add new detailed threshold section thresh detailed threshold new thresholds new detailed threshold stuff size stuff to array new thresholds synchronized this detailed thresholds new thresholds notify log threshold callbacks setdetailedthresholds invalidthresholdexception stringtokenizer stringtokenizer arraylist detailedthreshold arraylist detailedthreshold hasmoretokens nexttoken indexof loggerhook priorityof detailedthreshold detailedthreshold newthresholds detailedthreshold toarray newthresholds detailedthresholds newthresholds notifylogthresholdcallbacks public string get detailed thresholds detailed threshold thresh null synchronized this thresh detailed thresholds string builder sb new string builder for int i 0 i thresh length i if i 0 sb append sb append thresh i section sb append sb append logger hook priority of thresh i d threshold return sb to string getdetailedthresholds detailedthreshold detailedthresholds stringbuilder stringbuilder loggerhook priorityof dthreshold tostring returns the priority level matching the string if no priority matches logger normal is returned param s a string matching one of the logging priorities case insensitive public static int priority of string s throws invalid threshold exception if s equals ignore case error return logger error else if s equals ignore case normal return logger normal else if s equals ignore case minor return logger minor else if s equals ignore case debugging return logger debug else if s equals ignore case debug return logger debug else throw new invalid threshold exception l10n get string logger hook unrecognised priority name s return logger normal priorityof invalidthresholdexception equalsignorecase equalsignorecase equalsignorecase equalsignorecase equalsignorecase invalidthresholdexception getstring loggerhook unrecognisedpriority private static final long serial versionuid 1 invalid threshold exception string msg super msg serialversionuid invalidthresholdexception returns the name of the priority matching a number null if none do param priority the priority public static string priority of int priority switch priority case error return error case normal return normal case minor return minor case debug return debug default return null priorityof override public boolean instance should log int priority class c detailed threshold thresholds int thresh synchronized this thresholds detailed thresholds thresh threshold if c null thresholds length 0 string cname c get name for detailed threshold dt thresholds if cname starts with dt section thresh dt d threshold return priority thresh instanceshouldlog detailedthreshold detailedthresholds getname detailedthreshold startswith dthreshold override public final boolean instance should log int prio object o return instance should log prio o null null o get class instanceshouldlog instanceshouldlog getclass override public synchronized final void instance register log threshold callback log threshold callback ltc log threshold callback newltc new log threshold callback thresholds callbacks length 1 newltc 0 ltc system arraycopy thresholds callbacks 0 newltc 1 thresholds callbacks length thresholds callbacks newltc call the new callback to avoid code duplication ltc should update instanceregisterlogthresholdcallback logthresholdcallback logthresholdcallback logthresholdcallback thresholdscallbacks thresholdscallbacks thresholdscallbacks thresholdscallbacks shouldupdate private synchronized final void notify log threshold callbacks for log threshold callback ltc thresholds callbacks ltc should update notifylogthresholdcallbacks logthresholdcallback thresholdscallbacks shouldupdate public abstract long min flags ignore unless all these bits set minflags public abstract long min flags ignore unless all these bits set public abstract long not flags reject if any of these bits set minflags notflags public abstract long not flags reject if any of these bits set public abstract long any flags accept if any of these bits set notflags anyflags private boolean m identity publishes puzzles null public create identity wizard web interface my web interface http request request super my web interface null request midentitypublishespuzzles createidentitywizard webinterface mywebinterface httprequest mywebinterface public void make make create identity box makecreateidentitybox private void make create identity box html node create box add content box create an own identity html node create form add form child create box self uri create identity create identity boolean randomssk false exception requestur iproblem null exception insertur iproblem null exception nickname problem null stage 1 parse the passed form data int previous step m request is part set step integer parse int m request get part as string step 1 0 parse the generate random ssk boolean specified in step 1 if m request is part set generate randomssk randomssk m request get part as string generate randomssk 5 equals true if randomssk m identityuri m freetalk get plugin respirator gethl simple client generate key pair parse the uri specified in step 1 if m request is part set requesturi m request is part set inserturi assert randomssk false m identityuri new freeneturi 2 try m identityuri 0 new freeneturi m request get part as string inserturi 256 catch exception e insertur iproblem e try m identityuri 1 new freeneturi m request get part as string requesturi 256 catch exception e requestur iproblem e if insertur iproblem null requestur iproblem null m identityuri null fixme check whether the uri pair is correct i e if the insert uri really is one if the request uri really is one and if the two belong together how to do this parse the nickname specified in step 2 if m request is part set nickname try m identity nickname m request get part as string nickname 256 wot identity validate nickname m identity nickname catch exception e nickname problem e m identity nickname null parse the preferences specified in step 3 if previous step 3 we cannot just use is part set publish trust list because it won t be set if the checkbox is unchecked if m request is part set publish trust list m identity publishes trust list m request get part as string publish trust list 5 equals true else m identity publishes trust list false stage 2 display the wizard stage at which we are step 1 uri if m identityuri null html node chooseur ibox get content box step 1 of 3 choose the ssk uri create form add child chooseur ibox chooseur ibox add child p the ssk uri of your identity is a public private keypair which uniquely identifies your identity on the network you can either let freenet generate a new random one for you or enter an existing ssk uri pair for example if you own a freesite you can re use it s uri to show others that your identity belongs to your freesite if m request is part set generate randomssk html node p chooseur ibox add child p p add child input new string type name value checked new string radio generate randomssk true checked p add child generate a new random ssk keypair for the identity p chooseur ibox add child p p add child input new string type name value new string radio generate randomssk false p add child i want to use an existing ssk uri keypair for the identity else assert randomssk false html node p chooseur ibox add child p p add child input new string type name value checked new string radio generate randomssk false checked p add child i want to use an existing ssk uri keypair for the identity if requestur iproblem null p add child p style color red add child request uri error requestur iproblem get localized message if insertur iproblem null p add child p style color red add child insert uri error insertur iproblem get localized message p add child please enter the ssk uri pair p add child br chooseur ibox add child request uri p add child input new string type name size value new string text requesturi 70 m request get part as string requesturi 256 p add child br chooseur ibox add child insert uri p add child input new string type name size value new string text inserturi 70 m request get part as string inserturi 256 step 2 nickname if m identityuri null m identity nickname null add hidden form data create form 2 html node choose name box get content box step 2 of 3 choose the nickname create form add child choose name box choose name box add child p the nickname of an identity cannot be changed after the identity has been created please choose it carefully you cannot use spaces and some special characters in the nickname html node p choose name box add child p if nickname problem null p add child p style color red add child nickname error nickname problem get localized message p add child nickname p add child input new string type name size value new string text nickname 50 m request get part as string nickname 50 step 3 preferences if m identityuri null m identity nickname null m identity publishes trust list null add hidden form data create form 3 html node choose prefs box get content box step 3 of 3 choose your preferences create form add child choose prefs box html node tl box get content box trust list choose prefs box add child tl box html node p tl box add child p trust lists are the p add child b fundament of freetalk p add child you can publish a p add child b trust value p add child for every identity in your trust list the trust value can be between 100 and 100 inclusive and is a measurement for how valuable you rate the messages of an identity if someone posts spam you can give a negative trust value if he writes useful posts you can assign a positive one p tl box add child p for every identity freetalk will accumulate trust values which it has received by other identities and calculate a p add child b score p add child a weighted average from those if the score of an identity is negative freetalk will not download messages from that identity anymore unless you tell it to do so therefore the purpose of the trust system is to p add child b prevent spam p add child but it is p add child b not to punish authors for having a different opinion than yours p add child please respect that when assigning trust values p tl box add child p here you can choose whether freetalk should publish a trust list for your identity it is generally a good idea because it helps the other users however you can tell freetalk not to publish your trust list if you are concernced that it might compromise your anonymity because the trust values among several of your identities might correlate p tl box add child p p add child input new string type name value checked new string checkbox publish trust list true checked p add child publish the trust list of the identitiy if m identityuri null m identity nickname null m identity publishes trust list null add hidden form data create form 4 try wot own identity id wot own identity m freetalk get identity manager create own identity m identity nickname m identity publishes trust list true m identityuri 1 m identityuri 0 html node summary box get content box identity created create form add child summary box summary box add child a href self uri log in own identityid id getuid your identity was successfully created you can log in with it now catch exception e html node error box get alert box sorry there was a problem creating your identity create form add child error box error box add child p e get localized message return todo instead of just returning provide a go back button if creation fails etc create form add child input new string type name value new string submit submit continue makecreateidentitybox htmlnode createbox addcontentbox htmlnode createform addformchild createbox self_uri createidentity createidentity requesturiproblem inserturiproblem nicknameproblem previousstep mrequest ispartset parseint mrequest getpartasstring mrequest ispartset generaterandomssk mrequest getpartasstring generaterandomssk midentityuri mfreetalk getpluginrespirator gethlsimpleclient generatekeypair mrequest ispartset mrequest ispartset midentityuri midentityuri mrequest getpartasstring inserturiproblem midentityuri mrequest getpartasstring requesturiproblem inserturiproblem requesturiproblem midentityuri mrequest ispartset midentitynickname mrequest getpartasstring wotidentity validatenickname midentitynickname nicknameproblem midentitynickname previousstep ispartset publishtrustlist mrequest ispartset publishtrustlist midentitypublishestrustlist mrequest getpartasstring publishtrustlist midentitypublishestrustlist midentityuri htmlnode chooseuribox getcontentbox createform addchild chooseuribox chooseuribox addchild mrequest ispartset generaterandomssk htmlnode chooseuribox addchild addchild generaterandomssk addchild chooseuribox addchild addchild generaterandomssk addchild htmlnode chooseuribox addchild addchild generaterandomssk addchild requesturiproblem addchild addchild requesturiproblem getlocalizedmessage inserturiproblem addchild addchild inserturiproblem getlocalizedmessage addchild addchild chooseuribox addchild addchild mrequest getpartasstring addchild chooseuribox addchild addchild mrequest getpartasstring midentityuri midentitynickname addhiddenformdata createform htmlnode choosenamebox getcontentbox createform addchild choosenamebox choosenamebox addchild htmlnode choosenamebox addchild nicknameproblem addchild addchild nicknameproblem getlocalizedmessage addchild addchild mrequest getpartasstring midentityuri midentitynickname midentitypublishestrustlist addhiddenformdata createform htmlnode chooseprefsbox getcontentbox createform addchild chooseprefsbox htmlnode tlbox getcontentbox chooseprefsbox addchild tlbox htmlnode tlbox addchild addchild addchild addchild addchild tlbox addchild addchild addchild addchild addchild addchild addchild tlbox addchild tlbox addchild addchild publishtrustlist addchild midentityuri midentitynickname midentitypublishestrustlist addhiddenformdata createform wotownidentity wotownidentity mfreetalk getidentitymanager createownidentity midentitynickname midentitypublishestrustlist midentityuri midentityuri htmlnode summarybox getcontentbox createform addchild summarybox summarybox addchild self_uri login ownidentityid htmlnode errorbox getalertbox createform addchild errorbox errorbox addchild getlocalizedmessage createform addchild stores the form data which the user has already specified as hidden elements param my form the html node of the parent form private void add hidden form data html node my form string step my form add child input new string type name value new string hidden step step if m identityuri null my form add child input new string type name value new string hidden inserturi m identityuri 0 to string my form add child input new string type name value new string hidden requesturi m identityuri 1 to string if m identity nickname null my form add child input new string type name value new string hidden nickname m identity nickname if m identity publishes trust list null my form add child input new string type name value new string hidden publish trust list m identity publishes trust list to string myform htmlnode addhiddenformdata htmlnode myform myform addchild midentityuri myform addchild midentityuri tostring myform addchild midentityuri tostring midentitynickname myform addchild midentitynickname midentitypublishestrustlist myform addchild publishtrustlist midentitypublishestrustlist tostring public chosen block sendable request item token key key client key ckey boolean local request only boolean cache local requests boolean ignore store request scheduler sched this token token this key key this ckey ckey this local request only local request only this cache local requests cache local requests this ignore store ignore store chosenblock sendablerequestitem clientkey localrequestonly cachelocalrequests ignorestore requestscheduler localrequestonly localrequestonly cachelocalrequests cachelocalrequests ignorestore ignorestore public abstract boolean is persistent ispersistent public abstract boolean is persistent public abstract boolean is cancelled ispersistent iscancelled public abstract boolean is cancelled public abstract void on failure low level put exception e client context context iscancelled onfailure lowlevelputexception clientcontext public abstract void on failure low level put exception e client context context public abstract void on insert success client context context onfailure lowlevelputexception clientcontext oninsertsuccess clientcontext public abstract void on insert success client context context public abstract void on failure low level get exception e client context context oninsertsuccess clientcontext onfailure lowlevelgetexception clientcontext the actual data delivery goes through crs trip pending key this is just a notification for book keeping purposes we call the scheduler to tell it that the request succeeded so that it can be rescheduled soon for more requests param context might be useful trippendingkey public abstract void on fetch success client context context public abstract short get priority onfetchsuccess clientcontext getpriority public abstract short get priority public boolean send node client core core request scheduler sched client context context sched get context return get sender context send core sched context this getpriority nodeclientcore requestscheduler clientcontext getcontext getsender public abstract sendable request sender get sender client context context sendablerequestsender getsender clientcontext public abstract sendable request sender get sender client context context public void on dumped token dump sendablerequestsender getsender clientcontext ondumped public class database constructor of database this method initialize database if it not initialized yet starting from 2 72 version of perst net it supports automatic creation of table descriptors when database class is used so now it is not necessary to explicitly create tables and indices the database class will create them itself on demand indexable attribute should be used to mark key fields for which index should be created table descriptor is created when instance of the correspondent class is first time stored in the database perst creates table descriptors for all derived classes up to the root java lang object class param storage opened storage storage should be either empty non initialized either previously initialized by the this method it is not possible to open storage with root object other than table index created by this constructor param multithreaded code true code if database should support concurrent access to the data from multiple threads public database storage storage boolean multithreaded this storage multithreaded true null constructor of database this method initialize database if it not initialized yet param storage opened storage storage should be either empty non initialized either previously initialized by the this method it is not possible to open storage with root object other than table index created by this constructor param multithreaded code true code if database should support concurrent access to the data from multiple threads param auto register tables automatically create tables descriptors for instances of new param helper helper for full text index classes inserted in the database public database storage storage boolean multithreaded boolean auto register tables full text search helper helper this storage storage this multithreaded multithreaded this auto register tables auto register tables if multithreaded storage set property perst alternative btree boolean true i persistent root storage get root boolean schema updated false if root instanceof index backward compatibility begin transaction metadata new metadata storage index root helper storage set root metadata schema updated true else if root null begin transaction metadata new metadata storage helper storage set root metadata schema updated true else metadata metadata root iterator iterator metadata metaclasses entry iterator tables new hash map class table while iterator has next map entry map map entry iterator next table table table map get value class cls class descriptor load class storage string map get key table set class cls tables put cls table schema updated add indices table cls if schema updated commit transaction autoregistertables autoregistertables fulltextsearchhelper autoregistertables autoregistertables setproperty ipersistent getroot schemaupdated begintransaction setroot schemaupdated begintransaction setroot schemaupdated entryiterator hashmap hasnext getvalue classdescriptor loadclass getkey setclass schemaupdated addindices schemaupdated committransaction constructor of single threaded database this method initialize database if it not initialized yet param storage opened storage storage should be either empty non initialized either previously initialized by the this method it is not possible to open storage with root object other than table index created by this constructor public database storage storage this storage false begin transaction public void begin transaction if multithreaded storage begin thread transaction storage serializable transaction begintransaction beginthreadtransaction serializable_transaction commit transaction public void commit transaction if multithreaded storage end thread transaction else storage commit committransaction endthreadtransaction rollback transaction public void rollback transaction if multithreaded storage rollback thread transaction else storage rollback rollbacktransaction rollbackthreadtransaction create table for the specified class this function does nothing if table for such class already exists param table class corresponding to the table return code true code if table is created code false code if table alreay exists deprecated since version 2 75 of perst it is not necessary to create table and index descriptors explicitly them are automatically create when object is inserted in the database first time to mark fields for which indices should be created use indexable annotation public boolean create table class table if multithreaded metadata exclusive lock if tables get table null table t new table t extent storage create set t indices storage create link t indices map new hash map t set class table tables put table t metadata metaclasses put table get name t add indices t table return true return false createtable exclusivelock createset createlink indicesmap hashmap setclass getname addindices private boolean add indices table table class cls boolean schema updated false for field f cls get declared fields indexable idx indexable f get annotation indexable class if idx null schema updated create index table cls f get name idx unique idx case insensitive return schema updated addindices schemaupdated getdeclaredfields getannotation schemaupdated createindex getname caseinsensitive schemaupdated drop table associated with this class do nothing if there is no such table in the database param table class corresponding to the table return code true code if table is deleted code false code if table is not found public boolean drop table class table if multithreaded metadata exclusive lock if tables remove table null metadata metaclasses remove table get name return true return false droptable exclusivelock getname add new record to the table record is inserted in table corresponding to the class of the object record will be automatically added to all indices existed for this table if there is not table associated with class of this object then database will search for table associated with superclass and so on param record object to be inserted in the table return code true code if record was successfully added to the table code false code if there is already such record object with the same id in the table or there is some record with the same value of unique key field exception storage error class not found exception is thrown if there is no table corresponding to record class public t extends i persistent boolean add record t record return add record record get class record storageerror class_not_found ipersistent addrecord addrecord getclass private table locate table class cls boolean exclusive return locate table cls exclusive true locatetable locatetable private table locate table class cls boolean exclusive boolean should exist table table null if multithreaded metadata shared lock for class c cls c null table tables get c null c c get superclass if table null if should exist throw new storage error storage error class not found cls get name return null if multithreaded if exclusive table extent exclusive lock else table extent shared lock return table locatetable shouldexist sharedlock getsuperclass shouldexist storageerror storageerror class_not_found getname exclusivelock sharedlock private void register table class cls if multithreaded metadata shared lock if auto register tables boolean exclusive lock set false for class c cls c object class c c get superclass table t tables get c if t null if exclusive lock set metadata unlock try to avoid deadlock caused by concurrent insertion of objects exclusive lock set true create table c registertable sharedlock autoregistertables exclusivelockset getsuperclass exclusivelockset exclusivelockset createtable update full text index for modified record param record updated record public t extends i persistent void update full text index t record if multithreaded metadata full text index exclusive lock if record instanceof full text searchable metadata full text index add full text searchable record else string buffer full text new string buffer for class c record get class c null c c get superclass table t tables get c if t null for field f t full text indexable fields object text try text f get record catch illegal access exception x throw new illegal access error if text null full text append full text append text to string metadata full text index add record new string reader full text to string null ipersistent updatefulltextindex fulltextindex exclusivelock fulltextsearchable fulltextindex fulltextsearchable stringbuffer fulltext stringbuffer getclass getsuperclass fulltextindexablefields illegalaccessexception illegalaccesserror fulltext fulltext tostring fulltextindex stringreader fulltext tostring add new record to the specified table record is inserted in table corresponding to the specified class record will be automatically added to all indices existed for this table param table class corresponding to the table param record object to be inserted in the table return code true code if record was successfully added to the table code false code if there is already such record object with the same id in the table or there is some record with the same value of unique key field exception storage error class not found exception is thrown if there is no table corresponding to record class public t extends i persistent boolean add record class table t record boolean added false boolean found false register table table array list was inserted in new array list string buffer full text new string buffer for class c table c null c c get superclass table t tables get c if t null found true if multithreaded t extent exclusive lock if t extent add record was inserted in add t extent iterator iterator t indices map values iterator while iterator has next field index index field index iterator next if index put record was inserted in add index else iterator was inserted in iterator while iterator has next object idx iterator next if idx instanceof i persistent set i persistent set idx remove record else field index idx remove record return false for field f t full text indexable fields object text try text f get record catch illegal access exception x throw new illegal access error if text null full text append full text append text to string added true if found throw new storage error storage error class not found table get name if record instanceof full text searchable full text length 0 if multithreaded metadata full text index exclusive lock if record instanceof full text searchable metadata full text index add full text searchable record else metadata full text index add record new string reader full text to string null return added storageerror class_not_found ipersistent addrecord registertable arraylist wasinsertedin arraylist stringbuffer fulltext stringbuffer getsuperclass exclusivelock wasinsertedin indicesmap hasnext fieldindex fieldindex wasinsertedin wasinsertedin hasnext ipersistentset ipersistentset fieldindex fulltextindexablefields illegalaccessexception illegalaccesserror fulltext fulltext tostring storageerror storageerror class_not_found getname fulltextsearchable fulltext fulltextindex exclusivelock fulltextsearchable fulltextindex fulltextsearchable fulltextindex stringreader fulltext tostring delete record from the table record is removed from the table corresponding to the class of the object record will be automatically added to all indices existed for this table if there is not table associated with class of this object then database will search for table associated with superclass and so on object represented the record will be also deleted from the storage param record object to be deleted from the table return code true code if record was successfully deleted from the table code false code if there is not such record object with the same id in the table exception storage error class not found exception is thrown if there is no table corresponding to record class public t extends i persistent boolean delete record t record return delete record record get class record storageerror class_not_found ipersistent deleterecord deleterecord getclass delete record from the specified table record is removed from the table corresponding to the specified class record will be automatically added to all indices existed for this table object represented the record will be also deleted from the storage param table class corresponding to the table param record object to be deleted from the table return code true code if record was successfully deleted from the table code false code if there is not such record object with the same id in the table exception storage error class not found exception is thrown if there is no table corresponding to specified class public t extends i persistent boolean delete record class table t record boolean removed false if multithreaded metadata shared lock boolean full text indexed false for class c table c null c c get superclass table t tables get c if t null if multithreaded t extent exclusive lock if t extent remove record iterator iterator t indices map values iterator while iterator has next field index index field index iterator next index remove record if t full text indexable fields size 0 full text indexed true removed true if removed if record instanceof full text searchable full text indexed if multithreaded metadata full text index exclusive lock metadata full text index delete record record deallocate return removed storageerror class_not_found ipersistent deleterecord sharedlock fulltextindexed getsuperclass exclusivelock indicesmap hasnext fieldindex fieldindex fulltextindexablefields fulltextindexed fulltextsearchable fulltextindexed fulltextindex exclusivelock fulltextindex add new index to the table if such index already exists this method does nothing param table class corresponding to the table param key field of the class to be indexed param unique if index is unique or not exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if index is created code false code if index already exists deprecated since version 2 75 of perst it is not necessary to create table and index descriptors explicitly them are automatically create when object is inserted in the database first time to mark fields for which indices should be created use indexable annotation public boolean create index class table string key boolean unique return create index locate table table true table key unique false storageerror class_not_found createindex createindex locatetable add new index to the table if such index already exists this method does nothing param table class corresponding to the table param key field of the class to be indexed param unique if index is unique or not param case insensitive if string index is case insensitive exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if index is created code false code if index already exists deprecated since version 2 75 of perst it is not necessary to create table and index descriptors explicitly them are automatically cerate when objct is inserted in the database first time to mark fields for which indices should be created use indexable annotaion public boolean create index class table string key boolean unique boolean case insensitive return create index locate table table true table key unique case insensitive caseinsensitive storageerror class_not_found createindex caseinsensitive createindex locatetable caseinsensitive private boolean create index table t class c string key boolean unique boolean case insensitive if t indices map get key null field index index storage create field index c key unique case insensitive t indices map put key index t indices add index return true return false createindex caseinsensitive indicesmap fieldindex createfieldindex caseinsensitive indicesmap drop index for the specified table and key does nothing if there is no such index param table class corresponding to the table param key field of the class to be indexed exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if index is deleted code false code if index is not found public boolean drop index class table string key table t locate table table true field index index field index t indices map remove key if index null t indices remove t indices index of index return true return false storageerror class_not_found dropindex locatetable fieldindex fieldindex indicesmap indexof get indices for the specified table param table class corresponding to the table return map of table indices public hash map get indices class table table t locate table table true false return t null new hash map t indices map hashmap getindices locatetable hashmap indicesmap exclude record from specified index this method is needed to perform update of indexed field key before updating the record it is necessary to exclude it from indices which keys are affected after updating the field record should be reinserted in these indices using include in index method p if there is not table associated with class of this object then database will search for table associated with superclass and so on p this method does nothing if there is no index for the specified field param record object to be excluded from the specified index param key name of the indexed field exception storage error class not found exception is thrown if there is no table corresponding to record class return code true code if record is excluded from index code false code if there is no such index public boolean exclude from index i persistent record string key return exclude from index record get class record key includeinindex storageerror class_not_found excludefromindex ipersistent excludefromindex getclass exclude record from specified index this method is needed to perform update of indexed field key before updating the record it is necessary to exclude it from indices which keys are affected after updating the field record should be reinserted in these indices using include in index method p if there is not table associated with class of this object then database will search for table associated with superclass and so on p this method does nothing if there is no index for the specified field param table class corresponding to the table param record object to be excluded from the specified index param key name of the indexed field exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if record is excluded from index code false code if there is no such index public boolean exclude from index class table i persistent record string key table t locate table table true field index index field index t indices map get key if index null index remove record return true return false includeinindex storageerror class_not_found excludefromindex ipersistent locatetable fieldindex fieldindex indicesmap include record in the specified index this method is needed to perform update of indexed field key before updating the record it is necessary to exclude it from indices which keys are affected using exclude from index method after updating the field record should be reinserted in these indices using this method p if there is not table associated with class of this object then database will search for table associated with superclass and so on p this method does nothing if there is no index for the specified field param record object to be excluded from the specified index param key name of the indexed field exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if record is included in index code false code if there is no such index public boolean include in index i persistent record string key return include in index record get class record key excludefromindex storageerror class_not_found includeinindex ipersistent includeinindex getclass include record in the specified index this method is needed to perform update of indexed field key before updating the record it is necessary to exclude it from indices which keys are affected using exclude from index method after updating the field record should be reinserted in these indices using this method p if there is not table associated with class of this object then database will search for table associated with superclass and so on p this method does nothing if there is no index for the specified field param table class corresponding to the table param record object to be excluded from the specified index param key name of the indexed field exception storage error class not found exception is thrown if there is no table corresponding to the specified class return code true code if record is included in index code false code if there is no such index public boolean include in index class table i persistent record string key table t locate table table true field index index field index t indices map get key if index null index put record return true return false excludefromindex storageerror class_not_found includeinindex ipersistent locatetable fieldindex fieldindex indicesmap select record from specified table param table class corresponding to the table param predicate search predicate exception storage error class not found exception is thrown if there is no table corresponding to the specified class return iterator through selected records this iterator doesn t support remove method exception compile error exception is thrown if predicate is not valid jsql exception exception jsql runtime exception exception is thrown if there is runtime error during query execution public t extends i persistent iterable iterator t select class table string predicate return select table predicate false storageerror class_not_found compileerror jsqlruntimeexception ipersistent iterableiterator select record from specified table param table class corresponding to the table param predicate search predicate param for update code true code if records are selected for update in this case exclusive lock is set for the table to avoid deadlock exception storage error class not found exception is thrown if there is no table corresponding to the specified class return iterator through selected records this iterator doesn t support remove method exception compile error exception is thrown if predicate is not valid jsql exception exception jsql runtime exception exception is thrown if there is runtime error during query execution public t extends i persistent iterable iterator t select class table string predicate boolean for update query q prepare table predicate for update return q execute get records table forupdate storageerror class_not_found compileerror jsqlruntimeexception ipersistent iterableiterator forupdate forupdate getrecords prepare jsql query prepare is needed for queries with parameters also preparing query can improve speed if query will be executed multiple times using prepare it is compiled only once p to execute prepared query you should use query execute db get records xyz class method param table class corresponding to the table param predicate search predicate exception storage error class not found exception is thrown if there is no table corresponding to the specified class exception compile error exception is thrown if predicate is not valid jsql exception public t extends i persistent query t prepare class table string predicate return prepare table predicate false getrecords storageerror class_not_found compileerror ipersistent prepare jsql query prepare is needed for queries with parameters also preparing query can improve speed if query will be executed multiple times using prepare it is compiled only once p to execute prepared query you should use query execute db get records xyz class method param table class corresponding to the table param predicate search predicate param for update code true code if records are selected for update in this case exclusive lock is set for the table to avoid deadlock exception storage error class not found exception is thrown if there is no table corresponding to the specified class exception compile error exception is thrown if predicate is not valid jsql exception public t extends i persistent query t prepare class table string predicate boolean for update table t locate table table for update false query q storage create query q prepare table predicate while t null iterator iterator t indices map entry set iterator while iterator has next map entry entry map entry iterator next field index index field index entry get value string key string entry get key q add index key index t locate table t type get superclass for update false return q getrecords forupdate storageerror class_not_found compileerror ipersistent forupdate locatetable forupdate createquery indicesmap entryset hasnext fieldindex fieldindex getvalue getkey addindex locatetable getsuperclass forupdate get iterator through all table records param table class corresponding to the table return iterator through all table records exception storage error class not found exception is thrown if there is no table corresponding to the specified class public t extends i persistent iterable iterator t get records class table return get records table false storageerror class_not_found ipersistent iterableiterator getrecords getrecords get iterator through all table records param table class corresponding to the table param for update code true code if records are selected for update in this case exclusive lock is set for the table to avoid deadlock return iterator through all table records exception storage error class not found exception is thrown if there is no table corresponding to the specified class public t extends i persistent iterable iterator t get records class table boolean for update table t locate table table for update false return new iterator wrapper t t null new linked list t iterator t extent iterator forupdate storageerror class_not_found ipersistent iterableiterator getrecords forupdate locatetable forupdate iteratorwrapper linkedlist get storage associated with this database return underlying storage public storage get storage return storage getstorage parse and execute full text search query param query text of the query oaram language language if the query param max results maximal amount of selected documents param time limit limit for query execution time erturn result of query execution ordered by rank or null in case of empty or incorrect query public full text search result search string query string language int max results int time limit if multithreaded metadata full text index shared lock return metadata full text index search query language max results time limit maxresults timelimit fulltextsearchresult maxresults timelimit fulltextindex sharedlock fulltextindex maxresults timelimit execute full text search query param query prepared query param max results maximal amount of selected documents param time limit limit for query execution time erturn result of query execution ordered by rank or null in case of empty or incorrect query public full text search result search full text query query int max results int time limit if multithreaded metadata full text index shared lock return metadata full text index search query max results time limit maxresults timelimit fulltextsearchresult fulltextquery maxresults timelimit fulltextindex sharedlock fulltextindex maxresults timelimit metadata storage storage index index full text search helper helper super storage metaclasses index full text index helper null storage create full text index helper storage create full text index fulltextsearchhelper fulltextindex createfulltextindex createfulltextindex metadata storage storage full text search helper helper super storage metaclasses storage create index string class true full text index helper null storage create full text index helper storage create full text index fulltextsearchhelper createindex fulltextindex createfulltextindex createfulltextindex metadata void set class class cls type cls full text indexable fields new array list field for field f cls get declared fields full text indexable idx full text indexable f get annotation full text indexable class if idx null try f set accessible true catch exception x full text indexable fields add f setclass fulltextindexablefields arraylist getdeclaredfields fulltextindexable fulltextindexable getannotation fulltextindexable setaccessible fulltextindexablefields public void on load for int i indices size i 0 field index index field index indices get i indices map put index get key fields 0 get name index onload fieldindex fieldindex indicesmap getkeyfields getname public class util public static bucket fetch bucket string uri plugin respirator plugin respirator throws fetch exception malformedurl exception try local file first file file new file uri if file exists file can read return new file bucket file true false false false false freeneturi try to fetch from freenet high level simple client hlsc plugin respirator gethl simple client freeneturi u new freeneturi uri fetch result res while true try res hlsc fetch u break catch fetch exception e if e newuri null u e newuri continue else throw e return res as bucket fetchbucket pluginrespirator pluginrespirator fetchexception malformedurlexception canread filebucket highlevelsimpleclient pluginrespirator gethlsimpleclient fetchresult fetchexception asbucket public ssdp response set version http version 11 ssdpresponse setversion version_11 public void setst string value set header http st value setheader public string getst return get header value http st getheadervalue public void set location string value set header http location value setlocation setheader public string get location return get header value http location getlocation getheadervalue public void setusn string value set header http usn value setheader public string getusn return get header value http usn getheadervalue public void setmyname string value set header http myname value setheader public string getmyname return get header value http myname getheadervalue public void set lease time int len set header http cache control max age integer to string len setleasetime setheader cache_control tostring public int get lease time string cache ctrl get header value http cache control return ssdp get lease time cache ctrl getleasetime cachectrl getheadervalue cache_control getleasetime cachectrl public string get header string builder str new string builder str append get status line string str append get header string str append http crlf for intel u pnp control points return str to string getheader stringbuilder stringbuilder getstatuslinestring getheaderstring upnp tostring private static class precalc buffer fill extends native thread public precalc buffer fill super diffie hellman precalc native thread min priority false set daemon true precalcbufferfill nativethread precalcbufferfill nativethread min_priority setdaemon override public void run super run while true while precalc buffer size precalc max precalc buffer push gen params synchronized precalc buffer notify a waiting thread that new data is available precalc buffer notify synchronized precalcer wait obj try do not set the thread priority here because the thread may have been stopped while holding the precalcer wait obj lock the stop causes the thread group to be cleared and set priority to throw a npe precalcer wait obj wait precalc timeout todo this timeout might very well be unneccsary catch interrupted exception ie ignored precalcbuffer precalc_max precalcbuffer genparams precalcbuffer precalcbuffer precalcerwaitobj precalcerwaitobj setpriority precalcerwaitobj precalc_timeout interruptedexception public static void init random random r random precalc thread start precalcthread will ask the precalc thread to refill the buffer if necessary private static void ask refill if the buffer size is below the threshold then wake the precalc thread if precalc buffer size precalc resume synchronized precalcer wait obj precalcer wait obj notify askrefill precalcbuffer precalc_resume precalcerwaitobj precalcerwaitobj create a diffie hellman light context public static diffie hellman light context generate light context long time1 system current time millis native big integer params get params long time2 system current time millis if time2 time1 300 logger error null diffie hellman generate light context time2 is more than 300ms after time1 time2 time1 return new diffie hellman light context params 0 params 1 diffiehellmanlightcontext diffiehellmanlightcontext generatelightcontext currenttimemillis nativebiginteger getparams currenttimemillis diffiehellman generatelightcontext diffiehellmanlightcontext public static native big integer get params synchronized precalc buffer ensure that we will have something to pop at least pretty soon ask refill if precalc buffer is empty return precalc buffer pop logger normal diffie hellman class diffie hellman had to generate a parameter on thread report if that happens often return gen params nativebiginteger getparams precalcbuffer askrefill precalcbuffer isempty precalcbuffer diffiehellman diffiehellman genparams private static native big integer gen params native big integer params new native big integer 2 don t need native big integer do params 0 new native big integer 256 r params 1 native big integer group getg mod pow params 0 group getp while diffie hellman checkdh exponential validity diffie hellman class params 1 return params nativebiginteger genparams nativebiginteger nativebiginteger nativebiginteger nativebiginteger nativebiginteger modpow diffiehellman checkdhexponentialvalidity diffiehellman check the validity of a dh exponential param a big integer the exponential to test return a boolean whether the dh exponential provided is acceptable or not see http securitytracker com alerts 2005 aug 1014739 html see http www it iitb ac in praj acads netsec final report pdf public static boolean checkdh exponential validity class caller big integer exponential int ones count 0 zeros count 0 ensure that we have at least 16 bits of each gender for int i 0 i exponential bit length i if exponential test bit i ones count else zeros count if ones count 16 zeros count 16 logger error caller the provided exponential contains zeros count zeros and ones count ones wich is unacceptable return false ensure that g x 2 24 if min exponential value compare to exponential 1 logger error caller the provided exponential is smaller than 2 24 which is unacceptable return false ensure that g x p 2 24 if max exponential value compare to exponential 1 logger error diffie hellman class the provided exponential is bigger than p 2 24 which is unacceptable return false return true biginteger finalreport checkdhexponentialvalidity biginteger onescount zeroscount bitlength testbit onescount zeroscount onescount zeroscount zeroscount onescount min_exponential_value compareto max_exponential_value compareto diffiehellman public static dh group get group return group dhgroup getgroup return the length in bytes of the modulus exponentials will fit into this length public static int modulus length in bytes int bit length get group getp bit length return bit length 8 bit length 8 0 1 0 moduluslengthinbytes bitlength getgroup bitlength bitlength bitlength public fcp plugin reply string pluginname string identifier2 simple field set fs bucket bucket2 bucket bucket2 if bucket null data length 1 else bucket set read only data length bucket size plugname pluginname identifier identifier2 plugparams fs fcppluginreply simplefieldset datalength setreadonly datalength override string get identifier return identifier getidentifier override boolean is global return false isglobal override long data length return data length datalength datalength override string get end string if data length 0 return data else return end message getendstring datalength endmessage override public simple field set get field set simple field set sfs new simple field set true sfs put single plugin name plugname sfs put single identifier identifier if data length 0 sfs put data length data length sfs put replies plugparams return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle pluginname putsingle datalength datalength datalength override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message name goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception suppress warnings serial public class node need restart exception extends config exception public node need restart exception string msg super msg suppresswarnings nodeneedrestartexception configexception nodeneedrestartexception static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public static network interface create int port string bind to string allowed hosts executor executor boolean ignore unbindableip6 throws io exception network interface iface new network interface port allowed hosts executor try iface set bind to bind to ignore unbindableip6 catch io exception e try iface close catch io exception e1 logger error network interface class caught e1 closing after catching e binding while constructing e1 ignore throw e return iface networkinterface bindto allowedhosts ignoreunbindableip6 ioexception networkinterface networkinterface allowedhosts setbindto bindto ignoreunbindableip6 ioexception ioexception networkinterface creates a new network interface that can bind to several addresses and allows connection filtering on ip address level param bind to a comma separated list of addresses to bind to param allowed hosts a comma separated list of allowed addresses protected network interface int port string allowed hosts executor executor throws io exception this port port this allowed hosts new allowed hosts allowed hosts this executor executor bindto allowedhosts networkinterface allowedhosts ioexception allowedhosts allowedhosts allowedhosts protected server socket create server socket throws io exception return new server socket serversocket createserversocket ioexception serversocket sets the list of ip address this network interface binds to param bind to a comma separated list of ip address to bind to public void set bind to string bind to boolean ignore unbindableip6 throws io exception if bind to null bind to equals bind to network interface default bind to string tokenizer bind to tokens new string tokenizer bind to list string bind to token list new array list string while bind to tokens has more tokens bind to token list add bind to tokens next token trim stop the old acceptors for int acceptor index 0 acceptor count acceptors size acceptor index acceptor count acceptor index acceptor acceptor acceptors get acceptor index try acceptor close catch io exception e swallow exception synchronized sync object while running acceptors 0 try sync object wait catch interrupted exception e acceptors clear for int server socket index 0 server socket index bind to token list size server socket index server socket server socket create server socket inet socket address addr null try addr new inet socket address bind to token list get server socket index port server socket set reuse address true server socket bind addr catch socket exception e if ignore unbindableip6 addr null addr get address instanceof inet6 address continue else throw e acceptor acceptor new acceptor server socket acceptors add acceptor set so timeout timeout synchronized sync object for acceptor acceptor this acceptors executor execute acceptor network interface acceptor for acceptor server socket bindto setbindto bindto ignoreunbindableip6 ioexception bindto bindto bindto networkinterface default_bind_to stringtokenizer bindtotokens stringtokenizer bindto bindtotokenlist arraylist bindtotokens hasmoretokens bindtotokenlist bindtotokens nexttoken acceptorindex acceptorcount acceptorindex acceptorcount acceptorindex acceptorindex ioexception syncobject runningacceptors syncobject interruptedexception serversocketindex serversocketindex bindtotokenlist serversocketindex serversocket serversocket createserversocket inetsocketaddress inetsocketaddress bindtotokenlist serversocketindex serversocket setreuseaddress serversocket socketexception ignoreunbindableip6 getaddress inet6address serversocket setsotimeout syncobject serversocket public void set allowed hosts string allowed hosts this allowed hosts set allowed hosts allowed hosts setallowedhosts allowedhosts allowedhosts setallowedhosts allowedhosts sets the so timeout value on the server sockets param timeout the timeout in milliseconds code 0 code to disable throws socket exception if the so timeout value can not be set see server socket set so timeout int public void set so timeout int timeout throws socket exception for acceptor acceptor acceptors acceptor set so timeout timeout this timeout timeout so_timeout socketexception so_timeout serversocket setsotimeout setsotimeout socketexception setsotimeout waits for a connection if a timeout has been set using link set so timeout int and no connection is established this method will return after the specified timeout has been expired throwing a link socket timeout exception if no timeout has been set this method will wait until a connection has been established return the socket that is connected to the client or null if the timeout has expired waiting for a connection public socket accept synchronized sync object while accepted sockets size 0 if shutdown return null if wrapper manager has shutdown hook been triggered return null if acceptors size 0 return null try sync object wait timeout catch interrupted exception ie1 if timeout 0 accepted sockets size 0 return null return accepted sockets remove 0 setsotimeout sockettimeoutexception syncobject acceptedsockets wrappermanager hasshutdownhookbeentriggered syncobject interruptedexception acceptedsockets acceptedsockets closes this interface and all underlying server sockets throws io exception if an i o exception occurs see server socket close public void close throws io exception io exception exception null shutdown true for acceptor acceptor acceptors try acceptor close catch io exception ioe1 exception ioe1 synchronized sync object sync object notify all if exception null throw exception ioexception serversocket ioexception ioexception ioexception syncobject syncobject notifyall gets called by an acceptor if it has stopped private void acceptor stopped synchronized sync object running acceptors sync object notify all acceptorstopped syncobject runningacceptors syncobject notifyall creates a new acceptor on the specified server socket param server socket the server socket to listen on public acceptor server socket server socket this server socket server socket serversocket serversocket serversocket serversocket serversocket sets the so timeout value on this acceptor s server socket param timeout the timeout in milliseconds or code 0 code to disable throws socket exception if the so timeout value can not be set see server socket set so timeout int public void set so timeout int timeout throws socket exception server socket set so timeout timeout so_timeout socketexception so_timeout serversocket setsotimeout setsotimeout socketexception serversocket setsotimeout closes this acceptor and the underlying server socket throws io exception if an i o exception occurs see server socket close public void close throws io exception closed true server socket close ioexception serversocket ioexception serversocket main method that accepts connections and checks the address against the list of allowed hosts see network interface allowed hosts public void run freenet support logger os thread logpid this while closed try socket client socket server socket accept inet address client address client socket get inet address if logminor logger minor acceptor class connection from client address address type client address type address identifier get address type client address get host address check if the ip address is allowed if allowed hosts allowed client address type client address synchronized sync object accepted sockets add client socket sync object notify all else try client socket close catch io exception ioe1 logger normal acceptor class denied connection to client address catch socket timeout exception ste1 if logminor logger minor this timeout catch io exception ioe1 if logminor logger minor this caught ioe1 network interface this acceptor stopped networkinterface allowedhosts osthread clientsocket serversocket inetaddress clientaddress clientsocket getinetaddress clientaddress addresstype clientaddresstype addressidentifier getaddresstype clientaddress gethostaddress allowedhosts clientaddresstype clientaddress syncobject acceptedsockets clientsocket syncobject notifyall clientsocket ioexception clientaddress sockettimeoutexception ioexception networkinterface acceptorstopped public string get allowed hosts return allowed hosts get allowed hosts getallowedhosts allowedhosts getallowedhosts private final long m size size in bytes public attachment freeneturi myuri long my size muri myuri m size my size msize mysize msize mysize public freeneturi geturi return muri public long get size return m size getsize msize get a list of fields which the database should create an index on public static string get indexed fields return new string mid indexed because it is our primary key m threadid indexed for being able to query all messages of a thread m parentid indexed for being able to get all replies to a message m fetch date indexed because frost needs to query for all messages after the time it has last done so getindexedfields mthreadid mparentid mfetchdate protected message messageuri newuri freeneturi new realuri string newid message list new message list messageuri new threaduri messageuri new parenturi set board new boards board new reply to board ft identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception we only assert instead of throwing because the constructor is protected and the construct function should verify this assert newuri null arrays equals newuri get freeneturi get routing key new author get requesturi get routing key fixme assert new message list get author new author fixme assert new realuri null new message list contains new realuri verifyid new author newid if new parenturi null new threaduri null logger error this message with parent uri but without thread uri created newuri if new boards is empty throw new invalid parameter exception no boards in message newuri if new reply to board null new boards contains new reply to board logger error this message created with reply to board not being in new boards newuri new boards add new reply to board muri newuri m realuri new realuri m message list new message list m author new author mid newid m parenturi new parenturi m parentid m parenturi null m parenturi get messageid null if a message has no thread uri specified this is a bug in the client which inserted it we store the parent uri as thread uri instead this will be corrected later by set parent m threaduri new threaduri null new threaduri m parenturi m threadid m threaduri null m threaduri get messageid m parentid m boards new boards to array new board new boards size arrays sort m boards m reply to board new reply to board m title make title valid new title m date new date todo check out whether date provides a function for getting the timezone and throw an exception if not utc m fetch date current timeutc get m text make text valid new text if is title valid m title throw new invalid parameter exception invalid message title in message newuri if is text valid m text throw new invalid parameter exception invalid message text in message newuri m attachments new attachments null null new attachments to array new attachment new attachments size newrealuri messagelist newmessagelist newthreaduri newparenturi newboards newreplytoboard ftidentity newauthor newtitle newdate newtext newattachments invalidparameterexception getfreeneturi getroutingkey newauthor getrequesturi getroutingkey newmessagelist getauthor newauthor newrealuri newmessagelist newrealuri newauthor newparenturi newthreaduri newboards isempty invalidparameterexception newreplytoboard newboards newreplytoboard replytoboard newboards newboards newreplytoboard mrealuri newrealuri mmessagelist newmessagelist mauthor newauthor mparenturi newparenturi mparentid mparenturi mparenturi getmessageid setparent mthreaduri newthreaduri newthreaduri mparenturi mthreadid mthreaduri mthreaduri getmessageid mparentid mboards newboards toarray newboards mboards mreplytoboard newreplytoboard mtitle maketitlevalid newtitle mdate newdate mfetchdate currenttimeutc mtext maketextvalid newtext istitlevalid mtitle invalidparameterexception istextvalid mtext invalidparameterexception mattachments newattachments newattachments toarray newattachments has to be used after loading a ft board object from the database to initialize the transient fields public void initialize transient ext object container mydb message manager my message manager assert mydb null assert my message manager null db mydb m message manager my message manager ftboard initializetransient extobjectcontainer messagemanager mymessagemanager mymessagemanager mmessagemanager mymessagemanager verifies that the given message id begins with the routing key of the author throws invalid parameter exception if the id is not valid public static void verifyid ft identity author string id throws invalid parameter exception if id ends with base64 encode author get requesturi get routing key false throw new invalid parameter exception illegal id id invalidparameterexception ftidentity invalidparameterexception endswith getrequesturi getroutingkey invalidparameterexception get the uri of the message public messageuri geturi not synchronized because only own message might change the uri return muri ownmessage public string getid not synchronized because only own message might change the id return mid ownmessage get the messageuri of the thread this message belongs to throws no such message exception public synchronized messageuri get threaduri throws no such message exception if m threaduri null throw new no such message exception return m threaduri nosuchmessageexception getthreaduri nosuchmessageexception mthreaduri nosuchmessageexception mthreaduri get the id of the thread this message belongs to should not be used by the user interface for querying the database as the parent thread might not have been downloaded yet use get thread getid instead return the id of the message s parent thread throws no such message exception if the message is a thread itself public synchronized string get threadid throws no such message exception if m threadid null throw new no such message exception return m threadid getthread nosuchmessageexception getthreadid nosuchmessageexception mthreadid nosuchmessageexception mthreadid used internally for correcting the thread ur is of messages which have specified them wrong in the xml protected synchronized void set threaduri andid messageuri new threaduri m threaduri new threaduri m threadid m threaduri get messageid store uris setthreaduriandid newthreaduri mthreaduri newthreaduri mthreadid mthreaduri getmessageid get the messageuri to which this message is a reply null if the message is a thread public messageuri get parenturi throws no such message exception if m parenturi null throw new no such message exception return m parenturi getparenturi nosuchmessageexception mparenturi nosuchmessageexception mparenturi public string get parentid throws no such message exception if m parentid null throw new no such message exception return m parentid getparentid nosuchmessageexception mparentid nosuchmessageexception mparentid public boolean is thread return m parenturi null isthread mparenturi get the boards to which this message was posted the boards are returned in alphabetical order the transient fields of the returned boards are initialized already public board get boards for board b m boards b initialize transient db m message manager return m boards getboards mboards initializetransient mmessagemanager mboards public board get reply to board return m reply to board getreplytoboard mreplytoboard get the author of the message public ft identity get author m author initialize transient db m message manager get identity manager return m author ftidentity getauthor mauthor initializetransient mmessagemanager getidentitymanager mauthor get the title of the message public string get title return m title gettitle mtitle get the date when the message was written in strong utc time strong public date get date return m date getdate mdate get the date when the message was fetched by freetalk public date get fetch date return m fetch date getfetchdate mfetchdate get the text of the message public string get text return m text gettext mtext get the attachments of the message in the order in which they were received public attachment get attachments return m attachments getattachments mattachments get the thread to which this message belongs the transient fields of the returned message will be initialized already this might not always return the real parent thread it will return the topmost parent message if the parent thread has not been downloaded yet public synchronized message get thread throws no such message exception todo find all usages of this function and check whether we should put the activate here and what the fitting depth is db activate this 3 if m thread null throw new no such message exception m thread initialize transient db m message manager return m thread getthread nosuchmessageexception mthread nosuchmessageexception mthread initializetransient mmessagemanager mthread public synchronized void set thread message new parent thread assert m thread null if new parent thread getid equals m threadid throw new illegal argument exception trying to set a message as thread which has the wrong id new parent thread getid if new parent thread is thread throw new illegal argument exception trying to set thread not a thread m thread new parent thread store setthread newparentthread mthread newparentthread mthreadid illegalargumentexception newparentthread newparentthread isthread illegalargumentexception setthread mthread newparentthread get the message to which this message is a reply the transient fields of the returned message will be initialized already public synchronized message get parent throws no such message exception todo find all usages of this function and check whether we should put the activate here and what the fitting depth is db activate this 3 if m parent null throw new no such message exception m parent initialize transient db m message manager return m parent getparent nosuchmessageexception mparent nosuchmessageexception mparent initializetransient mmessagemanager mparent public synchronized void set parent message new parent if new parent getid equals m parentid throw new illegal argument exception trying to set a message as parent which has the wrong id new parent getid todo assert new parent contains at least one board which m boards contains m parent new parent check whether m threaduri id is correct if it is not adopt the thread uri id of the parent message and also set this on all our children and their children i thought about how to handle incorrect thread uri id for about 3 hours and it seems to me like this is the way to go requires lots of brainwork to imagine what side effects can happen due to incorrect thread uri id and the conclusion is that they must be corrected otherwise those messages will disappear in get all thread replies synchronized m parent string real threadid new parent is thread new parent getid m parent m threadid if real threadid equals m threadid logger error this correcting thread uri id of geturi it is unpredictable what messages will be affected by this code because we modify all children so unfortunately we should probably lock all changes to messages here synchronized message class if m parent is thread set threaduri andid m parent geturi set thread m parent else set threaduri andid m parent m threaduri use depth first search for setting the uri id on the children this is dangerous an attacker might cause very high memory usage if we do not ensure that we use dfs properly so that only 1 message must be in memory at once message child this boolean found child do found child false for message c child get children null if m threadid equals c m threadid db deactivate child 1 child c child set threaduri andid m threaduri found child true break if found child child this try child child get parent found child true catch no such message exception e logger error this should never happen while found child store setparent newparent newparent mparentid illegalargumentexception newparent newparent mboards mparent newparent mthreaduri getallthreadreplies mparent realthreadid newparent isthread newparent mparent mthreadid realthreadid mthreadid mparent isthread setthreaduriandid mparent setthread mparent setthreaduriandid mparent mthreaduri foundchild foundchild getchildren mthreadid mthreadid setthreaduriandid mthreaduri foundchild foundchild getparent foundchild nosuchmessageexception foundchild returns an iterator over the children of the message sorted descending by date the transient fields of the children will be initialized already suppress warnings unchecked public synchronized iterable message get children final board target board return new iterable message public iterator message iterator return new iterator message private iterator message iter private board board private message next board target board todo accelerate this query configure db4o to keep a per message date sorted index of children not very important for now since threads are usually small query q db query q constrain message class q descend m parent constrain this q descend m date order descending iter q execute iterator next iter has next iter next null public boolean has next if board null return next null while next null if arrays binary search next get boards board 0 return true next iter has next iter next null return false public message next if has next we have to call has next to ignore messages which do not belong to the selected board assert false however the users of the function should do this for us throw new no such element exception message child next next iter has next iter next null child initialize transient db m message manager return child public void remove throw new unsupported operation exception use child set parent null instead suppresswarnings getchildren targetboard targetboard mparent mdate orderdescending hasnext hasnext binarysearch getboards hasnext hasnext hasnext nosuchelementexception hasnext initializetransient mmessagemanager unsupportedoperationexception setparent return new iterable message public iterator message iterator return new iterator message private iterator message iter private board board private message next board target board todo accelerate this query configure db4o to keep a per message date sorted index of children not very important for now since threads are usually small query q db query q constrain message class q descend m parent constrain this q descend m date order descending iter q execute iterator next iter has next iter next null public boolean has next if board null return next null while next null if arrays binary search next get boards board 0 return true next iter has next iter next null return false public message next if has next we have to call has next to ignore messages which do not belong to the selected board assert false however the users of the function should do this for us throw new no such element exception message child next next iter has next iter next null child initialize transient db m message manager return child public void remove throw new unsupported operation exception use child set parent null instead targetboard mparent mdate orderdescending hasnext hasnext binarysearch getboards hasnext hasnext hasnext nosuchelementexception hasnext initializetransient mmessagemanager unsupportedoperationexception setparent public boolean has next if board null return next null while next null if arrays binary search next get boards board 0 return true next iter has next iter next null return false hasnext binarysearch getboards hasnext public message next if has next we have to call has next to ignore messages which do not belong to the selected board assert false however the users of the function should do this for us throw new no such element exception message child next next iter has next iter next null child initialize transient db m message manager return child hasnext hasnext nosuchelementexception hasnext initializetransient mmessagemanager public void remove throw new unsupported operation exception use child set parent null instead unsupportedoperationexception setparent checks whether the title of the message is valid validity conditions not empty no line breaks tabs or any other control characters no invalid characters no invalid formatting unpaired direction or annotation characters static public boolean is title valid string title return title null title length 0 string validity checker contains no invalid characters title string validity checker contains no linebreaks title string validity checker contains no control characters title string validity checker contains no invalid formatting title istitlevalid stringvaliditychecker containsnoinvalidcharacters stringvaliditychecker containsnolinebreaks stringvaliditychecker containsnocontrolcharacters stringvaliditychecker containsnoinvalidformatting checks whether the text of the message is valid validity conditions static public boolean is text valid string text if text null return false if text length max message text length return false try if text get bytes utf 8 length max message text byte length return false catch unsupported encoding exception e return false return true istextvalid max_message_text_length getbytes max_message_text_byte_length unsupportedencodingexception makes the passed title valid in means of code is title valid code see is title valid static public string make title valid string title fixme the newline handling here is based on the rfc 822 format newline linear white space single space if necessary we could move that part of the cleaning up to ui nntp article parser but the same algorithm should work fine in the general case string builder result new string builder boolean replacing newline false int dir count 0 boolean in annotated text false boolean in annotation false for int i 0 i title length int c title code point at i i character char count c if c r c n if replacing newline replacing newline true result append else if c t c if replacing newline result append else if c 0x202a left to right embedding c 0x202b right to left embedding c 0x202d left to right override c 0x202e right to left override dir count result append code point c else if c 0x202c pop directional formatting if dir count 0 dir count result append code point c else if c 0xfff9 interlinear annotation anchor if in annotated text in annotation result append code point c in annotated text true else if c 0xfffa interlinear annotation separator if in annotated text result append code point c in annotated text false in annotation true else if c 0xfffb interlinear annotation terminator if in annotation result append code point c in annotation false else if c 0xfffe 0xfffe invalid character ignore else replacing newline false switch character get type c case character control case character surrogate case character line separator case character paragraph separator break default result append code point c if in annotated text result append code point 0xfffa result append code point 0xfffb else if in annotation result append code point 0xfffb while dir count 0 result append code point 0x202c dir count return result to string istitlevalid istitlevalid maketitlevalid articleparser stringbuilder stringbuilder replacingnewline dircount inannotatedtext inannotation codepointat charcount replacingnewline replacingnewline replacingnewline dircount appendcodepoint dircount dircount appendcodepoint inannotatedtext inannotation appendcodepoint inannotatedtext inannotatedtext appendcodepoint inannotatedtext inannotation inannotation appendcodepoint inannotation replacingnewline gettype line_separator paragraph_separator appendcodepoint inannotatedtext appendcodepoint appendcodepoint inannotation appendcodepoint dircount appendcodepoint dircount tostring makes the passed text valid in means of code is text valid code see is text valid static public string make text valid string text return text replace r n n istextvalid istextvalid maketextvalid public synchronized void store fixme check for duplicates also notice that an own message which is equal might exist synchronized db lock if db ext is stored this db ext is active this throw new runtime exception trying to store a non active message object if m author null throw new runtime exception trying to store a message with m author null if muri null db store muri if m realuri null db store m realuri if m threaduri null db store m threaduri if m parenturi null db store m parenturi db store m boards not stored because it is a primitive for db4o db store m date not stored because it is a primitive for db4o db store m attachments not stored because it is a primitive for db4o db store this db commit ownmessage isstored isactive runtimeexception mauthor runtimeexception mauthor mrealuri mrealuri mthreaduri mthreaduri mparenturi mparenturi mboards mdate mattachments public int compare to message other return m date compare to other m date compareto mdate compareto mdate public final client requester parent get a numbered key to fetch public abstract client key get key object token object container container clientrequester clientkey getkey objectcontainer override public key get node key sendable request item token object container container client key key get key token container if key null return null return key get node key getnodekey sendablerequestitem objectcontainer clientkey getkey getnodekey what keys are we interested in for purposes of checking the datastore this is in sendable get not key listener in order to deal with it in smaller chunks param container database handle sendableget keylistener public abstract key list keys object container container get the fetch context settings object public abstract fetch context get context listkeys objectcontainer fetchcontext getcontext public abstract fetch context get context called when if the low level request fails public abstract void on failure low level get exception e object token object container container client context context fetchcontext getcontext onfailure lowlevelgetexception objectcontainer clientcontext public abstract void on failure low level get exception e object token object container container client context context should the request ignore the datastore public abstract boolean ignore store onfailure lowlevelgetexception objectcontainer clientcontext ignorestore public abstract boolean ignore store if true don t cache local requests param container public abstract boolean dont cache object container container ignorestore dontcache objectcontainer implementation public sendable get client requester parent super parent persistent this parent parent sendableget clientrequester static final sendable get request sender sender new sendable get request sender override public sendable request sender get sender object container container client context context return sender sendablegetrequestsender sendablegetrequestsender sendablerequestsender getsender objectcontainer clientcontext override public client request scheduler get scheduler client context context if isssk return context get ssk fetch scheduler else return context get chk fetch scheduler clientrequestscheduler getscheduler clientcontext getsskfetchscheduler getchkfetchscheduler get the time at which the key specified by the given token will wake up from the cooldown queue param token return public abstract long get cooldown wakeup object token object container container public abstract long get cooldown wakeup by key key key object container container getcooldownwakeup objectcontainer getcooldownwakeupbykey objectcontainer public abstract long get cooldown wakeup by key key key object container container reset the cooldown times when the request is reregistered public abstract void reset cooldown times object container container getcooldownwakeupbykey objectcontainer resetcooldowntimes objectcontainer an internal error occurred effecting this sendable get independantly of any chosen block s override public void internal error final throwable t final request scheduler sched object container container client context context boolean persistent sched call failure this new low level get exception low level get exception internal error t get message t native thread max priority persistent sendableget chosenblock internalerror requestscheduler objectcontainer clientcontext callfailure lowlevelgetexception lowlevelgetexception internal_error getmessage nativethread max_priority requeue a key after it has been on the cooldown queue for a while only requeue if our requeue time is less than or equal to the given time param key public abstract void requeue after cooldown key key long time object container container client context context override public final boolean is insert return false requeueaftercooldown objectcontainer clientcontext isinsert public void remove from object container container client context context container delete this removefrom objectcontainer clientcontext public class vector4f extends tuple4f public vector4f this 0 0 0 0 public vector4f float x this x x 0 this y x 1 this z x 2 this w x 2 public vector4f float x float y float z float w this x x this y y this z z this w w public vector4f vector4f t x t x y t y z t z w t w public vector4f tuple4f t x t x y t y z t z w t w public float dot vector4f v return v x x v y y v z z v w w public float length return float math sqrt x x y y z z w w public void normalize float d 1 0f x x y y z z w w x d y d z d w d uri newuri public permanent redirect exception super permanentredirectexception public permanent redirect exception uri newuri this newuri newuri permanentredirectexception public class device data extends node data public device data devicedata nodedata devicedata private file description file null public file get description file return description file descriptionfile getdescriptionfile descriptionfile public string get descriptionuri return descriptionuri getdescriptionuri public void set description file file description file this description file description file setdescriptionfile descriptionfile descriptionfile descriptionfile public void set descriptionuri string descriptionuri this descriptionuri descriptionuri setdescriptionuri private string location public string get location return location getlocation public void set location string location this location location setlocation private int lease time device default lease time public int get lease time return lease time leasetime default_lease_time getleasetime leasetime public void set lease time int val lease time val setleasetime leasetime private http server list http server list new http server list public http server list gethttp server list return http server list httpserverlist httpserverlist httpserverlist httpserverlist gethttpserverlist httpserverlist private int http port device http default port public int gethttp port return http port httpport http_default_port gethttpport httpport public void sethttp port int port http port port sethttpport httpport private listener list control action listener list new listener list public listener list get control action listener list return control action listener list listenerlist controlactionlistenerlist listenerlist listenerlist getcontrolactionlistenerlist controlactionlistenerlist private ssdp search socket list ssdp search socket list new ssdp search socket list public ssdp search socket list getssdp search socket list return ssdp search socket list ssdpsearchsocketlist ssdpsearchsocketlist ssdpsearchsocketlist ssdpsearchsocketlist getssdpsearchsocketlist ssdpsearchsocketlist private ssdp packet ssdp packet null public ssdp packet getssdp packet return ssdp packet ssdppacket ssdppacket ssdppacket getssdppacket ssdppacket public void setssdp packet ssdp packet packet ssdp packet packet setssdppacket ssdppacket ssdppacket private advertiser advertiser null public void set advertiser advertiser adv advertiser adv setadvertiser public advertiser get advertiser return advertiser getadvertiser logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog node dispatcher node node this node node this node stats node node stats node get ticker queue timed job this stale context check nodedispatcher nodestats nodestats getticker queuetimedjob stale_context_check byte counter ping counter new byte counter public void received bytes int x node node stats ping counter received x bytecounter pingcounter bytecounter receivedbytes nodestats pingcounterreceived public void sent bytes int x node node stats ping counter sent x sentbytes nodestats pingcountersent public void sent payload int x ignore sentpayload public interface node dispatcher callback public void snoop message m node n nodedispatchercallback public boolean handle message message m peer node source peer node m get source if source null node has been disconnected and garbage collected already ouch return true if logminor logger minor this dispatching m from source if callback null try callback snoop m node catch throwable t logger error this callback threw t t message type spec m get spec if spec dmt fnp ping send an fnp pong message reply dmt createfnp pong m get int dmt ping seqno try source send async reply null ping counter nothing we can do if can t contact source catch not connected exception e if logminor logger minor this lost connection replying to m return true else if spec dmt fnp store secret return node netid handle store secret m else if spec dmt fnp secret ping return node netid handle secret ping m else if spec dmt fnp detectedip address peer p peer m get object dmt external address source set remote detected peer p node ip detector redetect address return true else if spec dmt fnp time return handle time m source else if spec dmt fnp uptime return handle uptime m source else if spec dmt fnp sent packets source handle sent packets m return true else if spec dmt fnp void return true else if spec dmt fnp disconnect handle disconnect m source return true else if spec dmt node to node message node received node to node message m source return true else if spec dmt uom announce source is real connection return node node updater uom handle announce m source else if spec dmt uom request revocation source is real connection return node node updater uom handle request revocation m source else if spec dmt uom sending revocation source is real connection return node node updater uom handle sending revocation m source else if spec dmt uom request main source is real connection return node node updater uom handle request jar m source false else if spec dmt uom request extra source is real connection return node node updater uom handle request jar m source true else if spec dmt uom sending main source is real connection return node node updater uom handle sending main m source else if spec dmt uom sending extra source is real connection return node node updater uom handle sending ext m source else if spec dmt fnp opennet announce request return handle announce request m source else if spec dmt fnp routing status if source instanceof darknet peer node boolean value m get boolean dmt routing enabled if logminor logger minor this the peer source asked us to set routing value darknet peer node source set routing status value false we claim it in any case return true else if source is real connection spec dmt fnp loc change notification new double new loc m get double dmt location short buffer buffer short buffer m get object dmt peer locations double locs fields bytes to doubles buffer get data do not remove the sanity check below see http archives freenetproject org message 20080718 144240 359e16d3 en html if opennet manager max peers for scaling locs length source is opennet if locs length opennet manager max peers for scaling 2 this can t happen by accident logger error this we received locs length locations from source to string that should not happen possible attack source force disconnect true return true else a few extra can happen by accident just use the first 20 logger normal this too many locations from source to string locs length could be an accident using the first opennet manager max peers for scaling double first locs new double opennet manager max peers for scaling system arraycopy locs 0 first locs 0 opennet manager max peers for scaling locs first locs we are on darknet and we trust our peers or we are on opennet and the amount of locations sent to us seems reasonable source update location new loc locs return true if source is routable return false if logdebug logger debug this not routable if spec dmt fnp networkid source handlefnp networkid m return true else if spec dmt fnp swap request return node lm handle swap request m source else if spec dmt fnp swap reply return node lm handle swap reply m source else if spec dmt fnp swap rejected return node lm handle swap rejected m source else if spec dmt fnp swap commit return node lm handle swap commit m source else if spec dmt fnp swap complete return node lm handle swap complete m source else if spec dmt fnpchk data request return handle data request m source false else if spec dmt fnpssk data request return handle data request m source true else if spec dmt fnp insert request return handle insert request m source false else if spec dmt fnpssk insert request return handle insert request m source true else if spec dmt fnpssk insert request new return handle insert request m source true else if spec dmt fnprh probe request return handle probe request m source else if spec dmt fnp routed ping return handle routed m source else if spec dmt fnp routed pong return handle routed reply m else if spec dmt fnp routed rejected return handle routed rejected m fixme implement threaded probe requests of various kinds old probe request code was a major pain never really worked we should have threaded probe requests for simple code and one for each routing strategy else if spec dmt fnp probe request return handle probe request m source else if spec dmt fnp probe reply return handle probe reply m source else if spec dmt fnp probe rejected return handle probe rejected m source else if spec dmt fnp probe trace return handle probe trace m source else if spec dmt fnp offer key return handle offer key m source else if spec dmt fnp get offered key return handle get offered key m source return false handlemessage peernode peernode getsource messagetype getspec fnpping fnppong createfnppong getint ping_seqno sendasync pingcounter notconnectedexception fnpstoresecret handlestoresecret fnpsecretping handlesecretping fnpdetectedipaddress getobject external_address setremotedetectedpeer ipdetector redetectaddress fnptime handletime fnpuptime handleuptime fnpsentpackets handlesentpackets fnpvoid fnpdisconnect handledisconnect nodetonodemessage receivednodetonodemessage uomannounce isrealconnection nodeupdater handleannounce uomrequestrevocation isrealconnection nodeupdater handlerequestrevocation uomsendingrevocation isrealconnection nodeupdater handlesendingrevocation uomrequestmain isrealconnection nodeupdater handlerequestjar uomrequestextra isrealconnection nodeupdater handlerequestjar uomsendingmain isrealconnection nodeupdater handlesendingmain uomsendingextra isrealconnection nodeupdater handlesendingext fnpopennetannouncerequest handleannouncerequest fnproutingstatus darknetpeernode getboolean routing_enabled darknetpeernode setroutingstatus isrealconnection fnplocchangenotificationnew newloc getdouble shortbuffer shortbuffer getobject peer_locations bytestodoubles getdata opennetmanager max_peers_for_scaling isopennet opennetmanager max_peers_for_scaling tostring forcedisconnect tostring opennetmanager max_peers_for_scaling firstlocs opennetmanager max_peers_for_scaling firstlocs opennetmanager max_peers_for_scaling firstlocs updatelocation newloc isroutable fnpnetworkid handlefnpnetworkid fnpswaprequest handleswaprequest fnpswapreply handleswapreply fnpswaprejected handleswaprejected fnpswapcommit handleswapcommit fnpswapcomplete handleswapcomplete fnpchkdatarequest handledatarequest fnpsskdatarequest handledatarequest fnpinsertrequest handleinsertrequest fnpsskinsertrequest handleinsertrequest fnpsskinsertrequestnew handleinsertrequest fnprhproberequest handleproberequest fnproutedping handlerouted fnproutedpong handleroutedreply fnproutedrejected handleroutedrejected fnpproberequest handleproberequest fnpprobereply handleprobereply fnpproberejected handleproberejected fnpprobetrace handleprobetrace fnpofferkey handleofferkey fnpgetofferedkey handlegetofferedkey private boolean handle uptime message m peer node source byte uptime m get byte dmt uptime percent 48h source set uptime uptime return true handleuptime peernode getbyte uptime_percent_48h setuptime private boolean handle offer key message m peer node source key key key m get object dmt key byte authenticator short buffer m get object dmt offer authenticator get data node failure table on offer key source authenticator return true handleofferkey peernode getobject shortbuffer getobject offer_authenticator getdata failuretable onoffer private boolean handle get offered key message m peer node source key key key m get object dmt key byte authenticator short buffer m get object dmt offer authenticator get data long uid m get long dmt uid if hmac verify withsha256 node failure table offer authenticator key key get full key authenticator logger error this invalid offer request from source authenticator did not verify try source send async dmt createfnp get offered key invalid uid dmt get offered key rejected bad authenticator null node failure table sender counter catch not connected exception e too bad return true if logminor logger minor this valid get offered key for key from source do we want it we can reject overload if we don t have the bandwidth boolean isssk key instanceof nodessk offer reply tag tag new offer reply tag isssk node lockuid uid isssk false true false tag boolean need pub key try need pub key m get boolean dmt need pub key string reject node stats should reject request true false isssk false true source if reject null logger normal this rejecting fnp get offered key from source for key reject message rejected dmt createfnp rejected overload uid true try source send async rejected null node failure table sender counter catch not connected exception e logger normal this rejecting overload data request from source get peer e node unlockuid uid isssk false false true false tag return true catch error e node unlockuid uid isssk false false true false tag throw e catch runtime exception e node unlockuid uid isssk false false true false tag throw e otherwise send offered key is responsible for unlocking accept it try node failure table send offered key key isssk need pub key uid source tag catch not connected exception e too bad return true handlegetofferedkey peernode getobject shortbuffer getobject offer_authenticator getdata getlong verifywithsha256 failuretable offerauthenticatorkey getfullkey sendasync createfnpgetofferedkeyinvalid get_offered_key_rejected_bad_authenticator failuretable sendercounter notconnectedexception getofferedkey rejectoverload offerreplytag offerreplytag needpubkey needpubkey getboolean need_pub_key nodestats shouldrejectrequest fnpgetofferedkey createfnprejectedoverload sendasync failuretable sendercounter notconnectedexception getpeer runtimeexception sendofferedkey failuretable sendofferedkey needpubkey notconnectedexception private void handle disconnect final message m final peer node source must run on the packet sender thread as it sends a packet directly node get ticker queue timed job new fast runnable public void run send the ack source send any urgent notifications true finish disconnect m source 0 handledisconnect peernode getticker queuetimedjob fastrunnable sendanyurgentnotifications finishdisconnect node get ticker queue timed job new fast runnable public void run send the ack source send any urgent notifications true finish disconnect m source getticker queuetimedjob fastrunnable sendanyurgentnotifications finishdisconnect private void finish disconnect final message m final peer node source source disconnected true true if true remove from active routing table likely to be down for a while otherwise just dump all current connection state and keep trying to connect boolean remove m get boolean dmt remove if remove node peers disconnect source false false false if true purge all references to this node otherwise we can keep the node around in secondary tables etc in order to more easily reconnect later mostly used on opennet boolean purge m get boolean dmt purge if purge opennet manager om node get opennet if om null om purge old opennet peer source process parting message int type m get int dmt node to node message type short buffer message data short buffer m get object dmt node to node message data if message data get length 0 return node received node to node message source type message data true finishdisconnect peernode getboolean getboolean opennetmanager getopennet purgeoldopennetpeer getint node_to_node_message_type shortbuffer messagedata shortbuffer getobject node_to_node_message_data messagedata getlength receivednodetonodemessage messagedata private boolean handle time message m peer node source long delta m get long dmt time system current time millis source set time delta delta return true handletime peernode getlong currenttimemillis settimedelta handle an incoming fnp data request private boolean handle data request message m peer node source boolean isssk long id m get long dmt uid byte counter ctr isssk node node stats ssk request ctr node node stats chk request ctr if node recently completed id message rejected dmt createfnp rejected loop id try source send async rejected null ctr catch not connected exception e logger normal this rejecting data request loop finished e return true short htl m get short dmt htl key key key m get object dmt freenet routing key final request tag tag new request tag isssk request tag start remote if node lockuid id isssk false false false tag if logminor logger minor this could not lock id id rejecting already running message rejected dmt createfnp rejected loop id try source send async rejected null ctr catch not connected exception e logger normal this rejecting request from source get peer e node failure table on final failure key null htl 1 source return true else if logminor logger minor this locked id string reject reason node stats should reject request isssk false isssk false false source if reject reason null can accept 1 chk request every so often but not with ss ks because they aren t throttled so won t sort out bwlimit delay time which was the whole reason for accepting them when overloaded logger normal this rejecting isssk ssk chk request from source get peer preemptively because reject reason message rejected dmt createfnp rejected overload id true try source send async rejected null ctr catch not connected exception e logger normal this rejecting overload data request from source get peer e tag set rejected node unlockuid id isssk false false false false tag do not tell failure table otherwise an attacker can flood us with requests very cheaply and purge our failure table even though we didn t accept any of them return true node stats report incoming request location key to normalized double if node lockuid id return false request handler rh new request handler m source id node htl key tag node executor execute rh request handler for uid id on node get darknet port number return true fnpdatarequest handledatarequest peernode getlong bytecounter nodestats sskrequestctr nodestats chkrequestctr recentlycompleted createfnprejectedloop sendasync notconnectedexception getshort getobject freenet_routing_key requesttag requesttag requesttag createfnprejectedloop sendasync notconnectedexception getpeer failuretable onfinalfailure rejectreason nodestats shouldrejectrequest rejectreason ssks bwlimitdelaytime getpeer rejectreason createfnprejectedoverload sendasync notconnectedexception getpeer setrejected nodestats reportincomingrequestlocation tonormalizeddouble requesthandler requesthandler requesthandler getdarknetportnumber private boolean handle insert request message m peer node source boolean isssk byte counter ctr isssk node node stats ssk insert ctr node node stats chk insert ctr long id m get long dmt uid if node recently completed id message rejected dmt createfnp rejected loop id try source send async rejected null ctr catch not connected exception e logger normal this rejecting insert request from source get peer e return true insert tag tag new insert tag isssk insert tag start remote if node lockuid id isssk true false false tag if logminor logger minor this could not lock id id rejecting already running message rejected dmt createfnp rejected loop id try source send async rejected null ctr catch not connected exception e logger normal this rejecting insert request from source get peer e return true ss ks don t fix bwlimit delay time so shouldn t be accepted when overloaded string reject reason node stats should reject request isssk true isssk false false source if reject reason null logger normal this rejecting insert from source get peer preemptively because reject reason message rejected dmt createfnp rejected overload id true try source send async rejected null ctr catch not connected exception e logger normal this rejecting overload insert request from source get peer e node unlockuid id isssk true false false false tag return true long now system current time millis if m get spec equals dmt fnpssk insert request nodessk key nodessk m get object dmt freenet routing key byte data short buffer m get object dmt data get data byte headers short buffer m get object dmt block headers get data short htl m get short dmt htl ssk insert handler rh new ssk insert handler key data headers htl source id node now tag rh received bytes m received byte count node executor execute rh ssk insert handler for id on node get darknet port number else if m get spec equals dmt fnpssk insert request new nodessk key nodessk m get object dmt freenet routing key short htl m get short dmt htl ssk insert handler rh new ssk insert handler key null null htl source id node now tag rh received bytes m received byte count node executor execute rh ssk insert handler for id on node get darknet port number else chk insert handler rh new chk insert handler m source id node now tag node executor execute rh chk insert handler for id on node get darknet port number if logminor logger minor this started insert handler for id return true handleinsertrequest peernode bytecounter nodestats sskinsertctr nodestats chkinsertctr getlong recentlycompleted createfnprejectedloop sendasync notconnectedexception getpeer inserttag inserttag inserttag createfnprejectedloop sendasync notconnectedexception getpeer ssks bwlimitdelaytime rejectreason nodestats shouldrejectrequest rejectreason getpeer rejectreason createfnprejectedoverload sendasync notconnectedexception getpeer currenttimemillis getspec fnpsskinsertrequest getobject freenet_routing_key shortbuffer getobject getdata shortbuffer getobject block_headers getdata getshort sskinserthandler sskinserthandler receivedbytes receivedbytecount sskinserthandler getdarknetportnumber getspec fnpsskinsertrequestnew getobject freenet_routing_key getshort sskinserthandler sskinserthandler receivedbytes receivedbytecount sskinserthandler getdarknetportnumber chkinserthandler chkinserthandler chkinserthandler getdarknetportnumber inserthandler private boolean handle probe request message m peer node source long id m get long dmt uid if node recently completed id message rejected dmt createfnp rejected loop id try source send async rejected null node node stats probe request ctr catch not connected exception e logger normal this rejecting probe request from source get peer e return true lets not bother with full lockuid just add it to the recently completed list node completed id ss ks don t fix bwlimit delay time so shouldn t be accepted when overloaded if source should reject probe request logger normal this rejecting probe request from source get peer message rejected dmt createfnp rejected overload id true try source send async rejected null node node stats probe request ctr catch not connected exception e logger normal this rejecting overload insert request from source get peer e return true double target m get double dmt target location if target 1 0 target 0 0 logger normal this rejecting invalid target target probe request from source get peer message rejected dmt createfnp rejected overload id true try source send async rejected null node node stats probe request ctr catch not connected exception e logger normal this rejecting invalid insert request from source get peer e return true resettinghtl probe request handler start m source node target return true handleproberequest peernode getlong recentlycompleted createfnprejectedloop sendasync nodestats proberequestctr notconnectedexception getpeer ssks bwlimitdelaytime shouldrejectproberequest getpeer createfnprejectedoverload sendasync nodestats proberequestctr notconnectedexception getpeer getdouble target_location getpeer createfnprejectedoverload sendasync nodestats proberequestctr notconnectedexception getpeer resettinghtlproberequesthandler private boolean handle announce request message m peer node source long uid m get long dmt uid opennet manager om node get opennet if om null source can accept announcements message msg dmt createfnp opennet disabled uid try source send async msg null node node stats announce byte counter catch not connected exception e ok return true if node recently completed uid message msg dmt createfnp rejected loop uid try source send async msg null node node stats announce byte counter catch not connected exception e ok return true boolean success false no way to check whether it s actually running atm so lets report it to the completed list immediately fixme we should probably keep a list node completed uid try if source should accept announce uid message msg dmt createfnp rejected overload uid true try source send async msg null node node stats announce byte counter catch not connected exception e ok return true announce sender sender new announce sender m uid source om node node executor execute sender announcement sender for uid success true return true finally if success source completed announce uid handleannouncerequest peernode getlong opennetmanager getopennet canacceptannouncements createfnpopennetdisabled sendasync nodestats announcebytecounter notconnectedexception recentlycompleted createfnprejectedloop sendasync nodestats announcebytecounter notconnectedexception shouldacceptannounce createfnprejectedoverload sendasync nodestats announcebytecounter notconnectedexception announcesender announcesender completedannounce routed context message msg peer node source byte identity created time access time system current time millis this source source routed to new hash set peer node this msg msg last htl msg get short dmt htl this identity identity routedcontext peernode createdtime accesstime currenttimemillis routedto hashset peernode lasthtl getshort void add sent peer node n routed to add n addsent peernode routedto cleanup any old stale routing contexts and reschedule execution public void run long now system current time millis synchronized routed contexts iterator routed context i routed contexts values iterator while i has next routed context rc i next if now rc created time stale context i remove node get ticker queue timed job this stale context check currenttimemillis routedcontexts routedcontext routedcontexts hasnext routedcontext createdtime stale_context getticker queuetimedjob stale_context_check handle an fnp routed rejected message private boolean handle routed rejected message m long id m get long dmt uid long lid long value of id routed context rc routed contexts get lid if rc null gah logger error this unrecognized fnp routed rejected return false locally originated short htl rc last htl if rc source null htl rc source decrementhtl htl short ohtl m get short dmt htl if ohtl htl htl ohtl if htl 0 equivalent to dnf relay if rc source null try rc source send async dmt createfnp routed rejected id short 0 null node stats routed message ctr catch not connected exception e ouch logger error this unable to relay probe dnf peer disconnected rc source else try routing to the next node forward rc msg id rc source htl rc msg get double dmt target location rc rc identity return true fnproutedrejected handleroutedrejected getlong valueof routedcontext routedcontexts fnproutedrejected lasthtl getshort sendasync createfnproutedrejected nodestats routedmessagectr notconnectedexception getdouble target_location handle a routed to a specific node message param m return false if we want the message put back on the queue boolean handle routed message m peer node source if logminor logger minor this handle routed m long id m get long dmt uid long lid long value of id short htl m get short dmt htl byte identity short buffer m get object dmt node identity get data if source null htl source decrementhtl htl routed context ctx ctx routed contexts get lid if ctx null try source send async dmt createfnp routed rejected id htl null node stats routed message ctr catch not connected exception e if logminor logger minor this lost connection rejecting m return true ctx new routed context m source identity synchronized routed contexts routed contexts put lid ctx source null originated locally keep full htl double target m get double dmt target location if logminor logger minor this id id from source htl htl target target if math abs node lm get location target double min value if logminor logger minor this dispatching m get spec on node get darknet port number handle locally message type specific processing dispatch routed message m source id return true else if htl 0 message reject dmt createfnp routed rejected id short 0 if source null try source send async reject null node stats routed message ctr catch not connected exception e if logminor logger minor this lost connection rejecting m return true else return forward m id source htl target ctx identity handlerouted peernode handlerouted getlong valueof getshort shortbuffer getobject node_identity getdata routedcontext routedcontexts sendasync createfnproutedrejected nodestats routedmessagectr notconnectedexception routedcontext routedcontexts routedcontexts getdouble target_location getlocation min_value getspec getdarknetportnumber dispatchroutedmessage createfnproutedrejected sendasync nodestats routedmessagectr notconnectedexception boolean handle routed reply message m long id m get long dmt uid if logminor logger minor this got reply m long lid long value of id routed context ctx routed contexts get lid if ctx null logger error this unrecognized routed reply m return false peer node pn ctx source if pn null return false try pn send async m null node stats routed message ctr catch not connected exception e if logminor logger minor this lost connection forwarding m to pn return true handleroutedreply getlong valueof routedcontext routedcontexts peernode sendasync nodestats routedmessagectr notconnectedexception private boolean forward message m long id peer node pn short htl double target routed context ctx byte target identity if logminor logger minor this should forward forward m pre forward m htl while true peer node next node peers get by identity target identity if next null next is connected logger error this found target but disconnected next next null if next null next node peers closer peer pn ctx routed to target true node is advanced mode enabled 1 null null if logminor logger minor this next next message m if next null next is connected or at least has been next get peer cannot be null if logminor logger minor this forwarding m get spec to next get peer get port ctx add sent next try next send async m null node stats routed message ctr catch not connected exception e continue else if logminor logger minor this reached dead end for m get spec on node get darknet port number reached a dead end message reject dmt createfnp routed rejected id htl if pn null try pn send async reject null node stats routed message ctr catch not connected exception e logger error this cannot send reject message back to source pn return true return true peernode routedcontext targetidentity preforward peernode getbyidentity targetidentity isconnected closerpeer routedto isadvancedmodeenabled getpeer getspec getpeer getport addsent sendasync nodestats routedmessagectr notconnectedexception getspec getdarknetportnumber createfnproutedrejected sendasync nodestats routedmessagectr notconnectedexception prepare a routed to node message for forwarding private message pre forward message m short newhtl m set dmt htl newhtl update htl if m get spec dmt fnp routed ping int x m get int dmt counter x m set dmt counter x return m preforward getspec fnproutedping getint deal with a routed to node message that landed on this node this is where message type specific code executes param m return private boolean dispatch routed message message m peer node src long id if m get spec dmt fnp routed ping if logminor logger minor this routed ping reached other side id int x m get int dmt counter message reply dmt createfnp routed pong id x if logminor logger minor this replying counter x for id try src send async reply null node stats routed message ctr catch not connected exception e if logminor logger minor this lost connection replying to m in dispatch routed message return true return false dispatchroutedmessage peernode getspec fnproutedping routedping getint createfnproutedpong sendasync nodestats routedmessagectr notconnectedexception dispatchroutedmessage void start node stats stats this node stats stats nodestats nodestats public static string peersui ds to string long peerui ds double peer locs string builder sb new string builder peerui ds length 23 peer locs length 26 int min math min peerui ds length peer locs length for int i 0 i min i double loc peer locs i long uid peerui ds i sb append loc sb append sb append uid if i min 1 sb append if peerui ds length min for int i min i peerui ds length i sb append u sb append peerui ds i else if peer locs length min for int i min i peer locs length i sb append l sb append peer locs i return sb to string peersuidstostring peeruids peerlocs stringbuilder stringbuilder peeruids peerlocs peeruids peerlocs peerlocs peeruids peeruids peeruids peeruids peerlocs peerlocs peerlocs tostring public void start probe final double target final probe callback cb final long uid node random next long resettinghtl probe request sender rs new resettinghtl probe request sender target node maxhtl uid node node get location true null 2 0 rs add listener new resettinghtl probe request sender listener public void on completion double nearest double best short counter short unique counter short linear counter throws not connected exception cb on completed completed target best nearest uid counter unique counter linear counter public void onrnf short htl double nearest double best short counter short unique counter short linear counter throws not connected exception cb on completed rnf target best nearest uid counter unique counter linear counter public void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception cb on reject overload public void on timeout double nearest double best short counter short unique counter short linear counter string reason throws not connected exception cb on completed timeout target best nearest uid counter unique counter linear counter public void on trace long uid double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short fork count short linear counter string reason long prevuid throws not connected exception cb on trace uid target nearest best htl counter location myuid fields bytes to doubles peer locs get data fields bytes to longs peerui ds get data new double 0 fork count linear counter reason prevuid rs start startprobe probecallback nextlong resettinghtlproberequestsender resettinghtlproberequestsender getlocation addlistener resettinghtlproberequestsender oncompletion uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter onreceivedrejectoverload uniquecounter linearcounter notconnectedexception onrejectoverload ontimeout uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter ontrace uniquecounter shortbuffer peerlocs shortbuffer peeruids forkcount linearcounter notconnectedexception ontrace bytestodoubles peerlocs getdata bytestolongs peeruids getdata forkcount linearcounter rs add listener new resettinghtl probe request sender listener public void on completion double nearest double best short counter short unique counter short linear counter throws not connected exception cb on completed completed target best nearest uid counter unique counter linear counter addlistener resettinghtlproberequestsender oncompletion uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter public void onrnf short htl double nearest double best short counter short unique counter short linear counter throws not connected exception cb on completed rnf target best nearest uid counter unique counter linear counter uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter public void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception cb on reject overload onreceivedrejectoverload uniquecounter linearcounter notconnectedexception onrejectoverload public void on timeout double nearest double best short counter short unique counter short linear counter string reason throws not connected exception cb on completed timeout target best nearest uid counter unique counter linear counter ontimeout uniquecounter linearcounter notconnectedexception oncompleted uniquecounter linearcounter public void on trace long uid double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short fork count short linear counter string reason long prevuid throws not connected exception cb on trace uid target nearest best htl counter location myuid fields bytes to doubles peer locs get data fields bytes to longs peerui ds get data new double 0 fork count linear counter reason prevuid ontrace uniquecounter shortbuffer peerlocs shortbuffer peeruids forkcount linearcounter notconnectedexception ontrace bytestodoubles peerlocs getdata bytestolongs peeruids getdata forkcount linearcounter public void set hook node dispatcher callback cb this callback cb sethook nodedispatchercallback public blur filter super blur matrix blurfilter blurmatrix override public string to string return blur simple blur tostring public new reply page web interface my web interface ft own identity viewer http request request throws no such board exception no such message exception super my web interface viewer request m board m freetalk get message manager get board by name request get part as string board name board max boardname text length m parent message m freetalk get message manager get request get part as string parent messageid 128 todo adapt to maximal id length when it has been decided newreplypage webinterface mywebinterface ftownidentity httprequest nosuchboardexception nosuchmessageexception mywebinterface mboard mfreetalk getmessagemanager getboardbyname getpartasstring boardname max_boardname_text_length mparentmessage mfreetalk getmessagemanager getpartasstring parentmessageid public void make if m request is part set create reply hash set board boards new hash set board boards add m board string reply subject m request get part as string reply subject message max message title text length string reply text m request get part as string reply text message max message title text length try m freetalk get message manager post message m parent message boards m board m own identity reply subject null reply text null html node success box add content box reply created success box add child p the reply was put into your outbox freetalk will upload it after some time try we use get thread getid instead of get parent threadid because the message s thread might not have been downloaded yet success box add child new html node a href self uri show thread identity m own identity getuid board m board get name id m parent message is thread m parent message getid m parent message get thread getid go back to parent thread success box add child br catch no such message exception e logger error this should not happen e success box add child new html node a href self uri show board identity m own identity getuid name m board get name go back to m board get name catch exception e html node alert box add alert box the reply could not be created alert box add child div e get message make new reply page reply subject reply text else string subject m parent message get title if subject starts with re subject re subject make new reply page subject quoting get full quote m parent message mrequest ispartset createreply hashset hashset mboard replysubject mrequest getpartasstring replysubject max_message_title_text_length replytext mrequest getpartasstring replytext max_message_title_text_length mfreetalk getmessagemanager postmessage mparentmessage mboard mownidentity replysubject replytext htmlnode successbox addcontentbox successbox addchild getthread getparentthreadid successbox addchild htmlnode self_uri showthread mownidentity mboard getname mparentmessage isthread mparentmessage mparentmessage getthread successbox addchild nosuchmessageexception successbox addchild htmlnode self_uri showboard mownidentity mboard getname mboard getname htmlnode alertbox addalertbox alertbox addchild getmessage makenewreplypage replysubject replytext mparentmessage gettitle startswith makenewreplypage getfullquote mparentmessage private void make new reply page string reply subject string reply text html node reply box add content box new reply to m board get name html node new reply form add form child reply box self uri new reply new reply new reply form add child input new string type name value new string hidden board name m board get name new reply form add child input new string type name value new string hidden parent messageid m parent message getid html node author box new reply form add child get content box author author box add child input new string type name value new string hidden own identityid m own identity getuid author box add child b m own identity get freetalk address html node subject box new reply form add child get content box subject subject box add child input new string type name size value new string text reply subject 100 reply subject fixme find a reasonable maximal subject length and specify here and elsewhere html node text box new reply form add child get content box text text box add child textarea new string name cols rows new string reply text 80 30 reply text new reply form add child input new string type name value new string submit create reply submit makenewreplypage replysubject replytext htmlnode replybox addcontentbox mboard getname htmlnode newreplyform addformchild replybox self_uri newreply newreply newreplyform addchild boardname mboard getname newreplyform addchild parentmessageid mparentmessage htmlnode authorbox newreplyform addchild getcontentbox authorbox addchild ownidentityid mownidentity authorbox addchild mownidentity getfreetalkaddress htmlnode subjectbox newreplyform addchild getcontentbox subjectbox addchild replysubject replysubject htmlnode textbox newreplyform addchild getcontentbox textbox addchild replytext replytext newreplyform addchild createreply public static final short code 404 not found public not found pluginhttp exception string error message string location super error message location notfoundpluginhttpexception errormessage errormessage constructor for received messages public static wot message construct message list new message list freeneturi my realuri string newid wot messageuri new threaduri wot messageuri new parenturi set board new boards board new reply to board ft identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception if new message list null new boards null new author null throw new illegal argument exception if new message list get author new author throw new invalid parameter exception trying to construct a message of new author with a messagelist which belong to a different author new message list get author return new wot message calculateuri new message list newid my realuri newid new message list new threaduri new parenturi new boards new reply to board new author new title new date new text new attachments wotmessage messagelist newmessagelist myrealuri wotmessageuri newthreaduri wotmessageuri newparenturi newboards newreplytoboard ftidentity newauthor newtitle newdate newtext newattachments invalidparameterexception newmessagelist newboards newauthor illegalargumentexception newmessagelist getauthor newauthor invalidparameterexception newauthor newmessagelist getauthor wotmessage newmessagelist myrealuri newmessagelist newthreaduri newparenturi newboards newreplytoboard newauthor newtitle newdate newtext newattachments protected wot message wot messageuri newuri freeneturi new realuri string newid message list new message list wot messageuri new threaduri wot messageuri new parenturi set board new boards board new reply to board ft identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception super newuri new realuri newid new message list new threaduri new parenturi new boards new reply to board new author new title new date new text new attachments wotmessage wotmessageuri newrealuri messagelist newmessagelist wotmessageuri newthreaduri wotmessageuri newparenturi newboards newreplytoboard ftidentity newauthor newtitle newdate newtext newattachments invalidparameterexception newrealuri newmessagelist newthreaduri newparenturi newboards newreplytoboard newauthor newtitle newdate newtext newattachments public static wot messageuri calculateuri message list my message list string myid return new wot messageuri my message list geturi myid wotmessageuri messagelist mymessagelist wotmessageuri mymessagelist override public void start document state v1 state main header key null header value null startdocument v1state headerkey headervalue override public void characters char ch int start int length throws sax exception if state v1 state header inner header key null return header value append ch start length saxexception v1state header_inner headerkey headervalue override public void start element string uri string local name string q name attributes attributes throws sax exception switch state case main main start element uri local name q name attributes break case header header start element uri local name q name attributes break case header inner header inner start element uri local name q name attributes break case keywords keywords start element uri local name q name attributes break startelement localname qname saxexception mainstartelement localname qname headerstartelement localname qname header_inner headerinnerstartelement localname qname keywordsstartelement localname qname private void main start element string uri string local name string q name attributes attributes throws sax exception if main index equals local name state v1 state main else if header equals local name state v1 state header else if keywords equals local name state v1 state keywords else if prefix equals local name ignore else throw new sax exception bad tag local name in main location mainstartelement localname qname saxexception main_index localname v1state localname v1state localname v1state localname saxexception localname private void header start element string uri string local name string q name attributes attributes header key local name header value new string builder state v1 state header inner headerstartelement localname qname headerkey localname headervalue stringbuilder v1state header_inner private void header inner start element string uri string local name string q name attributes attributes throws sax exception throw new sax exception bad tag local name in header location headerinnerstartelement localname qname saxexception saxexception localname private void keywords start element string uri string local name string q name attributes attributes throws sax exception if sub index equals local name new sax exception bad tag local name in keywords location string key attributes get value key if key null key length 1 key length 32 key matches 0 9a fa f throw new sax exception bad sub index tag location key key to lower case locale us sub indice add key keywordsstartelement localname qname saxexception subindex localname saxexception localname getvalue saxexception subindex tolowercase subindice override public void end element string uri string local name string q name throws sax exception switch state case main main end element uri local name q name break case header header end element uri local name q name break case header inner header inner end element uri local name q name break case keywords keywords end element uri local name q name break endelement localname qname saxexception mainendelement localname qname headerendelement localname qname header_inner headerinnerendelement localname qname keywordsendelement localname qname private void main end element string uri string local name string q name throws sax exception if main index equals local name prefix equals local name throw new sax exception bad close tag local name in main location mainendelement localname qname saxexception main_index localname localname saxexception localname private void header end element string uri string local name string q name throws sax exception if header equals local name throw new sax exception bad close tag local name in header location state v1 state main headerendelement localname qname saxexception localname saxexception localname v1state private void header inner end element string uri string local name string q name throws sax exception if local name equals header key throw new sax exception bad close tag local name in header location header put header key header value to string header key null header value null state v1 state header headerinnerendelement localname qname saxexception localname headerkey saxexception localname headerkey headervalue tostring headerkey headervalue v1state private void keywords end element string uri string local name string q name throws sax exception if sub index equals local name ignore else if keywords equals local name state v1 state main else throw new sax exception bad close tag local name in keywords location keywordsendelement localname qname saxexception subindex localname localname v1state saxexception localname protected locator locator override public void characters char ch int start int length throws sax exception handler characters ch start length saxexception override public void set document locator locator locator this locator locator setdocumentlocator override public void start document header new hash map string string sub indice new hash set string site indice new hash set string handler null startdocument hashmap subindice hashset siteindice hashset override public void start element string uri string local name string q name attributes attributes throws sax exception if handler null version detect version uri local name q name attributes switch version case 1 handler new v1 handler break default throw new sax exception unsupported version location version handler start document handler start element uri local name q name attributes startelement localname qname saxexception detectversion localname qname v1handler saxexception startdocument startelement localname qname override public void end element string uri string local name string q name throws sax exception handler end element uri local name q name endelement localname qname saxexception endelement localname qname override public void end document throws sax exception handler end document enddocument saxexception enddocument private int detect version string uri string local name string q name attributes attributes throws sax exception if main index equals local name return 1 else throw new sax exception unknown tag location local name detectversion localname qname saxexception main_index localname saxexception localname private string location if locator null return locator get line number locator get column number else return getlinenumber getcolumnnumber public int get version return version getversion public string get header string key return header get key getheader public set string get sub indice return sub indice getsubindice subindice public set string get site indice return site indice getsiteindice siteindice public usk proxy completion callback usk usk get completion callback cb boolean persistent this usk usk this cb cb this persistent persistent uskproxycompletioncallback getcompletioncallback public void on success fetch result result client get state state object container container client context context if container null persistent container activate cb 1 container activate usk 5 context usk manager update known good usk usk suggested edition context cb on success result state container context if persistent remove from container onsuccess fetchresult clientgetstate objectcontainer clientcontext uskmanager updateknowngood suggestededition onsuccess removefrom private void remove from object container container container activate usk 5 usk remove from container container delete this removefrom objectcontainer removefrom public void on failure fetch exception e client get state state object container container client context context switch e mode case fetch exception not enough path components case fetch exception permanent redirect context usk manager update known good usk usk suggested edition context if persistent container activate cb 1 container activate usk 5 freeneturi uri e newuri if uri null uri usk turn myssk intousk uri e new fetch exception e uri cb on failure e state container context if persistent remove from container onfailure fetchexception clientgetstate objectcontainer clientcontext fetchexception not_enough_path_components fetchexception permanent_redirect uskmanager updateknowngood suggestededition turnmysskintousk fetchexception onfailure removefrom public void on block set finished client get state state object container container client context context if container null persistent container activate cb 1 cb on block set finished state container context onblocksetfinished clientgetstate objectcontainer clientcontext onblocksetfinished public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void on expectedmime string mime object container container client context context if container null persistent container activate cb 1 cb on expectedmime mime container context onexpectedmime objectcontainer clientcontext onexpectedmime public void on expected size long size object container container client context context if container null persistent container activate cb 1 cb on expected size size container context onexpectedsize objectcontainer clientcontext onexpectedsize public void on finalized metadata object container container if container null persistent container activate cb 1 cb on finalized metadata container onfinalizedmetadata objectcontainer onfinalizedmetadata public final class own message reference extends message reference public own message reference own message my message super my message getid my message get realuri null ownmessagereference messagereference ownmessagereference ownmessage mymessage mymessage mymessage getrealuri public own message list ft own identity new author int new index super new author new index ownmessagelist ftownidentity newauthor newindex newauthor newindex get the ssk insert uri of this message list return public freeneturi get inserturi return generateuri ft own identity m author get inserturi m index ssk forusk getinserturi ftownidentity mauthor getinserturi mindex sskforusk add an code own message code to this code message list code this function synchronizes on the code message list code and the given message throws exception if the message list is full public synchronized void add message wot own message new message throws exception synchronized new message if i am being inserted i was inserted throw new illegal argument exception trying to add a message to a message list which is already being inserted if new message get author m author throw new illegal argument exception trying to add a message with wrong author new message get author to an own message list of m author own message reference ref new own message reference new message m messages add ref if m messages size 1 fits into container false m messages remove ref throw new exception own message list is full todo chose a better exception new message set message list this store ownmessage messagelist messagelist addmessage wotownmessage newmessage newmessage iambeinginserted iwasinserted illegalargumentexception newmessage getauthor mauthor illegalargumentexception newmessage getauthor mauthor ownmessagereference ownmessagereference newmessage mmessages mmessages fitsintocontainer mmessages ownmessagelist newmessage setmessagelist public synchronized int get message count return m messages size getmessagecount mmessages protected abstract boolean fits into container fitsintocontainer protected abstract boolean fits into container public synchronized void begin of insert i am being inserted true store fitsintocontainer beginofinsert iambeinginserted public synchronized void cancel insert if i was inserted throw new runtime exception the own message list was already inserted i am being inserted false store cancelinsert iwasinserted runtimeexception ownmessagelist iambeinginserted public synchronized boolean was inserted return i was inserted wasinserted iwasinserted public synchronized void mark as inserted i was inserted true store markasinserted iwasinserted constructs a new jar class loader that loads classes from the jar file with the given name in the local file system param file name the name of the jar file throws io exception if an i o error occurs public jar class loader string file name throws io exception this new file file name filename ioexception jarclassloader filename ioexception filename constructs a new jar class loader that loads classes from the specified url param file url the url to load the jar file from param length the length of the jar file if known code 1 code otherwise throws io exception if an i o error occurs public jar class loader url file url long length throws io exception copy file to temp file url open stream length fileurl ioexception jarclassloader fileurl ioexception copyfiletotemp fileurl openstream constructs a new jar class loader that loads classes from the specified file param file the file to load classes from throws io exception if an i o error occurs public jar class loader file file throws io exception temp jar file new jar file file ioexception jarclassloader ioexception tempjarfile jarfile copies the contents of the input stream which are supposed to be the contents of a jar file to a temporary location param input stream the input stream to read from param length the length of the stream if known code 1 code if the length is not known throws io exception if an i o error occurs private void copy file to temp input stream input stream long length throws io exception file temp file file create temp file jar tmp file output stream file output stream new file output stream temp file file util copy input stream file output stream length file output stream close temp file delete on exit temp jar file new jar file temp file inputstream ioexception copyfiletotemp inputstream inputstream ioexception tempfile createtempfile fileoutputstream fileoutputstream fileoutputstream tempfile fileutil inputstream fileoutputstream fileoutputstream tempfile deleteonexit tempjarfile jarfile tempfile inherit doc p this method searches the temporary copy of the jar file for an entry that is specified by the given class name see java lang class loader find class java lang string override protected class find class string name throws class not found exception try string path name transform name name jar entry jar entry temp jar file get jar entry path name if jar entry null long size jar entry get size input stream jar entry input stream temp jar file get input stream jar entry byte array output stream class bytes output stream new byte array output stream int size file util copy jar entry input stream class bytes output stream size class bytes output stream close jar entry input stream close byte class bytes class bytes output stream to byte array class clazz define class name class bytes 0 class bytes length return clazz throw new class not found exception could not find jar entry for class name catch io exception e throw new class not found exception e get message e inheritdoc classloader findclass findclass classnotfoundexception pathname transformname jarentry jarentry tempjarfile getjarentry pathname jarentry jarentry getsize inputstream jarentryinputstream tempjarfile getinputstream jarentry bytearrayoutputstream classbytesoutputstream bytearrayoutputstream fileutil jarentryinputstream classbytesoutputstream classbytesoutputstream jarentryinputstream classbytes classbytesoutputstream tobytearray defineclass classbytes classbytes classnotfoundexception ioexception classnotfoundexception getmessage inherit doc see java lang class loader find resource java lang string override protected url find resource string name compatibility code remove when all plugins are fixed if name starts with name name substring 1 try return new url jar new file temp jar file get name touri tourl name catch malformedurl exception e return null inheritdoc classloader findresource findresource startswith tempjarfile getname malformedurlexception transforms the class name into a file name that can be used to locate an entry in the jar file param name the name of the class return the path name of the entry in the jar file private string transform name string name return name replace class transformname public void close throws io exception temp jar file close ioexception tempjarfile private static class item public item string string2 this string string2 public string counter map new hash map string item stringcounter hashmap public synchronized void inc string string item item map get string if item null item new item string item counter 1 map put string item else item counter public int get string string item item map get string if item null return 0 return item counter private synchronized item items return map values to array new item map size toarray private synchronized item sorted items final boolean ascending item items items arrays sort items new comparator item public int compare item it0 item it1 int ret if it0 counter it1 counter ret 1 else if it0 counter it1 counter ret 1 else ret it0 string compare to it1 string if ascending ret ret return ret return items sorteditems compareto arrays sort items new comparator item public int compare item it0 item it1 int ret if it0 counter it1 counter ret 1 else if it0 counter it1 counter ret 1 else ret it0 string compare to it1 string if ascending ret ret return ret compareto public string to long string item items sorted items false string builder sb new string builder for int i 0 i items length i if i 0 sb append n item it items i sb append it string sb append t sb append it counter return sb to string tolongstring sorteditems stringbuilder stringbuilder tostring public int to table rows html node table item items sorted items false for int i 0 i items length i item it items i html node row table add child tr row add child td integer to string it counter u00a0 row add child td it string return items length totablerows htmlnode sorteditems htmlnode addchild addchild tostring addchild construct a shadow filter public shadow filter shadowfilter shadowfilter construct a shadow filter param radius the radius of the shadow param x offset the x offset of the shadow param y offset the y offset of the shadow param opacity the opacity of the shadow public shadow filter float radius float x offset float y offset float opacity this radius radius this angle float math atan2 y offset x offset this distance float math sqrt x offset x offset y offset y offset this opacity opacity shadowfilter xoffset yoffset shadowfilter xoffset yoffset yoffset xoffset xoffset xoffset yoffset yoffset specifies the angle of the shadow param angle the angle of the shadow angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of the shadow return the angle of the shadow see set angle public float get angle return angle setangle getangle set the distance of the shadow param distance the distance see get distance public void set distance float distance this distance distance getdistance setdistance get the distance of the shadow return the distance see set distance public float get distance return distance setdistance getdistance set the radius of the kernel and hence the amount of blur the bigger the radius the longer this filter will take param radius the radius of the blur in pixels see get radius public void set radius float radius this radius radius getradius setradius get the radius of the kernel return the radius see set radius public float get radius return radius setradius getradius set the opacity of the shadow param opacity the opacity see get opacity public void set opacity float opacity this opacity opacity getopacity setopacity get the opacity of the shadow return the opacity see set opacity public float get opacity return opacity setopacity getopacity set the color of the shadow param shadow color the color see get shadow color public void set shadow color int shadow color this shadow color shadow color shadowcolor getshadowcolor setshadowcolor shadowcolor shadowcolor shadowcolor get the color of the shadow return the color see set shadow color public int get shadow color return shadow color setshadowcolor getshadowcolor shadowcolor set whether to increase the size of the output image to accomodate the shadow param add margins true to add margins see get add margins public void set add margins boolean add margins this add margins add margins addmargins getaddmargins setaddmargins addmargins addmargins addmargins get whether to increase the size of the output image to accomodate the shadow return true to add margins see set add margins public boolean get add margins return add margins setaddmargins getaddmargins addmargins set whether to only draw the shadow without the original image param shadow only true to only draw the shadow see get shadow only public void set shadow only boolean shadow only this shadow only shadow only shadowonly getshadowonly setshadowonly shadowonly shadowonly shadowonly get whether to only draw the shadow without the original image return true to only draw the shadow see set shadow only public boolean get shadow only return shadow only setshadowonly getshadowonly shadowonly override public rectangle2d get bounds2d buffered image src rectangle r new rectangle 0 0 src get width src get height if add margins float x offset distance float math cos angle float y offset distance float math sin angle r width int math abs x offset 2 radius r height int math abs y offset 2 radius return r getbounds2d bufferedimage getwidth getheight addmargins xoffset yoffset xoffset yoffset override public point2d get point2d point2d src pt point2d dst pt if dst pt null dst pt new point2d double if add margins float x offset distance float math cos angle float y offset distance float math sin angle float top shadow math max 0 radius y offset float left shadow math max 0 radius x offset dst pt set location src pt getx left shadow src pt gety top shadow else dst pt set location src pt getx src pt gety return dst pt getpoint2d srcpt dstpt dstpt dstpt addmargins xoffset yoffset topshadow yoffset leftshadow xoffset dstpt setlocation srcpt leftshadow srcpt topshadow dstpt setlocation srcpt srcpt dstpt public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null if add margins color model cm src get color model dst new buffered image cm cm create compatible writable raster src get width src get height cm is alpha premultiplied null else dst create compatible dest image src null float shadowr shadow color 16 0xff 255f float shadowg shadow color 8 0xff 255f float shadowb shadow color 0xff 255f make a black mask from the image s alpha channel float extract alpha 0 0 0 shadowr 0 0 0 shadowg 0 0 0 shadowb 0 0 0 opacity buffered image shadow new buffered image width height buffered image type int argb new band combine op extract alpha null filter src get raster shadow get raster shadow new gaussian filter radius filter shadow null float x offset distance float math cos angle float y offset distance float math sin angle graphics2d g dst create graphics g set composite alpha composite get instance alpha composite src over opacity if add margins float radius2 radius 2 float top shadow math max 0 radius y offset float left shadow math max 0 radius x offset g translate top shadow left shadow g draw rendered image shadow affine transform get translate instance x offset y offset if shadow only g set composite alpha composite src over g draw rendered image src null g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight addmargins colormodel getcolormodel bufferedimage createcompatiblewritableraster getwidth getheight isalphapremultiplied createcompatibledestimage shadowcolor shadowcolor shadowcolor extractalpha bufferedimage bufferedimage bufferedimage type_int_argb bandcombineop extractalpha getraster getraster gaussianfilter xoffset yoffset creategraphics setcomposite alphacomposite getinstance alphacomposite src_over addmargins topshadow yoffset leftshadow xoffset topshadow leftshadow drawrenderedimage affinetransform gettranslateinstance xoffset yoffset shadowonly setcomposite alphacomposite srcover drawrenderedimage override public string to string return stylize drop shadow tostring connects to a fcp server and adds a reference param args public static void main string args if args length 1 system err println please provide a file name as the first argument system exit 1 final file reference new file args 0 if reference null reference is file reference can read system err println please provide a file name as the first argument system exit 1 new add ref reference isfile canread addref add ref file reference socket fcp socket null fcp message fcpm simple field set sfs new simple field set true try fcp socket new socket 127 0 0 1 fcp server default fcp port fcp socket set so timeout 2000 input stream is fcp socket get input stream line reading input stream lis new line reading input stream is output stream os fcp socket get output stream try sfs put single name add ref sfs put single expected version 2 0 fcpm fcp message create client hello sfs fcpm send os os flush string message name lis read line 128 128 true sfs get message lis fcpm fcp message create message name sfs if fcpm null fcpm instanceof node hello message system err println not a valid fred node system exit 1 catch message invalid exception me me print stack trace try sfs simple field set read from reference false true fcpm fcp message create add peer name sfs fcpm send os os flush todo we ought to do stricter checking fixme some checks even catch message invalid exception me system err println invalid reference file me me print stack trace lis close is close os close fcp socket close system out println that reference has been added catch socket exception se system err println se se print stack trace system exit 1 catch io exception ioe system err println ioe ioe print stack trace system exit 2 finally try thread sleep 3000 catch interrupted exception e addref fcpsocket fcpmessage simplefieldset simplefieldset fcpsocket fcpserver default_fcp_port fcpsocket setsotimeout inputstream fcpsocket getinputstream linereadinginputstream linereadinginputstream outputstream fcpsocket getoutputstream putsingle addref putsingle expectedversion fcpmessage clienthello messagename readline getmessage fcpmessage messagename nodehellomessage messageinvalidexception printstacktrace simplefieldset readfrom fcpmessage addpeer messageinvalidexception printstacktrace fcpsocket socketexception printstacktrace ioexception printstacktrace interruptedexception protected simple field set get message line reading input stream lis simple field set sfs new simple field set true try while lis available 0 string line lis read line 128 128 true int index line index of if index 1 line starts with end return sfs sfs put single line substring 0 index line substring index 1 catch io exception e return sfs return sfs simplefieldset getmessage linereadinginputstream simplefieldset simplefieldset readline indexof startswith putsingle ioexception mime type string type string ext string extra types string extra exts boolean safe to read boolean safe to write content data filter read filter content data filter write filter boolean dangerous links boolean dangerous inlines boolean dangerous scripting boolean dangerous read metadata boolean dangerous write metadata boolean dangerous to write even with filter string read description string write description boolean takesa charset string default charset charset extractor charset extractor this primary mime type type this primary extension ext this alternate mime types extra types this alternate extensions extra exts this safe to read safe to read this safe to write safe to write this read filter read filter this write filter write filter this dangerous links dangerous links this dangerous inlines dangerous inlines this dangerous scripting dangerous scripting this dangerous read metadata dangerous read metadata this dangerous write metadata dangerous write metadata this dangerous to write even with filter dangerous to write even with filter this read description read description this write description write description this takesa charset takesa charset this default charset default charset this charset extractor charset extractor mimetype extratypes extraexts safetoread safetowrite contentdatafilter readfilter contentdatafilter writefilter dangerouslinks dangerousinlines dangerousscripting dangerousreadmetadata dangerouswritemetadata dangeroustowriteevenwithfilter readdescription writedescription takesacharset defaultcharset charsetextractor charsetextractor primarymimetype primaryextension alternatemimetypes extratypes alternateextensions extraexts safetoread safetoread safetowrite safetowrite readfilter readfilter writefilter writefilter dangerouslinks dangerouslinks dangerousinlines dangerousinlines dangerousscripting dangerousscripting dangerousreadmetadata dangerousreadmetadata dangerouswritemetadata dangerouswritemetadata dangeroustowriteevenwithfilter dangeroustowriteevenwithfilter readdescription readdescription writedescription writedescription takesacharset takesacharset defaultcharset defaultcharset charsetextractor charsetextractor throw an exception indicating that this is a dangerous content type public void throw unsafe content type exception throws known unsafe content type exception throw new known unsafe content type exception this throwunsafecontenttypeexception knownunsafecontenttypeexception knownunsafecontenttypeexception occurrence constructor param word lowercased word param position offset of word from the beginning of document text param kind word occurrence kind should be less than 8 public occurrence string word int position int kind this word word this position position this kind kind public int compare to object o occurrence occ occurrence o int diff word compare to occ word if diff 0 diff position occ position return diff compareto compareto public bump filter super emboss matrix bumpfilter embossmatrix override public string to string return blur emboss edges tostring return random chinese text public string get text return simplified chinese texts new random next int simplified chinese texts length gettext simplifiedchinesetexts nextint simplifiedchinesetexts public class option format exception extends invalid config value exception private static final long serial versionuid 1 public option format exception string msg super msg optionformatexception invalidconfigvalueexception serialversionuid optionformatexception data filter exception string raw string encoded string explanation html node html explanation this raw title raw this encoded title encoded this explanation explanation this html explanation html explanation datafilterexception htmlnode htmlexplanation rawtitle encodedtitle htmlexplanation htmlexplanation override public string get explanation return explanation getexplanation override public html node gethtml explanation return html explanation htmlnode gethtmlexplanation htmlexplanation override public string gethtml encoded title return encoded title gethtmlencodedtitle encodedtitle override public string get raw title return raw title getrawtitle rawtitle override public string to string return raw title tostring rawtitle public block receiver message core usm peer context sender long uid partially received block prb byte counter ctr ticker ticker boolean do too long sender sender prb prb uid uid usm usm ctr ctr ticker ticker dotoolong do too long blockreceiver messagecore peercontext partiallyreceivedblock bytecounter dotoolong _sender _prb _uid _usm _ctr _ticker _dotoolong dotoolong public void send aborted int reason string desc throws not connected exception usm send sender dmt create send aborted uid reason desc ctr sent aborted true sendaborted notconnectedexception _usm _sender createsendaborted _uid _ctr sentaborted public byte receive throws retrieval exception long start time system current time millis if dotoolong ticker queue timed job new runnable public void run if sender is connected return try if prb all received return catch aborted exception e return logger error this transfer took too long uid from sender synchronized block receiver this took too long true sender transfer failed took too long still running too long timeout int consecutive missing packet reports 0 try message filter mf packet transmit message filter create set timeout receipt timeout set type dmt packet transmit set field dmt uid uid set source sender message filter mf all sent message filter create set timeout receipt timeout set type dmt all sent set field dmt uid uid set source sender message filter mf send aborted message filter create set timeout receipt timeout set type dmt send aborted set field dmt uid uid set source sender message filter relevant messages mf packet transmit or mf all sent or mf send aborted while prb all received message m1 try m1 usm wait for relevant messages ctr if sender is connected throw new disconnected exception catch disconnected exception e1 logger normal this disconnected during receive uid from sender prb abort retrieval exception sender disconnected disconnected during receive throw new retrieval exception retrieval exception sender disconnected if logminor logger minor this received m1 if m1 null m1 get spec equals dmt send aborted string desc m1 get string dmt description if desc index of upstream 0 desc upstream transmit error desc prb abort m1 get int dmt reason desc synchronized this sender aborted true throw new retrieval exception m1 get int dmt reason desc if m1 null m1 get spec equals dmt packet transmit consecutive missing packet reports 0 packet transmit received int packet no m1 get int dmt packet no bit array sent bit array m1 get object dmt sent buffer data buffer m1 get object dmt data prb add packet packet no data remove it from rrmp if its in there recentlyreportedmissingpackets remove packet no check that we have what the sender thinks we have linked list integer missing new linked list integer for int x 0 x sent get size x if sent bit at x prb is received x sender thinks we have a block which we don t but have we already re requested it recently long resend time recentlyreportedmissingpackets get x if resend time null system current time millis resend time long value make a note of the earliest time we should resend this based on the number of other packets we are already waiting for long resend wait system current time millis max round trip time recentlyreportedmissingpackets size max send interval recentlyreportedmissingpackets put x resend wait missing add x if logminor logger minor this missing missing size if missing size 0 message mn dmt create missing packet notification uid missing usm send sender mn ctr consecutive missing packet reports if missing size 50 logger normal this excessive packet loss mn if m1 null m1 get spec equals dmt all sent if consecutive missing packet reports max consecutive missing packet reports prb abort retrieval exception sender died sender unresponsive to resend requests throw new retrieval exception retrieval exception sender died sender unresponsive to resend requests linked list integer missing new linked list integer for int x 0 x prb get num packets x if prb is received x missing add x message mn dmt create missing packet notification uid missing usm send sender mn ctr consecutive missing packet reports if missing size 50 logger normal this sending large missing packet notification due to packet receiver timeout after receipt timeout ms usm send sender dmt create all received uid ctr discard end time system current time millis cleanup timeout discard filter relevant messages maybe reset discard filter long end time system current time millis long transfer time end time start time if logminor synchronized avg time taken avg time taken report transfer time logger minor this block transfer took transfer time ms average is avg time taken return prb get block catch not connected exception e throw new retrieval exception retrieval exception sender disconnected catch aborted exception e we didn t cause it logger error this caught in receive probably a bug as receive sets it e throw new retrieval exception retrieval exception unknown aborted finally try if prb is aborted sent aborted send aborted prb get abort reason prb get abort description catch not connected exception e ignore retrievalexception starttime currenttimemillis _dotoolong _ticker queuetimedjob _sender isconnected _prb allreceived abortedexception _uid _sender blockreceiver tooktoolong _sender transferfailed too_long_timeout consecutivemissingpacketreports messagefilter mfpackettransmit messagefilter settimeout receipt_timeout settype packettransmit setfield _uid setsource _sender messagefilter mfallsent messagefilter settimeout receipt_timeout settype allsent setfield _uid setsource _sender messagefilter mfsendaborted messagefilter settimeout receipt_timeout settype sendaborted setfield _uid setsource _sender messagefilter relevantmessages mfpackettransmit mfallsent mfsendaborted _prb allreceived _usm waitfor relevantmessages _ctr _sender isconnected disconnectedexception disconnectedexception _uid _sender _prb retrievalexception sender_disconnected retrievalexception retrievalexception sender_disconnected getspec sendaborted getstring indexof _prb getint senderaborted retrievalexception getint getspec packettransmit consecutivemissingpacketreports packettransmit packetno getint packet_no bitarray bitarray getobject getobject _prb addpacket packetno _recentlyreportedmissingpackets packetno linkedlist linkedlist getsize bitat _prb isreceived resendtime _recentlyreportedmissingpackets resendtime currenttimemillis resendtime longvalue resendwait currenttimemillis max_round_trip_time _recentlyreportedmissingpackets max_send_interval _recentlyreportedmissingpackets resendwait createmissingpacketnotification _uid _usm _sender _ctr consecutivemissingpacketreports getspec allsent consecutivemissingpacketreports max_consecutive_missing_packet_reports _prb retrievalexception sender_died retrievalexception retrievalexception sender_died linkedlist linkedlist _prb getnumpackets _prb isreceived createmissingpacketnotification _uid _usm _sender _ctr consecutivemissingpacketreports missingpacketnotification receipt_timeout _usm _sender createallreceived _uid _ctr discardendtime currenttimemillis cleanup_timeout discardfilter relevantmessages mayberesetdiscardfilter endtime currenttimemillis transfertime endtime starttime avgtimetaken avgtimetaken transfertime transfertime avgtimetaken _prb getblock notconnectedexception retrievalexception retrievalexception sender_disconnected abortedexception retrievalexception retrievalexception _prb isaborted sentaborted sendaborted _prb getabortreason _prb getabortdescription notconnectedexception private void maybe reset discard filter long timeleft discard end time system current time millis if timeleft 0 try discard filter set timeout int timeleft usm add async filter discard filter this catch disconnected exception e ignore mayberesetdiscardfilter discardendtime currenttimemillis discardfilter settimeout _usm addasyncfilter discardfilter disconnectedexception used to discard leftover messages usually just packet transmit and all sent all sent is quite common as the receive routine usually quits immeadiately on receiving all packets packet transmit is less common when receive requested what it thought was a missing packet only reordered public void on matched message m if logminor logger minor this discarding message post receive m maybe reset discard filter packettransmit allsent allsent packettransmit onmatched mayberesetdiscardfilter public boolean should timeout return false shouldtimeout public void on timeout ignore ontimeout public void on disconnect peer context ctx ignore ondisconnect peercontext public void on restarted peer context ctx ignore onrestarted peercontext public synchronized boolean sender aborted return sender aborted senderaborted senderaborted public notify request notifyrequest public notify request http request http req set http req notifyrequest httprequest httpreq httpreq public void setnt string value set header http nt value setheader public void setnts string value set header http nts value setheader public void setsid string id set header http sid subscription tosid header string id setheader tosidheaderstring public string getsid return subscription getsid get header value http sid getheadervalue public void setseq long value set header http seq long to string value setheader tostring public long getseq return get long header value http seq getlongheadervalue public boolean set request subscriber sub string var name string value string sid sub getsid long notify cnt sub get notify count string host sub get delivery host string path sub get delivery path int port sub get delivery port set method http notify seturi path set host host port setnt nt event setnts nts propchange setsid sid setseq notify cnt set content type xml content type node prop set node create property set node var name value set content prop set node return true setrequest varname notifycnt getnotifycount getdeliveryhost getdeliverypath getdeliveryport setmethod sethost notifycnt setcontenttype content_type propsetnode createpropertysetnode varname setcontent propsetnode private node create property set node string var name string value node prop set node new node xmlns soap delim propertyset prop set node set name space xmlns subscription xmlns node prop node new node xmlns soap delim property prop set node add node prop node thanks for giordano sassaroli sassarol cefriel it 05 22 03 node var name node new node xmlns soap delim var name node var name node new node var name var name node set value value prop node add node var name node return prop set node createpropertysetnode varname propsetnode propsetnode setnamespace propnode propsetnode addnode propnode varnamenode varname varnamenode varname varnamenode setvalue propnode addnode varnamenode propsetnode thanks for giordano sassaroli sassarol cefriel it 09 08 03 private property get property node var node property prop new property if var node null return prop remove the event namespace string variable name var node get name int index variable name last index of if index 1 variable name variable name substring index 1 prop set name variable name prop set value var node get value return prop getproperty varnode varnode variablename varnode getname variablename lastindexof variablename variablename setname variablename setvalue varnode getvalue thanks for giordano sassaroli sassarol cefriel it 09 08 03 public property list get property list property list properties new property list node var set node get envelope node for int i 0 i var set node getn nodes i node prop node var set node get node i if prop node null continue property prop get property prop node get node 0 properties add prop return properties propertylist getpropertylist propertylist propertylist varsetnode getenvelopenode varsetnode getnnodes propnode varsetnode getnode propnode getproperty propnode getnode public get plugin info simple field set fs throws message invalid exception identifier fs get identifier optional detailed fields string to bool fs get detailed false plugname fs get plugin name if plugname null throw new message invalid exception protocol error message missing field get plugin info must contain a plugin name field null false getplugininfo simplefieldset messageinvalidexception stringtobool pluginname messageinvalidexception protocolerrormessage missing_field getplugininfo pluginname override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if detailed handler has full access throw new message invalid exception protocol error message access denied get plugin info detailed requires full access identifier false plugin info wrapper pi node plugin manager getfcp plugin info plugname if pi null handler output handler queue new protocol error message protocol error message no such plugin false plugin plugname does not exist or is not a fcp plugin identifier false else handler output handler queue new plugin info message pi identifier detailed fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied getplugininfo plugininfowrapper pluginmanager getfcpplugininfo outputhandler protocolerrormessage protocolerrormessage no_such_plugin outputhandler plugininfomessage override public void remove from object container container container delete this removefrom objectcontainer static string get svn revision return svn revision getsvnrevision svnrevision public static void main string args system out println system out println svn revision system out println svnrevision public static string get marketing version return 0 4 0 beta get svn revision getmarketingversion getsvnrevision public static long get real version return version getrealversion public final static boolean is all device string value if value null return false if value equals all device true return true return value equals all device isalldevice all_device all_device public final static boolean is root device string value if value null return false if value equals root device true return true return value equals root device isrootdevice root_device root_device public final static boolean isuuid device string value if value null return false if value starts with uuid device true return true return value starts with uuid device isuuiddevice startswith uuid_device startswith uuid_device public final static boolean isurn device string value if value null return false if value starts with urn device true return true return value starts with urn device isurndevice startswith urn_device startswith urn_device public final static boolean isurn service string value if value null return false if value starts with urn service true return true return value starts with urn service isurnservice startswith urn_service startswith urn_service persistent chosen request sendable request req short prio int retry count object container container request scheduler sched client context context throws no valid blocks exception request req this prio prio this retry count retry count if req instanceof sendable get sendable get sg sendable get req fetch context ctx sg get context if container null container activate ctx 1 local request only ctx local request only cache local requests ctx cache local requests ignore store ctx ignore store else sendable insert sg sendable insert req local request only false cache local requests sg cache inserts container ignore store false blocks not started new array list persistent chosen block blocks started new array list persistent chosen block blocks finished new array list persistent chosen block this scheduler sched fill up blocks not started boolean req active container ext is active req if req active container activate req 1 list persistent chosen block candidates req make blocks this sched container context if candidates null if req active container deactivate req 1 throw new no valid blocks exception for persistent chosen block block candidates key key block key if key null sched has fetching key key block on dumped continue blocks not started add block sender req get sender container context if req active container deactivate req 1 logminor logger should log logger minor this persistentchosenrequest sendablerequest retrycount objectcontainer requestscheduler clientcontext novalidblocksexception retrycount retrycount sendableget sendableget sendableget fetchcontext getcontext localrequestonly localrequestonly cachelocalrequests cachelocalrequests ignorestore ignorestore sendableinsert sendableinsert localrequestonly cachelocalrequests cacheinserts ignorestore blocksnotstarted arraylist persistentchosenblock blocksstarted arraylist persistentchosenblock blocksfinished arraylist persistentchosenblock blocksnotstarted reqactive isactive reqactive persistentchosenblock makeblocks reqactive novalidblocksexception persistentchosenblock hasfetchingkey ondumped blocksnotstarted getsender reqactive shouldlog void on finished persistent chosen block block client context context logminor logger should log logger minor this if logminor logger minor this on finished on this for block new exception debug synchronized this remove by pointer for int i 0 i blocks not started size i if blocks not started get i block blocks not started remove i logger error this block finished but was in blocks not started block for this new exception error i for int i 0 i blocks started size i if blocks started get i block blocks started remove i i for persistent chosen block cmp blocks finished if cmp block logger error this block already in blocks finished block for this return blocks finished add block if blocks not started is empty blocks started is empty if logminor logger minor this not finishing yet blocks not started blocks not started size started blocks started size finished blocks finished size return all finished context job runner queue new db job public void run object container container client context context finish container context false false native thread norm priority 1 false onfinished persistentchosenblock clientcontext shouldlog onfinished blocksnotstarted blocksnotstarted blocksnotstarted blocksnotstarted blocksstarted blocksstarted blocksstarted persistentchosenblock blocksfinished blocksfinished blocksfinished blocksnotstarted isempty blocksstarted isempty blocksnotstarted blocksstarted blocksfinished jobrunner dbjob objectcontainer clientcontext nativethread norm_priority context job runner queue new db job public void run object container container client context context finish container context false false jobrunner dbjob objectcontainer clientcontext private void finish object container container client context context boolean dumping boolean already active if container ext is stored request if logminor logger minor this request apparently already deleted request on this scheduler remove running request request return if already active container ext is active request logger error this already activated request new exception debug if already active container activate request 1 logger normal this finishing this for request call all the callbacks persistent chosen block finished blocks int started size synchronized this if finished if blocks finished is empty okay if already active container deactivate request 1 don t remove running request because we ve already done that return else logger error this finished but blocks finished not empty on this new exception debug process the blocks started size blocks started size if started size 0 logger error this still waiting for callbacks on this for started size blocks wait if we set finished we have to process them now and we can t process them now because we haven t had the callbacks we don t know what the outcome will be don t remove running request because we re not finished yet return finished true finished blocks blocks finished to array new persistent chosen block blocks finished size if finished blocks length 0 if dumping logger error this no finished blocks in finish on this else if logminor logger minor this no finished blocks in finish on this remove from running requests we won t be called scheduler remove running request request if already active container deactivate request 1 return if request instanceof sendable get boolean supports bulk request instanceof supports bulk call failure vector bulk call failure item bulk fail items null for persistent chosen block block finished blocks if block fetch succeeded low level get exception e block failed get if supports bulk if bulk fail items null bulk fail items new vector bulk call failure item bulk fail items add new bulk call failure item e block token else sendable get request on failure e block token container context container commit db4o is read committed so we need to commit here if bulk fail items null supports bulk call failure request on failure bulk fail items to array new bulk call failure item bulk fail items size container context container commit db4o is read committed so we need to commit here else if request instanceof sendable insert container activate request 1 for persistent chosen block block finished blocks container activate block 1 if block insert succeeded sendable insert request on success block token container context container commit db4o is read committed so we need to commit here else sendable insert request on failure block failed put block token container context container commit db4o is read committed so we need to commit here scheduler remove running request request if request instanceof sendable insert more blocks may have been added because splitfile inserts do not separate retries into separate sendable insert s if container ext is active request container activate request 1 if request is empty container request is cancelled container request get scheduler context maybe add to starter queue request container null request get scheduler context wake starter if already active container deactivate request 1 objectcontainer clientcontext alreadyactive isstored removerunningrequest alreadyactive isactive alreadyactive persistentchosenblock finishedblocks startedsize blocksfinished isempty alreadyactive removerunningrequest blocksfinished startedsize blocksstarted startedsize startedsize removerunningrequest finishedblocks blocksfinished toarray persistentchosenblock blocksfinished finishedblocks removerunningrequest alreadyactive sendableget supportsbulk supportsbulkcallfailure bulkcallfailureitem bulkfailitems persistentchosenblock finishedblocks fetchsucceeded lowlevelgetexception failedget supportsbulk bulkfailitems bulkfailitems bulkcallfailureitem bulkfailitems bulkcallfailureitem sendableget onfailure bulkfailitems supportsbulkcallfailure onfailure bulkfailitems toarray bulkcallfailureitem bulkfailitems sendableinsert persistentchosenblock finishedblocks insertsucceeded sendableinsert onsuccess sendableinsert onfailure failedput removerunningrequest sendableinsert sendableinsert isactive isempty iscancelled getscheduler maybeaddtostarterqueue getscheduler wakestarter alreadyactive public chosen block grab not started random random request scheduler sched array list persistent chosen block dumped null try synchronized this while true int size blocks not started size if size 0 return null persistent chosen block ret if size 1 ret blocks not started remove 0 else ret blocks not started remove random next int size key key ret key if key null sched has fetching key key already fetching remove from list if dumped null dumped new array list persistent chosen block dumped add ret continue blocks started add ret return ret finally if dumped null for persistent chosen block block dumped block on dumped chosenblock grabnotstarted requestscheduler arraylist persistentchosenblock blocksnotstarted persistentchosenblock blocksnotstarted blocksnotstarted nextint hasfetchingkey arraylist persistentchosenblock blocksstarted persistentchosenblock ondumped public synchronized int size not started return blocks not started size sizenotstarted blocksnotstarted public void on dumped client request scheduler core core object container container boolean req already active if logminor logger minor this dumping this scheduler remove running request request boolean was started persistent chosen block blocks synchronized this blocks blocks not started to array new persistent chosen block blocks not started size blocks not started clear was started blocks started is empty for persistent chosen block block blocks block on dumped if was started if logminor logger minor this finishing immediately in on dumped as nothing pending this finish container core sched client context true req already active ondumped clientrequestschedulercore objectcontainer reqalreadyactive removerunningrequest wasstarted persistentchosenblock blocksnotstarted toarray persistentchosenblock blocksnotstarted blocksnotstarted wasstarted blocksstarted isempty persistentchosenblock ondumped wasstarted ondumped clientcontext reqalreadyactive public synchronized void prune duplicates client request scheduler sched for int i 0 i blocks not started size i persistent chosen block block blocks not started get i key key block key if key null continue if sched has fetching key key blocks not started remove i if logminor logger minor this pruned duplicate block from this i pruneduplicates clientrequestscheduler blocksnotstarted persistentchosenblock blocksnotstarted hasfetchingkey blocksnotstarted copy from the input stream of code src code to the output stream of code dest code param src param dst throws io exception public final static void copy bucket src bucket dst throws io exception output stream out dst get output stream input stream in src get input stream readable byte channel read channel channels new channel in writable byte channel write channel channels new channel out byte buffer buffer byte buffer allocate direct block size while read channel read buffer 1 buffer flip while buffer has remaining write channel write buffer buffer clear write channel close read channel close ioexception ioexception outputstream getoutputstream inputstream getinputstream readablebytechannel readchannel newchannel writablebytechannel writechannel newchannel bytebuffer bytebuffer allocatedirect block_size readchannel hasremaining writechannel writechannel readchannel public final static void zero pad bucket b long size throws io exception output stream out b get output stream initialized to zero by default byte buffer new byte 16384 long count 0 while count size long n required buffer length if n required size count n required size count out write buffer 0 int n required count n required out close zeropad ioexception outputstream getoutputstream nrequired nrequired nrequired nrequired nrequired public final static void padded copy bucket from bucket to long n bytes int block size throws io exception if n bytes block size throw new illegal argument exception n bytes block size output stream out null input stream in null try out to get output stream byte buffer new byte 16384 in from get input stream long count 0 while count n bytes long n required n bytes count if n required buffer length n required buffer length long n read in read buffer 0 int n required if n read 1 throw new io exception not enough data in source bucket out write buffer 0 int n read count n read if count block size hmmm better to just allocate a new buffer instead of explicitly zeroing the old one zero pad to block size long pad length buffer length if pad length block size n bytes pad length block size n bytes for int i 0 i pad length i buffer i 0 while count block size long n required block size count if block size count buffer length n required buffer length out write buffer 0 int n required count n required finally if in null in close if out null out close paddedcopy nbytes blocksize ioexception nbytes blocksize illegalargumentexception nbytes blocksize outputstream inputstream getoutputstream getinputstream nbytes nrequired nbytes nrequired nrequired nread nrequired nread ioexception nread nread blocksize blocksize padlength padlength blocksize nbytes padlength blocksize nbytes padlength blocksize nrequired blocksize blocksize nrequired nrequired nrequired public static bucket make buckets bucket factory bf int count int size throws io exception bucket ret new bucket count for int i 0 i count i ret i bf make bucket size return ret makebuckets bucketfactory ioexception makebucket public final static int null indices bucket array list integer list new array list integer for int i 0 i array length i if array i null list add i int ret new int list size for int i 0 i list size i ret i list get i return ret nullindices arraylist public final static int non null indices bucket array list integer list new array list integer for int i 0 i array length i if array i null list add i int ret new int list size for int i 0 i list size i ret i list get i return ret nonnullindices arraylist public final static bucket non null buckets bucket array list bucket list new array list bucket array length for int i 0 i array length i if array i null list add array i bucket ret new bucket list size return list to array ret nonnullbuckets arraylist toarray read the entire bucket in as a byte array not a good idea unless it is very small don t call if concurrent writes may be happening throws io exception if there was an error reading from the bucket throws out of memory error if it was not possible to allocate enough memory to contain the entire bucket public final static byte to byte array bucket bucket throws io exception long size bucket size if size integer max value throw new out of memory error byte data new byte int size input stream is bucket get input stream data input stream dis null try dis new data input stream is dis read fully data finally closer close dis closer close is return data ioexception outofmemoryerror tobytearray ioexception max_value outofmemoryerror inputstream getinputstream datainputstream datainputstream readfully public static int to byte array bucket bucket byte output throws io exception long size bucket size if size output length throw new illegal argument exception data does not fit in provided buffer input stream is null try is bucket get input stream int moved 0 while true if moved size return moved int x is read output moved int size moved if x 1 return moved moved x finally if is null is close tobytearray ioexception illegalargumentexception inputstream getinputstream public static bucket make immutable bucket bucket factory bucket factory byte data throws io exception return make immutable bucket bucket factory data data length makeimmutablebucket bucketfactory bucketfactory ioexception makeimmutablebucket bucketfactory public static bucket make immutable bucket bucket factory bucket factory byte data int length throws io exception bucket bucket bucket factory make bucket length output stream os bucket get output stream os write data 0 length os close bucket set read only return bucket makeimmutablebucket bucketfactory bucketfactory ioexception bucketfactory makebucket outputstream getoutputstream setreadonly public static byte hash bucket data throws io exception input stream is data get input stream try message digest md sha256 get message digest try long bucket length data size long bytes read 0 byte buf new byte 4096 while bytes read bucket length bucket length 1 int read bytes is read buf if read bytes 0 break bytes read read bytes if read bytes 0 md update buf 0 read bytes if bytes read bucket length bucket length 0 throw new eof exception if bytes read bucket length bucket length 0 throw new io exception read bytes read but bucket length bucket length on data byte retval md digest return retval finally sha256 return message digest md finally if is null is close ioexception inputstream getinputstream messagedigest getmessagedigest bucketlength bytesread bytesread bucketlength bucketlength readbytes readbytes bytesread readbytes readbytes readbytes bytesread bucketlength bucketlength eofexception bytesread bucketlength bucketlength ioexception bytesread bucketlength returnmessagedigest copy the given quantity of data from the given bucket to the given output stream throws io exception if there was an error reading from the bucket or writing to the stream public static long copy to bucket decoded data output stream os long truncate length throws io exception if truncate length 0 return 0 if truncate length 0 truncate length long max value input stream is decoded data get input stream try byte buf new byte 4096 long moved 0 while moved truncate length do not move the int inside the math min big numbers truncate to negative numbers int bytes int math min buf length truncate length moved if bytes 0 throw new illegal state exception bytes bytes truncate length truncate length moved moved bytes is read buf 0 bytes if bytes 0 if truncate length long max value break io exception io exception new io exception could not move required quantity of data in copy to bytes moved moved of truncate length unable to read from is io exception print stack trace throw io exception os write buf 0 bytes moved bytes return moved finally is close os flush outputstream ioexception copyto decodeddata outputstream truncatelength ioexception truncatelength truncatelength truncatelength max_value inputstream decodeddata getinputstream truncatelength truncatelength illegalstateexception truncatelength truncatelength truncatelength max_value ioexception ioexception ioexception copyto truncatelength ioexception printstacktrace ioexception copy data from an input stream into a bucket public static void copy from bucket bucket input stream is long truncate length throws io exception output stream os bucket get output stream byte buf new byte 4096 if truncate length 0 truncate length long max value try long moved 0 while moved truncate length do not move the int inside the math min big numbers truncate to negative numbers int bytes int math min buf length truncate length moved if bytes 0 throw new illegal state exception bytes bytes truncate length truncate length moved moved bytes is read buf 0 bytes if bytes 0 if truncate length long max value break io exception io exception new io exception could not move required quantity of data in copy from bytes moved moved of truncate length unable to read from is io exception print stack trace throw io exception os write buf 0 bytes moved bytes finally os close inputstream copyfrom inputstream truncatelength ioexception outputstream getoutputstream truncatelength truncatelength max_value truncatelength truncatelength illegalstateexception truncatelength truncatelength truncatelength max_value ioexception ioexception ioexception copyfrom truncatelength ioexception printstacktrace ioexception split the data into a series of read only bucket s param orig data the original data bucket param split size the number of bytes to put into each bucket if the passed in bucket is a file bucket will be efficiently split into read only file slice buckets otherwise new buckets are created and the data written to them note that this method will allocate a buffer of size split size param free data param persistent if true the data is persistent this method is responsible for ensuring that the returned buckets have already been stored to the database using the provided handle the point segmentedbcb s buckets have already been stored param container database handle only needed if persistent true throws io exception if there is an error creating buckets reading from the provided bucket or writing to created buckets public static bucket split bucket orig data int split size bucket factory bf boolean free data boolean persistent object container container throws io exception if orig data instanceof file bucket if free data logger error bucket tools class asked to free data when splitting a file bucket not freeing as this would clobber the split result bucket buckets file bucket orig data split split size if persistent for bucket bucket buckets bucket store to container return buckets if orig data instanceof bucket chain bucket if persistent throw new illegal argument exception splitting a bucket chain bucket but persistent true bucket chain bucket data bucket chain bucket orig data if data bucket size split size bucket buckets data get buckets if free data data clear return buckets else logger error bucket tools class incompatible split size splitting a bucket chain bucket his split size is data bucket size but mine is split size we will copy the data but this suggests a bug new exception debug if orig data instanceof segmented bucket chain bucket segmented bucket chain bucket data segmented bucket chain bucket orig data if data bucket size split size bucket buckets data get buckets if free data data clear if persistent free data data remove from container buckets have already been stored no need to store to return buckets else logger error bucket tools class incompatible split size splitting a bucket chain bucket his split size is data bucket size but mine is split size we will copy the data but this suggests a bug new exception debug long length orig data size if length long integer max value split size throw new illegal argument exception way too big length for split size int bucket count int length split size if length split size 0 bucket count if logger should log logger minor bucket tools class logger minor bucket tools class splitting bucket orig data of size length into bucket count buckets bucket buckets new bucket bucket count input stream is orig data get input stream data input stream dis null try dis new data input stream is long remaining length length byte buf new byte split size for int i 0 i bucket count i int len int math min split size remaining length bucket bucket bf make bucket len buckets i bucket dis read fully buf 0 len remaining length len output stream os bucket get output stream try os write buf 0 len finally os close finally if dis null dis close else is close if free data orig data free if persistent free data orig data remove from container if persistent for bucket bucket buckets bucket store to container return buckets origdata splitsize filebucket readonlyfileslicebuckets splitsize freedata ioexception origdata splitsize bucketfactory freedata objectcontainer ioexception origdata filebucket freedata buckettools filebucket filebucket origdata splitsize storeto origdata bucketchainbucket illegalargumentexception bucketchainbucket bucketchainbucket bucketchainbucket origdata bucketsize splitsize getbuckets freedata buckettools bucketchainbucket bucketsize splitsize origdata segmentedbucketchainbucket segmentedbucketchainbucket segmentedbucketchainbucket origdata bucketsize splitsize getbuckets freedata freedata removefrom storeto buckettools bucketchainbucket bucketsize splitsize origdata max_value splitsize illegalargumentexception splitsize bucketcount splitsize splitsize bucketcount shouldlog buckettools buckettools origdata bucketcount bucketcount inputstream origdata getinputstream datainputstream datainputstream remaininglength splitsize bucketcount splitsize remaininglength makebucket readfully remaininglength outputstream getoutputstream freedata origdata freedata origdata removefrom storeto pad a bucket with random data param old bucket param block length param bucket factory param length return the paded bucket public static bucket pad bucket old bucket int block length bucket factory bf int length throws io exception byte hash bucket tools hash old bucket bucket b bf make bucket block length mersenne twister mt new mersenne twister hash output stream os b get output stream try bucket tools copy to old bucket os length byte buf new byte 4096 for int x length x block length int remaining block length x int this cycle math min remaining buf length mt next bytes buf fixme os write buf 0 this cycle x this cycle os close os null if b size block length throw new illegal state exception the bucket s size is b size whereas it should be block length return b finally closer close os oldbucket blocklength bucketfactory oldbucket blocklength bucketfactory ioexception buckettools oldbucket makebucket blocklength mersennetwister mersennetwister outputstream getoutputstream buckettools copyto oldbucket blocklength blocklength thiscycle nextbytes thiscycle thiscycle blocklength illegalstateexception blocklength final fcp connection handler handler public plugin reply senderfcp fcp connection handler handler2 string pluginname2 string identifier2 super pluginname2 identifier2 handler handler2 fcpconnectionhandler pluginreplysenderfcp fcpconnectionhandler override public void send simple field set params bucket bucket throws plugin not found exception like in linux everthing is a file in plugintalker everything is a plugin so it throws plugin not found exception instead fcp connection errors if handler is closed throw new plugin not found exception fcp connection closed fcp plugin reply reply new fcp plugin reply pluginname identifier params bucket handler output handler queue reply simplefieldset pluginnotfoundexception pluginnotfoundexception isclosed pluginnotfoundexception fcppluginreply fcppluginreply outputhandler public buffered image create compatible dest image buffered image src color model dstcm if dstcm null dstcm src get color model return new buffered image dstcm dstcm create compatible writable raster src get width src get height dstcm is alpha premultiplied null bufferedimage createcompatibledestimage bufferedimage colormodel getcolormodel bufferedimage createcompatiblewritableraster getwidth getheight isalphapremultiplied public rectangle2d get bounds2d buffered image src return new rectangle 0 0 src get width src get height getbounds2d bufferedimage getwidth getheight public point2d get point2d point2d src pt point2d dst pt if dst pt null dst pt new point2d double dst pt set location src pt getx src pt gety return dst pt getpoint2d srcpt dstpt dstpt dstpt dstpt setlocation srcpt srcpt dstpt public rendering hints get rendering hints return null renderinghints getrenderinghints a convenience method for getting argb pixels from an image this tries to avoid the performance penalty of buffered image getrgb unmanaging the image param image a buffered image object param x the left edge of the pixel block param y the right edge of the pixel block param width the width of the pixel arry param height the height of the pixel arry param pixels the array to hold the returned pixels may be null return the pixels see setrgb public int getrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb return int image get raster get data elements x y width height pixels return image getrgb x y width height pixels 0 width bufferedimage bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster getdataelements a convenience method for setting argb pixels in an image this tries to avoid the performance penalty of buffered image setrgb unmanaging the image param image a buffered image object param x the left edge of the pixel block param y the right edge of the pixel block param width the width of the pixel arry param height the height of the pixel arry param pixels the array of pixels to set see getrgb public void setrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb image get raster set data elements x y width height pixels else image setrgb x y width height pixels 0 width bufferedimage bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster setdataelements override public object clone try return super clone catch clone not supported exception e return null clonenotsupportedexception protected key byte routing key this routing key routing key hash fields hash code routing key cached normalized double 1 routingkey routingkey routingkey hashcode routingkey cachednormalizeddouble protected key key key this hash key hash this cached normalized double key cached normalized double this routing key new byte key routing key length system arraycopy key routing key 0 routing key 0 routing key length cachednormalizeddouble cachednormalizeddouble routingkey routingkey routingkey routingkey routingkey public abstract key clone key clonekey write to disk take up exactly 22 bytes param index _index read a key from a random access file param raf the file to read from return a key or throw an exception or return null if the key is not parsable public static final key read data input raf throws io exception byte type raf read byte byte subtype raf read byte if type nodechk base type return nodechk readchk raf subtype else if type nodessk base type return nodessk readssk raf subtype throw new io exception unrecognized format type randomaccessfile datainput ioexception readbyte readbyte base_type base_type ioexception public static key block create block short key type byte key bytes byte headers bytes byte data bytes byte pubkey bytes throws key verify exception byte type byte key type 8 byte subtype byte key type 0xff if type nodechk base type return chk block construct data bytes headers bytes else if type nodessk base type dsa public key pub key try pub key new dsa public key pubkey bytes catch io exception e throw new key verify exception failed to construct pubkey e e catch crypt format exception e throw new key verify exception failed to construct pubkey e e nodessk key new nodessk pub key as bytes hash key bytes pub key subtype return new ssk block data bytes headers bytes key false else throw new key verify exception no such key type integer to hex string type keyblock createblock keytype keybytes headersbytes databytes pubkeybytes keyverifyexception keytype keytype base_type chkblock databytes headersbytes base_type dsapublickey pubkey pubkey dsapublickey pubkeybytes ioexception keyverifyexception cryptformatexception keyverifyexception pubkey asbyteshash keybytes pubkey sskblock databytes headersbytes keyverifyexception tohexstring convert the key to a double between 0 0 and 1 0 normally we will hash the key first in order to make chosen key attacks harder public synchronized double to normalized double if cached normalized double 0 return cached normalized double message digest md sha256 get message digest if routing key null throw new null pointer exception md update routing key int type get type md update byte type 8 md update byte type byte digest md digest sha256 return message digest md md null long as long math abs fields bytes to long digest math abs can actually return negative if as long long min value as long long max value cached normalized double double as long double long max value return cached normalized double tonormalizeddouble cachednormalizeddouble cachednormalizeddouble messagedigest getmessagedigest routingkey nullpointerexception routingkey gettype returnmessagedigest aslong bytestolong aslong min_value aslong max_value cachednormalizeddouble aslong max_value cachednormalizeddouble public abstract short get type gettype public abstract short get type override public int hash code return hash gettype hashcode override public boolean equals object o if o null o instanceof key return false return arrays equals routing key key o routing key routingkey routingkey static bucket decompress boolean is compressed byte output int output length bucket factory bf long max length short compression algorithm boolean short length throws chk decode exception io exception if max length 0 throw new illegal argument exception maxlength max length if is compressed if logger should log logger minor key class logger minor key class decompressing output length bytes in decode with codec compression algorithm if output length short length 3 5 throw new chk decode exception no bytes to decompress decompress first get the length int len if short length len output 0 0xff 8 output 1 0xff else len output 0 0xff 8 output 1 0xff 8 output 2 0xff 8 output 3 0xff if len max length throw new too big exception invalid precompressed size len maxlength max length compressor type decompressor compressor type get compressor by metadataid compression algorithm if decompressor null throw new chk decode exception unknown compression algorithm compression algorithm bucket input bucket new simple read only array bucket output short length 2 4 output length short length 2 4 try return decompressor decompress input bucket bf max length 1 null catch compression output size exception e throw new too big exception too big else return bucket tools make immutable bucket bf output output length iscompressed outputlength bucketfactory maxlength compressionalgorithm shortlength chkdecodeexception ioexception maxlength illegalargumentexception maxlength iscompressed shouldlog compressionalgorithm shortlength chkdecodeexception shortlength maxlength toobigexception maxlength compressor_type compressor_type getcompressorbymetadataid compressionalgorithm chkdecodeexception compressionalgorithm inputbucket simplereadonlyarraybucket shortlength outputlength shortlength inputbucket maxlength compressionoutputsizeexception toobigexception buckettools makeimmutablebucket outputlength static class compressed public compressed byte final data short compression algorithm2 this compressed data final data this compression algorithm compression algorithm2 finaldata compressionalgorithm2 compresseddata finaldata compressionalgorithm compressionalgorithm2 static compressed compress bucket source data boolean dont compress short already compressed codec long source length long max length before compression int max compressed data length boolean short length throws key encode exception io exception byte final data null short compression algorithm 1 int max compressed data length max compressed data length if short length max compressed data length 2 else max compressed data length 4 if source data size max length before compression throw new key encode exception too big if dont compress already compressed codec 0 byte cbuf null if already compressed codec 0 if source data size max compressed data length throw new too big exception too big precompressed compression algorithm already compressed codec cbuf bucket tools to byte array source data if source length max length before compression throw new too big exception too big else if source data size max compressed data length determine the best algorithm for compressor type comp compressor type values array bucket compressed data try compressed data array bucket comp compress source data new array bucket factory long max value max compressed data length catch io exception e throw new error e catch compression output size exception e continue if compressed data size max compressed data length compression algorithm comp metadataid source length source data size try cbuf bucket tools to byte array compressed data fixme provide a method in array bucket catch io exception e throw new error e break if cbuf null use it int compressed length cbuf length final data new byte compressed length short length 2 4 system arraycopy cbuf 0 final data short length 2 4 compressed length if short length final data 0 byte source length 24 0xff final data 1 byte source length 16 0xff final data 2 byte source length 8 0xff final data 3 byte source length 0xff else final data 0 byte source length 8 0xff final data 1 byte source length 0xff if final data null not compressed or not compressible no size bytes to be added if source data size max compressed data length throw new chk encode exception too big source data size should be max compressed data length final data bucket tools to byte array source data return new compressed final data compression algorithm sourcedata dontcompress alreadycompressedcodec sourcelength max_length_before_compression max_compressed_data_length shortlength keyencodeexception ioexception finaldata compressionalgorithm maxcompresseddatalength max_compressed_data_length shortlength maxcompresseddatalength maxcompresseddatalength sourcedata max_length_before_compression keyencodeexception dontcompress alreadycompressedcodec alreadycompressedcodec sourcedata maxcompresseddatalength toobigexception compressionalgorithm alreadycompressedcodec buckettools tobytearray sourcedata sourcelength max_length_before_compression toobigexception sourcedata maxcompresseddatalength compressor_type compressor_type arraybucket compresseddata compresseddata arraybucket sourcedata arraybucketfactory max_value maxcompresseddatalength ioexception compressionoutputsizeexception compresseddata maxcompresseddatalength compressionalgorithm sourcelength sourcedata buckettools tobytearray compresseddata arraybucket ioexception compressedlength finaldata compressedlength shortlength finaldata shortlength compressedlength shortlength finaldata sourcelength finaldata sourcelength finaldata sourcelength finaldata sourcelength finaldata sourcelength finaldata sourcelength finaldata sourcedata max_compressed_data_length chkencodeexception sourcedata max_compressed_data_length finaldata buckettools tobytearray sourcedata finaldata compressionalgorithm public byte get routing key return routing key getroutingkey routingkey not just the routing key enough data to reconstruct the key excluding any pubkey needed public byte get key bytes return routing key getkeybytes routingkey public static client key block create key block client key key key block block throws key verify exception if key instanceof clientssk return clientssk block construct ssk block block clientssk key else if key instanceof clientchk return new clientchk block chk block block clientchk key clientkeyblock createkeyblock clientkey keyblock keyverifyexception clientsskblock sskblock clientchkblock chkblock get the full key including any crypto type bytes everything needed to construct a key object public abstract byte get full key getfullkey public abstract byte get full key public void remove from object container container container delete this getfullkey removefrom objectcontainer returns a dsa signature given a group private key x a random nonce k and the hash of the message m static dsa signature sign dsa group g dsa private key x big integer k big integer m random source random if k signum 1 throw new illegal argument exception if m signum 1 throw new illegal argument exception if g getq bit length 256 m m and signature mask if m compare to g getq 1 throw new illegal argument exception big integer r g getg mod pow k g getp mod g getq big integer k inv k mod inverse g getq return sign g x r k inv m random dsasignature dsagroup dsaprivatekey biginteger biginteger randomsource illegalargumentexception illegalargumentexception bitlength signature_mask compareto illegalargumentexception biginteger modpow biginteger kinv modinverse kinv public static dsa signature sign dsa group g dsa private key x big integer m random source r big integer k dsa generatek g r return sign g x k m r dsasignature dsagroup dsaprivatekey biginteger randomsource biginteger returns a dsa signature given a group private key x the precalculated values of r and k 1 and the hash of the message m static dsa signature sign dsa group g dsa private key x big integer r big integer k inv big integer m random source random big integer s1 m add x getx multiply r mod g getq big integer s k inv multiply s1 mod g getq if r compare to big integer zero 0 s compare to big integer zero 0 logger normal dsa class r or s equals 0 weird behaviour detected please report if seen too often return sign g x r generatek g random m random return new dsa signature r s dsasignature dsagroup dsaprivatekey biginteger biginteger kinv biginteger randomsource biginteger biginteger kinv compareto biginteger compareto biginteger dsasignature private static big integer generatek dsa group g random r if g getq bit length dsa group q bit length throw new illegal argument exception q is too short g getq bit length dsa group q bit length big integer k do k new native big integer dsa group q bit length r while g getq compare to k 1 k compare to big integer zero 1 return k biginteger dsagroup bitlength dsagroup q_bit_length illegalargumentexception bitlength dsagroup q_bit_length biginteger nativebiginteger dsagroup q_bit_length compareto compareto biginteger verifies the message authenticity given a group the public key y a signature and the hash of the message m param force mod if enabled skip the clipping m to 255 bits public static boolean verify dsa public key kp dsa signature sig big integer m boolean force mod if m signum 1 throw new illegal argument exception if kp get group getq bit length 256 force mod m m and signature mask try 0 r q has to be true if sig getr compare to big integer zero 1 kp getq compare to sig getr 1 if logger should log logger minor dsa class logger minor dsa class r 0 r q r sig getr q kp getq return false 0 s q has to be true as well if sig gets compare to big integer zero 1 kp getq compare to sig gets 1 if logger should log logger minor dsa class logger minor dsa class s 0 s q s sig gets q kp getq return false big integer w sig gets mod inverse kp getq big integer u1 m multiply w mod kp getq big integer u2 sig getr multiply w mod kp getq big integer v1 kp getg mod pow u1 kp getp big integer v2 kp gety mod pow u2 kp getp big integer v v1 multiply v2 mod kp getp mod kp getq return v equals sig getr fixme is there a better way to handle this exception raised on the w line above catch arithmetic exception e catch error raised by invalid data if logger should log logger minor dsa class logger minor dsa class verify failed e e return false and report that that data is bad forcemod dsapublickey dsasignature biginteger forcemod illegalargumentexception getgroup bitlength forcemod signature_mask compareto biginteger compareto shouldlog compareto biginteger compareto shouldlog biginteger modinverse biginteger biginteger biginteger modpow biginteger modpow biginteger arithmeticexception shouldlog public static void main string args throws exception dsa group g dsa group read from field args 0 dsa group g global ds agroup biga yarrow y new yarrow dummy random source y new dummy random source dsa private key pk new dsa private key g y dsa public key pub new dsa public key g pk dsa signature sig sign g pk big integer zero y system err println verify pub sig big integer zero false while true long total time signing 0 long total time verifying 0 long totalr size 0 long totals size 0 long total pub key size 0 long total priv key size 0 int max priv key size 0 int max pub key size 0 int maxr size 0 int maxs size 0 int totalr unsigned bit size 0 int maxr unsigned bit size 0 random r new random y next long byte msg new byte 32 for int i 0 i 1000 i r next bytes msg big integer m new big integer 1 msg pk new dsa private key g r int priv key size pk as bytes length total priv key size priv key size if priv key size max priv key size max priv key size priv key size pub new dsa public key g pk int pub key size pub as bytes length total pub key size pub key size if pub key size max pub key size max pub key size pub key size long t1 system current time millis sig sign g pk m y long t2 system current time millis if verify pub sig m false system err println failed to verify long t3 system current time millis total time signing t2 t1 total time verifying t3 t2 int r size sig getr bit length r size r size 8 r size 8 0 0 1 totalr size r size if r size maxr size maxr size r size int r unsigned bit size sig getr bit length totalr unsigned bit size r unsigned bit size maxr unsigned bit size math max maxr unsigned bit size r unsigned bit size int s size sig gets bit length s size s size 8 s size 8 0 0 1 totals size s size if s size maxs size maxs size s size system out println total time signing total time signing system out println total time verifying total time verifying system out println total r size totalr size max maxr size system out println total s size totals size max maxs size system out println total r unsigned bitsize totalr unsigned bit size system out println total pub key size total pub key size max max pub key size system out println total priv key size total priv key size max max priv key size dsagroup dsagroup readfromfield dsagroup dsagroupbiga dummyrandomsource dummyrandomsource dsaprivatekey dsaprivatekey dsapublickey dsapublickey dsasignature biginteger biginteger totaltimesigning totaltimeverifying totalrsize totalssize totalpubkeysize totalprivkeysize maxprivkeysize maxpubkeysize maxrsize maxssize totalrunsignedbitsize maxrunsignedbitsize nextlong nextbytes biginteger biginteger dsaprivatekey privkeysize asbytes totalprivkeysize privkeysize privkeysize maxprivkeysize maxprivkeysize privkeysize dsapublickey pubkeysize asbytes totalpubkeysize pubkeysize pubkeysize maxpubkeysize maxpubkeysize pubkeysize currenttimemillis currenttimemillis currenttimemillis totaltimesigning totaltimeverifying rsize bitlength rsize rsize rsize totalrsize rsize rsize maxrsize maxrsize rsize runsignedbitsize bitlength totalrunsignedbitsize runsignedbitsize maxrunsignedbitsize maxrunsignedbitsize runsignedbitsize ssize bitlength ssize ssize ssize totalssize ssize ssize maxssize maxssize ssize totaltimesigning totaltimeverifying totalrsize maxrsize totalssize maxssize totalrunsignedbitsize totalpubkeysize maxpubkeysize totalprivkeysize maxprivkeysize private dns state string name this name name sequence add this dnsstate public final string to string return name tostring returns the next advanced state in general this advances one step in the following sequence probing 1 probing 2 probing 3 announcing 1 announcing 2 announced does not advance for announced and canceled state public final dns state advance return is probing is announcing dns state sequence get ordinal 1 this probing_1 probing_2 probing_3 announcing_1 announcing_2 dnsstate isprobing isannouncing dnsstate returns to the next reverted state all states except canceled revert to probing 1 status canceled does not revert public final dns state revert return this canceled this probing 1 probing_1 dnsstate probing_1 returns true if this is a probing state public boolean is probing return compare to probing 1 0 compare to probing 3 0 isprobing compareto probing_1 compareto probing_3 returns true if this is an announcing state public boolean is announcing return compare to announcing 1 0 compare to announcing 2 0 isannouncing compareto announcing_1 compareto announcing_2 returns true if this is an announced state public boolean is announced return compare to announced 0 isannounced compareto compares two states the states compare as follows probing 1 lt probing 2 lt probing 3 lt announcing 1 lt announcing 2 lt responding lt announced lt canceled public int compare to object o return ordinal dns state o ordinal probing_1 probing_2 probing_3 announcing_1 announcing_2 compareto dnsstate public class projection from extends i persistent to extends i persistent extends hash set to constructor of projection specified by class and field name of projected objects param type base class for selected objects param field name field name used to perform projection public projection class type string field name set projection field type field name ipersistent ipersistent hashset fieldname fieldname setprojectionfield fieldname default constructor of projection this constructor should be used only when you are going to derive your class from projection and redefine map method in it or specify type and field name later using set projection field method fieldname setprojectionfield specify class of the projected objects and projection field name param type base class for selected objects param field name field name used to perform projection public void set projection field class type string field name try field type get declared field field name field set accessible true catch exception x throw new storage error storage error key not found x fieldname setprojectionfield fieldname getdeclaredfield fieldname setaccessible storageerror storageerror key_not_found project specified selection param selection array with selected object public void project from selection for int i 0 i selection length i map selection i project specified object param obj selected object public void project from obj map obj project specified selection param selection iterator specifying selected objects public void project iterator from selection while selection has next map selection next hasnext project specified selection param c selection iterator specifying selected objects public void project collection from c for from o c map o join this projection with another projection result of this join is set of objects present in both projections public void join projection from to prj retain all prj retainall get result of preceding project and join operations return array of objects public i persistent to persistent array return i persistent to array new i persistent size ipersistent topersistentarray ipersistent toarray ipersistent reset projection clear result of preceding project and join operations public void reset clear add object to the set param obj objet to be added public boolean add to obj if obj null return super add obj return false get related objects for the object obj it is possible to redifine this method in derived classes to provide application specific mapping param obj object from the selection protected void map from obj if field null add to obj else try object o field get obj if o instanceof link object arr link o to array for int i 0 i arr length i add to arr i else if o instanceof object object arr object o for int i 0 i arr length i add to arr i else add to o catch exception x throw new storage error storage error access violation x toarray storageerror storageerror access_violation static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog node client core node node config config sub config node config file node dir int port number int sort order simple field set old config sub config fproxy config simple toadlet server toadlets object container container throws node init exception this node node this node stats node node stats this random node random fec queue fec queue create node nodedb handle container this background block encoder new background block encoder client database executor new prioritized serial executor native thread norm priority native thread max priority 1 native thread norm priority true store checker new datastore checker node byte pwd buf new byte 16 random next bytes pwd buf compressor new real compressor node executor this form password base64 encode pwd buf alerts new user alert manager this restart jobs queue node restart jobs queue init node nodedb handle container startup database jobs restart jobs queue get early restart database jobs container if startup database jobs null startup database jobs length 0 queue startup job runner native thread high priority false restart jobs queue add late restart database jobs this container persister new configurable persister this node config client throttle file client throttle dat sort order true false node client core file for client stats node client core file for client stats long node ps node dir simple field set throttlefs persister read if logminor logger minor this read throttlefs n throttlefs if logminor logger minor this serializing request starter group from n throttlefs temp files node config register temp dir new file node dir temp port number to string sort order true true node client core temp dir node client core temp dir long new string callback override public string get return temp dir get path override public void set string val throws invalid config value exception if temp dir equals new file val return fixme throw new invalid config value exception l10n moving temp dir on the fly not supported override public boolean is read only return true temp dir new file node config get string temp dir if temp dir exists temp dir is directory temp dir mkdir string msg could not find or create temporary directory throw new node init exception node init exception exit bad temp dir msg try temp filename generator new filename generator random true temp dir temp catch io exception e string msg could not find or create temporary directory filename generator throw new node init exception node init exception exit bad temp dir msg usk manager new usk manager this persistent temp files node config register encrypt persistent temp buckets true sort order true false node client core encrypt persistent temp buckets node client core encrypt persistent temp buckets long new boolean callback override public boolean get return persistent temp bucket factory null true persistent temp bucket factory is encrypting override public void set boolean val throws invalid config value exception if get equals val persistent temp bucket factory null return persistent temp bucket factory set encryption val node config register persistent temp dir new file node dir persistent temp port number to string sort order true false node client core persistent temp dir node client core persistent temp dir long new string callback override public string get return persistent temp bucket factory get dir to string override public void set string val throws invalid config value exception if get equals val return fixme throw new invalid config value exception moving persistent temp directory on the fly not supported at present override public boolean is read only return true try file dir new file node config get string persistent temp dir string prefix freenet temp persistent temp bucket factory persistent temp bucket factory load dir prefix random node fast weak random container node nodedb handle node config get boolean encrypt persistent temp buckets this node get ticker persistent temp bucket factory init dir prefix random node fast weak random persistent filename generator persistent temp bucket factory fg catch io exception e2 string msg could not find or create persistent temporary directory e2 e2 print stack trace throw new node init exception node init exception exit bad temp dir msg node config register maxram bucket size 128 kib sort order true false node client core maxram bucket size node client core maxram bucket size long new long callback override public long get return temp bucket factory null 0 temp bucket factory get maxram bucket size override public void set long val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set maxram bucket size val true node config register ram bucket pool size 10 mib sort order true false node client core ram bucket pool size node client core ram bucket pool size long new long callback override public long get return temp bucket factory null 0 temp bucket factory get max ram used override public void set long val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set max ram used val true node config register encrypt temp buckets true sort order true false node client core encrypt temp buckets node client core encrypt temp buckets long new boolean callback override public boolean get return temp bucket factory null true temp bucket factory is encrypting override public void set boolean val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set encryption val temp bucket factory new temp bucket factory node executor temp filename generator node config get long maxram bucket size node config get long ram bucket pool size random node fast weak random node config get boolean encrypt temp buckets archive manager new archive manager max archive handlers max cached archive data max archived file size max cached elements temp bucket factory healing queue new simple healing queue new insert context temp bucket factory temp bucket factory persistent temp bucket factory 0 2 1 0 0 new simple event producer node dont cache local requests request starter prefetch priority class 512 fixme make configurable client context new client context this fec queue node executor background block encoder archive manager persistent temp bucket factory temp bucket factory healing queue usk manager random node fast weak random node get ticker temp filename generator persistent filename generator compressor compressor set client context client context store checker set context client context request starters new request starter group node this port number random config throttlefs client context client context init request starters client request scheduler load key listeners container client context insert compressor load container client context node security levels add physical threat level listener new security level listener physical threat level public void on change physical threat level old level physical threat level new level if new level physical threat level low if temp bucket factory is encrypting temp bucket factory set encryption false if persistent temp bucket factory is encrypting persistent temp bucket factory set encryption false else new level physical threat level normal if temp bucket factory is encrypting temp bucket factory set encryption true if persistent temp bucket factory is encrypting persistent temp bucket factory set encryption true downloads directory node config register downloads dir downloads sort order true true node client core download dir node client core download dir long new string callback override public string get return download dir get path override public void set string val throws invalid config value exception if download dir equals new file val return file f new file val if f exists f is directory f mkdir relatively commonly used despite being advanced i e not something we want to show to newbies so translate it throw new invalid config value exception l10n could not find or create dir download dir new file val string val node config get string downloads dir download dir new file val if download dir exists download dir is directory download dir mkdir throw new node init exception node init exception exit bad downloads dir could not find or create default downloads directory downloads allowed uploads allowed node config register download allowed dirs new string all sort order true true node client core download allowed dirs node client core download allowed dirs long new string arr callback override public string get synchronized node client core this if download allowed everywhere return new string all string dirs nodeclientcore subconfig nodeconfig nodedir portnumber sortorder simplefieldset oldconfig subconfig fproxyconfig simpletoadletserver objectcontainer nodeinitexception nodestats nodestats fecqueue fecqueue nodedbhandle backgroundblockencoder backgroundblockencoder clientdatabaseexecutor prioritizedserialexecutor nativethread norm_priority nativethread max_priority nativethread norm_priority storechecker datastorechecker pwdbuf nextbytes pwdbuf realcompressor formpassword pwdbuf useralertmanager restartjobsqueue noderestartjobsqueue nodedbhandle startupdatabasejobs restartjobsqueue getearlyrestartdatabasejobs startupdatabasejobs startupdatabasejobs startupjobrunner nativethread high_priority restartjobsqueue addlaterestartdatabasejobs configurablepersister nodeconfig clientthrottlefile sortorder nodeclientcore fileforclientstats nodeclientcore fileforclientstatslong nodedir simplefieldset requeststartergroup nodeconfig tempdir nodedir portnumber tostring sortorder nodeclientcore tempdir nodeclientcore tempdirlong stringcallback tempdir getpath invalidconfigvalueexception tempdir invalidconfigvalueexception movingtempdirontheflynotsupported isreadonly tempdir nodeconfig getstring tempdir tempdir tempdir isdirectory tempdir nodeinitexception nodeinitexception exit_bad_temp_dir tempfilenamegenerator filenamegenerator tempdir ioexception nodeinitexception nodeinitexception exit_bad_temp_dir uskmanager uskmanager nodeconfig encryptpersistenttempbuckets sortorder nodeclientcore encryptpersistenttempbuckets nodeclientcore encryptpersistenttempbucketslong booleancallback persistenttempbucketfactory persistenttempbucketfactory isencrypting invalidconfigvalueexception persistenttempbucketfactory persistenttempbucketfactory setencryption nodeconfig persistenttempdir nodedir portnumber tostring sortorder nodeclientcore persistenttempdir nodeclientcore persistenttempdirlong stringcallback persistenttempbucketfactory getdir tostring invalidconfigvalueexception invalidconfigvalueexception isreadonly nodeconfig getstring persistenttempdir persistenttempbucketfactory persistenttempbucketfactory fastweakrandom nodedbhandle nodeconfig getboolean encryptpersistenttempbuckets getticker persistenttempbucketfactory fastweakrandom persistentfilenamegenerator persistenttempbucketfactory ioexception printstacktrace nodeinitexception nodeinitexception exit_bad_temp_dir nodeconfig maxrambucketsize 128kib sortorder nodeclientcore maxrambucketsize nodeclientcore maxrambucketsizelong longcallback tempbucketfactory tempbucketfactory getmaxrambucketsize invalidconfigvalueexception tempbucketfactory tempbucketfactory setmaxrambucketsize nodeconfig rambucketpoolsize 10mib sortorder nodeclientcore rambucketpoolsize nodeclientcore rambucketpoolsizelong longcallback tempbucketfactory tempbucketfactory getmaxramused invalidconfigvalueexception tempbucketfactory tempbucketfactory setmaxramused nodeconfig encrypttempbuckets sortorder nodeclientcore encrypttempbuckets nodeclientcore encrypttempbucketslong booleancallback tempbucketfactory tempbucketfactory isencrypting invalidconfigvalueexception tempbucketfactory tempbucketfactory setencryption tempbucketfactory tempbucketfactory tempfilenamegenerator nodeconfig getlong maxrambucketsize nodeconfig getlong rambucketpoolsize fastweakrandom nodeconfig getboolean encrypttempbuckets archivemanager archivemanager max_archive_handlers max_cached_archive_data max_archived_file_size max_cached_elements tempbucketfactory healingqueue simplehealingqueue insertcontext tempbucketfactory tempbucketfactory persistenttempbucketfactory simpleeventproducer dont_cache_local_requests requeststarter prefetch_priority_class clientcontext clientcontext fecqueue backgroundblockencoder archivemanager persistenttempbucketfactory tempbucketfactory healingqueue uskmanager fastweakrandom getticker tempfilenamegenerator persistentfilenamegenerator setclientcontext clientcontext storechecker setcontext clientcontext requeststarters requeststartergroup portnumber clientcontext clientcontext requeststarters clientrequestscheduler loadkeylisteners clientcontext insertcompressor clientcontext securitylevels addphysicalthreatlevellistener securitylevellistener physical_threat_level onchange physical_threat_level oldlevel physical_threat_level newlevel newlevel physical_threat_level tempbucketfactory isencrypting tempbucketfactory setencryption persistenttempbucketfactory isencrypting persistenttempbucketfactory setencryption newlevel physical_threat_level tempbucketfactory isencrypting tempbucketfactory setencryption persistenttempbucketfactory isencrypting persistenttempbucketfactory setencryption nodeconfig downloadsdir sortorder nodeclientcore downloaddir nodeclientcore downloaddirlong stringcallback downloaddir getpath invalidconfigvalueexception downloaddir isdirectory invalidconfigvalueexception couldnotfindorcreatedir downloaddir nodeconfig getstring downloadsdir downloaddir downloaddir downloaddir isdirectory downloaddir nodeinitexception nodeinitexception exit_bad_downloads_dir nodeconfig downloadalloweddirs sortorder nodeclientcore downloadalloweddirs nodeclientcore downloadalloweddirslong stringarrcallback nodeclientcore downloadallowedeverywhere new string callback override public string get return temp dir get path stringcallback tempdir getpath override public void set string val throws invalid config value exception if temp dir equals new file val return fixme throw new invalid config value exception l10n moving temp dir on the fly not supported invalidconfigvalueexception tempdir invalidconfigvalueexception movingtempdirontheflynotsupported override public boolean is read only return true isreadonly node config register encrypt persistent temp buckets true sort order true false node client core encrypt persistent temp buckets node client core encrypt persistent temp buckets long new boolean callback override public boolean get return persistent temp bucket factory null true persistent temp bucket factory is encrypting nodeconfig encryptpersistenttempbuckets sortorder nodeclientcore encryptpersistenttempbuckets nodeclientcore encryptpersistenttempbucketslong booleancallback persistenttempbucketfactory persistenttempbucketfactory isencrypting override public void set boolean val throws invalid config value exception if get equals val persistent temp bucket factory null return persistent temp bucket factory set encryption val invalidconfigvalueexception persistenttempbucketfactory persistenttempbucketfactory setencryption new string callback override public string get return persistent temp bucket factory get dir to string stringcallback persistenttempbucketfactory getdir tostring override public void set string val throws invalid config value exception if get equals val return fixme throw new invalid config value exception moving persistent temp directory on the fly not supported at present invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly node config register maxram bucket size 128 kib sort order true false node client core maxram bucket size node client core maxram bucket size long new long callback override public long get return temp bucket factory null 0 temp bucket factory get maxram bucket size nodeconfig maxrambucketsize 128kib sortorder nodeclientcore maxrambucketsize nodeclientcore maxrambucketsizelong longcallback tempbucketfactory tempbucketfactory getmaxrambucketsize override public void set long val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set maxram bucket size val invalidconfigvalueexception tempbucketfactory tempbucketfactory setmaxrambucketsize node config register ram bucket pool size 10 mib sort order true false node client core ram bucket pool size node client core ram bucket pool size long new long callback override public long get return temp bucket factory null 0 temp bucket factory get max ram used nodeconfig rambucketpoolsize 10mib sortorder nodeclientcore rambucketpoolsize nodeclientcore rambucketpoolsizelong longcallback tempbucketfactory tempbucketfactory getmaxramused override public void set long val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set max ram used val invalidconfigvalueexception tempbucketfactory tempbucketfactory setmaxramused node config register encrypt temp buckets true sort order true false node client core encrypt temp buckets node client core encrypt temp buckets long new boolean callback override public boolean get return temp bucket factory null true temp bucket factory is encrypting nodeconfig encrypttempbuckets sortorder nodeclientcore encrypttempbuckets nodeclientcore encrypttempbucketslong booleancallback tempbucketfactory tempbucketfactory isencrypting override public void set boolean val throws invalid config value exception if get equals val temp bucket factory null return temp bucket factory set encryption val invalidconfigvalueexception tempbucketfactory tempbucketfactory setencryption public void on change physical threat level old level physical threat level new level if new level physical threat level low if temp bucket factory is encrypting temp bucket factory set encryption false if persistent temp bucket factory is encrypting persistent temp bucket factory set encryption false else new level physical threat level normal if temp bucket factory is encrypting temp bucket factory set encryption true if persistent temp bucket factory is encrypting persistent temp bucket factory set encryption true onchange physical_threat_level oldlevel physical_threat_level newlevel newlevel physical_threat_level tempbucketfactory isencrypting tempbucketfactory setencryption persistenttempbucketfactory isencrypting persistenttempbucketfactory setencryption newlevel physical_threat_level tempbucketfactory isencrypting tempbucketfactory setencryption persistenttempbucketfactory isencrypting persistenttempbucketfactory setencryption node config register downloads dir downloads sort order true true node client core download dir node client core download dir long new string callback override public string get return download dir get path nodeconfig downloadsdir sortorder nodeclientcore downloaddir nodeclientcore downloaddirlong stringcallback downloaddir getpath override public void set string val throws invalid config value exception if download dir equals new file val return file f new file val if f exists f is directory f mkdir relatively commonly used despite being advanced i e not something we want to show to newbies so translate it throw new invalid config value exception l10n could not find or create dir download dir new file val invalidconfigvalueexception downloaddir isdirectory invalidconfigvalueexception couldnotfindorcreatedir downloaddir override public string get synchronized node client core this if download allowed everywhere return new string all string dirs new string download allowed dirs length include download dir 1 0 for int i 0 i download allowed dirs length i dirs i download allowed dirs i get path if include download dir dirs download allowed dirs length downloads return dirs nodeclientcore downloadallowedeverywhere downloadalloweddirs includedownloaddir downloadalloweddirs downloadalloweddirs getpath includedownloaddir downloadalloweddirs override public void set string val throws invalid config value exception set download allowed dirs val invalidconfigvalueexception setdownloadalloweddirs override public string get synchronized node client core this if upload allowed everywhere return new string all string dirs new string upload allowed dirs length for int i 0 i upload allowed dirs length i dirs i upload allowed dirs i get path return dirs nodeclientcore uploadallowedeverywhere uploadalloweddirs uploadalloweddirs uploadalloweddirs getpath override public void set string val throws invalid config value exception set upload allowed dirs val invalidconfigvalueexception setuploadalloweddirs node client core maxusk fetchers long new int callback override public integer get return max backgroundusk fetchers nodeclientcore maxuskfetcherslong intcallback maxbackgrounduskfetchers override public void set integer usk fetch throws invalid config value exception if usk fetch 0 throw new invalid config value exception l10n maxusk fetchers must be greater than zero max backgroundusk fetchers usk fetch uskfetch invalidconfigvalueexception uskfetch invalidconfigvalueexception maxuskfetchersmustbegreaterthanzero maxbackgrounduskfetchers uskfetch private static string l10n string key return l10n get string node client core key getstring nodeclientcore protected synchronized void set download allowed dirs string val int x 0 download allowed everywhere false include download dir false int i 0 download allowed dirs new file val length for i 0 i download allowed dirs length i string s val i if s equals downloads include download dir true else if s equals all download allowed everywhere true else download allowed dirs x new file val i if x i file new dirs new file x system arraycopy download allowed dirs 0 new dirs 0 x download allowed dirs new dirs setdownloadalloweddirs downloadallowedeverywhere includedownloaddir downloadalloweddirs downloadalloweddirs includedownloaddir downloadallowedeverywhere downloadalloweddirs newdirs downloadalloweddirs newdirs downloadalloweddirs newdirs protected synchronized void set upload allowed dirs string val int x 0 int i 0 upload allowed everywhere false upload allowed dirs new file val length for i 0 i upload allowed dirs length i string s val i if s equals all upload allowed everywhere true else upload allowed dirs x new file val i if x i file new dirs new file x system arraycopy upload allowed dirs 0 new dirs 0 x upload allowed dirs new dirs setuploadalloweddirs uploadallowedeverywhere uploadalloweddirs uploadalloweddirs uploadallowedeverywhere uploadalloweddirs newdirs uploadalloweddirs newdirs uploadalloweddirs newdirs public void start config config throws node init exception background block encoder set context client context node executor execute background block encoder background block encoder client context job runner queue new db job public void run object container container client context context archive manager init container context context nodedb handle native thread max priority false persister start store checker start node executor datastore checker if fcp server null fcp server maybe start if tmci null tmci start background block encoder run persistent queue client context node executor execute compressor compression scheduler node executor execute new prio runnable public void run logger normal this resuming persistent requests call it anyway if we are not lazy it won t have to start any requests but it does other things too fcp server finish start persistent temp bucket factory completed init node plugin manager start node config node ip detector ip detector manager start fixme most of the work is done after this point on splitfile starter threads so do we want to make a fuss fixme but a better solution is real request resuming logger normal this completed startup all persistent requests resumed or restarted alerts unregister starting up alert public int get priority return native thread low priority startup completion thread client database executor start node executor client database access thread nodeinitexception backgroundblockencoder setcontext clientcontext backgroundblockencoder clientcontext jobrunner dbjob objectcontainer clientcontext archivemanager nodedbhandle nativethread max_priority storechecker fcpserver fcpserver maybestart backgroundblockencoder runpersistentqueue clientcontext priorunnable fcpserver finishstart persistenttempbucketfactory completedinit pluginmanager ipdetector ipdetectormanager startingupalert getpriority nativethread low_priority clientdatabaseexecutor client context job runner queue new db job public void run object container container client context context archive manager init container context context nodedb handle clientcontext jobrunner dbjob objectcontainer clientcontext archivemanager nodedbhandle public void run logger normal this resuming persistent requests call it anyway if we are not lazy it won t have to start any requests but it does other things too fcp server finish start persistent temp bucket factory completed init node plugin manager start node config node ip detector ip detector manager start fixme most of the work is done after this point on splitfile starter threads so do we want to make a fuss fixme but a better solution is real request resuming logger normal this completed startup all persistent requests resumed or restarted alerts unregister starting up alert fcpserver finishstart persistenttempbucketfactory completedinit pluginmanager ipdetector ipdetectormanager startingupalert public int get priority return native thread low priority getpriority nativethread low_priority public void run object container container client context context restartdb job job startup database jobs startup database jobs done try container activate job job 1 remove before execution to allow it to re add itself if it wants to system err println cleaning up after restart job job restart jobs queue remove restart job job job job prio container job job run container context container commit catch throwable t logger error this caught t in startup job job t try again next time restart jobs queue queue restart job job job job prio container true startup database jobs done if startup database jobs done startup database jobs length startup database jobs null else context job runner queue startup job runner native thread high priority false objectcontainer clientcontext restartdbjob startupdatabasejobs startupdatabasejobsdone restartjobsqueue removerestartjob restartjobsqueue queuerestartjob startupdatabasejobsdone startupdatabasejobsdone startupdatabasejobs startupdatabasejobs jobrunner startupjobrunner nativethread high_priority public interface simple request sender completion listener public void completed boolean success simplerequestsendercompletionlistener public void async get key key boolean cache boolean offers only final simple request sender completion listener listener final long uid random next long final boolean isssk key instanceof nodessk final request tag tag new request tag isssk request tag start async get if node lockuid uid isssk false false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng return async get key isssk cache offers only uid new request sender listener public void onchk transfer begins ignore public void on received reject overload ignore public void on request sender finished int status if transfer coalescing has happened we may have already unlocked node unlockuid uid isssk false true false true tag tag set request sender finished status if listener null listener completed status request sender success public void on abort downstream transfers int reason string desc ignore on request sender finished will also be called tag asyncget offersonly simplerequestsendercompletionlistener nextlong requesttag requesttag requesttag async_get asyncget offersonly requestsender onchktransferbegins onreceivedrejectoverload onrequestsenderfinished setrequestsenderfinished requestsender onabortdownstreamtransfers onrequestsenderfinished async get key isssk cache offers only uid new request sender listener public void onchk transfer begins ignore asyncget offersonly requestsender onchktransferbegins public void on received reject overload ignore onreceivedrejectoverload public void on request sender finished int status if transfer coalescing has happened we may have already unlocked node unlockuid uid isssk false true false true tag tag set request sender finished status if listener null listener completed status request sender success onrequestsenderfinished setrequestsenderfinished requestsender public void on abort downstream transfers int reason string desc ignore on request sender finished will also be called onabortdownstreamtransfers onrequestsenderfinished start an asynchronous fetch of the key in question which will complete to the datastore it will not decode the data because we don t provide a client key it will not return anything and will run asynchronously caller is responsible for unlocking the uid param key void async get key key boolean isssk boolean cache boolean offers only long uid request sender listener listener request tag tag try object o node make request sender key node maxhtl uid null false cache false offers only if o instanceof key block tag served from datastore true node unlockuid uid isssk false true false true tag return already have it request sender rs request sender o tag set sender rs rs add listener listener if rs uid uid node unlockuid uid isssk false false false true tag else it has started a request if logminor logger minor this started o for uid for key catch runtime exception e logger error this caught error trying to start request e e node unlockuid uid isssk false true false true tag catch error e logger error this caught error trying to start request e e node unlockuid uid isssk false true false true tag clientkey asyncget offersonly requestsender requesttag makerequestsender offersonly keyblock servedfromdatastore requestsender requestsender setsender addlistener runtimeexception public client key block real get key client key key boolean local only boolean cache boolean ignore store throws low level get exception if key instanceof clientchk return real getchk clientchk key local only cache ignore store else if key instanceof clientssk return real getssk clientssk key local only cache ignore store else throw new illegal argument exception not a chk or ssk key clientkeyblock realgetkey clientkey localonly ignorestore lowlevelgetexception realgetchk localonly ignorestore realgetssk localonly ignorestore illegalargumentexception clientchk block real getchk clientchk key boolean local only boolean cache boolean ignore store throws low level get exception long start time system current time millis long uid random next long request tag tag new request tag false request tag start local if node lockuid uid false false false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng throw new low level get exception low level get exception internal error try object o node make request sender key get nodechk node maxhtl uid null local only cache ignore store false if o instanceof chk block try tag set served from datastore return new clientchk block chk block o key catch chk verify exception e logger error this does not verify e e throw new low level get exception low level get exception decode failed if o null throw new low level get exception low level get exception data not found in store request sender rs request sender o boolean rejected overload false short wait status 0 while true wait status rs wait until status change wait status if rejected overload wait status request sender wait rejected overload 0 see below inserts count both request starters rejected overload false false rejected overload true int status rs get status if rs aborted downstream transfers status request sender transfer failed if status request sender not finished continue if status request sender timed out status request sender generated rejected overload status request sender internal error if logminor logger minor this chk fetch cost rs get total sent bytes rs get total received bytes bytes status node stats local chk fetch bytes sent average report rs get total sent bytes node stats local chk fetch bytes received average report rs get total received bytes if status request sender success see comments above declaration of successful we don t report sent bytes here node stats successful chk fetch bytes sent average report rs get total sent bytes node stats successful chk fetch bytes received average report rs get total received bytes if status request sender timed out status request sender generated rejected overload if rejected overload see below request starters rejected overload false false rejected overload true long rtt system current time millis start time node node stats reportchk time rtt false else if rs has forwarded status request sender data not found status request sender recently failed status request sender success status request sender route not found status request sender verify failure status request sender get offer verify failure long rtt system current time millis start time if rejected overload request starters request completed false false key get node key count towards rtt even if got a rejected overload but not if timed out request starters chk request throttle successful completion rtt node node stats reportchk time rtt status request sender success if status request sender success logger minor this successful chk fetch took rtt if status request sender success try return new clientchk block rs getprb get block rs get headers key true catch chk verify exception e logger error this does not verify e e throw new low level get exception low level get exception decode failed catch aborted exception e logger error this impossible e e throw new low level get exception low level get exception internal error else switch status case request sender not finished logger error this rs still running in getchk rs throw new low level get exception low level get exception internal error case request sender data not found throw new low level get exception low level get exception data not found case request sender recently failed throw new low level get exception low level get exception recently failed case request sender route not found throw new low level get exception low level get exception route not found case request sender transfer failed case request sender get offer transfer failed throw new low level get exception low level get exception transfer failed case request sender verify failure case request sender get offer verify failure throw new low level get exception low level get exception verify failed case request sender generated rejected overload case request sender timed out throw new low level get exception low level get exception rejected overload case request sender internal error throw new low level get exception low level get exception internal error default logger error this unknown request sender code in getchk status on rs throw new low level get exception low level get exception internal error finally node unlockuid uid false false true false true tag clientchkblock realgetchk localonly ignorestore lowlevelgetexception starttime currenttimemillis nextlong requesttag requesttag requesttag lowlevelgetexception lowlevelgetexception internal_error makerequestsender getnodechk localonly ignorestore chkblock setservedfromdatastore clientchkblock chkblock chkverifyexception lowlevelgetexception lowlevelgetexception decode_failed lowlevelgetexception lowlevelgetexception data_not_found_in_store requestsender requestsender rejectedoverload waitstatus waitstatus waituntilstatuschange waitstatus rejectedoverload waitstatus requestsender wait_rejected_overload requeststarters rejectedoverload rejectedoverload getstatus aborteddownstreamtransfers requestsender transfer_failed requestsender not_finished requestsender timed_out requestsender generated_rejected_overload requestsender internal_error gettotalsentbytes gettotalreceivedbytes nodestats localchkfetchbytessentaverage gettotalsentbytes nodestats localchkfetchbytesreceivedaverage gettotalreceivedbytes requestsender nodestats successfulchkfetchbytessentaverage gettotalsentbytes nodestats successfulchkfetchbytesreceivedaverage gettotalreceivedbytes requestsender timed_out requestsender generated_rejected_overload rejectedoverload requeststarters rejectedoverload rejectedoverload currenttimemillis starttime nodestats reportchktime hasforwarded requestsender data_not_found requestsender recently_failed requestsender requestsender route_not_found requestsender verify_failure requestsender get_offer_verify_failure currenttimemillis starttime rejectedoverload requeststarters requestcompleted getnodekey rejectedoverload requeststarters chkrequestthrottle successfulcompletion nodestats reportchktime requestsender requestsender requestsender clientchkblock getblock getheaders chkverifyexception lowlevelgetexception lowlevelgetexception decode_failed abortedexception lowlevelgetexception lowlevelgetexception internal_error requestsender not_finished lowlevelgetexception lowlevelgetexception internal_error requestsender data_not_found lowlevelgetexception lowlevelgetexception data_not_found requestsender recently_failed lowlevelgetexception lowlevelgetexception recently_failed requestsender route_not_found lowlevelgetexception lowlevelgetexception route_not_found requestsender transfer_failed requestsender get_offer_transfer_failed lowlevelgetexception lowlevelgetexception transfer_failed requestsender verify_failure requestsender get_offer_verify_failure lowlevelgetexception lowlevelgetexception verify_failed requestsender generated_rejected_overload requestsender timed_out lowlevelgetexception lowlevelgetexception rejected_overload requestsender internal_error lowlevelgetexception lowlevelgetexception internal_error requestsender lowlevelgetexception lowlevelgetexception internal_error clientssk block real getssk clientssk key boolean local only boolean cache boolean ignore store throws low level get exception long start time system current time millis long uid random next long request tag tag new request tag true request tag start local if node lockuid uid true false false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng throw new low level get exception low level get exception internal error try object o node make request sender key get node key node maxhtl uid null local only cache ignore store false if o instanceof ssk block try tag set served from datastore ssk block block ssk block o key set public key block get pub key return clientssk block construct block key catch ssk verify exception e logger error this does not verify e e throw new low level get exception low level get exception decode failed if o null throw new low level get exception low level get exception data not found in store request sender rs request sender o boolean rejected overload false short wait status 0 while true wait status rs wait until status change wait status if rejected overload wait status request sender wait rejected overload 0 request starters rejected overload true false rejected overload true int status rs get status if status request sender not finished continue if status request sender timed out status request sender generated rejected overload status request sender internal error if logminor logger minor this ssk fetch cost rs get total sent bytes rs get total received bytes bytes status node stats local ssk fetch bytes sent average report rs get total sent bytes node stats local ssk fetch bytes received average report rs get total received bytes if status request sender success see comments above successful ssk fetch bytes sent average we don t relay the data so reporting the sent bytes would be inaccurate node stats successful ssk fetch bytes sent average report rs get total sent bytes node stats successful ssk fetch bytes received average report rs get total received bytes if status request sender timed out status request sender generated rejected overload if rejected overload request starters rejected overload true false rejected overload true else if rs has forwarded status request sender data not found status request sender recently failed status request sender success status request sender route not found status request sender verify failure status request sender get offer verify failure long rtt system current time millis start time if rejected overload request starters request completed true false key get node key count towards rtt even if got a rejected overload but not if timed out request starters ssk request throttle successful completion rtt if rs get status request sender success try ssk block block rs getssk block key set public key block get pub key return clientssk block construct block key catch ssk verify exception e logger error this does not verify e e throw new low level get exception low level get exception decode failed else switch rs get status case request sender not finished logger error this rs still running in getchk rs throw new low level get exception low level get exception internal error case request sender data not found throw new low level get exception low level get exception data not found case request sender recently failed throw new low level get exception low level get exception recently failed case request sender route not found throw new low level get exception low level get exception route not found case request sender transfer failed case request sender get offer transfer failed logger error this wtf transfer failed on an ssk on uid throw new low level get exception low level get exception transfer failed case request sender verify failure case request sender get offer verify failure throw new low level get exception low level get exception verify failed case request sender generated rejected overload case request sender timed out throw new low level get exception low level get exception rejected overload case request sender internal error default logger error this unknown request sender code in getchk rs get status on rs throw new low level get exception low level get exception internal error finally node unlockuid uid true false true false true tag clientsskblock realgetssk localonly ignorestore lowlevelgetexception starttime currenttimemillis nextlong requesttag requesttag requesttag lowlevelgetexception lowlevelgetexception internal_error makerequestsender getnodekey localonly ignorestore sskblock setservedfromdatastore sskblock sskblock setpublickey getpubkey clientsskblock sskverifyexception lowlevelgetexception lowlevelgetexception decode_failed lowlevelgetexception lowlevelgetexception data_not_found_in_store requestsender requestsender rejectedoverload waitstatus waitstatus waituntilstatuschange waitstatus rejectedoverload waitstatus requestsender wait_rejected_overload requeststarters rejectedoverload rejectedoverload getstatus requestsender not_finished requestsender timed_out requestsender generated_rejected_overload requestsender internal_error gettotalsentbytes gettotalreceivedbytes nodestats localsskfetchbytessentaverage gettotalsentbytes nodestats localsskfetchbytesreceivedaverage gettotalreceivedbytes requestsender successfulsskfetchbytessentaverage nodestats successfulsskfetchbytessentaverage gettotalsentbytes nodestats successfulsskfetchbytesreceivedaverage gettotalreceivedbytes requestsender timed_out requestsender generated_rejected_overload rejectedoverload requeststarters rejectedoverload rejectedoverload hasforwarded requestsender data_not_found requestsender recently_failed requestsender requestsender route_not_found requestsender verify_failure requestsender get_offer_verify_failure currenttimemillis starttime rejectedoverload requeststarters requestcompleted getnodekey rejectedoverload requeststarters sskrequestthrottle successfulcompletion getstatus requestsender sskblock getsskblock setpublickey getpubkey clientsskblock sskverifyexception lowlevelgetexception lowlevelgetexception decode_failed getstatus requestsender not_finished lowlevelgetexception lowlevelgetexception internal_error requestsender data_not_found lowlevelgetexception lowlevelgetexception data_not_found requestsender recently_failed lowlevelgetexception lowlevelgetexception recently_failed requestsender route_not_found lowlevelgetexception lowlevelgetexception route_not_found requestsender transfer_failed requestsender get_offer_transfer_failed lowlevelgetexception lowlevelgetexception transfer_failed requestsender verify_failure requestsender get_offer_verify_failure lowlevelgetexception lowlevelgetexception verify_failed requestsender generated_rejected_overload requestsender timed_out lowlevelgetexception lowlevelgetexception rejected_overload requestsender internal_error requestsender getstatus lowlevelgetexception lowlevelgetexception internal_error public void real put key block block boolean cache throws low level put exception if block instanceof chk block real putchk chk block block cache else if block instanceof ssk block real putssk ssk block block cache else throw new illegal argument exception unknown put type block get class realput keyblock lowlevelputexception chkblock realputchk chkblock sskblock realputssk sskblock illegalargumentexception getclass public void real putchk chk block block boolean cache throws low level put exception byte data block get data byte headers block get headers partially received block prb new partially received block node packets in block node packet size data chk insert sender is long uid random next long insert tag tag new insert tag false insert tag start local if node lockuid uid false true false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng throw new low level put exception low level put exception internal error try long start time system current time millis if cache node store block is node make insert sender nodechk block get key node maxhtl uid null headers prb false cache boolean has received rejected overload false wait for status while true synchronized is if is get status chk insert sender not finished try is wait 5 1000 catch interrupted exception e ignore if is get status chk insert sender not finished break if has received rejected overload is received rejected overload has received rejected overload true request starters rejected overload false true wait for completion while true synchronized is if is completed break try is wait 10 1000 catch interrupted exception e go around again if is any transfers failed has received rejected overload has received rejected overload true not strictly true but same effect request starters rejected overload false true if logminor logger minor this completed uid overload has received rejected overload is get status string finished if has received rejected overload is it ours did we send a request if is sent request is uid uid is get status chk insert sender route not found is get status chk insert sender success it worked long end time system current time millis long len end time start time rejected overload requests count towards rtt timed out ones don t request starters chk insert throttle successful completion len request starters request completed false true block get key get status explicitly after completed so that it will be receive failed if the receive failed int status is get status if status chk insert sender timed out status chk insert sender generated rejected overload status chk insert sender internal error status chk insert sender route really not found int sent is get total sent bytes int received is get total received bytes if logminor logger minor this local chk insert cost sent received bytes status node stats local chk insert bytes sent average report sent node stats local chk insert bytes received average report received if status chk insert sender success only report sent bytes because we did not receive the data node stats successful chk insert bytes sent average report sent if status chk insert sender success logger normal this succeeded inserting block return else string msg failed inserting block is get status string if status chk insert sender route not found msg this is normal on small networks the data will still be propagated but it can t find the 20 nodes needed for full success if is get status chk insert sender route not found logger error this msg else logger normal this msg switch is get status case chk insert sender not finished logger error this is still running in putchk is throw new low level put exception low level put exception internal error case chk insert sender generated rejected overload case chk insert sender timed out throw new low level put exception low level put exception rejected overload case chk insert sender route not found throw new low level put exception low level put exception route not found case chk insert sender route really not found throw new low level put exception low level put exception route really not found case chk insert sender internal error throw new low level put exception low level put exception internal error default logger error this unknown chk insert sender code in putchk is get status on is throw new low level put exception low level put exception internal error finally node unlockuid uid false true true false true tag realputchk chkblock lowlevelputexception getdata getheaders partiallyreceivedblock partiallyreceivedblock packets_in_block packet_size chkinsertsender nextlong inserttag inserttag inserttag lowlevelputexception lowlevelputexception internal_error starttime currenttimemillis makeinsertsender getkey hasreceivedrejectedoverload getstatus chkinsertsender not_finished interruptedexception getstatus chkinsertsender not_finished hasreceivedrejectedoverload receivedrejectedoverload hasreceivedrejectedoverload requeststarters rejectedoverload interruptedexception anytransfersfailed hasreceivedrejectedoverload hasreceivedrejectedoverload requeststarters rejectedoverload hasreceivedrejectedoverload getstatusstring hasreceivedrejectedoverload sentrequest getstatus chkinsertsender route_not_found getstatus chkinsertsender endtime currenttimemillis endtime starttime rejectedoverload requeststarters chkinsertthrottle successfulcompletion requeststarters requestcompleted getkey receive_failed getstatus chkinsertsender timed_out chkinsertsender generated_rejected_overload chkinsertsender internal_error chkinsertsender route_really_not_found gettotalsentbytes gettotalreceivedbytes nodestats localchkinsertbytessentaverage nodestats localchkinsertbytesreceivedaverage chkinsertsender nodestats successfulchkinsertbytessentaverage chkinsertsender getstatusstring chkinsertsender route_not_found getstatus chkinsertsender route_not_found getstatus chkinsertsender not_finished lowlevelputexception lowlevelputexception internal_error chkinsertsender generated_rejected_overload chkinsertsender timed_out lowlevelputexception lowlevelputexception rejected_overload chkinsertsender route_not_found lowlevelputexception lowlevelputexception route_not_found chkinsertsender route_really_not_found lowlevelputexception lowlevelputexception route_really_not_found chkinsertsender internal_error lowlevelputexception lowlevelputexception internal_error chkinsertsender getstatus lowlevelputexception lowlevelputexception internal_error public void real putssk ssk block block boolean cache throws low level put exception ssk insert sender is long uid random next long insert tag tag new insert tag true insert tag start local if node lockuid uid true true false true tag logger error this could not lock uid just randomly generated uid probably indicates broken prng throw new low level put exception low level put exception internal error try long start time system current time millis ssk block alt block ssk block node fetch block get key false if alt block null alt block equals block throw new low level put exception low level put exception collision is node make insert sender block node maxhtl uid null false cache boolean has received rejected overload false wait for status while true synchronized is if is get status ssk insert sender not finished try is wait 5 1000 catch interrupted exception e ignore if is get status ssk insert sender not finished break if has received rejected overload is received rejected overload has received rejected overload true request starters rejected overload true true wait for completion while true synchronized is if is get status ssk insert sender not finished break try is wait 10 1000 catch interrupted exception e go around again if logminor logger minor this completed uid overload has received rejected overload is get status string finished if has received rejected overload is it ours did we send a request if is sent request is uid uid is get status ssk insert sender route not found is get status ssk insert sender success it worked long end time system current time millis long rtt end time start time request starters request completed true true block get key request starters ssk insert throttle successful completion rtt int status is get status if status chk insert sender timed out status chk insert sender generated rejected overload status chk insert sender internal error status chk insert sender route really not found int sent is get total sent bytes int received is get total received bytes if logminor logger minor this local ssk insert cost sent received bytes status node stats local ssk insert bytes sent average report sent node stats local ssk insert bytes received average report received if status ssk insert sender success only report sent bytes as we haven t received anything node stats successful ssk insert bytes sent average report sent if is has collided store it locally so it can be fetched immediately and overwrites any locally inserted try node store insert is get block catch key collision exception e impossible throw new low level put exception low level put exception collision else if cache try node store insert block catch key collision exception e throw new low level put exception low level put exception collision if status ssk insert sender success logger normal this succeeded inserting block return else string msg failed inserting block is get status string if status chk insert sender route not found msg this is normal on small networks the data will still be propagated but it can t find the 20 nodes needed for full success if is get status ssk insert sender route not found logger error this msg else logger normal this msg switch is get status case ssk insert sender not finished logger error this is still running in putchk is throw new low level put exception low level put exception internal error case ssk insert sender generated rejected overload case ssk insert sender timed out throw new low level put exception low level put exception rejected overload case ssk insert sender route not found throw new low level put exception low level put exception route not found case ssk insert sender route really not found throw new low level put exception low level put exception route really not found case ssk insert sender internal error throw new low level put exception low level put exception internal error default logger error this unknown chk insert sender code in putssk is get status on is throw new low level put exception low level put exception internal error finally node unlockuid uid true true true false true tag realputssk sskblock lowlevelputexception sskinsertsender nextlong inserttag inserttag inserttag lowlevelputexception lowlevelputexception internal_error starttime currenttimemillis sskblock altblock sskblock getkey altblock altblock lowlevelputexception lowlevelputexception makeinsertsender hasreceivedrejectedoverload getstatus sskinsertsender not_finished interruptedexception getstatus sskinsertsender not_finished hasreceivedrejectedoverload receivedrejectedoverload hasreceivedrejectedoverload requeststarters rejectedoverload getstatus sskinsertsender not_finished interruptedexception hasreceivedrejectedoverload getstatusstring hasreceivedrejectedoverload sentrequest getstatus sskinsertsender route_not_found getstatus sskinsertsender endtime currenttimemillis endtime starttime requeststarters requestcompleted getkey requeststarters sskinsertthrottle successfulcompletion getstatus chkinsertsender timed_out chkinsertsender generated_rejected_overload chkinsertsender internal_error chkinsertsender route_really_not_found gettotalsentbytes gettotalreceivedbytes nodestats localsskinsertbytessentaverage nodestats localsskinsertbytesreceivedaverage sskinsertsender nodestats successfulsskinsertbytessentaverage hascollided storeinsert getblock keycollisionexception lowlevelputexception lowlevelputexception storeinsert keycollisionexception lowlevelputexception lowlevelputexception sskinsertsender getstatusstring chkinsertsender route_not_found getstatus sskinsertsender route_not_found getstatus sskinsertsender not_finished lowlevelputexception lowlevelputexception internal_error sskinsertsender generated_rejected_overload sskinsertsender timed_out lowlevelputexception lowlevelputexception rejected_overload sskinsertsender route_not_found lowlevelputexception lowlevelputexception route_not_found sskinsertsender route_really_not_found lowlevelputexception lowlevelputexception route_really_not_found sskinsertsender internal_error lowlevelputexception lowlevelputexception internal_error chkinsertsender getstatus lowlevelputexception lowlevelputexception internal_error public high level simple client make client short prio class return make client prio class false highlevelsimpleclient makeclient prioclass makeclient prioclass public high level simple client make client short prio class boolean force dont ignore too many path components return new high level simple client impl this temp bucket factory random node dont cache local requests prio class force dont ignore too many path components highlevelsimpleclient makeclient prioclass forcedontignoretoomanypathcomponents highlevelsimpleclientimpl tempbucketfactory dont_cache_local_requests prioclass forcedontignoretoomanypathcomponents public boolean cache inserts return node dont cache local requests cacheinserts dont_cache_local_requests public fcp server getfcp server return fcp server fcpserver getfcpserver fcpserver public f proxy toadlet getf proxy return fproxy servlet fproxytoadlet getfproxy fproxyservlet public simple toadlet server get toadlet container return toadlet container simpletoadletserver gettoadletcontainer toadletcontainer public text mode client interface server get text mode client interface return tmci textmodeclientinterfaceserver gettextmodeclientinterface public void setf proxy f proxy toadlet fproxy this fproxy servlet fproxy setfproxy fproxytoadlet fproxyservlet public text mode client interface get directtmci return directtmci textmodeclientinterface getdirecttmci public void set directtmci text mode client interface i this directtmci i setdirecttmci textmodeclientinterface public file get download dir return download dir getdownloaddir downloaddir public healing queue get healing queue return healing queue healingqueue gethealingqueue healingqueue public void queue random reinsert key block block simple sendable insert ssi new simple sendable insert this block request starter maximum priority class if logminor logger minor this queueing random reinsert for block ssi ssi schedule queuerandomreinsert keyblock simplesendableinsert simplesendableinsert requeststarter maximum_priority_class public void store config logger normal this trying to write config to disk new exception debug node config store storeconfig public boolean is testnet enabled return node is testnet enabled istestnetenabled istestnetenabled public boolean is advanced mode enabled return get toadlet container null get toadlet container is advanced mode enabled isadvancedmodeenabled gettoadletcontainer gettoadletcontainer isadvancedmodeenabled public boolean isf proxy javascript enabled return get toadlet container null get toadlet container isf proxy javascript enabled isfproxyjavascriptenabled gettoadletcontainer gettoadletcontainer isfproxyjavascriptenabled public string get my name return node get my name getmyname getmyname public filter callback create filter callback uri uri founduri callback cb if logminor logger minor this creating filter callback uri cb return new generic read filter callback uri cb filtercallback createfiltercallback founduricallback genericreadfiltercallback public int max backgroundusk fetchers return max backgroundusk fetchers maxbackgrounduskfetchers maxbackgrounduskfetchers public boolean allow download to file filename if download allowed everywhere return true if include download dir if file util is parent download dir filename return true for int i 0 i download allowed dirs length i if file util is parent download allowed dirs i filename return true return false allowdownloadto downloadallowedeverywhere includedownloaddir fileutil isparent downloaddir downloadalloweddirs fileutil isparent downloadalloweddirs public boolean allow upload from file filename if upload allowed everywhere return true for int i 0 i upload allowed dirs length i if file util is parent upload allowed dirs i filename return true return false allowuploadfrom uploadallowedeverywhere uploadalloweddirs fileutil isparent uploadalloweddirs public file get allowed upload dirs return upload allowed dirs getalloweduploaddirs uploadalloweddirs public simple field set persist throttles to field set return request starters persist to field set simplefieldset persistthrottlestofieldset requeststarters persisttofieldset public ticker get ticker return node ps getticker public executor get executor return node executor getexecutor public file get persistent temp dir return persistent temp bucket factory get dir getpersistenttempdir persistenttempbucketfactory getdir public file get temp dir return temp dir gettempdir tempdir public boolean has loaded queue return fcp server has finished start hasloadedqueue fcpserver hasfinishedstart pass the offered key down to the client layer if the client layer wants it or force is enabled queue it public void maybe queue offered key key key boolean force client request scheduler sched key instanceof nodessk request starters ssk fetch scheduler request starters chk fetch scheduler sched maybe queue offered key key force maybequeueofferedkey clientrequestscheduler requeststarters sskfetchscheduler requeststarters chkfetchscheduler maybequeueofferedkey public void dequeue offered key key key client request scheduler sched key instanceof nodessk request starters ssk fetch scheduler request starters chk fetch scheduler sched dequeue offered key key dequeueofferedkey clientrequestscheduler requeststarters sskfetchscheduler requeststarters chkfetchscheduler dequeueofferedkey public freeneturi get bookmarkur is return toadlet container get bookmarkur is getbookmarkuris toadletcontainer getbookmarkuris public long count transient queued requests return request starters count transient queued requests counttransientqueuedrequests requeststarters counttransientqueuedrequests public void queue final db job job int priority boolean check dupes if check dupes this client database executor execute no dupes new db job wrapper job priority job else this client database executor execute new db job wrapper job priority job dbjob checkdupes checkdupes clientdatabaseexecutor executenodupes dbjobwrapper clientdatabaseexecutor dbjobwrapper class db job wrapper implements runnable db job wrapper db job job this job job if job null throw new null pointer exception dbjobwrapper dbjobwrapper dbjob nullpointerexception public void run try synchronized node client core this if killed database logger error this database killed already not running job return if job null throw new null pointer exception if node null throw new null pointer exception job run node db client context boolean killed synchronized node client core this killed killed database if killed node db rollback return else persistent temp bucket factory pre commit node db node db commit if logminor logger minor this committed persistent temp bucket factory post commit node db catch throwable t if t instanceof out of memory error synchronized node client core this killed database true oom handler handleoom out of memory error t else logger error this failed to run database job job caught t t boolean killed synchronized node client core this killed killed database if killed node db rollback nodeclientcore killeddatabase nullpointerexception nullpointerexception clientcontext nodeclientcore killeddatabase persistenttempbucketfactory precommit persistenttempbucketfactory postcommit outofmemoryerror nodeclientcore killeddatabase oomhandler outofmemoryerror nodeclientcore killeddatabase override public int hash code return job null 0 job hash code hashcode hashcode override public boolean equals object o if o instanceof db job wrapper return false db job wrapper cmp db job wrapper o return cmp job job dbjobwrapper dbjobwrapper dbjobwrapper override public string to string return db job wrapper job tostring dbjobwrapper public boolean on database thread return client database executor on thread ondatabasethread clientdatabaseexecutor onthread public int get queue size int priority return client database executor get queue size priority getqueuesize clientdatabaseexecutor getqueuesize public void handle low memory throws exception ignore handlelowmemory public void handle out of memory throws exception synchronized this killed database true wrapper manager request thread dump system err println out of memory emergency shutdown to protect database integrity in progress system exit node init exception exit out of memory protecting database handleoutofmemory killeddatabase wrappermanager requestthreaddump nodeinitexception exit_out_of_memory_protecting_database queue a job to be run soon after startup the job must delete itself public void queue restart job db job job int priority object container container boolean early restart jobs queue queue restart job job priority container early queuerestartjob dbjob objectcontainer restartjobsqueue queuerestartjob public void remove restart job db job job int priority object container container restart jobs queue remove restart job job priority container removerestartjob dbjob objectcontainer restartjobsqueue removerestartjob public void run blocking final db job job int priority if client database executor on thread job run node db client context else final mutable boolean finished new mutable boolean queue new db job public void run object container container client context context try job run container context finally synchronized finished finished value true finished notify all priority false synchronized finished while finished value try finished wait catch interrupted exception e ignore runblocking dbjob clientdatabaseexecutor onthread clientcontext mutableboolean mutableboolean dbjob objectcontainer clientcontext notifyall interruptedexception public void run object container container client context context try job run container context finally synchronized finished finished value true finished notify all objectcontainer clientcontext notifyall public boolean object can new object container container logger error this not storing node client core in database new exception error return false objectcannew objectcontainer nodeclientcore public synchronized void kill database killed database true killdatabase killeddatabase public message list fetcher node my node high level simple client my client string my name identity manager my identity manager message manager my message manager super my node my client my name m identity manager my identity manager m message manager my message manager messagelistfetcher mynode highlevelsimpleclient myclient myname identitymanager myidentitymanager messagemanager mymessagemanager mynode myclient myname midentitymanager myidentitymanager mmessagemanager mymessagemanager public static synchronized null persistent file tracker get instance if instance null instance new null persistent file tracker return instance nullpersistentfiletracker getinstance nullpersistentfiletracker private null persistent file tracker nullpersistentfiletracker public void register file file do nothing public void delayed free bucket delayed free bucket bucket free immediately bucket free delayedfreebucket delayedfreebucket public file get dir return new file getdir public boolean matches file file return false public filename generator get generator return null filenamegenerator getgenerator public long getid file file return 0 public class null boolean callback extends boolean callback override public boolean get return false nullbooleancallback booleancallback override public void set boolean val throws invalid config value exception ignore invalidconfigvalueexception public subscribedusk update string identifier long l usk key boolean new known good boolean new slot too this identifier identifier this edition l this key key this new known good new known good this new slot too new slot too subscribeduskupdate newknowngood newslottoo newknowngood newknowngood newslottoo newslottoo override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put edition edition fs put single uri key geturi to string fs put new known good new known good fs put new slot too new slot too return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring newknowngood newknowngood newslottoo newslottoo override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message subscribedusk update goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message subscribeduskupdate override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private final node client core core public user alert manager node client core core this core core alerts new linked hash set user alert nodeclientcore useralertmanager nodeclientcore linkedhashset useralert public void register user alert alert synchronized alerts if alerts contains alert alerts add alert useralert public void unregister user alert alert synchronized alerts alerts remove alert useralert tries to find the user alert with the given hash code and dismisses it if found see unregister user alert param alert hash code the hash code of the user alert to dismiss public void dismiss alert int alert hash code user alert user alerts get alerts for int index 0 count user alerts length index count index user alert user alert user alerts index if user alert hash code alert hash code if user alert user can dismiss if user alert should unregister on dismiss user alert on dismiss unregister user alert else user alert is valid false useralert alerthashcode dismissalert alerthashcode useralert useralerts getalerts useralerts useralert useralert useralerts useralert hashcode alerthashcode useralert usercandismiss useralert shouldunregisterondismiss useralert ondismiss useralert useralert isvalid public user alert get alerts user alert a synchronized alerts a alerts to array new user alert alerts size arrays sort a this return a useralert getalerts useralert toarray useralert public int compare user alert a0 user alert a1 if a0 a1 return 0 common case also we should be consistent with even with proxyuseralert s short prio0 a0 get priority class short prio1 a1 get priority class if prio0 prio1 0 boolean is event0 a0 is event notification boolean is event1 a1 is event notification if is event0 is event1 return 1 if is event0 is event1 return 1 first go by class int class hash0 a0 get class hash code int class hash1 a1 get class hash code if class hash0 class hash1 return 1 else if class hash0 class hash1 return 1 then by object hash code int hash0 a0 hash code int hash1 a1 hash code if hash0 hash1 return 1 if hash1 hash0 return 1 return 0 else if prio0 prio1 return 1 else return 1 useralert useralert getpriorityclass getpriorityclass isevent0 iseventnotification isevent1 iseventnotification isevent0 isevent1 isevent0 isevent1 classhash0 getclass hashcode classhash1 getclass hashcode classhash0 classhash1 classhash0 classhash1 hashcode hashcode hashcode write the alerts as html public html node create alerts html node alerts node new html node div user alert alerts get alerts int total number 0 for int i 0 i alerts length i user alert alert alerts i if alert is valid continue total number alerts node add child a name alert anchor alerts node add child render alert alert if total number 0 return new html node return alerts node htmlnode createalerts htmlnode alertsnode htmlnode useralert getalerts totalnumber useralert isvalid totalnumber alertsnode addchild alertsnode addchild renderalert totalnumber htmlnode alertsnode write each alert in uber concise form as html with a link to alerts anchor pointing to the real alert public html node create alerts short string title boolean advanced mode boolean draw dump events form user alert current alerts get alerts short max level short max value int events 0 for int i 0 i current alerts length i if current alerts i is valid continue short level current alerts i get priority class if level max level max level level if current alerts i is event notification events if max level short max value return new html node if events 2 draw dump events form false html node box node new html node div class infobox infobox get alert level name max level infobox summary status box box node add child div class infobox header infobox summary status header title html node content node box node add child div class infobox content infobox summary status content if advanced mode content node add child p class click for more l10n click for more html node alerts node content node add child ul class alert summary int total number 0 for int i 0 i current alerts length i user alert alert current alerts i if alert is valid continue html node list item alerts node add child li class alert summary text get alert level name alert get priority class list item add child a href alerts alert anchor alert get short text total number if draw dump events form html node dump form node content node add child form new string action method new string post add child div dump form node add child input new string type name value new string hidden form password core form password string builder sb new string builder for int i 0 i current alerts length i if current alerts i is event notification continue if sb length 0 sb append sb append current alerts i anchor dump form node add child input new string type name value new string hidden events sb to string dump form node add child input new string type name value new string submit dismiss events l10n dump events button return box node htmlnode createalertsshort advancedmode drawdumpeventsform useralert currentalerts getalerts maxlevel max_value currentalerts currentalerts isvalid currentalerts getpriorityclass maxlevel maxlevel currentalerts iseventnotification maxlevel max_value htmlnode drawdumpeventsform htmlnode boxnode htmlnode getalertlevelname maxlevel boxnode addchild htmlnode contentnode boxnode addchild advancedmode contentnode addchild clickformore htmlnode alertsnode contentnode addchild totalnumber currentalerts useralert currentalerts isvalid htmlnode listitem alertsnode addchild getalertlevelname getpriorityclass listitem addchild getshorttext totalnumber drawdumpeventsform htmlnode dumpformnode contentnode addchild addchild dumpformnode addchild formpassword formpassword stringbuilder stringbuilder currentalerts currentalerts iseventnotification currentalerts dumpformnode addchild tostring dumpformnode addchild dumpeventsbutton boxnode renders the given alert and returns the rendered html node param user alert the user alert to render return the rendered html node public html node render alert user alert user alert html node user alert node null short level user alert get priority class user alert node new html node div class infobox infobox get alert level name level user alert node add child div class infobox header user alert get title html node alert content node user alert node add child div class infobox content alert content node add child user alert gethtml text if user alert user can dismiss html node dismiss form node alert content node add child form new string action method new string post add child div dismiss form node add child input new string type name value new string hidden disable string value of user alert hash code dismiss form node add child input new string type name value new string hidden form password core form password dismiss form node add child input new string type name value new string submit dismiss user alert user alert dismiss button text return user alert node useralert htmlnode renderalert useralert useralert htmlnode useralertnode useralert getpriorityclass useralertnode htmlnode getalertlevelname useralertnode addchild useralert gettitle htmlnode alertcontentnode useralertnode addchild alertcontentnode addchild useralert gethtmltext useralert usercandismiss htmlnode dismissformnode alertcontentnode addchild addchild dismissformnode addchild valueof useralert hashcode dismissformnode addchild formpassword formpassword dismissformnode addchild useralert dismissbuttontext useralertnode private string get alert level name short level if level user alert critical error return error else if level user alert error return alert else if level user alert warning return warning else if level user alert minor return minor else logger error this unknown alert level level new exception debug return error getalertlevelname useralert critical_error useralert useralert useralert write the alert summary as html to a string builder public html node create summary short highest level 99 int number of critical error 0 int number of error 0 int number of warning 0 int number of minor 0 int total number 0 user alert alerts get alerts for int i 0 i alerts length i user alert alert alerts i if alert is valid continue short level alert get priority class if level highest level highest level level if level user alert critical error number of critical error else if level user alert error number of error else if level user alert warning number of warning else if level user alert minor number of minor total number if total number 0 return new html node boolean separator needed false int message types 0 string builder alert summary string new string builder 1024 if number of critical error 0 alert summary string append l10n critical error count label append append number of critical error separator needed true message types if number of error 0 if separator needed alert summary string append alert summary string append l10n error count label append append number of error separator needed true message types if number of warning 0 if separator needed alert summary string append alert summary string append l10n warning count label append append number of warning separator needed true message types if number of minor 0 if separator needed alert summary string append alert summary string append l10n minor count label append append number of minor separator needed true message types if message types 1 if separator needed alert summary string append alert summary string append l10n total label append append total number html node summary box null if highest level user alert critical error summary box new html node div class infobox infobox error else if highest level user alert error summary box new html node div class infobox infobox alert else if highest level user alert warning summary box new html node div class infobox infobox warning else if highest level user alert minor summary box new html node div class infobox infobox information summary box add child div class infobox header l10n alerts title html node summary content summary box add child div class infobox content alert summary string to string summary content add child l10n addl10n substitution summary content user alert manager alerts on alerts page new string link link new string a href alerts a return summary box stringbuilder htmlnode createsummary highestlevel numberofcriticalerror numberoferror numberofwarning numberofminor totalnumber useralert getalerts useralert isvalid getpriorityclass highestlevel highestlevel useralert critical_error numberofcriticalerror useralert numberoferror useralert numberofwarning useralert numberofminor totalnumber totalnumber htmlnode separatorneeded messagetypes stringbuilder alertsummarystring stringbuilder numberofcriticalerror alertsummarystring criticalerrorcountlabel numberofcriticalerror separatorneeded messagetypes numberoferror separatorneeded alertsummarystring alertsummarystring errorcountlabel numberoferror separatorneeded messagetypes numberofwarning separatorneeded alertsummarystring alertsummarystring warningcountlabel numberofwarning separatorneeded messagetypes numberofminor separatorneeded alertsummarystring alertsummarystring minorcountlabel numberofminor separatorneeded messagetypes messagetypes separatorneeded alertsummarystring alertsummarystring totallabel totalnumber htmlnode summarybox highestlevel useralert critical_error summarybox htmlnode highestlevel useralert summarybox htmlnode highestlevel useralert summarybox htmlnode highestlevel useralert summarybox htmlnode summarybox addchild alertstitle htmlnode summarycontent summarybox addchild alertsummarystring tostring summarycontent addchild addl10nsubstitution summarycontent useralertmanager alertsonalertspage summarybox private string l10n string key return l10n get string user alert manager key getstring useralertmanager public void dump events hash set string to dump an iterator might be faster but we don t want to call methods on the alert within the lock user alert alerts get alerts for int i 0 i alerts length i if alerts i is event notification continue if to dump contains alerts i anchor continue unregister alerts i alerts i on dismiss dumpevents hashset todump useralert getalerts iseventnotification todump ondismiss param args throws invalid threshold exception throws io exception throws node init exception throws interrupted exception public static void main string args throws invalid threshold exception io exception node init exception interrupted exception node second node null try string ip override null if args length 0 ip override args 0 file dir new file bootstrap pull test file util remove all dir random source random node starter global test init dir get path false logger error false byte seed new byte 64 random next bytes seed mersenne twister fast random new mersenne twister seed file seednodes new file seednodes fref if seednodes exists seednodes length 0 seednodes can read system err println unable to read seednodes fref it doesn t exist or is empty system exit exit no seednodes file second inner dir new file dir integer to string darknet port second inner dir mkdir file input stream fis new file input stream seednodes file util write to fis new file second inner dir seednodes fref fis close create the test data system out println creating test data file data file file create temp file testdata tmp dir output stream os new file output stream data file byte buf new byte 4096 for long written 0 written test size fast random next bytes buf int to write int math min test size written buf length os write buf 0 to write written to write os close insert it to the established node system out println inserting test data to an established node freeneturi uri insert data data file bootstrap a second node second inner dir mkdir fis new file input stream seednodes file util write to fis new file second inner dir seednodes fref fis close pooled executor executor new pooled executor second node node starter create test node darknet port opennet port dir get path true false false node default max htl 0 random executor 1000 5 1024 1024 true true true true true true true 12 1024 false true ip override second node start true wait for ten nodes second node fetch the data long start fetch time system current time millis high level simple client client second node client core make client short 0 try client fetch uri catch fetch exception e system err println fetch failed e e print stack trace system exit exit fetch failed return long end fetch time system current time millis system out println result fetch took end fetch time start fetch time ms time util format time end fetch time start fetch time of uri second node park system exit 0 catch throwable t system err println caught t t print stack trace try if second node null second node park catch throwable t1 system exit exit threw something invalidthresholdexception ioexception nodeinitexception interruptedexception invalidthresholdexception ioexception nodeinitexception interruptedexception secondnode ipoverride ipoverride fileutil removeall randomsource nodestarter globaltestinit getpath nextbytes mersennetwister fastrandom mersennetwister canread exit_no_seednodes secondinnerdir tostring darknet_port secondinnerdir fileinputstream fileinputstream fileutil writeto secondinnerdir datafile createtempfile outputstream fileoutputstream datafile test_size fastrandom nextbytes towrite test_size towrite towrite insertdata datafile secondinnerdir fileinputstream fileutil writeto secondinnerdir pooledexecutor pooledexecutor secondnode nodestarter createtestnode darknet_port opennet_port getpath default_max_htl ipoverride secondnode waitfortennodes secondnode startfetchtime currenttimemillis highlevelsimpleclient secondnode clientcore makeclient fetchexception printstacktrace exit_fetch_failed endfetchtime currenttimemillis endfetchtime startfetchtime timeutil formattime endfetchtime startfetchtime secondnode printstacktrace secondnode secondnode exit_threw_something private static freeneturi insert data file data file throws io exception long start insert time system current time millis inet address localhost inet address get by name 127 0 0 1 socket sock new socket localhost 9481 output stream sockos sock get output stream input stream sockis sock get input stream system out println connected to node line reading input stream lis new line reading input stream sockis output stream writer osw new output stream writer sockos utf 8 osw write client hello n expected version 0 7 n name bootstrap pull test system current time millis n end n osw flush string name lis read line 65536 128 true simple field set fs new simple field set lis 65536 128 true true false true if name equals node hello system err println no node hello from insertor node system exit exit inserter problem system out println connected to sock osw write client put n identifier test insert nuri chk n verbosity 1023 n upload from direct n max retries 1 n data length test size n data n osw flush input stream is new file input stream data file file util copy is sockos test size system out println sent data while true name lis read line 65536 128 true fs new simple field set lis 65536 128 true true false true system out println got fcp message n name system out print fs to ordered string if name equals protocol error system err println protocol error when inserting data system exit exit inserter problem if name equals put failed system err println insert failed system exit exit insert failed if name equals put successful long end insert time system current time millis freeneturi uri new freeneturi fs get uri system out println result insert took end insert time start insert time ms time util format time end insert time start insert time to uri sockos close sockis close sock close return uri insertdata datafile ioexception startinserttime currenttimemillis inetaddress inetaddress getbyname outputstream getoutputstream inputstream getinputstream linereadinginputstream linereadinginputstream outputstreamwriter outputstreamwriter clienthello nexpectedversion nname bootstrappulltest currenttimemillis nend readline simplefieldset simplefieldset nodehello nodehello exit_inserter_problem clientput nidentifier nverbosity nuploadfrom nmaxretries ndatalength test_size ndata inputstream fileinputstream datafile fileutil test_size readline simplefieldset toorderedstring protocolerror exit_inserter_problem putfailed exit_insert_failed putsuccessful endinserttime currenttimemillis endinserttime startinserttime timeutil formattime endinserttime startinserttime private static void wait for ten nodes node node throws interrupted exception long start time system current time millis wait until we have 10 connected nodes int seconds 0 boolean success false while seconds 600 thread sleep 1000 int seeds node peers count seednodes int seed conns node peers get connected seed server peers vector null size int opennet peers node peers count valid peers int opennet conns node peers count connected opennet peers system err println seconds seeds seeds connected seed conns opennet peers opennet peers connected opennet conns seconds if opennet conns target peers long time taken system current time millis start time system out println result completed bootstrap target peers peers in time taken ms time util format time time taken success true break if success system err println failed to reach target peers count target peers in 10 minutes node park system exit exit failed target waitfortennodes interruptedexception starttime currenttimemillis countseednodes seedconns getconnectedseedserverpeersvector opennetpeers countvalidpeers opennetconns countconnectedopennetpeers seedconns opennetpeers opennetconns opennetconns target_peers timetaken currenttimemillis starttime target_peers timetaken timeutil formattime timetaken target_peers exit_failed_target private final board m board public board page web interface my web interface ft own identity viewer http request request throws no such board exception super my web interface viewer request m board m freetalk get message manager get board by name request get param name mboard boardpage webinterface mywebinterface ftownidentity httprequest nosuchboardexception mywebinterface mboard mfreetalk getmessagemanager getboardbyname getparam public final void make html node threads box add content box threads in m board get name html node new thread form add form child threads box self uri new thread new thread page new thread form add child input new string type name value new string hidden own identityid m own identity getuid new thread form add child input new string type name value new string hidden board name m board get name new thread form add child input new string type name value new string submit submit new thread display the list of known identities html node threads table threads box add child table new string border width new string 0 100 html node row threads table add child tr row add child th title row add child th author row add child th date row add child th replies date format date format date format get instance synchronized m board fixme is this enough synchronization or should we lock the message manager iterator message reference threads m board thread iterator m own identity while threads has next message thread threads next get message row threads table add child tr html node title cell row add child td new string align new string left title cell add child new html node a href self uri show thread identity m own identity getuid board m board get name id thread getid thread get title author string author text thread get author get freetalk address fixme use the following algorithm for selecting how many characters after the to show character count 0 while two or more identities exist with author text being the same with given character count character count author text author text substring 0 author text index of 5 row add child td new string align new string left author text date row add child td new string align new string center date format format thread get date reply count row add child td new string align new string right integer to string m board thread reply count m own identity thread htmlnode threadsbox addcontentbox mboard getname htmlnode newthreadform addformchild threadsbox self_uri newthread newthreadpage newthreadform addchild ownidentityid mownidentity newthreadform addchild boardname mboard getname newthreadform addchild htmlnode threadstable threadsbox addchild htmlnode threadstable addchild addchild addchild addchild addchild dateformat dateformat dateformat getinstance mboard messagereference mboard threaditerator mownidentity hasnext getmessage threadstable addchild htmlnode titlecell addchild titlecell addchild htmlnode self_uri showthread mownidentity mboard getname gettitle authortext getauthor getfreetalkaddress charactercount authortext charactercount charactercount authortext authortext authortext indexof addchild authortext addchild dateformat getdate addchild tostring mboard threadreplycount mownidentity public misc composite context int rule float alpha color model src color model color model dst color model this rule rule this alpha alpha this src color model src color model this dst color model dst color model this src color space src color model get color space this dst color space dst color model get color space color model srgbcm color model getrg bdefault src needs converting src color model equals srgbcm dst needs converting dst color model equals srgbcm misccompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel srccolormodel dstcolormodel dstcolormodel srccolorspace srccolormodel getcolorspace dstcolorspace dstcolormodel getcolorspace colormodel colormodel getrgbdefault srcneedsconverting srccolormodel dstneedsconverting dstcolormodel public void dispose multiply two numbers in the range 0 255 such that 255 255 255 static int multiply255 int a int b int t a b 0x80 return t 8 t 8 static int clamp int a return a 0 0 a 255 255 a public void compose raster src raster dst in writable raster dst out float a 0 ac 0 float alpha this alpha int t float s hsv null di hsv null do hsv null switch rule case misc composite hue case misc composite saturation case misc composite value case misc composite color s hsv new float 3 di hsv new float 3 do hsv new float 3 break int src pix null int dst pix null int x dst out get minx int w dst out get width int y0 dst out get miny int y1 y0 dst out get height for int y y0 y y1 y src pix src get pixels x y w 1 src pix dst pix dst in get pixels x y w 1 dst pix int i 0 int end w 4 while i end int sr src pix i int dir dst pix i int sg src pix i 1 int dig dst pix i 1 int sb src pix i 2 int dib dst pix i 2 int sa src pix i 3 int dia dst pix i 3 int dor dog dob doa switch rule case misc composite add default dor dir sr if dor 255 dor 255 dog dig sg if dog 255 dog 255 dob dib sb if dob 255 dob 255 break case misc composite subtract dor dir sr if dor 0 dor 0 dog dig sg if dog 0 dog 0 dob dib sb if dob 0 dob 0 break case misc composite difference dor dir sr if dor 0 dor dor dog dig sg if dog 0 dog dog dob dib sb if dob 0 dob dob break case misc composite multiply t dir sr 0x80 dor t 8 t 8 t dig sg 0x80 dog t 8 t 8 t dib sb 0x80 dob t 8 t 8 break case misc composite screen t 255 dir 255 sr 0x80 dor 255 t 8 t 8 t 255 dig 255 sg 0x80 dog 255 t 8 t 8 t 255 dib 255 sb 0x80 dob 255 t 8 t 8 break case misc composite overlay if dir 128 t dir sr 0x80 dor 2 t 8 t 8 else t 255 dir 255 sr 0x80 dor 2 255 t 8 t 8 if dig 128 t dig sg 0x80 dog 2 t 8 t 8 else t 255 dig 255 sg 0x80 dog 2 255 t 8 t 8 if dib 128 t dib sb 0x80 dob 2 t 8 t 8 else t 255 dib 255 sb 0x80 dob 2 255 t 8 t 8 break case misc composite darken dor dir sr dir sr dog dig sg dig sg dob dib sb dib sb break case misc composite lighten dor dir sr dir sr dog dig sg dig sg dob dib sb dib sb break case misc composite average dor dir sr 2 dog dig sg 2 dob dib sb 2 break case misc composite hue case misc composite saturation case misc composite value case misc composite color color rg btohsb sr sg sb s hsv color rg btohsb dir dig dib di hsv switch rule case misc composite hue do hsv 0 s hsv 0 do hsv 1 di hsv 1 do hsv 2 di hsv 2 break case misc composite saturation do hsv 0 di hsv 0 do hsv 1 s hsv 1 do hsv 2 di hsv 2 break case misc composite value do hsv 0 di hsv 0 do hsv 1 di hsv 1 do hsv 2 s hsv 2 break case misc composite color do hsv 0 s hsv 0 do hsv 1 s hsv 1 do hsv 2 di hsv 2 break int dorgb color hs btorgb do hsv 0 do hsv 1 do hsv 2 dor dorgb 0xff0000 16 dog dorgb 0xff00 8 dob dorgb 0xff break case misc composite burn if dir 255 dor clamp 255 int 255 sr 8 dir 1 else dor sr if dig 255 dog clamp 255 int 255 sg 8 dig 1 else dog sg if dib 255 dob clamp 255 int 255 sb 8 dib 1 else dob sb break case misc composite color burn if sr 0 dor math max 255 int 255 dir 8 sr 0 else dor sr if sg 0 dog math max 255 int 255 dig 8 sg 0 else dog sg if sb 0 dob math max 255 int 255 dib 8 sb 0 else dob sb break case misc composite dodge dor clamp sr 8 256 dir dog clamp sg 8 256 dig dob clamp sb 8 256 dib break case misc composite color dodge if sr 255 dor math min dir 8 255 sr 255 else dor sr if sg 255 dog math min dig 8 255 sg 255 else dog sg if sb 255 dob math min dib 8 255 sb 255 else dob sb break case misc composite soft light int d d multiply255 sr dir dor d multiply255 dir 255 multiply255 255 dir 255 sr d d multiply255 sg dig dog d multiply255 dig 255 multiply255 255 dig 255 sg d d multiply255 sb dib dob d multiply255 dib 255 multiply255 255 dib 255 sb d break case misc composite hard light if sr 127 dor 255 2 multiply255 255 sr 255 dir else dor 2 multiply255 sr dir if sg 127 dog 255 2 multiply255 255 sg 255 dig else dog 2 multiply255 sg dig if sb 127 dob 255 2 multiply255 255 sb 255 dib else dob 2 multiply255 sb dib break case misc composite pin light dor sr 127 math max sr dir math min sr dir dog sg 127 math max sg dig math min sg dig dob sb 127 math max sb dib math min sb dib break case misc composite exclusion dor dir multiply255 sr 255 dir dir dog dig multiply255 sg 255 dig dig dob dib multiply255 sb 255 dib dib break case misc composite negation dor 255 math abs 255 sr dir dog 255 math abs 255 sg dig dob 255 math abs 255 sb dib break a alpha sa 255f ac 1 a dst pix i int a dor ac dir dst pix i 1 int a dog ac dig dst pix i 2 int a dob ac dib dst pix i 3 int sa alpha dia ac i 4 dst out set pixels x y w 1 dst pix dstin writableraster dstout shsv dihsv dohsv misccomposite misccomposite misccomposite misccomposite shsv dihsv dohsv srcpix dstpix dstout getminx dstout getwidth dstout getminy dstout getheight srcpix getpixels srcpix dstpix dstin getpixels dstpix srcpix dstpix srcpix dstpix srcpix dstpix srcpix dstpix misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite misccomposite rgbtohsb shsv rgbtohsb dihsv misccomposite dohsv shsv dohsv dihsv dohsv dihsv misccomposite dohsv dihsv dohsv shsv dohsv dihsv misccomposite dohsv dihsv dohsv dihsv dohsv shsv misccomposite dohsv shsv dohsv shsv dohsv dihsv hsbtorgb dohsv dohsv dohsv misccomposite misccomposite color_burn misccomposite misccomposite color_dodge misccomposite soft_light misccomposite hard_light misccomposite pin_light misccomposite misccomposite dstpix dstpix dstpix dstpix dstout setpixels dstpix boolean transfer succeeded background transfer peer node pn partially received block prb this pn pn bt new block transmitter node usm pn uid prb chk insert sender this transfersucceeded backgroundtransfer peernode partiallyreceivedblock blocktransmitter chkinsertsender void start node executor execute this chk insert background transfer for uid to pn get peer chkinsert backgroundtransfer getpeer public void run freenet support logger os thread logpid this try this real run catch throwable t this completed transfer false this received notice false logger error this caught t t osthread realrun completedtransfer receivednotice private void real run this completed transfer bt send node executor double check that the node is still connected pointless to wait otherwise if pn is connected transfer succeeded synch version this received notice wait for received notification this add ourselves as a listener for the longterm completion message of this transfer then gracefully exit try node usm add async filter get notification message filter this catch disconnected exception e normal if logminor logger minor this disconnected while adding filter this completed transfer false this received notice false else this received notice false pn local rejected overload transfer failed insert realrun completedtransfer isconnected transfersucceeded receivednotice waitforreceivednotification addasyncfilter getnotificationmessagefilter disconnectedexception completedtransfer receivednotice receivednotice localrejectedoverload transferfailedinsert private void completed transfer boolean success synchronized this transfer succeeded success completed transfer true notify all synchronized background transfers background transfers notify all if success set transfer timed out completedtransfer transfersucceeded completedtransfer notifyall backgroundtransfers backgroundtransfers notifyall settransfertimedout private void received notice boolean success synchronized this if received completion notice logger error this received notice success already had received notice completion succeeded else completion succeeded success received completion notice true notify all synchronized background transfers background transfers notify all if success set transfer timed out receivednotice receivedcompletionnotice receivednotice receivednotice completionsucceeded completionsucceeded receivedcompletionnotice notifyall backgroundtransfers backgroundtransfers notifyall settransfertimedout public void on matched message m pn success not overload peer node pn peer node m get source pn cannot be null because the filters will prevent garbage collection of the nodes if this pn equals pn boolean any timed out m get boolean dmt any timed out if any timed out chk insert sender this set transfer timed out received notice any timed out else logger error this received completion notice for wrong node pn this pn onmatched successnotoverload peernode peernode getsource anytimedout getboolean any_timed_out anytimedout chkinsertsender settransfertimedout receivednotice anytimedout public boolean should timeout afiacs this will still let the filter timeout but not call on matched twice return received completion notice shouldtimeout onmatched receivedcompletionnotice private message filter get notification message filter return message filter create set field dmt uid uid set type dmt fnp insert transfers completed set source pn set timeout transfer completion ack timeout messagefilter getnotificationmessagefilter messagefilter setfield settype fnpinserttransferscompleted setsource settimeout transfer_completion_ack_timeout public void on timeout fixme cascading timeout if this times out we don t have any time to report to the node of origin the timeout notification any timed out normal priority because it is normally caused by a transfer taking too long downstream and that doesn t usually indicate a bug logger normal this timed out waiting for a final ack from pn on this pn local rejected overload insert timeout no final ack received notice false ontimeout anytimedout localrejectedoverload inserttimeoutnofinalack receivednotice public void on disconnect peer context ctx logger normal this disconnected ctx for this received notice true as far as we know ondisconnect peercontext receivednotice public void on restarted peer context ctx logger normal this restarted ctx for this received notice true onrestarted peercontext receivednotice public int get priority return native thread high priority getpriority nativethread high_priority chk insert sender nodechk my key long uid byte headers short htl peer node source node node partially received block prb boolean from store this my key my key this target my key to normalized double this uid uid this headers headers this htl htl this source source this node node this prb prb this from store from store this start time system current time millis this background transfers new vector background transfer logminor logger should log logger minor this chkinsertsender mykey peernode partiallyreceivedblock fromstore mykey mykey mykey tonormalizeddouble fromstore fromstore starttime currenttimemillis backgroundtransfers backgroundtransfer shouldlog void start node executor execute this chk insert sender for uid uid on node get darknet port number at system current time millis chkinsertsender getdarknetportnumber currenttimemillis static final int receive failed 7 override public string to string return super to string for uid receive_failed tostring tostring public void run freenet support logger os thread logpid this short orightl synchronized this orightl htl node add insert sender my key orightl this try real run catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t finally always check we always set status even if receive failed int my status synchronized this my status status if my status not finished finish internal error null node remove insert sender my key orightl this osthread addinsertsender mykey realrun outofmemoryerror oomhandler receivefailed mystatus mystatus mystatus not_finished internal_error removeinsertsender mykey private void real run hash set peer node nodes routed to new hash set peer node peer node next null while true if receive failed return don t need to set status as killed by chk insert handler if we haven t routed to any node yet decrement according to the source if we have decrement according to the node which just failed because 1 if we always decrement according to source then we can be at max or min htl for a long time while we visit every peer node this is bad 2 the node which just failed can be seen as the requestor for our purposes decrement at this point so we can dnf immediately on reaching htl 0 htl node decrementhtl sent request next source htl synchronized this if htl 0 send an insert reply back finish success null return route it can backtrack so only route to nodes closer than we are to target next node peers closer peer source nodes routed to target true node is advanced mode enabled 1 null null if next null backtrack finish route not found null return if logminor logger minor this routing insert to next nodes routed to add next message req req dmt createfnp insert request uid htl my key wait for ack or reject will come before even a locally generated data reply message filter mf accepted message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp accepted message filter mf rejected loop message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected loop message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected overload mf rejected overload must be the last thing in the or so its or pointer remains null otherwise we need to recreate it below mf rejected overload clear or message filter mf mf accepted or mf rejected loop or mf rejected overload send to next node try when using send sync this send can often timeout it is the first request we are sending to this node if send sync blocks here message queue is full node down etc it can take up to 10 minutes if this occurs at even two nodes in any given insert at any point in the path the entire insert chain will fatally timeout we cannot be informed if send sync does timeout a message will be logged but this thread will simply continue to the wait for and spend another timeout period there the timeout on the wait for is 10 seconds accepted timeout the interesting case is when this next node is temporarily busy in which case we might skip a busy node if they don t respond in ten seconds accepted timeout or if the length of the send queue to them is greater than accepted timeout using send async will skip them before they get the request this would be a need for retuning accepted timeout next send async req null this catch not connected exception e1 if logminor logger minor this not connected to next continue synchronized this sent request true if receive failed return don t need to set status as killed by chk insert handler message msg null because messages may be re ordered it is entirely possible that we get a non local rejected overload followed by an accepted so we must loop here while msg null msg get spec dmt fnp accepted try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for accepted break if receive failed return don t need to set status as killed by chk insert handler if msg null terminal overload try to propagate back to source if logminor logger minor this timeout next local rejected overload timeout3 try another node forward rejected overload break if msg get spec dmt fnp rejected overload non fatal probably still have time left if msg get boolean dmt is local next local rejected overload forward rejected overload5 if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break else forward rejected overload continue if msg get spec dmt fnp rejected loop next success not overload loop we don t want to send the data to this one break if msg get spec dmt fnp accepted logger error this unexpected message waiting for accepted msg break otherwise is an fnp accepted if msg null msg get spec dmt fnp accepted continue if logminor logger minor this got accepted on this send them the data which might be the new data resulting from a collision message data insert data insert dmt createfnp data insert uid headers what are we waiting for now fnp route not found couldn t exhaust htl but send us the data anyway please fnp insert reply used up all htl yay fnp reject overload propagating an overload error fnp reject timeout we took too long to send the data insert fnp data insert rejected the insert was invalid message filter mf insert reply message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp insert reply mf rejected overload set timeout search timeout mf rejected overload clear or message filter mf route not found message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp route not found message filter mf data insert rejected message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp data insert rejected message filter mf timeout message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp rejected timeout mf mf insert reply or mf route not found or mf data insert rejected or mf timeout or mf rejected overload if logminor logger minor this sending data insert if receive failed return try next send sync data insert this catch not connected exception e1 if logminor logger minor this not connected sending data insert next for uid continue if logminor logger minor this sending data start background transfer next prb while true if receive failed return try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for insert reply on this break if receive failed return if msg null msg get spec dmt fnp rejected timeout timeout fairly serious problem logger error this timeout msg after accepted in insert terminal overload try to propagate back to source next local rejected overload after insert accepted timeout2 finish timed out next return if msg get spec dmt fnp rejected overload probably non fatal if so we have time left can try next one if msg get boolean dmt is local next local rejected overload forward rejected overload6 if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break else forward rejected overload continue wait for any further response if msg get spec dmt fnp route not found if logminor logger minor this rejected rnf short new htl msg get short dmt htl synchronized this if htl new htl htl new htl finished as far as this node is concerned next success not overload rnf means that the htl was not exhausted but that the data will still be stored break can occur after reception of the entire chk block if msg get spec dmt fnp data insert rejected next success not overload short reason msg get short dmt data insert rejected reason if logminor logger minor this data insert rejected reason if reason dmt data insert rejected verify failed if from store that s odd logger error this verify failed on ne realrun hashset peernode nodesroutedto hashset peernode peernode receivefailed chkinserthandler sentrequest insertreply closerpeer nodesroutedto isadvancedmodeenabled route_not_found nodesroutedto createfnpinsertrequest mykey datareply messagefilter mfaccepted messagefilter setsource setfield settimeout accepted_timeout settype fnpaccepted messagefilter mfrejectedloop messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedloop messagefilter mfrejectedoverload messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedoverload mfrejectedoverload mfrejectedoverload clearor messagefilter mfaccepted mfrejectedloop mfrejectedoverload sendsync sendsync sendsync waitfor waitfor accepted_timeout accepted_timeout accepted_timeout sendasync accepted_timeout sendasync notconnectedexception sentrequest receivefailed chkinserthandler rejectedoverload getspec fnpaccepted waitfor disconnectedexception receivefailed chkinserthandler localrejectedoverload forwardrejectedoverload getspec fnprejectedoverload getboolean is_local localrejectedoverload forwardrejectedoverload5 rejectedoverload forwardrejectedoverload getspec fnprejectedloop successnotoverload getspec fnpaccepted fnpaccepted getspec fnpaccepted datainsert datainsert createfnpdatainsert fnproutenotfound fnpinsertreply fnprejectoverload fnprejecttimeout datainsert fnpdatainsertrejected messagefilter mfinsertreply messagefilter setsource setfield settimeout search_timeout settype fnpinsertreply mfrejectedoverload settimeout search_timeout mfrejectedoverload clearor messagefilter mfroutenotfound messagefilter setsource setfield settimeout search_timeout settype fnproutenotfound messagefilter mfdatainsertrejected messagefilter setsource setfield settimeout search_timeout settype fnpdatainsertrejected messagefilter mftimeout messagefilter setsource setfield settimeout search_timeout settype fnprejectedtimeout mfinsertreply mfroutenotfound mfdatainsertrejected mftimeout mfrejectedoverload datainsert receivefailed sendsync datainsert notconnectedexception datainsert startbackgroundtransfer receivefailed waitfor disconnectedexception insertreply receivefailed getspec fnprejectedtimeout localrejectedoverload afterinsertacceptedtimeout2 timed_out getspec fnprejectedoverload getboolean is_local localrejectedoverload forwardrejectedoverload6 rejectedoverload forwardrejectedoverload getspec fnproutenotfound newhtl getshort newhtl newhtl successnotoverload getspec fnpdatainsertrejected successnotoverload getshort data_insert_rejected_reason datainsertrejected data_insert_rejected_verify_failed fromstore private void start background transfer peer node node partially received block prb background transfer ac new background transfer node prb synchronized background transfers background transfers add ac background transfers notify all ac start startbackgroundtransfer peernode partiallyreceivedblock backgroundtransfer backgroundtransfer backgroundtransfers backgroundtransfers backgroundtransfers notifyall private boolean has forwarded rejected overload synchronized boolean received rejected overload return has forwarded rejected overload hasforwardedrejectedoverload receivedrejectedoverload hasforwardedrejectedoverload forward rejected overload to the request originator do not call if have a local rejected overload private synchronized void forward rejected overload if has forwarded rejected overload return has forwarded rejected overload true notify all rejectedoverload rejectedoverload forwardrejectedoverload hasforwardedrejectedoverload hasforwardedrejectedoverload notifyall private void set transfer timed out if transfer timed out return synchronized this if transfer timed out transfer timed out true notify all settransfertimedout transfertimedout transfertimedout transfertimedout notifyall finish the insert process will set status wait for underlings to complete and report success if appropriate param code the status code to set param next the node we successfully inserted to private void finish int code peer node next if logminor logger minor this finished code on this new exception debug synchronized this if code route not found sent request code route really not found if status not finished if status receive failed if code success logger error this request succeeded despite receive failed on this else throw new illegal state exception finish called with code when was already status else status code notify all if logminor logger minor this set status code get status string on uid boolean failed recv receive failed is protected by background transfers but status by this now wait for transfers or for downstream transfer notifications note that even the data receive may not have completed by this point synchronized background transfers if background transfers is empty wait for background transfer completions else if logminor logger minor this no background transfers failed recv receive failed synchronized this if failed recv status receive failed all transfers completed true notify all if status success next null next on success true false if logminor logger minor this returning from finish peernode route_not_found sentrequest route_really_not_found not_finished receive_failed illegalstateexception notifyall getstatusstring failedrecv receivefailed backgroundtransfers backgroundtransfers backgroundtransfers isempty waitforbackgroundtransfercompletions failedrecv receivefailed failedrecv receive_failed alltransferscompleted notifyall onsuccess public synchronized int get status return status getstatus public synchronized short gethtl return htl called by chk insert handler to notify that the receive has failed public void receive failed synchronized background transfers receive failed true background transfers notify all set status immediately the code e g wait for status relies on a status eventually being set so we may as well set it here the alternative is to set it in real run when we notice that receive failed true synchronized this status receive failed all transfers completed true notify all do not call finish that can only be called on the main thread and it will block chkinserthandler receivefailed backgroundtransfers receivefailed backgroundtransfers notifyall waitforstatus realrun receivefailed receive_failed alltransferscompleted notifyall return the current status as a string public synchronized string get status string if status success return success if status route not found return route not found if status not finished return not finished if status internal error return internal error if status timed out return timed out if status generated rejected overload return generated rejected overload if status route really not found return route really not found return unknown status code status getstatusstring route_not_found not_finished internal_error timed_out generated_rejected_overload route_really_not_found public synchronized boolean sent request return sent request sentrequest sentrequest private void wait for background transfer completions try freenet support logger os thread logpid this if logminor logger minor this waiting for background transfer completions this we must presently be at such a stage that no more background transfers will be added background transfer transfers synchronized background transfers transfers new background transfer background transfers size transfers background transfers to array transfers wait for the outgoing transfers to complete if wait for background transfers transfers set transfer timed out return finally synchronized chk insert sender this all transfers completed true chk insert sender this notify all waitforbackgroundtransfercompletions osthread backgroundtransfer backgroundtransfers backgroundtransfer backgroundtransfers backgroundtransfers toarray waitforbackgroundtransfers settransfertimedout chkinsertsender alltransferscompleted chkinsertsender notifyall block until all transfers have reached a final terminal state success failure on success this means that a successful received notification has been received return true if all background transfers were successful private boolean wait for background transfers background transfer transfers long start system current time millis generous deadline so we catch bugs more obviously long deadline start transfer completion ack timeout 3 maybe all done while true if system current time millis deadline normal priority because it is normally caused by a transfer taking too long downstream and that doesn t usually indicate a bug logger normal this timed out waiting for background transfers probably caused by async filter not getting a timeout notification debug me return false if we want to be sure to exit as soon as the transfers are done then we must hold the lock while we check synchronized background transfers if receive failed return false boolean none routeable true boolean completed transfers true boolean completed notifications true for int i 0 i transfers length i if transfers i pn is routable continue none routeable false if transfers i completed transfer if logminor logger minor this waiting for transfer completion to transfers i pn transfers i must wait completed transfers false break if transfers i received completion notice if logminor logger minor this waiting for completion notice from transfers i pn transfers i must wait completed notifications false break if transfers i completion succeeded return false if none routeable return false if completed transfers completed notifications return true if logminor logger minor this waiting transfer completion completed transfers notification completed notifications try background transfers wait 100 1000 catch interrupted exception e ignore waitforbackgroundtransfers backgroundtransfer currenttimemillis transfer_completion_ack_timeout currenttimemillis backgroundtransfers receivefailed nonerouteable completedtransfers completednotifications isroutable nonerouteable completedtransfer completedtransfers receivedcompletionnotice completednotifications completionsucceeded nonerouteable completedtransfers completednotifications completedtransfers completednotifications backgroundtransfers interruptedexception public synchronized boolean completed return all transfers completed alltransferscompleted block until status has been set to something other than not finished public synchronized void wait for status while status not finished try chk insert sender this wait 100 1000 catch interrupted exception e ignore not_finished waitforstatus not_finished chkinsertsender interruptedexception public boolean any transfers failed return transfer timed out anytransfersfailed transfertimedout public byte get pubkey hash return headers getpubkeyhash public byte get headers return headers getheaders public long getuid return uid public void sent bytes int x synchronized total bytes sync total bytes sent x node node stats insert sent bytes false x sentbytes totalbytessync totalbytessent nodestats insertsentbytes public int get total sent bytes synchronized total bytes sync return total bytes sent gettotalsentbytes totalbytessync totalbytessent public void received bytes int x synchronized total bytes sync total bytes received x node node stats insert received bytes false x receivedbytes totalbytessync totalbytesreceived nodestats insertreceivedbytes public int get total received bytes synchronized total bytes sync return total bytes received gettotalreceivedbytes totalbytessync totalbytesreceived public void sent payload int x node sent payload x node node stats insert sent bytes false x sentpayload sentpayload nodestats insertsentbytes public boolean failed receive return receive failed failedreceive receivefailed public synchronized boolean started sending data return background transfers is empty startedsendingdata backgroundtransfers isempty public int get priority return native thread high priority getpriority nativethread high_priority public transient chosen block sendable request req sendable request item token key key client key ckey boolean local request only boolean cache local requests boolean ignore store request scheduler sched super token key ckey local request only cache local requests ignore store sched this request req this sched sched transientchosenblock sendablerequest sendablerequestitem clientkey localrequestonly cachelocalrequests ignorestore requestscheduler localrequestonly cachelocalrequests ignorestore override public boolean is cancelled return request is cancelled null iscancelled iscancelled override public boolean is persistent return false ispersistent override public void on failure low level put exception e client context context sendable insert request on failure e token null context onfailure lowlevelputexception clientcontext sendableinsert onfailure override public void on insert success client context context sendable insert request on success token null context oninsertsuccess clientcontext sendableinsert onsuccess override public void on failure low level get exception e client context context sendable get request on failure e token null context onfailure lowlevelgetexception clientcontext sendableget onfailure override public void on fetch success client context context sched succeeded sendable get request false onfetchsuccess clientcontext sendableget override public short get priority return request get priority class null getpriority getpriorityclass override public sendable request sender get sender client context context return request get sender null context sendablerequestsender getsender clientcontext getsender public void open i file file int page pool size if opened throw new storage error storage error storage already opened initialize file page pool size lock new persistent resource init new object sync new object done new object commit new object listening true connect thread new thread this thread start wait synchronization completion wait initialization completion opened true begin thread transaction replication slave transaction reload scheme end thread transaction ifile pagepoolsize storageerror storageerror storage_already_opened pagepoolsize persistentresource waitsynchronizationcompletion waitinitializationcompletion beginthreadtransaction replication_slave_transaction reloadscheme endthreadtransaction check if socket is connected to the master host return code true code if connection between slave and master is sucessfully established public boolean is connected return socket null isconnected public void begin thread transaction int mode if mode replication slave transaction throw new illegal argument exception illegal transaction mode lock shared lock page pg pool get page 0 header unpack pg data pool unfix pg curr index 1 header curr curr index size header root 1 curr index index used committed index size curr index size used size header root curr index size object cache clear beginthreadtransaction replication_slave_transaction illegalargumentexception sharedlock getpage currindex currindexsize currindex indexused committedindexsize currindexsize usedsize currindex objectcache public void end thread transaction int max delay lock unlock endthreadtransaction maxdelay protected void wait synchronization completion try synchronized sync while out of sync sync wait catch interrupted exception x waitsynchronizationcompletion outofsync interruptedexception protected void wait initialization completion try synchronized init while initialized init wait catch interrupted exception x waitinitializationcompletion interruptedexception wait until database is modified by master this method blocks current thread until master node commits trasanction and this transanction is completely delivered to this slave node public void wait for modification try synchronized commit if socket null commit wait catch interrupted exception x waitformodification interruptedexception when overriden by base class this method perfroms socket error handling return code true code if host should be reconnected and attempt to send data to it should be repeated code false code if no more attmpts to communicate with this host should be performed public boolean handle error return listener null listener replication error null false handleerror replicationerror void connect try socket get socket try socket set so linger true linger time catch no such method error er try socket set tcp no delay true catch exception x in socket get input stream if replication ack out socket get output stream catch io exception x socket null in null getsocket setsolinger linger_time nosuchmethoderror settcpnodelay getinputstream replicationack getoutputstream ioexception abstract socket get socket throws io exception getsocket ioexception abstract socket get socket throws io exception void cancelio getsocket ioexception public void run byte buf new byte page page size page data offset while listening int offs 0 do int rc try rc in read buf offs buf length offs catch io exception x rc 1 synchronized done if listening return if rc 0 if handle error connect else return else offs rc while offs buf length long pos bytes unpack8 buf 0 boolean transaction commit false if pos 0 if replication ack try out write buf 0 1 catch io exception x handle error if buf page data offset db hdr curr index offset prev index prev index buf page data offset db hdr curr index offset lock exclusive lock transaction commit true else if pos repl sync synchronized sync out of sync false sync notify continue else if pos repl close synchronized commit hangup commit notify all return page pg pool put page pos system arraycopy buf page data offset pg data 0 page page size pool unfix pg if pos 0 if initialized buf page data offset db hdr initialized offset 0 synchronized init initialized true init notify if transaction commit lock unlock synchronized commit commit notify all pool flush pagesize page_data_offset ioexception handleerror transactioncommit replicationack ioexception handleerror page_data_offset db_hdr_curr_index_offset previndex previndex page_data_offset db_hdr_curr_index_offset exclusivelock transactioncommit repl_sync outofsync repl_close notifyall putpage page_data_offset pagesize page_data_offset db_hdr_initialized_offset transactioncommit notifyall public void close synchronized done listening false cancelio try thread interrupt thread join catch interrupted exception x hangup pool flush super close interruptedexception protected void hangup if socket null try in close if out null out close socket close catch io exception x in null socket null ioexception protected boolean is dirty return false isdirty public histogram histogram null num samples 0 is gray true min value null max value null min frequency null max frequency null mean null numsamples isgray minvalue maxvalue minfrequency maxfrequency public histogram int pixels int w int h int offset int stride histogram new int 3 256 min value new int 4 max value new int 4 min frequency new int 3 max frequency new int 3 mean new float 3 num samples w h is gray true int index 0 for int y 0 y h y index offset y stride for int x 0 x w x int rgb pixels index int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff histogram red r histogram green g histogram blue b for int i 0 i 256 i if histogram red i histogram green i histogram green i histogram blue i is gray false break for int i 0 i 3 i for int j 0 j 256 j if histogram i j 0 min value i j break for int j 255 j 0 j if histogram i j 0 max value i j break min frequency i integer max value max frequency i 0 for int j 0 j 256 j min frequency i math min min frequency i histogram i j max frequency i math max max frequency i histogram i j mean i float j histogram i j mean i float num samples min value gray math min math min min value red min value green min value blue max value gray math max math max max value red max value green max value blue minvalue maxvalue minfrequency maxfrequency numsamples isgray isgray minvalue maxvalue minfrequency max_value maxfrequency minfrequency minfrequency maxfrequency maxfrequency numsamples minvalue minvalue minvalue minvalue maxvalue maxvalue maxvalue maxvalue public boolean is gray return is gray isgray isgray public int get num samples return num samples getnumsamples numsamples public int get frequency int value if num samples 0 is gray value 0 value 255 return histogram 0 value return 1 getfrequency numsamples isgray public int get frequency int channel int value if num samples 1 channel 0 channel 2 value 0 value 255 return 1 return histogram channel value getfrequency numsamples public int get min frequency if num samples 0 is gray return min frequency 0 return 1 getminfrequency numsamples isgray minfrequency public int get min frequency int channel if num samples 1 channel 0 channel 2 return 1 return min frequency channel getminfrequency numsamples minfrequency public int get max frequency if num samples 0 is gray return max frequency 0 return 1 getmaxfrequency numsamples isgray maxfrequency public int get max frequency int channel if num samples 1 channel 0 channel 2 return 1 return max frequency channel getmaxfrequency numsamples maxfrequency public int get min value if num samples 0 is gray return min value 0 return 1 getminvalue numsamples isgray minvalue public int get min value int channel return min value channel getminvalue minvalue public int get max value if num samples 0 is gray return max value 0 return 1 getmaxvalue numsamples isgray maxvalue public int get max value int channel return max value channel getmaxvalue maxvalue public float get mean value if num samples 0 is gray return mean 0 return 1 0f getmeanvalue numsamples isgray public float get mean value int channel if num samples 0 red channel channel blue return mean channel return 1 0f getmeanvalue numsamples test harness public static void main string args throws url encoded format exception for int i 0 i args length i system out println args i decode args i false urlencodedformatexception decodes a url encoder format string param s string to be translated param tolerant if true be tolerant of bogus escapes bogus escapes are treated as just plain characters not recommended a hack to allow users to paste in ur ls containing s return the translated string public static string decode string s boolean tolerant throws url encoded format exception if s length 0 return int len s length byte array output stream decoded bytes new byte array output stream boolean has decoded something false for int i 0 i len i char c s char at i if c if i len 2 throw new url encoded format exception s char hex chars new char 2 hex chars 0 s char at i hex chars 1 s char at i string hexval new string hex chars try long read fields hex to long hexval if read 0 throw new url encoded format exception can t encode 00 decoded bytes write int read has decoded something true catch number format exception nfe not encoded if tolerant has decoded something try byte buf hexval get bytes utf 8 decoded bytes write buf 0 buf length continue catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e throw new url encoded format exception not a two character hex escape hexval in s else try byte encoded c get bytes utf 8 decoded bytes write encoded 0 encoded length catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e try decoded bytes close return new string decoded bytes to byte array utf 8 catch io exception ioe1 if this throws something s wrong throw new url encoded format exception s urlencoder urls urlencodedformatexception bytearrayoutputstream decodedbytes bytearrayoutputstream hasdecodedsomething charat urlencodedformatexception hexchars hexchars charat hexchars charat hexchars hextolong urlencodedformatexception decodedbytes hasdecodedsomething numberformatexception hasdecodedsomething getbytes decodedbytes unsupportedencodingexception urlencodedformatexception getbytes decodedbytes unsupportedencodingexception decodedbytes decodedbytes tobytearray ioexception urlencodedformatexception construct a crop filter public crop filter this 0 0 32 32 cropfilter cropfilter construct a crop filter param x the left edge of the crop rectangle param y the top edge of the crop rectangle param width the width of the crop rectangle param height the height of the crop rectangle public crop filter int x int y int width int height this x x this y y this width width this height height cropfilter cropfilter set the left edge of the crop rectangle param x the left edge of the crop rectangle see getx public void setx int x this x x get the left edge of the crop rectangle return the left edge of the crop rectangle see setx public int getx return x set the top edge of the crop rectangle param y the top edge of the crop rectangle see gety public void sety int y this y y get the top edge of the crop rectangle return the top edge of the crop rectangle see sety public int gety return y set the width of the crop rectangle param width the width of the crop rectangle see get width public void set width int width this width width getwidth setwidth get the width of the crop rectangle return the width of the crop rectangle see set width public int get width return width setwidth getwidth set the height of the crop rectangle param height the height of the crop rectangle see get height public void set height int height this height height getheight setheight get the height of the crop rectangle return the height of the crop rectangle see set height public int get height return height setheight getheight public buffered image filter buffered image src buffered image dst int w src get width int h src get height if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster width height dstcm is alpha premultiplied null graphics2d g dst create graphics g draw rendered image src affine transform get translate instance x y g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight colormodel getcolormodel bufferedimage createcompatiblewritableraster isalphapremultiplied creategraphics drawrenderedimage affinetransform gettranslateinstance override public string to string return distort crop tostring public class key listener construction exception extends exception key listener construction exception fetch exception e super e keylistenerconstructionexception keylistenerconstructionexception fetchexception public fetch exception get fetch exception return fetch exception get cause fetchexception getfetchexception fetchexception getcause public abstract class relation m extends i persistent o extends i persistent extends persistent implements link m get relation owner return owner of the relation public o get owner return owner ipersistent ipersistent getowner set relation owner param owner new owner of the relation public void set owner o owner this owner owner modify setowner relation constructor creates empty relation with specified owner and no members members can be added to the relation later param owner owner of the relation public relation o owner this owner owner protected relation public action response set header http ext actionresponse setheader public action response soap response soap res super soap res set header http ext actionresponse soapresponse soapres soapres setheader public void set response action action set status code http status ok node body node get body node node res node create response node action body node add node res node node env node get envelope node set content env node setresponse setstatuscode httpstatus bodynode getbodynode resnode createresponsenode bodynode addnode resnode envnode getenvelopenode setcontent envnode private node create response node action action string action name action get name node action name res node new node soap methodns soap delim action name soap response service service action get service if service null action name res node set attribute xmlns soap methodns service get service type argument list arg list action get argument list int n args arg list size for int n 0 n n args n argument arg arg list get argument n if arg is out direction false continue node arg node new node arg node set name arg get name arg node set value arg get value action name res node add node arg node return action name res node createresponsenode actionname getname actionnameresnode actionname getservice actionnameresnode setattribute getservicetype argumentlist arglist getargumentlist nargs arglist nargs arglist getargument isoutdirection argnode argnode setname getname argnode setvalue getvalue actionnameresnode addnode argnode actionnameresnode private node get action response node node body node get body node if body node null body node has nodes false return null return body node get node 0 getactionresponsenode bodynode getbodynode bodynode bodynode hasnodes bodynode getnode public argument list get response argument list arg list new argument list node res node get action response node if res node null return arg list int n args res node getn nodes for int n 0 n n args n node node res node get node n string name node get name string value node get value argument arg new argument name value arg list add arg return arg list argumentlist getresponse argumentlist arglist argumentlist resnode getactionresponsenode resnode arglist nargs resnode getnnodes nargs resnode getnode getname getvalue arglist arglist public static void main string args throws fs parse exception peer parse exception chk encode exception invalid threshold exception node init exception reference signature verification exception interrupted exception string name real node request insert test file wd new file name if file util remove all wd system err println mass delete failed test may not be accurate system exit exit cannot delete old data wd mkdir note global test init returns in ignored random source node starter global test init name false logger error freenet node location normal freenet node simulator real node minor freenet node insert minor freenet node request minor freenet node node minor node starter global test init name false logger error freenet node location minor freenet io comm minor freenet node node dispatcher minor freenet node simulator minor freenet node peer manager minor freenet node request sender minor node starter global test init name false logger error freenet node fnp minor freenet node packet minor freenet io comm minor freenet node peer node minor freenet node darknet peer node minor node starter global test init name false logger error true system out println insert retrieve test system out println dummy random source random new dummy random source diffie hellman init random node nodes new node number of nodes logger normal real node routing test class creating nodes executor executor new pooled executor for int i 0 i number of nodes i nodes i node starter create test node 5001 i 0 name false true false max htl 20 5 random executor 500 number of nodes 256 1024 true enable swapping false enable ulprs enable per node failure tables enable swap queueing enable packet coalescing 12000 enable foaf false null logger normal real node routing test class created node i now link them up make kleinberg network nodes start with ideal locations degree force neighbour connections logger normal real node routing test class added random links for int i 0 i number of nodes i nodes i start false system err println started node i nodes length wait for all connected nodes wait for ping average 0 95 nodes random max pings 1000 system out println system out println ping average 95 lets do some inserts requests system out println int request number 0 running average requests avg new simple running average 100 0 0 string base string system current time millis int insert attempts 0 int insert successes 0 int fetch successes 0 while true try request number try thread sleep 100 catch interrupted exception e1 string data string base string request number pick random node to insert to int node1 random next int number of nodes node random node nodes node1 logger error real node request insert test class inserting data string to node1 boolean isssk request number 2 1 boolean isssk true freeneturi test key client key insert key client key fetch key client key block block byte buf data string get bytes utf 8 if isssk test key new freeneturi ksk data string insert key insertable clientssk create test key fetch key clientksk create test key block insertable clientssk insert key encode new array bucket buf false false short 1 buf length random else block clientchk block encode buf false false short 1 buf length insert key fetch key block get client key test key insert key geturi system err println system err println created random test key test key fetch key get node key system err println byte data data string get bytes utf 8 logger minor real node request insert test class decoded new string block memory decode logger normal real node request insert test class insert key insert key geturi logger normal real node request insert test class fetch key fetch key geturi try insert attempts random node client core real put block true logger error real node request insert test class inserted to node1 insert successes catch freenet node low level put exception put ex logger error real node request insert test class insert failed put ex system err println insert failed put ex system exit exit insert failed pick random node to request from int node2 do node2 random next int number of nodes while node2 node1 node fetch node nodes node2 block fetch node client core real get key fetch key false true false if block null int percent success 100 fetch successes insert attempts logger error real node request insert test class fetch request number failed percent success from node2 requests avg report 0 0 system exit exit request failed else byte results block memory decode requests avg report 1 0 if arrays equals results data fetch successes int percent success 100 fetch successes insert attempts logger error real node request insert test class fetch request number from node node2 succeeded percent success new string results system err println fetch request number succeeded percent success new string results if fetch successes target successes system err println succeeded target successes successful fetches system exit 0 else logger error real node request insert test class returned invalid data new string results system err println returned invalid data new string results system exit exit bad data string builder load new string builder running ui ds for nodes int total runningui ds 0 int total runningui ds alt 0 vector long runningui ds list new vector long for int i 0 i nodes length i load append i load append nodes i add runningui ds runningui ds list int runningui ds nodes i get total runningui ds int runningui ds alt nodes i get total runningui ds alt total runningui ds runningui ds total runningui ds alt runningui ds alt load append total runningui ds load append load append total runningui ds alt if i nodes length 1 load append system err println load to string if total runningui ds 0 system err println still running ui ds total runningui ds if total runningui ds alt 0 system err println still running ui ds alt total runningui ds alt if runningui ds list is empty system err println list of running ui ds arrays to string runningui ds list to array catch throwable t logger error real node request insert test class caught t t fsparseexception peerparseexception chkencodeexception invalidthresholdexception nodeinitexception referencesignatureverificationexception interruptedexception realnoderequestinserttest fileutil removeall exit_cannot_delete_old_data globaltestinit nodestarter globaltestinit realnode nodestarter globaltestinit nodedispatcher peermanager requestsender nodestarter globaltestinit peernode darknetpeernode nodestarter globaltestinit dummyrandomsource dummyrandomsource diffiehellman number_of_nodes realnoderoutingtest pooledexecutor number_of_nodes nodestarter createtestnode max_htl number_of_nodes enable_swapping enable_ulprs enable_per_node_failure_tables enable_swap_queueing enable_packet_coalescing enable_foaf realnoderoutingtest makekleinbergnetwork start_with_ideal_locations force_neighbour_connections realnoderoutingtest number_of_nodes waitforallconnected waitforpingaverage max_pings requestnumber runningaverage requestsavg simplerunningaverage basestring currenttimemillis insertattempts insertsuccesses fetchsuccesses requestnumber interruptedexception datastring basestring requestnumber nextint number_of_nodes randomnode realnoderequestinserttest datastring requestnumber testkey clientkey insertkey clientkey fetchkey clientkeyblock datastring getbytes testkey datastring insertkey insertableclientssk testkey fetchkey testkey insertableclientssk insertkey arraybucket clientchkblock insertkey fetchkey getclientkey testkey insertkey testkey fetchkey getnodekey datastring getbytes realnoderequestinserttest memorydecode realnoderequestinserttest insertkey realnoderequestinserttest fetchkey insertattempts randomnode clientcore realput realnoderequestinserttest insertsuccesses lowlevelputexception putex realnoderequestinserttest putex putex exit_insert_failed nextint number_of_nodes fetchnode fetchnode clientcore realgetkey fetchkey percentsuccess fetchsuccesses insertattempts realnoderequestinserttest requestnumber percentsuccess requestsavg exit_request_failed memorydecode requestsavg fetchsuccesses percentsuccess fetchsuccesses insertattempts realnoderequestinserttest requestnumber percentsuccess requestnumber percentsuccess fetchsuccesses target_successes target_successes realnoderequestinserttest exit_bad_data stringbuilder stringbuilder uids totalrunninguids totalrunninguidsalt runninguidslist addrunninguids runninguidslist runninguids gettotalrunninguids runninguidsalt gettotalrunninguidsalt totalrunninguids runninguids totalrunninguidsalt runninguidsalt totalrunninguids totalrunninguidsalt tostring totalrunninguids uids totalrunninguids totalrunninguidsalt uids totalrunninguidsalt runninguidslist isempty uids tostring runninguidslist toarray realnoderequestinserttest public static void initialize node node snmp agent setsnmp port port if has been runned return 0 is toatl i o io statistic collector collector node collector for int i 0 i io statistic collector statistics entries i snmp agent getsnmp agent add fetcher new data statistics info i true collector snmp agent getsnmp agent add fetcher new data statistics info i false collector snmp agent getsnmp agent add fetcher new info system has been runned true snmpagent setsnmpport has_been_runned iostatisticcollector iostatisticcollector statistics_entries snmpagent getsnmpagent addfetcher datastatisticsinfo snmpagent getsnmpagent addfetcher datastatisticsinfo snmpagent getsnmpagent addfetcher infosystem has_been_runned public static void maybe create node node config config fixme any config needed for snmp starter maybecreate snmpstarter set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of chrome return the amount see set amount public float get amount return amount setamount getamount set the exppsure of the effect param exposure the exposure min value 0 max value 1 see get exposure public void set exposure float exposure this exposure exposure getexposure setexposure get the exppsure of the effect return the exposure see set exposure public float get exposure return exposure setexposure getexposure override public buffered image filter buffered image src buffered image dst set color source light filter colors constant dst super filter src dst transfer filter tf new transfer filter override protected float transfer function float v v amount float math sin v 2 math pi return 1 float math exp v exposure return tf filter dst dst bufferedimage bufferedimage bufferedimage setcolorsource lightfilter colors_constant transferfilter transferfilter transferfunction transfer filter tf new transfer filter override protected float transfer function float v v amount float math sin v 2 math pi return 1 float math exp v exposure transferfilter transferfilter transferfunction override public string to string return effects chrome tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public client put dir fcp connection handler handler client put dir message message hash map string object manifest elements boolean was disk put fcp server server object container container throws identifier collision exception malformedurl exception super message uri message identifier message verbosity handler message priority class message persistence type message client token message global message getchk only message dont compress message max retries message early encode server container logminor logger should log logger minor this this was disk put was disk put object on new is called once object on update is never called yet manifest elements get blanked anyway this manifest elements new hash map string object this manifest elements put all manifest elements this manifest elements manifest elements this manifest elements new hash map string object this manifest elements put all manifest elements this default name message default name make putter if putter null number of files putter count files total size putter total size else number of files 1 total size 1 if logminor logger minor this putting dir identifier priority class clientputdir fcpconnectionhandler clientputdirmessage hashmap manifestelements wasdiskput fcpserver objectcontainer identifiercollisionexception malformedurlexception priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode shouldlog wasdiskput wasdiskput objectonnew objectonupdate manifestelements manifestelements hashmap manifestelements putall manifestelements manifestelements manifestelements manifestelements hashmap manifestelements putall manifestelements defaultname defaultname makeputter numberoffiles countfiles totalsize totalsize numberoffiles totalsize priorityclass puts a disk dir throws insert exception public client put dir fcp client client freeneturi uri string identifier int verbosity short priority class short persistence type string client token boolean getchk only boolean dont compress int max retries file dir string default name boolean allow unreadable files boolean global boolean early encode fcp server server object container container throws file not found exception identifier collision exception malformedurl exception super uri identifier verbosity null client priority class persistence type client token global getchk only dont compress max retries early encode server container was disk put true logminor logger should log logger minor this this manifest elements make disk dir manifest dir allow unreadable files this default name default name make putter if putter null number of files putter count files total size putter total size else number of files 1 total size 1 if logminor logger minor this putting dir identifier priority class insertexception clientputdir fcpclient priorityclass persistencetype clienttoken getchkonly dontcompress maxretries defaultname allowunreadablefiles earlyencode fcpserver objectcontainer filenotfoundexception identifiercollisionexception malformedurlexception priorityclass persistencetype clienttoken getchkonly dontcompress maxretries earlyencode wasdiskput shouldlog manifestelements makediskdirmanifest allowunreadablefiles defaultname defaultname makeputter numberoffiles countfiles totalsize totalsize numberoffiles totalsize priorityclass override void register object container container boolean lazy resume boolean no tags throws identifier collision exception if persistence type persist connection client register this false container if persistence type persist connection no tags fcp message msg persistent tag message container client queue client request message msg 0 container objectcontainer lazyresume notags identifiercollisionexception persistencetype persist_connection persistencetype persist_connection notags fcpmessage persistenttagmessage queueclientrequestmessage private hash map string object make disk dir manifest file dir string prefix boolean allow unreadable files throws file not found exception hash map string object map new hash map string object file files dir list files if files null throw new illegal argument exception no such directory for file f files if f exists f can read if f is file file bucket bucket new file bucket f true false false false false if logminor logger minor this add file f get absolute path map put f get name new manifest element f get name prefix f get name bucket defaultmime types guessmime type f get name true f length else if f is directory if logminor logger minor this add dir f get absolute path map put f get name make disk dir manifest f prefix f get name allow unreadable files else if allow unreadable files throw new file not found exception not a file and not a directory f else if allow unreadable files throw new file not found exception the file does not exist or is unreadable f return map hashmap makediskdirmanifest allowunreadablefiles filenotfoundexception hashmap hashmap listfiles illegalargumentexception canread isfile filebucket filebucket getabsolutepath getname manifestelement getname getname defaultmimetypes guessmimetype getname isdirectory getabsolutepath getname makediskdirmanifest getname allowunreadablefiles allowunreadablefiles filenotfoundexception allowunreadablefiles filenotfoundexception private void make putter simple manifest putter p p new simple manifest putter this manifest elements priority class uri default name ctx getchk only low level client early encode putter p makeputter simplemanifestputter simplemanifestputter manifestelements priorityclass defaultname getchkonly lowlevelclient earlyencode public client put dir simple field set fs fcp client client fcp server server object container container throws persistence parse exception io exception super fs client server logminor logger should log logger minor this simple field set files fs subset files default name fs get default name string type fs get put dir type if type equals disk was disk put true else was disk put false flattened for disk sort out afterwards int file count 0 long size 0 vector manifest element v new vector manifest element for int i 0 i string num integer to string i simple field set subset files subset num if subset null break otherwise serialize string name subset get name if name null throw new persistence parse exception no name on i string content type override subset get metadata content type string upload from subset get upload from bucket data null if logminor logger minor this parsing i if logminor logger minor this upload from upload from manifest element me if upload from null upload from equals ignore case direct long sz long parse long subset get data length if finished try data serializable to field set bucket util create fs subset return bucket server core random server core persistent temp bucket factory catch cannot create from field set exception e throw new persistence parse exception could not read old bucket for identifier e e else data null me new manifest element name data content type override sz file count else if upload from equals ignore case disk long sz long parse long subset get data length disk string f subset get filename if f null throw new persistence parse exception upload from disk but no name on i file ff new file f if ff exists ff can read logger error this file no longer exists cancelling upload ff throw new io exception file no longer exists cancelling upload ff data new file bucket ff true false false false false me new manifest element name data content type override sz file count else if upload from equals ignore case redirect freeneturi targeturi new freeneturi subset get targeturi me new manifest element name targeturi content type override else throw new persistence parse exception don t know upload from upload from v add me if data null data size 0 size data size manifest elements simple manifest putter unflatten v simple manifest putter p null if finished p new simple manifest putter this manifest elements priority class uri default name ctx getchk only low level client early encode putter p number of files file count total size size if persistence type persist connection fcp message msg persistent tag message container client queue client request message msg 0 container clientputdir simplefieldset fcpclient fcpserver objectcontainer persistenceparseexception ioexception shouldlog simplefieldset defaultname defaultname putdirtype wasdiskput wasdiskput filecount manifestelement manifestelement tostring simplefieldset persistenceparseexception contenttypeoverride contenttype uploadfrom uploadfrom uploadfrom uploadfrom manifestelement uploadfrom uploadfrom equalsignorecase parselong datalength serializabletofieldsetbucketutil returnbucket persistenttempbucketfactory cannotcreatefromfieldsetexception persistenceparseexception manifestelement contenttypeoverride filecount uploadfrom equalsignorecase parselong datalength persistenceparseexception uploadfrom canread ioexception filebucket manifestelement contenttypeoverride filecount uploadfrom equalsignorecase manifestelement contenttypeoverride persistenceparseexception uploadfrom uploadfrom manifestelements simplemanifestputter simplemanifestputter simplemanifestputter manifestelements priorityclass defaultname getchkonly lowlevelclient earlyencode numberoffiles filecount totalsize persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage override public void start object container container client context context if finished return if started return try if putter null putter start container context started true if logminor logger minor this started putter for this persistence persistence type if persistence type persist connection finished fcp message msg persistent tag message container client queue client request message msg 0 container if persistence type persist forever container store this update catch insert exception e started true on failure e null container objectcontainer clientcontext persistencetype persistencetype persist_connection fcpmessage persistenttagmessage queueclientrequestmessage persistencetype persist_forever insertexception onfailure override public void on lost connection object container container client context context if persistence type persist connection cancel container context otherwise ignore onlostconnection objectcontainer clientcontext persistencetype persist_connection override suppress warnings unchecked protected void free data object container container if logminor logger minor this free data on this persistence type persistence type synchronized this if manifest elements null if logminor logger minor this manifest elements manifest elements persistence type persist forever dir active container ext is active this new exception error return if logminor logger minor this free data more on this persistence type persistence type we have to commit everything so activating everything here doesn t cost us much memory if persistence type persist forever container deactivate manifest elements 1 must deactivate before activating if it has been activated to depth 1 empty map at some point it will fail to activate to depth 2 with contents see http tracker db4o com browse cor 1582 container activate manifest elements integer max value free data manifest elements container manifest elements null if persistence type persist forever container store this suppresswarnings freedata objectcontainer freedata persistencetype manifestelements manifestelements manifestelements persistencetype persist_forever isactive freedata persistencetype persistencetype persist_forever manifestelements manifestelements max_value freedata manifestelements manifestelements persistencetype persist_forever suppress warnings unchecked private void free data hash map string object manifest elements object container container if logminor logger minor this free data inner on this persistence type persistence type size manifest elements size iterator i manifest elements values iterator while i has next object o i next if o instanceof hash map free data hash map string object o container else manifest element e manifest element o if logminor logger minor this freeing e e free data container persistence type persist forever if persistence type persist forever container delete manifest elements suppresswarnings freedata hashmap manifestelements objectcontainer freedata persistencetype manifestelements manifestelements hasnext hashmap freedata hashmap manifestelement manifestelement freedata persistencetype persist_forever persistencetype persist_forever manifestelements override protected client requester get client request return putter clientrequester getclientrequest override public simple field set get field set simple field set fs super get field set translate manifest elements directly into a fieldset simple field set files new simple field set false flatten the hierarchy it can be reconstructed on restarting storing it directly would be a pita manifest element elements simple manifest putter flatten manifest elements fs put single default name default name fs put single put dir type was disk put disk complex for int i 0 i elements length i string num integer to string i manifest element e elements i string name e get name string mime override e get mime type override simple field set subset new simple field set false subset put single name name if mime override null subset put single metadata content type mime override freeneturi target e get targeturi if target null subset put single upload from redirect subset put single targeturi target to string else bucket data e get data what to do with the bucket it is either a persistent encrypted bucket or a file bucket subset put single data length long to string e get size if data instanceof file bucket subset put single upload from disk subset put single filename file bucket data get file get path else if finished subset put single upload from direct else if data instanceof padded ephemerally encrypted bucket subset put single upload from direct the bucket is a persistent encrypted temp bucket bucket tofs fs temp bucket false data else throw new illegal state exception don t know what to do with bucket data files put num subset fs put files files return fs simplefieldset getfieldset simplefieldset getfieldset manifestelements simplefieldset simplefieldset manifestelement simplemanifestputter manifestelements putsingle defaultname defaultname putsingle putdirtype wasdiskput tostring manifestelement getname mimeoverride getmimetypeoverride simplefieldset simplefieldset putsingle mimeoverride putsingle contenttype mimeoverride gettargeturi putsingle uploadfrom putsingle tostring getdata putsingle datalength tostring getsize filebucket putsingle uploadfrom putsingle filebucket getfile getpath putsingle uploadfrom paddedephemerallyencryptedbucket putsingle uploadfrom buckettofs tempbucket illegalstateexception override protected fcp message persistent tag message object container container if persistence type persist forever container activate publicuri 5 container activate ctx 1 container activate manifest elements 5 return new persistent put dir identifier publicuri verbosity priority class persistence type global default name manifest elements client token started ctx max insert retries was disk put container fcpmessage persistenttagmessage objectcontainer persistencetype persist_forever manifestelements persistentputdir priorityclass persistencetype defaultname manifestelements clienttoken maxinsertretries wasdiskput override protected string get type name return putdir gettypename override public boolean has succeeded return succeeded hassucceeded public freeneturi get finaluri object container container if persistence type persist forever container activate generateduri 5 return generateduri getfinaluri objectcontainer persistencetype persist_forever public int get number of files return number of files getnumberoffiles numberoffiles public long get total data size return total size gettotaldatasize totalsize override public boolean can restart if finished logger minor this cannot restart because not finished for identifier return false if succeeded logger minor this cannot restart because succeeded for identifier return false return true canrestart override public boolean restart object container container client context context if can restart return false set vars restart container make putter start container context return true objectcontainer clientcontext canrestart setvarsrestart makeputter public void on failure fetch exception e client getter state object container container onfailure fetchexception clientgetter objectcontainer public void on failure fetch exception e client getter state object container container public void on success fetch result result client getter state object container container onfailure fetchexception clientgetter objectcontainer onsuccess fetchresult clientgetter objectcontainer public void on success fetch result result client getter state object container container override public void on success base client putter state object container container super on success state container onsuccess fetchresult clientgetter objectcontainer onsuccess baseclientputter objectcontainer onsuccess override public void on failure insert exception e base client putter state object container container super on failure e state container onfailure insertexception baseclientputter objectcontainer onfailure public void on remove event producer object container container do nothing we called the remove from onremoveeventproducer objectcontainer removefrom override public void request was removed object container container client context context if persistence type persist forever container activate putter 1 putter remove from container context putter null super request was removed container context requestwasremoved objectcontainer clientcontext persistencetype persist_forever removefrom requestwasremoved public class soft hash table extends weak hash table public soft hash table int initial capacity super initial capacity softhashtable weakhashtable softhashtable initialcapacity initialcapacity protected reference create reference object obj return new soft reference obj createreference softreference get the value of a property for this algorithm public static string get property string key return properties get property key getproperty getproperty get the value of a property for this algorithm or return i value i if the property was not set public static string get property string key string value return properties get property key value getproperty getproperty list algorithm properties to the print stream i out i public static void list print stream out list new print writer out true printstream printstream printwriter list algorithm properties to the print writer i out i public static void list print writer out out println out println begin algorithm properties out println string key value enumeration enu properties property names while enu has more elements key string enu next element value get property key out println key value out println out println end algorithm properties printwriter printwriter propertynames hasmoreelements nextelement getproperty public synchronized void load input stream in throws io exception public static enumeration property names return properties property names inputstream ioexception propertynames propertynames return true if tracing is requested for a given class p user indicates this by setting the tracing code boolean code property for i label i in the code algorithm properties code file the property s key is code trace i label i code p param label the name of a class return true iff a boolean true value is set for a property with the key code trace i label i code static boolean is traceable string label string s get property trace label if s null return false return boolean value of s boolean value istraceable getproperty valueof booleanvalue return the debug level for a given class p user indicates this by setting the numeric property with key code debug level i label i code p if this property is not set code debug level code is looked up next if neither property is set or if the first property found is not a valid decimal integer then this method returns 0 param label the name of a class return the required debugging level for the designated class static int get level string label string s get property debug level label if s null s get property debug level if s null return 0 try return integer parse int s catch number format exception e return 0 getlevel getproperty getproperty parseint numberformatexception return the print writer to which tracing and debugging output is to be sent p user indicates this by setting the property with key code output code to the literal code out code or code err code p by default or if the set value is not allowed code system err code will be used static print writer get output print writer pw string name get property output if name null name equals out pw new print writer system out true else pw new print writer system err true return pw printwriter printwriter getoutput printwriter getproperty printwriter printwriter private int mask public mask filter this 0xff00ffff maskfilter public mask filter int mask can filter index color model true set mask mask maskfilter canfilterindexcolormodel setmask public void set mask int mask this mask mask setmask public int get mask return mask getmask override public int filterrgb int x int y int rgb return rgb mask override public string to string return mask tostring public final compressor type codec public started compression event compressor type codec this codec codec compressor_type startedcompressionevent compressor_type final static int code 0x08 public string get description return started compression attempt with codec name getdescription public int get code return code getcode public class string option extends option string public string option sub config conf string option name string default value int sort order boolean expert boolean force write string short desc string long desc string callback cb super conf option name cb sort order expert force write short desc long desc option data type string this default value default value this current value default value stringoption stringoption subconfig optionname defaultvalue sortorder forcewrite shortdesc longdesc stringcallback optionname sortorder forcewrite shortdesc longdesc datatype defaultvalue defaultvalue currentvalue defaultvalue override protected string parse string string val throws invalid config value exception return val parsestring invalidconfigvalueexception override protected string to string string val return val tostring public void write long page addr byte buf try long page offs 0 int page size buf length if page addr 0 assert that page size page page size assert that page addr page page size 1 0 long page pos page map get page addr boolean first update false if page pos 0 int bp int page addr page page size log 3 if bp 8 page index size byte pos buf new byte 8 page index buffer position bp page index buffer get pos buf 0 8 page pos bytes unpack8 pos buf 0 first update true page size int page pos page page size 1 1 deflater reset deflater set input buf 0 buf length deflater finish int new page size deflater deflate compression buf if new page size page page size system arraycopy buf 0 compression buf 0 new page size buf compression buf int new page bit size new page size allocation quantum 1 allocation quantum log int old page bit size page size allocation quantum 1 allocation quantum log if first update new page bit size old page bit size if first update bitmap free bitmap page pos page page size log allocation quantum log old page bit size page offs allocate new page bit size else page offs page pos page page size log page size new page size page map put page addr page offs page page size log page size 1 page pos crypt buf page size data file seek page offs data file write buf 0 page size catch io exception x throw new storage error storage error file access error x pageaddr pageoffs pagesize pageaddr pagesize pagesize pageaddr pagesize pagepos pagemap pageaddr firstupdate pagepos pageaddr pagesizelog pageindexsize posbuf pageindexbuffer pageindexbuffer posbuf pagepos posbuf firstupdate pagesize pagepos pagesize setinput newpagesize compressionbuf newpagesize pagesize compressionbuf newpagesize compressionbuf newpagebitsize newpagesize allocation_quantum allocation_quantum_log oldpagebitsize pagesize allocation_quantum allocation_quantum_log firstupdate newpagebitsize oldpagebitsize firstupdate pagepos pagesizelog allocation_quantum_log oldpagebitsize pageoffs newpagebitsize pageoffs pagepos pagesizelog pagesize newpagesize pagemap pageaddr pageoffs pagesizelog pagesize pagepos pagesize datafile pageoffs datafile pagesize ioexception storageerror storageerror file_access_error public int read long page addr byte buf try if page addr 0 assert that page addr page page size 1 0 long page pos 0 if page map null page pos page map get page addr if page pos 0 int bp int page addr page page size log 3 if bp 8 page index size byte pos buf new byte 8 page index buffer position bp page index buffer get pos buf 0 8 page pos bytes unpack8 pos buf 0 if page pos 0 system out println page pos 0 for address page addr return 0 data file seek page pos page page size log int size int page pos page page size 1 1 system out println read size bytes from page pos page page size log int rc data file read compression buf 0 size if rc size throw new storage error storage error file access error crypt compression buf size if size page page size inflater reset inflater set input compression buf 0 size rc inflater inflate buf assert that rc page page size else system arraycopy compression buf 0 buf 0 rc return rc else data file seek 0 return data file read buf 0 buf length catch exception x throw new storage error storage error file access error x pageaddr pageaddr pageaddr pagesize pagepos pagemap pagepos pagemap pageaddr pagepos pageaddr pagesizelog pageindexsize posbuf pageindexbuffer pageindexbuffer posbuf pagepos posbuf pagepos pagepos pageaddr datafile pagepos pagesizelog pagepos pagesize pagepos pagesizelog datafile compressionbuf storageerror storageerror file_access_error compressionbuf pagesize setinput compressionbuf pagesize compressionbuf datafile datafile storageerror storageerror file_access_error public void sync try flush data to the main database file if no flush data file getfd sync int tx size page map size if tx size 0 return make sure that new page mapping is saved in transaction log byte buf new byte 4 16 tx size bytes pack4 buf 0 tx size int pos 4 for page map entry e page map bytes pack8 buf pos e addr bytes pack8 buf pos 8 e new pos pos 16 page index log file write buf 0 pos if no flush page index log file getfd sync store new page mapping in the page index file for page map entry e page map set position e addr bytes pack8 buf 0 e new pos page index buffer put buf 0 8 if e old pos 0 bitmap free bitmap e old pos page page size log allocation quantum log e old pos page page size 1 allocation quantum allocation quantum log page map clear truncate log if necessary if page index log file length page index checkpoint threshold page index buffer force page index log file set length 0 catch io exception x throw new storage error storage error file access error x noflush datafile txsize pagemap txsize txsize txsize pagemap pagemap newpos pageindexlogfile noflush pageindexlogfile pagemap pagemap setposition newpos pageindexbuffer oldpos oldpos pagesizelog allocation_quantum_log oldpos pagesize allocation_quantum allocation_quantum_log pagemap pageindexlogfile pageindexcheckpointthreshold pageindexbuffer pageindexlogfile setlength ioexception storageerror storageerror file_access_error public boolean try lock boolean shared try lck data chan try lock 0 long max value shared return lck null catch io exception x return true trylock datachan trylock max_value ioexception public void lock boolean shared try lck data chan lock 0 long max value shared catch io exception x throw new storage error storage error lock failed x datachan max_value ioexception storageerror storageerror lock_failed public void unlock try lck release catch io exception x throw new storage error storage error lock failed x ioexception storageerror storageerror lock_failed public void close try data chan close data file close if page index log file null assert that page map size 0 page index buffer force page index log file set length 0 page index log file close page index chan close page index file close catch io exception x throw new storage error storage error file access error x datachan datafile pageindexlogfile pagemap pageindexbuffer pageindexlogfile setlength pageindexlogfile pageindexchan pageindexfile ioexception storageerror storageerror file_access_error public long length try return data chan size catch io exception x return 1 datachan ioexception constructor of compressed file with default parameter values param data file path path to the data file public compressed read write file string data file path this data file path null datafilepath compressedreadwritefile datafilepath datafilepath constructor of compressed file with default parameter values param data file path path to the data file param cipher key cipher key if null then no encryption is performed public compressed read write file string data file path string cipher key this data file path data file path map data file path log 8 1024 1024 1024 1024 1024 1024 false false cipher key datafilepath cipherkey compressedreadwritefile datafilepath cipherkey datafilepath datafilepath datafilepath cipherkey constructor of compressed file param data file path path to the data file param page index file path path to the page index file param page index log file path path to the transaction log file for page index param data file extension quantum quantum of extending data file param page index checkpoint threshold maximal size of page index log file after reaching this size page index is flushed and log is truncsated param page index init size initial size of page index param read only whether access to the file is read only param no flush whether synchronous write to the disk should be performed param cipher key cipher key if null then no encryption is performed public compressed read write file string data file path string page index file path string page index log file path long data file extension quantum long page index checkpoint threshold long page index init size boolean read only boolean no flush string cipher key this page index checkpoint threshold page index checkpoint threshold this no flush no flush if cipher key null set key cipher key get bytes try data file new random access file data file path read only r rw data chan data file get channel page index file new random access file page index file path read only r rw page index chan page index file get channel long size page index chan size page index size read only size page index init size size page index init size page index buffer page index chan map read only file channel map mode read only file channel map mode read write 0 position page index size deflater new deflater inflater new inflater compression buf new byte page page size if read only long page map size page index init size 8 if page map size max page map size page map size max page map size page map new page map int page map size page index log file new random access file page index log file path rw perform recovery bitmap extension quantum int data file extension quantum allocation quantum log 3 bitmap new byte int data chan size allocation quantum log 3 bitmap extension quantum bitmap pos bitmap start page page size allocation quantum log 3 byte buf new byte 8 size page index chan size page index buffer position 0 while size 8 0 page index buffer get buf 0 8 long page pos bytes unpack8 buf 0 long page bit offs page pos page page size log allocation quantum log long page bit size page pos page page size 1 allocation quantum allocation quantum log bitmap reserve bitmap page bit offs page bit size catch io exception x throw new storage error storage error file access error x datafilepath pageindexfilepath pageindexlogfilepath datafileextensionquantum pageindexcheckpointthreshold pageindexinitsize readonly noflush cipherkey compressedreadwritefile datafilepath pageindexfilepath pageindexlogfilepath datafileextensionquantum pageindexcheckpointthreshold pageindexinitsize readonly noflush cipherkey pageindexcheckpointthreshold pageindexcheckpointthreshold noflush noflush cipherkey setkey cipherkey getbytes datafile randomaccessfile datafilepath readonly datachan datafile getchannel pageindexfile randomaccessfile pageindexfilepath readonly pageindexchan pageindexfile getchannel pageindexchan pageindexsize readonly pageindexinitsize pageindexinitsize pageindexbuffer pageindexchan readonly filechannel mapmode read_only filechannel mapmode read_write pageindexsize compressionbuf pagesize readonly pagemapsize pageindexinitsize pagemapsize max_page_map_size pagemapsize max_page_map_size pagemap pagemap pagemapsize pageindexlogfile randomaccessfile pageindexlogfilepath performrecovery bitmapextensionquantum datafileextensionquantum allocation_quantum_log datachan allocation_quantum_log bitmapextensionquantum bitmappos bitmapstart pagesize allocation_quantum_log pageindexchan pageindexbuffer pageindexbuffer pagepos pagebitoffs pagepos pagesizelog allocation_quantum_log pagebitsize pagepos pagesize allocation_quantum allocation_quantum_log pagebitoffs pagebitsize ioexception storageerror storageerror file_access_error long allocate int bit size long pos bitmap allocate bitmap bitmap pos bitmap length bit size if pos 0 pos bitmap allocate bitmap bitmap start bitmap locate hole end bitmap bitmap pos bit size if pos 0 byte new bitmap new byte bitmap length bitmap extension quantum system arraycopy bitmap 0 new bitmap 0 bitmap length pos bitmap allocate new bitmap bitmap locate bitmap end new bitmap bitmap length new bitmap length bit size assert that pos 0 bitmap new bitmap bitmap pos int pos bit size 3 return pos allocation quantum log bitsize bitmappos bitsize bitmapstart locateholeend bitmappos bitsize newbitmap bitmapextensionquantum newbitmap newbitmap locatebitmapend newbitmap newbitmap bitsize newbitmap bitmappos bitsize allocation_quantum_log void set position long addr throws io exception long pos addr page page size log 3 if pos 8 page index size do page index size 2 while pos 8 page index size page index buffer page index chan map file channel map mode read write 0 page index size page index buffer position int pos setposition ioexception pagesizelog pageindexsize pageindexsize pageindexsize pageindexbuffer pageindexchan filechannel mapmode read_write pageindexsize pageindexbuffer void perform recovery throws io exception int rc byte hdr new byte 4 while rc page index log file read hdr 0 4 4 int n pages bytes unpack4 hdr 0 byte buf new byte n pages 16 if page index log file read buf 0 buf length buf length for int i 0 i n pages i set position bytes unpack8 buf i 16 page index buffer put buf i 16 8 8 else break performrecovery ioexception pageindexlogfile npages npages pageindexlogfile npages setposition pageindexbuffer public page map int initial capacity for table size prime 0 prime numbers table size prime initial capacity table size prime table size prime numbers table size prime threshold int table size load factor table new entry table size pagemap initialcapacity tablesizeprime primenumbers tablesizeprime initialcapacity tablesizeprime tablesize primenumbers tablesizeprime tablesize load_factor tablesize public void put long addr long new pos long old pos entry tab table int index int addr page page size log table size for entry e tab index e null e e next if e addr addr e new pos new pos return if count threshold rehash the table if the threshold is exceeded rehash tab table index int addr page page size log table size creates the new entry tab index new entry addr new pos old pos tab index count 1 newpos oldpos pagesizelog tablesize newpos newpos pagesizelog tablesize newpos oldpos public long get long addr int index int addr page page size log table size for entry e table index e null e e next if e addr addr return e new pos return 0 pagesizelog tablesize newpos public void clear entry tab table int size table size for int i 0 i size i tab i null count 0 tablesize void rehash int old capacity table size int new capacity table size prime numbers table size prime entry old map table entry new map new entry new capacity threshold int new capacity load factor table new map table size new capacity for int i 0 i old capacity i for entry old old map i old null entry e old old old next int index int e addr page page size log new capacity e next new map index new map index e oldcapacity tablesize newcapacity tablesize primenumbers tablesizeprime oldmap newmap newcapacity newcapacity load_factor newmap tablesize newcapacity oldcapacity oldmap pagesizelog newcapacity newmap newmap public iterator entry iterator return new page map iterator pagemapiterator public int size return count class page map iterator implements iterator entry page map iterator move forward pagemapiterator pagemapiterator moveforward public boolean has next return curr null hasnext public entry next entry e curr if e null throw new no such element exception move forward return e nosuchelementexception moveforward public void remove throw new unsupported operation exception unsupportedoperationexception private void move forward if curr null curr curr next while curr null i table size curr table i moveforward tablesize entry long addr long new pos long old pos entry chain next chain this addr addr this new pos new pos this old pos old pos newpos oldpos newpos newpos oldpos oldpos private void set key byte key init state new byte 256 state new byte 256 for int counter 0 counter 256 counter init state counter byte counter int index1 0 int index2 0 for int counter 0 counter 256 counter index2 key index1 init state counter index2 0xff byte temp init state counter init state counter init state index2 init state index2 temp index1 index1 1 key length setkey initstate initstate initstate initstate initstate initstate initstate private final void crypt byte buf int len byte state this state if state null int x 0 y 0 system arraycopy init state 0 state 0 state length for int i 0 i len i x x 1 0xff y y state x 0xff byte temp state x state x state y state y temp int next state state x state y 0xff buf i state next state initstate nextstate nextstate param jmdns impl public record reaper jmdns impl jmdns impl this jmdns impl jmdns impl jmdnsimpl recordreaper jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl public void start timer timer timer schedule this dns constants record reaper interval dns constants record reaper interval dnsconstants record_reaper_interval dnsconstants record_reaper_interval public void run synchronized this jmdns impl if this jmdns impl get state dns state canceled return logger finest run jmdns reaping cache remove expired answers from the cache to prevent race conditions we defensively copy all cache entries into a list list list new array list synchronized this jmdns impl get cache for iterator i this jmdns impl get cache iterator i has next for dns cache cache node n dns cache cache node i next n null n n next list add n get value now we remove them long now system current time millis for iterator i list iterator i has next dns record c dns record i next if c is expired now this jmdns impl update record now c this jmdns impl get cache remove c jmdnsimpl jmdnsimpl getstate dnsstate arraylist jmdnsimpl getcache jmdnsimpl getcache hasnext dnscache cachenode dnscache cachenode getvalue currenttimemillis hasnext dnsrecord dnsrecord isexpired jmdnsimpl updaterecord jmdnsimpl getcache private int dw dh public displace filter displacefilter set the displacement map param displacement map an image representing the displacment at each point see get displacement map public void set displacement map buffered image displacement map this displacement map displacement map displacementmap getdisplacementmap setdisplacementmap bufferedimage displacementmap displacementmap displacementmap get the displacement map return an image representing the displacment at each point see set displacement map public buffered image get displacement map return displacement map setdisplacementmap bufferedimage getdisplacementmap displacementmap set the amount of distortion param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of distortion return the amount see set amount public float get amount return amount setamount getamount override public buffered image filter buffered image src buffered image dst int w src get width int h src get height buffered image dm displacement map null displacement map src dw dm get width dh dm get height int map pixels new int dw dh getrgb dm 0 0 dw dh map pixels xmap new int dw dh ymap new int dw dh int i 0 for int y 0 y dh y for int x 0 x dw x int rgb map pixels i int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff map pixels i r g b 8 an arbitrary scaling factor which gives a good range for amount i i 0 for int y 0 y dh y int j1 y dh 1 dh dw int j2 y dw int j3 y 1 dh dw for int x 0 x dw x int k1 x dw 1 dw int k2 x int k3 x 1 dw xmap i map pixels k1 j1 map pixels k1 j2 map pixels k1 j3 map pixels k3 j1 map pixels k3 j2 map pixels k3 j3 ymap i map pixels k1 j3 map pixels k2 j3 map pixels k3 j3 map pixels k1 j1 map pixels k2 j1 map pixels k3 j1 i map pixels null dst super filter src dst xmap ymap null return dst bufferedimage bufferedimage bufferedimage getwidth getheight bufferedimage displacementmap displacementmap getwidth getheight mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels mappixels override protected void transform inverse int x int y float out float x displacement y displacement float nx x float ny y int i y dh dw x dw out 0 x amount xmap i out 1 y amount ymap i transforminverse xdisplacement ydisplacement override public string to string return distort displace tostring public static fec queue create final long nodedb handle object container container suppress warnings serial object set fec queue result container query new predicate fec queue override public boolean match fec queue queue if queue nodedb handle nodedb handle return true return false if result has next fec queue queue result next container activate queue 1 return queue else fec queue queue new fec queue nodedb handle container store queue return queue fecqueue nodedbhandle objectcontainer suppresswarnings objectset fecqueue fecqueue fecqueue nodedbhandle nodedbhandle hasnext fecqueue fecqueue fecqueue nodedbhandle private fec queue long nodedb handle this nodedb handle nodedb handle fecqueue nodedbhandle nodedbhandle nodedbhandle called after creating or deserializing the fec queue initialises all the transient fields suppress warnings unchecked public void init int priorities int max cache size db job runner db job runner executor exec client context client context this priorities priorities this max persistent queue cache size max cache size this database job runner db job runner this executor exec this client context client context transient queue new linked list priorities persistent queue cache new linked list priorities for int i 0 i priorities i transient queue i new linked list fec job persistent queue cache i new linked list fec job max runningfec threads get max runningfec threads oom handler addoom hook this init runner init cache filler job queue cache filler fecqueue suppresswarnings maxcachesize dbjobrunner dbjobrunner clientcontext clientcontext maxpersistentqueuecachesize maxcachesize databasejobrunner dbjobrunner clientcontext clientcontext transientqueue linkedlist persistentqueuecache linkedlist transientqueue linkedlist fecjob persistentqueuecache linkedlist fecjob maxrunningfecthreads getmaxrunningfecthreads oomhandler addoomhook initrunner initcachefillerjob queuecachefiller private void queue cache filler database job runner queue cache filler job native thread norm priority false queuecachefiller databasejobrunner cachefillerjob nativethread norm_priority public void add to queue fec job job fec codec codec object container container boolean logminor logger should log logger minor this if logminor logger minor standard onionfec codec class adding a new job to the queue job int max threads get max runningfec threads if job persistent job activate for execution container container store job boolean kept false synchronized this if job persistent transient queue job priority add last job kept true else int total above 0 for int i 0 i job priority i total above persistent queue cache i size if total above max persistent queue cache size don t add if logminor logger minor this not adding persistent job to in ram cache too many above it else if total above persistent queue cache job priority size max persistent queue cache size still don t add within a priority it s oldest first if logminor logger minor this not adding persistent job to in ram cache too many at same priority else persistent queue cache job priority add last job kept true int total total above persistent queue cache job priority size for int i job priority 1 i priorities i total persistent queue cache i size while total max persistent queue cache size persistent queue cache i is empty if logminor logger minor this removing low priority job from cache total now total persistent queue cache i remove last total if kept if logminor logger minor this deactivating job job job deactivate container if runningfec threads max threads executor execute runner fec pool fec pool counter runningfec threads notify all addtoqueue fecjob feccodec objectcontainer shouldlog standardonionfeccodec maxthreads getmaxrunningfecthreads activateforexecution transientqueue addlast totalabove totalabove persistentqueuecache totalabove maxpersistentqueuecachesize totalabove persistentqueuecache maxpersistentqueuecachesize persistentqueuecache addlast totalabove persistentqueuecache persistentqueuecache maxpersistentqueuecachesize persistentqueuecache isempty persistentqueuecache removelast runningfecthreads maxthreads fecpoolcounter runningfecthreads notifyall private void init runner runner new prio runnable runs on each thread author nextgens public void run freenet support logger os thread logpid this try while true final fec job job get a job synchronized fec queue this job getfec job blocking nodb access job running true if logger should log logger minor this logger minor this running job job encode it try if job isa decoding job job get codec real decode job data block status job check block status job block length job bucket factory else job get codec real encode job data blocks job check blocks job block length job bucket factory update split file blocks from buckets if necessary if job data block status null job check block status null for int i 0 i job data blocks length i job data block status i set data job data blocks i for int i 0 i job check blocks length i job check block status i set data job check blocks i catch io exception e logger error this boh ioe e get message e call the callback try if job persistent if job isa decoding job job callback on decoded segment null client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment null client context job job data blocks job check blocks job data block status job check block status else if logger should log logger minor this logger minor this scheduling callback for job int prio job isa decoding job native thread norm priority 1 native thread norm priority if job priority request starter immediate splitfile priority class prio if job priority request starter bulk splitfile priority class prio database job runner queue new db job public void run object container container client context context job store block statuses container don t activate the job itself it must already be activated because it is carrying the status blocks the status blocks have been set on the fec thread but not stored because they can t be stored on the fec thread logger minor this activating job callback is active container ext is active job callback container activate job callback 1 if logger should log logger minor this logger minor this running callback for job try if job isa decoding job job callback on decoded segment container client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment container client context job job data blocks job check blocks job data block status job check block status catch throwable t logger error this caught t in fec queue callback t finally always delete the job even if the callback throws container delete job if container ext is stored job callback container deactivate job callback 1 prio false if logger should log logger minor this logger minor this scheduled callback for job catch throwable e logger error this the callback failed e e catch throwable t logger error this caught t in this t finally synchronized fec queue this runningfec threads public int get priority return native thread low priority initrunner priorunnable osthread fecjob fecqueue getfecjobblockingnodbaccess shouldlog isadecodingjob getcodec realdecode datablockstatus checkblockstatus blocklength bucketfactory getcodec realencode datablocks checkblocks blocklength bucketfactory splitfileblocks datablockstatus checkblockstatus datablocks datablockstatus setdata datablocks checkblocks checkblockstatus setdata checkblocks ioexception getmessage isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus shouldlog isadecodingjob nativethread norm_priority nativethread norm_priority requeststarter immediate_splitfile_priority_class requeststarter bulk_splitfile_priority_class databasejobrunner dbjob objectcontainer clientcontext storeblockstatuses isactive shouldlog isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus fecqueue isstored shouldlog fecqueue runningfecthreads getpriority nativethread low_priority runner new prio runnable runs on each thread author nextgens public void run freenet support logger os thread logpid this try while true final fec job job get a job synchronized fec queue this job getfec job blocking nodb access job running true if logger should log logger minor this logger minor this running job job encode it try if job isa decoding job job get codec real decode job data block status job check block status job block length job bucket factory else job get codec real encode job data blocks job check blocks job block length job bucket factory update split file blocks from buckets if necessary if job data block status null job check block status null for int i 0 i job data blocks length i job data block status i set data job data blocks i for int i 0 i job check blocks length i job check block status i set data job check blocks i catch io exception e logger error this boh ioe e get message e call the callback try if job persistent if job isa decoding job job callback on decoded segment null client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment null client context job job data blocks job check blocks job data block status job check block status else if logger should log logger minor this logger minor this scheduling callback for job int prio job isa decoding job native thread norm priority 1 native thread norm priority if job priority request starter immediate splitfile priority class prio if job priority request starter bulk splitfile priority class prio database job runner queue new db job public void run object container container client context context job store block statuses container don t activate the job itself it must already be activated because it is carrying the status blocks the status blocks have been set on the fec thread but not stored because they can t be stored on the fec thread logger minor this activating job callback is active container ext is active job callback container activate job callback 1 if logger should log logger minor this logger minor this running callback for job try if job isa decoding job job callback on decoded segment container client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment container client context job job data blocks job check blocks job data block status job check block status catch throwable t logger error this caught t in fec queue callback t finally always delete the job even if the callback throws container delete job if container ext is stored job callback container deactivate job callback 1 prio false if logger should log logger minor this logger minor this scheduled callback for job catch throwable e logger error this the callback failed e e catch throwable t logger error this caught t in this t finally synchronized fec queue this runningfec threads priorunnable osthread fecjob fecqueue getfecjobblockingnodbaccess shouldlog isadecodingjob getcodec realdecode datablockstatus checkblockstatus blocklength bucketfactory getcodec realencode datablocks checkblocks blocklength bucketfactory splitfileblocks datablockstatus checkblockstatus datablocks datablockstatus setdata datablocks checkblocks checkblockstatus setdata checkblocks ioexception getmessage isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus shouldlog isadecodingjob nativethread norm_priority nativethread norm_priority requeststarter immediate_splitfile_priority_class requeststarter bulk_splitfile_priority_class databasejobrunner dbjob objectcontainer clientcontext storeblockstatuses isactive shouldlog isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus fecqueue isstored shouldlog fecqueue runningfecthreads public void run object container container client context context job store block statuses container don t activate the job itself it must already be activated because it is carrying the status blocks the status blocks have been set on the fec thread but not stored because they can t be stored on the fec thread logger minor this activating job callback is active container ext is active job callback container activate job callback 1 if logger should log logger minor this logger minor this running callback for job try if job isa decoding job job callback on decoded segment container client context job job data blocks job check blocks job data block status job check block status else job callback on encoded segment container client context job job data blocks job check blocks job data block status job check block status catch throwable t logger error this caught t in fec queue callback t finally always delete the job even if the callback throws container delete job if container ext is stored job callback container deactivate job callback 1 objectcontainer clientcontext storeblockstatuses isactive shouldlog isadecodingjob ondecodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus onencodedsegment clientcontext datablocks checkblocks datablockstatus checkblockstatus fecqueue isstored public int get priority return native thread low priority getpriority nativethread low_priority private void init cache filler job cache filler job new db job public void run object container container client context context try to avoid accessing the database while synchronized on the fec queue boolean logminor logger should log logger minor this if logminor logger minor this running fec cache filler job while true boolean added any false int total cached 0 for short prio 0 prio priorities prio int grab 0 synchronized fec queue this int new cached total cached persistent queue cache prio size if new cached max persistent queue cache size return grab max persistent queue cache size new cached total cached new cached if logminor logger minor this grabbing up to grab jobs at priority prio query query container query query constrain fec job class constraint con query descend priority constrain short value of prio con and query descend queue constrain fec queue this identity query descend added time order ascending suppress warnings unchecked object set fec job results query execute if results has next for int j 0 j grab results has next j fec job job results next job activate for execution container if job is cancelled container container delete job continue if logminor logger minor this maybe adding job synchronized fec queue this if job running j if logminor logger minor this not adding already running job continue if persistent queue cache prio contains job j if logminor logger minor this not adding as on persistent queue cache for prio job continue boolean added false for list iterator fec job it persistent queue cache prio list iterator it has next fec job cmp it next if cmp added time job added time it previous it add job added true if logminor logger minor this adding job before it break if added persistent queue cache prio add last job if logminor logger minor this added job added any true if added any if logminor logger minor this no more jobs to add don t notify let it sleep until more jobs are added return else synchronized fec queue this int max running threads max runningfec threads if runningfec threads max running threads int queue size 0 for int i 0 i priorities i queue size persistent queue cache i size if queue size runningfec threads max running threads break if queue size runningfec threads max running threads max running threads queue size runningfec threads while runningfec threads max running threads executor execute runner fec pool fec pool counter runningfec threads fec queue this notify all initcachefillerjob cachefillerjob dbjob objectcontainer clientcontext fecqueue shouldlog addedany totalcached fecqueue newcached totalcached persistentqueuecache newcached maxpersistentqueuecachesize maxpersistentqueuecachesize newcached totalcached newcached fecjob valueof fecqueue addedtime orderascending suppresswarnings objectset fecjob hasnext hasnext fecjob activateforexecution iscancelled fecqueue persistentqueuecache listiterator fecjob persistentqueuecache listiterator hasnext fecjob addedtime addedtime persistentqueuecache addlast addedany addedany fecqueue maxrunningthreads maxrunningfecthreads runningfecthreads maxrunningthreads queuesize queuesize persistentqueuecache queuesize runningfecthreads maxrunningthreads queuesize runningfecthreads maxrunningthreads maxrunningthreads queuesize runningfecthreads runningfecthreads maxrunningthreads fecpoolcounter runningfecthreads fecqueue notifyall public void run object container container client context context try to avoid accessing the database while synchronized on the fec queue boolean logminor logger should log logger minor this if logminor logger minor this running fec cache filler job while true boolean added any false int total cached 0 for short prio 0 prio priorities prio int grab 0 synchronized fec queue this int new cached total cached persistent queue cache prio size if new cached max persistent queue cache size return grab max persistent queue cache size new cached total cached new cached if logminor logger minor this grabbing up to grab jobs at priority prio query query container query query constrain fec job class constraint con query descend priority constrain short value of prio con and query descend queue constrain fec queue this identity query descend added time order ascending suppress warnings unchecked object set fec job results query execute if results has next for int j 0 j grab results has next j fec job job results next job activate for execution container if job is cancelled container container delete job continue if logminor logger minor this maybe adding job synchronized fec queue this if job running j if logminor logger minor this not adding already running job continue if persistent queue cache prio contains job j if logminor logger minor this not adding as on persistent queue cache for prio job continue boolean added false for list iterator fec job it persistent queue cache prio list iterator it has next fec job cmp it next if cmp added time job added time it previous it add job added true if logminor logger minor this adding job before it break if added persistent queue cache prio add last job if logminor logger minor this added job added any true if added any if logminor logger minor this no more jobs to add don t notify let it sleep until more jobs are added return else synchronized fec queue this int max running threads max runningfec threads if runningfec threads max running threads int queue size 0 for int i 0 i priorities i queue size persistent queue cache i size if queue size runningfec threads max running threads break if queue size runningfec threads max running threads max running threads queue size runningfec threads while runningfec threads max running threads executor execute runner fec pool fec pool counter runningfec threads fec queue this notify all objectcontainer clientcontext fecqueue shouldlog addedany totalcached fecqueue newcached totalcached persistentqueuecache newcached maxpersistentqueuecachesize maxpersistentqueuecachesize newcached totalcached newcached fecjob valueof fecqueue addedtime orderascending suppresswarnings objectset fecjob hasnext hasnext fecjob activateforexecution iscancelled fecqueue persistentqueuecache listiterator fecjob persistentqueuecache listiterator hasnext fecjob addedtime addedtime persistentqueuecache addlast addedany addedany fecqueue maxrunningthreads maxrunningfecthreads runningfecthreads maxrunningthreads queuesize queuesize persistentqueuecache queuesize runningfecthreads maxrunningthreads queuesize runningfecthreads maxrunningthreads maxrunningthreads queuesize runningfecthreads runningfecthreads maxrunningthreads fecpoolcounter runningfecthreads fecqueue notifyall private synchronized int get max runningfec threads if max runningfec threads 1 return max runningfec threads string os name system get property os name if os name index of windows 1 os name to lower case index of mac os x 0 native thread using native code os x niceness is really weak so we don t want any more background cpu load than necessary also on non windows we need the native threads library to be working max runningfec threads 1 else most other o ss will have reasonable niceness so go by ram runtime r runtime get runtime int max r available processors fixme this may change in a vm poll it long max memory r max memory if max memory 256 1024 1024 max 1 else measured 11mb decode 8mb encode on amd64 no more than 10 of available ram so 110mb for each extra processor no more than 3 so that we don t reach any file descriptor related limit max math min 3 math min max int math min integer max value max memory 128 1024 1024 max runningfec threads max logger minor fec codec class maximum fec threads max runningfec threads return max runningfec threads getmaxrunningfecthreads maxrunningfecthreads maxrunningfecthreads osname getproperty osname indexof osname tolowercase indexof nativethread usingnativecode maxrunningfecthreads oss getruntime availableprocessors maxmemory maxmemory maxmemory filedescriptor max_value maxmemory maxrunningfecthreads feccodec maxrunningfecthreads maxrunningfecthreads find a fec job to run return null only if there are too many fec threads running protected synchronized fec job getfec job blocking nodb access while true if runningfec threads get max runningfec threads return null for int i 0 i priorities i if transient queue i is empty return transient queue i remove first if persistent queue cache i is empty return persistent queue cache i remove first queue cache filler try wait catch interrupted exception e ignore fecjob getfecjobblockingnodbaccess runningfecthreads getmaxrunningfecthreads transientqueue isempty transientqueue removefirst persistentqueuecache isempty persistentqueuecache removefirst queuecachefiller interruptedexception public synchronized void handle low memory throws exception max runningfec threads math max 1 max runningfec threads 1 notify not notify all handlelowmemory maxrunningfecthreads maxrunningfecthreads notifyall public synchronized void handle out of memory throws exception max runningfec threads 1 notify all handleoutofmemory maxrunningfecthreads notifyall public void object on deactivate object container container logger error this attempting to deactivate fec queue new exception debug objectondeactivate objectcontainer fecqueue param job param container param context return true unless we were unable to remove the job because it has already started public boolean cancel fec job job object container container client context context synchronized this for int i 0 i priorities i transient queue i remove job persistent queue cache i remove job synchronized job if job running return false if job persistent container delete job return true fecjob objectcontainer clientcontext transientqueue persistentqueuecache public temp bucket long now bucket cur if cur null throw new null pointer exception this current bucket cur this creation time now this os index 0 this tbis new vector temp bucket input stream 1 if logminor logger minor this created this new exception debug tempbucket nullpointerexception currentbucket creationtime osindex tempbucketinputstream private synchronized void close input streams boolean for free for list iterator temp bucket input stream i tbis list iterator i has next temp bucket input stream is i next if for free i remove try is close catch io exception e logger error this caught e closing is else try is mayberesetinputstream catch io exception e i remove closer close is closeinputstreams forfree listiterator tempbucketinputstream listiterator hasnext tempbucketinputstream forfree ioexception _mayberesetinputstream ioexception a blocking method to force migrate from a ram bucket to a file bucket final void migrate to file bucket throws io exception bucket to migrate null synchronized this if isram bucket has been freed nothing to migrate we don t want to switch back to ram do we return to migrate current bucket bucket tempfb makefilebucket if os null os flush closer close os do not increment the os index here os tempfb get output stream if current size 0 bucket tools copy to to migrate os current size else if current size 0 output stream temp tempfb get output stream bucket tools copy to to migrate temp current size temp close if to migrate is read only tempfb set read only close input streams false current bucket tempfb we need streams to be reset to point to the new bucket if logminor logger minor this we have migrated to migrate hash code we can free it on thread as it s a rambucket to migrate free might have changed already so we can t rely on current size hasfreed to migrate size rambucket filebucket migratetofilebucket ioexception tomigrate isrambucket hasbeenfreed tomigrate currentbucket _makefilebucket osindex getoutputstream currentsize buckettools copyto tomigrate currentsize currentsize outputstream getoutputstream buckettools copyto tomigrate currentsize tomigrate isreadonly setreadonly closeinputstreams currentbucket tomigrate hashcode tomigrate currentsize _hasfreed tomigrate public synchronized final boolean isram bucket return current bucket instanceof array bucket isrambucket currentbucket arraybucket public synchronized output stream get output stream throws io exception if os index 0 throw new io exception only one output stream per bucket has written true output stream os new temp bucket output stream os index if logminor logger minor this got os for this new exception return os outputstream getoutputstream ioexception osindex ioexception outputstream haswritten outputstream tempbucketoutputstream osindex private class temp bucket output stream extends output stream boolean closed false temp bucket output stream short idx throws io exception if os null os current bucket get output stream tempbucketoutputstream outputstream tempbucketoutputstream ioexception currentbucket getoutputstream private void maybemigraterambucket long future size throws io exception if isram bucket boolean should migrate false boolean is oversized false if future size math min integer max value maxram bucket size rambucket conversion factor is oversized true should migrate true else if future size current size bytes in use max ram used should migrate true if should migrate if logminor if is oversized logger minor this the bucket is over size util format size maxram bucket size rambucket conversion factor we will force migrate it to disk else logger minor this the bucketpool is full force migrate before we go over the limit migrate to file bucket _maybemigraterambucket futuresize ioexception isrambucket shouldmigrate isoversized futuresize max_value maxrambucketsize rambucket_conversion_factor isoversized shouldmigrate futuresize currentsize bytesinuse maxramused shouldmigrate shouldmigrate isoversized sizeutil formatsize maxrambucketsize rambucket_conversion_factor migratetofilebucket override public final void write int b throws io exception synchronized temp bucket this long future size current size 1 maybemigraterambucket future size os write b current size future size if isram bucket we need to re check because it might have changed hastaken 1 ioexception tempbucket futuresize currentsize _maybemigraterambucket futuresize currentsize futuresize isrambucket _hastaken override public final void write byte b int off int len throws io exception synchronized temp bucket this long future size current size len maybemigraterambucket future size os write b off len current size future size if isram bucket we need to re check because it might have changed hastaken len ioexception tempbucket futuresize currentsize _maybemigraterambucket futuresize currentsize futuresize isrambucket _hastaken override public final void flush throws io exception synchronized temp bucket this maybemigraterambucket current size if closed os flush ioexception tempbucket _maybemigraterambucket currentsize override public final void close throws io exception synchronized temp bucket this if closed return maybemigraterambucket current size os flush os close os null closed true ioexception tempbucket _maybemigraterambucket currentsize public synchronized input stream get input stream throws io exception if has written throw new io exception no output stream has been openned why would you want an input stream then temp bucket input stream is new temp bucket input stream os index tbis add is if logminor logger minor this got is for this new exception return is inputstream getinputstream ioexception haswritten ioexception outputstream inputstream tempbucketinputstream tempbucketinputstream osindex private final short idx temp bucket input stream short idx throws io exception this idx idx this currentis current bucket get input stream tempbucketinputstream ioexception currentbucket getinputstream public void mayberesetinputstream throws io exception if idx os index close else closer close currentis currentis current bucket get input stream long to skip index while to skip 0 to skip currentis skip to skip _mayberesetinputstream ioexception osindex currentbucket getinputstream toskip toskip toskip toskip override public final int read throws io exception synchronized temp bucket this int to return currentis read if to return 1 index return to return ioexception tempbucket toreturn toreturn toreturn override public int read byte b throws io exception synchronized temp bucket this return read b 0 b length ioexception tempbucket override public int read byte b int off int len throws io exception synchronized temp bucket this int to return currentis read b off len if to return 0 index to return return to return ioexception tempbucket toreturn toreturn toreturn toreturn override public long skip long n throws io exception synchronized temp bucket this long skipped currentis skip n index skipped return skipped ioexception tempbucket override public int available throws io exception synchronized temp bucket this return currentis available ioexception tempbucket override public boolean mark supported return false marksupported override public final void close throws io exception synchronized temp bucket this closer close currentis tbis remove this ioexception tempbucket public synchronized string get name return current bucket get name getname currentbucket getname public synchronized long size return current size currentsize public synchronized boolean is read only return current bucket is read only isreadonly currentbucket isreadonly public synchronized void set read only current bucket set read only setreadonly currentbucket setreadonly public synchronized void free if has been freed return has been freed true closer close os close input streams true current bucket free if isram bucket hasfreed current size synchronized ram bucket queue ram bucket queue remove get reference hasbeenfreed hasbeenfreed closeinputstreams currentbucket isrambucket _hasfreed currentsize rambucketqueue rambucketqueue getreference public bucket create shadow throws io exception return current bucket create shadow createshadow ioexception currentbucket createshadow public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public void store to object container container throw new unsupported operation exception storeto objectcontainer unsupportedoperationexception private weak reference temp bucket weak ref new weak reference temp bucket this public weak reference temp bucket get reference return weak ref weakreference tempbucket weakref weakreference tempbucket weakreference tempbucket getreference weakref override protected void finalize if has been freed logger error this temp bucket not freed size size isram bucket isram bucket this free hasbeenfreed tempbucket isrambucket isrambucket storage accounting disabled by default public temp bucket factory executor executor filename generator filename generator long max bucket size kept in ram long max ram used random source strongprng random weakprng boolean really encrypt this filename generator filename generator this max ram used max ram used this maxram bucket size max bucket size kept in ram this strongprng strongprng this weakprng weakprng this really encrypt really encrypt this executor executor this logminor logger should log logger minor this tempbucketfactory filenamegenerator filenamegenerator maxbucketsizekeptinram maxramused randomsource reallyencrypt filenamegenerator filenamegenerator maxramused maxramused maxrambucketsize maxbucketsizekeptinram reallyencrypt reallyencrypt shouldlog public bucket make bucket long size throws io exception return make bucket size default factor default increment makebucket ioexception makebucket default_factor defaultincrement public bucket make bucket long size float factor throws io exception return make bucket size factor default increment makebucket ioexception makebucket defaultincrement private synchronized void hastaken long size bytes in use size _hastaken bytesinuse private synchronized void hasfreed long size bytes in use size _hasfreed bytesinuse public synchronized long get ram used return bytes in use getramused bytesinuse public synchronized void set max ram used long size logminor logger should log logger minor this max ram used size setmaxramused shouldlog maxramused public synchronized long get max ram used logminor logger should log logger minor this return max ram used getmaxramused shouldlog maxramused public synchronized void set maxram bucket size long size logminor logger should log logger minor this maxram bucket size size setmaxrambucketsize shouldlog maxrambucketsize public synchronized long get maxram bucket size logminor logger should log logger minor this return maxram bucket size getmaxrambucketsize shouldlog maxrambucketsize public void set encryption boolean value logminor logger should log logger minor this really encrypt value setencryption shouldlog reallyencrypt public boolean is encrypting return really encrypt isencrypting reallyencrypt create a temp bucket param size default size param factor factor to increase size by when need more space return a temporary bucket exception io exception if it is not possible to create a temp bucket due to an i o error public temp bucket make bucket long size float factor long increment throws io exception bucket real bucket null boolean useram bucket false long now system current time millis we need to clean the queue in order to have space to host new buckets clean bucket queue now synchronized this if size 0 size maxram bucket size bytes in use max ram used useram bucket true do we want a ram bucket or a file bucket real bucket useram bucket new array bucket makefilebucket temp bucket to return new temp bucket now real bucket if useram bucket no need to consider them for migration if they can t be migrated synchronized ram bucket queue ram bucket queue add to return get reference return to return ioexception tempbucket makebucket ioexception realbucket userambucket currenttimemillis cleanbucketqueue maxrambucketsize bytesinuse maxramused userambucket rambucket filebucket realbucket userambucket arraybucket _makefilebucket tempbucket toreturn tempbucket realbucket userambucket rambucketqueue rambucketqueue toreturn getreference toreturn migrate all long lived buckets from the queue private void clean bucket queue long now boolean should continue true create a new list to avoid race conditions final queue temp bucket to migrate new linked list temp bucket do synchronized ram bucket queue final weak reference temp bucket tmp bucket ref ram bucket queue peek if tmp bucket ref null should continue false else temp bucket tmp bucket tmp bucket ref get if tmp bucket null ram bucket queue remove tmp bucket ref continue ugh this is freed if tmp bucket creation time rambucket max age now should continue false else if logminor logger minor this the bucket is time util format time now tmp bucket creation time old we will force migrate it to disk ram bucket queue remove tmp bucket ref to migrate add tmp bucket while should continue if to migrate size 0 executor execute new runnable public void run if logminor logger minor this we are going to migrate to migrate size ram buckets for temp bucket tmp bucket to migrate try tmp bucket migrate to file bucket catch io exception e logger error tmp bucket an ioe occured while migrating long lived buckets e get message e ram bucket migrator now cleanbucketqueue shouldcontinue tempbucket tomigrate linkedlist tempbucket rambucketqueue weakreference tempbucket tmpbucketref rambucketqueue tmpbucketref shouldcontinue tempbucket tmpbucket tmpbucketref tmpbucket rambucketqueue tmpbucketref tmpbucket creationtime rambucket_max_age shouldcontinue timeutil formattime tmpbucket creationtime rambucketqueue tmpbucketref tomigrate tmpbucket shouldcontinue tomigrate tomigrate rambuckets tempbucket tmpbucket tomigrate tmpbucket migratetofilebucket ioexception tmpbucket getmessage rambucket public void run if logminor logger minor this we are going to migrate to migrate size ram buckets for temp bucket tmp bucket to migrate try tmp bucket migrate to file bucket catch io exception e logger error tmp bucket an ioe occured while migrating long lived buckets e get message e tomigrate rambuckets tempbucket tmpbucket tomigrate tmpbucket migratetofilebucket ioexception tmpbucket getmessage private bucket makefilebucket bucket file bucket new temp file bucket filename generator make random filename filename generator true true do we want it to be encrypted return really encrypt new padded ephemerally encrypted bucket file bucket 1024 strongprng weakprng file bucket _makefilebucket filebucket tempfilebucket filenamegenerator makerandomfilename filenamegenerator reallyencrypt paddedephemerallyencryptedbucket filebucket filebucket private static final long serial versionuid 1l get the contents of the error page public abstract string get explanation serialversionuid getexplanation public abstract string get explanation gets the contents of the error page as html public abstract html node gethtml explanation getexplanation htmlnode gethtmlexplanation public abstract html node gethtml explanation get the title of the error page public abstract string gethtml encoded title htmlnode gethtmlexplanation gethtmlencodedtitle public abstract string gethtml encoded title get the raw title of the error page may be unsafe for html public abstract string get raw title gethtmlencodedtitle getrawtitle final string identifier public unknown peer note type message int peer note type string identifier this peer note type peer note type this identifier identifier unknownpeernotetypemessage peernotetype peernotetype peernotetype override public simple field set get field set simple field set fs new simple field set true fs put peer note type peer note type if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset peernotetype peernotetype putsingle override public string get name return unknown peer note type getname unknownpeernotetype override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message unknown peer note type goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message unknownpeernotetype override public void remove from object container container container delete this removefrom objectcontainer public class persistent temp file bucket extends temp file bucket public persistent temp file bucket long id filename generator generator this id generator true persistenttempfilebucket tempfilebucket persistenttempfilebucket filenamegenerator protected persistent temp file bucket long id filename generator generator boolean delete on free super id generator false delete on free persistenttempfilebucket filenamegenerator deleteonfree deleteonfree override protected boolean delete on finalize do not delete on finalize return false deleteonfinalize override protected boolean delete on exit do not delete on exit return false deleteonexit public static bucket create simple field set fs persistent file tracker f throws cannot create from field set exception string tmp fs get filename if tmp null throw new cannot create from field set exception no filename file file file util get canonical file new file tmp long id f getid file if id 1 throw new cannot create from field set exception cannot derive persistent temp file id from filename file tmp fs get length if tmp null throw new cannot create from field set exception no length long length try length long parse long tmp if length file length throw new cannot create from field set exception invalid length should be length actually file length on file catch number format exception e throw new cannot create from field set exception corrupt length tmp e bucket bucket new persistent temp file bucket id f get generator true if file exists no point otherwise f register file return bucket simplefieldset persistentfiletracker cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception fileutil getcanonicalfile cannotcreatefromfieldsetexception cannotcreatefromfieldsetexception parselong cannotcreatefromfieldsetexception numberformatexception cannotcreatefromfieldsetexception persistenttempfilebucket getgenerator override public simple field set to field set if delete on finalize return null simple field set fs super to field set fs put overwrite type persistent temp file bucket fs put filenameid filenameid return fs simplefieldset tofieldset deleteonfinalize simplefieldset tofieldset putoverwrite persistenttempfilebucket must override create shadow so it creates a persistent bucket which will have delete on exit delete on finalize false override public bucket create shadow throws io exception persistent temp file bucket ret new persistent temp file bucket filenameid generator false ret set read only if get file exists logger error this file does not exist when creating shadow get file return ret createshadow deleteonexit deleteonfinalize createshadow ioexception persistenttempfilebucket persistenttempfilebucket setreadonly getfile getfile static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public limited range int byte array map int max range this max range max range contents new hash map integer limited range int byte array map element min value 1 max value 1 flag false limitedrangeintbytearraymap maxrange maxrange maxrange hashmap limitedrangeintbytearraymapelement minvalue maxvalue public synchronized int min value return min value minvalue minvalue public synchronized int max value return max value maxvalue maxvalue public synchronized byte get int index limited range int byte array map element wrapper contents get index if wrapper null return wrapper data else return null limitedrangeintbytearraymapelement public synchronized async message callback get callbacks int index limited range int byte array map element wrapper contents get index if wrapper null return wrapper callbacks else return null asyncmessagecallback getcallbacks limitedrangeintbytearraymapelement public synchronized long get time int index limited range int byte array map element wrapper contents get index if wrapper null return wrapper created time else return 1 gettime limitedrangeintbytearraymapelement createdtime public short get priority int index short default value integer i index limited range int byte array map element wrapper contents get i if wrapper null return wrapper priority else return default value getpriority defaultvalue limitedrangeintbytearraymapelement defaultvalue get the time at which an index was re added last public synchronized long get readded time int index limited range int byte array map element wrapper contents get index if wrapper null return wrapper reput time else return 1 getreaddedtime limitedrangeintbytearraymapelement reputtime try to add an index data mapping return true if we succeeded false if the index was out of range public synchronized boolean add int index byte data async message callback callbacks short priority if logminor logger minor this to string add index if max value 1 min value index max value index if index max value if index min value max range return false max value index if index min value if max value index max range return false min value index if data null throw new null pointer exception integer idx index limited range int byte array map element le contents get idx if le null contents put idx new limited range int byte array map element idx data callbacks priority else le reput notify all return true asyncmessagecallback tostring maxvalue minvalue maxvalue maxvalue minvalue maxrange maxvalue minvalue maxvalue maxrange minvalue nullpointerexception limitedrangeintbytearraymapelement limitedrangeintbytearraymapelement notifyall toggle the flag and notify all waiting lock s they will then throw interrupted exception s public synchronized void interrupt flag flag notify all interruptedexception notifyall wait until add index whatever would return true if this returns add index whatever will work if it throws it probably won t public synchronized void lock int index throws interrupted exception boolean old flag flag if min value 1 return if index min value max range return if logminor logger minor this to string lock index min value min value max value max value max range max range while true wait if flag old flag if logminor logger minor this interrupted throw new interrupted exception if index min value max range min value 1 if logminor logger minor this index index min value min value max range max range returning return interruptedexception oldflag minvalue minvalue maxrange tostring minvalue minvalue maxvalue maxvalue maxrange maxrange oldflag interruptedexception minvalue maxrange minvalue minvalue minvalue maxrange maxrange public boolean would block int index if min value 1 return false return index min value max range wouldblock minvalue minvalue maxrange wait until add index whatever would return true if this returns add index whatever will work if it throws it probably won t public synchronized void lock never block int index throws would block exception if min value 1 return if index min value max range return throw new would block exception to string would block lock never block index min value min value max value max value max range max range lockneverblock wouldblockexception minvalue minvalue maxrange wouldblockexception tostring lockneverblock minvalue minvalue maxvalue maxvalue maxrange maxrange return true if we removed something public synchronized boolean remove int index if logminor logger minor this removing index min min value max max value if contents remove index null if index min value index max value return true if contents size 0 min value max value 1 notify all return true if index max value for int i max value i min value i integer ii integer value of i if contents contains key ii max value i notify all return true still here wtf notify all throw new illegal state exception still here a if index min value for int i min value i max value i integer ii integer value of i if contents contains key ii min value i notify all return true still here wtf notify all throw new illegal state exception still here b notify all throw new illegal state exception impossible return false minvalue maxvalue minvalue maxvalue minvalue maxvalue notifyall maxvalue maxvalue minvalue valueof containskey maxvalue notifyall notifyall illegalstateexception minvalue minvalue maxvalue valueof containskey minvalue notifyall notifyall illegalstateexception notifyall illegalstateexception return the contents of each packet sent then clear public synchronized byte grab all bytes int len contents size byte output new byte len int count 0 for limited range int byte array map element o contents values output count o data clear return output graballbytes limitedrangeintbytearraymapelement public synchronized limited range int byte array map element grab all int len contents size limited range int byte array map element output new limited range int byte array map element len iterator limited range int byte array map element i contents values iterator int count 0 while i has next output count i next clear return output limitedrangeintbytearraymapelement graball limitedrangeintbytearraymapelement limitedrangeintbytearraymapelement limitedrangeintbytearraymapelement hasnext empty the structure private synchronized void clear contents clear min value max value 1 minvalue maxvalue public clock problem detected user alert super false null null null null user alert critical error true null false null clockproblemdetecteduseralert useralert critical_error override public string get title return l10n title gettitle private string l10n string key return l10n get string clock problem detected user alert key getstring clockproblemdetecteduseralert override public string get text return l10n text gettext override public string get short text return l10n short text getshorttext shorttext override public html node gethtml text return new html node div get text htmlnode gethtmltext htmlnode gettext override public boolean user can dismiss return false usercandismiss public insert context bucket factory bf bucket factory persistentbf persistent file tracker tracker int max retries int rnfs to success int max threads int splitfile segment data blocks int splitfile segment check blocks client event producer event producer boolean cache local requests this persistent file tracker tracker this persistent bucket factory persistentbf dont compress false splitfile algorithm metadata splitfile onion standard this consecutivern fs count as success rnfs to success this max insert retries max retries this max split insert threads max threads this event producer event producer this splitfile segment data blocks splitfile segment data blocks this splitfile segment check blocks splitfile segment check blocks this cache local requests cache local requests insertcontext bucketfactory bucketfactory persistentfiletracker maxretries rnfstosuccess maxthreads splitfilesegmentdatablocks splitfilesegmentcheckblocks clienteventproducer eventproducer cachelocalrequests persistentfiletracker persistentbucketfactory dontcompress splitfilealgorithm splitfile_onion_standard consecutivernfscountassuccess rnfstosuccess maxinsertretries maxretries maxsplitinsertthreads maxthreads eventproducer eventproducer splitfilesegmentdatablocks splitfilesegmentdatablocks splitfilesegmentcheckblocks splitfilesegmentcheckblocks cachelocalrequests cachelocalrequests public insert context insert context ctx simple event producer producer this persistent file tracker ctx persistent file tracker this persistent bucket factory ctx persistent bucket factory this dont compress ctx dont compress this splitfile algorithm ctx splitfile algorithm this consecutivern fs count as success ctx consecutivern fs count as success this max insert retries ctx max insert retries this max split insert threads ctx max split insert threads this event producer producer this splitfile segment data blocks ctx splitfile segment data blocks this splitfile segment check blocks ctx splitfile segment check blocks this cache local requests ctx cache local requests insertcontext insertcontext simpleeventproducer persistentfiletracker persistentfiletracker persistentbucketfactory persistentbucketfactory dontcompress dontcompress splitfilealgorithm splitfilealgorithm consecutivernfscountassuccess consecutivernfscountassuccess maxinsertretries maxinsertretries maxsplitinsertthreads maxsplitinsertthreads eventproducer splitfilesegmentdatablocks splitfilesegmentdatablocks splitfilesegmentcheckblocks splitfilesegmentcheckblocks cachelocalrequests cachelocalrequests public void remove from object container container if event producer null logger error this no event producer on insert context activated container ext is active this stored container ext is stored this new exception error else container activate event producer 1 event producer remove from container container delete this removefrom objectcontainer eventproducer eventproducer insertcontext isactive isstored eventproducer eventproducer removefrom override public string get logger hook chain chain logger get chain return logger hook priority of chain get threshold loggerhookchain getchain loggerhook priorityof getthreshold override public void set string val throws invalid config value exception logger hook chain chain logger get chain try chain set threshold val catch logger hook invalid threshold exception e throw new option format exception e get message invalidconfigvalueexception loggerhookchain getchain setthreshold loggerhook invalidthresholdexception optionformatexception getmessage public string get possible values return possible values getpossiblevalues possiblevalues public logging config handler sub config logging config executor executor throws invalid config value exception this config logging config this executor executor logging config register enabled true 1 true false log config handler enabled log config handler enabled long new boolean callback override public boolean get return file logger hook null override public void set boolean val throws invalid config value exception if val file logger hook null return if val disable logger else enable logger boolean logging enabled logging config get boolean enabled logging config register dirname logs 2 true false log config handler dir name log config handler dir name long new string callback override public string get return log dir get path override public void set string val throws invalid config value exception file f new file val if f equals log dir return pre set log dir f still here if file logger hook null log dir f else discard old data file logger hook switch base filename f get path file separator log prefix log dir f new deleter log dir start log dir new file config get string dirname if logging enabled pre set log dir log dir enable logger must run pre set log dir max space used by zipped logs config register max zipped logs size 128m 3 true true log config handler max zipped logs size log config handler max zipped logs size long new long callback override public long get return max zipped logs size override public void set long val throws invalid config value exception if val 0 val 0l max zipped logs size val if file logger hook null file logger hook set max old logs size val true max zipped logs size config get long max zipped logs size these two are forced below so we don t need to check them now priority node must override this to minor on testnet config register priority normal 4 false false log config handler min logging priority log config handler min logging priority long new priority callback detailed priority config register priority detail 5 true false log config handler detaild priority threshold log config handler detaild priority threshold long new string callback override public string get logger hook chain chain logger get chain return chain get detailed thresholds override public void set string val throws invalid config value exception logger hook chain chain logger get chain try chain set detailed thresholds val catch invalid threshold exception e throw new invalid config value exception e get message interval config register interval 10minute 5 true false log config handler rotation interval log config handler rotation interval long new string callback override public string get return log rotate interval override public void set string val throws invalid config value exception if val equals log rotate interval return if file logger hook null try file logger hook set interval val catch file logger hook interval parse exception e throw new option format exception e get message log rotate interval val log rotate interval config get string interval max cached bytes in ram config register max cached bytes 10m 6 true false log config handler max cached bytes log config handler max cached bytes long new long callback override public long get return max cached log bytes override public void set long val throws invalid config value exception if val 0 val 0l if val max cached log bytes return max cached log bytes val if file logger hook null file logger hook set max list bytes val true max cached log bytes config get long max cached bytes max cached lines in ram config register max cached lines 100k 7 true false log config handler max cached lines log config handler max cached lines long new int callback override public integer get return max cached log lines override public void set integer val throws invalid config value exception if val 0 val 0 if val max cached log lines return max cached log lines val if file logger hook null file logger hook set max list length val false max cached log lines config get int max cached lines if logging enabled enable logger config finished initialization loggingconfighandler subconfig loggingconfig invalidconfigvalueexception loggingconfig loggingconfig logconfighandler logconfighandler enabledlong booleancallback fileloggerhook invalidconfigvalueexception fileloggerhook disablelogger enablelogger loggingenabled loggingconfig getboolean loggingconfig logconfighandler dirname logconfighandler dirnamelong stringcallback logdir getpath invalidconfigvalueexception logdir presetlogdir fileloggerhook logdir fileloggerhook switchbasefilename getpath log_prefix logdir logdir logdir getstring loggingenabled presetlogdir logdir enablelogger presetlogdir maxzippedlogssize logconfighandler maxzippedlogssize logconfighandler maxzippedlogssizelong longcallback maxzippedlogssize invalidconfigvalueexception maxzippedlogssize fileloggerhook fileloggerhook setmaxoldlogssize maxzippedlogssize getlong maxzippedlogssize logconfighandler minloggingpriority logconfighandler minloggingprioritylong prioritycallback prioritydetail logconfighandler detaildprioritythreshold logconfighandler detaildprioritythresholdlong stringcallback loggerhookchain getchain getdetailedthresholds invalidconfigvalueexception loggerhookchain getchain setdetailedthresholds invalidthresholdexception invalidconfigvalueexception getmessage logconfighandler rotationinterval logconfighandler rotationintervallong stringcallback logrotateinterval invalidconfigvalueexception logrotateinterval fileloggerhook fileloggerhook setinterval fileloggerhook intervalparseexception optionformatexception getmessage logrotateinterval logrotateinterval getstring maxcachedbytes logconfighandler maxcachedbytes logconfighandler maxcachedbyteslong longcallback maxcachedlogbytes invalidconfigvalueexception maxcachedlogbytes maxcachedlogbytes fileloggerhook fileloggerhook setmaxlistbytes maxcachedlogbytes getlong maxcachedbytes maxcachedlines logconfighandler maxcachedlines logconfighandler maxcachedlineslong intcallback maxcachedloglines invalidconfigvalueexception maxcachedloglines maxcachedloglines fileloggerhook fileloggerhook setmaxlistlength maxcachedloglines getint maxcachedlines loggingenabled enablelogger finishedinitialization logging config register enabled true 1 true false log config handler enabled log config handler enabled long new boolean callback override public boolean get return file logger hook null loggingconfig logconfighandler logconfighandler enabledlong booleancallback fileloggerhook override public void set boolean val throws invalid config value exception if val file logger hook null return if val disable logger else enable logger invalidconfigvalueexception fileloggerhook disablelogger enablelogger new string callback override public string get return log dir get path stringcallback logdir getpath override public void set string val throws invalid config value exception file f new file val if f equals log dir return pre set log dir f still here if file logger hook null log dir f else discard old data file logger hook switch base filename f get path file separator log prefix log dir f new deleter log dir start invalidconfigvalueexception logdir presetlogdir fileloggerhook logdir fileloggerhook switchbasefilename getpath log_prefix logdir logdir config register max zipped logs size 128m 3 true true log config handler max zipped logs size log config handler max zipped logs size long new long callback override public long get return max zipped logs size maxzippedlogssize logconfighandler maxzippedlogssize logconfighandler maxzippedlogssizelong longcallback maxzippedlogssize override public void set long val throws invalid config value exception if val 0 val 0l max zipped logs size val if file logger hook null file logger hook set max old logs size val invalidconfigvalueexception maxzippedlogssize fileloggerhook fileloggerhook setmaxoldlogssize override public string get logger hook chain chain logger get chain return chain get detailed thresholds loggerhookchain getchain getdetailedthresholds override public void set string val throws invalid config value exception logger hook chain chain logger get chain try chain set detailed thresholds val catch invalid threshold exception e throw new invalid config value exception e get message invalidconfigvalueexception loggerhookchain getchain setdetailedthresholds invalidthresholdexception invalidconfigvalueexception getmessage config register interval 10minute 5 true false log config handler rotation interval log config handler rotation interval long new string callback override public string get return log rotate interval logconfighandler rotationinterval logconfighandler rotationintervallong stringcallback logrotateinterval override public void set string val throws invalid config value exception if val equals log rotate interval return if file logger hook null try file logger hook set interval val catch file logger hook interval parse exception e throw new option format exception e get message log rotate interval val invalidconfigvalueexception logrotateinterval fileloggerhook fileloggerhook setinterval fileloggerhook intervalparseexception optionformatexception getmessage logrotateinterval config register max cached bytes 10m 6 true false log config handler max cached bytes log config handler max cached bytes long new long callback override public long get return max cached log bytes maxcachedbytes logconfighandler maxcachedbytes logconfighandler maxcachedbyteslong longcallback maxcachedlogbytes override public void set long val throws invalid config value exception if val 0 val 0l if val max cached log bytes return max cached log bytes val if file logger hook null file logger hook set max list bytes val invalidconfigvalueexception maxcachedlogbytes maxcachedlogbytes fileloggerhook fileloggerhook setmaxlistbytes config register max cached lines 100k 7 true false log config handler max cached lines log config handler max cached lines long new int callback override public integer get return max cached log lines maxcachedlines logconfighandler maxcachedlines logconfighandler maxcachedlineslong intcallback maxcachedloglines override public void set integer val throws invalid config value exception if val 0 val 0 if val max cached log lines return max cached log lines val if file logger hook null file logger hook set max list length val invalidconfigvalueexception maxcachedloglines maxcachedloglines fileloggerhook fileloggerhook setmaxlistlength turn on the logger private void enable logger try pre set log dir log dir catch invalid config value exception e3 system err println cannot set log dir log dir e3 e3 print stack trace synchronized enable logger lock if file logger hook null return logger setup chain try config force update priority config force update priority detail catch invalid config value exception e2 system err println invalid config value for logger priority in config file config get string priority leave it at the default catch node need restart exception e impossible system err println impossible node need restart exception for logger priority in config file config get string priority file logger hook hook try hook new file logger hook true new file log dir log prefix get absolute path d c t p m mmm dd yyyy hh mm ss sss logger debug filtered by chain false true max zipped logs size 1gb of old compressed logfiles catch io exception e system err println cannot start logger e get message return try hook set interval log rotate interval catch interval parse exception e system err println invalid logging interval e get message try hook set interval 5minute catch interval parse exception e1 system err println impossible e1 get message hook set max list bytes max cached log bytes hook set max list length max cached log lines file logger hook hook logger global add hook hook hook start enablelogger presetlogdir logdir invalidconfigvalueexception logdir printstacktrace enableloggerlock fileloggerhook setupchain forceupdate forceupdate prioritydetail invalidconfigvalueexception getstring nodeneedrestartexception nodeneedrestartexception getstring fileloggerhook fileloggerhook logdir log_prefix getabsolutepath maxzippedlogssize ioexception getmessage setinterval logrotateinterval intervalparseexception getmessage setinterval intervalparseexception getmessage setmaxlistbytes maxcachedlogbytes setmaxlistlength maxcachedloglines fileloggerhook globaladdhook protected void disable logger synchronized enable logger lock if file logger hook null return file logger hook hook file logger hook logger global remove hook hook hook close file logger hook null logger destroy chain if empty disablelogger enableloggerlock fileloggerhook fileloggerhook fileloggerhook globalremovehook fileloggerhook destroychainifempty protected void pre set log dir file f throws invalid config value exception boolean exists f exists if exists f is directory throw new invalid config value exception cannot overwrite a file with a log directory if exists f mkdir exists f exists if exists f is directory throw new invalid config value exception cannot create log directory presetlogdir invalidconfigvalueexception isdirectory invalidconfigvalueexception isdirectory invalidconfigvalueexception file log dir public deleter file log dir this log dir log dir logdir logdir logdir logdir void start executor execute this old log directory log dir deleter logdir public void run freenet support logger os thread logpid this file logger hook wait for switch delete log dir osthread fileloggerhook waitforswitch logdir return true if we can t delete due to presence of non freenet files private boolean delete file dir boolean failed false file files dir list files for int i 0 i files length i file f files i string s f get name if s starts with freenet s index of log 1 if f is file if f delete failed true else if f is directory if delete f failed true else failed true if failed failed dir delete return failed listfiles getname startswith indexof isfile isdirectory public file logger hook get file logger hook return file logger hook fileloggerhook getfileloggerhook fileloggerhook public void force enable logging enable logger forceenablelogging enablelogger public long get max zipped log files return max zipped logs size getmaxzippedlogfiles maxzippedlogssize public void set max zipped log files string max size as string throws invalid config value exception node need restart exception config set max zipped logs size max size as string setmaxzippedlogfiles maxsizeasstring invalidconfigvalueexception nodeneedrestartexception maxzippedlogssize maxsizeasstring set the radius of the kernel and hence the amount of blur param radius the radius of the blur in pixels see get radius public void set radius float radius this radius radius getradius setradius get the radius of the kernel return the radius see set radius public float get radius return radius setradius getradius set the number of sides of the aperture param sides the number of sides see get sides public void set sides int sides this sides sides getsides setsides get the number of sides of the aperture return the number of sides see set sides public int get sides return sides setsides getsides set the bloom factor param bloom the bloom factor see get bloom public void set bloom float bloom this bloom bloom getbloom setbloom get the bloom factor return the bloom factor see set bloom public float get bloom return bloom setbloom getbloom set the bloom threshold param bloom threshold the bloom threshold see get bloom threshold public void set bloom threshold float bloom threshold this bloom threshold bloom threshold bloomthreshold getbloomthreshold setbloomthreshold bloomthreshold bloomthreshold bloomthreshold get the bloom threshold return the bloom threshold see set bloom threshold public float get bloom threshold return bloom threshold setbloomthreshold getbloomthreshold bloomthreshold public buffered image filter buffered image src buffered image dst int width src get width int height src get height int rows 1 cols 1 int log2rows 0 log2cols 0 int iradius int math ceil radius int tile width 128 int tile height tile width int adjusted width int width iradius 2 int adjusted height int height iradius 2 tile width iradius 32 math min 128 width 2 iradius math min 256 width 2 iradius tile height iradius 32 math min 128 height 2 iradius math min 256 height 2 iradius if dst null dst new buffered image width height buffered image type int argb while rows tile height rows 2 log2rows while cols tile width cols 2 log2cols int w cols int h rows tile width w tile height h fixme tile width w and cols are always all the same fft fft new fft math max log2rows log2cols int rgb new int w h float mask new float 2 w h float gb new float 2 w h float ar new float 2 w h create the kernel double poly angle math pi sides double poly scale 1 0f math cos poly angle double r2 radius radius double rangle math to radians angle float total 0 int i 0 for int y 0 y h y for int x 0 x w x double dx x w 2f double dy y h 2f double r dx dx dy dy double f r r2 1 0 if f 0 r math sqrt r if sides 0 double a math atan2 dy dx rangle a image math mod a poly angle 2 poly angle f math cos a poly scale else f 1 f f r radius 1 0 total float f mask 0 i float f mask 1 i 0 i normalize the kernel i 0 for int y 0 y h y for int x 0 x w x mask 0 i total i fft transform2d mask 0 mask 1 w h true for int tiley iradius tiley height tiley tile height 2 iradius for int tilex iradius tilex width tilex tile width 2 iradius system out println tile tilex tiley tile width tile height clip the tile to the image bounds int tx tilex ty tiley tw tile width th tile height int fx 0 fy 0 if tx 0 tw tx fx tx tx 0 if ty 0 th ty fy ty ty 0 if tx tw width tw width tx if ty th height th height ty src getrgb tx ty tw th rgb fy w fx w create a float array from the pixels any pixels off the edge of the source image get duplicated from the edge i 0 for int y 0 y h y int imagey y tiley int j if imagey 0 j fy else if imagey height j fy th 1 else j y j w for int x 0 x w x int imagex x tilex int k if imagex 0 k fx else if imagex width k fx tw 1 else k x k j ar 0 i rgb k 24 0xff float r rgb k 16 0xff float g rgb k 8 0xff float b rgb k 0xff bloom if r bloom threshold r bloom r bloom threshold r bloom threshold bloom if g bloom threshold g bloom g bloom threshold g bloom threshold bloom if b bloom threshold b bloom b bloom threshold b bloom threshold bloom ar 1 i r gb 0 i g gb 1 i b i k transform into frequency space fft transform2d ar 0 ar 1 cols rows true fft transform2d gb 0 gb 1 cols rows true multiply the transformed pixels by the transformed kernel i 0 for int y 0 y h y for int x 0 x w x float re ar 0 i float im ar 1 i float rem mask 0 i float imm mask 1 i ar 0 i re rem im imm ar 1 i re imm im rem re gb 0 i im gb 1 i gb 0 i re rem im imm gb 1 i re imm im rem i transform back fft transform2d ar 0 ar 1 cols rows false fft transform2d gb 0 gb 1 cols rows false convert back to rgb pixels with quadrant remapping int row flip w 1 int col flip h 1 int index 0 fixme don t bother converting pixels off image edges for int y 0 y w y int ym y row flip int yi ym cols for int x 0 x w x int xm yi x col flip int a int ar 0 xm int r int ar 1 xm int g int gb 0 xm int b int gb 1 xm clamp high pixels due to blooming if r 255 r 255 if g 255 g 255 if b 255 b 255 int argb a 24 r 16 g 8 b rgb index argb clip to the output image tx tilex iradius ty tiley iradius tw tile width 2 iradius th tile height 2 iradius if tx tw width tw width tx if ty th height th height ty dst setrgb tx ty tw th rgb iradius w iradius w return dst bufferedimage bufferedimage bufferedimage getwidth getheight tilewidth tileheight tilewidth adjustedwidth adjustedheight tilewidth tileheight bufferedimage bufferedimage type_int_argb tileheight tilewidth tilewidth tileheight tilewidth polyangle polyscale polyangle toradians imagemath polyangle polyangle polyscale tileheight tilewidth tilewidth tileheight tilewidth tileheight bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold bloomthreshold row_flip col_flip row_flip col_flip tilewidth tileheight override public string to string return blur lens blur tostring create a token bucket param max the maximum size of the bucket in tokens param nanos per tick the number of nanoseconds between ticks public token bucket long max long nanos per tick long initial value this max max this current initial value if current max logger error this initial value current max max in this new exception error current max this nanos per tick nanos per tick long now system current time millis this time last tick now 1000 1000 logminor logger should log logger minor this nanospertick tokenbucket nanospertick initialvalue initialvalue nanospertick nanospertick currenttimemillis timelasttick shouldlog either grab a bunch of tokens or don t never block param tokens the number of tokens to grab return true if we could acquire the tokens public synchronized boolean instant grab long tokens if logminor logger minor this instant grab tokens current current max max add tokens if logminor logger minor this instant grab tokens current current max max if current tokens current tokens if current max current max return true else if current max current max return false instantgrab addtokens either grab a bunch of tokens or don t never block param tokens the number of tokens to grab return true if we could acquire the tokens public synchronized long partial instant grab long tokens if logminor logger minor this instant grab tokens current current max max add tokens if logminor logger minor this instant grab tokens current current max max if current tokens current tokens if current max current max return tokens else tokens current current 0 return tokens partialinstantgrab addtokens remove tokens without blocking even if it causes the balance to go negative param tokens the number of tokens to remove public synchronized void force grab long tokens if logminor logger minor this force grab tokens if tokens 0 logger error this force grab tokens negative value new exception error return add tokens current tokens if current max current max if logminor logger minor this removed tokens balance now current forcegrab forcegrab forcegrab addtokens public synchronized long count return current get the current number of available tokens public synchronized long get count add tokens return current getcount addtokens protected long offset return 0 public synchronized void blocking grab long tokens logminor logger should log logger minor this if logminor logger minor this blocking grab tokens if tokens max inner blocking grab tokens else for int i 0 i tokens i max inner blocking grab math min tokens max blockinggrab shouldlog innerblockinggrab innerblockinggrab grab a bunch of tokens block if necessary param tokens the number of tokens to grab public synchronized void inner blocking grab long tokens if logminor logger minor this inner blocking grab tokens add tokens if current max current max if logminor logger minor this current current current tokens if current 0 if logminor logger minor this got tokens instantly current current return else if logminor logger minor this blocking grab removed tokens current current will have to wait because negative long min delayns nanos per tick current long min delayms min delayns 1000 1000 min delayns 1000 1000 0 0 1 long now system current time millis long wake at now min delayms if logminor logger minor this waking in min delayms millis while true now system current time millis int delay int math min integer max value wake at now if delay 0 break if logminor logger minor this waiting delay ms try wait delay catch interrupted exception e go around the loop again if logminor logger minor this blocking grab finished current current innerblockinggrab addtokens mindelayns nanospertick mindelayms mindelayns mindelayns currenttimemillis wakeat mindelayms mindelayms currenttimemillis max_value wakeat interruptedexception public synchronized void recycle long tokens current tokens if current max current max change the number of nanos per tick param nanos per tick the new number of nanos per tick public synchronized void change nanos per tick long nanos per tick synchronize up first using the old nanos per tick if nanos per tick 0 throw new illegal argument exception add tokens this nanos per tick nanos per tick if nanos per tick this nanos per tick notify all nanospertick changenanospertick nanospertick nanospertick nanospertick illegalargumentexception addtokens nanospertick nanospertick nanospertick nanospertick notifyall public synchronized void change bucket size long new max if new max 0 throw new illegal argument exception add tokens no clip max new max if current max current max changebucketsize newmax newmax illegalargumentexception addtokensnoclip newmax public synchronized void change nanos and bucket size long nanos per tick long new max if nanos per tick 0 throw new illegal argument exception if new max 0 throw new illegal argument exception synchronize up first using the old nanos per tick add tokens no clip if nanos per tick this nanos per tick notify all this nanos per tick nanos per tick this max new max if current max current max changenanosandbucketsize nanospertick newmax nanospertick illegalargumentexception newmax illegalargumentexception nanospertick addtokensnoclip nanospertick nanospertick notifyall nanospertick nanospertick newmax public synchronized void add tokens add tokens no clip if current max current max if logminor logger minor this add tokens clipped current current addtokens addtokensnoclip addtokens update the number of tokens according to elapsed time public synchronized void add tokens no clip long add tokens to add current add time last tick add nanos per tick if logminor logger minor this add tokens no clip added add tokens current current deliberately do not clip to size at this point caller must do this but it is usually beneficial for the caller to do so addtokensnoclip tokenstoadd timelasttick nanospertick addtokensnoclip synchronized long tokens to add long nowns system current time millis 1000 1000 long next tick time last tick nanos per tick if next tick nowns return 0 if next tick nanos per tick nowns return 1 return nowns next tick nanos per tick tokenstoadd currenttimemillis nexttick timelasttick nanospertick nexttick nexttick nanospertick nexttick nanospertick public synchronized long get nanos per tick return nanos per tick getnanospertick nanospertick public final string location public pluginhttp exception string error message string location this message error message this location location pluginhttpexception errormessage errormessage creates a new alert public ext old age user alert super true null null null null user alert error true l10n get string user alert hide true null extoldageuseralert useralert getstring useralert override public string get title return l10n ext too old title gettitle exttoooldtitle override public string get text return l10n ext too old gettext exttooold private string l10n string key return l10n get string ext old age user alert key getstring extoldageuseralert override public html node gethtml text return new html node div get text htmlnode gethtmltext htmlnode gettext override public string get short text return l10n ext too old short getshorttext exttoooldshort param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user throws unknown identity exception public introduce identity page web interface my web interface http request my request throws unknown identity exception super my web interface my request m identity wot get own identity byid request get part as string id 128 m client wot get introduction client todo can we risk that the identity is being deleted i don t think we should lock the whole wot if request is part set solve int idx 0 while request is part set id idx string id request get part as string id idx 128 string solution request get part as string solution id 10 fixme replace 10 with the maximal solution length if solution equals introduction puzzle p wot get introduction puzzle store get byid id if p null try m client solve puzzle m identity p solution catch exception e the identity or the puzzle might have been deleted here logger error this insert puzzle solution failed idx mywebinterface webinterface myrequest unknownidentityexception introduceidentitypage webinterface mywebinterface httprequest myrequest unknownidentityexception mywebinterface myrequest midentity getownidentitybyid getpartasstring mclient getintroductionclient ispartset ispartset getpartasstring getpartasstring introductionpuzzle getintroductionpuzzlestore getbyid mclient solvepuzzle midentity insertpuzzlesolution public void make plugin respirator pr wot get plugin respirator make info box pr make puzzle box pr pluginrespirator getpluginrespirator makeinfobox makepuzzlebox private void make info box plugin respirator pr html node box content add content box introduce identity m identity get nickname box content add child p solve about 10 puzzles to get your identity known by other identities do not continously solve puzzles fixme add more information makeinfobox pluginrespirator htmlnode boxcontent addcontentbox midentity getnickname boxcontent addchild private void make puzzle box plugin respirator pr html node box content add content box puzzles synchronized m client the client returns an array list not the object container so this should be safe list introduction puzzle puzzles m client get puzzles m identity puzzle type captcha puzzle display count if puzzles size 0 html node solve form pr add form child box content uri solve puzzles solve form add child input new string type name value new string hidden page solve puzzles solve form add child input new string type name value new string hidden id m identity getid html node puzzle table solve form add child table border 0 html node row puzzle table add child tr int counter 0 for introduction puzzle p puzzles solve form add child input new string type name value new string hidden id counter p getid if counter 4 0 row puzzle table add child tr html node cell row add child td cell add attribute align center fixme use self uri puzzle id instead cell add child img new string src new string data image jpeg base64 base64 encode standard p get data cell add child br cell add child input new string type name size new string text solution p getid 10 solve form add child input new string type name value new string submit solve submit else box content add child p no puzzles were downloaded yet sorry please give the wot plugin some time to retrieve puzzles makepuzzlebox pluginrespirator htmlnode boxcontent addcontentbox mclient arraylist objectcontainer introductionpuzzle mclient getpuzzles midentity puzzletype puzzle_display_count htmlnode solveform addformchild boxcontent solvepuzzles solveform addchild solvepuzzles solveform addchild midentity htmlnode puzzletable solveform addchild htmlnode puzzletable addchild introductionpuzzle solveform addchild puzzletable addchild htmlnode addchild addattribute self_uri addchild encodestandard getdata addchild addchild solveform addchild boxcontent addchild create an archive store element from a temp store element param key2 the key of the archive the file came from param real name the name of the file in that archive param temp the temp store element currently storing the data param manager the parent archive manager within which this item is stored real archive store item archive store context ctx freeneturi key2 string real name bucket bucket super new archive key key2 real name ctx mb new multi reader bucket bucket this bucket mb get reader bucket bucket set read only space used bucket size archivestoreelement tempstoreelement realname tempstoreelement archivemanager realarchivestoreitem archivestorecontext realname archivekey realname multireaderbucket getreaderbucket setreadonly spaceused return the data as a bucket in plaintext bucket data as bucket return bucket dataasbucket return the length of the data long data size return bucket size datasize return the estimated space used by the data override long space used return space used spaceused spaceused override void inner close if logger should log logger minor this logger minor this inner close this bucket free innerclose shouldlog innerclose override bucket get data or throw throws archive failure exception return data as bucket getdataorthrow archivefailureexception dataasbucket override bucket get reader bucket throws archive failure exception return mb get reader bucket getreaderbucket archivefailureexception getreaderbucket public direct dir put file simple field set subset string identifier boolean global bucket factory bf throws message invalid exception super subset identifier global string s subset get data length if s null throw new message invalid exception protocol error message missing field upload from direct requires a data length for name identifier global try length long parse long s catch number format exception e throw new message invalid exception protocol error message error parsing number could not parse data length e to string identifier global try if length 0 data new null bucket else data bf make bucket length catch io exception e throw new message invalid exception protocol error message internal error internal error could not allocate temp bucket e to string identifier global directdirputfile simplefieldset bucketfactory messageinvalidexception datalength messageinvalidexception protocolerrormessage missing_field uploadfrom datalength parselong numberformatexception messageinvalidexception protocolerrormessage error_parsing_number datalength tostring nullbucket makebucket ioexception messageinvalidexception protocolerrormessage internal_error tostring public long bytes to read return length bytestoread public void read input stream is throws io exception bucket tools copy from data is length inputstream ioexception buckettools copyfrom public void write output stream os throws io exception bucket tools copy to data os length outputstream ioexception buckettools copyto override public bucket get data return data getdata override public void remove from object container container data free data remove from container container delete this removefrom objectcontainer removefrom public abstract class iterable iterator t implements iterable t iterator t this class itself is iterator public iterator t iterator return this iterableiterator public static void compress output stream out input stream in string cipher key throws io exception int rc byte buf new byte page size data input stream din new data input stream in data output stream dout new data output stream out byte init state new byte 256 byte state new byte 256 if cipher key null byte key cipher key get bytes for int counter 0 counter 256 counter init state counter byte counter int index1 0 int index2 0 for int counter 0 counter 256 counter index2 key index1 init state counter index2 0xff byte temp init state counter init state counter init state index2 init state index2 temp index1 index1 1 key length while rc in read buf 0 page size 0 if rc page size throw new io exception database file is corrupted byte array output stream bs new byte array output stream gzip output stream gs new gzip output stream bs gs write buf 0 page size gs finish byte compressed bs to byte array int len compressed length if cipher key null int x 0 y 0 system arraycopy init state 0 state 0 state length for int i 0 i len i x x 1 0xff y y state x 0xff byte temp state x state x state y state y temp int next state state x state y 0xff compressed i state next state dout write short len dout write compressed 0 compressed length dout flush outputstream inputstream cipherkey ioexception page_size datainputstream datainputstream dataoutputstream dataoutputstream initstate cipherkey cipherkey getbytes initstate initstate initstate initstate initstate initstate page_size page_size ioexception bytearrayoutputstream bytearrayoutputstream gzipoutputstream gzipoutputstream page_size tobytearray cipherkey initstate nextstate nextstate writeshort this utility accepts one argument path to database file it creates new file at the same location and with the same name but with with dbz extension public static void main string args throws io exception if args length 0 args length 2 system err println usage java plugins xml spider org garret perst compress database for perst lite database file path cipher key return string path args 0 file input stream in new file input stream path int ext path last index of string gzip path substring 0 ext dgz string cipher key null if args length 1 cipher key args 1 file output stream out new file output stream gzip compress out in cipher key in close out close system out println file gzip is written ioexception xmlspider compressdatabaseforperstlite database_file_path fileinputstream fileinputstream lastindexof cipherkey cipherkey fileoutputstream fileoutputstream cipherkey private colormap colormap public rays filter raysfilter set the opacity of the rays param opacity the opacity see get opacity public void set opacity float opacity this opacity opacity getopacity setopacity get the opacity of the rays return the opacity see set opacity public float get opacity return opacity setopacity getopacity set the threshold value param threshold the threshold value see get threshold public void set threshold float threshold this threshold threshold getthreshold setthreshold get the threshold value return the threshold value see set threshold public float get threshold return threshold setthreshold getthreshold set the strength of the rays param strength the strength see get strength public void set strength float strength this strength strength getstrength setstrength get the strength of the rays return the strength see set strength public float get strength return strength setstrength getstrength set whether to render only the rays param rays only true to render rays only see get rays only public void set rays only boolean rays only this rays only rays only raysonly getraysonly setraysonly raysonly raysonly raysonly get whether to render only the rays return true to render rays only see set rays only public boolean get rays only return rays only setraysonly getraysonly raysonly set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap override public buffered image filter buffered image src buffered image dst int width src get width int height src get height int pixels new int width int src pixels new int width buffered image rays new buffered image width height buffered image type int argb int threshold3 int threshold 3 255 for int y 0 y height y getrgb src 0 y width 1 pixels for int x 0 x width x int rgb pixels x int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int l r g b if l threshold3 pixels x 0xff000000 else l 3 pixels x a l 16 l 8 l setrgb rays 0 y width 1 pixels rays super filter rays null for int y 0 y height y getrgb rays 0 y width 1 pixels getrgb src 0 y width 1 src pixels for int x 0 x width x int rgb pixels x int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if colormap null int l r g b rgb colormap get color l strength 1 3f else r pixel utils clamp int r strength g pixel utils clamp int g strength b pixel utils clamp int b strength rgb a r 16 g 8 b pixels x rgb setrgb rays 0 y width 1 pixels if dst null dst create compatible dest image src null graphics2d g dst create graphics if rays only g set composite alpha composite src over g draw rendered image src null g set composite misc composite get instance misc composite add opacity g draw rendered image rays null g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight srcpixels bufferedimage bufferedimage bufferedimage type_int_argb srcpixels getcolor pixelutils pixelutils pixelutils createcompatibledestimage creategraphics raysonly setcomposite alphacomposite srcover drawrenderedimage setcomposite misccomposite getinstance misccomposite drawrenderedimage override public string to string return stylize rays tostring public query response queryresponse public query response soap response soap res super soap res queryresponse soapresponse soapres soapres private node get return node node body node get body node if body node null return null if body node has nodes false return null node query res node body node get node 0 if query res node null return null if query res node has nodes false return null return query res node get node 0 getreturnnode bodynode getbodynode bodynode bodynode hasnodes queryresnode bodynode getnode queryresnode queryresnode hasnodes queryresnode getnode public string get return value node node get return node if node null return return node get value getreturnvalue getreturnnode getvalue public void set response state variable state var string var state var get value set status code http status ok node body node get body node node res node create response node var body node add node res node node env nodee get envelope node set content env nodee setresponse statevariable statevar statevar getvalue setstatuscode httpstatus bodynode getbodynode resnode createresponsenode bodynode addnode resnode envnodee getenvelopenode setcontent envnodee private node create response node string var node query res node new node query res node set name control ns control query state variable response query res node set name space control ns control xmlns node return node new node return node set name control return return node set value var query res node add node return node return query res node createresponsenode queryresnode queryresnode setname query_state_variable_response queryresnode setnamespace returnnode returnnode setname returnnode setvalue queryresnode addnode returnnode queryresnode protected bucket bucket bucket create bucket bucket factory bf long length fcp server server throws io exception return bf make bucket length createbucket bucketfactory fcpserver ioexception makebucket abstract string get identifier getidentifier abstract string get identifier abstract boolean is global getidentifier isglobal protected boolean free on sent void set free on sent free on sent true freeonsent setfreeonsent freeonsent override public void read from input stream is bucket factory bf fcp server server throws io exception message invalid exception long len data length if len 0 return if len 0 bucket new null bucket return bucket temp bucket try temp bucket create bucket bf len server catch io exception e logger error this bucket error e e throw new message invalid exception protocol error message internal error e to string get identifier is global bucket tools copy from temp bucket is len this bucket temp bucket readfrom inputstream bucketfactory fcpserver ioexception messageinvalidexception datalength nullbucket tempbucket tempbucket createbucket ioexception messageinvalidexception protocolerrormessage internal_error tostring getidentifier isglobal buckettools copyfrom tempbucket tempbucket override protected void write data output stream os throws io exception long len data length if len 0 bucket tools copy to bucket os len if free on sent bucket free always transient so no remove from needed writedata outputstream ioexception datalength buckettools copyto freeonsent removefrom override string get end string return data getendstring public cellular filter results new point 3 for int j 0 j results length j results j new point if probabilities null probabilities new byte 8192 float factorial 1 float total 0 float mean 2 5f for int i 0 i 10 i if i 1 factorial i float probability float math pow mean i float math exp mean factorial int start int total 8192 total probability int end int total 8192 for int j start j end j probabilities j byte i cellularfilter specifies the scale of the texture param scale the scale of the texture min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale specifies the stretch factor of the texture param stretch the stretch factor of the texture min value 1 max value 50 see get stretch public void set stretch float stretch this stretch stretch getstretch setstretch returns the stretch factor of the texture return the stretch factor of the texture see set stretch public float get stretch return stretch setstretch getstretch specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle public void set coefficient int i float v coefficients i v setcoefficient public float get coefficient int i return coefficients i getcoefficient public void set angle coefficient float angle coefficient this angle coefficient angle coefficient setanglecoefficient anglecoefficient anglecoefficient anglecoefficient public float get angle coefficient return angle coefficient getanglecoefficient anglecoefficient public void set gradient coefficient float gradient coefficient this gradient coefficient gradient coefficient setgradientcoefficient gradientcoefficient gradientcoefficient gradientcoefficient public float get gradient coefficient return gradient coefficient getgradientcoefficient gradientcoefficient public void setf1 float v coefficients 0 v public float getf1 return coefficients 0 public void setf2 float v coefficients 1 v public float getf2 return coefficients 1 public void setf3 float v coefficients 2 v public float getf3 return coefficients 2 public void setf4 float v coefficients 3 v public float getf4 return coefficients 3 set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set randomness float randomness this randomness randomness setrandomness public float get randomness return randomness getrandomness public void set grid type int grid type this grid type grid type setgridtype gridtype gridtype gridtype public int get grid type return grid type getgridtype gridtype public void set distance power float distance power this distance power distance power setdistancepower distancepower distancepower distancepower public float get distance power return distance power getdistancepower distancepower specifies the turbulence of the texture param turbulence the turbulence of the texture min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the effect return the turbulence of the effect see set turbulence public float get turbulence return turbulence setturbulence getturbulence set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of texture return the amount see set amount public float get amount return amount setamount getamount private float check cube float x float y int cubex int cubey point results int num points random set seed 571 cubex 23 cubey switch grid type case random default num points probabilities random next int 0x1fff break case square num points 1 break case hexagonal num points 1 break case octagonal num points 2 break case triangular num points 2 break for int i 0 i num points i float px 0 py 0 float weight 1 0f switch grid type case random px random next float py random next float break case square px py 0 5f if randomness 0 px randomness random next float 0 5 py randomness random next float 0 5 break case hexagonal if cubex 1 0 px 0 75f py 0 else px 0 75f py 0 5f if randomness 0 px randomness noise noise2 271 cubex px 271 cubey py py randomness noise noise2 271 cubex px 89 271 cubey py 137 break case octagonal switch i case 0 px 0 207f py 0 207f break case 1 px 0 707f py 0 707f weight 1 6f break if randomness 0 px randomness noise noise2 271 cubex px 271 cubey py py randomness noise noise2 271 cubex px 89 271 cubey py 137 break case triangular if cubey 1 0 if i 0 px 0 25f py 0 35f else px 0 75f py 0 65f else if i 0 px 0 75f py 0 35f else px 0 25f py 0 65f if randomness 0 px randomness noise noise2 271 cubex px 271 cubey py py randomness noise noise2 271 cubex px 89 271 cubey py 137 break float dx float math abs x px float dy float math abs y py float d dx weight dy weight if distance power 1 0f d dx dy else if distance power 2 0f d float math sqrt dx dx dy dy else d float math pow float math pow dx distance power float math pow dy distance power 1 distance power insertion sort the long way round to speed it up a bit if d results 0 distance point p results 2 results 2 results 1 results 1 results 0 results 0 p p distance d p dx dx p dy dy p x cubex px p y cubey py else if d results 1 distance point p results 2 results 2 results 1 results 1 p p distance d p dx dx p dy dy p x cubex px p y cubey py else if d results 2 distance point p results 2 p distance d p dx dx p dy dy p x cubex px p y cubey py return results 2 distance checkcube numpoints setseed gridtype numpoints nextint numpoints numpoints numpoints numpoints numpoints gridtype nextfloat nextfloat nextfloat nextfloat distancepower distancepower distancepower distancepower distancepower public float evaluate float x float y for int j 0 j results length j results j distance float positive infinity int ix int x int iy int y float fx x ix float fy y iy float d check cube fx fy ix iy results if d fy d check cube fx fy 1 ix iy 1 results if d 1 fy d check cube fx fy 1 ix iy 1 results if d fx check cube fx 1 fy ix 1 iy results if d fy d check cube fx 1 fy 1 ix 1 iy 1 results if d 1 fy d check cube fx 1 fy 1 ix 1 iy 1 results if d 1 fx d check cube fx 1 fy ix 1 iy results if d fy d check cube fx 1 fy 1 ix 1 iy 1 results if d 1 fy d check cube fx 1 fy 1 ix 1 iy 1 results float t 0 for int i 0 i 3 i t coefficients i results i distance if angle coefficient 0 float angle float math atan2 y results 0 y x results 0 x if angle 0 angle 2 float math pi angle 4 float math pi t angle coefficient angle if gradient coefficient 0 float a 1 results 0 dy results 0 dx t gradient coefficient a return t positive_infinity checkcube checkcube checkcube checkcube checkcube checkcube checkcube checkcube checkcube anglecoefficient anglecoefficient gradientcoefficient gradientcoefficient public float turbulence2 float x float y float freq float t 0 0f for float f 1 0f f freq f 2 t evaluate f x f y f return t public int get pixel int x int y int in pixels int width int height float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch nx 1000 ny 1000 reduce artifacts around 0 0 float f turbulence 1 0f evaluate nx ny turbulence2 nx ny turbulence normalize to 0 1 f f min max min f 2 f amount int a 0xff000000 int v if colormap null v colormap get color f if use color int srcx image math clamp int results 0 x 1000 scale 0 width 1 int srcy image math clamp int results 0 y 1000 scale 0 height 1 v in pixels srcy width srcx f results 1 distance results 0 distance results 1 distance results 0 distance f image math smooth step coefficients 1 coefficients 0 f v image math mix colors f 0xff000000 v return v else v pixel utils clamp int f 255 int r v 16 int g v 8 int b v return a r g b getpixel inpixels getcolor usecolor imagemath imagemath inpixels imagemath smoothstep imagemath mixcolors pixelutils override protected int filter pixels int width int height int in pixels rectangle transformed space float minmax noise find range this null min minmax 0 max minmax 1 int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x out pixels index get pixel x y in pixels width height return out pixels filterpixels inpixels transformedspace findrange outpixels outpixels getpixel inpixels outpixels override public object clone cellular filter f cellular filter super clone f coefficients float coefficients clone f results point results clone f random new random if colormap null f colormap colormap colormap clone return f cellularfilter cellularfilter override public string to string return texture cellular tostring private static random random generator new random public float evaluate float x return noise1 x randomgenerator public float evaluate float x float y return noise2 x y public float evaluate float x float y float z return noise3 x y z compute turbulence using perlin noise param x the x value param y the y value param octaves number of octaves of turbulence return turbulence value at x y public static float turbulence2 float x float y float octaves float t 0 0f for float f 1 0f f octaves f 2 t math abs noise2 f x f y f return t compute turbulence using perlin noise param x the x value param y the y value param octaves number of octaves of turbulence return turbulence value at x y public static float turbulence3 float x float y float z float octaves float t 0 0f for float f 1 0f f octaves f 2 t math abs noise3 f x f y f z f return t static boolean start true private static float s curve float t return t t 3 0f 2 0f t scurve compute 1 dimensional perlin noise param x the x value return noise value at x in the range 1 1 public static float noise1 float x int bx0 bx1 float rx0 rx1 sx t u v if start start false init t x n bx0 int t bm bx1 bx0 1 bm rx0 t int t rx1 rx0 1 0f sx s curve rx0 u rx0 g1 p bx0 v rx1 g1 p bx1 return 2 3f lerp sx u v scurve compute 2 dimensional perlin noise param x the x coordinate param y the y coordinate return noise value at x y public static float noise2 float x float y int bx0 bx1 by0 by1 b00 b10 b01 b11 float rx0 rx1 ry0 ry1 q sx sy a b t u v int i j if start start false init t x n bx0 int t bm bx1 bx0 1 bm rx0 t int t rx1 rx0 1 0f t y n by0 int t bm by1 by0 1 bm ry0 t int t ry1 ry0 1 0f i p bx0 j p bx1 b00 p i by0 b10 p j by0 b01 p i by1 b11 p j by1 sx s curve rx0 sy s curve ry0 q g2 b00 u rx0 q 0 ry0 q 1 q g2 b10 v rx1 q 0 ry0 q 1 a lerp sx u v q g2 b01 u rx0 q 0 ry1 q 1 q g2 b11 v rx1 q 0 ry1 q 1 b lerp sx u v return 1 5f lerp sy a b scurve scurve compute 3 dimensional perlin noise param x the x coordinate param y the y coordinate param y the y coordinate return noise value at x y z public static float noise3 float x float y float z int bx0 bx1 by0 by1 bz0 bz1 b00 b10 b01 b11 float rx0 rx1 ry0 ry1 rz0 rz1 q sy sz a b c d t u v int i j if start start false init t x n bx0 int t bm bx1 bx0 1 bm rx0 t int t rx1 rx0 1 0f t y n by0 int t bm by1 by0 1 bm ry0 t int t ry1 ry0 1 0f t z n bz0 int t bm bz1 bz0 1 bm rz0 t int t rz1 rz0 1 0f i p bx0 j p bx1 b00 p i by0 b10 p j by0 b01 p i by1 b11 p j by1 t s curve rx0 sy s curve ry0 sz s curve rz0 q g3 b00 bz0 u rx0 q 0 ry0 q 1 rz0 q 2 q g3 b10 bz0 v rx1 q 0 ry0 q 1 rz0 q 2 a lerp t u v q g3 b01 bz0 u rx0 q 0 ry1 q 1 rz0 q 2 q g3 b11 bz0 v rx1 q 0 ry1 q 1 rz0 q 2 b lerp t u v c lerp sy a b q g3 b00 bz1 u rx0 q 0 ry0 q 1 rz1 q 2 q g3 b10 bz1 v rx1 q 0 ry0 q 1 rz1 q 2 a lerp t u v q g3 b01 bz1 u rx0 q 0 ry1 q 1 rz1 q 2 q g3 b11 bz1 v rx1 q 0 ry1 q 1 rz1 q 2 b lerp t u v d lerp sy a b return 1 5f lerp sz c d scurve scurve scurve public static float lerp float t float a float b return a t b a private static void normalize2 float v float s float math sqrt v 0 v 0 v 1 v 1 v 0 v 0 s v 1 v 1 s static void normalize3 float v float s float math sqrt v 0 v 0 v 1 v 1 v 2 v 2 v 0 v 0 s v 1 v 1 s v 2 v 2 s private static int random return random generator next int 0x7fffffff randomgenerator nextint private static void init int i j k for i 0 i b i p i i g1 i float random b b b b for j 0 j 2 j g2 i j float random b b b b normalize2 g2 i for j 0 j 3 j g3 i j float random b b b b normalize3 g3 i for i b 1 i 0 i k p i p i p j random b p j k for i 0 i b 2 i p b i p i g1 b i g1 i for j 0 j 2 j g2 b i j g2 i j for j 0 j 3 j g3 b i j g3 i j returns the minimum and maximum of a number of random values of the given function this is useful for making some stab at normalising the function public static float find range function1d f float minmax if minmax null minmax new float 2 float min 0 max 0 some random numbers here for float x 100 x 100 x 1 27139 float n f evaluate x min math min min n max math max max n minmax 0 min minmax 1 max return minmax findrange returns the minimum and maximum of a number of random values of the given function this is useful for making some stab at normalising the function public static float find range function2d f float minmax if minmax null minmax new float 2 float min 0 max 0 some random numbers here for float y 100 y 100 y 10 35173 for float x 100 x 100 x 10 77139 float n f evaluate x y min math min min n max math max max n minmax 0 min minmax 1 max return minmax findrange private boolean background false public smear filter random generator new random smearfilter randomgenerator public void set shape int shape this shape shape setshape public int get shape return shape getshape public void set distance int distance this distance distance setdistance public int get distance return distance getdistance public void set density float density this density density setdensity public float get density return density getdensity public void set scatter float scatter this scatter scatter setscatter public float get scatter return scatter getscatter specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle public void set mix float mix this mix mix setmix public float get mix return mix getmix public void set fadeout int fadeout this fadeout fadeout setfadeout public int get fadeout return fadeout getfadeout public void set background boolean background this background background setbackground public boolean get background return background getbackground public void randomize seed new date get time gettime private float random float low float high return low high low random generator next float randomgenerator nextfloat override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height random generator set seed seed float sin angle float math sin angle float cos angle float math cos angle int i 0 int num shapes for int y 0 y height y for int x 0 x width x out pixels i background 0xffffffff in pixels i i switch shape case crosses crosses num shapes int 2 density width height distance 1 for i 0 i num shapes i int x random generator next int 0x7fffffff width int y random generator next int 0x7fffffff height int length random generator next int distance 1 int rgb in pixels y width x for int x1 x length x1 x length 1 x1 if x1 0 x1 width int rgb2 background 0xffffffff out pixels y width x1 out pixels y width x1 image math mix colors mix rgb2 rgb for int y1 y length y1 y length 1 y1 if y1 0 y1 height int rgb2 background 0xffffffff out pixels y1 width x out pixels y1 width x image math mix colors mix rgb2 rgb break case lines num shapes int 2 density width height 2 for i 0 i num shapes i int sx random generator next int 0x7fffffff width int sy random generator next int 0x7fffffff height int rgb in pixels sy width sx int length random generator next int 0x7fffffff distance int dx int length cos angle int dy int length sin angle int x0 sx dx int y0 sy dy int x1 sx dx int y1 sy dy int x y d incre incrne ddx ddy if x1 x0 ddx 1 else ddx 1 if y1 y0 ddy 1 else ddy 1 dx x1 x0 dy y1 y0 dx math abs dx dy math abs dy x x0 y y0 if x width x 0 y height y 0 int rgb2 background 0xffffffff out pixels y width x out pixels y width x image math mix colors mix rgb2 rgb if math abs dx math abs dy d 2 dy dx incre 2 dy incrne 2 dy dx while x x1 if d 0 d incre else d incrne y ddy x ddx if x width x 0 y height y 0 int rgb2 background 0xffffffff out pixels y width x out pixels y width x image math mix colors mix rgb2 rgb else d 2 dx dy incre 2 dx incrne 2 dx dy while y y1 if d 0 d incre else d incrne x ddx y ddy if x width x 0 y height y 0 int rgb2 background 0xffffffff out pixels y width x out pixels y width x image math mix colors mix rgb2 rgb break case squares case circles int radius distance 1 int radius2 radius radius num shapes int 2 density width height radius for i 0 i num shapes i int sx random generator next int 0x7fffffff width int sy random generator next int 0x7fffffff height int rgb in pixels sy width sx for int x sx radius x sx radius 1 x for int y sy radius y sy radius 1 y int f if shape circles f x sx x sx y sy y sy else f 0 if x 0 x width y 0 y height f radius2 int rgb2 background 0xffffffff out pixels y width x out pixels y width x image math mix colors mix rgb2 rgb return out pixels filterpixels inpixels transformedspace outpixels randomgenerator setseed sinangle cosangle numshapes outpixels inpixels numshapes numshapes randomgenerator nextint randomgenerator nextint randomgenerator nextint inpixels outpixels outpixels imagemath mixcolors outpixels outpixels imagemath mixcolors numshapes numshapes randomgenerator nextint randomgenerator nextint inpixels randomgenerator nextint cosangle sinangle outpixels outpixels imagemath mixcolors outpixels outpixels imagemath mixcolors outpixels outpixels imagemath mixcolors numshapes numshapes randomgenerator nextint randomgenerator nextint inpixels outpixels outpixels imagemath mixcolors outpixels override public string to string return effects smear tostring plugin respirator pr public void terminate goon false pluginrespirator public void run plugin plugin respirator pr this pr pr while goon system err println heartbeat from hello world plugin new date try thread sleep 1000 catch interrupted exception e who cares runplugin pluginrespirator helloworld interruptedexception private final get pubkey pubkey cache public ssk store get pubkey pubkey cache this pubkey cache pubkey cache getpubkey pubkeycache sskstore getpubkey pubkeycache pubkeycache pubkeycache override public storable block construct byte data byte headers byte routing key byte full key throws ssk verify exception if data null headers null throw new ssk verify exception need data and headers if full key null throw new ssk verify exception need full key to reconstruct an ssk nodessk key key nodessk construct full key if key grab pubkey pubkey cache throw new ssk verify exception no pubkey found ssk block block new ssk block data headers key false return block storableblock routingkey fullkey sskverifyexception sskverifyexception fullkey sskverifyexception fullkey grabpubkey pubkeycache sskverifyexception sskblock sskblock public ssk block fetch nodessk chk boolean dont promote throws io exception return ssk block store fetch chk get routing key chk get full key dont promote sskblock dontpromote ioexception sskblock getroutingkey getfullkey dontpromote public void put ssk block b boolean overwrite throws io exception key collision exception nodessk key nodessk b get key store put b key get routing key key get full key b get raw data b get raw headers overwrite sskblock ioexception keycollisionexception getkey getroutingkey getfullkey getrawdata getrawheaders override public int data length return ssk block data length datalength sskblock data_length override public int full key length return nodessk full key length fullkeylength full_key_length override public int header length return ssk block total headers length headerlength sskblock total_headers_length override public int routing key length return nodessk routing key length routingkeylength routing_key_length override public boolean store full keys return true storefullkeys override public boolean collision possible return true collisionpossible override public boolean construct needs key return true constructneedskey override public byte routing key from full key byte key buf return nodessk routing key from full key key buf routingkeyfromfullkey keybuf routingkeyfromfullkey keybuf private t next public limited enumeration next null limitedenumeration public limited enumeration t loner next loner limitedenumeration public final boolean has more elements return next null hasmoreelements public final t next element if next null throw new no such element exception try return next finally next null nextelement nosuchelementexception a new list with no items public doubly linked list impl clear doublylinkedlistimpl protected doubly linked list impl t h t t int size firstitem h lastitem t t i firstitem while i null i set parent this i i get next this size size doublylinkedlistimpl _h _t _firstitem _h _lastitem _t _firstitem setparent getnext inherit doc public void clear help to detect removal after clear the check in remove is enough strictly as long as people don t add elements afterwards if firstitem null return t pos firstitem t opos while true if pos null break pos set parent null pos set prev null opos pos pos pos get next opos set next null firstitem lastitem null size 0 inheritdoc _firstitem _firstitem setparent setprev getnext setnext _firstitem _lastitem inherit doc public final int size assert size 0 firstitem null lastitem null return size inheritdoc _firstitem _lastitem inherit doc public final boolean is empty assert size 0 firstitem null lastitem null return size 0 inheritdoc isempty _firstitem _lastitem inherit doc see forward elements public final enumeration t elements return forward elements inheritdoc forwardelements forwardelements public boolean contains t item for t i this if i equals item return true return false inherit doc public final t head return size 0 null firstitem inheritdoc _firstitem inherit doc public final t tail return size 0 null lastitem inheritdoc _lastitem methods that add remove items at the head of the list inherit doc public final void unshift t i insert next null i inheritdoc insertnext inherit doc public final t shift return size 0 null remove firstitem inheritdoc _firstitem inherit doc public doubly linked list t shift int n if n size n size if n 1 return new doubly linked list impl t t i firstitem for int m 0 m n 1 m i i get next t new tail item i t new first item new tail item get next new tail item set next null doubly linked list t newlist new doubly linked list impl t firstitem new tail item n if new first item null new first item set prev null firstitem new first item else firstitem lastitem null size n return newlist inheritdoc doublylinkedlist doublylinkedlistimpl _firstitem getnext newtailitem newfirstitem newtailitem getnext newtailitem setnext doublylinkedlist doublylinkedlistimpl _firstitem newtailitem newfirstitem newfirstitem setprev _firstitem newfirstitem _firstitem _lastitem methods that add remove items at the tail of the list inherit doc public final void push t i insert prev null i inheritdoc insertprev inherit doc public final t pop return size 0 null remove lastitem inheritdoc _lastitem inherit doc public doubly linked list t pop int n if n size n size if n 1 return new doubly linked list impl t t i lastitem for int m 0 m n 1 m i i get prev t new first item i t new last item new first item get prev new first item set prev null doubly linked list t newlist new doubly linked list impl t new first item lastitem n if new last item null new last item set next null lastitem new last item else firstitem lastitem null size n return newlist inheritdoc doublylinkedlist doublylinkedlistimpl _lastitem getprev newfirstitem newlastitem newfirstitem getprev newfirstitem setprev doublylinkedlist doublylinkedlistimpl newfirstitem _lastitem newlastitem newlastitem setnext _lastitem newlastitem _firstitem _lastitem testing looking at neighbor items inherit doc public final boolean has next t i t next i get next return next null inheritdoc hasnext getnext inherit doc public final boolean has prev t i t prev i get prev return prev null inheritdoc hasprev getprev inherit doc public final t next t i t next i get next return next inheritdoc getnext inherit doc public final t prev t i t prev i get prev return prev inheritdoc getprev inherit doc public t remove t i if i get parent null is empty return null not in list if i get parent this throw new promiscuous item exception i i get parent t next i get next t prev i get prev if next null prev null only item in list assert size 1 if next null last item assert lastitem i lastitem prev else assert next get prev i next set prev prev if prev null first item assert firstitem i firstitem next else assert prev get next i prev set next next i set next null i set prev null size i set parent null return i inheritdoc getparent isempty getparent promiscuousitemexception getparent getnext getprev _lastitem _lastitem getprev setprev _firstitem _firstitem getnext setnext setnext setprev setparent inherit doc public void insert prev t i t j if j get parent null throw new promiscuous item exception j j get parent if j get next null j get prev null throw new promiscuous item exception j if i null insert as tail j set prev lastitem j set next null j set parent this if lastitem null lastitem set next j lastitem j else firstitem lastitem j size else insert in middle if i get parent null throw new promiscuous item exception i i get parent different trace to make easier debugging if i get parent this throw new promiscuous item exception i i get parent t prev i get prev if prev null if i firstitem throw new virgin item exception i firstitem j else prev set next j j set prev prev i set prev j j set next i j set parent this size inheritdoc insertprev getparent promiscuousitemexception getparent getnext getprev promiscuousitemexception setprev _lastitem setnext setparent _lastitem _lastitem setnext _lastitem _firstitem _lastitem getparent promiscuousitemexception getparent getparent promiscuousitemexception getparent getprev _firstitem virginitemexception _firstitem setnext setprev setprev setnext setparent inherit doc public void insert next t i t j if j get parent null throw new promiscuous item exception j i get parent if j get next null j get prev null throw new promiscuous item exception j if i null insert as head j set prev null j set next firstitem j set parent this if firstitem null firstitem set prev j firstitem j else firstitem lastitem j size else if i get parent this throw new promiscuous item exception i i get parent t next i get next if next null if i lastitem throw new virgin item exception i lastitem j else next set prev j j set next next i set next j j set prev i j set parent this size inheritdoc insertnext getparent promiscuousitemexception getparent getnext getprev promiscuousitemexception setprev setnext _firstitem setparent _firstitem _firstitem setprev _firstitem _firstitem _lastitem getparent promiscuousitemexception getparent getnext _lastitem virginitemexception _lastitem setprev setnext setnext setprev setparent return an enumeration of list elements from head to tail private enumeration t forward elements return new forward walker forwardelements forwardwalker return an enumeration of list elements from tail to head protected enumeration t reverse elements return new reverse walker reverseelements reversewalker private class forward walker implements enumeration t protected t next protected forward walker next firstitem forwardwalker forwardwalker _firstitem next firstitem public final boolean has more elements return next null _firstitem hasmoreelements public t next element if next null throw new no such element exception t result next next next get next return result nextelement nosuchelementexception getnext private class reverse walker implements enumeration t protected t next protected reverse walker next lastitem reversewalker reversewalker _lastitem next lastitem public final boolean has more elements return next null _lastitem hasmoreelements public t next element if next null throw new no such element exception t result next if next null throw new illegal state exception next null next next get prev return result nextelement nosuchelementexception illegalstateexception getprev public final t get next return next getnext suppress warnings unchecked public final t set next doubly linked list item i t old next next t i return old suppresswarnings setnext doublylinkedlist public final t get prev return prev getprev suppress warnings unchecked public final t set prev doubly linked list item i t old prev prev t i return old suppresswarnings setprev doublylinkedlist public doubly linked list super t get parent return list doublylinkedlist getparent public doubly linked list super t set parent doubly linked list super t l doubly linked list super t old list list l return old doublylinkedlist setparent doublylinkedlist doublylinkedlist public iterator t iterator return new iterator t private enumeration t e forward elements public boolean has next return e has more elements public t next if has next throw new no such element exception return e next element public void remove throw new unsupported operation exception forwardelements hasnext hasmoreelements hasnext nosuchelementexception nextelement unsupportedoperationexception private enumeration t e forward elements public boolean has next return e has more elements forwardelements hasnext hasmoreelements public t next if has next throw new no such element exception return e next element hasnext nosuchelementexception nextelement public void remove throw new unsupported operation exception unsupportedoperationexception scalable set storage impl storage int initial size super storage if initial size btree threshold link storage t create link initial size else set storage t create set scalableset storageimpl initialsize initialsize btree_threshold createlink initialsize createset scalable set scalableset scalable set public boolean is empty return size 0 scalableset isempty public int size return link null link size set size public void clear if link null link clear modify else set clear public boolean contains object o if o instanceof i persistent i persistent p i persistent o return link null link contains p set contains p return false ipersistent ipersistent ipersistent public object to array return link null link to array set to array toarray toarray toarray public e e to array e a return link null link e to array a set e to array a toarray toarray toarray public iterator t iterator return link null link iterator set iterator public boolean add t obj if link null if link index of obj 0 return false if link size btree threshold set get storage t create set for int i 0 n link size i n i set add link get i link null modify set add obj else modify link add obj return true else return set add obj indexof btree_threshold getstorage createset public boolean remove t o if link null if link remove o modify return true return false else return set remove o public int hash code int h 0 iterator t i iterator while i has next h i next get oid return h hashcode hasnext getoid public boolean equals object o if o this return true if o instanceof set return false collection c collection o if c size size return false return contains all c containsall public void deallocate if set null set deallocate super deallocate protected final list address matcher address matchers new array list address matcher public allowed hosts string allowed hosts set allowed hosts allowed hosts addressmatcher addressmatchers arraylist addressmatcher allowedhosts allowedhosts setallowedhosts allowedhosts sets the list of allowed hosts to code allowed hosts code the new list is in effect immediately after this method has finished param allowed hosts the new list of allowed hosts s public void set allowed hosts string allowed hosts if allowed hosts null allowed hosts equals allowed hosts network interface default bind to string tokenizer allowed hosts tokens new string tokenizer allowed hosts list address matcher new address matchers new array list address matcher while allowed hosts tokens has more tokens string allowed host allowed hosts tokens next token trim string hostname allowed host if allowed host index of 1 hostname allowed host substring 0 allowed host index of address type address type address identifier get address type hostname if address type address type i pv4 new address matchers add new inet4 address matcher allowed host else if address type address type i pv6 new address matchers add new inet6 address matcher allowed host else if allowed host equals new address matchers add new everything matcher else logger error network interface class ignoring invalid allowed host allowed host synchronized this this address matchers clear this address matchers add all new address matchers allowedhosts allowedhosts setallowedhosts allowedhosts allowedhosts allowedhosts allowedhosts networkinterface default_bind_to stringtokenizer allowedhoststokens stringtokenizer allowedhosts addressmatcher newaddressmatchers arraylist addressmatcher allowedhoststokens hasmoretokens allowedhost allowedhoststokens nexttoken allowedhost allowedhost indexof allowedhost allowedhost indexof addresstype addresstype addressidentifier getaddresstype addresstype addresstype ipv4 newaddressmatchers inet4addressmatcher allowedhost addresstype addresstype ipv6 newaddressmatchers inet6addressmatcher allowedhost allowedhost newaddressmatchers everythingmatcher networkinterface allowedhost allowedhost addressmatchers addressmatchers addall newaddressmatchers public boolean allowed inet address client address address type client address type address identifier get address type client address get host address return allowed client address type client address inetaddress clientaddress addresstype clientaddresstype addressidentifier getaddresstype clientaddress gethostaddress clientaddresstype clientaddress public synchronized boolean allowed address type client address type inet address client address for address matcher matcher address matchers if matcher matches client address return true return false addresstype clientaddresstype inetaddress clientaddress addressmatcher addressmatchers clientaddress public synchronized string get allowed hosts string builder sb new string builder for int i 0 i address matchers size i address matcher matcher address matchers get i if matcher instanceof everything matcher return if i 0 sb append sb append matcher get human representation return sb to string getallowedhosts stringbuilder stringbuilder addressmatchers addressmatcher addressmatchers everythingmatcher gethumanrepresentation tostring private float turbulence 1 public marble filter set edge action clamp marblefilter setedgeaction set the x scale of the effect param x scale the scale see getx scale public void setx scale float x scale this x scale x scale xscale getxscale setxscale xscale xscale xscale get the x scale of the effect return the scale see setx scale public float getx scale return x scale setxscale getxscale xscale set the y scale of the effect param y scale the scale see gety scale public void sety scale float y scale this y scale y scale yscale getyscale setyscale yscale yscale yscale get the y scale of the effect return the scale see sety scale public float gety scale return y scale setyscale getyscale yscale set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of effect return the amount see set amount public float get amount return amount setamount getamount specifies the turbulence of the effect param turbulence the turbulence of the effect min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the effect return the turbulence of the effect see set turbulence public float get turbulence return turbulence setturbulence getturbulence private void initialize sin table new float 256 cos table new float 256 for int i 0 i 256 i float angle image math two pi i 256f turbulence sin table i float y scale math sin angle cos table i float y scale math cos angle sintable costable imagemath two_pi sintable yscale costable yscale private int displacement map int x int y return pixel utils clamp int 127 1 noise noise2 x x scale y x scale displacementmap pixelutils xscale xscale override protected void transform inverse int x int y float out int displacement displacement map x y out 0 x sin table displacement out 1 y cos table displacement transforminverse displacementmap sintable costable override public buffered image filter buffered image src buffered image dst initialize return super filter src dst bufferedimage bufferedimage bufferedimage override public string to string return distort marble tostring creates a new own identities page param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public own identities page web interface my web interface http request my request super my web interface my request ownidentitiespage mywebinterface webinterface myrequest ownidentitiespage webinterface mywebinterface httprequest myrequest mywebinterface myrequest public void make if request is part set restore identity try wot restore identity request get part as string requesturi 1024 request get part as string inserturi 1024 html node restore box add content box restoring is in progress restore box add child p please don t use that identity set trust edit parameters etc until it has been restored from freenet your changes will be overwritten by the old settings which are downloaded from freenet catch exception e add error box restoring the identity failed e get message synchronized wot make own identities list make restore own identity form ispartset restoreidentity restoreidentity getpartasstring getpartasstring htmlnode restorebox addcontentbox restorebox addchild adderrorbox getmessage makeownidentitieslist makerestoreownidentityform private void make own identities list html node box content add content box summary object set own identity own identities wot get all own identities if own identities size 0 box content add child p you have no own identity yet you should create one else html node identities table box content add child table border 0 html node row identities table add child tr row add child th name row add child th last change row add child th last insert row add child th publishes trustlist row add child th trusters row add child th manage while own identities has next own identity id own identities next row identities table add child tr row add child td new string title style align new string id get requesturi to string cursor help center id get nickname synchronized m date format m date format set time zone time zone get default simple date format format date in utc does convert to the configured time zone interesting eh row add child td m date format format id get last change date html node cell row add child td new string align new string center if id get last insert date equals new date 0 cell add child p never else synchronized m date format m date format set time zone time zone get default simple date format format date in utc does convert to the configured time zone interesting eh cell add child new html node a href id get requesturi to string m date format format id get last insert date row add child td new string align new string center id does publish trust list yes no html node trusters cell row add child td new string align new string center trusters cell add child new html node a href uri show identity id id getid long to string wot get received trusts id size html node manage cell row add child td new string align new string center html node edit form pr add form child manage cell uri edit identity edit form add child input new string type name value new string hidden page edit identity edit form add child input new string type name value new string hidden id id getid edit form add child input new string type name value new string submit edit edit html node delete form pr add form child manage cell uri delete identity delete form add child input new string type name value new string hidden page delete identity delete form add child input new string type name value new string hidden id id getid delete form add child input new string type name value new string submit delete delete html node introduce form pr add form child manage cell uri introduce identity introduce form add child input new string type name value new string hidden page introduce identity introduce form add child input new string type name value new string hidden id id getid introduce form add child input new string type name value new string submit introduce introduce html node create form pr add form child box content uri create identity create form add child input new string type name value new string hidden page create identity create form add child span new string title style new string no spaces or special characters border bottom 1px dotted cursor help nickname create form add child input new string type name size new string text nickname 30 create form add child input new string type name value new string submit create create makeownidentitieslist htmlnode boxcontent addcontentbox objectset ownidentity ownidentities getallownidentities ownidentities boxcontent addchild htmlnode identitiestable boxcontent addchild htmlnode identitiestable addchild addchild addchild addchild addchild addchild addchild ownidentities hasnext ownidentity ownidentities identitiestable addchild addchild getrequesturi tostring getnickname mdateformat mdateformat settimezone timezone getdefault simpledateformat timezone addchild mdateformat getlastchangedate htmlnode addchild getlastinsertdate addchild mdateformat mdateformat settimezone timezone getdefault simpledateformat timezone addchild htmlnode getrequesturi tostring mdateformat getlastinsertdate addchild doespublishtrustlist htmlnode trusterscell addchild trusterscell addchild htmlnode showidentity tostring getreceivedtrusts htmlnode managecell addchild htmlnode editform addformchild managecell editidentity editform addchild editidentity editform addchild editform addchild htmlnode deleteform addformchild managecell deleteidentity deleteform addchild deleteidentity deleteform addchild deleteform addchild htmlnode introduceform addformchild managecell introduceidentity introduceform addchild introduceidentity introduceform addchild introduceform addchild htmlnode createform addformchild boxcontent createidentity createform addchild createidentity createform addchild createform addchild createform addchild makes the form used to restore an own identity from freenet private void make restore own identity form html node restore box content add content box restore an identity from freenet restore box content add child p use this if you lost your database for some reason but still have your identity s keys html node restore form pr add form child restore box content uri restore identity restore form add child input new string type name value new string hidden page restore identity restore form add child input new string type name size value new string text requesturi 70 request uri restore form add child br restore form add child input new string type name size value new string text inserturi 70 inserturi restore form add child br restore form add child input new string type name value new string submit restore identity restore ownidentity makerestoreownidentityform htmlnode restoreboxcontent addcontentbox restoreboxcontent addchild htmlnode restoreform addformchild restoreboxcontent restoreidentity restoreform addchild restoreidentity restoreform addchild restoreform addchild restoreform addchild restoreform addchild restoreform addchild restoreidentity public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception if data size 6 throw header error l10n too short title l10n too short input stream is data get input stream buffered input stream bis new buffered input stream is data input stream dis new data input stream bis try check the header byte header check new byte header size dis read fully header check if arrays equals header check gif87a header arrays equals header check gif89a header throw header error l10n invalid header title l10n invalid header dis close finally closer close dis return data readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception throwheadererror tooshorttitle tooshort inputstream getinputstream bufferedinputstream bufferedinputstream datainputstream datainputstream headercheck header_size readfully headercheck headercheck gif87aheader headercheck gif89aheader throwheadererror invalidheadertitle invalidheader private static string l10n string key return l10n get string gif filter key getstring giffilter private void throw header error string short reason string reason throws data filter exception throw an exception string message l10n not gif if reason null message reason if short reason null message short reason throw new data filter exception short reason short reason p message p new html node p add child message throwheadererror shortreason datafilterexception notgif shortreason shortreason datafilterexception shortreason shortreason htmlnode addchild public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception return null writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception public final object token public bulk call failure item low level get exception e object token this e e this token token bulkcallfailureitem lowlevelgetexception private static final long serial versionuid 796276279268900609l public crypt format exception string message super message serialversionuid cryptformatexception public crypt format exception io exception e super e get message init cause e cryptformatexception ioexception getmessage initcause text mode client interface server node node node client core core int port string bind to string allowed hosts throws io exception this n node this core n client core this r n random this downloads dir core download dir this port port this bind to bind to this allowed hosts allowed hosts this is enabled true if ssl network interface ssl network interface create port bind to allowed hosts n executor true else network interface network interface create port bind to allowed hosts n executor true textmodeclientinterfaceserver nodeclientcore bindto allowedhosts ioexception clientcore downloadsdir downloaddir bindto bindto allowedhosts allowedhosts isenabled networkinterface sslnetworkinterface bindto allowedhosts networkinterface networkinterface bindto allowedhosts void start logger normal core tmci started on network interface get allowed hosts port system out println tmci started on network interface get allowed hosts port n executor execute this text mode client interface networkinterface getallowedhosts networkinterface getallowedhosts public static text mode client interface server maybe create node node node client core core config config throws io exception text mode client interface server server null sub config tmci config new sub config console config tmci config register enabled false 1 true true fixme only because can t be changed on the fly text mode client interface server enabled text mode client interface server enabled long new tmci enabled callback core tmci config register ssl false 1 true true text mode client interface server ssl text mode client interface server ssl long new tmcissl callback tmci config register bind to network interface default bind to 2 true false text mode client interface server bind to text mode client interface server bind to long new tmci bindto callback core tmci config register allowed hosts network interface default bind to 2 true false text mode client interface server allowed hosts text mode client interface server allowed hosts long new tmci allowed hosts callback core tmci config register port 2323 1 true false text mode client interface server telnet port number text mode client interface server telnet port number long new tcmi port number callback core false tmci config register direct enabled false 1 true false text mode client interface server enable input output text mode client interface server enable input output long new tmci direct enabled callback core boolean tmci enabled tmci config get boolean enabled int port tmci config get int port string bind ip tmci config get string bind to string allowed hosts tmci config get string allowed hosts boolean direct tmci config get boolean direct enabled if ssl available ssl tmci config get boolean ssl if tmci enabled server new text mode client interface server node core port bind ip allowed hosts if direct high level simple client client core make client request starter interactive priority class true text mode client interface directtmci new text mode client interface node client core download dir system in system out node executor execute directtmci direct text mode interface core set directtmci directtmci tmci config finished initialization return server caller must call start textmodeclientinterfaceserver maybecreate nodeclientcore ioexception textmodeclientinterfaceserver subconfig tmciconfig subconfig tmciconfig textmodeclientinterfaceserver textmodeclientinterfaceserver enabledlong tmcienabledcallback tmciconfig textmodeclientinterfaceserver textmodeclientinterfaceserver ssllong tmcisslcallback tmciconfig bindto networkinterface default_bind_to textmodeclientinterfaceserver bindto textmodeclientinterfaceserver bindtolong tmcibindtocallback tmciconfig allowedhosts networkinterface default_bind_to textmodeclientinterfaceserver allowedhosts textmodeclientinterfaceserver allowedhostslong tmciallowedhostscallback tmciconfig textmodeclientinterfaceserver telnetportnumber textmodeclientinterfaceserver telnetportnumberlong tcmiportnumbercallback tmciconfig directenabled textmodeclientinterfaceserver enableinputoutput textmodeclientinterfaceserver enableinputoutputlong tmcidirectenabledcallback tmcienabled tmciconfig getboolean tmciconfig getint bind_ip tmciconfig getstring bindto allowedhosts tmciconfig getstring allowedhosts tmciconfig getboolean directenabled tmciconfig getboolean tmcienabled textmodeclientinterfaceserver bind_ip allowedhosts highlevelsimpleclient makeclient requeststarter interactive_priority_class textmodeclientinterface textmodeclientinterface downloaddir setdirecttmci tmciconfig finishedinitialization final node client core core tmci enabled callback node client core core this core core nodeclientcore tmcienabledcallback nodeclientcore override public boolean get return core get text mode client interface null gettextmodeclientinterface override public void set boolean val throws invalid config value exception if get equals val return fixme implement see bug 122 throw new invalid config value exception cannot be updated on the fly invalidconfigvalueexception invalidconfigvalueexception throw new invalid config value exception cannot be updated on the fly override public boolean is read only return true invalidconfigvalueexception isreadonly static class tmcissl callback extends boolean callback override public boolean get return ssl tmcisslcallback booleancallback override public void set boolean val throws invalid config value exception if get equals val return if ssl available throw new invalid config value exception enable ssl support before use ssl with tmci ssl val throw new invalid config value exception cannot change ssl on the fly please restart freenet invalidconfigvalueexception invalidconfigvalueexception invalidconfigvalueexception throw new invalid config value exception cannot change ssl on the fly please restart freenet override public boolean is read only return true invalidconfigvalueexception isreadonly final node client core core tmci direct enabled callback node client core core this core core nodeclientcore tmcidirectenabledcallback nodeclientcore override public boolean get return core get directtmci null getdirecttmci override public void set boolean val throws invalid config value exception if get equals val return fixme implement see bug 122 throw new invalid config value exception cannot be updated on the fly invalidconfigvalueexception invalidconfigvalueexception throw new invalid config value exception cannot be updated on the fly override public boolean is read only return true invalidconfigvalueexception isreadonly final node client core core tmci bindto callback node client core core this core core nodeclientcore tmcibindtocallback nodeclientcore override public string get if core get text mode client interface null return core get text mode client interface bind to else return network interface default bind to gettextmodeclientinterface gettextmodeclientinterface bindto networkinterface default_bind_to override public void set string val throws invalid config value exception if val equals get return try core get text mode client interface network interface set bind to val false core get text mode client interface bind to val catch io exception e throw new invalid config value exception could not change bind to invalidconfigvalueexception gettextmodeclientinterface networkinterface setbindto gettextmodeclientinterface bindto ioexception invalidconfigvalueexception private final node client core core public tmci allowed hosts callback node client core core this core core nodeclientcore tmciallowedhostscallback nodeclientcore override public string get if core get text mode client interface null return core get text mode client interface allowed hosts return network interface default bind to gettextmodeclientinterface gettextmodeclientinterface allowedhosts networkinterface default_bind_to override public void set string val throws invalid config value exception if val equals get text mode client interface server server core get text mode client interface if server null server network interface set allowed hosts val server allowed hosts val else throw new invalid config value exception setting allowed hosts for tmci console server when tmci is disabled invalidconfigvalueexception textmodeclientinterfaceserver gettextmodeclientinterface networkinterface setallowedhosts allowedhosts invalidconfigvalueexception allowedhosts final node client core core tcmi port number callback node client core core this core core nodeclientcore tcmiportnumbercallback nodeclientcore override public integer get if core get text mode client interface null return core get text mode client interface port else return 2323 gettextmodeclientinterface gettextmodeclientinterface todo implement it override public void set integer val throws invalid config value exception if get equals val return core get text mode client interface set port val invalidconfigvalueexception gettextmodeclientinterface setport read commands run them public void run freenet support logger os thread logpid this while true int cur port port string temp bind to this bind to try network interface set so timeout 1000 catch socket exception e1 logger error this could not set timeout e1 e1 system err println could not start tmci e1 e1 print stack trace return while is enabled maybe something has changed if port cur port break if this bind to equals temp bind to break try socket s network interface accept if s null continue timeout input stream in s get input stream output stream out s get output stream text mode client interface tmci new text mode client interface this in out n executor execute tmci text mode client interface handler for s get port catch socket exception e logger error this socket error e e catch io exception e logger error this tmci failed to accept socket e e try network interface close catch io exception e logger error this error shuting down tmci e osthread curport tempbindto bindto networkinterface setsotimeout socketexception printstacktrace isenabled curport bindto tempbindto networkinterface inputstream getinputstream outputstream getoutputstream textmodeclientinterface textmodeclientinterface getport socketexception ioexception networkinterface ioexception public void set port int val port val setport create a new simple event producer public simple event producer listeners new vector client event listener simpleeventproducer simpleeventproducer clienteventlistener create a new simple event producer with the given listeners public simple event producer client event listener cela this for int i 0 i cela length i add event listener cela i simpleeventproducer simpleeventproducer clienteventlistener addeventlistener public void add event listener client event listener cel if cel null listeners add element cel else throw new illegal argument exception adding a null listener addeventlistener clienteventlistener addelement illegalargumentexception public boolean remove event listener client event listener cel boolean b listeners remove element cel listeners trim to size return b removeeventlistener clienteventlistener removeelement trimtosize sends the client event to all registered listeners of this object public void produce event client event ce object container container client context context if container null container activate listeners 1 for enumeration client event listener e listeners elements e has more elements try client event listener cel e next element if container null container activate cel 1 cel receive ce container context catch no such element exception ne logger normal this concurrent modification in produce event this catch exception ue system err println unexpected exception ue print stack trace system err println clientevent produceevent clientevent objectcontainer clientcontext clienteventlistener hasmoreelements clienteventlistener nextelement nosuchelementexception produceevent printstacktrace returns the listeners as an array public client event listener get event listeners client event listener ret new client event listener listeners size listeners copy into ret return ret clienteventlistener geteventlisteners clienteventlistener clienteventlistener copyinto adds all listeners in the given array public void add event listeners client event listener cela for int i 0 i cela length i add event listener cela i addeventlisteners clienteventlistener addeventlistener public void remove from object container container if container null container activate listeners 1 client event listener list listeners to array new client event listener listeners size listeners clear container delete listeners for int i 0 i list length i list i on remove event producer container container delete this removefrom objectcontainer clienteventlistener toarray clienteventlistener onremoveeventproducer update catastrophe exception file old config file new config super l10n update catastrophe new string old new new string old config to string new config to string this old config old config this new config new config updatecatastropheexception oldconfig newconfig updatecatastrophe oldconfig tostring newconfig tostring oldconfig oldconfig newconfig newconfig update deploy context throws updater parser exception properties p wrapper manager get properties for int prop no 1 true prop no string prop p get property wrapper java classpath prop no if prop null break file f new file prop boolean is absolute f is absolute string name f get name to lower case if ext jar null if name equals freenet ext jar new ext jar f new ext jar new file ext jar get parent freenet ext jar ext jar absolute is absolute ext classpath no prop no continue else if name equals freenet ext jar ext jar f new ext jar new file ext jar get parent freenet ext jar new ext classpath no prop no continue if main jar null try to match it if name starts with freenet name ends with jar main jar f new main jar new file main jar get parent freenet jar new main jar absolute is absolute main classpath no prop no continue else if name starts with freenet name ends with jar new main jar f new main jar new file main jar get parent freenet jar main jar absolute is absolute main classpath no prop no continue if main jar null ext jar null throw new updater parser exception l10n cannot update no jars if main jar null throw new updater parser exception l10n cannot update no main jar ext filename ext jar to string if ext jar null throw new updater parser exception l10n cannot update no ext jar main filename main jar to string updatedeploycontext updaterparserexception wrappermanager getproperties propno propno getproperty propno isabsolute isabsolute getname tolowercase extjar extjar newextjar extjar getparent extjarabsolute isabsolute extclasspathno propno extjar newextjar extjar getparent extclasspathno propno mainjar startswith endswith mainjar newmainjar mainjar getparent mainjarabsolute isabsolute mainclasspathno propno startswith endswith mainjar newmainjar mainjar getparent mainjarabsolute isabsolute mainclasspathno propno mainjar extjar updaterparserexception cannotupdatenojars mainjar updaterparserexception cannotupdatenomainjar extfilename extjar tostring extjar updaterparserexception cannotupdatenoextjar mainfilename mainjar tostring private string l10n string key return l10n get string update deploy context key getstring updatedeploycontext public static string l10n string key string patterns string values return l10n get string update deploy context key patterns values getstring updatedeploycontext public static string l10n string key string pattern string value return l10n get string update deploy context key pattern value getstring updatedeploycontext file get main jar return main jar getmainjar mainjar file get new main jar return new main jar getnewmainjar newmainjar file get ext jar return ext jar getextjar extjar file get new ext jar return new ext jar getnewextjar newextjar void rewrite wrapper conf boolean written new jar boolean written new ext throws io exception update catastrophe exception updater parser exception rewrite wrapper conf don t just write it out from properties we want to keep it as close to what it was as possible file old config new file wrapper conf file new config new file wrapper conf new file input stream fis new file input stream old config buffered input stream bis new buffered input stream fis input stream reader isr new input stream reader bis buffered reader br new buffered reader isr file output stream fos new file output stream new config output stream writer osw new output stream writer fos buffered writer bw new buffered writer osw string line boolean written main false boolean written ext false boolean written reload false string new main main jar absolute new main jar get absolute path new main jar get path string new ext ext jar absolute new ext jar get absolute path new ext jar get path while line br read line null if line starts with wrapper java classpath if written new jar line starts with wrapper java classpath main classpath no bw write wrapper java classpath main classpath no new main n system err println rewritten wrapper conf for main jar written main true else if written new ext line starts with wrapper java classpath ext classpath no bw write wrapper java classpath ext classpath no new ext n system err println rewritten wrapper conf for ext jar written ext true else bw write line n else if line equals ignore case wrapper restart reload configuration true written reload true bw write line n else bw write line n br close if written main written new jar written ext written new ext throw new updater parser exception l10n update failed non standard config new string main ext new string boolean to string written main boolean to string written ext if written reload add it bw write wrapper restart reload configuration true bw close if new config rename to old config if old config delete throw new updater parser exception l10n update failed cannot delete old config old old config to string if new config rename to old config throw new update catastrophe exception old config new config new config installed system err println rewritten wrapper conf for written new jar new main jar new main jar written new ext new ext jar new ext jar rewritewrapperconf writtennewjar writtennewext ioexception updatecatastropheexception updaterparserexception oldconfig newconfig fileinputstream fileinputstream oldconfig bufferedinputstream bufferedinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader fileoutputstream fileoutputstream newconfig outputstreamwriter outputstreamwriter bufferedwriter bufferedwriter writtenmain writtenext writtenreload newmain mainjarabsolute newmainjar getabsolutepath newmainjar getpath newext extjarabsolute newextjar getabsolutepath newextjar getpath readline startswith writtennewjar startswith mainclasspathno mainclasspathno newmain writtenmain writtennewext startswith extclasspathno extclasspathno newext writtenext equalsignorecase reload_configuration writtenreload writtenmain writtennewjar writtenext writtennewext updaterparserexception updatefailednonstandardconfig tostring writtenmain tostring writtenext writtenreload reload_configuration newconfig renameto oldconfig oldconfig updaterparserexception updatefailedcannotdeleteoldconfig oldconfig tostring newconfig renameto oldconfig updatecatastropheexception oldconfig newconfig writtennewjar newmainjar writtennewext newextjar public static address tracker create long last bootid file node dir int port file data new file node dir packets port dat file data bak new file node dir packets port bak data bak delete file input stream fis null try fis new file input stream data buffered input stream bis new buffered input stream fis input stream reader ir new input stream reader bis utf 8 buffered reader br new buffered reader ir simple field set fs new simple field set br false true return new address tracker fs last bootid catch io exception e fall through catch fs parse exception e logger error address tracker class failed to load from disk for port port e e fall through finally if fis null try fis close catch io exception e ignore return new address tracker addresstracker lastbootid nodedir nodedir databak nodedir databak fileinputstream fileinputstream bufferedinputstream bufferedinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader simplefieldset simplefieldset addresstracker lastbootid ioexception fsparseexception addresstracker ioexception addresstracker private address tracker time definitely no packets received system current time millis time definitely no packets sent system current time millis peer trackers new hash map peer peer address tracker item ip trackers new hash map inet address inet address address tracker item addresstracker timedefinitelynopacketsreceived currenttimemillis timedefinitelynopacketssent currenttimemillis peertrackers hashmap peeraddresstrackeritem iptrackers hashmap inetaddress inetaddressaddresstrackeritem private address tracker simple field set fs long last bootid throws fs parse exception int version fs get int version if version 1 throw new fs parse exception unknown version version long saved bootid fs get long bootid if saved bootid last bootid throw new fs parse exception wrong boot id maybe unclean shutdown last was last bootid stored saved bootid sadly we don t know whether there were packets arriving during the gap and some insecure firewalls will use incoming packets to keep tunnels open time definitely no packets received fs get long time definitely no packets received time definitely no packets received system current time millis time definitely no packets sent fs get long time definitely no packets sent peer trackers new hash map peer peer address tracker item simple field set peers fs subset peers if peers null iterator string i peers direct subset name iterator if i null while i has next simple field set peer peers subset i next peer address tracker item item new peer address tracker item peer peer trackers put item peer item ip trackers new hash map inet address inet address address tracker item simple field set ips fs subset i ps if ips null iterator string i ips direct subset name iterator if i null while i has next simple field set peer ips subset i next inet address address tracker item item new inet address address tracker item peer ip trackers put item addr item addresstracker simplefieldset lastbootid fsparseexception getint fsparseexception savedbootid getlong savedbootid lastbootid fsparseexception lastbootid savedbootid timedefinitelynopacketsreceived getlong timedefinitelynopacketsreceived timedefinitelynopacketsreceived currenttimemillis timedefinitelynopacketssent getlong timedefinitelynopacketssent peertrackers hashmap peeraddresstrackeritem simplefieldset directsubsetnameiterator hasnext simplefieldset peeraddresstrackeritem peeraddresstrackeritem peertrackers iptrackers hashmap inetaddress inetaddressaddresstrackeritem simplefieldset ips directsubsetnameiterator hasnext simplefieldset inetaddressaddresstrackeritem inetaddressaddresstrackeritem iptrackers public void sent packet to peer peer packet to peer true sentpacketto packetto public void received packet from peer peer packet to peer false receivedpacketfrom packetto private void packet to peer peer boolean sent peer peer2 peer drop host name if peer2 null logger error this impossible no host name in address tracker packet to for peer return peer peer2 inet address ip peer get address long now system current time millis synchronized this peer address tracker item peer item peer trackers get peer if peer item null peer item new peer address tracker item time definitely no packets received time definitely no packets sent peer if peer trackers size max items peer trackers clear ip trackers clear time definitely no packets received now time definitely no packets sent now peer trackers put peer peer item if sent peer item sent packet now else peer item received packet now inet address address tracker item ip item ip trackers get ip if ip item null ip item new inet address address tracker item time definitely no packets received time definitely no packets sent ip if ip trackers size max items peer trackers clear ip trackers clear time definitely no packets received now time definitely no packets sent now ip trackers put ip ip item if sent ip item sent packet now else ip item received packet now packetto drophostname addresstracker packetto inetaddress getaddress currenttimemillis peeraddresstrackeritem peeritem peertrackers peeritem peeritem peeraddresstrackeritem timedefinitelynopacketsreceived timedefinitelynopacketssent peertrackers max_items peertrackers iptrackers timedefinitelynopacketsreceived timedefinitelynopacketssent peertrackers peeritem peeritem sentpacket peeritem receivedpacket inetaddressaddresstrackeritem ipitem iptrackers ipitem ipitem inetaddressaddresstrackeritem timedefinitelynopacketsreceived timedefinitelynopacketssent iptrackers max_items peertrackers iptrackers timedefinitelynopacketsreceived timedefinitelynopacketssent iptrackers ipitem ipitem sentpacket ipitem receivedpacket public synchronized void start receive long now time definitely no packets received now startreceive timedefinitelynopacketsreceived public synchronized void start send long now time definitely no packets sent now startsend timedefinitelynopacketssent public synchronized peer address tracker item get peer address tracker items peer address tracker item items new peer address tracker item peer trackers size return peer trackers values to array items peeraddresstrackeritem getpeeraddresstrackeritems peeraddresstrackeritem peeraddresstrackeritem peertrackers peertrackers toarray public synchronized inet address address tracker item get inet address tracker items inet address address tracker item items new inet address address tracker item ip trackers size return ip trackers values to array items inetaddressaddresstrackeritem getinetaddresstrackeritems inetaddressaddresstrackeritem inetaddressaddresstrackeritem iptrackers iptrackers toarray public static final long horizon 24 60 60 1000l public long get longest send receive gap return get longest send receive gap horizon getlongestsendreceivegap getlongestsendreceivegap find the longest send known no packets sent receive gap it is highly unlikely that we are behind a nat or symmetric firewall with a timeout less than the returned length public long get longest send receive gap long horizon long longest gap 1 long now system current time millis peer address tracker item items get peer address tracker items for int i 0 i items length i peer address tracker item item items i if item packets received 0 continue if item peer is real internet address false false false continue longest gap math max longest gap item longest gap horizon now return longest gap getlongestsendreceivegap longestgap currenttimemillis peeraddresstrackeritem getpeeraddresstrackeritems peeraddresstrackeritem packetsreceived isrealinternetaddress longestgap longestgap longestgap longestgap public int get port forward status long min gap get longest send receive gap horizon if min gap definitely tunnel length return definitely port forwarded if min gap maybe tunnel length return maybe port forwarded only take is broken into account if we re not sure somebody could be playing with us by sending bogus fnp sent packets synchronized this if is broken return definitely nated if min gap 0 time presume guilty 0 system current time millis time presume guilty return maybe nated return dont know getportforwardstatus mingap getlongestsendreceivegap mingap definitely_tunnel_length definitely_port_forwarded mingap maybe_tunnel_length maybe_port_forwarded isbroken fnpsentpackets isbroken definitely_nated mingap timepresumeguilty currenttimemillis timepresumeguilty maybe_nated dont_know private boolean is broken return system current time millis broken time horizon isbroken currenttimemillis brokentime public static string status string int status switch status case definitely port forwarded return port forwarded case maybe port forwarded return maybe port forwarded case maybe nated return maybe behind nat case definitely nated return behind nat case dont know return status unknown default return error statusstring definitely_port_forwarded maybe_port_forwarded maybe_nated definitely_nated dont_know persist the table to disk public void store data long bootid file node dir int port don t write to disk if we know we re na ted anyway if is broken return file data new file node dir packets port dat file data bak new file node dir packets port bak data delete data bak delete file output stream fos null try fos new file output stream data bak buffered output stream bos new buffered output stream fos output stream writer osw new output stream writer bos utf 8 buffered writer bw new buffered writer osw simple field set fs get fieldset bootid fs write to bw bw flush bw close fos null data bak rename to data catch io exception e logger error this cannot store packet tracker to disk return finally if fos null try fos close catch io exception e ignore storedata nodedir nated isbroken nodedir databak nodedir databak fileoutputstream fileoutputstream databak bufferedoutputstream bufferedoutputstream outputstreamwriter outputstreamwriter bufferedwriter bufferedwriter simplefieldset getfieldset writeto databak renameto ioexception ioexception private synchronized simple field set get fieldset long bootid simple field set sfs new simple field set true sfs put version 1 sfs put bootid bootid sfs put time definitely no packets received time definitely no packets received sfs put time definitely no packets sent time definitely no packets sent peer address tracker item peer items get peer address tracker items simple field set items new simple field set true if peer items length 0 for int i 0 i peer items length i items put integer to string i peer items i to field set sfs put peers items inet address address tracker item inet items get inet address tracker items items new simple field set true if inet items length 0 for int i 0 i inet items length i items put integer to string i inet items i to field set sfs put i ps items return sfs simplefieldset getfieldset simplefieldset simplefieldset timedefinitelynopacketsreceived timedefinitelynopacketsreceived timedefinitelynopacketssent timedefinitelynopacketssent peeraddresstrackeritem peeritems getpeeraddresstrackeritems simplefieldset simplefieldset peeritems peeritems tostring peeritems tofieldset inetaddressaddresstrackeritem inetitems getinetaddresstrackeritems simplefieldset inetitems inetitems tostring inetitems tofieldset ips called when something changes at a higher level suggesting that the status may be wrong public void rescan do nothing for now as we don t maintain any final state yet public synchronized void set broken broken time system current time millis setbroken brokentime currenttimemillis private long time presume guilty 1 public synchronized void set presumed guilty at long l if time presume guilty 0 time presume guilty l timepresumeguilty setpresumedguiltyat timepresumeguilty timepresumeguilty public synchronized void set presumed innocent time presume guilty 1 setpresumedinnocent timepresumeguilty public final class subtract composite extends rgb composite public subtract composite float alpha super alpha subtractcomposite rgbcomposite subtractcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr if dor 0 dor 0 dog dig sg if dog 0 dog 0 dob dib sb if dob 0 dob 0 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac if you want persistent buckets which will be saved every 1000 buckets and deleted on restart if not stored by then then pass in the db job runner otherwise pass in null param bucket factory param block size param runner public bucket chain bucket factory bucket factory bucket factory int block size db job runner runner int segment size this factory bucket factory this block size block size this runner runner this segment size segment size dbjobrunner bucketfactory block_size bucketchainbucketfactory bucketfactory bucketfactory block_size dbjobrunner segmentsize bucketfactory blocksize block_size segmentsize segmentsize public bucket make bucket long size throws io exception if runner null return new bucket chain bucket block size factory else return new segmented bucket chain bucket block size factory runner segment size makebucket ioexception bucketchainbucket blocksize segmentedbucketchainbucket blocksize segmentsize public get config simple field set fs with current fields string to bool fs get with current false with defaults fields string to bool fs get with defaults false with sort order fields string to bool fs get with sort order false with expert flag fields string to bool fs get with expert flag false with force write flag fields string to bool fs get with force write flag false with short description fields string to bool fs get with short description false with long description fields string to bool fs get with long description false with data types fields string to bool fs get with data types false this identifier fs get identifier fs remove value identifier getconfig simplefieldset withcurrent stringtobool withcurrent withdefaults stringtobool withdefaults withsortorder stringtobool withsortorder withexpertflag stringtobool withexpertflag withforcewriteflag stringtobool withforcewriteflag withshortdescription stringtobool withshortdescription withlongdescription stringtobool withlongdescription withdatatypes stringtobool withdatatypes removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied get config requires full access identifier false handler output handler queue new config data node with current with defaults with sort order with expert flag with force write flag with short description with long description with data types identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied getconfig outputhandler configdata withcurrent withdefaults withsortorder withexpertflag withforcewriteflag withshortdescription withlongdescription withdatatypes override public void remove from object container container container delete this removefrom objectcontainer logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog final object token running transient insert sendable insert i object t insert i token t runningtransientinsert sendableinsert override public int hash code return insert hash code token hash code hashcode hashcode hashcode override public boolean equals object o if o instanceof running transient insert return false running transient insert r running transient insert o return r insert insert r token token r token equals token runningtransientinsert runningtransientinsert runningtransientinsert fetch a client request scheduler core from the database or create a new one param node param for inserts param forss ks param selector container param executor return public static client request scheduler core create node node final boolean for inserts final boolean forss ks object container selector container long cooldown time prioritized serial executor database executor client request scheduler sched client context context final long nodedb handle node nodedb handle object set client request scheduler core results selector container query new predicate client request scheduler core override public boolean match client request scheduler core core if core nodedb handle nodedb handle return false if core is insert scheduler for inserts return false if core isssk scheduler forss ks return false return true client request scheduler core core if results has next core results next selector container activate core 2 system err println loaded core if core nodedb handle nodedb handle throw new illegal state exception wrong nodedb handle if core is insert scheduler for inserts throw new illegal state exception wrong is insert scheduler if core isssk scheduler forss ks throw new illegal state exception wrong forss ks else core new client request scheduler core node for inserts forss ks selector container cooldown time selector container store core system err println created new core core on started selector container cooldown time sched context return core clientrequestschedulercore forinserts forssks selectorcontainer clientrequestschedulercore forinserts forssks objectcontainer selectorcontainer cooldowntime prioritizedserialexecutor databaseexecutor clientrequestscheduler clientcontext nodedbhandle nodedbhandle objectset clientrequestschedulercore selectorcontainer clientrequestschedulercore clientrequestschedulercore nodedbhandle nodedbhandle isinsertscheduler forinserts issskscheduler forssks clientrequestschedulercore hasnext selectorcontainer nodedbhandle nodedbhandle illegalstateexception nodedbhandle isinsertscheduler forinserts illegalstateexception isinsertscheduler issskscheduler forssks illegalstateexception forssks clientrequestschedulercore forinserts forssks selectorcontainer cooldowntime selectorcontainer onstarted selectorcontainer cooldowntime client request scheduler core node node boolean for inserts boolean forss ks object container selector container long cooldown time super for inserts forss ks this nodedb handle node nodedb handle if for inserts this persistent cooldown queue new persistent cooldown queue else this persistent cooldown queue null global salt new byte 32 node random next bytes global salt clientrequestschedulercore forinserts forssks objectcontainer selectorcontainer cooldowntime forinserts forssks nodedbhandle nodedbhandle forinserts persistentcooldownqueue persistentcooldownqueue persistentcooldownqueue globalsalt nextbytes globalsalt private void on started object container container long cooldown time client request scheduler sched client context context super on started system err println insert scheduler is insert scheduler if is insert scheduler persistent cooldown queue set cooldown time cooldown time this sched sched this init time system current time millis we do not want to rerun the query after consuming the initial set if is insert scheduler keys fetching new hash set key running transient inserts null this recent successes new array list random grab array else keys fetching null running transient inserts new hash set running transient insert if is insert scheduler pre register me runner new db job public void run object container container client context context synchronized client request scheduler core this if register me set null return long t start system current time millis fixme redflag evil db4o bug fixme verify and file a bug this code doesn t check the first bit i think this is related to the comparator register me set container query new predicate public boolean match register me reg if reg core client request scheduler core this return false if reg key added time init time return false return true new comparator public int compare object arg0 object arg1 register me reg0 register me arg0 register me reg1 register me arg1 register me sort key key0 reg0 key register me sort key key1 reg1 key return key0 compare to key1 object set results null for int i request starter maximum priority class i request starter minimum priority class i query query container query query constrain register me class query descend core constrain client request scheduler core this and query descend priority constrain i results query execute if results has next break else results null if results null return this throws not supported query descend core constrain this identity and query descend key descend added time constrain new long init time smaller fixme db4o db4o says it has indexed core but then when we try to query it produces a diagnostic suggesting we index it and of course the query takes ages and uses tons of ram so don t try to filter by core at this point deal with that later query descend core constrain client request scheduler core this evaluation eval new evaluation public void evaluate candidate candidate register me reg register me candidate get object if reg key added time init time reg core client request scheduler core this candidate include false candidate object container deactivate reg key 1 candidate object container deactivate reg 1 else candidate include true query constrain eval query descend key descend priority order ascending query descend key descend added time order ascending synchronized client request scheduler core this register me set results long t end system current time millis if logminor logger minor this register me query took t end t start has next register me set has next for insert is insert scheduler ssk isssk scheduler if logminor logger minor this register me query returned register me set size boolean boost client request scheduler core this sched is queue almost empty context job runner queue register me runner native thread norm priority 1 boost 1 0 true register me runner new register me runner onstarted objectcontainer cooldowntime clientrequestscheduler clientcontext onstarted isinsertscheduler isinsertscheduler persistentcooldownqueue setcooldowntime cooldowntime inittime currenttimemillis isinsertscheduler keysfetching hashset runningtransientinserts recentsuccesses arraylist randomgrabarray keysfetching runningtransientinserts hashset runningtransientinsert isinsertscheduler preregistermerunner dbjob objectcontainer clientcontext clientrequestschedulercore registermeset tstart currenttimemillis registermeset registerme clientrequestschedulercore addedtime inittime registerme registerme registerme registerme registermesortkey registermesortkey compareto objectset requeststarter maximum_priority_class requeststarter minimum_priority_class registerme clientrequestschedulercore hasnext notsupported addedtime inittime clientrequestschedulercore registerme registerme getobject addedtime inittime clientrequestschedulercore objectcontainer objectcontainer orderascending addedtime orderascending clientrequestschedulercore registermeset tend currenttimemillis registerme tend tstart hasnext registermeset hasnext isinsertscheduler issskscheduler registerme registermeset clientrequestschedulercore isqueuealmostempty jobrunner registermerunner nativethread norm_priority registermerunner registermerunner private transient db job pre register me runner void start db job runner runner start register me runner runner dbjob preregistermerunner dbjobrunner startregistermerunner private final void start register me runner db job runner runner if is insert scheduler runner queue pre register me runner native thread norm priority true startregistermerunner dbjobrunner isinsertscheduler preregistermerunner nativethread norm_priority private int remove first according to priorities boolean try offered keys int fuzz random source random offered keys list offered keys client request scheduler non persistent sched transient boolean transient only short max prio object container container sorted vector by number result null short iteration 0 priority we loop to ensure we try every possibilities n 1 prio will do 0 1 2 3 4 5 6 0 tweaked will do rand 6 0 1 2 3 4 5 6 while iteration request starter number of priority classes 1 priority fuzz 0 tweaked priority selector random next int tweaked priority selector length priority selector math abs fuzz priority selector length if transient only result null else result priorities priority if result null result sched transient priorities priority if priority max prio fuzz continue don t return because first round may be higher with soft scheduling if result null result is empty try offered keys offered keys priority is empty container if logminor logger minor this using priority priority return priority if logminor logger minor this priority priority is null fuzz fuzz fuzz fixme implement none return 1 removefirstaccordingtopriorities tryofferedkeys randomsource offeredkeyslist offeredkeys clientrequestschedulernonpersistent schedtransient transientonly maxprio objectcontainer sortedvectorbynumber requeststarter number_of_priority_classes tweakedpriorityselector nextint tweakedpriorityselector priorityselector priorityselector transientonly schedtransient maxprio isempty tryofferedkeys offeredkeys isempty the worry is is there any nested locking outside of the hierarchy chosen block remove first transient int fuzz random source random offered keys list offered keys request starter starter client request scheduler non persistent sched transient short max prio int retry count client context context object container container sendable request req remove first inner fuzz random offered keys starter sched transient true false max prio retry count context container if is insert scheduler req instanceof sendable get illegal state exception e new illegal state exception remove first inner returned a sendable get on an insert scheduler req internal error e sched container context req persistent throw e return maybe make chosen request req container context chosenblock removefirsttransient randomsource offeredkeyslist offeredkeys requeststarter clientrequestschedulernonpersistent schedtransient maxprio retrycount clientcontext objectcontainer sendablerequest removefirstinner offeredkeys schedtransient maxprio retrycount isinsertscheduler sendableget illegalstateexception illegalstateexception removefirstinner sendableget internalerror maybemakechosenrequest public chosen block maybe make chosen request sendable request req object container container client context context if req null return null if req is empty container req is cancelled container return null sendable request item token req choose key this req persistent container null context if token null return null else key key client key ckey if is insert scheduler key null ckey null else key base sendable get req get node key token persistent container null if req instanceof sendable get ckey sendable get req get key token persistent container null else ckey null chosen block ret assert req persistent if key null key get routing key null throw new null pointer exception boolean local request only boolean cache local requests boolean ignore store if req instanceof sendable get sendable get sg sendable get req fetch context ctx sg get context local request only ctx local request only cache local requests ctx cache local requests ignore store ctx ignore store else local request only false if req instanceof sendable insert cache local requests sendable insert req cache inserts null else cache local requests false ignore store false ret new transient chosen block req token key ckey local request only cache local requests ignore store sched return ret chosenblock maybemakechosenrequest sendablerequest objectcontainer clientcontext isempty iscancelled sendablerequestitem choosekey clientkey isinsertscheduler basesendableget getnodekey sendableget sendableget getkey chosenblock getroutingkey nullpointerexception localrequestonly cachelocalrequests ignorestore sendableget sendableget sendableget fetchcontext getcontext localrequestonly localrequestonly cachelocalrequests cachelocalrequests ignorestore ignorestore localrequestonly sendableinsert cachelocalrequests sendableinsert cacheinserts cachelocalrequests ignorestore transientchosenblock localrequestonly cachelocalrequests ignorestore sendable request remove first inner int fuzz random source random offered keys list offered keys request starter starter client request scheduler non persistent sched transient boolean transient only boolean not transient short max prio int retry count client context context object container container priorities start at 0 if logminor logger minor this remove first boolean try offered keys offered keys null not transient random next boolean int choosen priority class remove first according to priorities try offered keys fuzz random offered keys sched transient transient only max prio container if choosen priority class 1 offered keys null try offered keys not transient try offered keys true choosen priority class remove first according to priorities try offered keys fuzz random offered keys sched transient transient only max prio container if choosen priority class 1 if logminor logger minor this nothing to do return null if max prio request starter minimum priority class max prio request starter minimum priority class for choosen priority class max prio choosen priority class if logminor logger minor this using priority choosen priority class if try offered keys if offered keys choosen priority class has valid keys this null context return offered keys choosen priority class sorted vector by number perm null if transient only perm priorities choosen priority class sorted vector by number trans null if not transient trans sched transient priorities choosen priority class if perm null trans null if logminor logger minor this no requests to run chosen priority empty continue try next priority int perm retry index 0 int trans retry index 0 while true int perm retry count perm null integer max value perm get number by index perm retry index int trans retry count trans null integer max value trans get number by index trans retry index if choosen priority class max prio if perm retry count retry count perm retry count integer max value if trans retry count retry count trans retry count integer max value if perm retry count integer max value trans retry count integer max value if logminor logger minor this no requests to run ran out of retrycounts on chosen priority break try next priority sectored random grab array with int chosen tracker null sorted vector by number tracker parent null if perm retry count trans retry count choose between them sectored random grab array with int perm retry tracker sectored random grab array with int perm get by index perm retry index if persistent perm retry tracker null container activate perm retry tracker 1 sectored random grab array with int trans retry tracker sectored random grab array with int trans get by index trans retry index int perm tracker size perm retry tracker size int trans tracker size trans retry tracker size if perm tracker size trans tracker size 0 perm retry index trans retry index continue if random next int perm tracker size trans tracker size perm tracker size chosen tracker perm retry tracker tracker parent perm perm retry index else chosen tracker trans retry tracker tracker parent trans trans retry index else if perm retry count trans retry count chosen tracker sectored random grab array with int perm get by index perm retry index if persistent chosen tracker null container activate chosen tracker 1 tracker parent perm perm retry index else chosen tracker sectored random grab array with int trans get by index trans retry index tracker parent trans trans retry index if logminor logger minor this got retry count tracker chosen tracker sendable request req sendable request chosen tracker remove random starter container context if chosen tracker is empty tracker parent remove chosen tracker get number container if chosen tracker persistent chosen tracker remove from container if tracker parent is empty if logminor logger minor this should remove priority if req null if logminor logger minor this no requests adjusted retrycount chosen tracker get number chosen tracker of priority choosen priority class continue try next retry count if chosen tracker persistent container activate req 1 fixme if req persistent tracker parent persistent logger error this request persistent req persistent but is in the queue for persistent tracker parent persistent for req fixme fix it if req get priority class container choosen priority class reinsert it shouldn t happen if we are calling reregister all maybe we should ask people to report that error if seen logger normal this in wrong priority class req req prio req get priority class container but chosen choosen priority class remove it sectored random grab array with object client grabber sectored random grab array with object chosen tracker get grabber req get client container if client grabber null if chosen tracker persistent container activate client grabber 1 random grab array baserga random grab array client grabber get grabber req get client request if baserga null baserga remove req container else okay it s been removed already cool else logger error this could not find client grabber for client req get client container from chosen tracker if req persistent inner register req random container null else sched transient inner register req random container null continue try the next one on this retry count check recent successes choose a recently succeeded request 50 chance of using a recently succeeded request if there is one for transient requests we keep a list of recently succeeded base sendable get s because transient requests are chosen individually but for persistent requests we keep a list of random grab array s because persistent requests are chosen a whole sendable request at a time fixme only replaces persistent requests with persistent requests of similar priority and retry count or transient with transient probably this is acceptable if req persistent is insert scheduler list base sendable get recent sched transient recent successes base sendable get alt req null if recent is empty if random next boolean alt req recent remove recent size 1 if alt req null alt req is cancelled container alt req is empty container if logminor logger minor this ignoring cancelled recently succeeded item alt req alt req null if alt req null alt req req int prio alt req get priority class container if prio choosen priority class prio choosen priority class fix retry count alt req get retry count chosen tracker get number use the recent one instead if logminor logger minor this recently succeeded transient req alt req prio alt req get priority class container retry count alt req get retry count is better than req prio req get priority class container retry req get retry count using that don t need to reregister because remove random doesn t actually remove req alt req else don t use the recent one if logminor logger minor this chosen req req is better reregistering recently succeeded alt req recent add alt req else if is insert scheduler random grab array altrga null synchronized recent successes if recent successes is empty random next boolean altrga recent successes remove recent successes size 1 if altrga null container activate altrga 1 if container ext is stored altrga altrga is empty if logminor logger minor this maybe using recently succeeded item from altrga sendable request alt req sendable request altrga remove random starter container context if alt req null container activate alt req 1 int prio alt req get priority class container if prio choosen priority class prio choosen priority class fix retry count alt req get retry count chosen tracker get number alt req is empty container alt req req use the recent one instead if logminor logger minor this recently succeeded persistent req alt req prio alt req get priority class container retry count alt req get retry count is better than req prio req get priority class container retry req get retry count using that don t need to reregister because remove random doesn t actually remove req alt req else if alt req null if logminor logger minor this chosen persistent req req is better reregistering recently succeeded altrga for alt req synchronized recent successes recent successes add altrga else container deactivate altrga 1 sendablerequest removefirstinner randomsource offeredkeyslist offeredkeys requeststarter clientrequestschedulernonpersistent schedtransient transientonly nottransient maxprio retrycount clientcontext objectcontainer removefirst tryofferedkeys offeredkeys nottransient nextboolean choosenpriorityclass removefirstaccordingtopriorities tryofferedkeys offeredkeys schedtransient transientonly maxprio choosenpriorityclass offeredkeys tryofferedkeys nottransient tryofferedkeys choosenpriorityclass removefirstaccordingtopriorities tryofferedkeys offeredkeys schedtransient transientonly maxprio choosenpriorityclass maxprio requeststarter minimum_priority_class maxprio requeststarter minimum_priority_class choosenpriorityclass maxprio choosenpriorityclass choosenpriorityclass tryofferedkeys offeredkeys choosenpriorityclass hasvalidkeys offeredkeys choosenpriorityclass sortedvectorbynumber transientonly choosenpriorityclass sortedvectorbynumber nottransient schedtransient choosenpriorityclass permretryindex transretryindex permretrycount max_value getnumberbyindex permretryindex transretrycount max_value getnumberbyindex transretryindex choosenpriorityclass maxprio permretrycount retrycount permretrycount max_value transretrycount retrycount transretrycount max_value permretrycount max_value transretrycount max_value sectoredrandomgrabarraywithint chosentracker sortedvectorbynumber trackerparent permretrycount transretrycount sectoredrandomgrabarraywithint permretrytracker sectoredrandomgrabarraywithint getbyindex permretryindex permretrytracker permretrytracker sectoredrandomgrabarraywithint transretrytracker sectoredrandomgrabarraywithint getbyindex transretryindex permtrackersize permretrytracker transtrackersize transretrytracker permtrackersize transtrackersize permretryindex transretryindex nextint permtrackersize transtrackersize permtrackersize chosentracker permretrytracker trackerparent permretryindex chosentracker transretrytracker trackerparent transretryindex permretrycount transretrycount chosentracker sectoredrandomgrabarraywithint getbyindex permretryindex chosentracker chosentracker trackerparent permretryindex chosentracker sectoredrandomgrabarraywithint getbyindex transretryindex trackerparent transretryindex chosentracker sendablerequest sendablerequest chosentracker removerandom chosentracker isempty trackerparent chosentracker getnumber chosentracker chosentracker removefrom trackerparent isempty chosentracker getnumber chosentracker choosenpriorityclass chosentracker trackerparent trackerparent getpriorityclass choosenpriorityclass reregisterall getpriorityclass choosenpriorityclass sectoredrandomgrabarraywithobject clientgrabber sectoredrandomgrabarraywithobject chosentracker getgrabber getclient clientgrabber chosentracker clientgrabber randomgrabarray randomgrabarray clientgrabber getgrabber getclientrequest getclient chosentracker innerregister schedtransient innerregister recentsuccesses basesendableget randomgrabarray sendablerequest isinsertscheduler basesendableget schedtransient recentsuccesses basesendableget altreq isempty nextboolean altreq altreq altreq iscancelled altreq isempty altreq altreq altreq altreq altreq getpriorityclass choosenpriorityclass choosenpriorityclass fixretrycount altreq getretrycount chosentracker getnumber altreq altreq getpriorityclass altreq getretrycount getpriorityclass getretrycount removerandom altreq altreq altreq isinsertscheduler randomgrabarray recentsuccesses recentsuccesses isempty nextboolean recentsuccesses recentsuccesses isstored isempty sendablerequest altreq sendablerequest removerandom altreq altreq altreq getpriorityclass choosenpriorityclass choosenpriorityclass fixretrycount altreq getretrycount chosentracker getnumber altreq isempty altreq altreq altreq getpriorityclass altreq getretrycount getpriorityclass getretrycount removerandom altreq altreq altreq recentsuccesses recentsuccesses override boolean persistent return true public void run object container container client context context if sched database executor get queue size native thread norm priority 100 if the queue isn t empty reschedule at norm 1 wait for the backlog to clear if sched is queue almost empty context job runner queue register me runner native thread norm priority 1 false return long deadline system current time millis 10 1000 if register me set null logger error this register me set is null for client request scheduler core this this return for int i 0 i 1000 i try if register me set has next break catch null pointer exception t logger error this db4o thew npe in has next t t fixme find some way to get a reproducible test case i suspect it won t be easy context job runner queue pre register me runner native thread norm priority true return catch class cast exception t wtf logger error this db4o thew class cast exception in has next t t fixme find some way to get a reproducible test case i suspect it won t be easy context job runner queue pre register me runner native thread norm priority true return long start next system current time millis register me reg register me register me set next container activate reg 1 if reg bootid context bootid if logminor logger minor this not registering block reg as was added to the queue continue fixme remove the leftover old core handling at some point an npe is acceptable long term if reg core client request scheduler core this if container ext is stored reg if logminor logger minor this already deleted register me reg skipping continue if reg core null logger error this leftover register me reg core already deleted this is an error unless you have seen old core not active messages before this point container delete reg continue if container ext is active reg core logger error this old core not active in register me reg duplicated cores container delete reg core container delete reg continue if logminor logger minor this ignoring register me reg as doesn t belong to me my insert is insert scheduler my ssk isssk scheduler his insert reg core is insert scheduler his ssk reg core isssk scheduler container deactivate reg 1 continue don t delete if reg key added time init time if logminor logger minor this ignoring register me as created since startup container deactivate reg key 1 container deactivate reg 1 continue don t delete if logminor logger minor this running register me reg for reg non get request reg added time reg priority don t need to activate fields should exist fixme if reg non get request null container activate reg non get request 1 if reg non get request is cancelled container logger normal this register me request cancelled reg non get request else if logminor logger minor this registering register me for insert reg non get request sched register insert reg non get request true false container container delete reg container deactivate reg non get request 1 container deactivate reg 1 if system current time millis deadline break boolean boost sched is queue almost empty if register me set has next context job runner queue register me runner native thread norm priority 1 boost 1 0 true else if logminor logger minor this register me runner finished synchronized client request scheduler core this register me set null always re run the query if there is nothing to register it won t call back to us pre register me runner run container context objectcontainer clientcontext databaseexecutor getqueuesize nativethread norm_priority isqueuealmostempty jobrunner registermerunner nativethread norm_priority currenttimemillis registermeset registermeset clientrequestschedulercore registermeset hasnext nullpointerexception hasnext jobrunner preregistermerunner nativethread norm_priority classcastexception classcastexception hasnext jobrunner preregistermerunner nativethread norm_priority startnext currenttimemillis registerme registerme registermeset clientrequestschedulercore isstored registerme registerme isactive registerme registerme isinsertscheduler issskscheduler isinsertscheduler issskscheduler addedtime inittime registerme registerme nongetrequest addedtime nongetrequest nongetrequest nongetrequest iscancelled registerme nongetrequest registerme nongetrequest registerinsert nongetrequest nongetrequest currenttimemillis isqueuealmostempty registermeset hasnext jobrunner registermerunner nativethread norm_priority registermerunner clientrequestschedulercore registermeset preregistermerunner return true unless the key was already present public boolean add to fetching key key synchronized keys fetching boolean retval keys fetching add key if retval logger normal this already in keys fetching key else if logminor logger minor this added to keys fetching key return retval addtofetching keysfetching keysfetching keysfetching keysfetching public boolean has key key key if keys fetching null throw new null pointer exception synchronized keys fetching return keys fetching contains key haskey keysfetching nullpointerexception keysfetching keysfetching public void remove fetching key final key key if logminor logger minor this removing from keys fetching key if key null synchronized keys fetching keys fetching remove key removefetchingkey keysfetching keysfetching keysfetching public void rerun register me runner db job runner runner synchronized this if register me set null return start register me runner runner rerunregistermerunner dbjobrunner registermeset startregistermerunner override public synchronized long count queued requests object container container client context context long ret super count queued requests container context long cooldown persistent cooldown queue size container system out println cooldown queue size cooldown return ret cooldown countqueuedrequests objectcontainer clientcontext countqueuedrequests persistentcooldownqueue public boolean has transient insert sendable insert insert object token running transient insert tmp new running transient insert insert token synchronized running transient inserts return running transient inserts contains tmp hastransientinsert sendableinsert runningtransientinsert runningtransientinsert runningtransientinserts runningtransientinserts public boolean add transient insert fetching sendable insert insert object token running transient insert tmp new running transient insert insert token synchronized running transient inserts boolean retval running transient inserts add tmp if retval logger normal this already in running transient inserts insert token else if logminor logger minor this added to running transient inserts insert token return retval addtransientinsertfetching sendableinsert runningtransientinsert runningtransientinsert runningtransientinserts runningtransientinserts runningtransientinserts runningtransientinserts public void remove transient insert fetching sendable insert insert object token running transient insert tmp new running transient insert insert token if logminor logger minor this removing from running transient inserts insert token synchronized running transient inserts running transient inserts remove tmp removetransientinsertfetching sendableinsert runningtransientinsert runningtransientinsert runningtransientinserts runningtransientinserts runningtransientinserts override public void succeeded base sendable get succeeded object container container random grab array array succeeded get parent grab array container activate array 1 if array null return unregistered already synchronized recent successes if recent successes contains array return recent successes add array while recent successes size 8 recent successes remove 0 basesendableget objectcontainer randomgrabarray getparentgrabarray recentsuccesses recentsuccesses recentsuccesses recentsuccesses recentsuccesses public abstract class persistent comparator t extends i persistent extends persistent compare two members of collection param m1 first members param m2 second members return negative number if m1 lt m2 zero if m1 m2 and positive number if m1 gt m2 persistentcomparator ipersistent compare member with specified search key param mbr collection member param key search key return negative number if mbr lt key zero if mbr key and positive number if mbr gt key public class closer closes the given stream param output stream the output stream to close public static void close closeable closable if closable null try closable close catch io exception e outputstream ioexception closes the given zip file param zip file the zip file to close public static void close zip file zip file if zip file null try zip file close catch io exception e zipfile zipfile zipfile zipfile zipfile ioexception throws message invalid exception public testdda request message simple field set fs throws message invalid exception identifier fs get directory if identifier null throw new message invalid exception protocol error message missing field no directory given null false if identifier length 0 throw new message invalid exception protocol error message missing field the specified directory can t be empty null false want read fs get boolean want read false want write fs get boolean want write false if want read false want write false throw new message invalid exception protocol error message invalid message both want read and want write are set to false what s the point of sending a message identifier false messageinvalidexception testddarequestmessage simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field messageinvalidexception protocolerrormessage missing_field wantread getboolean want_read wantwrite getboolean want_write wantread wantwrite messageinvalidexception protocolerrormessage invalid_message want_read want_write override public simple field set get field set return null simplefieldset getfieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception dda check job job try job handler enqueuedda check identifier want read want write catch illegal argument exception e throw new message invalid exception protocol error message invalid field e get message identifier false testdda reply message reply new testdda reply message job handler output handler queue reply fcpconnectionhandler messageinvalidexception ddacheckjob enqueueddacheck wantread wantwrite illegalargumentexception messageinvalidexception protocolerrormessage invalid_field getmessage testddareplymessage testddareplymessage outputhandler override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog private final string target in archive private container element bucket data2 string target in archive2 data data2 target in archive target in archive2 targetinarchive containerelement targetinarchive2 targetinarchive targetinarchive2 param metadata2 param archive type2 param targeturi2 param token2 param getchk only2 param early encode2 param ctx2 param report metadata only2 public container inserter base client putter parent2 put completion callback cb2 hash map string object metadata2 freeneturi targeturi2 insert context ctx2 boolean dont compress2 boolean getchk only2 boolean report metadata only2 object token2 archive type archive type2 boolean free data boolean early encode2 parent parent2 cb cb2 hash code super hash code persistent parent persistent orig metadata metadata2 archive type archive type2 targeturi targeturi2 token token2 getchk only getchk only2 early encode early encode2 ctx ctx2 dont compress dont compress2 report metadata only report metadata only2 container items new array list container element archivetype2 getchkonly2 earlyencode2 reportmetadataonly2 containerinserter baseclientputter putcompletioncallback hashmap insertcontext dontcompress2 getchkonly2 reportmetadataonly2 archive_type archivetype2 freedata earlyencode2 hashcode hashcode origmetadata archivetype archivetype2 getchkonly getchkonly2 earlyencode earlyencode2 dontcompress dontcompress2 reportmetadataonly reportmetadataonly2 containeritems arraylist containerelement public void cancel object container container client context context synchronized this if cancelled return cancelled true if persistent container store this if persistent container activate cb 1 must call on failure so get remove from ed cb on failure new insert exception insert exception cancelled this container context objectcontainer clientcontext onfailure removefrom onfailure insertexception insertexception public base client putter get parent return parent baseclientputter getparent public object get token return token gettoken public void remove from object container container client context context todo removefrom objectcontainer clientcontext public void schedule object container container client context context throws insert exception start container context objectcontainer clientcontext insertexception private void start object container container client context context if logdebug logger debug this atempt to start a container inserter new exception debug make metadata context container synchronized this if finished return insert block block try bucket output bucket context get bucket factory persistent make bucket 1 string mime type archive type archive type tar create tar bucket output bucket container create zip bucket output bucket container if logminor logger minor this we are using archive type now we have to insert the archive we have generated can we just insert it and not bother with a redirect to it thereby exploiting implicit manifest support which will pick up on metadata we ought to be able to block new insert block output bucket new client metadata mime type persistent targeturi clone targeturi catch io exception e fail new insert exception insert exception bucket error e null container context return boolean dc dont compress if dont compress dc archive type archive type zip single file inserter sfi new single file inserter parent cb block false ctx dc getchk only report metadata only token archive type true null early encode if logminor logger minor this inserting container sfi for this cb on transition this sfi container try sfi schedule container context catch insert exception e fail new insert exception insert exception bucket error e null container context return cb on block set finished this container context objectcontainer clientcontext makemetadata insertblock outputbucket getbucketfactory makebucket mimetype archivetype archive_type createtarbucket outputbucket createzipbucket outputbucket archivetype insertblock outputbucket clientmetadata mimetype ioexception insertexception insertexception bucket_error dontcompress dontcompress archivetype archive_type singlefileinserter singlefileinserter getchkonly reportmetadataonly archivetype earlyencode ontransition insertexception insertexception insertexception bucket_error onblocksetfinished private void make metadata client context context object container container bucket bucket null int x 0 hash map string object manifest new hash map string object make manifest orig metadata manifest metadata md metadata mk redirection manifest with metadata manifest while true try bucket context temp bucket factory make bucket 1 byte buf md write to byte array output stream os bucket get output stream os write buf os close container items add new container element bucket metadata return catch io exception e fail new insert exception insert exception internal error e null container context return catch metadata unresolved exception e try x resolve e x bucket null null container context catch io exception e1 fail new insert exception insert exception internal error e null container context return makemetadata clientcontext objectcontainer hashmap hashmap makemanifest origmetadata mkredirectionmanifestwithmetadata tempbucketfactory makebucket writetobytearray outputstream getoutputstream containeritems containerelement ioexception insertexception insertexception internal_error metadataunresolvedexception ioexception insertexception insertexception internal_error private int resolve metadata unresolved exception e int x bucket bucket freeneturi key string element2 object container container client context context throws io exception metadata m e must resolve for int i 0 i m length i try byte buf m i write to byte array output stream os bucket get output stream os write buf os close string name in archive metadata x container items add new container element bucket name in archive m i resolve name in archive catch metadata unresolved exception e1 x resolve e x bucket key element2 container context return x metadataunresolvedexception objectcontainer clientcontext ioexception mustresolve writetobytearray outputstream getoutputstream nameinarchive containeritems containerelement nameinarchive nameinarchive metadataunresolvedexception private void fail insert exception e object container container client context context cancel all then call the callback synchronized this if finished return finished true if persistent container activate cb 1 cb on failure e this container context insertexception objectcontainer clientcontext onfailure private final int hash code override public int hash code return hash code hashcode hashcode hashcode public boolean object can update suppress warnings unused object container container if logminor logger minor this object can update on this new exception debug return true objectcanupdate suppresswarnings objectcontainer objectcanupdate public boolean object can new suppress warnings unused object container container if logminor logger minor this object can new on this new exception debug return true objectcannew suppresswarnings objectcontainer objectcannew private string create tar bucket bucket output bucket suppress warnings unused object container container throws io exception if logminor logger minor this create a tar bucket output stream os new buffered output stream output bucket get output stream tar output stream taros new tar output stream os taros set long file mode tar output stream longfile gnu tar entry ze for container element ph container items if logminor logger minor this putting into tar ph data length ph data size name ph target in archive ze new tar entry ph target in archive ze set mod time 0 long size ph data size ze set size size taros put next entry ze bucket tools copy to ph data taros size taros close entry taros close entry both finish and close are necessary taros finish taros flush taros close if logminor logger minor this archive size is output bucket size return archive type tar mime types 0 createtarbucket outputbucket suppresswarnings objectcontainer ioexception outputstream bufferedoutputstream outputbucket getoutputstream taroutputstream taroutputstream setlongfilemode taroutputstream longfile_gnu tarentry containerelement containeritems targetinarchive tarentry targetinarchive setmodtime setsize putnextentry buckettools copyto closeentry closeentry outputbucket archive_type mimetypes private string create zip bucket bucket output bucket suppress warnings unused object container container throws io exception if logminor logger minor this create a zip bucket output stream os new buffered output stream output bucket get output stream zip output stream zos new zip output stream os zip entry ze for container element ph container items ze new zip entry ph target in archive ze set time 0 zos put next entry ze bucket tools copy to ph data zos ph data size zos close entry zos close entry both finish and close are necessary zos finish zos flush zos close return archive type zip mime types 0 createzipbucket outputbucket suppresswarnings objectcontainer ioexception outputstream bufferedoutputstream outputbucket getoutputstream zipoutputstream zipoutputstream zipentry containerelement containeritems zipentry targetinarchive settime putnextentry buckettools copyto closeentry closeentry archive_type mimetypes private void make manifest hash map string object manifest elements hash map string object manifest string archive prefix for map entry string object me manifest elements entry set string name me get key object o me get value if o instanceof hash map suppress warnings unchecked hash map string object hm hash map string object o hash map string object sub map new hash map string object system out println decompose name sub dir manifest put name sub map make manifest hm sub map archive prefix name if logger should log logger debug this logger debug this sub map for name sub map size elements from hm size else if o instanceof metadata already metadata take as is system out println decompose name metadata manifest put name o else manifest element element manifest element o string mime type element mime override client metadata cm if mime type null mime type equals defaultmime types default mime type cm null else cm new client metadata mime type metadata m if element targeturi null system out println decompose name manifest element redirect m new metadata metadata simple redirect null null element targeturi cm else system out println decompose name manifest element data container items add new container element element data archive prefix name m new metadata metadata archive internal redirect null null archive prefix element full name cm manifest put name m makemanifest hashmap manifestelements hashmap archiveprefix manifestelements entryset getkey getvalue hashmap suppresswarnings hashmap hashmap hashmap submap hashmap subdir submap makemanifest submap archiveprefix shouldlog submap manifestelement manifestelement mimetype mimeoverride clientmetadata mimetype mimetype defaultmimetypes default_mime_type clientmetadata mimetype manifestelement simple_redirect manifestelement containeritems containerelement archiveprefix archive_internal_redirect archiveprefix fullname logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog node stats node node int sort order sub config stats config int obw limit int ibw limit file node dir throws node init exception this node node this peers node peers this hard random node random this routing miss distance new time decaying running average 0 0 180000 0 0 1 0 node this backed off percent new time decaying running average 0 0 180000 0 0 1 0 node preemptive reject reasons new string counter local preemptive reject reasons new string counter p instant reject incoming new time decaying running average 0 60000 0 0 1 0 node thread group tg thread current thread get thread group while tg get parent null tg tg get parent this root thread group tg this active threads by priorities new int native thread java priority range this waiting threads by priorities new int native thread java priority range throttled packet send average new time decaying running average 1 10 60 1000 should be significantly longer than a typical transfer 0 long max value node node pinger new node pinger node previous input stat 0 previous output stat 0 previous io stat time 1 last input stat 0 last output stat 0 last io stat time 3 stats config register thread limit 500 sort order true true node stat thread limit node stat thread limit long new int callback override public integer get return thread limit override public void set integer val throws invalid config value exception if get equals val return if val 100 throw new invalid config value exception l10n value too low thread limit val false thread limit stats config get int thread limit yes it could be in seconds insteed of multiples of 0 12 but we don t want people to play with it stats config register aggressivegc aggressivegc modificator sort order true false node stat aggressivegc node stat aggressivegc long new int callback override public integer get return aggressivegc modificator override public void set integer val throws invalid config value exception if get equals val return logger normal this changing aggressivegc modificator to val aggressivegc modificator val false aggressivegc modificator stats config get int aggressivegc my memory checker new memory checker node ps aggressivegc modificator stats config register memory checker true sort order true false node stat mem check node stat mem check long new boolean callback override public boolean get return my memory checker is running override public void set boolean val throws invalid config value exception if get equals val return if val my memory checker start else my memory checker terminate if stats config get boolean memory checker my memory checker start stats config register ignore local vs remote bandwidth liability false sort order true false node stat ignore local vs remote bandwidth liability node stat ignore local vs remote bandwidth liability long new boolean callback override public boolean get synchronized node stats this return ignore local vs remote bandwidth liability override public void set boolean val throws invalid config value exception synchronized node stats this ignore local vs remote bandwidth liability val this is a network level setting because it affects the rate at which we initiate local requests which could be seen by distant nodes node security levels add network threat level listener new security level listener network threat level public void on change network threat level old level network threat level new level if new level network threat level maximum ignore local vs remote bandwidth liability true if old level network threat level maximum ignore local vs remote bandwidth liability false otherwise leave it as it was it defaults to false persister new configurable persister this stats config node throttle file node throttle dat sort order true false node stat stats persister node stat stats persister long node ps node dir simple field set throttlefs persister read if logminor logger minor this read throttlefs n throttlefs guesstimates hopefully well over the reality local chk fetch bytes sent average new time decaying running average 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk fetch bytes sent average node local ssk fetch bytes sent average new time decaying running average 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local ssk fetch bytes sent average node local chk insert bytes sent average new time decaying running average 32768 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk insert bytes sent average node local ssk insert bytes sent average new time decaying running average 2048 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local ssk insert bytes sent average node local chk fetch bytes received average new time decaying running average 32768 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk fetch bytes received average node local ssk fetch bytes received average new time decaying running average 2048 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local ssk fetch bytes received average node local chk insert bytes received average new time decaying running average 1024 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk insert bytes received average node local ssk insert bytes received average new time decaying running average 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset local chk insert bytes received average node remote chk fetch bytes sent average new time decaying running average 32768 1024 500 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote chk fetch bytes sent average node remote ssk fetch bytes sent average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote ssk fetch bytes sent average node remote chk insert bytes sent average new time decaying running average 32768 32768 1024 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote chk insert bytes sent average node remote ssk insert bytes sent average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote ssk insert bytes sent average node remote chk fetch bytes received average new time decaying running average 32768 1024 500 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote chk fetch bytes received average node remote ssk fetch bytes received average new time decaying running average 2048 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote ssk fetch bytes received average node remote chk insert bytes received average new time decaying running average 32768 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote chk insert bytes received average node remote ssk insert bytes received average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset remote ssk insert bytes received average node successful chk fetch bytes sent average new time decaying running average 32768 1024 500 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk fetch bytes sent average node successful ssk fetch bytes sent average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful ssk fetch bytes sent average node successful chk insert bytes sent average new time decaying running average 32768 32768 1024 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk insert bytes sent average node successful ssk insert bytes sent average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful ssk insert bytes sent average node successful chk offer reply bytes sent average new time decaying running average 32768 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk offer reply bytes sent average node successful ssk offer reply bytes sent average new time decaying running average 3072 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful ssk offer reply bytes sent average node successful chk fetch bytes received average new time decaying running average 32768 1024 500 2048 path folding 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk fetch bytes received average node successful ssk fetch bytes received average new time decaying running average 2048 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful ssk fetch bytes received average node successful chk insert bytes received average new time decaying running average 32768 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful chk insert bytes received average node successful ssk insert bytes received average new time decaying running average 1024 1024 500 180000 0 0 1024 1024 1024 throttlefs null null throttlefs subset successful nodestats sortorder subconfig statsconfig obwlimit ibwlimit nodedir nodeinitexception hardrandom routingmissdistance timedecayingrunningaverage backedoffpercent timedecayingrunningaverage preemptiverejectreasons stringcounter localpreemptiverejectreasons stringcounter pinstantrejectincoming timedecayingrunningaverage threadgroup currentthread getthreadgroup getparent getparent rootthreadgroup activethreadsbypriorities nativethread java_priority_range waitingthreadsbypriorities nativethread java_priority_range throttledpacketsendaverage timedecayingrunningaverage max_value nodepinger nodepinger previous_input_stat previous_output_stat previous_io_stat_time last_input_stat last_output_stat last_io_stat_time statsconfig threadlimit sortorder nodestat threadlimit nodestat threadlimitlong intcallback threadlimit invalidconfigvalueexception invalidconfigvalueexception valuetoolow threadlimit threadlimit statsconfig getint threadlimit statsconfig aggressivegcmodificator sortorder nodestat nodestat aggressivegclong intcallback aggressivegcmodificator invalidconfigvalueexception aggressivegcmodificator aggressivegcmodificator aggressivegcmodificator statsconfig getint mymemorychecker memorychecker aggressivegcmodificator statsconfig memorychecker sortorder nodestat memcheck nodestat memchecklong booleancallback mymemorychecker isrunning invalidconfigvalueexception mymemorychecker mymemorychecker statsconfig getboolean memorychecker mymemorychecker statsconfig ignorelocalvsremotebandwidthliability sortorder nodestat ignorelocalvsremotebandwidthliability nodestat ignorelocalvsremotebandwidthliabilitylong booleancallback nodestats ignorelocalvsremotebandwidthliability invalidconfigvalueexception nodestats ignorelocalvsremotebandwidthliability securitylevels addnetworkthreatlevellistener securitylevellistener network_threat_level onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level ignorelocalvsremotebandwidthliability oldlevel network_threat_level ignorelocalvsremotebandwidthliability configurablepersister statsconfig nodethrottlefile sortorder nodestat statspersister nodestat statspersisterlong nodedir simplefieldset localchkfetchbytessentaverage timedecayingrunningaverage localchkfetchbytessentaverage localsskfetchbytessentaverage timedecayingrunningaverage localsskfetchbytessentaverage localchkinsertbytessentaverage timedecayingrunningaverage localchkinsertbytessentaverage localsskinsertbytessentaverage timedecayingrunningaverage localsskinsertbytessentaverage localchkfetchbytesreceivedaverage timedecayingrunningaverage localchkfetchbytesreceivedaverage localsskfetchbytesreceivedaverage timedecayingrunningaverage localsskfetchbytesreceivedaverage localchkinsertbytesreceivedaverage timedecayingrunningaverage localchkinsertbytesreceivedaverage localsskinsertbytesreceivedaverage timedecayingrunningaverage localchkinsertbytesreceivedaverage remotechkfetchbytessentaverage timedecayingrunningaverage remotechkfetchbytessentaverage remotesskfetchbytessentaverage timedecayingrunningaverage remotesskfetchbytessentaverage remotechkinsertbytessentaverage timedecayingrunningaverage remotechkinsertbytessentaverage remotesskinsertbytessentaverage timedecayingrunningaverage remotesskinsertbytessentaverage remotechkfetchbytesreceivedaverage timedecayingrunningaverage remotechkfetchbytesreceivedaverage remotesskfetchbytesreceivedaverage timedecayingrunningaverage remotesskfetchbytesreceivedaverage remotechkinsertbytesreceivedaverage timedecayingrunningaverage remotechkinsertbytesreceivedaverage remotesskinsertbytesreceivedaverage timedecayingrunningaverage remotesskinsertbytesreceivedaverage successfulchkfetchbytessentaverage timedecayingrunningaverage successfulchkfetchbytessentaverage successfulsskfetchbytessentaverage timedecayingrunningaverage successfulsskfetchbytessentaverage successfulchkinsertbytessentaverage timedecayingrunningaverage successfulchkinsertbytessentaverage successfulsskinsertbytessentaverage timedecayingrunningaverage successfulsskinsertbytessentaverage successfulchkofferreplybytessentaverage timedecayingrunningaverage successfulchkofferreplybytessentaverage successfulsskofferreplybytessentaverage timedecayingrunningaverage successfulsskofferreplybytessentaverage successfulchkfetchbytesreceivedaverage timedecayingrunningaverage successfulchkfetchbytesreceivedaverage successfulsskfetchbytesreceivedaverage timedecayingrunningaverage successfulsskfetchbytesreceivedaverage successfulchkinsertbytesreceivedaverage timedecayingrunningaverage successfulchkinsertbytesreceivedaverage successfulsskinsertbytesreceivedaverage timedecayingrunningaverage stats config register thread limit 500 sort order true true node stat thread limit node stat thread limit long new int callback override public integer get return thread limit statsconfig threadlimit sortorder nodestat threadlimit nodestat threadlimitlong intcallback threadlimit override public void set integer val throws invalid config value exception if get equals val return if val 100 throw new invalid config value exception l10n value too low thread limit val invalidconfigvalueexception invalidconfigvalueexception valuetoolow threadlimit stats config register aggressivegc aggressivegc modificator sort order true false node stat aggressivegc node stat aggressivegc long new int callback override public integer get return aggressivegc modificator statsconfig aggressivegcmodificator sortorder nodestat nodestat aggressivegclong intcallback aggressivegcmodificator override public void set integer val throws invalid config value exception if get equals val return logger normal this changing aggressivegc modificator to val aggressivegc modificator val invalidconfigvalueexception aggressivegcmodificator aggressivegcmodificator stats config register memory checker true sort order true false node stat mem check node stat mem check long new boolean callback override public boolean get return my memory checker is running statsconfig memorychecker sortorder nodestat memcheck nodestat memchecklong booleancallback mymemorychecker isrunning override public void set boolean val throws invalid config value exception if get equals val return if val my memory checker start else my memory checker terminate invalidconfigvalueexception mymemorychecker mymemorychecker override public boolean get synchronized node stats this return ignore local vs remote bandwidth liability nodestats ignorelocalvsremotebandwidthliability override public void set boolean val throws invalid config value exception synchronized node stats this ignore local vs remote bandwidth liability val invalidconfigvalueexception nodestats ignorelocalvsremotebandwidthliability public void on change network threat level old level network threat level new level if new level network threat level maximum ignore local vs remote bandwidth liability true if old level network threat level maximum ignore local vs remote bandwidth liability false otherwise leave it as it was it defaults to false onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level ignorelocalvsremotebandwidthliability oldlevel network_threat_level ignorelocalvsremotebandwidthliability protected string l10n string key return l10n get string node stats key getstring nodestats public void start throws node init exception node executor execute new runnable public void run node pinger start starting node pinger persister start node get ticker queue timed job throttled packet send average idle updater check throttle time nodeinitexception nodepinger nodepinger getticker queuetimedjob throttledpacketsendaverageidleupdater check_throttle_time public void start throws node init exception node executor execute new runnable public void run node pinger start nodeinitexception nodepinger new runnable public void run long now system current time millis try if throttled packet send average last report time now 5000 if last report more than 5 seconds ago shouldn t take long node output throttle blocking grab estimated size of one throttled packet node output throttle recycle estimated size of one throttled packet long after system current time millis report time it takes to grab the bytes throttled packet send average report after now catch throwable t logger error this caught t t finally node get ticker queue timed job this check throttle time long end system current time millis if logminor logger minor this throttle check took time util format time end now 2 true doesn t belong here but anyway should do the job active threads by priorities node executor running threads waiting threads by priorities node executor waiting threads currenttimemillis throttledpacketsendaverage lastreporttime outputthrottle blockinggrab estimatedsizeofonethrottledpacket outputthrottle estimatedsizeofonethrottledpacket currenttimemillis throttledpacketsendaverage getticker queuetimedjob check_throttle_time currenttimemillis timeutil formattime activethreadsbypriorities runningthreads waitingthreadsbypriorities waitingthreads return reject reason as string if should reject otherwise return null public string should reject request boolean can accept anyway boolean is insert boolean isssk boolean is local boolean is offer reply peer node source if logminor dump byte cost averages int thread count get active thread count if thread limit thread count p instant reject incoming report 1 0 rejected thread limit is local return thread limit thread count thread limit double bwlimit delay time throttled packet send average current value long total node collector get totalio long total sent total 0 long total overhead get sent overhead long uptime node get uptime double sent overhead per second total overhead 1000 0 uptime the fraction of output bytes which are used for requests double overhead fraction double total sent total overhead total sent long time first any connections peers time first any connections long now system current time millis if logminor logger minor this output rate total sent 1000 0 uptime overhead rate sent overhead per second non overhead fraction overhead fraction if time first any connections 0 long time now time first any connections if time default only period overhead fraction default overhead if logminor logger minor this adjusted overhead fraction overhead fraction else if time default only period default transition period time default only period overhead fraction time overhead fraction default transition period time default overhead default transition period if logminor logger minor this adjusted overhead fraction overhead fraction else if overhead fraction min overhead logger error this overhead fraction is overhead fraction assuming this is self inflicted and using default overhead fraction default overhead if no recent reports no packets have been sent correct the average downwards double ping time ping time node pinger average ping time synchronized this round trip time if ping time max ping time if now last accepted request max interrequest time can accept anyway if logminor logger minor this accepting request anyway take one every 10 secs to keep bwlimit delay time updated else p instant reject incoming report 1 0 rejected max ping time is local return max ping time time util format time long ping time 2 true else if ping time sub max ping time double x ping time sub max ping time max ping time sub max ping time if hard random next double x p instant reject incoming report 1 0 rejected sub max ping time is local return sub max ping time time util format time long ping time 2 true bandwidth limited packets if bwlimit delay time max throttle delay if now last accepted request max interrequest time can accept anyway if logminor logger minor this accepting request anyway take one every 10 secs to keep bwlimit delay time updated else p instant reject incoming report 1 0 rejected max throttle delay is local return max throttle delay time util format time long bwlimit delay time 2 true else if bwlimit delay time sub max throttle delay double x bwlimit delay time sub max throttle delay max throttle delay sub max throttle delay if hard random next double x p instant reject incoming report 1 0 rejected sub max throttle delay is local return sub max throttle delay time util format time long bwlimit delay time 2 true successful cluster timeout protection reject request if the result of all our current requests completing simultaneously would be that some of them timeout never reject a chk and accept an ssk because if we do that we would be constantly accepting ss ks as there would never be enough space for a chk so we add 1 to each type of request s count before computing the bandwidth liability thus if we have exactly enough space for 1 ssk and 1 chk we can accept either and when one of either type completes we can accept one of either type again we never let ss ks drain the bucket and block ch ks int num localchk requests node get num localchk requests 1 int num localssk requests node get num localssk requests 1 int num localchk inserts node get num localchk inserts 1 int num localssk inserts node get num localssk inserts 1 int num remotechk requests node get num remotechk requests 1 int num remotessk requests node get num remotessk requests 1 int num remotechk inserts node get num remotechk inserts 1 int num remotessk inserts node get num remotessk inserts 1 int numchk offer replies node get numchk offer replies 1 int numssk offer replies node get numssk offer replies 1 if is local if not local is already locked so we need to decrement the relevant value to counteract this and restore the ssk chk balance if is offer reply if isssk numssk offer replies else numchk offer replies else if is insert if isssk num remotessk inserts else num remotechk inserts else if isssk num remotessk requests else num remotechk requests if logminor logger minor this running adjusted chk fetch local num localchk requests remote num remotechk requests ssk fetch local num localssk requests remote num remotessk requests chk insert local num localchk inserts remote num remotechk inserts ssk insert local num localssk inserts remote num remotessk inserts chk offer replies local numchk offer replies ssk offer replies numssk offer replies double bandwidth liability output if ignore local vs remote bandwidth liability bandwidth liability output successful chk fetch bytes sent average current value num remotechk requests num localchk requests 1 successful ssk fetch bytes sent average current value num remotessk requests num localssk requests 1 successful chk insert bytes sent average current value num remotechk inserts num localchk inserts 1 successful ssk insert bytes sent average current value num remotessk inserts num localssk inserts 1 else bandwidth liability output successful chk fetch bytes sent average current value num remotechk requests local requests don t relay data so use the local average local chk fetch bytes sent average current value num localchk requests successful ssk fetch bytes sent average current value num remotessk requests local requests don t relay data so use the local average local ssk fetch bytes sent average current value num localssk requests inserts are the same for remote as local for sent bytes successful chk insert bytes sent average current value num remotechk inserts successful chk insert bytes sent average current value num localchk inserts inserts are the same for remote as local for sent bytes successful ssk insert bytes sent average current value num remotessk inserts successful ssk insert bytes sent average current value num localssk inserts successful chk offer reply bytes sent average current value numchk offer replies successful ssk offer reply bytes sent average current value numssk offer replies double output available per second node get output bandwidth limit sent overhead per second if there s been an auto update we may have used a vast amount of bandwidth for it also if things have broken our overhead might be above our bandwidth limit especially on a slow node so impose a minimum of 20 of the bandwidth limit this will ensure we don t get stuck in any situation where all our bandwidth is overhead and we don t accept any requests because of that so it remains that way if logminor logger minor this overhead per second sent overhead per second bwlimit node get output bandwidth limit output available per second output available per second but minimum of node get output bandwidth limit 5 0 output available per second math max output available per second node get output bandwidth limit 5 0 double bandwidth available output output available per second 90 90 seconds at full power we have to leave some time for the search as well if logminor logger minor this 90 second limit bandwidth available output expected output liability bandwidth liability output if bandwidth liability output bandwidth available output p instant reject incoming report 1 0 rejected output bandwidth liability is local return output bandwidth liability bandwidth liability output bandwidth available output double bandwidth liability input if ignore local vs remote bandwidth liability bandwidth liability input successful chk fetch bytes received average current value num remotechk requests num localchk requests 1 successful ssk fetch bytes received average current value num remotessk requests num localssk requests 1 successful chk insert bytes received average current value num remotechk inserts num localchk inserts 1 successful ssk insert bytes received average current value num remotessk inserts num localssk inserts 1 else bandwidth liability input for receiving data local requests are the same as remote ones successful chk fetch bytes received average current value num remotechk requests successful chk fetch bytes received average current value num localchk requests successful ssk fetch bytes received average current value num remotessk requests successful ssk fetch bytes shouldrejectrequest canacceptanyway isinsert islocal isofferreply peernode dumpbytecostaverages threadcount getactivethreadcount threadlimit threadcount pinstantrejectincoming threadlimit islocal threadlimit threadcount threadlimit bwlimitdelaytime throttledpacketsendaverage currentvalue gettotalio totalsent totaloverhead getsentoverhead getuptime sentoverheadpersecond totaloverhead overheadfraction totalsent totaloverhead totalsent timefirstanyconnections timefirstanyconnections currenttimemillis totalsent sentoverheadpersecond overheadfraction timefirstanyconnections timefirstanyconnections default_only_period overheadfraction default_overhead overheadfraction default_only_period default_transition_period default_only_period overheadfraction overheadfraction default_transition_period default_overhead default_transition_period overheadfraction overheadfraction min_overhead overheadfraction overheadfraction default_overhead pingtime pingtime nodepinger averagepingtime pingtime max_ping_time lastacceptedrequest max_interrequest_time canacceptanyway bwlimitdelaytime pinstantrejectincoming max_ping_time islocal max_ping_time timeutil formattime pingtime pingtime sub_max_ping_time pingtime sub_max_ping_time max_ping_time sub_max_ping_time hardrandom nextdouble pinstantrejectincoming sub_max_ping_time islocal sub_max_ping_time timeutil formattime pingtime bwlimitdelaytime max_throttle_delay lastacceptedrequest max_interrequest_time canacceptanyway bwlimitdelaytime pinstantrejectincoming max_throttle_delay islocal max_throttle_delay timeutil formattime bwlimitdelaytime bwlimitdelaytime sub_max_throttle_delay bwlimitdelaytime sub_max_throttle_delay max_throttle_delay sub_max_throttle_delay hardrandom nextdouble pinstantrejectincoming sub_max_throttle_delay islocal sub_max_throttle_delay timeutil formattime bwlimitdelaytime ssks ssks chks numlocalchkrequests getnumlocalchkrequests numlocalsskrequests getnumlocalsskrequests numlocalchkinserts getnumlocalchkinserts numlocalsskinserts getnumlocalsskinserts numremotechkrequests getnumremotechkrequests numremotesskrequests getnumremotesskrequests numremotechkinserts getnumremotechkinserts numremotesskinserts getnumremotesskinserts numchkofferreplies getnumchkofferreplies numsskofferreplies getnumsskofferreplies islocal isofferreply numsskofferreplies numchkofferreplies isinsert numremotesskinserts numremotechkinserts numremotesskrequests numremotechkrequests numlocalchkrequests numremotechkrequests numlocalsskrequests numremotesskrequests numlocalchkinserts numremotechkinserts numlocalsskinserts numremotesskinserts numchkofferreplies numsskofferreplies bandwidthliabilityoutput ignorelocalvsremotebandwidthliability bandwidthliabilityoutput successfulchkfetchbytessentaverage currentvalue numremotechkrequests numlocalchkrequests successfulsskfetchbytessentaverage currentvalue numremotesskrequests numlocalsskrequests successfulchkinsertbytessentaverage currentvalue numremotechkinserts numlocalchkinserts successfulsskinsertbytessentaverage currentvalue numremotesskinserts numlocalsskinserts bandwidthliabilityoutput successfulchkfetchbytessentaverage currentvalue numremotechkrequests localchkfetchbytessentaverage currentvalue numlocalchkrequests successfulsskfetchbytessentaverage currentvalue numremotesskrequests localsskfetchbytessentaverage currentvalue numlocalsskrequests successfulchkinsertbytessentaverage currentvalue numremotechkinserts successfulchkinsertbytessentaverage currentvalue numlocalchkinserts successfulsskinsertbytessentaverage currentvalue numremotesskinserts successfulsskinsertbytessentaverage currentvalue numlocalsskinserts successfulchkofferreplybytessentaverage currentvalue numchkofferreplies successfulsskofferreplybytessentaverage currentvalue numsskofferreplies outputavailablepersecond getoutputbandwidthlimit sentoverheadpersecond sentoverheadpersecond getoutputbandwidthlimit outputavailablepersecond getoutputbandwidthlimit outputavailablepersecond outputavailablepersecond getoutputbandwidthlimit bandwidthavailableoutput outputavailablepersecond bandwidthavailableoutput bandwidthliabilityoutput bandwidthliabilityoutput bandwidthavailableoutput pinstantrejectincoming islocal bandwidthliabilityoutput bandwidthavailableoutput bandwidthliabilityinput ignorelocalvsremotebandwidthliability bandwidthliabilityinput successfulchkfetchbytesreceivedaverage currentvalue numremotechkrequests numlocalchkrequests successfulsskfetchbytesreceivedaverage currentvalue numremotesskrequests numlocalsskrequests successfulchkinsertbytesreceivedaverage currentvalue numremotechkinserts numlocalchkinserts successfulsskinsertbytesreceivedaverage currentvalue numremotesskinserts numlocalsskinserts bandwidthliabilityinput successfulchkfetchbytesreceivedaverage currentvalue numremotechkrequests successfulchkfetchbytesreceivedaverage currentvalue numlocalchkrequests successfulsskfetchbytesreceivedaverage currentvalue numremotesskrequests successfulsskfetchbytes private void rejected string reason boolean is local if is local preemptive reject reasons inc reason else this local preemptive reject reasons inc reason islocal islocal preemptiverejectreasons localpreemptiverejectreasons private running average get throttle boolean is local boolean is insert boolean isssk boolean is sent if is local if is insert if isssk return is sent this local ssk insert bytes sent average this local ssk insert bytes received average else return is sent this local chk insert bytes sent average this local chk insert bytes received average else if isssk return is sent this local ssk fetch bytes sent average this local ssk fetch bytes received average else return is sent this local chk fetch bytes sent average this local chk fetch bytes received average else if is insert if isssk return is sent this remote ssk insert bytes sent average this remote ssk insert bytes received average else return is sent this remote chk insert bytes sent average this remote chk insert bytes received average else if isssk return is sent this remote ssk fetch bytes sent average this remote ssk fetch bytes received average else return is sent this remote chk fetch bytes sent average this remote chk fetch bytes received average runningaverage getthrottle islocal isinsert issent islocal isinsert issent localsskinsertbytessentaverage localsskinsertbytesreceivedaverage issent localchkinsertbytessentaverage localchkinsertbytesreceivedaverage issent localsskfetchbytessentaverage localsskfetchbytesreceivedaverage issent localchkfetchbytessentaverage localchkfetchbytesreceivedaverage isinsert issent remotesskinsertbytessentaverage remotesskinsertbytesreceivedaverage issent remotechkinsertbytessentaverage remotechkinsertbytesreceivedaverage issent remotesskfetchbytessentaverage remotesskfetchbytesreceivedaverage issent remotechkfetchbytessentaverage remotechkfetchbytesreceivedaverage private void dump byte cost averages logger minor this byte cost averages remote chk insert remote chk insert bytes sent average current value remote chk insert bytes received average current value ssk insert remote ssk insert bytes sent average current value remote ssk insert bytes received average current value chk fetch remote chk fetch bytes sent average current value remote chk fetch bytes received average current value ssk fetch remote ssk fetch bytes sent average current value remote ssk fetch bytes received average current value logger minor this byte cost averages local chk insert local chk insert bytes sent average current value local chk insert bytes received average current value ssk insert local ssk insert bytes sent average current value local ssk insert bytes received average current value chk fetch local chk fetch bytes sent average current value local chk fetch bytes received average current value ssk fetch local ssk fetch bytes sent average current value local ssk fetch bytes received average current value logger minor this byte cost averages successful chk insert successful chk insert bytes sent average current value successful chk insert bytes received average current value ssk insert successful ssk insert bytes sent average current value successful ssk insert bytes received average current value chk fetch successful chk fetch bytes sent average current value successful chk fetch bytes received average current value ssk fetch successful ssk fetch bytes sent average current value successful ssk fetch bytes received average current value chk offer reply successful chk offer reply bytes sent average current value successful chk offer reply bytes received average current value ssk offer reply successful ssk offer reply bytes sent average current value successful ssk offer reply bytes received average current value dumpbytecostaverages remotechkinsertbytessentaverage currentvalue remotechkinsertbytesreceivedaverage currentvalue remotesskinsertbytessentaverage currentvalue remotesskinsertbytesreceivedaverage currentvalue remotechkfetchbytessentaverage currentvalue remotechkfetchbytesreceivedaverage currentvalue remotesskfetchbytessentaverage currentvalue remotesskfetchbytesreceivedaverage currentvalue localchkinsertbytessentaverage currentvalue localchkinsertbytesreceivedaverage currentvalue localsskinsertbytessentaverage currentvalue localsskinsertbytesreceivedaverage currentvalue localchkfetchbytessentaverage currentvalue localchkfetchbytesreceivedaverage currentvalue localsskfetchbytessentaverage currentvalue localsskfetchbytesreceivedaverage currentvalue successfulchkinsertbytessentaverage currentvalue successfulchkinsertbytesreceivedaverage currentvalue successfulsskinsertbytessentaverage currentvalue successfulsskinsertbytesreceivedaverage currentvalue successfulchkfetchbytessentaverage currentvalue successfulchkfetchbytesreceivedaverage currentvalue successfulsskfetchbytessentaverage currentvalue successfulsskfetchbytesreceivedaverage currentvalue successfulchkofferreplybytessentaverage currentvalue successfulchkofferreplybytesreceivedaverage currentvalue successfulsskofferreplybytessentaverage currentvalue successfulsskofferreplybytesreceivedaverage currentvalue public double get bwlimit delay time return throttled packet send average current value getbwlimitdelaytime throttledpacketsendaverage currentvalue public double get node average ping time return node pinger average ping time getnodeaveragepingtime nodepinger averagepingtime public int get opennet size estimate long timestamp if node opennet null return 0 return node opennet get network size estimate timestamp getopennetsizeestimate getnetworksizeestimate return node opennet get network size estimate timestamp public int get darknet size estimate long timestamp return node lm get network size estimate timestamp getnetworksizeestimate getdarknetsizeestimate getnetworksizeestimate public object get known locations long timestamp return node lm get known locations timestamp getknownlocations getknownlocations public double p reject incoming instantly return p instant reject incoming current value prejectincominginstantly pinstantrejectincoming currentvalue update peer manager user alert stats if the timer has expired only called from packet sender so doesn t need sync public void maybe update peer manager user alert stats long now if now next peer manager user alert stats update time if get bwlimit delay time max bwlimit delay time alert threshold if first bwlimit delay time threshold break 0 first bwlimit delay time threshold break now else first bwlimit delay time threshold break 0 if first bwlimit delay time threshold break 0 now first bwlimit delay time threshold break max bwlimit delay time alert delay bwlimit delay alert relevant true else bwlimit delay alert relevant false if get node average ping time max node average ping time alert threshold if first node average ping time threshold break 0 first node average ping time threshold break now else first node average ping time threshold break 0 if first node average ping time threshold break 0 now first node average ping time threshold break max node average ping time alert delay node average ping alert relevant true else node average ping alert relevant false if logdebug logger debug this mupmuas now get bwlimit delay time max bwlimit delay time alert threshold since first bwlimit delay time threshold break bwlimit delay alert relevant get node average ping time max node average ping time alert threshold since first node average ping time threshold break node average ping alert relevant next peer manager user alert stats update time now peer manager user alert stats update interval peermanageruseralertstats packetsender maybeupdatepeermanageruseralertstats nextpeermanageruseralertstatsupdatetime getbwlimitdelaytime max_bwlimit_delay_time_alert_threshold firstbwlimitdelaytimethresholdbreak firstbwlimitdelaytimethresholdbreak firstbwlimitdelaytimethresholdbreak firstbwlimitdelaytimethresholdbreak firstbwlimitdelaytimethresholdbreak max_bwlimit_delay_time_alert_delay bwlimitdelayalertrelevant bwlimitdelayalertrelevant getnodeaveragepingtime max_node_average_ping_time_alert_threshold firstnodeaveragepingtimethresholdbreak firstnodeaveragepingtimethresholdbreak firstnodeaveragepingtimethresholdbreak firstnodeaveragepingtimethresholdbreak firstnodeaveragepingtimethresholdbreak max_node_average_ping_time_alert_delay nodeaveragepingalertrelevant nodeaveragepingalertrelevant getbwlimitdelaytime max_bwlimit_delay_time_alert_threshold firstbwlimitdelaytimethresholdbreak bwlimitdelayalertrelevant getnodeaveragepingtime max_node_average_ping_time_alert_threshold firstnodeaveragepingtimethresholdbreak nodeaveragepingalertrelevant nextpeermanageruseralertstatsupdatetime peermanageruseralertstatsupdateinterval public simple field set persist throttles to field set simple field set fs new simple field set true fs put remote chk fetch bytes sent average remote chk fetch bytes sent average export field set true fs put remote ssk fetch bytes sent average remote ssk fetch bytes sent average export field set true fs put remote chk insert bytes sent average remote chk insert bytes sent average export field set true fs put remote ssk insert bytes sent average remote ssk insert bytes sent average export field set true fs put remote chk fetch bytes received average remote chk fetch bytes received average export field set true fs put remote ssk fetch bytes received average remote ssk fetch bytes received average export field set true fs put remote chk insert bytes received average remote chk insert bytes received average export field set true fs put remote ssk insert bytes received average remote ssk insert bytes received average export field set true fs put local chk fetch bytes sent average local chk fetch bytes sent average export field set true fs put local ssk fetch bytes sent average local ssk fetch bytes sent average export field set true fs put local chk insert bytes sent average local chk insert bytes sent average export field set true fs put local ssk insert bytes sent average local ssk insert bytes sent average export field set true fs put local chk fetch bytes received average local chk fetch bytes received average export field set true fs put local ssk fetch bytes received average local ssk fetch bytes received average export field set true fs put local chk insert bytes received average local chk insert bytes received average export field set true fs put local ssk insert bytes received average local ssk insert bytes received average export field set true fs put successful chk fetch bytes sent average successful chk fetch bytes sent average export field set true fs put successful ssk fetch bytes sent average successful ssk fetch bytes sent average export field set true fs put successful chk insert bytes sent average successful chk insert bytes sent average export field set true fs put successful ssk insert bytes sent average successful ssk insert bytes sent average export field set true fs put successful chk offer reply bytes sent average successful chk offer reply bytes sent average export field set true fs put successful ssk offer reply bytes sent average successful ssk offer reply bytes sent average export field set true fs put successful chk fetch bytes received average successful chk fetch bytes received average export field set true fs put successful ssk fetch bytes received average successful ssk fetch bytes received average export field set true fs put successful chk insert bytes received average successful chk insert bytes received average export field set true fs put successful ssk insert bytes received average successful ssk insert bytes received average export field set true fs put successful chk offer reply bytes received average successful chk offer reply bytes received average export field set true fs put successful ssk offer reply bytes received average successful ssk offer reply bytes received average export field set true these are not really part of the throttling data but are also running averages which should be persisted fs put average cache location avg cache location export field set true fs put average store location avg store location export field set true fs put average cache success location avg cache success export field set true fs put average store success location avg store success export field set true fs put average request location avg request location export field set true return fs simplefieldset persistthrottlestofieldset simplefieldset simplefieldset remotechkfetchbytessentaverage remotechkfetchbytessentaverage exportfieldset remotesskfetchbytessentaverage remotesskfetchbytessentaverage exportfieldset remotechkinsertbytessentaverage remotechkinsertbytessentaverage exportfieldset remotesskinsertbytessentaverage remotesskinsertbytessentaverage exportfieldset remotechkfetchbytesreceivedaverage remotechkfetchbytesreceivedaverage exportfieldset remotesskfetchbytesreceivedaverage remotesskfetchbytesreceivedaverage exportfieldset remotechkinsertbytesreceivedaverage remotechkinsertbytesreceivedaverage exportfieldset remotesskinsertbytesreceivedaverage remotesskinsertbytesreceivedaverage exportfieldset localchkfetchbytessentaverage localchkfetchbytessentaverage exportfieldset localsskfetchbytessentaverage localsskfetchbytessentaverage exportfieldset localchkinsertbytessentaverage localchkinsertbytessentaverage exportfieldset localsskinsertbytessentaverage localsskinsertbytessentaverage exportfieldset localchkfetchbytesreceivedaverage localchkfetchbytesreceivedaverage exportfieldset localsskfetchbytesreceivedaverage localsskfetchbytesreceivedaverage exportfieldset localchkinsertbytesreceivedaverage localchkinsertbytesreceivedaverage exportfieldset localsskinsertbytesreceivedaverage localsskinsertbytesreceivedaverage exportfieldset successfulchkfetchbytessentaverage successfulchkfetchbytessentaverage exportfieldset successfulsskfetchbytessentaverage successfulsskfetchbytessentaverage exportfieldset successfulchkinsertbytessentaverage successfulchkinsertbytessentaverage exportfieldset successfulsskinsertbytessentaverage successfulsskinsertbytessentaverage exportfieldset successfulchkofferreplybytessentaverage successfulchkofferreplybytessentaverage exportfieldset successfulsskofferreplybytessentaverage successfulsskofferreplybytessentaverage exportfieldset successfulchkfetchbytesreceivedaverage successfulchkfetchbytesreceivedaverage exportfieldset successfulsskfetchbytesreceivedaverage successfulsskfetchbytesreceivedaverage exportfieldset successfulchkinsertbytesreceivedaverage successfulchkinsertbytesreceivedaverage exportfieldset successfulsskinsertbytesreceivedaverage successfulsskinsertbytesreceivedaverage exportfieldset successfulchkofferreplybytesreceivedaverage successfulchkofferreplybytesreceivedaverage exportfieldset successfulsskofferreplybytesreceivedaverage successfulsskofferreplybytesreceivedaverage exportfieldset averagecachelocation avgcachelocation exportfieldset averagestorelocation avgstorelocation exportfieldset averagecachesuccesslocation avgcachesuccess exportfieldset averagestoresuccesslocation avgstoresuccess exportfieldset averagerequestlocation avgrequestlocation exportfieldset update the node wide bandwidth i o stats if the timer has expired public void maybe update nodeio stats long now if now next nodeio stats update time long io stats node collector get totalio long outdiff long indiff synchronized io stat sync previous output stat last output stat previous input stat last input stat previous io stat time last io stat time last output stat io stats 0 last input stat io stats 1 last io stat time now outdiff last output stat previous output stat indiff last input stat previous input stat if logminor logger minor this last 2 seconds input indiff output outdiff next nodeio stats update time now nodeio stats update interval maybeupdatenodeiostats nextnodeiostatsupdatetime io_stats gettotalio iostatsync previous_output_stat last_output_stat previous_input_stat last_input_stat previous_io_stat_time last_io_stat_time last_output_stat io_stats last_input_stat io_stats last_io_stat_time last_output_stat previous_output_stat last_input_stat previous_input_stat nextnodeiostatsupdatetime nodeiostatsupdateinterval public long get nodeio stats long result new long 6 synchronized io stat sync result 0 previous output stat result 1 previous input stat result 2 previous io stat time result 3 last output stat result 4 last input stat result 5 last io stat time return result getnodeiostats iostatsync previous_output_stat previous_input_stat previous_io_stat_time last_output_stat last_input_stat last_io_stat_time public void wait until not overloaded boolean is insert while thread limit get active thread count try thread sleep 5000 catch interrupted exception e waituntilnotoverloaded isinsert threadlimit getactivethreadcount interruptedexception public int get active thread count return root thread group active count node executor get waiting threads count getactivethreadcount rootthreadgroup activecount getwaitingthreadscount public int get active threads by priority return active threads by priorities getactivethreadsbypriority activethreadsbypriorities public int get waiting threads by priority return waiting threads by priorities getwaitingthreadsbypriority waitingthreadsbypriorities public int get thread limit return thread limit getthreadlimit threadlimit public simple field set export volatile field set simple field set fs new simple field set true long now system current time millis fs put is using wrapper node is using wrapper long node uptime seconds 0 synchronized this fs put startup time node startup time node uptime seconds now node startup time 1000 if node uptime seconds 0 node uptime seconds 1 prevent division by zero fs put uptime seconds node uptime seconds fs put average ping time get node average ping time fs put bwlimit delay time get bwlimit delay time fs put opennet size estimate session get opennet size estimate 1 int opennet size estimate24hour recent get opennet size estimate now 24 60 60 1000 24 hours fs put opennet size estimate24hour recent opennet size estimate24hour recent int opennet size estimate48hour recent get opennet size estimate now 48 60 60 1000 48 hours fs put opennet size estimate48hour recent opennet size estimate48hour recent fs put network size estimate session get darknet size estimate 1 int network size estimate24hour recent get darknet size estimate now 24 60 60 1000 24 hours fs put network size estimate24hour recent network size estimate24hour recent int network size estimate48hour recent get darknet size estimate now 48 60 60 1000 48 hours fs put network size estimate48hour recent network size estimate48hour recent fs put routing miss distance routing miss distance current value fs put backed off percent backed off percent current value fs put p instant reject p reject incoming instantly fs put unclaimedfifo size node usm get unclaimedfifo size gather connection statistics peer node status peer node statuses peers get peer node statuses true int number of seed servers get count seed servers peer node statuses int number of seed clients get count seed clients peer node statuses int number of connected peer node status get peer status count peer node statuses peer manager peer node status connected int number of routing backed off peer node status get peer status count peer node statuses peer manager peer node status routing backed off int number of too new peer node status get peer status count peer node statuses peer manager peer node status too new int number of too old peer node status get peer status count peer node statuses peer manager peer node status too old int number of disconnected peer node status get peer status count peer node statuses peer manager peer node status disconnected int number of never connected peer node status get peer status count peer node statuses peer manager peer node status never connected int number of disabled peer node status get peer status count peer node statuses peer manager peer node status disabled int number of bursting peer node status get peer status count peer node statuses peer manager peer node status bursting int number of listening peer node status get peer status count peer node statuses peer manager peer node status listening int number of listen only peer node status get peer status count peer node statuses peer manager peer node status listen only int number of simple connected number of connected number of routing backed off int number of not connected number of too new number of too old number of disconnected number of never connected number of disabled number of bursting number of listening number of listen only fs put number of seed servers number of seed servers fs put number of seed clients number of seed clients fs put number of connected number of connected fs put number of routing backed off number of routing backed off fs put number of too new number of too new fs put number of too old number of too old fs put number of disconnected number of disconnected fs put number of never connected number of never connected fs put number of disabled number of disabled fs put number of bursting number of bursting fs put number of listening number of listening fs put number of listen only number of listen only fs put number of simple connected number of simple connected fs put number of not connected number of not connected fs put number of insert senders node get num insert senders fs put number of request senders node get num request senders fs put number of transferring request senders node get num transferring request senders fs put number ofark fetchers node get numark fetchers long total node collector get totalio long total output rate total 0 node uptime seconds long total input rate total 1 node uptime seconds long total payload output node get total payload sent long total payload output rate total payload output node uptime seconds int total payload output percent total 0 0 1 int 100 total payload output total 0 fs put total output bytes total 0 fs put total output rate total output rate fs put total payload output bytes total payload output fs put total payload output rate total payload output rate fs put total payload output percent total payload output percent fs put total input bytes total 1 fs put total input rate total input rate long rate get nodeio stats long deltams rate 5 rate 2 double recent output rate deltams 0 0 1000 0 rate 3 rate 0 deltams double recent input rate deltams 0 0 1000 0 rate 4 rate 1 deltams fs put recent output rate recent output rate fs put recent input rate recent input rate string routing backoff reasons peers get peer node routing backoff reasons if routing backoff reasons length 0 for int i 0 i routing backoff reasons length i fs put number with routing backoff reasons routing backoff reasons i peers get peer node routing backoff reason size routing backoff reasons i double swaps node get swaps double no swaps node get no swaps double number of remote peer locations seen in swaps node get number of remote peer locations seen in swaps fs put single number of remote peer locations seen in swaps double to string number of remote peer locations seen in swaps double avg connected peers per node 0 0 if number of remote peer locations seen in swaps 0 0 swaps 0 0 no swaps 0 0 avg connected peers per node number of remote peer locations seen in swaps swaps no swaps fs put single avg connected peers per node double to string avg connected peers per node int started swaps node get started swaps int swaps rejected already locked node get swaps rejected already locked int swaps rejected nowhere to go node get swaps rejected nowhere to go int swaps rejected rate limit node get swaps rejected rate limit int swaps rejected recognizedid node get swaps rejected recognizedid double location change per session node get location change session double location change per swap 0 0 double location change per minute 0 0 double swaps per minute 0 0 double no swaps per minute 0 0 double swaps per no swaps 0 0 if swaps 0 location change per swap location change per session swaps if swaps 0 0 node uptime seconds 60 location change per minute location change per session node uptime seconds 60 0 if swaps 0 0 node uptime seconds 60 swaps per minute swaps node uptime seconds 60 0 if no swaps 0 0 node uptime seconds 60 no swaps per minute no swaps node uptime seconds 60 0 if swaps 0 0 no swaps 0 0 swaps per no swaps swaps no swaps fs put location change per session location change per session fs put location change per swap location change per swap fs put location change per minute location change per minute fs put swaps per minute swaps per minute fs put no swaps per minute no swaps per minute fs put swaps per no swaps swaps per no swaps fs put swaps swaps fs put no swaps no swaps fs put started swaps started swaps fs put swaps rejected already locked swaps rejected already locked fs put swaps rejected nowhere to go swaps rejected nowhere to go fs put swaps rejected rate limit swaps rejected rate limit fs put swaps rejected recognizedid swaps rejected recognizedid long fix32kb 32 1024 long cached keys node get chk datacache key count long cached size cached keys fix32kb long store keys node get chk datastore key count long store size store keys fix32kb long overall keys cached keys store keys long overall size cached size store size long max overall keys node get max total keys long max overall size max overall keys fix32kb double percent overall keys of max double overall keys 100 double max overall keys long cached store hits node get chk datacache hits long cached store misses node get chk datacache misses long cache accesses cached store hits cached store misses double percent cached store hits of accesses double cached store hits 100 double cache accesses long store hits node get chk datastore hits long store misses node get chk datastore misses long store accesses store hits store misses double percent store hits of accesses double store hits 100 double store accesses long overall accesses store accesses cache accesses double avg store access rate double overall accesses double node uptime seconds fs put cached keys cached keys fs put cached size cached size fs put store keys store keys fs put store size store size fs put overall keys overall keys fs put overall size overall size fs put max overall keys max overall keys fs put max overall size max overall size fs put percent overall keys of max percent overall keys of max fs put cached store hits cached store hits fs put cached store misses cached store misses fs put cache accesses cache accesses fs put percent cached store hits of accesses percent cached store hits of accesses fs put store hits simplefieldset exportvolatilefieldset simplefieldset simplefieldset currenttimemillis isusingwrapper isusingwrapper nodeuptimeseconds startuptime startuptime nodeuptimeseconds startuptime nodeuptimeseconds nodeuptimeseconds uptimeseconds nodeuptimeseconds averagepingtime getnodeaveragepingtime bwlimitdelaytime getbwlimitdelaytime opennetsizeestimatesession getopennetsizeestimate opennetsizeestimate24hourrecent getopennetsizeestimate opennetsizeestimate24hourrecent opennetsizeestimate24hourrecent opennetsizeestimate48hourrecent getopennetsizeestimate opennetsizeestimate48hourrecent opennetsizeestimate48hourrecent networksizeestimatesession getdarknetsizeestimate networksizeestimate24hourrecent getdarknetsizeestimate networksizeestimate24hourrecent networksizeestimate24hourrecent networksizeestimate48hourrecent getdarknetsizeestimate networksizeestimate48hourrecent networksizeestimate48hourrecent routingmissdistance routingmissdistance currentvalue backedoffpercent backedoffpercent currentvalue pinstantreject prejectincominginstantly unclaimedfifosize getunclaimedfifosize peernodestatus peernodestatuses getpeernodestatuses numberofseedservers getcountseedservers peernodestatuses numberofseedclients getcountseedclients peernodestatuses numberofconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_connected numberofroutingbackedoff peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_routing_backed_off numberoftoonew peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_too_new numberoftooold peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_too_old numberofdisconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disconnected numberofneverconnected peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_never_connected numberofdisabled peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_disabled numberofbursting peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_bursting numberoflistening peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_listening numberoflistenonly peernodestatus getpeerstatuscount peernodestatuses peermanager peer_node_status_listen_only numberofsimpleconnected numberofconnected numberofroutingbackedoff numberofnotconnected numberoftoonew numberoftooold numberofdisconnected numberofneverconnected numberofdisabled numberofbursting numberoflistening numberoflistenonly numberofseedservers numberofseedservers numberofseedclients numberofseedclients numberofconnected numberofconnected numberofroutingbackedoff numberofroutingbackedoff numberoftoonew numberoftoonew numberoftooold numberoftooold numberofdisconnected numberofdisconnected numberofneverconnected numberofneverconnected numberofdisabled numberofdisabled numberofbursting numberofbursting numberoflistening numberoflistening numberoflistenonly numberoflistenonly numberofsimpleconnected numberofsimpleconnected numberofnotconnected numberofnotconnected numberofinsertsenders getnuminsertsenders numberofrequestsenders getnumrequestsenders numberoftransferringrequestsenders getnumtransferringrequestsenders numberofarkfetchers getnumarkfetchers gettotalio total_output_rate nodeuptimeseconds total_input_rate nodeuptimeseconds totalpayloadoutput gettotalpayloadsent total_payload_output_rate totalpayloadoutput nodeuptimeseconds total_payload_output_percent totalpayloadoutput totaloutputbytes totaloutputrate total_output_rate totalpayloadoutputbytes totalpayloadoutput totalpayloadoutputrate total_payload_output_rate totalpayloadoutputpercent total_payload_output_percent totalinputbytes totalinputrate total_input_rate getnodeiostats recent_output_rate recent_input_rate recentoutputrate recent_output_rate recentinputrate recent_input_rate routingbackoffreasons getpeernoderoutingbackoffreasons routingbackoffreasons routingbackoffreasons numberwithroutingbackoffreasons routingbackoffreasons getpeernoderoutingbackoffreasonsize routingbackoffreasons getswaps noswaps getnoswaps numberofremotepeerlocationsseeninswaps getnumberofremotepeerlocationsseeninswaps putsingle numberofremotepeerlocationsseeninswaps tostring numberofremotepeerlocationsseeninswaps avgconnectedpeerspernode numberofremotepeerlocationsseeninswaps noswaps avgconnectedpeerspernode numberofremotepeerlocationsseeninswaps noswaps putsingle avgconnectedpeerspernode tostring avgconnectedpeerspernode startedswaps getstartedswaps swapsrejectedalreadylocked getswapsrejectedalreadylocked swapsrejectednowheretogo getswapsrejectednowheretogo swapsrejectedratelimit getswapsrejectedratelimit swapsrejectedrecognizedid getswapsrejectedrecognizedid locationchangepersession getlocationchangesession locationchangeperswap locationchangeperminute swapsperminute noswapsperminute swapspernoswaps locationchangeperswap locationchangepersession nodeuptimeseconds locationchangeperminute locationchangepersession nodeuptimeseconds nodeuptimeseconds swapsperminute nodeuptimeseconds noswaps nodeuptimeseconds noswapsperminute noswaps nodeuptimeseconds noswaps swapspernoswaps noswaps locationchangepersession locationchangepersession locationchangeperswap locationchangeperswap locationchangeperminute locationchangeperminute swapsperminute swapsperminute noswapsperminute noswapsperminute swapspernoswaps swapspernoswaps noswaps noswaps startedswaps startedswaps swapsrejectedalreadylocked swapsrejectedalreadylocked swapsrejectednowheretogo swapsrejectednowheretogo swapsrejectedratelimit swapsrejectedratelimit swapsrejectedrecognizedid swapsrejectedrecognizedid cachedkeys getchkdatacache keycount cachedsize cachedkeys storekeys getchkdatastore keycount storesize storekeys overallkeys cachedkeys storekeys overallsize cachedsize storesize maxoverallkeys getmaxtotalkeys maxoverallsize maxoverallkeys percentoverallkeysofmax overallkeys maxoverallkeys cachedstorehits getchkdatacache cachedstoremisses getchkdatacache cacheaccesses cachedstorehits cachedstoremisses percentcachedstorehitsofaccesses cachedstorehits cacheaccesses storehits getchkdatastore storemisses getchkdatastore storeaccesses storehits storemisses percentstorehitsofaccesses storehits storeaccesses overallaccesses storeaccesses cacheaccesses avgstoreaccessrate overallaccesses nodeuptimeseconds cachedkeys cachedkeys cachedsize cachedsize storekeys storekeys storesize storesize overallkeys overallkeys overallsize overallsize maxoverallkeys maxoverallkeys maxoverallsize maxoverallsize percentoverallkeysofmax percentoverallkeysofmax cachedstorehits cachedstorehits cachedstoremisses cachedstoremisses cacheaccesses cacheaccesses percentcachedstorehitsofaccesses percentcachedstorehitsofaccesses storehits public void set output limit int obw limit request output throttle change nanos and bucket size int 1000l 1000l 1000l obw limit math max obw limit 60 32768 20 if node input limit default set input limit obw limit 4 setoutputlimit obwlimit requestoutputthrottle changenanosandbucketsize obwlimit obwlimit inputlimitdefault setinputlimit obwlimit public void set input limit int ibw limit request input throttle change nanos and bucket size int 1000l 1000l 1000l ibw limit math max ibw limit 60 32768 20 setinputlimit ibwlimit requestinputthrottle changenanosandbucketsize ibwlimit ibwlimit public boolean is testnet enabled return node is testnet enabled istestnetenabled istestnetenabled public boolean get reject reasons table html node table return preemptive reject reasons to table rows table 0 getrejectreasonstable htmlnode preemptiverejectreasons totablerows public boolean get local reject reasons table html node table return local preemptive reject reasons to table rows table 0 getlocalrejectreasonstable htmlnode localpreemptiverejectreasons totablerows public void request completed boolean succeeded boolean is remote boolean isssk global fetchp success report succeeded 1 0 0 0 if isssk ssk fetchp success report succeeded 1 0 0 0 else chk fetchp success report succeeded 1 0 0 0 if is remote remote fetchp success report succeeded 1 0 0 0 else local fetchp success report succeeded 1 0 0 0 requestcompleted isremote globalfetchpsuccess sskfetchpsuccess chkfetchpsuccess isremote remotefetchpsuccess localfetchpsuccess public void fill success rate box html node parent html node list parent add child table border 0 final trivial running average averages new trivial running average global fetchp success chk fetchp success ssk fetchp success local fetchp success remote fetchp success block transferp success block transfer fail turtled block transfer fail timeout final string names new string fixme l10n but atm this only shows up in advanced mode all requests ch ks ss ks local requests remote requests block transfers turtled downstream transfers timed out html node row list add child tr row add child th group row add child th p success row add child th count for int i 0 i averages length i row list add child tr row add child td names i if averages i count reports 0 row add child td row add child td 0 else row add child td fix3p3pct format averages i current value row add child td thousend point format averages i count reports row list add child tr row add child td turtle requests long total long succeeded synchronized this total turtle transfers completed succeeded turtle successes if total 0 row add child td row add child td 0 else row add child td fix3p3pct format double succeeded total row add child td thousend point format total fillsuccessratebox htmlnode htmlnode addchild trivialrunningaverage trivialrunningaverage globalfetchpsuccess chkfetchpsuccess sskfetchpsuccess localfetchpsuccess remotefetchpsuccess blocktransferpsuccess blocktransferfailturtled blocktransferfailtimeout chks ssks htmlnode addchild addchild addchild addchild addchild addchild countreports addchild addchild addchild currentvalue addchild thousendpoint countreports addchild addchild turtletransferscompleted turtlesuccesses addchild addchild addchild addchild thousendpoint public synchronized void request sent bytes boolean ssk int x if ssk ssk request sent bytes x else chk request sent bytes x requestsentbytes sskrequestsentbytes chkrequestsentbytes public synchronized void request received bytes boolean ssk int x if ssk ssk request rcvd bytes x else chk request rcvd bytes x requestreceivedbytes sskrequestrcvdbytes chkrequestrcvdbytes public synchronized void insert sent bytes boolean ssk int x if logdebug logger debug this insert sent bytes ssk x if ssk ssk insert sent bytes x else chk insert sent bytes x insertsentbytes insertsentbytes sskinsertsentbytes chkinsertsentbytes public synchronized void insert received bytes boolean ssk int x if ssk ssk insert rcvd bytes x else chk insert rcvd bytes x insertreceivedbytes sskinsertrcvdbytes chkinsertrcvdbytes public synchronized long getchk request total bytes sent return chk request sent bytes getchkrequesttotalbytessent chkrequestsentbytes public synchronized long getssk request total bytes sent return ssk request sent bytes getsskrequesttotalbytessent sskrequestsentbytes public synchronized long getchk insert total bytes sent return chk insert sent bytes getchkinserttotalbytessent chkinsertsentbytes public synchronized long getssk insert total bytes sent return ssk insert sent bytes getsskinserttotalbytessent sskinsertsentbytes private long offered keys sender sent bytes public synchronized void offered keys sender received bytes int x offered keys sender rcvd bytes x offeredkeyssendersentbytes offeredkeyssenderreceivedbytes offeredkeyssenderrcvdbytes return the number of bytes sent in replying to fnp get offered key s public synchronized void offered keys sender sent bytes int x offered keys sender sent bytes x fnpgetofferedkey offeredkeyssendersentbytes offeredkeyssendersentbytes public long get offered keys total bytes received return offered keys sender rcvd bytes getofferedkeystotalbytesreceived offeredkeyssenderrcvdbytes public long get offered keys total bytes sent return offered keys sender sent bytes getofferedkeystotalbytessent offeredkeyssendersentbytes public void received bytes int x synchronized node stats this offer keys rcvd bytes x receivedbytes nodestats offerkeysrcvdbytes public void sent bytes int x synchronized node stats this offer keys sent bytes x sentbytes nodestats offerkeyssentbytes public void sent payload int x ignore sentpayload public synchronized long get offers sent bytes sent return offer keys sent bytes getofferssentbytessent offerkeyssentbytes private long swapping sent bytes public synchronized void swapping received bytes int x swapping rcvd bytes x swappingsentbytes swappingreceivedbytes swappingrcvdbytes public synchronized void swapping sent bytes int x swapping sent bytes x swappingsentbytes swappingsentbytes public synchronized long get swapping total bytes received return swapping rcvd bytes getswappingtotalbytesreceived swappingrcvdbytes public synchronized long get swapping total bytes sent return swapping sent bytes getswappingtotalbytessent swappingsentbytes private long total auth bytes sent public synchronized void report auth bytes int x total auth bytes sent x totalauthbytessent reportauthbytes totalauthbytessent public synchronized long get total auth bytes sent return total auth bytes sent gettotalauthbytessent totalauthbytessent public final byte counter resend byte counter new byte counter public void received bytes int x ignore bytecounter resendbytecounter bytecounter receivedbytes public void sent bytes int x synchronized node stats this resend bytes sent x sentbytes nodestats resendbytessent public void sent payload int x logger error this payload sent in resend byte counter new exception error sentpayload resendbytecounter public synchronized long get resend bytes sent return resend bytes sent getresendbytessent resendbytessent private long uom bytes sent public synchronized void reportuom bytes sent int x uom bytes sent x uombytessent reportuombytessent uombytessent public synchronized long getuom bytes sent return uom bytes sent getuombytessent uombytessent public final byte counter announce byte counter new byte counter public void received bytes int x ignore bytecounter announcebytecounter bytecounter receivedbytes public void sent bytes int x synchronized node stats this announce bytes sent x sentbytes nodestats announcebytessent public void sent payload int x ignore sentpayload public synchronized long get announce bytes sent return announce bytes sent getannouncebytessent announcebytessent byte counter set routing status ctr new byte counter public void received bytes int x impossible logger error this routing status sender received bytes x isn t that impossible bytecounter setroutingstatusctr bytecounter receivedbytes public void sent bytes int x synchronized node stats this routing status bytes sent x sentbytes nodestats routingstatusbytessent public void sent payload int x ignore sentpayload public synchronized long get routing status bytes return routing status bytes sent getroutingstatusbytes routingstatusbytessent private long network coloring sent bytes counter public synchronized void network coloring received bytes int x network coloring received bytes counter x networkcoloringsentbytescounter networkcoloringreceivedbytes networkcoloringreceivedbytescounter public synchronized void network coloring sent bytes int x network coloring sent bytes counter x networkcoloringsentbytes networkcoloringsentbytescounter public synchronized long get network coloring sent bytes return network coloring sent bytes counter getnetworkcoloringsentbytes networkcoloringsentbytescounter private long ping bytes sent public synchronized void ping counter received int x ping bytes received x pingbytessent pingcounterreceived pingbytesreceived public synchronized void ping counter sent int x ping bytes sent x pingcountersent pingbytessent public synchronized long get ping sent bytes return ping bytes sent getpingsentbytes pingbytessent public void received bytes int x synchronized node stats this ssk request rcvd bytes x receivedbytes nodestats sskrequestrcvdbytes public void sent bytes int x synchronized node stats this ssk request sent bytes x sentbytes nodestats sskrequestsentbytes public void sent payload int x ignore sentpayload public void received bytes int x synchronized node stats this chk request rcvd bytes x receivedbytes nodestats chkrequestrcvdbytes public void sent bytes int x synchronized node stats this chk request sent bytes x sentbytes nodestats chkrequestsentbytes public void sent payload int x ignore sentpayload public void received bytes int x synchronized node stats this ssk insert rcvd bytes x receivedbytes nodestats sskinsertrcvdbytes public void sent bytes int x synchronized node stats this ssk insert sent bytes x sentbytes nodestats sskinsertsentbytes public void sent payload int x ignore sentpayload public void received bytes int x synchronized node stats this chk insert rcvd bytes x receivedbytes nodestats chkinsertrcvdbytes public void sent bytes int x synchronized node stats this chk insert sent bytes x sentbytes nodestats chkinsertsentbytes public void sent payload int x ignore sentpayload public void received bytes int x synchronized node stats this probe request rcvd bytes x receivedbytes nodestats proberequestrcvdbytes public void sent bytes int x synchronized node stats this probe request sent bytes x sentbytes nodestats proberequestsentbytes public void sent payload int x ignore sentpayload public synchronized long get probe request sent bytes return probe request sent bytes getproberequestsentbytes proberequestsentbytes public void received bytes int x synchronized node stats this routed message bytes rcvd x receivedbytes nodestats routedmessagebytesrcvd public void sent bytes int x synchronized node stats this routed message bytes sent x sentbytes nodestats routedmessagebytessent public void sent payload int x ignore sentpayload public synchronized long get routed message sent bytes return routed message bytes sent getroutedmessagesentbytes routedmessagebytessent private long disconn bytes sent void disconn bytes received int x this disconn bytes received x disconnbytessent disconnbytesreceived disconnbytesreceived void disconn bytes sent int x this disconn bytes sent x disconnbytessent disconnbytessent public long get disconn bytes sent return disconn bytes sent getdisconnbytessent disconnbytessent public void received bytes int x synchronized node stats this initial messages bytes received x receivedbytes nodestats initialmessagesbytesreceived public void sent bytes int x synchronized node stats this initial messages bytes sent x sentbytes nodestats initialmessagesbytessent public void sent payload int x ignore sentpayload public synchronized long get initial messages bytes sent return initial messages bytes sent getinitialmessagesbytessent initialmessagesbytessent public void received bytes int x synchronized node stats this changedip bytes received x receivedbytes nodestats changedipbytesreceived public void sent bytes int x synchronized node stats this changedip bytes sent x sentbytes nodestats changedipbytessent public void sent payload int x ignore sentpayload public long get changedip bytes sent return changedip bytes sent getchangedipbytessent changedipbytessent public void received bytes int x synchronized node stats this node to node rcvd bytes x receivedbytes nodestats nodetonodercvdbytes public void sent bytes int x synchronized node stats this node to node sent bytes x sentbytes nodestats nodetonodesentbytes public void sent payload int x ignore sentpayload public long get node to node bytes sent return node to node sent bytes getnodetonodebytessent nodetonodesentbytes private long notification only sent bytes synchronized void report notification only packet sent int packet size notification only sent bytes packet size notificationonlysentbytes reportnotificationonlypacketsent packetsize notificationonlysentbytes packetsize public long get notification only packets sent bytes return notification only sent bytes getnotificationonlypacketssentbytes notificationonlysentbytes public synchronized long get sent overhead return offer keys sent bytes offers we have sent swapping sent bytes swapping total auth bytes sent connection setup resend bytes sent resends fixme might be dependant on requests uom bytes sent update over mandatory announce bytes sent announcements routing status bytes sent routing status network coloring sent bytes counter network coloring ping bytes sent ping bytes probe request sent bytes probe requests routed message bytes sent routed test messages disconn bytes sent disconnection related bytes initial messages bytes sent initial messages changedip bytes sent changed ip node to node sent bytes n2n messages notification only sent bytes ack only packets getsentoverhead offerkeyssentbytes swappingsentbytes totalauthbytessent resendbytessent uombytessent announcebytessent routingstatusbytessent networkcoloringsentbytescounter pingbytessent proberequestsentbytes routedmessagebytessent disconnbytessent initialmessagesbytessent changedipbytessent nodetonodesentbytes notificationonlysentbytes the average number of bytes sent per second for things other than requests inserts and offer replies public double get sent overhead per second long uptime node get uptime return get sent overhead 1000 0 uptime getsentoverheadpersecond getuptime getsentoverhead public synchronized void successful block receive block transferp success report 1 0 if logminor logger minor this successful receives block transferp success current value count block transferp success count reports successfulblockreceive blocktransferpsuccess blocktransferpsuccess currentvalue blocktransferpsuccess countreports public synchronized void failed block receive boolean normal fetch boolean timeout boolean turtle if normal fetch block transfer fail turtled report turtle 1 0 0 0 block transfer fail timeout report timeout 1 0 0 0 block transferp success report 0 0 if logminor logger minor this successful receives block transferp success current value count block transferp success count reports failedblockreceive normalfetch normalfetch blocktransferfailturtled blocktransferfailtimeout blocktransferpsuccess blocktransferpsuccess currentvalue blocktransferpsuccess countreports public void report incoming request location double loc assert loc 0 loc 1 0 synchronized incoming requests by loc incoming requests by loc int math floor loc incoming requests by loc length incoming requests accounted reportincomingrequestlocation incomingrequestsbyloc incomingrequestsbyloc incomingrequestsbyloc incomingrequestsaccounted public int get incoming request location int retval int result new int incoming requests by loc length synchronized incoming requests by loc system arraycopy incoming requests by loc 0 result 0 incoming requests by loc length retval 0 incoming requests accounted return result getincomingrequestlocation incomingrequestsbyloc incomingrequestsbyloc incomingrequestsbyloc incomingrequestsbyloc incomingrequestsaccounted public void report outgoing local request location double loc assert loc 0 loc 1 0 synchronized outgoing local request by loc outgoing local request by loc int math floor loc outgoing local request by loc length outgoing local requests accounted reportoutgoinglocalrequestlocation outgoinglocalrequestbyloc outgoinglocalrequestbyloc outgoinglocalrequestbyloc outgoinglocalrequestsaccounted public int get outgoing local request location int retval int result new int outgoing local request by loc length synchronized outgoing local request by loc system arraycopy outgoing local request by loc 0 result 0 outgoing local request by loc length retval 0 outgoing local requests accounted return result getoutgoinglocalrequestlocation outgoinglocalrequestbyloc outgoinglocalrequestbyloc outgoinglocalrequestbyloc outgoinglocalrequestbyloc outgoinglocalrequestsaccounted public void report outgoing request location double loc assert loc 0 loc 1 0 synchronized outgoing request by loc outgoing request by loc int math floor loc outgoing request by loc length outgoing requests accounted reportoutgoingrequestlocation outgoingrequestbyloc outgoingrequestbyloc outgoingrequestbyloc outgoingrequestsaccounted public int get outgoing request location int retval int result new int outgoing request by loc length synchronized outgoing request by loc system arraycopy outgoing request by loc 0 result 0 outgoing request by loc length retval 0 outgoing requests accounted return result getoutgoingrequestlocation outgoingrequestbyloc outgoingrequestbyloc outgoingrequestbyloc outgoingrequestbyloc outgoingrequestsaccounted private int get count seed servers peer node status peer node statuses int count 0 for int peer index 0 peer index peer node statuses length peer index if peer node statuses peer index is seed server count return count getcountseedservers peernodestatus peernodestatuses peerindex peerindex peernodestatuses peerindex peernodestatuses peerindex isseedserver private int get count seed clients peer node status peer node statuses int count 0 for int peer index 0 peer index peer node statuses length peer index if peer node statuses peer index is seed client count return count getcountseedclients peernodestatus peernodestatuses peerindex peerindex peernodestatuses peerindex peernodestatuses peerindex isseedclient public void reportchk time long rtt boolean successful if successful successful localchk fetch time average report rtt else unsuccessful localchk fetch time average report rtt localchk fetch time average report rtt reportchktime successfullocalchkfetchtimeaverage unsuccessfullocalchkfetchtimeaverage localchkfetchtimeaverage public void fill detailed timings box html node html html node table html add child table html node row table add child tr row add child td successful row add child td time util format time long successful localchk fetch time average current value 2 true row table add child tr row add child td unsuccessful row add child td time util format time long unsuccessful localchk fetch time average current value 2 true row table add child tr row add child td average row add child td time util format time long localchk fetch time average current value 2 true filldetailedtimingsbox htmlnode htmlnode addchild htmlnode addchild addchild addchild timeutil formattime successfullocalchkfetchtimeaverage currentvalue addchild addchild addchild timeutil formattime unsuccessfullocalchkfetchtimeaverage currentvalue addchild addchild addchild timeutil formattime localchkfetchtimeaverage currentvalue private long turtle successes synchronized void turtle succeeded turtle successes turtle transfers completed turtlesuccesses turtlesucceeded turtlesuccesses turtletransferscompleted synchronized void turtle failed turtle transfers completed turtlefailed turtletransferscompleted logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private final node node public synchronized void set context client context context this context context setcontext clientcontext suppress warnings unchecked public datastore checker node node this node node int priorities request starter number of priority classes persistent keys new array list priorities for int i 0 i priorities i persistent keys i new array list key persistent getters new array list priorities for int i 0 i priorities i persistent getters i new array list sendable get persistent dont cache new array list priorities for int i 0 i priorities i persistent dont cache i new array list boolean persistent schedulers new array list priorities for int i 0 i priorities i persistent schedulers i new array list client request scheduler persistent checker items new array list priorities for int i 0 i priorities i persistent checker items i new array list datastore checker item persistent block sets new array list priorities for int i 0 i priorities i persistent block sets i new array list block set transient keys new array list priorities for int i 0 i priorities i transient keys i new array list key transient getters new array list priorities for int i 0 i priorities i transient getters i new array list sendable get transient block sets new array list priorities for int i 0 i priorities i transient block sets i new array list block set suppresswarnings datastorechecker requeststarter number_of_priority_classes persistentkeys arraylist persistentkeys arraylist persistentgetters arraylist persistentgetters arraylist sendableget persistentdontcache arraylist persistentdontcache arraylist persistentschedulers arraylist persistentschedulers arraylist clientrequestscheduler persistentcheckeritems arraylist persistentcheckeritems arraylist datastorecheckeritem persistentblocksets arraylist persistentblocksets arraylist blockset transientkeys arraylist transientkeys arraylist transientgetters arraylist transientgetters arraylist sendableget transientblocksets arraylist transientblocksets arraylist blockset private final db job loader new db job public void run object container container client context context load persistent requests container context dbjob dbjob objectcontainer clientcontext loadpersistentrequests public void load persistent requests object container container final client context context int total size 0 synchronized this for int i 0 i persistent keys length i for int j 0 j persistent keys i size j total size persistent keys i get j length if total size max persistent keys if logminor logger minor this persistent datastore checker queue already full return for short p request starter maximum priority class p request starter minimum priority class p final short prio p query query container query query constrain datastore checker item class query descend nodedb handle constrain context nodedb handle and query descend prio constrain prio suppress warnings unchecked object set datastore checker item results query execute for datastore checker item item results if item chosen by context bootid continue sendable get getter item getter if getter null container ext is stored getter if logminor logger minor this ignoring datastore checker item because the sendable get has already been deleted from the database container delete item continue block set blocks item blocks container activate getter 1 boolean dont cache getter dont cache container client request scheduler sched getter get scheduler context synchronized this if persistent getters prio contains getter continue key keys getter list keys container fixme check the store bloom filter using store probably in store item chosen by context bootid container store item synchronized this if persistent getters prio contains getter continue array list key final keys to check new array list key for key key keys key key clone key final keys to check add key key final keys final keys to check to array new key final keys to check size persistent keys prio add final keys persistent getters prio add getter persistent dont cache prio add dont cache persistent schedulers prio add sched persistent checker items prio add item persistent block sets prio add blocks if total size 0 notify all total size final keys length if total size max persistent keys boolean full trim persistent queue prio container notify all if full return else notify all container deactivate getter 1 loadpersistentrequests objectcontainer clientcontext totalsize persistentkeys persistentkeys totalsize persistentkeys totalsize max_persistent_keys requeststarter maximum_priority_class requeststarter minimum_priority_class datastorecheckeritem nodedbhandle nodedbhandle suppresswarnings objectset datastorecheckeritem datastorecheckeritem chosenby sendableget isstored datastorecheckeritem sendableget blockset dontcache dontcache clientrequestscheduler getscheduler persistentgetters listkeys probablyinstore chosenby persistentgetters arraylist finalkeystocheck arraylist clonekey finalkeystocheck finalkeys finalkeystocheck toarray finalkeystocheck persistentkeys finalkeys persistentgetters persistentdontcache dontcache persistentschedulers persistentcheckeritems persistentblocksets totalsize notifyall totalsize finalkeys totalsize max_persistent_keys trimpersistentqueue notifyall notifyall trim the queue of persistent requests until it is just over the limit param min prio only drop from priorities lower than this one return true unless the queue is under the limit private boolean trim persistent queue short prio object container container synchronized this int pre queue size 0 for int i 0 i prio i for int x 0 x persistent keys i size x pre queue size persistent keys i get x length if pre queue size max persistent keys dump everything for int i prio 1 i persistent keys length i for datastore checker item item persistent checker items i item chosen by 0 container store item persistent schedulers i clear persistent dont cache i clear persistent getters i clear persistent keys i clear persistent block sets i clear return true else int post queue size 0 for int i prio 1 i persistent keys length i for int x 0 x persistent keys i size x post queue size persistent keys i get x length if post queue size pre queue size max persistent keys return false need to dump some stuff for int i persistent keys length 1 i prio i while persistent keys i is empty int idx persistent keys i size 1 datastore checker item item persistent checker items i remove idx persistent schedulers i remove idx persistent dont cache i remove idx persistent getters i remove idx key keys persistent keys i remove idx persistent block sets i remove idx item chosen by 0 container store item if post queue size pre queue size keys length max persistent keys return false else post queue size keys length still over the limit return true minprio trimpersistentqueue objectcontainer prequeuesize persistentkeys prequeuesize persistentkeys prequeuesize max_persistent_keys persistentkeys datastorecheckeritem persistentcheckeritems chosenby persistentschedulers persistentdontcache persistentgetters persistentkeys persistentblocksets postqueuesize persistentkeys persistentkeys postqueuesize persistentkeys postqueuesize prequeuesize max_persistent_keys persistentkeys persistentkeys isempty persistentkeys datastorecheckeritem persistentcheckeritems persistentschedulers persistentdontcache persistentgetters persistentkeys persistentblocksets chosenby postqueuesize prequeuesize max_persistent_keys postqueuesize public void queue transient request sendable get getter block set blocks if logminor logger minor this queueing transient request getter key check keys getter list keys null short prio getter get priority class null fixme check using store probably in store array list key final keys to check new array list key synchronized this for key key check keys final keys to check add key transient getters prio add getter transient keys prio add final keys to check to array new key final keys to check size transient block sets prio add blocks notify all queuetransientrequest sendableget blockset checkkeys listkeys getpriorityclass probablyinstore arraylist finalkeystocheck arraylist checkkeys finalkeystocheck transientgetters transientkeys finalkeystocheck toarray finalkeystocheck transientblocksets notifyall queue a persistent request we will store a datastore checker item then check the datastore on the datastore checker thread and then call finish register on the database thread caller must have already stored and registered the has key listener if any param getter public void queue persistent request sendable get getter block set blocks object container container key check keys getter list keys container short prio getter get priority class container boolean dont cache getter dont cache container client request scheduler sched getter get scheduler context datastore checker item item new datastore checker item getter context nodedb handle prio blocks container store item container activate blocks 5 synchronized this fixme only add if queue not full int queue size 0 only count queued keys at no higher priority than this request for short p 0 p prio p for int x 0 x persistent keys p size x queue size persistent keys p get x length if queue size max persistent keys return item chosen by context bootid container store item fixme check using store probably in store array list key final keys to check new array list key for key key check keys final keys to check add key persistent getters prio add getter persistent keys prio add final keys to check to array new key final keys to check size persistent dont cache prio add dont cache persistent schedulers prio add sched persistent checker items prio add item persistent block sets prio add blocks trim persistent queue prio container notify all datastorecheckeritem finishregister haskeylistener queuepersistentrequest sendableget blockset objectcontainer checkkeys listkeys getpriorityclass dontcache dontcache clientrequestscheduler getscheduler datastorecheckeritem datastorecheckeritem nodedbhandle queuesize persistentkeys queuesize persistentkeys queuesize max_persistent_keys chosenby probablyinstore arraylist finalkeystocheck arraylist checkkeys finalkeystocheck persistentgetters persistentkeys finalkeystocheck toarray finalkeystocheck persistentdontcache dontcache persistentschedulers persistentcheckeritems persistentblocksets trimpersistentqueue notifyall public void run while true try real run catch throwable t logger error this caught t in datastore checker thread t realrun private void real run key keys null sendable get getter null boolean persistent false boolean dont cache false client request scheduler sched null datastore checker item item null block set blocks null if the queue is too large don t check any more blocks it is possible that we can check the datastore faster than we can handle the resulting blocks this will cause oom int queue size context job runner get queue size client request scheduler trip pending priority if queue size 500 if the queue is over 500 don t run the datastore checker at all it s entirely possible that looking up blocks in the store will make the situation first because a key which is queued for a non persistent request may also be used by a persistent one fixme consider setting a flag to not only only check transient requests but also check whether the keys are in the persistent bloom filters first and if they are not check them try thread sleep 10 1000 catch interrupted exception e ignore return if it s over 100 don t check blocks from persistent requests boolean not persistent queue size 100 synchronized this while true for short prio 0 prio transient keys length prio if transient keys prio is empty keys transient keys prio remove 0 getter transient getters prio remove 0 persistent false item null blocks transient block sets prio remove 0 if logminor logger minor this checking transient request getter break else if not persistent persistent getters prio is empty keys persistent keys prio remove 0 getter persistent getters prio remove 0 persistent true dont cache persistent dont cache prio remove 0 sched persistent schedulers prio remove 0 item persistent checker items prio remove 0 blocks persistent block sets prio remove 0 break if keys null context job runner queue loader native thread high priority true try wait 100 1000 catch interrupted exception e ok continue break if persistent dont cache getter dont cache null sched getter get scheduler context boolean any valid false for key key keys key block block null if blocks null block blocks get key if blocks null block node fetch key dont cache if block null if logminor logger minor this found key if key instanceof nodessk sched trip pending key block else chk sched trip pending key block else any valid true synchronized this keys to check priority remove key if persistent context job runner queue loader native thread high priority true if persistent final sendable get get getter final client request scheduler scheduler sched final boolean valid any valid final datastore checker item it item context job runner queue new db job public void run object container container client context context if container ext is active get logger error this already activated get if container ext is stored get completed and deleted already if logminor logger minor this already deleted from database container delete it return container activate get 1 scheduler finish register new sendable get get true true container valid it container deactivate get 1 loader run container context native thread norm priority false else sched finish register new sendable get getter false false null any valid item realrun sendableget dontcache clientrequestscheduler datastorecheckeritem blockset queuesize jobrunner getqueuesize clientrequestscheduler trip_pending_priority queuesize interruptedexception notpersistent queuesize transientkeys transientkeys isempty transientkeys transientgetters transientblocksets notpersistent persistentgetters isempty persistentkeys persistentgetters dontcache persistentdontcache persistentschedulers persistentcheckeritems persistentblocksets jobrunner nativethread high_priority interruptedexception dontcache dontcache getscheduler anyvalid keyblock dontcache trippendingkey trippendingkey anyvalid keystocheck jobrunner nativethread high_priority sendableget clientrequestscheduler anyvalid datastorecheckeritem jobrunner dbjob objectcontainer clientcontext isactive isstored finishregister sendableget nativethread norm_priority finishregister sendableget anyvalid public void run object container container client context context if container ext is active get logger error this already activated get if container ext is stored get completed and deleted already if logminor logger minor this already deleted from database container delete it return container activate get 1 scheduler finish register new sendable get get true true container valid it container deactivate get 1 loader run container context objectcontainer clientcontext isactive isstored finishregister sendableget synchronized void wake up notify all wakeup notifyall public void start executor executor string name context job runner queue loader native thread high priority 1 true executor execute this name jobrunner nativethread high_priority public int get priority return native thread norm priority getpriority nativethread norm_priority public boolean object can new object container container logger error this not storing datastore checker in database new exception error return false objectcannew objectcontainer datastorechecker first time wizard toadlet high level simple client client node node node client core core super client this core core this config node config firsttimewizardtoadlet highlevelsimpleclient nodeclientcore override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return wizard step current step wizard step value of request get param step wizard step welcome to string if current step wizard step browser warning html node page node ctx get page maker get page node l10n browser warning page title false ctx html node content node ctx get page maker get content node page node html node infobox content node add child div class infobox infobox normal html node infobox header infobox add child div class infobox header html node infobox content infobox add child div class infobox content infobox header add child l10n browser warning short l10n addl10n substitution infobox content first time wizard toadlet browser warning new string bold bold new string b b infobox content add child p l10n browser warning suggestion infobox content add child p add child a href step wizard step security network l10n get string first time wizard toadlet click continue this writehtml reply ctx 200 ok page node generate return else if current step wizard step security network html node page node ctx get page maker get page node l10n network security page title false ctx html node content node ctx get page maker get content node page node html node infobox content node add child div class infobox infobox normal html node infobox header infobox add child div class infobox header html node infobox content infobox add child div class infobox content infobox header add child l10n sec network threat level short infobox content add child p l10n sec network threat level html node form ctx add form child infobox content network security form html node div form add child div class opennet div string control name security levels network threat level for network threat level level network threat level values html node input input div add child p add child input new string type name value new string radio control name level name input add child b l10n sec network threat level name level input add child l10n addl10n substitution input security levels network threat level choice level new string bold bold new string b b html node inner input add child p add child i l10n addl10n substitution inner security levels network threat level desc level new string bold bold new string b b form add child input new string type name value new string submit network securityf l10n get string first time wizard toadlet continue form add child input new string type name value new string submit cancel l10n get string toadlet cancel this writehtml reply ctx 200 ok page node generate return else if current step wizard step security friends html node page node ctx get page maker get page node l10n friends security page title false ctx html node content node ctx get page maker get content node page node html node infobox content node add child div class infobox infobox normal html node infobox header infobox add child div class infobox header html node infobox content infobox add child div class infobox content infobox header add child l10n sec friends threat level short infobox content add child p l10n sec friends threat level html node form ctx add form child infobox content friends security form html node div form add child div class opennet div string control name security levels friends threat level for friends threat level level friends threat level values html node input input div add child p add child input new string type name value new string radio control name level name input add child b l10n sec friends threat level name level input add child l10n addl10n substitution input security levels friends threat level choice level new string bold bold new string b b html node inner input add child p add child i l10n addl10n substitution inner security levels friends threat level desc level new string bold bold new string b b form add child input new string type name value new string submit friends securityf l10n get string first time wizard toadlet continue form add child input new string type name value new string submit cancel l10n get string toadlet cancel this writehtml reply ctx 200 ok page node generate return else if current step wizard step security physical html node page node ctx get page maker get page node l10n physical security page title false ctx html node content node ctx get page maker get content node page node html node infobox content node add child div class infobox infobox normal html node infobox header infobox add child div class infobox header html node infobox content infobox add child div class infobox content infobox header add child l10n sec physical threat level short infobox content add child p l10n sec physical threat level html node form ctx add form child infobox content physical security form html node div form add child div class opennet div string control name security levels physical threat level for physical threat level level physical threat level values html node input input div add child p add child input new string type name value new string radio control name level name input add child b l10n sec physical threat level name level input add child l10n addl10n substitution input security levels physical threat level choice level new string bold bold new string b b html node inner input add child p add child i l10n addl10n substitution inner security levels physical threat level desc level new string bold bold new string b b form add child input new string type name value new string submit physical securityf l10n get string first time wizard toadlet continue form add child input new string type name value new string submit cancel l10n get string toadlet cancel this writehtml reply ctx 200 ok page node generate return else if current step wizard step name selection attempt to skip one step if possible opennet nodes don t need a name if boolean value of request get param opennet super write temporary redirect ctx step3 toadlet url step wizard step bandwidth return html node page node ctx get page maker get page node l10n step2 title false ctx html node content node ctx get page maker get content node page node html node nname infobox content node add child div class infobox infobox normal html node nname infobox header nname infobox add child div class infobox header html node nname infobox content nname infobox add child div class infobox content nname infobox header add child l10n choose node name nname infobox content add child l10n choose node name long html node nname form ctx add form child nname infobox content nname form nname form add child input name nname nname form add child input new string type name value new string submit nnamef l10n get string first time wizard toadlet continue nname form add child input new string type name value new string submit cancel l10n get string toadlet cancel this writehtml reply ctx 200 ok page node generate return else if current step wizard step bandwidth attempt to skip one step if possible if can autoconfigure bandwidth super write temporary redirect ctx step4 toadlet url step wizard step datastore size return html node page node ctx get page maker get page node l10n step3 title false ctx html node content node ctx get page maker get content node page node html node bandwidth infobox content node add child div class infobox infobox normal html node bandwidthnfobox header bandwidth infobox add child div class infobox header html node bandwidth infobox content bandwidth infobox add child div class infobox content bandwidthnfobox header add child l10n bandwidth limit bandwidth infobox content add child l10n bandwidth limit long html node bandwidth form ctx add form child bandwidth infobox content bw form html node result bandwidth form add child select name bw suppress warnings unchecked option integer size option option integer config get node get option output bandwidth limit if size option is default int current size option get value result add child option new string value selected new string size util format size current on l10n current speed size util format size current s don t forget to update handle post too if you change that result add child option value 8k l10n bwlimit lower speed handleget httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring wizard_step currentstep wizard_step valueof getparam wizard_step tostring currentstep wizard_step browser_warning htmlnode pagenode getpagemaker getpagenode browserwarningpagetitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild htmlnode infoboxheader addchild htmlnode infoboxcontent addchild infoboxheader addchild browserwarningshort addl10nsubstitution infoboxcontent firsttimewizardtoadlet browserwarning infoboxcontent addchild browserwarningsuggestion infoboxcontent addchild addchild wizard_step security_network getstring firsttimewizardtoadlet clickcontinue writehtmlreply pagenode currentstep wizard_step security_network htmlnode pagenode getpagemaker getpagenode networksecuritypagetitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild htmlnode infoboxheader addchild htmlnode infoboxcontent addchild infoboxheader addchild l10nsec networkthreatlevelshort infoboxcontent addchild l10nsec networkthreatlevel htmlnode addformchild infoboxcontent networksecurityform htmlnode addchild opennetdiv controlname networkthreatlevel network_threat_level network_threat_level htmlnode addchild addchild controlname addchild l10nsec networkthreatlevel addchild addl10nsubstitution securitylevels networkthreatlevel htmlnode addchild addchild addl10nsubstitution securitylevels networkthreatlevel addchild networksecurityf getstring firsttimewizardtoadlet addchild getstring writehtmlreply pagenode currentstep wizard_step security_friends htmlnode pagenode getpagemaker getpagenode friendssecuritypagetitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild htmlnode infoboxheader addchild htmlnode infoboxcontent addchild infoboxheader addchild l10nsec friendsthreatlevelshort infoboxcontent addchild l10nsec friendsthreatlevel htmlnode addformchild infoboxcontent friendssecurityform htmlnode addchild opennetdiv controlname friendsthreatlevel friends_threat_level friends_threat_level htmlnode addchild addchild controlname addchild l10nsec friendsthreatlevel addchild addl10nsubstitution securitylevels friendsthreatlevel htmlnode addchild addchild addl10nsubstitution securitylevels friendsthreatlevel addchild friendssecurityf getstring firsttimewizardtoadlet addchild getstring writehtmlreply pagenode currentstep wizard_step security_physical htmlnode pagenode getpagemaker getpagenode physicalsecuritypagetitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild htmlnode infoboxheader addchild htmlnode infoboxcontent addchild infoboxheader addchild l10nsec physicalthreatlevelshort infoboxcontent addchild l10nsec physicalthreatlevel htmlnode addformchild infoboxcontent physicalsecurityform htmlnode addchild opennetdiv controlname physicalthreatlevel physical_threat_level physical_threat_level htmlnode addchild addchild controlname addchild l10nsec physicalthreatlevel addchild addl10nsubstitution securitylevels physicalthreatlevel htmlnode addchild addchild addl10nsubstitution securitylevels physicalthreatlevel addchild physicalsecurityf getstring firsttimewizardtoadlet addchild getstring writehtmlreply pagenode currentstep wizard_step name_selection valueof getparam writetemporaryredirect toadlet_url wizard_step htmlnode pagenode getpagemaker getpagenode step2title htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode nnameinfobox contentnode addchild htmlnode nnameinfoboxheader nnameinfobox addchild htmlnode nnameinfoboxcontent nnameinfobox addchild nnameinfoboxheader addchild choosenodename nnameinfoboxcontent addchild choosenodenamelong htmlnode nnameform addformchild nnameinfoboxcontent nnameform nnameform addchild nnameform addchild getstring firsttimewizardtoadlet nnameform addchild getstring writehtmlreply pagenode currentstep wizard_step canautoconfigurebandwidth writetemporaryredirect toadlet_url wizard_step datastore_size htmlnode pagenode getpagemaker getpagenode step3title htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode bandwidthinfobox contentnode addchild htmlnode bandwidthnfoboxheader bandwidthinfobox addchild htmlnode bandwidthinfoboxcontent bandwidthinfobox addchild bandwidthnfoboxheader addchild bandwidthlimit bandwidthinfoboxcontent addchild bandwidthlimitlong htmlnode bandwidthform addformchild bandwidthinfoboxcontent bwform htmlnode bandwidthform addchild suppresswarnings sizeoption getoption outputbandwidthlimit sizeoption isdefault sizeoption getvalue addchild sizeutil formatsize currentspeed sizeutil formatsize handlepost addchild bwlimitlowerspeed private string l10n sec string key return l10n get string security levels key l10nsec getstring securitylevels private string l10n sec string key string pattern string value return l10n get string security levels key pattern value l10nsec getstring securitylevels override public void handle post uri uri http request request toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return string passwd request get part as string form password 32 boolean no password passwd null passwd equals core form password if no password if logger should log logger minor this logger minor this no password passwd should be core form password super write temporary redirect ctx invalid unhandled data return if request is part set security levels network threat level we don t require a confirmation here since it s one page at a time so there s less information to confuse the user and we don t know whether the node has friends yet etc fixme should we have confirmation here string network threat level request get part as string security levels network threat level 128 network threat level new threat level security levels parse network threat level network threat level if new threat level null super write temporary redirect ctx step1 toadlet url step wizard step security network return if new threat level network threat level maximum new threat level network threat level high if request is part set security levels network threat level confirm request is part set security levels network threat level try confirm html node page node ctx get page maker get page node l10n network security page title ctx html node content ctx get page maker get content node page node html node form node ctx add form child content config form sec levels form node add child input new string type name value new string hidden security levels network threat level network threat level html node infobox form node add child div class infobox infobox information infobox add child div class infobox header l10n sec network threat level confirm title mode security levels localised name new threat level html node infobox content infobox add child div class infobox content if new threat level network threat level maximum html node p infobox content add child p l10n addl10n substitution p security levels maximum network threat level warning new string bold bold new string b b p add child l10n addl10n substitution p security levels max security you need friends new string bold bold new string b b infobox content add child input new string type name value new string checkbox security levels network threat level confirm off l10n sec maximum network threat level checkbox else if new threat level network threat level high html node p infobox content add child p l10n addl10n substitution p first time wizard toadlet high network threat level warning new string bold bold new string b b infobox content add child input new string type name value new string checkbox security levels network threat level confirm off l10n high network threat level checkbox infobox content add child input new string type name value new string hidden security levels network threat level try confirm on form node add child input new string type name value new string hidden seclevels on form node add child input new string type value new string submit l10n get string config toadlet apply form node add child input new string type value new string reset l10n get string config toadlet reset writehtml reply ctx 200 ok page node generate return else if request is part set security levels network threat level confirm request is part set security levels network threat level try confirm super write temporary redirect ctx step1 toadlet url step wizard step security network return core node security levels set threat level new threat level super write temporary redirect ctx step1 toadlet url step wizard step security friends return else if request is part set security levels friends threat level we don t require a confirmation here since it s one page at a time so there s less information to confuse the user and we don t know whether the node has friends yet etc fixme should we have confirmation here string friends threat level request get part as string security levels friends threat level 128 friends threat level new threat level security levels parse friends threat level friends threat level if new threat level null super write temporary redirect ctx step1 toadlet url step wizard step security friends return if new threat level friends threat level high if request is part set security levels friends threat level confirm request is part set security levels friends threat level try confirm html node page node ctx get page maker get page node l10n friends security page title ctx html node content ctx get page maker get content node page node html node form node ctx add form child content config form sec levels form node add child input new string type name value new string hidden security levels friends threat level friends threat level html node infobox form node add child div class infobox infobox information infobox add child div class infobox header l10n sec friends threat level confirm title mode security levels localised name new threat level html node infobox content infobox add child div class infobox content html node p infobox content add child p l10n addl10n substitution p first time wizard toadlet high friends threat level warning new string bold bold new string b b infobox content add child input new string type name value new string checkbox security levels friends threat level confirm off l10n sec high friends threat level checkbox infobox content add child input new string type name value new string hidden security levels friends threat level try confirm on form node add child input new string type name value new string hidden seclevels on form node add child input new string type value new string submit l10n get string config toadlet apply form node add child input new string type value new string reset l10n get string config toadlet reset writehtml reply ctx 200 ok page node generate return else if request is part set security levels friends threat level confirm request is part set security levels friends threat level try confirm super write temporary redirect ctx step1 toadlet url step wizard step security friends return core node security levels set threat level new threat level super write temporary redirect ctx step1 toadlet url step wizard step security physical return else if request is part set security levels physical threat level we don t require a confirmation here since it s one page at a time so there s less information to confuse the user and we don t know whether the node has friends yet etc fixme should we have confirmation here string physical threat level request get part as string security levels physical threat level 128 physical threat level new threat level security levels parse physical threat level physical threat level if new threat level null super write temporary redirect ctx step1 toadlet url step wizard step security physical return core node security levels set threat level new threat level core store config super write temporary redirect ctx step1 toadlet url step wizard step name selection opennet core node is opennet enabled return else if request is part set nnamef string selectedn name request get part as string nname 128 try config get node set name selectedn name logger normal this the node name has been set to selectedn name catch config exception e logger error this should not happen please report e e super write temporary redirect ctx step3 toadlet url step wizard step bandwidth return else if request is part set bwf setupstreambandwidthlimit request get part as string bw 20 drop down options may be 6 chars or less but formatted ones e g old value if re running can be more super write temporary redirect ctx step4 toadlet url step wizard step datastore size return else if request is part set dsf setdatastoresize request get part as string ds 20 drop down options may be 6 chars or less but formatted ones e g old value if re running can be more super write temporary redirect ctx step5 toadlet url step wizard step memory return else if request is part set memoryf string selected memory size request get part as string memoryf 6 int memory size fields parse int selected memory size 1 if memory size 0 wrapper config set wrapper property wrapper java maxmemory selected memory size super write temporary redirect ctx step6 toadlet url step wizard step congratz return super write temporary redirect ctx invalid unhandled handlepost httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring getpartasstring formpassword nopassword formpassword nopassword shouldlog formpassword writetemporaryredirect ispartset networkthreatlevel networkthreatlevel getpartasstring networkthreatlevel network_threat_level newthreatlevel securitylevels parsenetworkthreatlevel networkthreatlevel newthreatlevel writetemporaryredirect toadlet_url wizard_step security_network newthreatlevel network_threat_level newthreatlevel network_threat_level ispartset networkthreatlevel ispartset networkthreatlevel tryconfirm htmlnode pagenode getpagemaker getpagenode networksecuritypagetitle htmlnode getpagemaker getcontentnode pagenode htmlnode formnode addformchild configformseclevels formnode addchild networkthreatlevel networkthreatlevel htmlnode formnode addchild addchild l10nsec networkthreatlevelconfirmtitle securitylevels localisedname newthreatlevel htmlnode infoboxcontent addchild newthreatlevel network_threat_level htmlnode infoboxcontent addchild addl10nsubstitution securitylevels maximumnetworkthreatlevelwarning addchild addl10nsubstitution securitylevels maxsecurityyouneedfriends infoboxcontent addchild networkthreatlevel l10nsec maximumnetworkthreatlevelcheckbox newthreatlevel network_threat_level htmlnode infoboxcontent addchild addl10nsubstitution firsttimewizardtoadlet highnetworkthreatlevelwarning infoboxcontent addchild networkthreatlevel highnetworkthreatlevelcheckbox infoboxcontent addchild networkthreatlevel tryconfirm formnode addchild formnode addchild getstring configtoadlet formnode addchild getstring configtoadlet writehtmlreply pagenode ispartset networkthreatlevel ispartset networkthreatlevel tryconfirm writetemporaryredirect toadlet_url wizard_step security_network securitylevels setthreatlevel newthreatlevel writetemporaryredirect toadlet_url wizard_step security_friends ispartset friendsthreatlevel friendsthreatlevel getpartasstring friendsthreatlevel friends_threat_level newthreatlevel securitylevels parsefriendsthreatlevel friendsthreatlevel newthreatlevel writetemporaryredirect toadlet_url wizard_step security_friends newthreatlevel friends_threat_level ispartset friendsthreatlevel ispartset friendsthreatlevel tryconfirm htmlnode pagenode getpagemaker getpagenode friendssecuritypagetitle htmlnode getpagemaker getcontentnode pagenode htmlnode formnode addformchild configformseclevels formnode addchild friendsthreatlevel friendsthreatlevel htmlnode formnode addchild addchild l10nsec friendsthreatlevelconfirmtitle securitylevels localisedname newthreatlevel htmlnode infoboxcontent addchild htmlnode infoboxcontent addchild addl10nsubstitution firsttimewizardtoadlet highfriendsthreatlevelwarning infoboxcontent addchild friendsthreatlevel l10nsec highfriendsthreatlevelcheckbox infoboxcontent addchild friendsthreatlevel tryconfirm formnode addchild formnode addchild getstring configtoadlet formnode addchild getstring configtoadlet writehtmlreply pagenode ispartset friendsthreatlevel ispartset friendsthreatlevel tryconfirm writetemporaryredirect toadlet_url wizard_step security_friends securitylevels setthreatlevel newthreatlevel writetemporaryredirect toadlet_url wizard_step security_physical ispartset physicalthreatlevel physicalthreatlevel getpartasstring physicalthreatlevel physical_threat_level newthreatlevel securitylevels parsephysicalthreatlevel physicalthreatlevel newthreatlevel writetemporaryredirect toadlet_url wizard_step security_physical securitylevels setthreatlevel newthreatlevel storeconfig writetemporaryredirect toadlet_url wizard_step name_selection isopennetenabled ispartset selectednname getpartasstring selectednname selectednname configexception writetemporaryredirect toadlet_url wizard_step ispartset _setupstreambandwidthlimit getpartasstring writetemporaryredirect toadlet_url wizard_step datastore_size ispartset _setdatastoresize getpartasstring writetemporaryredirect toadlet_url wizard_step ispartset selectedmemorysize getpartasstring memorysize parseint selectedmemorysize memorysize wrapperconfig setwrapperproperty selectedmemorysize writetemporaryredirect toadlet_url wizard_step writetemporaryredirect private string l10n string key return l10n get string first time wizard toadlet key getstring firsttimewizardtoadlet override public string supported methods return get post supportedmethods private void setdatastoresize string selected store size try config get node set store size selected store size logger normal this the store size has been set to selected store size catch config exception e logger error this should not happen please report e e _setdatastoresize selectedstoresize storesize selectedstoresize storesize selectedstoresize configexception private void setupstreambandwidthlimit string selected upload speed try config get node set output bandwidth limit selected upload speed logger normal this the output bandwidth limit has been set to selected upload speed catch config exception e logger error this should not happen please report e e _setupstreambandwidthlimit selecteduploadspeed outputbandwidthlimit selecteduploadspeed outputbandwidthlimit selecteduploadspeed configexception private void setdownstreambandwidthlimit string selected download speed try config get node set input bandwidth limit selected download speed logger normal this the input bandwidth limit has been set to selected download speed catch config exception e logger error this should not happen please report e e _setdownstreambandwidthlimit selecteddownloadspeed inputbandwidthlimit selecteddownloadspeed inputbandwidthlimit selecteddownloadspeed configexception private boolean can autoconfigure bandwidth if config get node get option output bandwidth limit is default return false fred plugin bandwidth indicator bw indicator core node ip detector get bandwidth indicator if bw indicator null return false int downstreambw limit bw indicator get downstream max bit rate if downstreambw limit 0 int bytes downstreambw limit 8 1 string downstreambw limit string size util format size bytes 2 3 setdownstreambandwidthlimit downstreambw limit string logger normal this the node has a bandwidth indicator it has reported downstream downstreambw limit bits sec we will use downstreambw limit string and skip the bandwidth selection step of the wizard we don t mind if the downstreambw limit couldn t be set but upstreambw limit is important int upstreambw limit bw indicator get upstram max bit rate if upstreambw limit 0 int bytes upstreambw limit 8 1 string upstreambw limit string bytes 16384 8k size util format size bytes 2 setupstreambandwidthlimit upstreambw limit string logger normal this the node has a bandwidth indicator it has reported upstream upstreambw limit bits sec we will use upstreambw limit string and skip the bandwidth selection step of the wizard return true else return false canautoconfigurebandwidth getoption outputbandwidthlimit isdefault fredpluginbandwidthindicator bwindicator ipdetector getbandwidthindicator bwindicator downstreambwlimit bwindicator getdownstreammaxbitrate downstreambwlimit downstreambwlimit downstreambwlimitstring sizeutil formatsize _setdownstreambandwidthlimit downstreambwlimitstring bandwidthindicator downstreambwlimit downstreambwlimitstring downstreambwlimit upstreambwlimit upstreambwlimit bwindicator getupstrammaxbitrate upstreambwlimit upstreambwlimit upstreambwlimitstring sizeutil formatsize _setupstreambandwidthlimit upstreambwlimitstring bandwidthindicator upstreambwlimit upstreambwlimitstring private boolean can autoconfigure datastore size if config get node get option store size is default return false use jni to find out the free space on this partition long free space 1 file dir file util get canonical file core node get node dir try class extends file c dir get class method m c get declared method get free space new class 0 if m null long l free space long m invoke dir new object 0 if l free space null free space l free space long value system err println found free space on node s partition on dir size util format size free space catch no such method exception e ignore free space 1 catch throwable t system err println trying to access 1 6 get free space caught t free space 1 if free space 0 return false else string short size null if free space 20 1024 1024 1024 20gb 5 limit 256gb if 20gb free 5 of available disk space maximum of 256gb that s a 128mb bloom filter short size size util format size math min free space 20 256 1024 1024 1024l else if free space 10 1024 1024 1024 10gb 10 if 10gb free 10 of available disk space short size size util format size free space 10 else if free space 5 1024 1024 1024 5gb 512mb if 5gb free default to 512mb short size 512mb else 5gb 256mb short size 256mb setdatastoresize short size return true canautoconfiguredatastoresize getoption storesize isdefault freespace fileutil getcanonicalfile getnodedir getclass getdeclaredmethod getfreespace lfreespace lfreespace freespace lfreespace longvalue sizeutil formatsize freespace nosuchmethodexception freespace getfreespace freespace freespace shortsize freespace shortsize sizeutil formatsize freespace freespace shortsize sizeutil formatsize freespace freespace shortsize shortsize _setdatastoresize shortsize private static final long serial versionuid 1528884682346143213l public node list serialversionuid nodelist public node get node int n return node get n getnode public node get node string name if name null return null int n lists size for int n 0 n n lists n node node get node n string node name node get name if name compare to node name 0 return node return null getnode nlists nlists getnode nodename getname compareto nodename public node get ends with string name if name null return null int n lists size for int n 0 n n lists n node node get node n string node name node get name if node name null continue if node name ends with name true return node return null getendswith nlists nlists getnode nodename getname nodename nodename endswith public message fetcher node my node high level simple client my client string my name identity manager my identity manager message manager my message manager super my node my client my name m identity manager my identity manager m message manager my message manager messagefetcher mynode highlevelsimpleclient myclient myname identitymanager myidentitymanager messagemanager mymessagemanager mynode myclient myname midentitymanager myidentitymanager mmessagemanager mymessagemanager private static int zz unpack action int result new int 357 int offset 0 offset zz unpack action zz action packed 0 offset result return result zzunpackaction zzunpackaction zz_action_packed_0 private static int zz unpack action string packed int offset int result int i 0 index in packed string int j offset index in unpacked array int l packed length while i l int count packed char at i int value packed char at i do result j value while count 0 return j zzunpackaction charat charat private static int zz unpack row map int result new int 357 int offset 0 offset zz unpack row map zz rowmap packed 0 offset result return result zzunpackrowmap zzunpackrowmap zz_rowmap_packed_0 private static int zz unpack row map string packed int offset int result int i 0 index in packed string int j offset index in unpacked array int l packed length while i l int high packed char at i 16 result j high packed char at i return j zzunpackrowmap charat charat private static int zz unpack trans int result new int 16483 int offset 0 offset zz unpack trans zz trans packed 0 offset result return result zzunpacktrans zzunpacktrans zz_trans_packed_0 private static int zz unpack trans string packed int offset int result int i 0 index in packed string int j offset index in unpacked array int l packed length while i l int count packed char at i int value packed char at i value do result j value while count 0 return j zzunpacktrans charat charat private static int zz unpack attribute int result new int 357 int offset 0 offset zz unpack attribute zz attribute packed 0 offset result return result zzunpackattribute zzunpackattribute zz_attribute_packed_0 private static int zz unpack attribute string packed int offset int result int i 0 index in packed string int j offset index in unpacked array int l packed length while i l int count packed char at i int value packed char at i do result j value while count 0 return j zzunpackattribute charat charat writer w null will npe if not initialized properly public void parse throws io exception while yylex null ioexception css tokenizer filter reader r writer w boolean paranoid string check this r this w w this paranoid string check paranoid string check csstokenizerfilter paranoidstringcheck paranoidstringcheck paranoidstringcheck void throw error string s throws io exception throw new illegal state exception you must override throw error throwerror ioexception illegalstateexception throwerror string process importurl string s throws comment exception throw new illegal state exception you must override process importurl processimporturl commentexception illegalstateexception processimporturl string processurl string s throws comment exception throw new illegal state exception you must override processurl commentexception illegalstateexception void log string s system err println css tokenizer filter s csstokenizerfilter void log error string s system err println css tokenizer filter error s logerror csstokenizerfilter static string unquote string s char c if s length 1 if s char at s length 1 c s s substring 1 s length 1 return s else return else return charat static boolean is hex digit char c return a c c f a c c f 0 c c 9 ishexdigit static string l10n string key return l10n get string css tokenizer filter key getstring csstokenizerfilter public string suffix includes any whitespace public decoded string thingy string s if s to lower case locale us starts with url s s substring 4 url length url true char q s char at 0 if q q quote q s s substring 1 else quote string builder buffer new string builder int x 0 boolean just escaping false boolean still escaping false string builder hex escape new string builder while x s length char c s char at x x if just escaping if c n buffer append c just escaping false else if is hex digit c hex escape append c just escaping false still escaping true else buffer append c will need to be reencoded if quote or n just escaping false else if still escaping if is hex digit c hex escape length 6 hex escape append c else if character is whitespace c ignore one whitespace char after an escape int d integer parse int hex escape to string 16 buffer append new string character to chars d still escaping false hex escape new string builder else int d integer parse int hex escape to string 16 buffer append new string character to chars d buffer append c still escaping false hex escape new string builder else if quote c quote break else if quote c break else if c just escaping true else buffer append c data buffer to string if url s length x s char at x x if x s length suffix s substring x else suffix decodedstringthingy tolowercase startswith charat stringbuilder stringbuilder justescaping stillescaping stringbuilder hexescape stringbuilder charat justescaping justescaping ishexdigit hexescape justescaping stillescaping justescaping stillescaping ishexdigit hexescape hexescape iswhitespace parseint hexescape tostring tochars stillescaping hexescape stringbuilder parseint hexescape tostring tochars stillescaping hexescape stringbuilder justescaping tostring charat override public string to string string builder out new string builder if url out append url if quote out append quote out append unescape data if quote out append quote if url out append out append suffix return out to string tostring stringbuilder stringbuilder unescapedata tostring public string unescape data string builder sb new string builder for int i 0 i data length i char c data char at i if c quote c n sb append sb append c return sb to string unescapedata stringbuilder stringbuilder charat tostring string comment encode string s string builder sb new string builder s length for int i 0 i s length i char c s char at i if c sb append else sb append c return sb to string commentencode stringbuilder stringbuilder charat tostring creates a new scanner there is also a java io input stream version of this constructor param in the java io reader to read input from css tokenizer filter java io reader in this zz reader in inputstream csstokenizerfilter zzreader creates a new scanner there is also java io reader version of this constructor param in the java io inputstream to read input from css tokenizer filter java io input stream in this new java io input stream reader in csstokenizerfilter inputstream inputstreamreader unpacks the compressed character translation table param packed the packed character translation table return the unpacked character translation table private static char zz unpackc map string packed char map new char 0x10000 int i 0 index in packed string int j 0 index in unpacked array while i 182 int count packed char at i char value packed char at i do map j value while count 0 return map zzunpackcmap charat charat refills the input buffer return code false code iff there was new input exception java io io exception if any i o error occurs private boolean zz refill throws java io io exception first make room if you can if zz start read 0 system arraycopy zz buffer zz start read zz buffer 0 zz end read zz start read translate stored positions zz end read zz start read zz current pos zz start read zz marked pos zz start read zz pushback pos zz start read zz start read 0 is the buffer big enough if zz current pos zz buffer length if not blow it up char new buffer new char zz current pos 2 system arraycopy zz buffer 0 new buffer 0 zz buffer length zz buffer new buffer finally fill the buffer with new input int num read zz reader read zz buffer zz end read zz buffer length zz end read if num read 0 return true else zz end read num read return false ioexception zzrefill ioexception zzstartread zzbuffer zzstartread zzbuffer zzendread zzstartread zzendread zzstartread zzcurrentpos zzstartread zzmarkedpos zzstartread zzpushbackpos zzstartread zzstartread zzcurrentpos zzbuffer newbuffer zzcurrentpos zzbuffer newbuffer zzbuffer zzbuffer newbuffer numread zzreader zzbuffer zzendread zzbuffer zzendread numread zzendread numread closes the input stream public final void yyclose throws java io io exception zz ateof true indicate end of file zz end read zz start read invalidate buffer if zz reader null zz reader close ioexception zzateof zzendread zzstartread zzreader zzreader resets the scanner to read from a new input stream does not close the old reader all internal variables are reset the old input stream b cannot b be reused internal buffer is discarded and lost lexical state is set to tt zz initial tt param reader the new input stream public final void yyreset java io reader reader zz reader reader zz atbol true zz ateof false zz end read zz start read 0 zz current pos zz marked pos zz pushback pos 0 yyline yychar yycolumn 0 zz lexical state yyinitial zz_initial zzreader zzatbol zzateof zzendread zzstartread zzcurrentpos zzmarkedpos zzpushbackpos zzlexicalstate returns the current lexical state public final int yystate return zz lexical state zzlexicalstate enters a new lexical state param new state the new lexical state public final void yybegin int new state zz lexical state new state newstate newstate zzlexicalstate newstate returns the text matched by the current regular expression public final string yytext return new string zz buffer zz start read zz marked pos zz start read zzbuffer zzstartread zzmarkedpos zzstartread returns the character at position tt pos tt from the matched text it is equivalent to yytext char at pos but faster param pos the position of the character to fetch a value from 0 to yylength 1 return the character at position pos public final char yycharat int pos return zz buffer zz start read pos charat zzbuffer zzstartread returns the length of the matched text region public final int yylength return zz marked pos zz start read zzmarkedpos zzstartread reports an error that occured while scanning in a wellformed scanner no or only correct usage of yypushback int and a match all fallback rule this method will only be called with things that can t possibly happen if this method is called something is seriously wrong e g a j flex bug producing a faulty scanner etc usual syntax scanner level error handling should be done in error fallback rules param error code the code of the errormessage to display private void zz scan error int error code string message try message zz error msg error code catch array index out of bounds exception e message zz error msg zz unknown error throw new error message jflex errorcode zzscanerror errorcode zz_error_msg errorcode arrayindexoutofboundsexception zz_error_msg zz_unknown_error pushes the specified amount of characters back into the input stream they will be read again by then next call of the scanning method param number the number of characters to be read again this number must not be greater than yylength public void yypushback int number if number yylength zz scan error zz pushback 2big zz marked pos number zzscanerror zz_pushback_2big zzmarkedpos resumes scanning until the next regular expression is matched the end of input is encountered or an i o error occurs return the next token exception java io io exception if any i o error occurs public yytoken yylex throws java io io exception int zz input int zz action cached fields int zz current posl int zz marked posl int zz end readl zz end read char zz bufferl zz buffer char zzc mapl zz cmap int zz transl zz trans int zz row mapl zz rowmap int zz attrl zz attribute while true zz marked posl zz marked pos zz action 1 zz current posl zz current pos zz start read zz marked posl zz state zz lexical state zz for action while true if zz current posl zz end readl zz input zz bufferl zz current posl else if zz ateof zz input yyeof break zz for action else store back cached positions zz current pos zz current posl zz marked pos zz marked posl boolean eof zz refill get translated positions and possibly new buffer zz current posl zz current pos zz marked posl zz marked pos zz bufferl zz buffer zz end readl zz end read if eof zz input yyeof break zz for action else zz input zz bufferl zz current posl int zz next zz transl zz row mapl zz state zzc mapl zz input if zz next 1 break zz for action zz state zz next int zz attributes zz attrl zz state if zz attributes 1 1 zz action zz state zz marked posl zz current posl if zz attributes 8 8 break zz for action store back cached position zz marked pos zz marked posl switch zz action 0 zz action zz action zz action case 24 this is horrible however it seems that there is no other way to do it with either jflex or cup as url cannot be an unambiguous token string s yytext if debug log recognized url s decoded string thingy dst new decoded string thingy s if dst url throw new illegal state exception parsing url isn t a url if dst suffix length 0 yypushback dst suffix length dst suffix s dst data if debug log url now s try s processurl s dst data s if s null s equals if debug log url invalid w write url else s dst to string if debug log writing s w write s catch comment exception e w write comment encode e get message case 33 break case 20 string s yytext w write s if debug log matched unicode s case 34 break case 28 if debug log deleted unofficial ident with url yytext w write l10n deleted unofficial ident withurl case 35 break case 8 string s yytext w write s if debug log matched close braces s case 36 break case 23 string s yytext w write s if debug log matched html comment s case 37 break case 12 string s yytext if debug log matched string s if paranoid string check s index of 1 w write l10n deleted disallowed string log deleted disallowed string s else w write s case 38 break case 17 string s yytext w write s if debug log matched s case 39 break case 26 string s yytext w write s if debug log matched page s case 40 break case 22 string s yytext string builder sb new string builder s length sb append boolean in prefix true for int i 2 i s length 2 i char c s char at i if in prefix character is whitespace c continue in prefix false if character is digit c character is whitespace c character is letter c c c c no no etc ie has been known to do things with comments in css and other browsers may too sb append c while character is whitespace sb char at sb length 1 sb delete char at sb length 1 sb append w write sb to string if debug log matched comment s sb to string case 41 break case 13 string s yytext w write s if debug log matched number s case 42 break case 6 string s yytext w write s if debug log matched semicolon s case 43 break case 21 string s yytext if debug log got hexcolor s w write s case 44 break case 7 string s yytext w write s if debug log matched open braces s case 45 break case 27 string s yytext s s substring media length trim w write media s if debug log matched media s case 46 break case 2 string s yytext w write s if debug log matched ident s case 47 break case 25 string s yytext w write s if debug log matched unicode range s case 48 break case 30 string s yytext w write s if debug log matched font face s case 49 break case 14 if debug log deleted unofficial ident yytext w write l10n deleted unofficial ident case 50 break case 19 string s yytext w write s if debug log matched html comment s case 51 break case 29 string s yytext if debug log found import s s s substring import length s s trim decoded string thingy dst new decoded string thingy s s dst data if debug log url s try s process importurl s dst data s if debug log processed url s if dst quote dst quote if s null s equals if debug log url now s s import dst to string if debug log writing s w write s else if debug log dropped import catch comment exception e w write comment encode e get message case 52 break case 3 string s yytext w write s if debug log matched whitespace s case 53 break case 1 string s yytext char c s char at 0 log matched anything yytext ignoring w write l10n deleted unmatched char c single char cannot break out of comment case 54 break case 31 string s yytext w write s if debug log matched important s case 55 break case 9 string s yytext if s to lower case starts with url throw error l10n invalidurl contents if s to lower case starts with rgb s to lower case starts with attr throw error l10n invalidurl contents w write s if debug log matched function start s case 56 break case 16 if delete errors throw error l10n unknown at identifier label yytext else string s yytext if debug log discarded identifier s ignore case 57 break case 11 string s yytext w write s if debug log matched measurement s case 58 break case 18 string s yytext w write s if debug log matched s case 59 break case 32 string s yytext detected charset s if debug log matched and ignoring charset s ignore case 60 break case 10 if post bad import flag ignore post bad import flag false if debug log ignoring mediums list because after bad import yytext else string s yytext w write s if debug log matched and passing on mediums list s case 61 break case 4 string s yytext w write s if debug log matched single char s case 62 break case 15 string s yytext w write s if debug log matched name s case 63 break case 5 string s yytext w write s if debug log matched function end s case 64 break default if zz input yyeof zz start read zz current pos zz ateof true return null else zz scan error zz no match ioexception ioexception zzinput zzaction zzcurrentposl zzmarkedposl zzendreadl zzendread zzbufferl zzbuffer zzcmapl zz_cmap zztransl zz_trans zzrowmapl zz_rowmap zzattrl zz_attribute zzmarkedposl zzmarkedpos zzaction zzcurrentposl zzcurrentpos zzstartread zzmarkedposl zzstate zzlexicalstate zzforaction zzcurrentposl zzendreadl zzinput zzbufferl zzcurrentposl zzateof zzinput zzforaction zzcurrentpos zzcurrentposl zzmarkedpos zzmarkedposl zzrefill zzcurrentposl zzcurrentpos zzmarkedposl zzmarkedpos zzbufferl zzbuffer zzendreadl zzendread zzinput zzforaction zzinput zzbufferl zzcurrentposl zznext zztransl zzrowmapl zzstate zzcmapl zzinput zznext zzforaction zzstate zznext zzattributes zzattrl zzstate zzattributes zzaction zzstate zzmarkedposl zzcurrentposl zzattributes zzforaction zzmarkedpos zzmarkedposl zzaction zzaction zz_action zzaction decodedstringthingy decodedstringthingy illegalstateexception tostring commentexception commentencode getmessage deletedunofficialidentwithurl paranoidstringcheck indexof deleteddisallowedstring stringbuilder stringbuilder inprefix charat inprefix iswhitespace inprefix isdigit iswhitespace isletter _ iswhitespace charat deletecharat tostring tostring deletedunofficialident decodedstringthingy decodedstringthingy processimporturl tostring commentexception commentencode getmessage charat deletedunmatchedchar tolowercase startswith throwerror invalidurlcontents tolowercase startswith tolowercase startswith throwerror invalidurlcontents deleteerrors throwerror unknownatidentifierlabel detectedcharset postbadimportflag postbadimportflag zzinput zzstartread zzcurrentpos zzateof zzscanerror zz_no_match construct a saturation filter public saturation filter saturationfilter saturationfilter construct a saturation filter the amount of saturation change public saturation filter float amount this amount amount can filter index color model true saturationfilter saturationfilter canfilterindexcolormodel set the amount of saturation change 1 leaves the image unchanged values between 0 and 1 desaturate 0 completely desaturates it and values above 1 increase the saturation param amount the amount public void set amount float amount this amount amount setamount set the amount of saturation change return the amount public float get amount return amount getamount override public int filterrgb int x int y int rgb if amount 1 int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int v r g b 3 or a better brightness calculation if you prefer r pixel utils clamp int v amount r v g pixel utils clamp int v amount g v b pixel utils clamp int v amount b v return a r 16 g 8 b return rgb pixelutils pixelutils pixelutils override public string to string return colors saturation tostring public class default allocator extends persistent implements custom allocator public default allocator storage storage super storage defaultallocator customallocator defaultallocator protected default allocator defaultallocator protected default allocator public long allocate long size return storage impl get storage allocate size 0 defaultallocator storageimpl getstorage public long reallocate long pos long old size long new size storage impl db storage impl get storage if new size storage impl db allocation quantum 1 storage impl db allocation quantum 1 old size storage impl db allocation quantum 1 storage impl db allocation quantum 1 long new pos db allocate new size 0 db clone bitmap pos old size db free pos old size pos new pos return pos oldsize newsize storageimpl storageimpl getstorage newsize storageimpl dballocationquantum storageimpl dballocationquantum oldsize storageimpl dballocationquantum storageimpl dballocationquantum newpos newsize clonebitmap oldsize oldsize newpos public void free long pos long size storage impl get storage clone bitmap pos size storageimpl getstorage clonebitmap public void commit public class simple user alert extends abstract user alert public simple user alert boolean can dismiss string title string text string short text short type this can dismiss title text short text type null simpleuseralert abstractuseralert simpleuseralert candismiss shorttext candismiss shorttext public simple user alert boolean can dismiss string title string text string short text short type object user identifier super can dismiss title text short text new html node div text type true l10n get string user alert hide true user identifier simpleuseralert candismiss shorttext useridentifier candismiss shorttext htmlnode getstring useralert useridentifier override public void is valid boolean validity do nothing isvalid public wot message list fetcher node my node high level simple client my client string my name wot identity manager my identity manager wot message manager my message manager super my node my client my name my identity manager my message manager m identity manager my identity manager m message manager my message manager m random m node fast weak random client context m node client core client context m request client m message manager request client start wotmessagelistfetcher mynode highlevelsimpleclient myclient myname wotidentitymanager myidentitymanager wotmessagemanager mymessagemanager mynode myclient myname myidentitymanager mymessagemanager midentitymanager myidentitymanager mmessagemanager mymessagemanager mrandom mnode fastweakrandom clientcontext mnode clientcore clientcontext mrequestclient mmessagemanager requestclient override protected collection client getter create fetch storage return new hash set client getter max parallel messagelist fetch count 2 clientgetter createfetchstorage hashset clientgetter max_parallel_messagelist_fetch_count override protected collection base client putter create insert storage return null baseclientputter createinsertstorage override public int get priority return native thread norm priority getpriority nativethread norm_priority override protected long get startup delay return startup delay 2 m random next int startup delay getstartupdelay startup_delay mrandom nextint startup_delay override protected long get sleep time return thread period 2 m random next int thread period getsleeptime thread_period mrandom nextint thread_period override protected synchronized void iterate abort all transfers array list wot identity identities to fetch from new array list wot identity max parallel messagelist fetch count 1 for wot identity identity m identity manager get all identities synchronized m identities if m identities contains identity m identity manager any own identity wants messages from identity identities to fetch from add identity m identities add identity if identities to fetch from size max parallel messagelist fetch count break m identities contains all identities which are available so we have to flush it if identities to fetch from size 0 m identities clear for wot identity identity m identity manager get all identities synchronized m identities if m identity manager any own identity wants messages from identity identities to fetch from add identity m identities add identity if identities to fetch from size max parallel messagelist fetch count break for wot identity identity identities to fetch from try fetch message lists wot identity identity catch exception e logger error this fetching of messages from identity get nickname failed e abortalltransfers arraylist wotidentity identitiestofetchfrom arraylist wotidentity max_parallel_messagelist_fetch_count wotidentity midentitymanager getallidentities midentities midentities midentitymanager anyownidentitywantsmessagesfrom identitiestofetchfrom midentities identitiestofetchfrom max_parallel_messagelist_fetch_count midentities identitiestofetchfrom midentities wotidentity midentitymanager getallidentities midentities midentitymanager anyownidentitywantsmessagesfrom identitiestofetchfrom midentities identitiestofetchfrom max_parallel_messagelist_fetch_count wotidentity identitiestofetchfrom fetchmessagelists wotidentity getnickname you have to synchronize on this code wot message list fetcher code when using this function throws fetch exception private void fetch message lists wot identity identity throws fetch exception int new index m message manager get unavailable new message list index identity fetch message list identity new index true if new index 0 int old index m message manager get unavailable old message list index identity if old index new index fetch message list identity m message manager get unavailable old message list index identity false wotmessagelistfetcher fetchexception fetchmessagelists wotidentity fetchexception newindex mmessagemanager getunavailablenewmessagelistindex fetchmessagelist newindex newindex oldindex mmessagemanager getunavailableoldmessagelistindex oldindex newindex fetchmessagelist mmessagemanager getunavailableoldmessagelistindex you have to synchronize on this code wot message fetcher code when using this function param follow redirects to higher index if true the usk redirects will be used to download the latest instead of the specified index private void fetch message list wot identity identity int index boolean follow redirects to higher index throws fetch exception freeneturi uri wot message list generateuri identity index if follow redirects to higher index uri uri ssk forusk fetch context fetch context m client get fetch context fetch context max splitfile block retries 2 3 and above or 1 cooldown queue 1 is infinite fetch context max non splitfile retries 2 client getter g m client fetch uri 1 m request client this fetch context g set priority class request starter update priority class pluginmanager defaults to interactive priority add fetch g logger debug this trying to fetch message list from uri wotmessagefetcher followredirectstohigherindex fetchmessagelist wotidentity followredirectstohigherindex fetchexception wotmessagelist followredirectstohigherindex sskforusk fetchcontext fetchcontext mclient getfetchcontext fetchcontext maxsplitfileblockretries fetchcontext maxnonsplitfileretries clientgetter mclient mrequestclient fetchcontext setpriorityclass requeststarter update_priority_class addfetch messagelist override public synchronized void on success fetch result result client getter state object container container logger debug this fetched message list state geturi input stream input null wot identity identity null try identity wot identity m identity manager get identity byuri state geturi input result as bucket get input stream wot message list list wot message listxml decode m message manager identity state geturi input m message manager on message list received list catch exception e logger error this parsing failed for message list state geturi e if identity null m message manager on message list fetch failed identity state geturi message list message list fetch failed reference reason parsing failed finally closer close input remove fetch state try int unavailable index m message manager get unavailable old message list index identity boolean unavailable is newer unavailable index state geturi get edition follow redirects then fetch message list identity unavailable index unavailable is newer catch exception e logger error this fetching of next message list failed e onsuccess fetchresult clientgetter objectcontainer messagelist inputstream wotidentity wotidentity midentitymanager getidentitybyuri asbucket getinputstream wotmessagelist wotmessagelistxml mmessagemanager mmessagemanager onmessagelistreceived messagelist mmessagemanager onmessagelistfetchfailed messagelist messagelistfetchfailedreference parsingfailed removefetch unavailableindex mmessagemanager getunavailableoldmessagelistindex unavailableisnewer unavailableindex getedition fetchmessagelist unavailableindex unavailableisnewer messagelist override public synchronized void on failure fetch exception e client getter state object container container try switch e get mode case fetch exception data not found wot identity identity try identity wot identity m identity manager get identity byuri state geturi m message manager on message list fetch failed identity state geturi message list message list fetch failed reference reason data not found catch no such identity exception ex logger error this should not happen ex logger debug this dnf for message list state geturi break case fetch exception permanent redirect try state restart e newuri null client context catch fetch exception e1 logger error this request restart failed e1 break case fetch exception cancelled logger debug this cancelled downloading message list state geturi break default logger error this downloading message list state geturi failed e break finally remove fetch state onfailure fetchexception clientgetter objectcontainer getmode fetchexception data_not_found wotidentity wotidentity midentitymanager getidentitybyuri mmessagemanager onmessagelistfetchfailed messagelist messagelistfetchfailedreference datanotfound nosuchidentityexception messagelist fetchexception permanent_redirect clientcontext fetchexception fetchexception messagelist messagelist removefetch not needed functions called for inserts override public void on generateduri freeneturi uri base client putter state object container container ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container override public void on success base client putter state object container container ongenerateduri baseclientputter objectcontainer onsuccess baseclientputter objectcontainer public void on success base client putter state object container container override public void on failure insert exception e base client putter state object container container onsuccess baseclientputter objectcontainer onfailure insertexception baseclientputter objectcontainer public void on failure insert exception e base client putter state object container container override public void on fetchable base client putter state object container container onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer public void on fetchable base client putter state object container container override public void on major progress object container container onfetchable baseclientputter objectcontainer onmajorprogress objectcontainer private float distortion 10 0f public void set distortion float distortion this distortion distortion setdistortion public float get distortion return distortion getdistortion public float evaluate float x float y float ox noise noise2 x 0 5f y distortion float oy noise noise2 x y 0 5f distortion return noise noise2 x ox y oy static void print index string prefix root page page system out println prefix size page size system out println prefix index page index system out println prefix shadow index page shadow index system out println prefix used size page used size system out println prefix index size page index size system out println prefix shadow index size page shadow index size system out println prefix index used page index used system out println prefix free list page free list system out println prefix bitmap end page bitmap end system out println prefix root object page root object system out println prefix class desc list page class desc list system out println prefix bitmap extent page bitmap extent printindex rootpage shadowindex shadowindex usedsize usedsize indexsize indexsize shadowindexsize shadowindexsize indexused indexused freelist freelist bitmapend bitmapend rootobject rootobject classdesclist classdesclist bitmapextent bitmapextent public static void main string args throws exception if args length 0 system err println usage java recovery utility file path current return string file path args 0 i file file file path starts with i file new multi file file path substring 1 false false i file new os file file path false false byte buf new byte header sizeof int rc file read 0 buf if rc 0 rc header sizeof system err println failed to read database header rc rc return header header new header header unpack buf if header curr 0 header curr 1 system err println database header was corrupted header curr header curr system out println curr header curr system out println dirty header dirty system out println database format version header database format version system out println transaction id header transaction id print index index 0 header root 0 print index index 1 header root 1 if args length 1 header curr integer parse int args 1 header dirty true header pack buf file write 0 buf system err println set current index to args 1 file close recoveryutility filepath ifile filepath startswith ifile multifile filepath ifile osfile filepath databaseformatversion transactionid transactionid printindex printindex parseint public static list object read list from data input stream class element type data input dis throws io exception linked list object ret new linked list object int length dis read int for int x 0 x length x ret add read from data input stream element type dis return ret readlistfromdatainputstream elementtype datainput ioexception linkedlist linkedlist readint readfromdatainputstream elementtype public static object read from data input stream class type data input dis throws io exception if type equals boolean class int bool dis read byte if bool 1 return boolean true if bool 0 return boolean false throw new io exception boolean is non boolean value bool else if type equals byte class int b dis read byte return byte b else if type equals short class return dis read short else if type equals integer class return dis read int else if type equals long class return dis read long else if type equals double class return dis read double else if type equals string class int length dis read int string builder sb new string builder length for int x 0 x length x sb append dis read char return sb to string else if type equals buffer class return new buffer dis else if type equals short buffer class return new short buffer dis else if type equals very long integer class return new very long integer dis else if type equals peer class return new peer dis else if type equals bit array class return new bit array dis max bitarray size else if type equals nodechk class use key read because write writes the type field return key read dis else if type equals nodessk class use key read because write writes the type field return key read dis else if type equals key class return key read dis else throw new runtime exception unrecognised field type type readfromdatainputstream datainput ioexception readbyte ioexception readbyte readshort readint readlong readdouble readint stringbuilder stringbuilder readchar tostring shortbuffer shortbuffer verylonginteger verylonginteger bitarray bitarray max_bitarray_size runtimeexception public static void write to data output stream object object data output stream dos peer context ctx throws io exception class type object get class if type equals long class dos write long long object long value else if type equals boolean class dos write boolean object boolean value 1 0 else if type equals integer class dos write int integer object int value else if type equals short class dos write short short object short value else if type equals double class dos write double double object double value else if writable to data output stream class is assignable from type writable to data output stream b writable to data output stream object b write to data output stream dos else if type equals string class string s string object dos write int s length for int x 0 x s length x dos write char s char at x else if type equals linked list class linked list ll linked list object dos write int ll size synchronized ll for object o ll write to data output stream o dos ctx else if type equals byte class dos write byte object byte value else throw new runtime exception unrecognised field type type writetodataoutputstream dataoutputstream peercontext ioexception getclass writelong longvalue booleanvalue writeint intvalue writeshort shortvalue writedouble doublevalue writabletodataoutputstream isassignablefrom writabletodataoutputstream writabletodataoutputstream writetodataoutputstream writeint writechar charat linkedlist linkedlist linkedlist writeint writetodataoutputstream bytevalue runtimeexception static final int btree threshold 128 thick index class key type storage impl db super db index db i persistent create index key type true btree_threshold thickindex keytype storageimpl ipersistent createindex keytype thick index thickindex public t get key key i persistent s index get key if s null return null if s instanceof relation relation r relation s if r size 1 return t r get 0 throw new storage error storage error key not unique ipersistent storageerror storageerror key_not_unique public t get object key return get btree get key from object key getkeyfromobject public array list t get list key from key till return extend list index get list from till arraylist getlist extendlist getlist public array list t get list object from object till return extend list index get list from till arraylist getlist extendlist getlist public i persistent get key from key till return extend index get from till ipersistent public i persistent get object from object till return extend index get from till ipersistent private array list t extend list array list s array list t list new array list t for int i 0 n s size i n i list add all collection t s get i return list arraylist extendlist arraylist arraylist arraylist addall private i persistent extend i persistent s array list list new array list for int i 0 i s length i list add all collection s i return i persistent list to array new i persistent list size ipersistent ipersistent arraylist arraylist addall ipersistent toarray ipersistent public t get string key return get new key key public i persistent get prefix string prefix return extend index get prefix prefix ipersistent getprefix getprefix public array list t get prefix list string prefix return extend list index get prefix list prefix arraylist getprefixlist extendlist getprefixlist public i persistent prefix search string word return extend index prefix search word ipersistent prefixsearch prefixsearch public array list t prefix search list string word return extend list index prefix search list word arraylist prefixsearchlist extendlist prefixsearchlist public int size return n elems nelems public void clear for i persistent p index p deallocate index clear n elems 0 modify ipersistent nelems public i persistent to persistent array return extend index to persistent array ipersistent topersistentarray topersistentarray public object to array return to persistent array toarray topersistentarray public e e to array e arr array list e list new array list e for i persistent c index list add all collection e c return list to array arr toarray arraylist arraylist ipersistent addall toarray static class extend iterator e extends i persistent extends iterable iterator e implements persistent iterator public boolean has next return inner null extenditerator ipersistent iterableiterator persistentiterator hasnext public e next e obj inner next if inner has next if outer has next inner iterable e outer next iterator else inner null return obj hasnext hasnext public int next oid int oid persistent iterator inner next oid if inner has next if outer has next object p outer next inner iterable e outer next iterator else inner null return oid nextoid persistentiterator nextoid hasnext hasnext public void remove throw new unsupported operation exception unsupportedoperationexception extend iterator iterable iterator iterable this iterable iterator extenditerator iterableiterator extend iterator iterator iterator outer iterator if iterator has next inner iterable e iterator next iterator extenditerator hasnext static class extend entry e extends i persistent implements map entry object e public object get key return key extendentry ipersistent getkey public e get value return value getvalue public e set value e value throw new unsupported operation exception setvalue unsupportedoperationexception extend entry object key e value this key key this value value extendentry static class extend entry iterator e extends i persistent extends iterable iterator map entry object e public boolean has next return inner null extendentryiterator ipersistent iterableiterator hasnext public map entry object e next extend entry e curr new extend entry e key inner next if inner has next if outer has next map entry entry map entry outer next key entry get key inner iterable e entry get value iterator else inner null return curr extendentry extendentry hasnext hasnext getkey getvalue public void remove throw new unsupported operation exception unsupportedoperationexception extend entry iterator iterable iterator iterator outer iterator if iterator has next map entry entry map entry iterator next key entry get key inner iterable e entry get value iterator extendentryiterator iterableiterator hasnext getkey getvalue class extend entry start from iterator extends extend entry iterator t extend entry start from iterator int start int order super entry iterator null null order int skip order ascent order start n elems start 1 while skip 0 has next next extendentrystartfromiterator extendentryiterator extendentrystartfromiterator entryiterator ascent_order nelems hasnext public iterator t iterator return new extend iterator t index iterator extenditerator public iterable iterator map entry object t entry iterator return new extend entry iterator t index entry iterator iterableiterator entryiterator extendentryiterator entryiterator public iterable iterator t iterator key from key till int order return new extend iterator t index iterator from till order iterableiterator extenditerator public iterable iterator t iterator object from object till int order return new extend iterator t index iterator from till order iterableiterator extenditerator public iterable iterator map entry object t entry iterator key from key till int order return new extend entry iterator t index entry iterator from till order iterableiterator entryiterator extendentryiterator entryiterator public iterable iterator map entry object t entry iterator object from object till int order return new extend entry iterator t index entry iterator from till order iterableiterator entryiterator extendentryiterator entryiterator public iterable iterator t prefix iterator string prefix return new extend iterator t index prefix iterator prefix iterableiterator prefixiterator extenditerator prefixiterator public class get key type return index get key type getkeytype getkeytype public class get key types return new class get key type getkeytypes getkeytype public boolean put key key t obj i persistent s index get key if s null relation t thick index r get storage t thick index create relation null r add obj index put key r else if s instanceof relation relation r relation s if r size btree threshold i persistent set t ps get storage t create set for int i 0 i btree threshold i ps add t r get i ps add obj index set key ps r deallocate else r add obj else i persistent set t s add obj n elems 1 modify return true ipersistent thickindex getstorage thickindex createrelation btree_threshold ipersistentset getstorage createset btree_threshold ipersistentset nelems public t set key key t obj i persistent s index get key if s null relation t thick index r get storage t thick index create relation null r add obj index put key r n elems 1 modify return null else if s instanceof relation relation r relation s if r size 1 i persistent prev r get 0 r set 0 obj return t prev throw new storage error storage error key not unique ipersistent thickindex getstorage thickindex createrelation nelems ipersistent storageerror storageerror key_not_unique public void remove key key t obj i persistent s index get key if s instanceof relation relation r relation s int i r index of obj if i 0 r remove i if r size 0 index remove key r r deallocate n elems 1 modify return else if s instanceof i persistent set i persistent set ps i persistent set s if ps remove obj if ps size 0 index remove key ps ps deallocate n elems 1 modify return throw new storage error storage error key not found ipersistent indexof nelems ipersistentset ipersistentset ipersistentset nelems storageerror storageerror key_not_found public t remove key key throw new storage error storage error key not unique storageerror storageerror key_not_unique public boolean put object key t obj return put btree get key from object key obj getkeyfromobject public t set object key t obj return set btree get key from object key obj getkeyfromobject public void remove object key t obj remove btree get key from object key obj getkeyfromobject public t remove string key throw new storage error storage error key not unique storageerror storageerror key_not_unique public t remove key object key throw new storage error storage error key not unique removekey storageerror storageerror key_not_unique public void deallocate clear index deallocate super deallocate public t get at int i iterable iterator map entry object t iterator if i 0 i n elems throw new index out of bounds exception position i index size n elems if i n elems 2 iterator entry iterator null null ascent order while i 0 iterator next else iterator entry iterator null null descent order i n elems while i 0 iterator next return iterator next get value getat iterableiterator nelems indexoutofboundsexception nelems nelems entryiterator ascent_order entryiterator descent_order nelems getvalue public iterable iterator map entry object t entry iterator int start int order return new extend entry start from iterator start order iterableiterator entryiterator extendentrystartfromiterator public boolean is unique return false isunique private static final long serial versionuid 1l public comment exception string msg super msg serialversionuid commentexception public class seed server peer node extends peer node public seed server peer node simple field set fs node node2 node crypto crypto peer manager peers boolean from local outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception super fs node2 crypto peers from local false mangler true seedserverpeernode peernode seedserverpeernode simplefieldset nodecrypto peermanager fromlocal outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception fromlocal override public peer node status get status boolean no heavy return new peer node status this no heavy peernodestatus getstatus noheavy peernodestatus noheavy override public boolean is darknet return false isdarknet override public boolean is opennet return false isopennet override public boolean is seed return true isseed override public boolean is real connection return false isrealconnection override public boolean equals object o if o this return true only equal to seednode of its own type different to an opennet peer node with the same identity if o instanceof seed server peer node return super equals o else return false opennetpeernode seedserverpeernode override public void on success boolean insert boolean ssk ignore onsuccess override public boolean is routing compatible return false isroutingcompatible override public boolean record status return false recordstatus override protected void send initial messages super send initial messages final opennet manager om node get opennet if om null logger normal this opennet turned off while connecting to seednodes node peers disconnect this true true true else wait 5 seconds another node may connect first we don t want all the announcements to go to the node which we connect to most quickly node get ticker queue timed job new runnable public void run try om announcer maybe send announcement catch throwable t logger error this caught t t 5 1000 sendinitialmessages sendinitialmessages opennetmanager getopennet getticker queuetimedjob maybesendannouncement node get ticker queue timed job new runnable public void run try om announcer maybe send announcement catch throwable t logger error this caught t t getticker queuetimedjob maybesendannouncement public inet address get inet addresses peer peers get handshakei ps array list inet address v new array list inet address for int i 0 i peers length i freenet inet address fa peers i get freenet address drop hostname if fa null continue inet address ia fa get address if v contains ia continue v add ia if v is empty logger error this no valid addresses for seed node this return v to array new inet address v size inetaddress getinetaddresses gethandshakeips arraylist inetaddress arraylist inetaddress freenetinetaddress getfreenetaddress drophostname inetaddress getaddress isempty toarray inetaddress override public boolean handshake unknown initiator return true handshakeunknowninitiator override public int handshake setup type return fnp packet mangler setup opennet seednode handshakesetuptype fnppacketmangler setup_opennet_seednode override public boolean disconnected boolean dump message queue boolean dump trackers boolean ret super disconnected dump message queue dump trackers node peers disconnect this false false false return ret dumpmessagequeue dumptrackers dumpmessagequeue dumptrackers override protected boolean generate identity from pubkey return false generateidentityfrompubkey override public boolean should disconnect and remove now opennet manager om node get opennet if om null return true if om announcer enough peers return false we have enough peers but we might fluctuate a bit drop the connection once we have consistently had enough opennet peers for 5 minutes return system current time millis om announcer time got enough peers 5 60 1000 shoulddisconnectandremovenow opennetmanager getopennet enoughpeers currenttimemillis timegotenoughpeers constuct a dither filter public dither filter rows 2 cols 2 matrix dither magic4x4 matrix levels 6 color dither true ditherfilter ditherfilter dithermagic4x4matrix colordither set the dither matrix param matrix the dither matrix see get matrix public void set matrix int matrix this matrix matrix getmatrix setmatrix get the dither matrix return the dither matrix see set matrix public int get matrix return matrix setmatrix getmatrix set the number of dither levels param levels the number of levels see get levels public void set levels int levels this levels levels getlevels setlevels get the number of dither levels return the number of levels see set levels public int get levels return levels setlevels getlevels set whether to use a color dither param color dither whether to use a color dither see get color dither public void set color dither boolean color dither this color dither color dither colordither getcolordither setcolordither colordither colordither colordither get whether to use a color dither return whether to use a color dither see get color dither public boolean get color dither return color dither getcolordither getcolordither colordither initialize the filter protected void initialize rows cols int math sqrt matrix length map new int levels for int i 0 i levels i int v 255 i levels 1 map i v div new int 256 mod new int 256 int rc rows cols 1 for int i 0 i 256 i div i levels 1 i 256 mod i i rc 256 override public int filterrgb int x int y int rgb if initialized initialized true initialize int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int col x cols int row y rows int v matrix row cols col if color dither r map mod r v div r 1 div r g map mod g v div g 1 div g b map mod b v div b 1 div b else int value r g b 3 r g b map mod value v div value 1 div value return a r 16 g 8 b colordither override public string to string return colors dither tostring construct a wood filter public wood filter woodfilter woodfilter specifies the rings value param rings the rings value min value 0 max value 1 see get rings public void set rings float rings this rings rings getrings setrings returns the rings value return the rings value see set rings public float get rings return rings setrings getrings specifies the scale of the texture param scale the scale of the texture min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale specifies the stretch factor of the texture param stretch the stretch factor of the texture min value 1 max value 50 see get stretch public void set stretch float stretch this stretch stretch getstretch setstretch returns the stretch factor of the texture return the stretch factor of the texture see set stretch public float get stretch return stretch setstretch getstretch specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle specifies the turbulence of the texture param turbulence the turbulence of the texture min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the texture return the turbulence of the texture see set turbulence public float get turbulence return turbulence setturbulence getturbulence specifies the amount of fibres in the texture param fibres the amount of fibres in the texture min value 0 max value 1 see get fibres public void set fibres float fibres this fibres fibres getfibres setfibres returns the amount of fibres in the texture return the amount of fibres in the texture see set fibres public float get fibres return fibres setfibres getfibres specifies the gain of the texture param gain the gain of the texture min value 0 max value 1 see get gain public void set gain float gain this gain gain getgain setgain returns the gain of the texture return the gain of the texture see set gain public float get gain return gain setgain getgain set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap override public int filterrgb int x int y int rgb float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch float f noise noise2 nx ny f 0 1f turbulence noise noise2 nx 0 05f ny 20 f f 0 5f 0 5f f rings 50 f f int f f 1 image math smooth step gain 1 0f f f fibres noise noise2 nx scale ny 50 int a rgb 0xff000000 int v if colormap null v colormap get color f else v pixel utils clamp int f 255 int r v 16 int g v 8 int b v v a r g b return v imagemath smoothstep getcolor pixelutils override public string to string return texture wood tostring create an outgoing multicast query or response public dns outgoing int flags this flags true dnsoutgoing create an outgoing query or response public dns outgoing int flags boolean multicast this flags flags this multicast multicast names new hashtable data new byte dns constants max msg typical off 12 dnsoutgoing dnsconstants max_msg_typical add a question to the message public void add question dns question rec throws io exception if num answers 0 num authorities 0 num additionals 0 throw new illegal state exception questions must be added before answers num questions write question rec addquestion dnsquestion ioexception numanswers numauthorities numadditionals illegalstateexception numquestions writequestion add an answer if it is not suppressed void add answer dns incoming in dns record rec throws io exception if num authorities 0 num additionals 0 throw new illegal state exception answers must be added before authorities and additionals if rec suppressed by in add answer rec 0 addanswer dnsincoming dnsrecord ioexception numauthorities numadditionals illegalstateexception suppressedby addanswer add an additional answer to the record omit if there is no room void add additional answer dns incoming in dns record rec throws io exception if off dns constants max msg typical 200 rec suppressed by in write record rec 0 num additionals addadditionalanswer dnsincoming dnsrecord ioexception dnsconstants max_msg_typical suppressedby writerecord numadditionals add an answer to the message public void add answer dns record rec long now throws io exception if num authorities 0 num additionals 0 throw new illegal state exception questions must be added before answers if rec null if now 0 rec is expired now write record rec now num answers addanswer dnsrecord ioexception numauthorities numadditionals illegalstateexception isexpired writerecord numanswers add an authorative answer to the message public void add authorative answer dns record rec throws io exception if num additionals 0 throw new illegal state exception authorative answers must be added before additional answers authorative answers add rec write record rec 0 num authorities verify addauthorativeanswer dnsrecord ioexception numadditionals illegalstateexception authorativeanswers writerecord numauthorities void write byte int value throws io exception if off data length throw new io exception buffer full data off byte value writebyte ioexception ioexception void write bytes string str int off int len throws io exception for int i 0 i len i write byte str char at off i writebytes ioexception writebyte charat void write bytes byte data throws io exception if data null write bytes data 0 data length writebytes ioexception writebytes void write bytes byte data int off int len throws io exception for int i 0 i len i write byte data off i writebytes ioexception writebyte void write short int value throws io exception write byte value 8 write byte value writeshort ioexception writebyte writebyte void write int int value throws io exception write short value 16 write short value writeint ioexception writeshort writeshort void writeutf string str int off int len throws io exception compute utf length int utflen 0 for int i 0 i len i int ch str char at off i if ch 0x0001 ch 0x007f utflen 1 else if ch 0x07ff utflen 3 else utflen 2 write utf length write byte utflen write utf data for int i 0 i len i int ch str char at off i if ch 0x0001 ch 0x007f write byte ch else if ch 0x07ff write byte 0xe0 ch 12 0x0f write byte 0x80 ch 6 0x3f write byte 0x80 ch 0 0x3f else write byte 0xc0 ch 6 0x1f write byte 0x80 ch 0 0x3f ioexception charat writebyte charat writebyte writebyte writebyte writebyte writebyte writebyte void write name string name throws io exception write name name true writename ioexception writename void write name string name boolean use compression throws io exception while true int n name index of if n 0 n name length if n 0 write byte 0 return if use compression use domain name compression integer offset integer names get name if offset null int val offset int value if val off logger log level warning dns outgoing write name failed val val name name write byte val 8 0xc0 write byte val 0xff return names put name integer value of off writeutf name 0 n name name substring n if name starts with name name substring 1 writename usecompression ioexception indexof writebyte usecompression use_domain_name_compression intvalue dnsoutgoing writename writebyte writebyte valueof startswith void write question dns question question throws io exception write name question name write short question type write short question clazz writequestion dnsquestion ioexception writename writeshort writeshort void write record dns record rec long now throws io exception int save off try write name rec name write short rec type write short rec clazz rec unique multicast dns constants class unique 0 write int now 0 rec get ttl rec get remainingttl now write short 0 int start off rec write this int len off start data start 2 byte len 8 data start 1 byte len 0xff catch io exception e off save throw e writerecord dnsrecord ioexception writename writeshort writeshort dnsconstants class_unique writeint getttl getremainingttl writeshort ioexception finish the message before sending it off void finish throws io exception int save off off 0 write short multicast 0 id write short flags write short num questions write short num answers write short num authorities write short num additionals off save ioexception writeshort writeshort writeshort numquestions writeshort numanswers writeshort numauthorities writeshort numadditionals boolean is query return flags dns constants flags qr mask dns constants flags qr query isquery dnsconstants flags_qr_mask dnsconstants flags_qr_query public boolean is empty return num questions 0 num authorities 0 num additionals 0 num answers 0 isempty numquestions numauthorities numadditionals numanswers public string to string string buffer buf new string buffer buf append is query dns query dns response buf append packet get address get host address buf append buf append packet get port buf append len buf append packet get length buf append id 0x buf append integer to hex string id if flags 0 buf append flags 0x buf append integer to hex string flags if flags dns constants flags qr response 0 buf append r if flags dns constants flags aa 0 buf append aa if flags dns constants flags tc 0 buf append tc if num questions 0 buf append questions buf append num questions if num answers 0 buf append answers buf append num answers if num authorities 0 buf append authorities buf append num authorities if num additionals 0 buf append additionals buf append num additionals buf append nnames names buf append nauthorative answers authorative answers buf append return buf to string tostring stringbuffer stringbuffer isquery getaddress gethostaddress getport getlength tohexstring tohexstring dnsconstants flags_qr_response dnsconstants flags_aa dnsconstants flags_tc numquestions numquestions numanswers numanswers numauthorities numauthorities numadditionals numadditionals nauthorativeanswers authorativeanswers tostring public action request actionrequest public action request http request http req set http req actionrequest httprequest httpreq httpreq public node get action node node body node get body node if body node null return null if body node has nodes false return null return body node get node 0 getactionnode bodynode getbodynode bodynode bodynode hasnodes bodynode getnode public string get action name node node get action node if node null return string name node get name if name null return int idx name index of soap delim 1 if idx 0 return return name substring idx name length getactionname getactionnode getname indexof public argument list get argument list node act node get action node int n arg nodes act node getn nodes argument list arg list new argument list for int n 0 n n arg nodes n argument arg new argument node arg node act node get node n arg set name arg node get name arg set value arg node get value arg list add arg return arg list argumentlist getargumentlist actnode getactionnode nargnodes actnode getnnodes argumentlist arglist argumentlist nargnodes argnode actnode getnode setname argnode getname setvalue argnode getvalue arglist arglist public void set request action action argument list arg list service service action get service set request host service set envelope node soap create envelope body node node env node get envelope node node body node get body node node arg node create content node service action arg list body node add node arg node set content env node string service type service get service type string action name action get name string soap action service type action name setsoap action soap action setrequest argumentlist arglist getservice setrequesthost setenvelopenode createenvelopebodynode envnode getenvelopenode bodynode getbodynode argnode createcontentnode arglist bodynode addnode argnode setcontent envnode servicetype getservicetype actionname getname soapaction servicetype actionname setsoapaction soapaction private node create content node service service action action argument list arg list string action name action get name string service type service get service type node action node new node action node set name control ns action name action node set name space control ns service type int arg list cnt arg list size for int n 0 n arg list cnt n argument arg arg list get argument n node arg node new node arg node set name arg get name arg node set value arg get value action node add node arg node return action node createcontentnode argumentlist arglist actionname getname servicetype getservicetype actionnode actionnode setname actionname actionnode setnamespace servicetype arglistcnt arglist arglistcnt arglist getargument argnode argnode setname getname argnode setvalue getvalue actionnode addnode argnode actionnode public action response post soap response soap res post message get request host get request port return new action response soap res actionresponse soapresponse soapres postmessage getrequesthost getrequestport actionresponse soapres fixme implement file hash support public disk dir put file simple field set subset string identifier boolean global throws message invalid exception super subset identifier global string s subset get filename if s null throw new message invalid exception protocol error message missing field missing field filename on name identifier global file new file s filehash diskdirputfile simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field override protected string guessmime string mime super guessmime if mime null mime defaultmime types guessmime type file get name false fixme return mime defaultmimetypes guessmimetype getname override public bucket get data return new file bucket file true false false false false getdata filebucket public file get file return file getfile override public void remove from object container container container delete file container delete this removefrom objectcontainer private config config public perst root perstroot public static perst root create root storage storage perst root root new perst root root md5 term storage create field index term class md5 true root word term storage create field index term class word true root id page storage create field index page class id true root uri page storage create field index page class uri true root queued pages storage create field index page class last change false root failed pages storage create field index page class last change false root succeeded pages storage create field index page class last change false root config new config storage storage set root root return root perstroot createroot perstroot perstroot md5term createfieldindex wordterm createfieldindex idpage createfieldindex uripage createfieldindex queuedpages createfieldindex lastchange failedpages createfieldindex lastchange succeededpages createfieldindex lastchange setroot public term get term by word string word boolean create md5 term exclusive lock word term exclusive lock try term term word term get new key word if create term null word new string word force a new instance prevent referring to the old char term new term word get storage md5 term put term word term put term return term finally word term unlock md5 term unlock gettermbyword md5term exclusivelock wordterm exclusivelock wordterm getstorage md5term wordterm wordterm md5term public iterable iterator term get term iterator string from string till md5 term shared lock try return md5 term iterator from till 0 finally md5 term unlock iterableiterator gettermiterator md5term sharedlock md5term md5term public list term get term list md5 term shared lock try return md5 term get list null null finally md5 term unlock gettermlist md5term sharedlock md5term getlist md5term public int get term count md5 term shared lock try return md5 term size finally md5 term unlock gettermcount md5term sharedlock md5term md5term public page get page byuri freeneturi uri boolean create string comment id page exclusive lock uri page exclusive lock queued pages exclusive lock try page page uri page get new key uri to string if create page null page new page uri to string comment get storage id page append page uri page put page queued pages put page return page finally queued pages unlock uri page unlock id page unlock getpagebyuri idpage exclusivelock uripage exclusivelock queuedpages exclusivelock uripage tostring tostring getstorage idpage uripage queuedpages queuedpages uripage idpage public page get page by id long id id page shared lock try page page id page get id return page finally id page unlock getpagebyid idpage sharedlock idpage idpage field index page get page index status status switch status case failed return failed pages case queued return queued pages case succeeded return succeeded pages default return null fieldindex getpageindex failedpages queuedpages succeededpages public void exclusive lock status status field index page index get page index status index exclusive lock exclusivelock fieldindex getpageindex exclusivelock public void shared lock pages status status field index page index get page index status index shared lock sharedlockpages fieldindex getpageindex sharedlock public void unlock pages status status field index page index get page index status index unlock unlockpages fieldindex getpageindex public iterator page get pages status status field index page index get page index status index shared lock try return index iterator finally index unlock getpages fieldindex getpageindex sharedlock public int get page count status status field index page index get page index status index shared lock try return index size finally index unlock getpagecount fieldindex getpageindex sharedlock public synchronized void set config config config this config config modify setconfig public synchronized config get config return config getconfig public persistent temp bucket factory file dir final string prefix random source strongprng random weakprng boolean encrypt long nodedb handle throws io exception boolean logminor logger should log logger minor this blob factory new persistent blob temp bucket factory blob size nodedb handle new file dir persistent blob tmp this strongprng strongprng this nodedb handle nodedb handle this weakprng weakprng this encrypt encrypt this fg new filename generator weakprng false dir prefix if dir exists dir mkdir if dir exists throw new io exception directory does not exist and cannot be created dir if dir is directory throw new io exception directory is not a directory dir original files new hash set file file files dir list files new file filter public boolean accept file pathname if pathname exists pathname is directory return false string name pathname get name if name starts with prefix return true return false for file f files f file util get canonical file f if logminor logger minor this found f original files add f buckets to free new array list delayed free bucket persistenttempbucketfactory randomsource nodedbhandle ioexception shouldlog blobfactory persistentblobtempbucketfactory blob_size nodedbhandle nodedbhandle nodedbhandle filenamegenerator ioexception isdirectory ioexception originalfiles hashset listfiles filefilter isdirectory getname startswith fileutil getcanonicalfile originalfiles bucketstofree arraylist delayedfreebucket public boolean accept file pathname if pathname exists pathname is directory return false string name pathname get name if name starts with prefix return true return false isdirectory getname startswith public void init file dir string prefix random source strongprng random weakprng throws io exception this strongprng strongprng this weakprng weakprng fg init dir prefix weakprng randomsource ioexception public void register file file synchronized this if original files null throw new illegal state exception completed init has already been called file file util get canonical file file if original files remove file logger error this preserving file but it wasn t found new exception error originalfiles illegalstateexception fileutil getcanonicalfile originalfiles called when boot up is complete deletes any old temp files still unclaimed public synchronized void completed init persisting requests in the database means we don t register files so keep all the temp files for now fixme tidy up unwanted temp files iterator file i original files iterator while i has next file f file i next if logger should log logger minor this logger minor this deleting old tempfile f f delete original files null completedinit originalfiles hasnext shouldlog originalfiles public bucket make bucket long size throws io exception bucket raw bucket null boolean must wrap true if size blob size no need for a delayed free bucket we handle this internally and more efficiently for blobs must wrap false raw bucket blob factory make bucket if raw bucket null raw bucket new persistent temp file bucket fg make random filename fg if encrypt raw bucket new padded ephemerally encrypted bucket raw bucket 1024 strongprng weakprng if must wrap raw bucket new delayed free bucket this raw bucket return raw bucket makebucket ioexception rawbucket mustwrap blob_size delayedfreebucket mustwrap rawbucket blobfactory makebucket rawbucket rawbucket persistenttempfilebucket makerandomfilename rawbucket paddedephemerallyencryptedbucket rawbucket mustwrap rawbucket delayedfreebucket rawbucket rawbucket free an allocated bucket but only after the change has been written to disk public void delayed free bucket delayed free bucket b synchronized this buckets to free add b modified buckets to free true delayedfreebucket delayedfreebucket bucketstofree modifiedbucketstofree private delayed free bucket grab buckets to free synchronized this if buckets to free is empty return null delayed free bucket buckets buckets to free to array new delayed free bucket buckets to free size buckets to free clear modified buckets to free true return buckets delayedfreebucket grabbucketstofree bucketstofree isempty delayedfreebucket bucketstofree toarray delayedfreebucket bucketstofree bucketstofree modifiedbucketstofree public file get dir return fg get dir getdir getdir public filename generator get generator return fg filenamegenerator getgenerator public boolean matches file file return fg matches file public long getid file file return fg getid file public boolean is encrypting return encrypt isencrypting suppress warnings serial public static persistent temp bucket factory load file dir string prefix random source random random fast weak random object container container final long nodedb handle boolean encrypt db job runner job runner ticker ticker throws io exception object set persistent temp bucket factory results container query new predicate persistent temp bucket factory override public boolean match persistent temp bucket factory factory if factory nodedb handle nodedb handle return true return false if results has next persistent temp bucket factory factory results next container activate factory 5 factory init dir prefix random fast weak random factory set encryption encrypt factory blob factory on init container job runner fast weak random new file dir persistent blob tmp blob size ticker return factory else persistent temp bucket factory factory new persistent temp bucket factory dir prefix random fast weak random encrypt nodedb handle factory blob factory on init container job runner fast weak random new file dir persistent blob tmp blob size ticker return factory suppresswarnings persistenttempbucketfactory randomsource fastweakrandom objectcontainer nodedbhandle dbjobrunner jobrunner ioexception objectset persistenttempbucketfactory persistenttempbucketfactory persistenttempbucketfactory nodedbhandle nodedbhandle hasnext persistenttempbucketfactory fastweakrandom setencryption blobfactory oninit jobrunner fastweakrandom blob_size persistenttempbucketfactory persistenttempbucketfactory fastweakrandom nodedbhandle blobfactory oninit jobrunner fastweakrandom blob_size public void set encryption boolean encrypt this encrypt encrypt setencryption public void pre commit object container db synchronized this if modified buckets to free return modified buckets to free false for delayed free bucket bucket buckets to free db activate bucket 1 bucket store to db db store buckets to free precommit objectcontainer modifiedbucketstofree modifiedbucketstofree delayedfreebucket bucketstofree storeto bucketstofree public void post commit object container db blob factory post commit delayed free bucket to free grab buckets to free if to free null to free length 0 return int x 0 for delayed free bucket bucket to free try if bucket to free bucket real free if bucket to remove bucket real remove from db catch throwable t logger error this caught t freeing bucket bucket after transaction commit t x if x 1024 db store buckets to free lots of buckets freed commit now to reduce memory footprint db commit postcommit objectcontainer blobfactory postcommit delayedfreebucket tofree grabbucketstofree tofree tofree delayedfreebucket tofree tofree realfree toremove realremovefrom bucketstofree public void add blob free callback db job job blob factory add blob free callback job addblobfreecallback dbjob blobfactory addblobfreecallback public void remove blob free callback db job job blob factory remove blob free callback job removeblobfreecallback dbjob blobfactory removeblobfreecallback public abstract class toadlet protected toadlet high level simple client client this client client highlevelsimpleclient handle a get request if not overridden by the client send method not supported param uri the uri relative to this client s document root to be fetched throws io exception throws toadlet context closed exception public void handle get uri uri http request req toadlet context ctx throws toadlet context closed exception io exception redirect exception handle unhandled request uri null ctx ioexception toadletcontextclosedexception handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception handleunhandledrequest public void handle post uri uri http request req toadlet context ctx throws toadlet context closed exception io exception redirect exception handle unhandled request uri null ctx handlepost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception handleunhandledrequest private void handle unhandled request uri uri bucket data toadlet context toadlet context throws toadlet context closed exception io exception redirect exception html node page node toadlet context get page maker get page node l10n not supported title toadlet context html node content node toadlet context get page maker get content node page node html node infobox content node add child div class infobox infobox error infobox add child div class infobox header l10n not supported title infobox add child div class infobox content l10n not supported with class class get class get name multi value table string string hdrtbl new multi value table string string hdrtbl put allow this supported methods string builder page buffer new string builder page node generate page buffer toadlet context send reply headers 405 operation not supported hdrtbl text html charset utf 8 page buffer length toadlet context write data page buffer to string get bytes utf 8 handleunhandledrequest toadletcontext toadletcontext toadletcontextclosedexception ioexception redirectexception htmlnode pagenode toadletcontext getpagemaker getpagenode notsupportedtitle toadletcontext htmlnode contentnode toadletcontext getpagemaker getcontentnode pagenode htmlnode contentnode addchild addchild notsupportedtitle addchild notsupportedwithclass getclass getname multivaluetable multivaluetable supportedmethods stringbuilder pagebuffer stringbuilder pagenode pagebuffer toadletcontext sendreplyheaders pagebuffer toadletcontext writedata pagebuffer tostring getbytes private static string l10n string key string pattern string value return l10n get string toadlet key new string pattern new string value getstring private static string l10n string key return l10n get string toadlet key getstring which methods are supported by this toadlet should return a string containing the methods supported separated by commas for example get put in which case both handle get and handle put must be overridden handleget handleput client calls from the above messages to run a freenet request this method may block or suspend param max size maximum length of returned content param client context client context object this should be the same for any group of related requests but different for any two unrelated requests request selection round robin s over these within any priority and retry count class and above the level of individual block fetches fetch result fetch freeneturi uri long max size request client client context throws fetch exception for now just run it blocking return client fetch uri max size client context maxsize clientcontext fetchresult maxsize requestclient clientcontext fetchexception maxsize clientcontext freeneturi insert insert block insert string filename hint boolean getchk only throws insert exception for now just run it blocking insert desireduri check inserturi return client insert insert getchk only filename hint insertblock filenamehint getchkonly insertexception checkinserturi getchkonly filenamehint client calls to write a reply to the http requestor protected void write reply toadlet context ctx int code string mime type string desc byte data int offset int length throws toadlet context closed exception io exception ctx send reply headers code desc null mime type length ctx write data data offset length writereply toadletcontext mimetype toadletcontextclosedexception ioexception sendreplyheaders mimetype writedata client calls to write a reply to the http requestor protected void write reply toadlet context ctx int code string mime type string desc bucket data throws toadlet context closed exception io exception write reply ctx code mime type desc null data writereply toadletcontext mimetype toadletcontextclosedexception ioexception writereply mimetype protected void write reply toadlet context context int code string mime type string desc multi value table string string headers bucket data throws toadlet context closed exception io exception context send reply headers code desc headers mime type data size context write data data writereply toadletcontext mimetype multivaluetable toadletcontextclosedexception ioexception sendreplyheaders mimetype writedata protected void write reply toadlet context ctx int code string mime type string desc string reply throws toadlet context closed exception io exception write reply ctx code mime type desc null reply writereply toadletcontext mimetype toadletcontextclosedexception ioexception writereply mimetype protected void writehtml reply toadlet context ctx int code string desc string reply throws toadlet context closed exception io exception write reply ctx code text html charset utf 8 desc null reply writehtmlreply toadletcontext toadletcontextclosedexception ioexception writereply protected void write text reply toadlet context ctx int code string desc string reply throws toadlet context closed exception io exception write reply ctx code text plain charset utf 8 desc null reply writetextreply toadletcontext toadletcontextclosedexception ioexception writereply protected void writehtml reply toadlet context ctx int code string desc multi value table string string headers string reply throws toadlet context closed exception io exception write reply ctx code text html charset utf 8 desc headers reply writehtmlreply toadletcontext multivaluetable toadletcontextclosedexception ioexception writereply protected void write text reply toadlet context ctx int code string desc multi value table string string headers string reply throws toadlet context closed exception io exception write reply ctx code text plain charset utf 8 desc headers reply writetextreply toadletcontext multivaluetable toadletcontextclosedexception ioexception writereply protected void write reply toadlet context context int code string mime type string desc multi value table string string headers string reply throws toadlet context closed exception io exception byte buffer reply get bytes utf 8 write reply context code mime type desc headers buffer 0 buffer length writereply toadletcontext mimetype multivaluetable toadletcontextclosedexception ioexception getbytes writereply mimetype protected void write reply toadlet context context int code string mime type string desc multi value table string string headers byte buffer int start index int length throws toadlet context closed exception io exception context send reply headers code desc headers mime type length context write data buffer start index length writereply toadletcontext mimetype multivaluetable startindex toadletcontextclosedexception ioexception sendreplyheaders mimetype writedata startindex static void write permanent redirect toadlet context ctx string msg string location throws toadlet context closed exception io exception multi value table string string mvt new multi value table string string mvt put location location if msg null msg else msg html encoder encode msg string redir doc html head title msg title head body h1 l10n perm redirect with reason reason msg h1 a href html encoder encode location l10n click here a body html byte buf try buf redir doc get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e ctx send reply headers 301 moved permanently mvt text html charset utf 8 buf length ctx write data buf 0 buf length writepermanentredirect toadletcontext toadletcontextclosedexception ioexception multivaluetable multivaluetable htmlencoder redirdoc permredirectwithreason htmlencoder clickhere redirdoc getbytes unsupportedencodingexception sendreplyheaders writedata protected void write temporary redirect toadlet context ctx string msg string location throws toadlet context closed exception io exception multi value table string string mvt new multi value table string string mvt put location location if msg null msg else msg html encoder encode msg string redir doc html head title msg title head body h1 l10n temp redirect with reason reason msg h1 a href html encoder encode location l10n click here a body html byte buf try buf redir doc get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e ctx send reply headers 302 found mvt text html charset utf 8 buf length ctx write data buf 0 buf length writetemporaryredirect toadletcontext toadletcontextclosedexception ioexception multivaluetable multivaluetable htmlencoder redirdoc tempredirectwithreason htmlencoder clickhere redirdoc getbytes unsupportedencodingexception sendreplyheaders writedata send a simple error page protected void send error page toadlet context ctx int code string desc string message throws toadlet context closed exception io exception send error page ctx code desc new html node message senderrorpage toadletcontext toadletcontextclosedexception ioexception senderrorpage htmlnode send a slightly more complex error page protected void send error page toadlet context ctx int code string desc html node message throws toadlet context closed exception io exception html node page node ctx get page maker get page node desc ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox error desc html node infobox content ctx get page maker get content node infobox infobox content add child message infobox content add child br infobox content add child a href l10n return to prev page infobox content add child br add homepage link infobox content writehtml reply ctx code desc page node generate senderrorpage toadletcontext htmlnode toadletcontextclosedexception ioexception htmlnode pagenode getpagemaker getpagenode htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox htmlnode infoboxcontent getpagemaker getcontentnode infoboxcontent addchild infoboxcontent addchild infoboxcontent addchild returntoprevpage infoboxcontent addchild addhomepagelink infoboxcontent writehtmlreply pagenode send an error page from an exception param ctx the context object for this request param desc the title of the error page param message the message to be sent to the user the stack trace will follow param t the throwable which caused the error throws io exception if there is an error writing the reply throws toadlet context closed exception if the context has already been closed protected void send error page toadlet context ctx string desc string message throwable t throws toadlet context closed exception io exception html node page node ctx get page maker get page node desc ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox error desc html node infobox content ctx get page maker get content node infobox infobox content add child message infobox content add child br string writer sw new string writer print writer pw new print writer sw pw println t t print stack trace pw pw close fixme what is the modern css xhtml equivalent of pre infobox content add child pre sw to string infobox content add child br infobox content add child a href l10n return to prev page add homepage link infobox content writehtml reply ctx 500 desc page node generate ioexception toadletcontextclosedexception senderrorpage toadletcontext toadletcontextclosedexception ioexception htmlnode pagenode getpagemaker getpagenode htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox htmlnode infoboxcontent getpagemaker getcontentnode infoboxcontent addchild infoboxcontent addchild stringwriter stringwriter printwriter printwriter printstacktrace infoboxcontent addchild tostring infoboxcontent addchild infoboxcontent addchild returntoprevpage addhomepagelink infoboxcontent writehtmlreply pagenode protected void write internal error throwable t toadlet context ctx throws toadlet context closed exception io exception logger error this caught t t string msg html head title l10n get string toadlet internal error title title head body h1 l10n get string toadlet internal error please report h1 pre string writer sw new string writer print writer pw new print writer sw t print stack trace pw pw flush msg msg sw to string pre body html writehtml reply ctx 500 internal error msg writeinternalerror toadletcontext toadletcontextclosedexception ioexception getstring internalerrortitle getstring internalerrorpleasereport stringwriter stringwriter printwriter printwriter printstacktrace tostring writehtmlreply protected static void add homepage link html node content content add child a new string href title new string l10n homepage l10n return to node homepage addhomepagelink htmlnode addchild returntonodehomepage get the client impl do not call the blocking methods on it just use it for configuration etc protected high level simple client get client impl return client highlevelsimpleclient getclientimpl public class opennet disabled exception extends exception private static final long serial versionuid 1 public opennet disabled exception exception e super e opennetdisabledexception serialversionuid opennetdisabledexception public opennet disabled exception string msg super msg opennetdisabledexception param args public static void main string args throws io exception snmp agent getsnmp agent add fetcher new data constant int 1 1 1 10 snmp agent getsnmp agent add fetcher new data constant int 1 1 2 20 snmp agent getsnmp agent add fetcher new data constant int 1 1 3 30 snmp agent getsnmp agent add fetcher new data constant int 1 1 4 40 snmp agent getsnmp agent add fetcher new data constant int 1 1 5 50 snmp agent getsnmp agent add fetcher new data constant string 1 1 0 step by 10 snmp agent getsnmp agent add fetcher new data constant string 1 2 nothing here ioexception snmpagent getsnmpagent addfetcher dataconstantint snmpagent getsnmpagent addfetcher dataconstantint snmpagent getsnmpagent addfetcher dataconstantint snmpagent getsnmpagent addfetcher dataconstantint snmpagent getsnmpagent addfetcher dataconstantint snmpagent getsnmpagent addfetcher dataconstantstring snmpagent getsnmpagent addfetcher dataconstantstring public static void setsnmp port int port ensure created snmpagent port port restartsnmp agent setsnmpport ensurecreated _snmpagent restartsnmpagent public int getsnm port return port getsnmport public static void setsnm pbindto string adr ensure created snmpagent bindto adr restartsnmp agent setsnmpbindto ensurecreated _snmpagent restartsnmpagent public string getsnm pbindto return bindto getsnmpbindto public static void restartsnmp agent ensure created snmpagent stop running new thread snmpagent snmp agent start restartsnmpagent ensurecreated _snmpagent stoprunning _snmpagent public static void stopsnmp agent ensure created snmpagent stop running stopsnmpagent ensurecreated _snmpagent stoprunning public static snmp agent getsnmp agent ensure created return snmpagent snmpagent getsnmpagent ensurecreated _snmpagent private static void ensure created if snmpagent null snmpagent new snmp agent ensurecreated _snmpagent _snmpagent snmpagent private snmp agent alldata new tree map alldata put 99 99 null snmpagent treemap public void add fetcher data fetcher df data handler dh new data handler df alldata put dh get stringoid dh alldata put df getsnmpoid replace all 1 3 df system err println s added df getsnmpoid as df getsnmpoid replace all 1 3 addfetcher datafetcher datahandler datahandler getstringoid replaceall sadded replaceall public void add fetcher multiplexed data fetcher df string oid for int i 0 oid df getsnmpoid i null i alldata put oid replace all 1 3 df system err println m added oid as oid replace all 1 3 addfetcher multiplexeddatafetcher replaceall madded replaceall public void remove fetcher string oid alldata remove oid starts with oid removefetcher startswith public void stop running try socket close catch throwable e prpbably since not running stoprunning public void run try socket new datagram socket port inet address get by name bindto catch io exception e e print stack trace return make smaller 0484 enough while socket is bound byte buf new byte 65536 datagram packet packet new datagram packet buf buf length try socket receive packet request container rc new request container int replylength 0 data handler dh null if rc null throw new bad format exception asdfa ber decoder question parse request start buf rc ber encoder reply reply start rc int err index 0 int err status 0 try while question sequence has more err index question start sequence rc loid question fetchoid rc oid rc loid length 0 for int i 0 i rc loid length i rc oid i 0 rc loid i system err println doing rc oid question fetch null question end sequence reply addoid reply rc catch no such field exception e err status 0x02 no such name if err status 0 need to restart the question question parse request start buf rc todo this does not follow the standard but works with snmpwalk or does it o reply reply start rc err status err index while question sequence has more question start sequence reply start sequence value reply putoid question fetchoid oid reply put null reply end sequence question fetch null question end sequence replylength reply end reply buf rc pdutype request container pdu get next send the response to the client at address and port inet address address packet get address int port packet get port packet new datagram packet buf replylength address port socket send packet catch io exception e e print stack trace break catch bad format exception e system err println datapacket length packet get length for int i 0 i packet get length i string num 000 integer to hex string buf i num num substring num length 2 system err print 0x num if i 1 8 0 system err print if i 1 16 0 system err println system err println e print stack trace system err println e to string catch array index out of bounds exception e e print stack trace not much to do ignore the request and it ll time out socket close datagramsocket inetaddress getbyname ioexception printstacktrace isbound datagrampacket datagrampacket requestcontainer requestcontainer datahandler badformatexception berdecoder parserequeststart berencoder replystart errindex errstatus sequencehasmore errindex startsequence fetchnull endsequence replyaddoid nosuchfieldexception errstatus errstatus parserequeststart replystart errstatus errindex sequencehasmore startsequence startsequence putnull endsequence fetchnull endsequence replyend requestcontainer pdu_get_next inetaddress getaddress getport datagrampacket ioexception printstacktrace badformatexception getlength getlength tohexstring printstacktrace tostring arrayindexoutofboundsexception printstacktrace private string get accualoid string oid boolean thisval throws no such field exception boolean keyfound false iterator it alldata key set iterator string key while it has next keyfound key string it next if key starts with oid keyfound true if it has next thisval key key equals oid string it next key else if keyfound throw new no such field exception oid not found return key getaccualoid nosuchfieldexception keyset hasnext startswith hasnext nosuchfieldexception private object get result fromoid string oid boolean thisval boolean keyfound false iterator it alldata key set iterator string key while it has next keyfound key string it next if key starts with oid keyfound true keyfound equal hasnext v rc pdutype rc pdu get this system err println keyfound key equals rc oid it has next if keyfound key equals rc oid it has next rc pdutype request container pdu get this object data null if keyfound key equals oid it has next if it has next thisval key key equals oid string it next key object df alldata get oid if df instanceof data fetcher data data fetcher df getsnmp data else if df instanceof multiplexed data fetcher data multiplexed data fetcher df getsnmp data oid if data null if oid starts with 1 3 data multiplexed data fetcher df getsnmp data 1 3 oid else data multiplexed data fetcher df getsnmp data oid substring 5 else data null new integer 0 rc loid split to long key replylength make int reply buf rc data else if rc loid length 0 rc loid 0 100 else rc loid new long 1 rc loid 0 0 data new integer 1 data null replylength make int reply buf rc new integer 1 if data null debug dnf oid return data getresultfromoid keyset hasnext startswith pdu_get_this hasnext hasnext requestcontainer pdu_get_this hasnext hasnext datafetcher datafetcher getsnmpdata multiplexeddatafetcher multiplexeddatafetcher getsnmpdata startswith multiplexeddatafetcher getsnmpdata multiplexeddatafetcher getsnmpdata splittolong makeintreply makeintreply private void debug string s system err println snmp agent new date s private ber encoder reply start request container rc return reply start rc 0 0 berencoder replystart requestcontainer replystart private ber encoder reply start request container rc int err status int err index throws snmp too big exception ber encoder be new ber encoder be start sequence whole pkg be put integer 0 version be put octet string rc community community be start sequence byte 0xa2 response be put integer rc requestid rid be put integer err status err be put integer err index err be start sequence oid s and their values return be berencoder replystart requestcontainer errstatus errindex snmptoobigexception berencoder berencoder startsequence putinteger putoctetstring startsequence putinteger putinteger errstatus putinteger errindex startsequence private void reply addoid ber encoder be request container rc throws no such field exception string aoid get accualoid rc oid rc pdutype request container pdu get this object data get result fromoid aoid rc pdutype request container pdu get this be start sequence value be putoid split to long aoid oid system err println will reply with oid rc oid aoid if data instanceof number be put integer number data long value else if data instanceof snmp type wrapper num be putsnmp type wrapper num snmp type wrapper num data else if data instanceof snmp counter32 be put cunter32 snmp counter32 data get value else if data instanceof string char charr string data to char array byte byarr new byte charr length for int i 0 i charr length i byarr i byte charr i be put octet string byarr be end sequence replyaddoid berencoder requestcontainer nosuchfieldexception getaccualoid requestcontainer pdu_get_this getresultfromoid requestcontainer pdu_get_this startsequence splittolong putinteger longvalue snmptypewrappernum putsnmptypewrappernum snmptypewrappernum snmpcounter32 putcunter32 snmpcounter32 getvalue tochararray putoctetstring endsequence private int reply end ber encoder be byte buf throws snmp too big exception return be to bytes buf replyend berencoder snmptoobigexception tobytes http www rane com note161 html private ber decoder parse request start byte buf request container rc throws bad format exception int tmpint ber decoder bd new ber decoder buf bd start sequence if tmpint bd fetch int 0 throw new bad format exception wrong version expected 0 got tmpint rc community bd fetch octet string if rc setpdu bd peek raw throw new bad format exception unknown pdu bd start sequence bd peek raw rc requestid bd fetch int todo care about errors eventually bd fetch int bd fetch int bd start sequence bd start sequence rc loid bd fetchoid rc oid rc loid length 0 for int i 0 i rc loid length i rc oid i 0 rc loid i return bd berdecoder parserequeststart requestcontainer badformatexception berdecoder berdecoder startsequence fetchint badformatexception fetchoctetstring peekraw badformatexception startsequence peekraw fetchint fetchint fetchint startsequence startsequence private long split to long string list if list starts with 1 3 list 1 3 list list list substring 1 string nums list split long ret new long nums length for int i 0 i ret length i ret i long parse long nums i system err print long parse long nums i system err println return ret splittolong startswith parselong parselong public boolean setpdu byte id switch id case byte 0xa0 pdutype pdu get this break case byte 0xa1 pdutype pdu get next break default system err println unknown pdu 0x integer to hex string id 256 256 return false return true pdu_get_this pdu_get_next tohexstring public string to string return community new string community pdu pdutype oid oid tostring public boolean pdu is get return pdutype request container pdu get this pdutype request container pdu get next pduisget requestcontainer pdu_get_this requestcontainer pdu_get_next public high level simple client impl node client core node bucket factory bf random source r boolean cache local requests short priority class boolean force dont ignore too many path components this core node this priority class priority class bucket factory bf this persistent file tracker node persistent temp bucket factory random r this global event producer new simple event producer global event producer add event listener new event logger logger minor false cur max length long max value cur max temp length long max value cur max metadata length 1024 1024 this cache local requests cache local requests this persistent bucket factory node persistent temp bucket factory highlevelsimpleclientimpl nodeclientcore bucketfactory randomsource cachelocalrequests priorityclass forcedontignoretoomanypathcomponents priorityclass priorityclass bucketfactory persistentfiletracker persistenttempbucketfactory globaleventproducer simpleeventproducer globaleventproducer addeventlistener eventlogger curmaxlength max_value curmaxtemplength max_value curmaxmetadatalength cachelocalrequests cachelocalrequests persistentbucketfactory persistenttempbucketfactory public void set max length long max length cur max length max length setmaxlength maxlength curmaxlength maxlength public void set max intermediate length long max intermediate length cur max temp length max intermediate length setmaxintermediatelength maxintermediatelength curmaxtemplength maxintermediatelength fetch a key either returns the data or throws an exception public fetch result fetch freeneturi uri throws fetch exception if uri null throw new null pointer exception fetch context context get fetch context fetch waiter fw new fetch waiter client getter get new client getter fw uri context priority class this null null core client context start get return fw wait for completion fetchresult fetchexception nullpointerexception fetchcontext getfetchcontext fetchwaiter fetchwaiter clientgetter clientgetter priorityclass clientcontext waitforcompletion public fetch result fetch freeneturi uri long override max size throws fetch exception return fetch uri override max size this fetchresult overridemaxsize fetchexception overridemaxsize public fetch result fetch freeneturi uri long override max size request client client context throws fetch exception if uri null throw new null pointer exception fetch waiter fw new fetch waiter fetch context context get fetch context override max size client getter get new client getter fw uri context priority class client context null null core client context start get return fw wait for completion fetchresult overridemaxsize requestclient clientcontext fetchexception nullpointerexception fetchwaiter fetchwaiter fetchcontext getfetchcontext overridemaxsize clientgetter clientgetter priorityclass clientcontext clientcontext waitforcompletion public client getter fetch freeneturi uri long max size request client client context client callback callback fetch context fctx throws fetch exception if uri null throw new null pointer exception client getter get new client getter callback uri fctx priority class client context null null core client context start get return get clientgetter maxsize requestclient clientcontext clientcallback fetchcontext fetchexception nullpointerexception clientgetter clientgetter priorityclass clientcontext clientcontext public freeneturi insert insert block insert boolean getchk only string filename hint throws insert exception return insert insert getchk only filename hint false insertblock getchkonly filenamehint insertexception getchkonly filenamehint public freeneturi insert insert block insert boolean getchk only string filename hint boolean is metadata throws insert exception insert context context get insert context true put waiter pw new put waiter client putter put new client putter pw insert get data insert desireduri insert client metadata context priority class getchk only is metadata this null filename hint false core client context start put false return pw wait for completion insertblock getchkonly filenamehint ismetadata insertexception insertcontext getinsertcontext putwaiter putwaiter clientputter clientputter getdata clientmetadata priorityclass getchkonly ismetadata filenamehint clientcontext waitforcompletion public client putter insert insert block insert boolean getchk only string filename hint boolean is metadata insert context ctx client callback cb throws insert exception client putter put new client putter cb insert get data insert desireduri insert client metadata ctx priority class getchk only is metadata this null filename hint false core client context start put false return put clientputter insertblock getchkonly filenamehint ismetadata insertcontext clientcallback insertexception clientputter clientputter getdata clientmetadata priorityclass getchkonly ismetadata filenamehint clientcontext public freeneturi insert redirect freeneturi inserturi freeneturi targeturi throws insert exception metadata m new metadata metadata simple redirect null null targeturi new client metadata bucket b try b bucket tools make immutable bucket bucket factory m write to byte array catch io exception e logger error this bucket error e e throw new insert exception insert exception internal error e null catch metadata unresolved exception e logger error this impossible error e e throw new insert exception insert exception internal error e null insert block block new insert block b null inserturi return insert block false null true insertredirect insertexception simple_redirect clientmetadata buckettools makeimmutablebucket bucketfactory writetobytearray ioexception insertexception insertexception internal_error metadataunresolvedexception insertexception insertexception internal_error insertblock insertblock public freeneturi insert manifest freeneturi inserturi hash map buckets by name string default name throws insert exception put waiter pw new put waiter simple manifest putter putter new simple manifest putter pw simple manifest putter buckets by name to manifest entries buckets by name priority class inserturi default name get insert context true false this false core client context start putter return pw wait for completion insertmanifest hashmap bucketsbyname defaultname insertexception putwaiter putwaiter simplemanifestputter simplemanifestputter simplemanifestputter bucketsbynametomanifestentries bucketsbyname priorityclass defaultname getinsertcontext clientcontext waitforcompletion public void add global hook client event listener listener global event producer add event listener listener addglobalhook clienteventlistener globaleventproducer addeventlistener public fetch context get fetch context return get fetch context 1 fetchcontext getfetchcontext getfetchcontext public fetch context get fetch context long override max size long max length cur max length long max temp length cur max temp length if override max size 0 max length override max size max temp length override max size return new fetch context max length max temp length cur max metadata length max recursion max archive restarts max archive levels dont enter implicit archives splitfile threads splitfile block retries non splitfile retries usk retries fetch splitfiles follow redirects local requests only max splitfile blocks per segment max splitfile check blocks per segment bucket factory global event producer cache local requests false fetchcontext getfetchcontext overridemaxsize maxlength curmaxlength maxtemplength curmaxtemplength overridemaxsize maxlength overridemaxsize maxtemplength overridemaxsize fetchcontext maxlength maxtemplength curmaxmetadatalength max_recursion max_archive_restarts max_archive_levels dont_enter_implicit_archives splitfile_threads splitfile_block_retries non_splitfile_retries usk_retries fetch_splitfiles follow_redirects local_requests_only max_splitfile_blocks_per_segment max_splitfile_check_blocks_per_segment bucketfactory globaleventproducer cachelocalrequests public insert context get insert context boolean force non persistent return new insert context bucket factory force non persistent bucket factory persistent bucket factory force non persistent null persistent file tracker get instance persistent file tracker insert retries consecutive rnfs assume success splitfile insert threads splitfile blocks per segment splitfile check blocks per segment global event producer cache local requests insertcontext getinsertcontext forcenonpersistent insertcontext bucketfactory forcenonpersistent bucketfactory persistentbucketfactory forcenonpersistent nullpersistentfiletracker getinstance persistentfiletracker insert_retries consecutive_rnfs_assume_success splitfile_insert_threads splitfile_blocks_per_segment splitfile_check_blocks_per_segment globaleventproducer cachelocalrequests public freeneturi generate key pair string doc name insertable clientssk key insertable clientssk create random random doc name return new freeneturi key get inserturi key geturi generatekeypair docname insertableclientssk insertableclientssk createrandom docname getinserturi private final client callback null callback new null client callback public void prefetch freeneturi uri long timeout long max size set allowed types prefetch uri timeout max size allowed types request starter prefetch priority class clientcallback nullcallback nullclientcallback maxsize allowedtypes maxsize allowedtypes requeststarter prefetch_priority_class public void prefetch freeneturi uri long timeout long max size set allowed types short prio fetch context ctx get fetch context max size ctx allowedmime types allowed types final client getter get new client getter null callback uri ctx prio this new null bucket null core get ticker queue timed job new runnable public void run get cancel null core client context timeout try core client context start get catch fetch exception e ignore maxsize allowedtypes fetchcontext getfetchcontext maxsize allowedmimetypes allowedtypes clientgetter clientgetter nullcallback nullbucket getticker queuetimedjob clientcontext clientcontext fetchexception final client getter get new client getter null callback uri ctx prio this new null bucket null core get ticker queue timed job new runnable public void run get cancel null core client context clientgetter clientgetter nullcallback nullbucket getticker queuetimedjob clientcontext public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public static void encode message m output stream os throws transformer exception parser configuration exception synchronized m stream result result stream new stream result os document builder factory xml factory document builder factory new instance document builder xml builder xml factory new document builder dom implementation impl xml builder getdom implementation document xml doc impl create document null freetalk plugin title null element root element xml doc get document element element message tag xml doc create element message message tag set attribute version integer to string xml format version version of the xml format element id tag xml doc create element messageid id tag append child xml doc createcdata section m getid message tag append child id tag element subject tag xml doc create element subject subject tag append child xml doc createcdata section m get title message tag append child subject tag element date tag xml doc create element date synchronized m date format date tag append child xml doc create text node m date format format m get date message tag append child date tag element time tag xml doc create element time synchronized m time format time tag append child xml doc create text node m time format format m get date message tag append child time tag element boards tag xml doc create element boards for board b m get boards element board tag xml doc create element board board tag append child xml doc createcdata section b get name boards tag append child board tag message tag append child boards tag if m get reply to board null element reply board tag xml doc create element reply board reply board tag append child xml doc createcdata section m get reply to board get name message tag append child reply board tag if m is thread element in reply to tag xml doc create element in reply to try element in reply to message xml doc create element message element in reply to order xml doc create element order in reply to order append child xml doc create text node 0 for fms compatibility not used by freetalk element in reply toid xml doc create element messageid in reply toid append child xml doc createcdata section m get parentid element in reply touri xml doc create element messageuri in reply touri append child xml doc createcdata section m get parenturi to string in reply to message append child in reply to order in reply to message append child in reply toid in reply to message append child in reply touri in reply to tag append child in reply to message catch no such message exception e try element in reply to thread xml doc create element thread element in reply toid xml doc create element messageid in reply toid append child xml doc createcdata section m get threadid element in reply touri xml doc create element messageuri in reply touri append child xml doc createcdata section m get threaduri to string in reply to thread append child in reply toid in reply to thread append child in reply touri in reply to tag append child in reply to thread catch no such message exception e message tag append child in reply to tag element body tag xml doc create element body body tag append child xml doc createcdata section m get text message tag append child body tag attachment attachments m get attachments if attachments null element attachments tag xml doc create element attachments for attachment a attachments element file tag xml doc create element file element key tag xml doc create element key key tag append child xml doc createcdata section a geturi to string element size tag xml doc create element size size tag append child xml doc createcdata section long to string a get size file tag append child key tag file tag append child size tag attachments tag append child file tag message tag append child attachments tag root element append child message tag dom source dom source new dom source xml doc transformer factory transform factory transformer factory new instance transformer serializer transform factory new transformer serializer set output property output keys encoding utf 8 serializer set output property output keys indent yes fixme set to no before release serializer set output property output keys standalone no serializer transform dom source result stream outputstream transformerexception parserconfigurationexception streamresult resultstream streamresult documentbuilderfactory xmlfactory documentbuilderfactory newinstance documentbuilder xmlbuilder xmlfactory newdocumentbuilder domimplementation xmlbuilder getdomimplementation xmldoc createdocument plugin_title rootelement xmldoc getdocumentelement messagetag xmldoc createelement messagetag setattribute tostring xml_format_version idtag xmldoc createelement idtag appendchild xmldoc createcdatasection messagetag appendchild idtag subjecttag xmldoc createelement subjecttag appendchild xmldoc createcdatasection gettitle messagetag appendchild subjecttag datetag xmldoc createelement mdateformat datetag appendchild xmldoc createtextnode mdateformat getdate messagetag appendchild datetag timetag xmldoc createelement mtimeformat timetag appendchild xmldoc createtextnode mtimeformat getdate messagetag appendchild timetag boardstag xmldoc createelement getboards boardtag xmldoc createelement boardtag appendchild xmldoc createcdatasection getname boardstag appendchild boardtag messagetag appendchild boardstag getreplytoboard replyboardtag xmldoc createelement replyboard replyboardtag appendchild xmldoc createcdatasection getreplytoboard getname messagetag appendchild replyboardtag isthread inreplytotag xmldoc createelement inreplyto inreplytomessage xmldoc createelement inreplytoorder xmldoc createelement inreplytoorder appendchild xmldoc createtextnode inreplytoid xmldoc createelement inreplytoid appendchild xmldoc createcdatasection getparentid inreplytouri xmldoc createelement inreplytouri appendchild xmldoc createcdatasection getparenturi tostring inreplytomessage appendchild inreplytoorder inreplytomessage appendchild inreplytoid inreplytomessage appendchild inreplytouri inreplytotag appendchild inreplytomessage nosuchmessageexception inreplytothread xmldoc createelement inreplytoid xmldoc createelement inreplytoid appendchild xmldoc createcdatasection getthreadid inreplytouri xmldoc createelement inreplytouri appendchild xmldoc createcdatasection getthreaduri tostring inreplytothread appendchild inreplytoid inreplytothread appendchild inreplytouri inreplytotag appendchild inreplytothread nosuchmessageexception messagetag appendchild inreplytotag bodytag xmldoc createelement bodytag appendchild xmldoc createcdatasection gettext messagetag appendchild bodytag getattachments attachmentstag xmldoc createelement filetag xmldoc createelement keytag xmldoc createelement keytag appendchild xmldoc createcdatasection tostring sizetag xmldoc createelement sizetag appendchild xmldoc createcdatasection tostring getsize filetag appendchild keytag filetag appendchild sizetag attachmentstag appendchild filetag messagetag appendchild attachmentstag rootelement appendchild messagetag domsource domsource domsource xmldoc transformerfactory transformfactory transformerfactory newinstance transformfactory newtransformer setoutputproperty outputkeys setoutputproperty outputkeys setoutputproperty outputkeys domsource resultstream param db param input stream param message manager needed for retrieving the board object from the strings of the board names param message list param uri return throws exception suppress warnings deprecation public static message decode message manager message manager input stream input stream wot message list message list freeneturi uri throws exception document builder factory xml factory document builder factory new instance xml factory set feature xml constants feature secure processing true dom parser use set attribute to pass to underlying xerces xml factory set attribute http apache org xml features disallow doctype decl true document builder xml builder xml factory new document builder document xml xml builder parse input stream element message element element xml get elements by tag name message item 0 if integer parse int message element get attribute version xml format version throw new exception version message element get attribute version xml format version string messageid message element get elements by tag name messageid item 0 get text content string message title message element get elements by tag name subject item 0 get text content date message date m date format parse message element get elements by tag name date item 0 get text content date message time m time format parse message element get elements by tag name time item 0 get text content message date set hours message time get hours message date set minutes message time get minutes message date set seconds message time get seconds set board message boards new hash set board element boards element element message element get elements by tag name boards item 0 node list board list boards element get elements by tag name board for int i 0 i board list get length i message boards add message manager get or create board board list item i get text content node reply to board element message element get elements by tag name reply board item 0 board message reply to board reply to board element null message manager get or create board reply to board element get text content null wot messageuri parent messageuri null wot messageuri parent threaduri null element in reply to element element message element get elements by tag name in reply to item 0 if in reply to element null node list parent messages in reply to element get elements by tag name message for int i 0 i parent messages get length i element parent message element parent messages item i if parent message get elements by tag name order item 0 get text content equals 0 parent messageuri new wot messageuri parent message get elements by tag name messageuri item 0 get text content element thread element element in reply to element get elements by tag name thread item 0 if thread element null parent threaduri new wot messageuri thread element get elements by tag name messageuri item 0 get text content string message body message element get elements by tag name body item 0 get text content array list message attachment message attachments null element attachments element element message element get elements by tag name attachments item 0 if attachments element null node list file elements attachments element get elements by tag name file message attachments new array list message attachment file elements get length for int i 0 i file elements get length i element file element element file elements item i node key element file element get elements by tag name key item 0 node size element file element get elements by tag name size item 0 message attachments add new message attachment new freeneturi key element get text content size element null long parse long size element get text content 1 return wot message construct message list uri messageid parent threaduri parent messageuri message boards message reply to board message list get author message title message date message body message attachments inputstream messagemanager messagelist suppresswarnings messagemanager messagemanager inputstream inputstream wotmessagelist messagelist documentbuilderfactory xmlfactory documentbuilderfactory newinstance xmlfactory setfeature xmlconstants feature_secure_processing setattribute xmlfactory setattribute documentbuilder xmlbuilder xmlfactory newdocumentbuilder xmlbuilder inputstream messageelement getelementsbytagname parseint messageelement getattribute xml_format_version messageelement getattribute xml_format_version messageelement getelementsbytagname gettextcontent messagetitle messageelement getelementsbytagname gettextcontent messagedate mdateformat messageelement getelementsbytagname gettextcontent messagetime mtimeformat messageelement getelementsbytagname gettextcontent messagedate sethours messagetime gethours messagedate setminutes messagetime getminutes messagedate setseconds messagetime getseconds messageboards hashset boardselement messageelement getelementsbytagname nodelist boardlist boardselement getelementsbytagname boardlist getlength messageboards messagemanager getorcreateboard boardlist gettextcontent replytoboardelement messageelement getelementsbytagname replyboard messagereplytoboard replytoboardelement messagemanager getorcreateboard replytoboardelement gettextcontent wotmessageuri parentmessageuri wotmessageuri parentthreaduri inreplytoelement messageelement getelementsbytagname inreplyto inreplytoelement nodelist parentmessages inreplytoelement getelementsbytagname parentmessages getlength parentmessage parentmessages parentmessage getelementsbytagname gettextcontent parentmessageuri wotmessageuri parentmessage getelementsbytagname gettextcontent threadelement inreplytoelement getelementsbytagname threadelement parentthreaduri wotmessageuri threadelement getelementsbytagname gettextcontent messagebody messageelement getelementsbytagname gettextcontent arraylist messageattachments attachmentselement messageelement getelementsbytagname attachmentselement nodelist fileelements attachmentselement getelementsbytagname messageattachments arraylist fileelements getlength fileelements getlength fileelement fileelements keyelement fileelement getelementsbytagname sizeelement fileelement getelementsbytagname messageattachments keyelement gettextcontent sizeelement parselong sizeelement gettextcontent wotmessage messagelist parentthreaduri parentmessageuri messageboards messagereplytoboard messagelist getauthor messagetitle messagedate messagebody messageattachments node updater node update manager manager freeneturi uri boolean ext update int current int min int max string blob filename prefix logminor logger should log logger minor this this manager manager this node manager node this uri uri set suggested edition version build number 1 this ticker node ps this core node client core this current version current this available version 1 this is running true this cg null this is fetching false this ext update ext update this blob filename prefix blob filename prefix this max deploy version max this min deploy version min fetch context temp context core make client short 0 true get fetch context temp context allow splitfiles true temp context dont enter implicit archives false this ctx temp context nodeupdater nodeupdatemanager extupdate blobfilenameprefix shouldlog setsuggestededition buildnumber clientcore currentversion availableversion isrunning isfetching extupdate extupdate blobfilenameprefix blobfilenameprefix maxdeployversion mindeployversion fetchcontext tempcontext makeclient getfetchcontext tempcontext allowsplitfiles tempcontext dontenterimplicitarchives tempcontext void start try because of uom this version is actually worth having as well usk my usk usk create uri set suggested edition current version core usk manager subscribe my usk this true this catch malformedurl exception e logger error this the auto update uri isn t valid and can t be used manager blow the auto update uri isn t valid and can t be used myusk setsuggestededition currentversion uskmanager myusk malformedurlexception public void on found edition long l usk key object container container client context context boolean was metadata short codec byte data boolean new known good boolean new slot too if new known good new slot too return logminor logger should log logger minor this if logminor logger minor this found edition l int found synchronized this if is running return found int key suggested edition real available version found if found max deploy version system err println ignoring ext update freenet ext jar update edition l version too new found max deploy version if found available version return system err println found ext update freenet ext jar update edition found logger minor this updating available version from available version to found and queueing an update this available version found finish on found edition found onfoundedition objectcontainer clientcontext wasmetadata newknowngood newslottoo newknowngood newslottoo shouldlog isrunning suggestededition realavailableversion maxdeployversion extupdate maxdeployversion availableversion extupdate availableversion availableversion availableversion finishonfoundedition private void finish on found edition int found ticker queue timed job new runnable public void run maybe update 60 1000 leave some time in case we get later editions locking always take the node updater lock before the node update manager lock if found current version system err println cancelling fetch for found not newer than current version current version return manager on start fetching ext update logger minor this fetching ext update freenet ext jar update edition found finishonfoundedition queuetimedjob maybeupdate nodeupdater nodeupdatemanager currentversion currentversion onstartfetching extupdate extupdate private void finish on found edition int found ticker queue timed job new runnable public void run maybe update finishonfoundedition queuetimedjob maybeupdate public void maybe update client getter to start null if manager is enabled return if manager is blown return client getter cancelled null synchronized this if logminor logger minor this maybe update is fetching is fetching is running is running available version available version if is running return if is fetching available version fetching version return if available version fetched version return if fetching version min deploy version fetching version current version logger normal this cancelling previous fetch cancelled cg cg null fetching version available version if available version current version logger normal this starting the update process available version system err println starting the update process found the update available version now fetching it if logminor logger minor this starting the update process available version we fetch it try if cg null cg is cancelled if logminor logger minor this scheduling request for uri set suggested edition available version if available version current version system err println starting ext update freenet ext jar fetch for available version temp blob file file create temp file blob filename prefix available version fblob tmp manager node client core get persistent temp dir freeneturi uri uri set suggested edition available version uri uri ssk forusk cg new client getter this uri ctx request starter immediate splitfile priority class this null new file bucket temp blob file false false false false false to start cg else system err println already fetching ext update freenet ext jar fetch for fetching version want available version is fetching true catch exception e logger error this error while starting the fetching e e is fetching false if to start null try node client core client context start to start catch fetch exception e logger error this error while starting the fetching e e synchronized this is fetching false if cancelled null cancelled cancel null core client context maybeupdate clientgetter tostart isenabled isblown clientgetter maybeupdate isfetching isfetching isrunning isrunning availableversion availableversion isrunning isfetching availableversion fetchingversion availableversion fetchedversion fetchingversion mindeployversion fetchingversion currentversion fetchingversion availableversion availableversion currentversion availableversion availableversion availableversion iscancelled setsuggestededition availableversion availableversion currentversion extupdate availableversion tempblobfile createtempfile blobfilenameprefix availableversion clientcore getpersistenttempdir setsuggestededition availableversion sskforusk clientgetter requeststarter immediate_splitfile_priority_class filebucket tempblobfile tostart extupdate fetchingversion availableversion isfetching isfetching tostart clientcore clientcontext tostart fetchexception isfetching clientcontext file get blob file int available version return new file node client core get persistent temp dir blob filename prefix available version fblob getblobfile availableversion clientcore getpersistenttempdir blobfilenameprefix availableversion public void write jar to file f new throws io exception int fetched synchronized this fetched fetched version synchronized write jar sync if f new delete f new exists system err println can t delete f new file output stream fos fos new file output stream f new bucket tools copy to result as bucket fos 1 fos flush fos close synchronized this written version fetched system err println written ext update ext main jar to f new writejarto fnew ioexception fetchedversion writejarsync fnew fnew fnew fileoutputstream fileoutputstream fnew buckettools copyto asbucket writtenversion extupdate fnew public void on success fetch result result client getter state object container container on success result state temp blob file fetching version onsuccess fetchresult clientgetter objectcontainer onsuccess tempblobfile fetchingversion void on success fetch result result client getter state file temp blob file int fetched version logminor logger should log logger minor this int required ext 1 int recommended ext 1 synchronized this if fetched version this fetched version temp blob file delete if result null bucket to free result as bucket if to free null to free free return if result null result as bucket null result as bucket size 0 temp blob file delete logger error this cannot update result either null or empty for available version system err println cannot update result either null or empty for available version try again if result null result as bucket null available version fetched version node ps queue timed job new runnable public void run maybe update 0 return file blob file get blob file fetched version if temp blob file rename to blob file blob file delete if temp blob file rename to blob file if blob file exists temp blob file exists blob file length temp blob file length logger minor this can t rename temp blob file over blob file for fetched version probably not a big deal though as the files are the same size else logger error this not able to rename binary blob for node updater temp blob file blob file may not be able to tell other peers about this build this fetched version fetched version system out println found ext update ext fetched version if fetched version current version logger normal this found version fetched version setting up a new updated version available user alert if ext update input stream is null try is result as bucket get input stream zip input stream zis new zip input stream is zip entry ze while true ze zis get next entry if ze null break if ze is directory continue string name ze get name if name equals meta inf manifest mf if logminor logger minor this found manifest long size ze get size if logminor logger minor this manifest size size if size max manifest size logger error this manifest is too big size bytes limit is max manifest size break byte buf new byte int size data input stream dis new data input stream zis dis read fully buf byte array input stream bais new byte array input stream buf input stream reader isr new input stream reader bais utf 8 buffered reader br new buffered reader isr string line while line br read line null if line starts with required ext prefix required ext integer parse int line substring required ext prefix length else if line starts with recommended ext prefix recommended ext integer parse int line substring recommended ext prefix length else zis close entry catch io exception e logger error this io exception trying to read manifest on update catch throwable t logger error this failed to parse update manifest t t required ext recommended ext 1 finally closer close is if required ext 1 system err println required ext version required ext logger normal this required ext version required ext if recommended ext 1 system err println recommended ext version recommended ext logger normal this recommended ext version recommended ext this cg null if this result null this result as bucket free this result result manager on downloaded new jar ext update required ext recommended ext onsuccess fetchresult clientgetter tempblobfile fetchedversion shouldlog requiredext recommendedext fetchedversion fetchedversion tempblobfile tofree asbucket tofree tofree asbucket asbucket tempblobfile availableversion availableversion asbucket availableversion fetchedversion queuetimedjob maybeupdate blobfile getblobfile fetchedversion tempblobfile renameto blobfile blobfile tempblobfile renameto blobfile blobfile tempblobfile blobfile tempblobfile tempblobfile blobfile fetchedversion tempblobfile blobfile fetchedversion fetchedversion extupdate fetchedversion fetchedversion currentversion fetchedversion updatedversionavailableuseralert extupdate inputstream asbucket getinputstream zipinputstream zipinputstream zipentry getnextentry isdirectory getname getsize max_manifest_size max_manifest_size datainputstream datainputstream readfully bytearrayinputstream bytearrayinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader readline startswith required_ext_prefix requiredext parseint required_ext_prefix startswith recommended_ext_prefix recommendedext parseint recommended_ext_prefix closeentry ioexception ioexception requiredext recommendedext requiredext requiredext requiredext recommendedext recommendedext recommendedext asbucket ondownloadednewjar extupdate requiredext recommendedext node ps queue timed job new runnable public void run maybe update queuetimedjob maybeupdate public void on failure fetch exception e client getter state object container container logminor logger should log logger minor this if is running return int error code e get mode temp blob file delete if logminor logger minor this on failure e state synchronized this this cg null is fetching false if error code fetch exception cancelled e is fatal logger normal this rescheduling new request ticker queue timed job new runnable public void run maybe update 0 else logger error this canceling fetch e get message system err println unexpected error fetching update e get message if e is fatal wait for the next version else ticker queue timed job new runnable public void run maybe update 60 60 1000 onfailure fetchexception clientgetter objectcontainer shouldlog isrunning errorcode getmode tempblobfile onfailure isfetching errorcode fetchexception isfatal queuetimedjob maybeupdate getmessage getmessage isfatal queuetimedjob maybeupdate public void on success base client putter state object container container impossible onsuccess baseclientputter objectcontainer public void on failure insert exception e base client putter state object container container impossible onfailure insertexception baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container impossible ongenerateduri baseclientputter objectcontainer called before kill don t do anything that will involve taking locks public void pre kill is running false prekill isrunning void kill try client getter c synchronized this is running false usk my usk usk create uri set suggested edition current version core usk manager unsubscribe my usk this c cg cg null c cancel null core client context catch exception e logger minor this cannot kill node updater e clientgetter isrunning myusk setsuggestededition currentversion uskmanager myusk clientcontext nodeupdater public freeneturi get update key return uri getupdatekey public void on major progress object container container ignore onmajorprogress objectcontainer public synchronized boolean can update now return fetched version current version canupdatenow fetchedversion currentversion public void on fetchable base client putter state object container container ignore we don t insert onfetchable baseclientputter objectcontainer called when the fetch uri has changed no major locks are held by caller param uri the new uri public void on changeuri freeneturi uri kill this uri uri maybe update onchangeuri maybeupdate public int get written version return written version getwrittenversion writtenversion public int get fetched version return fetched version getfetchedversion fetchedversion public boolean is fetching return available version fetched version available version current version isfetching availableversion fetchedversion availableversion currentversion public int fetching version we will not deploy current version if fetching version current version return available version else return fetching version fetchingversion currentversion fetchingversion currentversion availableversion fetchingversion public long get blob size return get blob file get fetched version length getblobsize getblobfile getfetchedversion public file get blob file return get blob file get fetched version getblobfile getblobfile getfetchedversion public short get polling priority normal return request starter immediate splitfile priority class getpollingprioritynormal requeststarter immediate_splitfile_priority_class public short get polling priority progress return request starter interactive priority class getpollingpriorityprogress requeststarter interactive_priority_class public boolean persistent return false called by node update manager to re set the min max versions for ext when a new freenet jar has been downloaded this is to try to avoid the node installing incompatible versions of main and ext public void set min max int required ext int recommended ext int call finished found 1 synchronized this if recommended ext 1 max deploy version recommended ext if required ext 1 min deploy version required ext if real available version available version available version required ext real available version required ext we found a revision but didn t fetch it because it wasn t within the range for the old jar the new one requires it however system err println previously out of range edition real available version is now needed by the new jar scheduling fetch call finished found available version real available version else if available version required ext including if it hasn t been found at all just try it call finished found available version required ext system err println need minimum edition required ext for new jar found available version scheduling fetch if call finished found 1 finish on found edition call finished found nodeupdatemanager setminmax requiredext recommendedext callfinishedfound recommendedext maxdeployversion recommendedext requiredext mindeployversion requiredext realavailableversion availableversion availableversion requiredext realavailableversion requiredext realavailableversion callfinishedfound availableversion realavailableversion availableversion requiredext callfinishedfound availableversion requiredext requiredext availableversion callfinishedfound finishonfoundedition callfinishedfound public boolean object can new object container container logger error this not storing node updater in database new exception error return false objectcannew objectcontainer nodeupdater public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private final array list sendable request list persistent sendable request set list new array list freenet node sendable request arraylist sendablerequest persistentsendablerequestset arraylist sendablerequest public synchronized boolean add request sendable request req object container container container activate list 1 int idx find req if idx 1 list add req container store req store to depth 1 otherwise it will update to depth 3 container ext store list 1 return true else return false addrequest sendablerequest objectcontainer private synchronized int find sendable request req for int i 0 i list size i if list get i req return i return 1 sendablerequest public synchronized sendable request list requests object container container container activate list 1 return list to array new sendable request list size sendablerequest listrequests objectcontainer toarray sendablerequest public synchronized boolean remove request sendable request req object container container container activate list 1 int idx find req if idx 1 return false list remove idx container ext store list 2 return true removerequest sendablerequest objectcontainer public void remove from object container container container activate list 1 container delete list container delete this removefrom objectcontainer protected message digest d public hmac message digest md this d md messagedigest messagedigest public boolean verify byte k byte text byte mac byte mac2 mac k text mac length return arrays equals mac mac2 public byte mac byte k byte text int macbytes byte k0 null if k length b step 1 k0 k else step 2 if k length b k0 k util hash bytes d k if k length b step 3 k0 new byte b system arraycopy k 0 k0 0 k length step 4 byte is1 util xor k0 ipad step 5 6 d update is1 d update text is1 d digest step 7 byte is2 util xor k0 opad step 8 9 d update is2 d update is1 is1 d digest step 10 if macbytes is1 length return is1 else byte rv new byte macbytes system arraycopy is1 0 rv 0 math min rv length is1 length return rv hashbytes public static void main string args throws unsupported encoding exception hmac s null try s new hmac message digest get instance sha1 catch no such algorithm exception e throw new runtime exception e byte key new byte 20 system err println 20x0b hi there byte text text hi there get bytes utf 8 for int i 0 i key length i key i byte 0x0b byte mv s mac key text 20 system out println hex util bytes to hex mv 0 mv length system err println 20xaa 50xdd for int i 0 i key length i key i byte 0xaa text new byte 50 for int i 0 i text length i text i byte 0xdd mv s mac key text 20 system out println hex util bytes to hex mv 0 mv length key new byte 25 system err println 25x i 1 50xcd for int i 0 i key length i key i byte i 1 for int i 0 i text length i text i byte 0xcd mv s mac key text 20 system out println hex util bytes to hex mv 0 mv length key new byte 20 system err println 20x0c test with truncation for int i 0 i key length i key i byte 0x0c text test with truncation get bytes utf 8 mv s mac key text 20 system out println hex util bytes to hex mv 0 mv length mv s mac key text 12 system out println hex util bytes to hex mv 0 mv length unsupportedencodingexception messagedigest getinstance nosuchalgorithmexception runtimeexception getbytes hexutil bytestohex hexutil bytestohex hexutil bytestohex getbytes hexutil bytestohex hexutil bytestohex public static byte mac withsha256 byte k byte text int macbytes message digest sha256 null try sha256 sha256 get message digest hmac hash new hmac sha256 return hash mac k text macbytes finally if sha256 null sha256 return message digest sha256 macwithsha256 messagedigest getmessagedigest returnmessagedigest public static boolean verify withsha256 byte k byte text byte mac message digest sha256 null try sha256 sha256 get message digest hmac hash new hmac sha256 return hash verify k text mac finally if sha256 null sha256 return message digest sha256 verifywithsha256 messagedigest getmessagedigest returnmessagedigest set whether decoding should proceed on a best effort basis if the input data is invalid public abstract void set ignore errors boolean ignore encode text into this representation public abstract byte buffer encode byte buffer input setignoreerrors bytebuffer bytebuffer decode text from this representation public abstract byte buffer decode byte buffer input bytebuffer bytebuffer get a mime transfer encoding object for encoding and decoding message body parts names are 7bit 8bit binary quoted printable base64 public static transfer encoding body encoding string name if name equals ignore case quoted printable return new quoted printable encoding false false else if name equals ignore case base64 return new base64 encoding else if name equals ignore case 7bit return new identity encoding true true else if name equals ignore case 8bit return new identity encoding true false else if name equals ignore case binary return new identity encoding false false else throw new illegal argument exception unknown encoding name mimetransferencoding transferencoding bodyencoding equalsignorecase quotedprintableencoding equalsignorecase base64encoding equalsignorecase identityencoding equalsignorecase identityencoding equalsignorecase identityencoding illegalargumentexception get a mime transfer encoding object for encoding and decoding mail headers note that semantics of quoted printable encoding differ slightly between body text and header encoded words in particular encoded words can have underscore representing space public static transfer encoding header word encoding string name if name equals ignore case q return new quoted printable encoding true false else if name equals ignore case b return new base64 encoding else throw new illegal argument exception unknown encoding name mimetransferencoding transferencoding headerwordencoding equalsignorecase quotedprintableencoding equalsignorecase base64encoding illegalargumentexception convenience function for appending a byte to a byte buffer protected static byte buffer append byte byte buffer buffer byte b if buffer has remaining buffer put b return buffer else byte buffer newbuf byte buffer allocate buffer capacity 2 buffer flip newbuf put buffer newbuf put b return newbuf bytebuffer bytebuffer appendbyte bytebuffer hasremaining bytebuffer bytebuffer creates a new instance param source the jmdns instance which originated the event param type the type name of the service param name the instance name of the service param info the service info record or null if the service could be be resolved public service event impl jmdns impl source string type string name service info impl info super source this type type this name name this info info serviceeventimpl jmdnsimpl serviceinfoimpl see plugins mdns discovery javax jmdns service event getdns public jmdns getdns return jmdns get source mdnsdiscovery serviceevent getsource see plugins mdns discovery javax jmdns service event get type public string get type return type mdnsdiscovery serviceevent gettype gettype see plugins mdns discovery javax jmdns service event get name public string get name return name mdnsdiscovery serviceevent getname getname see plugins mdns discovery javax jmdns service event to string public string to string string buffer buf new string buffer buf append get class get name buf append super to string buf append name buf append get name buf append type buf append get type buf append info buf append get info return buf to string mdnsdiscovery serviceevent tostring tostring stringbuffer stringbuffer getclass getname tostring getname gettype getinfo tostring public service info get info return info serviceinfo getinfo public final static boolean has data string value if value null return false if value length 0 return false return true hasdata public final static int to integer string value try return integer parse int value catch exception e debug warning e return 0 tointeger parseint public final static long to long string value try return long parse long value catch exception e debug warning e return 0 tolong parselong public final static int find of string str string chars int start idx int end idx int offset boolean is equal if offset 0 return 1 int char cnt chars length int idx start idx while true if 0 offset if end idx idx break else if idx end idx break char strc str char at idx int no equal cnt 0 for int n 0 n char cnt n char charc chars char at n if is equal true if strc charc return idx else if strc charc no equal cnt if no equal cnt char cnt return idx idx offset return 1 findof startidx endidx isequal charcnt startidx endidx endidx charat noequalcnt charcnt charat isequal noequalcnt noequalcnt charcnt public final static int find first of string str string chars return find of str chars 0 str length 1 1 true findfirstof findof public final static int find first not of string str string chars return find of str chars 0 str length 1 1 false findfirstnotof findof public final static int find last of string str string chars return find of str chars str length 1 0 1 true findlastof findof public final static int find last not of string str string chars return find of str chars str length 1 0 1 false findlastnotof findof public final static string trim string trim str string trim chars int sp idx find first not of trim str trim chars if sp idx 0 string buf trim str return buf string trim str2 trim str substring sp idx trim str length sp idx find last not of trim str2 trim chars if sp idx 0 string buf trim str2 return buf string buf trim str2 substring 0 sp idx 1 return buf trimstr trimchars spidx findfirstnotof trimstr trimchars spidx trimstr trimstr2 trimstr spidx trimstr spidx findlastnotof trimstr2 trimchars spidx trimstr2 trimstr2 spidx persister persistable t file persist temp file persist target packet sender ps this persistable t this persist temp persist temp this persist target persist target this ps ps persisttemp persisttarget packetsender persisttemp persisttemp persisttarget persisttarget subclass must set the others later protected persister persistable t packet sender ps this persistable t this ps ps packetsender void interrupt synchronized this notify all notifyall public void run freenet support logger os thread logpid this try persist throttle catch out of memory error e oom handler handleoom e system err println will restart throttle persister catch throwable t logger error this caught in throttle persister t t system err println caught in throttle persister t t print stack trace system err println will restart throttle persister ps queue timed job this 60 1000 osthread persistthrottle outofmemoryerror oomhandler throttlepersister throttlepersister throttlepersister printstacktrace throttlepersister queuetimedjob private void persist throttle boolean logminor logger should log logger minor this if logminor logger minor this trying to persist throttles simple field set fs persistable persist throttles to field set try file output stream fos new file output stream persist temp try fs write to fos fos close file util rename to persist temp persist target catch io exception e persist temp delete finally closer close fos catch file not found exception e logger error this could not store throttle data to disk e e return persistthrottle shouldlog simplefieldset persistthrottlestofieldset fileoutputstream fileoutputstream persisttemp writeto fileutil renameto persisttemp persisttarget ioexception persisttemp filenotfoundexception public simple field set read simple field set throttlefs null try throttlefs simple field set read from persist target false true catch io exception e try throttlefs simple field set read from persist temp false true catch file not found exception e1 ignore catch io exception e1 if persist target length 0 persist temp length 0 logger error this could not read persist target e and could not read persist temp either e1 return throttlefs simplefieldset simplefieldset simplefieldset readfrom persisttarget ioexception simplefieldset readfrom persisttemp filenotfoundexception ioexception persisttarget persisttemp persisttarget persisttemp public void start synchronized this if started logger error this already started this new exception debug return started true run public finished compression message string identifier boolean global finished compression event event this identifier identifier this codec event codec this compressed size event compressed size this orig size event original size this global global finishedcompressionmessage finishedcompressionevent compressedsize compressedsize origsize originalsize override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put single codec integer to string codec fs put single original size long to string orig size fs put single compressed size long to string compressed size if global fs put single global true return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring putsingle originalsize tostring origsize putsingle compressedsize tostring compressedsize putsingle override public string get name return finished compression getname finishedcompression override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message finished compression goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message finishedcompression override public void remove from object container container container delete this removefrom objectcontainer public finished compression event int codec long orig size long compressed size this codec codec this original size orig size this compressed size compressed size finishedcompressionevent origsize compressedsize originalsize origsize compressedsize compressedsize public string get description return compressed data codec codec orig size original size compressed size compressed size getdescription origsize originalsize compressedsize compressedsize public int get code return code getcode construct a map colors filter public map colors filter this 0xffffffff 0xff000000 mapcolorsfilter mapcolorsfilter construct a map colors filter param old color the color to replace param new color the color to replace it with public map colors filter int old color int new color can filter index color model true this old color old color this new color new color mapcolorsfilter oldcolor newcolor mapcolorsfilter oldcolor newcolor canfilterindexcolormodel oldcolor oldcolor newcolor newcolor override public int filterrgb int x int y int rgb if rgb old color return new color return rgb oldcolor newcolor public static string get name string os name system get property os name string os ver system get property os version return os name os ver name version getname osname getproperty osver getproperty osname osver public http server server sock null httpserver serversock private int bind port 0 public server socket get server sock return server sock bindport serversocket getserversock serversock public string get bind address if bind addr null return return bind addr to string getbindaddress bindaddr bindaddr tostring public int get bind port return bind port getbindport bindport public boolean open string addr int port if server sock null return true try bind addr inet address get by name addr bind port port server sock new server socket bind port 0 bind addr server sock set so timeout 10 1000 catch io exception e return false return true serversock bindaddr inetaddress getbyname bindport serversock serversocket bindport bindaddr serversock setsotimeout ioexception public boolean close if server sock null return true try server sock close server sock null bind addr null bind port 0 catch exception e debug warning e return false return true serversock serversock serversock bindaddr bindport public socket accept if server sock null return null try socket sock server sock accept sock set so timeout http default port 1000 return sock catch exception e return null serversock serversock setsotimeout default_port public boolean is opened return server sock null true false isopened serversock private listener list http request listener list new listener list public void add request listener http request listener listener http request listener list add listener listenerlist httprequestlistenerlist listenerlist addrequestlistener httprequestlistener httprequestlistenerlist public void remove request listener http request listener listener http request listener list remove listener removerequestlistener httprequestlistener httprequestlistenerlist public void perform request listener http request http req int listener size http request listener list size for int n 0 n listener size n http request listener listener http request listener http request listener list get n listener http request recieved http req performrequestlistener httprequest httpreq listenersize httprequestlistenerlist listenersize httprequestlistener httprequestlistener httprequestlistenerlist httprequestrecieved httpreq public void run if is opened false return thread this thread thread current thread while http server thread this thread thread yield socket sock try debug message accept sock accept if sock null debug message sock sock get remote socket address catch exception e debug warning e break http server thread http serv thread new http server thread this sock http serv thread start debug message http serv thread isopened thisthread currentthread httpserverthread thisthread getremotesocketaddress httpserverthread httpservthread httpserverthread httpservthread httpservthread public boolean start http server thread new thread this u pnp http server http server thread start return true httpserverthread upnp httpserver httpserverthread public boolean stop http server thread null return true httpserverthread construct a partially received bulk param size size of the file does not have to be a multiple of block size param block size block size param raf where to store the data param initial state if true assume all blocks have been received if false assume no blocks have been received public partially received bulk message core usm long size int block size random access thing raf boolean initial state this size size this block size block size this raf raf this usm usm long blocks size block size size block size 0 1 0 if blocks integer max value throw new illegal argument exception too big this blocks int blocks blocks received new bit array this blocks if initial state blocks received set all ones blocks received count this blocks partiallyreceivedbulk blocksize blocksize initialstate partiallyreceivedbulk messagecore blocksize randomaccessthing initialstate blocksize blocksize blocksize blocksize max_value illegalargumentexception blocksreceived bitarray initialstate blocksreceived setallones blocksreceivedcount clone the blocks received bit array used by bulk transmitter to find what blocks are available on creation bulk transmitter will have already taken the lock and will keep it over the add also return a copy of blocks received synchronized bit array clone blocks received return new bit array blocks received blocksreceived bitarray bulktransmitter bulktransmitter blocksreceived bitarray cloneblocksreceived bitarray blocksreceived add a bulk transmitter to the list of bulk transmitters when a block comes in we will tell each bulk transmitter about it param bt the bulk transmitter to register synchronized void add bulk transmitter bt if transmitters null transmitters new bulk transmitter bt else bulk transmitter t new bulk transmitter transmitters length 1 system arraycopy transmitters 0 t 0 transmitters length t transmitters length bt transmitters t bulktransmitter bulktransmitters bulktransmitter bulktransmitter bulktransmitter bulktransmitter bulktransmitter bulktransmitter called when a block has been received will copy the data from the provided buffer and store it param block num the block number param data the byte array from which to read the data param offset the start of the data in the buffer void received int block num byte data int offset int length if block num blocks logger error this received block block num of blocks return if logger should log logger minor this logger minor this received block block num bulk transmitter notifyb ts long file offset long block num long block size int bs int math min block size size file offset if length bs string err data too short should be bs actually length logger error this err for this abort retrieval exception premature eof err return synchronized this if blocks received bit at block num return ignore blocks received set bit block num true assume the rest of the function succeeds blocks received count notifyb ts transmitters try raf pwrite file offset data offset bs catch throwable t logger error this failed to store received block block num on this t t abort retrieval exception io error t to string if notifyb ts null return for int i 0 i notifyb ts length i not a generic callback so no catch guard notifyb ts i block received block num blocknum blocknum blocknum blocknum shouldlog blocknum bulktransmitter notifybts fileoffset blocknum blocksize blocksize fileoffset retrievalexception premature_eof blocksreceived bitat blocknum blocksreceived setbit blocknum blocksreceivedcount notifybts fileoffset blocknum retrievalexception io_error tostring notifybts notifybts notifybts blockreceived blocknum public void abort int err code string why if logger should log logger normal this logger normal this aborting this err code why new exception debug bulk transmitter notifyb ts bulk receiver notifybr synchronized this aborted true abortreason err code abortdescription why notifyb ts transmitters notifybr recv if notifyb ts null for int i 0 i notifyb ts length i notifyb ts i on aborted if notifybr null notifybr on aborted raf close errcode shouldlog errcode bulktransmitter notifybts bulkreceiver _aborted _abortreason errcode _abortdescription notifybts notifybts notifybts notifybts onaborted onaborted public synchronized boolean is aborted return aborted isaborted _aborted public boolean has whole file return blocks received count blocks haswholefile blocksreceivedcount public byte get block data int block num long file offset long block num long block size int bs int math min block size size file offset byte data new byte bs try raf pread file offset data 0 bs catch io exception e logger error this failed to read stored block block num on this e e abort retrieval exception io error e to string return null return data getblockdata blocknum fileoffset blocknum blocksize blocksize fileoffset fileoffset ioexception blocknum retrievalexception io_error tostring public synchronized void remove bulk transmitter remove boolean found false for int i 0 i transmitters length i if transmitters i remove found true if found return bulk transmitter new trans new bulk transmitter transmitters length 1 int j 0 for int i 0 i transmitters length i bulk transmitter t transmitters i if t remove continue new trans j t transmitters new trans bulktransmitter bulktransmitter newtrans bulktransmitter bulktransmitter newtrans newtrans public int get abort reason return abortreason getabortreason _abortreason public string get abort description return abortdescription getabortdescription _abortdescription public subscribeusk message simple field set fs throws message invalid exception this identifier fs get identifier if identifier null throw new message invalid exception protocol error message missing field no identifier null false string suri fs get uri if suri null throw new message invalid exception protocol error message missing field expected a uri on subscribeusk identifier false freeneturi uri try uri new freeneturi suri key usk create uri catch malformedurl exception e throw new message invalid exception protocol error message invalid field could not parse uri e identifier false this dont poll fields string to bool fs get dont poll false prio fs get short priority class request starter bulk splitfile priority class prio progress fs get short priority class progress short math max 0 prio 1 subscribeuskmessage simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field messageinvalidexception protocolerrormessage missing_field malformedurlexception messageinvalidexception protocolerrormessage invalid_field dontpoll stringtobool dontpoll getshort priorityclass requeststarter bulk_splitfile_priority_class prioprogress getshort priorityclassprogress override public simple field set get field set simple field set fs new simple field set true fs put single uri key geturi to string fs put dont poll dont poll return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring dontpoll dontpoll override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception try new subscribeusk this node client core handler catch identifier collision exception e handler output handler queue new identifier collision message identifier false return subscribedusk message reply new subscribedusk message this handler output handler queue reply fcpconnectionhandler messageinvalidexception clientcore identifiercollisionexception outputhandler identifiercollisionmessage subscribeduskmessage subscribeduskmessage outputhandler override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private int operation public math function1d int operation this operation operation mathfunction1d public float evaluate float v switch operation case sin return float math sin v case cos return float math cos v case tan return float math tan v case sqrt return float math sqrt v case asin return float math asin v case acos return float math acos v case atan return float math atan v case sqr return v v return v public string handlehttp get http request request throws pluginhttp exception string uri string type string action boolean automf boolean deep int hex width if request is parameter set key uri request get param key type request get param mftype automf request get param automf length 0 deep request get param deep length 0 hex width request get int param hex width 32 action request get param action else uri null type null automf true deep true hex width 32 action list string errors new linked list string if hex width 1 hex width 1024 errors add hex display columns out of range 1 1024 set to 32 default hex width 32 if splitdownload equals action byte data do download errors uri if errors size 0 throw new download pluginhttp exception data plugindownload defaultmime types default mime type else return make main page errors uri hex width false deep if zi pmanifest equals type return make manifest page errors uri true false hex width automf deep if ta rmanifest equals type return make manifest page errors uri false true hex width automf deep if simplemanifest equals type return make manifest page errors uri false false hex width automf deep return make main page errors uri hex width automf deep handlehttpget httprequest pluginhttpexception hexwidth isparameterset getparam getparam getparam getparam hexwidth getintparam hexwidth getparam hexwidth linkedlist hexwidth hexwidth hexwidth dodownload downloadpluginhttpexception defaultmimetypes default_mime_type makemainpage hexwidth zipmanifest makemanifestpage hexwidth tarmanifest makemanifestpage hexwidth makemanifestpage hexwidth makemainpage hexwidth public string handlehttp post http request request throws pluginhttp exception string uri request get part as string key 1024 int hex width request get int part hex width 32 boolean automf request get part as string automf 128 length 0 boolean deep request get part as string deep 128 length 0 list string errors new linked list string if hex width 1 hex width 1024 errors add hex display columns out of range 1 1024 set to 32 default hex width 32 return make main page errors uri hex width automf deep handlehttppost httprequest pluginhttpexception getpartasstring hexwidth getintpart hexwidth getpartasstring getpartasstring linkedlist hexwidth hexwidth hexwidth makemainpage hexwidth public void handle plugin reply sender replysender simple field set params bucket data int accesstype try real handle replysender params data accesstype catch plugin not found exception pnfe logger error this connction to request sender lost pnfe pluginreplysender simplefieldset realhandle pluginnotfoundexception param accesstype public void real handle plugin reply sender replysender simple field set params bucket data int accesstype throws plugin not found exception if params null send error replysender 0 got void message return if data null send error replysender 0 got a diatribe piece of writing data not allowed return string command params get command if command null command trim length 0 send error replysender 1 invalid command name return if ping equals command simple field set sfs new simple field set true sfs put pong system current time millis replysender send sfs return if get equals command final string identifier params get identifier if identifier null identifier trim length 0 send error replysender 3 missing identifier return final string uri params get uri if uri null uri trim length 0 send error replysender 4 missing freenet uri return try freeneturi furi sanitizeuri null uri get result get result simple get m pr furi simple field set sfs new simple field set true sfs put single identifier identifier sfs put is metadata get result is meta data sfs put single status data found replysender send sfs get result get data return catch malformedurl exception e send error replysender 5 malformed freenet uri e get message return catch low level get exception e send error replysender 6 get failed e to string return if list site manifest equals command final string identifier params get identifier if identifier null identifier trim length 0 send error replysender 3 missing identifier return final string uri params get uri if uri null uri trim length 0 send error replysender 4 missing freenet uri return try freeneturi furi new freeneturi uri get result get result simple get m pr furi simple field set sfs new simple field set true sfs put single identifier identifier sfs put is metadata get result is meta data sfs put single status data found replysender send sfs get result get data return catch malformedurl exception e send error replysender 5 malformed freenet uri e get message return catch low level get exception e send error replysender 6 get failed e to string return send error replysender 1 unknown command command realhandle pluginreplysender simplefieldset pluginnotfoundexception senderror senderror senderror simplefieldset simplefieldset currenttimemillis senderror senderror getresult getresult simpleget m_pr simplefieldset simplefieldset putsingle ismetadata getresult ismetadata putsingle datafound getresult getdata malformedurlexception senderror getmessage lowlevelgetexception senderror tostring listsitemanifest senderror senderror getresult getresult simpleget m_pr simplefieldset simplefieldset putsingle ismetadata getresult ismetadata putsingle datafound getresult getdata malformedurlexception senderror getmessage lowlevelgetexception senderror tostring senderror public void run plugin plugin respirator pr m pr pr m pm pr get page maker runplugin pluginrespirator m_pr m_pm getpagemaker public void terminate private byte do download list string errors string key if errors size 0 return null if key null key trim length 0 errors add are you jokingly empty uri return null try freeneturi furi sanitizeuri errors key get result getresult simple get m pr furi if getresult is meta data return unroll metadata errors metadata construct getresult get data else return bucket tools to byte array getresult get data catch malformedurl exception e errors add e get message e print stack trace catch low level get exception e errors add e get message e print stack trace catch metadata parse exception e errors add e get message e print stack trace catch io exception e errors add e get message e print stack trace catch fetch exception e errors add e get message e print stack trace catch key listener construction exception e errors add e get message e print stack trace return null dodownload getresult simpleget m_pr ismetadata unrollmetadata getdata buckettools tobytearray getdata malformedurlexception getmessage printstacktrace lowlevelgetexception getmessage printstacktrace metadataparseexception getmessage printstacktrace ioexception getmessage printstacktrace fetchexception getmessage printstacktrace keylistenerconstructionexception getmessage printstacktrace private byte unroll metadata list string errors metadata md throws malformedurl exception io exception low level get exception fetch exception metadata parse exception key listener construction exception if md is splitfile errors add unsupported metadata not a splitfile return null byte result null result bucket tools to byte array split get md as bucket return result unrollmetadata malformedurlexception ioexception lowlevelgetexception fetchexception metadataparseexception keylistenerconstructionexception issplitfile buckettools tobytearray splitget asbucket private static get result simple get plugin respirator pr freeneturi uri throws malformedurl exception low level get exception client key ck try ck client key base client key get base key uri catch class cast exception cce throw new malformedurl exception not a supported freenet uri uri very simple getter vsg new very simple getter short 1 uri request client pr gethl simple client very simple get vs new very simple get ck 0 pr gethl simple client get fetch context vsg vs schedule null pr get node client core client context return new get result vs wait for completion vs is metadata getresult simpleget pluginrespirator malformedurlexception lowlevelgetexception clientkey clientkey baseclientkey getbasekey classcastexception malformedurlexception verysimplegetter verysimplegetter requestclient gethlsimpleclient verysimpleget verysimpleget gethlsimpleclient getfetchcontext getnode clientcore clientcontext getresult waitforcompletion ismetadata private fetch result split get metadata metadata throws malformedurl exception low level get exception fetch exception metadata parse exception key listener construction exception final fetch waiter fw new fetch waiter get completion callback cb new get completion callback public void on block set finished client get state state object container container client context context todo auto generated method stub public void on expectedmime string mime object container container client context context todo auto generated method stub public void on expected size long size object container container client context context todo auto generated method stub public void on failure fetch exception e client get state state object container container client context context todo auto generated method stub fw on failure e null container public void on finalized metadata object container container todo auto generated method stub public void on success fetch result result client get state state object container container client context context meta metadata construct result as bucket system out println hehehe yeah fw on success result null container fresult result public void on transition client get state old state client get state new state object container container todo auto generated method stub linked list compressor type decompressors new linked list compressor type fetch context ctx m pr gethl simple client get fetch context boolean delete fetch context false client metadata client metadata null archive context actx null int recursion level 0 bucket return bucket null long token 0 if metadata is compressed compressor type codec metadata get compression codec decompressors add codec very simple getter vsg new very simple getter short 1 null request client m pr gethl simple client split file fetcher sf new split file fetcher metadata cb vsg ctx delete fetch context decompressors client metadata actx recursion level return bucket token null m pr get node client core client context very simple getter vsg new very simple getter short 1 uri request client m pr gethl simple client very simple get vs new very simple get ck 0 m pr gethl simple client get fetch context vsg sf schedule null m pr get node client core client context fw wait for completion return fw wait for completion fetchresult splitget malformedurlexception lowlevelgetexception fetchexception metadataparseexception keylistenerconstructionexception fetchwaiter fetchwaiter getcompletioncallback getcompletioncallback onblocksetfinished clientgetstate objectcontainer clientcontext onexpectedmime objectcontainer clientcontext onexpectedsize objectcontainer clientcontext onfailure fetchexception clientgetstate objectcontainer clientcontext onfailure onfinalizedmetadata objectcontainer onsuccess fetchresult clientgetstate objectcontainer clientcontext asbucket onsuccess ontransition clientgetstate oldstate clientgetstate newstate objectcontainer linkedlist compressor_type linkedlist compressor_type fetchcontext m_pr gethlsimpleclient getfetchcontext deletefetchcontext clientmetadata clientmetadata archivecontext recursionlevel returnbucket iscompressed compressor_type getcompressioncodec verysimplegetter verysimplegetter requestclient m_pr gethlsimpleclient splitfilefetcher splitfilefetcher deletefetchcontext clientmetadata recursionlevel returnbucket m_pr getnode clientcore clientcontext verysimplegetter verysimplegetter requestclient m_pr gethlsimpleclient verysimpleget verysimpleget m_pr gethlsimpleclient getfetchcontext m_pr getnode clientcore clientcontext waitforcompletion waitforcompletion get completion callback cb new get completion callback public void on block set finished client get state state object container container client context context todo auto generated method stub getcompletioncallback getcompletioncallback onblocksetfinished clientgetstate objectcontainer clientcontext public void on expectedmime string mime object container container client context context todo auto generated method stub onexpectedmime objectcontainer clientcontext public void on expected size long size object container container client context context todo auto generated method stub onexpectedsize objectcontainer clientcontext public void on failure fetch exception e client get state state object container container client context context todo auto generated method stub fw on failure e null container onfailure fetchexception clientgetstate objectcontainer clientcontext onfailure public void on finalized metadata object container container todo auto generated method stub onfinalizedmetadata objectcontainer public void on success fetch result result client get state state object container container client context context meta metadata construct result as bucket system out println hehehe yeah fw on success result null container fresult result onsuccess fetchresult clientgetstate objectcontainer clientcontext asbucket onsuccess public void on transition client get state old state client get state new state object container container todo auto generated method stub ontransition clientgetstate oldstate clientgetstate newstate objectcontainer private void send error plugin reply sender replysender int code string description throws plugin not found exception simple field set sfs new simple field set true sfs put overwrite status error sfs put code code sfs put overwrite description description replysender send sfs senderror pluginreplysender pluginnotfoundexception simplefieldset simplefieldset putoverwrite putoverwrite private string make main page list string errors string key int hex width boolean automf boolean deep throws pluginhttp exception html node page node m pm get page node key explorer null html node content node m pm get content node page node byte data null get result getresult null string extra params hexwidth hex width if automf extra params automf checked if deep extra params deep checked freeneturi furi null freeneturi retry uri null try if key null key trim length 0 furi sanitizeuri errors key retry uri furi getresult simple get m pr furi data bucket tools to byte array getresult get data catch malformedurl exception e errors add malformedurl key catch low level get exception e errors add get failed e code e get message catch io exception e errors add io error e get message finally if getresult null getresult free html node uri box create uri box furi null null furi to string false false hex width automf deep errors if errors size 0 content node add child create error box errors retry uri null errors clear content node add child uri box if data null metadata md null if getresult is meta data try md metadata construct data catch metadata parse exception e errors add metadata parse error e get message if md null if automf md is archive manifest if md get archive type archive type tar throw new redirect pluginhttp exception reopen as tar manifest plugins plugins key explorer key explorer mftype ta rmanifest key furi extra params else if md get archive type archive type zip throw new redirect pluginhttp exception reopen as zip manifest plugins plugins key explorer key explorer mftype zi pmanifest key furi extra params else errors add unknown archive type md get archive type name if automf md is simple manifest throw new redirect pluginhttp exception reopen as simple manifest plugins plugins key explorer key explorer mftype simplemanifest key furi extra params string title key furi to string false false if getresult is meta data title title u00a0 meta data html node data box2 m pm get infobox title data box2 add child pre lang en style font family monospace n data box2 add child hex dump data hex width data box2 add child n pre content node add child data box2 if getresult is meta data if md null html node meta box m pm get infobox decomposed metadata meta box add child document type meta box add child br if md is multi level metadata meta box add child document type multi level metadata meta box add child br if md is simple manifest meta box add child document type simple manifest meta box add child u00a0 meta box add child new html node a href plugins plugins key explorer key explorer mftype simplemanifest key furi reopen as manifest meta box add child br if md is splitfile meta box add child document type splitfile meta box add child br if md is simple splitfile meta box add child document type simple splitfile meta box add child br if md is single file redirect meta box add child document type single file redirect meta box add child u00a0 freeneturi uri md get single target if uri null string sfr uri md get single target to string false false meta box add child sfr uri meta box add child u00a0 meta box add child new html node a href key sfr uri open meta box add child u00a0 meta box add child new html node a href plugins plugins key explorer key explorer key sfr uri explore else meta box add child new html node a href key furi reopen normal meta box add child br if md is archive internal redirect meta box add child document type archive internal redirect meta box add child br if md is archive manifest meta box add child document type archive manifest meta box add child u00a0 meta box add child new html node a href plugins plugins key explorer key explorer mftype md get archive type name manifest key furi reopen as manifest meta box add child br if md is compressed meta box add child uncompressed else meta box add child compressed codec md get compression codec name meta box add child br meta box add child decompressed size md uncompressed data length bytes meta box add child br meta box add child data size u00a0 u00a0 md data length meta box add child br if md is resolved meta box add child resolved uri u00a0 u00a0 md get resolveduri meta box add child br content node add child meta box if errors size 0 content node add child create error box errors null null return page node generate makemainpage hexwidth pluginhttpexception htmlnode pagenode m_pm getpagenode keyexplorer htmlnode contentnode m_pm getcontentnode pagenode getresult extraparams hexwidth extraparams extraparams retryuri retryuri simpleget m_pr buckettools tobytearray getdata malformedurlexception lowlevelgetexception getmessage ioexception getmessage htmlnode uribox createuribox tostring hexwidth contentnode addchild createerrorbox retryuri contentnode addchild uribox ismetadata metadataparseexception getmessage isarchivemanifest getarchivetype archive_type redirectpluginhttpexception keyexplorer keyexplorer tarmanifest extraparams getarchivetype archive_type redirectpluginhttpexception keyexplorer keyexplorer zipmanifest extraparams getarchivetype issimplemanifest redirectpluginhttpexception keyexplorer keyexplorer extraparams tostring ismetadata metadata htmlnode databox2 m_pm getinfobox databox2 addchild databox2 addchild hexdump hexwidth databox2 addchild contentnode addchild databox2 ismetadata htmlnode metabox m_pm getinfobox metabox addchild metabox addchild ismultilevelmetadata metabox addchild multilevelmetadata metabox addchild issimplemanifest metabox addchild simplemanifest metabox addchild metabox addchild htmlnode keyexplorer keyexplorer metabox addchild issplitfile metabox addchild metabox addchild issimplesplitfile metabox addchild simplesplitfile metabox addchild issinglefileredirect metabox addchild singlefileredirect metabox addchild getsingletarget sfruri getsingletarget tostring metabox addchild sfruri metabox addchild metabox addchild htmlnode sfruri metabox addchild metabox addchild htmlnode keyexplorer keyexplorer sfruri metabox addchild htmlnode metabox addchild isarchiveinternalredirect metabox addchild archiveinternalredirect metabox addchild isarchivemanifest metabox addchild archivemanifest metabox addchild metabox addchild htmlnode keyexplorer keyexplorer getarchivetype metabox addchild iscompressed metabox addchild metabox addchild getcompressioncodec metabox addchild metabox addchild uncompresseddatalength metabox addchild metabox addchild datalength metabox addchild isresolved metabox addchild getresolveduri metabox addchild contentnode addchild metabox contentnode addchild createerrorbox pagenode private string hex dump byte data int width string builder sb new string builder formatter formatter new formatter sb locale us try for int offset 0 offset data length offset width formatter format 07x offset for int i 0 i width i if i 2 0 formatter out append if i offset data length formatter out append continue formatter format 02x data i offset formatter out append for int i 0 i width i if i offset data length break if data i offset 32 data i offset 127 formatter out append char data i offset else formatter out append formatter out append n catch io exception e impossible formatter flush return sb to string hexdump stringbuilder stringbuilder ioexception tostring private string make manifest page list string errors string key boolean zip boolean tar int hex width boolean automf boolean deep html node page node m pm get page node key explorer null html node content node m pm get content node page node metadata metadata null freeneturi furi null try furi sanitizeuri errors key if zip metadata zip manifest get furi else if tar metadata tar manifest get furi else metadata simple manifest get m pr furi catch malformedurl exception e errors add malformedurl key catch fetch exception e errors add get failed e mode e get message catch io exception e errors add io error e get message catch metadata parse exception e errors add metadata parse exception catch low level get exception e errors add get failed e code e get message if errors size 0 content node add child create error box errors null null content node add child create uri box furi null furi to string false false hex width automf deep errors return page node generate content node add child create uri box furi to string false false hex width automf deep errors string title key furi to string false false u00a0 manifest html node list box m pm get infobox title hash map string metadata docs metadata get documents html node content table content node add child table class column html node content table list box add child table html node table head content table add child thead html node table row table head add child tr html node next table cell table row add child th next table cell add child u00a0 next table cell table row add child th next table cell add child type next table cell table row add child th next table cell add child name next table cell table row add child th next table cell add child size next table cell table row add child th next table cell add child mime next table cell table row add child th next table cell add child target parse metadata content table docs furi to string false false errors if errors size 0 content node add child create error box errors null null content node add child list box return page node generate makemanifestpage hexwidth htmlnode pagenode m_pm getpagenode keyexplorer htmlnode contentnode m_pm getcontentnode pagenode zipmanifestget tarmanifestget simplemanifestget m_pr malformedurlexception fetchexception getmessage ioexception getmessage metadataparseexception metadataparseexception lowlevelgetexception getmessage contentnode addchild createerrorbox contentnode addchild createuribox tostring hexwidth pagenode contentnode addchild createuribox tostring hexwidth tostring htmlnode listbox m_pm getinfobox hashmap getdocuments htmlnode contenttable contentnode addchild htmlnode contenttable listbox addchild htmlnode tablehead contenttable addchild htmlnode tablerow tablehead addchild htmlnode nexttablecell tablerow addchild nexttablecell addchild nexttablecell tablerow addchild nexttablecell addchild nexttablecell tablerow addchild nexttablecell addchild nexttablecell tablerow addchild nexttablecell addchild nexttablecell tablerow addchild nexttablecell addchild nexttablecell tablerow addchild nexttablecell addchild parsemetadata contenttable tostring contentnode addchild createerrorbox contentnode addchild listbox pagenode private void add empty cell html node table row html node table cell table row add child td table cell add child u00a0 addemptycell htmlnode tablerow htmlnode tablecell tablerow addchild tablecell addchild private void parse metadata html node html table hash map string metadata docs string prefix string furi list string errors set string s docs key set iterator string i s iterator while i has next html node html table row html table add child tr add empty cell html table row html node next table cell html table row add child td string name i next metadata md docs get name string fname prefix name if md is archive internal redirect next table cell add child container u00a0 if md is archive manifest next table cell add child archive u00a0 if md is compressed next table cell add child compress u00a0 if md is multi level metadata next table cell add child multilevel u00a0 if md is resolved next table cell add child resolved u00a0 if md is simple manifest next table cell add child simple manifest u00a0 if md is simple splitfile next table cell add child simple splitf u00a0 else if md is splitfile next table cell add child splitf u00a0 if md is single file redirect next table cell add child extern u00a0 next table cell html table row add child td if md is simple splitfile next table cell add child new html node a href key furi fname fname next table cell html table row add child td if md is compressed next table cell add child long to string md uncompressed data length else next table cell add child long to string md data length next table cell html table row add child td next table cell add child md getmime type add empty cell html table row else if md is splitfile next table cell add child new html node a href key furi fname fname add empty cell html table row add empty cell html table row add empty cell html table row else if md is archive internal redirect next table cell add child new html node a href furi fname fname add empty cell html table row next table cell html table row add child td next table cell add child md getmime type add empty cell html table row else if md is single file redirect next table cell add child new html node a href key furi fname fname add empty cell html table row next table cell html table row add child td next table cell add child md getmime type next table cell html table row add child td if md is archive manifest string container target md get single target to string false false next table cell add child new html node a href plugins plugins key explorer key explorer mftype md get archive type name manifest key container target container target metadata sub md if md get archive type archive type tar try sub md tar manifest get md get single target parse metadata html table sub md get documents fname furi errors catch fetch exception e todo auto generated catch block e print stack trace catch metadata parse exception e todo auto generated catch block e print stack trace catch io exception e todo auto generated catch block e print stack trace else next table cell add child new html node a href plugins plugins key explorer key explorer key md get single target to string false false md get single target to string false false multi level stuff freeneturi ml uri md get single target if ml uri get extra 2 0x02 0 control document system out println may ml target ml uri to string false false try metadata sub md simple manifest get m pr ml uri if sub md is multi level metadata system out println is ml target ml uri to string false false sub md get resolveduri if sub md is single file redirect system out println try get ml target ml uri to string false false sub md split manifest get sub md parse metadata html table sub md get documents fname furi errors system out println brrrstlhipf else system out println seems splitfile ml target ml uri to string false false system out println try this sub md get single target else system out println no ml target ml uri to string false false catch malformedurl exception e todo auto generated catch block e print stack trace catch low level get exception e todo auto generated catch block e print stack trace catch metadata parse exception e todo auto generated catch block e print stack trace catch io exception e todo auto generated catch block e print stack trace catch fetch exception e todo auto generated catch block e print stack trace catch key listener construction exception e todo auto generated catch block e print stack trace else system out println no ml target ml uri to string false false else next table cell add child fname next table cell html table row add child td next table cell add child next table cell add child integer to string md get documents size next table cell add child items add empty cell html table row add empty cell html table row parse metadata html table md get documents fname furi errors parsemetadata htmlnode htmltable hashmap keyset hasnext htmlnode htmltablerow htmltable addchild addemptycell htmltablerow htmlnode nexttablecell htmltablerow addchild isarchiveinternalredirect nexttablecell addchild isarchivemanifest nexttablecell addchild iscompressed nexttablecell addchild ismultilevelmetadata nexttablecell addchild isresolved nexttablecell addchild issimplemanifest nexttablecell addchild issimplesplitfile nexttablecell addchild issplitfile nexttablecell addchild issinglefileredirect nexttablecell addchild nexttablecell htmltablerow addchild issimplesplitfile nexttablecell addchild htmlnode nexttablecell htmltablerow addchild iscompressed nexttablecell addchild tostring uncompresseddatalength nexttablecell addchild tostring datalength nexttablecell htmltablerow addchild nexttablecell addchild getmimetype addemptycell htmltablerow issplitfile nexttablecell addchild htmlnode addemptycell htmltablerow addemptycell htmltablerow addemptycell htmltablerow isarchiveinternalredirect nexttablecell addchild htmlnode addemptycell htmltablerow nexttablecell htmltablerow addchild nexttablecell addchild getmimetype addemptycell htmltablerow issinglefileredirect nexttablecell addchild htmlnode addemptycell htmltablerow nexttablecell htmltablerow addchild nexttablecell addchild getmimetype nexttablecell htmltablerow addchild isarchivemanifest containertarget getsingletarget tostring nexttablecell addchild htmlnode keyexplorer keyexplorer getarchivetype containertarget containertarget submd getarchivetype archive_type submd tarmanifestget getsingletarget parsemetadata htmltable submd getdocuments fetchexception printstacktrace metadataparseexception printstacktrace ioexception printstacktrace nexttablecell addchild htmlnode keyexplorer keyexplorer getsingletarget tostring getsingletarget tostring mluri getsingletarget mluri getextra mluri tostring submd simplemanifestget m_pr mluri submd ismultilevelmetadata mluri tostring submd getresolveduri submd issinglefileredirect mluri tostring submd splitmanifestget submd parsemetadata htmltable submd getdocuments mluri tostring submd getsingletarget mluri tostring malformedurlexception printstacktrace lowlevelgetexception printstacktrace metadataparseexception printstacktrace ioexception printstacktrace fetchexception printstacktrace keylistenerconstructionexception printstacktrace mluri tostring nexttablecell addchild nexttablecell htmltablerow addchild nexttablecell addchild nexttablecell addchild tostring getdocuments nexttablecell addchild addemptycell htmltablerow addemptycell htmltablerow parsemetadata htmltable getdocuments private html node create uri box string uri int hex width boolean automf boolean deep list string errors html node browse box m pm get infobox explore a freenet key html node browse content m pm get content node browse box if hex width 1 hex width 1024 errors add hex display columns out of range 1 1024 set to 32 default hex width 32 browse content add child display the top level chunk as hexprint or list the content of a manifest html node browse form m pr add form child browse content plugins plugins key explorer key explorer uri form browse form add child freenetkey to explore u00a0 if uri null browse form add child input new string type name size value new string text key 70 uri else browse form add child input new string type name size new string text key 70 browse form add child u00a0 browse form add child input new string type name value new string submit debug explore browse form add child br if automf browse form add child input new string type name value checked new string checkbox automf ok checked else browse form add child input new string type name value new string checkbox automf ok browse form add child u00a0auto open as manifest if possible u00a0 if deep browse form add child input new string type name value checked new string checkbox deep ok checked else browse form add child input new string type name value new string checkbox deep ok browse form add child u00a0parse manifest recursive include multilevel metadata subcontainers u00a0 u00a0 browse form add child hex display columns u00a0 browse form add child input new string type name size value new string text hex width 3 integer to string hex width return browse box htmlnode createuribox hexwidth htmlnode browsebox m_pm getinfobox htmlnode browsecontent m_pm getcontentnode browsebox hexwidth hexwidth hexwidth browsecontent addchild htmlnode browseform m_pr addformchild browsecontent keyexplorer keyexplorer uriform browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild browseform addchild hexwidth tostring hexwidth browsebox private html node create error box list string errors freeneturi retry uri string extra params html node error box m pm get infobox infobox alert error for string error errors error box add child error error box add child br if retry uri null error box add child retry error box add child new html node a href plugins plugins key explorer key explorer key extra params null retry uri retry uri extra params retry uri to string false false return error box htmlnode createerrorbox retryuri extraparams htmlnode errorbox m_pm getinfobox errorbox addchild errorbox addchild retryuri errorbox addchild errorbox addchild htmlnode keyexplorer keyexplorer extraparams retryuri retryuri extraparams retryuri tostring errorbox public string get version return 0 4 version svn revision getversion svnrevision public static metadata simple manifest get plugin respirator pr freeneturi uri throws metadata parse exception low level get exception io exception get result res simple get pr uri if res is meta data throw new metadata parse exception uri did not point to metadata uri return metadata construct res get data simplemanifestget pluginrespirator metadataparseexception lowlevelgetexception ioexception getresult simpleget ismetadata metadataparseexception getdata private metadata split manifest get metadata metadata throws metadata parse exception low level get exception io exception fetch exception key listener construction exception fetch result res split get metadata return metadata construct res as bucket splitmanifestget metadataparseexception lowlevelgetexception ioexception fetchexception keylistenerconstructionexception fetchresult splitget asbucket private metadata zip manifest get freeneturi uri throws fetch exception metadata parse exception io exception high level simple client hlsc m pr gethl simple client fetch context fctx hlsc get fetch context fctx returnzip manifests true fetch waiter fw new fetch waiter hlsc fetch uri 1 request client hlsc fw fctx fetch result fr fw wait for completion zip input stream zis new zip input stream fr as bucket get input stream zip entry entry byte array output stream bos while true entry zis get next entry if entry null break if entry is directory continue string name entry get name if metadata equals name byte buf new byte 32768 bos new byte array output stream read the element int read bytes while read bytes zis read buf 0 bos write buf 0 read bytes bos close return metadata construct bos to byte array throw new fetch exception 200 impossible no metadata in archive uri zipmanifestget fetchexception metadataparseexception ioexception highlevelsimpleclient m_pr gethlsimpleclient fetchcontext getfetchcontext returnzipmanifests fetchwaiter fetchwaiter requestclient fetchresult waitforcompletion zipinputstream zipinputstream asbucket getinputstream zipentry bytearrayoutputstream getnextentry isdirectory getname bytearrayoutputstream readbytes readbytes readbytes tobytearray fetchexception private metadata tar manifest get freeneturi uri throws fetch exception metadata parse exception io exception high level simple client hlsc m pr gethl simple client fetch context fctx hlsc get fetch context fctx returnzip manifests true fetch waiter fw new fetch waiter hlsc fetch uri 1 request client hlsc fw fctx fetch result fr fw wait for completion tar input stream zis new tar input stream fr as bucket get input stream tar entry entry byte array output stream bos while true entry zis get next entry if entry null break if entry is directory continue string name entry get name if metadata equals name byte buf new byte 32768 bos new byte array output stream read the element int read bytes while read bytes zis read buf 0 bos write buf 0 read bytes bos close return metadata construct bos to byte array throw new fetch exception 200 impossible no metadata in archive uri tarmanifestget fetchexception metadataparseexception ioexception highlevelsimpleclient m_pr gethlsimpleclient fetchcontext getfetchcontext returnzipmanifests fetchwaiter fetchwaiter requestclient fetchresult waitforcompletion tarinputstream tarinputstream asbucket getinputstream tarentry bytearrayoutputstream getnextentry isdirectory getname bytearrayoutputstream readbytes readbytes readbytes tobytearray fetchexception public string get string string key todo auto generated method stub return key getstring public void set language language selected language todo auto generated method stub setlanguage selectedlanguage public long get real version return version version getrealversion private freeneturi sanitizeuri list string errors string key throws malformedurl exception if key null throw new null pointer exception freeneturi tempuri new freeneturi key get rid of metas useles if tempuri has meta strings if errors null tempuri tempuri set meta string null errors add uri did contain meta strings removed it for you else throw new malformedurl exception ur is with meta strings not supported turn usk into ssk if tempuri isusk if errors null tempuri tempuri ssk forusk errors add uri was an usk converted it to ssk for you else throw new malformedurl exception usk not supported use underlying ssk instead return tempuri malformedurlexception nullpointerexception hasmetastrings setmetastring malformedurlexception uris sskforusk malformedurlexception public soap response set root node soap create envelope body node set content type xml content type soapresponse setrootnode createenvelopebodynode setcontenttype content_type public soap response http response http res super http res set root node soap create envelope body node set content type xml content type soapresponse httpresponse httpres httpres setrootnode createenvelopebodynode setcontenttype content_type public soap response soap response soap res super soap res set envelope node soap res get envelope node set content type xml content type soapresponse soapresponse soapres soapres setenvelopenode soapres getenvelopenode setcontenttype content_type private node root node private void set root node node node root node node rootnode setrootnode rootnode private node get root node return root node getrootnode rootnode public void set envelope node node node set root node node setenvelopenode setrootnode public node get envelope node return get root node getenvelopenode getrootnode public node get body node node env node get envelope node if env node null return null return env node get node ends with soap body getbodynode envnode getenvelopenode envnode envnode getnodeendswith public node get method response node string name node body node get body node if body node null return null string method res name name soap response return body node get node ends with method res name getmethodresponsenode bodynode getbodynode bodynode methodresname bodynode getnodeendswith methodresname public node get fault node node body node get body node if body node null return null return body node get node ends with soap fault getfaultnode bodynode getbodynode bodynode bodynode getnodeendswith public node get fault code node node fault node get fault node if fault node null return null return fault node get node ends with soap fault code getfaultcodenode faultnode getfaultnode faultnode faultnode getnodeendswith fault_code public node get fault string node node fault node get fault node if fault node null return null return fault node get node ends with soap fault string getfaultstringnode faultnode getfaultnode faultnode faultnode getnodeendswith fault_string public node get fault actor node node fault node get fault node if fault node null return null return fault node get node ends with soap faultactor getfaultactornode faultnode getfaultnode faultnode faultnode getnodeendswith public node get fault detail node node fault node get fault node if fault node null return null return fault node get node ends with soap detail getfaultdetailnode faultnode getfaultnode faultnode faultnode getnodeendswith public string get fault code node node get fault code node if node null return return node get value getfaultcode getfaultcodenode getvalue public string get fault string node node get fault string node if node null return return node get value getfaultstring getfaultstringnode getvalue public string get fault actor node node get fault actor node if node null return return node get value getfaultactor getfaultactornode getvalue public void set content node node thanks for ralf g r bergs ralf ber gs inma marin lopez inma dif um es string con str con str soap version header con str n con str node to string set content con str setcontent constr constr version_header constr constr tostring setcontent constr public void print system out println to string if has content true return node root elem get root node if root elem null return system out println root elem to string tostring hascontent rootelem getrootnode rootelem rootelem tostring modify persistent request simple field set fs throws message invalid exception this global fields string to bool fs get global false this identifier fs get identifier this client token fs get client token if identifier null throw new message invalid exception protocol error message missing field missing field identifier null global string prio fs get priority class if prio null try priority class short parse short prio if request starter is valid priority class priority class throw new message invalid exception protocol error message invalid field invalid priority class priority class range is request starter minimum priority class to request starter maximum priority class identifier global catch number format exception e throw new message invalid exception protocol error message error parsing number could not parse priority class e get message identifier global else priority class 1 modifypersistentrequest simplefieldset messageinvalidexception stringtobool clienttoken clienttoken messageinvalidexception protocolerrormessage missing_field priorityclass priorityclass parseshort requeststarter isvalidpriorityclass priorityclass messageinvalidexception protocolerrormessage invalid_field priorityclass requeststarter minimum_priority_class requeststarter maximum_priority_class numberformatexception messageinvalidexception protocolerrormessage error_parsing_number priorityclass getmessage priorityclass override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put single global boolean to string global fs put single priority class short to string priority class if client token null fs put single client token client token return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle tostring putsingle priorityclass tostring priorityclass clienttoken putsingle clienttoken clienttoken override public string get name return name getname override public void run final fcp connection handler handler node node throws message invalid exception client request req handler get reboot request global handler identifier if req null node client core client context job runner queue new db job public void run object container container client context context client request req handler get forever request global handler identifier container container activate req 1 if req null logger error this huh the request is null protocol error message msg new protocol error message protocol error message no such identifier false null identifier global handler output handler queue msg return else req modify request client token priority class handler server container container deactivate req 1 native thread norm priority false else req modify request client token priority class node client core getfcp server null fcpconnectionhandler messageinvalidexception clientrequest getrebootrequest clientcore clientcontext jobrunner dbjob objectcontainer clientcontext clientrequest getforeverrequest protocolerrormessage protocolerrormessage protocolerrormessage no_such_identifier outputhandler modifyrequest clienttoken priorityclass nativethread norm_priority modifyrequest clienttoken priorityclass clientcore getfcpserver public void run object container container client context context client request req handler get forever request global handler identifier container container activate req 1 if req null logger error this huh the request is null protocol error message msg new protocol error message protocol error message no such identifier false null identifier global handler output handler queue msg return else req modify request client token priority class handler server container container deactivate req 1 objectcontainer clientcontext clientrequest getforeverrequest protocolerrormessage protocolerrormessage protocolerrormessage no_such_identifier outputhandler modifyrequest clienttoken priorityclass override public void remove from object container container container delete this removefrom objectcontainer public long option sub config conf string option name string default value string int sort order boolean expert boolean force write string short desc string long desc long callback cb boolean is size this conf option name fields parse long default value string sort order expert force write short desc long desc cb is size longoption subconfig optionname defaultvaluestring sortorder forcewrite shortdesc longdesc longcallback issize optionname parselong defaultvaluestring sortorder forcewrite shortdesc longdesc issize public long option sub config conf string option name long default value int sort order boolean expert boolean force write string short desc string long desc long callback cb boolean is size super conf option name cb sort order expert force write short desc long desc option data type number this default value default value this current value default value this is size is size longoption subconfig optionname defaultvalue sortorder forcewrite shortdesc longdesc longcallback issize optionname sortorder forcewrite shortdesc longdesc datatype defaultvalue defaultvalue currentvalue defaultvalue issize issize override protected long parse string string val throws invalid config value exception long x try x fields parse long val catch number format exception e throw new invalid config value exception l10n parse error val val return x parsestring invalidconfigvalueexception parselong numberformatexception invalidconfigvalueexception parseerror private string l10n string key string pattern string value return l10n get string long option key pattern value getstring longoption override protected string to string long val return fields long to string val is size tostring longtostring issize public class full text query visitor public void visit full text query q fulltextqueryvisitor fulltextquery public void visit full text query binary op q visit full text query q fulltextquerybinaryop fulltextquery public void visit full text query unary op q visit full text query q fulltextqueryunaryop fulltextquery public void visit full text query match op q visit full text query q fulltextquerymatchop fulltextquery public testdda response message simple field set sfs throws message invalid exception identifier sfs get testdda request message directory if identifier null throw new message invalid exception protocol error message missing field no directory given null false if identifier length 0 throw new message invalid exception protocol error message missing field the specified directory can t be empty null false read content sfs get read content testddaresponsemessage simplefieldset messageinvalidexception testddarequestmessage messageinvalidexception protocolerrormessage missing_field messageinvalidexception protocolerrormessage missing_field readcontent read_content override public simple field set get field set return null simplefieldset getfieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception dda check job job try job handler popdda check identifier catch illegal argument exception e throw new message invalid exception protocol error message invalid field e get message identifier false if job null throw new message invalid exception protocol error message invalid message the node doesn t know that testdda identifier double check it identifier identifier false else if job read filename null read content null throw new message invalid exception protocol error message missing field you need to send read content back to the node if you specify testdda request message want read in testdda request message name identifier false testdda complete message reply new testdda complete message handler job read content handler output handler queue reply fcpconnectionhandler messageinvalidexception ddacheckjob popddacheck illegalargumentexception messageinvalidexception protocolerrormessage invalid_field getmessage messageinvalidexception protocolerrormessage invalid_message readfilename readcontent messageinvalidexception protocolerrormessage missing_field read_content testddarequestmessage want_read testddarequestmessage testddacompletemessage testddacompletemessage readcontent outputhandler override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private boolean initialized false public posterize filter set num levels 6 posterizefilter setnumlevels set the number of levels in the output image param num levels the number of levels see get num levels public void set num levels int num levels this num levels num levels initialized false numlevels getnumlevels setnumlevels numlevels numlevels numlevels get the number of levels in the output image return the number of levels see set num levels public int get num levels return num levels setnumlevels getnumlevels numlevels initialize the filter protected void initialize levels new int 256 if num levels 1 for int i 0 i 256 i levels i 255 num levels i 256 num levels 1 numlevels numlevels numlevels override public int filterrgb int x int y int rgb if initialized initialized true initialize int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r levels r g levels g b levels b return a r 16 g 8 b override public string to string return colors posterize tostring public class mapped file implements i file private final void check size long size throws io exception if size map size long new size map size integer max value 2 map size 2 integer max value if new size size new size size map size new size map chan map file channel map mode read write 0 position map size mappedfile ifile checksize ioexception mapsize newsize mapsize max_value mapsize max_value newsize newsize mapsize newsize filechannel mapmode read_write mapsize public void write long pos byte buf try check size pos buf length map position int pos map put buf 0 buf length catch io exception x throw new storage error storage error file access error x checksize ioexception storageerror storageerror file_access_error public int read long pos byte buf if pos map size return 0 map position int pos map get buf 0 buf length return buf length mapsize public void sync map force public void close try chan close f close catch io exception x throw new storage error storage error file access error x ioexception storageerror storageerror file_access_error public boolean try lock boolean shared try lck chan try lock 0 long max value shared return lck null catch io exception x return true trylock trylock max_value ioexception public void lock boolean shared try lck chan lock 0 long max value shared catch io exception x throw new storage error storage error lock failed x max_value ioexception storageerror storageerror lock_failed public void unlock try lck release catch io exception x throw new storage error storage error lock failed x ioexception storageerror storageerror lock_failed public long length try return f length catch io exception x return 1 ioexception public mapped file string file path long initial size boolean read only try f new random access file file path read only r rw chan f get channel long size chan size map size read only size initial size size initial size map chan map read only file channel map mode read only file channel map mode read write 0 position map size catch io exception x throw new storage error storage error file access error x mappedfile filepath initialsize readonly randomaccessfile filepath readonly getchannel mapsize readonly initialsize initialsize readonly filechannel mapmode read_only filechannel mapmode read_write mapsize ioexception storageerror storageerror file_access_error public all data message bucket bucket string identifier boolean global long startup time long completion time string mime type this bucket bucket this data length bucket size this identifier identifier this global global this startup time startup time this completion time completion time this mime type mime type alldatamessage startuptime completiontime mimetype datalength startuptime startuptime completiontime completiontime mimetype mimetype override long data length return data length datalength datalength override public simple field set get field set simple field set fs new simple field set true fs put data length data length fs put single identifier identifier if global fs put single global true fs put startup time startup time fs put completion time completion time if mime type null fs put single metadata content type mime type return fs simplefieldset getfieldset simplefieldset simplefieldset datalength datalength putsingle putsingle startuptime startuptime completiontime completiontime mimetype putsingle contenttype mimetype override public string get name return all data getname alldata override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message all data goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message alldata override string get identifier return identifier getidentifier override boolean is global return global isglobal override public void remove from object container container container delete this removefrom objectcontainer final boolean remove with producer public event logger int prio boolean remove with producer log prio prio this remove with producer remove with producer removewithproducer eventlogger removewithproducer logprio removewithproducer removewithproducer logs an event param ce the event that occured public void receive client event ce object container container client context context logger log static ce ce get description log prio clientevent objectcontainer clientcontext logstatic getdescription logprio public void on remove event producer object container container if remove with producer container delete this onremoveeventproducer objectcontainer removewithproducer public void run plugin plugin respirator mypr logger debug this plugin starting up m plugin respirator mypr logger debug this opening database db open database database filename logger debug this database opened m config config load or create this db if m config get int config database format version freetalk database format version throw new runtime exception the wot plugin s database format is newer than the wot plugin which is being used upgrade database delete broken objects fixme debug code remove when not needed anymore logger debug this wiping database object set object result db query by example new object for object o result db delete o db commit logger debug this database wiped logger debug this creating identity manager m identity manager new wot identity manager db this logger debug this creating message manager m message manager new wot message manager db m plugin respirator get node executor m identity manager logger debug this creating message fetcher m message fetcher new wot message fetcher m plugin respirator get node m plugin respirator gethl simple client ft message fetcher m identity manager m message manager logger debug this creating message inserter m message inserter new wot message inserter m plugin respirator get node m plugin respirator gethl simple client ft message inserter m identity manager m message manager logger debug this creating message list fetcher m message list fetcher new wot message list fetcher m plugin respirator get node m plugin respirator gethl simple client ft message list fetcher m identity manager m message manager logger debug this creating message list inserter m message list inserter new wot message list inserter m plugin respirator get node m plugin respirator gethl simple client ft message list inserter m identity manager m message manager logger debug this creating web interface m web interface new web interface no wot this logger debug this creating fcp interface mfcp interface new fcp interface this fixme fix this https bugs freenetproject org view php id 2977 logger debug this starting nntp server mnntp server new freetalknntp server m plugin respirator get node this 1199 127 0 0 1 127 0 0 1 mnntp server new freetalknntp server m plugin respirator get node this 1199 0 0 0 0 logger debug this plugin loaded runplugin pluginrespirator mpluginrespirator opendatabase database_filename mconfig loadorcreate mconfig getint database_format_version database_format_version runtimeexception upgradedatabase deletebrokenobjects objectset querybyexample midentitymanager wotidentitymanager mmessagemanager wotmessagemanager mpluginrespirator getnode midentitymanager mmessagefetcher wotmessagefetcher mpluginrespirator getnode mpluginrespirator gethlsimpleclient midentitymanager mmessagemanager mmessageinserter wotmessageinserter mpluginrespirator getnode mpluginrespirator gethlsimpleclient midentitymanager mmessagemanager mmessagelistfetcher wotmessagelistfetcher mpluginrespirator getnode mpluginrespirator gethlsimpleclient messagelist midentitymanager mmessagemanager mmessagelistinserter wotmessagelistinserter mpluginrespirator getnode mpluginrespirator gethlsimpleclient messagelist midentitymanager mmessagemanager mwebinterface webinterfacenowot mfcpinterface fcpinterface mnntpserver freetalknntpserver mpluginrespirator getnode mnntpserver freetalknntpserver mpluginrespirator getnode private ext object container open database string filename configuration db cfg db4o new configuration db cfg reflect with new jdk reflector m class loader db cfg exceptions on not storable true db cfg activation depth 5 fixme figure out a reasonable value for string f message get indexed fields db cfg object class message class object field f indexed true db cfg object class message list message fetch failed reference class persist static field values make it store enums for string f board get indexed fields db cfg object class board class object field f indexed true for string f board get board message link indexed fields db cfg object class board board message link class object field f indexed true for string f wot identity get indexed fields db cfg object class wot identity class object field f indexed true for string f wot own identity get indexed fields db cfg object class wot own identity class object field f indexed true return db4o open file db cfg filename ext extobjectcontainer opendatabase dbcfg newconfiguration dbcfg reflectwith jdkreflector mclassloader dbcfg exceptionsonnotstorable dbcfg activationdepth getindexedfields dbcfg objectclass objectfield dbcfg objectclass messagelist messagefetchfailedreference persiststaticfieldvalues getindexedfields dbcfg objectclass objectfield getboardmessagelinkindexedfields dbcfg objectclass boardmessagelink objectfield wotidentity getindexedfields dbcfg objectclass wotidentity objectfield wotownidentity getindexedfields dbcfg objectclass wotownidentity objectfield openfile dbcfg private void upgrade database int old version m config get int config database format version if old version freetalk database format version return throw new runtime exception your database is too outdated to be upgraded automatically please create a new one by deleting database filename contact the developers if you really need your old data upgradedatabase oldversion mconfig getint database_format_version oldversion database_format_version runtimeexception database_filename debug function suppress warnings unchecked private void delete broken objects query q db query q constrain message class q descend m author constrain null identity object set message broken messages q execute for message m broken messages logger error m deleting message with m author null m geturi db delete m db commit suppresswarnings deletebrokenobjects mauthor objectset brokenmessages brokenmessages mauthor private void close database synchronized db lock try db rollback db close db null catch runtime exception e logger error this error while closing database e closedatabase runtimeexception public synchronized void handle wot connected logger debug this connected to wot plugin m web interface new web interface this handlewotconnected mwebinterface webinterface public synchronized void handle wot disconnected logger debug this disconnected from wot plugin if m web interface instanceof web interface no wot m web interface new web interface no wot this handlewotdisconnected mwebinterface webinterfacenowot mwebinterface webinterfacenowot public void terminate logger debug this terminating freetalk we use single try catch blocks so that failure of termination of one service does not prevent termination of the others try mnntp server terminate catch exception e logger error this error during termination e try mfcp interface terminate catch exception e logger error this error during termination e web interface is stateless and does not need to be terminated try m message list inserter terminate catch exception e logger error this error during termination e try m message list fetcher terminate catch exception e logger error this error during termination e try m message inserter terminate catch exception e logger error this error during termination e try m message fetcher terminate catch exception e logger error this error during termination e try m message manager terminate catch exception e logger error this error during termination e try m identity manager terminate catch exception e logger error this error during termination e try close database catch exception e logger error this error while closing database e logger debug this freetalk plugin terminated mnntpserver mfcpinterface webinterface mmessagelistinserter mmessagelistfetcher mmessageinserter mmessagefetcher mmessagemanager midentitymanager closedatabase public synchronized string handlehttp get http request request throws pluginhttp exception return m web interface handlehttp get request handlehttpget httprequest pluginhttpexception mwebinterface handlehttpget public synchronized string handlehttp post http request request throws pluginhttp exception return m web interface handlehttp post request handlehttppost httprequest pluginhttpexception mwebinterface handlehttppost public void handle plugin reply sender replysender simple field set params bucket data int accesstype mfcp interface handle replysender params data accesstype pluginreplysender simplefieldset mfcpinterface public plugin respirator get plugin respirator return m plugin respirator pluginrespirator getpluginrespirator mpluginrespirator public identity manager get identity manager return m identity manager identitymanager getidentitymanager midentitymanager public message manager get message manager return m message manager messagemanager getmessagemanager mmessagemanager public string get version return r version svn revision getversion svnrevision public long get real version return version version getrealversion public string get string string key logger error this request translation for key return key getstring called by the node during the loading of the plugin the code class loader code which was used by the node is passed to db4o by freetalk db4o needs to know the code class loader code which was used to create the classes of the objects it is supposed to store public void set class loader class loader my class loader m class loader my class loader classloader classloader setclassloader classloader myclassloader mclassloader myclassloader public void set language language new language m language new language logger debug this set language to m language iso code setlanguage newlanguage mlanguage newlanguage mlanguage isocode public void set theme theme new theme m theme new theme logger error this set theme to m theme code settheme newtheme mtheme newtheme mtheme public class unknowncpu exception extends runtime exception private static final long serial versionuid 1 public unknowncpu exception super unknowncpuexception runtimeexception serialversionuid unknowncpuexception public unknowncpu exception string message super message unknowncpuexception static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog final long trackerid everything is clear to start with packet tracker peer node pn this pn pn node random next long long max value packettracker peernode nextlong max_value packet tracker peer node pn long tid trackerid tid this pn pn ack queue new linked list queued ack forgotten queue new linked list queued forgotten highest seen incoming serial number 1 give some leeway sent packets contents new limited range int byte array map 128 resend request queue new updatable sorted linked list with foreign index queued resend request ack request queue new updatable sorted linked list with foreign index queued ack request packets to resend new hash set integer packet numbers received new received packet numbers 512 is deprecated false next packet number pn node random next int 100 1000 created time system current time millis packettracker peernode ackqueue linkedlist queuedack forgottenqueue linkedlist queuedforgotten highestseenincomingserialnumber sentpacketscontents limitedrangeintbytearraymap resendrequestqueue updatablesortedlinkedlistwithforeignindex queuedresendrequest ackrequestqueue updatablesortedlinkedlistwithforeignindex queuedackrequest packetstoresend hashset packetnumbersreceived receivedpacketnumbers isdeprecated nextpacketnumber nextint createdtime currenttimemillis set the deprecated flag to indicate that we are now no longer the primary key and wake up any threads trying to lock a packet number they can be sent with the new kt after this new packets will not be sent it will not be possible to allocate a new packet number however old resend requests etc may still be sent public void deprecated if logminor logger minor this deprecated this is deprecated true sent packets contents interrupt isdeprecated sentpacketscontents return the highest received incoming serial number public int highest received incoming seq number return this highest seen incoming serial number highestreceivedincomingseqnumber highestseenincomingserialnumber received this packet public boolean already received int seq number return packet numbers received contains seq number alreadyreceived seqnumber packetnumbersreceived seqnumber to string don t leak the key unless asked to override public string to string return super to string for pn short to string tostring tostring tostring shorttostring queue an ack to be sent back to the node soon param seq number the number of the packet to be acked public void queue ack int seq number if logminor logger minor this queueing ack for seq number queued ack qa new queued ack seq number synchronized ack queue ack queue add qa will go urgent in 200ms seqnumber queueack seqnumber seqnumber queuedack queuedack seqnumber ackqueue ackqueue public void queue forgotten int seq number queue forgotten seq number true queueforgotten seqnumber queueforgotten seqnumber public void queue forgotten int seq number boolean log if log is deprecated logminor string msg queueing forgotten for seq number for this if is deprecated logger error this msg else logger minor this msg queued forgotten qf new queued forgotten seq number synchronized forgotten queue forgotten queue add qf queueforgotten seqnumber isdeprecated seqnumber isdeprecated queuedforgotten queuedforgotten seqnumber forgottenqueue forgottenqueue long urgent time override public string to string return super to string packet packet number urgent urgent time system current time millis urgent time urgenttime tostring tostring packetnumber urgenttime currenttimemillis urgenttime queued ack int packet long now system current time millis packet number packet if not included on a packet in next 200ms then force a send of an otherwise empty packet urgent time now 200 queuedack currenttimemillis packetnumber urgenttime queued forgotten int packet long now system current time millis packet number packet urgent time now packet sender max coalescing delay queuedforgotten currenttimemillis packetnumber urgenttime packetsender max_coalescing_delay void sent throws updatable sorted linked list killed exception long now system current time millis active time now 500 urgent time active time urgent delay this is only removed when we actually receive the packet but for now it will sleep updatablesortedlinkedlistkilledexception currenttimemillis activetime urgenttime activetime urgentdelay base queued resend int packet number this packet number packet number long now system current time millis active time initial active time now urgent time active time urgent delay basequeuedresend packetnumber packetnumber packetnumber currenttimemillis activetime initialactivetime urgenttime activetime urgentdelay abstract long urgent delay urgentdelay abstract long urgent delay abstract long initial active time long now urgentdelay initialactivetime private t prev public final t get next return next getnext suppress warnings unchecked public final t set next item i t old next next t i return old suppresswarnings setnext public t get prev return prev getprev suppress warnings unchecked public t set prev item i t old prev prev t i return old suppresswarnings setprev public int compare to t r if urgent time r urgent time return 1 if urgent time r urgent time return 1 if packet number r packet number return 1 if packet number r packet number return 1 return 0 compareto urgenttime urgenttime urgenttime urgenttime packetnumber packetnumber packetnumber packetnumber public object index value return packet number indexvalue packetnumber private doubly linked list super t parent public doubly linked list super t get parent return parent doublylinkedlist doublylinkedlist getparent public doubly linked list super t set parent doubly linked list super t l doubly linked list super t old parent parent l return old doublylinkedlist setparent doublylinkedlist doublylinkedlist private class queued resend request extends base queued resend queued resend request override long initial active time long now return now active immediately reordering is rare queuedresendrequest basequeuedresend queuedresendrequest initialactivetime queued resend request int packet number super packet number queuedresendrequest packetnumber packetnumber override void sent throws updatable sorted linked list killed exception synchronized resend request queue super sent resend request queue update this updatablesortedlinkedlistkilledexception resendrequestqueue resendrequestqueue override long urgent delay return packet sender max coalescing delay urgent pretty soon urgentdelay packetsender max_coalescing_delay override long initial active time long now request an ack after four rt ts active delay twort ts return now active delay initialactivetime rtts activedelay twortts activedelay queued ack request int packet number super packet number this created time system current time millis queuedackrequest packetnumber packetnumber createdtime currenttimemillis override void sent throws updatable sorted linked list killed exception synchronized ack request queue super sent ack request queue update this updatablesortedlinkedlistkilledexception ackrequestqueue ackrequestqueue acknowledged public void on acked long t math max 0 system current time millis created time pn report ping t if logminor logger minor this reported round trip time of time util format time t 2 true on pn get peer avg time util format time long pn average ping time 2 true packet number onacked currenttimemillis createdtime reportping timeutil formattime getpeer timeutil formattime averagepingtime packetnumber override long urgent delay return packet sender max coalescing delay urgentdelay packetsender max_coalescing_delay called when we receive a packet param seq number the packet s serial number see the comments in fnp packet mangler process outgoing for the reason for the locking public synchronized void received packet int seq number time last decoded packet system current time millis if logminor logger minor this received packet seq number from pn short to string if seq number 1 return received packet received packet number seq number ack it even if it is a resend queue ack seq number seqnumber fnppacketmangler processoutgoing receivedpacket seqnumber timelastdecodedpacket currenttimemillis seqnumber shorttostring seqnumber receivedpacketnumber seqnumber queueack seqnumber tcp uses four rt ts with no ack to resend but we have a more drawn out protocol we should use only two public long twort ts fixme upper bound necessary return long math min math max 250 pn average ping time 2 2500 rtts twortts averagepingtime protected void received packet number int seq number if logminor logger minor this handling received packet number seq number queue resend requests seq number packet numbers received got seq number try remove resend request seq number catch updatable sorted linked list killed exception e ignore not our problem synchronized this highest seen incoming serial number math max highest seen incoming serial number seq number if logminor logger minor this handled received packet number seq number receivedpacketnumber seqnumber seqnumber queueresendrequests seqnumber packetnumbersreceived seqnumber removeresendrequest seqnumber updatablesortedlinkedlistkilledexception highestseenincomingserialnumber highestseenincomingserialnumber seqnumber seqnumber remove a resend request from the queue param seq number throws updatable sorted linked list killed exception private void remove resend request int seq number throws updatable sorted linked list killed exception synchronized resend request queue resend request queue remove by key seq number seqnumber updatablesortedlinkedlistkilledexception removeresendrequest seqnumber updatablesortedlinkedlistkilledexception resendrequestqueue resendrequestqueue removebykey seqnumber add some resend requests if necessary param seq number the number of the packet we just received private void queue resend requests int seq number int max synchronized this max packet numbers received highest if seq number max try if max 1 seq number max 1 if logminor logger minor this queueing resends from max to seq number missed some packets out for int i max 1 i seq number i queue resend request i catch updatable sorted linked list killed exception e ignore we are decoding packet not sending one seqnumber queueresendrequests seqnumber packetnumbersreceived seqnumber seqnumber seqnumber seqnumber queueresendrequest updatablesortedlinkedlistkilledexception queue a resend request param packet number the packet serial number to queue a resend request for throws updatable sorted linked list killed exception private void queue resend request int packet number throws updatable sorted linked list killed exception synchronized resend request queue if queued resend request packet number if logminor logger minor this not queueing resend request for packet number already queued return if logminor logger minor this queueing resend request for packet number queued resend request qrr new queued resend request packet number resend request queue add qrr packetnumber updatablesortedlinkedlistkilledexception queueresendrequest packetnumber updatablesortedlinkedlistkilledexception resendrequestqueue queuedresendrequest packetnumber packetnumber packetnumber queuedresendrequest queuedresendrequest packetnumber resendrequestqueue queue an ack request param packet number the packet serial number to queue a resend request for throws updatable sorted linked list killed exception private void queue ack request int packet number throws updatable sorted linked list killed exception synchronized ack request queue fixme should we just remove the existing ack request if we do we get a better estimate of rtt on lossy links if we don t lossy links will include the average time to send a packet including all resends the latter may be useful and in fact the former is unreliable if queued ack request packet number if logminor logger minor this not queueing ack request for packet number already queued return if logminor logger minor this queueing ack request for packet number on this queued ack request qrr new queued ack request packet number ack request queue add qrr packetnumber updatablesortedlinkedlistkilledexception queueackrequest packetnumber updatablesortedlinkedlistkilledexception ackrequestqueue queuedackrequest packetnumber packetnumber packetnumber queuedackrequest queuedackrequest packetnumber ackrequestqueue is an ack request queued for this packet number private boolean queued ack request int packet number synchronized ack request queue return ack request queue contains key packet number queuedackrequest packetnumber ackrequestqueue ackrequestqueue containskey packetnumber is a resend request queued for this packet number private boolean queued resend request int packet number synchronized resend request queue return resend request queue contains key packet number queuedresendrequest packetnumber resendrequestqueue resendrequestqueue containskey packetnumber called when we have received several packet acknowledgements synchronized for the same reason as the sender code is so that we don t end up sending packets too late when overloaded and get horrible problems such as asking to resend packets which haven t been sent yet public synchronized void acknowledged packets int seq nos fixme locking can we just sync on the first part and not the callbacks acknowledged packet only sync s on remove ack request but as mentioned above we need to do a bit more async message callback callbacks new async message callback seq nos length for int i 0 i seq nos length i int real seq no seq nos i if logminor logger minor this acknowledged packet real seq no try remove ack request real seq no catch updatable sorted linked list killed exception e ignore we are processing an incoming packet if logminor logger minor this removed ack request callbacks i sent packets contents get callbacks real seq no byte buf sent packets contents get real seq no long time added sent packets contents get time real seq no if sent packets contents remove real seq no if buf length node packet size packet throttle throttle pn get throttle throttle notify of packet acknowledged throttle set round trip time system current time millis time added int cb count 0 for int i 0 i callbacks length i async message callback cbs callbacks i if cbs null for int j 0 j cbs length j cbs j acknowledged cb count if cb count 0 logminor logger minor this executed cb count callbacks try would block true catch blocked too long exception e ignore will come up again in any case it s rather unlikely acknowledgedpackets seqnos acknowledgedpacket removeackrequest asyncmessagecallback asyncmessagecallback seqnos seqnos realseqno seqnos realseqno removeackrequest realseqno updatablesortedlinkedlistkilledexception sentpacketscontents getcallbacks realseqno sentpacketscontents realseqno timeadded sentpacketscontents gettime realseqno sentpacketscontents realseqno packet_size packetthrottle getthrottle notifyofpacketacknowledged setroundtriptime currenttimemillis timeadded cbcount asyncmessagecallback cbcount cbcount cbcount wouldblock blockedtoolongexception called when we have received a packet acknowledgement param real seq no public void acknowledged packet int real seq no async message callback callbacks if logminor logger minor this acknowledged packet real seq no try synchronized this remove ack request real seq no catch updatable sorted linked list killed exception e ignore we are processing an incoming packet if logminor logger minor this removed ack request callbacks sent packets contents get callbacks real seq no byte buf sent packets contents get real seq no long time added sent packets contents get time real seq no if sent packets contents remove real seq no if buf length node packet size packet throttle throttle pn get throttle throttle notify of packet acknowledged throttle set round trip time system current time millis time added try would block true catch blocked too long exception e ignore will come up again in any case it s rather unlikely if callbacks null for int i 0 i callbacks length i callbacks i acknowledged if logminor logger minor this executed callbacks length callbacks realseqno acknowledgedpacket realseqno asyncmessagecallback realseqno removeackrequest realseqno updatablesortedlinkedlistkilledexception sentpacketscontents getcallbacks realseqno sentpacketscontents realseqno timeadded sentpacketscontents gettime realseqno sentpacketscontents realseqno packet_size packetthrottle getthrottle notifyofpacketacknowledged setroundtriptime currenttimemillis timeadded wouldblock blockedtoolongexception remove an ack request from the queue by packet number throws updatable sorted linked list killed exception private void remove ack request int seq no throws updatable sorted linked list killed exception queued ack request qr null synchronized ack request queue qr ack request queue remove by key seq no if qr null qr on acked else logger normal this removing ack request twice null on seq no from pn get peer time util format time int pn average ping time 2 true ping avg updatablesortedlinkedlistkilledexception removeackrequest seqno updatablesortedlinkedlistkilledexception queuedackrequest ackrequestqueue ackrequestqueue removebykey seqno onacked seqno getpeer timeutil formattime averagepingtime resend off thread but asap a packet param seq number the serial number of the packet to be resent public void resend packet int seq number byte resend data sent packets contents get seq number if resend data null if resend data length node packet size pn get throttle notify of packet lost synchronized packets to resend packets to resend add seq number pn node ps wake up else synchronized this if next packet number seq number logger error this asking me to resend packet seq number which i haven t sent yet next next packet number on this fixme force disconnect when sure this won t be catastrophic return else logger error this asking me to resend packet seq number which has already been acked or we skipped the packet number next next packet number on this will tell other side we have forgotten it can t resend it tell other side we forgot it queue forgotten seq number happens to be true or maybe it didn t exist in the first place seqnumber resendpacket seqnumber resenddata sentpacketscontents seqnumber resenddata resenddata packet_size getthrottle notifyofpacketlost packetstoresend packetstoresend seqnumber wakeup nextpacketnumber seqnumber seqnumber nextpacketnumber forcedisconnect seqnumber nextpacketnumber queueforgotten seqnumber called when we receive an ack request param packet number the packet that the other side wants us to re ack public synchronized void received ack request int packet number if queued ack packet number already going to send an ack don t speed it up though wasteful else if packet numbers received contains packet number we have received it so send them an ack queue ack packet number else we have not received it so get them to resend it try queue resend request packet number catch updatable sorted linked list killed exception e ignore we are decoding not sending highest seen incoming serial number math max highest seen incoming serial number packet number ackrequest packetnumber receivedackrequest packetnumber queuedack packetnumber packetnumbersreceived packetnumber queueack packetnumber queueresendrequest packetnumber updatablesortedlinkedlistkilledexception highestseenincomingserialnumber highestseenincomingserialnumber packetnumber is there a queued ack with the given packet number fixme have a hashtable the others do but probably it isn t necessary we should be consistent about this either take it out of updatable sorted linked list with foreign index or add one here private boolean queued ack int packet number synchronized ack queue for queued ack qa ack queue if qa packet number packet number return true return false updatablesortedlinkedlistwithforeignindex queuedack packetnumber ackqueue queuedack ackqueue packetnumber packetnumber destination forgot a packet this is normal if we are the secondary key param seq number the packet number lost public void dest forgot packet int seq number if is deprecated logger normal this destination forgot packet seq number else logger error this destination forgot packet seq number synchronized this try remove resend request seq number catch updatable sorted linked list killed exception e ignore seqnumber destforgotpacket seqnumber isdeprecated seqnumber seqnumber removeresendrequest seqnumber updatablesortedlinkedlistkilledexception public boolean would block boolean wake ticker throws blocked too long exception long now system current time millis synchronized this if sent packets contents would block next packet number if time would block 1 time would block now else long delta now time would block if delta max would block delta logger error this not been able to allocate a packet to tracker this for time util format time delta 3 true throw new blocked too long exception this delta return true else if time would block 1 long delta now time would block time would block 1 if delta packet sender max coalescing delay logger error this waking packet sender have been blocking for packet ack for time util format time delta 3 true else return false else return false pn node ps wake up return false wouldblock waketicker blockedtoolongexception currenttimemillis sentpacketscontents wouldblock nextpacketnumber timewouldblock timewouldblock timewouldblock max_would_block_delta timeutil formattime blockedtoolongexception timewouldblock timewouldblock timewouldblock packetsender max_coalescing_delay packetsender timeutil formattime wakeup return a packet number for a new outgoing packet this method will not block and will throw an exception if it would need to block throws key changed exception if the thread is interrupted when waiting public int allocate outgoing packet number never block throws key changed exception not connected exception would block exception int packet number if pn is connected throw new not connected exception synchronized this packet number next packet number if is deprecated throw new key changed exception sent packets contents lock never block packet number time would block 1 next packet number packet number 1 if logminor logger minor this allocated packet number in allocate outgoing packet number never block for this return packet number keychangedexception allocateoutgoingpacketnumberneverblock keychangedexception notconnectedexception wouldblockexception packetnumber isconnected notconnectedexception packetnumber nextpacketnumber isdeprecated keychangedexception sentpacketscontents lockneverblock packetnumber timewouldblock nextpacketnumber packetnumber packetnumber allocateoutgoingpacketnumberneverblock packetnumber public int grab forgotten if logminor logger minor this grabbing forgotten packet numbers int acks synchronized forgotten queue grab the acks and tell them they are sent int length forgotten queue size acks new int length int i 0 iterator queued forgotten it forgotten queue iterator while it has next queued forgotten ack it next acks i ack packet number if logminor logger minor this grabbing ack ack packet number from this it remove sent return acks grabforgotten forgottenqueue forgottenqueue queuedforgotten forgottenqueue hasnext queuedforgotten packetnumber packetnumber public void requeue forgot int forgot packets int start int length synchronized forgotten queue it doesn t do anything else does it redflag for int i start i start length i queue forgotten i false requeueforgot forgotpackets forgottenqueue queueforgotten grab all the currently queued acks to be sent to this node return an array of packet numbers that we need to acknowledge public int grab acks if logminor logger minor this grabbing acks int acks synchronized ack queue grab the acks and tell them they are sent int length ack queue size acks new int length int i 0 iterator queued ack it ack queue iterator while it has next queued ack ack it next acks i ack packet number if logminor logger minor this grabbing ack ack packet number from this ack queue clear return acks grabacks ackqueue ackqueue queuedack ackqueue hasnext queuedack packetnumber packetnumber ackqueue grab all the currently queued resend requests return an array of the packet numbers of all the packets we want to be resent throws not connected exception if the peer is no longer connected public int grab resend requests throws not connected exception queued resend request items int packet numbers int real length long now system current time millis try synchronized resend request queue items resend request queue to array new queued resend request resend request queue size int length items length packet numbers new int length real length 0 for int i 0 i length i queued resend request qrr items i if packet numbers received contains qrr packet number if logminor logger minor this have already seen qrr packet number removing from resend list resend request queue remove qrr continue if qrr active time now packet numbers real length qrr packet number if logminor logger minor this grabbing resend request qrr packet number from this qrr sent else if logminor logger minor this rejecting resend request qrr packet number in future by qrr active time now ms for this catch updatable sorted linked list killed exception e throw new not connected exception int trimmed packet numbers new int real length system arraycopy packet numbers 0 trimmed packet numbers 0 real length return trimmed packet numbers notconnectedexception grabresendrequests notconnectedexception queuedresendrequest packetnumbers reallength currenttimemillis resendrequestqueue resendrequestqueue toarray queuedresendrequest resendrequestqueue packetnumbers reallength queuedresendrequest packetnumbersreceived packetnumber packetnumber resendrequestqueue activetime packetnumbers reallength packetnumber packetnumber packetnumber activetime updatablesortedlinkedlistkilledexception notconnectedexception trimmedpacketnumbers reallength packetnumbers trimmedpacketnumbers reallength trimmedpacketnumbers public int grab ack requests throws not connected exception still not acked exception queued ack request items int packet numbers int real length if logminor logger minor this grabbing ack requests try synchronized ack request queue long now system current time millis items ack request queue to array new queued ack request ack request queue size int length items length packet numbers new int length real length 0 for int i 0 i length i queued ack request qr items i int packet number qr packet number if qr active time now if sent packets contents get packet number null if logminor logger minor this asking to ack packet which has already been acked packet number on this grab ack requests ack request queue remove qr continue if now qr created time 2 60 1000 if logminor logger minor this packet qr packet number sent over now qr created time ms ago and still not acked on this for pn if now qr created time 10 60 1000 logger error this packet qr packet number sent over now qr created time ms ago and still not acked on this for pn throw new still not acked exception this packet numbers real length packet number if logminor logger minor this grabbing ack request packet number real length from this qr sent else if logminor logger minor this ignoring ack request packet number real length will become active in qr active time now ms on this qr catch updatable sorted linked list killed exception e throw new not connected exception if logminor logger minor this real length now real length int trimmed packet numbers new int real length system arraycopy packet numbers 0 trimmed packet numbers 0 real length if logminor logger minor this returning trimmed packet numbers length ack requests return trimmed packet numbers grabackrequests notconnectedexception stillnotackedexception queuedackrequest packetnumbers reallength ackrequestqueue currenttimemillis ackrequestqueue toarray queuedackrequest ackrequestqueue packetnumbers reallength queuedackrequest packetnumber packetnumber activetime sentpacketscontents packetnumber packetnumber grabackrequests ackrequestqueue createdtime packetnumber createdtime createdtime packetnumber createdtime stillnotackedexception packetnumbers reallength packetnumber packetnumber reallength packetnumber reallength activetime updatablesortedlinkedlistkilledexception notconnectedexception reallength reallength trimmedpacketnumbers reallength packetnumbers trimmedpacketnumbers reallength trimmedpacketnumbers ackrequests trimmedpacketnumbers return the time at which we will have to send some notifications or long max value if there are none to send public long get next urgent time long earliest time long max value synchronized ack queue if ack queue is empty queued ack qa ack queue get 0 earliest time qa urgent time packet action item qr null synchronized resend request queue if resend request queue is empty qr resend request queue get lowest if qr null earliest time math min earliest time qr urgent time synchronized ack request queue if ack request queue is empty qr ack request queue get lowest if qr null earliest time math min earliest time qr urgent time return earliest time max_value getnexturgenttime earliesttime max_value ackqueue ackqueue isempty queuedack ackqueue earliesttime urgenttime packetactionitem resendrequestqueue resendrequestqueue isempty resendrequestqueue getlowest earliesttime earliesttime urgenttime ackrequestqueue ackrequestqueue isempty ackrequestqueue getlowest earliesttime earliesttime urgenttime earliesttime return the last sent new packet number public int get last outgoing seq number synchronized this return next packet number 1 getlastoutgoingseqnumber nextpacketnumber report a packet has been sent param data the data we have just sent payload only decrypted param seq number the packet number throws not connected exception public void sent packet byte data int seq number async message callback callbacks short priority throws not connected exception if callbacks null for int i 0 i callbacks length i if callbacks i null throw new null pointer exception if sent packets contents add seq number data callbacks priority throw new illegal state exception cannot add data for packet seq number try queue ack request seq number catch updatable sorted linked list killed exception e throw new not connected exception seqnumber notconnectedexception sentpacket seqnumber asyncmessagecallback notconnectedexception nullpointerexception sentpacketscontents seqnumber illegalstateexception seqnumber queueackrequest seqnumber updatablesortedlinkedlistkilledexception notconnectedexception clear the session key deprecate it clear all resend ack request ack etc queues return the messages we still had in flight the caller will then either add them to another session key or call their callbacks to indicate failure private limited range int byte array map element clear if logminor logger minor this clearing this is deprecated true limited range int byte array map element elements synchronized sent packets contents elements sent packets contents grab all will clear synchronized ack queue ack queue clear synchronized resend request queue resend request queue kill synchronized ack request queue ack request queue kill synchronized packets to resend packets to resend clear packet numbers received clear return elements sessionkey sessionkey limitedrangeintbytearraymapelement isdeprecated limitedrangeintbytearraymapelement sentpacketscontents sentpacketscontents graball ackqueue ackqueue resendrequestqueue resendrequestqueue ackrequestqueue ackrequestqueue packetstoresend packetstoresend packetnumbersreceived completely deprecate the session key in favour of a new one it will no longer be used for anything the session key will be cleared and all outstanding packets moved to the new session key must only be called if the session key is not to be kept otherwise we may receive some packets twice public void completely deprecated session key new tracker if new tracker packets this logger error this completely deprecated in favour of self new exception debug return if logminor logger minor this completely deprecated this in favour of new tracker limited range int byte array map element elements clear if elements length 0 return nothing more to do message item messages new message item elements length for int i 0 i elements length i limited range int byte array map element element elements i byte buf element data async message callback callbacks element callbacks ignore packet if logminor logger minor this queueing resend of what was once element packet number messages i new message item buf callbacks true pn resend byte counter element priority pn requeue message items messages 0 messages length true pn node ps wake up sessionkey sessionkey sessionkey sessionkey completelydeprecated sessionkey newtracker newtracker newtracker limitedrangeintbytearraymapelement messageitem messageitem limitedrangeintbytearraymapelement asyncmessagecallback packetnumber messageitem resendbytecounter requeuemessageitems wakeup called when the node appears to have been disconnected dump all sent messages public void disconnected clear everything call the callbacks limited range int byte array map element elements clear for int i 0 i elements length i limited range int byte array map element element elements i async message callback callbacks element callbacks if callbacks null for int j 0 j callbacks length j callbacks j disconnected limitedrangeintbytearraymapelement limitedrangeintbytearraymapelement asyncmessagecallback fill rpi temp with resend packet items of packets that need to be resent return an array of integers which contains the packet numbers to be resent the rpi s are put into rpi temp or null if there are no packets to resend not a very nice api but it saves a load of allocations and at least it s documented public int grab resend packets vector resend packet item rpi temp int numbers rpi temp clear long now system current time millis long fourrt ts twort ts int count 0 synchronized packets to resend int len packets to resend size if numbers length len numbers new int len 2 for iterator integer it packets to resend iterator it has next int packet no it next long resent time sent packets contents get readded time packet no if now resent time fourrt ts either never resent or resent at least 4 rt ts ago numbers count packet no it remove packets to resend clear for int i 0 i count i int packet no numbers i byte buf sent packets contents get packet no if buf null if logminor logger minor this contents null for packet no in grab resend packets on this continue acked already async message callback callbacks sent packets contents get callbacks packet no short priority sent packets contents get priority packet no dmt priority bulk data rpi temp add new resend packet item buf packet no this callbacks priority if rpi temp is empty return null return numbers rpitemp resendpacketitems rpitemp grabresendpackets resendpacketitem rpitemp rpitemp currenttimemillis fourrtts twortts packetstoresend packetstoresend packetstoresend hasnext packetno resenttime sentpacketscontents getreaddedtime packetno resenttime fourrtts rtts packetno packetstoresend packetno sentpacketscontents packetno packetno grabresendpackets asyncmessagecallback sentpacketscontents getcallbacks packetno sentpacketscontents getpriority packetno priority_bulk_data rpitemp resendpacketitem packetno rpitemp isempty public boolean has packets to resend synchronized packets to resend return packets to resend is empty haspacketstoresend packetstoresend packetstoresend isempty public boolean is deprecated return this is deprecated isdeprecated isdeprecated public int count ack requests synchronized ack request queue return ack request queue size countackrequests ackrequestqueue ackrequestqueue public int count resend requests synchronized resend request queue return resend request queue size countresendrequests resendrequestqueue resendrequestqueue public int count acks synchronized ack queue return ack queue size countacks ackqueue ackqueue public synchronized long time last decoded packet return time last decoded packet timelastdecodedpacket timelastdecodedpacket public config exception string param name string param value throwable cause super invalid value param value for config parameter param name cause configexception paramname paramvalue paramvalue paramname public config exception string param name string param value string message super invalid value param value for config parameter param name message configexception paramname paramvalue paramvalue paramname create a rijndael instance param keysize the key size param blocksize the block size throws unsupported cipher exception public rijndael int keysize int blocksize throws unsupported cipher exception if keysize 128 keysize 192 keysize 256 throw new unsupported cipher exception invalid keysize if blocksize 128 blocksize 192 blocksize 256 throw new unsupported cipher exception invalid blocksize this keysize keysize this blocksize blocksize unsupportedcipherexception unsupportedcipherexception unsupportedcipherexception unsupportedcipherexception for util get cipher by name and yes screw you too java public rijndael this keysize 128 this blocksize 128 getcipherbyname public final int get block size return blocksize getblocksize public final int get key size return keysize getkeysize public final void initialize byte key try byte nkey new byte keysize 3 system arraycopy key 0 nkey 0 nkey length session key rijndael algorithm make key nkey blocksize 8 catch invalid key exception e e print stack trace logger error this invalid key sessionkey rijndael_algorithm makekey invalidkeyexception printstacktrace public synchronized final void encipher byte block byte result if block length blocksize 8 throw new illegal argument exception rijndael algorithm block encrypt block result 0 session key blocksize 8 illegalargumentexception rijndael_algorithm blockencrypt sessionkey return size of temporary int a t if these are passed in this can speed things up by avoiding unnecessary allocations between rounds only consumer is rijndaelpcfb mode public synchronized final int get temp array size return blocksize 8 4 rijndaelpcfbmode gettemparraysize only consumer is rijndaelpcfb mode public synchronized final void encipher byte block byte result int a int t if block length blocksize 8 throw new illegal argument exception if a length t length t length blocksize 8 4 throw new illegal argument exception rijndael algorithm block encrypt block result 0 session key blocksize 8 a t rijndaelpcfbmode illegalargumentexception illegalargumentexception rijndael_algorithm blockencrypt sessionkey public synchronized final void decipher byte block byte result if block length blocksize 8 throw new illegal argument exception rijndael algorithm block decrypt block result 0 session key blocksize 8 illegalargumentexception rijndael_algorithm blockdecrypt sessionkey private final map t q item t hash new hash map t q item t public lru queue qitem hashmap qitem lruqueue push ing an object that is already in the queue moves that object to the most recently used position but doesn t add a duplicate entry in the queue public final synchronized void push t obj if obj null throw new null pointer exception q item t insert hash get obj if insert null insert new q item t obj hash put obj insert else list remove insert list unshift insert nullpointerexception qitem qitem push to bottom least recently used position public synchronized void push least t obj if obj null throw new null pointer exception q item t insert hash get obj if insert null insert new q item t obj hash put obj insert else list remove insert list push insert pushleast nullpointerexception qitem qitem return least recently pushed object public final synchronized t pop if list size 0 return hash remove list pop obj obj else return null public final int size return list size public final synchronized boolean remove object obj if obj null throw new null pointer exception q item t i hash remove obj if i null list remove i return true else return false nullpointerexception qitem check if this queue contains obj param obj object to match return true if this queue contains obj public final synchronized boolean contains object obj return hash contains key obj containskey public enumeration t elements return new item enumeration itemenumeration private enumeration q item t source list reverse elements public boolean has more elements return source has more elements qitem reverseelements hasmoreelements hasmoreelements public t next element return source next element obj nextelement nextelement public t obj public q item t obj this obj obj qitem return the objects in the queue as an array in an arbitrary and meaningless order public synchronized object to array return hash key set to array toarray keyset toarray return the objects in the queue as an array in an arbitrary and meaningless order param array the array to fill in if it is too small a new array of the same type will be allocated public synchronized e e to array e array return hash key set to array array toarray keyset toarray return the objects in the queue as an array the strong least strong recently used object is in tt 0 tt the strong most strong recently used object is in tt array length 1 tt public synchronized object to array ordered object array new object list size int x 0 for enumeration q item t e list reverse elements e has more elements array x e next element obj return array toarrayordered qitem reverseelements hasmoreelements nextelement return the objects in the queue as an array the strong least strong recently used object is in tt 0 tt the strong most strong recently used object is in tt array length 1 tt param array the array to fill in if it is too small a new array of the same type will be allocated public synchronized e e to array ordered e array array to array array int list size list size if array length list size throw new illegal state exception array length array length but list size list size int x 0 for enumeration q item t e list reverse elements e has more elements array x e e next element obj return array toarrayordered toarray listsize listsize illegalstateexception listsize qitem reverseelements hasmoreelements nextelement public synchronized boolean is empty return hash is empty isempty isempty scalable list storage storage int initial size super storage if initial size btree threshold small storage e create link initial size else large storage e create list scalablelist initialsize initialsize btree_threshold createlink initialsize createlist scalable list scalablelist scalable list public e get int i return small null small get i large get i scalablelist public e set int i e obj return small null small set i obj large set i obj public boolean is empty return small null small is empty large is empty isempty isempty isempty public int size return small null small size large size public boolean contains object o if o instanceof i persistent i persistent p i persistent o return small null small contains p large contains p return false ipersistent ipersistent ipersistent public t t to array t a return small null small t to array a large t to array a toarray toarray toarray public object to array return small null small to array large to array toarray toarray toarray return small null small to array large to array public boolean add e o add size o return true toarray toarray public void add int i e o if small null if small size btree threshold large get storage e create list large add all small large add i o modify small null else small add i o else large add i o btree_threshold getstorage createlist addall public e remove int i return small null small remove i large remove i public void clear if large null large clear else small clear public int index of object o return small null small index of o large index of o indexof indexof indexof public int last index of object o return small null small last index of o large last index of o lastindexof lastindexof lastindexof public boolean add all int index collection extends e c boolean modified false iterator extends e e c iterator while e has next add index e next modified true return modified addall hasnext public iterator e iterator return small null small iterator large iterator public list iterator e list iterator return list iterator 0 listiterator listiterator listiterator public list iterator e list iterator int index return small null small list iterator index large list iterator index listiterator listiterator listiterator listiterator public list e sub list int from index int to index return small null small sub list from index to index large sub list from index to index sublist fromindex toindex sublist fromindex toindex sublist fromindex toindex public query request queryrequest public query request http request http req set http req queryrequest httprequest httpreq httpreq private node get var name node node body node get body node if body node null return null if body node has nodes false return null node query state var node body node get node 0 if query state var node null return null if query state var node has nodes false return null return query state var node get node 0 getvarnamenode bodynode getbodynode bodynode bodynode hasnodes querystatevarnode bodynode getnode querystatevarnode querystatevarnode hasnodes querystatevarnode getnode public string get var name node node get var name node if node null return return node get value getvarname getvarnamenode getvalue public void set request state variable state var service service state var get service set request host service set envelope node soap create envelope body node node env node get envelope node node body node get body node node qeury node create content node state var body node add node qeury node set content env node setsoap action control query soapaction setrequest statevariable statevar statevar getservice setrequesthost setenvelopenode createenvelopebodynode envnode getenvelopenode bodynode getbodynode qeurynode createcontentnode statevar bodynode addnode qeurynode setcontent envnode setsoapaction query_soapaction private node create content node state variable state var node query var node new node query var node set name control ns control query state variable query var node set name space control ns control xmlns node var node new node var node set name control ns control var name var node set value state var get name query var node add node var node return query var node createcontentnode statevariable statevar queryvarnode queryvarnode setname query_state_variable queryvarnode setnamespace varnode varnode setname var_name varnode setvalue statevar getname queryvarnode addnode varnode queryvarnode public query response post soap response soap res post message get request host get request port return new query response soap res queryresponse soapresponse soapres postmessage getrequesthost getrequestport queryresponse soapres private static final long serial versionuid 1l public bad format exception string s super s serialversionuid badformatexception datastore checker item sendable get getter long nodedb handle short prio block set blocks this getter getter this nodedb handle nodedb handle this prio prio this blocks blocks datastorecheckeritem sendableget nodedbhandle blockset nodedbhandle nodedbhandle transient int update counter alt btree updatecounter altbtree i persistent old node btree key key key i persistent node this key key this node node ipersistent oldnode btreekey ipersistent static final int btree page size page page size object header sizeof 4 3 abstract object get data btree_page_size pagesize objectheader getdata abstract object get data abstract object get key value int i getdata getkeyvalue abstract object get data abstract object get key value int i abstract key get key int i getdata getkeyvalue getkey abstract object get key value int i abstract key get key int i abstract int compare key key int i getkeyvalue getkey abstract key get key int i abstract int compare key key int i abstract void insert btree key key int i getkey btreekey abstract int compare key key int i abstract void insert btree key key int i abstract btree page clone page btreekey btreepage clonepage abstract btree page clone page void clear key value int i btreepage clonepage clearkeyvalue boolean find key first key key last key int height array list result int l 0 n n items r n int oid height 1 if first key null while l r int i l r 1 if compare first key i first key inclusion l i 1 else r i assert that r l if last key null if height 0 while l n if compare last key l last key inclusion return false result add items get l l 1 return true else do if btree page items get l find first key last key height result return false if l n return true while compare last key l 0 return false if height 0 while l n result add items get l l 1 else do if btree page items get l find first key last key height result return false while l n return true firstkey lastkey arraylist nitems firstkey firstkey firstkey lastkey lastkey lastkey btreepage firstkey lastkey lastkey btreepage firstkey lastkey static void memcpy data btree page dst pg int dst idx btree page src pg int src idx int len system arraycopy src pg get data src idx dst pg get data dst idx len memcpydata btreepage dst_pg dst_idx btreepage src_pg src_idx src_pg getdata src_idx dst_pg getdata dst_idx static void memcpy items btree page dst pg int dst idx btree page src pg int src idx int len system arraycopy src pg items to raw array src idx dst pg items to raw array dst idx len memcpyitems btreepage dst_pg dst_idx btreepage src_pg src_idx src_pg torawarray src_idx dst_pg torawarray dst_idx static void memcpy btree page dst pg int dst idx btree page src pg int src idx int len memcpy data dst pg dst idx src pg src idx len memcpy items dst pg dst idx src pg src idx len btreepage dst_pg dst_idx btreepage src_pg src_idx memcpydata dst_pg dst_idx src_pg src_idx memcpyitems dst_pg dst_idx src_pg src_idx void memset int i int len while len 0 items set object i null setobject int insert btree key ins int height boolean unique boolean overwrite int result int l 0 n n items r n int ahead unique 1 0 while l r int i l r 1 if compare ins key i ahead l i 1 else r i assert that l r insert before e r if height 0 result btree page items get r insert ins height unique overwrite assert that result op not found if result op overflow return result n 1 else if r n compare ins key r 0 if overwrite ins old node items get r modify items set object r ins node return op overwrite else if unique ins old node items get r return op duplicate int max items size modify if n max memcpy this r 1 this r n r insert ins r n items 1 return op done else page is full then divide page btree page b clone page assert that n max int m max 2 if r m memcpy b 0 this 0 r memcpy b r 1 this r m r 1 memcpy this 0 this m 1 max m 1 b insert ins r else memcpy b 0 this 0 m memcpy this 0 this m r m memcpy this r m 1 this r max r insert ins r m memset max m 1 m 1 ins node b ins key b get key m 1 if height 0 n items max m 1 b n items m else b clear key value m 1 n items max m b n items m 1 return op overflow btreekey nitems btreepage op_not_found op_overflow oldnode setobject op_overwrite oldnode op_duplicate nitems op_done btreepage clonepage getkey nitems nitems clearkeyvalue nitems nitems op_overflow int handle page underflow int r btree key rem int height btree page a btree page items get r a modify modify int an a n items if r n items exists greater page btree page b btree page items get r 1 int bn b n items assert that bn an if height 1 memcpy data a an this r 1 an 1 bn 1 if an bn items size reallocation of nodes between pages a and b int i bn an bn 1 b modify memcpy a an b 0 i memcpy b 0 b i bn i memcpy data this r a an i 1 1 if height 1 a clear key value an i 1 b memset bn i i b n items i a n items i return op done else merge page b to a memcpy a an b 0 bn b deallocate memcpy data this r this r 1 n items r 1 memcpy items this r 1 this r 2 n items r 1 items set object n items null a n items bn n items 1 return n items items size 1 op underflow op done else page b is before a btree page b btree page items get r 1 int bn b n items assert that bn an if height 1 an 1 bn 1 if an bn items size reallocation of nodes between pages a and b int i bn an bn 1 b modify memcpy a i a 0 an memcpy a 0 b bn i i if height 1 memcpy data a i 1 this r 1 1 memcpy data this r 1 b bn i 1 1 if height 1 b clear key value bn i 1 b memset bn i i b n items i a n items i return op done else merge page b to a memcpy a bn a 0 an memcpy a 0 b 0 bn if height 1 memcpy data a bn 1 this r 1 1 b deallocate items set object r 1 a items set object n items null a n items bn n items 1 return n items items size 1 op underflow op done handlepageunderflow btreekey btreepage btreepage nitems nitems btreepage btreepage nitems memcpydata memcpydata clearkeyvalue nitems nitems op_done memcpydata nitems memcpyitems nitems setobject nitems nitems nitems nitems op_underflow op_done btreepage btreepage nitems memcpydata memcpydata clearkeyvalue nitems nitems op_done memcpydata setobject setobject nitems nitems nitems nitems op_underflow op_done int remove btree key rem int height int i n n items l 0 r n while l r i l r 1 if compare rem key i 0 l i 1 else r i if height 0 i persistent node rem node while r n if compare rem key r 0 if node null items contains element r node rem old node items get r modify memcpy this r this r 1 n r 1 n items n memset n 1 return n items size 1 op underflow op done else break r 1 return op not found do switch btree page items get r remove rem height case op underflow return handle page underflow r rem height case op done return op done while r n return op not found btreekey nitems ipersistent containselement oldnode nitems op_underflow op_done op_not_found btreepage op_underflow handlepageunderflow op_done op_done op_not_found void purge int height if height 0 int n n items do btree page items get n purge height while n 0 super deallocate nitems btreepage int traverse forward int height i persistent result int pos int i n n items if height 0 for i 0 i n i pos btree page items get i traverse forward height result pos else for i 0 i n i result pos items get i return pos traverseforward ipersistent nitems btreepage traverseforward btree page storage s int n super s items s create link n items set size n btreepage createlink setsize btree page btreepage static final int max items btree page size 4 1 object get data return data max_items btree_page_size getdata object get key value int i return new byte data i getkeyvalue key get key int i return new key data i getkey btree page clone page return new btree page of byte get storage btreepage clonepage btreepageofbyte getstorage int compare key key int i return byte key ival data i void insert btree key key int i items set object i key node data i byte key key ival btreekey setobject btree page of byte storage s super s max items data new byte max items btreepageofbyte max_items max_items btree page of byte btreepageofbyte static class btree page of boolean extends btree page of byte key get key int i return new key data i 0 btreepageofboolean btreepageofbyte getkey object get key value int i return boolean value of data i 0 getkeyvalue valueof btree page clone page return new btree page of boolean get storage btreepage clonepage btreepageofboolean getstorage btree page of boolean btreepageofboolean btree page of boolean btree page of boolean storage s super s btreepageofboolean btreepageofboolean static final int max items btree page size 4 2 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return short value of data i getkeyvalue valueof btree page clone page return new btree page of short get storage btreepage clonepage btreepageofshort getstorage int compare key key int i return short key ival data i void insert btree key key int i items set object i key node data i short key key ival btreekey setobject btree page of short storage s super s max items data new short max items btreepageofshort max_items max_items btree page of short btreepageofshort static final int max items btree page size 4 2 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new character data i getkeyvalue btree page clone page return new btree page of char get storage btreepage clonepage btreepageofchar getstorage int compare key key int i return char key ival data i void insert btree key key int i items set object i key node data i char key key ival btreekey setobject btree page of char storage s super s max items data new char max items btreepageofchar max_items max_items btree page of char btreepageofchar static final int max items btree page size 4 4 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new integer data i getkeyvalue btree page clone page return new btree page of int get storage btreepage clonepage btreepageofint getstorage int compare key key int i return key ival data i void insert btree key key int i items set object i key node data i key key ival btreekey setobject btree page of int storage s super s max items data new int max items btreepageofint max_items max_items btree page of int btreepageofint static final int max items btree page size 4 8 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new long data i getkeyvalue btree page clone page return new btree page of long get storage btreepage clonepage btreepageoflong getstorage int compare key key int i return key lval data i 1 key lval data i 0 1 void insert btree key key int i items set object i key node data i key key lval btreekey setobject btree page of long storage s super s max items data new long max items btreepageoflong max_items max_items btree page of long btreepageoflong static final int max items btree page size 4 4 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new float data i getkeyvalue btree page clone page return new btree page of float get storage btreepage clonepage btreepageoffloat getstorage int compare key key int i return float key dval data i 1 float key dval data i 0 1 void insert btree key key int i items set object i key node data i float key key dval btreekey setobject btree page of float storage s super s max items data new float max items btreepageoffloat max_items max_items btree page of float btreepageoffloat static final int max items btree page size 4 8 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new double data i getkeyvalue btree page clone page return new btree page of double get storage btreepage clonepage btreepageofdouble getstorage int compare key key int i return key dval data i 1 key dval data i 0 1 void insert btree key key int i items set object i key node data i key key dval btreekey setobject btree page of double storage s super s max items data new double max items btreepageofdouble max_items max_items btree page of double btreepageofdouble static final int max items btree page size 4 4 object get data return data to raw array max_items btree_page_size getdata torawarray key get key int i return new key data get raw i getkey getraw object get key value int i return data get i getkeyvalue btree page clone page return new btree page of object get storage btreepage clonepage btreepageofobject getstorage int compare key key int i i persistent obj data get raw i int oid obj null 0 obj get oid return key ival oid ipersistent getraw getoid void insert btree key key int i items set object i key node data set object i i persistent key key oval btreekey setobject setobject ipersistent btree page of object storage s super s max items data s create link max items data set size max items btreepageofobject max_items createlink max_items setsize max_items btree page of object btreepageofobject static final int max items 100 object get data return data max_items getdata key get key int i return new key data i getkey object get key value int i return data i getkeyvalue void clear key value int i data i null clearkeyvalue btree page clone page return new btree page of string get storage btreepage clonepage btreepageofstring getstorage int compare key key int i return string key oval compare to data i compareto void insert btree key key int i items set object i key node data i string key key oval btreekey setobject void memset int i int len while len 0 items set object i null data i null i 1 setobject boolean prefix search string key int height array list result int l 0 n n items r n height 1 while l r int i l r 1 if key starts with data i key compare to data i 0 l i 1 else r i assert that r l if height 0 while l n if key compare to data l 0 return false result add items get l l 1 else do if btree page of string items get l prefix search key height result return false if l n return true while key compare to data l 0 return false return true prefixsearch arraylist nitems startswith compareto compareto btreepageofstring prefixsearch compareto btree page of string storage s super s max items data new string max items btreepageofstring max_items max_items btree page of string btreepageofstring static final int max items 100 object get data return data max_items getdata key get key int i return new key comparable object data i getkey object get key value int i return object data i getkeyvalue void clear key value int i object data i null clearkeyvalue btree page clone page return new btree page of raw get storage btreepage clonepage btreepageofraw getstorage int compare key key int i return comparable key oval compare to object data i compareto void insert btree key key int i items set object i key node object data i key key oval btreekey setobject btree page of raw storage s super s max items data new object max items btreepageofraw max_items max_items btree page of raw btreepageofraw static int check type class c int elem type class descriptor get type code c if elem type class descriptor tp object elem type class descriptor tp raw elem type class descriptor tp enum throw new storage error storage error unsupported index type c return elem type checktype elemtype classdescriptor gettypecode elemtype classdescriptor tpobject elemtype classdescriptor tpraw elemtype classdescriptor tpenum storageerror storageerror unsupported_index_type elemtype alt btree class cls boolean unique this unique unique type check type cls altbtree checktype alt btree int type boolean unique this type type this unique unique altbtree static final int op overwrite 5 public class get key types return new class get key type op_overwrite getkeytypes getkeytype public class get key type return map key type type getkeytype mapkeytype static class map key type int type switch type case class descriptor tp boolean return boolean class case class descriptor tp byte return byte class case class descriptor tp char return char class case class descriptor tp short return short class case class descriptor tp int return int class case class descriptor tp long return long class case class descriptor tp float return float class case class descriptor tp double return double class case class descriptor tp string return string class case class descriptor tp date return date class case class descriptor tp object return i persistent class case class descriptor tp raw return comparable class case class descriptor tp enum return enum class default return null mapkeytype classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpstring classdescriptor tpdate classdescriptor tpobject ipersistent classdescriptor tpraw classdescriptor tpenum key check key key key if key null if key type type throw new storage error storage error incompatible key type if type class descriptor tp object key ival 0 key oval null i persistent obj i persistent key oval get storage make persistent obj key new key obj key inclusion 0 if key oval instanceof char key new key new string char key oval key inclusion 0 return key checkkey storageerror storageerror incompatible_key_type classdescriptor tpobject ipersistent ipersistent getstorage makepersistent public t get key key key check key key if root null array list list new array list root find key key height list if list size 1 throw new storage error storage error key not unique else if list size 0 return null else return t list get 0 return null checkkey arraylist arraylist storageerror storageerror key_not_unique public array list t prefix search list string key if class descriptor tp string type throw new storage error storage error incompatible key type array list t list new array list t if root null btree page of string root prefix search key height list return list arraylist prefixsearchlist classdescriptor tpstring storageerror storageerror incompatible_key_type arraylist arraylist btreepageofstring prefixsearch public i persistent prefix search string key array list t list prefix search list key return i persistent list to array new i persistent list size ipersistent prefixsearch arraylist prefixsearchlist ipersistent toarray ipersistent public array list t get list key from key till array list t list new array list t if root null root find check key from check key till height list return list arraylist getlist arraylist arraylist checkkey checkkey public array list t get list object from object till return get list btree get key from object from btree get key from object till arraylist getlist getlist getkeyfromobject getkeyfromobject public i persistent get key from key till array list t list get list from till return i persistent list to array new i persistent list size ipersistent arraylist getlist ipersistent toarray ipersistent public i persistent get object from object till return get btree get key from object from btree get key from object till ipersistent getkeyfromobject getkeyfromobject public boolean put key key t obj return insert key obj false null public t set key key t obj return insert key obj true final void allocate root page btree key ins storage s get storage btree page new root null switch type case class descriptor tp byte new root new btree page of byte s break case class descriptor tp short new root new btree page of short s break case class descriptor tp char new root new btree page of char s break case class descriptor tp boolean new root new btree page of boolean s break case class descriptor tp int case class descriptor tp enum new root new btree page of int s break case class descriptor tp long case class descriptor tp date new root new btree page of long s break case class descriptor tp float new root new btree page of float s break case class descriptor tp double new root new btree page of double s break case class descriptor tp object new root new btree page of object s break case class descriptor tp string new root new btree page of string s break case class descriptor tp raw new root new btree page of raw s break default assert failed invalid type new root insert ins 0 new root items set object 1 root new root n items 1 root new root allocaterootpage btreekey getstorage btreepage newroot classdescriptor tpbyte newroot btreepageofbyte classdescriptor tpshort newroot btreepageofshort classdescriptor tpchar newroot btreepageofchar classdescriptor tpboolean newroot btreepageofboolean classdescriptor tpint classdescriptor tpenum newroot btreepageofint classdescriptor tplong classdescriptor tpdate newroot btreepageoflong classdescriptor tpfloat newroot btreepageoffloat classdescriptor tpdouble newroot btreepageofdouble classdescriptor tpobject newroot btreepageofobject classdescriptor tpstring newroot btreepageofstring classdescriptor tpraw newroot btreepageofraw newroot newroot setobject newroot nitems newroot final t insert key key t obj boolean overwrite btree key ins new btree key check key key obj if root null allocate root page ins height 1 else int result root insert ins height unique overwrite if result op overflow allocate root page ins height 1 else if result op duplicate result op overwrite return t ins old node update counter 1 n elems 1 modify return null btreekey btreekey checkkey allocaterootpage op_overflow allocaterootpage op_duplicate op_overwrite oldnode updatecounter nelems public void remove key key t obj remove new btree key check key key obj btreekey checkkey void remove btree key rem if remove if exists rem throw new storage error storage error key not found btreekey removeifexists storageerror storageerror key_not_found boolean remove if exists btree key rem if root null return false int result root remove rem height if result op not found return false n elems 1 if result op underflow if root n items 0 btree page new root null if height 1 new root btree page root items get 0 root deallocate root new root height 1 update counter 1 modify return true removeifexists btreekey op_not_found nelems op_underflow nitems btreepage newroot newroot btreepage newroot updatecounter public t remove key key if unique throw new storage error storage error key not unique btree key rk new btree key check key key null remove rk return t rk old node storageerror storageerror key_not_unique btreekey btreekey checkkey oldnode public t get object key return get btree get key from object key getkeyfromobject public array list t get prefix list string prefix return get list new key prefix true new key prefix character max value false arraylist getprefixlist getlist max_value public i persistent get prefix string prefix return get new key prefix true new key prefix character max value false ipersistent getprefix max_value public boolean put object key t obj return put btree get key from object key obj getkeyfromobject public t set object key t obj return set btree get key from object key obj getkeyfromobject public void remove object key t obj remove btree get key from object key obj getkeyfromobject public t remove string key return remove new key key public t remove key object key return remove key btree get key from object key removekey removekey getkeyfromobject public int size return n elems nelems public void clear if root null root purge height root null n elems 0 height 0 update counter 1 modify nelems updatecounter public i persistent to persistent array i persistent arr new i persistent n elems if root null root traverse forward height arr 0 return arr ipersistent topersistentarray ipersistent ipersistent nelems traverseforward public object to array return to persistent array toarray topersistentarray public e e to array e arr if arr length n elems arr e array new instance arr get class get component type n elems if root null root traverse forward height i persistent arr 0 if arr length n elems arr n elems null return arr toarray nelems newinstance getclass getcomponenttype nelems traverseforward ipersistent nelems nelems public void deallocate if root null root purge height super deallocate static class btree entry t implements map entry object t public object get key return pg get key value pos btreeentry getkey getkeyvalue public t get value return t pg items get pos getvalue public t set value t value throw new unsupported operation exception setvalue unsupportedoperationexception public boolean equals object o if o instanceof map entry return false map entry e map entry o return get key null e get key null get key equals e get key get value null e get value null get value equals e get value getkey getkey getkey getkey getvalue getvalue getvalue getvalue public int hash code return get key null 0 get key hash code get value null 0 get value hash code hashcode getkey getkey hashcode getvalue getvalue hashcode public string to string return get key get value tostring getkey getvalue btree entry btree page pg int pos this pg pg this pos pos btreeentry btreepage public iterator t iterator return iterator null null ascent order ascent_order public iterable iterator map entry object t entry iterator return entry iterator null null ascent order iterableiterator entryiterator entryiterator ascent_order class btree selection iterator e extends iterable iterator e implements persistent iterator btree selection iterator key from key till int order this from from this till till this order order reset btreeselectioniterator iterableiterator persistentiterator btreeselectioniterator void reset int i l r sp 0 counter update counter if height 0 return btree page page root int h height page stack new btree page h pos stack new int h if order ascent order if from null while h 0 pos stack sp 0 page stack sp page page btree page page items get 0 sp 1 pos stack sp 0 page stack sp page end page n items sp 1 else while h 0 page stack sp page l 0 r page n items while l r i l r 1 if page compare from i from inclusion l i 1 else r i assert that r l pos stack sp r page btree page page items get r sp 1 page stack sp page l 0 r end page n items while l r i l r 1 if page compare from i from inclusion l i 1 else r i assert that r l if r end sp 1 goto next item page r 1 else pos stack sp r if sp 0 till null page page stack sp 1 if page compare till pos stack sp 1 till inclusion sp 0 else descent order if till null while h 0 page stack sp page pos stack sp page n items page btree page page items get page n items sp 1 page stack sp page pos stack sp page n items 1 else while h 0 page stack sp page l 0 r page n items while l r i l r 1 if page compare till i 1 till inclusion l i 1 else r i assert that r l pos stack sp r page btree page page items get r sp 1 page stack sp page l 0 r page n items while l r i l r 1 if page compare till i 1 till inclusion l i 1 else r i assert that r l if r 0 sp 1 goto next item page r else pos stack sp r 1 if sp 0 from null page page stack sp 1 if page compare from pos stack sp 1 from inclusion sp 0 updatecounter btreepage pagestack btreepage posstack ascent_order posstack pagestack btreepage posstack pagestack nitems pagestack nitems posstack btreepage pagestack nitems gotonextitem posstack pagestack posstack pagestack posstack nitems btreepage nitems pagestack posstack nitems pagestack nitems posstack btreepage pagestack nitems gotonextitem posstack pagestack posstack public boolean has next if counter update counter if storage impl get storage concurrent iterator refresh else throw new concurrent modification exception return sp 0 hasnext updatecounter storageimpl getstorage concurrentiterator concurrentmodificationexception public e next if has next throw new no such element exception int pos pos stack sp 1 btree page pg page stack sp 1 curr pos pos curr page pg e curr e get current pg pos if storage impl get storage concurrent iterator curr key new btree key pg get key pos pg items get raw pos goto next item pg pos return curr hasnext nosuchelementexception posstack btreepage pagestack currpos currpage getcurrent storageimpl getstorage concurrentiterator currkey btreekey getkey getraw gotonextitem public int next oid if has next throw new no such element exception int pos pos stack sp 1 btree page pg page stack sp 1 curr pos pos curr page pg i persistent obj pg items get raw pos int oid obj null 0 obj get oid if storage impl get storage concurrent iterator curr key new btree key pg get key pos pg items get raw pos goto next item pg pos return oid nextoid hasnext nosuchelementexception posstack btreepage pagestack currpos currpage ipersistent getraw getoid storageimpl getstorage concurrentiterator currkey btreekey getkey getraw gotonextitem protected object get current btree page pg int pos return pg items get pos getcurrent btreepage protected final void goto next item btree page pg int pos if order ascent order if pos end while sp 0 pos pos stack sp 1 pg page stack sp 1 if pos pg n items pos stack sp 1 pos do pg btree page pg items get pos end pg n items page stack sp pg pos stack sp pos 0 while sp page stack length break else pos stack sp 1 pos if sp 0 till null pg compare till pos till inclusion sp 0 else descent order if pos 0 while sp 0 pos pos stack sp 1 pg page stack sp 1 if pos 0 pos stack sp 1 pos do pg btree page pg items get pos page stack sp pg pos stack sp pos pg n items while sp page stack length pos stack sp 1 pos break else pos stack sp 1 pos if sp 0 from null pg compare from pos from inclusion sp 0 if storage impl get storage concurrent iterator sp 0 next key pg get key pos next obj pg items get raw pos gotonextitem btreepage ascent_order posstack pagestack nitems posstack btreepage nitems pagestack posstack pagestack posstack posstack pagestack posstack btreepage pagestack posstack nitems pagestack posstack posstack storageimpl getstorage concurrentiterator nextkey getkey nextobj getraw private void refresh if sp 0 if next key null reset else if order ascent order from next key else till next key i persistent next next obj reset while true int pos pos stack sp 1 btree page pg page stack sp 1 if pg items get raw pos equals next goto next item pg pos else break counter update counter nextkey ascent_order nextkey nextkey ipersistent nextobj posstack btreepage pagestack getraw gotonextitem updatecounter public void remove if curr page null throw new no such element exception storage impl db storage impl get storage if db concurrent iterator if counter update counter throw new concurrent modification exception curr key new btree key curr page get key curr pos curr page items get raw curr pos if sp 0 int pos pos stack sp 1 btree page pg page stack sp 1 next key pg get key pos next obj pg items get raw pos alt btree this remove if exists curr key refresh curr page null currpage nosuchelementexception storageimpl storageimpl getstorage concurrentiterator updatecounter concurrentmodificationexception currkey btreekey currpage getkey currpos currpage getraw currpos posstack btreepage pagestack nextkey getkey nextobj getraw altbtree removeifexists currkey currpage class btree selection entry iterator extends btree selection iterator map entry object t btree selection entry iterator key from key till int order super from till order btreeselectionentryiterator btreeselectioniterator btreeselectionentryiterator protected object get current btree page pg int pos return new btree entry pg pos getcurrent btreepage btreeentry btree entry start from iterator int start int order super null null order this start start reset btreeentrystartfromiterator void reset super reset int skip order ascent order start n elems start 1 while skip 0 has next next ascent_order nelems hasnext public iterable iterator t iterator key from key till int order return new btree selection iterator t check key from check key till order iterableiterator btreeselectioniterator checkkey checkkey public iterable iterator t iterator object from object till int order return new btree selection iterator t check key btree get key from object from check key btree get key from object till order iterableiterator btreeselectioniterator checkkey getkeyfromobject checkkey getkeyfromobject public iterable iterator t prefix iterator string prefix return iterator new key prefix new key prefix character max value false ascent order iterableiterator prefixiterator max_value ascent_order public iterable iterator map entry object t entry iterator key from key till int order return new btree selection entry iterator check key from check key till order iterableiterator entryiterator btreeselectionentryiterator checkkey checkkey public iterable iterator map entry object t entry iterator object from object till int order return new btree selection entry iterator check key btree get key from object from check key btree get key from object till order iterableiterator entryiterator btreeselectionentryiterator checkkey getkeyfromobject checkkey getkeyfromobject public t get at int i iterable iterator map entry object t iterator if i 0 i n elems throw new index out of bounds exception position i index size n elems if i n elems 2 iterator entry iterator null null ascent order while i 0 iterator next else iterator entry iterator null null descent order i n elems while i 0 iterator next return iterator next get value getat iterableiterator nelems indexoutofboundsexception nelems nelems entryiterator ascent_order entryiterator descent_order nelems getvalue public iterable iterator map entry object t entry iterator int start int order return new btree entry start from iterator start order iterableiterator entryiterator btreeentrystartfromiterator public boolean is unique return unique isunique specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle public void set sides int sides this sides sides setsides public int get sides return sides getsides public void set fade start float fade start this fade start fade start setfadestart fadestart fadestart fadestart public float get fade start return fade start getfadestart fadestart public void set fade width float fade width this fade width fade width setfadewidth fadewidth fadewidth fadewidth public float get fade width return fade width getfadewidth fadewidth public void set invert boolean invert this invert invert setinvert public boolean get invert return invert getinvert override public void set dimensions int width int height this width width this height height super set dimensions width height setdimensions setdimensions override public int filterrgb int x int y int rgb float nx m00 x m01 y float ny m10 x m11 y if sides 2 nx float math sqrt nx nx ny ny else if sides 3 nx image math mod nx 16 else if sides 4 nx symmetry nx 16 int alpha int image math smooth step fade start fade start fade width nx 255 if invert alpha 255 alpha return alpha 24 rgb 0x00ffffff imagemath imagemath smoothstep fadestart fadestart fadewidth public float symmetry float x float b int d int x b x image math mod x b if d 1 1 return b x return x x image math mod x 2 b if x b return 2 b x return x imagemath imagemath override public string to string return fade tostring plugin info message plugin info wrapper pi string identifier boolean detail this identifier identifier this detailed detail classname pi get plugin class name originuri pi get filename started pi get started is talkable pi isfcp plugin plugininfomessage plugininfowrapper getpluginclassname getfilename getstarted istalkable isfcpplugin override public simple field set get field set simple field set sfs new simple field set true if identifier null is optional on these two only sfs put single identifier identifier sfs put single plugin name classname sfs put is talkable is talkable if detailed sfs put single origin uri originuri sfs put started started sfs put single temp filename tempfilename return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle pluginname istalkable istalkable putsingle originuri putsingle tempfilename override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message name goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container container delete this removefrom objectcontainer set whether to premultiply the alpha channel param premultiply alpha true to premultiply the alpha see get premultiply alpha public void set premultiply alpha boolean premultiply alpha this premultiply alpha premultiply alpha premultiplyalpha getpremultiplyalpha setpremultiplyalpha premultiplyalpha premultiplyalpha premultiplyalpha get whether to premultiply the alpha channel return true to premultiply the alpha see set premultiply alpha public boolean get premultiply alpha return premultiply alpha setpremultiplyalpha getpremultiplyalpha premultiplyalpha public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst new buffered image width height buffered image type int argb int in pixels new int width height int out pixels new int width height getrgb src 0 0 width height in pixels if premultiply alpha image math premultiply in pixels 0 in pixels length for int i 0 i iterations i blur in pixels out pixels width height h radius 1 blur out pixels in pixels height width v radius 2 if premultiply alpha image math unpremultiply in pixels 0 in pixels length setrgb dst 0 0 width height in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight bufferedimage bufferedimage type_int_argb inpixels outpixels inpixels premultiplyalpha imagemath inpixels inpixels inpixels outpixels hradius outpixels inpixels vradius premultiplyalpha imagemath inpixels inpixels inpixels override public buffered image create compatible dest image buffered image src color model dstcm if dstcm null dstcm src get color model return new buffered image dstcm dstcm create compatible writable raster src get width src get height dstcm is alpha premultiplied null bufferedimage createcompatibledestimage bufferedimage colormodel getcolormodel bufferedimage createcompatiblewritableraster getwidth getheight isalphapremultiplied override public rectangle2d get bounds2d buffered image src return new rectangle 0 0 src get width src get height getbounds2d bufferedimage getwidth getheight override public point2d get point2d point2d src pt point2d dst pt if dst pt null dst pt new point2d double dst pt set location src pt getx src pt gety return dst pt getpoint2d srcpt dstpt dstpt dstpt dstpt setlocation srcpt srcpt dstpt override public rendering hints get rendering hints return null renderinghints getrenderinghints public void blur int in int out int width int height int radius int pass int width minus1 width 1 int r new int width int g new int width int b new int width int a new int width int mask new int width int in index 0 for int y 0 y height y int out index y if blur mask null if pass 1 getrgb blur mask 0 y width 1 mask else getrgb blur mask y 0 1 width mask for int x 0 x width x int argb in in index x a x argb 24 0xff r x argb 16 0xff g x argb 8 0xff b x argb 0xff if x 0 a x a x 1 r x r x 1 g x g x 1 b x b x 1 for int x 0 x width x get the blur radius at x y int ra if blur mask null if pass 1 ra int mask x 0xff h radius 255f else ra int mask x 0xff v radius 255f else if pass 1 ra int blur radius at x y width height h radius else ra int blur radius at y x height width v radius int divisor 2 ra 1 int ta 0 tr 0 tg 0 tb 0 int i1 x ra if i1 width minus1 int f i1 width minus1 int l width minus1 ta a l a l 1 f tr r l r l 1 f tg g l g l 1 f tb b l b l 1 f i1 width minus1 int i2 x ra 1 if i2 0 ta a 0 i2 tr r 0 i2 tg g 0 i2 tb b 0 i2 i2 0 ta a i1 a i2 tr r i1 r i2 tg g i1 g i2 tb b i1 b i2 out out index ta divisor 24 tr divisor 16 tg divisor 8 tb divisor out index height in index width widthminus1 inindex outindex blurmask blurmask blurmask inindex blurmask hradius vradius blurradiusat hradius blurradiusat vradius widthminus1 widthminus1 widthminus1 widthminus1 outindex outindex inindex override this to get a different blur radius at eahc point param x the x coordinate param y the y coordinate param width the width of the image param height the height of the image return the blur radius protected float blur radius at int x int y int width int height return float x width blurradiusat set the horizontal size of the blur param h radius the radius of the blur in the horizontal direction min value 0 see geth radius public void seth radius int h radius this h radius h radius hradius gethradius sethradius hradius hradius hradius get the horizontal size of the blur return the radius of the blur in the horizontal direction see seth radius public int geth radius return h radius sethradius gethradius hradius set the vertical size of the blur param v radius the radius of the blur in the vertical direction min value 0 see getv radius public void setv radius int v radius this v radius v radius vradius getvradius setvradius vradius vradius vradius get the vertical size of the blur return the radius of the blur in the vertical direction see setv radius public int getv radius return v radius setvradius getvradius vradius set the radius of the effect param radius the radius min value 0 see get radius public void set radius int radius this h radius this v radius radius getradius setradius hradius vradius get the radius of the effect return the radius see set radius public int get radius return h radius setradius getradius hradius set the number of iterations the blur is performed param iterations the number of iterations min value 0 see get iterations public void set iterations int iterations this iterations iterations getiterations setiterations get the number of iterations the blur is performed return the number of iterations see set iterations public int get iterations return iterations setiterations getiterations set the mask used to give the amount of blur at each point param blur mask the mask see get blur mask public void set blur mask buffered image blur mask this blur mask blur mask blurmask getblurmask setblurmask bufferedimage blurmask blurmask blurmask get the mask used to give the amount of blur at each point return the mask see set blur mask public buffered image get blur mask return blur mask setblurmask bufferedimage getblurmask blurmask override public string to string return blur variable blur tostring create a placeholder item for a file which could not be extracted from the archive param ctx the context object which tracks all the items with this key param key2 the key from which the archive was fetched param name the name of the file which failed to extract param error the error message to be included in the thrown exception when somebody tries to get the data public error archive store item archive store context ctx freeneturi key2 string name string error super new archive key key2 name ctx this error error errorarchivestoreitem archivestorecontext archivekey throws an exception with the given error message because this file could not be extracted from the archive override bucket get data or throw throws archive failure exception throw new archive failure exception error getdataorthrow archivefailureexception archivefailureexception override public long space used return 0 spaceused override bucket get reader bucket throws archive failure exception throw new archive failure exception error getreaderbucket archivefailureexception archivefailureexception get time series elements stored in this block return preallocated array of time series element only code used code items of this array actually contains time series elements but all array items should be not null and conain referen to tick object public manifest element string name string full name bucket data string mime override long size this name name this full name full name this data data this mime override mime override this data size size this targeturi null manifestelement fullname mimeoverride fullname fullname mimeoverride mimeoverride datasize public manifest element string name bucket data string mime override long size this name name this full name name this data data this mime override mime override this data size size this targeturi null manifestelement mimeoverride fullname mimeoverride mimeoverride datasize public manifest element manifest element me string new name this name new name this full name me full name this data me data this mime override me mime override this data size me data size this targeturi me targeturi manifestelement manifestelement newname newname fullname fullname mimeoverride mimeoverride datasize datasize public manifest element string name freeneturi targeturi string mime override this name name this full name name this data null this mime override mime override this data size 1 this targeturi targeturi manifestelement mimeoverride fullname mimeoverride mimeoverride datasize override public int hash code return name hash code hashcode hashcode override public boolean equals object o if this o return true if o instanceof manifest element if manifest element o name equals name return true return false manifestelement manifestelement public void free data object container container boolean persist forever if data null if persist forever container activate data 1 data free if persist forever data remove from container data null if persist forever container delete this freedata objectcontainer persistforever persistforever persistforever removefrom persistforever public string get name return name getname public string get mime type override return mime override getmimetypeoverride mimeoverride public bucket get data return data getdata public long get size return data size getsize datasize public freeneturi get targeturi return targeturi gettargeturi public void remove from object container container container activate data 1 data remove from container container activate targeturi 5 targeturi remove from container container delete this removefrom objectcontainer removefrom removefrom public dir put file simple field set subset string identifier boolean global throws message invalid exception this name subset get name if name null throw new message invalid exception protocol error message missing field missing field name identifier global string content type override subset get metadata content type if content type override null meta new client metadata content type override else meta new client metadata guessmime dirputfile simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field contenttypeoverride contenttype contenttypeoverride clientmetadata contenttypeoverride clientmetadata protected string guessmime guess it just from the name return defaultmime types guessmime type name false fixme defaultmimetypes guessmimetype create a dir put file from a simple field set public static dir put file create simple field set subset string identifier boolean global bucket factory bf throws message invalid exception string type subset get upload from if type null type equals ignore case direct return new direct dir put file subset identifier global bf else if type equals ignore case disk return new disk dir put file subset identifier global else if type equals ignore case redirect return new redirect dir put file subset identifier global else throw new message invalid exception protocol error message invalid field unsupported or unknown upload from type identifier global dirputfile simplefieldset dirputfile simplefieldset bucketfactory messageinvalidexception uploadfrom equalsignorecase directdirputfile equalsignorecase diskdirputfile equalsignorecase redirectdirputfile messageinvalidexception protocolerrormessage invalid_field uploadfrom public string get name return name getname public string getmime type return meta getmime type getmimetype getmimetype public abstract bucket get data getdata public manifest element get element string n name int idx n last index of if idx 1 n n substring idx 1 if logger should log logger minor this logger minor this element name name n return new manifest element n get data getmime type get data size manifestelement getelement lastindexof shouldlog manifestelement getdata getmimetype getdata remove the dir put file from the database this would only be called if we had stored a client put dir message into the database without executing it which never happens maybe we should get rid and throw unsupported operation exception param container dirputfile clientput dirmessage unsupportedoperationexception public void send output stream os throws io exception simple field set sfs get field set sfs set end marker get end string string msg sfs to string os write get name n get bytes utf 8 os write msg get bytes utf 8 if logger should log logger debug this logger debug this outgoing fcp message n get name n sfs to string logger debug this being handled by this outputstream ioexception simplefieldset getfieldset setendmarker getendstring tostring getname getbytes getbytes shouldlog getname tostring string get end string return end message getendstring endmessage public abstract simple field set get field set simplefieldset getfieldset public abstract simple field set get field set public abstract string get name simplefieldset getfieldset getname create a message from a simple field set and the message s name if possible public static fcp message create string name simple field set fs bucket factory bf temp persistent temp bucket factory bf persistent throws message invalid exception if name equals add peer name return new add peer fs if name equals client get message name return new client get message fs if name equals client hello message name return new client hello message fs if name equals client put complex dir message name return new client put complex dir message fs bf temp bf persistent if name equals client put disk dir message name return new client put disk dir message fs if name equals client put message name return new client put message fs if name equals fcp plugin message name return new fcp plugin message fs if name equals generatessk message name return new generatessk message fs if name equals get config name return new get config fs if name equals get node name return new get node fs if name equals get plugin info name return new get plugin info fs if name equals get request status message name return new get request status message fs if name equals list peer message name return new list peer message fs if name equals list peers message name return new list peers message fs if name equals list peer notes message name return new list peer notes message fs if name equals list persistent requests message name return new list persistent requests message fs if name equals modify config name return new modify config fs if name equals modify peer name return new modify peer fs if name equals modify peer note name return new modify peer note fs if name equals modify persistent request name return new modify persistent request fs if name equals remove peer name return new remove peer fs if name equals remove persistent request name name equals remove persistent request alt name return new remove persistent request fs if name equals shutdown message name return new shutdown message if name equals subscribeusk message name return new subscribeusk message fs if name equals unsubscribeusk message name return new unsubscribeusk message fs if name equals testdda request message name return new testdda request message fs if name equals testdda response message name return new testdda response message fs if name equals watch global name return new watch global fs if name equals void return null throw new message invalid exception protocol error message invalid message unknown message name name null false simplefieldset fcpmessage simplefieldset bucketfactory bftemp persistenttempbucketfactory bfpersistent messageinvalidexception addpeer addpeer clientgetmessage clientgetmessage clienthellomessage clienthellomessage clientputcomplexdirmessage clientputcomplexdirmessage bftemp bfpersistent clientputdiskdirmessage clientputdiskdirmessage clientputmessage clientputmessage fcppluginmessage fcppluginmessage generatesskmessage generatesskmessage getconfig getconfig getnode getnode getplugininfo getplugininfo getrequeststatusmessage getrequeststatusmessage listpeermessage listpeermessage listpeersmessage listpeersmessage listpeernotesmessage listpeernotesmessage listpersistentrequestsmessage listpersistentrequestsmessage modifyconfig modifyconfig modifypeer modifypeer modifypeernote modifypeernote modifypersistentrequest modifypersistentrequest removepeer removepeer removepersistentrequest removepersistentrequest alt_name removepersistentrequest shutdownmessage shutdownmessage subscribeuskmessage subscribeuskmessage unsubscribeuskmessage unsubscribeuskmessage testddarequestmessage testddarequestmessage testddaresponsemessage testddaresponsemessage watchglobal watchglobal messageinvalidexception protocolerrormessage invalid_message create a message from a simple field set and the message s name if possible usefull for fcp clients public static fcp message create string name simple field set fs throws message invalid exception return fcp message create name fs null null simplefieldset fcpclients fcpmessage simplefieldset messageinvalidexception fcpmessage do whatever it is that we do with this type of message throws message invalid exception public abstract void run fcp connection handler handler node node throws message invalid exception messageinvalidexception fcpconnectionhandler messageinvalidexception public abstract void run fcp connection handler handler node node throws message invalid exception remove this message and its dependancies internal objects from the database public abstract void remove from object container container fcpconnectionhandler messageinvalidexception removefrom objectcontainer message digest digest override public object clone throws clone not supported exception return new javasha1 message digest digest clone messagedigest clonenotsupportedexception messagedigest protected javasha1 message digest d digest d messagedigest public javasha1 throws exception digest message digest get instance sha1 messagedigest getinstance public void extract int digest int offset throw new unsupported operation exception unsupportedoperationexception public void update byte b digest update b public void update byte data int offset int length digest update data offset length public void update byte data digest update data public byte digest return digest digest public void digest boolean reset byte buffer int offset if reset true throw new unsupported operation exception try digest digest buffer offset digest get digest length catch digest exception e throw new illegal state exception e to string unsupportedoperationexception getdigestlength digestexception illegalstateexception tostring public int digest size return 160 digestsize public simple read only array bucket byte buf int offset int length this buf buf this offset offset this length length simplereadonlyarraybucket public simple read only array bucket byte buf this buf 0 buf length simplereadonlyarraybucket public output stream get output stream throws io exception throw new io exception read only outputstream getoutputstream ioexception ioexception public input stream get input stream throws io exception return new byte array input stream buf offset length inputstream getinputstream ioexception bytearrayinputstream public string get name return simple read only array bucket len length super to string getname simplereadonlyarraybucket tostring public long size return length public boolean is read only return true isreadonly public void set read only already read only setreadonly public void free do nothing public void store to object container container container store this storeto objectcontainer public void remove from object container container container delete this removefrom objectcontainer public bucket create shadow throws io exception if buf length 256 1024 byte new buf new byte length system arraycopy buf offset new buf 0 length return new simple read only array bucket new buf return null createshadow ioexception newbuf newbuf simplereadonlyarraybucket newbuf private boolean logdebug logger should log logger debug this override public final object clone return new simple running average this shouldlog simplerunningaverage clear the sra public synchronized void clear next slot ptr 0 cur len 0 total reports 0 total 0 for int i 0 i refs length i refs i 0 0 nextslotptr curlen totalreports public simple running average int length double init value refs new double length this init value init value total reports 0 simplerunningaverage initvalue initvalue initvalue totalreports public simple running average simple running average a this cur len a cur len this init value a init value this next slot ptr a next slot ptr this refs a refs clone this total a total this total reports a total reports simplerunningaverage simplerunningaverage curlen curlen initvalue initvalue nextslotptr nextslotptr totalreports totalreports public synchronized double current value if cur len 0 return init value return total cur len currentvalue curlen initvalue curlen public synchronized double value if reported double r if cur len refs length return total r cur len 1 else don t increment cur len because it won t be incremented return total r refs next slot ptr cur len valueifreported curlen curlen curlen nextslotptr curlen public synchronized void report double d total reports if logdebug logger debug this report d on this if cur len refs length cur len else total pop value push value d total d totalreports curlen curlen popvalue pushvalue protected synchronized void push value double value refs next slot ptr value next slot ptr if next slot ptr refs length next slot ptr 0 pushvalue nextslotptr nextslotptr nextslotptr nextslotptr protected synchronized double pop value return refs next slot ptr popvalue nextslotptr override public synchronized string to string return super to string cur len cur len ptr next slot ptr total total average total cur len tostring tostring curlen curlen nextslotptr curlen public void report long d report double d public void write data to data output stream out throw new unsupported operation exception writedatato dataoutputstream unsupportedoperationexception public synchronized long count reports return total reports countreports totalreports public synchronized double min report for value double target value if cur len refs length don t need to remove any values before reporting so is slightly simpler total report cur len 1 target value report cur len 1 target value total cur len 1 report target value total cur len 1 cur len 1 report target value cur len 1 total example mean 5 5 5 5 5 x 10 x 10 6 25 35 mean 25 35 6 60 6 10 return target value cur len 1 total else essentially the same but 1 length will be cur len not cur len 1 because is full 2 take off the value that will be taken off first return target value cur len total refs next slot ptr minreportforvalue targetvalue curlen curlen targetvalue curlen targetvalue curlen targetvalue curlen curlen targetvalue curlen targetvalue curlen curlen curlen targetvalue curlen nextslotptr public class line reading input stream extends filter input stream implements line reader public line reading input stream input stream in super in linereadinginputstream filterinputstream linereader linereadinginputstream inputstream read a n or r n terminated line of utf 8 or iso 8859 1 param max length the maximum length of a line if a line is longer than this we throw io exception rather than keeping on reading it forever param buffer size the initial size of the read buffer param utf if true read as utf 8 if false read as iso 8859 1 public string read line int max length int buffer size boolean utf throws io exception if max length 1 return null if max length buffer size buffer size max length 1 buffer too big shrink it add 1 for the optional r if mark supported return read line without marking max length buffer size utf byte buf new byte math max math min 128 max length math min 1024 buffer size int ctr 0 mark max length 2 in case we have both a r and a n while true int x read buf ctr buf length ctr if x 1 if ctr 0 return null return new string buf 0 ctr utf utf 8 iso 8859 1 redflag this is definitely safe with the above charsets it may not be safe with some wierd ones int end ctr x for ctr end ctr if buf ctr n string to return if ctr 0 boolean removecr buf ctr 1 r to return new string buf 0 removecr ctr 1 ctr utf utf 8 iso 8859 1 reset skip ctr 1 return to return if ctr max length throw new too long exception we reached max length max length parsing n hex util bytes to hex buf 0 ctr n new string buf 0 ctr utf utf 8 iso 8859 1 if buf length max length buf length ctr buffer size byte new buf new byte math min buf length 2 max length system arraycopy buf 0 new buf 0 ctr buf new buf maxlength ioexception buffersize readline maxlength buffersize ioexception maxlength maxlength buffersize buffersize maxlength marksupported readlinewithoutmarking maxlength buffersize maxlength buffersize maxlength toreturn toreturn toreturn maxlength toolongexception maxlength maxlength hexutil bytestohex maxlength buffersize newbuf maxlength newbuf newbuf public string read line without marking int max length int buffer size boolean utf throws io exception if max length buffer size buffer size max length 1 buffer too big shrink it add 1 for the optional r byte buf new byte math max math min 128 max length math min 1024 buffer size int ctr 0 while true int x read if x 1 if ctr 0 return null return new string buf 0 ctr utf utf 8 iso 8859 1 redflag this is definitely safe with the above charsets it may not be safe with some wierd ones if x n if ctr 0 return if buf ctr 1 r ctr return new string buf 0 ctr utf utf 8 iso 8859 1 if ctr max length throw new too long exception we reached max length max length parsing n hex util bytes to hex buf 0 ctr n new string buf 0 ctr utf utf 8 iso 8859 1 if ctr buf length byte new buf new byte math min buf length 2 max length system arraycopy buf 0 new buf 0 buf length buf new buf buf ctr byte x readlinewithoutmarking maxlength buffersize ioexception maxlength buffersize buffersize maxlength maxlength buffersize maxlength toolongexception maxlength maxlength hexutil bytestohex newbuf maxlength newbuf newbuf public final class hard light composite extends rgb composite public hard light composite float alpha super alpha hardlightcomposite rgbcomposite hardlightcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob if sr 127 dor 255 2 multiply255 255 sr 255 dir else dor 2 multiply255 sr dir if sg 127 dog 255 2 multiply255 255 sg 255 dig else dog 2 multiply255 sg dig if sb 127 dob 255 2 multiply255 255 sb 255 dib else dob 2 multiply255 sb dib float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac logger register log threshold callback new log threshold callback override public void should update logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public plain manifest putter client callback client callback hash map string object manifest elements short prio class freeneturi target string default name insert context ctx boolean getchk only request client client context boolean early encode super client callback manifest elements prio class target default name ctx getchk only client context early encode plainmanifestputter clientcallback clientcallback hashmap manifestelements prioclass defaultname insertcontext getchkonly requestclient clientcontext earlyencode clientcallback manifestelements prioclass defaultname getchkonly clientcontext earlyencode override protected void make put handlers hash map string object manifest elements hash map string object put handlers by name make put handlers manifest elements put handlers by name makeputhandlers hashmap manifestelements hashmap puthandlersbyname makeputhandlers manifestelements puthandlersbyname private void make put handlers hash map string object manifest elements hash map string object put handlers by name string prefix iterator string it manifest elements key set iterator while it has next string name it next object o manifest elements get name if o instanceof hash map hash map string object sub map new hash map string object put handlers by name put name sub map make put handlers hash map string object o sub map prefix name if logdebug logger debug this sub map for name sub map size elements from hash map o size else manifest element element manifest element o add redirect name element put handlers by name makeputhandlers hashmap manifestelements hashmap puthandlersbyname manifestelements keyset hasnext manifestelements hashmap hashmap submap hashmap puthandlersbyname submap makeputhandlers hashmap submap submap hashmap manifestelement manifestelement addredirect puthandlersbyname static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private packet throttle deprecatedfor public packet throttle peer peer int packet size peer peer packet size packet size packetthrottle _deprecatedfor packetthrottle packetsize _peer packet_size packetsize public synchronized void set round trip time long rtt roundtriptime math max rtt 10 if logminor logger minor this set round trip time to rtt on this setroundtriptime _roundtriptime public synchronized void notify of packet lost droppedpackets totalpackets simulatedwindowsize packet drop decrease multiple slow start false if logminor logger minor this notify of packet lost this packetseqwindowfullchecked packetseq notifyofpacketlost _droppedpackets _totalpackets _simulatedwindowsize packet_drop_decrease_multiple slowstart notifyofpacketlost _packetseqwindowfullchecked _packetseq public synchronized void notify of packet acknowledged totalpackets if we didn t use the whole window shrink the window a bit this is similar but not identical to rfc2861 see freenet dev major weakness in our current link level congestion control int window size int get window size if packetseqwindowfullchecked window size packetseq if packetseqwindowfull packetseqwindowfullchecked we haven t used the full window once since we last checked simulatedwindowsize packet drop decrease multiple packetseqwindowfullchecked window size if logminor logger minor this window not used since we last checked full packetseqwindowfull last checked packetseqwindowfullchecked window simulatedwindowsize for this return packetseqwindowfullchecked window size if slow start if logminor logger minor this still in slow start simulatedwindowsize simulatedwindowsize slow start divisor else simulatedwindowsize packet transmit increment simulatedwindowsize if simulatedwindowsize window size 1 notify all if logminor logger minor this notify of packet acked this notifyofpacketacknowledged _totalpackets windowsize getwindowsize _packetseqwindowfullchecked windowsize _packetseq _packetseqwindowfull _packetseqwindowfullchecked _simulatedwindowsize packet_drop_decrease_multiple _packetseqwindowfullchecked windowsize _packetseqwindowfull _packetseqwindowfullchecked _simulatedwindowsize _packetseqwindowfullchecked windowsize slowstart _simulatedwindowsize _simulatedwindowsize slow_start_divisor _simulatedwindowsize packet_transmit_increment _simulatedwindowsize _simulatedwindowsize windowsize notifyall notifyofpacketacked public synchronized long get delay float win size for min packet delay float roundtriptime min delay if simulatedwindowsize win size for min packet delay simulatedwindowsize win size for min packet delay if simulatedwindowsize 1 simulatedwindowsize 1 return long roundtriptime simulatedwindowsize return math max min delay long roundtriptime simulatedwindowsize getdelay winsizeforminpacketdelay _roundtriptime min_delay _simulatedwindowsize winsizeforminpacketdelay _simulatedwindowsize winsizeforminpacketdelay _simulatedwindowsize _simulatedwindowsize _roundtriptime _simulatedwindowsize min_delay _roundtriptime _simulatedwindowsize override public synchronized string to string return double to string packet size 1000 0 get delay 1024 k sec w simulatedwindowsize r roundtriptime d float droppedpackets float totalpackets total totalpackets for peer super to string tostring tostring packet_size getdelay _simulatedwindowsize _roundtriptime _droppedpackets _totalpackets _totalpackets _peer tostring public synchronized long get round trip time return roundtriptime getroundtriptime _roundtriptime public synchronized double get window size return math max 1 0 simulatedwindowsize getwindowsize _simulatedwindowsize returns the number of bytes per second in the transmition link fixme will not return more than 1m s due to min delay in get delay public synchronized double get bandwidth packet size 1024 bytes 1000 ms sec return packet size 1000 0 get delay min_delay getdelay getbandwidth packet_size packet_size getdelay public void send throttled message message msg peer context peer int packet size byte counter ctr long deadline boolean block for send async message callback cb for async send throws not connected exception throttle deprecated exception waited too long exception sync send waited too long exception long start system current time millis long bootid peer get bootid synchronized this long this ticket packetticketgenerator fixme a list or even a tree map by deadline would use less cpu than waking up every waiter twice whenever a packet is acked while true int window size int get window size if we have different timeouts and we have packets 1 and 2 timeout and 3 and 4 not timeout we could end up not sending 3 and 4 at all if we use here boolean were next packetseq this ticket abandonedtickets if there is room for it in the window break and send it immeadiately if packetsinflight window size were next packetsinflight packetseq if window size packetsinflight packetseqwindowfull packetseq if logminor logger minor this window full at packetseq for this if logminor logger minor this sending window size now window size packets in flight packetsinflight for this break long waiting behind this ticket abandonedtickets packetseq if logminor logger minor this window size window size packets in flight packetsinflight waiting behind in front of this thread for this long now system current time millis int wait for int math min integer max value deadline now if wait for 0 double check if peer is connected logger error this not notified of disconnection before timeout abandonedtickets throw new not connected exception if bootid peer get bootid logger error this not notified of reconnection before timeout abandonedtickets throw new not connected exception logger error this unable to send throttled message waited now start ms abandonedtickets throw new waited too long exception try wait wait for catch interrupted exception e ignore if peer is connected abandonedtickets throw new not connected exception if bootid peer get bootid abandonedtickets throw new not connected exception if deprecatedfor null abandonedtickets throw new throttle deprecated exception deprecatedfor because we send in order we have to go around all the waiters again after sending otherwise we will miss slots seq 0 a wait for seq 1 b wait for seq 2 packet acked packet acked b i m not next since seq 0 and i m waiting for 2 do nothing a i m next because seq 0 and i m waiting for 1 send a packet a sends b doesn t even though it ought to its slot is lost and this can cause big problems if we are sending more than one packet at a time notify all long wait time system current time millis start if wait time 60 1000 logger error this congestion control wait time wait time for this else if logminor logger minor this congestion control wait time wait time for this my callback callback new my callback cb for async send try peer send async msg callback ctr ctr sent payload packet size if block for send synchronized callback long timeout system current time millis 60 1000 long now while now system current time millis timeout callback finished try callback wait int timeout now catch interrupted exception e ignore if callback finished throw new sync send waited too long exception catch runtime exception e callback fatal error throw e catch error e callback fatal error throw e catch not connected exception e synchronized this callback disconnected notify all throw e sendthrottledmessage peercontext packetsize bytecounter blockforsend asyncmessagecallback cbforasyncsend notconnectedexception throttledeprecatedexception waitedtoolongexception syncsendwaitedtoolongexception currenttimemillis getbootid thisticket _packetticketgenerator treemap windowsize getwindowsize werenext _packetseq thisticket _abandonedtickets _packetsinflight windowsize werenext _packetsinflight _packetseq windowsize _packetsinflight _packetseqwindowfull _packetseq _packetseq windowsize _packetsinflight waitingbehind thisticket _abandonedtickets _packetseq windowsize _packetsinflight waitingbehind currenttimemillis waitfor max_value waitfor isconnected _abandonedtickets notconnectedexception getbootid _abandonedtickets notconnectedexception _abandonedtickets waitedtoolongexception waitfor interruptedexception isconnected _abandonedtickets notconnectedexception getbootid _abandonedtickets notconnectedexception _deprecatedfor _abandonedtickets throttledeprecatedexception _deprecatedfor notifyall waittime currenttimemillis waittime waittime waittime mycallback mycallback cbforasyncsend sendasync sentpayload packetsize blockforsend currenttimemillis currenttimemillis interruptedexception syncsendwaitedtoolongexception runtimeexception fatalerror fatalerror notconnectedexception notifyall private async message callback chain callback public my callback async message callback cb for async send this chain callback cb for async send asyncmessagecallback chaincallback mycallback asyncmessagecallback cbforasyncsend chaincallback cbforasyncsend public void acknowledged synchronized packet throttle this if finished if logminor logger minor this already acked ignoring callback this return finished true packetsinflight packet throttle this notify all if logminor logger minor this removed packet acked for this if chain callback null chain callback acknowledged packetthrottle _packetsinflight packetthrottle notifyall chaincallback chaincallback public void disconnected synchronized packet throttle this if finished return finished true packetsinflight packet throttle this notify all if logminor logger minor this removed packet disconnected for this if chain callback null chain callback disconnected packetthrottle _packetsinflight packetthrottle notifyall chaincallback chaincallback public void fatal error synchronized packet throttle this if finished return finished true packetsinflight packet throttle this notify all if logminor logger minor this removed packet error for this if chain callback null chain callback fatal error fatalerror packetthrottle _packetsinflight packetthrottle notifyall chaincallback chaincallback fatalerror public void sent ignore if chain callback null chain callback sent chaincallback chaincallback override public string to string return super to string packet throttle this to string tostring tostring packetthrottle tostring public synchronized void maybe disconnected notify all maybedisconnected notifyall public synchronized void changed address packet throttle new throttle deprecatedfor new throttle notify all changedaddress packetthrottle newthrottle _deprecatedfor newthrottle notifyall public peer get peer return peer getpeer _peer public thread core threadcore private java lang thread m thread object null public void set thread object java lang thread obj m thread object obj mthreadobject setthreadobject mthreadobject public java lang thread get thread object return m thread object getthreadobject mthreadobject public void start java lang thread thread object get thread object if thread object null thread object new java lang thread this set thread object thread object thread object start threadobject getthreadobject threadobject threadobject setthreadobject threadobject threadobject public void run public boolean is runnable return thread current thread get thread object true false isrunnable currentthread getthreadobject public void stop java lang thread thread object get thread object if thread object null thread object destroy thread object stop set thread object null threadobject getthreadobject threadobject threadobject threadobject setthreadobject public void restart stop start public remove persistent request simple field set fs throws message invalid exception this global fields string to bool fs get global false this identifier fs get identifier if identifier null throw new message invalid exception protocol error message missing field must have identifier null global removepersistentrequest simplefieldset messageinvalidexception stringtobool messageinvalidexception protocolerrormessage missing_field override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle override public string get name return name getname override public void run final fcp connection handler handler node node throws message invalid exception client request req handler remove persistent reboot request global identifier if req null global req handler remove request by identifier identifier true if req null handler server core client context job runner queue new db job public void run object container container client context context try client request req handler remove persistent forever request global identifier container if req null logger error this huh the request is null catch message invalid exception e fcp message err new protocol error message e protocol code false e get message e ident e global handler output handler queue err native thread high priority false fcpconnectionhandler messageinvalidexception clientrequest removepersistentrebootrequest removerequestbyidentifier clientcontext jobrunner dbjob objectcontainer clientcontext clientrequest removepersistentforeverrequest messageinvalidexception fcpmessage protocolerrormessage protocolcode getmessage outputhandler nativethread high_priority public void run object container container client context context try client request req handler remove persistent forever request global identifier container if req null logger error this huh the request is null catch message invalid exception e fcp message err new protocol error message e protocol code false e get message e ident e global handler output handler queue err objectcontainer clientcontext clientrequest removepersistentforeverrequest messageinvalidexception fcpmessage protocolerrormessage protocolcode getmessage outputhandler override public void remove from object container container container delete this removefrom objectcontainer public limited range int byte array map element int packet number byte data2 async message callback callbacks2 short priority this packet number packet number this data data2 this callbacks callbacks2 this priority priority created time system current time millis limitedrangeintbytearraymapelement packetnumber asyncmessagecallback packetnumber packetnumber createdtime currenttimemillis long reput time public void reput this reput time system current time millis reputtime reputtime currenttimemillis final high level simple client hlsc plugin down loader freenet high level simple client hlsc this hlsc hlsc highlevelsimpleclient plugindownloaderfreenet highlevelsimpleclient override public freeneturi check source string source throws plugin not found exception try return new freeneturi source catch malformedurl exception e logger error this not a valid freenet key source e throw new plugin not found exception not a valid freenet key source e checksource pluginnotfoundexception malformedurlexception pluginnotfoundexception override input stream get input stream throws io exception plugin not found exception freeneturi uri get source while true try fetch result fres hlsc fetch uri return fres as bucket get input stream catch fetch exception e if e get mode fetch exception permanent redirect e get mode fetch exception too many path components uri e newuri continue logger error this error while fetching plugin get source e throw new plugin not found exception error while fetching plugin get source e inputstream getinputstream ioexception pluginnotfoundexception getsource fetchresult asbucket getinputstream fetchexception getmode fetchexception permanent_redirect getmode fetchexception too_many_path_components getsource pluginnotfoundexception getsource override string get plugin name string source throws plugin not found exception return source substring source last index of 1 getpluginname pluginnotfoundexception lastindexof override string getsha1sum throws plugin not found exception return null pluginnotfoundexception override string getsha256sum throws plugin not found exception return null pluginnotfoundexception logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog fetch a key param client param sched param uri param ctx param priority class param client context the context object can be anything used for round robin query balancing param return bucket the bucket to return the data in can be null if not null the client getter must either write the data directly to the bucket or copy it and free the original temporary bucket preferably the former obviously public client getter client callback client freeneturi uri fetch context ctx short priority class request client client context bucket return bucket bucket binary blob bucket super priority class client context this client callback client this return bucket return bucket this uri uri this ctx ctx this finished false this actx new archive context ctx max temp length ctx max archive levels this binary blob bucket binary blob bucket if binary blob bucket null binary blob keys added already new hash set key else binary blob keys added already null archive restarts 0 priorityclass clientcontext returnbucket clientgetter clientgetter clientcallback fetchcontext priorityclass requestclient clientcontext returnbucket binaryblobbucket priorityclass clientcontext clientcallback returnbucket returnbucket archivecontext maxtemplength maxarchivelevels binaryblobbucket binaryblobbucket binaryblobbucket binaryblobkeysaddedalready hashset binaryblobkeysaddedalready archiverestarts public void start object container container client context context throws fetch exception start false null container context objectcontainer clientcontext fetchexception public boolean start boolean restart freeneturi overrideuri object container container client context context throws fetch exception if persistent container activate uri 5 if logminor logger minor this starting this persistent persistent try fixme synchronization is probably unnecessary but we definitely do not want to synchronize while calling current state schedule which can call on success and thereby almost anything synchronized this if overrideuri null uri overrideuri if finished if restart return false current state null cancelled false finished false current state single file fetcher create this this uri ctx actx ctx max non splitfile retries 0 false 1 true return bucket true container context if cancelled cancel schedule may deactivate stuff so store it now if persistent container store current state container store this if current state null finished if binary blob bucket null try binary blob stream new data output stream new buffered output stream binary blob bucket get output stream binary blob write binary blob header binary blob stream catch io exception e on failure new fetch exception fetch exception bucket error failed to open binary blob bucket e null container context if persistent container store this return false current state schedule container context if cancelled cancel catch malformedurl exception e throw new fetch exception fetch exception invalid uri e catch key listener construction exception e on failure e get fetch exception current state container context if persistent container store this container deactivate current state 1 return true objectcontainer clientcontext fetchexception currentstate onsuccess currentstate currentstate singlefilefetcher maxnonsplitfileretries returnbucket currentstate currentstate binaryblobbucket binaryblobstream dataoutputstream bufferedoutputstream binaryblobbucket getoutputstream binaryblob writebinaryblobheader binaryblobstream ioexception onfailure fetchexception fetchexception bucket_error currentstate malformedurlexception fetchexception fetchexception invalid_uri keylistenerconstructionexception onfailure getfetchexception currentstate currentstate public void on success fetch result result client get state state object container container client context context if logminor logger minor this succeeded from state on this if persistent container activate uri 5 if close binary blob stream container context return synchronized this finished true current state null if persistent container store this rest of method does not need to be synchronized variables will be updated on exit of method and the only thing that is set is the return bucket and the result not locking not only prevents nested locking resulting in deadlocks it also prevents long locks due to doing massive encrypted i os while holding a lock if return bucket null result as bucket return bucket bucket from result as bucket bucket to return bucket try if logminor logger minor this copying return bucket not respected by client async if persistent container activate from 5 container activate return bucket 5 bucket tools copy from to from free if persistent from remove from container catch io exception e logger error this error copying from from to to e to string e on failure new fetch exception fetch exception bucket error e to string state not strictly to blame but we re not ako client get state container context return result new fetch result result to else if return bucket null logminor logger minor this client async returned data in return bucket if persistent container activate state 1 state remove from container context container activate client callback 1 fetch result res result client callback on success res client getter this container onsuccess fetchresult clientgetstate objectcontainer clientcontext closebinaryblobstream currentstate returnbucket returnbucket asbucket returnbucket asbucket returnbucket returnbucket returnbucket buckettools removefrom ioexception tostring onfailure fetchexception fetchexception bucket_error tostring clientgetstate fetchresult returnbucket returnbucket removefrom clientcallback fetchresult clientcallback onsuccess clientgetter public void on failure fetch exception e client get state state object container container client context context if logminor logger minor this failed from state e on this e close binary blob stream container context if persistent container activate uri 5 client get state old state null while true if e mode fetch exception archive restart int ar synchronized this archive restarts ar archive restarts if logminor logger minor this archive restart on this ar ar if ar ctx max archive restarts e new fetch exception fetch exception too many archive restarts else try start container context catch fetch exception e1 e e1 continue return synchronized this finished true old state current state current state null if e error codes null e error codes is one code only e new fetch exception e error codes get first code e if e mode fetch exception data not found super successful blocks 0 e new fetch exception e fetch exception all data not found if logminor logger minor this on failure e state on this for uri e final fetch exception e1 e if persistent container store this if persistent container activate client callback 1 client callback on failure e1 client getter this container break if persistent if state null container activate state 1 state remove from container context if old state state old state null container activate old state 1 old state remove from container context onfailure fetchexception clientgetstate objectcontainer clientcontext closebinaryblobstream clientgetstate oldstate fetchexception archive_restart archiverestarts archiverestarts maxarchiverestarts fetchexception fetchexception too_many_archive_restarts fetchexception oldstate currentstate currentstate errorcodes errorcodes isonecodeonly fetchexception errorcodes getfirstcode fetchexception data_not_found successfulblocks fetchexception fetchexception all_data_not_found onfailure fetchexception clientcallback clientcallback onfailure clientgetter removefrom oldstate oldstate oldstate oldstate removefrom cancel the request this must result in on failure being called in order to send the client a cancel fetch exception and to remove from the state override public void cancel object container container client context context if logminor logger minor this cancelling this new exception debug client get state s synchronized this if super cancel if logminor logger minor this already cancelled this return s current state if persistent container store this if s null if persistent container activate s 1 if logminor logger minor this cancelling s for this instance super to string s cancel container context if persistent container deactivate s 1 else if logminor logger minor this nothing to cancel client get state state synchronized this state current state if state null return logger error this cancelling current state did not call on failure so did not remove from or call callback this on failure new fetch exception fetch exception cancelled state container context onfailure fetchexception removefrom objectcontainer clientcontext clientgetstate currentstate tostring clientgetstate currentstate currentstate onfailure removefrom onfailure fetchexception fetchexception override public synchronized boolean is finished return finished cancelled isfinished override public freeneturi geturi return uri override public void notify clients object container container client context context if persistent container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new splitfile progress event this total blocks this successful blocks this failed blocks this fatally failed blocks this min success blocks this block set finalized container context notifyclients objectcontainer clientcontext eventproducer eventproducer produceevent splitfileprogressevent totalblocks successfulblocks failedblocks fatallyfailedblocks minsuccessblocks blocksetfinalized override protected void inner to network object container container client context context if persistent container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new sending to network event container context innertonetwork objectcontainer clientcontext eventproducer eventproducer produceevent sendingtonetworkevent public void on block set finished client get state state object container container client context context if logminor logger minor this set finished new exception debug block set finalized container context onblocksetfinished clientgetstate objectcontainer clientcontext blocksetfinalized override public void on transition client get state old state client get state new state object container container synchronized this if current state old state current state new state if logminor logger minor this transition old state new state on this persistent persistent instance super to string new exception debug else if logminor logger minor this ignoring transition old state new state because current current state on this persistent persistent new exception debug return if persistent container store this container deactivate this 1 system gc system run finalization system gc system run finalization container activate this 1 synchronized this logger minor this post transition current state ontransition clientgetstate oldstate clientgetstate newstate objectcontainer currentstate oldstate currentstate newstate oldstate newstate tostring oldstate newstate currentstate runfinalization runfinalization currentstate public boolean can restart if current state null finished if logminor logger minor this cannot restart because not finished for uri return false return true canrestart currentstate public boolean restart freeneturi redirect object container container client context context throws fetch exception return start true redirect container context objectcontainer clientcontext fetchexception override public string to string return super to string tostring tostring void add key to binary blob client key block block object container container client context context if binary blob keys added already null return if persistent container activate binary blob stream 1 container activate binary blob keys added already 1 if logminor logger minor this adding key block get client key geturi to this new exception debug key key block get key synchronized binary blob keys added already if binary blob stream null return if binary blob keys added already contains key return binary blob keys added already add key try binary blob write key binary blob stream block key catch io exception e logger error this failed to write key to binary blob stream e e on failure new fetch exception fetch exception bucket error failed to write key to binary blob stream e null container context binary blob stream null binary blob keys added already clear addkeytobinaryblob clientkeyblock objectcontainer clientcontext binaryblobkeysaddedalready binaryblobstream binaryblobkeysaddedalready getclientkey getkey binaryblobkeysaddedalready binaryblobstream binaryblobkeysaddedalready binaryblobkeysaddedalready binaryblob writekey binaryblobstream ioexception onfailure fetchexception fetchexception bucket_error binaryblobstream binaryblobkeysaddedalready close the binary blob stream return true unless a failure occurred in which case we will have already called on failure with an appropriate error private boolean close binary blob stream object container container client context context if persistent container activate binary blob stream 1 container activate binary blob keys added already 1 if binary blob keys added already null return true synchronized binary blob keys added already if binary blob stream null return true boolean tried close false try binary blob write end blob binary blob stream binary blob stream flush tried close true binary blob stream close return true catch io exception e logger error this failed to close binary blob stream e e on failure new fetch exception fetch exception bucket error failed to close binary blob stream e null container context if tried close try binary blob stream close catch io exception e1 ignore return false finally binary blob stream null binary blob keys added already clear onfailure closebinaryblobstream objectcontainer clientcontext binaryblobstream binaryblobkeysaddedalready binaryblobkeysaddedalready binaryblobkeysaddedalready binaryblobstream triedclose binaryblob writeendblob binaryblobstream binaryblobstream triedclose binaryblobstream ioexception onfailure fetchexception fetchexception bucket_error triedclose binaryblobstream ioexception binaryblobstream binaryblobkeysaddedalready boolean collecting binary blob return binary blob bucket null collectingbinaryblob binaryblobbucket public void on expectedmime string mime object container container client context context if finalized metadata return expectedmime mime if persistent container store this container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new expectedmime event mime container context onexpectedmime objectcontainer clientcontext finalizedmetadata eventproducer eventproducer produceevent expectedmimeevent public void on expected size long size object container container client context context if finalized metadata return expected size size if persistent container store this container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new expected file size event size container context onexpectedsize objectcontainer clientcontext finalizedmetadata expectedsize eventproducer eventproducer produceevent expectedfilesizeevent public void on finalized metadata object container container finalized metadata true if persistent container store this onfinalizedmetadata objectcontainer finalizedmetadata public boolean finalized metadata return finalized metadata finalizedmetadata finalizedmetadata public string expectedmime return expectedmime public long expected size return expected size expectedsize expectedsize public client callback get client callback return client callback clientcallback getclientcallback clientcallback override public void remove from object container container client context context container activate uri 5 uri remove from container container activate ctx 1 ctx remove from container container activate actx 5 actx remove from container if return bucket null container activate return bucket 1 return bucket remove from container super remove from container context removefrom objectcontainer clientcontext removefrom removefrom removefrom returnbucket returnbucket returnbucket removefrom removefrom private static final simple field set default translation l10n get default language translation translation toadlet high level simple client client node client core core super client this core core simplefieldset default_translation getdefaultlanguagetranslation translationtoadlet highlevelsimpleclient nodeclientcore override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return boolean show everything request is parameter set to translate only if request is parameter set get override tranlation file simple field set sfs l10n get override for current language translation if sfs null super send error page ctx 503 service unavailable service unavailable l10n no custom translations return byte data sfs to ordered string get bytes utf 8 multi value table string string head new multi value table string string head put content disposition attachment filename l10n get selected language l10n override filename ctx send reply headers 200 found head text plain charset utf 8 data length ctx write data data return else if request is parameter set translation updated string key request get param translation updated html node page node ctx get page maker get page node l10n translation updated title true ctx html node content node ctx get page maker get content node page node html node translation node content node add child div class translation html node legend table translation node add child table class translation html node legend row legend table add child tr add child b legend row add child td class translation key l10n translation key label legend row add child td class translation key l10n original version label legend row add child td class translation key l10n current translation label html node content row legend table add child tr content row add child td class translation key key content row add child td class translation orig l10n get default string key content row add child td class translation new l10n get string key html node footer translation node add child div class warning footer add child a href toadlet url get override tranlation file add child l10n download translations file footer add child nbsp nbsp footer add child a href toadlet url translate key show everything to translate only add child l10n re edit footer add child nbsp nbsp footer add child a href toadlet url show everything to translate only add child l10n return to translations this writehtml reply ctx 200 ok page node generate return else if request is parameter set translate boolean goto next request is parameter set goto next string key request get param translate html node page node ctx get page maker get page node l10n translation update title true ctx html node content node ctx get page maker get content node page node html node translation node content node add child div class translation html node update form ctx add form child translation node toadlet url trans update html node legend table update form add child table class translation html node legend row legend table add child tr legend row add child td class translation key l10n translation key label legend row add child td class translation key l10n original version label legend row add child td class translation key l10n current translation label html node content row legend table add child tr content row add child td class translation key key content row add child td class translation orig l10n get default string key content row add child td class translation new add child textarea new string name rows cols new string trans 6 80 l10n get string key content row add child input new string type name value new string hidden key key update form add child input new string type name value new string submit translation update l10n update translation command update form add child input new string type name goto next checked unchecked new string checkbox goto next l10n goto next if show everything update form add child input new string type name value new string hidden to translate only key update form add child input new string type name value new string submit cancel l10n get string toadlet cancel this writehtml reply ctx 200 ok page node generate return else if request is parameter set remove string key request get param remove html node page node ctx get page maker get page node l10n remove override title true ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox warning l10n remove override warning title html node content ctx get page maker get content node infobox content add child p add child l10n get string translation toadlet confirm remove override new string key value new string key l10n get string key html node remove form ctx add form child content add child p toadlet url remove confirmed if show everything remove form add child input new string type name value new string hidden to translate only key remove form add child input new string type name value new string hidden remove confirm key remove form add child input new string type name value new string submit remove confirmed l10n remove remove form add child input new string type name value new string submit cancel l10n get string toadlet cancel this writehtml reply ctx 200 ok page node generate return html node page node ctx get page maker get page node l10n translation update title true ctx html node content node ctx get page maker get content node page node html node translation node content node add child div class translation html node translation header node translation node add child p translation header node add child l10n contributing to label with lang lang l10n get selected language full name translation header node add child a href toadlet url get override tranlation file add child l10n download translations file translation header node add child if show everything translation header node add child a href toadlet url to translate only add child l10n hide already translated else translation header node add child a href toadlet url add child l10n show everything html node legend table translation node add child table class translation html node legend row legend table add child tr legend row add child td class translation key l10n translation key label legend row add child td class translation key l10n original version label legend row add child td class translation key l10n current translation label simple field set sfs l10n get current language translation if sfs null key iterator it default translation key iterator while it has next string key it next key boolean is overriden l10n is overridden key if show everything is overriden l10n get string key true null continue html node content row legend table add child tr content row add child td class translation key key content row add child td class translation orig l10n get default string key content row add child td class translation new add child setorremoveoverride key is overriden show everything this writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring showeverything isparameterset totranslateonly isparameterset getoverridetranlationfile simplefieldset getoverrideforcurrentlanguagetranslation senderrorpage nocustomtranslations toorderedstring getbytes multivaluetable multivaluetable getselectedlanguage l10noverridefilename sendreplyheaders writedata isparameterset translation_updated getparam translation_updated htmlnode pagenode getpagemaker getpagenode translationupdatedtitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode translationnode contentnode addchild htmlnode legendtable translationnode addchild htmlnode legendrow legendtable addchild addchild legendrow addchild translationkeylabel legendrow addchild originalversionlabel legendrow addchild currenttranslationlabel htmlnode contentrow legendtable addchild contentrow addchild contentrow addchild getdefaultstring contentrow addchild getstring htmlnode translationnode addchild addchild toadlet_url getoverridetranlationfile addchild downloadtranslationsfile addchild addchild toadlet_url showeverything totranslateonly addchild reedit addchild addchild toadlet_url showeverything totranslateonly addchild returntotranslations writehtmlreply pagenode isparameterset gotonext isparameterset gotonext getparam htmlnode pagenode getpagemaker getpagenode translationupdatetitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode translationnode contentnode addchild htmlnode updateform addformchild translationnode toadlet_url trans_update htmlnode legendtable updateform addchild htmlnode legendrow legendtable addchild legendrow addchild translationkeylabel legendrow addchild originalversionlabel legendrow addchild currenttranslationlabel htmlnode contentrow legendtable addchild contentrow addchild contentrow addchild getdefaultstring contentrow addchild addchild getstring contentrow addchild updateform addchild translation_update updatetranslationcommand updateform addchild gotonext gotonext gotonext showeverything updateform addchild totranslateonly updateform addchild getstring writehtmlreply pagenode isparameterset getparam htmlnode pagenode getpagemaker getpagenode removeoverridetitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox removeoverridewarningtitle htmlnode getpagemaker getcontentnode addchild addchild getstring translationtoadlet confirmremoveoverride getstring htmlnode removeform addformchild addchild toadlet_url remove_confirmed showeverything removeform addchild totranslateonly removeform addchild remove_confirm removeform addchild remove_confirmed removeform addchild getstring writehtmlreply pagenode htmlnode pagenode getpagemaker getpagenode translationupdatetitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode translationnode contentnode addchild htmlnode translationheadernode translationnode addchild translationheadernode addchild contributingtolabelwithlang getselectedlanguage fullname translationheadernode addchild toadlet_url getoverridetranlationfile addchild downloadtranslationsfile translationheadernode addchild showeverything translationheadernode addchild toadlet_url totranslateonly addchild hidealreadytranslated translationheadernode addchild toadlet_url addchild showeverything htmlnode legendtable translationnode addchild htmlnode legendrow legendtable addchild legendrow addchild translationkeylabel legendrow addchild originalversionlabel legendrow addchild currenttranslationlabel simplefieldset getcurrentlanguagetranslation keyiterator default_translation keyiterator hasnext nextkey isoverriden isoverridden showeverything isoverriden getstring htmlnode contentrow legendtable addchild contentrow addchild contentrow addchild getdefaultstring contentrow addchild addchild _setorremoveoverride isoverriden showeverything writehtmlreply pagenode override public void handle post uri uri http request request toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return final boolean logminor logger should log logger minor this final string passwd request get part as string form password 32 boolean no password passwd null passwd equals core form password if no password if logminor logger minor this no password passwd should be core form password redirect to ctx return boolean to translate only request is part set to translate only if request get part as string translation update 32 length 0 string key request get part as string key 256 l10n set override key new string bucket tools to byte array request get part trans utf 8 trim if on equals ignore case request get part as string goto next 7 key iterator it default translation key iterator while it has next string new key it next key boolean is overriden l10n is overridden new key system out println newkey new key if is overriden l10n get string new key true null continue redirect to ctx toadlet url goto next translate new key to translate only to translate only return redirect to ctx toadlet url translation updated key to translate only to translate only return else if request get part as string remove confirmed 32 length 0 string key request get part as string remove confirm 256 trim l10n set override key redirect to ctx toadlet url translation updated key to translate only to translate only return else shouldn t reach that point redirect to ctx handlepost httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring shouldlog getpartasstring formpassword nopassword formpassword nopassword formpassword redirectto totranslateonly ispartset totranslateonly getpartasstring translation_update getpartasstring setoverride buckettools tobytearray getpart equalsignorecase getpartasstring gotonext keyiterator default_translation keyiterator hasnext newkey nextkey isoverriden isoverridden newkey newkey isoverriden getstring newkey redirectto toadlet_url gotonext newkey totranslateonly totranslateonly redirectto toadlet_url translation_updated totranslateonly totranslateonly getpartasstring remove_confirmed getpartasstring remove_confirm setoverride redirectto toadlet_url translation_updated totranslateonly totranslateonly redirectto private void redirect to toadlet context ctx string target throws toadlet context closed exception io exception multi value table string string headers new multi value table string string headers put location target ctx send reply headers 302 found headers null 0 return redirectto toadletcontext toadletcontextclosedexception ioexception multivaluetable multivaluetable sendreplyheaders override public string supported methods return get post supportedmethods private html node setorremoveoverride string key boolean is overriden boolean show everything string value l10n get string key true html node translation field new html node span class is overriden translate d translate it if value null translation field add child l10n get default string key translation field add child a href translation toadlet toadlet url translate key show everything to translate only add child small l10n bracket translate it else translation field add child l10n get string key translation field add child a href translation toadlet toadlet url translate key show everything to translate only add child small l10n bracket update translation if is overriden translation field add child a href translation toadlet toadlet url remove key show everything to translate only add child small l10n bracket remove override return translation field htmlnode _setorremoveoverride isoverriden showeverything getstring htmlnode translationfield htmlnode isoverriden translate_d translate_it translationfield addchild getdefaultstring translationfield addchild translationtoadlet toadlet_url showeverything totranslateonly addchild brackettranslateit translationfield addchild getstring translationfield addchild translationtoadlet toadlet_url showeverything totranslateonly addchild bracketupdatetranslation isoverriden translationfield addchild translationtoadlet toadlet_url showeverything totranslateonly addchild bracketremoveoverride translationfield private string l10n string key return l10n get string translation toadlet key getstring translationtoadlet private string l10n string key string pattern string value return l10n get string translation toadlet key new string pattern new string value getstring translationtoadlet public class wot own message extends own message public static wot own message construct message new parent thread message new parent message set board new boards board new reply to board ft own identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception return new wot own message new parent thread new parent message new boards new reply to board new author new title new date new text new attachments wotownmessage ownmessage wotownmessage newparentthread newparentmessage newboards newreplytoboard ftownidentity newauthor newtitle newdate newtext newattachments invalidparameterexception wotownmessage newparentthread newparentmessage newboards newreplytoboard newauthor newtitle newdate newtext newattachments protected wot own message message new parent thread message new parent message set board new boards board new reply to board ft own identity new author string new title date new date string new text list attachment new attachments throws invalid parameter exception super null null generate randomid new author null new parent thread null null new parent thread geturi new parent message null null new parent message geturi new boards new reply to board new author new title new date new text new attachments wotownmessage newparentthread newparentmessage newboards newreplytoboard ftownidentity newauthor newtitle newdate newtext newattachments invalidparameterexception generaterandomid newauthor newparentthread newparentthread newparentmessage newparentmessage newboards newreplytoboard newauthor newtitle newdate newtext newattachments protected static string generate randomid ft identity author return uuid randomuuid base64 encode author get requesturi get routing key generaterandomid ftidentity getrequesturi getroutingkey generate the insert uri for a message public synchronized freeneturi get inserturi return freeneturi empty chk uri getinserturi empty_chk_uri private final board board public freetalknntp group board board this board board freetalknntpgroup convert nntp group name into a freetalk board name public static string group to board name string name fixme this does nothing at the moment in the future it could be used to quote names in ascii for older newsreaders that only allow ascii group names return name grouptoboardname convert a freetalk board name into an nntp group name public static string board to group name string name return name boardtogroupname get the ft board object associated with this group public board get board return board ftboard getboard get the group name public string get name return board to group name board get name getname boardtogroupname getname estimate number of messages that have been posted public long message count return board get all messages false size messagecount getallmessages get the first valid message number public int first message return 1 firstmessage get the last valid message number public int last message return board get last message index lastmessage getlastmessageindex get an iterator for articles in the given range public iterator freetalknntp article get message iterator int start int end throws no such message exception synchronized board if start first message start first message if end 1 end last message end last message iterator freetalknntp article iter final int start index start final int end index end iter new iterator freetalknntp article private int current index start index private message current message null public boolean has next if current message null return true while current index end index try current message board get message by index current index return true catch no such message exception e ignore current index return false public freetalknntp article next if has next throw new no such element exception else message msg current message current message null return new freetalknntp article msg current index public void remove throw new unsupported operation exception if iter has next throw new no such message exception return iter freetalknntparticle getmessageiterator nosuchmessageexception firstmessage firstmessage lastmessage lastmessage freetalknntparticle startindex endindex freetalknntparticle currentindex startindex currentmessage hasnext currentmessage currentindex endindex currentmessage getmessagebyindex currentindex nosuchmessageexception currentindex freetalknntparticle hasnext nosuchelementexception currentmessage currentmessage freetalknntparticle currentindex unsupportedoperationexception hasnext nosuchmessageexception public boolean has next if current message null return true while current index end index try current message board get message by index current index return true catch no such message exception e ignore current index return false hasnext currentmessage currentindex endindex currentmessage getmessagebyindex currentindex nosuchmessageexception currentindex public freetalknntp article next if has next throw new no such element exception else message msg current message current message null return new freetalknntp article msg current index freetalknntparticle hasnext nosuchelementexception currentmessage currentmessage freetalknntparticle currentindex public void remove throw new unsupported operation exception unsupportedoperationexception get the board posting status this is normally either y posting is allowed n posting is not allowed or m group is moderated it is a hint to the reader and doesn t necessarily indicate whether the client will be allowed to post or whether any given message will be accepted public string posting status return y postingstatus static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog override public string to string return super to string msg dest tostring tostring public send message on error callback message message peer node pn byte counter ctr this msg message this dest pn this ctr ctr if logminor logger minor this created this sendmessageonerrorcallback peernode bytecounter public void sent ignore public void acknowledged all done public void disconnected if logminor logger minor this disconnect trigger this try dest send async msg null ctr catch not connected exception e if logminor logger minor this both source and destination disconnected msg for this sendasync notconnectedexception public void fatal error disconnected fatalerror public put successful message string identifier boolean global freeneturi uri long startup time long completion time this identifier identifier this global global this uri uri this startup time startup time this completion time completion time putsuccessfulmessage startuptime completiontime startuptime startuptime completiontime completiontime override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier if global fs put single global true this is useful for simple clients if uri null fs put single uri uri to string false false fs put startup time startup time fs put completion time completion time return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle putsingle tostring startuptime startuptime completiontime completiontime override public string get name return put successful getname putsuccessful override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message insert successful goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message insertsuccessful override public void remove from object container container container activate uri 5 uri remove from container container delete this removefrom objectcontainer removefrom logger register log threshold callback new log threshold callback override public void should update logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog param priorityclass param chkscheduler param sskscheduler param client2 public very simple getter short priorityclass freeneturi uri2 request client client2 super priorityclass client2 uri uri2 verysimplegetter requestclient override public freeneturi geturi return uri override public boolean is finished logger error this todo new error todo return false isfinished override public void cancel object container container client context context logger error this todo new error todo objectcontainer clientcontext override public void notify clients object container container client context context progress ignore logger error this todo new error todo notifyclients objectcontainer clientcontext override public void on transition client get state old state client get state new state object container container logger error this todo new error todo ontransition clientgetstate oldstate clientgetstate newstate objectcontainer override protected void inner to network object container container client context context if logdebug logger debug this request goes out to network now innertonetwork objectcontainer clientcontext public u pnp super ports forwarded new hash set forward port add device change listener this upnp portsforwarded hashset forwardport adddevicechangelistener public void run plugin plugin respirator pr this pr pr super start runplugin pluginrespirator public void terminate unregister port mappings super stop unregisterportmappings public detectedip get address logger minor this up p get address is called o if is disabled logger normal this plugin has been disabled previously ignoring request return null else if isnat present logger normal this no up p device found detection of the external ip address using the plugin has failed return null detectedip result null final string nat address getnat address try inet address detectedip inet address get by name nat address short status detectedip not supported thinks we are double natted ip util is valid address detectedip false if we have forwarded a port and we don t have a private address if ports forwarded size 1 thinks we are double natted status detectedip full internet result new detectedip detectedip status logger normal this successful up p discovery result system out println successful up p discovery result return new detectedip result catch unknown host exception e logger error this caught an unknown host exception resolving nat address e system err println up p discovery has failed unable to resolve result return null getaddress getaddress isdisabled isnatpresent nataddress getnataddress inetaddress inetaddress getbyname nataddress not_supported thinkswearedoublenatted iputil isvalidaddress portsforwarded thinkswearedoublenatted full_internet unknownhostexception unknownhostexception nataddress public void device added device dev synchronized lock if is disabled logger normal this plugin has been disabled previously ignoring new device return if router device equals dev get device type dev is root device return silently ignore non igd devices else if isnat present logger error this we got a second igd on the network the plugin doesn t handle that let s disable it system err println the up p plugin has found more than one igd on the network as a result it will be disabled is disabled true synchronized lock router null service null stop return logger normal this up p igd found dev get friendly name system out println up p igd found dev get friendly name synchronized lock router dev discover service we have found the device we need stop the listener thread stop synchronized lock if service null logger error this the igd device we got isn t suiting our needs let s disable the plugin system err println the igd device we got isn t suiting our needs let s disable the plugin is disabled true router null return register port mappings deviceadded isdisabled router_device getdevicetype isrootdevice isnatpresent isdisabled _router _service getfriendlyname getfriendlyname _router discoverservice _service isdisabled _router registerportmappings private void register port mappings set ports synchronized lock ports ports to forward if ports null return register ports ports registerportmappings portstoforward registerports traverses the structure of the router device looking for the port mapping service private void discover service synchronized lock for iterator iter router get device list iterator iter has next device current device iter next if current get device type equals wan device continue device list l current get device list for int i 0 i current get device list size i device current2 l get device i if current2 get device type equals wancon device continue service current2 get service wan ppp connection if service null logger normal this router get friendly name doesn t seems to be using ppp we won t be able to extract bandwidth related informations out of it service current2 get service wan ip connection if service null logger error this router get friendly name doesn t export wan ip connection either we won t be able to use it return discoverservice _router getdevicelist hasnext getdevicetype wan_device devicelist getdevicelist getdevicelist getdevice getdevicetype wancon_device _service getservice wan_ppp_connection _service _router getfriendlyname _service getservice wan_ip_connection _service _router getfriendlyname wan_ip_connection public boolean try add mapping string protocol int port string description forward port fp logger normal this registering a port mapping for port protocol system err println u pnp registering a port mapping for port protocol int nb of tries 0 boolean is port forwarded false while nb of tries 5 is port forwarded add mapping protocol port freenet 0 7 description fp if is port forwarded break try thread sleep 5000 catch interrupted exception e logger normal this is port forwarded mapping is successful mapping has failed nb of tries tries system err println u pnp is port forwarded mapping is successful mapping has failed nb of tries tries return is port forwarded tryaddmapping forwardport upnp nboftries isportforwarded nboftries isportforwarded addmapping isportforwarded interruptedexception isportforwarded nboftries upnp isportforwarded nboftries isportforwarded public void unregister port mappings set ports synchronized lock ports ports forwarded this unregister ports ports unregisterportmappings portsforwarded unregisterports public void device removed device dev synchronized lock if router null return if router equals dev router null service null deviceremoved _router _router _router _service return whether we are behind an u pnp enabled nat router public boolean isnat present return router null service null upnp isnatpresent _router _service return the external address the nat thinks we have blocking null if we can t find it public string getnat address if isnat present return null action getip service get action get externalip address if getip null getip post control action return null return getip get output argument list get argument new externalip address get value getnataddress isnatpresent _service getaction getexternalipaddress postcontrolaction getoutputargumentlist getargument newexternalipaddress getvalue return the reported upstream bit rate in bits per second 1 if it s not available blocking public int get upstram max bit rate if isnat present thinks we are double natted return 1 action getip service get action get link layer max bit rates if getip null getip post control action return 1 return integer value of getip get output argument list get argument new upstream max bit rate get value getupstrammaxbitrate isnatpresent thinkswearedoublenatted _service getaction getlinklayermaxbitrates postcontrolaction valueof getoutputargumentlist getargument newupstreammaxbitrate getvalue return the reported downstream bit rate in bits per second 1 if it s not available blocking public int get downstream max bit rate if isnat present thinks we are double natted return 1 action getip service get action get link layer max bit rates if getip null getip post control action return 1 return integer value of getip get output argument list get argument new downstream max bit rate get value getdownstreammaxbitrate isnatpresent thinkswearedoublenatted _service getaction getlinklayermaxbitrates postcontrolaction valueof getoutputargumentlist getargument newdownstreammaxbitrate getvalue private void list state table service serv string builder sb service state table table serv get service state table sb append div small for int i 0 i table size i state variable current table get state variable i sb append current get name current get value br sb append small div liststatetable stringbuilder servicestatetable getservicestatetable statevariable getstatevariable getname getvalue private void list actions arguments action action string builder sb argument list ar action get argument list for int i 0 i ar size i argument argument ar get argument i if argument null continue sb append div small argument i argument get name small div listactionsarguments stringbuilder argumentlist getargumentlist getargument getname private void list actions service service string builder sb action list al service get action list for int i 0 i al size i action action al get action i if action null continue sb append div action i action get name list actions arguments action sb sb append div listactions stringbuilder actionlist getactionlist getaction getname listactionsarguments private string to string string action string argument service serv action getip serv get action action if getip null getip post control action return null argument ret getip get output argument list get argument argument return ret get value tostring getaction postcontrolaction getoutputargumentlist getargument getvalue todo extend it rtfm private void list sub services device dev string builder sb service list sl dev get service list for int i 0 i sl size i service serv sl get service i if serv null continue sb append div service i serv get service type br if urn schemas upnp org service wan common interface config 1 equals serv get service type sb append wan common interface config sb append status to string get common link properties new physical link status serv sb append type to string get common link properties newwan access type serv sb append upstream to string get common link properties new layer1 upstream max bit rate serv sb append downstream to string get common link properties new layer1 downstream max bit rate serv br else if urn schemas upnp org service wanppp connection 1 equals serv get service type sb append wanppp connection sb append status to string get status info new connection status serv sb append type to string get connection type info new connection type serv sb append upstream to string get link layer max bit rates new upstream max bit rate serv sb append downstream to string get link layer max bit rates new downstream max bit rate serv br sb append external ip to string get externalip address new externalip address serv br else if urn schemas upnp org service layer3 forwarding 1 equals serv get service type sb append layer3 forwarding sb append default connection service to string get default connection service new default connection service serv else if wan ip connection equals serv get service type sb append wanip connection sb append status to string get status info new connection status serv sb append type to string get connection type info new connection type serv sb append external ip to string get externalip address new externalip address serv br else if urn schemas upnp org service wan ethernet link config 1 equals serv get service type sb append wan ethernet link config sb append status to string get ethernet link status new ethernet link status serv br else sb append serv get service type list actions serv sb list state table serv sb sb append div listsubservices stringbuilder servicelist getservicelist getservice getservicetype wancommoninterfaceconfig getservicetype wancommoninterfaceconfig tostring getcommonlinkproperties newphysicallinkstatus tostring getcommonlinkproperties newwanaccesstype tostring getcommonlinkproperties newlayer1upstreammaxbitrate tostring getcommonlinkproperties newlayer1downstreammaxbitrate wanpppconnection getservicetype wanpppconnection tostring getstatusinfo newconnectionstatus tostring getconnectiontypeinfo newconnectiontype tostring getlinklayermaxbitrates newupstreammaxbitrate tostring getlinklayermaxbitrates newdownstreammaxbitrate tostring getexternalipaddress newexternalipaddress layer3forwarding getservicetype layer3forwarding defaultconnectionservice tostring getdefaultconnectionservice newdefaultconnectionservice wan_ip_connection getservicetype wanipconnection tostring getstatusinfo newconnectionstatus tostring getconnectiontypeinfo newconnectiontype tostring getexternalipaddress newexternalipaddress wanethernetlinkconfig getservicetype wanethernetlinkconfig tostring getethernetlinkstatus newethernetlinkstatus getservicetype listactions liststatetable private void list sub dev string prefix device dev string builder sb sb append div p device dev get friendly name dev get device type br list sub services dev sb device list dl dev get device list for int j 0 j dl size j device sub dev dl get device j if sub dev null continue sb append div list sub dev dev get friendly name sub dev sb sb append div div sb append p div listsubdev stringbuilder getfriendlyname getdevicetype listsubservices devicelist getdevicelist subdev getdevice subdev listsubdev getfriendlyname subdev public string handlehttp get http request request throws pluginhttp exception if request is parameter set get device capabilities final string builder sb new string builder sb append html head title u pnp report title head body list sub dev wan device router sb sb append body html return sb to string html node page node pr get page maker get page node up p plugin configuration page false null html node content node pr get page maker get content node page node if is disabled html node disabled infobox content node add child div class infobox infobox error html node disabled infobox header disabled infobox add child div class infobox header html node disabled infobox content disabled infobox add child div class infobox content disabled infobox header add child up p plugin report disabled infobox content add child the plugin has been disabled do you have more than one up p igd on your lan return page node generate else if isnat present html node not found infobox content node add child div class infobox infobox warning html node not found infobox header not found infobox add child div class infobox header html node not found infobox content not found infobox add child div class infobox content not found infobox header add child up p plugin report not found infobox content add child the plugin hasn t found any up p aware compatible device on your lan return page node generate html node found infobox content node add child div class infobox infobox normal html node found infobox header found infobox add child div class infobox header html node found infobox content found infobox add child div class infobox content fixme l10n found infobox header add child up p plugin report found infobox content add child p the following device has been found add child a href get device capabilities add child router get friendly name found infobox content add child p our current external ip address is getnat address int downstream max bit rate get downstream max bit rate int upstream max bit rate get upstram max bit rate if downstream max bit rate 0 found infobox content add child p our reported max downstream bit rate is get downstream max bit rate bits sec if upstream max bit rate 0 found infobox content add child p our reported max upstream bit rate is get upstram max bit rate bits sec synchronized lock if ports to forward null for forward port port ports to forward if ports forwarded contains port found infobox content add child p the port name port port port number port protocol has been forwarded successfully else found infobox content add child p the port name port port port number port protocol has not been forwarded return page node generate handlehttpget httprequest pluginhttpexception isparameterset getdevicecapabilities stringbuilder stringbuilder upnp listsubdev wandevice _router tostring htmlnode pagenode getpagemaker getpagenode htmlnode contentnode getpagemaker getcontentnode pagenode isdisabled htmlnode disabledinfobox contentnode addchild htmlnode disabledinfoboxheader disabledinfobox addchild htmlnode disabledinfoboxcontent disabledinfobox addchild disabledinfoboxheader addchild disabledinfoboxcontent addchild pagenode isnatpresent htmlnode notfoundinfobox contentnode addchild htmlnode notfoundinfoboxheader notfoundinfobox addchild htmlnode notfoundinfoboxcontent notfoundinfobox addchild notfoundinfoboxheader addchild notfoundinfoboxcontent addchild pagenode htmlnode foundinfobox contentnode addchild htmlnode foundinfoboxheader foundinfobox addchild htmlnode foundinfoboxcontent foundinfobox addchild foundinfoboxheader addchild foundinfoboxcontent addchild addchild getdevicecapabilities addchild _router getfriendlyname foundinfoboxcontent addchild getnataddress downstreammaxbitrate getdownstreammaxbitrate upstreammaxbitrate getupstrammaxbitrate downstreammaxbitrate foundinfoboxcontent addchild getdownstreammaxbitrate upstreammaxbitrate foundinfoboxcontent addchild getupstrammaxbitrate portstoforward forwardport portstoforward portsforwarded foundinfoboxcontent addchild portnumber foundinfoboxcontent addchild portnumber pagenode public string handlehttp post http request request throws pluginhttp exception return null handlehttppost httprequest pluginhttpexception private boolean add mapping string protocol int port string description forward port fp if is disabled isnat present router null return false just in case remove mapping protocol port fp true action add service get action add port mapping if add null logger error this couldn t find add port mapping action return false add set argument value new remote host add set argument value new external port port add set argument value new internal client router get interface address add set argument value new internal port port add set argument value new protocol protocol add set argument value new port mapping description description add set argument value new enabled 1 add set argument value new lease duration 0 if add post control action synchronized lock ports forwarded add fp return true else return false addmapping forwardport isdisabled isnatpresent _router removemapping _service getaction addportmapping addportmapping setargumentvalue newremotehost setargumentvalue newexternalport setargumentvalue newinternalclient _router getinterfaceaddress setargumentvalue newinternalport setargumentvalue newprotocol setargumentvalue newportmappingdescription setargumentvalue newenabled setargumentvalue newleaseduration postcontrolaction portsforwarded private boolean remove mapping string protocol int port forward port fp boolean no log if is disabled isnat present return false action remove service get action delete port mapping if remove null logger error this couldn t find delete port mapping action return false remove set argument value new remote host remove set argument value new external port port remove set argument value new protocol protocol boolean retval remove post control action synchronized lock ports forwarded remove fp if no log system err println u pnp removed mapping for fp name port protocol return retval removemapping forwardport nolog isdisabled isnatpresent _service getaction deleteportmapping deleteportmapping setargumentvalue newremotehost setargumentvalue newexternalport setargumentvalue newprotocol postcontrolaction portsforwarded nolog upnp public void on change public ports set forward port ports forward port callback cb set forward port ports to dump now null set forward port ports to forward now null system err println up p forwarding ports size ports synchronized lock if forward callback null forward callback cb cb null logger error this forward port callback changed from forward callback to cb using new value but this is very strange forward callback cb if ports to forward null ports to forward is empty ports to forward ports ports to forward now ports ports to dump now null else if ports null ports is empty ports to dump now ports to forward ports to forward ports ports to forward now null else some ports to keep some ports to dump ports in ports but not in ports to forward now we must forward ports in ports to forward now but not in ports we must dump for forward port port ports if ports to forward contains port we have forwarded it and it should be forwarded cool else needs forwarding if ports to forward now null ports to forward now new hash set forward port ports to forward now add port for forward port port ports to forward if ports contains port should be forwarded has been forwarded cool else needs dropping if ports to dump now null ports to dump now new hash set forward port ports to dump now add port ports to forward ports if router null return when one is found we will do the forwards if ports to dump now null unregister ports ports to dump now if ports to forward now null register ports ports to forward now onchangepublicports forwardport forwardportcallback forwardport portstodumpnow forwardport portstoforwardnow forwardcallback forwardcallback forwardportcallback forwardcallback forwardcallback portstoforward portstoforward isempty portstoforward portstoforwardnow portstodumpnow isempty portstodumpnow portstoforward portstoforward portstoforwardnow portstoforwardnow portstoforwardnow forwardport portstoforward portstoforwardnow portstoforwardnow hashset forwardport portstoforwardnow forwardport portstoforward portstodumpnow portstodumpnow hashset forwardport portstodumpnow portstoforward _router portstodumpnow unregisterports portstodumpnow portstoforwardnow registerports portstoforwardnow private void register ports set forward port ports to forward now for forward port port ports to forward now string proto if port protocol forward port protocol udp ipv4 proto udp else if port protocol forward port protocol tcp ipv4 proto tcp else hash map forward port forward port status map new hash map forward port forward port status map put port new forward port status forward port status definite failure protocol not supported port port number forward callback port forward status map continue if try add mapping proto port port number port name port hash map forward port forward port status map new hash map forward port forward port status map put port new forward port status forward port status maybe success port apparently forwarded by u pnp port port number forward callback port forward status map continue else hash map forward port forward port status map new hash map forward port forward port status map put port new forward port status forward port status probable failure u pnp port forwarding apparently failed port port number forward callback port forward status map continue registerports forwardport portstoforwardnow forwardport portstoforwardnow forwardport protocol_udp_ipv4 forwardport protocol_tcp_ipv4 hashmap forwardport forwardportstatus hashmap forwardport forwardportstatus forwardportstatus forwardportstatus definite_failure portnumber forwardcallback portforwardstatus tryaddmapping portnumber hashmap forwardport forwardportstatus hashmap forwardport forwardportstatus forwardportstatus forwardportstatus maybe_success upnp portnumber forwardcallback portforwardstatus hashmap forwardport forwardportstatus hashmap forwardport forwardportstatus forwardportstatus forwardportstatus probable_failure upnp portnumber forwardcallback portforwardstatus private void unregister ports set forward port ports to forward now for forward port port ports to forward now string proto if port protocol forward port protocol udp ipv4 proto udp else if port protocol forward port protocol tcp ipv4 proto tcp else ignore we ve already complained about it continue remove mapping proto port port number port false unregisterports forwardport portstoforwardnow forwardport portstoforwardnow forwardport protocol_udp_ipv4 forwardport protocol_tcp_ipv4 removemapping portnumber public string get version return version get version version get svn revision getversion getversion getsvnrevision public long get real version return version get real version getrealversion getrealversion public static void main string args throws exception u pnp upnp new u pnp control point cp new control point system out println searching for up p devices cp start cp search while true device list list cp get device list system out println found list size devices string builder sb new string builder iterator device it list iterator while it has next device device it next upnp list sub dev device to string device sb system out println here is the listing for device to string system out println sb to string sb new string builder system out println end thread sleep 2000 upnp upnp controlpoint controlpoint devicelist getdevicelist stringbuilder stringbuilder hasnext listsubdev tostring tostring tostring stringbuilder public full text search hit hits public full text search result full text search hit hits int estimation this hits hits this estimation estimation fulltextsearchhit fulltextsearchresult fulltextsearchhit protected function2d basis public compound function2d function2d basis this basis basis compoundfunction2d public void set basis function2d basis this basis basis setbasis public function2d get basis return basis getbasis final long max archive size public archive context long max archive size int max this max archive levels max this max archive size max archive size maxarchivesize archivecontext maxarchivesize maxarchivelevels maxarchivesize maxarchivesize check for a loop the uri provided is expected to be a reasonably unique identifier for the archive public synchronized void do loop detection freeneturi key throws archive failure exception if so far size max archive levels throw new archive failure exception archive failure exception too many levels doloopdetection archivefailureexception sofar maxarchivelevels archivefailureexception archivefailureexception too_many_levels public void remove from object container container container delete so far container delete this removefrom objectcontainer sofar private random random numbers new random public noise filter randomnumbers noisefilter set the amount of effect param amount the amount min value 0 max value 1 see get amount public void set amount int amount this amount amount getamount setamount get the amount of noise return the amount see set amount public int get amount return amount setamount getamount set the distribution of the noise param distribution the distribution see get distribution public void set distribution int distribution this distribution distribution getdistribution setdistribution get the distribution of the noise return the distribution see set distribution public int get distribution return distribution setdistribution getdistribution set whether to use monochrome noise param monochrome true for monochrome noise see get monochrome public void set monochrome boolean monochrome this monochrome monochrome getmonochrome setmonochrome get whether to use monochrome noise return true for monochrome noise see set monochrome public boolean get monochrome return monochrome setmonochrome getmonochrome set the density of the noise param density the density see get density public void set density float density this density density getdensity setdensity get the density of the noise return the density see set density public float get density return density setdensity getdensity private int random int x x int distribution gaussian random numbers next gaussian 2 random numbers next float 1 amount if x 0 x 0 else if x 0xff x 0xff return x randomnumbers nextgaussian randomnumbers nextfloat override public int filterrgb int x int y int rgb if random numbers next float density int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if monochrome int n int distribution gaussian random numbers next gaussian 2 random numbers next float 1 amount r pixel utils clamp r n g pixel utils clamp g n b pixel utils clamp b n else r random r g random g b random b return a r 16 g 8 b return rgb randomnumbers nextfloat randomnumbers nextgaussian randomnumbers nextfloat pixelutils pixelutils pixelutils override public string to string return stylize add noise tostring applies distortion by adding shadow to the text and also two noises param base image the base image return the distorted image public buffered image get distorted image buffered image base image noise producer noise producer get config get noise impl buffered image distorted image new buffered image base image get width base image get height buffered image type int argb graphics2d graph graphics2d distorted image get graphics shadow filter shadow filter new shadow filter shadow filter set radius 10 shadow filter set distance 5 shadow filter set opacity 1 random rand new random ripple filter ripple filter new ripple filter ripple filter set wave type ripple filter sine ripple filter setx amplitude 7 6f ripple filter sety amplitude rand next float 1 0f ripple filter setx wavelength rand next int 7 8 ripple filter sety wavelength rand next int 3 2 ripple filter set edge action transform filter bilinear buffered image effect image ripple filter filter base image null effect image shadow filter filter effect image null graph draw image effect image 0 0 null null graph dispose draw lines over the image and or text noise producer make noise distorted image 1f 1f 25f 25f noise producer make noise distorted image 1f 25f 5f 9f return distorted image baseimage bufferedimage getdistortedimage bufferedimage baseimage noiseproducer noiseproducer getconfig getnoiseimpl bufferedimage distortedimage bufferedimage baseimage getwidth baseimage getheight bufferedimage type_int_argb distortedimage getgraphics shadowfilter shadowfilter shadowfilter shadowfilter setradius shadowfilter setdistance shadowfilter setopacity ripplefilter ripplefilter ripplefilter ripplefilter setwavetype ripplefilter ripplefilter setxamplitude ripplefilter setyamplitude nextfloat ripplefilter setxwavelength nextint ripplefilter setywavelength nextint ripplefilter setedgeaction transformfilter bufferedimage effectimage ripplefilter baseimage effectimage shadowfilter effectimage drawimage effectimage noiseproducer makenoise distortedimage noiseproducer makenoise distortedimage distortedimage public insert compressor long nodedb handle2 single file inserter inserter2 bucket orig data2 int min size2 bucket factory bf boolean persistent this nodedb handle nodedb handle2 this inserter inserter2 this orig data orig data2 this min size min size2 this bucket factory bf this persistent persistent insertcompressor nodedbhandle2 singlefileinserter origdata2 minsize2 bucketfactory nodedbhandle nodedbhandle2 origdata origdata2 minsize minsize2 bucketfactory public void init object container container final client context ctx logminor logger should log logger minor this if persistent container activate inserter 1 container activate orig data 1 if orig data null if inserter null inserter cancelled container delete this return inserter was cancelled we weren t told else if inserter started logger error this inserter started already but we are about to attempt to compress the data container delete this return already started no point but this really shouldn t happen else logger error this original data was deleted but inserter neither deleted nor cancelled nor missing container delete this return synchronized this can happen with the above activation and lazy query evaluation if scheduled logger error this already scheduled compression not rescheduling return scheduled true if logger should log logger minor this logger minor this compressing this orig data size orig data size for inserter ctx rc enqueue new job this objectcontainer clientcontext shouldlog origdata origdata shouldlog origdata origdata enqueuenewjob public void try compress final client context context throws insert exception logminor logger should log logger minor this long orig size orig data size compressor type best codec null bucket best compressed data orig data long best compressed data size orig size if logminor logger minor this attempt to compress the data try to compress the data try each algorithm starting with the fastest and weakest stop when run out of algorithms or the compressed data fits in a single block try bucket chain bucket factory bucket factory2 new bucket chain bucket factory bucket factory nodechk block size persistent context job runner null 1024 for final compressor type comp compressor type values boolean should free on finally true bucket result null try if logminor logger minor this attempt to compress using comp only produce if we are compressing the original data final int phase comp metadataid if persistent context job runner queue new db job public void run object container container client context context if container ext is stored inserter if logminor logger minor this already deleted start compression inserter for insert compressor this return if container ext is active inserter logger error this already active in start compression callback inserter container activate inserter 1 inserter on start compression comp container context container deactivate inserter 1 native thread norm priority 1 false else try inserter on start compression comp null context catch throwable t logger error this transient insert callback threw t t result comp compress orig data bucket factory2 orig size best compressed data size long result size result size min size is ssk block chk block max compressed data length if result size min size if logminor logger minor this new size result size smaller then min size min size best codec comp if best compressed data null best compressed data orig data don t need to remove from we haven t stored it best compressed data free best compressed data result best compressed data size result size should free on finally false break if result size best compressed data size if logminor logger minor this new size result size better than old best best compressed data size if best compressed data null best compressed data orig data best compressed data free best compressed data result best compressed data size result size best codec comp should free on finally false catch compression output size exception e continue try next compressor type finally if should free on finally result null result orig data result free final compression output output new compression output best compressed data best codec if persistent context job runner queue new db job public void run object container container client context context if container ext is stored inserter if logminor logger minor this already deleted inserter for insert compressor this container delete insert compressor this return if container ext is active inserter logger error this already active in compressed callback inserter container activate inserter 1 inserter on compressed output container context container deactivate inserter 1 container delete insert compressor this native thread norm priority 1 false else we do it off thread so that real compressor can release the semaphore context main executor execute new prio runnable public int get priority return native thread norm priority public void run try inserter on compressed output null context catch throwable t logger error this caught t running compression job t insert thread for this catch final io exception e if persistent context job runner queue new db job public void run object container container client context context if container ext is stored inserter if logminor logger minor this already deleted on failed inserter for insert compressor this container delete insert compressor this return if container ext is active inserter logger error this already active in compress failure callback inserter container activate inserter 1 container activate inserter cb 1 inserter cb on failure new insert exception insert exception bucket error e null inserter container context container deactivate inserter cb 1 container deactivate inserter 1 container delete insert compressor this native thread norm priority 1 false else inserter cb on failure new insert exception insert exception bucket error e null inserter null context trycompress clientcontext insertexception shouldlog origsize origdata compressor_type bestcodec bestcompresseddata origdata bestcompresseddatasize origsize bucketchainbucketfactory bucketfactory2 bucketchainbucketfactory bucketfactory block_size jobrunner compressor_type compressor_type shouldfreeonfinally jobrunner dbjob objectcontainer clientcontext isstored insertcompressor isactive onstartcompression nativethread norm_priority onstartcompression origdata bucketfactory2 origsize bestcompresseddatasize resultsize minsize sskblock chkblock max_compressed_data_length resultsize minsize resultsize minsize minsize bestcodec bestcompresseddata bestcompresseddata origdata removefrom bestcompresseddata bestcompresseddata bestcompresseddatasize resultsize shouldfreeonfinally resultsize bestcompresseddatasize resultsize bestcompresseddatasize bestcompresseddata bestcompresseddata origdata bestcompresseddata bestcompresseddata bestcompresseddatasize resultsize bestcodec shouldfreeonfinally compressionoutputsizeexception shouldfreeonfinally origdata compressionoutput compressionoutput bestcompresseddata bestcodec jobrunner dbjob objectcontainer clientcontext isstored insertcompressor insertcompressor isactive oncompressed insertcompressor nativethread norm_priority realcompressor mainexecutor priorunnable getpriority nativethread norm_priority oncompressed ioexception jobrunner dbjob objectcontainer clientcontext isstored insertcompressor insertcompressor isactive onfailure insertexception insertexception bucket_error insertcompressor nativethread norm_priority onfailure insertexception insertexception bucket_error public void run object container container client context context if container ext is stored inserter if logminor logger minor this already deleted start compression inserter for insert compressor this return if container ext is active inserter logger error this already active in start compression callback inserter container activate inserter 1 inserter on start compression comp container context container deactivate inserter 1 objectcontainer clientcontext isstored insertcompressor isactive onstartcompression public void run object container container client context context if container ext is stored inserter if logminor logger minor this already deleted inserter for insert compressor this container delete insert compressor this return if container ext is active inserter logger error this already active in compressed callback inserter container activate inserter 1 inserter on compressed output container context container deactivate inserter 1 container delete insert compressor this objectcontainer clientcontext isstored insertcompressor insertcompressor isactive oncompressed insertcompressor context main executor execute new prio runnable public int get priority return native thread norm priority mainexecutor priorunnable getpriority nativethread norm_priority public void run try inserter on compressed output null context catch throwable t logger error this caught t running compression job t oncompressed public void run object container container client context context if container ext is stored inserter if logminor logger minor this already deleted on failed inserter for insert compressor this container delete insert compressor this return if container ext is active inserter logger error this already active in compress failure callback inserter container activate inserter 1 container activate inserter cb 1 inserter cb on failure new insert exception insert exception bucket error e null inserter container context container deactivate inserter cb 1 container deactivate inserter 1 container delete insert compressor this objectcontainer clientcontext isstored insertcompressor insertcompressor isactive onfailure insertexception insertexception bucket_error insertcompressor create an insert compressor add it to the database schedule it param container param context param inserter2 param orig data2 param one block compressed size param bf return public static insert compressor start object container container client context context single file inserter inserter bucket orig data int min size bucket factory bf boolean persistent if persistent container null throw new illegal state exception starting compression persistent persistent but container container insert compressor compressor new insert compressor context nodedb handle inserter orig data min size bf persistent if persistent container store compressor compressor init container context return compressor insertcompressor origdata2 oneblockcompressedsize insertcompressor objectcontainer clientcontext singlefileinserter origdata minsize bucketfactory illegalstateexception insertcompressor insertcompressor nodedbhandle origdata minsize public static void load object container container client context context final long handle context nodedb handle query query container query query constrain insert compressor class query descend nodedb handle constrain handle object set insert compressor results query execute while results has next insert compressor comp results next if container ext is active comp logger error insert compressor class insert compressor not activated by query container activate comp 1 comp init container context objectcontainer clientcontext nodedbhandle insertcompressor nodedbhandle objectset insertcompressor hasnext insertcompressor isactive insertcompressor insertcompressor public void on failure final insert exception e client put state c client context context if persistent context job runner queue new db job public void run object container container client context context if container ext is active inserter logger error this already active in compress failure callback inserter container activate inserter 1 container activate inserter cb 1 inserter cb on failure e inserter container context container deactivate inserter cb 1 container deactivate inserter 1 container delete insert compressor this native thread norm priority 1 false else inserter cb on failure e inserter null context onfailure insertexception clientputstate clientcontext jobrunner dbjob objectcontainer clientcontext isactive onfailure insertcompressor nativethread norm_priority onfailure public void run object container container client context context if container ext is active inserter logger error this already active in compress failure callback inserter container activate inserter 1 container activate inserter cb 1 inserter cb on failure e inserter container context container deactivate inserter cb 1 container deactivate inserter 1 container delete insert compressor this objectcontainer clientcontext isactive onfailure insertcompressor construct a compound filter param filter1 the first filter param filter2 the second filter public compound filter buffered image op filter1 buffered image op filter2 this filter1 filter1 this filter2 filter2 compoundfilter compoundfilter bufferedimageop bufferedimageop public buffered image filter buffered image src buffered image dst buffered image image filter1 filter src dst image filter2 filter image dst return image bufferedimage bufferedimage bufferedimage bufferedimage public boolean add object obj if 0 index of obj return false return super add obj indexof public class os file implements i file public void write long pos byte buf try file seek pos file write buf 0 buf length catch io exception x throw new storage error storage error file access error x osfile ifile ioexception storageerror storageerror file_access_error public int read long pos byte buf try file seek pos return file read buf 0 buf length catch io exception x throw new storage error storage error file access error x ioexception storageerror storageerror file_access_error public void sync if no flush try file getfd sync catch io exception x throw new storage error storage error file access error x noflush ioexception storageerror storageerror file_access_error public void close try file close catch io exception x throw new storage error storage error file access error x ioexception storageerror storageerror file_access_error public boolean try lock boolean shared try lck file get channel try lock 0 long max value shared return lck null catch io exception x return true trylock getchannel trylock max_value ioexception public void lock boolean shared try lck file get channel lock 0 long max value shared catch io exception x throw new storage error storage error lock failed x getchannel max_value ioexception storageerror storageerror lock_failed public void unlock try lck release catch io exception x throw new storage error storage error lock failed x ioexception storageerror storageerror lock_failed public os file string file path boolean read only boolean no flush this no flush no flush try file new random access file file path read only r rw catch io exception x throw new storage error storage error file access error x osfile filepath readonly noflush noflush noflush randomaccessfile filepath readonly ioexception storageerror storageerror file_access_error public long length try return file length catch io exception x return 1 ioexception public download pluginhttp exception byte data string filename string mime type super ok none this data data this filename filename this mime type mime type downloadpluginhttpexception mimetype mimetype mimetype private static final long serial versionuid 1 public plugin not found exception super serialversionuid pluginnotfoundexception public plugin not found exception string arg0 super arg0 pluginnotfoundexception public plugin not found exception string arg0 throwable arg1 super arg0 arg1 pluginnotfoundexception public plugin not found exception throwable arg0 super arg0 pluginnotfoundexception private static final long serial versionuid 1 public not in trust tree exception string message super message serialversionuid notintrusttreeexception public node data node node boolean give opennet ref boolean with private boolean with volatile string identifier this node node this give opennet ref give opennet ref this with private with private this with volatile with volatile this identifier identifier nodedata giveopennetref withprivate withvolatile giveopennetref giveopennetref withprivate withprivate withvolatile withvolatile override public simple field set get field set simple field set fs if give opennet ref if with private fs node export opennet private field set else fs node export opennet public field set else if with private fs node export darknet private field set else fs node export darknet public field set if with volatile simple field set vol node export volatile field set if vol is empty fs put volatile vol if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset giveopennetref withprivate exportopennetprivatefieldset exportopennetpublicfieldset withprivate exportdarknetprivatefieldset exportdarknetpublicfieldset withvolatile simplefieldset exportvolatilefieldset isempty putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message node data goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message nodedata override public void remove from object container container container delete this removefrom objectcontainer public class relation impl m extends i persistent o extends i persistent extends relation m o public int size return link size relationimpl ipersistent ipersistent public void set size int new size link set size new size setsize newsize setsize newsize public boolean is empty return link is empty isempty isempty public boolean remove object o return link remove o public m get int i return link get i public i persistent get raw int i return link get raw i ipersistent getraw getraw public m set int i m obj return link set i obj public void set object int i m obj link set object i obj setobject setobject public void remove object int i link remove object i removeobject removeobject public m remove int i return link remove i public void insert int i m obj link insert i obj public void add int i m obj link add i obj public boolean add m obj return link add obj public void add all m arr link add all arr addall addall public void add all m arr int from int length link add all arr from length addall addall public boolean add all link m another link return link add all another link addall anotherlink addall anotherlink public i persistent to persistent array return link to persistent array ipersistent topersistentarray topersistentarray public i persistent to raw array return link to raw array ipersistent torawarray torawarray public object to array return link to array toarray toarray public t t to array t arr return link t to array arr toarray toarray public boolean contains object obj return link contains obj public boolean contains object m obj return link contains object obj containsobject containsobject public int index of object obj return link index of obj indexof indexof public int last index of object obj return link last index of obj lastindexof lastindexof public int index of object object obj return link index of object obj indexofobject indexofobject public int last index of object object obj return link last index of object obj lastindexofobject lastindexofobject public void clear link clear public iterator m iterator return link iterator public boolean contains all collection c return link contains all c containsall containsall public boolean contains element int i m obj return link contains element i obj containselement containselement public boolean add all collection extends m c return link add all c addall addall public boolean add all int index collection extends m c return link add all index c addall addall public boolean remove all collection c return link remove all c removeall removeall public boolean retain all collection c return link retain all c retainall retainall public void pin link pin public void unpin link unpin public list m sub list int from index int to index return link sub list from index to index sublist fromindex toindex sublist fromindex toindex public list iterator m list iterator int index return link list iterator index listiterator listiterator listiterator public list iterator m list iterator return link list iterator listiterator listiterator listiterator public iterable iterator m select class cls string predicate query m query new query impl m get storage return query select cls link iterator predicate iterableiterator queryimpl getstorage relation impl relationimpl relation impl relation impl o owner super owner link new link impl m 8 relationimpl relationimpl linkimpl public testdda complete message fcp connection handler handler dda check job job string read content this check job job this read content from client read content this handler handler testddacompletemessage fcpconnectionhandler ddacheckjob readcontent checkjob readcontentfromclient readcontent override public simple field set get field set simple field set sfs new simple field set true sfs put single testdda request message directory check job directory to string boolean is read allowed false boolean is write allowed false if check job read filename null is read allowed read content from client null check job read content equals read content from client cleanup in any case we created it let s hope the client will do the same on its side check job read filename delete sfs put single read allowed string value of is read allowed if check job write filename null file maybe written file check job write filename if maybe written file exists maybe written file is file maybe written file can read try is write allowed check job write content equals file util readutf maybe written file trim catch io exception e logger error this caught an ioe trying to read the file maybe written file e get message sfs put single write allowed string value of is write allowed fixme this really shouldn t be a side effect handler register testdda result check job directory to string is read allowed is write allowed return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle testddarequestmessage checkjob tostring isreadallowed iswriteallowed checkjob readfilename isreadallowed readcontentfromclient checkjob readcontent readcontentfromclient checkjob readfilename putsingle read_allowed valueof isreadallowed checkjob writefilename maybewrittenfile checkjob writefilename maybewrittenfile maybewrittenfile isfile maybewrittenfile canread iswriteallowed checkjob writecontent fileutil maybewrittenfile ioexception maybewrittenfile getmessage putsingle write_allowed valueof iswriteallowed registertestddaresult checkjob tostring isreadallowed iswriteallowed override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message name goes from server to client not the other way around name false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public class point3f extends tuple3f public point3f this 0 0 0 public point3f float x this x x 0 this y x 1 this z x 2 public point3f float x float y float z this x x this y y this z z public point3f point3f t this x t x this y t y this z t z public point3f tuple3f t this x t x this y t y this z t z public float distancel1 point3f p return math abs x p x math abs y p y math abs z p z public float distance squared point3f p float dx x p x float dy y p y float dz z p z return dx dx dy dy dz dz distancesquared public float distance point3f p float dx x p x float dy y p y float dz z p z return float math sqrt dx dx dy dy dz dz protected long count 0 public counted input stream input stream in super in if in null throw new illegal state exception null fed to counted input stream countedinputstream inputstream illegalstateexception countedinputstream public final long count return count override public int read throws io exception int ret super read if ret 1 count return ret ioexception override public int read byte buf int off int len throws io exception int ret in read buf off len if ret 1 count ret return ret ioexception override public int read byte buf throws io exception int ret in read buf if ret 1 count ret return ret ioexception override public long skip long n throws io exception long l in skip n if l 0 count l return l ioexception private static final long serial versionuid 1l public invalid encoded text exception string desc super desc serialversionuid invalidencodedtextexception public bitmap custom allocator storage storage int quantum long base long extension long limit super storage this quantum quantum this base base this limit limit int bits 0 for int q quantum q 1 q 1 bits 1 quantum bits bits assert that 1 bits quantum extension pages int extension long bitmap page bits quantum bits 1 long bitmap page bits quantum bits pages storage create link bitmapcustomallocator quantumbits extensionpages bitmap_page_bits quantumbits bitmap_page_bits quantumbits createlink protected bitmap custom allocator bitmapcustomallocator public long allocate long size size size quantum 1 quantum 1 long obj bit size size quantum bits long pos long hole bit size 0 int first page curr page int last page pages size int offs curr offs long last hole size 0 while true for int i first page i last page i bitmap page pg bitmap page pages get i while offs bitmap page size int mask pg data offs 0xff if hole bit size bitmap first hole size mask obj bit size pos base long i bitmap page size offs 8 hole bit size quantum bits long next pos was reserved pos size if next pos 0 long quant no next pos base quantum bits 7 i int quant no bitmap page bits offs int quant no long i bitmap page bits 3 hole bit size 0 continue curr page i curr offs offs pg data offs byte 1 int obj bit size hole bit size 1 pg modify if hole bit size 0 if hole bit size offs 8 memset pg 0 0xff offs hole bit size offs 8 pg bitmap page pages get i offs page page size while hole bit size bitmap page bits memset pg 0 0xff bitmap page size hole bit size bitmap page bits pg bitmap page pages get i while hole bit size 8 0 pg data offs byte 0xff pg data offs 1 byte 1 int hole bit size 1 pg modify return pos else if bitmap max hole size mask obj bit size int hole bit offset bitmap max hole offset mask pos base long i bitmap page size offs 8 hole bit offset quantum bits long next pos was reserved pos size if next pos 0 long quant no next pos base quantum bits 7 i int quant no bitmap page bits offs int quant no long i bitmap page bits 3 hole bit size 0 continue curr page i curr offs offs pg data offs byte 1 int obj bit size 1 hole bit offset pg modify return pos offs 1 if bitmap last hole size mask 8 hole bit size 8 else hole bit size bitmap last hole size mask offs 0 if first page 0 first page pages size int n pages int size bitmap page bits quantum last page first page n pages extension pages n pages extension pages if long last page bitmap page bits quantum limit throw new storage error storage error not enough space pages set size last page for int i first page i last page i bitmap page pg new bitmap page pg data new byte bitmap page size pages set object i pg hole bit size last hole size else last hole size hole bit size hole bit size 0 last page first page 1 first page 0 objbitsize quantumbits holebitsize firstpage currpage lastpage curroffs lastholesize firstpage lastpage bitmappage bitmappage bitmap_page_size holebitsize firstholesize objbitsize bitmap_page_size holebitsize quantumbits nextpos wasreserved nextpos quantno nextpos quantumbits quantno bitmap_page_bits quantno bitmap_page_bits holebitsize currpage curroffs objbitsize holebitsize holebitsize holebitsize holebitsize bitmappage pagesize holebitsize bitmap_page_bits bitmap_page_size holebitsize bitmap_page_bits bitmappage holebitsize holebitsize maxholesize objbitsize holebitoffset maxholeoffset bitmap_page_size holebitoffset quantumbits nextpos wasreserved nextpos quantno nextpos quantumbits quantno bitmap_page_bits quantno bitmap_page_bits holebitsize currpage curroffs objbitsize holebitoffset lastholesize holebitsize holebitsize lastholesize firstpage firstpage npages bitmap_page_bits lastpage firstpage npages extensionpages npages extensionpages lastpage bitmap_page_bits storageerror storageerror not_enough_space setsize lastpage firstpage lastpage bitmappage bitmappage bitmap_page_size setobject holebitsize lastholesize lastholesize holebitsize holebitsize lastpage firstpage firstpage public long reallocate long pos long old size long new size storage impl db storage impl get storage if new size quantum 1 quantum 1 old size quantum 1 quantum 1 long new pos allocate new size free0 pos old size pos new pos return pos oldsize newsize storageimpl storageimpl getstorage newsize oldsize newpos newsize oldsize newpos public void free long pos long size reserve pos size free0 pos size long size location long pos long size this pos pos this size size public int compare to object o location loc location o return pos size loc pos 1 loc pos loc size pos 1 0 compareto private long was reserved long pos long size location loc new location pos size location r location reserved get loc if r null return math max pos size r pos r size return 0 wasreserved private void reserve long pos long size location loc new location pos size reserved put loc loc private void free0 long pos long size long quant no pos base quantum bits long obj bit size size quantum 1 quantum bits int page id int quant no bitmap page bits int offs int quant no long page id bitmap page bits 3 bitmap page pg bitmap page pages get page id int bit offs int quant no 7 if obj bit size 8 bit offs obj bit size 8 bit offs pg data offs 1 bit offs 1 while obj bit size offs 8 bitmap page bits memset pg offs 0 bitmap page size offs pg bitmap page pages get page id obj bit size bitmap page size offs 8 offs 0 while obj bit size 8 0 pg data offs byte 0 pg data offs byte 1 int obj bit size 8 1 else pg data offs byte 1 int obj bit size 1 bit offs pg modify quantno quantumbits objbitsize quantumbits pageid quantno bitmap_page_bits quantno pageid bitmap_page_bits bitmappage bitmappage pageid bitoffs quantno objbitsize bitoffs objbitsize bitoffs bitoffs objbitsize bitmap_page_bits bitmap_page_size bitmappage pageid objbitsize bitmap_page_size objbitsize objbitsize objbitsize bitoffs static final void memset bitmap page pg int offs int pattern int len byte arr pg data byte pat byte pattern while len 0 arr offs pat pg modify bitmappage public void commit reserved clear construct a color map with a grayscale ramp from black to white public linear colormap this 0xff000000 0xffffffff linearcolormap construct a linear color map param color1 the color corresponding to value 0 in the colormap param color2 the color corresponding to value 1 in the colormap public linear colormap int color1 int color2 this color1 color1 this color2 color2 linearcolormap set the first color param color1 the color corresponding to value 0 in the colormap public void set color1 int color1 this color1 color1 setcolor1 get the first color return the color corresponding to value 0 in the colormap public int get color1 return color1 getcolor1 set the second color param color2 the color corresponding to value 1 in the colormap public void set color2 int color2 this color2 color2 setcolor2 get the second color return the color corresponding to value 1 in the colormap public int get color2 return color2 getcolor2 convert a value in the range 0 1 to an rgb color param v a value in the range 0 1 return an rgb color public int get color float v return image math mix colors image math clamp v 0 1 0f color1 color2 getcolor imagemath mixcolors imagemath construct an iterated filter param filter the filetr to iterate param iterations the number of iterations public iterated filter buffered image op filter int iterations this filter filter this iterations iterations iteratedfilter iteratedfilter bufferedimageop public buffered image filter buffered image src buffered image dst buffered image image src for int i 0 i iterations i image filter filter image dst return image bufferedimage bufferedimage bufferedimage bufferedimage query node visitor public void visit full text query visitor visitor visitor visit this fulltextqueryvisitor match node provides query constraint public boolean is constrained return true isconstrained public string to string return op match word word tostring match node constructor param op operation code should ne match or stict match param word searched word param pos position of word in the query public full text query match op int op string word int pos super op this word word this pos pos stict_match fulltextquerymatchop public subscription response set server u pnp get server name subscriptionresponse setserver upnp getservername public subscription response http response http res super http res subscriptionresponse httpresponse httpres httpres public void set response int code set status code code set content length 0 setresponse setstatuscode setcontentlength public void set error response int code set status code code set content length 0 seterrorresponse setstatuscode setcontentlength public void setsid string id set header http sid subscription tosid header string id setheader tosidheaderstring public string getsid return subscription getsid get header value http sid getheadervalue public void set timeout long value set header http timeout subscription to timeout header string value settimeout setheader totimeoutheaderstring public long get timeout return subscription get timeout get header value http timeout gettimeout gettimeout getheadervalue register me sendable request non get request short prio client request scheduler core core block set blocks long bootid this bootid bootid this core core this non get request non get request priority prio added time system current time millis this blocks blocks int hash core hash code hash non get request hash code hash prio hash code hash registerme sendablerequest nongetrequest clientrequestschedulercore blockset nongetrequest nongetrequest addedtime currenttimemillis hashcode nongetrequest hashcode hashcode override public int hash code return hash code hashcode hashcode public bulk receiver partially received bulk prb peer context peer long uid byte counter ctr this prb prb this peer peer this uid uid this peer bootid peer get bootid this ctr ctr prb recv this bulkreceiver partiallyreceivedbulk peercontext bytecounter peerbootid getbootid public void on aborted synchronized this if sent cancel return sent cancel true try peer send async dmt createfnp bulk receive aborted uid null ctr catch not connected exception e cool onaborted sentcancel sentcancel sendasync createfnpbulkreceiveaborted notconnectedexception receive the file return true if the whole file was received false otherwise public boolean receive while true message filter mf send killed message filter create set source peer set type dmt fnp bulk send aborted set field dmt uid uid set timeout timeout message filter mf packet message filter create set source peer set type dmt fnp bulk packet send set field dmt uid uid set timeout timeout if prb has whole file try peer send async dmt createfnp bulk received all uid null ctr catch not connected exception e ignore we have the data return true message m try m prb usm wait for mf send killed or mf packet ctr catch disconnected exception e prb abort retrieval exception sender disconnected sender disconnected return false if peer get bootid peer bootid prb abort retrieval exception sender died sender restarted return false if m null prb abort retrieval exception timed out sender timeout return false if m get spec dmt fnp bulk send aborted prb abort retrieval exception sender died sender cancelled send return false if m get spec dmt fnp bulk packet send int packet no m get int dmt packet no byte data short buffer m get object dmt data get data prb received packet no data 0 data length messagefilter mfsendkilled messagefilter setsource settype fnpbulksendaborted setfield settimeout messagefilter mfpacket messagefilter setsource settype fnpbulkpacketsend setfield settimeout haswholefile sendasync createfnpbulkreceivedall notconnectedexception waitfor mfsendkilled mfpacket disconnectedexception retrievalexception sender_disconnected getbootid peerbootid retrievalexception sender_died retrievalexception timed_out getspec fnpbulksendaborted retrievalexception sender_died getspec fnpbulkpacketsend packetno getint packet_no shortbuffer getobject getdata packetno config page xml spider xml spider this xml spider xml spider page maker xml spider get page maker pr xml spider get plugin respirator config xml spider get config configpage xmlspider xmlspider xmlspider xmlspider pagemaker xmlspider getpagemaker xmlspider getpluginrespirator xmlspider getconfig public synchronized void process post request http request request html node content node config xml spider get config clone if request is part set max parallel requests working int v request get int part max parallel requests working config get max parallel requests working config set max parallel requests working v if request is part set max parallel requests non working int v request get int part max parallel requests non working config get max parallel requests non working config set max parallel requests non working v if request is part set begin working period int v request get int part begin working period config get begin working period config set begin working period v if request is part set end working period int v request get int part end working period config get end working period config set end working period v if request is part set index max entries int v request get int part index max entries config get index max entries config set index max entries v if request is part set index subindex max size int v request get int part index subindex max size config get index subindex max size 1024 1024 config set index subindex max size v 1024 1024 if request is part set bad listed extensions string v request get part as string bad listed extensions 512 string v0 v split boolean good true for int i 0 i v0 length i v0 i v0 i trim if v0 i length 0 v0 i char at 0 good false break if good config set badlisted extensions v0 if request is part set index dir string v request get part as string index dir 256 config set index dir v if request is part set index title string v request get part as string index title 256 config set index title v if request is part set index owner string v request get part as string index owner 256 config set index owner v if request is part set index owner email string v request get part as string index owner email 256 config set index owner email v if request is part set debug string v request get part as string debug 10 config debug boolean value of v xml spider set config config processpostrequest httprequest htmlnode contentnode xmlspider getconfig ispartset maxparallelrequestsworking getintpart maxparallelrequestsworking getmaxparallelrequestsworking setmaxparallelrequestsworking ispartset maxparallelrequestsnonworking getintpart maxparallelrequestsnonworking getmaxparallelrequestsnonworking setmaxparallelrequestsnonworking ispartset beginworkingperiod getintpart beginworkingperiod getbeginworkingperiod setbeginworkingperiod ispartset endworkingperiod getintpart endworkingperiod getendworkingperiod setendworkingperiod ispartset indexmaxentries getintpart indexmaxentries getindexmaxentries setindexmaxentries ispartset indexsubindexmaxsize getintpart indexsubindexmaxsize getindexsubindexmaxsize setindexsubindexmaxsize ispartset badlistedextensions getpartasstring badlistedextensions charat setbadlistedextensions ispartset indexdir getpartasstring indexdir setindexdir ispartset indextitle getpartasstring indextitle setindextitle ispartset indexowner getpartasstring indexowner setindexowner ispartset indexowneremail getpartasstring indexowneremail setindexowneremail ispartset getpartasstring valueof xmlspider setconfig public void write content http request request html node content node html node config box page maker get infobox configuration html node config content page maker get content node config box html node config form pr add form child config content plugins xml spider xml spider config page config form config form add child div class configprefix spider options html node spider config config form add child ul class config add config spider config max parallel requests working maximum number of parallel requests if we are in the working period max parallel requests working new string 0 10 50 100 250 500 integer to string config get max parallel requests working add config spider config max parallel requests non working maximum number of parallel requests if we are not in the working period max parallel requests non working new string 0 10 50 100 250 500 integer to string config get max parallel requests non working add config spider config working period beginning hour beginning hour of the working period begin working period new string 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 integer to string config get begin working period add config spider config working period ending hour ending hour of the working period end working period new string 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 integer to string config get end working period add config spider config bad listed extensions comma seprated list of banned uri suffix bad listed extensions config get badlisted extensions addhtml spider config blar blar blar new html node a href blarla bla config form add child div class configprefix index writer options html node index config config form add child ul class config add config index config index directory directory where the index should be written to index dir config get index dir add config index config index title index title index title config get index title add config index config index owner index owner index owner config get index owner add config index config index owner email index owner email index owner email config get index owner email add config index config maximum subindex entries maximum number of entries in each index index max entries new string 500 1000 2000 4000 8000 integer to string config get index max entries add config index config maximum subindex size maximum size of a subindex mib index subindex max size new string 1 2 4 8 integer to string config get index subindex max size 1024 1024 add config index config write debug info write debug info debug new string false true boolean to string config is debug config form add child input new string type value new string submit apply content node add child config box writecontent httprequest htmlnode contentnode htmlnode configbox pagemaker getinfobox htmlnode configcontent pagemaker getcontentnode configbox htmlnode configform addformchild configcontent xmlspider xmlspider configpage configform configform addchild htmlnode spiderconfig configform addchild addconfig spiderconfig maxparallelrequestsworking tostring getmaxparallelrequestsworking addconfig spiderconfig maxparallelrequestsnonworking tostring getmaxparallelrequestsnonworking addconfig spiderconfig beginworkingperiod tostring getbeginworkingperiod addconfig spiderconfig endworkingperiod tostring getendworkingperiod addconfig spiderconfig badlistedextensions getbadlistedextensions spiderconfig htmlnode configform addchild htmlnode indexconfig configform addchild addconfig indexconfig indexdir getindexdir addconfig indexconfig indextitle getindextitle addconfig indexconfig indexowner getindexowner addconfig indexconfig indexowneremail getindexowneremail addconfig indexconfig indexmaxentries tostring getindexmaxentries addconfig indexconfig indexsubindexmaxsize tostring getindexsubindexmaxsize addconfig indexconfig tostring isdebug configform addchild contentnode addchild configbox private void addhtml html node config ui string short desc html node node html node li config ui add child li li add child span class configshortdesc short desc li add child span class config add child node htmlnode configui shortdesc htmlnode htmlnode configui addchild addchild shortdesc addchild addchild private void add config html node config ui string short desc string long desc string name string value html node li config ui add child li li add child span class configshortdesc short desc li add child span class config add child input new string class type name value new string config text name value li add child span class configlongdesc long desc addconfig htmlnode configui shortdesc longdesc htmlnode configui addchild addchild shortdesc addchild addchild addchild longdesc private void add config html node config ui string short desc string long desc string name string values string value html node li config ui add child li li add child span class configshortdesc short desc html node select li add child span class config add child select new string class name new string config name for string v values html node o select add child option value v v if v equals value o add attribute selected selected li add child span class configlongdesc long desc addconfig htmlnode configui shortdesc longdesc htmlnode configui addchild addchild shortdesc htmlnode addchild addchild htmlnode addchild addattribute addchild longdesc private void add config html node config ui string short desc string long desc string name string value string builder value2 new string builder value 0 for int i 1 i value length i value2 append value2 append value i html node li config ui add child li li add child span class configshortdesc short desc li add child span class config add child input new string class type name value new string config text name value2 to string li add child span class configlongdesc long desc addconfig htmlnode configui shortdesc longdesc stringbuilder stringbuilder htmlnode configui addchild addchild shortdesc addchild addchild tostring addchild longdesc override public url check source string source throws plugin not found exception try return new url source catch malformedurl exception e logger error this could not build plugin url for source e throw new plugin not found exception could not build plugin url for source e checksource pluginnotfoundexception malformedurlexception pluginnotfoundexception override input stream get input stream throws io exception url connection url connection get source open connection url connection set use caches false url connection set allow user interaction false url connection connect return open connection check redirects url connection inputstream getinputstream ioexception urlconnection urlconnection getsource openconnection urlconnection setusecaches urlconnection setallowuserinteraction urlconnection openconnectioncheckredirects urlconnection override string get plugin name string source throws plugin not found exception string name source substring source last index of 1 if name ends with url name name substring 0 name length 4 return name getpluginname pluginnotfoundexception lastindexof endswith override string getsha1sum throws plugin not found exception return null pluginnotfoundexception override string getsha256sum throws plugin not found exception return null pluginnotfoundexception static input stream open connection check redirects url connection c throws io exception boolean redir int redirects 0 input stream in null do if c instanceof httpurl connection httpurl connection c set instance follow redirects false we want to open the input stream before getting headers because get header field et al swallow io exceptions in c get input stream redir false if c instanceof httpurl connection httpurl connection http httpurl connection c int stat http get response code if stat 300 stat 307 stat 306 stat httpurl connection http not modified url base http geturl string loc http get header field location url target null if loc null target new url base loc http disconnect redirection should be allowed only for http and https and should be limited to 5 redirections at most if target null target get protocol equals http target get protocol equals https target get protocol equals ftp redirects 5 throw new security exception illegal url redirect redir true c target open connection redirects while redir return in inputstream openconnectioncheckredirects urlconnection ioexception inputstream httpurlconnection httpurlconnection setinstancefollowredirects getheaderfield ioexceptions getinputstream httpurlconnection httpurlconnection httpurlconnection getresponsecode httpurlconnection http_not_modified getheaderfield getprotocol getprotocol getprotocol securityexception openconnection public class fs parse exception extends exception private static final long serial versionuid 1 public fs parse exception exception e super e fsparseexception serialversionuid fsparseexception public fs parse exception string msg super msg fsparseexception get a list of fields which the database should create an index on protected static string get indexed fields return new string m tree owner m target getindexedfields mtreeowner mtarget creates a score from given parameters only for being used by the wot package and unit tests not for user interfaces param my tree owner the owner of the trust tree param my target the identity that has the score param my value the actual score of the identity param my rank how far the identity is from the tree s root param my capacity how much point the target identity can add to its trustees score public score own identity my tree owner identity my target int my value int my rank int my capacity if my tree owner null throw new null pointer exception if my target null throw new null pointer exception m tree owner my tree owner m target my target set value my value set rank my rank set capacity my capacity mytreeowner mytarget myvalue myrank mycapacity ownidentity mytreeowner mytarget myvalue myrank mycapacity mytreeowner nullpointerexception mytarget nullpointerexception mtreeowner mytreeowner mtarget mytarget setvalue myvalue setrank myrank setcapacity mycapacity override public synchronized string to string we do not synchronize on target and tree owner because nickname changes are not allowed the only thing which can happen is that we get a blank nickname if it has not been received yet that is not severe though return get target get nickname has get score points in get tree owner get nickname s trust tree rank get rank capacity get capacity tostring treeowner gettarget getnickname getscore gettreeowner getnickname getrank getcapacity return in which own identity s trust tree this score is public own identity get tree owner return m tree owner ownidentity ownidentity gettreeowner mtreeowner return identity that has this score public identity get target return m target gettarget mtarget return the numeric value of this score xxx rename to get value public synchronized int get score return m value getvalue getscore mvalue sets the numeric value of this score protected synchronized void set value int new value m value new value setvalue newvalue mvalue newvalue return how far the target identity is from the trust tree s root public synchronized int get rank return m rank getrank mrank sets how far the target identity is from the trust tree s root protected synchronized void set rank int new rank if new rank 1 throw new illegal argument exception illegal rank m rank new rank setrank newrank newrank illegalargumentexception mrank newrank return how much points the target identity can add to its trustees score public synchronized int get capacity return m capacity getcapacity mcapacity sets how much points the target identity can add to its trustees score protected synchronized void set capacity int new capacity if new capacity 0 throw new illegal argument exception negative capacities are not allowed m capacity new capacity setcapacity newcapacity newcapacity illegalargumentexception mcapacity newcapacity private float softness 0 public shine filter shinefilter public void set angle float angle this angle angle setangle public float get angle return angle getangle public void set distance float distance this distance distance setdistance public float get distance return distance getdistance set the radius of the kernel and hence the amount of blur the bigger the radius the longer this filter will take param radius the radius of the blur in pixels public void set radius float radius this radius radius setradius get the radius of the kernel return the radius public float get radius return radius getradius public void set bevel float bevel this bevel bevel setbevel public float get bevel return bevel getbevel public void set shine color int shine color this shine color shine color setshinecolor shinecolor shinecolor shinecolor public int get shine color return shine color getshinecolor shinecolor public void set shadow only boolean shadow only this shadow only shadow only setshadowonly shadowonly shadowonly shadowonly public boolean get shadow only return shadow only getshadowonly shadowonly public void set brightness float brightness this brightness brightness setbrightness public float get brightness return brightness getbrightness public void set softness float softness this softness softness setsoftness public float get softness return softness getsoftness public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null float x offset distance float math cos angle float y offset distance float math sin angle buffered image matte new buffered image width height buffered image type int argb erode alpha filter s new erode alpha filter bevel 10 0 75f 0 1f matte s filter src null buffered image shine layer new buffered image width height buffered image type int argb graphics2d g shine layer create graphics g set color new color shine color g fill rect 0 0 width height g set composite alpha composite dst in g draw rendered image matte null g set composite alpha composite dst out g translate x offset y offset g draw rendered image matte null g dispose shine layer new gaussian filter radius filter shine layer null shine layer new rescale filter 3 brightness filter shine layer shine layer g dst create graphics g draw rendered image src null g set composite new add composite 1 0f g draw rendered image shine layer null g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage xoffset yoffset bufferedimage bufferedimage bufferedimage type_int_argb erodealphafilter erodealphafilter bufferedimage shinelayer bufferedimage bufferedimage type_int_argb shinelayer creategraphics setcolor shinecolor fillrect setcomposite alphacomposite dstin drawrenderedimage setcomposite alphacomposite dstout xoffset yoffset drawrenderedimage shinelayer gaussianfilter shinelayer shinelayer rescalefilter shinelayer shinelayer creategraphics drawrenderedimage setcomposite addcomposite drawrenderedimage shinelayer override public string to string return stylize shine tostring public darknet peer node status darknet peer node peer node boolean no heavy super peer node no heavy this name peer node get name this burst only peer node is burst only this listening peer node is listen only this disabled peer node is disabled this private darknet comment note peer node get private darknet comment note darknetpeernodestatus darknetpeernode peernode noheavy peernode noheavy peernode getname burstonly peernode isburstonly peernode islistenonly peernode isdisabled privatedarknetcommentnote peernode getprivatedarknetcommentnote return the name public string get name return name getname return the burst only public boolean is burst only return burst only burstonly isburstonly burstonly return the disabled public boolean is disabled return disabled isdisabled return the listening public boolean is listening return listening islistening return the private darknet comment note public string get private darknet comment note return private darknet comment note privatedarknetcommentnote getprivatedarknetcommentnote privatedarknetcommentnote override public string to string return name super to string tostring tostring private static final boolean trace rijndael properties is traceable name private static void debug string s err println name s rijndael_properties istraceable private static void trace boolean in string s if trace err println in name s multiply two elements of gf 2 m private static final int mul int a int b return a 0 b 0 alog log a 0xff log b 0xff 255 0 convenience method used in generating transposition boxes private static final int mul4 int a byte b if a 0 return 0 a log a 0xff int a0 b 0 0 alog a log b 0 0xff 255 0xff 0 int a1 b 1 0 alog a log b 1 0xff 255 0xff 0 int a2 b 2 0 alog a log b 2 0xff 255 0xff 0 int a3 b 3 0 alog a log b 3 0xff 255 0xff 0 return a0 24 a1 16 a2 8 a3 convenience method to encrypt exactly one block of plaintext assuming rijndael s default block size 128 bit param in the plaintext param result the buffer into which to write the resulting ciphertext param in offset index of in from which to start considering data param session key the session key to use for encryption private static final void block encrypt byte in byte result int in offset object session key if rdebug trace in block encrypt in in offset session key int ke int object session key 0 extract encryption round keys int rounds ke length 1 int ker ke 0 plaintext to ints key int t0 in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff ker 0 int t1 in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff ker 1 int t2 in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff ker 2 int t3 in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff ker 3 int a0 a1 a2 a3 for int r 1 r rounds r apply round transforms ker ke r a0 t1 t0 24 0xff t2 t1 16 0xff t3 t2 8 0xff t4 t3 0xff ker 0 a1 t1 t1 24 0xff t2 t2 16 0xff t3 t3 8 0xff t4 t0 0xff ker 1 a2 t1 t2 24 0xff t2 t3 16 0xff t3 t0 8 0xff t4 t1 0xff ker 2 a3 t1 t3 24 0xff t2 t0 16 0xff t3 t1 8 0xff t4 t2 0xff ker 3 t0 a0 t1 a1 t2 a2 t3 a3 if rdebug debuglevel 6 system out println ct r int to string t0 int to string t1 int to string t2 int to string t3 last round is special ker ke rounds int tt ker 0 result 0 byte s t0 24 0xff tt 24 result 1 byte s t1 16 0xff tt 16 result 2 byte s t2 8 0xff tt 8 result 3 byte s t3 0xff tt tt ker 1 result 4 byte s t1 24 0xff tt 24 result 5 byte s t2 16 0xff tt 16 result 6 byte s t3 8 0xff tt 8 result 7 byte s t0 0xff tt tt ker 2 result 8 byte s t2 24 0xff tt 24 result 9 byte s t3 16 0xff tt 16 result 10 byte s t0 8 0xff tt 8 result 11 byte s t1 0xff tt tt ker 3 result 12 byte s t3 24 0xff tt 24 result 13 byte s t0 16 0xff tt 16 result 14 byte s t1 8 0xff tt 8 result 15 byte s t2 0xff tt if rdebug debuglevel 6 system out println ct to string result system out println if rdebug trace out block encrypt inoffset sessionkey blockencrypt inoffset sessionkey blockencrypt inoffset sessionkey sessionkey inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inttostring inttostring inttostring inttostring tostring blockencrypt convenience method to decrypt exactly one block of plaintext assuming rijndael s default block size 128 bit param in the ciphertext param result the resulting ciphertext param in offset index of in from which to start considering data param session key the session key to use for decryption private static final void block decrypt byte in byte result int in offset object session key if rdebug trace in block decrypt in in offset session key int kd int object session key 1 extract decryption round keys int rounds kd length 1 int kdr kd 0 ciphertext to ints key int t0 in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff kdr 0 int t1 in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff kdr 1 int t2 in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff kdr 2 int t3 in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff kdr 3 int a0 a1 a2 a3 for int r 1 r rounds r apply round transforms kdr kd r a0 t5 t0 24 0xff t6 t3 16 0xff t7 t2 8 0xff t8 t1 0xff kdr 0 a1 t5 t1 24 0xff t6 t0 16 0xff t7 t3 8 0xff t8 t2 0xff kdr 1 a2 t5 t2 24 0xff t6 t1 16 0xff t7 t0 8 0xff t8 t3 0xff kdr 2 a3 t5 t3 24 0xff t6 t2 16 0xff t7 t1 8 0xff t8 t0 0xff kdr 3 t0 a0 t1 a1 t2 a2 t3 a3 if rdebug debuglevel 6 system out println pt r int to string t0 int to string t1 int to string t2 int to string t3 last round is special kdr kd rounds int tt kdr 0 result 0 byte si t0 24 0xff tt 24 result 1 byte si t3 16 0xff tt 16 result 2 byte si t2 8 0xff tt 8 result 3 byte si t1 0xff tt tt kdr 1 result 4 byte si t1 24 0xff tt 24 result 5 byte si t0 16 0xff tt 16 result 6 byte si t3 8 0xff tt 8 result 7 byte si t2 0xff tt tt kdr 2 result 8 byte si t2 24 0xff tt 24 result 9 byte si t1 16 0xff tt 16 result 10 byte si t0 8 0xff tt 8 result 11 byte si t3 0xff tt tt kdr 3 result 12 byte si t3 24 0xff tt 24 result 13 byte si t2 16 0xff tt 16 result 14 byte si t1 8 0xff tt 8 result 15 byte si t0 0xff tt if rdebug debuglevel 6 system out println pt to string result system out println if rdebug trace out block decrypt inoffset sessionkey blockdecrypt inoffset sessionkey blockdecrypt inoffset sessionkey sessionkey inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inoffset inttostring inttostring inttostring inttostring tostring blockdecrypt a basic symmetric encryption decryption test static boolean self test return self test block size self_test self_test block_size return the default length in bytes of the algorithm input block static final int block size return block size blocksize block_size expand a user supplied key material into a session key param k the 128 192 256 bit user key to use param block size the block size in bytes of this rijndael exception invalid key exception if the key is invalid todo this method doesn t really need synchronization the only reason i can see for it to be synchronized is that it will consume 100 cpu due to heavy calculations when called probably should be unsynchronized if we want better support for dual cpu machines iakin 2003 10 12 concur the class has no fields which are not final and does not reference fields of any other classes control over how many simultaneous make key invocations should be allowed is a problem the callers should resolve among themselves it is a fact that allowing no more than one make key on any given cpu will result in fewer cache misses ejhuff 2003 10 12 final static synchronized object make key byte k int block size throws invalid key exception if rdebug trace in make key k block size if k null throw new invalid key exception empty key if k length 16 k length 24 k length 32 throw new invalid key exception incorrect key length int rounds get rounds k length block size int bc block size 4 int ke new int rounds 1 bc encryption round keys int kd new int rounds 1 bc decryption round keys int round key count rounds 1 bc int kc k length 4 int tk new int kc int i j copy user material bytes into temporary ints for i 0 j 0 i kc tk i k j 0xff 24 k j 0xff 16 k j 0xff 8 k j 0xff copy values into round key arrays int t 0 for j 0 j kc t round key count j t ke t bc t bc tk j kd rounds t bc t bc tk j int tt rconpointer 0 while t round key count extrapolate using phi the round key evolution function tt tk kc 1 tk 0 s tt 16 0xff 0xff 24 s tt 8 0xff 0xff 16 s tt 0xff 0xff 8 s tt 24 0xff 0xff rcon rconpointer 0xff 24 if kc 8 for i 1 j 0 i kc tk i tk j the above line replaced with the code below in order to work around a bug in the kjc 1 4f java compiler which has been reported tk i tk j i else for i 1 j 0 i kc 2 tk i tk j the above line replaced with the code below in order to work around a bug in the kjc 1 4f java compiler which has been reported tk i tk j i tt tk kc 2 1 tk kc 2 s tt 0xff 0xff s tt 8 0xff 0xff 8 s tt 16 0xff 0xff 16 s tt 24 0xff 0xff 24 for j kc 2 i j 1 i kc tk i tk j the above line replaced with the code below in order to work around a bug in the kjc 1 4f java compiler which has been reported tk i tk j i copy values into round key arrays for j 0 j kc t round key count j t ke t bc t bc tk j kd rounds t bc t bc tk j for int r 1 r rounds r inverse mix column where needed for j 0 j bc j tt kd r j kd r j u1 tt 24 0xff u2 tt 16 0xff u3 tt 8 0xff u4 tt 0xff assemble the encryption ke and decryption kd round keys into one session key object object session key new object ke kd if rdebug trace out make key return session key blocksize invalidkeyexception makekey makekey makekey blocksize invalidkeyexception makekey blocksize invalidkeyexception invalidkeyexception getrounds blocksize blocksize round_key_count round_key_count round_key_count round_key_count mixcolumn sessionkey sessionkey makekey sessionkey encrypt exactly one block of plaintext param in the plaintext param result the buffer into which to write the resulting ciphertext param in offset index of in from which to start considering data param session key the session key to use for encryption param block size the block size in bytes of this rijndael static final void block encrypt byte in byte result int in offset object session key int block size if block size block size block encrypt in result in offset session key return int bc block size 4 int a new int bc int t new int bc temporary work array block encrypt in result in offset session key block size a t inoffset sessionkey blocksize blockencrypt inoffset sessionkey blocksize blocksize block_size blockencrypt inoffset sessionkey blocksize blockencrypt inoffset sessionkey blocksize encrypt exactly one block of plaintext param in the plaintext param result the buffer into which to write the resulting ciphertext param in offset index of in from which to start considering data param session key the session key to use for encryption param block size the block size in bytes of this rijndael static final void block encrypt byte in byte result int in offset object session key int block size int a int t if block size block size block encrypt in result in offset session key return if rdebug trace in block encrypt in in offset session key block size object s key object session key extract encryption round keys int ke int s key 0 int bc block size 4 int rounds ke length 1 int sc bc 4 0 bc 6 1 2 int s1 shifts sc 1 0 int s2 shifts sc 2 0 int s3 shifts sc 3 0 int i int j 0 tt for i 0 i bc i plaintext to ints key t i in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff ke 0 i for int r 1 r rounds r apply round transforms for i 0 i bc i a i t1 t i 24 0xff t2 t i s1 bc 16 0xff t3 t i s2 bc 8 0xff t4 t i s3 bc 0xff ke r i system arraycopy a 0 t 0 bc if rdebug debuglevel 6 system out println ct r to string t for i 0 i bc i last round is special tt ke rounds i result j byte s t i 24 0xff tt 24 result j byte s t i s1 bc 16 0xff tt 16 result j byte s t i s2 bc 8 0xff tt 8 result j byte s t i s3 bc 0xff tt if rdebug debuglevel 6 system out println ct to string result system out println if rdebug trace out block encrypt inoffset sessionkey blocksize blockencrypt inoffset sessionkey blocksize blocksize block_size blockencrypt inoffset sessionkey blockencrypt inoffset sessionkey blocksize skey sessionkey skey blocksize inoffset inoffset inoffset inoffset tostring tostring blockencrypt decrypt exactly one block of ciphertext param in the ciphertext param result the resulting ciphertext param in offset index of in from which to start considering data param session key the session key to use for decryption param block size the block size in bytes of this rijndael static final void block decrypt byte in byte result int in offset object session key int block size if block size block size block decrypt in result in offset session key return if rdebug trace in block decrypt in in offset session key block size object s key object session key extract decryption round keys int kd int s key 1 int bc block size 4 int rounds kd length 1 int sc bc 4 0 bc 6 1 2 int s1 shifts sc 1 1 int s2 shifts sc 2 1 int s3 shifts sc 3 1 int a new int bc int t new int bc temporary work array int i int j 0 tt for i 0 i bc i ciphertext to ints key t i in in offset 0xff 24 in in offset 0xff 16 in in offset 0xff 8 in in offset 0xff kd 0 i for int r 1 r rounds r apply round transforms for i 0 i bc i a i t5 t i 24 0xff t6 t i s1 bc 16 0xff t7 t i s2 bc 8 0xff t8 t i s3 bc 0xff kd r i system arraycopy a 0 t 0 bc if rdebug debuglevel 6 system out println pt r to string t for i 0 i bc i last round is special tt kd rounds i result j byte si t i 24 0xff tt 24 result j byte si t i s1 bc 16 0xff tt 16 result j byte si t i s2 bc 8 0xff tt 8 result j byte si t i s3 bc 0xff tt if rdebug debuglevel 6 system out println pt to string result system out println if rdebug trace out block decrypt inoffset sessionkey blocksize blockdecrypt inoffset sessionkey blocksize blocksize block_size blockdecrypt inoffset sessionkey blockdecrypt inoffset sessionkey blocksize skey sessionkey skey blocksize inoffset inoffset inoffset inoffset tostring tostring blockdecrypt a basic symmetric encryption decryption test for a given key size private static boolean self test int keysize if rdebug trace in self test keysize boolean ok false try byte kb new byte keysize byte pt new byte block size int i for i 0 i keysize i kb i byte i for i 0 i block size i pt i byte i if rdebug debuglevel 6 system out println system out println system out println keysize 8 keysize system out println key to string kb system out println object key make key kb block size if rdebug debuglevel 6 system out println intermediate ciphertext values encryption system out println system out println pt to string pt byte ct new byte block size block encrypt pt ct 0 key block size if rdebug debuglevel 6 system out println intermediate plaintext values decryption system out println system out println ct to string ct byte cpt new byte block size block decrypt ct cpt 0 key block size ok are equal pt cpt if ok throw new runtime exception symmetric operation failed catch exception x if rdebug debuglevel 0 debug exception encountered during self test x get message x print stack trace if rdebug debuglevel 0 debug self test ok ok if rdebug trace out self test return ok self_test self_test block_size block_size tostring makekey block_size tostring block_size blockencrypt block_size tostring block_size blockdecrypt block_size areequal runtimeexception getmessage printstacktrace self_test return the number of rounds for a given rijndael s key and block sizes param key size the size of the user key material in bytes param block size the desired block size in bytes return the number of rounds for a given rijndael s key and block sizes private static final int get rounds int key size int block size switch key size case 16 return block size 16 10 block size 24 12 14 case 24 return block size 32 12 14 default 32 bytes 256 bits return 14 keysize blocksize getrounds keysize blocksize keysize blocksize blocksize blocksize compares two byte arrays for equality return true if the arrays have identical contents private static final boolean are equal byte a byte b int a length a length if a length b length return false for int i 0 i a length i if a i b i return false return true areequal alength alength alength returns a string of 2 hexadecimal digits most significant digit first corresponding to the lowest 8 bits of i n i private static final string byte to string int n char buf hex digits n 4 0x0f hex digits n 0x0f return new string buf bytetostring hex_digits hex_digits returns a string of 8 hexadecimal digits most significant digit first corresponding to the integer i n i which is treated as unsigned private static final string int to string int n char buf new char 8 for int i 7 i 0 i buf i hex digits n 0x0f n 4 return new string buf inttostring hex_digits returns a string of hexadecimal digits from a byte array each byte is converted to 2 hex symbols private static final string to string byte ba int length ba length char buf new char length 2 for int i 0 j 0 k i length k ba i buf j hex digits k 4 0x0f buf j hex digits k 0x0f return new string buf tostring hex_digits hex_digits returns a string of hexadecimal digits from an integer array each int is converted to 4 hex symbols private static final string to string int ia int length ia length char buf new char length 8 for int i 0 j 0 k i length i k ia i buf j hex digits k 28 0x0f buf j hex digits k 24 0x0f buf j hex digits k 20 0x0f buf j hex digits k 16 0x0f buf j hex digits k 12 0x0f buf j hex digits k 8 0x0f buf j hex digits k 4 0x0f buf j hex digits k 0x0f return new string buf tostring hex_digits hex_digits hex_digits hex_digits hex_digits hex_digits hex_digits hex_digits public static void main string args self test 16 self test 24 self test 32 self_test self_test self_test construct a motion blur op public motion blur op motionblurop motionblurop construct a motion blur op param distance the distance of blur param angle the angle of blur param rotation the angle of rotation param zoom the zoom factor public motion blur op float distance float angle float rotation float zoom this distance distance this angle angle this rotation rotation this zoom zoom motionblurop motionblurop specifies the angle of blur param angle the angle of blur angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of blur return the angle of blur see set angle public float get angle return angle setangle getangle set the distance of blur param distance the distance of blur see get distance public void set distance float distance this distance distance getdistance setdistance get the distance of blur return the distance of blur see set distance public float get distance return distance setdistance getdistance set the blur rotation param rotation the angle of rotation see get rotation public void set rotation float rotation this rotation rotation getrotation setrotation get the blur rotation return the angle of rotation see set rotation public float get rotation return rotation setrotation getrotation set the blur zoom param zoom the zoom factor see get zoom public void set zoom float zoom this zoom zoom getzoom setzoom get the blur zoom return the zoom factor see set zoom public float get zoom return zoom setzoom getzoom set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre private int log2 int n int m 1 int log2n 0 while m n m 2 log2n return log2n public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null buffered image tsrc src float cx float src get width centrex float cy float src get height centrey float image radius float math sqrt cx cx cy cy float translatex float distance math cos angle float translatey float distance math sin angle float scale zoom float rotate rotation float max distance distance math abs rotation image radius zoom image radius int steps log2 int max distance translatex max distance translatey max distance scale max distance rotate max distance if steps 0 graphics2d g dst create graphics g draw rendered image src null g dispose return dst buffered image tmp create compatible dest image src null for int i 0 i steps i graphics2d g tmp create graphics g draw image tsrc null null g set rendering hint rendering hints key antialiasing rendering hints value antialias on g set rendering hint rendering hints key interpolation rendering hints value interpolation bilinear g set composite alpha composite get instance alpha composite src over 0 5f g translate cx translatex cy translatey g scale 1 0001 scale 1 0001 scale the 0001 works round a bug on windows where draw image throws an array index outof bound exception if rotation 0 g rotate rotate g translate cx cy g draw image dst null null g dispose buffered image ti dst dst tmp tmp ti tsrc dst translatex 2 translatey 2 scale 2 rotate 2 return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage bufferedimage getwidth getheight imageradius maxdistance imageradius imageradius maxdistance maxdistance maxdistance maxdistance maxdistance creategraphics drawrenderedimage bufferedimage createcompatibledestimage creategraphics drawimage setrenderinghint renderinghints key_antialiasing renderinghints value_antialias_on setrenderinghint renderinghints key_interpolation renderinghints value_interpolation_bilinear setcomposite alphacomposite getinstance alphacomposite src_over drawimage arrayindexoutofboundexception drawimage bufferedimage override public string to string return blur faster motion blur tostring final trivial running average mean public median mean running average reports new array list double mean new trivial running average trivialrunningaverage medianmeanrunningaverage arraylist trivialrunningaverage public median mean running average median mean running average average this mean new trivial running average average mean this reports new array list double reports add all average reports medianmeanrunningaverage medianmeanrunningaverage trivialrunningaverage arraylist addall override public object clone synchronized this return new median mean running average this medianmeanrunningaverage public synchronized long count reports return reports size countreports public synchronized double current value int size reports size int middle size 2 java util collections sort reports return reports get middle currentvalue public synchronized void report double d mean report d reports add d public void report long d report double d public double value if reported double r throw new unsupported operation exception valueifreported unsupportedoperationexception override public synchronized string to string return median current value mean mean current value tostring currentvalue currentvalue public synchronized double mean value return mean current value meanvalue currentvalue private int unsigned byte byte b if b 0 return b else return 256 b unsignedbyte public int read int data input stream dis throws io exception int result byte data new byte 4 result dis read data if result 0 end of file reached throw new eof exception result unsigned byte data 2 16 unsigned byte data 1 8 unsigned byte data 0 result unsigned byte data 3 24 return result readint datainputstream ioexception eofexception unsignedbyte unsignedbyte unsignedbyte unsignedbyte public int read short data input stream dis throws io exception int result dis read if result 0 end of file reached throw new eof exception int r2 dis read if r2 0 end of file reached throw new eof exception return result r2 256 readshort datainputstream ioexception eofexception eofexception public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception if data size 54 size of the bmp header is 54 throw header error l10n too short file l10n the file is too short to contain a bmp header input stream is data get input stream buffered input stream bis new buffered input stream is data input stream dis new data input stream bis try byte start word new byte 2 dis read fully start word if arrays equals start word bmp headerwindows arrays equals start word bmp headeros2b array arrays equals start word bmp headeros2c icon arrays equals start word bmp headeros2c pointer arrays equals start word bmp headeros2 icon arrays equals start word bmp headeros2 pointer checking the first word throw header error l10n invalid start word l10n invalid header int file size read int dis read total file size byte skipbytes new byte 4 dis read fully skipbytes int header size read int dis read file header size or pixel offset if header size 0 throw header error l10n invalid offset l10n image has invalid pixel offset of header size int size bitmapinfoheader read int dis if size bitmapinfoheader 40 throw header error l10n invalid bit map info header size l10n size of bitmap info header is not 40 int image width read int dis read width int image height read int dis read height if image width 0 image height 0 throw header error l10n invalid dimensions l10n the image has invalid width or height int no plane read short dis if no plane 1 no of planes should be 1 throw header error l10n invalid no of plannes l10n the image has no plane planes int bit depth read short dis bit depth should be 1 2 4 8 16 or 32 if bit depth 1 bit depth 2 bit depth 4 bit depth 8 bit depth 16 bit depth 24 bit depth 32 throw header error l10n invalid bit depth l10n the bit depth field is set to bit depth it is not of 1 2 4 8 16 and 32 int compression type read int dis if compression type 0 compression type 3 throw header error l10n invalid compression type l10n compression type field is set to compression type instead of 0 3 int imagedatasize read int dis if file size header size imagedatasize throw header error l10n invalid file size l10n file size is not matching to headersize imagedatasize int horizontal resolution read int dis int vertical resolution read int dis if horizontal resolution 0 vertical resolution 0 throw header error l10n invalid resolution l10n this image file has resolution of horizontal resolution x vertical resolution if compression type 0 verifying the file size w r t image dimensions width and height bit depth with imagedatasize including padding int bytesperline int math ceil image width bit depth 8 int paddingperline 0 if bytesperline 4 0 paddingperline 4 bytesperline 4 int calculatedsize int math ceil image width image height bit depth 8 paddingperline image height if calculatedsize imagedatasize throw header error l10n invalid size of image data l10n the calculated image data size calculatedsize is not matching with the actual size imagedatasize dis close finally closer close dis return data readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception throwheadererror inputstream getinputstream bufferedinputstream bufferedinputstream datainputstream datainputstream startword readfully startword startword bmpheaderwindows startword bmpheaderos2barray startword bmpheaderos2cicon startword bmpheaderos2cpointer startword bmpheaderos2icon startword bmpheaderos2pointer throwheadererror invalidheader filesize readint readfully headersize readint headersize throwheadererror headersize size_bitmapinfoheader readint size_bitmapinfoheader throwheadererror imagewidth readint imageheight readint imagewidth imageheight throwheadererror no_plane readshort no_plane throwheadererror no_plane bitdepth readshort bitdepth bitdepth bitdepth bitdepth bitdepth bitdepth bitdepth throwheadererror bitdepth compression_type readint compression_type compression_type throwheadererror compression_type readint filesize headersize throwheadererror horizontal_resolution readint vertical_resolution readint horizontal_resolution vertical_resolution throwheadererror horizontal_resolution vertical_resolution compression_type bitdepth imagewidth bitdepth imagewidth imageheight bitdepth imageheight throwheadererror private static string l10n string key return l10n get string bmp filter key getstring bmpfilter private void throw header error string short reason string reason throws data filter exception throw an exception string message l10n notbmp if reason null message reason if short reason null message short reason throw new data filter exception short reason short reason p message p new html node p add child message throwheadererror shortreason datafilterexception shortreason shortreason datafilterexception shortreason shortreason htmlnode addchild public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception return null writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception private final short restart prio native thread high priority public segmented bucket chain bucket kill job segmented bucket chain bucket bucket bcb bucket restart_prio nativethread high_priority segmentedbucketchainbucketkilljob segmentedbucketchainbucket public void run object container container client context context container activate bcb 2 logger normal this freeing unfinished unstored bucket this restart jobs runner will remove us from the queue this may take more than one transaction if bcb remove contents container more work needs to be done we will have already been removed so re add in case we crash soon schedule restart container context context persistent bucket factory add blob free callback this but try to sort it out now context job runner queue this native thread norm priority true else context job runner remove restart job this restart prio container container delete this context persistent bucket factory remove blob free callback this objectcontainer clientcontext removecontents schedulerestart persistentbucketfactory addblobfreecallback jobrunner nativethread norm_priority jobrunner removerestartjob restart_prio persistentbucketfactory removeblobfreecallback public void schedule restart object container container client context context context job runner queue restart job this restart prio container true schedulerestart objectcontainer clientcontext jobrunner queuerestartjob restart_prio private container size sizefiles 0 sizefilesnolimit 0 sizesubtrees 0 sizesubtreesnolimit 0 containersize _sizefiles _sizefilesnolimit _sizesubtrees _sizesubtreesnolimit public long get size total return sizefiles sizesubtrees getsizetotal _sizefiles _sizesubtrees public long get size total no limit return sizefilesnolimit sizesubtreesnolimit getsizetotalnolimit _sizefilesnolimit _sizesubtreesnolimit public long get size files return sizefiles getsizefiles _sizefiles public long get size files no limit return sizefilesnolimit getsizefilesnolimit _sizefilesnolimit public long get size sub trees return sizesubtrees getsizesubtrees _sizesubtrees public long get size sub trees no limit return sizesubtreesnolimit getsizesubtreesnolimit _sizesubtreesnolimit private container size estimator containersizeestimator public static container size get sub tree size hash map string object metadata long max item size long max container size int max deep container size result new container size get sub tree size metadata result max item size max container size max deep return result containersize getsubtreesize hashmap maxitemsize maxcontainersize maxdeep containersize containersize getsubtreesize maxitemsize maxcontainersize maxdeep private static void get sub tree size hash map string object metadata container size result long max item size long max container size int max deep set string set metadata key set files for string name set object o metadata get name if o instanceof manifest element manifest element me manifest element o long itemsize me get size if itemsize 1 result sizefilesnolimit get container item size me get size if itemsize max item size result sizefiles 512 spare for redirect else result sizefiles get container item size me get size if result sizefiles max container size break sub dirs if max deep 0 for string name set object o metadata get name if o instanceof hash map result sizesubtrees 512 suppress warnings unchecked hash map string object hm hash map string object o container size temp result new container size get sub tree size hm temp result max item size max container size result sizesubtrees max deep 1 result sizesubtrees temp result get size total result sizesubtreesnolimit temp result get size total no limit if result sizesubtrees max container size break getsubtreesize hashmap containersize maxitemsize maxcontainersize maxdeep keyset manifestelement manifestelement manifestelement getsize _sizefilesnolimit getcontaineritemsize getsize maxitemsize _sizefiles _sizefiles getcontaineritemsize getsize _sizefiles maxcontainersize maxdeep hashmap _sizesubtrees suppresswarnings hashmap hashmap containersize tempresult containersize getsubtreesize tempresult maxitemsize maxcontainersize _sizesubtrees maxdeep _sizesubtrees tempresult getsizetotal _sizesubtreesnolimit tempresult getsizetotalnolimit _sizesubtrees maxcontainersize public static long get container item size long size return get container item size default archive type size getcontaineritemsize getcontaineritemsize default_archive_type private static long get container item size archive type archive type long size if archive type archive type tar return tar item size size throw new unsupported operation exception todo only tar supportet atm getcontaineritemsize archive_type archivetype archivetype archive_type taritemsize unsupportedoperationexception public static final long tar item size long size return 512 size 511 512 512 taritemsize create a simple field set param short lived if false strings will be interned to ensure that they use as little memory as possible only set to true if the sfs will be short lived or small public simple field set boolean short lived values new hash map string string subsets null this short lived short lived simplefieldset shortlived simplefieldset shortlived hashmap shortlived shortlived construct a simple field set from reading a buffered reader param br param allow multiple if true multiple lines with the same field name will be combined if false the constructor will throw param short lived if false strings will be interned to ensure that they use as little memory as possible only set to true if the sfs will be short lived or small throws io exception if the buffer could not be read or if there was a formatting problem public simple field set buffered reader br boolean allow multiple boolean short lived throws io exception this short lived read br allow multiple simplefieldset bufferedreader allowmultiple shortlived ioexception simplefieldset bufferedreader allowmultiple shortlived ioexception shortlived allowmultiple public simple field set simple field set sfs values new hash map string string sfs values if sfs subsets null subsets new hash map string simple field set sfs subsets this short lived false it s been copied end marker sfs end marker simplefieldset simplefieldset hashmap hashmap simplefieldset shortlived endmarker endmarker public simple field set line reader lis int max line length int line buffer size boolean tolerant boolean utf8 or iso88591 boolean allow multiple boolean short lived throws io exception this short lived read lis max line length line buffer size tolerant utf8 or iso88591 allow multiple simplefieldset linereader maxlinelength linebuffersize utf8oriso88591 allowmultiple shortlived ioexception shortlived maxlinelength linebuffersize utf8oriso88591 allowmultiple construct from a string string format blah blah blah blah end param short lived if false strings will be interned to ensure that they use as little memory as possible only set to true if the sfs will be short lived or small throws io exception if the string is too short or invalid public simple field set string content boolean allow multiple boolean short lived throws io exception this short lived string reader sr new string reader content buffered reader br new buffered reader sr read br allow multiple shortlived ioexception simplefieldset allowmultiple shortlived ioexception shortlived stringreader stringreader bufferedreader bufferedreader allowmultiple read from disk format blah blah blah blah end param allow multiple private void read buffered reader br boolean allow multiple throws io exception boolean first line true while true string line br read line if line null if first line throw new eof exception throw new io exception no end marker first line false int index line index of keyvalue separator char if index 0 mapping string before line substring 0 index string after line substring index 1 if short lived after after intern put before after allow multiple false else end marker line return allowmultiple bufferedreader allowmultiple ioexception firstline readline firstline eofexception ioexception firstline indexof keyvalue_separator_char shortlived allowmultiple endmarker read from disk format blah blah blah blah end param utf or iso88591 if true read as utf 8 otherwise read as iso 8859 1 private void read line reader br int max length int buffer size boolean tolerant boolean utf or iso88591 boolean allow multiple throws io exception boolean first line true while true string line br read line max length buffer size utf or iso88591 if line null if first line throw new eof exception if tolerant logger error this no end marker else throw new io exception no end marker return if line length 0 tolerant continue ignore first line false int index line index of keyvalue separator char if index 0 mapping string before line substring 0 index string after line substring index 1 if short lived after after intern put before after allow multiple false else end marker line return utforiso88591 linereader maxlength buffersize utforiso88591 allowmultiple ioexception firstline readline maxlength buffersize utforiso88591 firstline eofexception ioexception firstline indexof keyvalue_separator_char shortlived allowmultiple endmarker public synchronized string get string key int idx key index of multi level char if idx 1 return values get key else if idx 0 return subset null null subset get key substring 1 else if subsets null return null string before key substring 0 idx string after key substring idx 1 simple field set fs subsets get before if fs null return null return fs get after indexof multi_level_char simplefieldset public string get all string key string k get key if k null return null return split k getall private static final string split string string if string null return empty string array return string split string value of multi value char slower int index string index of if index 1 return null vector v new vector v remove all elements while index 0 mapping string before string substring 0 index string after string substring index 1 v add element before string after index string index of return string v to array empty_string_array valueof multi_value_char indexof removeallelements addelement indexof toarray private static final string unsplit string strings string builder sb new string builder for int i 0 i strings length i if i 0 sb append multi value char sb append strings i return sb to string stringbuilder stringbuilder multi_value_char tostring put contents of a fieldset overwrite old values public void put all overwrite simple field set fs iterator string i fs values key set iterator while i has next string key i next string his val fs values get key values put key his val overwrite old if fs subsets null return if subsets null subsets new hash map string simple field set i fs subsets key set iterator while i has next string key i next simple field set hisfs fs subsets get key simple field set myfs subsets get key if myfs null myfs put all overwrite hisfs else subsets put key hisfs putalloverwrite simplefieldset keyset hasnext hisval hisval hashmap simplefieldset keyset hasnext simplefieldset simplefieldset putalloverwrite set a key to a value if the value already exists throw illegal state exception param key the key param value the value public void put single string key string value if value null return if short lived value value intern if put key value false false throw new illegal state exception value already exists value but want to set key to value illegalstateexception putsingle shortlived illegalstateexception aggregating put set a key to a value if the value already exists append to it if you do not need this functionality please use put overwrite for a minimal performance gain param key the key param value the value public void put append string key string value if value null return if short lived value value intern put key value true false putoverwrite putappend shortlived set a key to a value overwriting any existing value if present this function is a little bit faster than put append because it does not check whether the key already exists param key the key param value the value public void put overwrite string key string value if value null return if short lived value value intern put key value false true putappend putoverwrite shortlived set a key to a value param key the key param value the value param allow multiple if true if the key already exists then the value will be appended to the existing value if false we return false to indicate that the old value is unchanged return true unless allow multiple was false and there was a pre existing value or value was null private synchronized final boolean put string key string value boolean allow multiple boolean overwrite int idx if value null return true valid no op if value index of n 1 throw new illegal argument exception a simplefield set can t accept newlines if idx key index of multi level char 1 if short lived key key intern if overwrite values put key value else if values get key null values put key value else if allow multiple return false values put key values get key multi value char value else string before key substring 0 idx string after key substring idx 1 simple field set fs null if subsets null subsets new hash map string simple field set fs subsets get before if fs null fs new simple field set short lived if short lived before before intern subsets put before fs fs put after value allow multiple overwrite return true allowmultiple allowmultiple allowmultiple indexof illegalargumentexception simplefieldset indexof multi_level_char shortlived allowmultiple multi_value_char simplefieldset hashmap simplefieldset simplefieldset shortlived shortlived allowmultiple public void put string key int value use put single so it does the intern check put single key integer to string value putsingle putsingle tostring public void put string key long value put single key long to string value putsingle tostring public void put string key short value put single key short to string value putsingle tostring public void put string key char c put single key character to string c putsingle tostring public void put string key boolean b don t use put single avoid intern check boolean to string returns interned strings anyway put key boolean to string b false false putsingle tostring tostring public void put string key double window size put single key double to string window size windowsize putsingle tostring windowsize write the contents of the simple field set to a writer note the caller must buffer the writer to avoid lousy performance string writer is by definition buffered otherwise wrap it in a buffered writer warning keep in mind that a writer is not necessarily utf 8 public void write to writer w throws io exception write to w false simplefieldset stringwriter bufferedwriter writeto ioexception writeto write the contents of the simple field set to a writer note the caller must buffer the writer to avoid lousy performance string writer is by definition buffered otherwise wrap it in a buffered writer warning keep in mind that a writer is not necessarily utf 8 synchronized void write to writer w string prefix boolean no end marker throws io exception for iterator map entry string string i values entry set iterator i has next map entry string string entry i next string key entry get key string value entry get value w write prefix w write key w write keyvalue separator char w write value w write n if subsets null for iterator map entry string simple field set i subsets entry set iterator i has next map entry string simple field set entry i next string key entry get key simple field set subset entry get value if subset null throw new null pointer exception subset write to w prefix key multi level char true if no end marker if end marker null w write end n else w write end marker w write n simplefieldset stringwriter bufferedwriter writeto noendmarker ioexception entryset hasnext getkey getvalue keyvalue_separator_char simplefieldset entryset hasnext simplefieldset getkey simplefieldset getvalue nullpointerexception writeto multi_level_char noendmarker endmarker endmarker public void write to ordered writer w throws io exception write to ordered w false writetoordered ioexception writetoordered private synchronized void write to ordered writer w string prefix boolean no end marker throws io exception string keys values key set to array new string values size int i 0 sort arrays sort keys output for i 0 i keys length i w write prefix keys i keyvalue separator char get keys i n if subsets null string ordered prefixes subsets key set to array new string subsets size sort arrays sort ordered prefixes for i 0 i ordered prefixes length i simple field set subset subset ordered prefixes i if subset null throw new null pointer exception subset write to ordered w prefix ordered prefixes i multi level char true if no end marker if end marker null w write end n else w write end marker n writetoordered noendmarker ioexception keyset toarray keyvalue_separator_char orderedprefixes keyset toarray orderedprefixes orderedprefixes simplefieldset orderedprefixes nullpointerexception writetoordered orderedprefixes multi_level_char noendmarker endmarker endmarker override public string to string string writer sw new string writer try write to sw catch io exception e logger error this wtf e in to string e return sw to string tostring stringwriter stringwriter writeto ioexception tostring tostring public string to ordered string string writer sw new string writer try write to ordered sw catch io exception e logger error this wtf e in to string e return sw to string toorderedstring stringwriter stringwriter writetoordered ioexception tostring tostring public string get end marker return end marker getendmarker endmarker public void set end marker string s end marker s setendmarker endmarker public synchronized simple field set subset string key if subsets null return null int idx key index of multi level char if idx 1 return subsets get key string before key substring 0 idx string after key substring idx 1 simple field set fs subsets get before if fs null return null return fs subset after simplefieldset indexof multi_level_char simplefieldset like subset only throws instead of returning null throws fs parse exception public synchronized simple field set get subset string key throws fs parse exception simple field set fs subset key if fs null throw new fs parse exception no such subset key return fs fsparseexception simplefieldset getsubset fsparseexception simplefieldset fsparseexception public iterator string key iterator return new key iterator keyiterator keyiterator public key iterator key iterator string prefix return new key iterator prefix keyiterator keyiterator keyiterator public iterator string toplevel key iterator return values key set iterator toplevelkeyiterator keyset it provides an iterator for the simple set field which passes through every key e g for key1 value1 key2 sub2 value2 key1 sub value3 it will provide key1 key2 sub2 key1 sub param a prefix to put before every key e g for key1 value if the iterator is created with prefix a prefix it will provide a prefixkey1 public key iterator string prefix synchronized simple field set this values iterator values key set iterator if subsets null subset iterator subsets key set iterator else subset iterator null while true if values iterator null values iterator has next break if subset iterator null subset iterator has next break string name subset iterator next if name null continue simple field set fs subsets get name if fs null continue string new prefix prefix name multi level char sub iterator fs key iterator new prefix if sub iterator has next break sub iterator null this prefix prefix simplesetfield aprefix aprefixkey1 keyiterator simplefieldset valuesiterator keyset subsetiterator keyset subsetiterator valuesiterator valuesiterator hasnext subsetiterator subsetiterator hasnext subsetiterator simplefieldset newprefix multi_level_char subiterator keyiterator newprefix subiterator hasnext subiterator public boolean has next synchronized simple field set this while true if values iterator has next return true if sub iterator null sub iterator has next return true if sub iterator null sub iterator null if subset iterator null subset iterator has next string key subset iterator next simple field set fs subsets get key string new prefix prefix key multi level char sub iterator fs key iterator new prefix else return false hasnext simplefieldset valuesiterator hasnext subiterator subiterator hasnext subiterator subiterator subsetiterator subsetiterator hasnext subsetiterator simplefieldset newprefix multi_level_char subiterator keyiterator newprefix public final string next return next key nextkey public string next key synchronized simple field set this string ret null if values iterator null values iterator has next return prefix values iterator next iterate subsets while true if sub iterator null sub iterator has next if we have a retval and we have a next value return if ret null return ret ret sub iterator next if sub iterator has next if we have a retval and we have a next value return if ret null return ret otherwise we need to get a new sub iterator or has next will return false sub iterator null if subset iterator null subset iterator has next string key subset iterator next simple field set fs subsets get key string new prefix prefix key multi level char sub iterator fs key iterator new prefix else no more sub iterator s if ret null logger error this returning null from key iterator next key should never happen return ret nextkey simplefieldset valuesiterator valuesiterator hasnext valuesiterator subiterator subiterator hasnext subiterator subiterator hasnext subiterator hasnext subiterator subsetiterator subsetiterator hasnext subsetiterator simplefieldset newprefix multi_level_char subiterator keyiterator newprefix subiterator keyiterator nextkey public synchronized void remove throw new unsupported operation exception unsupportedoperationexception tolerant put does nothing if fs is empty public void tput string key simple field set fs if fs null fs is empty return put key fs simplefieldset isempty public void put string key simple field set fs if fs null return legal no op because used everywhere if fs is empty can t just no op because caller might add the fs then populate it throw new illegal argument exception empty if subsets null subsets new hash map string simple field set if subsets contains key key throw new illegal argument exception already contains key but trying to add a simple field set if short lived key key intern subsets put key fs simplefieldset isempty illegalargumentexception hashmap simplefieldset containskey illegalargumentexception simplefieldset shortlived public synchronized void remove value string key int idx if idx key index of multi level char 1 values remove key else if subsets null return string before key substring 0 idx string after key substring idx 1 simple field set fs subsets get before if fs null return fs remove value after if fs is empty subsets remove before if subsets is empty subsets null removevalue indexof multi_level_char simplefieldset removevalue isempty isempty it removes the specified subset for example in a simple field set like this foo bar foo bar foobar foo bar boo foobarboo calling it with the parameter foo means to drop the second and the third line param is the subset to remove public synchronized void remove subset string key if subsets null return int idx if idx key index of multi level char 1 subsets remove key else string before key substring 0 idx string after key substring idx 1 simple field set fs subsets get before if fs null return fs remove subset after if fs is empty subsets remove before if subsets is empty subsets null simplefieldset removesubset indexof multi_level_char simplefieldset removesubset isempty isempty is this simple field set empty public synchronized boolean is empty return values is empty subsets null subsets is empty simplefieldset isempty isempty isempty public iterator string direct subset name iterator return subsets null null subsets key set iterator directsubsetnameiterator keyset public string names of direct subsets return subsets null empty string array subsets key set to array new string subsets size namesofdirectsubsets empty_string_array keyset toarray public static simple field set read from input stream is boolean allow multiple boolean short lived throws io exception buffered input stream bis null input stream reader isr null buffered reader br null try bis new buffered input stream is try isr new input stream reader bis utf 8 catch unsupported encoding exception e logger error simple field set class impossible e e is close throw new error impossible jvm doesn t support utf 8 e e br new buffered reader isr simple field set fs new simple field set br allow multiple short lived br close return fs finally closer close br closer close isr closer close bis simplefieldset readfrom inputstream allowmultiple shortlived ioexception bufferedinputstream inputstreamreader bufferedreader bufferedinputstream inputstreamreader unsupportedencodingexception simplefieldset bufferedreader simplefieldset simplefieldset allowmultiple shortlived public static simple field set read from file f boolean allow multiple boolean short lived throws io exception return read from new file input stream f allow multiple short lived simplefieldset readfrom allowmultiple shortlived ioexception readfrom fileinputstream allowmultiple shortlived write to the given output stream close it and flush it public void write to output stream os throws io exception buffered output stream bos null output stream writer osw null buffered writer bw null try bos new buffered output stream os try osw new output stream writer bos utf 8 catch unsupported encoding exception e logger error simple field set class impossible e e os close return bw new buffered writer osw write to bw close calls flush but ignores all errors bw flush bw close finally closer close bw closer close osw closer close bos outputstream writeto outputstream ioexception bufferedoutputstream outputstreamwriter bufferedwriter bufferedoutputstream outputstreamwriter unsupportedencodingexception simplefieldset bufferedwriter writeto public int get int string key int def string s get key if s null return def try return integer parse int s catch number format exception e return def getint parseint numberformatexception public int get int string key throws fs parse exception string s get key if s null throw new fs parse exception no key key try return integer parse int s catch number format exception e throw new fs parse exception cannot parse s for integer key getint fsparseexception fsparseexception parseint numberformatexception fsparseexception public double get double string key double def string s get key if s null return def try return double parse double s catch number format exception e return def getdouble parsedouble numberformatexception public double get double string key throws fs parse exception string s get key if s null throw new fs parse exception no key key try return double parse double s catch number format exception e throw new fs parse exception cannot parse s for integer key getdouble fsparseexception fsparseexception parsedouble numberformatexception fsparseexception public long get long string key long def string s get key if s null return def try return long parse long s catch number format exception e return def getlong parselong numberformatexception public long get long string key throws fs parse exception string s get key if s null throw new fs parse exception no key key try return long parse long s catch number format exception e throw new fs parse exception cannot parse s for long key getlong fsparseexception fsparseexception parselong numberformatexception fsparseexception public short get short string key throws fs parse exception string s get key if s null throw new fs parse exception no key key try return short parse short s catch number format exception e throw new fs parse exception cannot parse s for short key getshort fsparseexception fsparseexception parseshort numberformatexception fsparseexception public short get short string key short def string s get key if s null return def try return short parse short s catch number format exception e return def getshort parseshort numberformatexception public char get char string key throws fs parse exception string s get key if s null throw new fs parse exception no key key if s length 1 return s char at 0 else throw new fs parse exception cannot parse s for char key getchar fsparseexception fsparseexception charat fsparseexception public char get char string key char def string s get key if s null return def if s length 1 return s char at 0 else return def getchar charat public boolean get boolean string key boolean def return fields string to bool get key def getboolean stringtobool public boolean get boolean string key throws fs parse exception try return fields string to bool get key catch number format exception e throw new fs parse exception e getboolean fsparseexception stringtobool numberformatexception fsparseexception public void put string key int value remove value key for int v value put append key string value of v removevalue putappend valueof public void put string key double value remove value key for double v value put append key string value of v removevalue putappend valueof public int get int array string key string strings get all key if strings null return null int ret new int strings length for int i 0 i strings length i try ret i integer parse int strings i catch number format exception e logger error this cannot parse strings i e e return null return ret getintarray getall parseint numberformatexception public double get double array string key string strings get all key if strings null return null double ret new double strings length for int i 0 i strings length i try ret i double value of strings i catch number format exception e logger error this cannot parse strings i e e return null return ret getdoublearray getall valueof numberformatexception public void put overwrite string key string strings put overwrite key unsplit strings putoverwrite putoverwrite public string get string string key throws fs parse exception string s get key if s null throw new fs parse exception no such element key return s getstring fsparseexception fsparseexception public void remove from object container container container delete values for simple field set fs subsets values fs remove from container container delete subsets container delete this removefrom objectcontainer simplefieldset removefrom get the thread s process id or return 1 if it s unavailable for some reason public synchronized static int getpid object o if getpid enabled return 1 return getpid from proc self stat o getpidenabled getpidfromprocselfstat get the thread s parent process id or return 1 if it s unavailable for some reason public synchronized static int getppid object o if getppid enabled return 1 return getppid from proc self stat o getppidenabled getppidfromprocselfstat get a specified field from proc self stat or return null if it s unavailable for some reason public synchronized static string get field from proc self stat int field number object o string read line null if proc self stat enabled return null read proc self stat and parse for the specified field buffered reader br null file reader fr null file proc file new file proc self stat if proc file exists try fr new file reader proc file br new buffered reader fr catch file not found exception e1 log static o proc self stat not found log to file verbosity proc self stat enabled false fr null if null br try read line br read line catch io exception e error o caught io exception in br read line of os thread get field from proc self stat e read line null finally closer close br if null read line try string proc fields read line trim split if 4 proc fields length return proc fields field number catch pattern syntax exception e error o caught pattern syntax exception in read line trim split of os thread get field from proc self stat while parsing read line e closer close br return null getfieldfromprocselfstat fieldnumber readline procselfstatenabled bufferedreader filereader procfile procfile filereader procfile bufferedreader filenotfoundexception logstatic logtofileverbosity procselfstatenabled readline readline ioexception ioexception readline osthread getfieldfromprocselfstat readline readline procfields readline procfields procfields fieldnumber patternsyntaxexception patternsyntaxexception readline osthread getfieldfromprocselfstat readline get the thread s process id using the proc self stat method or return 1 if it s unavailable for some reason this is an ugly hack required by java to get the os process id of a thread on linux without using jni public synchronized static int getpid from proc self stat object o int pid 1 if getpid enabled return 1 if proc self stat enabled return 1 string pid string get field from proc self stat 0 o if null pid string return 1 try pid integer parse int pid string trim catch number format exception e error o caught number format exception in integer parse int of os thread getpid from proc self stat while parsing pid string e return pid getpidfromprocselfstat getpidenabled procselfstatenabled pidstring getfieldfromprocselfstat pidstring parseint pidstring numberformatexception numberformatexception parseint osthread getpidfromprocselfstat pidstring get the thread s parent process id using the proc self stat method or return 1 if it s unavailable for some reason this is ugly hack required by java to get the os parent process id of a thread on linux without using jni public synchronized static int getppid from proc self stat object o int ppid 1 if getppid enabled return 1 if proc self stat enabled return 1 string ppid string get field from proc self stat 3 o if null ppid string return 1 try ppid integer parse int ppid string trim catch number format exception e error o caught number format exception in integer parse int of os thread getppid from proc self stat while parsing ppid string e return ppid getppidfromprocselfstat getppidenabled procselfstatenabled ppidstring getfieldfromprocselfstat ppidstring parseint ppidstring numberformatexception numberformatexception parseint osthread getppidfromprocselfstat ppidstring log the thread s process id or return 1 if it s unavailable for some reason public synchronized static int logpid object o if getpid enabled return 1 int pid getpid o string msg if 1 pid msg this thread s os pid is pid else msg this thread s os pid could not be determined if log to std out enabled system out println msg o if log to file enabled log static o msg log to file verbosity return pid getpidenabled logtostdoutenabled logtofileenabled logstatic logtofileverbosity log the thread s process id or return 1 if it s unavailable for some reason public synchronized static int logppid object o if getppid enabled return 1 int ppid getppid o string msg if 1 ppid msg this thread s os ppid is ppid else msg this thread s os ppid could not be determined if log to std out enabled system out println msg o if log to file enabled log static o msg log to file verbosity return ppid getppidenabled logtostdoutenabled logtofileenabled logstatic logtofileverbosity public synchronized static file logger hook setup stdout logging int level string detail throws invalid threshold exception setup chain logger set threshold level logger set detailed thresholds detail file logger hook fh fh new file logger hook system out d c t p m mmm dd yyyy hh mm ss sss level if detail null fh set detailed thresholds detail logger hook chain logger add hook fh fh start return fh fileloggerhook setupstdoutlogging invalidthresholdexception setupchain setthreshold setdetailedthresholds fileloggerhook fileloggerhook setdetailedthresholds loggerhookchain addhook public synchronized static void setup chain logger new logger hook chain setupchain loggerhookchain public synchronized static void debug object o string s logger log o s debug public synchronized static void debug object o string s throwable t logger log o s t debug public synchronized static void error class c string s logger log c s error public synchronized static void error object o string s logger log o s error public synchronized static void error object o string s throwable e logger log o s e error public synchronized static void minor class c string s logger log c s minor public synchronized static void minor object o string s logger log o s minor public synchronized static void minor object o string s throwable t logger log o s t minor public synchronized static void minor class class1 string string throwable t logger log class1 string t minor public synchronized static void normal object o string s logger log o s normal public synchronized static void normal object o string s throwable t logger log o s t normal public synchronized static void normal class c string s logger log c s normal public synchronized static void log static object o string s int prio logger log o s prio logstatic log a message param o the object where this message was generated param source the class where this message was generated param message a clear and verbose message describing the event param e logs this exception with the message param priority the priority of the mesage one of logger error logger normal logger minor or logger debug public abstract void log object o class source string message throwable e log a message param source the source object where this message was generated param message a clear and verbose message describing the event param priority the priority of the mesage one of logger error logger normal logger minor or logger debug log a message with an exception param o the source object where this message was generated param message a clear and verbose message describing the event param e logs this exception with the message param priority the priority of the mesage one of logger error logger normal logger minor or logger debug see log object o string message int priority public abstract void log object o string message throwable e int priority log a message from static code param c the class where this message was generated param message a clear and verbose message describing the event param priority the priority of the mesage one of logger error logger normal logger minor or logger debug log a message from static code param c the class where this message was generated param message a clear and verbose message describing the event param e logs this exception with the message param priority the priority of the mesage one of logger error logger normal logger minor or logger debug public abstract void log class c string message throwable e int priority public abstract boolean instance should log int priority class c instanceshouldlog public abstract boolean instance should log int priority class c public static boolean should log int priority class c return logger instance should log priority c instanceshouldlog shouldlog instanceshouldlog public static boolean should log int priority object o return should log priority o get class shouldlog shouldlog getclass public abstract boolean instance should log int prio object o instanceshouldlog changes the priority threshold param thresh the new threshhold changes the priority threshold param symbolic threshold the new threshhold must be one of error normal etc throws invalid threshold exception symbolicthreshold invalidthresholdexception public abstract void set threshold string symbolic threshold throws invalid threshold exception return the currently used logging threshold public abstract int get threshold setthreshold symbolicthreshold invalidthresholdexception getthreshold public abstract int get threshold public abstract void set detailed thresholds string details throws invalid threshold exception getthreshold setdetailedthresholds invalidthresholdexception register a log threshold callback this callback will be called after registration public static void register log threshold callback log threshold callback ltc logger instance register log threshold callback ltc logthresholdcallback registerlogthresholdcallback logthresholdcallback instanceregisterlogthresholdcallback public abstract void instance register log threshold callback log threshold callback ltc instanceregisterlogthresholdcallback logthresholdcallback report a fatal error and exit param cause the object or class involved param retcode the return code param message the reason why public static void fatal object cause int retcode string message error cause message system exit retcode public synchronized static void global add hook logger hook logger2 if logger instanceof void logger setup chain logger hook chain logger add hook logger2 globaladdhook loggerhook voidlogger setupchain loggerhookchain addhook public synchronized static void global set threshold int i logger set threshold i globalsetthreshold setthreshold public synchronized static int global get threshold return logger get threshold globalgetthreshold getthreshold public synchronized static void global remove hook file logger hook hook if logger instanceof logger hook chain logger hook chain logger remove hook hook else system err println cannot remove hook hook global logger is logger globalremovehook fileloggerhook loggerhookchain loggerhookchain removehook public synchronized static void destroy chain if empty if logger instanceof void logger return if logger instanceof logger hook chain logger hook chain logger get hooks length 0 logger new void logger destroychainifempty voidlogger loggerhookchain loggerhookchain gethooks voidlogger public synchronized static logger hook chain get chain if logger instanceof logger hook chain return logger hook chain logger else setup chain return logger hook chain logger loggerhookchain getchain loggerhookchain loggerhookchain setupchain loggerhookchain private final boolean is meta data public get result bucket data2 boolean is meta data2 data data2 is meta data is meta data2 ismetadata getresult ismetadata2 ismetadata ismetadata2 public boolean is meta data return is meta data ismetadata ismetadata public bucket get data return data getdata public void free if data null data free public freetalknntp server node my node freetalk ft int port string bind to string allowed hosts node my node freetalk ft this port port todo as soon as freetalk has a configuration class read it from there this bind to bind to todo as soon as freetalk has a configuration class read it from there this allowed hosts allowed hosts todo as soon as freetalk has a configuration class read it from there shutdown shutdown finished false client handlers new array list freetalknntp handler node executor execute this freetalk nntp server freetalknntpserver mynode bindto allowedhosts mynode bindto bindto allowedhosts allowedhosts shutdownfinished clienthandlers arraylist freetalknntphandler shut down the server and disconnect any currently connected clients public void terminate shutdown true try iface close catch io exception e logger error this error shutting down nntp server e synchronized this while shutdown finished try wait catch interrupted exception e ignore ioexception shutdownfinished interruptedexception main server connection loop public void run try iface network interface create port bind to allowed hosts node executor true fixme network interface accept currently does not support being interrupted by thread interrupt shutdown works by timeout this sucks and should be changed as long as it is still like that we have to use a low timeout iface set so timeout 1000 while shutdown socket client socket iface accept if client socket null null is returned on timeout logger debug this accepted an nntp connection from client socket get inet address freetalknntp handler handler new freetalknntp handler freetalk client socket node executor execute handler freetalk nntp client client socket get inet address client handlers add handler remove disconnected clients from the list for iterator freetalknntp handler i client handlers iterator i has next freetalknntp handler handler i next if handler is alive i remove logger debug this nntp server exiting iface close catch io exception e logger error this unable to start nntp server e finally terminate handlers synchronized this shutdown finished true notify networkinterface bindto allowedhosts networkinterface setsotimeout clientsocket clientsocket clientsocket getinetaddress freetalknntphandler freetalknntphandler clientsocket clientsocket getinetaddress clienthandlers freetalknntphandler clienthandlers hasnext freetalknntphandler isalive ioexception terminatehandlers shutdownfinished private void terminate handlers logger debug this closing client handlers synchronized client handlers close client sockets for iterator freetalknntp handler i client handlers iterator i has next freetalknntp handler handler i next handler terminate terminatehandlers clienthandlers freetalknntphandler clienthandlers hasnext freetalknntphandler private static final long serial versionuid 1l public incorrect type exception string s super s serialversionuid incorrecttypeexception public final big integer p g public dh group big integer p big integer g this p p this g g biginteger dhgroup biginteger biginteger public string to long string string p str hex util bi to hex p string g str hex util bi to hex g string builder b new string builder p str length g str length 1 b append p str append append g str return b to string tolongstring pstr hexutil bitohex gstr hexutil bitohex stringbuilder stringbuilder pstr gstr pstr gstr tostring public static crypto key read from field string field big integer p g string tokenizer str new string tokenizer field p new native big integer 1 hex util hex to bytes str next token g new native big integer 1 hex util hex to bytes str next token return new dh group p g cryptokey readfromfield biginteger stringtokenizer stringtokenizer nativebiginteger hexutil hextobytes nexttoken nativebiginteger hexutil hextobytes nexttoken dhgroup public static crypto key read data input stream i throws io exception big integer p g p util readmpi i g util readmpi i return new dh group p g cryptokey datainputstream ioexception biginteger dhgroup public big integer getp return p biginteger public big integer getg return g biginteger override public string key type return dhg p bit length keytype bitlength override public byte fingerprint return fingerprint new big integer p g biginteger override public byte as bytes byte pb util mp ibytes p byte gb util mp ibytes g byte tb new byte pb length gb length system arraycopy pb 0 tb 0 pb length system arraycopy gb 0 tb pb length gb length return tb asbytes mpibytes mpibytes private boolean really closed public static string get name boolean is store store type type string newdb prefix type name type is store store cache return newdb prefix chk reallyclosed getname isstore storetype newdbprefix typename isstore newdbprefix public static file get file boolean is store store type type file base store dir string suffix string new store file name type name type suffix is store store cache return new file base store dir new store file name getfile isstore storetype basestoredir newstorefilename typename isstore basestoredir newstorefilename public static freenet store construct file base store dir boolean is store string suffix long max store keys store type type environment store environment semi ordered shutdown hook store shutdown hook file reconstruct file store callback callback random source random throws database exception io exception location of new store file string new store file name type name type suffix is store store cache file new store file new file base store dir new store file name file lru file new file base store dir new store file name lru file keys file if callback store full keys keys file new file base store dir new store file name keys else keys file null string newdb prefix type name type is store store cache file new fix secondary file new file base store dir recreate secondary db new store file name system err println opening database using new store file return open store store environment newdb prefix new store file lru file keys file new fix secondary file max store keys store shutdown hook reconstruct file callback random freenetstore basestoredir isstore maxstorekeys storetype storeenvironment semiorderedshutdownhook storeshutdownhook reconstructfile storecallback randomsource databaseexception ioexception newstorefilename typename isstore newstorefile basestoredir newstorefilename lrufile basestoredir newstorefilename keysfile storefullkeys keysfile basestoredir newstorefilename keysfile newdbprefix typename isstore newfixsecondaryfile basestoredir recreate_secondary_db newstorefilename newstorefile openstore storeenvironment newdbprefix newstorefile lrufile keysfile newfixsecondaryfile maxstorekeys storeshutdownhook reconstructfile private static freenet store open store environment store environment string newdb prefix file new store file file lru file file keys file file new fix secondary file long max store keys semi ordered shutdown hook store shutdown hook file reconstruct file store callback callback random source random throws database exception io exception try first try just opening it return new berkeleydb freenet store store environment newdb prefix new store file lru file keys file new fix secondary file max store keys false store shutdown hook reconstruct file callback random catch database exception e try a reconstruct system err println could not open store e e print stack trace system err println attempting to reconstruct index wrapper manager signal starting 5 60 60 1000 reconstruct return new berkeleydb freenet store store environment newdb prefix new store file lru file keys file new fix secondary file max store keys store shutdown hook reconstruct file callback random freenetstore openstore storeenvironment newdbprefix newstorefile lrufile keysfile newfixsecondaryfile maxstorekeys semiorderedshutdownhook storeshutdownhook reconstructfile storecallback randomsource databaseexception ioexception berkeleydbfreenetstore storeenvironment newdbprefix newstorefile lrufile keysfile newfixsecondaryfile maxstorekeys storeshutdownhook reconstructfile databaseexception printstacktrace wrappermanager signalstarting berkeleydbfreenetstore storeenvironment newdbprefix newstorefile lrufile keysfile newfixsecondaryfile maxstorekeys storeshutdownhook reconstructfile private static string type name store type type return type to string to lower case typename storetype tostring tolowercase initializes the datastore param env berkeley db link environment param prefix database name prefix param store file store file where the actual data are stored param lru file lru data file flat file store for recovery param keys file keys data file flat file store for recovery created only if code callback store full keys code is code true code param fix secondary file flag file created when secondary database error occur if this file exist on start delete it and recreate the secondary database param max chk blocks maximum number of blocks param wipe if code true code wipe and reconstruct the database param store shutdown hook link semi ordered shutdown hook for hooking database shutdown hook param reconstruct file flag file created when database crash param callback link store callback object for this store throws io exception throws database exception private berkeleydb freenet store environment env string prefix file store file file lru file file keys file file fix secondary file long max chk blocks boolean wipe semi ordered shutdown hook store shutdown hook file reconstruct file store callback callback random source random throws io exception database exception logminor logger should log logger minor this logdebug logger should log logger debug this this random random this environment env this name prefix this fix secondary file fix secondary file this max blocks in store max chk blocks this reconstruct file reconstruct file this callback callback this collision possible callback collision possible this data block size callback data length this header block size callback header length this key length callback full key length callback set store this oom handler addoom hook this this free blocks new sorted long set delete old database s if wipe system err println wiping old database for prefix wipe old databases environment prefix initialize chk database database config db config new database config db config set allow create true db config set transactional true keysdb environment open database null prefix chk db config system err println opened main database for prefix if fix secondary file exists fix secondary file delete remove secondary database store block tuple binding new store block tuple binding initialize secondary chk database sorted on accesstime access timedb open secondary data base prefix chk accesstime keysdb count 0 wipe wipe true new access time key creator store block tuple binding initialize other secondary database sorted on block number block numdb open secondary data base prefix chk blocknum keysdb count 0 wipe wipe false new block number key creator store block tuple binding initialize the store file try if store file exists if store file create new file throw new io exception can t create a new file store file storeraf new random access file store file rw storefc storeraf get channel if lru file exists if lru file create new file throw new io exception can t create a new file lru file lruraf new random access file lru file rw lrufc lruraf get channel if keys file null if keys file exists if keys file create new file throw new io exception can t create a new file keys file keysraf new random access file keys file rw keysfc keysraf get channel else keysraf null if wipe wipe and reconstruct blocks in store 0 last recently used 0 reconstruct blocks in store countchk blocks from file last recently used get max recently used maybe offline shrink true else just open boolean dont check for holes shrinking false long chk blocks in database highest block number in database blocks in store chk blocks in database long chk blocks from file countchk blocks from file last recently used get max recently used system out println keys in store db chk blocks in database file chk blocks from file max max chk blocks if chk blocks in database chk blocks from file system out println more keys in database than in store throw new database exception more keys in database than in store fixme reinstate if handling code doesn t work fixme we can do a cleverer recovery find all keys whose block number is chk blocks from file and delete them if blocks in store 0 chk blocks from file 0 blocks in store 10 1 1 chk blocks from file try close false catch throwable t logger error this failed to close t t system err println failed to close t t print stack trace throw new database exception keys in database blocks in store but keys in file chk blocks from file blocks in store math max blocks in store chk blocks from file if logminor logger minor this keys in store blocks in store maybe offline shrink dont check for holes shrinking chk blocks from file countchk blocks from file blocks in store math max blocks in store chk blocks from file add shutdownhook store shutdown hook add early job new shutdown hook catch database exception t logger error this caught exception closing database prefix t system err println caught exception closing database prefix t t print stack trace close false throw t catch io exception t system err println caught exception closing database prefix t logger error this caught exception closing database prefix t close false throw t storefile lrufile keysfile storefullkeys fixsecondaryfile maxchkblocks storeshutdownhook semiorderedshutdownhook reconstructfile storecallback ioexception databaseexception berkeleydbfreenetstore storefile lrufile keysfile fixsecondaryfile maxchkblocks semiorderedshutdownhook storeshutdownhook reconstructfile storecallback randomsource ioexception databaseexception shouldlog shouldlog fixsecondaryfile fixsecondaryfile maxblocksinstore maxchkblocks reconstructfile reconstructfile collisionpossible collisionpossible datablocksize datalength headerblocksize headerlength keylength fullkeylength setstore oomhandler addoomhook freeblocks sortedlongset wipeolddatabases databaseconfig dbconfig databaseconfig dbconfig setallowcreate dbconfig settransactional opendatabase dbconfig fixsecondaryfile fixsecondaryfile removesecondarydatabase storeblocktuplebinding storeblocktuplebinding accesstimedb opensecondarydatabase chk_accesstime accesstimekeycreator storeblocktuplebinding blocknumdb opensecondarydatabase chk_blocknum blocknumberkeycreator storeblocktuplebinding storefile storefile createnewfile ioexception storefile randomaccessfile storefile getchannel lrufile lrufile createnewfile ioexception lrufile randomaccessfile lrufile getchannel keysfile keysfile keysfile createnewfile ioexception keysfile randomaccessfile keysfile getchannel blocksinstore lastrecentlyused blocksinstore countchkblocksfromfile lastrecentlyused getmaxrecentlyused maybeofflineshrink dontcheckforholesshrinking chkblocksindatabase highestblocknumberindatabase blocksinstore chkblocksindatabase chkblocksfromfile countchkblocksfromfile lastrecentlyused getmaxrecentlyused chkblocksindatabase chkblocksfromfile maxchkblocks chkblocksindatabase chkblocksfromfile databaseexception chkblocksfromfile blocksinstore chkblocksfromfile blocksinstore chkblocksfromfile printstacktrace databaseexception blocksinstore chkblocksfromfile blocksinstore blocksinstore chkblocksfromfile blocksinstore maybeofflineshrink dontcheckforholesshrinking chkblocksfromfile countchkblocksfromfile blocksinstore blocksinstore chkblocksfromfile storeshutdownhook addearlyjob shutdownhook databaseexception printstacktrace ioexception private long check for holes long blocks in file boolean dont truncate throws database exception system err println checking for holes in database blocks in file blocks in file wrapper manager signal starting int math min integer max value 5 60 1000 blocks in file 100l 10 sec long holes 0 long max present 0 free blocks clear for long i 0 i blocks in file i database entry block num entry new database entry database entry found new database entry long binding long to entry i block num entry operation status success block numdb get null block num entry found lock mode default if success equals operation status notfound add free block i true hole found holes else max present i if i 1024 0 system err println checked i blocks found holes holes system err println checked database of blocks in file blocks found holes holes maximum non hole block max present long bound max present 1 if dont truncate if bound blocks in store system err println truncating to bound as no non holes after that point try storeraf set length bound data block size header block size lruraf set length bound 8 if keysraf null keysraf set length bound key length blocks in store bound for long l bound l blocks in store l free blocks remove l catch io exception e logger error this unable to truncate e e system err println unable to truncate e e print stack trace return bound checkforholes blocksinfile donttruncate databaseexception blocksinfile wrappermanager signalstarting max_value blocksinfile maxpresent freeblocks blocksinfile databaseentry blocknumentry databaseentry databaseentry databaseentry longbinding longtoentry blocknumentry operationstatus blocknumdb blocknumentry lockmode operationstatus addfreeblock maxpresent blocksinfile maxpresent maxpresent donttruncate blocksinstore setlength datablocksize headerblocksize setlength setlength keylength blocksinstore blocksinstore freeblocks ioexception printstacktrace do an offline shrink if necessary will not return until completed param dont check for holes if code true code don t check for holes throws database exception throws io exception private void maybe offline shrink boolean dont check for holes throws database exception io exception if blocks in store max blocks in store return maybe slow shrink dont check for holes true dontcheckforholes databaseexception ioexception maybeofflineshrink dontcheckforholes databaseexception ioexception blocksinstore maxblocksinstore maybeslowshrink dontcheckforholes do an online shrink if necessary this method is non blocking i e it will do the shrink on a new thread param force big online shrinks if true force the node to shrink the store immediately even if it is a major more than tt 10 tt shrink br normally this flag is should not be set because online shrinks drops the most recently used data the best thing to do is to restart the node and let it do an offline shrink throws database exception if a database error occurs throws io exception if an i o error occurs return code true code if the database will be shrunk in the background or the database is already small enough code false code otherwise for example major shrink is needed but code force big online shrinks code was not set private boolean maybe online shrink boolean force big online shrinks throws database exception io exception synchronized this if blocks in store max blocks in store return true if blocks in store 0 9 max blocks in store force big online shrinks logger error this doing quick and dirty shrink of the store by 100 blocks in store max blocks in store blocks in store logger error this offline shrinks will preserve the most recently used data this online shrink does not runnable r new runnable public void run try synchronized shrink lock if shrinking return shrinking true maybe quick shrink false catch throwable t logger error this online shrink failed t t finally synchronized shrink lock shrinking false thread t new thread r t set daemon true t start return true else return false forcebigonlineshrinks databaseexception ioexception forcebigonlineshrinks maybeonlineshrink forcebigonlineshrinks databaseexception ioexception blocksinstore maxblocksinstore blocksinstore maxblocksinstore forcebigonlineshrinks blocksinstore maxblocksinstore blocksinstore shrinklock maybequickshrink shrinklock setdaemon runnable r new runnable public void run try synchronized shrink lock if shrinking return shrinking true maybe quick shrink false catch throwable t logger error this online shrink failed t t finally synchronized shrink lock shrinking false shrinklock maybequickshrink shrinklock private void maybe slow shrink boolean dont check for holes boolean in start up throws database exception io exception list integer wanted keep new array list integer keep content is wanted and is in the right place list integer unwanted ignore new array list integer ignore content is not wanted and is not in the right place list integer wanted move new array list integer content is wanted but is in the wrong part of the store list integer unwanted move new array list integer content is not wanted but is in the part of the store we will keep list integer already dropped new array list integer any blocks past the end which have already been truncated but which there are still database blocks pointing to cursor c null transaction t null long new size max blocks in store if blocks in store max blocks in store return system err println shrinking from blocks in store to max blocks in store from db keysdb count from file countchk blocks from file if dont check for holes check for holes max blocks in store true wrapper manager signal starting int math min integer max value 5 60 1000 blocks in store 100l 10 per second long real size countchk blocks from file long highest block 0 try c access timedb open cursor null null database entry keydbe new database entry database entry blockdbe new database entry operation status op stat op stat c get last keydbe blockdbe lock mode rmw if op stat operation status notfound system err println database is empty shrinking c close c null return logger minor this found first key int x 0 while true store block store block store block tuple binding entry to object blockdbe long block store block offset if block highest block highest block block if store block offset integer max value 2 31 block size 70tb for ch ks 2tb for the others system err println store too big doing quick shrink memory usage would be insane c close c null maybe quick shrink true return integer block num int store block offset long seq num new long store block recently used system out println x seq seq num block block num if block num long value real size truncated already logger minor this truncated already block num long value already dropped add block num else if x new size wanted if block new size system out println keep where it is block block num seq x new size wanted keep add block num else system out println move to where it should go block num seq x new size wanted move add block num else unwanted if block new size system out println overwrite block num seq x new size unwanted move add block num else system out println ignore will be wiped block block num seq x new size unwanted ignore add block num x if x 1024 0 system out println reading store prior to shrink x 100l real size x real size if x integer max value system err println key number x ignoring store after x data block size header block size bytes break op stat c get prev keydbe blockdbe lock mode rmw if op stat operation status notfound system out println read store x keys break finally if c null c close integer wanted keep nums wanted keep to array new integer wanted keep size integer unwanted ignore nums unwanted ignore to array new integer unwanted ignore size integer wanted move nums wanted move to array new integer wanted move size integer unwanted move nums unwanted move to array new integer unwanted move size long free early slots free blocks to array arrays sort wanted keep nums arrays sort unwanted ignore nums arrays sort wanted move nums arrays sort unwanted move nums for int i 0 i new size i integer ii integer value of i if arrays binary search wanted keep nums ii 0 continue if arrays binary search unwanted ignore nums ii 0 continue if arrays binary search wanted move nums ii 0 continue if arrays binary search unwanted move nums ii 0 continue unwanted move add ii unwanted move nums unwanted move to array new integer unwanted move size system err println keys to keep where they are wanted keep nums length system err println keys which will be wiped anyway unwanted ignore nums length system err println keys to move wanted move nums length system err println keys to be moved over unwanted move nums length system err println free slots to be moved over free early slots length now move all the wanted move blocks onto the corresponding unwanted move s wrapper manager signal starting int math min integer max value 5 60 1000 wanted move nums length 1000l already dropped size 100l 1 per second byte buffer buf byte buffer allocate header block size data block size long lru value byte key buf new byte key length t null try t environment begin transaction null null if already dropped size 0 system err println deleting already dropped size blocks beyond the length of the file for int i 0 i already dropped size i int unwanted block already dropped get i int value database entry unwanted block entry new database entry long binding long to entry unwanted block unwanted block entry block numdb delete t unwanted block entry if i 1024 0 t commit t environment begin transaction null null if already dropped size 1024 0 t commit t environment begin transaction null null for int i 0 i wanted move nums length i integer wanted block wanted move nums i integer unwanted block can we move over an empty slot if i free early slots length don t need to delete old block unwanted block integer value of int free early slots i will fit in an int else if unwanted move nums length free early slots length i unwanted block unwanted move nums i free early slots length delete unwanted block from the store database entry unwanted block entry new database entry long binding long to entry unwanted block long value unwanted block entry delete the old block from the database block numdb delete t unwanted block entry else system err println keys to move but no keys to move over moved i t commit t null return move old data to new location database entry wanted block entry new database entry long binding long to entry wanted block long value wanted block entry long entry wanted block long value boolean readlru false boolean read key false try buf rewind do int byte read storefc read buf entry header block size data block size buf position if byte read 1 throw new eof exception while buf has remaining buf flip lru value 0 if lruraf length entry 1 8 readlru true lru value fc readlru entry if keysraf null keysraf length entry 1 key length read key true fc read key entry key buf catch eof exception e system err println was reading wanted block to write to unwanted block system err println e e print stack trace throw e entry unwanted block long value do int byte written storefc write buf entry header block size data block size buf position if byte written 1 throw new eof exception while buf has remaining if readlru fc writelru entry lru value if read key fc write key entry key buf update the database w r t the old block database entry routing keydbe new database entry database entry blockdbe new database entry block numdb get t wanted block entry routing keydbe blockdbe lock mode rmw store block block store block tuple binding entry to object blockdbe block offset unwanted block long value store block tuple binding object to entry block blockdbe keysdb put t routing keydbe blockdbe think about committing the transaction if i 1 2048 0 t commit t environment begin transaction null null system out println moving blocks i 100 wanted move size i wanted move size system err println moved wanted block to unwanted block system out println moved all wanted move size blocks if t null t commit t null finally if t null t abort t null system out println completing shrink fixme remove int total unwanted blocks unwanted move nums length free early slots length wrapper manager signal starting int math min integer max value 5 60 1000 total unwanted blocks wanted move nums length 100l if there are any slots left over they must be free fixme put these into the database as we do in reconstruct not doing that now as its not immediately obvious how to deal with it free blocks clear t e maybeslowshrink dontcheckforholes instartup databaseexception ioexception wantedkeep arraylist unwantedignore arraylist wantedmove arraylist unwantedmove arraylist alreadydropped arraylist newsize maxblocksinstore blocksinstore maxblocksinstore blocksinstore maxblocksinstore countchkblocksfromfile dontcheckforholes checkforholes maxblocksinstore wrappermanager signalstarting max_value blocksinstore realsize countchkblocksfromfile highestblock accesstimedb opencursor databaseentry databaseentry databaseentry databaseentry operationstatus opstat opstat getlast lockmode opstat operationstatus storeblock storeblock storeblocktuplebinding entrytoobject storeblock highestblock highestblock storeblock max_value blocksize chks maybequickshrink blocknum storeblock seqnum storeblock recentlyused seqnum blocknum blocknum longvalue realsize blocknum longvalue alreadydropped blocknum newsize newsize blocknum newsize wantedkeep blocknum blocknum newsize wantedmove blocknum newsize blocknum newsize unwantedmove blocknum blocknum newsize unwantedignore blocknum realsize realsize max_value datablocksize headerblocksize opstat getprev lockmode opstat operationstatus wantedkeepnums wantedkeep toarray wantedkeep unwantedignorenums unwantedignore toarray unwantedignore wantedmovenums wantedmove toarray wantedmove unwantedmovenums unwantedmove toarray unwantedmove freeearlyslots freeblocks toarray wantedkeepnums unwantedignorenums wantedmovenums unwantedmovenums newsize valueof binarysearch wantedkeepnums binarysearch unwantedignorenums binarysearch wantedmovenums binarysearch unwantedmovenums unwantedmove unwantedmovenums unwantedmove toarray unwantedmove wantedkeepnums unwantedignorenums wantedmovenums unwantedmovenums freeearlyslots wantedmove unwantedmove wrappermanager signalstarting max_value wantedmovenums alreadydropped bytebuffer bytebuffer headerblocksize datablocksize lruvalue keybuf keylength begintransaction alreadydropped alreadydropped alreadydropped unwantedblock alreadydropped intvalue databaseentry unwantedblockentry databaseentry longbinding longtoentry unwantedblock unwantedblockentry blocknumdb unwantedblockentry begintransaction alreadydropped begintransaction wantedmovenums wantedblock wantedmovenums unwantedblock freeearlyslots unwantedblock valueof freeearlyslots unwantedmovenums freeearlyslots unwantedblock unwantedmovenums freeearlyslots unwantedblock databaseentry unwantedblockentry databaseentry longbinding longtoentry unwantedblock longvalue unwantedblockentry blocknumdb unwantedblockentry databaseentry wantedblockentry databaseentry longbinding longtoentry wantedblock longvalue wantedblockentry wantedblock longvalue readkey byteread headerblocksize datablocksize byteread eofexception hasremaining lruvalue lruvalue fcreadlru keylength readkey fcreadkey keybuf eofexception wantedblock unwantedblock printstacktrace unwantedblock longvalue bytewritten headerblocksize datablocksize bytewritten eofexception hasremaining fcwritelru lruvalue readkey fcwritekey keybuf databaseentry routingkeydbe databaseentry databaseentry databaseentry blocknumdb wantedblockentry routingkeydbe lockmode storeblock storeblocktuplebinding entrytoobject unwantedblock longvalue storeblocktuplebinding objecttoentry routingkeydbe begintransaction wantedmove wantedmove wantedblock unwantedblock wantedmove totalunwantedblocks unwantedmovenums freeearlyslots wrappermanager signalstarting max_value totalunwantedblocks wantedmovenums freeblocks shrink the store on the fly quickly param offline if false keep going until the store has shrunk enough throws database exception throws io exception private void maybe quick shrink boolean offline throws database exception io exception long s are not atomic long max blocks long cur blocks synchronized this max blocks max blocks in store cur blocks blocks in store if max blocks cur blocks system out println not shrinking store cur blocks max blocks return inner quick shrink cur blocks max blocks offline databaseexception ioexception maybequickshrink databaseexception ioexception maxblocks curblocks maxblocks maxblocksinstore curblocks blocksinstore maxblocks curblocks curblocks maxblocks innerquickshrink curblocks maxblocks param cur blocks the current number of blocks in the file from the file length param max blocks the target number of blocks in the file the file will be truncated to this length in blocks param offline if true inner quick shrink will run once if false after the first run if the store is still over its required size it will shrink it again and so on until the store is within its required size if false inner quick shrink will repeat itself until it deletes no more blocks this is to handle throws database exception if a database error occurs throws io exception if an i o error occurs private void inner quick shrink long cur blocks long max blocks boolean offline throws database exception io exception long old cur blocks cur blocks try cur blocks math max old cur blocks highest block number in database catch database exception e logger error this ignoring e in inner quick shrink initialisation e transaction t null try string msg shrinking store cur blocks max blocks from db keysdb count highest highest block number in database from file countchk blocks from file system err println msg logger normal this msg wrapper manager signal starting int math min integer max value 5 60 1000 100l math max 0 cur blocks max blocks while true t environment begin transaction null null long deleted 0 for long i cur blocks 1 i max blocks i if t null t environment begin transaction null null delete the block with this blocknum database entry block num entry new database entry long binding long to entry i block num entry operation status result block numdb delete t block num entry if result equals operation status success deleted t commit t null free blocks remove i long chk blocks in database highest block number in database synchronized this max blocks max blocks in store cur blocks blocks in store chk blocks in database if max blocks cur blocks break if t null t commit system err println deleted deleted keys t null if offline break system err println checking synchronized this max blocks max blocks in store cur blocks blocks in store if max blocks cur blocks break storeraf set length max blocks in store data block size header block size lruraf set length max blocks in store 8 if keysraf null keysraf set length max blocks in store key length blocks in store max blocks in store system err println successfully shrunk store to blocks in store finally if t null t abort curblocks maxblocks innerquickshrink innerquickshrink databaseexception ioexception innerquickshrink curblocks maxblocks databaseexception ioexception oldcurblocks curblocks curblocks oldcurblocks highestblocknumberindatabase databaseexception innerquickshrink curblocks maxblocks highestblocknumberindatabase countchkblocksfromfile wrappermanager signalstarting max_value curblocks maxblocks begintransaction curblocks maxblocks begintransaction databaseentry blocknumentry databaseentry longbinding longtoentry blocknumentry operationstatus blocknumdb blocknumentry operationstatus freeblocks chkblocksindatabase highestblocknumberindatabase maxblocks maxblocksinstore curblocks blocksinstore chkblocksindatabase maxblocks curblocks maxblocks maxblocksinstore curblocks blocksinstore maxblocks curblocks setlength maxblocksinstore datablocksize headerblocksize setlength maxblocksinstore setlength maxblocksinstore keylength blocksinstore maxblocksinstore blocksinstore recreate the index from the data file call this when the index has been corrupted param env berkeley db link environment param prefix datastore name prefix param store file store file where the actual data are stored param lru file lru data file flat file store for recovery param keys file keys data file flat file store for recvoery param fix secondary file flag file created when secondary database error occur if this file exist on start delete it and recreate the secondary database param max chk blocks maximum number of blocks param store shutdown hook link semi ordered shutdown hook for hooking database shutdown hook param reconstruct file flag file created when database crash param callback link store callback object for this store throws io exception throws database exception private berkeleydb freenet store environment env string prefix file store file file lru file file keys file file fix secondary file long max chk blocks semi ordered shutdown hook store shutdown hook file reconstruct file store callback callback random source random throws database exception io exception this env prefix store file lru file keys file fix secondary file max chk blocks true store shutdown hook reconstruct file callback random storefile lrufile keysfile fixsecondaryfile maxchkblocks storeshutdownhook semiorderedshutdownhook reconstructfile storecallback ioexception databaseexception berkeleydbfreenetstore storefile lrufile keysfile fixsecondaryfile maxchkblocks semiorderedshutdownhook storeshutdownhook reconstructfile storecallback randomsource databaseexception ioexception storefile lrufile keysfile fixsecondaryfile maxchkblocks storeshutdownhook reconstructfile private static void wipe old databases environment env string prefix wipe database env prefix chk wipe database env prefix chk accesstime wipe database env prefix chk blocknum system err println removed old database prefix wipeolddatabases wipedatabase wipedatabase chk_accesstime wipedatabase chk_blocknum private static void wipe database environment env string name wrapper manager signal starting 5 60 60 1000 logger normal berkeleydb freenet store class wiping database name try env remove database null name catch database not found exception e system err println database name does not exist deleting it catch database exception e logger error berkeleydb freenet store class could not remove old database name e e system err println could not remove old database name e e print stack trace wipedatabase wrappermanager signalstarting berkeleydbfreenetstore removedatabase databasenotfoundexception databaseexception berkeleydbfreenetstore printstacktrace reconstruct the database using flat file stores and other dark magic strong you are not expected to understand this strong dl dt header data dt dd read from storeraf always available dd dt full key dt dd read from keyraf maybe null dd dt routingkey dt dd ol li code callback routing key from full key code li li if code null code or code key verify exception code code callback construct get routing key code may throw code key verify exception code li ol code full key code and hence code callback routing key from full key code may be phantom hence we must verify code callback construct get routing key routingkey code on code fetch code dd dl on code operation status keyexist code or bad code callback construct code ol li insert a database entry with random key minimum lru 1 li li if code op operation status success code code add free block code li ol throws database exception throws io exception private void reconstruct throws database exception io exception if keysdb count 0 throw new illegal state exception store must be empty before reconstruction timeout must be well below integer max value it is added to previous timeouts in an integer value if it s too high we get wraparound and instant timeout int timeout int math min 7 24 60 60 1000 5 60 1000 storeraf length data block size header block size 1000l system err println reconstructing store index from store file callback callback allowing timeout ms logger error this reconstructing store index from store file callback callback wrapper manager signal starting timeout reusing the buffer is safe provided we don t do anything with the resulting store block byte header new byte header block size byte data new byte data block size byte key buf new byte key length long l 0 long dupes 0 long failures 0 long expected length storeraf length data block size header block size find minimum and maximum lru long minlru long max value long maxlru long min value try lruraf seek 0 for long i 0 i lruraf length 8 i long lru lruraf read long if lru maxlru maxlru lru if lru minlru minlru lru catch io exception e we don t want this to be fatal try storeraf seek 0 lruraf seek 0 long lruraf length lruraf length long keysraf length 0 if keysraf null keysraf seek 0 keysraf length keysraf length for l 0 true l if l 1024 0 system out println key l expected length ok dupes dupes failures failures long lru val 0 transaction t null boolean data read false if lruraf length l 1 8 try lru val lruraf read long catch eof exception e system err println eof reading lru file at lruraf get file pointer of lruraf length l l orig lru length lruraf length lru val 0 lruraf length 0 if lru val 0 logger minor this block l resetting lru lru val get new recently used else logger minor this block l lru lru val boolean read key false if keysraf null key buf null keysraf length l 1 key length try keysraf read fully key buf read key true catch eof exception e system err println eof reading keys file at keysraf get file pointer of keysraf length l l orig keys length keysraf length read key false if read key key buf null boolean key from data false try byte routingkey null if key buf null is all null key buf routingkey callback routing key from full key key buf if routingkey key buf copy it byte newkey new byte routingkey length system arraycopy routingkey 0 newkey 0 routingkey length routingkey newkey if data read storeraf seek l header block size data block size storeraf read fully header storeraf read fully data data read true if routingkey null is all null header is all null data key from data true try storable block block callback construct data header null key buf routingkey block get routing key catch key verify exception e string err bogus or unreconstructible key at slot l e lost block l logger error this err e system err println err failures if routingkey null can t recover mark this as free t environment begin transaction null null reconstruct add free block l t minlru t commit no sync t null continue t environment begin transaction null null store block store block new store block l lru val database entry routingkeydbe new database entry routingkey database entry blockdbe new database entry store block tuple binding object to entry store block blockdbe operation status op keysdb put no overwrite t routingkeydbe blockdbe if op operation status keyexist if key from data byte old routingkey routingkey try if data read storeraf seek l header block size data block size storeraf read fully header storeraf read fully data data read true storable block block callback construct data header null key buf routingkey block get routing key if arrays equals old routingkey routingkey dupes string err really duplicated block l key null is all null key buf routing key null is all null routingkey headers null is all null header data null is all null data logger error this err system err println err reconstruct add free block l t minlru else routingkeydbe new database entry routingkey op keysdb put no overwrite t routingkeydbe blockdbe if op operation status keyexist dupes string err duplicate block reconstructed the key different duplicate block l key null is all null key buf routing key null is all null routingkey headers null is all null header data null is all null data logger error this err system err println err reconstruct add free block l t minlru else if op operation status success failures string err unknown error op for duplicate block l after reconstructing key logger error this err system err println err reconstruct add free block l t minlru else it worked catch key verify exception e string err duplicate slot bogus or unreconstructible key at l e lost block l logger error this err e system err println err failures reconstruct add free block l t minlru else logger error this duplicate block l key null is all null key buf routing key null is all null routingkey headers null is all null header data null is all null data system err println duplicate block l key null is all null key buf routing key null is all null routingkey headers null is all null header data null is all null data dupes reconstruct add free block l t minlru t commit no sync t null continue else if op operation status success add free block l true failure op failures t commit no sync t null catch database exception e t abort below may also throw system err println error while reconstructing e e print stack trace finally if t null t abort catch eof exception e long size l data block size header block size if l expected length system err println found end of store truncating to l blocks size failures failures dupes dupes e print stack trace else system err println confirmed store is expected length blocks long failures failures dupes dupes blocks in store l try storeraf set length size lruraf set length l 8 if keysraf null keysraf set length l key length catch io exception e1 system err println failed to set size fullkey routingkeyfromfullkey keyverifyexception getroutingkey keyverifyexception fullkey routingkeyfromfullkey getroutingkey operationstatus operationstatus addfreeblock databaseexception ioexception databaseexception ioexception illegalstateexception max_value datablocksize headerblocksize wrappermanager signalstarting storeblock headerblocksize datablocksize keybuf keylength expectedlength datablocksize headerblocksize max_value min_value readlong ioexception lruraflength keysraflength keysraflength expectedlength lruval dataread lruraflength lruval readlong eofexception getfilepointer lruraflength lruval lruraflength lruval lruval getnewrecentlyused lruval readkey keybuf keysraflength keylength readfully keybuf readkey eofexception getfilepointer keysraflength readkey readkey keybuf keyfromdata keybuf isallnull keybuf routingkeyfromfullkey keybuf keybuf dataread headerblocksize datablocksize readfully readfully dataread isallnull isallnull keyfromdata storableblock keybuf getroutingkey keyverifyexception begintransaction reconstructaddfreeblock commitnosync begintransaction storeblock storeblock storeblock lruval databaseentry databaseentry databaseentry databaseentry storeblocktuplebinding objecttoentry storeblock operationstatus putnooverwrite operationstatus keyfromdata oldroutingkey dataread headerblocksize datablocksize readfully readfully dataread storableblock keybuf getroutingkey oldroutingkey isallnull keybuf isallnull isallnull isallnull reconstructaddfreeblock databaseentry putnooverwrite operationstatus isallnull keybuf isallnull isallnull isallnull reconstructaddfreeblock operationstatus reconstructaddfreeblock keyverifyexception reconstructaddfreeblock isallnull keybuf isallnull isallnull isallnull isallnull keybuf isallnull isallnull isallnull reconstructaddfreeblock commitnosync operationstatus addfreeblock commitnosync databaseexception printstacktrace eofexception datablocksize headerblocksize expectedlength printstacktrace expectedlength blocksinstore setlength setlength setlength keylength ioexception private void reconstruct add free block long l transaction t long lru throws database exception store block store block new store block l lru byte buf new byte 32 random next bytes buf database entry routingkeydbe new database entry buf database entry blockdbe new database entry store block tuple binding object to entry store block blockdbe operation status op keysdb put no overwrite t routingkeydbe blockdbe if op operation status success logger error this impossible operation status inserting bogus key to lru op add free block l true impossible to add invalid to lru op reconstructaddfreeblock databaseexception storeblock storeblock storeblock nextbytes databaseentry databaseentry databaseentry databaseentry storeblocktuplebinding objecttoentry storeblock operationstatus putnooverwrite operationstatus addfreeblock private boolean is all null byte buf for int i 0 i buf length i if buf i 0 return false return true isallnull inherit doc public storable block fetch byte routingkey byte full key boolean dont promote throws io exception database entry routingkeydbe new database entry routingkey database entry blockdbe new database entry int running synchronized this if closed return null running running fetches cursor c null transaction t null try t environment begin transaction null null c keysdb open cursor t null we will have to write unless both dont promote and the key is valid the lock only applies to this record so it s not a big problem for our use what is a big problem is that if we take a lock mode default and two threads access the same key they will both take the read lock and then both try to take the write lock neither can relinquish the read in order for the other to take the write so we re screwed if logminor logger minor this fetching hex util bytes to hex routingkey dont promote dont promote for callback running fetches running if c get search key routingkeydbe blockdbe lock mode rmw operation status success c close c null t abort t null synchronized this misses if logminor logger minor this not found return null store block store block store block tuple binding entry to object blockdbe storable block block null if logminor logger minor this reading block store block offset try byte header new byte header block size byte data new byte data block size try fc read store store block offset header data catch eof exception e logger error this no block c close c null keysdb delete t routingkeydbe t commit t null add free block store block offset true data off end of store file return null block callback construct data header routingkey full key write the key byte new full key block get full key if keysraf null fc write key store block offset new full key if arrays equals block get routing key routingkey synchronized this misses keysdb delete t routingkeydbe insert the block into the index set the lru to minimum 1 long lru get min recently used t 1 logger normal this does not verify not the expected key setting access time to lru for hex util bytes to hex routingkey store block new store block store block offset lru routingkeydbe new database entry block get routing key blockdbe new database entry store block tuple binding object to entry store block blockdbe try keysdb put t routingkeydbe blockdbe if full key null full key block get full key if keysraf null fc write key store block offset full key if logdebug logger debug this written full key length full key length to block store block offset at store block offset key length for callback else if logdebug logger debug this not writing full key length full key length for block store block offset for callback catch database exception e logger error this caught database exception e while replacing element add free block store block offset true bogus key c close c null t commit t null return null logger normal this successfully replaced entry at block number store block offset lru lru c close c null t commit t null return null if dont promote store block update recently used database entry updatedbe new database entry store block tuple binding object to entry store block updatedbe c put current updatedbe c close c null t commit t null fc writelru store block offset store block recently used else c close c null t abort t null if logminor logger minor this headers header length bytes hash fields hash code header logger minor this data data length bytes hash fields hash code data fetching hex util bytes to hex routingkey catch key verify exception ex logger normal this does not verify ex setting access time to 0 for hex util bytes to hex routingkey ex synchronized this misses clear the key in the keys file byte buf new byte key length for int i 0 i buf length i buf i 0 fixme unnecessary if keysraf null fc write key store block offset buf keysdb delete t routingkeydbe insert the block into the index with a random key so that it s part of the lru set the lru to minimum 1 long lru get min recently used t 1 byte random key new byte key length random next bytes random key store block new store block store block offset lru routingkeydbe new database entry random key blockdbe new database entry store block tuple binding object to entry store block blockdbe try keysdb put t routingkeydbe blockdbe catch database exception e logger error this caught database exception e while adding corrupt element to lru add free block store block offset true bogus key c close c null t commit t null return null c close c null t commit t null return null synchronized this hits return block catch closed channel exception cce the channel is already close logger debug this channel closed cce return null catch throwable ex fixme ugly if ex instanceof io exception synchronized this if closed return null if c null try c close catch database exception ex2 if t null try t abort catch database exception ex2 check secondary database error ex logger error this caught ex ex ex print stack trace throw new io exception ex get message finally int x synchronized this x running fetches if logminor logger minor this running fetches now x inheritdoc storableblock fullkey dontpromote ioexception databaseentry databaseentry databaseentry databaseentry runningfetches begintransaction opencursor dontpromote lockmode hexutil bytestohex dontpromote dontpromote getsearchkey lockmode operationstatus storeblock storeblock storeblocktuplebinding entrytoobject storableblock storeblock headerblocksize datablocksize fcreadstore storeblock eofexception addfreeblock storeblock fullkey newfullkey getfullkey fcwritekey storeblock newfullkey getroutingkey getminrecentlyused accesstime hexutil bytestohex storeblock storeblock storeblock databaseentry getroutingkey databaseentry storeblocktuplebinding objecttoentry storeblock fullkey fullkey getfullkey fcwritekey storeblock fullkey fullkey storeblock storeblock keylength fullkey storeblock databaseexception addfreeblock storeblock storeblock dontpromote storeblock updaterecentlyused databaseentry databaseentry storeblocktuplebinding objecttoentry storeblock putcurrent fcwritelru storeblock storeblock recentlyused hashcode hashcode hexutil bytestohex keyverifyexception accesstime hexutil bytestohex keylength fcwritekey storeblock getminrecentlyused randomkey keylength nextbytes randomkey storeblock storeblock storeblock databaseentry randomkey databaseentry storeblocktuplebinding objecttoentry storeblock databaseexception addfreeblock storeblock closedchannelexception ioexception databaseexception databaseexception checksecondarydatabaseerror printstacktrace ioexception getmessage runningfetches private void add free block long offset boolean loud string reason if free blocks push offset if loud system err println freed block offset reason logger normal this freed block offset reason else if logminor logger minor this freed block offset reason else if logminor logger minor this already freed block offset reason addfreeblock freeblocks inherit doc public void put storable block block byte routingkey byte full key byte data byte header boolean overwrite throws key collision exception io exception if logminor logger minor this putting hex util bytes to hex routingkey for callback storable block old block fetch routingkey full key false if old block null if collision possible return if block equals old block if overwrite throw new key collision exception else overwrite key unchanged routingkey full key data header else return already in store else inner put block routingkey full key data header inheritdoc storableblock fullkey keycollisionexception ioexception hexutil bytestohex storableblock oldblock fullkey oldblock collisionpossible oldblock keycollisionexception overwritekeyunchanged fullkey innerput fullkey overwrite a block with a new block which has the same key private boolean overwrite key unchanged byte routingkey byte full key byte data byte header throws io exception synchronized this if closed return false database entry routingkeydbe new database entry routingkey database entry blockdbe new database entry cursor c null transaction t null try t environment begin transaction null null c keysdb open cursor t null lock the record if c get search key routingkeydbe blockdbe lock mode rmw operation status success c close c null t abort t null return false store block store block store block tuple binding entry to object blockdbe fc write store store block offset header data if keysraf null fc write key store block offset full key unlock record c close c null t commit t null catch throwable ex fixme ugly check secondary database error ex logger error this caught ex ex ex print stack trace throw new io exception ex get message finally if c null try c close catch database exception ex2 if t null try t abort catch database exception ex2 return true overwritekeyunchanged fullkey ioexception databaseentry databaseentry databaseentry databaseentry begintransaction opencursor getsearchkey lockmode operationstatus storeblock storeblock storeblocktuplebinding entrytoobject fcwritestore storeblock fcwritekey storeblock fullkey checksecondarydatabaseerror printstacktrace ioexception getmessage databaseexception databaseexception private void inner put storable block block byte routingkey byte full key byte data byte header throws io exception synchronized this if closed return if data length data block size logger error this this data is data length bytes should be data block size return if header length header block size logger error this this header is data length bytes should be header block size return transaction t null try t environment begin transaction null null database entry routingkeydbe new database entry routingkey database entry blockdbe new database entry check whether it already exists if logminor logger minor this putting key block checking whether it exists first operation status result keysdb get t routingkeydbe blockdbe lock mode rmw if result operation status success result operation status keyexist if logminor logger minor this key already exists key already exists but is it valid t abort t null if fetch routingkey full key false null return old key was valid we are not overwriting if we are here it was corrupt or it was just deleted so we can replace it if logminor logger minor this old key was invalid adding anyway inner put block routingkey full key data header return else if result operation status keyempty logger error this got keyempty record deleted shouldn t be possible with record locking put it in anyway else if result operation status notfound good else throw new illegal state exception unknown operation status result write block header data t routingkeydbe full key t commit t null if logminor logger minor this headers header length bytes hash fields hash code header logger minor this data data length bytes hash fields hash code data putting hex util bytes to hex routingkey catch closed channel exception cce the channel is already close logger debug this channel closed cce catch throwable ex fixme ugly if ex instanceof io exception synchronized this if closed return check secondary database error ex logger error this caught ex ex ex print stack trace if ex instanceof io exception throw io exception ex else throw new io exception ex get message finally if t null try t abort catch database exception ex2 innerput storableblock fullkey ioexception datablocksize datablocksize headerblocksize headerblocksize begintransaction databaseentry databaseentry databaseentry databaseentry operationstatus lockmode operationstatus operationstatus fullkey innerput fullkey operationstatus operationstatus illegalstateexception writeblock fullkey hashcode hashcode hexutil bytestohex closedchannelexception ioexception checksecondarydatabaseerror printstacktrace ioexception ioexception ioexception getmessage databaseexception private void overwritelru block byte header byte data transaction t database entry routingkeydbe byte full key throws database exception io exception overwrite an other block cursor c access timedb open cursor t null store block old store block try database entry keydbe new database entry database entry datadbe new database entry c get first keydbe datadbe lock mode rmw old store block store block tuple binding entry to object datadbe c delete finally c close deleted so we can now reuse it because we acquired a write lock nobody else has taken it fixme if this fails we can leak the block store block store block new store block this old store block get offset database entry blockdbe new database entry store block tuple binding object to entry store block blockdbe keysdb put t routingkeydbe blockdbe fc write store store block get offset header data fc writelru store block get offset store block recently used if keysraf null fc write key store block get offset full key synchronized this writes overwritelrublock databaseentry fullkey databaseexception ioexception accesstimedb opencursor storeblock oldstoreblock databaseentry databaseentry databaseentry databaseentry getfirst lockmode oldstoreblock storeblocktuplebinding entrytoobject storeblock storeblock storeblock oldstoreblock getoffset databaseentry databaseentry storeblocktuplebinding objecttoentry storeblock fcwritestore storeblock getoffset fcwritelru storeblock getoffset storeblock recentlyused fcwritekey storeblock getoffset fullkey private boolean write new block long block num byte header byte data transaction t database entry routingkeydbe byte full key throws database exception io exception store block store block new store block this block num long lru value store block recently used database entry blockdbe new database entry store block tuple binding object to entry store block blockdbe try keysdb put t routingkeydbe blockdbe catch database exception e database entry block num entry new database entry database entry found new database entry long binding long to entry block num block num entry operation status success block numdb get t block num entry found lock mode default if success operation status keyexist success operation status success system err println trying to overwrite block block num but already used get name for e e print stack trace logger error this trying to overwrite block block num but already used get name for e return false else logger minor this key doesn t exist for block num block num but caught e e throw e fc write store block num header data fc writelru block num lru value if keysraf null fc write key block num full key if logdebug logger debug this written full key length full key length to block block num at block num key length for callback else if logdebug logger debug this not writing full key length full key length for block block num for callback synchronized this writes return true writenewblock blocknum databaseentry fullkey databaseexception ioexception storeblock storeblock storeblock blocknum lruvalue storeblock recentlyused databaseentry databaseentry storeblocktuplebinding objecttoentry storeblock databaseexception databaseentry blocknumentry databaseentry databaseentry databaseentry longbinding longtoentry blocknum blocknumentry operationstatus blocknumdb blocknumentry lockmode operationstatus operationstatus blocknum getname printstacktrace blocknum getname blocknum fcwritestore blocknum fcwritelru blocknum lruvalue fcwritekey blocknum fullkey fullkey blocknum blocknum keylength fullkey blocknum get prefix name of this database such as tt ssk cache tt tt ssk store tt etc public final string get name return name getname private void check secondary database error throwable ex string msg ex get message if ex instanceof database exception if msg null msg index of missing key in the primary database 1 msg index of the primary record contains a key that is not present in the secondary 1 try fix secondary file create new file catch io exception e logger error this corrupt secondary database get name but could not create flag file fix secondary file system err println corrupt secondary database get name but could not create flag file fix secondary file return not sure what else we can do logger error this corrupt secondary database get name should be cleaned up on restart system err println corrupt secondary database get name should be cleaned up on restart system err println flusing data store files get name flush and closeraf storeraf storeraf null flush and closeraf lruraf lruraf null flush and closeraf keysraf keysraf null wrapper manager restart system exit freenet node node init exception exit database requires restart else if ex instanceof db checksum exception ex instanceof run recovery exception ex instanceof log file not found exception ugh we really shouldn t have to do this msg null msg index of log file not found exception 0 msg index of db checksum exception 0 msg index of run recovery exception 0 system err println corrupt database will be reconstructed on restart logger error this corrupt database will be reconstructed on restart try reconstruct file create new file catch io exception e logger error this corrupt database get name but could not create flag file reconstruct file system err println corrupt database get name but could not create flag file reconstruct file return not sure what else we can do system err println flusing data store files get name flush and closeraf storeraf storeraf null flush and closeraf lruraf lruraf null flush and closeraf keysraf keysraf null system err println restarting to fix corrupt store database logger error this restarting to fix corrupt store database wrapper manager restart else if ex get cause null check secondary database error ex get cause checksecondarydatabaseerror getmessage databaseexception indexof indexof fixsecondaryfile createnewfile ioexception getname fixsecondaryfile getname fixsecondaryfile getname getname getname flushandcloseraf flushandcloseraf flushandcloseraf wrappermanager nodeinitexception exit_database_requires_restart dbchecksumexception runrecoveryexception logfilenotfoundexception indexof logfilenotfoundexception indexof dbchecksumexception indexof runrecoveryexception reconstructfile createnewfile ioexception getname reconstructfile getname reconstructfile getname flushandcloseraf flushandcloseraf flushandcloseraf wrappermanager getcause checksecondarydatabaseerror getcause private void write block byte header byte data transaction t database entry routingkeydbe byte full key throws database exception io exception long block num keep trying until we succeed while true if block num grab free block 0 if logminor logger minor this overwriting free block block num if write new block block num header data t routingkeydbe full key return else if blocks in store max blocks in store expand the store file synchronized blocks in store lock block num blocks in store blocks in store if logminor logger minor this expanding store and writing block block num just in case free blocks remove block num if write new block block num header data t routingkeydbe full key return else if logminor logger minor this overwriting lru block overwritelru block header data t routingkeydbe full key return writeblock databaseentry fullkey databaseexception ioexception blocknum blocknum grabfreeblock blocknum writenewblock blocknum fullkey blocksinstore maxblocksinstore blocksinstorelock blocknum blocksinstore blocksinstore blocknum freeblocks blocknum writenewblock blocknum fullkey overwritelrublock fullkey private long grab free block while free blocks is empty long block num free blocks remove first if block num max blocks in store return block num return 1 grabfreeblock freeblocks isempty blocknum freeblocks removefirst blocknum maxblocksinstore blocknum private long offset public store block final berkeleydb freenet store bdbfs long offset this offset bdbfs get new recently used storeblock berkeleydbfreenetstore getnewrecentlyused public store block long offset long recently used this offset offset this recently used recently used storeblock recentlyused recentlyused recentlyused public long get recently used return recently used getrecentlyused recentlyused public void set recently used to zero recently used 0 setrecentlyusedtozero recentlyused public void update recently used recently used get new recently used updaterecentlyused recentlyused getnewrecentlyused public long get offset return offset getoffset override public void object to entry store block my data tuple output to to write long my data get offset to write long my data get recently used objecttoentry storeblock mydata tupleoutput writelong mydata getoffset writelong mydata getrecentlyused override public store block entry to object tuple input ti long offset ti read long long last accessed ti read long store block store block new store block offset last accessed return store block storeblock entrytoobject tupleinput readlong lastaccessed readlong storeblock storeblock storeblock lastaccessed storeblock private final tuple binding store block the binding public access time key creator tuple binding store block the binding1 the binding the binding1 tuplebinding storeblock thebinding accesstimekeycreator tuplebinding storeblock thebinding1 thebinding thebinding1 public boolean create secondary key secondary database sec db database entry key entry database entry data entry database entry result entry store block storeblock the binding entry to object data entry long binding long to entry storeblock get recently used result entry return true createsecondarykey secondarydatabase secdb databaseentry keyentry databaseentry dataentry databaseentry resultentry storeblock thebinding entrytoobject dataentry longbinding longtoentry getrecentlyused resultentry private final tuple binding store block the binding public block number key creator tuple binding store block the binding1 the binding the binding1 tuplebinding storeblock thebinding blocknumberkeycreator tuplebinding storeblock thebinding1 thebinding thebinding1 public boolean create secondary key secondary database sec db database entry key entry database entry data entry database entry result entry store block storeblock the binding entry to object data entry long binding long to entry storeblock offset result entry return true createsecondarykey secondarydatabase secdb databaseentry keyentry databaseentry dataentry databaseentry resultentry storeblock thebinding entrytoobject dataentry longbinding longtoentry resultentry private class shutdown hook extends thread override public void run system err println closing database due to shutdown close true shutdownhook private static void flush and closeraf random access file file try if file null file get channel force true catch io exception e ignore closeraf file false flushandcloseraf randomaccessfile getchannel ioexception private static void closeraf random access file file boolean log error try if file null file close catch io exception e if log error system err println caught closing file e e print stack trace randomaccessfile logerror ioexception logerror printstacktrace private static void closedb database db boolean log error try if db null db close catch database exception e if log error system err println caught closing database e e print stack trace logerror databaseexception logerror printstacktrace private void close boolean sleep try fixme we should be sure all access to the database has stopped before we try to close it currently we just guess this is nothing too problematic however since the worst thing that should happen is that we miss the last few store s and get an exception logminor logger should log logger minor this if logminor logger minor this closing database this synchronized this closed true give all threads some time to complete if sleep try thread sleep 5000 catch interrupted exception ie logger error this thread interrupted ie if really closed logger error this already closed this return synchronized close lock if really closed logger error this already closed this return closeraf storeraf true storeraf null closeraf lruraf true lruraf null closeraf keysraf true keysraf null closedb access timedb true access timedb null closedb block numdb true block numdb null closedb keysdb true keysdb null if logminor logger minor this closing database finished system err println closed database catch runtime exception ex logger error this error while closing database ex ex print stack trace finally really closed true shouldlog interruptedexception reallyclosed closelock reallyclosed accesstimedb accesstimedb blocknumdb blocknumdb runtimeexception printstacktrace reallyclosed private long highest block number in database throws database exception cursor c null try c block numdb open cursor null null database entry keydbe new database entry database entry datadbe new database entry if c get last keydbe datadbe null operation status success store block store block store block tuple binding entry to object datadbe return store block offset 1 c close c null finally if c null try c close catch database exception e logger error this caught e e return 0 highestblocknumberindatabase databaseexception blocknumdb opencursor databaseentry databaseentry databaseentry databaseentry getlast operationstatus storeblock storeblock storeblocktuplebinding entrytoobject storeblock databaseexception private long countchk blocks from file throws io exception int key size header block size data block size long file size storeraf length return file size key size countchkblocksfromfile ioexception keysize headerblocksize datablocksize filesize filesize keysize private long get max recently used long max recently used 0 cursor c null try c access timedb open cursor null null database entry keydbe new database entry database entry datadbe new database entry if c get last keydbe datadbe null operation status success store block store block store block tuple binding entry to object datadbe max recently used store block get recently used c close c null catch database exception ex ex print stack trace finally if c null try c close catch database exception e logger error this caught e e return max recently used getmaxrecentlyused maxrecentlyused accesstimedb opencursor databaseentry databaseentry databaseentry databaseentry getlast operationstatus storeblock storeblock storeblocktuplebinding entrytoobject maxrecentlyused storeblock getrecentlyused databaseexception printstacktrace databaseexception maxrecentlyused private long get min recently used transaction t long min recently used 0 cursor c null try c access timedb open cursor t null database entry keydbe new database entry database entry datadbe new database entry if c get first keydbe datadbe null operation status success store block store block store block tuple binding entry to object datadbe min recently used store block get recently used c close c null catch database exception ex ex print stack trace finally if c null try c close catch database exception e logger error this caught e e return min recently used getminrecentlyused minrecentlyused accesstimedb opencursor databaseentry databaseentry databaseentry databaseentry getfirst operationstatus storeblock storeblock storeblocktuplebinding entrytoobject minrecentlyused storeblock getrecentlyused databaseexception printstacktrace databaseexception minrecentlyused private long get new recently used synchronized last recently used sync last recently used return last recently used getnewrecentlyused lastrecentlyusedsync lastrecentlyused lastrecentlyused inherit doc public void set max keys long max store keys boolean force big shrink throws database exception io exception synchronized this max blocks in store max store keys maybe online shrink false inheritdoc setmaxkeys maxstorekeys forcebigshrink databaseexception ioexception maxblocksinstore maxstorekeys maybeonlineshrink inherit doc public long get max keys return max blocks in store inheritdoc getmaxkeys maxblocksinstore inherit doc public long hits return hits inheritdoc inherit doc public long misses return misses inheritdoc inherit doc public long writes return writes inheritdoc inherit doc public long key count return blocks in store inheritdoc keycount blocksinstore remove all secondary database of this datastore throws database exception private void remove secondary database throws database exception logger error this recreating secondary databases logger error this this may take some time system err println recreating secondary databases system err println this may take some time wrapper manager signal starting int math min integer max value 5 60 1000 keysdb count 100l of course it s not a solution but a quick fix integer max value seems to trigger an overflow or whatever either we find out what the maximum value is and we do a static method somewhere ensuring it won t overflow or we debug the wrapper nb it might be a wrapper version mismatch problem nextgens try try environment remove database null name chk accesstime catch database not found exception e cool try environment remove database null name chk blocknum catch database not found exception e cool catch database exception e close false throw e databaseexception removesecondarydatabase databaseexception wrappermanager signalstarting max_value max_value removedatabase chk_accesstime databasenotfoundexception removedatabase chk_blocknum databasenotfoundexception databaseexception open a secondary database of this datastore param db name full database name param create code true code if allowed to create a new secondary database code false code otherwise param populate code true code if populate this secondary database automatically code false code otherwise param secondary key creator link secondary key creator for this secondary database instance return throws database exception private secondary database open secondary data base string db name boolean create boolean populate boolean sorted duplicates secondary key creator secondary key creator throws database exception secondary database db null secondary config sec db config new secondary config sec db config set allow create create sec db config set sorted duplicates sorted duplicates sec db config set transactional true sec db config set allow populate populate sec db config set key creator secondary key creator try try system err println opening secondary database db name db environment open secondary database null db name keysdb sec db config the below is too slow to be useful because secondary database count isn t optimised long chkdb count keysdb count system err println counting size of access times database long db count db count if db count chkdb count system err println access times database db count but main database chkdb count throw new database exception needs repopulation catch database exception e failed try to create it wrapper manager signal starting int math min integer max value 5 60 1000l keysdb count 100l of course it s not a solution but a quick fix integer max value seems to trigger an overflow or whatever either we find out what the maximum value is and we do a static method somewhere ensuring it won t overflow or we debug the wrapper nb it might be a wrapper version missmatch problem nextgens system err println reconstructing index for secondary database db name logger error this reconstructing index for secondary database db name if db null db close try environment remove database null db name catch database not found exception e1 ok sec db config set allow create true sec db config set allow populate true db environment open secondary database null db name keysdb sec db config catch database exception e1 log this now because close will probably throw too system err println error opening secondary database db name e1 print stack trace logger error this error opening secondary database db name e1 get message e1 close false throw e1 system err println opened secondary database db name return db dbname secondarykeycreator secondarykeycreator databaseexception secondarydatabase opensecondarydatabase dbname sortedduplicates secondarykeycreator secondarykeycreator databaseexception secondarydatabase secondaryconfig secdbconfig secondaryconfig secdbconfig setallowcreate secdbconfig setsortedduplicates sortedduplicates secdbconfig settransactional secdbconfig setallowpopulate secdbconfig setkeycreator secondarykeycreator dbname opensecondarydatabase dbname secdbconfig secondarydatabase chkdbcount dbcount dbcount chkdbcount dbcount chkdbcount databaseexception databaseexception wrappermanager signalstarting max_value max_value dbname dbname removedatabase dbname databasenotfoundexception secdbconfig setallowcreate secdbconfig setallowpopulate opensecondarydatabase dbname secdbconfig databaseexception dbname printstacktrace dbname getmessage dbname private void fc writelru long entry long data throws io exception byte buffer bf byte buffer allocate 8 bf put long data bf flip do int byte written lrufc write bf entry 8 bf position if byte written 1 throw new eof exception while bf has remaining fcwritelru ioexception bytebuffer bytebuffer putlong bytewritten bytewritten eofexception hasremaining private long fc readlru long entry throws io exception byte buffer bf byte buffer allocate 8 do int byte read lrufc read bf entry 8 bf position if byte read 1 throw new eof exception while bf has remaining bf flip return bf get long fcreadlru ioexception bytebuffer bytebuffer byteread byteread eofexception hasremaining getlong private void fc read key long entry byte data throws io exception byte buffer bf byte buffer wrap data do int byte read keysfc read bf entry key length bf position if byte read 1 throw new eof exception while bf has remaining fcreadkey ioexception bytebuffer bytebuffer byteread keylength byteread eofexception hasremaining private void fc write key long entry byte data throws io exception assert data length key length byte buffer bf byte buffer wrap data do int byte written keysfc write bf entry key length bf position if byte written 1 throw new eof exception while bf has remaining fcwritekey ioexception keylength bytebuffer bytebuffer bytewritten keylength bytewritten eofexception hasremaining private void fc write store long entry byte header byte data throws io exception byte buffer bf byte buffer allocate header block size data block size bf put header bf put data bf flip do int byte written storefc write bf header block size data block size entry bf position if byte written 1 throw new eof exception while bf has remaining fcwritestore ioexception bytebuffer bytebuffer headerblocksize datablocksize bytewritten headerblocksize datablocksize bytewritten eofexception hasremaining private void fc read store long entry byte header byte data throws io exception byte buffer bf byte buffer allocate header block size data block size do int data read storefc read bf header block size data block size entry if data read 1 throw new eof exception while bf has remaining bf flip bf get header bf get data fcreadstore ioexception bytebuffer bytebuffer headerblocksize datablocksize dataread headerblocksize datablocksize dataread eofexception hasremaining public void handle low memory throws exception flush all if storefc null storefc force true if keysfc null keysfc force true if lrufc null lrufc force true environment evict memory handlelowmemory evictmemory public void handle out of memory throws exception database likely to be corrupted reconstruct it just in case reconstruct file create new file flush all if storefc null storefc force true if keysfc null keysfc force true if lrufc null lrufc force true handleoutofmemory reconstructfile createnewfile return public static environment config getbdb config first global settings percentage of the database that must contain usefull data decrease to increase performance increase to save disk space let it stay at the default of 50 for best performance we only use it for indexes so it won t get huge system set property je cleaner min utilization 90 delete empty log files system set property je cleaner expunge true environment config env config new environment config env config set allow create true env config set transactional true env config set txn write no sync true env config set lock timeout 600 1000 1000 should be long enough even for severely overloaded nodes note that the above is in micro seconds env config set config param je log fault read size 6144 http www oracle com technology products berkeley db faq je faq html 35 env config set config param je evictor lru only false is not a mutable config option and must be set before opening of environment env config set config param je evictor nodes per scan 50 is not a mutable config option and must be set before opening of environment recommended is 100 but smaller values reduce latency cost tune latency env config set config param je env background read limit 65536 env config set config param je env background write limit 65536 env config set config param je env background sleep interval 10000 microseconds 10ms return env config environmentconfig getbdbconfig setproperty minutilization setproperty environmentconfig envconfig environmentconfig envconfig setallowcreate envconfig settransactional envconfig settxnwritenosync envconfig setlocktimeout envconfig setconfigparam faultreadsize je_faq envconfig setconfigparam lruonly envconfig setconfigparam nodesperscan envconfig setconfigparam backgroundreadlimit envconfig setconfigparam backgroundwritelimit envconfig setconfigparam backgroundsleepinterval envconfig public long get bloom false positive return 1 getbloomfalsepositive public boolean probably in store byte routing key this needs to be fast so that it can be run from any thread accessing the bdbje database is often slow involves many disk seeks and can stall for long periods return true database entry routingkeydbe new database entry routing key database entry blockdbe new database entry synchronized this if closed return false try return keysdb get null routingkeydbe blockdbe lock mode read uncommitted operation status success catch database exception e return false probablyinstore routingkey databaseentry databaseentry routingkey databaseentry databaseentry lockmode read_uncommitted operationstatus databaseexception option sub config config string name config callback t cb int sort order boolean expert boolean force write string short desc string long desc data type data type this config config this name name this cb cb this sort order sort order this expert expert this short desc short desc this long desc long desc this force write force write this data type data type subconfig configcallback sortorder forcewrite shortdesc longdesc datatype datatype sortorder sortorder shortdesc shortdesc longdesc longdesc forcewrite forcewrite datatype datatype set this option s current value to a string will call the callback does not care whether the value of the option has changed public final void set value string val throws invalid config value exception node need restart exception t x parse string val set x setvalue invalidconfigvalueexception nodeneedrestartexception parsestring protected abstract t parse string string val throws invalid config value exception parsestring invalidconfigvalueexception protected abstract t parse string string val throws invalid config value exception protected abstract string to string t val parsestring invalidconfigvalueexception tostring protected final void set t val throws invalid config value exception node need restart exception try cb set val current value val catch node need restart exception e current value val throw e invalidconfigvalueexception nodeneedrestartexception currentvalue nodeneedrestartexception currentvalue get the current value of the option as a string public final string get value string return to string current value getvaluestring tostring currentvalue set to a value from the config file this is not passed on to the callback as we expect the client side initialization to check the value the callback is not valid until the client calls finished initialization throws invalid config value exception public final void set initial value string val throws invalid config value exception current value parse string val finishedinitialization invalidconfigvalueexception setinitialvalue invalidconfigvalueexception currentvalue parsestring call the callback with the current value of the option public void force update throws invalid config value exception node need restart exception set value get value string forceupdate invalidconfigvalueexception nodeneedrestartexception setvalue getvaluestring public string get name return name getname public string get short desc return short desc getshortdesc shortdesc public string get long desc return long desc getlongdesc longdesc public boolean is expert return expert isexpert public boolean is forced write return force write isforcedwrite forcewrite public int get sort order return sort order getsortorder sortorder public data type get data type return data type datatype getdatatype datatype public string get data type str switch data type case string return string case number return number case boolean return boolean case string array return string array default return null getdatatypestr datatype string_array stringarray get the current value this is the value in use if we have finished initialization otherwise it is the value set at startup possibly the default public final t get value if config has finished initialization return current value cb get else return current value getvalue hasfinishedinitialization currentvalue currentvalue is this option set to the default public boolean is default get value return current value null false current value equals default value isdefault getvalue currentvalue currentvalue defaultvalue set to the default don t use after completed initialization as this does not call the callback public final void set default current value default value setdefault currentvalue defaultvalue public final string get default return to string default value getdefault tostring defaultvalue public final config callback t get callback return cb configcallback getcallback public final class darken composite extends rgb composite public darken composite float alpha super alpha darkencomposite rgbcomposite darkencomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr dir sr dog dig sg dig sg dob dib sb dib sb float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac protected final int k n protected abstract void loadfec protected fec codec int k int n this k k this n n if n 0 n k throw new illegal argument exception invalid k k n n feccodec illegalargumentexception get a codec where we know both the number of data blocks and the number of check blocks and the codec type normally for decoding public static fec codec get codec short splitfile type int data blocks int check blocks if logger should log logger minor fec codec class logger minor fec codec class get codec splitfile type splitfile type data blocks data blocks check blocks check blocks if splitfile type metadata splitfile nonredundant return null if splitfile type metadata splitfile onion standard return standard onionfec codec get instance data blocks check blocks else return null feccodec getcodec splitfiletype datablocks checkblocks shouldlog feccodec feccodec getcodec splitfiletype splitfiletype datablocks datablocks checkblocks checkblocks splitfiletype splitfile_nonredundant splitfiletype splitfile_onion_standard standardonionfeccodec getinstance datablocks checkblocks get a codec where we know only the number of data blocks and the codec type normally for encoding public static fec codec get codec short splitfile type int data blocks if splitfile type metadata splitfile nonredundant return null if splitfile type metadata splitfile onion standard int check blocks standard onion check blocks data blocks return standard onionfec codec get instance data blocks check blocks else return null feccodec getcodec splitfiletype datablocks splitfiletype splitfile_nonredundant splitfiletype splitfile_onion_standard checkblocks standardonioncheckblocks datablocks standardonionfeccodec getinstance datablocks checkblocks private static int standard onion check blocks int data blocks alchemy what we do know is that redundancy by fec is much more efficient than redundancy by simply duplicating blocks for obvious reasons see e g wuala but we have to have some redundancy at the duplicating blocks level because we do use some keys directly etc we store an insert in 3 nodes we also cache it on 20 nodes but generally the key will fall out of the caches within days so long term it s 3 multiplied by 2 here makes 6 used to be 1 5 3 4 5 wuala uses 5 but that s all fec int check blocks data blocks high level simple client impl splitfile check blocks per segment high level simple client impl splitfile blocks per segment if data blocks high level simple client impl splitfile check blocks per segment check blocks high level simple client impl splitfile check blocks per segment return check blocks standardonioncheckblocks datablocks checkblocks datablocks highlevelsimpleclientimpl splitfile_check_blocks_per_segment highlevelsimpleclientimpl splitfile_blocks_per_segment datablocks highlevelsimpleclientimpl splitfile_check_blocks_per_segment checkblocks highlevelsimpleclientimpl splitfile_check_blocks_per_segment checkblocks public static int get check blocks short splitfile type int data blocks if splitfile type metadata splitfile onion standard return standard onion check blocks data blocks else return 0 getcheckblocks splitfiletype datablocks splitfiletype splitfile_onion_standard standardonioncheckblocks datablocks how many check blocks public abstract int count check blocks countcheckblocks protected void real decode splitfile block data block status splitfile block check block status int block length bucket factory bf throws io exception loadfec logminor logger should log logger minor this if logminor logger minor this doing decode data block status length data blocks check block status length check blocks block length block length with this new exception debug if data block status length check block status length n throw new illegal argument exception if data block status length k throw new illegal argument exception buffer packets new buffer k bucket buckets new bucket n data input stream readers new data input stream n output stream writers new output stream k int number to decode 0 can be less than n k try byte real buffer new byte k stripe size int packet indexes new int k for int i 0 i packet indexes length i packet indexes i 1 int idx 0 for int i 0 i k i packets i new buffer real buffer i stripe size stripe size shortcut due to the not fetching last block code we need to check here rather than relying on number to decode since the last data block won t be part of number to decode boolean need decode false for int i 0 i data block status length i if data block status i get data null need decode true if need decode return for int i 0 i data block status length i buckets i data block status i get data if buckets i null buckets i bf make bucket block length writers i buckets i get output stream if logminor logger minor this writers i null readers i null number to decode else long sz buckets i size if sz block length if i data block status length 1 throw new illegal argument exception all buckets must be the full size caller must pad if needed but data bucket i of data block status length data block status i is sz not block length else if logminor logger minor this writers i null already filled writers i null readers i new data input stream buckets i get input stream packet indexes idx i for int i 0 i check block status length i buckets i k check block status i get data if buckets i k null readers i k null else readers i k new data input stream buckets i k get input stream if idx k packet indexes idx i k if idx k throw new illegal argument exception must have at least k packets k k idx idx if logminor for int i 0 i packet indexes length i logger minor this i packet indexes i if number to decode 0 do the striped decode for int offset 0 offset block length offset stripe size read the data in first for int i 0 i k i int x packet indexes i readers x read fully real buffer i stripe size stripe size do the decode not shuffled int disposable indexes new int packet indexes length system arraycopy packet indexes 0 disposable indexes 0 packet indexes length fec decode packets disposable indexes packets now contains an array of decoded blocks in order write the data out for int i 0 i k i if writers i null writers i write real buffer i stripe size stripe size finally for int i 0 i k i closer close writers i for int i 0 i n i closer close readers i set new buckets only after have a successful decode note that the last data bucket will be overwritten padded for int i 0 i data block status length i bucket data buckets i if data size block length throw new illegal state exception block i data data block status i length data size whereas block length block length data block status i set data data realdecode splitfileblock datablockstatus splitfileblock checkblockstatus blocklength bucketfactory ioexception shouldlog datablockstatus checkblockstatus blocklength datablockstatus checkblockstatus illegalargumentexception datablockstatus illegalargumentexception datainputstream datainputstream outputstream outputstream numbertodecode realbuffer stripe_size packetindexes packetindexes packetindexes realbuffer stripe_size stripe_size numbertodecode numbertodecode needdecode datablockstatus datablockstatus getdata needdecode needdecode datablockstatus datablockstatus getdata makebucket blocklength getoutputstream numbertodecode blocklength datablockstatus illegalargumentexception datablockstatus datablockstatus blocklength datainputstream getinputstream packetindexes checkblockstatus checkblockstatus getdata datainputstream getinputstream packetindexes illegalargumentexception packetindexes packetindexes numbertodecode blocklength stripe_size packetindexes readfully realbuffer stripe_size stripe_size disposableindexes packetindexes packetindexes disposableindexes packetindexes disposableindexes realbuffer stripe_size stripe_size datablockstatus blocklength illegalstateexception datablockstatus blocklength blocklength datablockstatus setdata do the actual encode protected void real encode bucket data block status bucket check block status int block length bucket factory bf throws io exception loadfec logminor logger should log logger minor this runtime get runtime gc runtime get runtime run finalization runtime get runtime gc runtime get runtime run finalization long mem used at start runtime get runtime total memory runtime get runtime free memory if logminor logger minor this memory in use at start mem used at start max runtime get runtime max memory logger minor this doing encode data block status length data blocks check block status length check blocks block length block length with this if data block status length check block status length n data block status length k throw new illegal argument exception data blocks data block status length check blocks check block status length n n k k buffer data packets new buffer k buffer check packets new buffer n k bucket buckets new bucket n data input stream readers new data input stream k output stream writers new output stream n k try int to encode new int n k int number to encode 0 can be less than n k byte real buffer new byte n stripe size for int i 0 i k i data packets i new buffer real buffer i stripe size stripe size for int i 0 i n k i check packets i new buffer real buffer i k stripe size stripe size for int i 0 i data block status length i buckets i data block status i if buckets i null throw new null pointer exception data bucket i is null long sz buckets i size if sz block length throw new illegal argument exception all buckets must be the full size caller must pad the last one if needed readers i new data input stream buckets i get input stream int created 0 for int i 0 i check block status length i buckets i k check block status i if buckets i k null buckets i k bf make bucket block length writers i buckets i k get output stream to encode number to encode i k created else writers i null if logminor logger minor this created created check buckets runtime get runtime gc runtime get runtime run finalization runtime get runtime gc runtime get runtime run finalization long mem used before encodes runtime get runtime total memory runtime get runtime free memory if logminor logger minor this memory in use before encodes mem used before encodes if number to encode 0 do the striped encode for int offset 0 offset block length offset stripe size long mem used before read runtime get runtime total memory runtime get runtime free memory if logminor logger minor this memory in use before read mem used before read read the data in first for int i 0 i k i readers i read fully real buffer i stripe size stripe size do the encode not shuffled long start time system current time millis runtime get runtime gc runtime get runtime run finalization runtime get runtime gc runtime get runtime run finalization long mem used before stripe runtime get runtime total memory runtime get runtime free memory if logminor logger minor this memory in use before stripe mem used before stripe fec encode data packets check packets to encode runtime get runtime gc runtime get runtime run finalization runtime get runtime gc runtime get runtime run finalization long mem used after stripe runtime get runtime total memory runtime get runtime free memory if logminor logger minor this memory in use after stripe mem used after stripe long end time system current time millis if logminor logger minor this stripe encode took end time start time ms for k k n n stripe size stripe size packets now contains an array of decoded blocks in order write the data out for int i k i n i if writers i k null writers i k write real buffer i stripe size stripe size finally for int i 0 i k i closer close readers i for int i 0 i n k i closer close writers i set new buckets only after have a successful decode for int i 0 i check block status length i bucket data buckets i k if data null throw new null pointer exception check block status i data realencode datablockstatus checkblockstatus blocklength bucketfactory ioexception shouldlog getruntime getruntime runfinalization getruntime getruntime runfinalization memusedatstart getruntime totalmemory getruntime freememory memusedatstart getruntime maxmemory datablockstatus checkblockstatus blocklength datablockstatus checkblockstatus datablockstatus illegalargumentexception datablockstatus checkblockstatus datapackets checkpackets datainputstream datainputstream outputstream outputstream toencode numbertoencode realbuffer stripe_size datapackets realbuffer stripe_size stripe_size checkpackets realbuffer stripe_size stripe_size datablockstatus datablockstatus nullpointerexception blocklength illegalargumentexception datainputstream getinputstream checkblockstatus checkblockstatus makebucket blocklength getoutputstream toencode numbertoencode getruntime getruntime runfinalization getruntime getruntime runfinalization memusedbeforeencodes getruntime totalmemory getruntime freememory memusedbeforeencodes numbertoencode blocklength stripe_size memusedbeforeread getruntime totalmemory getruntime freememory memusedbeforeread readfully realbuffer stripe_size stripe_size starttime currenttimemillis getruntime getruntime runfinalization getruntime getruntime runfinalization memusedbeforestripe getruntime totalmemory getruntime freememory memusedbeforestripe datapackets checkpackets toencode getruntime getruntime runfinalization getruntime getruntime runfinalization memusedafterstripe getruntime totalmemory getruntime freememory memusedafterstripe endtime currenttimemillis endtime starttime stripesize stripe_size realbuffer stripe_size stripe_size checkblockstatus nullpointerexception checkblockstatus the method used to submit link fec job s to the pool author florent daigni egrave re lt nextgens freenetproject org gt param fec job public void add to queue fec job job fec queue queue object container container queue add to queue job this container fecjob fecjob addtoqueue fecjob fecqueue objectcontainer addtoqueue public void object can deactivate object container container logger minor this deactivating this new exception debug objectcandeactivate objectcontainer public abstract short get algorithm getalgorithm public class browser test toadlet extends toadlet browser test toadlet high level simple client client node client core c super client this core c browsertesttoadlet browsertesttoadlet highlevelsimpleclient nodeclientcore override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception yes we need that in order to test the browser number of connections per server if request is parameter set wontload return else if request is parameter set mime test this writehtml reply ctx 200 ok img warning mime return html node page node ctx get page maker get page node freenet browser testing tool ctx html node content node ctx get page maker get content node page node if ctx is allowed full access content node add child core alerts create summary test mime inline html node mime autodetect box content node add child ctx get page maker get infobox infobox warning mime inline html node mime autodetect content ctx get page maker get content node mime autodetect box mime autodetect content add child img new string src alt new string data image gif base64 img warning mime your browser is probably safe mime autodetect content add child img new string src alt new string mime test your browser is probably safe test whether we can have more than 10 simultaneous connections to fproxy html node max connections per server box content node add child ctx get page maker get infobox infobox warning number of connections html node max connections per server content ctx get page maker get content node max connections per server box max connections per server content add child if you do not see a green picture below your browser is probably missconfigured ensure it allows more than 10 connections per server for int i 0 i 10 i max connections per server content add child img src wontload max connections per server content add child img new string src alt new string static themes clean success gif fail test whether js is available should do the test with pictures instead html node js test box content node add child ctx get page maker get infobox infobox warning javascript html node js test content ctx get page maker get content node js test box html node js test js test content add child div js test add child img new string id src alt new string jstest static themes clean success gif fail js test add child script type text javascript add child document get element by id jstest src static themes clean warning gif this writehtml reply ctx 200 ok page node generate handleget httprequest toadletcontext toadletcontextclosedexception ioexception isparameterset isparameterset mimetest writehtmlreply imgwarningmime htmlnode pagenode getpagemaker getpagenode htmlnode contentnode getpagemaker getcontentnode pagenode isallowedfullaccess contentnode addchild createsummary htmlnode mimeautodetectbox contentnode addchild getpagemaker getinfobox htmlnode mimeautodetectcontent getpagemaker getcontentnode mimeautodetectbox mimeautodetectcontent addchild imgwarningmime mimeautodetectcontent addchild mimetest htmlnode maxconnectionsperserverbox contentnode addchild getpagemaker getinfobox htmlnode maxconnectionsperservercontent getpagemaker getcontentnode maxconnectionsperserverbox maxconnectionsperservercontent addchild maxconnectionsperservercontent addchild maxconnectionsperservercontent addchild htmlnode jstestbox contentnode addchild getpagemaker getinfobox htmlnode jstestcontent getpagemaker getcontentnode jstestbox htmlnode jstest jstestcontent addchild jstest addchild jstest addchild addchild getelementbyid writehtmlreply pagenode override public string supported methods return get supportedmethods construct a twirl filter with no distortion public twirl filter set edge action clamp twirlfilter twirlfilter setedgeaction set the angle of twirl in radians 0 means no distortion param angle the angle of twirl this is the angle by which pixels at the nearest edge of the image will move see get angle public void set angle float angle this angle angle getangle setangle get the angle of twist return the angle in radians see set angle public float get angle return angle setangle getangle set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius override public buffered image filter buffered image src buffered image dst icentrex src get width centrex icentrey src get height centrey if radius 0 radius math min icentrex icentrey radius2 radius radius return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight override protected void transform inverse int x int y float out float dx x icentrex float dy y icentrey float distance dx dx dy dy if distance radius2 out 0 x out 1 y else distance float math sqrt distance float a float math atan2 dy dx angle radius distance radius out 0 icentrex distance float math cos a out 1 icentrey distance float math sin a transforminverse override public string to string return distort twirl tostring private static final long serial versionuid 648427977601494972l public subscriber list serialversionuid subscriberlist public subscriber get subscriber int n object obj null try obj get n catch exception e return subscriber obj getsubscriber private float upper threshold public erode alpha filter this 3 0 75f 0 upperthreshold erodealphafilter public erode alpha filter float radius float threshold float softness this radius radius this threshold threshold this softness softness erodealphafilter public void set radius float radius this radius radius setradius public float get radius return radius getradius public void set threshold float threshold this threshold threshold setthreshold public float get threshold return threshold getthreshold public void set softness float softness this softness softness setsoftness public float get softness return softness getsoftness override public buffered image filter buffered image src buffered image dst dst new gaussian filter int radius filter src null lower threshold 255 threshold softness 0 5f upper threshold 255 threshold softness 0 5f return super filter dst dst bufferedimage bufferedimage bufferedimage gaussianfilter lowerthreshold upperthreshold override public int filterrgb int x int y int rgb int a rgb 24 0xff int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff if a 255 return 0xffffffff float f image math smooth step lower threshold upper threshold float a a int f 255 if a 0 a 0 else if a 255 a 255 return a 24 0xffffff imagemath smoothstep lowerthreshold upperthreshold override public string to string return alpha erode tostring private static final long serial versionuid 1 public ssk encode exception string message key encode exception e super message e serialversionuid sskencodeexception keyencodeexception async message filter callback public void on matched message m do nothing asyncmessagefiltercallback onmatched public boolean should timeout not until matched return false shouldtimeout public void on timeout do nothing ontimeout public void on disconnect peer context ctx do nothing ondisconnect peercontext public void on restarted peer context ctx do nothing onrestarted peercontext public final long delta public blocked too long exception packet tracker tracker long delta this tracker tracker this delta delta blockedtoolongexception packettracker get a list of fields which the database should create an index on public static string get indexed fields fixme figure out whether indexed fields are inherited from parent classes otherwise we would have to also list the indexed fields of wot identity here fixme figure out whether we really need lookups by insert uri if not remove the index return new string m inserturi getindexedfields wotidentity minserturi public wot own identity string myuid freeneturi my requesturi freeneturi my inserturi string my nickname super myuid my requesturi my nickname if my inserturi null throw new illegal argument exception m inserturi my inserturi wotownidentity myrequesturi myinserturi mynickname myrequesturi mynickname myinserturi illegalargumentexception minserturi myinserturi public freeneturi get inserturi return m inserturi getinserturi minserturi public synchronized void subscribe to board board board if m subscribed boards contains board assert false todo add logging check whether this should be allowed to happen return m subscribed boards add board store subscribetoboard msubscribedboards msubscribedboards public synchronized void unsubscribe from board board board m subscribed boards remove board store unsubscribefromboard msubscribedboards public synchronized iterator board subscribed boards iterator return m subscribed boards iterator subscribedboardsiterator msubscribedboards public synchronized boolean wants messages from ft identity identity return m identity manager get score this identity 0 fixme this has to be configurable wantsmessagesfrom ftidentity midentitymanager getscore public void store fixme check for duplicates if db ext is stored this db ext is active this throw new runtime exception trying to store a non active wot own identity object db store m subscribed boards db store m inserturi super store isstored isactive runtimeexception wotownidentity msubscribedboards minserturi public replication master storage impl int port string hosts int async buf size this port port this hosts hosts this async buf size async buf size replicationmasterstorageimpl asyncbufsize asyncbufsize asyncbufsize public void open i file file int page pool size super open async buf size 0 replication master file new async replication master file this file async buf size new replication master file this file page pool size ifile pagepoolsize asyncbufsize replicationmasterfile asyncreplicationmasterfile asyncbufsize replicationmasterfile pagepoolsize public int get number of available hosts return replication master file pool file get number of available hosts getnumberofavailablehosts replicationmasterfile getnumberofavailablehosts public fcp client string name2 fcp connection handler handler boolean is global queue request completion callback cb short persistence type fcp persistent root root object container container this name name2 if name null throw new null pointer exception this current connection handler final boolean forever persistence type client request persist forever running persistent requests new array list client request completed unacked requests new array list client request client requests by identifier new hash map string client request this is global queue is global queue this persistence type persistence type assert persistence type client request persist forever persistence type client request persist reboot watch global verbosity mask integer max value low level client new request client public boolean persistent return forever public void remove from object container container if forever container delete this else throw new unsupported operation exception completion callback cb if persistence type client request persist forever assert root null this root root else this root null fcpclient fcpconnectionhandler isglobalqueue requestcompletioncallback persistencetype fcppersistentroot objectcontainer nullpointerexception currentconnection persistencetype clientrequest persist_forever runningpersistentrequests arraylist clientrequest completedunackedrequests arraylist clientrequest clientrequestsbyidentifier hashmap clientrequest isglobalqueue isglobalqueue persistencetype persistencetype persistencetype clientrequest persist_forever persistencetype clientrequest persist_reboot watchglobalverbositymask max_value lowlevelclient requestclient removefrom objectcontainer unsupportedoperationexception completioncallback persistencetype clientrequest persist_forever final short persistence type public synchronized fcp connection handler get connection return current connection persistencetype fcpconnectionhandler getconnection currentconnection public synchronized void set connection fcp connection handler handler this current connection handler setconnection fcpconnectionhandler currentconnection public synchronized void on lost connection fcp connection handler handler handler freedda jobs if current connection handler current connection null onlostconnection fcpconnectionhandler freeddajobs currentconnection currentconnection called when a client request has finished but is persistent it has not been acked yet so it should be moved to the unacked completed requests set public void finished client request client request get object container container if logger should log logger minor this logger minor this finished client request new exception debug assert persistence type client request persist forever container null assert get persistence type persistence type if container null container activate running persistent requests 2 container activate completed unacked requests 2 synchronized this if running persistent requests remove get completed unacked requests add get if container null container store get http tracker db4o com browse cor 1436 if we don t specify depth we end up updating everything resulting in bad things especially on client put dir manifest elements container ext store running persistent requests 2 container ext store completed unacked requests 2 finishedclientrequest clientrequest objectcontainer shouldlog persistencetype clientrequest persist_forever persistencetype persistencetype runningpersistentrequests completedunackedrequests runningpersistentrequests completedunackedrequests clientputdir manifestelements runningpersistentrequests completedunackedrequests queue any and all pending messages from already completed unacknowledged persistent requests to be immediately sent this happens automatically on startup and hopefully will encourage clients to acknowledge persistent requests public void queue pending messages on connection restart fcp connection output handler output handler object container container assert persistence type client request persist forever container null object reqs if container null container activate completed unacked requests 2 synchronized this reqs completed unacked requests to array for int i 0 i reqs length i client request req client request reqs i if persistence type client request persist forever container activate req 1 client request reqs i send pending messages output handler true false false container queuependingmessagesonconnectionrestart fcpconnectionoutputhandler outputhandler objectcontainer persistencetype clientrequest persist_forever completedunackedrequests completedunackedrequests toarray clientrequest clientrequest persistencetype clientrequest persist_forever clientrequest sendpendingmessages outputhandler queue any and all pending messages from running requests happens on demand public void queue pending messages from running requests fcp connection output handler output handler object container container assert persistence type client request persist forever container null object reqs if container null container activate running persistent requests 2 synchronized this reqs running persistent requests to array for int i 0 i reqs length i client request req client request reqs i if persistence type client request persist forever container activate req 1 req send pending messages output handler true false false container queuependingmessagesfromrunningrequests fcpconnectionoutputhandler outputhandler objectcontainer persistencetype clientrequest persist_forever runningpersistentrequests runningpersistentrequests toarray clientrequest clientrequest persistencetype clientrequest persist_forever sendpendingmessages outputhandler public void register client request cg boolean start later object container container throws identifier collision exception assert cg persistence type persistence type assert persistence type client request persist forever container null if logger should log logger minor this logger minor this registering cg get identifier start later to start later if container null container activate completed unacked requests 2 container activate running persistent requests 2 container activate client requests by identifier 2 synchronized this string ident cg get identifier client request old client requests by identifier get ident if old null old cg throw new identifier collision exception if cg has finished completed unacked requests add cg if container null container store cg container store completed unacked requests else running persistent requests add cg if container null cg store to container container ext store running persistent requests 2 client requests by identifier put ident cg if container null container ext store client requests by identifier 2 clientrequest startlater objectcontainer identifiercollisionexception persistencetype persistencetype persistencetype clientrequest persist_forever shouldlog getidentifier startlater completedunackedrequests runningpersistentrequests clientrequestsbyidentifier getidentifier clientrequest clientrequestsbyidentifier identifiercollisionexception hasfinished completedunackedrequests completedunackedrequests runningpersistentrequests storeto runningpersistentrequests clientrequestsbyidentifier clientrequestsbyidentifier public boolean remove by identifier string identifier boolean kill fcp server server object container container client context context assert persistence type client request persist forever container null client request req boolean logminor logger should log logger minor this if logminor logger minor this remove by identifier identifier kill if container null container activate completed unacked requests 2 container activate running persistent requests 2 container activate client requests by identifier 2 synchronized this req client requests by identifier get identifier if container null req null container activate req 1 boolean removed from running false if req null for client request r completed unacked requests container activate r 1 if r get identifier equals identifier req r completed unacked requests remove r logger error this found completed unacked request r for identifier r get identifier but not in client requests by identifier break container deactivate r 1 if req null for client request r running persistent requests container activate r 1 if r get identifier equals identifier req r running persistent requests remove r removed from running true logger error this found running request r for identifier r get identifier but not in client requests by identifier break container deactivate r 1 if req null return false else if removed from running running persistent requests remove req completed unacked requests remove req logger error this removing identifier in client requests by identifier but not in running completed maps return false client requests by identifier remove identifier if container null if removed from running container ext store running persistent requests 2 else container store completed unacked requests container ext store client requests by identifier 2 if container null container activate req 1 if kill if logminor logger minor this killing request req req cancel container context req request was removed container context if completion callback null completion callback on remove req container return true removebyidentifier fcpserver objectcontainer clientcontext persistencetype clientrequest persist_forever clientrequest shouldlog removebyidentifier completedunackedrequests runningpersistentrequests clientrequestsbyidentifier clientrequestsbyidentifier removedfromrunning clientrequest completedunackedrequests getidentifier completedunackedrequests getidentifier clientrequestsbyidentifier clientrequest runningpersistentrequests getidentifier runningpersistentrequests removedfromrunning getidentifier clientrequestsbyidentifier removedfromrunning runningpersistentrequests completedunackedrequests clientrequestsbyidentifier clientrequestsbyidentifier removedfromrunning runningpersistentrequests completedunackedrequests clientrequestsbyidentifier requestwasremoved completioncallback completioncallback onremove public boolean has persistent requests object container container assert persistence type client request persist forever container null if running persistent requests null if container ext is active this logger error this fcpclient not active throw new null pointer exception if completed unacked requests null if container ext is active this logger error this fcpclient not active throw new null pointer exception if container null container activate completed unacked requests 2 container activate running persistent requests 2 return running persistent requests is empty completed unacked requests is empty haspersistentrequests objectcontainer persistencetype clientrequest persist_forever runningpersistentrequests isactive nullpointerexception completedunackedrequests isactive nullpointerexception completedunackedrequests runningpersistentrequests runningpersistentrequests isempty completedunackedrequests isempty public void add persistent requests list client request v boolean only forever object container container assert persistence type client request persist forever container null if container null container activate completed unacked requests 2 container activate running persistent requests 2 container activate client requests by identifier 2 synchronized this iterator client request i running persistent requests iterator while i has next client request req i next if container null container activate req 1 if req is persistent forever only forever v add req if container null for client request req completed unacked requests container activate req 1 v add all completed unacked requests addpersistentrequests clientrequest onlyforever objectcontainer persistencetype clientrequest persist_forever completedunackedrequests runningpersistentrequests clientrequestsbyidentifier clientrequest runningpersistentrequests hasnext clientrequest ispersistentforever onlyforever clientrequest completedunackedrequests addall completedunackedrequests enable or disable watch the global queue param enabled whether we want watch global queue to be enabled param verbosity mask if so what verbosity mask to use to filter messages generated by the global queue public void set watch global boolean enabled int verbosity mask fcp server server object container container assert persistence type client request persist forever container null if is global queue logger error this set watch global on global queue this new exception debug return if watch global enabled server global reboot client unwatch this server global forever client unwatch this watch global false else if enabled watch global server global reboot client watch this server global forever client watch this fcp connection handler conn handler get connection if conn handler null if persistence type client request persist reboot server global reboot client queue pending messages on connection restart conn handler output handler container else server global forever client queue pending messages on connection restart conn handler output handler container watch global true otherwise the status is unchanged this watch global verbosity mask verbosity mask verbositymask setwatchglobal verbositymask fcpserver objectcontainer persistencetype clientrequest persist_forever isglobalqueue watchglobal globalrebootclient globalforeverclient watchglobal watchglobal globalrebootclient globalforeverclient fcpconnectionhandler connhandler getconnection connhandler persistencetype clientrequest persist_reboot globalrebootclient queuependingmessagesonconnectionrestart connhandler outputhandler globalforeverclient queuependingmessagesonconnectionrestart connhandler outputhandler watchglobal watchglobalverbositymask verbositymask public void queue client request message fcp message msg int verbosity level object container container queue client request message msg verbosity level false container queueclientrequestmessage fcpmessage verbositylevel objectcontainer queueclientrequestmessage verbositylevel public void queue client request message fcp message msg int verbosity level boolean use global mask object container container if use global mask verbosity level watch global verbosity mask verbosity level return fcp connection handler conn get connection if conn null conn output handler queue msg fcp client clients if is global queue synchronized clients watching lock if clients watching null clients clients watching to array new fcp client clients watching size else clients null if clients null for int i 0 i clients length i if persistence type client request persist forever container activate clients i 1 if clients i persistence type persistence type continue clients i queue client request message msg verbosity level true container if persistence type client request persist forever container deactivate clients i 1 queueclientrequestmessage fcpmessage verbositylevel useglobalmask objectcontainer useglobalmask verbositylevel watchglobalverbositymask verbositylevel fcpconnectionhandler getconnection outputhandler fcpclient isglobalqueue clientswatchinglock clientswatching clientswatching toarray fcpclient clientswatching persistencetype clientrequest persist_forever persistencetype persistencetype queueclientrequestmessage verbositylevel persistencetype clientrequest persist_forever private void unwatch fcp client client if is global queue return synchronized clients watching lock if clients watching null clients watching remove client fcpclient isglobalqueue clientswatchinglock clientswatching clientswatching private void watch fcp client client if is global queue return synchronized clients watching lock if clients watching null clients watching new linked list fcp client clients watching add client fcpclient isglobalqueue clientswatchinglock clientswatching clientswatching linkedlist fcpclient clientswatching public synchronized client request get request string identifier object container container assert persistence type client request persist forever container null if container null container activate client requests by identifier 2 client request req client requests by identifier get identifier if persistence type client request persist forever container activate req 1 return req clientrequest getrequest objectcontainer persistencetype clientrequest persist_forever clientrequestsbyidentifier clientrequest clientrequestsbyidentifier persistencetype clientrequest persist_forever override public string to string return super to string name tostring tostring callback called when a request succeeds public void notify success client request req object container container assert req persistence type persistence type if completion callback null completion callback notify success req container notifysuccess clientrequest objectcontainer persistencetype persistencetype completioncallback completioncallback notifysuccess callback called when a request fails param get public void notify failure client request req object container container assert req persistence type persistence type if completion callback null completion callback notify failure req container notifyfailure clientrequest objectcontainer persistencetype persistencetype completioncallback completioncallback notifyfailure public synchronized request completion callback set request completion callback request completion callback cb request completion callback old completion callback completion callback cb return old requestcompletioncallback setrequestcompletioncallback requestcompletioncallback requestcompletioncallback completioncallback completioncallback public void remove from database object container container container activate running persistent requests 2 container delete running persistent requests container activate completed unacked requests 2 container delete completed unacked requests container activate client requests by identifier 2 container delete client requests by identifier container activate low level client 2 low level client remove from container container delete this container delete clients watching lock removefromdatabase objectcontainer runningpersistentrequests runningpersistentrequests completedunackedrequests completedunackedrequests clientrequestsbyidentifier clientrequestsbyidentifier lowlevelclient lowlevelclient removefrom clientswatchinglock public void remove all object container container client context context hash set client request to kill new hash set client request if container null container activate completed unacked requests 2 container activate running persistent requests 2 container activate client requests by identifier 2 synchronized this iterator client request i running persistent requests iterator while i has next client request req i next to kill add req running persistent requests clear for client request req completed unacked requests if persistence type client request persist forever container activate req 1 to kill add req completed unacked requests clear for client request req client requests by identifier values if persistence type client request persist forever container activate req 1 to kill add req client requests by identifier clear if persistence type client request persist forever container ext store client requests by identifier 2 removeall objectcontainer clientcontext hashset clientrequest tokill hashset clientrequest completedunackedrequests runningpersistentrequests clientrequestsbyidentifier clientrequest runningpersistentrequests hasnext clientrequest tokill runningpersistentrequests clientrequest completedunackedrequests persistencetype clientrequest persist_forever tokill completedunackedrequests clientrequest clientrequestsbyidentifier persistencetype clientrequest persist_forever tokill clientrequestsbyidentifier persistencetype clientrequest persist_forever clientrequestsbyidentifier public client get get completed request freeneturi key object container container fixme speed this up with another hashmap or something fixme keep a transient hashmap in ram use it for fproxy fixme consider supporting inserts too if container null container activate completed unacked requests 2 for int i 0 i completed unacked requests size i client request req completed unacked requests get i if req instanceof client get continue client get getter client get req if persistence type client request persist forever container activate getter 1 if getter geturi container equals key return getter else if persistence type client request persist forever container deactivate getter 1 return null clientget getcompletedrequest objectcontainer completedunackedrequests completedunackedrequests clientrequest completedunackedrequests clientget clientget clientget persistencetype clientrequest persist_forever persistencetype clientrequest persist_forever public void init object container container container activate running persistent requests 2 container activate completed unacked requests 2 container activate client requests by identifier 2 container activate low level client 2 objectcontainer runningpersistentrequests completedunackedrequests clientrequestsbyidentifier lowlevelclient public boolean object can new object container container if persistence type client request persist forever logger error this not storing non persistent request in database new exception error return false return true objectcannew objectcontainer persistencetype clientrequest persist_forever public final class log in page extends web page impl public log in page web interface my web interface ft own identity viewer http request request super my web interface viewer request todo auto generated constructor stub loginpage webpageimpl loginpage webinterface mywebinterface ftownidentity httprequest mywebinterface public void make make welcome box if m freetalk get identity manager own identity iterator has next make login box make create identity box else new create identity wizard m web interface m request add to page m content node makewelcomebox mfreetalk getidentitymanager ownidentityiterator hasnext makeloginbox makecreateidentitybox createidentitywizard mwebinterface mrequest addtopage mcontentnode private final void make welcome box todo make double sure that the following text is short and yet makes very clear what freetalk is about it will be the first text which people read when they access freetalk from f proxy html node welcome box add content box welcome to freetalk welcome box add child p freetalk is a pseudo anonymous messaging system based on freenet it is very similar to internet forums and newsgroups pseudo anonymous means that you post your messages using an identity which is uniquely identitfied by it s freetalk address which consists of a nickname and an unique cryptography key html node p welcome box add child p because you can keep the private part of the cryptography key secret only you can post under your freetalk address which means that everyone knows that all messages from a given identity probably come from the same author therefore you are p add child b pseudo p add child anonymous welcome box add child p but due to the nature of freenet nobody will know who is inserting the messages of your identity which means that you as a real person are still an add child b anonymous author makewelcomebox fproxy htmlnode welcomebox addcontentbox welcomebox addchild htmlnode welcomebox addchild addchild addchild welcomebox addchild addchild private final void make login box html node login box add content box log in iterator ft own identity iter m freetalk get identity manager own identity iterator if iter has next login box add child p sorry freetalk has not yet downloaded your own identities from the wot plugin please wait 1 2 minutes html node p login box add child p if you have not created an own identity yet please go to the p add child a href plugins plugins wot wot wot web interface p add child and create an own identity there do not forget to introduce it to others by solving introduction puzzles return html node select form add form child login box self uri log in log in html node select box select form add child select name own identityid while iter has next ft own identity own identity iter next select box add child option value own identity getuid own identity get freetalk address select form add child input new string type name value new string submit submit log in makeloginbox htmlnode loginbox addcontentbox ftownidentity mfreetalk getidentitymanager ownidentityiterator hasnext loginbox addchild htmlnode loginbox addchild addchild addchild htmlnode selectform addformchild loginbox self_uri login login htmlnode selectbox selectform addchild ownidentityid hasnext ftownidentity ownidentity selectbox addchild ownidentity ownidentity getfreetalkaddress selectform addchild private void make create identity box html node create identity box add content box create an own identity create identity box add child a href self uri create identity you can create another own identity here makecreateidentitybox htmlnode createidentitybox addcontentbox createidentitybox addchild self_uri createidentity get port number from a config create socket and packet mangler throws node init exception public node crypto final node node final boolean is opennet node crypto config config long startup time boolean enablear ks throws node init exception this node node this config config random node random this is opennet is opennet logminor logger should log logger minor this config starting this try int port config get port freenet inet address bindto config get bind to udp socket handler u null if port 65535 throw new node init exception node init exception exit impossible usm port impossible port number port else if port 1 pick a random port for int i 0 i 200000 i int port no 1024 random next int 65535 1024 try u new udp socket handler port no bindto get address node startup time get title port no node collector port u get port number break catch exception e logger normal this could not use port bindto port no e e system err println could not use port bindto port no e e print stack trace continue if u null throw new node init exception node init exception exit no available udp ports could not find an available udp port number for fnp none specified else try u new udp socket handler port bindto get address node startup time get title port node collector catch exception e logger error this caught e e system err println e e print stack trace throw new node init exception node init exception exit impossible usm port could not bind to port port node already running socket u logger normal this fnp port created on bindto port system out println fnp port created on bindto port port number port config set port port socket set drop probability config get drop probability socket set low level filter packet mangler new fnp packet mangler node this socket detector new nodeip port detector node node ip detector this enablear ks anon setup cipher new rijndael 256 256 catch node init exception e config stopping this throw e catch runtime exception e config stopping this throw e catch error e config stopping this throw e catch unsupported cipher exception e config stopping this throw new error e finally config maybe started this nodeinitexception nodecrypto isopennet nodecryptoconfig startuptime enablearks nodeinitexception isopennet isopennet shouldlog getport freenetinetaddress getbindto udpsockethandler nodeinitexception nodeinitexception exit_impossible_usm_port portno nextint udpsockethandler portno getaddress startuptime gettitle portno getportnumber portno portno printstacktrace nodeinitexception nodeinitexception exit_no_available_udp_ports udpsockethandler getaddress startuptime gettitle printstacktrace nodeinitexception nodeinitexception exit_impossible_usm_port portnumber setport setdropprobability getdropprobability setlowlevelfilter packetmangler fnppacketmangler nodeipportdetector ipdetector enablearks anonsetupcipher nodeinitexception runtimeexception unsupportedcipherexception maybestarted private string get title int port fixme l10n return udp is opennet opennet darknet port port gettitle isopennet read the cryptographic keys etc from a simple field set param fs throws io exception public void read crypto simple field set fs throws io exception string identity fs get identity if identity null throw new io exception try my identity base64 decode identity catch illegal base64 exception e2 throw new io exception identity hash sha256 digest my identity anon setup cipher initialize identity hash identity hash hash sha256 digest identity hash try crypto group dsa group create fs subset dsa group priv key dsa private key create fs subset dsa priv key crypto group pub key dsa public key create fs subset dsa pub key crypto group catch illegal base64 exception e logger error this caught e e throw new io exception e to string catch fs parse exception e logger error this caught e e throw new io exception e to string insertable clientssk ark null ark string s fs get ark number string privark fs get ark privuri try if privark null freeneturi uri new freeneturi privark ark insertable clientssk create uri if s null ark null myark number 0 else try myark number long parse long s catch number format exception e myark number 0 ark null catch malformedurl exception e logger minor this caught e e ark null if ark null ark insertable clientssk create random random ark myark number 0 myark ark string cn fs get client nonce if cn null try client nonce base64 decode cn catch illegal base64 exception e throw new io exception invalid client nonce field e else client nonce new byte 32 node random next bytes client nonce simplefieldset ioexception readcrypto simplefieldset ioexception ioexception myidentity illegalbase64exception ioexception identityhash myidentity anonsetupcipher identityhash identityhashhash identityhash cryptogroup dsagroup dsagroup privkey dsaprivatekey dsaprivkey cryptogroup pubkey dsapublickey dsapubkey cryptogroup illegalbase64exception ioexception tostring fsparseexception ioexception tostring insertableclientssk insertableclientssk myarknumber myarknumber parselong numberformatexception myarknumber malformedurlexception insertableclientssk createrandom myarknumber clientnonce clientnonce illegalbase64exception ioexception clientnonce clientnonce nextbytes clientnonce create the cryptographic keys etc from scratch public void init crypto my identity new byte 32 random next bytes my identity message digest md sha256 get message digest identity hash md digest my identity identity hash hash md digest identity hash crypto group global ds agroup biga priv key new dsa private key crypto group random pub key new dsa public key crypto group priv key myark insertable clientssk create random random ark myark number 0 sha256 return message digest md anon setup cipher initialize identity hash client nonce new byte 32 node random next bytes client nonce initcrypto myidentity nextbytes myidentity messagedigest getmessagedigest identityhash myidentity identityhashhash identityhash cryptogroup dsagroupbiga privkey dsaprivatekey cryptogroup pubkey dsapublickey cryptogroup privkey insertableclientssk createrandom myarknumber returnmessagedigest anonsetupcipher identityhash clientnonce nextbytes clientnonce public void start packet mangler start socket start packetmangler public simple field set export private field set simple field set fs export public field set false false false add private fields fs return fs simplefieldset exportprivatefieldset simplefieldset exportpublicfieldset addprivatefields export my node reference so that another node can connect to me public version includes everything apart from private keys see export public field set boolean for setup public simple field set export public field set return export public field set false false false exportpublicfieldset forsetup simplefieldset exportpublicfieldset exportpublicfieldset export my reference so that another node can connect to me param for setup if true strip out everything that isn t needed for the references exchanged immediately after connection setup i e strip out everything that is invariant or that can safely be exchanged later param for anon initiator if true we are adding a node from an anonymous initiator noderef exchange minimal noderef which we can construct a peer node from short lived so no ark etc already signed so dump the signature simple field set export public field set boolean for setup boolean for anon initiator boolean forark simple field set fs export public crypto field set for setup forark for anon initiator if for anon initiator for setup ip addresses peer ips detector detect primary peers if ips null for int i 0 i ips length i fs put append physical udp ips i to string keep important that node know all our i ps don t include i ps for anonymous initiator negotiation types fs put single version version get version string keep vital that peer know our version for example some types may be sent in different formats to different node versions e g peer if for anon initiator fs put single last good version version get last good version string also vital if node testnet enabled fs put testnet true fs put testnet port node testnet handler get port useful saves a lot of complexity if is opennet for setup forark fs put single my name node get my name if for anon initiator anonymous initiator setup type specifies whether the node is opennet or not fs put opennet is opennet synchronized reference sync if my reference signature null my signed reference null my signed reference equals fs to ordered string my signed reference fs to ordered string try my reference signature sign ref my signed reference catch node init exception e node exit e exit code fs put single sig my reference signature to long string if logminor logger minor this my reference fs to ordered string return fs forsetup foranoninitiator peernode simplefieldset exportpublicfieldset forsetup foranoninitiator simplefieldset exportpubliccryptofieldset forsetup foranoninitiator foranoninitiator forsetup detectprimarypeers putappend tostring ips ips putsingle getversionstring foranoninitiator putsingle lastgoodversion getlastgoodversionstring testnetenabled testnetport testnethandler getport isopennet forsetup putsingle myname getmyname foranoninitiator isopennet referencesync myreferencesignature mysignedreference mysignedreference toorderedstring mysignedreference toorderedstring myreferencesignature signref mysignedreference nodeinitexception exitcode putsingle myreferencesignature tolongstring toorderedstring simple field set export public crypto field set boolean for setup boolean for anon initiator simple field set fs new simple field set true int neg types packet mangler supported neg types if for setup for anon initiator can t change on setup anonymous initiator doesn t need identity as we don t use it fs put single identity base64 encode my identity if for setup these are invariant they cannot change on connection setup they can safely be excluded fs put dsa group crypto group as field set fs put dsa pub key pub key as field set if for anon initiator short lived connections don t need ark and don t need neg types either fs put auth neg types neg types if for setup fs put ark number myark number can be changed on setup fs put single ark puburi myark geturi to string false false can be changed on setup return fs simplefieldset exportpubliccryptofieldset forsetup foranoninitiator simplefieldset simplefieldset negtypes packetmangler supportednegtypes forsetup foranoninitiator putsingle myidentity forsetup dsagroup cryptogroup asfieldset dsapubkey pubkey asfieldset foranoninitiator negtypes negtypes negtypes forsetup myarknumber putsingle tostring dsa signature sign ref string my signed reference throws node init exception if logminor logger minor this signing reference n my signed reference try byte ref my signed reference get bytes utf 8 big integer m new big integer 1 sha256 digest ref if logminor logger minor this m m to string 16 dsa signature signature dsa sign crypto group priv key m random if logminor dsa verify pub key signature m false throw new node init exception node init exception exit exception to debug my signed reference return signature catch unsupported encoding exception e duh logger error this error while signing the node identity e e system err println error while signing the node identity e e print stack trace throw new node init exception node init exception exit crappy jvm impossible jvm doesn t support utf 8 dsasignature signref mysignedreference nodeinitexception mysignedreference mysignedreference getbytes biginteger biginteger tostring dsasignature _signature cryptogroup privkey pubkey _signature nodeinitexception nodeinitexception exit_exception_to_debug mysignedreference _signature unsupportedencodingexception printstacktrace nodeinitexception nodeinitexception exit_crappy_jvm private byte my compressed ref boolean setup boolean heavy setup boolean forark simple field set fs export public field set setup heavy setup forark boolean should strip group heavy setup global ds agroup biga equals crypto group if should strip group fs remove subset dsa group byte array output stream baos new byte array output stream deflater output stream gis gis new deflater output stream baos try fs write to gis catch io exception e logger error this ioe e get message e finally closer close gis closer close baos byte buf baos to byte array if buf length 4096 throw new illegal state exception we are attempting to send a buf length bytes big reference byte obuf new byte buf length 1 should strip group 1 0 int offset 0 if should strip group obuf offset 0x3 compressed noderef group int dsa group index global group index big a if logminor logger minor this we are stripping the group from the reference as it s a known group group index dsa group index obuf offset byte dsa group index 0xff else obuf offset 0x01 compressed noderef system arraycopy buf 0 obuf offset buf length if logminor logger minor this my compressed ref setup heavy setup returning obuf length bytes return obuf mycompressedref heavysetup simplefieldset exportpublicfieldset heavysetup shouldstripgroup heavysetup dsagroupbiga cryptogroup shouldstripgroup removesubset dsagroup bytearrayoutputstream bytearrayoutputstream deflateroutputstream deflateroutputstream writeto ioexception getmessage tobytearray illegalstateexception shouldstripgroup shouldstripgroup dsagroupindex group_index_big_a groupindex dsagroupindex dsagroupindex mycompressedref heavysetup the part of our node reference which is exchanged in the connection setup compressed see export setup field set public byte my compressed setup ref return my compressed ref true false false exportsetupfieldset mycompressedsetupref mycompressedref the part of our node reference which is exchanged in the connection setup if we don t already have the node compressed see export setup field set public byte my compressed heavy setup ref return my compressed ref false true false exportsetupfieldset mycompressedheavysetupref mycompressedref our full node reference compressed see export setup field set public byte my compressed full ref return my compressed ref false false false exportsetupfieldset mycompressedfullref mycompressedref void add private fields simple field set fs fs put dsa priv key priv key as field set fs put single ark privuri myark get inserturi to string false false fixme remove the conditional after we ve removed it from export public we must save the location if fs get location null fs put location node lm get location fs put single client nonce base64 encode client nonce addprivatefields simplefieldset dsaprivkey privkey asfieldset putsingle getinserturi tostring exportpublic getlocation putsingle clientnonce clientnonce public int get identity hash return fields hash code identity hash getidentityhash hashcode identityhash sign a hash dsa signature sign byte hash return dsa sign crypto group priv key new native big integer 1 hash random dsasignature cryptogroup privkey nativebiginteger public void on set drop probability int val synchronized this if socket null return socket set drop probability val onsetdropprobability setdropprobability public void stop config stopping this socket close public peer node get peer nodes if node peers null return null if is opennet return node peers get opennet peers else return node peers get darknet peers peernode getpeernodes isopennet getopennetpeers getdarknetpeers public boolean allow connection peer node pn freenet inet address addr if config one connection per address disallow multiple connections to the same address if node peers any connected peer has address addr pn detector includes addr logger normal this not sending handshake packets to addr for pn same ip address as another node return false return true allowconnection peernode freenetinetaddress oneconnectionperaddress anyconnectedpeerhasaddress dsa group get crypto group return crypto group dsagroup getcryptogroup cryptogroup get the cipher for connection attempts for e g seednode connections from nodes we don t know public block cipher get anon setup cipher return anon setup cipher blockcipher getanonsetupcipher anonsetupcipher public peer node get anon setup peer nodes array list peer node v new array list peer node peer node peers node peers my peers for int i 0 i peers length i peer node pn peers i if pn handshake unknown initiator pn get outgoing mangler packet mangler v add pn return v to array new peer node v size peernode getanonsetuppeernodes arraylist peernode arraylist peernode peernode mypeers peernode handshakeunknowninitiator getoutgoingmangler packetmangler toarray peernode void set port forwarding broken this socket get address tracker set broken setportforwardingbroken getaddresstracker setbroken get my identity param unknown initiator unknown initiator connections use the hash of the pubkey as the identity to save space in packets 3 and 4 public byte get identity boolean unknown initiator if unknown initiator return this pub key as bytes hash else return my identity unknowninitiator getidentity unknowninitiator unknowninitiator pubkey asbyteshash myidentity public boolean definitely port forwarded return socket get detected connectivity status address tracker definitely port forwarded definitelyportforwarded getdetectedconnectivitystatus addresstracker definitely_port_forwarded public int get detected connectivity status return socket get detected connectivity status getdetectedconnectivitystatus getdetectedconnectivitystatus public freenet inet address get bind to return config get bind to freenetinetaddress getbindto getbindto public long get node handle object container setup container ignore warnings this is db4o magic object set handle port tuple result setup container query new predicate handle port tuple override public boolean match handle port tuple tuple return tuple port number port number long handle if result has next handle result next handle system err println retrieved database handle for node on port port number handle return handle else while true handle random next long handle port tuple tuple new handle port tuple tuple handle handle double check with qbe just in case the rng is broken similar things have happened before object set os setup container get tuple if os has next system err println generating database handle for node already taken handle continue tuple port number port number setup container store tuple setup container commit if logger should log logger minor this logger minor this committed system err println generated and stored database handle for node on port port number handle return handle getnodehandle objectcontainer setupcontainer objectset handleporttuple setupcontainer handleporttuple handleporttuple portnumber portnumber hasnext portnumber nextlong handleporttuple handleporttuple objectset setupcontainer hasnext portnumber portnumber setupcontainer setupcontainer shouldlog portnumber ignore warnings this is db4o magic object set handle port tuple result setup container query new predicate handle port tuple override public boolean match handle port tuple tuple return tuple port number port number objectset handleporttuple setupcontainer handleporttuple handleporttuple portnumber portnumber public int filterrgb int x int y int rgb1 int rgb2 int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff int r pixel utils clamp r1 r2 int g pixel utils clamp r1 r2 int b pixel utils clamp r1 r2 return a1 24 r 16 g 8 b pixelutils pixelutils pixelutils public image producer filter image image1 image image2 int x int y int w int h int pixels1 new int w h int pixels2 new int w h int pixels3 new int w h pixel grabber pg1 new pixel grabber image1 x y w h pixels1 0 w pixel grabber pg2 new pixel grabber image2 x y w h pixels2 0 w try pg1 grab pixels pg2 grab pixels catch interrupted exception e system err println interrupted waiting for pixels return null if pg1 status image observer abort 0 system err println image fetch aborted or errored return null if pg2 status image observer abort 0 system err println image fetch aborted or errored return null for int j 0 j h j for int i 0 i w i int k j w i pixels3 k filterrgb x i y j pixels1 k pixels2 k return new memory image source w h pixels3 0 w imageproducer pixelgrabber pixelgrabber pixelgrabber pixelgrabber grabpixels grabpixels interruptedexception imageobserver imageobserver memoryimagesource page pool int pool size long lru limit if pool size 0 auto extended true pool size infinite pool initial size this pool size pool size this lru limit lru limit pagepool poolsize lrulimit poolsize autoextended poolsize infinite_pool_initial_size poolsize poolsize lrulimit lrulimit final page find long addr int state assert that addr page page size 1 0 page pg int page no int addr page page size log int hash code page no pool size synchronized this for pg hash table hash code pg null pg pg collision chain if pg offs addr if pg access count 0 pg unlink break if pg null pg free pages if pg null free pages page pg next else if auto extended if page no pool size int new pool size page no pool size 2 page no 1 pool size 2 page new hash table new page new pool size system arraycopy hash table 0 new hash table 0 hash table length hash table new hash table pool size new pool size pg new page hash code page no else assert that unfixed page available lru prev lru pg page lru prev pg unlink synchronized pg if pg state page ps dirty 0 pg state 0 file write pg offs pg data if flushing dirty pages pg write queue index dirty pages n dirty pages dirty pages pg write queue index write queue index pg write queue index int h int pg offs page page size log pool size page curr hash table h prev null while curr pg prev curr curr curr collision chain if prev null hash table h pg collision chain else prev collision chain pg collision chain pg access count 1 pg offs addr pg state page ps raw pg collision chain hash table hash code hash table hash code pg if pg state page ps dirty 0 state page ps dirty 0 assert that flushing if n dirty pages dirty pages length page new dirty pages new page n dirty pages 2 system arraycopy dirty pages 0 new dirty pages 0 dirty pages length dirty pages new dirty pages dirty pages n dirty pages pg pg write queue index n dirty pages pg state page ps dirty if pg state page ps raw 0 if file read pg offs pg data page page size for int i 0 i page page size i pg data i 0 pg state page ps raw return pg pagesize pageno pagesizelog hashcode pageno poolsize hashtable hashcode collisionchain accesscount freepages freepages autoextended pageno poolsize newpoolsize pageno poolsize pageno poolsize newhashtable newpoolsize hashtable newhashtable hashtable hashtable newhashtable poolsize newpoolsize hashcode pageno psdirty dirtypages writequeueindex dirtypages ndirtypages dirtypages writequeueindex writequeueindex writequeueindex pagesizelog poolsize hashtable collisionchain hashtable collisionchain collisionchain collisionchain accesscount psraw collisionchain hashtable hashcode hashtable hashcode psdirty psdirty ndirtypages dirtypages newdirtypages ndirtypages dirtypages newdirtypages dirtypages dirtypages newdirtypages dirtypages ndirtypages writequeueindex ndirtypages psdirty psraw pagesize pagesize psraw final synchronized void copy long dst long src long size int dst offs int dst page page size 1 int src offs int src page page size 1 dst dst offs src src offs page dst page find dst page ps dirty page src page find src 0 do if dst offs page page size unfix dst page dst page page size dst page find dst page ps dirty dst offs 0 if src offs page page size unfix src page src page page size src page find src 0 src offs 0 long len size if len page page size src offs len page page size src offs if len page page size dst offs len page page size dst offs system arraycopy src page data src offs dst page data dst offs int len src offs len dst offs len size len while size 0 unfix dst page unfix src page dstoffs pagesize srcoffs pagesize dstoffs srcoffs dstpage psdirty srcpage dstoffs pagesize dstpage pagesize dstpage psdirty dstoffs srcoffs pagesize srcpage pagesize srcpage srcoffs pagesize srcoffs pagesize srcoffs pagesize dstoffs pagesize dstoffs srcpage srcoffs dstpage dstoffs srcoffs dstoffs dstpage srcpage final void write long dst pos byte src assert that dst pos page page size 1 0 assert that src length page page size 1 0 for int i 0 i src length page pg find dst pos page ps dirty byte dst pg data for int j 0 j page page size j dst j src i unfix pg dst pos page page size dstpos dstpos pagesize pagesize dstpos psdirty pagesize dstpos pagesize final void open i file f file f reset ifile final void reset lru new lru free pages null hash table new page pool size dirty pages new page pool size n dirty pages 0 if auto extended for int i pool size i 0 page pg new page pg next free pages free pages pg freepages hashtable poolsize dirtypages poolsize ndirtypages autoextended poolsize freepages freepages final void clear assert that n dirty pages 0 reset ndirtypages final synchronized void close file close hash table null dirty pages null lru null free pages null hashtable dirtypages freepages final synchronized void unfix page pg assert that pg access count 0 if pg access count 0 if pg offs lru limit lru link pg else lru prev link pg accesscount accesscount lrulimit final synchronized void modify page pg assert that pg access count 0 if pg state page ps dirty 0 assert that flushing pg state page ps dirty if n dirty pages dirty pages length page new dirty pages new page n dirty pages 2 system arraycopy dirty pages 0 new dirty pages 0 dirty pages length dirty pages new dirty pages dirty pages n dirty pages pg pg write queue index n dirty pages accesscount psdirty psdirty ndirtypages dirtypages newdirtypages ndirtypages dirtypages newdirtypages dirtypages dirtypages newdirtypages dirtypages ndirtypages writequeueindex ndirtypages final page get page long addr return find addr 0 getpage final page put page long addr return find addr page ps dirty putpage psdirty final byte get long pos assert that pos 0 int offs int pos page page size 1 page pg find pos offs 0 int size object header get size pg data offs assert that size object header sizeof byte obj new byte size int dst 0 while size page page size offs system arraycopy pg data offs obj dst page page size offs unfix pg size page page size offs pos page page size offs dst page page size offs pg find pos 0 offs 0 system arraycopy pg data offs obj dst size unfix pg return obj pagesize objectheader getsize objectheader pagesize pagesize pagesize pagesize pagesize final void put long pos byte obj put pos obj obj length final void put long pos byte obj int size int offs int pos page page size 1 page pg find pos offs page ps dirty int src 0 while size page page size offs system arraycopy obj src pg data offs page page size offs unfix pg size page page size offs pos page page size offs src page page size offs pg find pos page ps dirty offs 0 system arraycopy obj src pg data offs size unfix pg pagesize psdirty pagesize pagesize pagesize pagesize pagesize psdirty void flush synchronized this flushing true java util arrays sort dirty pages 0 n dirty pages for int i 0 i n dirty pages i page pg dirty pages i synchronized pg if pg state page ps dirty 0 file write pg offs pg data pg state page ps dirty file sync n dirty pages 0 flushing false dirtypages ndirtypages ndirtypages dirtypages psdirty psdirty ndirtypages copied from encoder thread see below re licensing public bucket compress bucket data bucket factory bf long max read length long max write length throws io exception compression output size exception bucket output output bf make bucket max write length if logger should log logger minor this logger minor this compressing data size data size to new bucket output counted input stream cis null counted output stream cos null try cis new counted input stream new buffered input stream data get input stream cos new counted output stream new buffered output stream output get output stream encoder encoder new encoder encoder set end marker mode true encoder set dictionary size 1 20 enc write coder properties out 5d 00 00 10 00 encoder code cis cos 1 1 null if logger should log logger minor this logger minor this output output size output size read cis count written cos written cis close cos close finally closer close cis closer close cos return output encoderthread bucketfactory maxreadlength maxwritelength ioexception compressionoutputsizeexception makebucket maxwritelength shouldlog countedinputstream countedoutputstream countedinputstream bufferedinputstream getinputstream countedoutputstream bufferedoutputstream getoutputstream setendmarkermode setdictionarysize writecoderproperties shouldlog public bucket decompress bucket data bucket factory bf long max length long max check size length bucket preferred throws io exception compression output size exception bucket output if preferred null output preferred else output bf make bucket max length if logger should log logger minor this logger minor this decompressing data size data size to new bucket output counted input stream is new counted input stream new buffered input stream data get input stream counted output stream os new counted output stream new buffered output stream output get output stream decompress is os max length max check size length os close if logger should log logger minor this logger minor this output output size output size read is count written os written return output bucketfactory maxlength maxchecksizelength ioexception compressionoutputsizeexception makebucket maxlength shouldlog countedinputstream countedinputstream bufferedinputstream getinputstream countedoutputstream countedoutputstream bufferedoutputstream getoutputstream maxlength maxchecksizelength shouldlog private void decompress input stream is output stream os long max length long max check size bytes throws io exception compression output size exception decoder decoder new decoder decoder set decoder properties props decoder code is os max length inputstream outputstream maxlength maxchecksizebytes ioexception compressionoutputsizeexception setdecoderproperties maxlength public int decompress byte dbuf int i int j byte output throws compression output size exception didn t work with inflater fixme fix sometimes to use inflater format issue byte array input stream bais new byte array input stream dbuf i j byte array output stream baos new byte array output stream output length int bytes 0 try decompress bais baos output length 1 bytes baos size catch io exception e impossible throw new error got io exception e get message e byte buf baos to byte array system arraycopy buf 0 output 0 bytes return bytes compressionoutputsizeexception bytearrayinputstream bytearrayinputstream bytearrayoutputstream bytearrayoutputstream ioexception ioexception getmessage tobytearray tries to detemine the address type of the given address param address the address to determine the type of return link address type other if code address code is a hostname link address type i pv4 or link address type i pv6 otherwise public static address type get address type string address return address identifier get address type address false addresstype addresstype ipv4 addresstype ipv6 addresstype getaddresstype addressidentifier getaddresstype tries to detemine the address type of the given address param address the address to determine the type of param allowi pv6 percent scopeid if true match scope id suffixed i pv6 ip addresses return link address type other if code address code is a hostname link address type i pv4 or link address type i pv6 otherwise public static address type get address type string address boolean allowi pv6 percent scopeid if ipv4 pattern matcher address matches return address type i pv4 else if allowi pv6 percent scopeid ipv6 pattern with percent scopeid ipv6 pattern matcher address matches return address type i pv6 return address type other allowipv6percentscopeid ipv6 addresstype addresstype ipv4 addresstype ipv6 addresstype getaddresstype allowipv6percentscopeid ipv4pattern addresstype ipv4 allowipv6percentscopeid ipv6patternwithpercentscopeid ipv6pattern addresstype ipv6 addresstype see http www ietf org rfc rfc4214 txt public static boolean is anisatapi pv6 address string address return ipv6isatap pattern matcher address matches isanisatapipv6address ipv6isatappattern private static final long serial versionuid 7066290881503106399l public ssdp notify socket list serialversionuid ssdpnotifysocketlist public ssdp notify socket getssdp notify socket int n return ssdp notify socket get n ssdpnotifysocket getssdpnotifysocket ssdpnotifysocket public void set control point control point ctrl point int n sockets size for int n 0 n n sockets n ssdp notify socket sock getssdp notify socket n sock set control point ctrl point setcontrolpoint controlpoint ctrlpoint nsockets nsockets ssdpnotifysocket getssdpnotifysocket setcontrolpoint ctrlpoint public boolean open int n host addrs host interface getn host addresses for int n 0 n n host addrs n string bind addr host interface get host address n ssdp notify socket ssdp notify socket new ssdp notify socket bind addr add ssdp notify socket return true nhostaddrs hostinterface getnhostaddresses nhostaddrs bindaddr hostinterface gethostaddress ssdpnotifysocket ssdpnotifysocket ssdpnotifysocket bindaddr ssdpnotifysocket public void close int n sockets size for int n 0 n n sockets n ssdp notify socket sock getssdp notify socket n sock close clear nsockets nsockets ssdpnotifysocket getssdpnotifysocket public void start int n sockets size for int n 0 n n sockets n ssdp notify socket sock getssdp notify socket n sock start nsockets nsockets ssdpnotifysocket getssdpnotifysocket public void stop int n sockets size for int n 0 n n sockets n ssdp notify socket sock getssdp notify socket n sock stop nsockets nsockets ssdpnotifysocket getssdpnotifysocket private static final long serial versionuid 1 public chk verify exception super serialversionuid chkverifyexception public chk verify exception string message super message chkverifyexception public chk verify exception string message throwable cause super message cause chkverifyexception public chk verify exception throwable cause super cause chkverifyexception public final file file public file exists exception file f super file exists f this file f fileexistsexception public class solarize filter extends transfer filter override protected float transfer function float v return v 0 5f 2 v 0 5f 2 0 5f v solarizefilter transferfilter transferfunction override public string to string return colors solarize tostring public final long length public null bucket this 0 nullbucket public null bucket long length this length length nullbucket returns an output stream that is used to put data in this bucket public output stream get output stream return null out outputstream outputstream getoutputstream nullout returns an input stream that reads data from this bucket if there is no data in this bucket null is returned inputstream returns the amount of data currently in this bucket public long size return length returns the name of this null bucket public string get name return president george w null bucket nullbucket getname nullbucket public boolean is read only return false isreadonly public void set read only do nothing setreadonly public void free do nothing public simple field set to field set simple field set fs new simple field set false fs put single type null bucket return fs simplefieldset tofieldset simplefieldset simplefieldset putsingle nullbucket public void store to object container container container store this storeto objectcontainer public void remove from object container container container delete this removefrom objectcontainer public bucket create shadow throws io exception return new null bucket createshadow ioexception nullbucket private float icentrey public water filter set edge action clamp waterfilter setedgeaction set the wavelength of the ripples param wavelength the wavelength see get wavelength public void set wavelength float wavelength this wavelength wavelength getwavelength setwavelength get the wavelength of the ripples return the wavelength see set wavelength public float get wavelength return wavelength setwavelength getwavelength set the amplitude of the ripples param amplitude the amplitude see get amplitude public void set amplitude float amplitude this amplitude amplitude getamplitude setamplitude get the amplitude of the ripples return the amplitude see set amplitude public float get amplitude return amplitude setamplitude getamplitude set the phase of the ripples param phase the phase see get phase public void set phase float phase this phase phase getphase setphase get the phase of the ripples return the phase see set phase public float get phase return phase setphase getphase set the centre of the effect in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float centrex this centrex centrex getcentrex setcentrex get the centre of the effect in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the effect in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float centrey this centrey centrey getcentrey setcentrey get the centre of the effect in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey set the centre of the effect as a proportion of the image size param centre the center see get centre public void set centre point2d centre this centrex float centre getx this centrey float centre gety getcentre setcentre get the centre of the effect as a proportion of the image size return the center see set centre public point2d get centre return new point2d float centrex centrey setcentre getcentre set the radius of the effect param radius the radius min value 0 see get radius public void set radius float radius this radius radius getradius setradius get the radius of the effect return the radius see set radius public float get radius return radius setradius getradius private boolean inside int v int a int b return a v v b override public buffered image filter buffered image src buffered image dst icentrex src get width centrex icentrey src get height centrey if radius 0 radius math min icentrex icentrey radius2 radius radius return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight override protected void transform inverse int x int y float out float dx x icentrex float dy y icentrey float distance2 dx dx dy dy if distance2 radius2 out 0 x out 1 y else float distance float math sqrt distance2 float amount amplitude float math sin distance wavelength image math two pi phase amount radius distance radius if distance 0 amount wavelength distance out 0 x dx amount out 1 y dy amount transforminverse imagemath two_pi override public string to string return distort water ripples tostring public global probe node n this node n cb new probe callback public void on completed string reason double target double best double nearest long id short counter short unique count short linear count string msg completed probe request target best r n nearest actually hit nearest counter nodes linear count hops unique count unique nodes in system current time millis last time id id r n logger error this msg synchronized global probe this done something true last location best last hops counter global probe this notify all public void on trace long uid double target double nearest double best short htl short counter double location long nodeuid double peer locs long peerui ds double locs not visited short fork count short linear count string reason long prevuid string msg probe trace uid uid target target nearest nearest best best htl htl counter counter location location node uid nodeuid prev uid prevuid peers node dispatcher peersui ds to string peerui ds peer locs locs not visited arrays to string locs not visited fork count fork count linear count linear count from reason logger normal this msg public void on reject overload logger normal this probe trace received rejected overload globalprobe probecallback oncompleted uniquecount linearcount nnearest linearcount uniquecount currenttimemillis lasttime globalprobe donesomething lastlocation lasthops globalprobe notifyall ontrace peerlocs peeruids locsnotvisited forkcount linearcount nodedispatcher peersuidstostring peeruids peerlocs tostring locsnotvisited forkcount linearcount onrejectoverload cb new probe callback public void on completed string reason double target double best double nearest long id short counter short unique count short linear count string msg completed probe request target best r n nearest actually hit nearest counter nodes linear count hops unique count unique nodes in system current time millis last time id id r n logger error this msg synchronized global probe this done something true last location best last hops counter global probe this notify all probecallback oncompleted uniquecount linearcount nnearest linearcount uniquecount currenttimemillis lasttime globalprobe donesomething lastlocation lasthops globalprobe notifyall public void on trace long uid double target double nearest double best short htl short counter double location long nodeuid double peer locs long peerui ds double locs not visited short fork count short linear count string reason long prevuid string msg probe trace uid uid target target nearest nearest best best htl htl counter counter location location node uid nodeuid prev uid prevuid peers node dispatcher peersui ds to string peerui ds peer locs locs not visited arrays to string locs not visited fork count fork count linear count linear count from reason logger normal this msg ontrace peerlocs peeruids locsnotvisited forkcount linearcount nodedispatcher peersuidstostring peeruids peerlocs tostring locsnotvisited forkcount linearcount public void on reject overload logger normal this probe trace received rejected overload onrejectoverload public void run freenet support logger os thread logpid this synchronized this last location 0 0 double prev loc last location while true done something false last time system current time millis node dispatcher start probe last location cb for int i 0 i 20 done something i try wait 1000 10 catch interrupted exception e ignore all vars should be updated by resynchronizing here right if done something error stalled on last location waiting some more try wait 100 1000 catch interrupted exception e ignore if done something error still no response to probe request trying again continue if math abs last location prev loc double min value 2 error location is same as previous sleeping then trying again try wait 100 1000 catch interrupted exception e ignore continue output last location last hops prev loc last location if last location 1 0 math abs last location 1 0 2 double min value break ctr sleep 10 seconds so we don t flood try wait 10 1000 catch interrupted exception e ignore osthread lastlocation prevloc lastlocation donesomething lasttime currenttimemillis startprobe lastlocation donesomething interruptedexception donesomething lastlocation interruptedexception donesomething lastlocation prevloc min_value interruptedexception lastlocation lasthops prevloc lastlocation lastlocation lastlocation min_value interruptedexception private void output double loc int hops double estimated nodes ctr 1 0 loc logger error this location ctr loc estimated nodes estimated nodes hops hops system err println location ctr loc estimated nodes estimated nodes hops hops estimatednodes estimatednodes estimatednodes private void error string string logger error this string system err println global probe error string globalprobe creates a new config object and stores the default values in it protected config wot my wot m wot my wot mdb m wot getdb m string params new hash map string string m int params new hash map string integer set default values false mywot mwot mywot mwot mstringparams hashmap mintparams hashmap setdefaultvalues protected void initialize transient wot my wot m wot my wot mdb my wot getdb initializetransient mywot mwot mywot mywot loads an existing config object from the database and adds any missing default values to it creates and stores a new one if none exists return the config object public static config load or create wot my wot ext object container db my wot getdb synchronized db lock config config object set config result db query by example config class if result size 0 logger debug my wot creating new config config new config my wot config store and commit else if result size 1 do not throw we do not want to prevent wot from starting up logger error my wot multiple config objects stored logger debug my wot loaded config config result next config initialize transient my wot config set default values false return config loadorcreate mywot extobjectcontainer mywot objectset querybyexample mywot mywot storeandcommit mywot mywot initializetransient mywot setdefaultvalues stores the config object in the database please call this after any modifications to the config it is not done automatically because the user interface will usually change many values at once public synchronized void store and commit synchronized mdb lock try mdb store m string params 3 mdb store m int params 3 mdb store this catch runtime exception e mdb rollback throw e storeandcommit mstringparams mintparams runtimeexception sets a string configuration parameter you have to call store and commit to write it to disk param key name of the config parameter param value value of the config parameter public synchronized void set string key string value m string params put key value storeandcommit mstringparams sets an integer configuration parameter and stores it in the database you have to call store and commit to write it to disk param key name of the config parameter param value value of the config parameter public synchronized void set string key int value m int params put key value storeandcommit mintparams gets a string configuration parameter public synchronized string get string string key return m string params get key getstring mstringparams gets an integer configuration parameter public synchronized int get int string key return m int params get key getint mintparams check wheter a string config parameter exists public synchronized boolean contains string string key return m string params contains key key containsstring mstringparams containskey check wheter an integer config parameter exists public synchronized boolean contains int string key return m int params contains key key containsint mintparams containskey get all valid string configuration keys return a string array containing a copy of all keys in the database at the point of calling the function changes to the array do not change the database public synchronized string get all string keys we return a copy of the key set if we returned an iterator of the key set modifications on the configuration hash map would be reflected in the iterator this might lead to problems if the configuration is modified while someone is using an iterator returned by this function further the iterator would allow the user to delete keys from the configuration fixme there is a null pointer somewhere in here i don t have the time for fixing it right now return m string params key set to array new string m string params size getallstringkeys keyset keyset hashmap mstringparams keyset toarray mstringparams get all valid string configuration keys return a string array containing a copy of all keys in the database at the point of calling the function changes to the array do not change the database public synchronized string get all int keys we return a copy of the key set if we returned an iterator of the key set modifications on the configuration hash map would be reflected in the iterator this might lead to problems if the configuration is modified while someone is using an iterator returned by this function further the iterator would allow the user to delete keys from the configuration fixme there is a null pointer somewhere in here i don t have the time for fixing it right now return m int params key set to array new string m string params size getallintkeys keyset keyset hashmap mintparams keyset toarray mstringparams add the default configuration values to the database param overwrite if true overwrite already set values with the default value public synchronized void set default values boolean overwrite do not overwrite it shall only be overwritten when the database has been converted to a new format if contains int database format version set database format version wot database format version setdefaultvalues containsint database_format_version database_format_version database_format_version construct a spline colormap public spline colormap rebuild gradient splinecolormap splinecolormap rebuildgradient construct a spline colormap param x knots the knot positions param y knots the knot colors public spline colormap int x knots int y knots this x knots x knots this y knots y knots num knots x knots length rebuild gradient splinecolormap xknots yknots splinecolormap xknots yknots xknots xknots yknots yknots numknots xknots rebuildgradient set a knot color param n the knot index param color the color see get knot public void set knot int n int color y knots n color rebuild gradient getknot setknot yknots rebuildgradient get a knot color param n the knot index return the knot color see set knot public int get knot int n return y knots n setknot getknot yknots add a new knot param x the knot position param color the color see remove knot public void add knot int x int color int nx new int num knots 1 int ny new int num knots 1 system arraycopy x knots 0 nx 0 num knots system arraycopy y knots 0 ny 0 num knots x knots nx y knots ny x knots num knots x y knots num knots color num knots sort knots rebuild gradient removeknot addknot numknots numknots xknots numknots yknots numknots xknots yknots xknots numknots yknots numknots numknots sortknots rebuildgradient remove a knot param n the knot index see add knot public void remove knot int n if num knots 4 return if n num knots 1 system arraycopy x knots n 1 x knots n num knots n 1 system arraycopy y knots n 1 y knots n num knots n 1 num knots rebuild gradient addknot removeknot numknots numknots xknots xknots numknots yknots yknots numknots numknots rebuildgradient set a knot position param n the knot index param x the knot position public void set knot position int n int x x knots n pixel utils clamp x sort knots rebuild gradient setknotposition xknots pixelutils sortknots rebuildgradient private void rebuild gradient x knots 0 1 x knots num knots 1 256 y knots 0 y knots 1 y knots num knots 1 y knots num knots 2 for int i 0 i 256 i map i image math color spline i num knots x knots y knots rebuildgradient xknots xknots numknots yknots yknots yknots numknots yknots numknots imagemath colorspline numknots xknots yknots private void sort knots for int i 1 i num knots i for int j 1 j i j if x knots i x knots j int t x knots i x knots i x knots j x knots j t t y knots i y knots i y knots j y knots j t sortknots numknots xknots xknots xknots xknots xknots xknots yknots yknots yknots yknots private static final string plug name librarian public void terminate goon false plugname public string handlehttp post http request request throws pluginhttp exception return null handlehttppost httprequest pluginhttpexception private void append default page start string builder out string stylesheet out append html head title plug name title if stylesheet null out append link href stylesheet type text css rel stylesheet out append head body n out append center h1 plug name h1 br br br n appenddefaultpagestart stringbuilder plugname plugname private void append default page end string builder out out append center body html appenddefaultpageend stringbuilder private void append default post fields string builder out string search string index search html encoder encode search index html encoder encode index out append search for br out append form method get input type text value append search append name search size 80 br br out append using the index br out append input type text name index value append index append size 80 out append input type submit value find form n index key to index search text to search for appenddefaultpostfields stringbuilder htmlencoder htmlencoder private hash map get full index string uri throws exception high level simple client hlsc pr gethl simple client freeneturi u new freeneturi uri fetch result res while true try res hlsc fetch u break catch fetch exception e if e newuri null u e newuri continue else throw e string index new string res as byte array trim split n vector uris new vector hash map keywords new hash map int i uri wrapper uriw new uri wrapper for i 0 i index length i if index i starts with start new uriw new uri wrapper uriw uri index i substring 1 uris add uriw else if index i starts with continue old if uriw descr null uriw descr index i substring 1 else uriw descr n index i substring 1 else break for i index length i if index i starts with break string parts index i split vector keyuris new vector system err println for int j 1 j parts length j int uri number integer parse int parts j uri wrapper uw uri wrapper uris get uri number yes i know this is o n but there shouldn t be that many hits for a single word fixme if there are use a linked hash set note that this will cost far more memory don t use a plain hash set because we want the results returned in order if keyuris contains uw keyuris add uw system err println keywords put parts 0 substring 1 keyuris return keywords hashmap getfullindex highlevelsimpleclient gethlsimpleclient fetchresult fetchexception asbytearray hashmap hashmap uriwrapper uriwrapper startswith uriwrapper startswith startswith urinumber parseint uriwrapper uriwrapper urinumber linkedhashset hashset public string handlehttp get http request request throws pluginhttp exception string builder out new string builder int page request get int param page 1 string indexuri request get param index default index uri string search request get param search string stylesheet request get param stylesheet null if stylesheet null filter callback cb pr make filter callback request get path try stylesheet cb processuri stylesheet text css catch comment exception e return invalid stylesheet e get message if search equals append default page start out stylesheet append default post fields out append default post fields out search indexuri append default page end out return out to string try cache later high level simple client hlsc pr gethl simple client string index new string hlsc fetch new freeneturi indexuri as byte array trim cache imglist imglist replace all r n do i imglist hash code imglist imglist replace all n n n while i imglist hash code string imgarr imglist split n hash map index get full index indexuri append default page start out stylesheet append default post fields out search indexuri out append p span class librarian searching for header searching for span span class librarian searching for target append html encoder encode search append span p n string search words search replace all 20 split get search result string search words search split return results in order linked hash set hs new linked hash set synchronized hs add all for the first word vector keyuris vector index get search words 0 to lower case trim if keyuris null iterator it keyuris iterator while it has next hs add it next synchronized hs for int i 1 i search words length i vector keyuris vector index get search words i to lower case trim iterator it hs iterator while it has next object o it next if keyuris contains o it remove output results int results 0 out append table class librarian results tr n iterator it hs iterator while it has next uri wrapper o uri wrapper it next string showurl o uri string description html encoder encode o descr description description replace all n lt b b r r gt br description description replace all nbsp description description replace all lt a za z gt showurl html encoder encode showurl if showurl length 60 showurl showurl substring 0 15 hellip showurl replace first string realurl o uri starts with o uri realurl html encoder encode realurl out append p n table class librarian result width 100 border 1 tr td align center bgcolor d0d0d0 class librarian result url n out append a href append realurl append title append o uri append append showurl append a n out append td tr tr td align left class librarian result summary n out append tt append description append tt n out append td tr table n results out append tr table n out append p span class librarian summary found text found span span class librarian summary found number append results append results span p n append default page end out return out to string catch exception e todo auto generated catch block e print stack trace return e to string handlehttpget httprequest pluginhttpexception stringbuilder stringbuilder getintparam getparam default_index_uri getparam getparam filtercallback makefiltercallback getpath commentexception getmessage appenddefaultpagestart appenddefaultpostfields appenddefaultpostfields appenddefaultpageend tostring highlevelsimpleclient gethlsimpleclient asbytearray replaceall hashcode replaceall hashcode hashmap getfullindex appenddefaultpagestart appenddefaultpostfields htmlencoder searchwords replaceall searchwords linkedhashset linkedhashset searchwords tolowercase hasnext searchwords searchwords tolowercase hasnext hasnext uriwrapper uriwrapper htmlencoder replaceall replaceall replaceall htmlencoder replacefirst startswith htmlencoder appenddefaultpageend tostring printstacktrace tostring public void run plugin plugin respirator pr this pr pr int i int system current time millis 1000 while goon fetch result fr try fr pr gethl simple client fetch new freeneturi freenet chk j v1zc0cun3wla cpxl kd6vt6c1j ant9 kisc vjfz lu54 q9f ilj sh8m1i1ymr bz a0fs ic gkvuy zah zb5j7uepla aaea 8 system err println got data from key length fr size message new string fr as byte array trim catch exception e try thread sleep 300000 catch interrupted exception e todo auto generated catch block e print stack trace runplugin pluginrespirator currenttimemillis fetchresult gethlsimpleclient v1zc0cun3wlacpxlkd6vt6c1jant9kiscvjfzlu54 q9filjsh8m1i1ymrbz a0fsicgkvuyzahzb5j7uepla asbytearray interruptedexception printstacktrace public int compare to object o if o instanceof uri wrapper return uri compare to uri wrapper o uri return 1 compareto uriwrapper compareto uriwrapper public abstract class base data carrying message extends fcp message abstract long data length basedatacarryingmessage fcpmessage datalength abstract long data length public abstract void read from input stream is bucket factory bf fcp server server throws io exception message invalid exception datalength readfrom inputstream bucketfactory fcpserver ioexception messageinvalidexception override public void send output stream os throws io exception super send os write data os outputstream ioexception writedata protected abstract void write data output stream os throws io exception writedata outputstream ioexception construct a transition filter private transition filter transitionfilter transitionfilter construct a transition filter param filter the filter to use param property the filter property which is changed over the transition param min value the start value for the filter property param max value the end value for the filter property public transition filter buffered image op filter string property float min value float max value this filter filter this property property this min value min value this max value max value try bean info info introspector get bean info filter get class property descriptor pds info get property descriptors for int i 0 i pds length i property descriptor pd pds i if property equals pd get name method pd get write method break if method null throw new illegal argument exception no such property in object property catch introspection exception e throw new illegal argument exception e to string transitionfilter minvalue maxvalue transitionfilter bufferedimageop minvalue maxvalue minvalue minvalue maxvalue maxvalue beaninfo getbeaninfo getclass propertydescriptor getpropertydescriptors propertydescriptor getname getwritemethod illegalargumentexception introspectionexception illegalargumentexception tostring set the transition of the image in the range 0 1 param transition the transition min value 0 max value 1 see get transition public void set transition float transition this transition transition gettransition settransition get the transition of the image return the transition see set transition public float get transition return transition settransition gettransition set the destination image param destination the destination image see get destination public void set destination buffered image destination this destination destination getdestination setdestination bufferedimage get the destination image return the destination image see set destination public buffered image get destination return destination setdestination bufferedimage getdestination prepare the filter for the transiton at a given time the default implementation sets the given filter property but you could override this method to make other changes param transition the transition time in the range 0 1 public void prepare filter float transition try method invoke filter new object new float transition catch exception e throw new illegal argument exception error setting value for property property preparefilter illegalargumentexception public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null if destination null return dst float itransition 1 transition graphics2d g dst create graphics if transition 1 float t min value transition max value min value prepare filter t g draw image src filter 0 0 if transition 0 g set composite alpha composite get instance alpha composite src over transition float t min value itransition max value min value prepare filter t g draw image destination filter 0 0 g dispose return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage creategraphics minvalue maxvalue minvalue preparefilter drawimage setcomposite alphacomposite getinstance alphacomposite src_over minvalue maxvalue minvalue preparefilter drawimage override public string to string return transitions transition tostring logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog f proxy fetch tracker client context context fetch context fctx request client rc fetchers new multi value table freeneturi f proxy fetch in progress this context context this fctx fctx this rc rc fproxyfetchtracker clientcontext fetchcontext requestclient multivaluetable fproxyfetchinprogress f proxy fetch waiter make fetcher freeneturi key long max size f proxy fetch in progress progress locking call get waiter inside the fetchers lock since we will purge old fetchers inside that lock hence avoid a race condition fetch in progress lock is always taken last synchronized fetchers if fetchers contains key key object check fetchers get array key for int i 0 i check length i progress f proxy fetch in progress check i if progress max size max size progress not finished or fatally finished progress has data return progress get waiter progress new f proxy fetch in progress this key max size fetch identifiers context fctx rc fetchers put key progress try progress start context catch fetch exception e synchronized fetchers fetchers remove element key progress return progress get waiter fixme promote a fetcher when it is re used fixme get rid of fetchers over some age fproxyfetchwaiter makefetcher maxsize fproxyfetchinprogress getwaiter fetchinprogress containskey getarray fproxyfetchinprogress maxsize maxsize notfinishedorfatallyfinished hasdata getwaiter fproxyfetchinprogress maxsize fetchidentifiers fetchexception removeelement getwaiter public void queue cancel f proxy fetch in progress progress if logminor logger minor this queueing removal of old f proxy fetch in progress s synchronized this if queued job requeue true return queued job true context ticker queue timed job this f proxy fetch in progress lifetime queuecancel fproxyfetchinprogress fproxyfetchinprogress queuedjob queuedjob queuetimedjob fproxyfetchinprogress public void run if logminor logger minor this removing old f proxy fetch in progress s array list f proxy fetch in progress to remove null boolean need requeue false synchronized fetchers if requeue requeue false need requeue true else queued job false horrible hack fixme enumeration e fetchers keys while e has more elements freeneturi uri freeneturi e next element really horrible hack fixme vector f proxy fetch in progress list vector f proxy fetch in progress fetchers iterate all uri for f proxy fetch in progress f list fixme remove on the fly although cancel must wait if f can cancel if to remove null to remove new array list f proxy fetch in progress to remove add f if to remove null for f proxy fetch in progress r to remove fetchers remove element r uri r if to remove null for f proxy fetch in progress r to remove r finish cancel if need requeue context ticker queue timed job this f proxy fetch in progress lifetime fproxyfetchinprogress arraylist fproxyfetchinprogress toremove needrequeue needrequeue queuedjob hasmoreelements nextelement fproxyfetchinprogress fproxyfetchinprogress iterateall fproxyfetchinprogress cancancel toremove toremove arraylist fproxyfetchinprogress toremove toremove fproxyfetchinprogress toremove removeelement toremove fproxyfetchinprogress toremove finishcancel needrequeue queuetimedjob fproxyfetchinprogress int types rnd btree compound index rndbtreecompoundindex rnd btree compound index class key types boolean unique this unique unique type class descriptor tp raw types new int key types length for int i 0 i key types length i types i get compound key component type key types i rndbtreecompoundindex keytypes classdescriptor tpraw keytypes keytypes getcompoundkeycomponenttype keytypes static int get compound key component type class c if c equals boolean class return class descriptor tp boolean else if c equals byte class return class descriptor tp byte else if c equals character class return class descriptor tp char else if c equals short class return class descriptor tp short else if c equals integer class return class descriptor tp int else if c equals long class return class descriptor tp long else if c equals float class return class descriptor tp float else if c equals double class return class descriptor tp double else if c equals string class return class descriptor tp string else if c equals date class return class descriptor tp date else if i persistent class is assignable from c return class descriptor tp object else if comparable class is assignable from c return class descriptor tp raw else throw new storage error storage error unsupported index type c getcompoundkeycomponenttype classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpstring classdescriptor tpdate ipersistent isassignablefrom classdescriptor tpobject isassignablefrom classdescriptor tpraw storageerror storageerror unsupported_index_type public class get key types class key types new class types length for int i 0 i key types length i key types i map key type types i return key types getkeytypes keytypes keytypes keytypes mapkeytype keytypes public int compare to object o compound key c compound key o int n keys length c keys length keys length c keys length for int i 0 i n i int diff comparable keys i compare to c keys i if diff 0 return diff return 0 allow to compare part of the compound key compareto compoundkey compoundkey compareto compound key object keys this keys keys compoundkey private key convert key key key if key null return null if key type class descriptor tp array of object throw new storage error storage error incompatible key type return new key new compound key object key oval key inclusion 0 convertkey classdescriptor tparrayofobject storageerror storageerror incompatible_key_type compoundkey public array list t get list key from key till return super get list convert key from convert key till arraylist getlist getlist convertkey convertkey public t get key key return super get convert key key convertkey public t remove key key return super remove convert key key convertkey public void remove key key t obj super remove convert key key obj convertkey public t set key key t obj return super set convert key key obj convertkey public boolean put key key t obj return super put convert key key obj convertkey public iterable iterator t iterator key from key till int order return super iterator convert key from convert key till order iterableiterator convertkey convertkey public iterable iterator map entry object t entry iterator key from key till int order return super entry iterator convert key from convert key till order iterableiterator entryiterator entryiterator convertkey convertkey get a list of fields which the database should create an index on public static string get indexed fields return new string mid getindexedfields creates a new own identity with the given parameters param inserturi a link freeneturi used to insert this own identity in freenet param requesturi a link freeneturi used to fetch this own identity in freenet param nick name the nick name of this own identity param publish trust list whether this own identity publishes its trust list or not throws invalid parameter exception if a given parameter is invalid public own identity freeneturi inserturi freeneturi requesturi string nick name boolean publish trust list throws invalid parameter exception super requesturi nick name publish trust list m creation date current timeutc get set inserturi inserturi m last insert date new date 0 set edition 0 if m requesturi null throw new invalid parameter exception own identities must have a request uri if m inserturi null throw new invalid parameter exception own identities must have an insert uri ownidentity ownidentity ownidentity nickname nickname ownidentity publishtrustlist ownidentity trustlist invalidparameterexception ownidentity nickname publishtrustlist invalidparameterexception nickname publishtrustlist mcreationdate currenttimeutc setinserturi mlastinsertdate setedition mrequesturi invalidparameterexception minserturi invalidparameterexception creates a new own identity with the given parameters inserturi and requesturi are converted from string to link freeneturi param inserturi a string representing the key needed to insert this own identity in freenet param requesturia string representing the key needed to fetch this own identity from freenet param nick name the nick name of this own identity param publish trust list whether this own identity publishes its trust list or not throws invalid parameter exception if a given parameter is invalid throws malformedurl exception if either requesturi or inserturi is not a valid freeneturi public own identity string inserturi string requesturi string nick name boolean publish trust list throws invalid parameter exception malformedurl exception this new freeneturi inserturi new freeneturi requesturi nick name publish trust list ownidentity ownidentity ownidentity nickname nickname ownidentity publishtrustlist ownidentity trustlist invalidparameterexception malformedurlexception ownidentity nickname publishtrustlist invalidparameterexception malformedurlexception nickname publishtrustlist whether this own identity needs to be inserted or not we insert own identities when they have been modified and at least once every three days return whether this own identity needs to be inserted or not public synchronized boolean needs insert return get last change date after get last insert date new date get time get last insert date get time identity inserter max unchanged tine before reinsert ownidentity ownidentities ownidentity needsinsert getlastchangedate getlastinsertdate gettime getlastinsertdate gettime identityinserter max_unchanged_tine_before_reinsert return this own identity s inserturi public synchronized freeneturi get inserturi return m inserturi ownidentity getinserturi minserturi sets this own identity s inserturi the key must be a usk or a ssk and is stored as a usk anyway param key this own identity s inserturi throws invalid parameter exception if the supplied key is neither a usk nor a ssk private void set inserturi freeneturi new inserturi throws invalid parameter exception if m inserturi null new inserturi equals keypair m inserturi throw new illegal argument exception cannot change the insert uri of an existing identity if new inserturi isusk new inserturi isssk throw new illegal argument exception identity uri keytype not supported new inserturi m inserturi new inserturi set key type usk set doc name wot set meta string null updated ownidentity ownidentity invalidparameterexception setinserturi newinserturi invalidparameterexception minserturi newinserturi equalskeypair minserturi illegalargumentexception newinserturi newinserturi illegalargumentexception newinserturi minserturi newinserturi setkeytype setdocname setmetastring override protected synchronized void set edition long edition throws invalid parameter exception super set edition edition if edition m inserturi get edition m inserturi m inserturi set suggested edition edition updated setedition invalidparameterexception setedition minserturi getedition minserturi minserturi setsuggestededition only needed for normal identities override protected synchronized void decrease edition return decreaseedition public date get creation date return date m creation date clone getcreationdate mcreationdate get the date of last insertion of this own identity in utc null if it was not inserted yet public synchronized date get last insert date return date m last insert date clone ownidentity getlastinsertdate mlastinsertdate sets the last insertion date of this own identity to current time in utc protected synchronized void update last insert date m last insert date current timeutc get ownidentity updatelastinsertdate mlastinsertdate currenttimeutc public float x y z angle public axis angle4f this 0 0 0 0 axisangle4f public axis angle4f float x this x x 0 this y x 1 this z x 2 this angle x 2 axisangle4f public axis angle4f float x float y float z float angle this x x this y y this z z this angle angle axisangle4f public axis angle4f axis angle4f t this x t x this y t y this z t z this angle t angle axisangle4f axisangle4f public axis angle4f vector3f v float angle this x v x this y v y this z v z this angle angle axisangle4f public void set float x float y float z float angle this x x this y y this z z this angle angle public void set axis angle4f t x t x y t y z t z angle t angle axisangle4f public void get axis angle4f t t x x t y y t z z t angle angle axisangle4f public void get float t t 0 x t 1 y t 2 z t 3 angle override public string to string return x y z angle tostring public opennet manager node node node crypto config opennet config long startup time boolean enable announcement throws node init exception logminor logger should log logger minor this this creation time system current time millis this node node crypto new node crypto node true opennet config startup time node enablear ks file node file new file node node dir opennet crypto port number file backup node file new file opennet crypto port number bak keep opennet crypto details in a separate file try read file node file catch io exception e try read file backup node file catch io exception e1 crypto init crypto peerslru new lru queue peer node old peers new lru queue peer node node peers try read peers new file node node dir openpeers crypto port number to string crypto this true false opennet peer node nodes node peers get opennet peers arrays sort nodes new comparator opennet peer node public int compare opennet peer node pn1 opennet peer node pn2 long last success1 pn1 time last success long last success2 pn2 time last success if last success1 last success2 return 1 if last success2 last success1 return 1 boolean never connected1 pn1 never connected boolean never connected2 pn2 never connected if never connected1 never connected2 return 1 if never connected1 never connected2 return 1 return pn1 hash code pn2 hash code for int i 0 i nodes length i peerslru push nodes i drop excess peers write file node file backup node file read old peers node peers try read peers new file node node dir openpeers old crypto port number to string crypto this true true announcer enable announcement new announcer this null if logminor logger minor this my full compressed ref crypto my compressed full ref length logger minor this my full setup ref crypto my compressed setup ref length logger minor this my heavy setup ref crypto my compressed heavy setup ref length opennetmanager nodecryptoconfig opennetconfig startuptime enableannouncement nodeinitexception shouldlog creationtime currenttimemillis nodecrypto opennetconfig startuptime enablearks nodefile nodedir portnumber backupnodefile portnumber readfile nodefile ioexception readfile backupnodefile ioexception initcrypto lruqueue peernode oldpeers lruqueue peernode tryreadpeers nodedir portnumber tostring opennetpeernode getopennetpeers opennetpeernode opennetpeernode opennetpeernode lastsuccess1 timelastsuccess lastsuccess2 timelastsuccess lastsuccess1 lastsuccess2 lastsuccess2 lastsuccess1 neverconnected1 neverconnected neverconnected2 neverconnected neverconnected1 neverconnected2 neverconnected1 neverconnected2 hashcode hashcode dropexcesspeers writefile nodefile backupnodefile tryreadpeers nodedir portnumber tostring enableannouncement mycompressedfullref mycompressedsetupref mycompressedheavysetupref arrays sort nodes new comparator opennet peer node public int compare opennet peer node pn1 opennet peer node pn2 long last success1 pn1 time last success long last success2 pn2 time last success if last success1 last success2 return 1 if last success2 last success1 return 1 boolean never connected1 pn1 never connected boolean never connected2 pn2 never connected if never connected1 never connected2 return 1 if never connected1 never connected2 return 1 return pn1 hash code pn2 hash code opennetpeernode opennetpeernode opennetpeernode lastsuccess1 timelastsuccess lastsuccess2 timelastsuccess lastsuccess1 lastsuccess2 lastsuccess2 lastsuccess1 neverconnected1 neverconnected neverconnected2 neverconnected neverconnected1 neverconnected2 neverconnected1 neverconnected2 hashcode hashcode public void write file file node file new file node node dir opennet crypto port number file backup node file new file opennet crypto port number bak write file node file backup node file writefile nodefile nodedir portnumber backupnodefile portnumber writefile nodefile backupnodefile private void write file file orig file backup logminor logger should log logger minor this simple field set fs crypto export private field set if orig exists backup delete file output stream fos null output stream writer osr null buffered writer bw null try fos new file output stream backup osr new output stream writer fos utf 8 bw new buffered writer osr fs write to bw bw close file util rename to backup orig catch io exception e closer close bw closer close osr closer close fos writefile shouldlog simplefieldset exportprivatefieldset fileoutputstream outputstreamwriter bufferedwriter fileoutputstream outputstreamwriter bufferedwriter writeto fileutil renameto ioexception private void read file file filename throws io exception redflag any way to share this code with node and node peer file input stream fis new file input stream filename input stream reader isr new input stream reader fis utf 8 buffered reader br new buffered reader isr simple field set fs new simple field set br false true br close read contents string udp fs get all physical udp if udp null udp length 0 for int i 0 i udp length i just keep the first one with the correct port number peer p try p new peer udp i false true catch hostname syntax exception e logger error this invalid hostname or ip address syntax error while loading opennet peer node reference udp i system err println invalid hostname or ip address syntax error while loading opennet peer node reference udp i continue catch peer parse exception e io exception e1 new io exception e1 init cause e throw e1 if p get port crypto port number dns requester doesn t deal with our own node node ip detector set oldip address p get freenet address break crypto read crypto fs readfile ioexception nodepeer fileinputstream fileinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader simplefieldset simplefieldset getall hostnamesyntaxexception peerparseexception ioexception ioexception initcause getport portnumber dnsrequester ipdetector setoldipaddress getfreenetaddress readcrypto public void start crypto start if announcer null announcer start called when opennet is disabled public void stop boolean purge if announcer null announcer stop crypto stop if purge node peers remove opennet peers crypto socket get address tracker set presumed innocent removeopennetpeers getaddresstracker setpresumedinnocent public opennet peer node add new opennet node simple field set fs throws fs parse exception peer parse exception reference signature verification exception try opennet peer node pn new opennet peer node fs node crypto this node peers false crypto packet mangler if arrays equals pn get identity crypto my identity if logminor logger minor this not adding self as opennet peer return null equal to myself if peerslru contains pn if logminor logger minor this not adding pn user to string to opennet list as already there return null if want peer pn true false false return pn else return null start at bottom node must prove itself catch throwable t don t break the code flow in the caller which is normally a request logger error this caught t adding opennet node from fieldset t return null opennetpeernode addnewopennetnode simplefieldset fsparseexception peerparseexception referencesignatureverificationexception opennetpeernode opennetpeernode packetmangler getidentity myidentity usertostring wantpeer void force add peer peer node node to add now boolean add atlru synchronized this if add atlru peerslru push least node to add now else peerslru push node to add now old peers remove node to add now drop excess peers forceaddpeer peernode nodetoaddnow addatlru addatlru pushleast nodetoaddnow nodetoaddnow oldpeers nodetoaddnow dropexcesspeers trim the peers list and possibly add a new node note that if we are not adding a new node we will only return true every min time between offers to prevent problems caused by many pending offers being accepted simultaneously param node to add now node to add param add atlru if there is a node to add add it at the bottom rather than the top normally we set this on new path folded nodes so that they will be replaced if during the trial period plus the time it takes to get a new path folding offer they don t have a successful request param just checking if true we want to know whether there is space for a node to be added right now if false the normal behaviour applies if node to add now is passed in we decide whether to add that node if it s null we decide whether to send an offer subject to the inter offer time param old opennet peer if true we are trying to add an old opennet peer which has reconnected there is a throttle we accept no more than one old opennet peer every 30 seconds on receiving a packet we call once to decide whether to try to parse it against the old opennet peers and then again to decide whether it is worth keeping in the latter case if we decide not the old opennet peer will be told to disconnect and go away but normally we don t reach that point because of the first check return true if the node was added should be added public boolean want peer peer node node to add now boolean add atlru boolean just checking boolean old opennet peer boolean not many false boolean no disconnect synchronized this if node to add now null peerslru contains node to add now if logminor logger minor this opennet peer already present in lru node to add now return true if get size get number of connected peers to aim if node to add now null if logminor logger minor this added opennet peer node to add now as opennet peers list not full if add atlru peerslru push least node to add now else peerslru push node to add now old peers remove node to add now else if logminor logger minor this want peer because not enough opennet nodes if node to add now null just checking time last offered system current time millis not many true don t check time last added old opennet peer since we want it anyway but do update it if old opennet peer time last added old opennet peer system current time millis no disconnect success count min success between drop conns if not many if node to add now null node peers add peer node to add now true true add to peers outside the om lock return true boolean can add true array list opennet peer node drop list new array list opennet peer node synchronized this int max peers get number of connected peers to aim if we have dropped a disconnected peer then the inter peer offer cooldown doesn t apply we can accept immediately boolean has disconnected false if get size max peers node to add now null peer node to drop peer to drop true false if to drop null has disconnected to drop is connected else while get size max peers node to add now null 0 1 opennet peer node to drop can drop peers which are over the limit to drop peer to drop no disconnect node to add now null false if to drop null if logminor logger minor this no more peers to drop still peerslru size peers cannot accept peer node to add now null node to add now to string can add false break if logminor logger minor this drop opennet peer to drop connected to drop is connected of peerslru size get size if to drop is connected has disconnected true peerslru remove to drop drop list add to drop long now system current time millis if can add old opennet peer if time last added old opennet peer 0 now time last added old opennet peer old opennet peer interval can add false if can add just checking if node to add now null success count 0 if add atlru peerslru push least node to add now else peerslru push node to add now if logminor logger minor this added opennet peer node to add now after clearing drop list size items now have peerslru size opennet peers old peers remove node to add now if drop list is empty time last dropped now if old opennet peer time last added old opennet peer now else if now time last offered min time between offers has disconnected if logminor logger minor this cannot make offer because of minimum time between offers last offered now time last offered ms ago cancel can add false else if drop list is empty time last dropped now if just checking time last offered now if logminor logger minor this sending offer if node to add now null can add node peers add peer node to add now true true if logminor logger minor this already in global peers list node to add now when adding opennet node just because it s in the global peers list doesn t mean its in the lru it may be an old opennet peers reconnection in which case we add it to the global peers list before adding it here for opennet peer node pn drop list if logminor logger minor this dropping lru opennet peer pn node peers disconnect pn true true true return can add min_time_between_offers nodetoaddnow addatlru justchecking nodetoaddnow oldopennetpeer wantpeer peernode nodetoaddnow addatlru justchecking oldopennetpeer notmany nodisconnect nodetoaddnow nodetoaddnow nodetoaddnow getsize getnumberofconnectedpeerstoaim nodetoaddnow nodetoaddnow addatlru pushleast nodetoaddnow nodetoaddnow oldpeers nodetoaddnow nodetoaddnow justchecking timelastoffered currenttimemillis notmany timelastaddedoldopennetpeer oldopennetpeer timelastaddedoldopennetpeer currenttimemillis nodisconnect successcount min_success_between_drop_conns notmany nodetoaddnow addpeer nodetoaddnow canadd arraylist opennetpeernode droplist arraylist opennetpeernode maxpeers getnumberofconnectedpeerstoaim hasdisconnected getsize maxpeers nodetoaddnow peernode todrop peertodrop todrop hasdisconnected todrop isconnected getsize maxpeers nodetoaddnow opennetpeernode todrop todrop peertodrop nodisconnect nodetoaddnow todrop nodetoaddnow nodetoaddnow tostring canadd todrop todrop isconnected getsize todrop isconnected hasdisconnected todrop droplist todrop currenttimemillis canadd oldopennetpeer timelastaddedoldopennetpeer timelastaddedoldopennetpeer old_opennet_peer_interval canadd canadd justchecking nodetoaddnow successcount addatlru pushleast nodetoaddnow nodetoaddnow nodetoaddnow droplist oldpeers nodetoaddnow droplist isempty timelastdropped oldopennetpeer timelastaddedoldopennetpeer timelastoffered min_time_between_offers hasdisconnected timelastoffered canadd droplist isempty timelastdropped justchecking timelastoffered nodetoaddnow canadd addpeer nodetoaddnow nodetoaddnow opennetpeernode droplist canadd void drop excess peers while get size get number of connected peers to aim if logminor logger minor this dropping opennet peers currently peerslru size peer node to drop to drop peer to drop false false if to drop null to drop peer to drop false true if to drop null return peerslru remove to drop if logminor logger minor this dropping to drop node peers disconnect to drop true true true dropexcesspeers getsize getnumberofconnectedpeerstoaim peernode todrop todrop peertodrop todrop todrop peertodrop todrop todrop todrop todrop how many opennet peers do we have connected but out of date nodes don t count towards the connection limit let them connect for long enough to auto update they will be disconnected eventually and then removed see opennet peer node should disconnect and remove now synchronized public int get size int x 0 for enumeration peer node e peerslru elements e has more elements peer node pn e next element if pn is connected pn is unroutable older version x return x opennetpeernode shoulddisconnectandremovenow getsize peernode hasmoreelements peernode nextelement isconnected isunroutableolderversion synchronized opennet peer node peer to drop boolean no disconnect boolean force if get size get number of connected peers to aim don t drop any peers return null else do we want it opennet peer node peers peerslru to array ordered new opennet peer node peerslru size for int i 0 i peers length i opennet peer node pn peers i if pn is connected pn is unroutable older version doesn t count anyway continue if pn null continue if pn is droppable false force continue locking always take the opennet manager lock first if pn is connected if logger should log logger minor this logger minor this possibly dropping opennet peer pn as is disconnected pn set was dropped return pn if system current time millis time last dropped drop connected time return null if no disconnect return null for int i 0 i peers length i opennet peer node pn peers i if pn null continue if pn is connected pn is unroutable older version doesn t count anyway continue if pn is droppable false force continue if logger should log logger minor this logger minor this possibly dropping opennet peer pn system current time millis time last dropped ms since last dropped peer pn set was dropped return pn return null opennetpeernode peertodrop nodisconnect getsize getnumberofconnectedpeerstoaim opennetpeernode toarrayordered opennetpeernode opennetpeernode isconnected isunroutableolderversion isdroppable opennetmanager isconnected shouldlog setwasdropped currenttimemillis timelastdropped drop_connected_time nodisconnect opennetpeernode isconnected isunroutableolderversion isdroppable shouldlog currenttimemillis timelastdropped setwasdropped public void on success opennet peer node pn synchronized this success count if peerslru contains pn peerslru push pn if logminor logger minor this opennet peer pn promoted to top of lru because of successful request return else if logminor logger minor this success on opennet peer which isn t in the lru pn new exception debug re add it nasty race condition when we have few peers if want peer pn false false false start at top as it just succeeded node peers disconnect pn true false true onsuccess opennetpeernode successcount wantpeer public void on remove opennet peer node pn synchronized this peerslru remove pn if pn is droppable true pn grab was dropped if logminor logger minor this on remove for pn old peers push pn while old peers size max old peers old peers pop onremove opennetpeernode isdroppable grabwasdropped onremove oldpeers oldpeers max_old_peers oldpeers synchronized peer node get old peers return old peers to array ordered new peer node old peers size peernode getoldpeers oldpeers toarrayordered peernode oldpeers synchronized peer node get unsorted old peers return old peers to array new peer node old peers size peernode getunsortedoldpeers oldpeers toarray peernode oldpeers add an old opennet node a node which might try to reconnect and which we should accept if we are desperate param pn the node to add to the old opennet nodes lru synchronized void add old opennet node peer node pn old peers push pn addoldopennetnode peernode oldpeers string get old peers filename return new file node node dir openpeers old crypto port number to string getoldpeersfilename nodedir portnumber tostring synchronized int count old opennet peers return old peers size countoldopennetpeers oldpeers peer node random old opennet node peer node nodes get unsorted old peers if nodes length 0 return null return nodes node random next int nodes length peernode randomoldopennetnode peernode getunsortedoldpeers nextint public void purge old opennet peer peer node source old peers remove source purgeoldopennetpeer peernode oldpeers protected int get number of connected peers to aim int max node get max opennet peers if enable peers per kb output int obw limit node get output bandwidth limit if obw limit target bandwidth usage max math min max max peers for scaling else int limit math min max obw limit max peers for scaling target bandwidth usage if limit min peers for scaling limit min peers for scaling max math min max limit return max node peers count connected darknet peers getnumberofconnectedpeerstoaim getmaxopennetpeers enable_peers_per_kb_output obwlimit getoutputbandwidthlimit obwlimit target_bandwidth_usage max_peers_for_scaling obwlimit max_peers_for_scaling target_bandwidth_usage min_peers_for_scaling min_peers_for_scaling countconnecteddarknetpeers send our opennet noderef to a node param is reply if true send an fnp opennet connect reply else send an fnp opennet connect destination param uid the unique id of the request chain involved param peer the node to send the noderef to param cs the full compressed noderef to send throws not connected exception if the peer becomes disconnected while we are trying to send the noderef public void send opennet ref boolean is reply long uid peer node peer byte noderef byte counter ctr throws not connected exception byte padded new byte padded size noderef length if noderef length padded length logger error this noderef too big noderef length bytes return node fast weak random next bytes padded fixme implement next bytes buf offset length system arraycopy noderef 0 padded 0 noderef length long xferuid node random next long message msg2 is reply dmt createfnp opennet connect reply new uid xferuid noderef length padded length dmt createfnp opennet connect destination new uid xferuid noderef length padded length peer send async msg2 null ctr inner send opennet ref xferuid padded peer ctr isreply fnpopennetconnectreply fnpopennetconnectdestination notconnectedexception sendopennetref isreply peernode bytecounter notconnectedexception paddedsize fastweakrandom nextbytes nextbytes nextlong isreply createfnpopennetconnectreplynew createfnpopennetconnectdestinationnew sendasync innersendopennetref just the actual transfer param xferuid the transfer uid param padded the length of the data to transfer param peer the peer to send it to throws not connected exception if the peer is not connected or we lose the connection to the peer or it restarts private void inner send opennet ref long xferuid byte padded peer node peer byte counter ctr throws not connected exception byte array random access thing raf new byte array random access thing padded raf set read only partially received bulk prb new partially received bulk node usm padded length node packet size raf true try bulk transmitter bt new bulk transmitter prb peer xferuid true ctr bt send catch disconnected exception e throw new not connected exception e notconnectedexception innersendopennetref peernode bytecounter notconnectedexception bytearrayrandomaccessthing bytearrayrandomaccessthing setreadonly partiallyreceivedbulk partiallyreceivedbulk packet_size bulktransmitter bulktransmitter disconnectedexception notconnectedexception public long start send announcement request long uid peer node peer byte noderef byte counter ctr double target short htl throws not connected exception long xferuid node random next long message msg dmt createfnp opennet announce request uid xferuid noderef length padded size noderef length target htl peer send async msg null ctr return xferuid startsendannouncementrequest peernode bytecounter notconnectedexception nextlong createfnpopennetannouncerequest paddedsize sendasync public void finish sent announcement request peer node peer byte noderef byte counter ctr long xferuid throws not connected exception byte padded new byte padded size noderef length node fast weak random next bytes padded fixme implement next bytes buf offset length system arraycopy noderef 0 padded 0 noderef length inner send opennet ref xferuid padded peer ctr finishsentannouncementrequest peernode bytecounter notconnectedexception paddedsize fastweakrandom nextbytes nextbytes innersendopennetref private int padded size int length if length padded noderef size return padded noderef size logger normal this large noderef length if length max opennet noderef length throw new illegal argument exception too big noderef length limit is max opennet noderef length return length 10 length 1023 0 0 1 10 paddedsize padded_noderef_size padded_noderef_size max_opennet_noderef_length illegalargumentexception max_opennet_noderef_length public void send announcement reply long uid peer node peer byte noderef byte counter ctr throws not connected exception byte padded new byte padded noderef size if noderef length padded length logger error this noderef too big noderef length bytes return system arraycopy noderef 0 padded 0 noderef length long xferuid node random next long message msg dmt createfnp opennet announce reply uid xferuid noderef length padded length peer send async msg null ctr inner send opennet ref xferuid padded peer ctr sendannouncementreply peernode bytecounter notconnectedexception padded_noderef_size nextlong createfnpopennetannouncereply sendasync innersendopennetref wait for an opennet noderef param is reply if true wait for an fnp opennet connect reply new if false wait for an fnp opennet connect destination new param uid the uid of the parent request return an opennet noderef public byte wait for opennet noderef boolean is reply peer node source long uid byte counter ctr fixme remove back compat code message filter mf message filter create set source source set field dmt uid uid set timeout request sender opennet timeout set type is reply dmt fnp opennet connect reply new dmt fnp opennet connect destination new if is reply also waiting for an ack message filter mf ack message filter create set source source set field dmt uid uid set timeout request sender opennet timeout set type dmt fnp opennet completed ack mf mf ack or mf message msg try msg node usm wait for mf ctr catch disconnected exception e logger normal this no opennet response because node disconnected on this return null lost connection with request source if msg null timeout logger normal this timeout waiting for opennet peer on this return null if msg get spec dmt fnp opennet completed ack return null acked only possible if is reply noderef bulk transfer long xferuid msg get long dmt transfer uid int padded length msg get int dmt padded length int real length msg get int dmt noderef length return inner wait for opennet noderef xferuid padded length real length source is reply uid false ctr isreply fnpopennetconnectreply fnpopennetconnectdestination waitforopennetnoderef isreply peernode bytecounter messagefilter messagefilter setsource setfield settimeout requestsender opennet_timeout settype isreply fnpopennetconnectreplynew fnpopennetconnectdestinationnew isreply messagefilter mfack messagefilter setsource setfield settimeout requestsender opennet_timeout settype fnpopennetcompletedack mfack waitfor disconnectedexception getspec fnpopennetcompletedack isreply getlong transfer_uid paddedlength getint padded_length reallength getint noderef_length innerwaitforopennetnoderef paddedlength reallength isreply byte inner wait for opennet noderef long xferuid int padded length int real length peer node source boolean is reply long uid boolean send reject byte counter ctr if padded length opennet manager max opennet noderef length logger error this noderef too big size util format size padded length real length size util format size real length if send reject reject ref uid source dmt noderef rejected too big ctr return null if real length padded length logger error this real length larger than padded length size util format size padded length real length size util format size real length if send reject reject ref uid source dmt noderef rejected real bigger than padded ctr return null byte buf new byte padded length byte array random access thing raf new byte array random access thing buf partially received bulk prb new partially received bulk node usm buf length node packet size raf false bulk receiver br new bulk receiver prb source xferuid ctr if logminor logger minor this receiving noderef reply is reply as bulk transfer for request uid uid with transfer xferuid from source if br receive if source is connected string msg failed to receive noderef bulk transfer for this retrieval exception get err string prb get abort reason prb get abort description from source if prb get abort reason retrieval exception sender disconnected logger error this msg else logger normal this msg if send reject reject ref uid source dmt noderef rejected transfer failed ctr return null byte noderef new byte real length system arraycopy buf 0 noderef 0 real length return noderef innerwaitforopennetnoderef paddedlength reallength peernode isreply sendreject bytecounter paddedlength opennetmanager max_opennet_noderef_length sizeutil formatsize paddedlength sizeutil formatsize reallength sendreject rejectref noderef_rejected_too_big reallength paddedlength sizeutil formatsize paddedlength sizeutil formatsize reallength sendreject rejectref noderef_rejected_real_bigger_than_padded paddedlength bytearrayrandomaccessthing bytearrayrandomaccessthing partiallyreceivedbulk partiallyreceivedbulk packet_size bulkreceiver bulkreceiver isreply isconnected retrievalexception geterrstring getabortreason getabortdescription getabortreason retrievalexception sender_disconnected sendreject rejectref noderef_rejected_transfer_failed reallength reallength public void reject ref long uid peer node source int reason byte counter ctr message msg dmt createfnp opennet noderef rejected uid reason try source send async msg null ctr catch not connected exception e ignore rejectref peernode bytecounter createfnpopennetnoderefrejected sendasync notconnectedexception public simple field set validate noderef byte noderef int offset int length peer node from boolean force opennet enabled simple field set ref try ref peer node compressed noderef to field set noderef 0 noderef length catch fs parse exception e logger error this invalid noderef e e return null if force opennet enabled ref put opennet true if opennet peer node validate ref ref logger error this could not parse opennet noderef for this from from return null if ref null string identity ref get identity if identity null n2n message type diffnoderef don t have identity register known identity identity return ref simplefieldset validatenoderef peernode forceopennetenabled simplefieldset peernode compressednodereftofieldset fsparseexception forceopennetenabled opennetpeernode validateref n2n_message_type_diffnoderef registerknownidentity do an announcement param target the location to announce to in 0 7 we don t try to prevent nodes from choosing their announcement location because it is easy for them to get the location they want later on anyway and we can do a much more effective announcement this way public void announce double target announcement callback cb announce sender sender new announce sender target this node cb null node executor execute sender announcement to target announcementcallback announcesender announcesender public long get creation time return creation time getcreationtime creationtime private void register known identity string d if logminor logger minor this known id d long now system current time millis synchronized known ids logger minor this adding id d known ids size known ids size known ids push d now logger minor this added id d known ids size known ids size known ids remove before now max age logger minor this added and pruned location d known ids size known ids size if logminor logger minor this estimated opennet size session known ids size registerknownidentity currenttimemillis knownids knownids knownids knownids knownids knownids knownids removebefore max_age knownids knownids knownids return the estimated network size based on locations seen after timestamp or for the whole session if 1 public int get network size estimate long timestamp return known ids count values after timestamp getnetworksizeestimate knownids countvaluesafter static synchronized final void getu name if uname equals unknown return system out println getting uname for logging try inet address addr inet address get local host if addr null uname new string tokenizer addr get host name next token catch exception e ignored getuname inetaddress inetaddress getlocalhost stringtokenizer gethostname nexttoken private static class old log file public old log file file current filename long start time long end time long length this filename current filename this start start time this end end time this size length oldlogfile oldlogfile currentfilename starttime endtime currentfilename starttime endtime public void set max list length int len synchronized list max list size len setmaxlistlength max_list_size public void set max list bytes long len synchronized list max list bytes len setmaxlistbytes max_list_bytes public void set interval string interval name throws interval parse exception string builder sb new string builder interval name length for int i 0 i interval name length i char c interval name char at i if character is digit c break sb append c if sb length 0 string prefix sb to string interval name interval name substring prefix length interval multiplier integer parse int prefix else interval multiplier 1 if interval name ends with s interval name interval name substring 0 interval name length 1 if interval name equals ignore case minute interval calendar minute else if interval name equals ignore case hour interval calendar hour else if interval name equals ignore case day interval calendar day of month else if interval name equals ignore case week interval calendar week of year else if interval name equals ignore case month interval calendar month else if interval name equals ignore case year interval calendar year else throw new interval parse exception invalid interval interval name setinterval intervalname intervalparseexception stringbuilder stringbuilder intervalname intervalname intervalname charat isdigit tostring intervalname intervalname interval_multiplier parseint interval_multiplier intervalname endswith intervalname intervalname intervalname intervalname equalsignorecase intervalname equalsignorecase intervalname equalsignorecase day_of_month intervalname equalsignorecase week_of_year intervalname equalsignorecase intervalname equalsignorecase intervalparseexception intervalname private static final long serial versionuid 69847854744673572l public interval parse exception string string super string serialversionuid intervalparseexception protected string get hour log name calendar c boolean compressed string builder buf new string builder 50 buf append base filename append buf append version build number buf append buf append c get calendar year append pad2digits buf c get calendar month 1 buf append pad2digits buf c get calendar day of month buf append pad2digits buf c get calendar hour of day if interval calendar minute buf append pad2digits buf c get calendar minute buf append log if compressed buf append gz return buf to string gethourlogname stringbuilder stringbuilder basefilename buildnumber day_of_month hour_of_day tostring the extra parameter int digit is to be used for creating a logfile name when a log exists already with the same date param c param digit param compressed return protected string get hour log name calendar c int digit boolean compressed string builder buf new string builder 50 buf append base filename append buf append version build number buf append buf append c get calendar year append pad2digits buf c get calendar month 1 buf append pad2digits buf c get calendar day of month buf append pad2digits buf c get calendar hour of day if interval calendar minute buf append pad2digits buf c get calendar minute buf append buf append digit buf append log if compressed buf append gz return buf to string gethourlogname stringbuilder stringbuilder basefilename buildnumber day_of_month hour_of_day tostring private string builder pad2digits string builder buf int x string s integer to string x if s length 1 buf append 0 buf append s return buf stringbuilder stringbuilder tostring class writer thread extends thread writer thread super log file writer thread writerthread writerthread override suppress warnings fallthrough public void run file current filename null byte o null long this time long last time 1 long start time long next hour 1 gregorian calendar gc null if base filename null latest file new file base filename latest log previous file new file base filename previous log find old log files gc new gregorian calendar switch interval case calendar year gc set calendar month 0 case calendar month gc set calendar day of month 0 case calendar week of year if interval calendar week of year gc set calendar day of week 0 case calendar day of month gc set calendar hour 0 case calendar hour gc set calendar minute 0 case calendar minute gc set calendar second 0 gc set calendar millisecond 0 if interval multiplier 1 int x gc get interval gc set interval x interval multiplier interval multiplier current filename new file get hour log name gc true synchronized log files if log files is empty log files get last filename equals current filename log files remove last log stream open new log file current filename true if latest file null alt log stream open new log file latest file false system err println created log files start time gc get time in millis if logger should log logger minor this logger minor this start time gc start time last time start time gc add interval interval multiplier next hour gc get time in millis while true try this time system current time millis if base filename null if this time next hour switched base filename current filename rotate log current filename last time next hour gc gc add interval interval multiplier last time next hour next hour gc get time in millis if switched base filename synchronized file logger hook class switched base filename false if list size 0 if current filename null my write log stream null if alt log stream null my write alt log stream null synchronized list while list size 0 if closed return try list wait 500 catch interrupted exception e ignored o list remove first list bytes o length line overhead my write log stream o if alt log stream null my write alt log stream o catch out of memory error e system err println e get class system err println e get message e print stack trace fixme freenet node main dump interesting objects catch throwable t system err println file logger hook log writer caught t t print stack trace system err suppresswarnings currentfilename thistime lasttime starttime nexthour gregoriancalendar basefilename latestfile basefilename previousfile basefilename findoldlogfiles gregoriancalendar day_of_month week_of_year week_of_year day_of_week day_of_month interval_multiplier interval_multiplier interval_multiplier currentfilename gethourlogname logfiles logfiles isempty logfiles getlast currentfilename logfiles removelast logstream opennewlogfile currentfilename latestfile altlogstream opennewlogfile latestfile starttime gettimeinmillis shouldlog starttime lasttime starttime interval_multiplier nexthour gettimeinmillis thistime currenttimemillis basefilename thistime nexthour switchedbasefilename currentfilename rotatelog currentfilename lasttime nexthour interval_multiplier lasttime nexthour nexthour gettimeinmillis switchedbasefilename fileloggerhook switchedbasefilename currentfilename mywrite logstream altlogstream mywrite altlogstream interruptedexception removefirst listbytes line_overhead mywrite logstream altlogstream mywrite altlogstream outofmemoryerror getclass getmessage printstacktrace dumpinterestingobjects fileloggerhook printstacktrace private file rotate log file current filename long last time long next hour gregorian calendar gc switch logs try log stream flush if alt log stream null alt log stream flush catch io exception e system err println flushing on change caught e try log stream close catch io exception e system err println closing on change caught e long length current filename length old log file olf new old log file current filename last time next hour length synchronized log files log files add last olf old log files disk space usage length trim old log files rotate primary log stream current filename new file get hour log name gc true log stream open new log file current filename true if latest file null try alt log stream close catch io exception e system err println closing alt on change caught e if previous file null previous file exists file util rename to latest file previous file latest file delete alt log stream open new log file latest file false return current filename rotatelog currentfilename lasttime nexthour gregoriancalendar logstream altlogstream altlogstream ioexception logstream ioexception currentfilename oldlogfile oldlogfile currentfilename lasttime nexthour logfiles logfiles addlast oldlogfilesdiskspaceusage trimoldlogfiles currentfilename gethourlogname logstream opennewlogfile currentfilename latestfile altlogstream ioexception previousfile previousfile fileutil renameto latestfile previousfile latestfile altlogstream opennewlogfile latestfile currentfilename static final int max sleep time 60 1000 param b the bytes to write null to flush protected void my write output stream os byte b long sleep time 1000 while true boolean thrown false try if b null os write b else os flush catch io exception e system err println exception writing to log e sleeping sleep time thrown true if thrown try thread sleep sleep time catch interrupted exception e sleep time sleep time if sleep time max sleep time sleep time max sleep time else return maxsleeptime mywrite outputstream sleeptime ioexception sleeptime sleeptime interruptedexception sleeptime sleeptime sleeptime maxsleeptime sleeptime maxsleeptime protected output stream open new log file file filename boolean compress while true long sleep time 1000 try output stream o new file output stream filename log overwrite if compress buffer gzip buffer file o new buffered output stream o 32768 to file o new gzip output stream o gzip block size is 32kb o new buffered output stream o 65536 to gzipper else buffer file o new buffered output stream o 32768 return o catch io exception e system err println could not create fos filename e system err println sleeping sleep time 1000 seconds try thread sleep sleep time catch interrupted exception ex sleep time sleep time outputstream opennewlogfile sleeptime outputstream fileoutputstream logoverwrite bufferedoutputstream gzipoutputstream bufferedoutputstream bufferedoutputstream ioexception sleeptime sleeptime interruptedexception sleeptime sleeptime create a logger to append to the given file if the file does not exist it will be created param filename the name of the file to log to param fmt log message format string param dfmt date format string param threshold lowest logged priority param assume working if false check whether stderr and stdout are writable and if not redirect them to the log file exception io exception if the file couldn t be opened for append public file logger hook string filename string fmt string dfmt int threshold boolean assume working boolean log overwrite long max old logfiles disk usage throws io exception this false filename fmt dfmt threshold assume working log overwrite max old logfiles disk usage assumeworking ioexception fileloggerhook assumeworking logoverwrite maxoldlogfilesdiskusage ioexception assumeworking logoverwrite maxoldlogfilesdiskusage public void trim old log files synchronized trim old log files lock while old log files disk space usage max old logfiles disk usage old log file olf todo creates a double lock situation but only here i think this is okay because the inner lock is only used for trivial things synchronized log files if log files is empty system err println error inconsistent logger totals log file list is empty but still used old log files disk space usage bytes olf log files remove first olf filename delete old log files disk space usage olf size if logger should log logger minor this logger minor this deleting olf filename saving olf size bytes disk usage now old log files disk space usage of max old logfiles disk usage trimoldlogfiles trimoldlogfileslock oldlogfilesdiskspaceusage maxoldlogfilesdiskusage oldlogfile logfiles logfiles isempty oldlogfilesdiskspaceusage logfiles removefirst oldlogfilesdiskspaceusage shouldlog oldlogfilesdiskspaceusage maxoldlogfilesdiskusage initialize old log files public void find old log files gregorian calendar gc new gregorian calendar file current filename new file get hour log name gc true file numeric same date filename int slash index base filename last index of file separator char file dir string prefix if slash index 1 dir new file system get property user dir prefix base filename to lower case else dir new file base filename substring 0 slash index prefix base filename substring slash index 1 to lower case file files dir list files if files null return java util arrays sort files long last start time 1 file old file null if latest file exists file util rename to latest file previous file boolean logminor logger should log logger minor this for int i 0 i files length i file f files i string name f get name if name to lower case starts with prefix if name equals previous file get name name equals latest file get name continue if name ends with log gz if logminor logger minor this does not end in log gz name f delete continue else name name substring 0 name length log gz length name name substring prefix length if name length 0 name char at 0 if logminor logger minor this deleting unrecognized name f get path f delete continue else name name substring 1 string tokens name split int nums new int tokens length for int j 0 j tokens length j try nums j integer parse int tokens j catch number format exception e logger normal this could not parse tokens j into number from name broken f delete continue first field version if nums 0 version build number if logminor logger minor this deleting old log from build nums 0 current version build number logs that old are useless f delete continue if nums length 1 gc set calendar year nums 1 if nums length 2 gc set calendar month nums 2 1 if nums length 3 gc set calendar day of month nums 3 if nums length 4 gc set calendar hour of day nums 4 if nums length 5 gc set calendar minute nums 5 gc set calendar second 0 gc set calendar millisecond 0 long start time gc get time in millis if old file null long l old file length old log file olf new old log file old file last start time start time l synchronized log files log files add last olf synchronized trim old log files lock old log files disk space usage l last start time start time old file f else nothing to do with us logger normal this unknown file name in the log directory if a compressed log file already exists for a given date add a number to the end of the file that already exists for int a 1 current filename null current filename exists a numeric same date filename new file get hour log name gc a true if numeric same date filename null numeric same date filename exists current filename numeric same date filename else file util rename to current filename numeric same date filename current filename numeric same date filename break if old file null long l old file length old log file olf new old log file old file last start time system current time millis l synchronized log files log files add last olf synchronized trim old log files lock old log files disk space usage l trim old log files oldlogfiles findoldlogfiles gregoriancalendar gregoriancalendar currentfilename gethourlogname numericsamedatefilename slashindex basefilename lastindexof separatorchar slashindex getproperty basefilename tolowercase basefilename slashindex basefilename slashindex tolowercase listfiles laststarttime oldfile latestfile fileutil renameto latestfile previousfile shouldlog getname tolowercase startswith previousfile getname latestfile getname endswith charat getpath parseint numberformatexception buildnumber buildnumber day_of_month hour_of_day starttime gettimeinmillis oldfile oldfile oldlogfile oldlogfile oldfile laststarttime starttime logfiles logfiles addlast trimoldlogfileslock oldlogfilesdiskspaceusage laststarttime starttime oldfile currentfilename currentfilename numericsamedatefilename gethourlogname numericsamedatefilename numericsamedatefilename currentfilename numericsamedatefilename fileutil renameto currentfilename numericsamedatefilename currentfilename numericsamedatefilename oldfile oldfile oldlogfile oldlogfile oldfile laststarttime currenttimemillis logfiles logfiles addlast trimoldlogfileslock oldlogfilesdiskspaceusage trimoldlogfiles public file logger hook string filename string fmt string dfmt string threshold boolean assume working boolean log overwrite long max old log files disk usage throws io exception invalid threshold exception this filename fmt dfmt priority of threshold assume working log overwrite max old log files disk usage fileloggerhook assumeworking logoverwrite maxoldlogfilesdiskusage ioexception invalidthresholdexception priorityof assumeworking logoverwrite maxoldlogfilesdiskusage private void check std streams redirect system err and system out to the logger printstream if they don t exist like when running under javaw system out print b if system out check error redirect std out true system err print b if system err check error redirect std err true checkstdstreams checkerror redirectstdout checkerror redirectstderr public file logger hook output stream os string fmt string dfmt int threshold this new print stream os fmt dfmt threshold true log stream os fileloggerhook outputstream printstream logstream public file logger hook output stream os string fmt string dfmt string threshold throws invalid threshold exception this new print stream os fmt dfmt priority of threshold true log stream os fileloggerhook outputstream invalidthresholdexception printstream priorityof logstream create a logger to send log output to the given print stream param stream the print stream to send log output to param fmt log message format string param dfmt date format string param threshold lowest logged priority public file logger hook print stream stream string fmt string dfmt int threshold boolean overwrite this fmt dfmt threshold overwrite 1 log stream stream printstream printstream fileloggerhook printstream logstream public void start if redirect std out system set out new print stream new output stream logger logger normal stdout if redirect std err system set err new print stream new output stream logger logger error stderr writer thread wt new writer thread wt set daemon true closer thread ct new closer thread runtime get runtime add shutdown hook ct wt start redirectstdout setout printstream outputstreamlogger redirectstderr seterr printstream outputstreamlogger writerthread writerthread setdaemon closerthread closerthread getruntime addshutdownhook public file logger hook boolean rotate string base filename string fmt string dfmt int threshold boolean assume working boolean log overwrite long max old logfiles disk usage throws io exception this fmt dfmt threshold log overwrite max old logfiles disk usage system err println creating file logger hook with threshold threshold if assume working check std streams if rotate this base filename base filename else log stream new buffered output stream new file output stream base filename log overwrite 65536 fileloggerhook basefilename assumeworking logoverwrite maxoldlogfilesdiskusage ioexception logoverwrite maxoldlogfilesdiskusage fileloggerhook assumeworking checkstdstreams basefilename basefilename logstream bufferedoutputstream fileoutputstream basefilename logoverwrite public file logger hook boolean rotate string base filename string fmt string dfmt string threshold boolean assume working boolean log overwrite long max old log files disk usage throws io exception invalid threshold exception this rotate base filename fmt dfmt priority of threshold assume working log overwrite max old log files disk usage fileloggerhook basefilename assumeworking logoverwrite maxoldlogfilesdiskusage ioexception invalidthresholdexception basefilename priorityof assumeworking logoverwrite maxoldlogfilesdiskusage private file logger hook string fmt string dfmt int threshold boolean overwrite long max old logfiles disk usage super threshold this max old logfiles disk usage max old logfiles disk usage this log overwrite overwrite set date format dfmt set log format fmt fileloggerhook maxoldlogfilesdiskusage maxoldlogfilesdiskusage maxoldlogfilesdiskusage logoverwrite setdateformat setlogformat private void set log format string fmt if fmt null fmt length 0 fmt d c h t p m char f fmt to char array array list integer fmt vec new array list integer array list string str vec new array list string string builder sb new string builder boolean comment false for int i 0 i f length i int type number of f i if type uname getu name if comment type 0 if sb length 0 str vec add sb to string fmt vec add 0 sb new string builder fmt vec add type else if f i comment true else comment false sb append f i if sb length 0 str vec add sb to string fmt vec add 0 this fmt new int fmt vec size int size fmt vec size for int i 0 i size i this fmt i fmt vec get i this str new string str vec size str str vec to array str setlogformat tochararray arraylist fmtvec arraylist arraylist strvec arraylist stringbuilder stringbuilder numberof getuname strvec tostring fmtvec stringbuilder fmtvec strvec tostring fmtvec fmtvec fmtvec fmtvec strvec strvec toarray private void set date format string dfmt if dfmt null dfmt length 0 try df new simple date format dfmt catch runtime exception e df date format get date time instance else df date format get date time instance df set time zone time zone get time zone utc setdateformat simpledateformat runtimeexception dateformat getdatetimeinstance dateformat getdatetimeinstance settimezone timezone gettimezone override public void log object o class c string msg throwable e int priority if instance should log priority c return if closed return string builder sb new string builder e null 512 1024 int sctr 0 for int i 0 i fmt length i switch fmt i case 0 sb append str sctr break case date long now system current time millis synchronized this my date set time now sb append df format my date break case class sb append c null none c get name break case hashcode sb append o null none integer to hex string o hash code break case thread sb append thread current thread get name break case priority sb append logger hook priority of priority break case message sb append msg break case uname sb append uname break sb append n write stacktrace if available for int j 0 j 20 e null j sb append e to string stack trace element trace e get stack trace if trace null sb append null n else if trace length 0 sb append no stack trace n else sb append n for int i 0 i trace length i sb append tat sb append trace i to string sb append n throwable cause e get cause if cause e e cause else break log string sb to string get bytes instanceshouldlog stringbuilder stringbuilder currenttimemillis mydate settime mydate getname tohexstring hashcode currentthread getname loggerhook priorityof tostring stacktraceelement getstacktrace tostring getcause logstring tostring getbytes public void log string byte b int no element count 0 synchronized list int sz list size list add b list bytes b length line overhead total guess int x 0 if list size max list size list bytes max list bytes while list size max list size 0 9f list bytes max list bytes 0 9f byte ss try ss list remove first catch no such element exception e yes i know this is impossible but it happens with 1 6 with heap profiling enabled this is a bug in sun netbeans profiler around 2006 era no element count if no element count 1000 system err println lost log line because of constant no such element exception s e print stack trace return continue list bytes ss length line overhead x string err grrr error logging too fast chopped x entries list bytes bytes in memory n byte buf err get bytes list add 0 buf list bytes buf length line overhead if sz 0 list notify all logstring noelementcount listbytes line_overhead max_list_size listbytes max_list_bytes max_list_size listbytes max_list_bytes removefirst nosuchelementexception noelementcount noelementcount nosuchelementexception printstacktrace listbytes line_overhead listbytes getbytes listbytes line_overhead notifyall public long list bytes synchronized list return list bytes listbytes listbytes public static int number of char c switch c case d return date case c return class case h return hashcode case t return thread case p return priority case m return message case u return uname default return 0 numberof override public long min flags return 0 minflags override public long not flags return internal notflags override public long any flags return 2 error 1 threshold 1 anyflags public void close closed true class closer thread extends thread override public void run closed true closerthread print a human and script readable list of available log files throws io exception public void list available logs output stream writer writer throws io exception old log file old log files synchronized log files old log files log files to array new old log file log files size date format tempdf date format get date time instance date format short date format short locale english tempdf set time zone time zone get time zone gmt for int i 0 i old log files length i old log file olf old log files i writer write olf filename get name tempdf format new date olf start to tempdf format new date olf end olf size bytes n ioexception listavailablelogs outputstreamwriter ioexception oldlogfile oldlogfiles logfiles oldlogfiles logfiles toarray oldlogfile logfiles dateformat dateformat getdatetimeinstance dateformat dateformat settimezone timezone gettimezone oldlogfiles oldlogfile oldlogfiles getname public void send log by contained date long time output stream os throws io exception old log file to return null synchronized log files iterator old log file i log files iterator while i has next old log file olf i next boolean logminor logger should log logger minor this if logminor logger minor this checking time against olf filename start olf start end olf end if time olf start time olf end to return olf if logminor logger minor this found olf break if to return null return couldn t find it file input stream fis new file input stream to return filename data input stream dis new data input stream fis long written 0 long size to return size byte buf new byte 4096 while written size int to read int math min buf length size written try dis read fully buf 0 to read catch io exception e logger error this could not read bytes written to written to read from file to return filename which is supposed to be size bytes to return filename length return os write buf 0 to read written to read dis close fis close sendlogbycontaineddate outputstream ioexception oldlogfile toreturn logfiles oldlogfile logfiles hasnext oldlogfile shouldlog toreturn toreturn fileinputstream fileinputstream toreturn datainputstream datainputstream toreturn toread readfully toread ioexception toread toreturn toreturn toread toread set the maximum size of old gzipped log files to keep will start to prune old files immediately but this will likely not be completed by the time the function returns as it is run off thread public void set max old logs size long val synchronized trim old log files lock max old logfiles disk usage val runnable r new runnable public void run trim old log files thread t new thread r shrink logs t set daemon true t start setmaxoldlogssize trimoldlogfileslock maxoldlogfilesdiskusage trimoldlogfiles setdaemon runnable r new runnable public void run trim old log files trimoldlogfiles public void switch base filename string filename synchronized this this base filename filename switched base filename true switchbasefilename basefilename switchedbasefilename public void wait for switch long now system current time millis synchronized this if switched base filename return long start time now long end time start time 10000 while now system current time millis end time switched base filename try wait math max 1 end time now catch interrupted exception e ignore waitforswitch currenttimemillis switchedbasefilename starttime endtime starttime currenttimemillis endtime switchedbasefilename endtime interruptedexception public void delete all old log files synchronized trim old log files lock while true old log file olf synchronized log files if log files is empty return olf log files remove first olf filename delete old log files disk space usage olf size if logger should log logger minor this logger minor this deleting olf filename saving olf size bytes disk usage now old log files disk space usage of max old logfiles disk usage deletealloldlogfiles trimoldlogfileslock oldlogfile logfiles logfiles isempty logfiles removefirst oldlogfilesdiskspaceusage shouldlog oldlogfilesdiskspaceusage maxoldlogfilesdiskusage this is used by the lost lock deadlock detector so must not take a lock ever public boolean has redirected std out err no lock return redirect std out redirect std err hasredirectedstdouterrnolock redirectstdout redirectstderr creates a new address matcher that matches inet address objects to the address specification given by code cidr hostname code param cidr hostname the address range this matcher matches public inet4 address matcher string cidr hostname int slash position cidr hostname index of if slash position 1 address convert to bytes cidr hostname network mask 0xffffffff else address convert to bytes cidr hostname substring 0 slash position string mask part cidr hostname substring slash position 1 if mask part index of 1 network mask 0xffffffff 32 integer parse int mask part if integer parse int mask part 0 network mask 0 else network mask convert to bytes mask part inetaddress cidrhostname cidrhostname inet4addressmatcher cidrhostname slashposition cidrhostname indexof slashposition converttobytes cidrhostname networkmask converttobytes cidrhostname slashposition maskpart cidrhostname slashposition maskpart indexof networkmask parseint maskpart parseint maskpart networkmask networkmask converttobytes maskpart converts a dotted ip address a b c d to a 32 bit value the first octet will be in bits 24 to 31 the second in bits 16 to 23 the third in bits 8 to 15 and the fourth in bits 0 to 7 param address the address to convert return the ip address as 32 bit value throws number format exception if a part of the string can not be parsed using link integer parse int java lang string throws java util no such element exception if code address code contains less than 3 dots public static int convert to bytes string address string tokenizer address tokens new string tokenizer address int bytes integer parse int address tokens next token 24 integer parse int address tokens next token 16 integer parse int address tokens next token 8 integer parse int address tokens next token return bytes numberformatexception parseint nosuchelementexception converttobytes stringtokenizer addresstokens stringtokenizer parseint addresstokens nexttoken parseint addresstokens nexttoken parseint addresstokens nexttoken parseint addresstokens nexttoken checks whether the given address matches this matcher s address param inet address the address to match to this matcher return code true code if code inet address code matches the specification of this matcher code false code otherwise public boolean matches inet address inet address if inet address instanceof inet4 address return false int match address convert to bytes inet address get host address return match address network mask address network mask inetaddress inetaddress inetaddress inetaddress inetaddress inet4address matchaddress converttobytes inetaddress gethostaddress matchaddress networkmask networkmask shortcut method for creating a new inet4 address matcher and matching code address code to it param cidr hostname the host specification to match param address the address to match return code true code if code address code matches the specification in code cidr hostname code code false code otherwise see inet4 address matcher string see matches inet address public static boolean matches string cidr hostname inet address address return new inet4 address matcher cidr hostname matches address inet4addressmatcher cidrhostname cidrhostname inet4addressmatcher inetaddress cidrhostname inetaddress inet4addressmatcher cidrhostname public string get human representation if network mask 1 return convert to string address else return convert to string address convert to string network mask gethumanrepresentation networkmask converttostring converttostring converttostring networkmask private string convert to string int addr string builder sb new string builder for int i 0 i 4 i int x addr 24 addr addr 8 if i 0 sb append sb append x return sb to string converttostring stringbuilder stringbuilder tostring public testnet status uploader node node2 int update interval this node node2 this update interval update interval logger error this starting testnet statusuploader logger error this anonymity mode off system err println starting testnet statusuploader system err println anonymity mode off system err println you have no anonymity thank you for running a testnet node this will help the developers to efficiently debug freenet by letting them and anyone else who knows how automatically fetch your log files system err println we repeat you have no anonymity whatsoever do not post anything you do not want to be associated with system err println if you want a real freenet node with anonymity turn off testnet mode testnetstatusuploader updateinterval updateinterval updateinterval void start node executor execute this testnet status uploader thread testnetstatusuploader public void run freenet support logger os thread logpid this thread loop while true set up client socket try client new socket emu freenetproject org 23415 print stream output new print stream client get output stream output println node export darknet public field set to string output println output println node get freeviz output output close client close catch io exception e logger error this could not open connection to the uploadhost system err println could not open connection to the uploadhost try thread sleep update interval how i love java catch interrupted exception e return osthread printstream printstream getoutputstream exportdarknetpublicfieldset tostring getfreevizoutput ioexception updateinterval interruptedexception public bucket compress bucket data bucket factory bf long max read length long max write length throws io exception compression output size exception if max read length 0 throw new illegal argument exception bucket output bf make bucket max write length input stream is null output stream os null cb zip2 output stream bz2os null try is data get input stream os output get output stream counted output stream cos new counted output stream os bz2os new cb zip2 output stream new buffered output stream cos long read 0 bigger input buffer so can compress all at once won t hurt on i o either although most o ss will only return a page at a time byte buffer new byte 32768 while true int l int math min buffer length max read length read int x l 0 1 is read buffer 0 buffer length if x 1 break if x 0 throw new io exception returned zero from read bz2os write buffer 0 x read x if cos written max write length throw new compression output size exception bz2os flush bz2os close os null finally if is null is close if os null os close return output bucketfactory maxreadlength maxwritelength ioexception compressionoutputsizeexception maxreadlength illegalargumentexception makebucket maxwritelength inputstream outputstream cbzip2outputstream getinputstream getoutputstream countedoutputstream countedoutputstream cbzip2outputstream bufferedoutputstream oss maxreadlength ioexception maxwritelength compressionoutputsizeexception public bucket decompress bucket data bucket factory bf long max length long max check size length bucket preferred throws io exception compression output size exception bucket output if preferred null output preferred else output bf make bucket max length input stream is data get input stream output stream os output get output stream decompress is os max length max check size length os close is close return output bucketfactory maxlength maxchecksizelength ioexception compressionoutputsizeexception makebucket maxlength inputstream getinputstream outputstream getoutputstream maxlength maxchecksizelength private long decompress input stream is output stream os long max length long max check size bytes throws io exception compression output size exception cb zip2 input stream bz2is new cb zip2 input stream is long written 0 byte buffer new byte 4096 while true int l int math min buffer length max length written we can over read to determine whether we have over read we enforce maximum size this way fixme there is probably a better way to do this int x bz2is read buffer 0 buffer length if l x logger normal this l l x x written written max length max length throwing a compression output size exception if max check size bytes 0 written x while true l int math min buffer length max length max check size bytes written x bz2is read buffer 0 l if x 1 throw new compression output size exception written if x 0 throw new io exception returned zero from read written x throw new compression output size exception if x 1 return written if x 0 throw new io exception returned zero from read os write buffer 0 x written x inputstream outputstream maxlength maxchecksizebytes ioexception compressionoutputsizeexception cbzip2inputstream cbzip2inputstream maxlength maxlength maxlength compressionoutputsizeexception maxchecksizebytes maxlength maxchecksizebytes compressionoutputsizeexception ioexception compressionoutputsizeexception ioexception public int decompress byte dbuf int i int j byte output throws compression output size exception didn t work with inflater fixme fix sometimes to use inflater format issue byte array input stream bais new byte array input stream dbuf i j byte array output stream baos new byte array output stream output length int bytes 0 try bytes int decompress bais baos output length 1 catch io exception e impossible throw new error got io exception e get message e byte buf baos to byte array system arraycopy buf 0 output 0 bytes return bytes compressionoutputsizeexception bytearrayinputstream bytearrayinputstream bytearrayoutputstream bytearrayoutputstream ioexception ioexception getmessage tobytearray protected int rule private misc composite int rule this rule 1 0f misccomposite private misc composite int rule float alpha if alpha 0 0f alpha 1 0f throw new illegal argument exception alpha value out of range if rule min rule rule max rule throw new illegal argument exception unknown composite rule this rule rule this extra alpha alpha misccomposite illegalargumentexception min_rule max_rule illegalargumentexception extraalpha public static composite get instance int rule float alpha switch rule case misc composite blend return alpha composite get instance alpha composite src over alpha case misc composite add return new add composite alpha case misc composite subtract return new subtract composite alpha case misc composite difference return new difference composite alpha case misc composite multiply return new multiply composite alpha case misc composite darken return new darken composite alpha case misc composite burn return new burn composite alpha case misc composite color burn return new color burn composite alpha case misc composite screen return new screen composite alpha case misc composite lighten return new lighten composite alpha case misc composite dodge return new dodge composite alpha case misc composite color dodge return new color dodge composite alpha case misc composite hue return new hue composite alpha case misc composite saturation return new saturation composite alpha case misc composite value return new value composite alpha case misc composite color return new color composite alpha case misc composite overlay return new overlay composite alpha case misc composite soft light return new soft light composite alpha case misc composite hard light return new hard light composite alpha case misc composite pin light return new pin light composite alpha case misc composite exclusion return new exclusion composite alpha case misc composite negation return new negation composite alpha case misc composite average return new average composite alpha case misc composite stencil return alpha composite get instance alpha composite dst in alpha case misc composite silhouette return alpha composite get instance alpha composite dst out alpha return new misc composite rule alpha getinstance misccomposite alphacomposite getinstance alphacomposite src_over misccomposite addcomposite misccomposite subtractcomposite misccomposite differencecomposite misccomposite multiplycomposite misccomposite darkencomposite misccomposite burncomposite misccomposite color_burn colorburncomposite misccomposite screencomposite misccomposite lightencomposite misccomposite dodgecomposite misccomposite color_dodge colordodgecomposite misccomposite huecomposite misccomposite saturationcomposite misccomposite valuecomposite misccomposite colorcomposite misccomposite overlaycomposite misccomposite soft_light softlightcomposite misccomposite hard_light hardlightcomposite misccomposite pin_light pinlightcomposite misccomposite exclusioncomposite misccomposite negationcomposite misccomposite averagecomposite misccomposite alphacomposite getinstance alphacomposite dst_in misccomposite alphacomposite getinstance alphacomposite dst_out misccomposite public composite context create context color model src color model color model dst color model rendering hints hints return new misc composite context rule extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints misccompositecontext extraalpha srccolormodel dstcolormodel public float get alpha return extra alpha getalpha extraalpha public int get rule return rule getrule override public int hash code return float float to int bits extra alpha 31 rule hashcode floattointbits extraalpha override public boolean equals object o if o instanceof misc composite return false misc composite c misc composite o if rule c rule return false if extra alpha c extra alpha return false return true misccomposite misccomposite misccomposite extraalpha extraalpha logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog final string name final runnable job job string name runnable job this name name this job job packet sender node node timed jobs by time new tree map long object this node node my thread new native thread this packet sender thread for node get darknet port number native thread max priority false my thread set daemon true rpi temp new vector resend packet item rpi int temp new int 64 packetsender timedjobsbytime treemap mythread nativethread packetsender getdarknetportnumber nativethread max_priority mythread setdaemon rpitemp resendpacketitem rpiinttemp void start node stats stats this stats stats logger normal this starting packet sender system out println starting packet sender long now system current time millis long transition version transition time if now transition queue timed job new runnable public void run freenet support logger os thread logpid this peer node nodes node peers my peers for int i 0 i nodes length i peer node pn nodes i pn update version routablity transition now my thread start nodestats packetsender packetsender currenttimemillis transitiontime queuetimedjob osthread peernode mypeers peernode updateversionroutablity mythread public void run freenet support logger os thread logpid this peer node nodes node peers my peers for int i 0 i nodes length i peer node pn nodes i pn update version routablity osthread peernode mypeers peernode updateversionroutablity public void run if logminor logger minor this in packet sender run freenet support logger os thread logpid this index of the point in the nodes list at which we sent a packet and then ran out of bandwidth we start the loop from here next time int broke at 0 while true last received packet from any node last reported no packets try broke at real run broke at catch out of memory error e oom handler handleoom e system err println will retry above failed operation catch throwable t logger error this caught in packet sender t t system err println caught in packet sender t t print stack trace packetsender osthread brokeat lastreceivedpacketfromanynode lastreportednopackets brokeat realrun brokeat outofmemoryerror oomhandler packetsender packetsender printstacktrace private int real run int broke at long now system current time millis peer manager pm node peers peer node nodes pm my peers run the time sensitive status updater separately for int i 0 i nodes length i peer node pn nodes i only routing backed off nodes should need status updating since everything else should get updated immediately when it s changed if pn get peer node status peer manager peer node status routing backed off pn set peer node status now pm maybe log peer node status summary now pm maybe update oldest never connected peer age now stats maybe update peer manager user alert stats now stats maybe update nodeio stats now pm maybe update peer node routable connection stats now long next action time long max value long old temp now now needs to be run very frequently maybe change to a regular once per second schedule job maybe not worth it as it is fairly lightweight fixme given the lock contention maybe it s worth it what about running it on the udp socket handler thread that would surely be better node lm remove too old queued items boolean can send throttled false int max packet size node darknet crypto socket get max packet size long count node output throttle get count if count max packet size can send throttled true else long can send at node output throttle get nanos per tick max packet size count can send at can send at 1000 1000 can send at 1000 1000 0 0 1 if logminor logger minor this can send throttled packets in can send at ms next action time math min next action time now can send at int new broke at broke at for int i 0 i nodes length i int idx i broke at 1 nodes length peer node pn nodes idx last received packet from any node math max pn last received packet time last received packet from any node pn maybe on connect if pn should disconnect and remove now pn is disconnecting might as well do it properly node peers disconnect pn true true false if pn is connected if pn should throttle can send throttled continue is the node dead if now pn last received packet time pn max time between received packets logger normal this disconnecting from pn haven t received packets recently pn disconnected false false hopefully will recover transient network glitch continue else if pn is routable pn no longer routable note whereas is routable no longer routable are generally mutually exclusive this code will only execute because of the scheduled runnable in start which executes update version routablity on all our peers we don t disconnect the peer but mark it as being incompatible pn invalidate pn set peer node status now logger normal this should disconnect now has returned true marking the peer as incompatible pn continue try if can send throttled pn should throttle pn maybe send packet now rpi temp rpi int temp can send throttled false count node output throttle get count if count max packet size can send throttled true else long can send at node output throttle get nanos per tick max packet size count can send at can send at 1000 1000 can send at 1000 1000 0 0 1 if logminor logger minor this can send throttled packets in can send at ms next action time math min next action time now can send at new broke at idx catch blocked too long exception e logger error this waited too long time util format time e delta to allocate a packet number to send to this on e tracker disconnecting pn force disconnect true on force disconnect block too long pn e long urgent time pn get next urgent time now should spam the logs unless there is a deadlock if urgent time long max value logminor logger minor this next urgent time urgent time in urgent time now for pn get peer next action time math min next action time urgent time else not connected if pn no contact details pn startark fetcher if pn should send handshake send handshake if necessary long before handshake time system current time millis pn get outgoing mangler send handshake pn false long after handshake time system current time millis if after handshake time before handshake time 2 1000 logger error this after handshake time is more than 2 seconds past before handshake time after handshake time before handshake time in packet sender working with pn user to string long temp now system current time millis if temp now old temp now 5 1000 logger error this temp now is more than 5 seconds past old temp now temp now old temp now in packet sender working with pn user to string old temp now temp now broke at new broke at attempt to connect to old opennet peers constantly send handshake packets in order to get through a nat most jfk 1 s are less than 300 bytes 25 300 15 avg 500b sec bandwidth cost well worth it to allow us to reconnect more quickly opennet manager om node get opennet if om null node get uptime 30 1000 peer node peers om get old peers for peer node pn peers if pn time last connected 0 logger error this last connected is zero or negative for old opennet peer pn will be removed by next line if now pn time last connected opennet manager max time on old opennet peers om purge old opennet peer pn if logminor logger minor this removing old opennet peer too old pn continue if pn is connected continue race condition if pn no contact details pn startark fetcher continue if pn should send handshake send handshake if necessary long before handshake time system current time millis pn get outgoing mangler send handshake pn true long after handshake time system current time millis if after handshake time before handshake time 2 1000 logger error this after handshake time is more than 2 seconds past before handshake time after handshake time before handshake time in packet sender working with pn user to string if now last cleared old swap chains 10000 node lm clear old swap chains last cleared old swap chains now long old now now send may have taken some time now system current time millis if now old now 10 1000 logger error this now is more than 10 seconds past old now now old now in packet sender list job jobs to run null synchronized timed jobs by time while timed jobs by time is empty long t run timed jobs by time first key if t run long value now if jobs to run null jobs to run new array list job object o timed jobs by time remove t run if o instanceof job job r job o for int i 0 i r length i jobs to run add r i else job r job o jobs to run add r else fixme how accurately do we want ticker jobs to be scheduled fixme can they wait the odd 200ms break if jobs to run null for job r jobs to run if logminor logger minor this running r if r job instanceof fast runnable run in line try r job run catch throwable t logger error this caught t running r t else try node executor execute r job r name true catch out of memory error e oom handler handleoom e system err println will retry above failed operation queue timed job r job r name 200 true catch throwable t logger error this caught in packet sender t t system err println caught in packet sender t t print stack trace long sleep time next action time now max coalescing delayms maximum sleep time same as the maximum coalescing delay sleep time math min sleep time max coalescing delay if now node startup time 60 1000 5 if now last received packet from any node node alarm time logger error this have not received any packets from any node in last node alarm time 1000 seconds last reported no packets now if sleep time 0 update logging only when have time to do so try if logminor logger minor this sleeping for sleep time synchronized this wait sleep time catch interrupted exception e ignore just wake up probably we got interrupt ed because a new packet came in return broke at realrun brokeat currenttimemillis peermanager peernode mypeers peernode getpeernodestatus peermanager peer_node_status_routing_backed_off setpeernodestatus maybelogpeernodestatussummary maybeupdateoldestneverconnectedpeerage maybeupdatepeermanageruseralertstats maybeupdatenodeiostats maybeupdatepeernoderoutableconnectionstats nextactiontime max_value oldtempnow udpsockethandler removetoooldqueueditems cansendthrottled max_packet_size darknetcrypto getmaxpacketsize outputthrottle getcount max_packet_size cansendthrottled cansendat outputthrottle getnanospertick max_packet_size cansendat cansendat cansendat cansendat nextactiontime nextactiontime cansendat newbrokeat brokeat brokeat peernode lastreceivedpacketfromanynode lastreceivedpackettime lastreceivedpacketfromanynode maybeonconnect shoulddisconnectandremovenow isdisconnecting isconnected shouldthrottle cansendthrottled lastreceivedpackettime maxtimebetweenreceivedpackets isroutable nolongerroutable isroutable nolongerroutable updateversionroutablity setpeernodestatus shoulddisconnectnow cansendthrottled shouldthrottle maybesendpacket rpitemp rpiinttemp cansendthrottled outputthrottle getcount max_packet_size cansendthrottled cansendat outputthrottle getnanospertick max_packet_size cansendat cansendat cansendat cansendat nextactiontime nextactiontime cansendat newbrokeat blockedtoolongexception timeutil formattime forcedisconnect onforcedisconnectblocktoolong urgenttime getnexturgenttime urgenttime max_value urgenttime urgenttime getpeer nextactiontime nextactiontime urgenttime nocontactdetails startarkfetcher shouldsendhandshake beforehandshaketime currenttimemillis getoutgoingmangler sendhandshake afterhandshaketime currenttimemillis afterhandshaketime beforehandshaketime afterhandshaketime beforehandshaketime afterhandshaketime beforehandshaketime packetsender usertostring tempnow currenttimemillis tempnow oldtempnow tempnow oldtempnow tempnow oldtempnow packetsender usertostring oldtempnow tempnow brokeat newbrokeat opennetmanager getopennet getuptime peernode getoldpeers peernode timelastconnected timelastconnected opennetmanager max_time_on_old_opennet_peers purgeoldopennetpeer isconnected nocontactdetails startarkfetcher shouldsendhandshake beforehandshaketime currenttimemillis getoutgoingmangler sendhandshake afterhandshaketime currenttimemillis afterhandshaketime beforehandshaketime afterhandshaketime beforehandshaketime afterhandshaketime beforehandshaketime packetsender usertostring lastclearedoldswapchains clearoldswapchains lastclearedoldswapchains oldnow currenttimemillis oldnow oldnow oldnow packetsender jobstorun timedjobsbytime timedjobsbytime isempty trun timedjobsbytime firstkey trun longvalue jobstorun jobstorun arraylist timedjobsbytime trun jobstorun jobstorun jobstorun jobstorun fastrunnable outofmemoryerror oomhandler queuetimedjob packetsender packetsender printstacktrace sleeptime nextactiontime max_coalescing_delayms sleeptime sleeptime max_coalescing_delay startuptime lastreceivedpacketfromanynode alarm_time alarm_time lastreportednopackets sleeptime sleeptime sleeptime interruptedexception brokeat private void on force disconnect block too long peer node pn blocked too long exception e peer p pn get peer synchronized peers dumped blocked too long peers dumped blocked too long add p if peers dumped blocked too long size 1 return if node client core null node client core alerts null return node client core alerts register peers dumped blocked too long alert onforcedisconnectblocktoolong peernode blockedtoolongexception getpeer peersdumpedblockedtoolong peersdumpedblockedtoolong peersdumpedblockedtoolong clientcore clientcore clientcore peersdumpedblockedtoolongalert private user alert peers dumped blocked too long alert new user alert public string anchor return disconnected still not acked useralert peersdumpedblockedtoolongalert useralert disconnectedstillnotacked public string dismiss button text return null dismissbuttontext public short get priority class return user alert error getpriorityclass useralert public string get short text int sz synchronized peers dumped blocked too long sz peers dumped blocked too long size return l10n some peers disconnected blocked too long count integer to string sz getshorttext peersdumpedblockedtoolong peersdumpedblockedtoolong somepeersdisconnectedblockedtoolong tostring public html node gethtml text html node div new html node div peer peers synchronized peers dumped blocked too long peers peers dumped blocked too long to array new peer peers dumped blocked too long size l10n addl10n substitution div packet sender some peers disconnected blocked too long detail new string count link link new string integer to string peers length a href checked http https bugs freenetproject org a html node list div add child ul for peer peer peers list add child li peer to string return div htmlnode gethtmltext htmlnode htmlnode peersdumpedblockedtoolong peersdumpedblockedtoolong toarray peersdumpedblockedtoolong addl10nsubstitution packetsender somepeersdisconnectedblockedtoolongdetail tostring _checked_http_ htmlnode addchild addchild tostring public string get text string buffer sb new string buffer peer peers synchronized peers dumped blocked too long peers peers dumped blocked too long to array new peer peers dumped blocked too long size sb append l10n some peers disconnected still not acked detail new string count link link new string integer to string peers length sb append n for peer peer peers sb append t sb append peer to string sb append n return sb to string gettext stringbuffer stringbuffer peersdumpedblockedtoolong peersdumpedblockedtoolong toarray peersdumpedblockedtoolong somepeersdisconnectedstillnotackeddetail tostring tostring tostring public string get title return get short text gettitle getshorttext public object get user identifier return packet sender this getuseridentifier packetsender public boolean is event notification return false iseventnotification public boolean is valid return true isvalid public void is valid boolean validity ignore isvalid public void on dismiss ignore ondismiss public boolean should unregister on dismiss return false shouldunregisterondismiss public boolean user can dismiss return false usercandismiss wake up and send any queued packets void wake up wake up if needed synchronized this notify all wakeup notifyall protected string l10n string key string patterns string values return l10n get string packet sender key patterns values getstring packetsender protected string l10n string key string pattern string value return l10n get string packet sender key pattern value getstring packetsender public void queue timed job runnable job long offset queue timed job job scheduled job job offset false queuetimedjob queuetimedjob public void queue timed job runnable runner string name long offset boolean run on ticker anyway run directly if that won t cause any priority problems if offset 0 run on ticker anyway if logminor logger minor this running directly runner node executor execute runner name return job job new job name runner if offset 0 offset 0 long now system current time millis long l long value of offset now synchronized timed jobs by time object o timed jobs by time get l if o null timed jobs by time put l job else if o instanceof job timed jobs by time put l new job job o job else if o instanceof job job r job o job jobs new job r length 1 system arraycopy r 0 jobs 0 r length jobs jobs length 1 job timed jobs by time put l jobs if offset max coalescing delay wake up queuetimedjob runontickeranyway runontickeranyway currenttimemillis valueof timedjobsbytime timedjobsbytime timedjobsbytime timedjobsbytime timedjobsbytime max_coalescing_delay wakeup round up a value to the next multiple of a power of 2 private static final long roundup 2n long val int blocksize int mask blocksize 1 return val mask mask roundup_2n guesstimate real disk usage for a file with a given filename of a given length public static long estimate usage file file long flen it s possible that none of these assumptions are accurate for any filesystem this is intended to be a plausible worst case assume 4kb clusters for calculating block usage ntfs long block usage roundup 2n flen 4096 assume 512 byte filename entries with 100 bytes overhead for filename overhead ntfs string filename file get name int name length filename get bytes length 100 long filename usage roundup 2n name length 512 assume 50 bytes per block tree overhead with 1kb blocks reiser3 worst case long extra roundup 2n flen 1024 1024 50 return block usage filename usage extra estimateusage blockusage roundup_2n getname namelength getbytes filenameusage roundup_2n namelength roundup_2n blockusage filenameusage is poss parent a parent of filename why doesn t java provide this public static boolean is parent file poss file filename file canon file util get canonical file poss file canon file file util get canonical file filename if is parent inner poss filename return true if is parent inner poss canon file return true if is parent inner canon filename return true if is parent inner canon canon file return true return false possparent isparent fileutil getcanonicalfile canonfile fileutil getcanonicalfile isparentinner isparentinner canonfile isparentinner isparentinner canonfile private static boolean is parent inner file poss parent file filename while true if filename equals poss parent return true filename filename get parent file if filename null return false isparentinner possparent possparent getparentfile public static file get canonical file file file having some problems storing file s in db4o it would start up and canonicalise a file with path var lib freenet experimental persistent temp 24374 to var lib freenet experimental var lib freenet experimental persistent temp 24374 where var lib freenet experimental is the current working dir regenerating from path worked so do that here and yes it s voodoo file new file file get path file result try result file get absolute file get canonical file catch io exception e result file get absolute file return result getcanonicalfile getpath getabsolutefile getcanonicalfile ioexception getabsolutefile public static string readutf file file throws file not found exception io exception return readutf file 0 filenotfoundexception ioexception public static string readutf file file long offset throws file not found exception io exception string builder result new string builder file input stream fis null buffered input stream bis null input stream reader isr null try fis new file input stream file skip fully fis offset bis new buffered input stream fis isr new input stream reader bis utf 8 char buf new char 4096 int length 0 while length isr read buf 0 result append buf 0 length finally closer close isr closer close bis closer close fis return result to string filenotfoundexception ioexception stringbuilder stringbuilder fileinputstream bufferedinputstream inputstreamreader fileinputstream skipfully bufferedinputstream inputstreamreader tostring reliably skip a number of bytes or throw public static void skip fully input stream is long skip throws io exception long skipped 0 while skipped skip long x is skip skip skipped if x 0 throw new io exception unable to skip skip skipped bytes skipped x skipfully inputstream ioexception ioexception public static boolean write to input stream input file target throws file not found exception io exception data input stream dis null file output stream fos null file file file create temp file temp tmp target get parent file if logger should log logger minor file util class logger minor file util class writing to file to be renamed to target try dis new data input stream input fos new file output stream file int len 0 byte buffer new byte 4096 while len dis read buffer 0 fos write buffer 0 len catch io exception e throw e finally if dis null dis close if fos null fos close if file util rename to file target return true else file delete return false writeto inputstream filenotfoundexception ioexception datainputstream fileoutputstream createtempfile getparentfile shouldlog fileutil fileutil datainputstream fileoutputstream ioexception fileutil renameto public static boolean rename to file orig file dest try an atomic rename shall we prevent symlink race conditions here if orig equals dest throw new illegal argument exception huh the two file descriptors are the same if orig exists throw new illegal argument exception original doesn t exist if orig rename to dest not supported on some systems windows if dest delete if dest exists logger error file util could not delete dest check permissions if orig rename to dest logger error file util could not rename orig to dest dest exists target exists orig exists source exists check permissions return false return true renameto illegalargumentexception illegalargumentexception renameto fileutil renameto fileutil like rename to but can move across filesystems by copying the data param f param file public static boolean move to file orig file dest boolean overwrite if orig equals dest throw new illegal argument exception huh the two file descriptors are the same if orig exists throw new illegal argument exception original doesn t exist if dest exists overwrite dest delete else system err println not overwriting dest already exists moving orig return false if orig rename to dest copy the data input stream is null output stream os null try is new file input stream orig os new file output stream dest copy is os orig length is close is null os close os null orig delete return true catch io exception e dest delete logger error file util class move failed from orig to dest e e system err println move failed from orig to dest e e print stack trace return false finally closer close is closer close os else return true renameto moveto illegalargumentexception illegalargumentexception renameto inputstream outputstream fileinputstream fileoutputstream ioexception fileutil printstacktrace public static string sanitize string s string builder sb new string builder s length for int i 0 i s length i char c s char at i if c c c c c c c c continue if character is digit c sb append c else if character is letter c sb append c else if character is whitespace c sb append else if c c c sb append c return sb to string stringbuilder stringbuilder charat isdigit isletter iswhitespace _ tostring public static string sanitize string filename string mime type filename sanitize filename if mime type null return filename if filename index of 0 string old ext filename substring filename last index of if defaultmime types is valid ext mime type old ext return filename string default ext defaultmime types get extension filename if default ext null return filename else return filename default ext mimetype mimetype indexof oldext lastindexof defaultmimetypes isvalidext mimetype oldext defaultext defaultmimetypes getextension defaultext defaultext find the length of an input stream this method will consume the complete input stream until its link input stream read byte method returns code 1 code thus signalling the end of the stream param source the input stream to find the length of return the numbe of bytes that can be read from the stream throws io exception if an i o error occurs public static long find length input stream source throws io exception long length 0 byte buffer new byte buffer size int read 0 while read 1 read source read buffer if read 1 length read return length inputstream ioexception findlength inputstream ioexception buffer_size copies code length code bytes from the source input stream to the destination output stream if code length code is code 1 code as much bytes as possible will be copied i e until link input stream read returns code 1 code to signal the end of the stream param source the input stream to read from param destination the output stream to write to param length the number of bytes to copy throws io exception if an i o error occurs public static void copy input stream source output stream destination long length throws io exception long remaining length byte buffer new byte buffer size int read 0 while remaining 1 remaining 0 read source read buffer 0 remaining buffer size remaining 1 buffer size int remaining if read 1 if length 1 return throw new eof exception stream reached eof destination write buffer 0 read remaining read inputstream ioexception inputstream outputstream ioexception buffer_size buffer_size buffer_size eofexception delete everything in a directory only use this when we are very sure there is no important data below it public static boolean remove all file wd if wd is directory system err println deleting file wd if wd delete wd exists logger error file util class could not delete file wd return false else file subfiles wd list files for int i 0 i subfiles length i if remove all subfiles i return false if wd delete logger error file util class could not delete directory wd return true removeall isdirectory fileutil listfiles removeall fileutil static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public updatable sorted linked list list new doubly linked list impl t updatablesortedlinkedlist doublylinkedlistimpl public synchronized void add t i throws updatable sorted linked list killed exception if killed throw new updatable sorted linked list killed exception if logminor logger minor this add i on this if list is empty list push i check list return if i compare to list tail 0 list push i check list return if i compare to list head 0 list unshift i check list return search the list for a good place to put it enumeration t e list elements t prev null while e has more elements t cur e next element if prev null cur compare to i 0 prev compare to i 0 list insert next prev i check list return if logminor logger minor this not matching cur prev prev cur throw new illegal state exception impossible updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception isempty checklist compareto checklist compareto checklist hasmoreelements nextelement compareto compareto insertnext checklist illegalstateexception protected synchronized void check list if get errors make this happen all the time ctr if ctr 256 0 debug return int stated length list size int real length 0 for enumeration t e list elements e has more elements t i e next element sanity check for infinite looping if real length 100 1000 logger normal this real length i prev i get prev real length if stated length real length string err stated length stated length but real length real length on this logger error this illegal error err new exception error throw new illegal state exception err else logger minor this check list successful real length stated length real length on this checklist statedlength reallength hasmoreelements nextelement reallength reallength getprev reallength statedlength reallength statedlength statedlength reallength reallength illegalstateexception checklist reallength statedlength reallength public synchronized t remove t i throws updatable sorted linked list killed exception if killed throw new updatable sorted linked list killed exception if logminor logger minor this remove i on this check list t item list remove i if logminor logger minor this returning item check list return item updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception checklist checklist public synchronized void add or update t item throws updatable sorted linked list killed exception if item get parent list update item else if item get parent null add item else throw new illegal state exception item item should be on our list list or null but is item get parent addorupdate updatablesortedlinkedlistkilledexception getparent getparent illegalstateexception getparent public synchronized void update t i throws updatable sorted linked list killed exception if killed throw new updatable sorted linked list killed exception if logminor logger minor this update i on this check list if i compare to list tail 0 list remove i list push i check list return if i compare to list head 0 list remove i list unshift i check list return if list head list tail i list head logger error this only 1 element list head and updating i on this new exception error add i check list return forwards or backwards t next list next i t prev list prev i if next null prev null return if next null prev null next compare to i 0 prev compare to i 0 return already exactly where it should be if next null prev null if prev compare to i 0 return already in right place at end if next null prev null if next compare to i 0 return already where it should be if next null i compare to next 0 i next move forwards while true prev next next list next next if next null throw new null pointer exception impossible we checked if i compare to next 0 i compare to prev 0 list remove i list insert next prev i check list return else if prev null i compare to prev 0 i next move backwards while true next prev prev list prev prev if next null throw new null pointer exception impossible we checked if i compare to next 0 i compare to prev 0 list remove i list insert next prev i check list return logger error this could not update i new exception error if logminor dump remove i add i check list updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception checklist compareto checklist compareto checklist checklist compareto compareto compareto compareto compareto nullpointerexception compareto compareto insertnext checklist compareto nullpointerexception compareto compareto insertnext checklist checklist dump the current status of the list to the log throws updatable sorted linked list killed exception private synchronized void dump throws updatable sorted linked list killed exception if killed throw new updatable sorted linked list killed exception for enumeration t e list elements e has more elements t item e next element if logminor logger minor this item to string updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception hasmoreelements nextelement tostring return the number of items in the list public synchronized int size return list size return an array in order of the elements in the list throws updatable sorted linked list killed exception suppress warnings unchecked public synchronized updatable sorted linked list item to array throws updatable sorted linked list killed exception if killed throw new updatable sorted linked list killed exception int size list size if size 0 throw new illegal state exception list size size for this updatable sorted linked list item output new updatable sorted linked list item size int i 0 for enumeration t e list elements e has more elements output i e next element logger minor this i 1 output i 1 return output updatablesortedlinkedlistkilledexception suppresswarnings updatablesortedlinkedlistitem toarray updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception illegalstateexception updatablesortedlinkedlistitem updatablesortedlinkedlistitem hasmoreelements nextelement return an array in order of the elements in the list throws updatable sorted linked list killed exception suppress warnings unchecked public synchronized e e to array e array throws updatable sorted linked list killed exception if killed throw new updatable sorted linked list killed exception int size list size if size 0 throw new illegal state exception list size size for this int i 0 for enumeration t e list elements e has more elements array i e e next element logger minor this i 1 output i 1 return array updatablesortedlinkedlistkilledexception suppresswarnings toarray updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception illegalstateexception hasmoreelements nextelement return does the list contain that item public synchronized boolean contains t item return list contains item return is the list empty public synchronized boolean is empty return list is empty isempty isempty return the item on the list with the lowest value public synchronized t get lowest return list head getlowest public synchronized void clear list clear public synchronized void kill clear killed true public synchronized t remove lowest throws updatable sorted linked list killed exception if is empty return null t i get lowest remove i return i removelowest updatablesortedlinkedlistkilledexception isempty getlowest public synchronized void move to updatable sorted linked list t dest throws updatable sorted linked list killed exception enumeration t e list elements while e has more elements t item e next element remove item dest add item moveto updatablesortedlinkedlist updatablesortedlinkedlistkilledexception hasmoreelements nextelement public synchronized iterator t iterator return list iterator public float r factor g factor b factor public rgb adjust filter this 0 0 0 rfactor gfactor bfactor rgbadjustfilter public rgb adjust filter float r float g float b r factor 1 r g factor 1 g b factor 1 b can filter index color model true rgbadjustfilter rfactor gfactor bfactor canfilterindexcolormodel public void setr factor float r factor this r factor 1 r factor setrfactor rfactor rfactor rfactor public float getr factor return r factor 1 getrfactor rfactor public void setg factor float g factor this g factor 1 g factor setgfactor gfactor gfactor gfactor public float getg factor return g factor 1 getgfactor gfactor public void setb factor float b factor this b factor 1 b factor setbfactor bfactor bfactor bfactor public float getb factor return b factor 1 getbfactor bfactor public int getlut int lut new int 256 for int i 0 i 256 i lut i filterrgb 0 0 i 24 i 16 i 8 i return lut override public int filterrgb int x int y int rgb int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r pixel utils clamp int r r factor g pixel utils clamp int g g factor b pixel utils clamp int b b factor return a r 16 g 8 b pixelutils rfactor pixelutils gfactor pixelutils bfactor override public string to string return colors adjust rgb tostring construct a composite filter public composite filter compositefilter compositefilter construct a composite filter param composite the composite to use public composite filter composite composite this composite composite compositefilter compositefilter construct a composite filter param composite the composite to use param transform a transform for the composited image public composite filter composite composite affine transform transform this composite composite this transform transform compositefilter compositefilter affinetransform set the composite param composite the composite to use see get composite public void set composite composite composite this composite composite getcomposite setcomposite get the composite return the composite to use see set composite public composite get composite return composite setcomposite getcomposite set the transform param transform the transform to use see get transform public void set transform affine transform transform this transform transform gettransform settransform affinetransform get the transform return the transform to use see set transform public affine transform get transform return transform settransform affinetransform gettransform public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null graphics2d g dst create graphics g set rendering hint rendering hints key antialiasing rendering hints value antialias on g set rendering hint rendering hints key interpolation rendering hints value interpolation bilinear g set composite composite g draw rendered image src transform g dispose return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage creategraphics setrenderinghint renderinghints key_antialiasing renderinghints value_antialias_on setrenderinghint renderinghints key_interpolation renderinghints value_interpolation_bilinear setcomposite drawrenderedimage override public string to string return composite tostring private static string if address public final static void set interface string ifaddr if address ifaddr ifaddress setinterface ifaddress public final static string get interface return if address getinterface ifaddress private final static boolean has assigned interface return 0 if address length true false hasassignedinterface ifaddress private final static boolean is usable address inet address addr if use loopback addr false if addr is loopback address true return false if use only ipv4 addr true if addr instanceof inet6 address return false if use only ipv6 addr true if addr instanceof inet4 address return false return true isusableaddress inetaddress use_loopback_addr isloopbackaddress use_only_ipv4_addr inet6address use_only_ipv6_addr inet4address public final static int getn host addresses if has assigned interface true return 1 int n host addrs 0 try enumeration nis network interface get network interfaces while nis has more elements network interface ni network interface nis next element enumeration addrs ni get inet addresses while addrs has more elements inet address addr inet address addrs next element if is usable address addr false continue n host addrs catch exception e return n host addrs getnhostaddresses hasassignedinterface nhostaddrs networkinterface getnetworkinterfaces hasmoreelements networkinterface networkinterface nextelement getinetaddresses hasmoreelements inetaddress inetaddress nextelement isusableaddress nhostaddrs nhostaddrs public final static string get host address int n if has assigned interface true return get interface int host addr cnt 0 try enumeration nis network interface get network interfaces while nis has more elements network interface ni network interface nis next element enumeration addrs ni get inet addresses while addrs has more elements inet address addr inet address addrs next element if is usable address addr false continue if host addr cnt n host addr cnt continue string host addr get host address if addr instanceof inet6 address host host return host catch exception e return gethostaddress hasassignedinterface getinterface hostaddrcnt networkinterface getnetworkinterfaces hasmoreelements networkinterface networkinterface nextelement getinetaddresses hasmoreelements inetaddress inetaddress nextelement isusableaddress hostaddrcnt hostaddrcnt gethostaddress inet6address public final static boolean isi pv6 address string host try inet address addr inet address get by name host return addr instanceof inet6 address catch exception e return false isipv6address inetaddress inetaddress getbyname inet6address public final static boolean isi pv4 address string host try inet address addr inet address get by name host return addr instanceof inet4 address catch exception e return false isipv4address inetaddress inetaddress getbyname inet4address public final static boolean hasi pv4 addresses int addr cnt getn host addresses for int n 0 n addr cnt n string addr get host address n if isi pv4 address addr true return true return false hasipv4addresses addrcnt getnhostaddresses addrcnt gethostaddress isipv4address public final static boolean hasi pv6 addresses int addr cnt getn host addresses for int n 0 n addr cnt n string addr get host address n if isi pv6 address addr true return true return false hasipv6addresses addrcnt getnhostaddresses addrcnt gethostaddress isipv6address public final static string geti pv4 address int addr cnt getn host addresses for int n 0 n addr cnt n string addr get host address n if isi pv4 address addr true return addr return getipv4address addrcnt getnhostaddresses addrcnt gethostaddress isipv4address public final static string geti pv6 address int addr cnt getn host addresses for int n 0 n addr cnt n string addr get host address n if isi pv6 address addr true return addr return getipv6address addrcnt getnhostaddresses addrcnt gethostaddress isipv6address public final static string get hosturl string host int port string uri string host addr host if isi pv6 address host true host addr host return http host addr integer to string port uri gethosturl hostaddr isipv6address hostaddr hostaddr tostring public static final string too many levels too many archive levels public archive failure exception string message super message too_many_levels archivefailureexception public archive failure exception string message io exception e super message init cause e archivefailureexception ioexception initcause public peer note string node identifier string note text int peer note type string identifier this node identifier node identifier this note text note text this peer note type peer note type this identifier identifier peernote nodeidentifier notetext peernotetype nodeidentifier nodeidentifier notetext notetext peernotetype peernotetype override public simple field set get field set simple field set fs new simple field set true fs put single node identifier node identifier fs put single peer note type integer to string peer note type try fs put single note text base64 encode note text get bytes utf 8 true catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle nodeidentifier nodeidentifier putsingle peernotetype tostring peernotetype putsingle notetext notetext getbytes unsupportedencodingexception putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message peer note goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message peernote override public void remove from object container container container delete this removefrom objectcontainer public final static boolean is discover string value if value null return false if value equals man discover true return true return value equals man discover isdiscover public dsa signature input stream in throws io exception r util readmpi in s util readmpi in if r signum 1 s signum 1 throw new io exception both r and s should be positive dsasignature inputstream ioexception ioexception parses a dsa signature pair from a string where r and s are in unsigned hex strings separated by a comma public dsa signature string sig throws number format exception int x sig index of if x 0 throw new number format exception dsa signatures have two values r new native big integer sig substring 0 x 16 s new native big integer sig substring x 1 16 if r signum 1 s signum 1 throw new illegal argument exception dsasignature numberformatexception indexof numberformatexception nativebiginteger nativebiginteger illegalargumentexception public static dsa signature read input stream in throws io exception big integer r s r util readmpi in s util readmpi in return new dsa signature r s dsasignature inputstream ioexception biginteger dsasignature public void write output stream o throws io exception util writempi r o util writempi s o outputstream ioexception public dsa signature big integer r big integer s this r r this s s if r signum 1 s signum 1 throw new illegal argument exception dsasignature biginteger biginteger illegalargumentexception public big integer getr return r biginteger public big integer gets return s biginteger public string to long string if to string cached null to string cached hex util bi to hex r hex util bi to hex s return to string cached tolongstring tostringcached tostringcached hexutil bitohex hexutil bitohex tostringcached public byte getr bytes int length return get param bytes r length getrbytes getparambytes public byte gets bytes int length return get param bytes s length getsbytes getparambytes private static byte get param bytes big integer param int length byte data param to byte array if data length length byte out new byte length system arraycopy data 0 out out length data length data length return out else if data length length 1 if data 0 0 byte out new byte length system arraycopy data 1 out 0 length return out else throw new illegal argument exception parameter longer than length bytes param bit length else if data length length return data else throw new illegal argument exception length is much shorter data length but target length length getparambytes biginteger tobytearray illegalargumentexception bitlength illegalargumentexception private static final long serial versionuid 1 public config exception string msg super msg serialversionuid configexception static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public sectored random grab array boolean persistent object container container remove random parent parent this persistent persistent grab clients new object 0 grab arrays new remove random with object 0 this parent parent sectoredrandomgrabarray objectcontainer removerandomparent grabclients grabarrays removerandomwithobject add directly to a random grab array with client under us public synchronized void add object client random grab array item item object container container if item persistent persistent throw new illegal argument exception item persistent item persistent but array persistent persistent item item array this random grab array with client rga int client index have client client if client index 1 if logminor logger minor this adding new rga with client for client on this for item rga new random grab array with client client persistent container this add element client rga if persistent container store rga container store this else rga random grab array with client grab arrays client index if persistent container activate rga 1 if logminor logger minor this adding item to rga rga for client rga add item container if persistent container deactivate rga 1 if logminor logger minor this size now grab arrays length on this randomgrabarraywithclient randomgrabarrayitem objectcontainer illegalargumentexception randomgrabarraywithclient clientindex haveclient clientindex rgawithclient randomgrabarraywithclient addelement randomgrabarraywithclient grabarrays clientindex grabarrays private void add element object client remove random with object rga int len grab arrays length remove random with object new arrays new remove random with object len 1 system arraycopy grab arrays 0 new arrays 0 len new arrays len rga grab arrays new arrays object new clients new object len 1 system arraycopy grab clients 0 new clients 0 len new clients len client grab clients new clients addelement removerandomwithobject grabarrays removerandomwithobject newarrays removerandomwithobject grabarrays newarrays newarrays grabarrays newarrays newclients grabclients newclients newclients grabclients newclients private synchronized int have client object client for int i 0 i grab clients length i if grab clients i client return i return 1 haveclient grabclients grabclients get a grabber this lets us use things other than random grab array with client s so don t mix calls to add with calls to get grabber add grabber public synchronized remove random with object get grabber object client int idx have client client if idx 1 return null else return grab arrays idx randomgrabarraywithclient getgrabber addgrabber removerandomwithobject getgrabber haveclient grabarrays public synchronized object get client int x return grab clients x getclient grabclients put a grabber this lets us use things other than random grab array with client s so don t mix calls to add with calls to get grabber add grabber public synchronized void add grabber object client remove random with object request grabber object container container if request grabber get object client throw new illegal argument exception client not equal to remove random with object s client client client rr request grabber his object request grabber get object add element client request grabber if persistent container store this randomgrabarraywithclient getgrabber addgrabber addgrabber removerandomwithobject requestgrabber objectcontainer requestgrabber getobject illegalargumentexception removerandomwithobject requestgrabber requestgrabber getobject addelement requestgrabber public synchronized random grab array item remove random random grab array item exclusion list excluding object container container client context context count of arrays that have items but didn t return anything because of exclusions int excluded 0 final int max excluded 10 while true if grab arrays length 0 return null if grab arrays length 1 optimise the common case remove random with object rga grab arrays 0 if persistent container activate rga 1 random grab array item item rga remove random excluding container context if rga is empty if logminor logger minor this removing only grab array 0 rga grab arrays new remove random with object 0 grab clients new object 0 if persistent container store this rga remove from container if logminor logger minor this returning one item only item for rga return item if grab arrays length 2 another simple common case int x context fast weak random next boolean 1 0 remove random with object rga grab arrays x if persistent container activate rga 1 remove random with object firstrga rga if rga null logger error this rga null on this if container null container ext is active this logger error this not active if grab arrays 1 x null logger error this other rga is also null on this else remove random with object valid grab arrays 1 x logger error this grab arrays 1 x is valid but x is null correcting grab arrays new remove random with object grab arrays 1 x grab clients new object grab clients 1 x if persistent container store this continue random grab array item item rga remove random excluding container context if item null x 1 x rga grab arrays x if persistent container activate rga 1 item rga remove random excluding container context if firstrga is empty rga is empty grab arrays new remove random with object 0 grab clients new object 0 if persistent container store this firstrga remove from container rga remove from container else if firstrga is empty if persistent container activate firstrga 1 grab arrays new remove random with object rga grab clients new object grab clients x if persistent container store this firstrga remove from container if persistent container deactivate rga 1 container deactivate firstrga 1 if logminor logger minor this returning two items only item for rga return item else if persistent container deactivate rga 1 if logminor logger minor this returning two items only item for rga return item int x context fast weak random next int grab arrays length remove random with object rga grab arrays x if persistent container activate rga 1 if logminor logger minor this picked x of grab arrays length rga on this random grab array item item rga remove random excluding container context if logminor logger minor this rga has picked x grab arrays length item item null cancelled item is empty container rga is empty rga is empty just because the item is cancelled does not necessarily mean the whole client is e g a segment may return cancelled because it is decoding that doesn t mean other segments are cancelled so just go around the loop in that case if rga is empty if logminor logger minor this removing grab array x rga is empty remove element x if persistent container store this rga remove from container if item null if rga is empty hmmm excluded if excluded max excluded logger normal this too many sub arrays are entirely excluded on this length grab arrays length new exception error if persistent container deactivate rga 1 return null if persistent container deactivate rga 1 continue if persistent container deactivate rga 1 if item is empty container continue return item randomgrabarrayitem removerandom randomgrabarrayitemexclusionlist objectcontainer clientcontext max_excluded grabarrays grabarrays removerandomwithobject grabarrays randomgrabarrayitem removerandom isempty grabarrays removerandomwithobject grabclients removefrom grabarrays fastweakrandom nextboolean removerandomwithobject grabarrays removerandomwithobject isactive grabarrays removerandomwithobject grabarrays grabarrays grabarrays removerandomwithobject grabarrays grabclients grabclients randomgrabarrayitem removerandom grabarrays removerandom isempty isempty grabarrays removerandomwithobject grabclients removefrom removefrom isempty grabarrays removerandomwithobject grabclients grabclients removefrom fastweakrandom nextint grabarrays removerandomwithobject grabarrays grabarrays randomgrabarrayitem removerandom grabarrays isempty isempty isempty isempty removeelement removefrom isempty max_excluded grabarrays isempty private synchronized void remove element int x final int grab arrays length grab arrays length int new len grab arrays length 1 grab arrays length 1 0 remove random with object new array new remove random with object new len if x 0 system arraycopy grab arrays 0 new array 0 x if x grab arrays length 1 system arraycopy grab arrays x 1 new array x grab arrays length x 1 grab arrays new array object new clients new object new len if x 0 system arraycopy grab clients 0 new clients 0 x if x grab arrays length 1 system arraycopy grab clients x 1 new clients x grab arrays length x 1 grab clients new clients removeelement grabarrayslength grabarrays newlen grabarrayslength grabarrayslength removerandomwithobject newarray removerandomwithobject newlen grabarrays newarray grabarrayslength grabarrays newarray grabarrayslength grabarrays newarray newclients newlen grabclients newclients grabarrayslength grabclients newclients grabarrayslength grabclients newclients public synchronized boolean is empty return grab arrays length 0 isempty grabarrays public boolean persistent return persistent public int size return grab arrays length grabarrays public void remove from object container container if grab arrays null grab arrays length 0 for remove random with object rr grab arrays if rr null logger error this not empty removing this rr return container delete this removefrom objectcontainer grabarrays grabarrays removerandomwithobject grabarrays public void maybe remove remove random r object container container int count 0 synchronized this while true int found 1 for int i 0 i grab arrays length i if grab arrays i r found i break if found 1 count if count 1 logger error this found r many times in this new exception error remove element found else break if count 0 logger error this not in parent r for this new exception error else if persistent container store this r remove from container mayberemove removerandom objectcontainer grabarrays grabarrays removeelement removefrom basic constructor archive store item archive key key archive store context context this key key this context context context add item this archivestoreitem archivekey archivestorecontext additem delete any stored data on disk etc override in subtypes for specific cleanup will be called with locks held so should only do low level operations such as deletes shortcut to start the removal cleanup process final void close context remove item this removeitem return cached data as a bucket or throw an archive failure exception abstract bucket get data or throw throws archive failure exception archivefailureexception getdataorthrow archivefailureexception return the amount of cache space used by the item may be called inside locks so should not take any nontrivial locks or take long get the data as a bucket and guarantee that it won t be freed until the returned object is either finalized or freed public class array bucket factory implements bucket factory public bucket make bucket long size throws io exception return new array bucket arraybucketfactory bucketfactory makebucket ioexception arraybucket public void free bucket bucket b throws io exception b free freebucket ioexception public static final boolean is absoluteurl string url str try new url url str return true catch exception e return false isabsoluteurl urlstr urlstr public static final string get host string url str try url url new url url str return url get host catch exception e return gethost urlstr urlstr gethost public static final int get port string url str try url url new url url str thanks for giordano sassaroli sassarol cefriel it 08 30 03 int port url get port if port 0 port default port return port catch exception e return default port getport urlstr urlstr getport default_port default_port public static final string get request hosturl string host int port string req host http host port return req host getrequesthosturl reqhost reqhost public static final string to relativeurl string url str boolean with param string uri url str if is absoluteurl url str false if 0 url str length url str char at 0 uri url str else try url url new url url str uri url get path if with param true string query str url get query if query str equals uri query str if uri ends with uri uri substring 0 uri length 1 catch exception e return uri torelativeurl urlstr withparam urlstr isabsoluteurl urlstr urlstr urlstr charat urlstr urlstr getpath withparam querystr getquery querystr querystr endswith public static final string to relativeurl string url str return to relativeurl url str true torelativeurl urlstr torelativeurl urlstr public static final string get absoluteurl string baseurl str string relu rl str try url baseurl new url baseurl str string url baseurl get protocol baseurl get host baseurl get port to relativeurl relu rl str return url catch exception e return getabsoluteurl baseurlstr relurlstr baseurlstr getprotocol gethost getport torelativeurl relurlstr private static int chunk size default chunk size public static final void set chunk size int size chunk size size chunksize default_chunk_size setchunksize chunksize public static final int get chunk size return chunk size getchunksize chunksize public usk retriever fetch context fctx short prio request client client usk retriever callback cb usk origusk super prio client if client persistent throw new unsupported operation exception usk retriever cannot be persistent this ctx fctx this cb cb this origusk origusk uskretriever fetchcontext requestclient uskretrievercallback unsupportedoperationexception uskretriever public void on found edition long l usk key object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too if l 0 logger error this found negative edition l for key return create a single file fetcher for the key as an ssk put the edition number into its context object put ourself as callback fetch it if it fails ignore it if it succeeds return the data with the edition to the client freeneturi uri key getssk l geturi try single file fetcher getter single file fetcher single file fetcher create this this uri ctx new archive context ctx max temp length ctx max archive levels ctx max non splitfile retries 0 true l true null false null context getter schedule null context catch malformedurl exception e logger error this impossible e e catch fetch exception e logger error this could not start fetcher for uri e e onfoundedition objectcontainer clientcontext newknowngood newslottoo singlefilefetcher singlefilefetcher singlefilefetcher singlefilefetcher archivecontext maxtemplength maxarchivelevels maxnonsplitfileretries malformedurlexception fetchexception public void on success fetch result result client get state state object container container client context context if logger should log logger minor this logger minor this success on this from state length result size mime type result get mime type cb on found origusk state get token result context usk manager update known good origusk state get token context onsuccess fetchresult clientgetstate objectcontainer clientcontext shouldlog getmimetype onfound gettoken uskmanager updateknowngood gettoken public void on failure fetch exception e client get state state object container container client context context switch e mode case fetch exception not enough path components case fetch exception permanent redirect context usk manager update known good origusk state get token context return logger error this found edition state get token but failed to fetch edition e e onfailure fetchexception clientgetstate objectcontainer clientcontext fetchexception not_enough_path_components fetchexception permanent_redirect uskmanager updateknowngood gettoken gettoken public void on block set finished client get state state object container container client context context ignore onblocksetfinished clientgetstate objectcontainer clientcontext override public freeneturi geturi return null override public boolean is finished return false isfinished override public void notify clients object container container client context context ignore for now notifyclients objectcontainer clientcontext override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void on expectedmime string mime object container container client context context ignore onexpectedmime objectcontainer clientcontext public void on expected size long size object container container client context context ignore onexpectedsize objectcontainer clientcontext public void on finalized metadata object container container ignore onfinalizedmetadata objectcontainer public short get polling priority normal return cb get polling priority normal getpollingprioritynormal getpollingprioritynormal public short get polling priority progress return cb get polling priority progress getpollingpriorityprogress getpollingpriorityprogress override public void cancel object container container client context context super cancel objectcontainer clientcontext override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext public class snmp time ticks extends snmp type wrapper num public snmp time ticks super snmptimeticks snmptypewrappernum snmptimeticks public class snmp time ticks extends snmp type wrapper num public snmp time ticks super public snmp time ticks long value super value snmptimeticks snmptypewrappernum snmptimeticks snmptimeticks public snmp time ticks long value super value protected void init this typeid 0x43 snmptimeticks public string to string long rest value long dec rest 100 rest rest 100 long sec rest 60 rest rest 60 long min rest 60 rest rest 60 long hour rest 24 rest rest 24 long day rest return day hour min sec dec tostring public int positions public term position termposition public term position storage storage positions new int 0 storage make persistent this termposition makepersistent public synchronized void add positions int position int new positions new int positions length 1 system arraycopy positions 0 new positions 0 positions length new positions positions length position positions new positions modify addpositions newpositions newpositions newpositions newpositions public synchronized int add positions return positions addpositions public final int length public patricia trie key long mask int length this mask mask this length length patriciatriekey public static patricia trie key from ip address inet address addr byte bytes addr get address long mask 0 for int i 0 i bytes length i mask mask 8 bytes i 0xff return new patricia trie key mask bytes length 8 patriciatriekey fromipaddress inetaddress getaddress patriciatriekey public static patricia trie key from ip address string addr throws number format exception long mask 0 int pos 0 int len 0 do int dot addr index of pos string part dot 0 addr substring pos addr substring pos dot pos dot 1 int b integer parse int part 10 mask mask 8 b 0xff len 8 while pos 0 return new patricia trie key mask len patriciatriekey fromipaddress numberformatexception indexof parseint patriciatriekey public static patricia trie key from decimal digits string digits long mask 0 int n digits length assert that n 16 for int i 0 i n i char ch digits char at i assert that ch 0 ch 9 mask mask 4 ch 0 return new patricia trie key mask n 4 patriciatriekey fromdecimaldigits charat patriciatriekey public static patricia trie key from7bit string string str long mask 0 int n str length assert that n 7 64 for int i 0 i n i char ch str char at i mask mask 7 ch 0x7f return new patricia trie key mask n 7 patriciatriekey from7bitstring charat patriciatriekey public static patricia trie key from8bit string string str long mask 0 int n str length assert that n 8 for int i 0 i n i char ch str char at i mask mask 8 ch 0xff return new patricia trie key mask n 8 patriciatriekey from8bitstring charat patriciatriekey public static patricia trie key from byte array byte arr long mask 0 int n arr length assert that n 8 for int i 0 i n i mask mask 8 arr i 0xff return new patricia trie key mask n 8 patriciatriekey frombytearray patriciatriekey public service list servicelist public service get service int n object obj null try obj get n catch exception e return service obj getservice public static final int routing key length 32 override public string to string return super to string pkh hex util bytes to hex pub key hash ehd hex util bytes to hex encrypted hashed docname routing_key_length tostring tostring hexutil bytestohex pubkeyhash hexutil bytestohex encryptedhasheddocname public nodessk byte pk hash byte eh docname dsa public key pub key byte crypto algorithm throws ssk verify exception super make routing key pk hash eh docname this encrypted hashed docname eh docname this pub key hash pk hash this crypto algorithm crypto algorithm this pub key pub key if pub key null byte hash sha256 digest pub key as bytes if arrays equals hash pk hash throw new ssk verify exception invalid pub key wrong hash if eh docname length e h docname size throw new illegal argument exception eh docname must be e h docname size bytes if pk hash length pubkey hash size throw new illegal argument exception pub key hash must be pubkey hash size bytes hash code fields hash code pk hash fields hash code eh docname pkhash ehdocname dsapublickey pubkey cryptoalgorithm sskverifyexception makeroutingkey pkhash ehdocname encryptedhasheddocname ehdocname pubkeyhash pkhash cryptoalgorithm cryptoalgorithm pubkey pubkey pubkey pubkey asbytes pkhash sskverifyexception pubkey ehdocname e_h_docname_size illegalargumentexception ehdocname e_h_docname_size pkhash pubkey_hash_size illegalargumentexception pubkeyhash pubkey_hash_size hashcode hashcode pkhash hashcode ehdocname private nodessk nodessk key super key this crypto algorithm key crypto algorithm this pub key key pub key this pub key hash new byte key pub key hash length system arraycopy key pub key hash 0 pub key hash 0 key pub key hash length this encrypted hashed docname new byte key encrypted hashed docname length system arraycopy key encrypted hashed docname 0 encrypted hashed docname 0 key encrypted hashed docname length this hash code key hash code cryptoalgorithm cryptoalgorithm pubkey pubkey pubkeyhash pubkeyhash pubkeyhash pubkeyhash pubkeyhash encryptedhasheddocname encryptedhasheddocname encryptedhasheddocname encryptedhasheddocname encryptedhasheddocname hashcode hashcode override public key clone key return new nodessk this clonekey routing key h e h docname h pubkey private static byte make routing key byte pk hash byte eh docname message digest md256 sha256 get message digest md256 update eh docname md256 update pk hash byte key md256 digest sha256 return message digest md256 return key routingkey makeroutingkey pkhash ehdocname messagedigest getmessagedigest ehdocname pkhash returnmessagedigest override public void write data output index throws io exception index write short get type index write encrypted hashed docname index write pub key hash dataoutput _index ioexception _index writeshort gettype _index encryptedhasheddocname _index pubkeyhash public static key readssk data input raf byte crypto algorithm throws io exception byte buf new byte e h docname size raf read fully buf byte buf2 new byte pubkey hash size raf read fully buf2 try return new nodessk buf2 buf null crypto algorithm catch ssk verify exception e illegal state exception impossible new illegal state exception impossible e impossible init cause e throw impossible datainput cryptoalgorithm ioexception e_h_docname_size readfully pubkey_hash_size readfully cryptoalgorithm sskverifyexception illegalstateexception illegalstateexception initcause override public short get type return short 0x0200 crypto algorithm 0xff gettype cryptoalgorithm public void write to data output stream data output stream stream throws io exception write stream writetodataoutputstream dataoutputstream ioexception return true if we know the pubkey public boolean has pub key return pub key null haspubkey pubkey return the public key if we know it otherwise null public dsa public key get pub key return pub key dsapublickey getpubkey pubkey public byte get pub key hash return pub key hash getpubkeyhash pubkeyhash public void set pub key dsa public key pub key2 throws ssk verify exception if pub key pub key2 return if pub key2 null return if pub key null pub key2 equals pub key if pub key2 null byte new pub key hash sha256 digest pub key2 as bytes if arrays equals pub key hash new pub key hash if pub key null same hash yet different keys logger error this found sha 256 collision or something wtf throw new ssk verify exception invalid new pubkey pub key2 old pubkey pub key valid key assign else throw new ssk verify exception new pubkey has invalid hash pub key pub key2 setpubkey dsapublickey pubkey2 sskverifyexception pubkey pubkey2 pubkey2 pubkey pubkey2 pubkey pubkey2 newpubkeyhash pubkey2 asbytes pubkeyhash newpubkeyhash pubkey sskverifyexception pubkey2 pubkey sskverifyexception pubkey pubkey2 override public boolean equals object o if o this return true if o instanceof nodessk return false nodessk key nodessk o if arrays equals key encrypted hashed docname encrypted hashed docname return false if arrays equals key pub key hash pub key hash return false if arrays equals key routing key routing key return false cached normalized double and pub key could be negative null return true encryptedhasheddocname encryptedhasheddocname pubkeyhash pubkeyhash routingkey routingkey cachednormalizeddouble pubkey override public int hash code return hash code hashcode hashcode not just the routing key enough data to reconstruct the key excluding any pubkey needed override public byte get key bytes return encrypted hashed docname getkeybytes encryptedhasheddocname override public byte get full key byte buf new byte full key length short type get type buf 0 byte type 8 buf 1 byte type 0xff system arraycopy encrypted hashed docname 0 buf 2 e h docname size system arraycopy pub key hash 0 buf 2 e h docname size pubkey hash size return buf getfullkey full_key_length gettype encryptedhasheddocname e_h_docname_size pubkeyhash e_h_docname_size pubkey_hash_size public static nodessk construct byte buf throws ssk verify exception if buf 0 2 throw new ssk verify exception unknown type byte buf 0 byte crypto algorithm buf 1 if crypto algorithm key algo aes pcfb 256 sha256 throw new ssk verify exception unknown crypto algorithm buf 1 byte encrypted hashed docname new byte e h docname size system arraycopy buf 2 encrypted hashed docname 0 e h docname size byte pubkey hash new byte pubkey hash size system arraycopy buf 2 e h docname size pubkey hash 0 pubkey hash size return new nodessk pubkey hash encrypted hashed docname null crypto algorithm sskverifyexception sskverifyexception cryptoalgorithm cryptoalgorithm algo_aes_pcfb_256_sha256 sskverifyexception encryptedhasheddocname e_h_docname_size encryptedhasheddocname e_h_docname_size pubkeyhash pubkey_hash_size e_h_docname_size pubkeyhash pubkey_hash_size pubkeyhash encryptedhasheddocname cryptoalgorithm public boolean grab pubkey get pubkey pubkey cache if pub key null return false pub key pubkey cache get key pub key hash return pub key null grabpubkey getpubkey pubkeycache pubkey pubkey pubkeycache getkey pubkeyhash pubkey public static byte routing key from full key byte key buf if key buf length full key length logger error nodessk class routing key from full key on buffer length key buf length byte encrypted hashed docname new byte e h docname size byte pub key hash new byte pubkey hash size system arraycopy key buf 2 encrypted hashed docname 0 e h docname size system arraycopy key buf 2 e h docname size pub key hash 0 pubkey hash size return make routing key pub key hash encrypted hashed docname routingkeyfromfullkey keybuf keybuf full_key_length routingkeyfromfullkey keybuf encryptedhasheddocname e_h_docname_size pubkeyhash pubkey_hash_size keybuf encryptedhasheddocname e_h_docname_size keybuf e_h_docname_size pubkeyhash pubkey_hash_size makeroutingkey pubkeyhash encryptedhasheddocname public int compare to object arg0 if arg0 instanceof nodechk return 1 nodessk key nodessk arg0 int result fields compare bytes encrypted hashed docname key encrypted hashed docname if result 0 return result return fields compare bytes pub key hash key pub key hash compareto comparebytes encryptedhasheddocname encryptedhasheddocname comparebytes pubkeyhash pubkeyhash override public void remove from object container container super remove from container removefrom objectcontainer removefrom construct a render text filter public render text filter rendertextfilter rendertextfilter construct a render text filter param text the text param font the font to use may be null param paint the paint may be null param composite the composite may be null param transform the transform may be null public render text filter string text font font paint paint composite composite affine transform transform this text text this font font this composite composite this paint paint this transform transform rendertextfilter rendertextfilter affinetransform set the text to paint param text the text see get text public void set text string text this text text gettext settext get the text to paint return the text see set text public string get text return text settext gettext set the composite with which to paint the text param composite the composite see get composite public void set composite composite composite this composite composite getcomposite setcomposite get the composite with which to paint the text return the composite see set composite public composite get composite return composite setcomposite getcomposite set the paint with which to paint the text param paint the paint see get paint public void set paint paint paint this paint paint getpaint setpaint get the paint with which to paint the text return the paint see set paint public paint get paint return paint setpaint getpaint set the font with which to paint the text param font the font see get font public void set font font font this font font getfont setfont get the font with which to paint the text return the font see set font public font get font return font setfont getfont set the transform with which to paint the text param transform the transform see get transform public void set transform affine transform transform this transform transform gettransform settransform affinetransform get the transform with which to paint the text return the transform see set transform public affine transform get transform return transform settransform affinetransform gettransform public buffered image filter buffered image src buffered image dst if dst null dst create compatible dest image src null graphics2d g dst create graphics g set rendering hint rendering hints key text antialiasing rendering hints value text antialias on if font null g set font font if transform null g set transform transform if composite null g set composite composite if paint null g set paint paint if text null g draw string text 10 100 g dispose return dst bufferedimage bufferedimage bufferedimage createcompatibledestimage creategraphics setrenderinghint renderinghints key_text_antialiasing renderinghints value_text_antialias_on setfont settransform setcomposite setpaint drawstring construct a filter with a null kernel this is only useful if you re going to change the kernel later on public convolve filter this new float 9 convolvefilter construct a filter with the given 3x3 kernel param matrix an array of 9 floats containing the kernel public convolve filter float matrix this new kernel 3 3 matrix convolvefilter construct a filter with the given kernel param rows the number of rows in the kernel param cols the number of columns in the kernel param matrix an array of rows cols floats containing the kernel public convolve filter int rows int cols float matrix this new kernel cols rows matrix convolvefilter construct a filter with the given 3x3 kernel param kernel the convolution kernel public convolve filter kernel kernel this kernel kernel convolvefilter set the convolution kernel param kernel the kernel see get kernel public void set kernel kernel kernel this kernel kernel getkernel setkernel get the convolution kernel return the kernel see set kernel public kernel get kernel return kernel setkernel getkernel set the action to perfomr for pixels off the image edges param edge action the action see get edge action public void set edge action int edge action this edge action edge action edgeaction getedgeaction setedgeaction edgeaction edgeaction edgeaction get the action to perfomr for pixels off the image edges return the action see set edge action public int get edge action return edge action setedgeaction getedgeaction edgeaction set whether to convolve the alpha channel param use alpha true to convolve the alpha see get use alpha public void set use alpha boolean use alpha this alpha use alpha usealpha getusealpha setusealpha usealpha usealpha get whether to convolve the alpha channel return true to convolve the alpha see set use alpha public boolean get use alpha return alpha setusealpha getusealpha set whether to premultiply the alpha channel param premultiply alpha true to premultiply the alpha see get premultiply alpha public void set premultiply alpha boolean premultiply alpha this premultiply alpha premultiply alpha premultiplyalpha getpremultiplyalpha setpremultiplyalpha premultiplyalpha premultiplyalpha premultiplyalpha get whether to premultiply the alpha channel return true to premultiply the alpha see set premultiply alpha public boolean get premultiply alpha return premultiply alpha setpremultiplyalpha getpremultiplyalpha premultiplyalpha public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int in pixels new int width height int out pixels new int width height getrgb src 0 0 width height in pixels if premultiply alpha image math premultiply in pixels 0 in pixels length convolve kernel in pixels out pixels width height alpha edge action if premultiply alpha image math unpremultiply out pixels 0 out pixels length setrgb dst 0 0 width height out pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage inpixels outpixels inpixels premultiplyalpha imagemath inpixels inpixels inpixels outpixels edgeaction premultiplyalpha imagemath outpixels outpixels outpixels override public buffered image create compatible dest image buffered image src color model dstcm if dstcm null dstcm src get color model return new buffered image dstcm dstcm create compatible writable raster src get width src get height dstcm is alpha premultiplied null bufferedimage createcompatibledestimage bufferedimage colormodel getcolormodel bufferedimage createcompatiblewritableraster getwidth getheight isalphapremultiplied override public rectangle2d get bounds2d buffered image src return new rectangle 0 0 src get width src get height getbounds2d bufferedimage getwidth getheight override public point2d get point2d point2d src pt point2d dst pt if dst pt null dst pt new point2d double dst pt set location src pt getx src pt gety return dst pt getpoint2d srcpt dstpt dstpt dstpt dstpt setlocation srcpt srcpt dstpt override public rendering hints get rendering hints return null renderinghints getrenderinghints convolve a block of pixels param kernel the kernel param in pixels the input pixels param out pixels the output pixels param width the width param height the height param edge action what to do at the edges public static void convolve kernel kernel int in pixels int out pixels int width int height int edge action convolve kernel in pixels out pixels width height true edge action inpixels outpixels edgeaction inpixels outpixels edgeaction inpixels outpixels edgeaction convolve a block of pixels param kernel the kernel param in pixels the input pixels param out pixels the output pixels param width the width param height the height param alpha include alpha channel param edge action what to do at the edges public static void convolve kernel kernel int in pixels int out pixels int width int height boolean alpha int edge action if kernel get height 1 convolveh kernel in pixels out pixels width height alpha edge action else if kernel get width 1 convolvev kernel in pixels out pixels width height alpha edge action else convolvehv kernel in pixels out pixels width height alpha edge action inpixels outpixels edgeaction inpixels outpixels edgeaction getheight inpixels outpixels edgeaction getwidth inpixels outpixels edgeaction inpixels outpixels edgeaction convolve with a 2d kernel param kernel the kernel param in pixels the input pixels param out pixels the output pixels param width the width param height the height param alpha include alpha channel param edge action what to do at the edges public static void convolvehv kernel kernel int in pixels int out pixels int width int height boolean alpha int edge action int index 0 float matrix kernel get kernel data null int rows kernel get height int cols kernel get width int rows2 rows 2 int cols2 cols 2 for int y 0 y height y for int x 0 x width x float r 0 g 0 b 0 a 0 for int row rows2 row rows2 row int iy y row int ioffset if 0 iy iy height ioffset iy width else if edge action clamp edges ioffset y width else if edge action wrap edges ioffset iy height height width else continue int moffset cols row rows2 cols2 for int col cols2 col cols2 col float f matrix moffset col if f 0 int ix x col if 0 ix ix width if edge action clamp edges ix x else if edge action wrap edges ix x width width else continue int rgb in pixels ioffset ix a f rgb 24 0xff r f rgb 16 0xff g f rgb 8 0xff b f rgb 0xff int ia alpha pixel utils clamp int a 0 5 0xff int ir pixel utils clamp int r 0 5 int ig pixel utils clamp int g 0 5 int ib pixel utils clamp int b 0 5 out pixels index ia 24 ir 16 ig 8 ib inpixels outpixels edgeaction inpixels outpixels edgeaction getkerneldata getheight getwidth edgeaction clamp_edges edgeaction wrap_edges edgeaction clamp_edges edgeaction wrap_edges inpixels pixelutils pixelutils pixelutils pixelutils outpixels convolve with a kernel consisting of one row param kernel the kernel param in pixels the input pixels param out pixels the output pixels param width the width param height the height param alpha include alpha channel param edge action what to do at the edges public static void convolveh kernel kernel int in pixels int out pixels int width int height boolean alpha int edge action int index 0 float matrix kernel get kernel data null int cols kernel get width int cols2 cols 2 for int y 0 y height y int ioffset y width for int x 0 x width x float r 0 g 0 b 0 a 0 int moffset cols2 for int col cols2 col cols2 col float f matrix moffset col if f 0 int ix x col if ix 0 if edge action clamp edges ix 0 else if edge action wrap edges ix x width width else if ix width if edge action clamp edges ix width 1 else if edge action wrap edges ix x width width int rgb in pixels ioffset ix a f rgb 24 0xff r f rgb 16 0xff g f rgb 8 0xff b f rgb 0xff int ia alpha pixel utils clamp int a 0 5 0xff int ir pixel utils clamp int r 0 5 int ig pixel utils clamp int g 0 5 int ib pixel utils clamp int b 0 5 out pixels index ia 24 ir 16 ig 8 ib inpixels outpixels edgeaction inpixels outpixels edgeaction getkerneldata getwidth edgeaction clamp_edges edgeaction wrap_edges edgeaction clamp_edges edgeaction wrap_edges inpixels pixelutils pixelutils pixelutils pixelutils outpixels convolve with a kernel consisting of one column param kernel the kernel param in pixels the input pixels param out pixels the output pixels param width the width param height the height param alpha include alpha channel param edge action what to do at the edges public static void convolvev kernel kernel int in pixels int out pixels int width int height boolean alpha int edge action int index 0 float matrix kernel get kernel data null int rows kernel get height int rows2 rows 2 for int y 0 y height y for int x 0 x width x float r 0 g 0 b 0 a 0 for int row rows2 row rows2 row int iy y row int ioffset if iy 0 if edge action clamp edges ioffset 0 else if edge action wrap edges ioffset y height height width else ioffset iy width else if iy height if edge action clamp edges ioffset height 1 width else if edge action wrap edges ioffset y height height width else ioffset iy width else ioffset iy width float f matrix row rows2 if f 0 int rgb in pixels ioffset x a f rgb 24 0xff r f rgb 16 0xff g f rgb 8 0xff b f rgb 0xff int ia alpha pixel utils clamp int a 0 5 0xff int ir pixel utils clamp int r 0 5 int ig pixel utils clamp int g 0 5 int ib pixel utils clamp int b 0 5 out pixels index ia 24 ir 16 ig 8 ib inpixels outpixels edgeaction inpixels outpixels edgeaction getkerneldata getheight edgeaction clamp_edges edgeaction wrap_edges edgeaction clamp_edges edgeaction wrap_edges inpixels pixelutils pixelutils pixelutils pixelutils outpixels override public string to string return blur convolve tostring override protected void set up throws exception super set up a new own identity uria uria a true b new identity urib b true m wot store and commit a m wot store and commit b score score new score a b 100 1 40 m wot getdb store score m wot getdb commit setup setup ownidentity mwot storeandcommit mwot storeandcommit mwot mwot public void test score creation throws not in trust tree exception score score m wot get score a b assert true score get score 100 assert true score get rank 1 assert true score get capacity 40 assert true score get tree owner a assert true score get target b testscorecreation notintrusttreeexception mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity asserttrue gettreeowner asserttrue gettarget public void test score persistence throws malformedurl exception unknown identity exception not in trust tree exception m wot terminate m wot null system gc system run finalization m wot new wot get database filename a m wot get own identity byuri uria b m wot get identity byuri urib score score m wot get score a b assert true score get score 100 assert true score get rank 1 assert true score get capacity 40 assert true score get tree owner a assert true score get target b testscorepersistence malformedurlexception unknownidentityexception notintrusttreeexception mwot mwot runfinalization mwot getdatabasefilename mwot getownidentitybyuri mwot getidentitybyuri mwot getscore asserttrue getscore asserttrue getrank asserttrue getcapacity asserttrue gettreeowner asserttrue gettarget protected transient wot identity manager m identity manager get a list of fields which the database should create an index on public static string get indexed fields return new string muid m requesturi wotidentitymanager midentitymanager getindexedfields mrequesturi public wot identity string myuid freeneturi my requesturi string my nickname if myuid null throw new illegal argument exception uid null if myuid length 0 throw new illegal argument exception uid length 0 if my requesturi null throw new illegal argument exception requesturi null if my nickname null throw new illegal argument exception nickname null if my nickname length 0 throw new illegal argument exception nickname length 0 muid myuid m requesturi my requesturi m nickname my nickname m last received from wot current timeutc get in millis m is needed false wotidentity myrequesturi mynickname illegalargumentexception illegalargumentexception myrequesturi illegalargumentexception mynickname illegalargumentexception mynickname illegalargumentexception mrequesturi myrequesturi mnickname mynickname mlastreceivedfromwot currenttimeutc getinmillis misneeded has to be used after loading a ft identity wot object from the database to initialize the transient fields public void initialize transient ext object container mydb identity manager my identity manager assert mydb null db mydb m identity manager wot identity manager my identity manager ftidentitywot initializetransient extobjectcontainer identitymanager myidentitymanager midentitymanager wotidentitymanager myidentitymanager public string getuid return muid generates a unique id from a link freeneturi it is simply a string representing it s routing key we use this to identify identities and perform requests on the database param uri the requesturi of the identity return a string to uniquely identify an identity public static string getuid fromuri freeneturi uri warning this is a copy of the code of plugins wot identity freetalk is not allowed to have its own custom i ds you cannot change this code here return base64 encode uri get routing key getuidfromuri ids getroutingkey public freeneturi get requesturi return m requesturi getrequesturi mrequesturi public string get nickname return m nickname getnickname mnickname public string get freetalk address return m nickname muid freetalk wot context to lower case getfreetalkaddress mnickname wot_context tolowercase public synchronized long get last received from wot return m last received from wot getlastreceivedfromwot mlastreceivedfromwot set the time this identity was last received from the wot plugin to the given utc time in milliseconds param time public synchronized void set last received from wot long time m last received from wot time store setlastreceivedfromwot mlastreceivedfromwot public synchronized boolean is needed return m is needed isneeded misneeded public synchronized void set is needed boolean new value m is needed new value store setisneeded newvalue misneeded newvalue validates the nickname if it is valid nothing happens if it is invalid an exception is thrown which exactly describes what is wrong about the nickname throws invalid parameter exception if the nickname is invalid the exception contains a description of the problem as message important this code is duplicated in plugins wot identity is nickname valid please also modify it there if you modify it here public static void validate nickname string new nickname throws invalid parameter exception if string validity checker contains noidn blacklist characters new nickname throw new invalid parameter exception nickname contains invalid characters fixme tell the user which ones are invalid if new nickname length 0 throw new invalid parameter exception blank nickname if new nickname length 50 throw new invalid parameter exception nickname is too long the limit is 50 characters invalidparameterexception isnicknamevalid validatenickname newnickname invalidparameterexception stringvaliditychecker containsnoidnblacklistcharacters newnickname invalidparameterexception newnickname invalidparameterexception newnickname invalidparameterexception public void store fixme check for duplicates synchronized db lock if db ext is stored this db ext is active this throw new runtime exception trying to store a non active wot identity object db store m requesturi db store this db commit isstored isactive runtimeexception wotidentity mrequesturi public final class add composite extends rgb composite public add composite float alpha super alpha addcomposite rgbcomposite addcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob dor dir sr if dor 255 dor 255 dog dig sg if dog 255 dog 255 dob dib sb if dob 255 dob 255 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac construct a motion blur filter public motion blur filter motionblurfilter motionblurfilter construct a motion blur filter param distance the distance of blur param angle the angle of blur param rotation the angle of rotation param zoom the zoom factor public motion blur filter float distance float angle float rotation float zoom this distance distance this angle angle this rotation rotation this zoom zoom motionblurfilter motionblurfilter specifies the angle of blur param angle the angle of blur angle see get angle public void set angle float angle this angle angle getangle setangle returns the angle of blur return the angle of blur see set angle public float get angle return angle setangle getangle set the distance of blur param distance the distance of blur see get distance public void set distance float distance this distance distance getdistance setdistance get the distance of blur return the distance of blur see set distance public float get distance return distance setdistance getdistance set the blur rotation param rotation the angle of rotation see get rotation public void set rotation float rotation this rotation rotation getrotation setrotation get the blur rotation return the angle of rotation see set rotation public float get rotation return rotation setrotation getrotation public void set zoom float zoom this zoom zoom setzoom get the blur zoom return the zoom factor see set zoom public float get zoom return zoom setzoom getzoom set whether to wrap at the image edges param wrap edges true if it should wrap see get wrap edges public void set wrap edges boolean wrap edges this wrap edges wrap edges wrapedges getwrapedges setwrapedges wrapedges wrapedges wrapedges get whether to wrap at the image edges return true if it should wrap see set wrap edges public boolean get wrap edges return wrap edges setwrapedges getwrapedges wrapedges set whether to premultiply the alpha channel param premultiply alpha true to premultiply the alpha see get premultiply alpha public void set premultiply alpha boolean premultiply alpha this premultiply alpha premultiply alpha premultiplyalpha getpremultiplyalpha setpremultiplyalpha premultiplyalpha premultiplyalpha premultiplyalpha get whether to premultiply the alpha channel return true to premultiply the alpha see set premultiply alpha public boolean get premultiply alpha return premultiply alpha setpremultiplyalpha getpremultiplyalpha premultiplyalpha public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int in pixels new int width height int out pixels new int width height getrgb src 0 0 width height in pixels float sin angle float math sin angle float cos angle float math cos angle float total int cx width 2 int cy height 2 int index 0 float image radius float math sqrt cx cx cy cy float translatex float distance math cos angle float translatey float distance math sin angle float max distance distance math abs rotation image radius zoom image radius int repetitions int max distance affine transform t new affine transform point2d float p new point2d float if premultiply alpha image math premultiply in pixels 0 in pixels length for int y 0 y height y for int x 0 x width x int a 0 r 0 g 0 b 0 int count 0 for int i 0 i repetitions i int newx x newy y float f float i repetitions p x x p y y t set to identity t translate cx f translatex cy f translatey float s 1 zoom f t scale s s if rotation 0 t rotate rotation f t translate cx cy t transform p p newx int p x newy int p y if newx 0 newx width if wrap edges newx image math mod newx width else break if newy 0 newy height if wrap edges newy image math mod newy height else break count int rgb in pixels newy width newx a rgb 24 0xff r rgb 16 0xff g rgb 8 0xff b rgb 0xff if count 0 out pixels index in pixels index else a pixel utils clamp int a count r pixel utils clamp int r count g pixel utils clamp int g count b pixel utils clamp int b count out pixels index a 24 r 16 g 8 b index if premultiply alpha image math unpremultiply out pixels 0 in pixels length setrgb dst 0 0 width height out pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage inpixels outpixels inpixels sinangle cosangle imageradius maxdistance imageradius imageradius maxdistance affinetransform affinetransform premultiplyalpha imagemath inpixels inpixels settoidentity wrapedges imagemath wrapedges imagemath inpixels outpixels inpixels pixelutils pixelutils pixelutils pixelutils outpixels premultiplyalpha imagemath outpixels inpixels outpixels override public string to string return blur motion blur tostring public header tokenizer string text boolean use comments boolean use quotes string specials this text text this specials specials this use comments use comments this use quotes use quotes position 0 last token text null headertokenizer usecomments usequotes usecomments usecomments usequotes usequotes lasttokentext public header tokenizer string text this text text specials default specials use comments use quotes true position 0 last token text null headertokenizer default_specials usecomments usequotes lasttokentext move the current position past any whitespace and comments comments are delimited by parentheses and may be nested ugh private void skip whitespace int nparen 0 while position text length char c text char at position if use comments c comment start nparen else if c nparen 0 comment end nparen else if c nparen 0 position else if c c t c r c n nparen 0 break position skipwhitespace charat usecomments check if any more tokens are available public boolean tokens remaining skip whitespace return position text length tokensremaining skipwhitespace read the next token if we are at the end of the input returns 1 if the next token is a special character returns that character as an integer if the next token is a quoted or unquoted word returns 0 call get token text to read the contents public int get token last token text null if tokens remaining return 1 char c text char at position position if specials index of c 1 c c 127 return c if use quotes c quoted string string builder result new string builder while position text length c text char at position position if c if position text length c text char at position position result append c else if c break else result append c last token text result to string return 0 atom unquoted string int start position 1 while position text length c text char at position if c c 127 use quotes c specials index of c 1 break position last token text text substring start position return 0 gettokentext gettoken lasttokentext tokensremaining charat indexof usequotes stringbuilder stringbuilder charat charat lasttokentext tostring charat usequotes indexof lasttokentext if the previous call to get token returned 0 return the contents of the previous word token public string get token text return last token text gettoken gettokentext lasttokentext this is a caching class loader param name the name of the class to load static public class load string name throws class not found exception class c classes get name if c null c class for name name classes put name c return c classnotfoundexception forname creates a new object of given classname param classname name of class to instantiate public static object get instance string classname throws invocation target exception no such method exception instantiation exception illegal access exception class not found exception return get instance classname new class new object getinstance invocationtargetexception nosuchmethodexception instantiationexception illegalaccessexception classnotfoundexception getinstance creates a new object of given classname param classname name of class to instantiate param argtypes the classes of the arguments param args the arguments since this uses the reflect methods it s ok to wrap primitives public static object get instance string classname class argtypes object args throws invocation target exception no such method exception instantiation exception illegal access exception class not found exception return get instance load classname argtypes args getinstance invocationtargetexception nosuchmethodexception instantiationexception illegalaccessexception classnotfoundexception getinstance creats a new object of a given class param c the class to instantiate param argtypes the classes of the arguments param args the arguments since this uses the reflect methods it s ok to wrap primitives public static object get instance class c class argtypes object args throws invocation target exception no such method exception instantiation exception illegal access exception constructor con c get constructor argtypes return con new instance args getinstance invocationtargetexception nosuchmethodexception instantiationexception illegalaccessexception getconstructor newinstance private float amount 0 5f public glow filter radius 2 glowfilter set the amount of glow param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of glow return the amount see set amount public float get amount return amount setamount getamount override public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int in pixels new int width height int out pixels new int width height src getrgb 0 0 width height in pixels 0 width if radius 0 convolve and transpose kernel in pixels out pixels width height alpha alpha premultiply alpha false clamp edges convolve and transpose kernel out pixels in pixels height width alpha false alpha premultiply alpha clamp edges src getrgb 0 0 width height out pixels 0 width float a 4 amount int index 0 for int y 0 y height y for int x 0 x width x int rgb1 out pixels index int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int rgb2 in pixels index int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff r1 pixel utils clamp int r1 a r2 g1 pixel utils clamp int g1 a g2 b1 pixel utils clamp int b1 a b2 in pixels index rgb1 0xff000000 r1 16 g1 8 b1 index dst setrgb 0 0 width height in pixels 0 width return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage inpixels outpixels inpixels convolveandtranspose inpixels outpixels premultiplyalpha clamp_edges convolveandtranspose outpixels inpixels premultiplyalpha clamp_edges outpixels outpixels inpixels pixelutils pixelutils pixelutils inpixels inpixels override public string to string return blur glow tostring public static network interface create int port string bind to string allowed hosts executor executor boolean ignore unbindableip6 throws io exception network interface iface new ssl network interface port allowed hosts executor try iface set bind to bind to ignore unbindableip6 catch io exception e try iface close catch io exception e1 logger error network interface class caught e1 closing after catching e binding while constructing e1 ignore throw e return iface networkinterface bindto allowedhosts ignoreunbindableip6 ioexception networkinterface sslnetworkinterface allowedhosts setbindto bindto ignoreunbindableip6 ioexception ioexception networkinterface see link network interface protected ssl network interface int port string allowed hosts executor executor throws io exception super port allowed hosts executor networkinterface sslnetworkinterface allowedhosts ioexception allowedhosts inherit doc override protected server socket create server socket throws io exception server socket server socket ssl create server socket ssl server socket server socket set need client auth require client authentication return server socket inheritdoc serversocket createserversocket ioexception serversocket serversocket createserversocket sslserversocket serversocket setneedclientauth requireclientauthentication serversocket set true if client authentication is required param value true or false public void set require client authentication boolean value require client authentication value setrequireclientauthentication requireclientauthentication private transient int update counter rtreer2 updatecounter rtreer2 rtreer2 storage storage super storage public void put rectangler2 r t obj if root null root new rtreer2 page get storage obj r height 1 else rtreer2 page p root insert get storage r obj height if p null root new rtreer2 page get storage root p height 1 n 1 update counter 1 modify rtreer2page getstorage rtreer2page getstorage rtreer2page getstorage updatecounter public int size return n public void remove rectangler2 r t obj if root null throw new storage error storage error key not found array list reinsert list new array list int reinsert level root remove r obj height reinsert list if reinsert level 0 throw new storage error storage error key not found for int i reinsert list size i 0 rtreer2 page p rtreer2 page reinsert list get i for int j 0 n p n j n j rtreer2 page q root insert get storage p b j p branch get j height reinsert level if q null root splitted root new rtreer2 page get storage root q height 1 reinsert level 1 p deallocate if root n 1 height 1 rtreer2 page new root rtreer2 page root branch get 0 root deallocate root new root height 1 n 1 update counter 1 modify storageerror storageerror key_not_found arraylist reinsertlist arraylist reinsertlevel reinsertlist reinsertlevel storageerror storageerror key_not_found reinsertlist rtreer2page rtreer2page reinsertlist rtreer2page getstorage reinsertlevel rtreer2page getstorage reinsertlevel rtreer2page newroot rtreer2page newroot updatecounter public i persistent get rectangler2 r array list result new array list if root null root find r result height return i persistent result to array new i persistent result size ipersistent arraylist arraylist ipersistent toarray ipersistent public array list t get list rectangler2 r array list t result new array list t if root null root find r result height return result arraylist getlist arraylist arraylist public rectangler2 get wrapping rectangle if root null return root cover return null getwrappingrectangle public void clear if root null root purge height root null height 0 n 0 update counter 1 modify updatecounter public void deallocate clear super deallocate public object to array return get get wrapping rectangle toarray getwrappingrectangle public e e to array e arr return get list get wrapping rectangle to array arr toarray getlist getwrappingrectangle toarray class rtree iterator e extends iterable iterator e implements persistent iterator rtree iterator rectangler2 r counter update counter if height 0 return this r r page stack new rtreer2 page height pos stack new int height if goto first item 0 root page stack null pos stack null rtreeiterator iterableiterator persistentiterator rtreeiterator updatecounter pagestack rtreer2page posstack gotofirstitem pagestack posstack public boolean has next if counter update counter throw new concurrent modification exception return page stack null hasnext updatecounter concurrentmodificationexception pagestack protected object current int sp return page stack sp branch get pos stack sp pagestack posstack public e next if has next throw new no such element exception e curr e current height 1 if goto next item height 1 page stack null pos stack null return curr hasnext nosuchelementexception gotonextitem pagestack posstack public int next oid if has next throw new no such element exception int oid page stack height 1 branch get raw pos stack height 1 get oid if goto next item height 1 page stack null pos stack null return oid nextoid hasnext nosuchelementexception pagestack getraw posstack getoid gotonextitem pagestack posstack private boolean goto first item int sp rtreer2 page pg for int i 0 n pg n i n i if r intersects pg b i if sp 1 height goto first item sp 1 rtreer2 page pg branch get i page stack sp pg pos stack sp i return true return false gotofirstitem rtreer2page gotofirstitem rtreer2page pagestack posstack private boolean goto next item int sp rtreer2 page pg page stack sp for int i pos stack sp n pg n i n if r intersects pg b i if sp 1 height goto first item sp 1 rtreer2 page pg branch get i page stack sp pg pos stack sp i return true page stack sp null return sp 0 goto next item sp 1 false gotonextitem rtreer2page pagestack posstack gotofirstitem rtreer2page pagestack posstack pagestack gotonextitem public void remove throw new unsupported operation exception unsupportedoperationexception int pos public rectangler2 get key return pg b pos getkey public t get value return t pg branch get pos getvalue public t set value t value throw new unsupported operation exception setvalue unsupportedoperationexception rtree entry rtreer2 page pg int pos this pg pg this pos pos rtreeentry rtreer2page class rtree entry iterator extends rtree iterator map entry rectangler2 t rtree entry iterator rectangler2 r super r rtreeentryiterator rtreeiterator rtreeentryiterator protected object current int sp return new rtree entry page stack sp pos stack sp rtreeentry pagestack posstack public iterator t iterator return iterator get wrapping rectangle getwrappingrectangle public iterable iterator map entry rectangler2 t entry iterator return entry iterator get wrapping rectangle iterableiterator entryiterator entryiterator getwrappingrectangle public iterable iterator t iterator rectangler2 r return new rtree iterator t r iterableiterator rtreeiterator public iterable iterator map entry rectangler2 t entry iterator rectangler2 r return new rtree entry iterator r iterableiterator entryiterator rtreeentryiterator public final class overlay composite extends rgb composite public overlay composite float alpha super alpha overlaycomposite rgbcomposite overlaycomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob int t if dir 128 t dir sr 0x80 dor 2 t 8 t 8 else t 255 dir 255 sr 0x80 dor 2 255 t 8 t 8 if dig 128 t dig sg 0x80 dog 2 t 8 t 8 else t 255 dig 255 sg 0x80 dog 2 255 t 8 t 8 if dib 128 t dib sb 0x80 dob 2 t 8 t 8 else t 255 dib 255 sb 0x80 dob 2 255 t 8 t 8 float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac uri newuri public redirect exception super redirectexception public redirect exception string newuri throws uri syntax exception this newuri new uri newuri redirectexception urisyntaxexception public redirect exception uri newuri this newuri newuri redirectexception public sharpen filter super sharpen matrix sharpenfilter sharpenmatrix override public string to string return blur sharpen tostring public strong hash table int initial capacity threshold int initial capacity load factor if initial capacity 0 table new entry initial capacity modified new i persistent modified buffer size stronghashtable initialcapacity initialcapacity loadfactor initialcapacity initialcapacity ipersistent modified_buffer_size public synchronized boolean remove int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index prev null e null prev e e e next if e oid oid e obj null count 1 if prev null prev next e next else tab index e next return true return false public synchronized void put int oid i persistent obj entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid e obj obj return if count threshold flushing rehash the table if the threshold is exceeded rehash tab table index oid 0x7fffffff tab length creates the new entry tab index new entry oid obj tab index count ipersistent public synchronized i persistent get int oid entry tab table int index oid 0x7fffffff tab length for entry e tab index e null e e next if e oid oid return e obj return null ipersistent void rehash int old capacity table length entry old map table int i int new capacity old capacity 2 1 entry new map new entry new capacity threshold int new capacity load factor table new map for i old capacity i 0 for entry old old map i old null entry e old old old next int index e oid 0x7fffffff new capacity e next new map index new map index e oldcapacity oldmap newcapacity oldcapacity newmap newcapacity newcapacity loadfactor newmap oldcapacity oldmap newcapacity newmap newmap public synchronized void flush if n modified modified buffer size i persistent mod modified for int i n modified i 0 i persistent obj mod i if obj is modified obj store else entry tab table flushing true for int i 0 i tab length i for entry e tab i e null e e next if e obj is modified e obj store flushing false if count threshold rehash the table if the threshold is exceeded rehash n modified 0 nmodified modified_buffer_size ipersistent nmodified ipersistent ismodified ismodified nmodified public synchronized void clear entry tab table for int i 0 i tab length i tab i null count 0 n modified 0 nmodified public synchronized void invalidate for int i 0 i table length i for entry e table i e null e e next if e obj is modified e obj invalidate table i null count 0 n modified 0 ismodified nmodified public synchronized void set dirty i persistent obj if n modified modified buffer size modified n modified obj setdirty ipersistent nmodified modified_buffer_size nmodified public void clear dirty i persistent obj cleardirty ipersistent public int size return count public void preprocess entry int oid i persistent obj entry chain next chain this oid oid this obj obj ipersistent protected static float the matrix 0 1f 0 1f 0 1f 0 1f 0 2f 0 1f 0 1f 0 1f 0 1f public average filter super the matrix thematrix averagefilter thematrix override public string to string return blur average blur tostring public plugin reply sender direct node node2 fred plugin talker target2 string pluginname2 string identifier2 super pluginname2 identifier2 node node2 target target2 pluginreplysenderdirect fredplugintalker override public void send final simple field set params final bucket bucket node executor execute new runnable public void run try target on reply pluginname identifier params bucket catch throwable t logger error this cought error while handling plugin reply t get message t fcp plugin reply runner for pluginname simplefieldset onreply getmessage fcpplugin public void run try target on reply pluginname identifier params bucket catch throwable t logger error this cought error while handling plugin reply t get message t onreply getmessage final boolean global public sending to network message string id boolean global2 this identifier id this global global2 sendingtonetworkmessage override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put global global return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle override public string get name return name getname override public void remove from object container container container delete this removefrom objectcontainer override public void run fcp connection handler handler node node throws message invalid exception not possible fcpconnectionhandler messageinvalidexception public class close connection duplicate client name message extends fcp message override public simple field set get field set return new simple field set true closeconnectionduplicateclientnamemessage fcpmessage simplefieldset getfieldset simplefieldset override public string get name return close connection duplicate client name getname closeconnectionduplicateclientname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message close connection duplicate client name goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message closeconnectionduplicateclientname override public void remove from object container container container delete this removefrom objectcontainer public abstract class config callback t get the current used value of the config variable public abstract t get configcallback set the config variable to a new value param val the new value throws invalid config option exception if the new value is invalid for this particular option invalidconfigoptionexception public abstract void set t val throws invalid config value exception node need restart exception public boolean is read only return false invalidconfigvalueexception nodeneedrestartexception isreadonly initializes the xml creator parser and caches those objects in the new identityxml object so that they do not have to be initialized each time an identity is exported imported public xml transformer wot my wot throws parser configuration exception transformer configuration exception transformer factory configuration error m wot my wot mdb m wot getdb document builder factory xml factory document builder factory new instance xml factory set feature xml constants feature secure processing true dom parser uses set attribute to pass to underlying xerces xml factory set attribute http apache org xml features disallow doctype decl true m document builder xml factory new document builder mdom m document builder getdom implementation m serializer transformer factory new instance new transformer m serializer set output property output keys encoding utf 8 m serializer set output property output keys indent yes fixme set to no before release m serializer set output property output keys standalone no xmltransformer mywot parserconfigurationexception transformerconfigurationexception transformerfactoryconfigurationerror mwot mywot mwot documentbuilderfactory xmlfactory documentbuilderfactory newinstance xmlfactory setfeature xmlconstants feature_secure_processing setattribute xmlfactory setattribute mdocumentbuilder xmlfactory newdocumentbuilder mdocumentbuilder getdomimplementation mserializer transformerfactory newinstance newtransformer mserializer setoutputproperty outputkeys mserializer setoutputproperty outputkeys mserializer setoutputproperty outputkeys public synchronized void export own identity own identity identity output stream os throws transformer exception document xml doc mdom create document null wot wot name null element root element xml doc get document element create the identity element element identity element xml doc create element identity identity element set attribute version integer to string xml format version version of the xml format synchronized m wot synchronized identity identity element set attribute name identity get nickname identity element set attribute publishes trust list boolean to string identity does publish trust list create the context elements for string context identity get contexts element context element xml doc create element context context element set attribute name context identity element append child context element create the property elements for entry string string property identity get properties entry set element property element xml doc create element property property element set attribute name property get key property element set attribute value property get value identity element append child property element create the trust list element and its trust elements element trust list element xml doc create element trust list for trust trust m wot get given trusts identity we should make very sure that we do not reveal the other own identity s if trust get truster identity throw new runtime exception error in wot it is trying to export trust values of someone else in the trust list of identity trust value from trust get truster element trust element xml doc create element trust trust element set attribute identity trust get trustee get requesturi to string trust element set attribute value byte to string trust get value trust element set attribute comment trust get comment trust list element append child trust element identity element append child trust list element root element append child identity element dom source dom source new dom source xml doc stream result result stream new stream result os m serializer transform dom source result stream exportownidentity ownidentity outputstream transformerexception xmldoc createdocument wot_name rootelement xmldoc getdocumentelement identityelement xmldoc createelement identityelement setattribute tostring xml_format_version mwot identityelement setattribute getnickname identityelement setattribute publishestrustlist tostring doespublishtrustlist getcontexts contextelement xmldoc createelement contextelement setattribute identityelement appendchild contextelement getproperties entryset propertyelement xmldoc createelement propertyelement setattribute getkey propertyelement setattribute getvalue identityelement appendchild propertyelement trustlistelement xmldoc createelement trustlist mwot getgiventrusts gettruster runtimeexception gettruster trustelement xmldoc createelement trustelement setattribute gettrustee getrequesturi tostring trustelement setattribute tostring getvalue trustelement setattribute getcomment trustlistelement appendchild trustelement identityelement appendchild trustlistelement rootelement appendchild identityelement domsource domsource domsource xmldoc streamresult resultstream streamresult mserializer domsource resultstream imports a identity xml file into the given web of trust this includes the identity itself and its attributes the trust list of the identity if it has published one in the xml if the identity does not exist yet it is created if it does the existing one is updated param xml input stream the input stream containing the xml public synchronized void import identity freeneturi identityuri input stream xml input stream throws exception document xml m document builder parse xml input stream element identity element element xml get elements by tag name identity item 0 if integer parse int identity element get attribute version xml format version throw new exception version identity element get attribute version xml format version string identity name identity element get attribute name boolean identity publishes trust list boolean parse boolean identity element get attribute publishes trust list array list string identity contexts new array list string 4 node list context list identity element get elements by tag name context for int i 0 i context list get length i element context element element context list item i identity contexts add context element get attribute name hash map string string identity properties new hash map string string 8 node list property list identity element get elements by tag name property for int i 0 i property list get length i element property element element property list item i identity properties put property element get attribute name property element get attribute value we tried to parse as much as we can without synchronization before we lock everything synchronized m wot identity identity boolean is new identity false try identity m wot get identity byuri identityuri catch unknown identity exception e identity new identity identityuri identity name identity publishes trust list is new identity true synchronized identity identity set edition identityuri get edition identity on fetched we store the identity and especially it s edition right now so that bogus xml files are skipped m wot store and commit identity try identity set nickname identity name catch exception e nickname changes are not allowed ignore them logger error identityuri set nickname failed e try failure of context importing should not make an identity disappear therefore we catch exceptions identity set contexts identity contexts catch exception e logger error identityuri set contexts failed e try failure of property importing should not make an identity disappear therefore we catch exceptions identity set properties identity properties catch exception e logger error identityuri set properties failed e we store the identity even if it s trust list import fails identities should not disappear then m wot store and commit identity if identity publishes trust list this try block is for rolling back in catch if an exception is thrown during trust list import our policy is we either import the whole trust list or nothing we should not bias the trust system by allowing the import of partial trust lists especially we should not ignore failing deletions of old trust objects try boolean trustee creation allowed m wot get best score identity 0 identity instanceof own identity element trust list element element identity element get elements by tag name trust list item 0 node list trust list trust list element get elements by tag name trust for int i 0 i trust list get length i element trust element element trust list item i string trusteeuri trust element get attribute identity byte trust value byte parse byte trust element get attribute value string trust comment trust element get attribute comment identity trustee null try trustee m wot get identity byuri trusteeuri catch unknown identity exception e if trustee creation allowed we only create trustees if the truster has a positive score trustee new identity trusteeuri null false mdb store trustee m wot get identity fetcher fetch trustee if trustee null m wot set trust without commit identity trustee trust value trust comment if is new identity delete trust objects of trustees which were removed from the trust list for trust trust m wot get given trusts older than identity identityuri get edition m wot remove trust without commit trust m wot store and commit identity catch exception e mdb rollback logger error identityuri importing trust list failed e xmlinputstream importidentity inputstream xmlinputstream mdocumentbuilder xmlinputstream identityelement getelementsbytagname parseint identityelement getattribute xml_format_version identityelement getattribute xml_format_version identityname identityelement getattribute identitypublishestrustlist parseboolean identityelement getattribute publishestrustlist arraylist identitycontexts arraylist nodelist contextlist identityelement getelementsbytagname contextlist getlength contextelement contextlist identitycontexts contextelement getattribute hashmap identityproperties hashmap nodelist propertylist identityelement getelementsbytagname propertylist getlength propertyelement propertylist identityproperties propertyelement getattribute propertyelement getattribute mwot isnewidentity mwot getidentitybyuri unknownidentityexception identityname identitypublishestrustlist isnewidentity setedition getedition onfetched mwot storeandcommit setnickname identityname setnickname setcontexts identitycontexts setcontexts setproperties identityproperties setproperties mwot storeandcommit identitypublishestrustlist trusteecreationallowed mwot getbestscore ownidentity trustlistelement identityelement getelementsbytagname trustlist nodelist trustlist trustlistelement getelementsbytagname trustlist getlength trustelement trustlist trustelement getattribute trustvalue parsebyte trustelement getattribute trustcomment trustelement getattribute mwot getidentitybyuri unknownidentityexception trusteecreationallowed mwot getidentityfetcher mwot settrustwithoutcommit trustvalue trustcomment isnewidentity mwot getgiventrustsolderthan getedition mwot removetrustwithoutcommit mwot storeandcommit public synchronized void export introduction own identity identity output stream os throws transformer exception document xml doc mdom create document null wot wot name null element root element xml doc get document element element intro element xml doc create element identity introduction intro element set attribute version integer to string xml format version version of the xml format element identity element xml doc create element identity identity element set attribute uri identity get requesturi to string intro element append child identity element root element append child intro element dom source dom source new dom source xml doc stream result result stream new stream result os m serializer transform dom source result stream exportintroduction ownidentity outputstream transformerexception xmldoc createdocument wot_name rootelement xmldoc getdocumentelement introelement xmldoc createelement identityintroduction introelement setattribute tostring xml_format_version identityelement xmldoc createelement identityelement setattribute getrequesturi tostring introelement appendchild identityelement rootelement appendchild introelement domsource domsource domsource xmldoc streamresult resultstream streamresult mserializer domsource resultstream creates an identity from an identity introduction stores it in the database and returns the new identity if the identity already exists the existing identity is returned throws invalid parameter exception throws io exception throws sax exception public identity import introduction own identity puzzle owner input stream xml input stream throws invalid parameter exception sax exception io exception freeneturi identityuri identity new identity synchronized this document xml m document builder parse xml input stream element introduction element element xml get elements by tag name identity introduction item 0 if integer parse int introduction element get attribute version xml format version throw new invalid parameter exception version introduction element get attribute version xml format version element identity element element introduction element get elements by tag name identity item 0 identityuri new freeneturi identity element get attribute uri synchronized m wot try new identity m wot get identity byuri identityuri logger minor this imported introduction for an already existing identity new identity catch unknown identity exception e new identity new identity identityuri null false m wot store and commit new identity try m wot get trust puzzle owner new identity double check logger error new identity the identity is already trusted even though it did not exist catch not trusted exception ex fixme we need null trust giving trust by solving captchas is a bad idea because they receive capacity for giving trust to others by that m wot set trust without commit puzzle owner new identity byte 0 trust received by solving a captcha m wot get identity fetcher fetch new identity return new identity invalidparameterexception ioexception saxexception importintroduction ownidentity puzzleowner inputstream xmlinputstream invalidparameterexception saxexception ioexception newidentity mdocumentbuilder xmlinputstream introductionelement getelementsbytagname identityintroduction parseint introductionelement getattribute xml_format_version invalidparameterexception introductionelement getattribute xml_format_version identityelement introductionelement getelementsbytagname identityelement getattribute mwot newidentity mwot getidentitybyuri newidentity unknownidentityexception newidentity mwot storeandcommit newidentity mwot gettrust puzzleowner newidentity newidentity nottrustedexception mwot settrustwithoutcommit puzzleowner newidentity mwot getidentityfetcher newidentity newidentity public synchronized void export introduction puzzle introduction puzzle puzzle output stream os throws transformer exception parser configuration exception document xml doc mdom create document null wot wot name null element root element xml doc get document element element puzzle element xml doc create element introduction puzzle puzzle element set attribute version integer to string xml format version version of the xml format todo this lock is actually not neccessary because all values which are taken from the puzzle are final decide whether anything else which is bad can happen if we do not synchronize for example how does db4o handle deletion of objects if they are still referenced somewhere synchronized puzzle puzzle element set attribute id puzzle getid puzzle element set attribute type puzzle get type to string puzzle element set attribute mime type puzzle get mime type puzzle element set attribute valid until time long to string puzzle get valid until time element data element xml doc create element data data element set attribute value base64 encode standard puzzle get data puzzle element append child data element root element append child puzzle element dom source dom source new dom source xml doc stream result result stream new stream result os m serializer transform dom source result stream exportintroductionpuzzle introductionpuzzle outputstream transformerexception parserconfigurationexception xmldoc createdocument wot_name rootelement xmldoc getdocumentelement puzzleelement xmldoc createelement introductionpuzzle puzzleelement setattribute tostring xml_format_version puzzleelement setattribute puzzleelement setattribute gettype tostring puzzleelement setattribute mimetype getmimetype puzzleelement setattribute validuntiltime tostring getvaliduntiltime dataelement xmldoc createelement dataelement setattribute encodestandard getdata puzzleelement appendchild dataelement rootelement appendchild puzzleelement domsource domsource domsource xmldoc streamresult resultstream streamresult mserializer domsource resultstream public introduction puzzle import introduction puzzle freeneturi puzzleuri input stream xml input stream throws sax exception io exception invalid parameter exception unknown identity exception illegal base64 exception parse exception string puzzleid introduction puzzle puzzle type puzzle type string puzzle mime type long puzzle valid until time byte puzzle data synchronized this document xml m document builder parse xml input stream element puzzle element element xml get elements by tag name introduction puzzle item 0 if integer parse int puzzle element get attribute version xml format version throw new invalid parameter exception version puzzle element get attribute version xml format version puzzleid puzzle element get attribute id puzzle type introduction puzzle puzzle type value of puzzle element get attribute type puzzle mime type puzzle element get attribute mime type puzzle valid until time long parse long puzzle element get attribute valid until time element data element element puzzle element get elements by tag name data item 0 puzzle data base64 decode standard data element get attribute value introduction puzzle puzzle synchronized m wot identity puzzle inserter m wot get identity byuri puzzleuri puzzle new introduction puzzle puzzle inserter puzzleid puzzle type puzzle mime type puzzle data puzzle valid until time introduction puzzle get date from requesturi puzzleuri introduction puzzle get index from requesturi puzzleuri m wot get introduction puzzle store store and commit puzzle return puzzle introductionpuzzle importintroductionpuzzle inputstream xmlinputstream saxexception ioexception invalidparameterexception unknownidentityexception illegalbase64exception parseexception introductionpuzzle puzzletype puzzletype puzzlemimetype puzzlevaliduntiltime puzzledata mdocumentbuilder xmlinputstream puzzleelement getelementsbytagname introductionpuzzle parseint puzzleelement getattribute xml_format_version invalidparameterexception puzzleelement getattribute xml_format_version puzzleelement getattribute puzzletype introductionpuzzle puzzletype valueof puzzleelement getattribute puzzlemimetype puzzleelement getattribute mimetype puzzlevaliduntiltime parselong puzzleelement getattribute validuntiltime dataelement puzzleelement getelementsbytagname puzzledata decodestandard dataelement getattribute introductionpuzzle mwot puzzleinserter mwot getidentitybyuri introductionpuzzle puzzleinserter puzzletype puzzlemimetype puzzledata puzzlevaliduntiltime introductionpuzzle getdatefromrequesturi introductionpuzzle getindexfromrequesturi mwot getintroductionpuzzlestore storeandcommit public generic read filter callback uri uri founduri callback cb this baseuri uri this cb cb set strippeduri uri to string genericreadfiltercallback founduricallback setstrippeduri tostring public generic read filter callback freeneturi uri founduri callback cb try this baseuri uri to relativeuri set strippeduri baseuri to string this cb cb catch uri syntax exception e throw new error e genericreadfiltercallback founduricallback torelativeuri setstrippeduri tostring urisyntaxexception private void set strippeduri string u int idx u last index of if idx 0 u u substring 0 idx 1 try stripped baseuri new uri u catch uri syntax exception e logger error this can t strip base uri e parsing u stripped baseuri baseuri else stripped baseuri baseuri setstrippeduri lastindexof strippedbaseuri urisyntaxexception strippedbaseuri strippedbaseuri public string processuri string u string override type throws comment exception return processuri u override type false false overridetype commentexception overridetype public string processuri string u string override type boolean no relative boolean inline throws comment exception if u matches fragment hack for anchors see 710 return u evil hack see 2451 and r24565 r24566 u u replace all 23 uri uri uri resolved boolean logminor logger should log logger minor this try if logminor logger minor this processing u uri uri pre encoder encodeuri u normalize if logminor logger minor this processing uri if no relative resolved baseuri resolve uri else resolved uri if logminor logger minor this resolved resolved catch uri syntax exception e1 if logminor logger minor this failed to parse uri e1 throw new comment exception l10n could not parseuri with error error e1 get message string path uri get path http request req new http request impl uri if path null if path equals req is parameter set newbookmark allow links to the root to add bookmarks string bookmark key req get param newbookmark string bookmark desc req get param desc string bookmark activelink req get param has an activelink bookmark key html encoder encode bookmark key bookmark desc html encoder encode bookmark desc string url newbookmark bookmark key desc bookmark desc if bookmark activelink equals bookmark activelink html encoder encode bookmark activelink url url has an activelink true return url else if path starts with static toadlet root url see bug 2297 return path string reason try as an absolute uri string rpath uri get path boolean is absolute false if rpath null if logminor logger minor this resolved uri rpath absolute rpath valid freeneturi try string p rpath while p starts with is absolute true p p substring 1 freeneturi furi new freeneturi p if logminor logger minor this parsed furi return processuri furi uri override type no relative inline catch malformedurl exception e not a freeneturi if logminor logger minor this malformed url a e e if e get message null reason l10n malformed absoluteurl error e get message else reason l10n could not parse absolute freeneturi if is absolute relative uri rpath resolved get path if rpath null throw new comment exception no uri if logminor logger minor this resolved uri rpath relative rpath valid freeneturi try string p rpath while p starts with p p substring 1 freeneturi furi new freeneturi p if logminor logger minor this parsed furi return processuri furi uri override type no relative inline catch malformedurl exception e if logminor logger minor this malformed url b e e if e get message null reason l10n malformed relativeurl error e get message else reason l10n could not parse relative freeneturi if generic read filter callback allowed protocols contains uri get scheme return generic read filter callback magichttp escape string uri else if uri get scheme null throw new comment exception reason throw new comment exception l10n protocol not escaped protocol uri get scheme overridetype norelative commentexception replaceall shouldlog uripreencoder norelative urisyntaxexception commentexception couldnotparseuriwitherror getmessage getpath httprequest httprequestimpl isparameterset bookmark_key getparam bookmark_desc getparam bookmark_activelink getparam hasanactivelink bookmark_key htmlencoder bookmark_key bookmark_desc htmlencoder bookmark_desc bookmark_key bookmark_desc bookmark_activelink bookmark_activelink htmlencoder bookmark_activelink hasanactivelink startswith statictoadlet root_url getpath isabsolute startswith isabsolute overridetype norelative malformedurlexception getmessage malformedabsoluteurl getmessage couldnotparseabsolutefreeneturi isabsolute getpath commentexception startswith overridetype norelative malformedurlexception getmessage malformedrelativeurl getmessage couldnotparserelativefreeneturi genericreadfiltercallback allowedprotocols getscheme genericreadfiltercallback magichttpescapestring getscheme commentexception commentexception protocolnotescaped getscheme private static string l10n string key string pattern string value return l10n get string generic read filter callback key pattern value getstring genericreadfiltercallback private static string l10n string key return l10n get string generic read filter callback key getstring genericreadfiltercallback private string finish process http request req string override type string path uri u boolean no relative string type override req get param type null if override type null type override override type redflag any other options we should support obviously we don t want to support force at the moment type and force are the only options supported by f proxy anyway try uri encoding issues freeneturi to string does url encode ing of critical components so if we just pass it in to the component wise constructor we end up encoding twice so get 2520 for a space however we want to support encoded slashes or s in the path so we don t want to just decode before feeding it to the constructor it looks like the best option is to construct it ourselves and then re parse it this is doing unnecessary work it would be much easier if we had a component wise constructor for uri that didn t re encode but at least it works string builder sb new string builder sb append path if type override null sb append type sb append type override if u get fragment null sb append sb append u get raw fragment uri uri new uri sb to string if no relative uri stripped baseuri relativize uri if logger should log logger minor this logger minor this returning uri toascii string from path from baseuri baseuri return uri toascii string catch uri syntax exception e logger error this could not parse own uri path path type override type override frag u get fragment e e string p path if type override null p type type override if u get fragment null try fixme encode it properly p url encoder encode u get fragment utf 8 catch unsupported encoding exception e1 throw new error impossible jvm doesn t support utf 8 e e return p finishprocess httprequest overridetype norelative typeoverride getparam overridetype typeoverride overridetype fproxy tostring urlencode stringbuilder stringbuilder typeoverride typeoverride getfragment getrawfragment tostring norelative strippedbaseuri shouldlog toasciistring toasciistring urisyntaxexception typeoverride typeoverride getfragment typeoverride typeoverride getfragment urlencoder getfragment unsupportedencodingexception private string processuri freeneturi furi uri uri string override type boolean no relative boolean inline valid freenet uri allow it now what about the queries http request req new http request impl uri if cb null cb founduri furi if cb null cb founduri furi inline return finish process req override type furi to string false false uri no relative overridetype norelative httprequest httprequestimpl finishprocess overridetype tostring norelative public string on base href string base href string ret try ret processuri base href null true false catch comment exception e1 logger error this failed to parse base href base href e1 get message ret null if ret null logger error this on base href failed cannot sanitize base href return null else try baseuri new uri ret set strippeduri ret catch uri syntax exception e throw new error e impossible return baseuri toascii string onbasehref basehref basehref commentexception basehref getmessage onbasehref basehref setstrippeduri urisyntaxexception toasciistring public void on text string s string type if cb null cb on text s type baseuri ontext ontext process a form current strategy both post and get forms are allowed to anything that is hazardous should be protected through form password throws comment exception if the form element could not be parsed and the user should be told public string process form string method string action throws comment exception if action null return null if method null method get method method to upper case if method equals post method equals get return null no irregular form sending methods everything is allowed to updating the node shutting it down everything why becuase it s all protected by form password anyway fixme whitelist most things are okay if the user is prompted for a confirmation fixme what about queue friends etc if action equals return action try uri uri uri pre encoder encodeuri action if uri get scheme null uri get host null uri get port 1 uri get user info null throw new comment exception l10n invalid formuri string path uri get path if path starts with plugins prefix string after path substring plugins prefix length if after index of 1 throw new comment exception l10n invalid formuri attempt to escape if after matches a za z0 9 return uri toascii string catch uri syntax exception e throw new comment exception l10n could not parse formuri with error error e get localized message otherwise disallow return null formpassword commentexception processform commentexception touppercase formpassword uripreencoder getscheme gethost getport getuserinfo commentexception invalidformuri getpath startswith plugins_prefix plugins_prefix indexof commentexception invalidformuriattempttoescape toasciistring urisyntaxexception commentexception couldnotparseformuriwitherror getlocalizedmessage public static string escapeurl string uri return magichttp escape string uri magichttpescapestring private string identifier public end list peer notes message string id string identifier this node identifier id this identifier identifier endlistpeernotesmessage nodeidentifier override public simple field set get field set simple field set sfs new simple field set true sfs put single node identifier node identifier if identifier null sfs put single identifier identifier return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle nodeidentifier nodeidentifier putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message end list peer notes goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message endlistpeernotes override public void remove from object container container container delete this removefrom objectcontainer public final class color burn composite extends rgb composite public color burn composite float alpha super alpha colorburncomposite rgbcomposite colorburncomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob if sr 0 dor math max 255 int 255 dir 8 sr 0 else dor sr if sg 0 dog math max 255 int 255 dig 8 sg 0 else dog sg if sb 0 dob math max 255 int 255 dib 8 sb 0 else dob sb float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac caller must create bloom file but it may be empty param new filter if true the bloom file is empty and the bloom filter should be created from scratch throws io exception public split file fetcher key listener split file fetcher parent int key count file bloom file file alt bloom file int main bloom size bytes int main bloomk boolean dont cache byte local salt int segments int segment filter size bytes int segment bloomk boolean persistent boolean new filter throws io exception fetcher parent this persistent persistent this key count key count this main bloom file bloom file this alt bloom file alt bloom file this dont cache dont cache assert local salt length 32 if persistent this local salt new byte 32 system arraycopy local salt 0 this local salt 0 32 else this local salt local salt segments filter buffer new byte segment filter size bytes segments byte buffer base buffer byte buffer wrap segments filter buffer segment filters new binary bloom filter segments int start 0 int end segment filter size bytes for int i 0 i segments i base buffer position start base buffer limit end byte buffer slice base buffer slice segment filters i new binary bloom filter slice segment filter size bytes 8 segment bloomk start segment filter size bytes end segment filter size bytes filter buffer new byte main bloom size bytes if new filter filter new counting bloom filter main bloom size bytes 8 2 main bloomk filter buffer filter set warn on remove from empty else read from file file input stream fis new file input stream bloom file data input stream dis new data input stream fis dis read fully filter buffer dis close filter new counting bloom filter main bloom size bytes 8 2 main bloomk filter buffer filter set warn on remove from empty fis new file input stream alt bloom file dis new data input stream fis dis read fully segments filter buffer dis close if logger should log logger minor this logger minor this created this for fetcher bloomfile newfilter ioexception splitfilefetcherkeylistener splitfilefetcher keycount bloomfile altbloomfile mainbloomsizebytes mainbloomk dontcache localsalt segmentfiltersizebytes segmentbloomk newfilter ioexception keycount keycount mainbloomfile bloomfile altbloomfile altbloomfile dontcache dontcache localsalt localsalt localsalt localsalt localsalt localsalt segmentsfilterbuffer segmentfiltersizebytes bytebuffer basebuffer bytebuffer segmentsfilterbuffer segmentfilters binarybloomfilter segmentfiltersizebytes basebuffer basebuffer bytebuffer basebuffer segmentfilters binarybloomfilter segmentfiltersizebytes segmentbloomk segmentfiltersizebytes segmentfiltersizebytes filterbuffer mainbloomsizebytes newfilter countingbloomfilter mainbloomsizebytes mainbloomk filterbuffer setwarnonremovefromempty fileinputstream fileinputstream bloomfile datainputstream datainputstream readfully filterbuffer countingbloomfilter mainbloomsizebytes mainbloomk filterbuffer setwarnonremovefromempty fileinputstream altbloomfile datainputstream readfully segmentsfilterbuffer shouldlog public long count keys return key count countkeys keycount split file fetcher adds keys in whatever blocks are convenient param keys void add key key key int seg no client context context byte salted key context get chk fetch scheduler salt key key filter add key salted key byte local salted local salt key key segment filters seg no add key local salted if segment filters seg no check filter local salted logger error this key added but not in filter key on this splitfilefetcher addkey segno clientcontext saltedkey getchkfetchscheduler saltkey addkey saltedkey localsalted localsaltkey segmentfilters segno addkey localsalted segmentfilters segno checkfilter localsalted private byte local salt key key key message digest md sha256 get message digest md update key get routing key md update local salt byte ret md digest sha256 return message digest md return ret localsaltkey messagedigest getmessagedigest getroutingkey localsalt returnmessagedigest public boolean probably want key key key byte salted key if filter null logger error this probably want key filter null for this fetcher fetcher return filter check filter salted key probablywantkey saltedkey checkfilter saltedkey public short definitely want key key key byte salted key object container container client context context caller has already called probably want key so don t do it again byte salted local salt key key for int i 0 i segment filters length i if segment filters i check filter salted if persistent if container ext is active fetcher logger error this already active in definitely want key fetcher container activate fetcher 1 split file fetcher segment segment fetcher get segment i if persistent container deactivate fetcher 1 if persistent if container ext is active segment logger error this already active in definitely want key segment container activate segment 1 boolean found segment get block number key container 0 if found logger error this found block in primary and segment bloom filters but segment doesn t want it segment on this if persistent container deactivate segment 1 if found return prio return 1 definitelywantkey saltedkey objectcontainer clientcontext probablywantkey localsaltkey segmentfilters segmentfilters checkfilter isactive definitelywantkey splitfilefetchersegment getsegment isactive definitelywantkey getblocknumber public boolean handle block key key byte salted key key block block object container container client context context caller has already called probably want key so don t do it again boolean found false byte salted local salt key key boolean logminor logger should log logger minor this if logminor logger minor this handle block key on this for fetcher for int i 0 i segment filters length i boolean match synchronized this match segment filters i check filter salted if match if persistent if container ext is stored fetcher logger error this fetcher not in database for this return false if container ext is active fetcher logger error this already activated fetcher container activate fetcher 1 split file fetcher segment segment fetcher get segment i if persistent if container ext is active segment logger error this already activated segment container activate segment 1 if logminor logger minor this key key may be in segment segment if segment on got key key block container context synchronized this if filter check filter salted key filter remove key salted key key count else logger error this not removing key from splitfile filter because already removed key for this new exception debug update the persistent key count fetcher set key count key count container found true if persistent container deactivate segment 1 if persistent container deactivate fetcher 1 return found handleblock saltedkey keyblock objectcontainer clientcontext probablywantkey localsaltkey shouldlog handleblock segmentfilters segmentfilters checkfilter isstored isactive splitfilefetchersegment getsegment isactive ongotkey checkfilter saltedkey removekey saltedkey keycount keycount setkeycount keycount public boolean dont cache return dont cache dontcache dontcache public has key listener get has key listener return fetcher haskeylistener gethaskeylistener public short get priority class object container container return prio getpriorityclass objectcontainer public sendable get get requests for key key key byte salted key object container container client context context array list sendable get ret new array list sendable get caller has already called probably want key so don t do it again byte salted local salt key key for int i 0 i segment filters length i if segment filters i check filter salted if persistent if container ext is active fetcher logger error this already activated in get requests for key fetcher container activate fetcher 1 split file fetcher segment segment fetcher get segment i if persistent container deactivate fetcher 1 if persistent if container ext is active segment logger error this already activated in get requests for key segment container activate segment 1 int block num segment get block number key container if block num 0 ret add segment get sub segment for block num container if persistent container deactivate segment 1 return ret to array new sendable get ret size sendableget getrequestsforkey saltedkey objectcontainer clientcontext arraylist sendableget arraylist sendableget probablywantkey localsaltkey segmentfilters segmentfilters checkfilter isactive getrequestsforkey splitfilefetchersegment getsegment isactive getrequestsforkey blocknum getblocknumber blocknum getsubsegmentfor blocknum toarray sendableget public void on remove synchronized this killed true if persistent main bloom file delete alt bloom file delete onremove mainbloomfile altbloomfile public boolean persistent return persistent public void write filters throws io exception if persistent return synchronized this if killed return random access file raf new random access file main bloom file rw raf write filter buffer raf close raf new random access file alt bloom file rw raf write segments filter buffer raf close writefilters ioexception randomaccessfile randomaccessfile mainbloomfile filterbuffer randomaccessfile altbloomfile segmentsfilterbuffer public synchronized int kill segment split file fetcher segment segment object container container client context context int seg no segment seg num segment filters seg no unset all key remove keys segment list keys container if logger should log logger minor this logger minor this removing segment from bloom filter segment keys remove keys length for int i 0 i remove keys length i if logger should log logger minor this logger minor this removing key from bloom filter remove keys i byte salted context get chk fetch scheduler salt key remove keys i if filter check filter salted filter remove key salted else huh logger error this removing key remove keys i for this from segment not in bloom filter new exception debug schedule write filters context return key count remove keys length killsegment splitfilefetchersegment objectcontainer clientcontext segno segnum segmentfilters segno unsetall removekeys listkeys shouldlog removekeys removekeys shouldlog removekeys getchkfetchscheduler saltkey removekeys checkfilter removekey removekeys schedulewritefilters keycount removekeys arrange to write the filters at some point after this transaction is committed private void schedule write filters client context context synchronized this worst case we end up blocking the database thread while a write completes off thread common case the write executes on a separate thread don t run the write at too low a priority or we may get priority inversion if writing bloom filter return writing bloom filter true try context ticker queue timed job new prio runnable public void run synchronized split file fetcher key listener this try write filters catch io exception e logger error this failed to write bloom filters we will have more false positives on already found blocks which aren t in the store e e finally writing bloom filter true public int get priority don t run the write at too low a priority or we may get priority inversion return native thread high priority write delay catch throwable t writing bloom filter false schedulewritefilters clientcontext writingbloomfilter writingbloomfilter queuetimedjob priorunnable splitfilefetcherkeylistener writefilters ioexception writingbloomfilter getpriority nativethread high_priority write_delay writingbloomfilter public void run synchronized split file fetcher key listener this try write filters catch io exception e logger error this failed to write bloom filters we will have more false positives on already found blocks which aren t in the store e e finally writing bloom filter true splitfilefetcherkeylistener writefilters ioexception writingbloomfilter public int get priority don t run the write at too low a priority or we may get priority inversion return native thread high priority getpriority nativethread high_priority public boolean is empty fixme we rely on split file fetcher unregistering itself maybe we should keep track of how many segments have been cleared we d have to be sure that they weren t cleared twice return killed isempty splitfilefetcher public boolean isssk return false public void object on deactivate object container container logger error this deactivating a split file fetcher key listener this new exception error objectondeactivate objectcontainer splitfilefetcherkeylistener public transfer thread node my node high level simple client my client string my name m node my node m client my client mtbf m node client core temp bucket factory m name my name transferthread mynode highlevelsimpleclient myclient myname mnode mynode mclient myclient mnode clientcore tempbucketfactory mname myname protected void start m node executor execute this m name logger debug this started mnode mname specify the priority of this thread priorities to return can be found in class native thread public abstract int get priority nativethread getpriority public void run is running true m thread thread current thread try thread sleep get startup delay catch interrupted exception e m thread interrupt try while is running thread interrupted try logger debug this loop running iterate long sleep time get sleep time logger debug this loop finished sleeping for sleep time 1000 60 minutes thread sleep sleep time catch interrupted exception e m thread interrupt catch exception e logger error this error in iterate probably e finally try abort all transfers catch runtime exception e logger error this should not happen please report this exception e finally synchronized this shutdown finished true notify isrunning mthread currentthread getstartupdelay interruptedexception mthread isrunning sleeptime getsleeptime sleeptime sleeptime interruptedexception mthread abortalltransfers runtimeexception shutdownfinished wakes up the thread so that iterate is called public void next iteration m thread interrupt nextiteration mthread protected void abort all transfers logger debug this trying to stop all fetches inserts abort fetches abort inserts abortalltransfers abortfetches abortinserts protected void abort fetches logger debug this trying to stop all fetches if m fetches null synchronized m fetches client getter fetches m fetches to array new client getter m fetches size int fcounter 0 for client getter fetch fetches this calls on failure which removes the fetch from m fetches on the same thread therefore we need to copy to an array fetch cancel null m node client core client context fcounter logger debug this stopped fcounter current fetches abortfetches mfetches mfetches clientgetter mfetches toarray clientgetter mfetches clientgetter onfailure mfetches mnode clientcore clientcontext protected void abort inserts logger debug this trying to stop all inserts if m inserts null synchronized m inserts base client putter inserts m inserts to array new base client putter m inserts size int icounter 0 for base client putter insert inserts this calls on failure which removes the fetch from m fetches on the same thread therefore we need to copy to an array insert cancel null m node client core client context icounter logger debug this stopped icounter current inserts abortinserts minserts minserts baseclientputter minserts toarray baseclientputter minserts baseclientputter onfailure mfetches mnode clientcore clientcontext protected void add fetch client getter g synchronized m fetches m fetches add g addfetch clientgetter mfetches mfetches protected void remove fetch client getter g synchronized m fetches m fetches remove g logger debug this removed request for g geturi removefetch clientgetter mfetches mfetches protected void add insert base client putter p synchronized m inserts m inserts add p addinsert baseclientputter minserts minserts protected void remove insert base client putter p synchronized m inserts m inserts remove p logger debug this removed insert for p geturi removeinsert baseclientputter minserts minserts protected int fetch count synchronized m fetches return m fetches size fetchcount mfetches mfetches protected int insert count synchronized m inserts return m inserts size insertcount minserts minserts public void terminate logger debug this terminating is running false m thread interrupt synchronized this while shutdown finished try wait catch interrupted exception e thread interrupted logger debug this terminated isrunning mthread shutdownfinished interruptedexception protected abstract collection client getter create fetch storage clientgetter createfetchstorage protected abstract collection client getter create fetch storage protected abstract collection base client putter create insert storage clientgetter createfetchstorage baseclientputter createinsertstorage protected abstract collection base client putter create insert storage protected abstract long get startup delay baseclientputter createinsertstorage getstartupdelay protected abstract long get startup delay protected abstract long get sleep time getstartupdelay getsleeptime protected abstract long get sleep time called by the transfer thread after get startup delay milliseconds for the first time and then after each get sleep time milliseconds protected abstract void iterate getsleeptime transferthread getstartupdelay getsleeptime fetches you have to do finally remove fetch when using this function public abstract void on success fetch result result client getter state object container container removefetch onsuccess fetchresult clientgetter objectcontainer public abstract void on success fetch result result client getter state object container container you have to do finally remove fetch when using this function public abstract void on failure fetch exception e client getter state object container container onsuccess fetchresult clientgetter objectcontainer removefetch onfailure fetchexception clientgetter objectcontainer inserts you have to do finally remove insert when using this function public abstract void on success base client putter state object container container removeinsert onsuccess baseclientputter objectcontainer public abstract void on success base client putter state object container container you have to do finally remove insert when using this function public abstract void on failure insert exception e base client putter state object container container onsuccess baseclientputter objectcontainer removeinsert onfailure insertexception baseclientputter objectcontainer public abstract void on failure insert exception e base client putter state object container container public abstract void on fetchable base client putter state object container container onfailure insertexception baseclientputter objectcontainer onfetchable baseclientputter objectcontainer public abstract void on fetchable base client putter state object container container public abstract void on generateduri freeneturi uri base client putter state object container container onfetchable baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer public abstract void on generateduri freeneturi uri base client putter state object container container called when freenet async thinks that the request should be serialized to disk if it is a persistent request public abstract void on major progress object container container ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer public abstract void on major progress object container container public boolean object can new object container container logger error this not storing transfer thread in database new exception error return false onmajorprogress objectcontainer objectcannew objectcontainer transferthread public class maximum filter extends whole image filter public maximum filter maximumfilter wholeimagefilter maximumfilter override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int pixel 0xff000000 for int dy 1 dy 1 dy int iy y dy int ioffset if 0 iy iy height ioffset iy width for int dx 1 dx 1 dx int ix x dx if 0 ix ix width pixel pixel utils combine pixels pixel in pixels ioffset ix pixel utils max out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels pixelutils combinepixels inpixels pixelutils outpixels outpixels override public string to string return blur maximum tostring public cellular function2d results new point 2 for int j 0 j results length j results j new point cellularfunction2d public void set coefficient int c float v coefficients c v setcoefficient public float get coefficient int c return coefficients c getcoefficient private float check cube float x float y int cubex int cubey point results random set seed 571 cubex 23 cubey int num points 3 random next int 4 num points 4 for int i 0 i num points i float px random next float float py random next float float dx math abs x px float dy math abs y py float d if distance power 1 0f d dx dy else if distance power 2 0f d float math sqrt dx dx dy dy else d float math pow math pow dx distance power math pow dy distance power 1 distance power insertion sort for int j 0 j results length j if results j distance double positive infinity point last results j last distance d last x px last y py results j last break else if d results j distance point last results results length 1 for int k results length 1 k j k results k results k 1 last distance d last x px last y py results j last break return results 1 distance checkcube setseed numpoints nextint numpoints numpoints nextfloat nextfloat distancepower distancepower distancepower distancepower distancepower positive_infinity public float evaluate float x float y for int j 0 j results length j results j distance float positive infinity int ix int x int iy int y float fx x ix float fy y iy float d check cube fx fy ix iy results if d fy d check cube fx fy 1 ix iy 1 results if d 1 fy d check cube fx fy 1 ix iy 1 results if d fx check cube fx 1 fy ix 1 iy results if d fy d check cube fx 1 fy 1 ix 1 iy 1 results if d 1 fy d check cube fx 1 fy 1 ix 1 iy 1 results if d 1 fx d check cube fx 1 fy ix 1 iy results if d fy d check cube fx 1 fy 1 ix 1 iy 1 results if d 1 fy d check cube fx 1 fy 1 ix 1 iy 1 results float t 0 for int i 0 i 2 i t coefficients i results i distance if angular t math atan2 fy results 0 y fx results 0 x 2 math pi 0 5 return t positive_infinity checkcube checkcube checkcube checkcube checkcube checkcube checkcube checkcube checkcube private cache node next public cache node dns entry value this value value cachenode cachenode dnsentry public cache node next return next cachenode public dns entry get value return value dnsentry getvalue create a table with a given initial size public dns cache final int size hashtable new hash map size dnscache hashmap clears the cache public synchronized void clear hashtable clear size 0 adds an entry to the table public synchronized void add final dns entry entry logger log dns cache add entry get name final cache node new value new cache node entry final cache node node cache node hashtable get entry get name if node null hashtable put entry get name new value else new value next node next node next new value size dnsentry dnscache getname cachenode newvalue cachenode cachenode cachenode getname getname newvalue newvalue newvalue remove a specific entry from the table returns true if the entry was found public synchronized boolean remove dns entry entry cache node node cache node hashtable get entry get name if node null if node value entry if node next null hashtable remove entry get name else hashtable put entry get name node next size return true cache node previous node node node next while node null if node value entry previous next node next size return true previous node node node next return false dnsentry cachenode cachenode getname getname getname cachenode get a matching dns entry from the table using equals returns the entry that was found public synchronized dns entry get dns entry entry for cache node node find entry get name node null node node next if node value equals entry return node value return null dnsentry dnsentry cachenode getname get a matching dns entry from the table public synchronized dns entry get string name int type int clazz for cache node node find name node null node node next if node value type type node value clazz clazz return node value return null dnsentry cachenode iterates over all cache nodes the iterator returns instances of dns cache cache node each instance returned is the first node of a linked list to retrieve all entries one must iterate over this linked list see code snippets in the header of the class public synchronized iterator iterator return new array list hashtable values iterator dnscache cachenode arraylist iterate only over items with matching name returns an instance of dns cache cache node or null if an instance is returned it is the first node of a linked list to retrieve all entries one must iterate over this linked list public synchronized cache node find string name return cache node hashtable get name dnscache cachenode cachenode cachenode list all entries for debugging public synchronized void print for final iterator i iterator i has next for cache node n cache node i next n null n n next system out println n value hasnext cachenode cachenode public synchronized string to string final string buffer a log new string buffer a log append t cache for final iterator i iterator i has next for cache node n cache node i next n null n n next a log append n t t n value return a log to string tostring stringbuffer alog stringbuffer alog hasnext cachenode cachenode alog alog tostring creates a new home page param my web interface a reference to the web interface which created the page used to get resources the page needs param my request the request sent by the user public home page web interface my web interface http request my request super my web interface my request homepage mywebinterface webinterface myrequest homepage webinterface mywebinterface httprequest myrequest mywebinterface myrequest public void make make summary makesummary creates a short summary of what the plugin knows of the wot private void make summary add error box warning wot is currently in beta stage the web of trust will be purged when we release a final version so please create backups of your identities request and insert ur is if you want to use the same keys when the stable version is released html node box add content box summary html node list new html node ul list add child new html node li own identities wot get all own identities size list add child new html node li known identities wot get all non own identities size list add child new html node li trust relationships wot get all trusts size introduction puzzle store puzzle store wot get introduction puzzle store list add child new html node li unsolved own captchas puzzle store get own catpcha amount false list add child new html node li solved own captchas puzzle store get own catpcha amount true list add child new html node li unsolved captchas of others puzzle store get non own captcha amount false list add child new html node li solved captchas of others puzzle store get non own captcha amount true list add child new html node li not inserted captchas solutions puzzle store get uninserted solved puzzles size box add child list makesummary adderrorbox uris htmlnode addcontentbox htmlnode htmlnode addchild htmlnode getallownidentities addchild htmlnode getallnonownidentities addchild htmlnode getalltrusts introductionpuzzlestore puzzlestore getintroductionpuzzlestore addchild htmlnode puzzlestore getowncatpchaamount addchild htmlnode puzzlestore getowncatpchaamount addchild htmlnode puzzlestore getnonowncaptchaamount addchild htmlnode puzzlestore getnonowncaptchaamount addchild htmlnode puzzlestore getuninsertedsolvedpuzzles addchild private int threshold 1 public unsharp filter radius 2 unsharpfilter set the threshold value param threshold the threshold value see get threshold public void set threshold int threshold this threshold threshold getthreshold setthreshold get the threshold value return the threshold value see set threshold public int get threshold return threshold setthreshold getthreshold set the amount of sharpening param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of sharpening return the amount see set amount public float get amount return amount setamount getamount override public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int in pixels new int width height int out pixels new int width height src getrgb 0 0 width height in pixels 0 width if radius 0 convolve and transpose kernel in pixels out pixels width height alpha alpha premultiply alpha false clamp edges convolve and transpose kernel out pixels in pixels height width alpha false alpha premultiply alpha clamp edges src getrgb 0 0 width height out pixels 0 width float a 4 amount int index 0 for int y 0 y height y for int x 0 x width x int rgb1 out pixels index int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int rgb2 in pixels index int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff if math abs r1 r2 threshold r1 pixel utils clamp int a 1 r1 r2 r2 if math abs g1 g2 threshold g1 pixel utils clamp int a 1 g1 g2 g2 if math abs b1 b2 threshold b1 pixel utils clamp int a 1 b1 b2 b2 in pixels index rgb1 0xff000000 r1 16 g1 8 b1 index dst setrgb 0 0 width height in pixels 0 width return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage inpixels outpixels inpixels convolveandtranspose inpixels outpixels premultiplyalpha clamp_edges convolveandtranspose outpixels inpixels premultiplyalpha clamp_edges outpixels outpixels inpixels pixelutils pixelutils pixelutils inpixels inpixels override public string to string return blur unsharp mask tostring private double total public trivial running average trivial running average average this reports average reports this total average total trivialrunningaverage trivialrunningaverage public trivial running average reports 0 total 0 0 trivialrunningaverage public synchronized long count reports return reports countreports public synchronized double current value return total reports currentvalue public synchronized void report double d total d reports todo auto generated method stub public void report long d report double d public synchronized double value if reported double r return total r reports 1 valueifreported override public object clone synchronized this return new trivial running average this trivialrunningaverage public class null input stream extends input stream public null input stream nullinputstream inputstream nullinputstream public class null input stream extends input stream public null input stream override public int read return 1 nullinputstream inputstream nullinputstream public disposer control point ctrlp set control point ctrlp controlpoint setcontrolpoint private control point ctrl point public void set control point control point ctrlp ctrl point ctrlp controlpoint ctrlpoint setcontrolpoint controlpoint ctrlpoint public control point get control point return ctrl point controlpoint getcontrolpoint ctrlpoint public void run control point ctrlp get control point long monitor interval ctrlp get expired device monitoring interval 1000 while is runnable true try thread sleep monitor interval catch interrupted exception e ctrlp remove expired devices ctrlp print controlpoint getcontrolpoint monitorinterval getexpireddevicemonitoringinterval isrunnable monitorinterval interruptedexception removeexpireddevices public web interface no wot freetalk my freetalk super my freetalk m page maker remove all navigation links m page maker add navigation link freetalk plugin uri home freetalk plugin home false null m page maker add navigation link back to freenet back to your freenet node false null m page maker add navigation link plugins go to plugins page the plugins page of freenet false null webinterfacenowot myfreetalk myfreetalk mpagemaker removeallnavigationlinks mpagemaker addnavigationlink plugin_uri mpagemaker addnavigationlink mpagemaker addnavigationlink public string handlehttp get http request request throws pluginhttp exception return new wot is missing page this request false tohtml handlehttpget httprequest pluginhttpexception wotismissingpage public string handlehttp post http request request throws pluginhttp exception return handlehttppost httprequest pluginhttpexception public class null writer extends writer override public void write char cbuf int off int len throws io exception nullwriter ioexception override public void flush throws io exception ioexception override public void close throws io exception ioexception public class despeckle filter extends whole image filter public despeckle filter despecklefilter wholeimagefilter despecklefilter private short pepper and salt short c short v1 short v2 if c v1 c if c v2 c if c v1 c if c v2 c return c pepperandsalt override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 short r new short 3 width short g new short 3 width short b new short 3 width int out pixels new int width height for int x 0 x width x int rgb in pixels x r 1 x short rgb 16 0xff g 1 x short rgb 8 0xff b 1 x short rgb 0xff for int y 0 y height y boolean y in y 0 y height 1 int next row index index width if y height 1 for int x 0 x width x int rgb in pixels next row index r 2 x short rgb 16 0xff g 2 x short rgb 8 0xff b 2 x short rgb 0xff for int x 0 x width x boolean x in x 0 x width 1 short or r 1 x short og g 1 x short ob b 1 x int w x 1 int e x 1 if y in or pepper and salt or r 0 x r 2 x og pepper and salt og g 0 x g 2 x ob pepper and salt ob b 0 x b 2 x if x in or pepper and salt or r 1 w r 1 e og pepper and salt og g 1 w g 1 e ob pepper and salt ob b 1 w b 1 e if y in x in or pepper and salt or r 0 w r 2 e og pepper and salt og g 0 w g 2 e ob pepper and salt ob b 0 w b 2 e or pepper and salt or r 2 w r 0 e og pepper and salt og g 2 w g 0 e ob pepper and salt ob b 2 w b 0 e out pixels index in pixels index 0xff000000 or 16 og 8 ob index short t t r 0 r 0 r 1 r 1 r 2 r 2 t t g 0 g 0 g 1 g 1 g 2 g 2 t t b 0 b 0 b 1 b 1 b 2 b 2 t return out pixels filterpixels inpixels transformedspace outpixels inpixels yin nextrowindex inpixels nextrowindex xin yin pepperandsalt pepperandsalt pepperandsalt xin pepperandsalt pepperandsalt pepperandsalt yin xin pepperandsalt pepperandsalt pepperandsalt pepperandsalt pepperandsalt pepperandsalt outpixels inpixels outpixels override public string to string return blur despeckle tostring static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public random grab array boolean persistent object container container remove random parent parent this blocks new block new block blocks 0 reqs new random grab array item min size this persistent persistent index 0 this hash code super hash code this parent parent randomgrabarray objectcontainer removerandomparent randomgrabarrayitem min_size hashcode hashcode override public int hash code return hash code hashcode hashcode public void add random grab array item req object container container if req persistent persistent throw new illegal argument exception req persistent req persistent but array persistent persistent item req array this if req is empty container if logminor logger minor this is finished already req return req set parent grab array this container synchronized this int x 0 if blocks length 1 index block size if persistent container activate blocks 0 1 for int i 0 i index i if blocks 0 reqs i req if persistent container deactivate blocks 0 1 return if index blocks 0 reqs length int new size math min block size blocks 0 reqs length 2 random grab array item new reqs new random grab array item new size system arraycopy blocks 0 reqs 0 new reqs 0 blocks 0 reqs length blocks 0 reqs new reqs blocks 0 reqs index req if persistent container store blocks 0 container store this container deactivate blocks 0 1 return int target block index block size for int i 0 i blocks length i block block blocks i if persistent container activate block 1 if i blocks length 1 block reqs length block size logger error this block i of blocks length is wrong size block reqs length should be block size for int j 0 j block reqs length j if x index break if block reqs j req if logminor logger minor this already contains req this size now index if persistent container deactivate block 1 return if block reqs j null logger error this reqs i j null on this x if persistent i target block container deactivate block 1 int old block len blocks length if blocks length target block if logminor logger minor this adding blocks on this block new blocks new block target block 1 system arraycopy blocks 0 new blocks 0 blocks length for int i blocks length i new blocks length i new blocks i new block new blocks i reqs new random grab array item block size blocks new blocks else if persistent container activate blocks target block 1 block target blocks target block target reqs index block size req if persistent for int i old block len i blocks length i container store blocks i container store this container store target for int i old block len i blocks length i container deactivate blocks i 1 if logminor logger minor this added req to this size now index randomgrabarrayitem objectcontainer illegalargumentexception isempty setparentgrabarray block_size newsize block_size randomgrabarrayitem newreqs randomgrabarrayitem newsize newreqs newreqs targetblock block_size block_size block_size targetblock oldblocklen targetblock newblocks targetblock newblocks newblocks newblocks newblocks randomgrabarrayitem block_size newblocks targetblock targetblock block_size oldblocklen oldblocklen public random grab array item remove random random grab array item exclusion list excluding object container container client context context random grab array item ret oret if logminor logger minor this remove random on this index index synchronized this int last active block 1 must be less than block size final int max excluded 10 int excluded 0 boolean changed me false while true if index 0 if logminor logger minor this all null on this return null if index max excluded optimise the common case of not many items and avoid some spurious errors int random 1 if persistent container activate blocks 0 1 random grab array item reqs blocks 0 reqs while true int exclude 0 int valid 0 int valid index 1 int target 0 int chosen index 1 random grab array item chosen item null random grab array item valid item null for int i 0 i index i compact the array random grab array item item reqs i if persistent container activate item 1 if item null continue else if item is empty container changed me true we are doing compaction here we don t need to swap with the end we write valid ones to the target location reqs i null item set parent grab array null container if persistent container deactivate item 1 continue if i target changed me true reqs i null reqs target item else the request can happily stay where it is target if excluding exclude item container context exclude else if valid random picked on previous round chosen index target 1 chosen item item if valid index 1 take the first valid item valid index target 1 valid item item valid if persistent item chosen item item valid item if logminor logger minor this deactivating item container deactivate item 1 if container ext is active item logger error this still active after deactivation item else if logminor logger minor this deactivated item if index target changed me true index target we reach this point if 1 the random number we picked last round is invalid because an item became cancelled or excluded or 2 we are on the first round anyway if chosen item null if persistent valid item null valid item chosen item container deactivate valid item 1 changed me true ret chosen item assert ret reqs chosen index if logminor logger minor this chosen random item ret out of valid total index if persistent changed me container store blocks 0 container store this return ret if valid 0 exclude 0 index 0 if persistent container store blocks 0 container store this if logminor logger minor this no valid or excluded items total index return null else if valid 0 if persistent changed me container store blocks 0 container store this if logminor logger minor this no valid items exclude excluded items total index return null else if valid 1 ret valid item assert ret reqs valid index if logminor logger minor this no valid or excluded items apart from ret total index if persistent changed me container store blocks 0 container store this return ret else random context fast weak random next int valid int i context fast weak random next int index int block no i block size if persistent block no last active block if last active block 1 container deactivate blocks last active block 1 last active block block no container activate blocks block no 1 ret blocks block no reqs i block size if ret null logger error this reqs i null remove block no i container changed me true continue if persistent container activate ret 1 oret ret if ret is empty container if logminor logger minor this not returning because cancelled ret ret null will be removed in the do loop tell it that it s been removed first oret set parent grab array null container if ret null excluding exclude ret container context excluded if persistent container deactivate ret 1 if excluded max excluded logger normal this remove random returning null because excluded excluded items length index new exception error if persistent changed me container store this return null continue if ret null if logminor logger minor this returning cannot remove ret of index if persistent changed me container store this return ret remove an element do changed me true remove block no i container if persistent oret null ret null if ret null we will return it container deactivate oret 1 oret blocks block no reqs i block size check for nulls but don t check for cancelled since we d have to activate while index i oret null shrink array if blocks length 1 index blocks 0 reqs length 4 changed me true shrink array int new size math max index 2 min size random grab array item r new random grab array item new size system arraycopy blocks 0 reqs 0 r 0 r length blocks 0 reqs r if persistent container store this else if blocks length 1 index block size 2 block size 1 blocks length if logminor logger minor this shrinking blocks on this block new blocks new block index block size 2 block size 1 system arraycopy blocks 0 new blocks 0 new blocks length if persistent container store this for int x new blocks length x blocks length x container delete blocks x blocks new blocks if ret null break if logminor logger minor this returning ret of index ret set parent grab array null container if persistent container store this return ret randomgrabarrayitem removerandom randomgrabarrayitemexclusionlist objectcontainer clientcontext randomgrabarrayitem removerandom lastactiveblock block_size max_excluded changedme max_excluded randomgrabarrayitem validindex chosenindex randomgrabarrayitem chosenitem randomgrabarrayitem validitem randomgrabarrayitem isempty changedme setparentgrabarray changedme chosenindex chosenitem validindex validindex validitem chosenitem validitem isactive changedme chosenitem validitem validitem chosenitem validitem changedme chosenitem chosenindex changedme changedme validitem validindex changedme fastweakrandom nextint fastweakrandom nextint blockno block_size blockno lastactiveblock lastactiveblock lastactiveblock lastactiveblock blockno blockno blockno block_size blockno changedme isempty setparentgrabarray max_excluded changedme changedme changedme blockno blockno block_size changedme newsize min_size randomgrabarrayitem randomgrabarrayitem newsize block_size block_size newblocks block_size block_size newblocks newblocks newblocks newblocks setparentgrabarray block no is assumed to be already active the last block is assumed not to be private void remove int block no int i object container container index int end block index block size if blocks length 1 block no end block random grab array item items blocks block no reqs int idx index block size items i block size items idx items idx null if persistent container store blocks block no else random grab array item to items blocks block no reqs if persistent container activate blocks end block 1 random grab array item end items blocks end block reqs to items i block size end items index block size end items index block size null if persistent container store blocks block no container store blocks end block container deactivate blocks end block 1 blockno blockno objectcontainer endblock block_size blockno endblock randomgrabarrayitem blockno block_size block_size blockno randomgrabarrayitem toitems blockno endblock randomgrabarrayitem enditems endblock toitems block_size enditems block_size enditems block_size blockno endblock endblock public void remove random grab array item it object container container if logminor logger minor this removing it from this boolean matched false boolean empty false synchronized this if blocks length 1 block block blocks 0 if persistent container activate block 1 for int i 0 i index i if block reqs i it block reqs i block reqs index block reqs index null matched true if persistent container store block break if index 0 empty true if persistent container deactivate block 1 else int x 0 for int i 0 i blocks length i block block blocks i if persistent container activate block 1 for int j 0 j block reqs length j if x index break x if block reqs i it int pull from index int idx pull from block size int end block pull from block size if i end block block reqs j block reqs idx block reqs idx null else block from block blocks end block if persistent container activate from block 1 block reqs j from block reqs idx from block reqs idx null if persistent container store from block container deactivate from block 1 if persistent container store block matched true break if persistent container deactivate block 1 if index 0 empty true if it get parent grab array this it set parent grab array null container else logger error this removing item it from this but rga is it get parent grab array new exception debug if matched return if persistent container store this if empty parent null boolean active true if persistent active container ext is active parent if active container activate parent 1 parent maybe remove this container if active container deactivate parent 1 randomgrabarrayitem objectcontainer pullfrom pullfrom block_size endblock pullfrom block_size endblock fromblock endblock fromblock fromblock fromblock fromblock fromblock getparentgrabarray setparentgrabarray getparentgrabarray isactive mayberemove public synchronized boolean is empty return index 0 isempty public boolean persistent return persistent public boolean contains random grab array item item object container container synchronized this if blocks length 1 block block blocks 0 if persistent container activate block 1 for int i 0 i index i if block reqs i item if persistent container deactivate block 1 return true if persistent container deactivate block 1 else int x 0 for int i 0 i blocks length i block block blocks i if persistent container activate block 1 for int j 0 j block reqs length j if x index break x if block reqs i item if persistent container deactivate block 1 return true if persistent container deactivate block 1 return false randomgrabarrayitem objectcontainer public synchronized int size return index public synchronized random grab array item get int idx object container container int block no idx block size if persistent container activate blocks block no 1 random grab array item item blocks block no reqs idx block size if persistent container deactivate blocks block no 1 return item randomgrabarrayitem objectcontainer blockno block_size blockno randomgrabarrayitem blockno block_size blockno public void remove from object container container if blocks null for block block blocks container activate block 1 for random grab array item item block reqs if item null logger error this valid item while deleting block item on this container delete block container delete this removefrom objectcontainer randomgrabarrayitem final int edx cpuid result int eax int ebx int ecx int edx this eax eax this ebx ebx this ecx ecx this edx edx cpuidresult calls the indicated cpuid function and returns the result of the execution param i function the cpuid function to call should be 0 or larger return the contents of the cpu registers after the call to the cpuid function ifunction private static string getcpu vendorid cpuid result c docpuid 0 string builder sb new string builder 13 sb append char c ebx 0xff sb append char c ebx 8 0xff sb append char c ebx 16 0xff sb append char c ebx 24 0xff sb append char c edx 0xff sb append char c edx 8 0xff sb append char c edx 16 0xff sb append char c edx 24 0xff sb append char c ecx 0xff sb append char c ecx 8 0xff sb append char c ecx 16 0xff sb append char c ecx 24 0xff return sb to string getcpuvendorid cpuidresult stringbuilder stringbuilder tostring private static int getcpu family cpuid result c docpuid 1 return c eax 8 0xf getcpufamily cpuidresult private static int getcpu model cpuid result c docpuid 1 return c eax 4 0xf getcpumodel cpuidresult private static int getcpu extended family cpuid result c docpuid 1 return c eax 20 0xff getcpuextendedfamily cpuidresult private static int getcpu stepping cpuid result c docpuid 1 return c eax 0xf getcpustepping cpuidresult private static int getcpu flags cpuid result c docpuid 1 return c edx getcpuflags cpuidresult other detection methods than the x86 only cpuid instruction public static cpu info get info throws unknowncpu exception if nativeok throw new unknowncpu exception failed to read cpu information from the system please verify the existence of the jcpuid dll so if isx86 throw new unknowncpu exception failed to read cpu information from the system the cpuid instruction exists on x86 cpu s only if getcpu vendorid equals authenticamd return new amd info impl if getcpu vendorid equals genuine intel return new intel info impl throw new unknowncpu exception unknown cpu type getcpu vendorid cpuinfo getinfo unknowncpuexception _nativeok unknowncpuexception unknowncpuexception getcpuvendorid amdinfoimpl getcpuvendorid genuineintel intelinfoimpl unknowncpuexception getcpuvendorid protected abstract static class cpuidcpu info public string get vendor return getcpu vendorid cpuidcpuinfo getvendor getcpuvendorid return getcpu vendorid public boolean hasmmx return getcpu flags 0x800000 0 bit 23 getcpuvendorid getcpuflags return getcpu flags 0x800000 0 bit 23 public boolean hassse return getcpu flags 0x2000000 0 bit 25 getcpuflags getcpuflags return getcpu flags 0x2000000 0 bit 25 public boolean hassse2 return getcpu flags 0x4000000 0 bit 26 getcpuflags getcpuflags protected static class amd info impl extends cpuidcpu info implements amdcpu info public boolean isk6 compatible return getcpu family 5 getcpu model 6 amdinfoimpl cpuidcpuinfo amdcpuinfo isk6compatible getcpufamily getcpumodel return getcpu family 5 getcpu model 6 public boolean isk6 2 compatible return getcpu family 5 getcpu model 8 getcpufamily getcpumodel isk6_2_compatible getcpufamily getcpumodel return getcpu family 5 getcpu model 8 public boolean isk6 3 compatible return getcpu family 5 getcpu model 9 getcpufamily getcpumodel isk6_3_compatible getcpufamily getcpumodel return getcpu family 5 getcpu model 9 public boolean is athlon compatible return getcpu family 6 getcpufamily getcpumodel isathloncompatible getcpufamily return getcpu family 6 public boolean is athlon64 compatible return getcpu family 15 getcpu extended family 0 getcpufamily isathlon64compatible getcpufamily getcpuextendedfamily public string getcpu model string throws unknowncpu exception if getcpu family 4 switch getcpu model case 3 return 486 dx 2 case 7 return 486 dx 2 wb case 8 return 486 dx 4 case 9 return 486 dx 4 wb case 14 return am5x86 wt case 15 return am5x86 wb if getcpu family 5 switch getcpu model case 0 return k5 ssa5 case 1 return k5 case 2 return k5 case 3 return k5 case 6 return k6 case 7 return k6 case 8 return k6 2 case 9 return k6 3 case 13 return k6 2 or k6 iii if getcpu family 6 switch getcpu model case 0 return athlon 250 nm case 1 return athlon 250 nm case 2 return athlon 180 nm case 3 return duron case 4 return athlon thunderbird case 6 return athlon palamino case 7 return duron morgan case 8 return athlon thoroughbred case 10 return athlon barton if getcpu family 15 must check extended family if getcpu extended family 0 amd k8 this just tells us socket type and chip die technology see brandid both the id and nn portions if you need to determine a specific chip brand switch getcpu model case 4 return athlon 64 case 5 return athlon 64 fx opteron case 7 return athlon 64 0 13 um 939 case 8 return athlon 64 0 13 um 754 case 11 return athlon 64 0 13 um 939 case 12 return athlon 64 0 13 um 754 case 15 return athlon 64 0 13 um 939 throw new unknowncpu exception unknown amd cpu family getcpu family model getcpu model getcpumodelstring unknowncpuexception getcpufamily getcpumodel getcpufamily getcpumodel getcpufamily getcpumodel getcpufamily getcpuextendedfamily getcpumodel unknowncpuexception getcpufamily getcpumodel protected static class intel info impl extends cpuidcpu info implements intelcpu info public boolean is pentium compatible return getcpu family 5 intelinfoimpl cpuidcpuinfo intelcpuinfo ispentiumcompatible getcpufamily return getcpu family 5 public boolean is pentiummmx compatible return is pentium2 compatible getcpu family 5 getcpu model 4 getcpu model 8 getcpufamily ispentiummmxcompatible ispentium2compatible getcpufamily getcpumodel getcpumodel return is pentium2 compatible getcpu family 5 getcpu model 4 getcpu model 8 public boolean is pentium2 compatible return getcpu family 6 getcpu family 6 getcpu model 3 ispentium2compatible getcpufamily getcpumodel getcpumodel ispentium2compatible getcpufamily getcpufamily getcpumodel return getcpu family 6 getcpu family 6 getcpu model 3 public boolean is pentium3 compatible return getcpu family 6 getcpu family 6 getcpu model 7 getcpufamily getcpufamily getcpumodel ispentium3compatible getcpufamily getcpufamily getcpumodel return getcpu family 6 getcpu family 6 getcpu model 7 public boolean is pentium4 compatible return getcpu family 15 getcpufamily getcpufamily getcpumodel ispentium4compatible getcpufamily public string getcpu model string throws unknowncpu exception if getcpu family 4 switch getcpu model case 0 return 486 dx 25 33 case 1 return 486 dx 50 case 2 return 486 sx case 3 return 486 dx 2 case 4 return 486 sl case 5 return 486 sx 2 case 7 return 486 dx 2 wb case 8 return 486 dx 4 case 9 return 486 dx 4 wb if getcpu family 5 switch getcpu model case 0 return pentium 60 66 a step case 1 return pentium 60 66 case 2 return pentium 75 200 case 3 return over drive podp5v83 case 4 return pentium mmx case 7 return mobile pentium 75 200 case 8 return mobile pentium mmx if getcpu family 6 switch getcpu model case 0 return pentium pro a step case 1 return pentium pro case 3 return pentium ii klamath case 5 return pentium ii deschutes celeron covington mobile pentium ii dixon case 6 return mobile pentium ii celeron mendocino case 7 return pentium iii katmai case 8 return pentium iii coppermine celeron w sse case 9 return mobile pentium iii case 10 return pentium iii xeon cascades case 11 return pentium iii 130 nm if getcpu family 7 switch getcpu model itanium todo if getcpu family 15 if getcpu extended family 0 switch getcpu model case 0 return pentium iv 180 nm case 1 return pentium iv 180 nm case 2 return pentium iv 130 nm case 3 return pentium iv 90 nm if getcpu extended family 1 switch getcpu model itanium 2 todo throw new unknowncpu exception unknown intel cpu family getcpu family model getcpu model getcpumodelstring unknowncpuexception getcpufamily getcpumodel getcpufamily getcpumodel overdrive getcpufamily getcpumodel getcpufamily getcpumodel getcpufamily getcpuextendedfamily getcpumodel getcpuextendedfamily getcpumodel unknowncpuexception getcpufamily getcpumodel public static void main string args system out println system get property os arch to lower case if nativeok system out println failed to retrieve cpu info please verify the existence of jcpuid dll so system out println cpu info system out println cpu vendor getcpu vendorid system out println cpu family getcpu family system out println cpu extended family getcpu extended family system out println cpu model getcpu model system out println cpu stepping getcpu stepping system out println cpu flags getcpu flags cpu info c get info system out println more cpu info system out println cpu model string c getcpu model string system out println cpu has mmx c hasmmx system out println cpu has sse c hassse system out println cpu has sse2 c hassse2 if c instanceof intelcpu info system out println intel info system out println is pii compatible intelcpu info c is pentium2 compatible system out println is piii compatible intelcpu info c is pentium3 compatible system out println is piv compatible intelcpu info c is pentium4 compatible if c instanceof amdcpu info system out println amd info system out println is athlon compatible amdcpu info c is athlon compatible system out println is athlon64 compatible amdcpu info c is athlon64 compatible getproperty tolowercase _nativeok cpuinfo cpuinfo getcpuvendorid getcpufamily getcpuextendedfamily getcpumodel getcpustepping getcpuflags cpuinfo getinfo cpuinfo getcpumodelstring intelcpuinfo intelcpuinfo ispentium2compatible intelcpuinfo ispentium3compatible intelcpuinfo ispentium4compatible amdcpuinfo amdcpuinfo isathloncompatible amdcpuinfo isathlon64compatible p do whatever we can to load up the native library if it can find a custom built jcpuid dll libjcpuid so it ll use that otherwise it ll try to look in the classpath for the correct library see load from resource if the user specifies djcpuid enable false it ll skip all of this p private static final void load native try string wanted prop system get property jcpuid enable true boolean want native true equals ignore case wanted prop if want native boolean loaded load from resource if loaded nativeok true if dolog system err println info native cpuid library get resource name loaded from resource else loaded load generic if loaded nativeok true if dolog system err println info native cpuid library get library middle part loaded from somewhere in the path else nativeok false if dolog system err println warn native cpuid library jcpuid not loaded will not be able to read cpu information using cpuid else if dolog system err println info native cpuid library jcpuid not loaded will not be able to read cpu information using cpuid catch exception e if dolog system err println info native cpuid library jcpuid not loaded reason e get message will not be able to read cpu information using cpuid loadfromresource loadnative wantedprop getproperty wantnative equalsignorecase wantedprop wantnative loadfromresource _nativeok _dolog getresourcename loadgeneric _nativeok _dolog getlibrarymiddlepart _nativeok _dolog _dolog _dolog getmessage p try loading it from an explictly built jcpuid dll libjcpuid so p return true if it was loaded successfully else false private static final boolean load generic try system load library get library middle part return true catch unsatisfied link error ule return false loadgeneric loadlibrary getlibrarymiddlepart unsatisfiedlinkerror p check all of the jars in the classpath for the jcpuid dll so this file should be stored in the resource in the same package as this class p this is a pretty ugly hack using the general technique illustrated by the onion fec libraries it works by pulling the resource writing out the byte stream to a temporary file loading the native library from that file then deleting the file p return true if it was loaded successfully else false private static final boolean load from resource string resource name get resource name if resource name null return false url resource cpuid class get class loader get resource resource name if resource null if dolog system err println error resource name resource name was not found return false file out file null try input stream lib stream resource open stream try out file file create temp file jcpuid lib tmp catch io exception e logger error cpuid can t create the temporary file in system get property java io tmpdir trying something else now out file new file cpuid lib tmp file output stream fos new file output stream out file byte buf new byte 4096 1024 while true int read lib stream read buf if read 0 break fos write buf 0 read fos close system load out file get absolute path system load requires an absolute path to the lib return true catch unsatisfied link error ule if dolog system err println error the resource resource name was not a valid library for this platform ule print stack trace return false catch io exception ioe if dolog system err println error problem writing out the temporary native library data ioe print stack trace return false finally if out file null out file delete on exit loadfromresource resourcename getresourcename resourcename getclassloader getresource resourcename _dolog resourcename outfile inputstream libstream openstream outfile createtempfile ioexception getproperty outfile fileoutputstream fileoutputstream outfile libstream outfile getabsolutepath unsatisfiedlinkerror _dolog resourcename printstacktrace ioexception _dolog printstacktrace outfile outfile deleteonexit private static final string get resource name string pname cpuid class get package get name replace return pname get library prefix get library middle part get library suffix getresourcename getpackage getname getlibraryprefix getlibrarymiddlepart getlibrarysuffix private static final string get library prefix boolean is windows system get property os name to lower case index of windows 1 if is windows return else return lib getlibraryprefix iswindows getproperty tolowercase indexof iswindows private static final string get library middle part boolean is windows system get property os name to lower case index of windows 1 boolean is linux system get property os name to lower case index of linux 1 boolean is freebsd system get property os name to lower case index of freebsd 1 boolean is macos system get property os name to lower case index of mac os x 1 if is windows return jcpuid x86 windows the convention on windows if is linux return jcpuid x86 linux the convention on linux if is freebsd return jcpuid x86 freebsd the convention on freebsd if is macos return jcpuid x86 osx the convention on mac os x throw new runtime exception dont know jcpuid library name for os type system get property os name getlibrarymiddlepart iswindows getproperty tolowercase indexof islinux getproperty tolowercase indexof isfreebsd getproperty tolowercase indexof ismacos getproperty tolowercase indexof iswindows islinux isfreebsd ismacos runtimeexception getproperty private static final string get library suffix boolean is windows system get property os name to lower case index of windows 1 if is windows return dll else return so getlibrarysuffix iswindows getproperty tolowercase indexof iswindows static final class default constructor profile new class 0 public constructor get default constructor class cls throws exception return cls get declared constructor default constructor profile defaultconstructorprofile getdefaultconstructor getdeclaredconstructor defaultconstructorprofile public void set int field field object object int value throws exception field set int object value setint setint public void set long field field object object long value throws exception field set long object value setlong setlong public void set short field field object object short value throws exception field set short object value setshort setshort public void set char field field object object char value throws exception field set char object value setchar setchar public void set byte field field object object byte value throws exception field set byte object value setbyte setbyte public void set float field field object object float value throws exception field set float object value setfloat setfloat public void set double field field object object double value throws exception field set double object value setdouble setdouble public void set boolean field field object object boolean value throws exception field set boolean object value setboolean setboolean public void set field field object object object value throws exception field set object value private final vector bookmarks new vector public bookmark category string name set name name bookmarkcategory setname public bookmark category simple field set sfs throws fs parse exception string a name sfs get name if a name null throw new fs parse exception no name set name a name bookmarkcategory simplefieldset fsparseexception aname aname fsparseexception setname aname protected synchronized bookmark add bookmark bookmark b if b null return null overwrite any existing bookmark int x bookmarks index of b if x 0 return bookmark bookmarks get x bookmarks add b return b addbookmark indexof protected synchronized void remove bookmark bookmark b bookmarks remove b removebookmark public bookmark get int i return bookmark bookmarks get i protected void move bookmark up bookmark b int index bookmarks index of b if index 1 return bookmark bk get index bookmarks remove index bookmarks add index 0 0 index bk movebookmarkup indexof protected void move bookmark down bookmark b int index bookmarks index of b if index 1 return bookmark bk get index bookmarks remove index bookmarks add index size size index bk movebookmarkdown indexof public int size return bookmarks size public list bookmark item get items list bookmark item items new vector bookmark item for int i 0 i size i if get i instanceof bookmark item items add bookmark item get i return items bookmarkitem getitems bookmarkitem bookmarkitem bookmarkitem bookmarkitem public list bookmark item get all items list bookmark item items get items list bookmark category sub categories get sub categories for int i 0 i sub categories size i items add all sub categories get i get all items return items bookmarkitem getallitems bookmarkitem getitems bookmarkcategory subcategories getsubcategories subcategories addall subcategories getallitems public list bookmark category get sub categories list bookmark category categories new vector bookmark category for int i 0 i size i if get i instanceof bookmark category categories add bookmark category get i return categories bookmarkcategory getsubcategories bookmarkcategory bookmarkcategory bookmarkcategory bookmarkcategory public list bookmark category get all sub categories list bookmark category categories get sub categories list bookmark category sub categories get sub categories for int i 0 i sub categories size i categories add all sub categories get i get all sub categories return categories bookmarkcategory getallsubcategories bookmarkcategory getsubcategories bookmarkcategory subcategories getsubcategories subcategories addall subcategories getallsubcategories public string to strings return to strings to array new string 0 tostrings tostrings toarray private vector string to strings string prefix vector string strings new vector string list bookmark item items get items list bookmark category sub categories get sub categories prefix this name for int i 0 i items size i strings add prefix items get i to string for int i 0 i sub categories size i strings add all sub categories get i to strings prefix return strings tostrings bookmarkitem getitems bookmarkcategory subcategories getsubcategories tostring subcategories addall subcategories tostrings override public simple field set get simple field set simple field set sfs new simple field set true sfs put single name name sfs put content bookmark manager to simple field set this return sfs simplefieldset getsimplefieldset simplefieldset simplefieldset putsingle bookmarkmanager tosimplefieldset private final string client token public persistent request modified message string identifier boolean global short priority class this identifier global priority class null client token not set clienttoken persistentrequestmodifiedmessage priorityclass priorityclass clienttoken public persistent request modified message string identifier boolean global string client token this identifier global short 1 client token priority class not set persistentrequestmodifiedmessage clienttoken clienttoken priorityclass public persistent request modified message string identifier boolean global short priority class string client token this ident identifier this global global this priority class priority class this client token client token persistentrequestmodifiedmessage priorityclass clienttoken priorityclass priorityclass clienttoken clienttoken override public simple field set get field set final simple field set fs new simple field set true fs put single identifier ident if global fs put single global true if priority class 0 fs put single priority class short to string priority class if client token null fs put single client token client token return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle priorityclass putsingle priorityclass tostring priorityclass clienttoken putsingle clienttoken clienttoken override public string get name return persistent request modified getname persistentrequestmodified override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message persistent request modified goes from server to client not the other way around ident global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message persistentrequestmodified override public void remove from object container container container delete this removefrom objectcontainer override protected float transfer function float f f f brightness f f 0 5f contrast 0 5f return f transferfunction set the filter brightness param brightness the brightness in the range 0 to 1 min value 0 max value 0 see get brightness public void set brightness float brightness this brightness brightness initialized false getbrightness setbrightness get the filter brightness return the brightness in the range 0 to 1 see set brightness public float get brightness return brightness setbrightness getbrightness set the filter contrast param contrast the contrast in the range 0 to 1 min value 0 max value 0 see get contrast public void set contrast float contrast this contrast contrast initialized false getcontrast setcontrast get the filter contrast return the contrast in the range 0 to 1 see set contrast public float get contrast return contrast setcontrast getcontrast override public string to string return colors contrast tostring public opennet peer node simple field set fs node node2 node crypto crypto opennet manager opennet peer manager peers boolean from local outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception super fs node2 crypto peers from local false mangler true if from local simple field set metadata fs subset metadata time last success metadata get long time last success 0 this opennet opennet opennetpeernode simplefieldset nodecrypto opennetmanager peermanager fromlocal outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception fromlocal fromlocal simplefieldset timelastsuccess getlong timelastsuccess override public peer node status get status boolean no heavy return new opennet peer node status this no heavy peernodestatus getstatus noheavy opennetpeernodestatus noheavy override public boolean is routing compatible if node is opennet enabled return false return super is routing compatible isroutingcompatible isopennetenabled isroutingcompatible override public boolean is darknet return false isdarknet override public boolean is opennet return true isopennet override public boolean is seed return false isseed public boolean is droppable boolean ignore disconnect long now system current time millis if now get peer added time opennet manager drop min age return false new node if now node usm get started time opennet manager drop startup delay return false give them time to connect after we startup int status get peer node status if ignore disconnect synchronized this if status peer manager peer node status disconnected super never connected now time last disconnect opennet manager drop disconnect delay now time prev disconnect opennet manager drop disconnect delay cooldown grace period for node restarting return false return true isdroppable ignoredisconnect currenttimemillis getpeeraddedtime opennetmanager drop_min_age getstartedtime opennetmanager drop_startup_delay getpeernodestatus ignoredisconnect peermanager peer_node_status_disconnected neverconnected timelastdisconnect opennetmanager drop_disconnect_delay timeprevdisconnect opennetmanager drop_disconnect_delay_cooldown override public void on success boolean insert boolean ssk if insert ssk return time last success system current time millis opennet on success this onsuccess timelastsuccess currenttimemillis onsuccess override public void on remove opennet on remove this super on remove onremove onremove onremove override public synchronized simple field set export metadata field set simple field set fs super export metadata field set fs put time last success time last success return fs simplefieldset exportmetadatafieldset simplefieldset exportmetadatafieldset timelastsuccess timelastsuccess public final long time last success return time last success timelastsuccess timelastsuccess is the simple field set a valid noderef public static boolean validate ref simple field set ref if ref get boolean opennet false return false return true simplefieldset validateref simplefieldset getboolean override public boolean is real connection return true isrealconnection override public boolean record status return true recordstatus override protected boolean generate identity from pubkey return false generateidentityfrompubkey override public boolean equals object o if o this return true only equal to seednode of its own type if o instanceof opennet peer node return super equals o else return false opennetpeernode override public final boolean should disconnect and remove now allow announced peers 15 minutes to download the auto update if is connected is unroutable older version system current time millis time last connection completed 60 60 1000 return true return false shoulddisconnectandremovenow isconnected isunroutableolderversion currenttimemillis timelastconnectioncompleted override protected void on connect super on connect opennet crypto socket get address tracker set presumed guilty at system current time millis 60 60 1000 onconnect onconnect getaddresstracker setpresumedguiltyat currenttimemillis private boolean was dropped synchronized void set was dropped was dropped true wasdropped setwasdropped wasdropped synchronized boolean was dropped return was dropped wasdropped wasdropped synchronized boolean grab was dropped boolean ret was dropped was dropped false return ret grabwasdropped wasdropped wasdropped public class snmp gauge32 extends snmp type wrapper num public snmp gauge32 super snmpgauge32 snmptypewrappernum snmpgauge32 public class snmp gauge32 extends snmp type wrapper num public snmp gauge32 super public snmp gauge32 long value super value snmpgauge32 snmptypewrappernum snmpgauge32 snmpgauge32 public void set value long value todo make it prettier this value new long value int value system err println value cut from value to this value setvalue intvalue protected void init this typeid 0x42 construct a ripple filter public ripple filter x amplitude 5 0f y amplitude 0 0f x wavelength y wavelength 16 0f ripplefilter ripplefilter xamplitude yamplitude xwavelength ywavelength set the amplitude of ripple in the x direction param x amplitude the amplitude in pixels see getx amplitude public void setx amplitude float x amplitude this x amplitude x amplitude xamplitude getxamplitude setxamplitude xamplitude xamplitude xamplitude get the amplitude of ripple in the x direction return the amplitude in pixels see setx amplitude public float getx amplitude return x amplitude setxamplitude getxamplitude xamplitude set the wavelength of ripple in the x direction param x wavelength the wavelength in pixels see getx wavelength public void setx wavelength float x wavelength this x wavelength x wavelength xwavelength getxwavelength setxwavelength xwavelength xwavelength xwavelength get the wavelength of ripple in the x direction return the wavelength in pixels see setx wavelength public float getx wavelength return x wavelength setxwavelength getxwavelength xwavelength set the amplitude of ripple in the y direction param y amplitude the amplitude in pixels see gety amplitude public void sety amplitude float y amplitude this y amplitude y amplitude yamplitude getyamplitude setyamplitude yamplitude yamplitude yamplitude get the amplitude of ripple in the y direction return the amplitude in pixels see sety amplitude public float gety amplitude return y amplitude setyamplitude getyamplitude yamplitude set the wavelength of ripple in the y direction param y wavelength the wavelength in pixels see gety wavelength public void sety wavelength float y wavelength this y wavelength y wavelength ywavelength getywavelength setywavelength ywavelength ywavelength ywavelength get the wavelength of ripple in the y direction return the wavelength in pixels see sety wavelength public float gety wavelength return y wavelength setywavelength getywavelength ywavelength set the wave type param wave type the type see get wave type public void set wave type int wave type this wave type wave type wavetype getwavetype setwavetype wavetype wavetype wavetype get the wave type return the type see set wave type public int get wave type return wave type setwavetype getwavetype wavetype override protected void transform space rectangle r if edge action zero r x int x amplitude r width int 2 x amplitude r y int y amplitude r height int 2 y amplitude transformspace edgeaction xamplitude xamplitude yamplitude yamplitude override protected void transform inverse int x int y float out float nx float y x wavelength float ny float x y wavelength float fx fy switch wave type case sine default fx float math sin nx fy float math sin ny break case sawtooth fx image math mod nx 1 fy image math mod ny 1 break case triangle fx image math triangle nx fy image math triangle ny break case noise fx noise noise1 nx fy noise noise1 ny break out 0 x x amplitude fx out 1 y y amplitude fy transforminverse xwavelength ywavelength wavetype imagemath imagemath imagemath imagemath xamplitude yamplitude override public string to string return distort ripple tostring public f proxy toadlet final high level simple client client node client core core super client client set max length max length client set max intermediate length max length this core core this context core client context prefetch hook new founduri callback public void founduri freeneturi uri ignore public void founduri freeneturi uri boolean inline if inline return if logger should log logger minor this logger minor this prefetching uri client prefetch uri 60 1000 512 1024 prefetch allowed types public void on text string text string type uri baseuri ignore fetch tracker new f proxy fetch tracker context get client impl get fetch context this fproxytoadlet highlevelsimpleclient nodeclientcore setmaxlength max_length setmaxintermediatelength max_length clientcontext prefetchhook founduricallback shouldlog prefetchallowedtypes ontext fetchtracker fproxyfetchtracker getclientimpl getfetchcontext prefetch hook new founduri callback public void founduri freeneturi uri ignore prefetchhook founduricallback public void founduri freeneturi uri boolean inline if inline return if logger should log logger minor this logger minor this prefetching uri client prefetch uri 60 1000 512 1024 prefetch allowed types shouldlog prefetchallowedtypes public void on text string text string type uri baseuri ignore ontext override public string supported methods return get supportedmethods override public void handle post uri uri http request req toadlet context ctx throws toadlet context closed exception io exception redirect exception string ks uri get path if ks equals ks starts with servlet try throw new redirect exception welcome catch uri syntax exception e huh handlepost httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception getpath startswith redirectexception urisyntaxexception public static void handle download toadlet context context bucket data bucket factory bucket factory string mime type string requested mime type string force string boolean force download string base path freeneturi key string extras string referrer boolean download link toadlet context ctx node client core core boolean dont free data throws toadlet context closed exception io exception toadlet container container context get container if logger should log logger minor f proxy toadlet class logger minor f proxy toadlet class handle download data size data size mime type mime type requested mime type requested mime type force download force download base path base path key key string extras no mime extras extras will not include mime type to start with redflag maybe it should be an array if requested mime type null if mime type null requested mime type equals mime type if extras null extras extras extras type requested mime type mime type requested mime type long size data size long now system current time millis boolean force false if force string null if force string equals get force value key now force string equals get force value key now force grain interval force true bucket to free null bucket tmp range null try if force force download filter output fo content filter filter data bucket factory mime type key touri base path container enable inline prefetch prefetch hook null if data fo data to free fo data data fo data mime type fo type if horrible evil hack data mime type starts with application rss xml html node page node context get page maker get page node l10n dangerousrss title context html node content node context get page maker get content node page node html node infobox content node add child div class infobox infobox alert infobox add child div class infobox header l10n dangerousrss subtitle html node infobox content infobox add child div class infobox content infobox content add child l10n get string f proxy toadlet dangerousrss new string type new string mime type infobox content add child p l10n options html node option list infobox content add child ul html node option option list add child li l10n addl10n substitution option f proxy toadlet open possrss as plain text new string link link bold bold new string a href base path key to string type text plain force get force value key now extras no mime a b b fixme is this safe see bug 131 option option list add child li l10n addl10n substitution option f proxy toadlet open possrss force disk new string link link bold bold new string a href base path key to string forcedownload extras a b b boolean mimerss mime type starts with application xml rss mime type starts with text xml blergh if mimerss mime type starts with text plain option option list add child li l10n addl10n substitution option f proxy toadlet openrss force new string link link bold bold mime new string a href base path key to string force get force value key now extras a b b html encoder encode mime type these are not encoded because mostly they are tags so we have to encode it option option list add child li l10n addl10n substitution option f proxy toadlet openrss asrss new string link link bold bold new string a href base path key to string type application xml rss force get force value key now extras no mime a b b if referrer null option option list add child li l10n addl10n substitution option f proxy toadlet back to referrer new string link link new string a href html encoder encode referrer a option option list add child li l10n addl10n substitution option f proxy toadlet back tof proxy new string link link new string a href a byte page bytes page node generate get bytes utf 8 context send reply headers 200 ok new multi value table string string text html charset utf 8 page bytes length context write data page bytes return if force download multi value table string string headers new multi value table string string headers put content disposition attachment filename key get preferred filename context send reply headers 200 ok headers application x msdownload data size context write data data else send the data intact multi value table string string hdr context get headers string range str hdr get range was a range request if range str null long range parse range range str if range 1 1 range 1 data size range 1 data size 1 tmp range bucket factory make bucket range 1 range 0 input stream is data get input stream output stream os tmp range get output stream if range 0 0 is skip range 0 file util copy is os range 1 range 0 1 os close is close multi value table string string ret hdr new multi value table string string ret hdr put content range bytes range 0 range 1 data size context send reply headers 206 partial content ret hdr mime type tmp range size context write data tmp range else context send reply headers 200 ok new multi value table string string mime type data size context write data data catch uri syntax exception use1 shouldn t happen use1 print stack trace logger error f proxy toadlet class could not create uri use1 catch unsafe content type exception e html node page node context get page maker get page node l10n dangerous content title context html node content node context get page maker get content node page node html node infobox content node add child div class infobox infobox alert infobox add child div class infobox header e get raw title html node infobox content infobox add child div class infobox content html node list infobox content add child ul write size andmime list size mime type true infobox content add child p add child e gethtml explanation infobox content add child p l10n options html node option list infobox content add child ul html node option if mime type equals application x freenet index core node plugin manager is plugin loaded plugins thaw index browser thaw index browser option option list add child li l10n addl10n substitution option f proxy toadlet open as thaw index new string link link new string b a href base path plugins plugins thaw index browser thaw index browser key key to string a b option option list add child li fixme is this safe see bug 131 l10n addl10n substitution option f proxy toadlet open as text new string link link new string a href base path key to string type text plain extras no mime a option option list add child li l10n addl10n substitution option f proxy toadlet open force disk new string link link new string a href base path key to string forcedownload extras a if mime type equals application octet stream mime type equals application x msdownload option option list add child li l10n addl10n substitution option f proxy toadlet open force new string link link mime new string a href base path key to string force get force value key now extras a html encoder encode mime type if referrer null option option list add child li l10n addl10n substitution option f proxy toadlet back to referrer new string link link new string a href html encoder encode referrer a option option list add child li l10n addl10n substitution option f proxy toadlet back tof proxy new string link link new string a href a if ctx is allowed full access container public gateway mode option option list add child li html node option form ctx add form child option queue too big queue form option form add child input new string type name value new string hidden key key to string option form add child input new string type name value new string hidden return type disk option form add child input new string type name value new string hidden persistence forever option form add child input new string type name value new string hidden type mime type option form add child input new string type name value new string submit download l10n download in background to disk byte page bytes page node generate get bytes utf 8 context send reply headers 200 ok new multi value table handledownload toadletcontext bucketfactory bucketfactory mimetype requestedmimetype forcestring forcedownload basepath downloadlink toadletcontext nodeclientcore dontfreedata toadletcontextclosedexception ioexception toadletcontainer getcontainer shouldlog fproxytoadlet fproxytoadlet handledownload mimetype mimetype requestedmimetype requestedmimetype forcedownload forcedownload basepath basepath extrasnomime requestedmimetype mimetype requestedmimetype mimetype requestedmimetype mimetype requestedmimetype currenttimemillis forcestring forcestring getforcevalue forcestring getforcevalue force_grain_interval tofree tmprange forcedownload filteroutput contentfilter bucketfactory mimetype basepath enableinlineprefetch prefetchhook tofree mimetype horribleevilhack mimetype startswith htmlnode pagenode getpagemaker getpagenode dangerousrsstitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild addchild dangerousrsssubtitle htmlnode infoboxcontent addchild infoboxcontent addchild getstring fproxytoadlet mimetype infoboxcontent addchild htmlnode optionlist infoboxcontent addchild htmlnode optionlist addchild addl10nsubstitution fproxytoadlet openpossrssasplaintext basepath tostring getforcevalue extrasnomime optionlist addchild addl10nsubstitution fproxytoadlet openpossrssforcedisk basepath tostring mimetype startswith mimetype startswith mimetype startswith optionlist addchild addl10nsubstitution fproxytoadlet openrssforce basepath tostring getforcevalue htmlencoder mimetype optionlist addchild addl10nsubstitution fproxytoadlet openrssasrss basepath tostring getforcevalue extrasnomime optionlist addchild addl10nsubstitution fproxytoadlet backtoreferrer htmlencoder optionlist addchild addl10nsubstitution fproxytoadlet backtofproxy pagebytes pagenode getbytes sendreplyheaders multivaluetable pagebytes writedata pagebytes forcedownload multivaluetable multivaluetable getpreferredfilename sendreplyheaders writedata multivaluetable getheaders rangestr rangestr parserange rangestr tmprange bucketfactory makebucket inputstream getinputstream outputstream tmprange getoutputstream fileutil multivaluetable rethdr multivaluetable rethdr sendreplyheaders rethdr mimetype tmprange writedata tmprange sendreplyheaders multivaluetable mimetype writedata urisyntaxexception printstacktrace fproxytoadlet unsafecontenttypeexception htmlnode pagenode getpagemaker getpagenode dangerouscontenttitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild addchild getrawtitle htmlnode infoboxcontent addchild htmlnode infoboxcontent addchild writesizeandmime mimetype infoboxcontent addchild addchild gethtmlexplanation infoboxcontent addchild htmlnode optionlist infoboxcontent addchild htmlnode mimetype pluginmanager ispluginloaded thawindexbrowser thawindexbrowser optionlist addchild addl10nsubstitution fproxytoadlet openasthawindex basepath thawindexbrowser thawindexbrowser tostring optionlist addchild addl10nsubstitution fproxytoadlet openastext basepath tostring extrasnomime optionlist addchild addl10nsubstitution fproxytoadlet openforcedisk basepath tostring mimetype mimetype optionlist addchild addl10nsubstitution fproxytoadlet openforce basepath tostring getforcevalue htmlencoder mimetype optionlist addchild addl10nsubstitution fproxytoadlet backtoreferrer htmlencoder optionlist addchild addl10nsubstitution fproxytoadlet backtofproxy isallowedfullaccess publicgatewaymode optionlist addchild htmlnode optionform addformchild toobigqueueform optionform addchild tostring optionform addchild optionform addchild optionform addchild mimetype optionform addchild downloadinbackgroundtodisk pagebytes pagenode getbytes sendreplyheaders multivaluetable private static string l10n string msg return l10n get string f proxy toadlet msg getstring fproxytoadlet does the first 512 bytes of the data contain anything that firefox might regard as rss this is a horrible evil hack we shouldn t be doing blacklisting we should be doing whitelisting redflag expect future security issues throws io exception private static boolean horrible evil hack bucket data throws io exception input stream is null try int sz int math min data size 512 if sz 0 return false is data get input stream byte buf new byte sz fixme fortunately firefox doesn t detect rss in utf16 etc yet is read buf look for any of the following strings rss lt feed lt rdf rdf if they start at the beginning of the file or are preceded by one or more lt or lt tags then firefox will read it as rss in which case we must force it to be downloaded to disk if check for string buf rss return true if check for string buf feed return true if check for string buf rdf rdf return true finally closer close is return false ioexception horribleevilhack ioexception inputstream getinputstream checkforstring checkforstring checkforstring scan for a us ascii byte char string within a given buffer of possibly binary data private static boolean check for string byte buf string find int offset 0 int buf progress 0 while offset buf length byte b buf offset if b find char at buf progress buf progress if buf progress find length return true else buf progress 0 if buf progress 0 continue check if this byte is equal to the first one offset return false checkforstring bufprogress charat bufprogress bufprogress bufprogress bufprogress bufprogress override public void handle get uri uri http request httprequest toadlet context ctx throws toadlet context closed exception io exception redirect exception string ks uri get path boolean logminor logger should log logger minor this if ks equals if httprequest is parameter set key string k httprequest get param key freeneturi newuri try newuri new freeneturi k catch malformedurl exception e logger normal this invalid key e for k e send error page ctx 404 l10n not found title l10n get string f proxy toadlet invalid key with reason new string reason new string e to string return if logminor logger minor this redirecting to freeneturi newuri string requested mime type httprequest get param type long max size httprequest get long param max size max length string location get link newuri requested mime type max size httprequest get param force null httprequest is parameter set forcedownload write temporary redirect ctx null location return try string querystring uri get query if querystring null throw new redirect exception welcome else todp possibly a proper url encode method querystring querystring replace throw new redirect exception welcome querystring catch uri syntax exception e huh else if ks equals favicon ico byte buf new byte 1024 int len input stream strm get class get resource as stream staticfiles favicon ico if strm null this send error page ctx 404 l10n path not found title l10n path not found return ctx send reply headers 200 ok null image x icon strm available while len strm read buf 0 ctx write data buf 0 len strm close return else if ks equals robots txt ctx do robots this write text reply ctx 200 ok user agent n disallow return else if ks starts with darknet ks equals darknet todo pre build 1045 url format remove when obsolete write permanent redirect ctx obsoleted friends return else if ks starts with opennet ks equals opennet todo pre build 1045 url format remove when obsolete write permanent redirect ctx obsoleted strangers return if ks starts with ks ks substring 1 long max size boolean restricted container public gateway mode ctx is allowed full access if restricted max size max length else max size httprequest get long param max size max length first check of httprange before get only valid number format is checked here string range str ctx get headers get range if range str null try parse range range str catch http range exception e logger normal this invalid range header range str e ctx send reply headers 416 requested range not satisfiable null null 0 return freeneturi key try key new freeneturi ks catch malformedurl exception e html node page node ctx get page maker get page node l10n invalid key title ctx html node content node ctx get page maker get content node page node html node error infobox content node add child div class infobox infobox error error infobox add child div class infobox header l10n get string f proxy toadlet invalid key with reason new string reason new string e to string html node error content error infobox add child div class infobox content error content add child l10n expected key but got error content add child code ks error content add child br error content add child ctx get page maker create back link ctx l10n go back error content add child br add homepage link error content this writehtml reply ctx 400 l10n invalid key title page node generate return string requested mime type httprequest get param type null string override requested mime type null type url encoder encode requested mime type true no point passing force across a redirect since the key will change however there is every point in passing forcedownload if httprequest is parameter set forcedownload if override length 0 override forcedownload else override override forcedownload bucket data null string mime type null string referer sanitize referer ctx fetch exception fe null multi value table string string headers ctx get headers string ua headers get user agent string accept headers get accept f proxy fetch result fr null if logminor logger minor this ua ua accept accept if is browser ua accept null accept index of text html 1 f proxy fetch waiter fetch fetch tracker make fetcher key max size while true fr fetch get result if fr has data data fr data mime type fr mime type fetch close not waiting any more but still locked the results until sent break else if fr failed null fe fr failed fetch close not waiting any more but still locked the results until sent break else still in progress boolean is js enabled ctx get container isf proxy javascript enabled html node page node ctx get page maker get page node l10n fetching page title ctx string location get link key requested mime type max size httprequest get param force null httprequest is parameter set forcedownload html node head node ctx get page maker get head node page node if is js enabled if the user has enabled javascript we add a noscript http refresh if he has disabled it in the browser and the script file head node add child noscript add child meta http equiv refresh add attribute content 2 url location html node script node head node add child script abc script node add attribute type text javascript script node add attribute src static js progresspage js else if he disabled it we just put the http refresh meta without the noscript head node add child meta http equiv refresh add attribute content 2 url location html node content node ctx get page maker get content node page node html node infobox content node add child div class infobox infobox information infobox add child div class infobox header l10n fetching page box html node infobox content infobox add child div class infobox content infobox content add attribute id info content infobox content add child l10n filename label infobox content add child a href key to string false false key get preferred filename if fr mime type null infobox content add child br l10n content type label fr mime type if fr size 0 infobox content add child br size size util format size fr size if core is advanced mode enabled infobox content add child br l10n blocks detail new string fetched required total failed fatallyfailed new string integer to string fr fetched blocks integer to string fr required blocks integer to string fr total blocks integer to string fr failed blocks integer to string fr fatally failed blocks infobox content add child br l10n time elapsed label time util format time system current time millis fr time started long eta fr eta if eta 0 infobox content add child br eta time util format time eta if fr gone to network infobox content add child p l10n progress downloading else infobox content add child p l10n progress checking store if fr finalized blocks infobox content add child p l10n progress not finalized html node table infobox content add child table border 0 html node progress cell table add child tr add child td class request progress if fr total blocks 0 progress cell add child l10n get string queue toadlet unknown else int total fr required blocks int fetched percent int fr fetched blocks double total 100 int failed percent int fr failed blocks double total 100 int fatally failed percent int fr fatally failed blocks double total 100 html node progress bar progress cell add child div class progressbar progress bar add child div new string class style new string progressbar done width fetched percent if fr failed blocks 0 progress bar add child div new string class style new string progressbar failed width failed percent if fr fatally failed blocks 0 progress bar add child div new string class style new string progressbar failed2 width fatally failed percent number format nf number format get instance nf set maximum fraction digits 1 string prefix integer to string fr fetched blocks integer to string total if fr finalized blocks progress bar add child div new string class title new string progress fraction finalized prefix l10n get string queue toadlet progressbar accurate nf format int fr fetched blocks double total 1000 10 0 else string text nf format int fr fetched blocks double total 1000 10 0 if fr finalized blocks text fr fetched bloc handleget httprequest toadletcontext toadletcontextclosedexception ioexception redirectexception getpath shouldlog isparameterset getparam malformedurlexception senderrorpage notfoundtitle getstring fproxytoadlet invalidkeywithreason tostring requestedmimetype getparam maxsize getlongparam max_length getlink requestedmimetype maxsize getparam isparameterset writetemporaryredirect getquery redirectexception urlencode redirectexception urisyntaxexception inputstream getclass getresourceasstream senderrorpage pathnotfoundtitle pathnotfound sendreplyheaders writedata dorobots writetextreply ndisallow startswith writepermanentredirect startswith writepermanentredirect startswith maxsize publicgatewaymode isallowedfullaccess maxsize max_length maxsize getlongparam max_length rangestr getheaders rangestr parserange rangestr httprangeexception rangestr sendreplyheaders malformedurlexception htmlnode pagenode getpagemaker getpagenode invalidkeytitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode errorinfobox contentnode addchild errorinfobox addchild getstring fproxytoadlet invalidkeywithreason tostring htmlnode errorcontent errorinfobox addchild errorcontent addchild expectedkeybutgot errorcontent addchild errorcontent addchild errorcontent addchild getpagemaker createbacklink goback errorcontent addchild addhomepagelink errorcontent writehtmlreply invalidkeytitle pagenode requestedmimetype getparam requestedmimetype urlencoder requestedmimetype isparameterset mimetype sanitizereferer fetchexception multivaluetable getheaders fproxyfetchresult isbrowser indexof fproxyfetchwaiter fetchtracker makefetcher maxsize getresult hasdata mimetype mimetype isjsenabled getcontainer isfproxyjavascriptenabled htmlnode pagenode getpagemaker getpagenode fetchingpagetitle getlink requestedmimetype maxsize getparam isparameterset htmlnode headnode getpagemaker getheadnode pagenode isjsenabled headnode addchild addchild addattribute htmlnode scriptnode headnode addchild scriptnode addattribute scriptnode addattribute headnode addchild addattribute htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild addchild fetchingpagebox htmlnode infoboxcontent addchild infoboxcontent addattribute infocontent infoboxcontent addchild filenamelabel infoboxcontent addchild tostring getpreferredfilename mimetype infoboxcontent addchild contenttypelabel mimetype infoboxcontent addchild sizeutil formatsize isadvancedmodeenabled infoboxcontent addchild blocksdetail tostring fetchedblocks tostring requiredblocks tostring totalblocks tostring failedblocks tostring fatallyfailedblocks infoboxcontent addchild timeelapsedlabel timeutil formattime currenttimemillis timestarted infoboxcontent addchild timeutil formattime gonetonetwork infoboxcontent addchild progressdownloading infoboxcontent addchild progresscheckingstore finalizedblocks infoboxcontent addchild progressnotfinalized htmlnode infoboxcontent addchild htmlnode progresscell addchild addchild totalblocks progresscell addchild getstring queuetoadlet requiredblocks fetchedpercent fetchedblocks failedpercent failedblocks fatallyfailedpercent fatallyfailedblocks htmlnode progressbar progresscell addchild progressbar addchild fetchedpercent failedblocks progressbar addchild failedpercent fatallyfailedblocks progressbar addchild fatallyfailedpercent numberformat numberformat getinstance setmaximumfractiondigits tostring fetchedblocks tostring finalizedblocks progressbar addchild progress_fraction_finalized getstring queuetoadlet progressbaraccurate fetchedblocks fetchedblocks finalizedblocks fetchedbloc if data null fe null fr has waited fetch result result fetch key max size new request client public boolean persistent return false haswaited fetchresult maxsize requestclient return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private boolean is browser string ua if ua null return false if ua index of mozilla 1 return true if ua index of opera 1 return true return false isbrowser indexof indexof private static string write size andmime html node file information list fetch exception e boolean finalized e finalized size string mime e get expected mime type long size e expected size write size andmime file information list size mime finalized return mime writesizeandmime htmlnode fileinformationlist fetchexception finalizedsize getexpectedmimetype expectedsize writesizeandmime fileinformationlist private static void write size andmime html node file information list long size string mime boolean finalized if size 0 if finalized file information list add child li l10n size label size util format size size else file information list add child li l10n size label size util format size size l10n may change else file information list add child li l10n size unknown if mime null file information list add child li l10n get string f proxy toadlet finalized mime type expected mime type new string mime new string mime else file information list add child li l10n unknownmime type writesizeandmime htmlnode fileinformationlist fileinformationlist addchild sizelabel sizeutil formatsize fileinformationlist addchild sizelabel sizeutil formatsize maychange fileinformationlist addchild sizeunknown fileinformationlist addchild getstring fproxytoadlet mimetype expectedmimetype fileinformationlist addchild unknownmimetype private string l10n string key string pattern string value return l10n get string f proxy toadlet key new string pattern new string value getstring fproxytoadlet private string l10n string key string pattern string value return l10n get string f proxy toadlet key pattern value getstring fproxytoadlet private string get link freeneturi uri string requested mime type long max size string force boolean force download string builder sb new string builder sb append sb append uri toascii string char c if requested mime type null sb append c append type append url encoder encode requested mime type false c if max size 0 max size max length sb append c append max size append max size c if force null sb append c append force append force c if force download sb append c append forcedownload true c return sb to string getlink requestedmimetype maxsize forcedownload stringbuilder stringbuilder toasciistring requestedmimetype urlencoder requestedmimetype maxsize maxsize max_length maxsize forcedownload tostring private string sanitize referer toadlet context ctx fixme we do something similar in the generic filter callback thingy string referer ctx get headers get referer if referer null try uri refereruri new uri referer string path refereruri get path while path starts with path path substring 1 if equals path return freeneturi furi new freeneturi path http request req new http request impl refereruri string type req get param type referer furi to string if type null type length 0 referer type type catch malformedurl exception e referer logger normal this caught malformedurl exception on the referer e get message catch throwable t logger error this caught handling referrer t for referer t referer null return referer sanitizereferer toadletcontext genericfiltercallback getheaders getpath startswith httprequest httprequestimpl getparam tostring malformedurlexception malformedurlexception getmessage private static string get force value freeneturi key long time byte array output stream bos new byte array output stream try bos write random bos write key to string get bytes utf 8 bos write long to string time force grain interval get bytes utf 8 catch io exception e throw new error e string f hex util bytes to hex sha256 digest bos to byte array return f getforcevalue bytearrayoutputstream bytearrayoutputstream tostring getbytes tostring force_grain_interval getbytes ioexception hexutil bytestohex tobytearray public static void maybe createf proxy etc node client core core node node config config simple toadlet server server bookmark manager bookmarks throws io exception fixme how to change these on the fly when the interface language is changed high level simple client client core make client request starter interactive priority class true random new byte 32 core random next bytes random f proxy toadlet fproxy new f proxy toadlet client core core setf proxy fproxy server register fproxy false f proxy toadlet welcome title f proxy toadlet welcome false null user alerts toadlet alerts new user alerts toadlet client node core server register alerts alerts true f proxy toadlet alerts title f proxy toadlet alerts true null queue toadlet queue toadlet new queue toadlet core core getfcp server client server register queue toadlet queue true f proxy toadlet queue title f proxy toadlet queue false queue toadlet pproxy toadlet pproxy new pproxy toadlet client node core server register pproxy plugins true f proxy toadlet plugins title f proxy toadlet plugins true null welcome toadlet welcometoadlet new welcome toadlet client core node bookmarks server register welcometoadlet welcome true false symlinker toadlet symlink toadlet new symlinker toadlet client node server register symlink toadlet sl true false darknet connections toadlet friends toadlet new darknet connections toadlet node core client server register friends toadlet friends true f proxy toadlet friends title f proxy toadlet friends true null opennet connections toadlet opennet toadlet new opennet connections toadlet node core client server register opennet toadlet strangers true f proxy toadlet opennet title f proxy toadlet opennet true opennet toadlet n2ntm toadlet n2ntm toadlet new n2ntm toadlet node core client server register n2ntm toadlet send n2ntm true true local file insert toadlet local file insert toadlet new local file insert toadlet core client server register local file insert toadlet files true false bookmark editor toadlet bookmark editor toadlet new bookmark editor toadlet client core bookmarks server register bookmark editor toadlet bookmark editor true false browser test toadlet browsert test toadlet new browser test toadlet client core server register browsert test toadlet test true false statistics toadlet statistics toadlet new statistics toadlet node core client server register statistics toadlet stats true f proxy toadlet stats title f proxy toadlet stats true null connectivity toadlet connectivity toadlet new connectivity toadlet client node core server register connectivity toadlet connectivity true connectivity toadlet connectivity title connectivity toadlet connectivity true null translation toadlet translation toadlet new translation toadlet client core server register translation toadlet translation toadlet toadlet url true true first time wizard toadlet first time wizard toadlet new first time wizard toadlet client node core server register first time wizard toadlet first time wizard toadlet toadlet url true false config toadlet configtoadlet new config toadlet client config node core server register configtoadlet config true f proxy toadlet config title f proxy toadlet config true null simple help toadlet simple help toadlet new simple help toadlet client core server register simple help toadlet help true false maybecreatefproxyetc nodeclientcore simpletoadletserver bookmarkmanager ioexception highlevelsimpleclient makeclient requeststarter interactive_priority_class nextbytes fproxytoadlet fproxytoadlet setfproxy fproxytoadlet welcometitle fproxytoadlet useralertstoadlet useralertstoadlet fproxytoadlet alertstitle fproxytoadlet queuetoadlet queuetoadlet queuetoadlet getfcpserver queuetoadlet fproxytoadlet queuetitle fproxytoadlet queuetoadlet pproxytoadlet pproxytoadlet fproxytoadlet pluginstitle fproxytoadlet welcometoadlet welcometoadlet symlinkertoadlet symlinktoadlet symlinkertoadlet symlinktoadlet darknetconnectionstoadlet friendstoadlet darknetconnectionstoadlet friendstoadlet fproxytoadlet friendstitle fproxytoadlet opennetconnectionstoadlet opennettoadlet opennetconnectionstoadlet opennettoadlet fproxytoadlet opennettitle fproxytoadlet opennettoadlet n2ntmtoadlet n2ntmtoadlet n2ntmtoadlet n2ntmtoadlet send_n2ntm localfileinserttoadlet localfileinserttoadlet localfileinserttoadlet localfileinserttoadlet bookmarkeditortoadlet bookmarkeditortoadlet bookmarkeditortoadlet bookmarkeditortoadlet bookmarkeditor browsertesttoadlet browserttesttoadlet browsertesttoadlet browserttesttoadlet statisticstoadlet statisticstoadlet statisticstoadlet statisticstoadlet fproxytoadlet statstitle fproxytoadlet connectivitytoadlet connectivitytoadlet connectivitytoadlet connectivitytoadlet connectivitytoadlet connectivitytitle connectivitytoadlet translationtoadlet translationtoadlet translationtoadlet translationtoadlet translationtoadlet toadlet_url firsttimewizardtoadlet firsttimewizardtoadlet firsttimewizardtoadlet firsttimewizardtoadlet firsttimewizardtoadlet toadlet_url configtoadlet configtoadlet fproxytoadlet configtitle fproxytoadlet simplehelptoadlet simplehelptoadlet simplehelptoadlet simplehelptoadlet get expected filename for a file param e the fetch exception param uri the original uri param expected mime type the expected mime type private string get filename fetch exception e freeneturi uri string expected mime type string s uri get preferred filename int dot idx s last index of string ext defaultmime types get extension expected mime type if ext null ext bin if dot idx 1 expected mime type null s ext return s if dot idx 1 string old ext s substring dot idx 1 if defaultmime types is valid ext expected mime type old ext return s return s ext return s ext fetchexception expectedmimetype getfilename fetchexception expectedmimetype getpreferredfilename dotidx lastindexof defaultmimetypes getextension expectedmimetype dotidx expectedmimetype dotidx oldext dotidx defaultmimetypes isvalidext expectedmimetype oldext private static long parse range string hdrrange throws http range exception long result new long 2 try string units hdrrange split 2 fixme are m bytes and co valid if so we need to adjust the values and return always bytes if bytes equals units 0 throw new http range exception unknown unit only bytes supportet yet string range units 1 split 2 result 0 long parse long range 0 if result 0 0 throw new http range exception negative from value if range 1 trim length 0 result 1 long parse long range 1 if result 1 result 0 throw new http range exception from value must be less then to value else result 1 1 catch number format exception nfe throw new http range exception nfe catch index out of bounds exception ioobe throw new http range exception ioobe return result parserange httprangeexception mbytes httprangeexception parselong httprangeexception parselong httprangeexception numberformatexception httprangeexception indexoutofboundsexception httprangeexception public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private static final long serial versionuid 1 override public final synchronized throwable fill in stack trace return null serialversionuid fillinstacktrace private ticker ticker public synchronized void set ticker ticker ticker this ticker ticker setticker public pooled executor for int i 0 i running threads length i running threads i new array list my thread waiting threads i new array list my thread thread counter i new atomic long waiting threads count 0 pooledexecutor runningthreads runningthreads arraylist mythread waitingthreads arraylist mythread threadcounter atomiclong waitingthreadscount static final int timeout 5 60 1000 public void start logminor logger should log logger minor this shouldlog public void execute runnable job string job name execute job job name false jobname jobname public void execute runnable runnable string job name boolean from ticker int prio native thread norm priority if runnable instanceof prio runnable prio prio runnable runnable get priority if logminor logger minor this executing runnable as job name at prio prio if prio native thread min priority prio native thread max priority throw new illegal argument exception unreconized priority level prio job job new job runnable job name while true my thread t null boolean miss false synchronized this job count if waiting threads prio 1 is empty t waiting threads prio 1 remove waiting threads prio 1 size 1 if t null waiting threads count if logminor logger minor this reusing thread t else must create new thread if from ticker native thread using native code prio thread current thread get priority run on ticker j16sdiz 22 dec 2008 should we queue it the ticker is packet sender but it keep busying on non packet related works ticker queue timed job runnable job name 0 true return miss true miss if miss long thread no thread counter prio 1 get and increment will be coalesced by thread count listings if we use or for t new my thread pooled thread awaiting work thread no job thread no prio from ticker t set daemon true synchronized this running threads prio 1 add t job misses if logminor logger minor this jobs job misses misses of job count starting urgently job name t start return use existing thread synchronized t if t alive continue if t next job null continue t next job job it is possible that we could get a wierd race condition with notify wait signalling on a thread being used by higher level code so we d best use notify all t notify all if logminor synchronized this logger minor this not starting jobs job misses misses of job count starting urgently job name return jobname fromticker nativethread norm_priority priorunnable priorunnable getpriority jobname nativethread min_priority nativethread max_priority illegalargumentexception jobname mythread jobcount waitingthreads isempty waitingthreads waitingthreads waitingthreadscount fromticker nativethread usingnativecode currentthread getpriority packetsender queuetimedjob jobname threadno threadcounter getandincrement mythread threadno threadno fromticker setdaemon runningthreads jobmisses jobmisses jobcount jobname nextjob nextjob notifyall notifyall jobmisses jobcount jobname public synchronized int running threads int result new int running threads length for int i 0 i result length i result i running threads i size waiting threads i size return result runningthreads runningthreads runningthreads waitingthreads public synchronized int waiting threads int result new int waiting threads length for int i 0 i result length i result i waiting threads i size return result waitingthreads waitingthreads waitingthreads public int get waiting threads count return waiting threads count getwaitingthreadscount waitingthreadscount private string name job runnable runnable string name this runnable runnable this name name public my thread string default name job first job long thread counter int prio boolean dont check renice super default name prio dont check renice this default name default name thread no thread counter next job first job mythread defaultname firstjob threadcounter dontcheckrenice defaultname dontcheckrenice defaultname defaultname threadno threadcounter nextjob firstjob override public void run super run long ran jobs 0 int native priority get native priority while true job job synchronized this job next job next job null if job null synchronized pooled executor this waiting threads native priority 1 add this waiting threads count synchronized this if next job null this set name default name try wait timeout catch interrupted exception e ignore synchronized pooled executor this if waiting threads native priority 1 remove this waiting threads count synchronized this job next job next job null if job null alive false if alive running threads native priority 1 remove this if logminor logger minor this exiting having executed ran jobs jobs this return run the job try set name job name thread no job runnable run catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t running job job t ran jobs ranjobs nativepriority getnativepriority nextjob nextjob pooledexecutor waitingthreads nativepriority waitingthreadscount nextjob setname defaultname interruptedexception pooledexecutor waitingthreads nativepriority waitingthreadscount nextjob nextjob runningthreads nativepriority ranjobs setname threadno outofmemoryerror oomhandler ranjobs draws a noise on the image the noise curve depends on the factor values noise won t be visible if all factors have the value 1 0f param image the image to add the noise to param factor one param factor two param factor three param factor four public void make noise buffered image image float factor one float factor two float factor three float factor four color color get config get noise color image size int width image get width int height image get height the points where the line changes the stroke and direction point2d pts null random rand new random the curve from where the points are taken cubic curve2d cc new cubic curve2d float width factor one height rand next float width factor two height rand next float width factor three height rand next float width factor four height rand next float creates an iterator to define the boundary of the flattened curve path iterator pi cc get path iterator null 2 point2d tmp new point2d 200 int i 0 while pi is iterating the curve adds points to tmp array while pi is done float coords new float 6 switch pi current segment coords case path iterator seg moveto case path iterator seg lineto tmp i new point2d float coords 0 coords 1 i pi next pts new point2d i system arraycopy tmp 0 pts 0 i graphics2d graph graphics2d image get graphics graph set rendering hints new rendering hints rendering hints key antialiasing rendering hints value antialias on graph set color color for the maximum 3 point change the stroke and direction for i 0 i pts length 1 i if i 3 graph set stroke new basic stroke 0 9f 4 i graph draw line int pts i getx int pts i gety int pts i 1 getx int pts i 1 gety graph dispose factorone factortwo factorthree factorfour makenoise bufferedimage factorone factortwo factorthree factorfour getconfig getnoisecolor getwidth getheight cubiccurve2d cubiccurve2d factorone nextfloat factortwo nextfloat factorthree nextfloat factorfour nextfloat pathiterator getpathiterator isdone currentsegment pathiterator seg_moveto pathiterator seg_lineto getgraphics setrenderinghints renderinghints renderinghints key_antialiasing renderinghints value_antialias_on setcolor setstroke basicstroke drawline query node visitor public void visit full text query visitor visitor visitor visit this opd visit visitor fulltextqueryvisitor this method checks that query can be executed by interection of keyword occurrences lists return true if quuery can be executed by full text index false otherwise public boolean is constrained return op not false opd is constrained fulltextindex isconstrained isconstrained public string to string return operator name op opd to string tostring operatorname tostring unary node constructor param op operation code param opd operand public full text query unary op int op full text query opd super op this opd opd fulltextqueryunaryop fulltextquery public final string expectedmime type public expectedmime event string type this expectedmime type type expectedmimetype expectedmimeevent expectedmimetype public int get code return code getcode public string get description return expected mime type expectedmime type getdescription expectedmimetype public static void main string args throws fs parse exception io exception opennet disabled exception peer parse exception interrupted exception reference signature verification exception node init exception invalid threshold exception node node null try if args length 1 status dir new file args 0 random source random node starter global test init seednode pingtest false logger error false create one node executor executor new pooled executor node node starter create test node 5000 5001 seednode pingtest true false false node default max htl 0 random executor 1000 5 1024 1024 true false false false false false false 0 false false null connect ping list seed server test peer node seed nodes new array list seed server test peer node list simple field set seed nodes assfs announcer read seednodes new file tmp int number of nodes in the file 0 for simple field set sfs seed nodes assfs number of nodes in the file seed server test peer node seednode node create new seed server test peer node sfs try node connect to seednode seednode seed nodes add seednode catch exception fse system out println error adding seednode to string fse get message start it node start true logger setup stdout logging logger minor freenet normal freenet node node dispatcher minor freenet node fnp packet mangler minor logger get chain set threshold 32 kill logging thread sleep 2000 if seed nodes size number of nodes in the file system out println error adding some of the seednodes system out println let some time for the seed nodes size nodes to connect thread sleep 8000 int pingid 0 long deadline system current time millis 2 60 1000 while system current time millis deadline int count connected seednodes 0 for seed server peer node seednode node peers get connected seed server peers vector null try double ping time seednode average ping time int uptime seednode get uptime long time delta seednode get clock delta if seednode is real connection continue count connected seednodes boolean ping seednode ping pingid if ping system out println seednode get identity string uptime uptime ping ping ping time ping time uptime seednode get uptime time delta time util format time time delta sanity check if seednode is routable system out println seednode is routable catch not connected exception e system out println seednode get identity string is not connected seednode get handshake count map fate integer totals new enum map fate integer seed server test peer node fate class for seed server test peer node seednode seed nodes fate fate seednode get fate integer x totals get fate if x null totals put fate 1 else totals put fate x 1 system out println seednode get identity string fate seednode get peer node status string system out println totals for fate fate totals key set system out println fate totals get fate system out println node peers count connected peers count connected seednodes node peers count seednodes thread sleep 5000 map fate integer totals new enum map fate integer seed server test peer node fate class for seed server test peer node seednode seed nodes fate fate seednode get fate integer x totals get fate if x null totals put fate 1 else totals put fate x 1 system out println seednode get identity string fate seednode get peer node status string system out println result totals for fate fate totals key set system out println result fate totals get fate system out println completed seednodes scan record statuses system out println final status long write time system current time millis for seed server test peer node peer seed nodes string status write time peer get identity string peer get fate system out println status file log file new file status dir peer get identity string file output stream fos new file output stream log file true output stream writer osw new output stream writer fos utf 8 osw write status n osw close file input stream fis new file input stream log file input stream reader isr new input stream reader fis utf 8 buffered reader br new buffered reader isr string line int successes 0 int failures 0 long last success 0 long first sample 0 long count since write time count successes period do line br read line if line null break string results line split if results length 3 system err println unable to parse line in log file wrong number of fields results length line continue long time long parse long results 0 fate fate fate value of results 2 if first sample 0 first sample time if fate fate connected success if time count since successes last success time else if time count since failures while line null br close if first sample count since successes 0 system err println result peer get identity string not connected in last week last connected last success 0 time util format time write time last success never system out println peer get identity string last success last success 0 time util format time write time last success never failures in last week failures successes in last week successes node park system exit 0 catch throwable t system err println caught t t print stack trace try if node null node park catch throwable t1 system exit 1 fsparseexception ioexception opennetdisabledexception peerparseexception interruptedexception referencesignatureverificationexception nodeinitexception invalidthresholdexception status_dir randomsource nodestarter globaltestinit pooledexecutor nodestarter createtestnode default_max_htl seedservertestpeernode seednodes arraylist seedservertestpeernode simplefieldset seednodesassfs readseednodes numberofnodesinthefile simplefieldset seednodesassfs numberofnodesinthefile seedservertestpeernode createnewseedservertestpeernode connecttoseednode seednodes tostring getmessage setupstdoutlogging nodedispatcher fnppacketmangler getchain setthreshold seednodes numberofnodesinthefile seednodes currenttimemillis currenttimemillis countconnectedseednodes seedserverpeernode getconnectedseedserverpeersvector pingtime averagepingtime getuptime timedelta getclockdelta isrealconnection countconnectedseednodes getidentitystring pingtime pingtime getuptime timedelta timeutil formattime timedelta isroutable notconnectedexception getidentitystring gethandshakecount enummap seedservertestpeernode seedservertestpeernode seednodes getfate getidentitystring getpeernodestatusstring keyset countconnectedpeers countconnectedseednodes countseednodes enummap seedservertestpeernode seedservertestpeernode seednodes getfate getidentitystring getpeernodestatusstring keyset writetime currenttimemillis seedservertestpeernode seednodes writetime getidentitystring getfate logfile status_dir getidentitystring fileoutputstream fileoutputstream logfile outputstreamwriter outputstreamwriter fileinputstream fileinputstream logfile inputstreamreader inputstreamreader bufferedreader bufferedreader lastsuccess firstsample countsince writetime count_successes_period readline logfile parselong valueof firstsample firstsample connected_success countsince lastsuccess countsince firstsample countsince getidentitystring lastsuccess timeutil formattime writetime lastsuccess getidentitystring lastsuccess timeutil formattime writetime lastsuccess printstacktrace public class null output stream extends output stream public null output stream nulloutputstream outputstream nulloutputstream public class null output stream extends output stream public null output stream override public void write int b nulloutputstream outputstream nulloutputstream override public void write int b override public void write byte buf int off int len static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public abstract void on transition client get state old state client get state new state object container container ontransition clientgetstate oldstate clientgetstate newstate objectcontainer protected final sendable request set requests public short get priority class return priority class sendablerequestset getpriorityclass priorityclass protected client requester short priority class request client client this priority class priority class this client client if client null throw new null pointer exception hash code super hash code the old object id will do fine as long as we ensure it doesn t change requests persistent new persistent sendable request set new transient sendable request set clientrequester priorityclass requestclient priorityclass priorityclass nullpointerexception hashcode hashcode persistentsendablerequestset transientsendablerequestset public synchronized boolean cancel boolean ret cancelled cancelled true return ret public abstract void cancel object container container client context context objectcontainer clientcontext public abstract void cancel object container container client context context public boolean is cancelled return cancelled objectcontainer clientcontext iscancelled public abstract freeneturi geturi public abstract freeneturi geturi public abstract boolean is finished isfinished we need a hash code that persists across restarts override public int hash code return hash code hashcode hashcode public void block set finalized object container container client context context synchronized this if block set finalized return block set finalized true if logminor logger minor this finalized set of blocks for this new exception debug if persistent container store this notify clients container context blocksetfinalized objectcontainer clientcontext blocksetfinalized blocksetfinalized notifyclients public void add block object container container boolean was finalized synchronized this total blocks was finalized block set finalized if was finalized if logger global get threshold logger minor logger error this add block but set finalized on this else logger error this add block but set finalized on this new exception error if logminor logger minor this add block total total blocks successful successful blocks failed failed blocks required min success blocks if persistent container store this addblock objectcontainer wasfinalized totalblocks wasfinalized blocksetfinalized wasfinalized globalgetthreshold addblock addblock addblock totalblocks successfulblocks failedblocks minsuccessblocks public void add blocks int num object container container boolean was finalized synchronized this total blocks num was finalized block set finalized if was finalized if logger global get threshold logger minor logger error this add blocks but set finalized on this else logger error this add blocks but set finalized on this new exception error if logminor logger minor this add blocks num total total blocks successful successful blocks failed failed blocks required min success blocks if persistent container store this addblocks objectcontainer wasfinalized totalblocks wasfinalized blocksetfinalized wasfinalized globalgetthreshold addblocks addblocks addblocks totalblocks successfulblocks failedblocks minsuccessblocks public void completed block boolean dont notify object container container client context context if logminor logger minor this completed block dont notify total total blocks success successful blocks failed failed blocks fatally fatally failed blocks finalised block set finalized required min success blocks on this synchronized this if cancelled return successful blocks if persistent container store this if dont notify return notify clients container context completedblock dontnotify objectcontainer clientcontext dontnotify totalblocks successfulblocks failedblocks fatallyfailedblocks blocksetfinalized minsuccessblocks successfulblocks dontnotify notifyclients public void failed block object container container client context context synchronized this failed blocks if persistent container store this notify clients container context failedblock objectcontainer clientcontext failedblocks notifyclients public void fatally failed block object container container client context context synchronized this fatally failed blocks if persistent container store this notify clients container context fatallyfailedblock objectcontainer clientcontext fatallyfailedblocks notifyclients public synchronized void add must succeed blocks int blocks object container container min success blocks blocks if persistent container store this if logminor logger minor this add must succeed blocks blocks total total blocks successful successful blocks failed failed blocks required min success blocks addmustsucceedblocks objectcontainer minsuccessblocks addmustsucceedblocks totalblocks successfulblocks failedblocks minsuccessblocks public abstract void notify clients object container container client context context notifyclients objectcontainer clientcontext public void to network object container container client context context synchronized this if sent to network return sent to network true if persistent container store this inner to network container context tonetwork objectcontainer clientcontext senttonetwork senttonetwork innertonetwork protected abstract void inner to network object container container client context context innertonetwork objectcontainer clientcontext protected abstract void inner to network object container container client context context get client context object public request client get client return client innertonetwork objectcontainer clientcontext requestclient getclient public void set priority class short new priority class client context ctx object container container this priority class new priority class ctx get chk fetch scheduler reregister all this container ctx get chk insert scheduler reregister all this container ctx get ssk fetch scheduler reregister all this container ctx get ssk insert scheduler reregister all this container if persistent container store this setpriorityclass newpriorityclass clientcontext objectcontainer priorityclass newpriorityclass getchkfetchscheduler reregisterall getchkinsertscheduler reregisterall getsskfetchscheduler reregisterall getsskinsertscheduler reregisterall public boolean persistent return client persistent public void remove from object container container client context context container activate requests 1 requests remove from container container delete this removefrom objectcontainer clientcontext removefrom public void object on activate object container container container activate client 1 objectonactivate objectcontainer public void add to requests sendable request req object container container if persistent container activate requests 1 requests add request req container if persistent container deactivate requests 1 addtorequests sendablerequest objectcontainer addrequest public sendable request get sendable requests object container container if persistent container activate requests 1 sendable request reqs requests list requests container if persistent container deactivate requests 1 return reqs sendablerequest getsendablerequests objectcontainer sendablerequest listrequests public void remove from requests sendable request req object container container boolean dont complain if persistent container activate requests 1 if requests remove request req container dont complain logger error this not in request list for this req if persistent container deactivate requests 1 removefromrequests sendablerequest objectcontainer dontcomplain removerequest dontcomplain private int ies public multi value table this 16 3 multivaluetable public multi value table int initial size this initial size 3 multivaluetable initialsize initialsize public multi value table int initial size int initial entry size table new hashtable k vector v initial size ies initial entry size multivaluetable initialsize initialentrysize initialsize initialentrysize public void put k key v value synchronized table vector v v table get key if v null v new vector v ies table put key v v add element value addelement returns the first element for this key public v get k key synchronized table vector v v table get key return v null null v first element firstelement public boolean contains key k key synchronized table return table contains key key containskey containskey public boolean contains element k key v value synchronized table vector v v table get key return v null v contains value containselement users will have to handle synchronizing public enumeration v get all k key vector v v synchronized table v table get key return v null new limited enumeration v null v elements getall limitedenumeration to be used in for x y public iterable v iterate all k key synchronized table return table get key iterateall public int count all k key vector v v synchronized table v table get key if v null return v size else return 0 countall public object get sync k key synchronized table return table get key getsync public object get array k key synchronized table vector v v table get key if v null return null else object r new object v size v copy into r return r getarray copyinto public void remove k key synchronized table table remove key public boolean is empty synchronized table return table is empty isempty isempty public void clear synchronized table table clear public boolean remove element k key v value synchronized table vector v v table get key if v null return false else boolean b v remove element value if v is empty table remove key return b removeelement removeelement isempty public enumeration k keys synchronized table return table keys public enumeration v elements synchronized table if table is empty return new limited enumeration v null else return new multi value enumeration isempty limitedenumeration multivalueenumeration private enumeration vector v global public multi value enumeration synchronized table global table elements current global next element elements step multivalueenumeration nextelement public final void step while current has more elements global has more elements current global next element elements hasmoreelements hasmoreelements nextelement public final boolean has more elements return global has more elements current has more elements hasmoreelements hasmoreelements hasmoreelements public final v next element v o current next element step return o nextelement nextelement construct a gaussian filter public gaussian filter this 2 gaussianfilter construct a gaussian filter param radius blur radius in pixels public gaussian filter float radius set radius radius gaussianfilter setradius set the radius of the kernel and hence the amount of blur the bigger the radius the longer this filter will take param radius the radius of the blur in pixels min value 0 max value 100 see get radius public void set radius float radius this radius radius kernel make kernel radius getradius setradius makekernel get the radius of the kernel return the radius see set radius public float get radius return radius setradius getradius override public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int in pixels new int width height int out pixels new int width height src getrgb 0 0 width height in pixels 0 width if radius 0 convolve and transpose kernel in pixels out pixels width height alpha alpha premultiply alpha false clamp edges convolve and transpose kernel out pixels in pixels height width alpha false alpha premultiply alpha clamp edges dst setrgb 0 0 width height in pixels 0 width return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage inpixels outpixels inpixels convolveandtranspose inpixels outpixels premultiplyalpha clamp_edges convolveandtranspose outpixels inpixels premultiplyalpha clamp_edges inpixels blur and transpose a block of argb pixels param kernel the blur kernel param in pixels the input pixels param out pixels the output pixels param width the width of the pixel array param height the height of the pixel array param alpha whether to blur the alpha channel param edge action what to do at the edges public static void convolve and transpose kernel kernel int in pixels int out pixels int width int height boolean alpha boolean premultiply boolean unpremultiply int edge action float matrix kernel get kernel data null int cols kernel get width int cols2 cols 2 for int y 0 y height y int index y int ioffset y width for int x 0 x width x float r 0 g 0 b 0 a 0 int moffset cols2 for int col cols2 col cols2 col float f matrix moffset col if f 0 int ix x col if ix 0 if edge action clamp edges ix 0 else if edge action wrap edges ix x width width else if ix width if edge action clamp edges ix width 1 else if edge action wrap edges ix x width width int rgb in pixels ioffset ix int pa rgb 24 0xff int pr rgb 16 0xff int pg rgb 8 0xff int pb rgb 0xff if premultiply float a255 pa 1 0f 255 0f pr a255 pg a255 pb a255 a f pa r f pr g f pg b f pb if unpremultiply a 0 a 255 float f 255 0f a r f g f b f int ia alpha pixel utils clamp int a 0 5 0xff int ir pixel utils clamp int r 0 5 int ig pixel utils clamp int g 0 5 int ib pixel utils clamp int b 0 5 out pixels index ia 24 ir 16 ig 8 ib index height inpixels outpixels edgeaction convolveandtranspose inpixels outpixels edgeaction getkerneldata getwidth edgeaction clamp_edges edgeaction wrap_edges edgeaction clamp_edges edgeaction wrap_edges inpixels pixelutils pixelutils pixelutils pixelutils outpixels make a gaussian blur kernel param radius the blur radius return the kernel public static kernel make kernel float radius int r int math ceil radius int rows r 2 1 float matrix new float rows float sigma radius 3 float sigma22 2 sigma sigma float sigma pi2 2 image math pi sigma float sqrt sigma pi2 float math sqrt sigma pi2 float radius2 radius radius float total 0 int index 0 for int row r row r row float distance row row if distance radius2 matrix index 0 else matrix index float math exp distance sigma22 sqrt sigma pi2 total matrix index index for int i 0 i rows i matrix i total return new kernel rows 1 matrix makekernel sigmapi2 imagemath sqrtsigmapi2 sigmapi2 sqrtsigmapi2 override public string to string return blur gaussian blur tostring private function2d function new noise public texture filter texturefilter set the amount of texture param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of texture return the amount see set amount public float get amount return amount setamount getamount public void set function function2d function this function function setfunction public function2d get function return function getfunction public void set operation int operation this operation operation setoperation public int get operation return operation getoperation specifies the scale of the texture param scale the scale of the texture min value 1 max value 300 see get scale public void set scale float scale this scale scale getscale setscale returns the scale of the texture return the scale of the texture see set scale public float get scale return scale setscale getscale specifies the stretch factor of the texture param stretch the stretch factor of the texture min value 1 max value 50 see get stretch public void set stretch float stretch this stretch stretch getstretch setstretch returns the stretch factor of the texture return the stretch factor of the texture see set stretch public float get stretch return stretch setstretch getstretch specifies the angle of the texture param angle the angle of the texture angle see get angle public void set angle float angle this angle angle float cos float math cos angle float sin float math sin angle m00 cos m01 sin m10 sin m11 cos getangle setangle returns the angle of the texture return the angle of the texture see set angle public float get angle return angle setangle getangle specifies the turbulence of the texture param turbulence the turbulence of the texture min value 0 max value 1 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the texture return the turbulence of the texture see set turbulence public float get turbulence return turbulence setturbulence getturbulence set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap override public int filterrgb int x int y int rgb float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch float f turbulence 1 0 noise noise2 nx ny noise turbulence2 nx ny turbulence f f 0 5f 0 5f f image math gain f gain f image math bias f bias f amount int a rgb 0xff000000 int v if colormap null v colormap get color f else v pixel utils clamp int f 255 int r v 16 int g v 8 int b v v a r g b if operation pixel utils replace v pixel utils combine pixels rgb v operation return v imagemath imagemath getcolor pixelutils pixelutils pixelutils combinepixels override public string to string return texture noise tostring public soap request set content type soap content type set method http post soaprequest setcontenttype content_type setmethod public soap request http request http req set http req soaprequest httprequest httpreq httpreq public void setsoap action string action set string header soapaction action setsoapaction setstringheader public string getsoap action return get string header value soapaction getsoapaction getstringheadervalue public boolean issoap action string value string header value get header value soapaction if header value null return false if header value equals value true return true string soap action getsoap action if soap action null return false return soap action equals value issoapaction headervalue getheadervalue headervalue headervalue soapaction getsoapaction soapaction soapaction public soap response post message string host int port http response http res post host port soap response soap res new soap response http res byte content soap res get content if content length 0 return soap res try byte array input stream byte in new byte array input stream content parser xml parser soap getxml parser node root node xml parser parse byte in soap res set envelope node root node catch exception e debug warning e return soap res soapresponse postmessage httpresponse httpres soapresponse soapres soapresponse httpres soapres getcontent soapres bytearrayinputstream bytein bytearrayinputstream xmlparser getxmlparser rootnode xmlparser bytein soapres setenvelopenode rootnode soapres private node root node private void set root node node node root node node rootnode setrootnode rootnode private synchronized node get root node if root node null return root node try byte content get content byte array input stream content in new byte array input stream content parser parser soap getxml parser root node parser parse content in catch parser exception e debug warning e return root node getrootnode rootnode rootnode getcontent bytearrayinputstream contentin bytearrayinputstream getxmlparser rootnode contentin parserexception rootnode public void set envelope node node node set root node node setenvelopenode setrootnode public node get envelope node return get root node getenvelopenode getrootnode public node get body node node env node get envelope node if env node null return null if env node has nodes false return null return env node get node 0 getbodynode envnode getenvelopenode envnode envnode hasnodes envnode getnode public void set content node node thanks for ralf g r bergs ralf ber gs inma marin lopez inma dif um es string con str con str soap version header con str n con str node to string set content con str setcontent constr constr version_header constr constr tostring setcontent constr public void print system out println to string if has content true return node root elem get root node if root elem null return system out println root elem to string tostring hascontent rootelem getrootnode rootelem rootelem tostring override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog protected class put handler extends base client putter implements put completion callback protected put handler final base manifest putter smp string name bucket data client metadata cm boolean getchk only this smp null name data cm getchk only puthandler baseclientputter putcompletioncallback puthandler basemanifestputter clientmetadata getchkonly getchkonly protected put handler final base manifest putter smp put handler parent string name bucket data client metadata cm boolean getchk only super smp priority class smp client this persistent base manifest putter this persistent this cm cm this name name insert block block new insert block data cm persistent freeneturi empty chk uri clone freeneturi empty chk uri this origsfi new single file inserter this this block false ctx false getchk only true null null false null early encode metadata null parent put handler parent is archive is container false puthandler basemanifestputter puthandler clientmetadata getchkonly priorityclass basemanifestputter insertblock insertblock empty_chk_uri empty_chk_uri singlefileinserter getchkonly earlyencode parentputhandler isarchive iscontainer protected put handler final base manifest putter smp put handler parent string name hash map string object data freeneturi inserturi client metadata cm boolean getchk only boolean is archive2 super smp priority class smp client this persistent base manifest putter this persistent this cm cm this name name this origsfi new container inserter this this data persistent inserturi clone inserturi ctx false getchk only false null archive type tar false early encode metadata null parent put handler parent is container true is archive is archive2 puthandler basemanifestputter puthandler hashmap clientmetadata getchkonly isarchive2 priorityclass basemanifestputter containerinserter getchkonly archive_type earlyencode parentputhandler iscontainer isarchive isarchive2 protected put handler final base manifest putter smp string name freeneturi target client metadata cm this smp null name name target cm puthandler basemanifestputter clientmetadata protected put handler final base manifest putter smp put handler parent string name string target in archive2 freeneturi target client metadata cm super smp get priority class smp client this persistent base manifest putter this persistent this cm cm this name name metadata m new metadata metadata simple redirect null null target cm metadata m if logminor logger minor this simple redirect metadata m origsfi null parent put handler parent is archive is container false target in archive target in archive2 puthandler basemanifestputter puthandler targetinarchive2 clientmetadata getpriorityclass basemanifestputter simple_redirect parentputhandler isarchive iscontainer targetinarchive targetinarchive2 public void start object container container client context context throws insert exception if logdebug logger debug this starting a put handler for this name is root container this root container put handler is archive this is archive this if origsfi null logger error this origsfi is null on start should be impossible new exception debug return if metadata null logger error this metdata metadata on start should be impossible new exception debug return client put state sfi synchronized this sfi origsfi current state sfi origsfi null if persistent container activate sfi 1 container store this sfi schedule container context if persistent container deactivate sfi 1 objectcontainer clientcontext insertexception puthandler isrootcontainer rootcontainerputhandler isarchive isarchive clientputstate currentstate override public void cancel object container container client context context if logminor logger minor this cancelling this new exception debug client put state old state null synchronized this if cancelled return super cancel old state current state if persistent container store this if old state null container activate old state 1 if old state null old state cancel container context on failure new insert exception insert exception cancelled null container context objectcontainer clientcontext clientputstate oldstate oldstate currentstate oldstate oldstate oldstate oldstate onfailure insertexception insertexception override public freeneturi geturi return null override public boolean is finished if logminor logger minor this finished this new exception debug return base manifest putter this finished cancelled base manifest putter this cancelled isfinished basemanifestputter basemanifestputter public void on success client put state state object container container client context context if logminor logger minor this completed this name this if is archive vector put handler phv put handlers archive transform map get this for put handler ph phv per container put handlers waiting for fetchable get ph parent put handler remove this metadata m new metadata metadata simple redirect null null archiveuri set doc name target in archive cm hm put ph name m put handlers transform map remove ph try maybe start parent container ph parent put handler container context catch insert exception e fail new insert exception insert exception internal error e null container context return return if persistent container activate base manifest putter this 1 container activate running put handlers 2 base manifest putter this on fetchable this container client put state old state boolean inserted all files true synchronized this old state current state current state null synchronized base manifest putter this if persistent container store this running put handlers remove this if persistent container ext store running put handlers 2 container activate put handlers waiting for metadata 2 if put handlers waiting for metadata contains this put handlers waiting for metadata remove this container ext store put handlers waiting for metadata 2 logger error this put handler this name was in waiting for metadata in on success on this for base manifest putter this if persistent container deactivate put handlers waiting for metadata 1 container activate waiting for block sets 2 if waiting for block sets contains this waiting for block sets remove this container store waiting for block sets logger error this put handler was in waiting for block sets in on success on this for base manifest putter this if persistent container deactivate waiting for block sets 1 container deactivate put handlers waiting for fetchable 1 container activate put handlers waiting for fetchable 2 if put handlers waiting for fetchable contains this put handlers waiting for fetchable remove this container ext store put handlers waiting for fetchable 2 not getting an on fetchable is not unusual just ignore it if logminor logger minor this put handler was in waiting for fetchable in on success on this for base manifest putter this if persistent container deactivate put handlers waiting for fetchable 1 if running put handlers is empty if logminor logger minor this running put handlers running put handlers size for object o running put handlers boolean activated true if persistent activated container ext is active o if activated container activate o 1 logger minor this still running o if activated container deactivate o 1 inserted all files false if persistent if old state null old state state container activate old state 1 old state remove from container context else if state null state remove from container context if inserted all files inserted all files container context if persistent container deactivate running put handlers 1 container deactivate base manifest putter this 1 onsuccess clientputstate objectcontainer clientcontext isarchive puthandler puthandlersarchivetransformmap puthandler percontainerputhandlerswaitingforfetchable parentputhandler simple_redirect setdocname targetinarchive puthandlerstransformmap maybestartparentcontainer parentputhandler insertexception insertexception insertexception internal_error basemanifestputter runningputhandlers basemanifestputter onfetchable clientputstate oldstate insertedallfiles oldstate currentstate currentstate basemanifestputter runningputhandlers runningputhandlers puthandlerswaitingformetadata puthandlerswaitingformetadata puthandlerswaitingformetadata puthandlerswaitingformetadata puthandler waitingformetadata onsuccess basemanifestputter puthandlerswaitingformetadata waitingforblocksets waitingforblocksets waitingforblocksets waitingforblocksets puthandler waitingforblocksets onsuccess basemanifestputter waitingforblocksets puthandlerswaitingforfetchable puthandlerswaitingforfetchable puthandlerswaitingforfetchable puthandlerswaitingforfetchable puthandlerswaitingforfetchable onfetchable puthandler waitingforfetchable onsuccess basemanifestputter puthandlerswaitingforfetchable runningputhandlers isempty runningputhandlers runningputhandlers isactive insertedallfiles oldstate oldstate oldstate oldstate removefrom removefrom insertedallfiles insertedallfiles runningputhandlers basemanifestputter public void on failure insert exception e client put state state object container container client context context client put state old state synchronized this old state current state current state null if old state null old state state persistent container activate old state 1 old state remove from container context else if state null persistent state remove from container context if logminor logger minor this failed this e e if persistent container activate base manifest putter this 1 fail e container context if persistent container deactivate base manifest putter this 1 onfailure insertexception clientputstate objectcontainer clientcontext clientputstate oldstate oldstate currentstate currentstate oldstate oldstate oldstate oldstate removefrom removefrom basemanifestputter basemanifestputter public void on encode base client key key client put state state object container container client context context if logminor logger minor this on encode key for this system out println got a uri key geturi to string false false for this if is archive freeneturi archiveuri key geturi vector put handler phv put handlers archive transform map get this for put handler ph phv hash map string object hm put handlers transform map get ph per container put handlers waiting for fetchable get ph parent put handler remove this if ph target in archive null throw new null pointer exception metadata m new metadata metadata simple redirect null null archiveuri set meta string new string ph target in archive cm hm put ph name m put handlers transform map remove ph per container put handlers waiting for fetchable get parent container handle remove this put handlers archive transform map remove this return if metadata null the file was too small to have its own metadata we get this instead so we make the key into metadata if persistent container activate key 5 container activate base manifest putter this 1 metadata m new metadata metadata simple redirect null null key geturi cm on metadata m null container context if persistent container deactivate base manifest putter this 1 onencode baseclientkey clientputstate objectcontainer clientcontext onencode tostring isarchive puthandler puthandlersarchivetransformmap puthandler hashmap puthandlerstransformmap percontainerputhandlerswaitingforfetchable parentputhandler targetinarchive nullpointerexception simple_redirect setmetastring targetinarchive puthandlerstransformmap percontainerputhandlerswaitingforfetchable parentcontainerhandle puthandlersarchivetransformmap basemanifestputter simple_redirect onmetadata basemanifestputter the caller of on transition removes the old state so we don t have to however in on success or on failure we need to remove the new state even if what is passed in is different in which case we remove that too public void on transition client put state old state client put state new state object container container if new state null throw new null pointer exception on transition is not responsible for removing the old state the caller is synchronized this if current state old state current state new state if persistent container store this if logminor logger minor this on transition cur current state old old state new new state for this return logger error this ignoring on transition cur current state old old state new new state for this ontransition onsuccess onfailure ontransition clientputstate oldstate clientputstate newstate objectcontainer newstate nullpointerexception ontransition currentstate oldstate currentstate newstate ontransition currentstate oldstate newstate ontransition currentstate oldstate newstate public void on metadata metadata m client put state state object container container client context context if logminor logger minor this assigning metadata m for this name this from state persistent persistent if metadata null logger error this reassigning metadata new exception debug return metadata m if is container containers are inserted with report metadata only false so it can never reach here throw new illegal state exception if persistent container activate base manifest putter this 1 container activate put handlers waiting for metadata 2 boolean all metadatas false synchronized base manifest putter this put handlers waiting for metadata remove this if persistent container ext store put handlers waiting for metadata 2 container store this all metadatas put handlers waiting for metadata is empty if all metadatas if logminor logger minor this still waiting for metadata put handlers waiting for metadata size if all metadatas will resolve etc got all metadata container context else resolve now to speed up the insert try byte buf m write to byte array if buf length metadata max size in manifest throw new metadata unresolved exception new metadata m too big catch metadata unresolved exception e try resolve e container context catch io exception e1 fail new insert exception insert exception bucket error e1 null container context return catch insert exception e1 fail e1 container context if persistent container deactivate put handlers waiting for metadata 1 container deactivate base manifest putter this 1 onmetadata clientputstate objectcontainer clientcontext iscontainer reportmetadataonly illegalstateexception basemanifestputter puthandlerswaitingformetadata allmetadatas basemanifestputter puthandlerswaitingformetadata puthandlerswaitingformetadata allmetadatas puthandlerswaitingformetadata isempty allmetadatas puthandlerswaitingformetadata allmetadatas gotallmetadata writetobytearray max_size_in_manifest metadataunresolvedexception metadataunresolvedexception ioexception insertexception insertexception bucket_error insertexception puthandlerswaitingformetadata basemanifestputter override public void add block object container container if persistent container activate base manifest putter this 1 base manifest putter this add block container if persistent container deactivate base manifest putter this 1 addblock objectcontainer basemanifestputter basemanifestputter addblock basemanifestputter override public void add blocks int num object container container if persistent container activate base manifest putter this 1 base manifest putter this add blocks num container if persistent container deactivate base manifest putter this 1 addblocks objectcontainer basemanifestputter basemanifestputter addblocks basemanifestputter override public void completed block boolean dont notify object container container client context context if persistent container activate base manifest putter this 1 base manifest putter this completed block dont notify container context if persistent container deactivate base manifest putter this 1 completedblock dontnotify objectcontainer clientcontext basemanifestputter basemanifestputter completedblock dontnotify basemanifestputter override public void failed block object container container client context context if persistent container activate base manifest putter this 1 base manifest putter this failed block container context if persistent container deactivate base manifest putter this 1 failedblock objectcontainer clientcontext basemanifestputter basemanifestputter failedblock basemanifestputter override public void fatally failed block object container container client context context if persistent container activate base manifest putter this 1 base manifest putter this fatally failed block container context if persistent container deactivate base manifest putter this 1 fatallyfailedblock objectcontainer clientcontext basemanifestputter basemanifestputter fatallyfailedblock basemanifestputter override public void add must succeed blocks int blocks object container container if persistent container activate base manifest putter this 1 base manifest putter this add must succeed blocks blocks container if persistent container deactivate base manifest putter this 1 addmustsucceedblocks objectcontainer basemanifestputter basemanifestputter addmustsucceedblocks basemanifestputter override public void notify clients object container container client context context if persistent container activate base manifest putter this 1 base manifest putter this notify clients container context if persistent container deactivate base manifest putter this 1 notifyclients objectcontainer clientcontext basemanifestputter basemanifestputter notifyclients basemanifestputter public void on block set finished client put state state object container container client context context if persistent container activate base manifest putter this 1 container activate waiting for block sets 2 boolean all block sets false synchronized base manifest putter this waiting for block sets remove this if persistent container store waiting for block sets all block sets waiting for block sets is empty if all block sets base manifest putter this block set finalized container context if persistent container deactivate waiting for block sets 1 container deactivate base manifest putter this 1 onblocksetfinished clientputstate objectcontainer clientcontext basemanifestputter waitingforblocksets allblocksets basemanifestputter waitingforblocksets waitingforblocksets allblocksets waitingforblocksets isempty allblocksets basemanifestputter blocksetfinalized waitingforblocksets basemanifestputter override public void on major progress object container container if persistent container activate base manifest putter this 1 base manifest putter this on major progress container if persistent container deactivate base manifest putter this 1 onmajorprogress objectcontainer basemanifestputter basemanifestputter onmajorprogress basemanifestputter public void on fetchable client put state state object container container if logminor logger minor this on fetchable this new exception debug if is archive per container put handlers waiting for fetchable get container handle remove this return if persistent container activate base manifest putter this 1 base manifest putter this on fetchable this container if persistent container deactivate base manifest putter this 1 onfetchable clientputstate objectcontainer onfetchable isarchive percontainerputhandlerswaitingforfetchable containerhandle basemanifestputter basemanifestputter onfetchable basemanifestputter override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void clear metadata object container container metadata null if persistent container store this clearmetadata objectcontainer override public void remove from object container container client context context if logminor logger minor this removing this client put state oldsfi client put state old state synchronized this oldsfi origsfi old state current state origsfi null current state null if oldsfi null logger error this origsfi is set in remove from on this for base manifest putter this new exception debug container activate oldsfi 1 oldsfi cancel container context oldsfi remove from container context if old state oldsfi old state null if old state null logger error this current state is set in remove from on this for base manifest putter this new exception debug container activate old state 1 old state cancel container context old state remove from container context if cm null container activate cm 5 cm remove from container if metadata null possible if cancelled logger normal this metadata is set in remove from on this for base manifest putter this container activate metadata 1 metadata remove from container data is responsibility of original caller usually client put dir we don t support free data atm super remove from container context removefrom objectcontainer clientcontext clientputstate clientputstate oldstate oldstate currentstate currentstate removefrom basemanifestputter removefrom oldstate oldstate oldstate currentstate removefrom basemanifestputter oldstate oldstate oldstate removefrom removefrom removefrom basemanifestputter removefrom clientputdir freedata removefrom public boolean object can new object container container if cancelled logger error this storing this when already cancelled new exception error return false if logminor logger minor this storing this activated container ext is active this stored container ext is stored this new exception debug return true objectcannew objectcontainer isactive isstored override public string to string if logdebug return super to string name this name is root container this root container put handler is container this is container is archive this is archive return super to string tostring tostring isrootcontainer rootcontainerputhandler iscontainer iscontainer isarchive isarchive tostring override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext public base manifest putter client callback cb hash map string object manifest elements short prio class freeneturi target string default name insert context ctx boolean getchk only2 request client client context boolean early encode super prio class client context this default name default name if client persistent this targeturi target clone else this targeturi target this cb cb this ctx ctx this getchk only getchk only2 this early encode early encode put handlers by name new hash map string object running put handlers new hash set put handler put handlers waiting for metadata new hash set put handler put handlers waiting for fetchable new hash set put handler waiting for block sets new hash set put handler metadata putters by metadata new hash map metadata client put state metadata putters unfetchable new hash map metadata client put state container put handlers new hash set put handler per container put handlers waiting for metadata new hash map put handler hash set put handler per container put handlers waiting for fetchable new hash map put handler hash set put handler put handlers transform map new hash map put handler hash map string object put handlers archive transform map new hash map put handler vector put handler make put handlers manifest elements put handlers by name basemanifestputter clientcallback hashmap manifestelements prioclass defaultname insertcontext getchkonly2 requestclient clientcontext earlyencode prioclass clientcontext defaultname defaultname getchkonly getchkonly2 earlyencode earlyencode puthandlersbyname hashmap runningputhandlers hashset puthandler puthandlerswaitingformetadata hashset puthandler puthandlerswaitingforfetchable hashset puthandler waitingforblocksets hashset puthandler metadataputtersbymetadata hashmap clientputstate metadataputtersunfetchable hashmap clientputstate containerputhandlers hashset puthandler percontainerputhandlerswaitingformetadata hashmap puthandler hashset puthandler percontainerputhandlerswaitingforfetchable hashmap puthandler hashset puthandler puthandlerstransformmap hashmap puthandler hashmap puthandlersarchivetransformmap hashmap puthandler puthandler makeputhandlers manifestelements puthandlersbyname public void start object container container client context context throws insert exception if logminor logger minor this starting this persistence persistent containermode container mode put handler running put handler containers if persistent container activate running put handlers 2 synchronized this running running put handlers to array new put handler running put handlers size if container mode containers get containers to start else containers null try boolean persistent persistent this might get deactivated for int i 0 i running length i running i start container context if persistent container ext is active this container activate this 1 if logminor logger minor this started i of running length if is finished if logminor logger minor this already finished killing start on this return if logminor logger minor this started running length put handler s for this if container mode for int i 0 i containers length i containers i start container context if persistent container ext is active this container activate this 1 if logminor logger minor this started i of containers length if is finished if logminor logger minor this already finished killing start on this return if logminor logger minor this started containers length put handler s containers for this if container mode running length 0 inserted all files true if persistent container store this got all metadata container context catch insert exception e synchronized this finished true cancel and finish container context throw e objectcontainer clientcontext insertexception containermode puthandler puthandler runningputhandlers runningputhandlers toarray puthandler runningputhandlers containermode getcontainerstostart isactive isfinished puthandler containermode isactive isfinished puthandler containermode insertedallfiles gotallmetadata insertexception cancelandfinish private put handler get containers to start put handler maybe startph container put handlers to array new put handler container put handlers size array list put handler ph to start new array list put handler for put handler ph maybe startph if per container put handlers waiting for metadata get ph is empty per container put handlers waiting for fetchable get ph is empty ph to start add ph if maybe startph length 0 ph to start add root container self handle return ph to start to array new put handler ph to start size puthandler getcontainerstostart puthandler maybestartph containerputhandlers toarray puthandler containerputhandlers arraylist puthandler phtostart arraylist puthandler puthandler maybestartph percontainerputhandlerswaitingformetadata isempty percontainerputhandlerswaitingforfetchable isempty phtostart maybestartph phtostart rootcontainer selfhandle phtostart toarray puthandler phtostart implement the pack logic param manifest elements param put handlers by name manifestelements puthandlersbyname protected abstract void make put handlers hash map string object manifest elements hash map string object put handlers by name override public freeneturi geturi return finaluri makeputhandlers hashmap manifestelements hashmap puthandlersbyname override public synchronized boolean is finished return finished cancelled isfinished public void run object container container client context context context job runner remove restart job this native thread norm priority container container activate base manifest putter this 1 inner got all metadata container context container deactivate base manifest putter this 1 objectcontainer clientcontext jobrunner removerestartjob nativethread norm_priority basemanifestputter innergotallmetadata basemanifestputter called when we have metadata for all the put handler s this does not necessarily mean we can immediately insert the final metadata since if these metadata s are too big they will need to be inserted separately see resolve and start base param container param context private void got all metadata object container container client context context this can be huge run it on its own transaction to minimize the build up of stuff to commit and maximise the opportunities for garbage collection if persistent container activate run got all metadata 1 need to activate this context job runner queue restart job run got all metadata native thread norm priority container false context job runner queue run got all metadata native thread norm priority false else inner got all metadata null context puthandler resolveandstartbase gotallmetadata objectcontainer clientcontext rungotallmetadata jobrunner queuerestartjob rungotallmetadata nativethread norm_priority jobrunner rungotallmetadata nativethread norm_priority innergotallmetadata generate the global metadata and then call resolve and start base param container param context private void inner got all metadata object container container client context context if logminor logger minor this got all metadata if container mode hash map string object names to byte arrays new hash map string object we ll end up committing it all anyway and hash maps in hash maps can cause severe problems see cor 1582 so activate to max depth first if persistent container activate put handlers by name integer max value names to byte arrays put handlers by name names to byte arrays container if default name null metadata meta metadata names to byte arrays get default name if meta null fail new insert exception insert exception invalid uri default name default name does not exist null container context return names to byte arrays put meta else for int j 0 j default default names length j string name default default names j metadata meta metadata names to byte arrays get name if meta null names to byte arrays put meta break base metadata metadata mk redirection manifest with metadata names to byte arrays if persistent container store base metadata container store this resolve and start base container context resolveandstartbase innergotallmetadata objectcontainer clientcontext containermode hashmap namestobytearrays hashmap puthandlersbyname max_value namestobytearrays puthandlersbyname namestobytearrays defaultname namestobytearrays defaultname insertexception insertexception invalid_uri defaultname namestobytearrays defaultdefaultnames defaultdefaultnames namestobytearrays namestobytearrays basemetadata mkredirectionmanifestwithmetadata namestobytearrays basemetadata resolveandstartbase attempt to insert the base metadata and the container if the base metadata cannot be resolved try to resolve it start inserts for each part that cannot be resolved and wait for them to generate ur is that can be incorporated into the metadata this method will then be called again and will complete or do more resolutions as necessary param container param context private void resolve and start base object container container client context context bucket bucket null synchronized this if has resolved base return while true try if persistent container activate base metadata integer max value bucket bucket tools make immutable bucket context get bucket factory persistent base metadata write to byte array if logminor logger minor this metadata bucket is bucket size bytes long break catch io exception e fail new insert exception insert exception bucket error e null container context return catch metadata unresolved exception e try start the insert for the sub metadata eventually it will generate a uri and call on encode which will call back here if logminor logger minor this main metadata needs resolving e resolve e container context if persistent container deactivate base metadata 1 return catch io exception e1 if persistent container deactivate base metadata 1 fail new insert exception insert exception bucket error e null container context return catch insert exception e2 if persistent container deactivate base metadata 1 fail e2 container context return if bucket null return synchronized this if has resolved base return has resolved base true if persistent container store this container activate elements to put in archive 2 insert block block boolean is metadata true archive type archive type null block new insert block bucket null persistent targeturi clone targeturi single file inserter metadata inserter try metadata inserter new single file inserter this this block is metadata ctx archive type archive type zip getchk only false base metadata archive type true null early encode if logminor logger minor this inserting main metadata metadata inserter for base metadata if persistent container activate metadata putters by metadata 2 container activate metadata putters unfetchable 2 this metadata putters by metadata put base metadata metadata inserter metadata putters unfetchable put base metadata metadata inserter if persistent container ext store metadata putters by metadata 2 container ext store metadata putters unfetchable 2 container deactivate metadata putters by metadata 1 container deactivate metadata putters unfetchable 1 container deactivate base metadata 1 metadata inserter start null container context catch insert exception e fail e container context return if persistent container deactivate metadata inserter 1 uris resolveandstartbase objectcontainer clientcontext hasresolvedbase basemetadata max_value buckettools makeimmutablebucket getbucketfactory basemetadata writetobytearray ioexception insertexception insertexception bucket_error metadataunresolvedexception onencode basemetadata ioexception basemetadata insertexception insertexception bucket_error insertexception basemetadata hasresolvedbase hasresolvedbase elementstoputinarchive insertblock ismetadata archive_type archivetype insertblock singlefileinserter metadatainserter metadatainserter singlefileinserter ismetadata archivetype archive_type getchkonly basemetadata archivetype earlyencode metadatainserter basemetadata metadataputtersbymetadata metadataputtersunfetchable metadataputtersbymetadata basemetadata metadatainserter metadataputtersunfetchable basemetadata metadatainserter metadataputtersbymetadata metadataputtersunfetchable metadataputtersbymetadata metadataputtersunfetchable basemetadata metadatainserter insertexception metadatainserter start inserts for unresolved too big metadata s eventually these will call back with an on encode meaning they have the chk and we can progress to resolve and start base param e param container param context return throws insert exception throws io exception private void resolve metadata unresolved exception e object container container client context context throws insert exception io exception metadata metas e must resolve if persistent container activate metadata putters by metadata 2 for int i 0 i metas length i metadata m metas i if persistent container activate m 100 if logminor logger minor this resolving m synchronized this if metadata putters by metadata contains key m if logminor logger minor this already started insert for m in resolve for metas length metadata s continue if m is resolved logger error this already resolved m in resolve race condition if persistent container deactivate m 1 continue try bucket b m to bucket context get bucket factory persistent insert block ib new insert block b null persistent freeneturi empty chk uri clone freeneturi empty chk uri single file inserter metadata inserter new single file inserter this this ib true ctx false getchk only false m null true null early encode if logminor logger minor this inserting subsidiary metadata metadata inserter for m synchronized this this metadata putters by metadata put m metadata inserter metadata inserter start null container context if persistent container deactivate metadata inserter 1 container deactivate m 1 catch metadata unresolved exception e1 resolve e1 container context container deactivate m 1 if persistent container ext store metadata putters by metadata 2 container deactivate metadata putters by metadata 1 onencode resolveandstartbase insertexception ioexception metadataunresolvedexception objectcontainer clientcontext insertexception ioexception mustresolve metadataputtersbymetadata metadataputtersbymetadata containskey isresolved tobucket getbucketfactory insertblock insertblock empty_chk_uri empty_chk_uri singlefileinserter metadatainserter singlefileinserter getchkonly earlyencode metadatainserter metadataputtersbymetadata metadatainserter metadatainserter metadatainserter metadataunresolvedexception metadataputtersbymetadata metadataputtersbymetadata private void names to byte arrays hash map string object put handlers by name hash map string object names to byte arrays object container container for map entry string object me put handlers by name entry set string name me get key object o me get value if o instanceof put handler put handler ph put handler o if persistent container activate ph 1 metadata meta ph metadata if ph metadata null logger error this metadata for name ph is null else ph clear metadata container if persistent container activate meta 100 logger minor this putting name names to byte arrays put name meta if logminor logger minor this putting put handler into base metadata ph name name else if o instanceof hash map hash map string object sub map new hash map string object already activated names to byte arrays put name sub map if logminor logger minor this putting hashmap into base metadata name size hash map o size active container null null boolean to string container ext is active o logger minor this putting directory name names to byte arrays hash map string object o sub map container else throw new illegal state exception namestobytearrays hashmap puthandlersbyname hashmap namestobytearrays objectcontainer puthandlersbyname entryset getkey getvalue puthandler puthandler puthandler clearmetadata namestobytearrays puthandler hashmap hashmap submap hashmap namestobytearrays submap hashmap tostring isactive namestobytearrays hashmap submap illegalstateexception private void inserted all files object container container client context context if logminor logger minor this inserted all files synchronized this inserted all files true if finished cancelled if logminor logger minor this already finished finished cancelled if persistent container store this return if inserted manifest if logminor logger minor this haven t inserted manifest if persistent container store this return finished true if persistent container store this complete container context insertedallfiles objectcontainer clientcontext insertedallfiles insertedmanifest private void complete object container container client context context fixme we could remove the put handlers after inserting all files but not having finished the insert of the manifest however it would complicate matters for no real gain in most cases also doing it this way means we don t need to worry about if persistent remove put handlers container context boolean deactivatecb false if persistent deactivatecb container ext is active cb container activate cb 1 cb on success this container if deactivatecb container deactivate cb 1 objectcontainer clientcontext removeputhandlers isactive onsuccess private void fail insert exception e object container container client context context cancel all then call the callback synchronized this if finished return finished true cancel and finish container context if persistent remove put handlers container context if persistent container activate cb 1 cb on failure e this container insertexception objectcontainer clientcontext cancelandfinish removeputhandlers onfailure private void remove put handlers object container container client context context container activate put handlers by name 2 container activate running put handlers 2 container activate put handlers waiting for metadata 2 container activate waiting for block sets 2 container activate put handlers waiting for fetchable 2 remove put handlers by name container context put handlers by name put handlers by name null if running put handlers is empty logger error this running put handlers not part of put handlers by name running put handlers size in remove put handlers on this new exception error put handler handlers running put handlers to array new put handler running put handlers size for put handler handler handlers container activate handler 1 logger error this still running but not in put handlers by name handler handler cancel handler remove from container context running put handlers clear if put handlers waiting for metadata is empty logger error this put handlers waiting for metadata not part of put handlers by name put handlers waiting for metadata size in remove put handlers on this new exception error put handler handlers put handlers waiting for metadata to array new put handler put handlers waiting for metadata size for put handler handler handlers container activate handler 1 logger error this still waiting for metadata but not in put handlers by name handler handler cancel handler remove from container context put handlers waiting for metadata clear if waiting for block sets is empty logger error this put handlers waiting for block sets not part of put handlers by name waiting for block sets size in remove put handlers on this new exception error put handler handlers waiting for block sets to array new put handler waiting for block sets size for put handler handler handlers container activate handler 1 logger error this still waiting for block set but not in put handlers by name handler handler cancel handler remove from container context waiting for block sets clear if put handlers waiting for fetchable is empty logger error this put handlers waiting for fetchable not part of put handlers by name put handlers waiting for fetchable size in remove put handlers on this new exception error put handler handlers put handlers waiting for fetchable to array new put handler put handlers waiting for fetchable size for put handler handler handlers container activate handler 1 logger error this still waiting for fetchable but not in put handlers by name handler handler cancel handler remove from container context put handlers waiting for fetchable clear container delete running put handlers container delete put handlers waiting for metadata container delete waiting for block sets container delete put handlers waiting for fetchable running put handlers null put handlers waiting for metadata null waiting for block sets null put handlers waiting for fetchable null container store this removeputhandlers objectcontainer clientcontext puthandlersbyname runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable removeputhandlersbyname puthandlersbyname puthandlersbyname runningputhandlers isempty puthandlersbyname runningputhandlers removeputhandlers puthandler runningputhandlers toarray puthandler runningputhandlers puthandler puthandlersbyname removefrom runningputhandlers puthandlerswaitingformetadata isempty puthandlersbyname puthandlerswaitingformetadata removeputhandlers puthandler puthandlerswaitingformetadata toarray puthandler puthandlerswaitingformetadata puthandler puthandlersbyname removefrom puthandlerswaitingformetadata waitingforblocksets isempty puthandlersbyname waitingforblocksets removeputhandlers puthandler waitingforblocksets toarray puthandler waitingforblocksets puthandler puthandlersbyname removefrom waitingforblocksets puthandlerswaitingforfetchable isempty puthandlersbyname puthandlerswaitingforfetchable removeputhandlers puthandler puthandlerswaitingforfetchable toarray puthandler puthandlerswaitingforfetchable puthandler puthandlersbyname removefrom puthandlerswaitingforfetchable runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable remove all put handler s from the given put handlers by name sub map remove the put handler s themselves also remove them from and complain about running put handlers put handlers waiting for metadata waiting for block sets put handlers waiting for fetchable which must have been activated by the caller param container param put handlers by name private void remove put handlers by name object container container client context context hash map string object put handlers by name if logminor logger minor this remove put handlers by name on this map size put handlers by name size for map entry string object entry put handlers by name entry set string key entry get key object value entry get value if value instanceof put handler put handler handler put handler value container activate handler 1 if running put handlers remove handler container ext store running put handlers 2 if put handlers waiting for metadata remove handler container ext store put handlers waiting for metadata 2 if waiting for block sets remove handler container ext store waiting for block sets 2 if put handlers waiting for fetchable remove handler container ext store put handlers waiting for fetchable 2 if elements to put in archive remove handler container ext store elements to put in archive 2 handler remove from container context else suppress warnings unchecked hash map string object sub map hash map string object value container activate sub map 2 remove put handlers by name container context sub map container delete key put handlers by name clear container delete put handlers by name puthandler puthandlersbyname puthandler runningputhandlers puthandlerswaitingformetadata waitingforblocksets puthandlerswaitingforfetchable puthandlersbyname removeputhandlersbyname objectcontainer clientcontext hashmap puthandlersbyname removeputhandlersbyname puthandlersbyname puthandlersbyname entryset getkey getvalue puthandler puthandler puthandler runningputhandlers runningputhandlers puthandlerswaitingformetadata puthandlerswaitingformetadata waitingforblocksets waitingforblocksets puthandlerswaitingforfetchable puthandlerswaitingforfetchable elementstoputinarchive elementstoputinarchive removefrom suppresswarnings hashmap submap hashmap submap removeputhandlersbyname submap puthandlersbyname puthandlersbyname cancel all running inserters private void cancel and finish object container container client context context put handler running boolean persistent persistent if persistent container activate running put handlers 2 synchronized this running running put handlers to array new put handler running put handlers size if logminor logger minor this put handler s to cancel running length for put handler putter running boolean active true if persistent active container ext is active putter if active container activate putter 1 putter cancel container context if active container deactivate putter 1 if persistent container activate this 1 client put state running meta if persistent container activate metadata putters by metadata 2 synchronized this running meta metadata putters by metadata values to array new client put state metadata putters by metadata size if logminor logger minor this metadata putters to cancel running meta length for client put state putter running meta boolean active true if persistent active container ext is active putter if active container activate putter 1 putter cancel container context if active container deactivate putter 1 if persistent container activate this 1 cancelandfinish objectcontainer clientcontext puthandler runningputhandlers runningputhandlers toarray puthandler runningputhandlers puthandler puthandler isactive clientputstate runningmeta metadataputtersbymetadata runningmeta metadataputtersbymetadata toarray clientputstate metadataputtersbymetadata runningmeta clientputstate runningmeta isactive override public void cancel object container container client context context synchronized this if finished return if super cancel return if persistent container store this fail new insert exception insert exception cancelled container context objectcontainer clientcontext insertexception insertexception public void on success client put state state object container container client context context if persistent container activate metadata putters by metadata 2 boolean fin false client put state old state null metadata token metadata state get token synchronized this if persistent container activate token 1 boolean present metadata putters by metadata contains key token if present old state metadata putters by metadata remove token if persistent container activate metadata putters unfetchable 2 if metadata putters unfetchable contains key token metadata putters unfetchable remove token if persistent container ext store metadata putters unfetchable 2 if metadata putters by metadata is empty if logminor logger minor this still running metadata putters metadata putters by metadata size else logger minor this inserted manifest successfully on this state inserted manifest true if finished if logminor logger minor this already finished if persistent container store this else if inserted all files if logminor logger minor this not inserted all files if persistent container store this else finished true if persistent container store this fin true if persistent if token base metadata token remove from container container ext store metadata putters by metadata 2 container deactivate metadata putters by metadata 1 state remove from container context if old state state old state null container activate old state 1 old state remove from container context if fin complete container context onsuccess clientputstate objectcontainer clientcontext metadataputtersbymetadata clientputstate oldstate gettoken metadataputtersbymetadata containskey oldstate metadataputtersbymetadata metadataputtersunfetchable metadataputtersunfetchable containskey metadataputtersunfetchable metadataputtersunfetchable metadataputtersbymetadata isempty metadataputtersbymetadata insertedmanifest insertedallfiles basemetadata removefrom metadataputtersbymetadata metadataputtersbymetadata removefrom oldstate oldstate oldstate oldstate removefrom public void on failure insert exception e client put state state object container container client context context if persistent container activate metadata putters by metadata 2 client put state old state null metadata token metadata state get token synchronized this if persistent container activate token 1 boolean present metadata putters by metadata contains key token if present old state metadata putters by metadata remove token if persistent container activate metadata putters unfetchable 2 if metadata putters unfetchable contains key token metadata putters unfetchable remove token if persistent container ext store metadata putters unfetchable if persistent if token base metadata token remove from container container ext store metadata putters by metadata 2 container deactivate metadata putters by metadata 1 state remove from container context if old state state old state null container activate old state 1 old state remove from container context fail e container context onfailure insertexception clientputstate objectcontainer clientcontext metadataputtersbymetadata clientputstate oldstate gettoken metadataputtersbymetadata containskey oldstate metadataputtersbymetadata metadataputtersunfetchable metadataputtersunfetchable containskey metadataputtersunfetchable metadataputtersunfetchable basemetadata removefrom metadataputtersbymetadata metadataputtersbymetadata removefrom oldstate oldstate oldstate oldstate removefrom public void on encode base client key key client put state state object container container client context context if state get token base metadata this finaluri key geturi if logminor logger minor this got metadata key finaluri if persistent container activate cb 1 cb on generateduri persistent finaluri clone finaluri this container if persistent container deactivate cb 1 if persistent container store this else it s a sub metadata metadata m metadata state get token if persistent container activate m 2 m resolve key geturi if persistent container store m if logminor logger minor this resolved m key geturi resolve and start base container context onencode baseclientkey clientputstate objectcontainer clientcontext gettoken basemetadata ongenerateduri gettoken resolveandstartbase public void on transition client put state old state client put state new state object container container metadata m metadata old state get token if persistent container activate m 100 container activate metadata putters unfetchable 2 container activate metadata putters by metadata 2 synchronized this if metadata putters by metadata contains key m client put state prev state metadata putters by metadata get m if prev state old state if logminor logger minor this ignoring transition in this for metadata putter old state new state because current for m is prev state container deactivate metadata putters unfetchable 1 container deactivate metadata putters by metadata 1 return if persistent container store new state metadata putters by metadata put m new state if persistent container ext store metadata putters by metadata 2 if logminor logger minor this metadata putter transition old state new state if metadata putters unfetchable contains key m metadata putters unfetchable put m new state if persistent container ext store metadata putters unfetchable 2 if logminor logger minor this unfetchable metadata putter transition old state new state if logminor logger minor this transition old state new state else logger error this on transition but metadata putters by metadata does not contain metadata tag m for old state should new state if persistent container deactivate m 100 container deactivate metadata putters unfetchable 2 container deactivate metadata putters by metadata 2 ontransition clientputstate oldstate clientputstate newstate objectcontainer oldstate gettoken metadataputtersunfetchable metadataputtersbymetadata metadataputtersbymetadata containskey clientputstate prevstate metadataputtersbymetadata prevstate oldstate oldstate newstate prevstate metadataputtersunfetchable metadataputtersbymetadata newstate metadataputtersbymetadata newstate metadataputtersbymetadata oldstate newstate metadataputtersunfetchable containskey metadataputtersunfetchable newstate metadataputtersunfetchable oldstate newstate oldstate newstate ontransition metadataputtersbymetadata oldstate newstate metadataputtersunfetchable metadataputtersbymetadata public void on metadata metadata m client put state state object container container client context context ignore onmetadata clientputstate objectcontainer clientcontext override public void notify clients object container container client context context if persistent container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new splitfile progress event this total blocks this successful blocks this failed blocks this fatally failed blocks this min success blocks this block set finalized container context notifyclients objectcontainer clientcontext eventproducer eventproducer produceevent splitfileprogressevent totalblocks successfulblocks failedblocks fatallyfailedblocks minsuccessblocks blocksetfinalized public void on block set finished client put state state object container container client context context synchronized this this metadata block set finalized true if persistent container activate waiting for block sets 2 if waiting for block sets is empty if persistent container store this container deactivate waiting for block sets 1 return this block set finalized container context if persistent container store this container deactivate waiting for block sets 1 onblocksetfinished clientputstate objectcontainer clientcontext metadatablocksetfinalized waitingforblocksets waitingforblocksets isempty waitingforblocksets blocksetfinalized waitingforblocksets override public void block set finalized object container container client context context synchronized this if metadata block set finalized return if persistent container activate waiting for block sets 2 if waiting for block sets is empty if persistent container deactivate waiting for block sets 1 return if persistent container deactivate waiting for block sets 1 super block set finalized container context if persistent container store this blocksetfinalized objectcontainer clientcontext metadatablocksetfinalized waitingforblocksets waitingforblocksets isempty waitingforblocksets waitingforblocksets blocksetfinalized public int count files return number of files countfiles numberoffiles public long total size return total size totalsize totalsize override public void on major progress object container container boolean deactivate false if persistent deactivate container ext is active cb if deactivate container activate cb 1 cb on major progress container if deactivate container deactivate cb 1 onmajorprogress objectcontainer isactive onmajorprogress protected void on fetchable put handler handler object container container if persistent container activate put handlers waiting for fetchable 2 container activate metadata putters unfetchable 2 if check fetchable handler if persistent container ext store put handlers waiting for metadata 2 container store this container deactivate put handlers waiting for fetchable 1 container deactivate metadata putters unfetchable 1 container activate cb 1 cb on fetchable this container if persistent container deactivate cb 1 else if persistent container deactivate put handlers waiting for fetchable 1 container deactivate metadata putters unfetchable 1 onfetchable puthandler objectcontainer puthandlerswaitingforfetchable metadataputtersunfetchable checkfetchable puthandlerswaitingformetadata puthandlerswaitingforfetchable metadataputtersunfetchable onfetchable puthandlerswaitingforfetchable metadataputtersunfetchable private synchronized boolean check fetchable put handler handler put handlers waiting for fetchable remove handler if fetchable return false if put handlers waiting for fetchable is empty return false if has resolved base return false if metadata putters unfetchable is empty return false fetchable true return true checkfetchable puthandler puthandlerswaitingforfetchable puthandlerswaitingforfetchable isempty hasresolvedbase metadataputtersunfetchable isempty public void on fetchable client put state state object container container metadata m metadata state get token if persistent container activate m 100 container activate metadata putters unfetchable 2 container activate put handlers waiting for fetchable 2 if check fetchable m if persistent container ext store metadata putters unfetchable 2 container store this container activate cb 1 cb on fetchable this container if persistent container deactivate cb 1 if persistent container deactivate metadata putters unfetchable 1 container deactivate put handlers waiting for fetchable 1 onfetchable clientputstate objectcontainer gettoken metadataputtersunfetchable puthandlerswaitingforfetchable checkfetchable metadataputtersunfetchable onfetchable metadataputtersunfetchable puthandlerswaitingforfetchable private synchronized boolean check fetchable metadata m metadata putters unfetchable remove m if metadata putters unfetchable is empty return false if fetchable return false if put handlers waiting for fetchable is empty return false fetchable true return true checkfetchable metadataputtersunfetchable metadataputtersunfetchable isempty puthandlerswaitingforfetchable isempty override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext override public void remove from object container container client context context if put handlers by name null logger error this put handlers list still present in remove from on this remove put handlers container context if finaluri null container activate finaluri 5 finaluri remove from container container activate targeturi 5 targeturi remove from container this is passed in we should not remove it because the caller client put dir should remove it container activate ctx 1 ctx remove from container container activate metadata putters by metadata 2 container activate metadata putters unfetchable 2 array list metadata metas null if metadata putters by metadata is empty logger error this metadata putters by metadata not empty in remove from on this for map entry metadata client put state entry metadata putters by metadata entry set metadata meta entry get key container activate meta 1 client put state sfi entry get value container activate sfi 1 metadata putters unfetchable remove meta logger error this metadata putters not empty sfi for this sfi cancel container context sfi remove from container context if metas null metas new array list metadata metas add meta if metadata putters unfetchable is empty logger error this metadata putters unfetchable by metadata not empty in remove from on this for map entry metadata client put state entry metadata putters by metadata entry set metadata meta entry get key container activate meta 1 client put state sfi entry get value container activate sfi 1 metadata putters unfetchable remove meta logger error this metadata putters unfetchable not empty sfi for this sfi cancel container context sfi remove from container context if metas null for metadata meta metas if meta base metadata continue container activate meta 1 meta remove from container metadata putters by metadata clear metadata putters unfetchable clear container delete metadata putters by metadata container delete metadata putters unfetchable if base metadata null container activate base metadata 1 base metadata remove from container container activate run got all metadata 1 container delete run got all metadata super remove from container context removefrom objectcontainer clientcontext puthandlersbyname removefrom removeputhandlers removefrom removefrom clientputdir removefrom metadataputtersbymetadata metadataputtersunfetchable arraylist metadataputtersbymetadata isempty removefrom clientputstate metadataputtersbymetadata entryset getkey clientputstate getvalue metadataputtersunfetchable removefrom arraylist metadataputtersunfetchable isempty removefrom clientputstate metadataputtersbymetadata entryset getkey clientputstate getvalue metadataputtersunfetchable removefrom basemetadata removefrom metadataputtersbymetadata metadataputtersunfetchable metadataputtersbymetadata metadataputtersunfetchable basemetadata basemetadata basemetadata removefrom rungotallmetadata rungotallmetadata removefrom public void object on update object container container if logdebug logger debug this updating this activated container ext is active this stored container ext is stored this new exception debug objectonupdate objectcontainer isactive isstored public boolean object can new object container container if finished logger error this storing this when already finished new exception error return false if logdebug logger debug this storing this activated container ext is active this stored container ext is stored this new exception debug return true objectcannew objectcontainer isactive isstored private void maybe start parent container put handler container handle2 object container container client context context throws insert exception if per container put handlers waiting for metadata get container handle2 is empty per container put handlers waiting for fetchable get container handle2 is empty container handle2 start container context maybestartparentcontainer puthandler containerhandle2 objectcontainer clientcontext insertexception percontainerputhandlerswaitingformetadata containerhandle2 isempty percontainerputhandlerswaitingforfetchable containerhandle2 isempty containerhandle2 compose helper stuff protected final client metadata guess mime string name manifest element me return guess mime name me mime override clientmetadata guessmime manifestelement guessmime mimeoverride protected final client metadata guess mime string name string mimetype string mime type mimetype if mime type null mime type defaultmime types guessmime type name true client metadata cm if mime type null mime type equals defaultmime types default mime type cm null else cm new client metadata mime type return cm clientmetadata guessmime mimetype mimetype mimetype defaultmimetypes guessmimetype clientmetadata mimetype mimetype defaultmimetypes default_mime_type clientmetadata mimetype protected final void add redirect no mime string name manifest element me hash map string object put handlers by name2 add redirect name me null put handlers by name2 addredirectnomime manifestelement hashmap puthandlersbyname2 addredirect puthandlersbyname2 protected final void add redirect string name manifest element me hash map string object put handlers by name2 add redirect name me guess mime name me put handlers by name2 addredirect manifestelement hashmap puthandlersbyname2 addredirect guessmime puthandlersbyname2 protected final void add redirect string name manifest element me client metadata cm hash map string object put handlers by name2 if container mode throw new illegal state exception you can not add freeform elements in container mode put handler ph bucket data me data if me targeturi null ph new put handler this name me targeturi cm just a placeholder don t actually run it else ph new put handler this name data cm getchk only running put handlers add ph put handlers waiting for metadata add ph put handlers waiting for fetchable add ph if logminor logger minor this inserting separately as put handler name ph persistent ph persistent ph persistent persistent number of files total size data size put handlers by name2 put name ph addredirect manifestelement clientmetadata hashmap puthandlersbyname2 containermode illegalstateexception puthandler puthandler puthandler getchkonly runningputhandlers puthandlerswaitingformetadata puthandlerswaitingforfetchable puthandler numberoffiles totalsize puthandlersbyname2 public container builder make archive return new container builder false null null true containerbuilder makearchive containerbuilder protected container builder get root container if container mode container mode true root container new container builder true put handlers by name null return root container containerbuilder getrootcontainer containermode containermode rootcontainer containerbuilder puthandlersbyname rootcontainer private final stack hash map string object dir stack private container builder boolean is root this is root null null false hashmap dirstack containerbuilder isroot isroot private container builder put handler parent string name this false parent name false containerbuilder puthandler private container builder boolean is root put handler parent string name boolean is archive if put handlers by name null put handlers by name size 0 throw new illegal state exception you can not add containers in free form mode dir stack new stack hash map string object root dir new hash map string object self handle new put handler base manifest putter this parent name root dir is root base manifest putter this targeturi freeneturi empty chk uri null getchk only is archive current dir root dir if is root root container put handler self handle else container put handlers add self handle per container put handlers waiting for metadata put self handle new hash set put handler per container put handlers waiting for fetchable put self handle new hash set put handler if is archive put handlers archive transform map put self handle new vector put handler containerbuilder isroot puthandler isarchive puthandlersbyname puthandlersbyname illegalstateexception dirstack hashmap rootdir hashmap selfhandle puthandler basemanifestputter rootdir isroot basemanifestputter empty_chk_uri getchkonly isarchive currentdir rootdir isroot rootcontainerputhandler selfhandle containerputhandlers selfhandle percontainerputhandlerswaitingformetadata selfhandle hashset puthandler percontainerputhandlerswaitingforfetchable selfhandle hashset puthandler isarchive puthandlersarchivetransformmap selfhandle puthandler public container builder make sub container string name container builder sub con new container builder self handle name current dir put name sub con self handle put handlers transform map put sub con self handle current dir per container put handlers waiting for fetchable get self handle add sub con self handle return sub con containerbuilder makesubcontainer containerbuilder subcon containerbuilder selfhandle currentdir subcon selfhandle puthandlerstransformmap subcon selfhandle currentdir percontainerputhandlerswaitingforfetchable selfhandle subcon selfhandle subcon public void make sub dircd string name current dir make sub dir current dir name makesubdircd currentdir makesubdir currentdir private hash map string object make sub dir hash map string object parent dir string name hash map string object new dir new hash map string object parent dir put name new dir return new dir hashmap makesubdir hashmap parentdir hashmap newdir hashmap parentdir newdir newdir public void add item string name string name in archive string mime override bucket data add item name name in archive mime override data false additem nameinarchive mimeoverride additem nameinarchive mimeoverride public void add item string name string name in archive string mime override bucket data boolean is default doc manifest element element new manifest element name name in archive data mime override data size add element name element is default doc additem nameinarchive mimeoverride isdefaultdoc manifestelement manifestelement nameinarchive mimeoverride addelement isdefaultdoc public void add redirect string name string mime override freeneturi targeturi2 add redirect name mime override targeturi2 false addredirect mimeoverride addredirect mimeoverride public void add redirect string name string mime override freeneturi targeturi2 boolean is default doc manifest element element new manifest element name targeturi2 mime override add element name element is default doc addredirect mimeoverride isdefaultdoc manifestelement manifestelement mimeoverride addelement isdefaultdoc public void add external string name string mime override bucket data add external name mime override data false addexternal mimeoverride addexternal mimeoverride public void add external string name string mime override bucket data boolean is default doc put handler ph new put handler base manifest putter this self handle name data guess mime name mime override getchk only running put handlers add ph per container put handlers waiting for metadata get self handle add ph put handlers transform map put ph current dir addexternal mimeoverride isdefaultdoc puthandler puthandler basemanifestputter selfhandle guessmime mimeoverride getchkonly runningputhandlers percontainerputhandlerswaitingformetadata selfhandle puthandlerstransformmap currentdir private void add element string name manifest element element boolean is default doc current dir put name element if is default doc current dir put element addelement manifestelement isdefaultdoc currentdir isdefaultdoc currentdir public void add archive item container builder archive string name string name in archive string mime type override bucket data add archive item archive name name in archive mime type override data false addarchiveitem containerbuilder nameinarchive mimetypeoverride addarchiveitem nameinarchive mimetypeoverride public void add archive item container builder archive string name string name in archive string mime type override bucket data boolean is default doc archive add item name name in archive mime type override data is default doc put handler ph new put handler base manifest putter this self handle name name in archive freeneturi empty chk uri guess mime name mime type override put handlers transform map put ph current dir per container put handlers waiting for fetchable get self handle add archive self handle put handlers archive transform map get archive self handle add ph addarchiveitem containerbuilder nameinarchive mimetypeoverride isdefaultdoc additem nameinarchive mimetypeoverride isdefaultdoc puthandler puthandler basemanifestputter selfhandle nameinarchive empty_chk_uri guessmime mimetypeoverride puthandlerstransformmap currentdir percontainerputhandlerswaitingforfetchable selfhandle selfhandle puthandlersarchivetransformmap selfhandle public void push current dir dir stack push current dir pushcurrentdir dirstack currentdir public void pop current dir current dir dir stack pop popcurrentdir currentdir dirstack public abstract class base client putter extends client requester protected base client putter short priority class request client context super priority class context baseclientputter clientrequester baseclientputter priorityclass requestclient priorityclass public abstract void on major progress object container container onmajorprogress objectcontainer static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private final runnable runner new prio runnable public int get priority return priority priorunnable getpriority public void run while true synchronized sync lock thread waiting true runnable job null try job jobs poll newjob timeout time unit milliseconds catch interrupted exception e ignore synchronized sync lock thread waiting false if job null synchronized sync lock thread started false return try job run catch throwable t logger error this caught t t logger error this while running job on this synclock threadwaiting newjob_timeout timeunit interruptedexception synclock threadwaiting synclock threadstarted public serial executor int priority jobs new linked blocking queue runnable this priority priority this sync lock new object serialexecutor linkedblockingqueue synclock public void start executor real executor string name this real executor real executor this name name synchronized sync lock if jobs is empty really start realexecutor realexecutor realexecutor synclock isempty reallystart private void really start synchronized sync lock thread started true if logminor logger minor this starting thread name runner real executor execute runner name reallystart synclock threadstarted realexecutor public void execute runnable job string job name if logminor logger minor this running job name job started thread started waiting thread waiting jobs add job synchronized sync lock if thread started real executor null really start jobname jobname threadstarted threadwaiting synclock threadstarted realexecutor reallystart public void execute runnable job string job name boolean from ticker execute job job name jobname fromticker jobname public int running threads int retval new int native thread java priority range 1 if thread started thread waiting retval priority 1 return retval runningthreads nativethread java_priority_range threadstarted threadwaiting public int waiting threads int retval new int native thread java priority range 1 synchronized sync lock if thread started thread waiting retval priority 1 return retval waitingthreads nativethread java_priority_range synclock threadstarted threadwaiting public int get waiting threads count synchronized sync lock return thread started thread waiting 1 0 getwaitingthreadscount synclock threadstarted threadwaiting public forward port status int status string reason int external port this status status this reason string reason this external port external port forwardportstatus externalport reasonstring externalport externalport public get node simple field set fs give opennet ref fields string to bool fs get give opennet ref false with private fields string to bool fs get with private false with volatile fields string to bool fs get with volatile false identifier fs get identifier fs remove value identifier getnode simplefieldset giveopennetref stringtobool giveopennetref withprivate stringtobool withprivate withvolatile stringtobool withvolatile removevalue override public simple field set get field set simple field set fs new simple field set true if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied get node requires full access identifier false handler output handler queue new node data node give opennet ref with private with volatile identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied getnode outputhandler nodedata giveopennetref withprivate withvolatile override public void remove from object container container container delete this removefrom objectcontainer public class xml importer public xml importer storage impl storage reader reader this storage storage scanner new xml scanner reader xmlimporter xmlimporter storageimpl xmlscanner public void import database throws xml import exception if scanner scan xml scanner xml lt scanner scan xml scanner xml ident scanner get identifier equals database throw exception no root element if scanner scan xml scanner xml ident scanner get identifier equals root scanner scan xml scanner xml eq scanner scan xml scanner xml sconst scanner scan xml scanner xml gt throw exception database element should have root attribute int root id 0 try root id integer parse int scanner get string catch number format exception x throw exception incorrect root object specification id map new int root id 2 id map root id storage allocate id storage header root 1 storage curr index root object id map root id xml element elem int tkn while tkn scanner scan xml scanner xml lt if scanner scan xml scanner xml ident throw exception element name expected string elem name scanner get identifier if elem name equals plugins xml spider org garret perst impl btree elem name equals plugins xml spider org garret perst impl bit index impl elem name equals plugins xml spider org garret perst impl persistent set elem name equals plugins xml spider org garret perst impl btree field index elem name equals plugins xml spider org garret perst impl btree case insensitive field index elem name equals plugins xml spider org garret perst impl btree compound index elem name equals plugins xml spider org garret perst impl btree multi field index elem name equals plugins xml spider org garret perst impl btree case insensitive multi field index create index elem name else create object read element elem name if tkn xml scanner xml lts scanner scan xml scanner xml ident scanner get identifier equals database scanner scan xml scanner xml gt throw exception root element is not closed importdatabase xmlimportexception xmlscanner xml_lt xmlscanner xml_ident getidentifier throwexception xmlscanner xml_ident getidentifier xmlscanner xml_eq xmlscanner xml_sconst xmlscanner xml_gt throwexception rootid rootid parseint getstring numberformatexception throwexception idmap rootid idmap rootid allocateid currindex rootobject idmap rootid xmlelement xmlscanner xml_lt xmlscanner xml_ident throwexception elemname getidentifier elemname xmlspider elemname xmlspider bitindeximpl elemname xmlspider persistentset elemname xmlspider btreefieldindex elemname xmlspider btreecaseinsensitivefieldindex elemname xmlspider btreecompoundindex elemname xmlspider btreemultifieldindex elemname xmlspider btreecaseinsensitivemultifieldindex createindex elemname createobject readelement elemname xmlscanner xml_lts xmlscanner xml_ident getidentifier xmlscanner xml_gt throwexception static final int null value 4 xml element string name this name name value type no value null_value xmlelement valuetype no_value final void add sibling xml element elem if siblings null siblings new hash map xml element prev xml element siblings get elem name if prev null elem next null elem prev prev prev elem prev next elem prev prev elem prev counter 1 else siblings put elem name elem elem prev elem elem counter 1 addsibling xmlelement hashmap xmlelement xmlelement final void add attribute string name string value if attributes null attributes new hash map attributes put name value addattribute hashmap final xml element get sibling string name if siblings null return xml element siblings get name return null xmlelement getsibling xmlelement final xml element get next sibling return next xmlelement getnextsibling final int get counter return counter getcounter final string get attribute string name return attributes null string attributes get name null getattribute final void set int value long val ivalue val value type int value setintvalue valuetype int_value final void set real value double val rvalue val value type real value setrealvalue valuetype real_value final void set string value string val svalue val value type string value setstringvalue valuetype string_value final void set null value value type null value setnullvalue valuetype null_value final string get string value return svalue getstringvalue final long get int value return ivalue getintvalue final double get real value return rvalue getrealvalue final boolean is int value return value type int value isintvalue valuetype int_value final boolean is real value return value type real value isrealvalue valuetype real_value final boolean is string value return value type string value isstringvalue valuetype string_value final boolean is null value return value type null value isnullvalue valuetype null_value final string get attribute xml element elem string name throws xml import exception string value elem get attribute name if value null throw exception attribute name is not set return value getattribute xmlelement xmlimportexception getattribute throwexception final int get int attribute xml element elem string name throws xml import exception string value elem get attribute name if value null throw exception attribute name is not set try return integer parse int value catch number format exception x throw exception attribute name should has integer value return 1 getintattribute xmlelement xmlimportexception getattribute throwexception parseint numberformatexception throwexception final int map id int id int oid 0 if id 0 if id id map length int new map new int id 2 system arraycopy id map 0 new map 0 id map length id map new map id map id oid storage allocate id else oid id map id if oid 0 id map id oid storage allocate id return oid mapid idmap newmap idmap newmap idmap idmap newmap idmap allocateid idmap idmap allocateid final int map type string signature throws xml import exception for int i 0 i class descriptor signature length i if class descriptor signature i equals signature return i throw exception bad type return 1 maptype xmlimportexception classdescriptor classdescriptor throwexception final key create compound key int types string values throws xml import exception i persistent obj date date byte buffer buf new byte buffer int dst 0 try for int i 0 i types length i string value values i switch types i case class descriptor tp boolean buf extend dst 1 buf arr dst byte integer parse int value 0 1 0 break case class descriptor tp byte buf extend dst 1 buf arr dst byte parse byte value break case class descriptor tp char buf extend dst 2 bytes pack2 buf arr dst short integer parse int value dst 2 break case class descriptor tp short buf extend dst 2 bytes pack2 buf arr dst short parse short value dst 2 break case class descriptor tp int case class descriptor tp enum buf extend dst 4 bytes pack4 buf arr dst integer parse int value dst 4 break case class descriptor tp object buf extend dst 4 bytes pack4 buf arr dst map id integer parse int value dst 4 break case class descriptor tp long case class descriptor tp date buf extend dst 8 bytes pack8 buf arr dst long parse long value dst 8 break case class descriptor tp float buf extend dst 4 bytes pack4 buf arr dst float float to int bits float parse float value dst 4 break case class descriptor tp double buf extend dst 8 bytes pack8 buf arr dst double double to long bits double parse double value dst 8 break case class descriptor tp string dst buf pack string dst value storage encoding break case class descriptor tp array of byte buf extend dst 4 value length 1 bytes pack4 buf arr dst value length 1 dst 4 for int j 0 n value length j n j 2 buf arr dst byte get hex value value char at j 4 get hex value value char at j 1 break default throw exception bad key type catch number format exception x throw exception failed to convert key value return new key buf to array createcompoundkey xmlimportexception ipersistent bytebuffer bytebuffer classdescriptor tpboolean parseint classdescriptor tpbyte parsebyte classdescriptor tpchar parseint classdescriptor tpshort parseshort classdescriptor tpint classdescriptor tpenum parseint classdescriptor tpobject mapid parseint classdescriptor tplong classdescriptor tpdate parselong classdescriptor tpfloat floattointbits parsefloat classdescriptor tpdouble doubletolongbits parsedouble classdescriptor tpstring packstring classdescriptor tparrayofbyte gethexvalue charat gethexvalue charat throwexception numberformatexception throwexception toarray final key create key int type string value throws xml import exception try date date switch type case class descriptor tp boolean return new key integer parse int value 0 case class descriptor tp byte return new key byte parse byte value case class descriptor tp char return new key char integer parse int value case class descriptor tp short return new key short parse short value case class descriptor tp int case class descriptor tp enum return new key integer parse int value case class descriptor tp object return new key new persistent stub storage map id integer parse int value case class descriptor tp long return new key long parse long value case class descriptor tp float return new key float parse float value case class descriptor tp double return new key double parse double value case class descriptor tp string return new key value case class descriptor tp array of byte byte buf new byte value length 1 for int i 0 i buf length i buf i byte get hex value value char at i 2 4 get hex value value char at i 2 1 return new key buf case class descriptor tp date if value equals null date null else date http formatter parse value new parse position 0 if date null throw exception invalid date return new key date default throw exception bad key type catch number format exception x throw exception failed to convert key value return null createkey xmlimportexception classdescriptor tpboolean parseint classdescriptor tpbyte parsebyte classdescriptor tpchar parseint classdescriptor tpshort parseshort classdescriptor tpint classdescriptor tpenum parseint classdescriptor tpobject persistentstub mapid parseint classdescriptor tplong parselong classdescriptor tpfloat parsefloat classdescriptor tpdouble parsedouble classdescriptor tpstring classdescriptor tparrayofbyte gethexvalue charat gethexvalue charat classdescriptor tpdate httpformatter parseposition throwexception throwexception numberformatexception throwexception final int parse int string str throws xml import exception try return integer parse int str catch number format exception x throw exception bad integer constant return 1 parseint xmlimportexception parseint numberformatexception throwexception final void create index string index type throws xml import exception btree btree null int tkn int oid 0 boolean unique false string class name null string field name null string field names null int types null long autoinc 0 string type null while tkn scanner scan xml scanner xml ident string attr name scanner get identifier if scanner scan xml scanner xml eq scanner scan xml scanner xml sconst throw exception attribute value expected string attr value scanner get string if attr name equals id oid map id parse int attr value else if attr name equals unique unique parse int attr value 0 else if attr name equals class class name attr value else if attr name equals type type attr value else if attr name equals autoinc autoinc parse int attr value else if attr name equals field field name attr value else if attr name starts with type int type no integer parse int attr name substring 4 if types null types length type no int new types new int type no 1 if types null system arraycopy types 0 new types 0 types length types new types types type no map type attr value else if attr name starts with field int field no integer parse int attr name substring 5 if field names null field names length field no string new field names new string field no 1 if field names null system arraycopy field names 0 new field names 0 field names length field names new field names field names field no attr value if tkn xml scanner xml gt throw exception unclosed element tag if oid 0 throw exception id is not specified or index if class name null class cls class descriptor load class storage class name if field name null if index type equals plugins xml spider org garret perst impl btree case insensitive field index btree new btree case insensitive field index cls field name unique autoinc else btree new btree field index cls field name unique autoinc else if field names null if index type equals plugins xml spider org garret perst impl btree case insensitive multi field index btree new btree case insensitive multi field index cls field names unique else btree new btree multi field index cls field names unique else throw exception field name is not specified for field index else if types null btree new btree compound index types unique else if type null if index type equals plugins xml spider org garret perst impl persistent set btree new persistent set else throw exception key type is not specified for index else if index type equals plugins xml spider org garret perst impl bit index impl btree new bit index impl else btree new btree map type type unique storage assign oid btree oid while tkn scanner scan xml scanner xml lt if scanner scan xml scanner xml ident scanner get identifier equals ref throw exception ref element expected xml element ref read element ref key key null int mask 0 if field names null string values new string field names length for int i 0 i values length i values i get attribute ref key i key create compound key btree multi field index btree types values else if types null string values new string types length for int i 0 i values length i values i get attribute ref key i key create compound key types values else if btree instanceof bit index mask get int attribute ref key else key create key btree type get attribute ref key i persistent obj new persistent stub storage map id get int attribute ref id if btree instanceof bit index bit index btree put obj mask else btree insert key obj false if tkn xml scanner xml lts scanner scan xml scanner xml ident scanner get identifier equals index type scanner scan xml scanner xml gt throw exception element is not closed byte data storage pack object btree false int size object header get size data 0 long pos storage allocate size 0 storage set pos oid pos storage impl db modified flag storage pool put pos storage impl db flags mask data size createindex indextype xmlimportexception classname fieldname fieldnames xmlscanner xml_ident attrname getidentifier xmlscanner xml_eq xmlscanner xml_sconst throwexception attrvalue getstring attrname mapid parseint attrvalue attrname parseint attrvalue attrname classname attrvalue attrname attrvalue attrname parseint attrvalue attrname fieldname attrvalue attrname startswith typeno parseint attrname typeno newtypes typeno newtypes newtypes typeno maptype attrvalue attrname startswith fieldno parseint attrname fieldnames fieldnames fieldno newfieldnames fieldno fieldnames fieldnames newfieldnames fieldnames fieldnames newfieldnames fieldnames fieldno attrvalue xmlscanner xml_gt throwexception throwexception classname classdescriptor loadclass classname fieldname indextype xmlspider btreecaseinsensitivefieldindex btreecaseinsensitivefieldindex fieldname btreefieldindex fieldname fieldnames indextype xmlspider btreecaseinsensitivemultifieldindex btreecaseinsensitivemultifieldindex fieldnames btreemultifieldindex fieldnames throwexception btreecompoundindex indextype xmlspider persistentset persistentset throwexception indextype xmlspider bitindeximpl bitindeximpl maptype assignoid xmlscanner xml_lt xmlscanner xml_ident getidentifier throwexception xmlelement readelement fieldnames fieldnames getattribute createcompoundkey btreemultifieldindex getattribute createcompoundkey bitindex getintattribute createkey getattribute ipersistent persistentstub mapid getintattribute bitindex bitindex xmlscanner xml_lts xmlscanner xml_ident getidentifier indextype xmlscanner xml_gt throwexception packobject objectheader getsize setpos storageimpl dbmodifiedflag storageimpl dbflagsmask final void create object xml element elem throws xml import exception class cls class descriptor load class storage elem name class descriptor desc storage get class descriptor cls int oid map id get int attribute elem id byte buffer buf new byte buffer int offs object header sizeof buf extend offs offs pack object elem desc offs buf object header set size buf arr 0 offs object header set type buf arr 0 desc get oid long pos storage allocate offs 0 storage set pos oid pos storage impl db modified flag storage pool put pos buf arr offs createobject xmlelement xmlimportexception classdescriptor loadclass classdescriptor getclassdescriptor mapid getintattribute bytebuffer bytebuffer objectheader packobject objectheader setsize objectheader settype getoid setpos storageimpl dbmodifiedflag final int get hex value char ch throws xml import exception if ch 0 ch 9 return ch 0 else if ch a ch f return ch a 10 else if ch a ch f return ch a 10 else throw exception bad hexadecimal constant return 1 gethexvalue xmlimportexception throwexception final int import binary xml element elem int offs byte buffer buf string field name throws xml import exception if elem null elem is null value buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 else if elem is string value string hex str elem get string value int len hex str length if hex str starts with buf extend offs 4 len 2 1 bytes pack4 buf arr offs 2 get hex value hex str char at 1 offs 4 for int j 2 j len j 2 buf arr offs byte get hex value hex str char at j 4 get hex value hex str char at j 1 else buf extend offs 4 len 2 bytes pack4 buf arr offs len 2 offs 4 for int j 0 j len j 2 buf arr offs byte get hex value hex str char at j 4 get hex value hex str char at j 1 else xml element ref elem get sibling ref if ref null buf extend offs 4 bytes pack4 buf arr offs map id get int attribute ref id offs 4 else xml element item elem get sibling element int len item null 0 item get counter buf extend offs 4 len bytes pack4 buf arr offs len offs 4 while len 0 if item is int value buf arr offs byte item get int value else if item is real value buf arr offs byte item get real value else throw exception conversion for field field name is not possible item item get next sibling offs 1 return offs importbinary xmlelement bytebuffer fieldname xmlimportexception isnullvalue isstringvalue hexstr getstringvalue hexstr hexstr startswith gethexvalue hexstr charat gethexvalue hexstr charat gethexvalue hexstr charat gethexvalue hexstr charat gethexvalue hexstr charat xmlelement getsibling mapid getintattribute xmlelement getsibling getcounter isintvalue getintvalue isrealvalue getrealvalue throwexception fieldname getnextsibling final int pack object xml element obj elem class descriptor desc int offs byte buffer buf throws xml import exception class descriptor field descriptor flds desc all fields for int i 0 n flds length i n i class descriptor field descriptor fd flds i string field name fd field name xml element elem obj elem null obj elem get sibling field name null switch fd type case class descriptor tp byte buf extend offs 1 if elem null if elem is int value buf arr offs byte elem get int value else if elem is real value buf arr offs byte elem get real value else throw exception conversion for field field name is not possible offs 1 continue case class descriptor tp boolean buf extend offs 1 if elem null if elem is int value buf arr offs byte elem get int value 0 1 0 else if elem is real value buf arr offs byte elem get real value 0 0 1 0 else throw exception conversion for field field name is not possible offs 1 continue case class descriptor tp short case class descriptor tp char buf extend offs 2 if elem null if elem is int value bytes pack2 buf arr offs short elem get int value else if elem is real value bytes pack2 buf arr offs short elem get real value else throw exception conversion for field field name is not possible offs 2 continue case class descriptor tp int buf extend offs 4 if elem null if elem is int value bytes pack4 buf arr offs int elem get int value else if elem is real value bytes pack4 buf arr offs int elem get real value else throw exception conversion for field field name is not possible offs 4 continue case class descriptor tp long buf extend offs 8 if elem null if elem is int value bytes pack8 buf arr offs elem get int value else if elem is real value bytes pack8 buf arr offs long elem get real value else throw exception conversion for field field name is not possible offs 8 continue case class descriptor tp float buf extend offs 4 if elem null if elem is int value bytes pack4 buf arr offs float float to int bits float elem get int value else if elem is real value bytes pack4 buf arr offs float float to int bits float elem get real value else throw exception conversion for field field name is not possible offs 4 continue case class descriptor tp double buf extend offs 8 if elem null if elem is int value bytes pack8 buf arr offs double double to long bits double elem get int value else if elem is real value bytes pack8 buf arr offs double double to long bits double elem get real value else throw exception conversion for field field name is not possible offs 8 continue case class descriptor tp enum buf extend offs 4 if elem null if elem is int value bytes pack4 buf arr offs int elem get int value else if elem is real value bytes pack4 buf arr offs int elem get real value else if elem is null value bytes pack4 buf arr offs 1 else if elem is string value bytes pack4 buf arr offs enum value of class fd field get type elem get string value ordinal else throw exception conversion for field field name is not possible offs 4 continue case class descriptor tp date buf extend offs 8 if elem null if elem is int value bytes pack8 buf arr offs elem get int value else if elem is null value bytes pack8 buf arr offs 1 else if elem is string value date date http formatter parse elem get string value new parse position 0 if date null throw exception invalid date bytes pack8 buf arr offs date get time else throw exception conversion for field field name is not possible offs 8 continue case class descriptor tp string if elem null string value null if elem is int value value long to string elem get int value else if elem is real value value double to string elem get real value else if elem is string value value elem get string value else if elem is null value value null else throw exception conversion for field field name is not possible offs buf pack string offs value storage encoding continue buf extend offs 4 bytes pack4 buf arr offs 1 offs 4 continue case class descriptor tp object int oid 0 if elem null xml element ref elem get sibling ref if ref null throw exception ref element expected oid map id get int attribute ref id buf extend offs 4 bytes pack4 buf arr offs oid offs 4 continue case class descriptor tp value offs pack object elem fd value desc offs buf continue case class descriptor tp raw case class descriptor tp array of byte offs import binary elem offs buf field name continue case class descriptor tp custom if elem is string value throw exception text element expected string str elem get string value try custom serializable obj storage serializer parse str storage serializer pack obj buf get output stream offs buf size catch io exception x throw exception exception in custom serializer x break case class descriptor tp array of boolean if elem null elem is null value buf extend offs 4 packobject xmlelement objelem classdescriptor bytebuffer xmlimportexception classdescriptor fielddescriptor allfields classdescriptor fielddescriptor fieldname fieldname xmlelement objelem objelem getsibling fieldname classdescriptor tpbyte isintvalue getintvalue isrealvalue getrealvalue throwexception fieldname classdescriptor tpboolean isintvalue getintvalue isrealvalue getrealvalue throwexception fieldname classdescriptor tpshort classdescriptor tpchar isintvalue getintvalue isrealvalue getrealvalue throwexception fieldname classdescriptor tpint isintvalue getintvalue isrealvalue getrealvalue throwexception fieldname classdescriptor tplong isintvalue getintvalue isrealvalue getrealvalue throwexception fieldname classdescriptor tpfloat isintvalue floattointbits getintvalue isrealvalue floattointbits getrealvalue throwexception fieldname classdescriptor tpdouble isintvalue doubletolongbits getintvalue isrealvalue doubletolongbits getrealvalue throwexception fieldname classdescriptor tpenum isintvalue getintvalue isrealvalue getrealvalue isnullvalue isstringvalue valueof gettype getstringvalue throwexception fieldname classdescriptor tpdate isintvalue getintvalue isnullvalue isstringvalue httpformatter getstringvalue parseposition throwexception gettime throwexception fieldname classdescriptor tpstring isintvalue tostring getintvalue isrealvalue tostring getrealvalue isstringvalue getstringvalue isnullvalue throwexception fieldname packstring classdescriptor tpobject xmlelement getsibling throwexception mapid getintattribute classdescriptor tpvalue packobject valuedesc classdescriptor tpraw classdescriptor tparrayofbyte importbinary fieldname classdescriptor tpcustom isstringvalue throwexception getstringvalue customserializable getoutputstream ioexception throwexception classdescriptor tparrayofboolean isnullvalue final xml element read element string name throws xml import exception xml element elem new xml element name string attribute int tkn while true switch scanner scan case xml scanner xml gts return elem case xml scanner xml gt while tkn scanner scan xml scanner xml lt if scanner scan xml scanner xml ident throw exception element name expected string sibling name scanner get identifier xml element sibling read element sibling name elem add sibling sibling switch tkn case xml scanner xml sconst elem set string value scanner get string tkn scanner scan break case xml scanner xml iconst elem set int value scanner get int tkn scanner scan break case xml scanner xml fconst elem set real value scanner get real tkn scanner scan break case xml scanner xml ident if scanner get identifier equals null elem set null value else elem set string value scanner get identifier tkn scanner scan if tkn xml scanner xml lts scanner scan xml scanner xml ident scanner get identifier equals name scanner scan xml scanner xml gt throw exception element is not closed return elem case xml scanner xml ident attribute scanner get identifier if scanner scan xml scanner xml eq scanner scan xml scanner xml sconst throw exception attribute value expected elem add attribute attribute scanner get string continue default throw exception unexpected token xmlelement readelement xmlimportexception xmlelement xmlelement xmlscanner xml_gts xmlscanner xml_gt xmlscanner xml_lt xmlscanner xml_ident throwexception siblingname getidentifier xmlelement readelement siblingname addsibling xmlscanner xml_sconst setstringvalue getstring xmlscanner xml_iconst setintvalue getint xmlscanner xml_fconst setrealvalue getreal xmlscanner xml_ident getidentifier setnullvalue setstringvalue getidentifier xmlscanner xml_lts xmlscanner xml_ident getidentifier xmlscanner xml_gt throwexception xmlscanner xml_ident getidentifier xmlscanner xml_eq xmlscanner xml_sconst throwexception addattribute getstring throwexception final void throw exception string message throws xml import exception throw new xml import exception scanner get line scanner get column message throwexception xmlimportexception xmlimportexception getline getcolumn xml scanner reader in reader in sconst new char size 1024 line 1 column 0 has unget char false xmlscanner hasungetchar final int get throws xml import exception if has unget char has unget char false return unget char try int ch reader read if ch n line 1 column 0 else if ch t column column 8 7 else column 1 return ch catch io exception x throw new xml import exception line column x get message xmlimportexception hasungetchar hasungetchar ungetchar ioexception xmlimportexception getmessage final void unget int ch if ch n line 1 else column 1 unget char ch has unget char true ungetchar hasungetchar final int scan throws xml import exception int i ch boolean floating point while true do if ch get 0 return xml eof while ch switch ch case ch get if ch while ch get if ch 0 throw new xml import exception line column bad xml file format if ch get throw new xml import exception line column bad xml file format continue if ch unget ch return xml lt return xml lts case return xml gt case ch get if ch unget ch throw new xml import exception line column bad xml file format return xml gts case return xml eq case i 0 while true ch get if ch 0 throw new xml import exception line column bad xml file format else if ch switch get case a if get m get p get throw new xml import exception line column bad xml file format ch break case l if get t get throw new xml import exception line column bad xml file format ch break case g if get t get throw new xml import exception line column bad xml file format ch break case q if get u get o get t get throw new xml import exception line column bad xml file format ch break default throw new xml import exception line column bad xml file format else if ch slen i return xml sconst if i size char new buf new char size 2 system arraycopy sconst 0 new buf 0 i sconst new buf sconst i char ch case case case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 case 8 case 9 i 0 floating point false while true if character is digit char ch ch ch ch ch e unget ch try if floating point fconst double parse double new string sconst 0 i return xml fconst else iconst long parse long new string sconst 0 i return xml iconst catch number format exception x throw new xml import exception line column bad xml file format if i size throw new xml import exception line column bad xml file format sconst i char ch if ch floating point true ch get default i 0 while character is letter or digit char ch ch ch ch ch if i size throw new xml import exception line column bad xml file format if ch ch sconst i char ch ch get unget ch if i 0 throw new xml import exception line column bad xml file format ident new string sconst 0 i return xml ident xmlimportexception floatingpoint xml_eof xmlimportexception xmlimportexception xml_lt xml_lts xml_gt xmlimportexception xml_gts xml_eq xmlimportexception xmlimportexception xmlimportexception xmlimportexception xmlimportexception xmlimportexception xml_sconst newbuf newbuf newbuf floatingpoint isdigit floatingpoint parsedouble xml_fconst parselong xml_iconst numberformatexception xmlimportexception xmlimportexception floatingpoint isletterordigit _ xmlimportexception xmlimportexception xml_ident final string get identifier return ident getidentifier final string get string return new string sconst 0 slen getstring final long get int return iconst getint final double get real return fconst getreal final int get line return line getline final int get column return column getcolumn byte body chunk chunk chunk storage db super db body new byte chunk size chunk_size protected iterator iterator public int read byte b new byte 1 return read b 0 1 1 b 0 0xff 1 public int read byte b int off int len if curr pos size return 1 long rest size curr pos if len rest len int rest int rc len while len 0 if curr pos curr chunk pos chunk size map entry e map entry iterator next curr chunk pos long e get key long value curr chunk chunk e get value assert that curr pos curr chunk pos chunk size if curr pos curr chunk pos int fill len curr chunk pos curr pos len int curr chunk pos curr pos len fill curr pos fill while fill 0 b off 0 int chunk offs int curr pos curr chunk pos int copy len chunk size chunk offs len chunk size chunk offs system arraycopy curr chunk body chunk offs b off copy len copy off copy curr pos copy return rc currpos currpos currpos currchunkpos chunk_size currchunkpos getkey longvalue currchunk getvalue currpos currchunkpos chunk_size currpos currchunkpos currchunkpos currpos currchunkpos currpos currpos chunkoffs currpos currchunkpos chunk_size chunkoffs chunk_size chunkoffs currchunk chunkoffs currpos public long set position long new pos if new pos 0 return 1 curr pos new pos size size new pos iterator chunks entry iterator new key curr pos chunk size chunk size null index ascent order curr chunk pos long min value curr chunk null return curr pos setposition newpos newpos currpos newpos newpos entryiterator currpos chunk_size chunk_size ascent_order currchunkpos min_value currchunk currpos public long get position return curr pos getposition currpos public long size return size public long skip long offs return set position curr pos offs setposition currpos public int available return int size curr pos currpos public void close curr chunk null iterator null currchunk protected blob input stream set position 0 blobinputstream setposition public void write int b byte buf new byte 1 buf 0 byte b write buf 0 1 public void write byte b int off int len while len 0 boolean new chunk false if curr pos curr chunk pos chunk size if iterator has next map entry e map entry iterator next curr chunk pos long e get key long value curr chunk chunk e get value assert that curr pos curr chunk pos chunk size else curr chunk new chunk get storage curr chunk pos curr pos chunk size chunk size new chunk true if curr pos curr chunk pos curr chunk new chunk get storage curr chunk pos curr pos chunk size chunk size new chunk true int chunk offs int curr pos curr chunk pos int copy len chunk size chunk offs len chunk size chunk offs system arraycopy b off curr chunk body chunk offs copy len copy curr pos copy off copy if new chunk chunks put new key curr chunk pos curr chunk iterator chunks entry iterator new key curr chunk pos chunk size null index ascent order else curr chunk modify if curr pos size size curr pos modify newchunk currpos currchunkpos chunk_size hasnext currchunkpos getkey longvalue currchunk getvalue currpos currchunkpos chunk_size currchunk getstorage currchunkpos currpos chunk_size chunk_size newchunk currpos currchunkpos currchunk getstorage currchunkpos currpos chunk_size chunk_size newchunk chunkoffs currpos currchunkpos chunk_size chunkoffs chunk_size chunkoffs currchunk chunkoffs currpos newchunk currchunkpos currchunk entryiterator currchunkpos chunk_size ascent_order currchunk currpos currpos public long set position long new pos if new pos 0 return 1 curr pos new pos iterator chunks entry iterator new key curr pos chunk size chunk size null index ascent order curr chunk pos long min value curr chunk null return curr pos setposition newpos newpos currpos newpos entryiterator currpos chunk_size chunk_size ascent_order currchunkpos min_value currchunk currpos public long get position return curr pos getposition currpos public long size return size public long skip long offs return set position curr pos offs setposition currpos public void close curr chunk null iterator null currchunk protected blob output stream int flags set position flags append 0 size 0 bloboutputstream setposition public random access input stream get input stream return get input stream 0 randomaccessinputstream getinputstream getinputstream public random access input stream get input stream int flags return new blob input stream randomaccessinputstream getinputstream blobinputstream public random access output stream get output stream return get output stream 0 randomaccessoutputstream getoutputstream getoutputstream public random access output stream get output stream boolean multisession return get output stream 0 randomaccessoutputstream getoutputstream getoutputstream public random access output stream get output stream long position boolean multisession random access output stream stream get output stream multisession stream set position position return stream randomaccessoutputstream getoutputstream randomaccessoutputstream getoutputstream setposition public random access output stream get output stream int flags return new blob output stream flags randomaccessoutputstream getoutputstream bloboutputstream public void deallocate iterator iterator chunks iterator while iterator has next iterator next iterator remove chunks clear super deallocate hasnext random access blob impl storage storage super storage chunks storage create index long class true randomaccessblobimpl createindex random access blob impl randomaccessblobimpl public thread page web interface my web interface ft own identity viewer http request request throws no such message exception no such board exception super my web interface viewer request m board m freetalk get message manager get board by name request get param board m thread m freetalk get message manager get request get param id threadpage webinterface mywebinterface ftownidentity httprequest nosuchmessageexception nosuchboardexception mywebinterface mboard mfreetalk getmessagemanager getboardbyname getparam mthread mfreetalk getmessagemanager getparam public final void make synchronized m local date format synchronized m board fixme is this enough synchronization or should we lock the message manager add message box m thread for message reference reference m board get all thread replies m thread true add message box reference get message mlocaldateformat mboard addmessagebox mthread messagereference mboard getallthreadreplies mthread addmessagebox getmessage you have to synchronize on m local date format when using this function private void add message box message message html node message box add content box subject message get title html node table message box add child table new string border width new string 0 100 html node row table add child tr row add child th new string align new string left author row add child td new string align new string left message get author get freetalk address row add child th new string align new string left date row add child td new string align new string left m local date format format message get date row table add child tr row add child th new string align new string left debug add debug info row add child td new string align colspan new string left 3 message row table add child tr html node cell row add child td new string align colspan new string left 4 string lines message get text split r n n for string line lines cell add child line cell add child br add reply button cell message mlocaldateformat addmessagebox htmlnode messagebox addcontentbox gettitle htmlnode messagebox addchild htmlnode addchild addchild addchild getauthor getfreetalkaddress addchild addchild mlocaldateformat getdate addchild addchild adddebuginfo addchild addchild htmlnode addchild gettext addchild addchild addreplybutton private void add reply button html node parent message parent message parent parent add child div align right html node new reply form add form child parent self uri new reply new reply page new reply form add child input new string type name value new string hidden own identityid m own identity getuid new reply form add child input new string type name value new string hidden board name m board get name new reply form add child input new string type name value new string hidden parent messageid parent message getid new reply form add child input new string type name value new string submit submit reply addreplybutton htmlnode parentmessage addchild htmlnode newreplyform addformchild self_uri newreply newreplypage newreplyform addchild ownidentityid mownidentity newreplyform addchild boardname mboard getname newreplyform addchild parentmessageid parentmessage newreplyform addchild private void add debug info html node message box message message message box message box add child font new string size new string 2 message box add child uri message geturi message box add child br id message getid try message box add child br threadid message get threadid catch no such message exception e message box add child br threadid null try message box add child br parentid message get parentid catch no such message exception e message box add child br parentid null adddebuginfo htmlnode messagebox messagebox messagebox addchild messagebox addchild messagebox addchild messagebox addchild getthreadid nosuchmessageexception messagebox addchild messagebox addchild getparentid nosuchmessageexception messagebox addchild logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog request cooldown queue long cooldown time keys new key min size times new long min size clients new sendable get min size holes 0 start ptr 0 end ptr 0 this cooldown time cooldown time requestcooldownqueue cooldowntime min_size min_size sendableget min_size startptr endptr cooldowntime cooldowntime public synchronized long add key key sendable get client object container container long remove time system current time millis cooldown time if remove time get last time remove time get last time logger error this clock skew detected attempting to compensate expect things to break add key client remove time return remove time sendableget objectcontainer removetime currenttimemillis cooldowntime removetime getlasttime removetime getlasttime removetime removetime private synchronized long get last time if start ptr end ptr return 1 if end ptr 0 return times end ptr 1 return times times length 1 getlasttime startptr endptr endptr endptr private synchronized void add key key sendable get client long remove time if holes 0 logger error this holes holes if logminor logger minor this adding key key client client remove time remove time start ptr start ptr end ptr end ptr keys length keys length int ptr end ptr if end ptr start ptr if logminor logger minor this end ptr start ptr if end ptr keys length 1 last key if start ptr 0 no room expand queue add key client null return else wrap around end ptr 0 else end ptr else if end ptr start ptr if logminor logger minor this end ptr start ptr if end ptr start ptr 1 expand queue add key client null return else end ptr else end ptr start ptr nothing queued if logminor logger minor this end ptr start ptr end ptr 1 start ptr 0 ptr 0 if logminor logger minor this added at ptr start ptr start ptr end ptr end ptr keys ptr key times ptr remove time clients ptr client return sendableget removetime removetime startptr startptr endptr endptr endptr endptr startptr endptr startptr endptr startptr expandqueue endptr endptr endptr startptr endptr startptr endptr startptr expandqueue endptr endptr startptr endptr startptr endptr startptr startptr startptr endptr endptr removetime public synchronized object remove key before long now long dont care after millis object container container int max keys array list key v new array list key boolean foundit false if logdebug foundit big log if logminor logger minor this remove key before now start ptr start ptr end ptr end ptr holes holes keys length keys length if holes 0 logger error this holes holes if foundit if logminor logger minor this found it fixme remove while true if start ptr end ptr if logminor logger minor this no keys queued if v is empty return v to array new key v size else return null long time times start ptr key key keys start ptr if key null times start ptr 0 clients start ptr null start ptr holes if start ptr times length start ptr 0 if logminor logger minor this skipped hole continue else if time now if logminor logger minor this first key is later at time time if v is empty return v to array new key v size else if time now dont care after millis return long value of time else return null times start ptr 0 keys start ptr null clients start ptr null start ptr if start ptr times length start ptr 0 if logminor logger minor this returning key key v add key if v size max keys return v to array new key v size removekeybefore dontcareaftermillis objectcontainer maxkeys arraylist arraylist biglog startptr startptr endptr endptr startptr endptr isempty toarray startptr startptr startptr startptr startptr startptr startptr isempty toarray dontcareaftermillis valueof startptr startptr startptr startptr startptr startptr maxkeys toarray heavy logging and debugging point very useful when debugging certain classes of problems return private boolean big log boolean foundit false if clients start ptr null client requester cr clients start ptr parent if cr instanceof client getter string s client getter cr geturi to short string if logminor logger minor this client s if s equals debug target uri foundit true java util hash map counts by shorturi new java util hash map int nulls 0 int null clients 0 int not getter 0 int valid 0 for int i 0 i keys length i if keys i null nulls continue if clients i null null clients odd continue valid client requester cr clients i parent if cr instanceof client getter string shorturi client getter cr geturi to short string integer ctr integer counts by shorturi get shorturi if ctr null ctr integer value of 1 else ctr integer value of ctr int value 1 counts by shorturi put shorturi ctr else not getter system err println cooldown queue dump system err println system err println by clients for java util iterator it counts by shorturi key set iterator it has next string short key string it next system err println short key counts by shorturi get short key system err println system err println nulls nulls system err println null clients null clients system err println not a getter not getter system err println valid valid system err println return foundit biglog startptr clientrequester startptr clientgetter clientgetter toshortstring debug_target_uri hashmap countsbyshorturi hashmap nullclients notgetter nullclients clientrequester clientgetter clientgetter toshortstring countsbyshorturi valueof valueof intvalue countsbyshorturi notgetter countsbyshorturi keyset hasnext shortkey shortkey countsbyshorturi shortkey nullclients notgetter public synchronized boolean remove key key key sendable get client long time object container container if time 0 return false we won t find it if holes 0 logger error this holes holes if logminor logger minor this remove key key client client at time time start ptr start ptr end ptr end ptr holes holes keys length keys length int idx 1 if end ptr start ptr idx fields binary search times time start ptr end ptr else if end ptr start ptr if logminor logger minor this no keys queued return false else end ptr start ptr fixme argh java doesn t provide binary search with from and to if start ptr times length 1 idx fields binary search times time start ptr times length 1 if idx 0 start ptr 0 idx fields binary search times time 0 end ptr if logminor logger minor this idx idx if idx 0 return false if keys idx key clients idx client keys idx null clients idx null holes if logminor logger minor this found exact return true try backwards first int nidx idx while true if times nidx time break if keys nidx key clients nidx client keys nidx null clients nidx null holes if logminor logger minor this found backwards return true if nidx start ptr break nidx if nidx 1 nidx times length 1 nidx idx now try forwards while true if times nidx time break if keys nidx key clients nidx client keys nidx null clients nidx null holes if logminor logger minor this found forwards return true if nidx end ptr break nidx if nidx times length nidx 0 if logminor logger minor this not found return false removekey sendableget objectcontainer startptr startptr endptr endptr endptr startptr binarysearch startptr endptr endptr startptr endptr startptr binarysearch startptr binarysearch startptr startptr binarysearch endptr startptr endptr allocate a new queue and compact while copying private synchronized void expand queue if logminor logger minor this expanding queue if holes 0 logger error this holes holes holes 0 int new size keys length holes 2 if new size min size new size min size fixme reuse the old buffers if it fits key new keys new key new size long new times new long new size sendable get new clients new sendable get new size reset start ptr to 0 and remove holes int x 0 long last time 1 if end ptr start ptr for int i start ptr i end ptr i if keys i null continue new keys x keys i new times x times i new clients x clients i if last time times i logger error this request cooldown queue inconsistency times i times i but last time last time last time times i x else if end ptr start ptr for int i start ptr i keys length i if keys i null continue new keys x keys i new times x times i new clients x clients i if last time times i logger error this request cooldown queue inconsistency times i times i but last time last time last time times i x for int i 0 i end ptr i if keys i null continue new keys x keys i new times x times i new clients x clients i if last time times i logger error this request cooldown queue inconsistency times i times i but last time last time last time times i x else end ptr start ptr logger error this request cooldown queue expand queue called with end ptr start ptr start ptr return holes 0 start ptr 0 keys new keys times new times clients new clients end ptr x expandqueue newsize newsize min_size newsize min_size newkeys newsize newtimes newsize sendableget newclients sendableget newsize startptr lasttime endptr startptr startptr endptr newkeys newtimes newclients lasttime requestcooldownqueue lasttime lasttime lasttime endptr startptr startptr newkeys newtimes newclients lasttime requestcooldownqueue lasttime lasttime lasttime endptr newkeys newtimes newclients lasttime requestcooldownqueue lasttime lasttime lasttime endptr startptr requestcooldownqueue expandqueue endptr startptr startptr startptr newkeys newtimes newclients endptr public final metadata must resolve public metadata unresolved exception metadata must resolve string message super message this must resolve must resolve mustresolve metadataunresolvedexception mustresolve mustresolve mustresolve public static void encode wot message manager message manager wot own message list list output stream os throws transformer exception parser configuration exception no such message exception synchronized list stream result result stream new stream result os document builder factory xml factory document builder factory new instance document builder xml builder xml factory new document builder dom implementation impl xml builder getdom implementation document xml doc impl create document null freetalk plugin title null element root element xml doc get document element element message list tag xml doc create element message list message list tag set attribute version integer to string xml format version version of the xml format important a own message list contains a single reference for each message a message list however contains a message reference for each board a message is posted to if this function is changed to be able to encode non own message lists then you need to ensure that each message is only listed once the for each message reference will return duplicates if a message is posted to multiple boards for message list message reference ref list own message message message manager get own message ref get messageid if message was inserted false throw new runtime exception trying to convert a message list to xml which contains a not inserted message element message tag xml doc create element message message tag set attribute id message getid message tag set attribute uri message get realuri to string synchronized m date format todo the date is currently not used anywhere message tag set attribute date m date format format message get date for board board message get boards element board tag xml doc create element board board tag set attribute name board get name message tag append child board tag message list tag append child message tag root element append child message list tag dom source dom source new dom source xml doc transformer factory transform factory transformer factory new instance transformer serializer transform factory new transformer serializer set output property output keys encoding utf 8 serializer set output property output keys indent yes fixme set to no before release serializer set output property output keys standalone no serializer transform dom source result stream wotmessagemanager messagemanager wotownmessagelist outputstream transformerexception parserconfigurationexception nosuchmessageexception streamresult resultstream streamresult documentbuilderfactory xmlfactory documentbuilderfactory newinstance documentbuilder xmlbuilder xmlfactory newdocumentbuilder domimplementation xmlbuilder getdomimplementation xmldoc createdocument plugin_title rootelement xmldoc getdocumentelement messagelisttag xmldoc createelement messagelist messagelisttag setattribute tostring xml_format_version ownmessagelist messagelist messagelists messagereference messagelist messagereference ownmessage messagemanager getownmessage getmessageid wasinserted runtimeexception messagelist messagetag xmldoc createelement messagetag setattribute messagetag setattribute getrealuri tostring mdateformat messagetag setattribute mdateformat getdate getboards boardtag xmldoc createelement boardtag setattribute getname messagetag appendchild boardtag messagelisttag appendchild messagetag rootelement appendchild messagelisttag domsource domsource domsource xmldoc transformerfactory transformfactory transformerfactory newinstance transformfactory newtransformer setoutputproperty outputkeys setoutputproperty outputkeys setoutputproperty outputkeys domsource resultstream public static wot message list decode wot message manager message manager wot identity author freeneturi uri input stream input stream throws exception document builder factory xml factory document builder factory new instance xml factory set feature xml constants feature secure processing true dom parser use set attribute to pass to underlying xerces xml factory set attribute http apache org xml features disallow doctype decl true document xml xml factory new document builder parse input stream element list element element xml get elements by tag name message list item 0 if integer parse int list element get attribute version xml format version throw new exception version list element get attribute version xml format version node list message elements list element get elements by tag name message the message count is multiplied by 2 because if a message is posted to multiple boards a message reference has to be created for each array list message list message reference messages new array list message list message reference message elements get length 2 for int message index 0 message index message elements get length message index element message element element message elements item message index string messageid message element get attribute id freeneturi messageuri new freeneturi message element get attribute uri node list board elements message element get elements by tag name board hash set board message boards new hash set board board elements get length 2 for int board index 0 board index board elements get length board index element board element element board elements item board index message boards add message manager get or create board board element get attribute name for board board message boards messages add new message list message reference messageid messageuri board return new wot message list author uri messages wotmessagelist wotmessagemanager messagemanager wotidentity inputstream inputstream documentbuilderfactory xmlfactory documentbuilderfactory newinstance xmlfactory setfeature xmlconstants feature_secure_processing setattribute xmlfactory setattribute xmlfactory newdocumentbuilder inputstream listelement getelementsbytagname messagelist parseint listelement getattribute xml_format_version listelement getattribute xml_format_version nodelist messageelements listelement getelementsbytagname messagereference arraylist messagelist messagereference arraylist messagelist messagereference messageelements getlength messageindex messageindex messageelements getlength messageindex messageelement messageelements messageindex messageelement getattribute messageelement getattribute nodelist boardelements messageelement getelementsbytagname hashset messageboards hashset boardelements getlength boardindex boardindex boardelements getlength boardindex boardelement boardelements boardindex messageboards messagemanager getorcreateboard boardelement getattribute messageboards messagelist messagereference wotmessagelist public static final short code 403 access denied public access denied pluginhttp exception string error message string location super error message location accessdeniedpluginhttpexception errormessage errormessage public final static boolean is alive string nts value if nts value null return false return nts value starts with nts alive isalive ntsvalue ntsvalue ntsvalue startswith public final static boolean is bye bye string nts value if nts value null return false return nts value starts with nts byebye isbyebye ntsvalue ntsvalue ntsvalue startswith public abstract class base sendable get extends sendable request protected base sendable get boolean persistent super persistent basesendableget sendablerequest basesendableget get a numbered key to fetch public abstract key get node key sendable request item token object container container getnodekey sendablerequestitem objectcontainer public abstract key get node key sendable request item token object container container public abstract boolean has valid keys keys fetching locally fetching object container container client context context getnodekey sendablerequestitem objectcontainer hasvalidkeys keysfetchinglocally objectcontainer clientcontext called after checking the datastore and before registering the request to be sent some gets may want to cancel here some may want to send an event to fcp param to network if true we are actually going to send requests unless we cancel in this callback if false we completed all the work assigned tonetwork private static random random generator new random public float evaluate float x return evaluate x 1f randomgenerator public float evaluate float x float y int i j k h n int ix iy float sum 0 float fx fy dx dy distsq if impulse tab null impulse tab impulse tab init 665 ix floor x fx x ix iy floor y fy y iy perform the sparse convolution int m 2 for i m i m i for j m j m j compute voxel hash code h perm ix i perm iy j tabmask tabmask for n nimpulses n 0 n h h 1 tabmask convolve filter and impulse int h4 h 4 dx fx i impulse tab h4 dy fy j impulse tab h4 distsq dx dx dy dy sum catrom2 distsq impulse tab h4 return sum nimpulses impulsetab impulsetab impulsetabinit impulsetab impulsetab impulsetab public float evaluate float x float y float z int i j k h n int ix iy iz float sum 0 float fx fy fz dx dy dz distsq if impulse tab null impulse tab impulse tab init 665 ix floor x fx x ix iy floor y fy y iy iz floor z fz z iz perform the sparse convolution int m 2 for i m i m i for j m j m j for k m k m k compute voxel hash code h perm ix i perm iy j perm iz k tabmask tabmask tabmask for n nimpulses n 0 n h h 1 tabmask convolve filter and impulse int h4 h 4 dx fx i impulse tab h4 dy fy j impulse tab h4 dz fz k impulse tab h4 distsq dx dx dy dy dz dz sum catrom2 distsq impulse tab h4 return sum nimpulses impulsetab impulsetab impulsetabinit impulsetab impulsetab impulsetab impulsetab public static int floor float x int ix int x if x 0 x ix return ix 1 return ix public float catrom2 float d float x int i if d 4 return 0 if table null table new float nentries for i 0 i nentries i x i float samprate x float math sqrt x if x 1 table i 0 5f 2 x x 5 x 3 else table i 0 5f 4 x 8 x 5 x d d samprate 0 5f i floor d if i nentries return 0 return table i static float impulse tab init int seed float impulse tab new float tabsize 4 random generator new random seed set random number generator seed for int i 0 i tabsize i impulse tab i random generator next float impulse tab i random generator next float impulse tab i random generator next float impulse tab i 1 0f 2 0f random generator next float return impulse tab impulsetabinit impulsetab randomgenerator impulsetab randomgenerator nextfloat impulsetab randomgenerator nextfloat impulsetab randomgenerator nextfloat impulsetab randomgenerator nextfloat impulsetab public abstract class store callback length of a data block fixed for lifetime of the store public abstract int data length storecallback datalength public abstract int data length length of a header block fixed for the lifetime of the store public abstract int header length datalength headerlength public abstract int header length length of a routing key routing key is what we use to search for a block also fixed public abstract int routing key length headerlength routingkeylength public abstract int routing key length whether we should create a keys file to keep full keys in in order to reconstruct public abstract boolean store full keys routingkeylength storefullkeys public abstract boolean store full keys whether we need the key in order to reconstruct a block public abstract boolean construct needs key storefullkeys constructneedskey public abstract boolean construct needs key length of a full key full keys are stored in the keys file also fixed public abstract int full key length constructneedskey fullkeylength public abstract int full key length can the same key be valid for two different storable blocks public abstract boolean collision possible fullkeylength storableblocks collisionpossible protected freenet store store called once when first connecting to a freenet store package local public void set store freenet store store this store store freenetstore freenetstore setstore freenetstore public freenet store get store return store freenetstore getstore construct a storable block from the data headers and optionally routing key or full key important using the full key or routing key is optional and if we don t use them we don t check them either caller must check that the key is the one expected throws key verify exception public abstract storable block construct byte data byte headers byte routing key byte full key storableblock keyverifyexception storableblock routingkey fullkey throws key verify exception public void set max keys long max store keys boolean shrink now throws database exception io exception store set max keys max store keys shrink now keyverifyexception setmaxkeys maxstorekeys shrinknow databaseexception ioexception setmaxkeys maxstorekeys shrinknow public long get max keys return store get max keys getmaxkeys getmaxkeys public long hits return store hits public long misses return store misses public long writes return store writes public long key count return store key count keycount keycount public long get bloom false positive return store get bloom false positive getbloomfalsepositive getbloomfalsepositive generate a routing key from a full key public abstract byte routing key from full key byte key buf routingkeyfromfullkey keybuf public simple sendable insert node client core core key block block short prio class super false this block block this prio class prio class this client core node non persistent client if block instanceof chk block scheduler core request starters chk put scheduler else if block instanceof ssk block scheduler core request starters ssk put scheduler else throw new illegal argument exception don t know what to do with block if scheduler is insert scheduler throw new illegal state exception scheduler scheduler is not an insert scheduler simplesendableinsert nodeclientcore keyblock prioclass prioclass prioclass nonpersistentclient chkblock requeststarters chkputscheduler sskblock requeststarters sskputscheduler illegalargumentexception isinsertscheduler illegalstateexception public simple sendable insert key block block short prio class request client client client request scheduler scheduler super false this block block this prio class prio class this client client this scheduler scheduler simplesendableinsert keyblock prioclass requestclient clientrequestscheduler prioclass prioclass override public void on success object key num object container container client context context yay if logger should log logger minor this logger minor this finished insert of block onsuccess keynum objectcontainer clientcontext shouldlog override public void on failure low level put exception e object key num object container container client context context if logger should log logger minor this logger minor this failed insert of block e onfailure lowlevelputexception keynum objectcontainer clientcontext shouldlog override public short get priority class object container container return prio class getpriorityclass objectcontainer prioclass override public int get retry count no retries return 0 getretrycount override public sendable request sender get sender object container container client context context return new sendable request sender public boolean send node client core core request scheduler sched client context context chosen block req ignore key num key since this is a single block boolean logminor logger should log logger minor this try if logminor logger minor this starting request this core real put block should cache catch low level put exception e on failure e req token null context if logminor logger minor this request failed this for e return true finally finished true if logminor logger minor this request succeeded this on success req token null context return true sendablerequestsender getsender objectcontainer clientcontext sendablerequestsender nodeclientcore requestscheduler clientcontext chosenblock keynum shouldlog realput shouldcache lowlevelputexception onfailure onsuccess override public request client get client object container container return client requestclient getclient objectcontainer override public client requester get client request return null clientrequester getclientrequest override public boolean is cancelled object container container return finished iscancelled objectcontainer public boolean is empty object container container return finished isempty objectcontainer public void schedule finished false can reschedule scheduler register insert this false false null registerinsert public void cancel object container container client context context synchronized this if finished return finished true super unregister container context objectcontainer clientcontext public boolean should cache this is only used as is by the random reinsert from a request code subclasses should override return false shouldcache override public synchronized long count all keys object container container client context context if finished return 0 return 1 countallkeys objectcontainer clientcontext override public synchronized long count sendable keys object container container client context context if finished return 0 return 1 countsendablekeys objectcontainer clientcontext override public synchronized sendable request item choose key keys fetching locally keys object container container client context context if keys has transient insert this null sendable request item null item return null if finished return null else return null sendable request item null item sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext hastransientinsert nullsendablerequestitem nullitem nullsendablerequestitem nullitem override public boolean isssk return block instanceof ssk block sskblock override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context transient only so no make blocks throw new unsupported operation exception persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext makeblocks unsupportedoperationexception override public boolean cache inserts object container container return scheduler cache inserts cacheinserts objectcontainer cacheinserts construct a tile image filter public tile image filter this 32 32 tileimagefilter tileimagefilter construct a tile image filter param width the output image width param height the output image height public tile image filter int width int height this width width this height height tileimagefilter tileimagefilter set the output image width param width the width see get width public void set width int width this width width getwidth setwidth get the output image width return the width see set width public int get width return width setwidth getwidth set the output image height param height the height see get height public void set height int height this height height getheight setheight get the output image height return the height see set height public int get height return height setheight getheight public buffered image filter buffered image src buffered image dst int tile width src get width int tile height src get height if dst null color model dstcm src get color model dst new buffered image dstcm dstcm create compatible writable raster width height dstcm is alpha premultiplied null graphics2d g dst create graphics for int y 0 y height y tile height for int x 0 x width x tile width g draw image src null x y g dispose return dst bufferedimage bufferedimage bufferedimage tilewidth getwidth tileheight getheight colormodel getcolormodel bufferedimage createcompatiblewritableraster isalphapremultiplied creategraphics tileheight tilewidth drawimage override public string to string return tile tostring public class simplehtml user alert extends abstract user alert public simplehtml user alert boolean can dismiss string title string short text html node content short type super can dismiss title content get content short text content type true l10n get string user alert hide true null simplehtmluseralert abstractuseralert simplehtmluseralert candismiss shorttext htmlnode candismiss getcontent shorttext getstring useralert override public void is valid boolean validity do nothing isvalid get completion callback protected base client getter short priority class request client client super priority class client getcompletioncallback baseclientgetter priorityclass requestclient priorityclass constructs a brushed metal filter object public brushed metal filter brushedmetalfilter brushedmetalfilter constructs a brushed metal filter object param color an int specifying the metal color param radius an int specifying the blur size param amount a float specifying the amount of texture param monochrome a boolean true for monochrome texture param shine a float specifying the shine to add public brushed metal filter int color int radius float amount boolean monochrome float shine this color color this radius radius this amount amount this monochrome monochrome this shine shine brushedmetalfilter brushedmetalfilter public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int in pixels new int width int out pixels new int width random numbers new random 0 int a color 0xff000000 int r color 16 0xff int g color 8 0xff int b color 0xff for int y 0 y height y for int x 0 x width x int tr r int tg g int tb b if shine 0 int f int 255 shine math sin double x width math pi tr f tg f tb f if monochrome int n int 255 2 random numbers next float 1 amount in pixels x a clamp tr n 16 clamp tg n 8 clamp tb n else in pixels x a random tr 16 random tg 8 random tb if radius 0 blur in pixels out pixels width radius setrgb dst 0 y width 1 out pixels else setrgb dst 0 y width 1 in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage inpixels outpixels randomnumbers randomnumbers nextfloat inpixels inpixels inpixels outpixels outpixels inpixels private int random int x x int 255 2 random numbers next float 1 amount if x 0 x 0 else if x 0xff x 0xff return x randomnumbers nextfloat private static int clamp int c if c 0 return 0 if c 255 return 255 return c return a mod b this differs from the operator with respect to negative numbers param a the dividend param b the divisor return a mod b private static int mod int a int b int n a b a n b if a 0 return a b return a public void blur int in int out int width int radius int width minus1 width 1 int r2 2 radius 1 int tr 0 tg 0 tb 0 for int i radius i radius i int rgb in mod i width tr rgb 16 0xff tg rgb 8 0xff tb rgb 0xff for int x 0 x width x out x 0xff000000 tr r2 16 tg r2 8 tb r2 int i1 x radius 1 if i1 width minus1 i1 mod i1 width int i2 x radius if i2 0 i2 mod i2 width int rgb1 in i1 int rgb2 in i2 tr rgb1 0xff0000 rgb2 0xff0000 16 tg rgb1 0xff00 rgb2 0xff00 8 tb rgb1 0xff rgb2 0xff widthminus1 widthminus1 set the horizontal size of the blur param radius the radius of the blur in the horizontal direction min value 0 max value 100 see get radius public void set radius int radius this radius radius getradius setradius get the horizontal size of the blur return the radius of the blur in the horizontal direction see set radius public int get radius return radius setradius getradius set the amount of noise to add in the range 0 1 param amount the amount of noise min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of noise to add return the amount of noise see set amount public float get amount return amount setamount getamount set the amount of shine to add to the range 0 1 param shine the amount of shine min value 0 max value 1 see get shine public void set shine float shine this shine shine getshine setshine get the amount of shine to add in the range 0 1 return the amount of shine see set shine public float get shine return shine setshine getshine set the color of the metal param color the color in argb form see get color public void set color int color this color color getcolor setcolor get the color of the metal return the color in argb form see set color public int get color return color setcolor getcolor set the type of noise to add param monochrome true for monochrome noise see get monochrome public void set monochrome boolean monochrome this monochrome monochrome getmonochrome setmonochrome get the type of noise to add return true for monochrome noise see set monochrome public boolean get monochrome return monochrome setmonochrome getmonochrome public buffered image create compatible dest image buffered image src color model dstcm if dstcm null dstcm src get color model return new buffered image dstcm dstcm create compatible writable raster src get width src get height dstcm is alpha premultiplied null bufferedimage createcompatibledestimage bufferedimage colormodel getcolormodel bufferedimage createcompatiblewritableraster getwidth getheight isalphapremultiplied public rectangle2d get bounds2d buffered image src return new rectangle 0 0 src get width src get height getbounds2d bufferedimage getwidth getheight public point2d get point2d point2d src pt point2d dst pt if dst pt null dst pt new point2d double dst pt set location src pt getx src pt gety return dst pt getpoint2d srcpt dstpt dstpt dstpt dstpt setlocation srcpt srcpt dstpt public rendering hints get rendering hints return null renderinghints getrenderinghints a convenience method for setting argb pixels in an image this tries to avoid the performance penalty of buffered image setrgb unmanaging the image private void setrgb buffered image image int x int y int width int height int pixels int type image get type if type buffered image type int argb type buffered image type int rgb image get raster set data elements x y width height pixels else image setrgb x y width height pixels 0 width bufferedimage bufferedimage gettype bufferedimage type_int_argb bufferedimage type_int_rgb getraster setdataelements override public string to string return texture brushed metal tostring create a padded encrypted proxy bucket param bucket the bucket which we are proxying to must be empty param pcfb the encryption mode with which to encipher decipher the data param min size the minimum padded size of the file after it has been closed param strongprng a strong prng we will key from param weakprng a week prng we will padd from serialization note that it is not our responsibility to free the random number generators but we will free the underlying bucket throws unsupported cipher exception public padded ephemerally encrypted bucket bucket bucket int min size random source strongprng random weakprng this bucket bucket if bucket size 0 throw new illegal argument exception bucket must be empty byte temp key new byte 32 random seed new byte 32 weakprng next bytes random seed strongprng next bytes temp key this key temp key this min padded size min size read only false last output stream 0 data length 0 minsize unsupportedcipherexception paddedephemerallyencryptedbucket minsize randomsource illegalargumentexception tempkey randomseed nextbytes randomseed nextbytes tempkey tempkey minpaddedsize minsize readonly lastoutputstream datalength load an existing padded ephemerally encrypted bucket with a key the bucket can and should already exist param bucket param min size param known size the size of the data this cannot be deduced from the bucket alone and must be specified if the bucket is smaller than this we throw param key param orig random throws io exception public padded ephemerally encrypted bucket bucket bucket int min size long known size byte key random source orig random throws io exception if bucket size known size throw new io exception bucket bucket is too small on disk known size known size but bucket size bucket size for bucket this data length known size this bucket bucket if key length 32 throw new illegal argument exception key wrong length key length random seed new byte 32 orig random next bytes random seed this key key this min padded size min size read only false last output stream 0 paddedephemerallyencryptedbucket minsize knownsize origrandom ioexception paddedephemerallyencryptedbucket minsize knownsize randomsource origrandom ioexception knownsize ioexception knownsize knownsize datalength knownsize illegalargumentexception randomseed origrandom nextbytes randomseed minpaddedsize minsize readonly lastoutputstream public padded ephemerally encrypted bucket simple field set fs random source orig random persistent file tracker f throws cannot create from field set exception string tmp fs get data length if tmp null throw new cannot create from field set exception no data length try data length long parse long tmp catch number format exception e throw new cannot create from field set exception corrupt data length tmp e simple field set underlying fs subset underlying if underlying null throw new cannot create from field set exception no underlying bucket bucket serializable to field set bucket util create underlying orig random f tmp fs get decrypt key if tmp null throw new cannot create from field set exception no key key hex util hex to bytes tmp if key length 32 throw new illegal argument exception key wrong length key length tmp fs get min padded size if tmp null throw new cannot create from field set exception no min padded size else try min padded size integer parse int tmp catch number format exception e throw new cannot create from field set exception corrupt data length tmp e if data length bucket size throw new cannot create from field set exception underlying bucket bucket is too small should be data length actually bucket size random seed new byte 32 orig random next bytes random seed paddedephemerallyencryptedbucket simplefieldset randomsource origrandom persistentfiletracker cannotcreatefromfieldsetexception datalength cannotcreatefromfieldsetexception datalength datalength parselong numberformatexception cannotcreatefromfieldsetexception datalength simplefieldset cannotcreatefromfieldsetexception serializabletofieldsetbucketutil origrandom decryptkey cannotcreatefromfieldsetexception hexutil hextobytes illegalargumentexception minpaddedsize cannotcreatefromfieldsetexception minpaddedsize minpaddedsize parseint numberformatexception cannotcreatefromfieldsetexception datalength datalength cannotcreatefromfieldsetexception datalength randomseed origrandom nextbytes randomseed public padded ephemerally encrypted bucket padded ephemerally encrypted bucket orig bucket new bucket this data length orig data length this key new byte orig key length system arraycopy orig key 0 key 0 orig key length this random seed null will be read only set read only this bucket new bucket this min padded size orig min padded size paddedephemerallyencryptedbucket paddedephemerallyencryptedbucket newbucket datalength datalength randomseed setreadonly newbucket minpaddedsize minpaddedsize public output stream get output stream throws io exception if read only throw new io exception read only output stream os bucket get output stream synchronized this data length 0 return new padded ephemerally encrypted output stream os last output stream outputstream getoutputstream ioexception readonly ioexception outputstream getoutputstream datalength paddedephemerallyencryptedoutputstream lastoutputstream public padded ephemerally encrypted output stream output stream out int stream number this out out data length 0 this stream number stream number rijndael aes get rijndael pcfb pcfb mode create aes paddedephemerallyencryptedoutputstream outputstream streamnumber datalength streamnumber streamnumber getrijndael pcfbmode override public void write int b throws io exception if closed throw new io exception already closed if stream number last output stream throw new illegal state exception writing to old stream in get name if b 0 b 255 throw new illegal argument exception int to write pcfb encipher b synchronized padded ephemerally encrypted bucket this out write to write data length ioexception ioexception streamnumber lastoutputstream illegalstateexception getname illegalargumentexception towrite paddedephemerallyencryptedbucket towrite datalength override this or fos will use write int override public void write byte buf throws io exception if closed throw new io exception already closed if stream number last output stream throw new illegal state exception writing to old stream in get name write buf 0 buf length ioexception ioexception streamnumber lastoutputstream illegalstateexception getname override public void write byte buf int offset int length throws io exception if closed throw new io exception already closed if stream number last output stream throw new illegal state exception writing to old stream in get name if length 0 return byte enc new byte length system arraycopy buf offset enc 0 length pcfb block encipher enc 0 enc length synchronized padded ephemerally encrypted bucket this out write enc 0 enc length data length enc length ioexception ioexception streamnumber lastoutputstream illegalstateexception getname blockencipher paddedephemerallyencryptedbucket datalength override suppress warnings cast public void close throws io exception if closed return try if stream number last output stream logger normal this not padding out to length because have been superceded get name return random random new mersenne twister random seed synchronized padded ephemerally encrypted bucket this long final length padded length long padding final length data length byte buf new byte 4096 long written padding 0 while written padding padding int left int math min long padding written padding long buf length random next bytes buf out write buf 0 left written padding left finally closed true out flush out close suppresswarnings ioexception streamnumber lastoutputstream getname mersennetwister randomseed paddedephemerallyencryptedbucket finallength paddedlength finallength datalength writtenpadding writtenpadding writtenpadding nextbytes writtenpadding public input stream get input stream throws io exception return new padded ephemerally encrypted input stream bucket get input stream inputstream getinputstream ioexception paddedephemerallyencryptedinputstream getinputstream public padded ephemerally encrypted input stream input stream in this in in rijndael aes get rijndael pcfb pcfb mode create aes ptr 0 paddedephemerallyencryptedinputstream inputstream getrijndael pcfbmode override public int read throws io exception if ptr data length return 1 int x in read if x 1 return x ptr return pcfb decipher x ioexception datalength override public final int available int x int math min data length ptr integer max value return x 0 0 x datalength max_value override public int read byte buf int offset int length throws io exception fixme remove debugging if length offset buf length offset 0 length 0 throw new array index out of bounds exception a offset b length length buf length int x available if x 0 return 1 length math min length x int read bytes in read buf offset length if read bytes 0 return read bytes ptr read bytes pcfb block decipher buf offset read bytes return read bytes ioexception arrayindexoutofboundsexception readbytes readbytes readbytes readbytes blockdecipher readbytes readbytes override public int read byte buf throws io exception return read buf 0 buf length ioexception override public long skip long bytes throws io exception byte buf new byte int math min 4096 bytes long skipped 0 while skipped bytes int x read buf 0 int math min bytes skipped buf length if x 0 return skipped skipped x return skipped ioexception override public void close throws io exception in close ioexception return the length of the data in the proxied bucket after padding public synchronized long padded length long size data length if size min padded size size min padded size if size min padded size return size long min min padded size long max long min padded size 1 while true if max 0 throw new error impossible size size min min max max if size min throw new illegal state exception if size min size max if logger should log logger minor this logger minor this padded max was data length for get name return max min max max max 1 paddedlength datalength minpaddedsize minpaddedsize minpaddedsize minpaddedsize minpaddedsize illegalstateexception shouldlog datalength getname private synchronized rijndael get rijndael rijndael aes try aes new rijndael 256 256 catch unsupported cipher exception e throw new error e aes initialize key return aes getrijndael unsupportedcipherexception public string get name return encrypted bucket get name getname getname override public string to string return super to string bucket to string tostring tostring tostring public synchronized long size return data length datalength public boolean is read only return read only isreadonly readonly public void set read only read only true setreadonly readonly return the underlying bucket public bucket get underlying return bucket getunderlying public void free bucket free get the decryption key public byte get key return key getkey public simple field set to field set simple field set fs new simple field set false fs put single type padded ephemerally encrypted bucket synchronized this fs put data length data length if key null fs put single decrypt key hex util bytes to hex key else logger error this cannot serialize because no key return null if bucket instanceof serializable to field set bucket fs put underlying serializable to field set bucket bucket to field set else logger error this cannot serialize underlying bucket bucket return null fs put min padded size min padded size return fs simplefieldset tofieldset simplefieldset simplefieldset putsingle paddedephemerallyencryptedbucket datalength datalength putsingle decryptkey hexutil bytestohex serializabletofieldsetbucket serializabletofieldsetbucket tofieldset minpaddedsize minpaddedsize public void store to object container container bucket store to container container store this storeto objectcontainer storeto public void remove from object container container if logger should log logger minor this logger minor this removing from database this bucket remove from container container delete this removefrom objectcontainer shouldlog removefrom public void object on activate object container container logger minor this activating super to string bucket null bucket null cascading activation of dependancies container activate bucket 1 objectonactivate objectcontainer tostring public bucket create shadow throws io exception bucket new underlying bucket create shadow if new underlying null return null return new padded ephemerally encrypted bucket this new underlying createshadow ioexception newunderlying createshadow newunderlying paddedephemerallyencryptedbucket newunderlying create a null peer public peer throws exception this inet address get local host 0 inetaddress getlocalhost public peer data input dis throws io exception addr new freenet inet address dis port dis read int if port 65535 port 0 throw new io exception bogus port datainput ioexception freenetinetaddress _port readint _port _port ioexception public peer data input dis boolean check hostname orip syntax throws hostname syntax exception io exception addr new freenet inet address dis check hostname orip syntax port dis read int if port 65535 port 0 throw new io exception bogus port datainput checkhostnameoripsyntax hostnamesyntaxexception ioexception freenetinetaddress checkhostnameoripsyntax _port readint _port _port ioexception create a peer from an inet address and a port the ip address is primary that is to say it will remain the same regardless of dns changes don t do this if you are dealing with domain names whose ip may change public peer inet address address int port addr new freenet inet address address port port if port 65535 port 0 throw new illegal argument exception bogus port inetaddress inetaddress freenetinetaddress _port _port _port illegalargumentexception create a peer from a string this may be an ip address or a domain name if it is the latter the name is primary rather than the ip address get handshake address will do a new lookup on the name and change the ip address if the domain name has changed param physical the string to be parsed in the format ip or domain name port number param allow unknown if true allow construction of the peer even if the domain name lookup fails throws peer parse exception if the string is not valid e g if it doesn t contain a port throws unknown host exception if allow unknown is not set and a domain name which does not exist was passed in public peer string physical boolean allow unknown throws peer parse exception unknown host exception int offset physical last index of ipv6 if offset 0 throw new peer parse exception string host physical substring 0 offset addr new freenet inet address host allow unknown string strport physical substring offset 1 try port integer parse int strport if port 0 port 65535 throw new peer parse exception invalid port port catch number format exception e throw new peer parse exception e gethandshakeaddress allowunknown peerparseexception unknownhostexception allowunknown allowunknown peerparseexception unknownhostexception lastindexof peerparseexception freenetinetaddress allowunknown _port parseint _port _port peerparseexception _port numberformatexception peerparseexception create a peer from a string this may be an ip address or a domain name if it is the latter the name is primary rather than the ip address get handshake address will do a new lookup on the name and change the ip address if the domain name has changed param physical the string to be parsed in the format ip or domain name port number param allow unknown if true allow construction of the peer even if the domain name lookup fails param check hostname orip syntax if true validate the syntax of the given dns hostname or i pv4 ip address throws host syntax exception if the string is not formatted as a proper dns hostname or i pv4 ip address throws peer parse exception if the string is not valid e g if it doesn t contain a port throws unknown host exception if allow unknown is not set and a domain name which does not exist was passed in public peer string physical boolean allow unknown boolean check hostname orip syntax throws hostname syntax exception peer parse exception unknown host exception int offset physical last index of ipv6 if offset 0 throw new peer parse exception string host physical substring 0 offset addr new freenet inet address host allow unknown check hostname orip syntax string strport physical substring offset 1 try port integer parse int strport if port 0 port 65535 throw new peer parse exception invalid port port catch number format exception e throw new peer parse exception e gethandshakeaddress allowunknown checkhostnameoripsyntax ipv4 hostsyntaxexception ipv4 peerparseexception unknownhostexception allowunknown allowunknown checkhostnameoripsyntax hostnamesyntaxexception peerparseexception unknownhostexception lastindexof peerparseexception freenetinetaddress allowunknown checkhostnameoripsyntax _port parseint _port _port peerparseexception _port numberformatexception peerparseexception public peer freenet inet address addr int port this addr addr if addr null throw new null pointer exception this port port if port 65535 port 0 throw new illegal argument exception bogus port freenetinetaddress nullpointerexception _port _port _port illegalargumentexception public boolean is null return port 0 isnull _port override public boolean equals object o if this o return true if o instanceof peer return false final peer peer peer o if port peer port return false if addr equals peer addr return false return true _port _port public boolean strict equals object o if this o return true if o null return false if o instanceof peer return false final peer peer peer o if port peer port return false if addr strict equals peer addr return false return true strictequals _port _port strictequals get the ip address look it up if necessary but return the last value if it has ever been looked up before will not trigger a new lookup if it has been looked up before public inet address get address return get address true inetaddress getaddress getaddress get the ip address look it up if allowed to but return the last value if it has ever been looked up before will not trigger a new lookup if it has been looked up before public inet address get address boolean dodns request return addr get address dodns request inetaddress getaddress dodnsrequest getaddress dodnsrequest public inet address get address boolean dodns request boolean allow local throws local address exception inet address a addr get address dodns request if a null return null if allow local ip util is valid address a false return a throw new local address exception inetaddress getaddress dodnsrequest allowlocal localaddressexception inetaddress getaddress dodnsrequest allowlocal iputil isvalidaddress localaddressexception get the ip address looking up the hostname if the hostname is primary even if it has been looked up before typically called on a reconnect attempt when the dyndns address may have changed public inet address get handshake address return addr get handshake address inetaddress gethandshakeaddress gethandshakeaddress override public int hash code return addr hash code port hashcode hashcode _port public int get port return port getport _port override public string to string return addr to string port tostring tostring _port public void write to data output stream data output stream dos throws io exception addr write to data output stream dos dos write int port writetodataoutputstream dataoutputstream ioexception writetodataoutputstream writeint _port public freenet inet address get freenet address return addr freenetinetaddress getfreenetaddress public boolean is real internet address boolean lookup boolean default val boolean allow local addresses return addr is real internet address lookup default val allow local addresses isrealinternetaddress defaultval allowlocaladdresses isrealinternetaddress defaultval allowlocaladdresses get the address port string but prefer numeric i ps don t return the name public string to string pref numeric return addr to string pref numeric port ips tostringprefnumeric tostringprefnumeric _port public peer drop host name freenet inet address new addr addr drop hostname if new addr null return null if addr new addr return new peer new addr port else return this drophostname freenetinetaddress newaddr drophostname newaddr newaddr newaddr _port protected float extra alpha public rgb composite this 1 0f extraalpha rgbcomposite public rgb composite float alpha if alpha 0 0f alpha 1 0f throw new illegal argument exception rgb composite alpha must be between 0 and 1 this extra alpha alpha rgbcomposite illegalargumentexception rgbcomposite extraalpha public float get alpha return extra alpha getalpha extraalpha override public int hash code return float float to int bits extra alpha hashcode floattointbits extraalpha override public boolean equals object o if o instanceof rgb composite return false rgb composite c rgb composite o if extra alpha c extra alpha return false return true rgbcomposite rgbcomposite rgbcomposite extraalpha extraalpha public rgb composite context float alpha color model src color model color model dst color model this alpha alpha this src color model src color model this dst color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel srccolormodel dstcolormodel dstcolormodel public void dispose multiply two numbers in the range 0 255 such that 255 255 255 static int multiply255 int a int b int t a b 0x80 return t 8 t 8 static int clamp int a return a 0 0 a 255 255 a public abstract void composergb int src int dst float alpha public void compose raster src raster dst in writable raster dst out float alpha this alpha int src pix null int dst pix null int x dst out get minx int w dst out get width int y0 dst out get miny int y1 y0 dst out get height for int y y0 y y1 y src pix src get pixels x y w 1 src pix dst pix dst in get pixels x y w 1 dst pix composergb src pix dst pix alpha dst out set pixels x y w 1 dst pix dstin writableraster dstout srcpix dstpix dstout getminx dstout getwidth dstout getminy dstout getheight srcpix getpixels srcpix dstpix dstin getpixels dstpix srcpix dstpix dstout setpixels dstpix public static void main string args throws fs parse exception peer parse exception chk encode exception invalid threshold exception node init exception reference signature verification exception key collision exception ssk encode exception io exception interrupted exception ssk verify exception system err println ulpr test system err println string test name real nodeulpr test file wd new file test name if file util remove all wd system err println mass delete failed test may not be accurate system exit exit cannot delete old data wd mkdir dummy random source random new dummy random source note global test init returns in ignored random source node starter global test init test name false logger error freenet node location normal freenet node simulator real node routing test normal freenet node node dispatcher normal freenet node failure table minor freenet node node minor freenet node request minor freenet io comm message core minor freenet store minor freenet node location manager debug freenet node fnp packet manager normal freenet io comm message core debug node starter global test init test name false logger error freenet node location normal freenet node simulator real node routing test normal freenet node node dispatcher normal freenet node failure table minor freenet node node minor freenet node request minor freenet io comm message core minor freenet node peer node minor freenet io xfer packet throttle minor freenet node peer manager minor true node nodes new node number of nodes logger normal real node routing test class creating nodes executor executor new pooled executor for int i 0 i number of nodes i nodes i node starter create test node 5000 i 0 test name false true true max htl 20 5 random executor 500 number of nodes 1024 1024 true enable swapping false enable ulprs enable per node failure tables true true 0 enable foaf false null logger normal real node routing test class created node i simple field set refs new simple field set number of nodes for int i 0 i number of nodes i refs i nodes i export darknet public field set logger normal real node routing test class created number of nodes nodes now link them up connect the set for int i 0 i number of nodes i int next i 1 number of nodes int prev i number of nodes 1 number of nodes nodes i connect nodes next nodes i connect nodes prev logger normal real node routing test class connected nodes now add some random links for int i 0 i number of nodes 5 i if i number of nodes 0 logger normal real node routing test class i int length int math pow number of nodes random next double int nodea random next int number of nodes int nodeb nodea length number of nodes system out println nodea nodeb node a nodes nodea node b nodes nodeb a connect b b connect a logger normal real node routing test class added random links for int i 0 i number of nodes i nodes i start false int successful tests 0 long total propagation time 0 for int total count 0 total count number of tests total count final boolean isssk isssk total count 0x1 1 isssk true now create a key byte buf new byte 32 random next bytes buf string key name hex util bytes to hex buf freeneturi test key client key insert key client key fetch key client key block block if isssk test key new freeneturi ksk key name insert key insertable clientssk create test key fetch key clientksk create test key block insertable clientssk insert key encode new array bucket buf false false short 1 buf length random else block clientchk block encode buf false false short 1 buf length insert key fetch key block get client key test key insert key geturi final key node key fetch key get node key system err println system err println created random test key test key node key system err println logger error real nodeulpr test class starting ulpr test successful tests test key fetch key node key wait for all connected nodes fetch the key from each node only those nodes which have been asked by another node not directly here for the key will want it further only those nodes on the actual dnf path will learn from their mistakes a rejected loop doesn t tell you much lets track which nodes have been visited final boolean visited new boolean nodes length node dispatcher callback cb new node dispatcher callback public void snoop message m node n if isssk m get spec dmt fnpchk data request isssk m get spec dmt fnpssk data request key key key m get object dmt freenet routing key if key equals node key visited n get darknet port number 5000 true for int i 0 i nodes length i nodes i set dispatcher hook cb for int i 0 i nodes length i system out println searching from node i try nodes i nodes length client core real get key fetch key false true false system err println test failed key already present impossible system exit exit key exists catch low level get exception e switch e code case low level get exception data not found case low level get exception route not found expected system err println node i nodes length key not found expected behaviour continue default system err println node i nodes length unexpected error e to string system exit exit unknown error checking key not exist now we should have a good web of subscriptions set up int visited count 0 string builder sb new string builder 3 nodes length 1 boolean first true for int i 0 i visited length i if visited i continue visited count if first sb append first false sb append i system err println nodes which were asked for the key by another node visited count sb to string store the key to one node long t start system current time millis nodes nodes length 1 store block false int x 1 while true x thread sleep 1000 int count 0 for int i 0 i nodes length i if nodes i fetch fetch key get node key true null count system err println t x count nodes length have the data on test successful tests logger normal real nodeulpr test class t x count nodes length have the data on test successful tests if x 300 system err println system err println test failed system exit exit test failed if count nodes length successful tests long t end system current time millis long propagation time t end t start system err println successful test successful tests in propagation time ms total propagation time propagation time system err println average propagation time total propagation time successful tests ms system err println break if x nodes length 0 system err print nodes that don t have the data for int i 0 i nodes length i if nodes i fetch fetch key get node key true null system err print i system err println system err println overall average propagation time total propagation time successful tests ms system exit 0 fsparseexception peerparseexception chkencodeexception invalidthresholdexception nodeinitexception referencesignatureverificationexception keycollisionexception sskencodeexception ioexception interruptedexception sskverifyexception testname realnodeulprtest testname fileutil removeall exit_cannot_delete_old_data dummyrandomsource dummyrandomsource globaltestinit nodestarter globaltestinit testname realnoderoutingtest nodedispatcher failuretable messagecore locationmanager fnppacketmanager messagecore nodestarter globaltestinit testname realnoderoutingtest nodedispatcher failuretable messagecore peernode packetthrottle peermanager number_of_nodes realnoderoutingtest pooledexecutor number_of_nodes nodestarter createtestnode testname max_htl number_of_nodes enable_swapping enable_ulprs enable_per_node_failure_tables enable_foaf realnoderoutingtest simplefieldset simplefieldset number_of_nodes number_of_nodes exportdarknetpublicfieldset realnoderoutingtest number_of_nodes number_of_nodes number_of_nodes number_of_nodes number_of_nodes realnoderoutingtest number_of_nodes number_of_nodes realnoderoutingtest number_of_nodes nextdouble nextint number_of_nodes number_of_nodes realnoderoutingtest number_of_nodes successfultests totalpropagationtime totalcount totalcount number_of_tests totalcount totalcount nextbytes keyname hexutil bytestohex testkey clientkey insertkey clientkey fetchkey clientkeyblock testkey keyname insertkey insertableclientssk testkey fetchkey testkey insertableclientssk insertkey arraybucket clientchkblock insertkey fetchkey getclientkey testkey insertkey nodekey fetchkey getnodekey testkey nodekey realnodeulprtest successfultests testkey fetchkey nodekey waitforallconnected rejectedloop nodedispatchercallback nodedispatchercallback getspec fnpchkdatarequest getspec fnpsskdatarequest getobject freenet_routing_key nodekey getdarknetportnumber setdispatcherhook clientcore realgetkey fetchkey exit_key_exists lowlevelgetexception lowlevelgetexception data_not_found lowlevelgetexception route_not_found tostring exit_unknown_error_checking_key_not_exist visitedcount stringbuilder stringbuilder visitedcount visitedcount tostring tstart currenttimemillis fetchkey getnodekey successfultests realnodeulprtest successfultests exit_test_failed successfultests tend currenttimemillis propagationtime tend tstart successfultests propagationtime totalpropagationtime propagationtime totalpropagationtime successfultests fetchkey getnodekey totalpropagationtime successfultests public void snoop message m node n if isssk m get spec dmt fnpchk data request isssk m get spec dmt fnpssk data request key key key m get object dmt freenet routing key if key equals node key visited n get darknet port number 5000 true getspec fnpchkdatarequest getspec fnpsskdatarequest getobject freenet_routing_key nodekey getdarknetportnumber public class quoting public static string get full quote message message return message get author get freetalk address wrote n quote lines message get text getfullquote getauthor getfreetalkaddress quotelines gettext maybe frost has code for that which can be used here private static string quote lines string text string lines text split r n n string buffer result new string buffer text length lines length 2 16 for string line lines result append result append line result append n return result to string quotelines stringbuffer stringbuffer tostring private multicast socket ssdp uni sock null public datagram socket get datagram socket return ssdp uni sock multicastsocket ssdpunisock datagramsocket getdatagramsocket ssdpunisock public httpu socket open httpusocket public httpu socket string bind addr int bind port open bind addr bind port httpusocket bindaddr bindport bindaddr bindport public httpu socket int bind port open bind port httpusocket bindport bindport protected void finalize close private string local addr public void set local address string addr local addr addr localaddr setlocaladdress localaddr public string get local address if 0 local addr length return local addr return ssdp uni sock get local address get host address getlocaladdress localaddr localaddr ssdpunisock getlocaladdress gethostaddress public boolean open close try ssdp uni sock new datagram socket catch exception e debug warning e return false return true ssdpunisock datagramsocket public boolean open string bind addr int bind port close try bind only using the port without the interface address 2003 12 12 inet socket address bind sock new inet socket address inet address get by name bind addr bind port ssdp uni sock new datagram socket null ssdp uni sock set reuse address true ssdp uni sock bind bind sock catch exception e debug warning e return false set local address bind addr return true bindaddr bindport inetsocketaddress bindsock inetsocketaddress inetaddress getbyname bindaddr bindport ssdpunisock datagramsocket ssdpunisock setreuseaddress ssdpunisock bindsock setlocaladdress bindaddr public boolean open int bind port close try inet socket address bind sock new inet socket address bind port ssdp uni sock new datagram socket null ssdp uni sock set reuse address true ssdp uni sock bind bind sock catch exception e debug warning e return false return true bindport inetsocketaddress bindsock inetsocketaddress bindport ssdpunisock datagramsocket ssdpunisock setreuseaddress ssdpunisock bindsock public boolean close if ssdp uni sock null return true try ssdp uni sock close ssdp uni sock null catch exception e debug warning e return false return true ssdpunisock ssdpunisock ssdpunisock public boolean post string addr int port string msg try inet address inet addr inet address get by name addr datagram packet dgm packet new datagram packet msg get bytes msg length inet addr port ssdp uni sock send dgm packet catch exception e debug warning addr ssdp uni sock get local address get host name debug warning port ssdp uni sock get local port debug warning e return false return true inetaddress inetaddr inetaddress getbyname datagrampacket dgmpacket datagrampacket getbytes inetaddr ssdpunisock dgmpacket ssdpunisock getlocaladdress gethostname ssdpunisock getlocalport public ssdp packet receive byte ssdv recv buf new byte ssdp recv message bufsize ssdp packet recv packet new ssdp packet ssdv recv buf ssdv recv buf length recv packet set local address get local address try ssdp uni sock receive recv packet get datagram packet recv packet set time stamp system current time millis catch exception e debug warning e return null return recv packet ssdppacket ssdvrecvbuf recv_message_bufsize ssdppacket recvpacket ssdppacket ssdvrecvbuf ssdvrecvbuf recvpacket setlocaladdress getlocaladdress ssdpunisock recvpacket getdatagrampacket recvpacket settimestamp currenttimemillis recvpacket private transient int update counter rtree updatecounter public void put rectangle r t obj if root null root new rtree page get storage obj r height 1 else rtree page p root insert get storage r obj height if p null root new rtree page get storage root p height 1 update counter 1 n 1 modify rtreepage getstorage rtreepage getstorage rtreepage getstorage updatecounter public int size return n public void remove rectangle r t obj if root null throw new storage error storage error key not found array list reinsert list new array list int reinsert level root remove r obj height reinsert list if reinsert level 0 throw new storage error storage error key not found for int i reinsert list size i 0 rtree page p rtree page reinsert list get i for int j 0 n p n j n j rtree page q root insert get storage p b j p branch get j height reinsert level if q null root splitted root new rtree page get storage root q height 1 reinsert level 1 p deallocate if root n 1 height 1 rtree page new root rtree page root branch get 0 root deallocate root new root height 1 n 1 update counter 1 modify storageerror storageerror key_not_found arraylist reinsertlist arraylist reinsertlevel reinsertlist reinsertlevel storageerror storageerror key_not_found reinsertlist rtreepage rtreepage reinsertlist rtreepage getstorage reinsertlevel rtreepage getstorage reinsertlevel rtreepage newroot rtreepage newroot updatecounter public i persistent get rectangle r array list t result get list r return i persistent result to array new i persistent result size ipersistent arraylist getlist ipersistent toarray ipersistent public array list t get list rectangle r array list t result new array list t if root null root find r result height return result arraylist getlist arraylist arraylist public object to array return get get wrapping rectangle toarray getwrappingrectangle public e e to array e arr return get list get wrapping rectangle to array arr toarray getlist getwrappingrectangle toarray public rectangle get wrapping rectangle if root null return root cover return null getwrappingrectangle public void clear if root null root purge height root null height 0 n 0 modify public void deallocate clear super deallocate class rtree iterator e extends iterable iterator e implements persistent iterator rtree iterator rectangle r counter update counter if height 0 return this r r page stack new rtree page height pos stack new int height if goto first item 0 root page stack null pos stack null rtreeiterator iterableiterator persistentiterator rtreeiterator updatecounter pagestack rtreepage posstack gotofirstitem pagestack posstack public boolean has next if counter update counter throw new concurrent modification exception return page stack null hasnext updatecounter concurrentmodificationexception pagestack protected object current int sp return page stack sp branch get pos stack sp pagestack posstack public e next if has next throw new no such element exception e curr e current height 1 if goto next item height 1 page stack null pos stack null return curr hasnext nosuchelementexception gotonextitem pagestack posstack public int next oid if has next throw new no such element exception int oid page stack height 1 branch get raw pos stack height 1 get oid if goto next item height 1 page stack null pos stack null return oid nextoid hasnext nosuchelementexception pagestack getraw posstack getoid gotonextitem pagestack posstack private boolean goto first item int sp rtree page pg for int i 0 n pg n i n i if r intersects pg b i if sp 1 height goto first item sp 1 rtree page pg branch get i page stack sp pg pos stack sp i return true return false gotofirstitem rtreepage gotofirstitem rtreepage pagestack posstack private boolean goto next item int sp rtree page pg page stack sp for int i pos stack sp n pg n i n if r intersects pg b i if sp 1 height goto first item sp 1 rtree page pg branch get i page stack sp pg pos stack sp i return true page stack sp null return sp 0 goto next item sp 1 false gotonextitem rtreepage pagestack posstack gotofirstitem rtreepage pagestack posstack pagestack gotonextitem public void remove throw new unsupported operation exception unsupportedoperationexception int pos public rectangle get key return pg b pos getkey public t get value return t pg branch get pos getvalue public t set value t value throw new unsupported operation exception setvalue unsupportedoperationexception rtree entry rtree page pg int pos this pg pg this pos pos rtreeentry rtreepage class rtree entry iterator extends rtree iterator map entry rectangle t rtree entry iterator rectangle r super r rtreeentryiterator rtreeiterator rtreeentryiterator protected object current int sp return new rtree entry page stack sp pos stack sp rtreeentry pagestack posstack public iterator t iterator return iterator get wrapping rectangle getwrappingrectangle public iterable iterator map entry rectangle t entry iterator return entry iterator get wrapping rectangle iterableiterator entryiterator entryiterator getwrappingrectangle public iterable iterator t iterator rectangle r return new rtree iterator t r iterableiterator rtreeiterator public iterable iterator map entry rectangle t entry iterator rectangle r return new rtree entry iterator r iterableiterator entryiterator rtreeentryiterator public message invalid exception int protocol code string extra string ident boolean global super extra this protocol code protocol code this ident ident this global global messageinvalidexception protocolcode protocolcode protocolcode transient boolean running override public int hash code return hash code hashcode hashcode public fec job fec codec codec fec queue queue splitfile block data block status splitfile block check block status int block length bucket factory bucket factory fec callback callback boolean isa decoding job short priority boolean persistent this codec codec this fec algo codec get algorithm this queue queue this priority priority this added time system current time millis this data block status new splitfile block data block status length this check block status new splitfile block check block status length for int i 0 i data block status length i this data block status i data block status i for int i 0 i check block status length i this check block status i check block status i this data block status data block status this check block status check block status this data blocks new bucket data block status length this check blocks new bucket check block status length for int i 0 i data blocks length i this data blocks i data block status i get data for int i 0 i check blocks length i this check blocks i check block status i get data this block length block length this bucket factory bucket factory this callback callback this isa decoding job isa decoding job this persistent persistent this hash code super hash code fecjob feccodec fecqueue splitfileblock datablockstatus splitfileblock checkblockstatus blocklength bucketfactory bucketfactory feccallback isadecodingjob fecalgo getalgorithm addedtime currenttimemillis datablockstatus splitfileblock datablockstatus checkblockstatus splitfileblock checkblockstatus datablockstatus datablockstatus datablockstatus checkblockstatus checkblockstatus checkblockstatus datablockstatus datablockstatus checkblockstatus checkblockstatus datablocks datablockstatus checkblocks checkblockstatus datablocks datablocks datablockstatus getdata checkblocks checkblocks checkblockstatus getdata blocklength blocklength bucketfactory bucketfactory isadecodingjob isadecodingjob hashcode hashcode override public string to string return super to string decode isa decoding job callback callback persistent persistent tostring tostring isadecodingjob public fec job fec codec codec fec queue queue bucket data blocks bucket check blocks int block length bucket factory bucket factory fec callback callback boolean isa decoding job short priority boolean persistent this hash code super hash code this codec codec this fec algo codec get algorithm this queue queue this priority priority this added time system current time millis this data blocks data blocks this check blocks check blocks this data block status null this check block status null this block length block length this bucket factory bucket factory this callback callback this isa decoding job isa decoding job this persistent persistent fecjob feccodec fecqueue datablocks checkblocks blocklength bucketfactory bucketfactory feccallback isadecodingjob hashcode hashcode fecalgo getalgorithm addedtime currenttimemillis datablocks datablocks checkblocks checkblocks datablockstatus checkblockstatus blocklength blocklength bucketfactory bucketfactory isadecodingjob isadecodingjob public fec codec get codec if codec null codec fec codec get codec fec algo data blocks length check blocks length if codec null logger error this no codec found for algo fec algo data blocks length data blocks length check blocks length check blocks length return codec feccodec getcodec feccodec getcodec fecalgo datablocks checkblocks fecalgo datablocks checkblocks public void activate for execution object container container boolean logminor logger should log logger minor this if logminor logger minor this activating fec job if data block status null logminor for int i 0 i data block status length i logger minor this data block status i data block status i before activation container activate this 2 if data block status null for int i 0 i data block status length i container activate data block status i 2 if data block status null logminor for int i 0 i data block status length i logger minor this data block status i data block status i after activation if check block status null for int i 0 i check block status length i container activate check block status i 2 if data blocks null for int i 0 i data blocks length i logger minor this data bucket i data blocks i before activation container activate data blocks i 1 logger minor this data bucket i data blocks i after activation if check blocks null for int i 0 i check blocks length i container activate check blocks i 1 activateforexecution objectcontainer shouldlog fecjob datablockstatus datablockstatus datablockstatus datablockstatus datablockstatus datablockstatus datablockstatus datablockstatus datablockstatus checkblockstatus checkblockstatus checkblockstatus datablocks datablocks datablocks datablocks datablocks checkblocks checkblocks checkblocks public void deactivate object container container if logger should log logger minor this logger minor this deactivating fec job if data block status null for int i 0 i data block status length i container deactivate data block status i 2 if check block status null for int i 0 i check block status length i container deactivate check block status i 2 if data blocks null for int i 0 i data blocks length i container deactivate data blocks i 1 if check blocks null for int i 0 i check blocks length i container deactivate check blocks i 1 objectcontainer shouldlog fecjob datablockstatus datablockstatus datablockstatus checkblockstatus checkblockstatus checkblockstatus datablocks datablocks datablocks checkblocks checkblocks checkblocks public void store block statuses object container container boolean logminor logger should log logger minor this if logminor logger minor this storing block statuses if data block status null for int i 0 i data block status length i splitfile block block data block status i if logminor logger minor this storing data block i block block store to container if check block status null for int i 0 i check block status length i splitfile block block check block status i if logminor logger minor this storing check block i block block store to container storeblockstatuses objectcontainer shouldlog datablockstatus datablockstatus splitfileblock datablockstatus storeto checkblockstatus checkblockstatus splitfileblock checkblockstatus storeto public boolean is cancelled object container container if callback null for bucket data data blocks if data null logger error this callback is null deleted but data is valid data data free data remove from container for bucket data check blocks if data null logger error this callback is null deleted but data is valid data data free data remove from container for splitfile block block data block status if block null logger error this callback is null deleted but data is valid block bucket data block get data if data null logger error this callback is null deleted but data is valid data data free data remove from container container delete block for splitfile block block check block status if block null logger error this callback is null deleted but data is valid block bucket data block get data if data null logger error this callback is null deleted but data is valid data data free data remove from container container delete block return true return false iscancelled objectcontainer datablocks removefrom checkblocks removefrom splitfileblock datablockstatus getdata removefrom splitfileblock checkblockstatus getdata removefrom param container param context return true unless we were unable to remove the job because it has already started public boolean cancel object container container client context context return queue cancel this container context objectcontainer clientcontext override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this shouldupdate shouldlog shouldlog public static final long default containersize spare 196 1024 public default manifest putter client callback client callback hash map string object manifest elements short prio class freeneturi target string default name insert context ctx boolean getchk only request client client context boolean early encode super client callback manifest elements prio class target default name ctx getchk only client context early encode default_containersize_spare defaultmanifestputter clientcallback clientcallback hashmap manifestelements prioclass defaultname insertcontext getchkonly requestclient clientcontext earlyencode clientcallback manifestelements prioclass defaultname getchkonly clientcontext earlyencode implements the pack logic see freenet client async base manifest putter make put handlers java util hash map java util hash map override protected void make put handlers hash map string object manifest elements hash map string object put handlers by name verify manifest manifest elements make put handlers get root container manifest elements make put handlers get root container manifest elements default max containersize null basemanifestputter makeputhandlers hashmap hashmap makeputhandlers hashmap manifestelements hashmap puthandlersbyname verifymanifest manifestelements makeputhandlers getrootcontainer manifestelements makeputhandlers getrootcontainer manifestelements default_max_containersize ensure the tree contains only elements we understand so we do not need further checking in the pack algorithm private void verify manifest hash map string object metadata set string set metadata key set for string name set object o metadata get name if o instanceof hash map suppress warnings unchecked hash map string object hm hash map string object o verify manifest hm continue if o instanceof manifest element continue throw new illegal argument exception fatal unknown manifest element o verifymanifest hashmap keyset hashmap suppresswarnings hashmap hashmap verifymanifest manifestelement illegalargumentexception param container builder param manifest elements param prefix param max size param parent name return the size of items in container private long make put handlers container builder container builder hash map string object manifest elements string prefix long max size string parent name hash map string object md plugin reply sender replysender string identifier long max size boolean do insert string parent name throws insert exception system out println stat handling parent name null root parent name if do insert parent name null throw new illegal state exception parent name cant be null for insert if do insert containercounter 1 if max size default max containersize max size default max containersize default containersize spare first get the size the whole one container size whole size container size estimator get sub tree size manifest elements default max containeritemsize max size integer max value step one have a look at all if whole size get size total no limit max size that was easy the whole tree fits into current container without externals system out println pack stat2 the whole tree unlimited fits into container no externals make every thing unlimited put handlers container builder manifest elements prefix return whole size get size total no limit if whole size get size total max size that was easy the whole tree fits into current container with externals system out println pack stat2 the whole tree fits into container with externals make every thing put handlers container builder manifest elements prefix return whole size get size total set string keyset manifest elements key set long tmp size 0 step two here to ensure to have specific files in the root container see pack hints for clients the files in dir fits into container if whole size get size files max size whole size get size files no limit max size the files in dir fits into container system out println pack stat2 the files in dir fits into container with spare so it need to grab stuff from sub s to fill container up if whole size get size files no limit max size for string name keyset object o manifest elements get name if o instanceof manifest element manifest element me manifest element o container builder add item name prefix name me get mime type override me get data tmp size whole size get size files no limit else for string name keyset object o manifest elements get name if o instanceof manifest element manifest element me manifest element o if me get size default max containeritemsize container builder add external name me get mime type override me get data else container builder add item name prefix name me get mime type override me get data tmp size whole size get size files now fill up with stuff from sub s for string name keyset object o manifest elements get name if o instanceof hash map suppress warnings unchecked hash map string object hm hash map string object o tmp size 512 if tmp size max size container builder push current dir container builder make sub dircd name tmp size make put handlers container builder hm max size tmp size name container builder pop current dir else container builder subc container builder make sub container name make put handlers subc hm default max containersize name return tmp size last step three all subdirs fit into current container if whole size get size sub trees max size whole size get size sub trees no limit max size all subdirs fit into current container do it and add files up to limit system out print pack stat2 the sub dirs fit into container with spare so it need to grab files to fill container up if whole size get size sub trees no limit max size system out println unlimited for string name keyset object o manifest elements get name if o instanceof hash map suppress warnings unchecked hash map string object hm hash map string object o container builder push current dir container builder make sub dircd name make every thing unlimited put handlers container builder hm prefix container builder pop current dir tmp size whole size get size sub trees no limit else system out println limited for string name keyset object o manifest elements get name if o instanceof hash map suppress warnings unchecked hash map string object hm hash map string object o container builder push current dir container builder make sub dircd name make every thing put handlers container builder hm prefix container builder pop current dir tmp size whole size get size sub trees else sub dirs does not fit into container make each its own system out print pack stat2 sub dirs does not fit into container make each its own for string name keyset object o manifest elements get name if o instanceof hash map suppress warnings unchecked hash map string object hm hash map string object o container builder subc container builder make sub container name make put handlers subc hm default max containersize name tmp size 512 fill up container with files hash map string object items left new hash map string object for string name keyset object o manifest elements get name if o instanceof manifest element manifest element me manifest element o if me get size 1 me get size default max containeritemsize me get size max size tmp size container builder add item name name me get mime type override me get data tmp size container size estimator tar item size me get size else tmp size 512 items left put name me group files left into external archives chk name redirects while items left is empty system out println items left checker items left size if items left size 1 one item left make it external set string l key setset items left key set for string lname l key setset manifest element me manifest element items left get lname container builder add external lname me get mime type override me get data items left clear continue final long left limit default max containersize default containersize spare container size left size container size estimator get sub tree size items left default max containeritemsize left limit 0 if left size get size files 0 left size get size files no limit left limit possible container items are left and everything fits into single archive do it container builder archive make archive set string l key setset items left key set for string lname l key setset manifest element me manifest element items left get lname container builder add archive item archive lname lname me get mime type override me get data items left clear continue if left size get size files 0 left size get size files no limit 0 all items left are to big make all external set string l key setset items left key set for string lname l key setset manifest element me manifest element items left get lname container builder add external lname me get mime type override me get data items left clear continue fill up a archive long archive limit default containersize spare set string l key setset items left key set container builder archive make archive for string lname l key setset manifest element me manifest element items left get lname if me get size 1 me get size default max containeritemsize me get size default max containersize archive limit container builder add archive item archive lname lname me get mime type override me get data tmp size 512 archive limit container size estimator tar item size me get size l key setset remove lname return tmp size containerbuilder manifestelements maxsize parentname makeputhandlers containerbuilder containerbuilder hashmap manifestelements maxsize parentname hashmap pluginreplysender maxsize doinsert parentname insertexception parentname parentname doinsert parentname illegalstateexception doinsert maxsize default_max_containersize maxsize default_max_containersize default_containersize_spare containersize wholesize containersizeestimator getsubtreesize manifestelements default_max_containeritemsize maxsize max_value wholesize getsizetotalnolimit maxsize packstat2 makeeverythingunlimitedputhandlers containerbuilder manifestelements wholesize getsizetotalnolimit wholesize getsizetotal maxsize packstat2 makeeverythingputhandlers containerbuilder manifestelements wholesize getsizetotal manifestelements keyset tmpsize wholesize getsizefiles maxsize wholesize getsizefilesnolimit maxsize packstat2 wholesize getsizefilesnolimit maxsize manifestelements manifestelement manifestelement manifestelement containerbuilder additem getmimetypeoverride getdata tmpsize wholesize getsizefilesnolimit manifestelements manifestelement manifestelement manifestelement getsize default_max_containeritemsize containerbuilder addexternal getmimetypeoverride getdata containerbuilder additem getmimetypeoverride getdata tmpsize wholesize getsizefiles manifestelements hashmap suppresswarnings hashmap hashmap tmpsize tmpsize maxsize containerbuilder pushcurrentdir containerbuilder makesubdircd tmpsize makeputhandlers containerbuilder maxsize tmpsize containerbuilder popcurrentdir containerbuilder containerbuilder makesubcontainer makeputhandlers default_max_containersize tmpsize wholesize getsizesubtrees maxsize wholesize getsizesubtreesnolimit maxsize packstat2 wholesize getsizesubtreesnolimit maxsize manifestelements hashmap suppresswarnings hashmap hashmap containerbuilder pushcurrentdir containerbuilder makesubdircd makeeverythingunlimitedputhandlers containerbuilder containerbuilder popcurrentdir tmpsize wholesize getsizesubtreesnolimit manifestelements hashmap suppresswarnings hashmap hashmap containerbuilder pushcurrentdir containerbuilder makesubdircd makeeverythingputhandlers containerbuilder containerbuilder popcurrentdir tmpsize wholesize getsizesubtrees packstat2 manifestelements hashmap suppresswarnings hashmap hashmap containerbuilder containerbuilder makesubcontainer makeputhandlers default_max_containersize tmpsize hashmap itemsleft hashmap manifestelements manifestelement manifestelement manifestelement getsize getsize default_max_containeritemsize getsize maxsize tmpsize containerbuilder additem getmimetypeoverride getdata tmpsize containersizeestimator taritemsize getsize tmpsize itemsleft itemsleft isempty itemsleft itemsleft itemsleft lkeysetset itemsleft keyset lkeysetset manifestelement manifestelement itemsleft containerbuilder addexternal getmimetypeoverride getdata itemsleft leftlimit default_max_containersize default_containersize_spare containersize leftsize containersizeestimator getsubtreesize itemsleft default_max_containeritemsize leftlimit leftsize getsizefiles leftsize getsizefilesnolimit leftlimit containerbuilder makearchive lkeysetset itemsleft keyset lkeysetset manifestelement manifestelement itemsleft containerbuilder addarchiveitem getmimetypeoverride getdata itemsleft leftsize getsizefiles leftsize getsizefilesnolimit lkeysetset itemsleft keyset lkeysetset manifestelement manifestelement itemsleft containerbuilder addexternal getmimetypeoverride getdata itemsleft archivelimit default_containersize_spare lkeysetset itemsleft keyset containerbuilder makearchive lkeysetset manifestelement manifestelement itemsleft getsize getsize default_max_containeritemsize getsize default_max_containersize archivelimit containerbuilder addarchiveitem getmimetypeoverride getdata tmpsize archivelimit containersizeestimator taritemsize getsize lkeysetset tmpsize private void make every thing unlimited put handlers container builder container builder hash map string object manifest elements string prefix files first for string name manifest elements key set object o manifest elements get name if o instanceof manifest element manifest element element manifest element o container builder add item name prefix name element get mime type override element get data subdirs for string name manifest elements key set object o manifest elements get name if o instanceof hash map suppress warnings unchecked hash map string object hm hash map string object o container builder push current dir container builder make sub dircd name make every thing unlimited put handlers container builder hm container builder pop current dir makeeverythingunlimitedputhandlers containerbuilder containerbuilder hashmap manifestelements manifestelements keyset manifestelements manifestelement manifestelement manifestelement containerbuilder additem getmimetypeoverride getdata manifestelements keyset manifestelements hashmap suppresswarnings hashmap hashmap containerbuilder pushcurrentdir containerbuilder makesubdircd makeeverythingunlimitedputhandlers containerbuilder containerbuilder popcurrentdir private void make every thing put handlers container builder container builder hash map string object manifest elements string prefix files first for string name manifest elements key set object o manifest elements get name if o instanceof manifest element manifest element element manifest element o if element get size default max containeritemsize container builder add external name element get mime type override element get data else container builder add item name prefix name element get mime type override element get data subdirs for string name manifest elements key set object o manifest elements get name if o instanceof hash map suppress warnings unchecked hash map string object hm hash map string object o container builder push current dir container builder make sub dircd name make every thing put handlers container builder hm container builder pop current dir makeeverythingputhandlers containerbuilder containerbuilder hashmap manifestelements manifestelements keyset manifestelements manifestelement manifestelement manifestelement getsize default_max_containeritemsize containerbuilder addexternal getmimetypeoverride getdata containerbuilder additem getmimetypeoverride getdata manifestelements keyset manifestelements hashmap suppresswarnings hashmap hashmap containerbuilder pushcurrentdir containerbuilder makesubdircd makeeverythingputhandlers containerbuilder containerbuilder popcurrentdir private final static string escapexml chars string input boolean quote string builder out new string builder if input null return null int oldsize input length char old new char oldsize input get chars 0 oldsize old 0 int selstart 0 string entity null for int i 0 i oldsize i switch old i case entity amp break case entity lt break case entity gt break case if quote entity apos break case if quote entity quot break if entity null out append old selstart i selstart out append entity selstart i 1 entity null if selstart 0 return input out append old selstart oldsize selstart return out to string escapexmlchars stringbuilder stringbuilder getchars tostring public final static string escapexml chars string input return escapexml chars input true escapexmlchars escapexmlchars final string identifier public unknown node identifier message string id string identifier this node identifier id this identifier identifier unknownnodeidentifiermessage nodeidentifier override public simple field set get field set simple field set sfs new simple field set true sfs put single node identifier node identifier if identifier null sfs put single identifier identifier return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle nodeidentifier nodeidentifier putsingle override public string get name return unknown node identifier getname unknownnodeidentifier override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message unknown node identifier goes from server to client not the other way around node identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message unknownnodeidentifier nodeidentifier override public void remove from object container container container delete this removefrom objectcontainer private boolean use image colors false public plasma filter random generator new random useimagecolors plasmafilter randomgenerator specifies the turbulence of the texture param turbulence the turbulence of the texture min value 0 max value 10 see get turbulence public void set turbulence float turbulence this turbulence turbulence getturbulence setturbulence returns the turbulence of the effect return the turbulence of the effect see set turbulence public float get turbulence return turbulence setturbulence getturbulence public void set scaling float scaling this scaling scaling setscaling public float get scaling return scaling getscaling set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set use colormap boolean use colormap this use colormap use colormap setusecolormap usecolormap usecolormap usecolormap public boolean get use colormap return use colormap getusecolormap usecolormap public void set use image colors boolean use image colors this use image colors use image colors setuseimagecolors useimagecolors useimagecolors useimagecolors public boolean get use image colors return use image colors getuseimagecolors useimagecolors public void set seed int seed this seed seed setseed public int get seed return int seed getseed public void randomize seed new date get time gettime private int randomrgb int in pixels int x int y if use image colors return in pixels y original space width x else int r int 255 random generator next float int g int 255 random generator next float int b int 255 random generator next float return 0xff000000 r 16 g 8 b inpixels useimagecolors inpixels originalspace randomgenerator nextfloat randomgenerator nextfloat randomgenerator nextfloat private int displace int rgb float amount int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff r pixel utils clamp r int amount random generator next float 0 5 g pixel utils clamp g int amount random generator next float 0 5 b pixel utils clamp b int amount random generator next float 0 5 return 0xff000000 r 16 g 8 b pixelutils randomgenerator nextfloat pixelutils randomgenerator nextfloat pixelutils randomgenerator nextfloat private int average int rgb1 int rgb2 return pixel utils combine pixels rgb1 rgb2 pixel utils average pixelutils combinepixels pixelutils private int get pixel int x int y int pixels int stride return pixels y stride x getpixel private void put pixel int x int y int rgb int pixels int stride pixels y stride x rgb putpixel private boolean do pixel int x1 int y1 int x2 int y2 int pixels int stride int depth int scale int mx my if depth 0 int ml mr mt mb mm t int tl get pixel x1 y1 pixels stride int bl get pixel x1 y2 pixels stride int tr get pixel x2 y1 pixels stride int br get pixel x2 y2 pixels stride float amount 256 0f 2 0f scale turbulence mx x1 x2 2 my y1 y2 2 if mx x1 mx x2 my y1 my y2 return true if mx x1 mx x2 ml average tl bl ml displace ml amount put pixel x1 my ml pixels stride if x1 x2 mr average tr br mr displace mr amount put pixel x2 my mr pixels stride if my y1 my y2 if x1 mx my y2 mb average bl br mb displace mb amount put pixel mx y2 mb pixels stride if y1 y2 mt average tl tr mt displace mt amount put pixel mx y1 mt pixels stride if y1 y2 x1 x2 mm average tl br t average bl tr mm average mm t mm displace mm amount put pixel mx my mm pixels stride if x2 x1 3 y2 y1 3 return false return true mx x1 x2 2 my y1 y2 2 do pixel x1 y1 mx my pixels stride depth 1 scale 1 do pixel x1 my mx y2 pixels stride depth 1 scale 1 do pixel mx y1 x2 my pixels stride depth 1 scale 1 return do pixel mx my x2 y2 pixels stride depth 1 scale 1 dopixel getpixel getpixel getpixel getpixel putpixel putpixel putpixel putpixel putpixel dopixel dopixel dopixel dopixel override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height random generator set seed seed int w1 width 1 int h1 height 1 put pixel 0 0 randomrgb in pixels 0 0 out pixels width put pixel w1 0 randomrgb in pixels w1 0 out pixels width put pixel 0 h1 randomrgb in pixels 0 h1 out pixels width put pixel w1 h1 randomrgb in pixels w1 h1 out pixels width put pixel w1 2 h1 2 randomrgb in pixels w1 2 h1 2 out pixels width put pixel 0 h1 2 randomrgb in pixels 0 h1 2 out pixels width put pixel w1 h1 2 randomrgb in pixels w1 h1 2 out pixels width put pixel w1 2 0 randomrgb in pixels w1 2 0 out pixels width put pixel w1 2 h1 randomrgb in pixels w1 2 h1 out pixels width int depth 1 while do pixel 0 0 width 1 height 1 out pixels width depth 0 depth if use colormap colormap null int index 0 for int y 0 y height y for int x 0 x width x out pixels index colormap get color out pixels index 0xff 255 0f index return out pixels filterpixels inpixels transformedspace outpixels randomgenerator setseed putpixel inpixels outpixels putpixel inpixels outpixels putpixel inpixels outpixels putpixel inpixels outpixels putpixel inpixels outpixels putpixel inpixels outpixels putpixel inpixels outpixels putpixel inpixels outpixels putpixel inpixels outpixels dopixel outpixels usecolormap outpixels getcolor outpixels outpixels override public string to string return texture plasma tostring public int option sub config conf string option name string default value string int sort order boolean expert boolean force write string short desc string long desc int callback cb boolean is size this conf option name fields parse int default value string sort order expert force write short desc long desc cb is size intoption subconfig optionname defaultvaluestring sortorder forcewrite shortdesc longdesc intcallback issize optionname parseint defaultvaluestring sortorder forcewrite shortdesc longdesc issize public int option sub config conf string option name integer default value int sort order boolean expert boolean force write string short desc string long desc int callback cb boolean is size super conf option name cb sort order expert force write short desc long desc option data type number this default value default value this current value default value this is size is size intoption subconfig optionname defaultvalue sortorder forcewrite shortdesc longdesc intcallback issize optionname sortorder forcewrite shortdesc longdesc datatype defaultvalue defaultvalue currentvalue defaultvalue issize issize override protected integer parse string string val throws invalid config value exception integer x try x fields parse int val catch number format exception e throw new invalid config value exception l10n parse error val val return x parsestring invalidconfigvalueexception parseint numberformatexception invalidconfigvalueexception parseerror private string l10n string key string pattern string value return l10n get string int option key pattern value getstring intoption override protected string to string integer val return fields int to string val is size tostring inttostring issize public void write long pos byte buf if pos length if zero page null zero page new byte page page size encrypt zero page 0 zero page 0 page page size do file write length zero page while length page page size pos if pos length length page page size encrypt buf 0 cipher buf 0 buf length file write pos cipher buf zeropage zeropage pagesize zeropage zeropage pagesize zeropage pagesize pagesize cipherbuf cipherbuf public int read long pos byte buf if pos length int rc file read pos buf decrypt buf 0 buf 0 rc return rc return 0 public rc4 file string file path boolean read only boolean no flush string key file new os file file path read only no flush length file length page page size 1 set key key get bytes rc4file filepath readonly noflush osfile filepath readonly noflush pagesize setkey getbytes public rc4 file i file file string key this file file length file length page page size 1 set key key get bytes rc4file ifile pagesize setkey getbytes private void set key byte key for int counter 0 counter 256 counter init state counter byte counter int index1 0 int index2 0 for int counter 0 counter 256 counter index2 key index1 init state counter index2 0xff byte temp init state counter init state counter init state index2 init state index2 temp index1 index1 1 key length setkey initstate initstate initstate initstate initstate initstate private final void encrypt byte clear text int clear off byte cipher text int cipher off int len x y 0 system arraycopy init state 0 state 0 state length for int i 0 i len i cipher text cipher off i byte clear text clear off i state next state cleartext clearoff ciphertext cipheroff initstate ciphertext cipheroff cleartext clearoff nextstate private final void decrypt byte cipher text int cipher off byte clear text int clear off int len x y 0 system arraycopy init state 0 state 0 state length for int i 0 i len i clear text clear off i byte cipher text cipher off i state next state ciphertext cipheroff cleartext clearoff initstate cleartext clearoff ciphertext cipheroff nextstate private final int next state x x 1 0xff y y state x 0xff byte temp state x state x state y state y temp return state x state y 0xff nextstate public void close file close public boolean try lock boolean shared return file try lock shared trylock trylock public void lock boolean shared file lock shared public void unlock file unlock public void sync file sync public long length return file length private static final long serial versionuid 1l public too big exception string msg super msg serialversionuid toobigexception public final static string get server name string os name system get property os name string os ver system get property os version return os name os ver u pnp 1 0 name version getservername osname getproperty osver getproperty osname osver upnp public final static void set enable int value switch value case use only ipv6 addr host interface use only ipv6 addr true break case use only ipv4 addr host interface use only ipv4 addr true break case use loopback addr host interface use loopback addr true break case use ipv6 link local scope ssdp seti pv6 address ssdp ipv6 link local address break case use ipv6 subnet scope ssdp seti pv6 address ssdp ipv6 subnet address break case use ipv6 administrative scope ssdp seti pv6 address ssdp ipv6 administrative address break case use ipv6 site local scope ssdp seti pv6 address ssdp ipv6 site local address break case use ipv6 global scope ssdp seti pv6 address ssdp ipv6 global address break setenable use_only_ipv6_addr hostinterface use_only_ipv6_addr use_only_ipv4_addr hostinterface use_only_ipv4_addr use_loopback_addr hostinterface use_loopback_addr use_ipv6_link_local_scope setipv6address ipv6_link_local_address use_ipv6_subnet_scope setipv6address ipv6_subnet_address use_ipv6_administrative_scope setipv6address ipv6_administrative_address use_ipv6_site_local_scope setipv6address ipv6_site_local_address use_ipv6_global_scope setipv6address ipv6_global_address public final static void set disable int value switch value case use only ipv6 addr host interface use only ipv6 addr false break case use only ipv4 addr host interface use only ipv4 addr false break case use loopback addr host interface use loopback addr false break setdisable use_only_ipv6_addr hostinterface use_only_ipv6_addr use_only_ipv4_addr hostinterface use_only_ipv4_addr use_loopback_addr hostinterface use_loopback_addr public final static boolean is enabled int value switch value case use only ipv6 addr return host interface use only ipv6 addr case use only ipv4 addr return host interface use only ipv4 addr case use loopback addr return host interface use loopback addr return false isenabled use_only_ipv6_addr hostinterface use_only_ipv6_addr use_only_ipv4_addr hostinterface use_only_ipv4_addr use_loopback_addr hostinterface use_loopback_addr private static final string touuid int seed string id integer to string int seed 0xffff 16 int id len id length string uuid for int n 0 n 4 id len n uuid 0 uuid id return uuid tostring idlen idlen public static final string createuuid long time1 system current time millis long time2 long double system current time millis math random return touuid int time1 0xffff touuid int time1 32 0xa000 0xffff touuid int time2 0xffff touuid int time2 32 0xe000 0xffff currenttimemillis currenttimemillis public final static void setxml parser parser parser xml parser parser soap setxml parser parser setxmlparser xmlparser setxmlparser public final static parser getxml parser return xml parser getxmlparser xmlparser public final static void initialize dummy function to call u pnp static upnp private float fuzziness 0 1f public pointillize filter set scale 16 set randomness 0 0f pointillizefilter setscale setrandomness public void set edge thickness float edge thickness this edge thickness edge thickness setedgethickness edgethickness edgethickness edgethickness public float get edge thickness return edge thickness getedgethickness edgethickness public void set fade edges boolean fade edges this fade edges fade edges setfadeedges fadeedges fadeedges fadeedges public boolean get fade edges return fade edges getfadeedges fadeedges public void set edge color int edge color this edge color edge color setedgecolor edgecolor edgecolor edgecolor public int get edge color return edge color getedgecolor edgecolor public void set fuzziness float fuzziness this fuzziness fuzziness setfuzziness public float get fuzziness return fuzziness getfuzziness override public int get pixel int x int y int in pixels int width int height float nx m00 x m01 y float ny m10 x m11 y nx scale ny scale stretch nx 1000 ny 1000 reduce artifacts around 0 0 float f evaluate nx ny float f1 results 0 distance int srcx image math clamp int results 0 x 1000 scale 0 width 1 int srcy image math clamp int results 0 y 1000 scale 0 height 1 int v in pixels srcy width srcx if fade edges float f2 results 1 distance srcx image math clamp int results 1 x 1000 scale 0 width 1 srcy image math clamp int results 1 y 1000 scale 0 height 1 int v2 in pixels srcy width srcx v image math mix colors 0 5f f1 f2 v v2 else f 1 image math smooth step edge thickness edge thickness fuzziness f1 v image math mix colors f edge color v return v getpixel inpixels imagemath imagemath inpixels fadeedges imagemath imagemath inpixels imagemath mixcolors imagemath smoothstep edgethickness edgethickness imagemath mixcolors edgecolor override public string to string return stylize pointillize tostring public class null filter callback implements filter callback public string processuri string uri string override type return null nullfiltercallback filtercallback overridetype public string on base href string base href return null onbasehref basehref public void on text string s string type do nothing ontext public string process form string method string action return null processform public string processuri string uri string override type boolean no relative boolean inline throws comment exception return null overridetype norelative commentexception public received packet numbers int horizon ranges new linked list range lowest seq number 1 highest seq number 1 this horizon horizon receivedpacketnumbers linkedlist lowestseqnumber highestseqnumber public synchronized void clear lowest seq number 1 highest seq number 1 ranges clear lowestseqnumber highestseqnumber int end inclusive override public string to string return range start end tostring we received a packet param seq number the number of the packet return true if we stored the packet false if it is out of range of the current window public synchronized boolean got int seq number if seq number 0 throw new illegal argument exception if ranges is empty range r new range r start r end lowest seq number highest seq number seq number ranges add first r return true else list iterator range li ranges list iterator range r li next int first seq r end if seq number first seq horizon delete first item li remove r li next lowest seq number r start while true if seq number r start 1 r start if li has previous range r1 li previous if r1 end seq number 1 r start r1 start li remove else lowest seq number seq number return true if seq number r start 1 if highest seq number seq number horizon out of window don t store return false range r1 new range r1 start r1 end seq number li previous move cursor back if li has previous inserting at start lowest seq number seq number li add r1 return true if seq number r start seq number r end duh return true if seq number r end 1 r end if li has next range r1 li next if r1 start seq number 1 r end r1 end li remove else highest seq number seq number return true if seq number r end 1 if li has next this is the end of the list range r1 new range r1 start r1 end highest seq number seq number li add r1 return true r li next seqnumber seqnumber seqnumber illegalargumentexception isempty lowestseqnumber highestseqnumber seqnumber addfirst listiterator listiterator firstseq seqnumber firstseq lowestseqnumber seqnumber hasprevious seqnumber lowestseqnumber seqnumber seqnumber highestseqnumber seqnumber seqnumber hasprevious lowestseqnumber seqnumber seqnumber seqnumber seqnumber hasnext seqnumber highestseqnumber seqnumber seqnumber hasnext highestseqnumber seqnumber have we received packet seq number param seq number return public synchronized boolean contains int seq number if seq number highest seq number return false if seq number highest seq number return true if seq number lowest seq number return true if highest seq number seq number horizon return true assume we have since out of window iterator range i ranges iterator range last null for i has next range r i next if r start r end logger error this bad range r if last null r start last end logger error this this range r but last was last if r start seq number r end seq number return true return false seqnumber seqnumber seqnumber seqnumber highestseqnumber seqnumber highestseqnumber seqnumber lowestseqnumber highestseqnumber seqnumber hasnext seqnumber seqnumber return the highest packet number seen so far public synchronized int highest return highest seq number highestseqnumber override public string to string string builder sb new string builder sb append super to string sb append max synchronized this sb append highest seq number sb append min sb append lowest seq number sb append ranges iterator range i ranges iterator while i has next range r i next sb append r start sb append sb append r end if i has next sb append return sb to string tostring stringbuilder stringbuilder tostring highestseqnumber lowestseqnumber hasnext hasnext tostring int n public my key int n int k this n n this k k mykey override public boolean equals object o if o instanceof my key my key key my key o return key n n key k k else return false mykey mykey mykey override public int hash code return n 16 k hashcode public synchronized static fec codec get instance int data blocks int check blocks my key key new my key data blocks check blocks data blocks standard onionfec codec codec standard onionfec codec recently used codecs get key if codec null recently used codecs push key codec return codec codec new standard onionfec codec data blocks check blocks data blocks recently used codecs push key codec while recently used codecs size max cached codecs recently used codecs pop key return codec feccodec getinstance datablocks checkblocks mykey mykey datablocks checkblocks datablocks standardonionfeccodec standardonionfeccodec recentlyusedcodecs recentlyusedcodecs standardonionfeccodec datablocks checkblocks datablocks recentlyusedcodecs recentlyusedcodecs max_cached_codecs recentlyusedcodecs popkey public standard onionfec codec int k int n super k n loadfec logminor logger should log logger minor this standardonionfeccodec shouldlog override protected void loadfec synchronized this if fec null return fec code fec2 null if no native try fec2 new native8 code k n catch throwable t if no native system err println failed to load native fec t t print stack trace logger error this failed to load native fec t k k n n t if t instanceof unsatisfied link error no native true if fec2 null synchronized this fec fec2 else fec2 new pure code k n synchronized this fec fec2 revert to below if above causes jvm crashes worst performance but decode crashes fec new pure code k n crashes are caused by bugs which cause to use 320 128 etc n 256 k 256 feccode nonative native8code nonative printstacktrace unsatisfiedlinkerror nonative purecode purecode override public int count check blocks return n k countcheckblocks override public string to string return super to string n n k k tostring tostring override public short get algorithm return metadata splitfile onion standard getalgorithm splitfile_onion_standard public data statistics info int blocks boolean in io statistic collector collector this oid 1 1 blocks in 1 0 system err println adding this oid this in in this blocks blocks this collector collector datastatisticsinfo iostatisticcollector public string getsnmpoid system err println this oid return oid public object getsnmp data if blocks 0 long io collector get totalio return new snmp counter32 io in 1 0 else sum all fields up to blocks int res 0 int stats collector get total statistics for int i 0 i blocks i res stats i in 1 0 return new long res getsnmpdata gettotalio snmpcounter32 gettotalstatistics static final int magic 0x5ff4ac94 override public final object clone return new time decaying running average this timedecayingrunningaverage override public string to string long now system current time millis synchronized this return super to string current value cur value half life half life last report time now last report time ms ago created time now created time ms ago total reports total reports started started default value default value min min report max max report tostring currenttimemillis tostring currentvalue curvalue halflife halflife lastreporttime lastreporttime createdtime createdtime totalreports totalreports defaultvalue defaultvalue minreport maxreport public time decaying running average double default value long half life double min double max time skew detector callback callback cur value default value this default value default value started false this half life half life created time last report time system current time millis this min report min this max report max total reports 0 logdebug logger should log logger debug this if logdebug logger debug this created this new exception debug this time skew callback callback timedecayingrunningaverage defaultvalue halflife timeskewdetectorcallback curvalue defaultvalue defaultvalue defaultvalue halflife halflife createdtime lastreporttime currenttimemillis minreport maxreport totalreports shouldlog timeskewcallback public time decaying running average double default value long half life double min double max simple field set fs time skew detector callback callback cur value default value this default value default value started false this half life half life created time system current time millis this last report time 1 long warm up may skew results so lets wait for the first report this min report min this max report max total reports 0 logdebug logger should log logger debug this if logdebug logger debug this created this new exception debug if fs null started fs get boolean started false if started cur value fs get double current value cur value if cur value max report cur value min report double is nan cur value cur value default value total reports 0 created time system current time millis else total reports fs get long total reports 0 long uptime fs get long uptime 0 created time system current time millis uptime this time skew callback callback timedecayingrunningaverage defaultvalue halflife simplefieldset timeskewdetectorcallback curvalue defaultvalue defaultvalue defaultvalue halflife halflife createdtime currenttimemillis lastreporttime minreport maxreport totalreports shouldlog getboolean curvalue getdouble currentvalue curvalue curvalue maxreport curvalue minreport isnan curvalue curvalue defaultvalue totalreports createdtime currenttimemillis totalreports getlong totalreports getlong createdtime currenttimemillis timeskewcallback public time decaying running average double default value double half life double min double max data input stream dis time skew detector callback callback throws io exception int m dis read int if m magic throw new io exception invalid magic m int v dis read int if v 1 throw new io exception invalid version v cur value dis read double if double is infinite cur value double is nan cur value throw new io exception invalid weighted total cur value if cur value min cur value max throw new io exception out of range cur value cur value started dis read boolean long prior experience time dis read long this half life half life this min report min this max report max this default value default value logdebug logger should log logger debug this last report time 1 created time system current time millis prior experience time total reports dis read long this time skew callback callback timedecayingrunningaverage defaultvalue halflife datainputstream timeskewdetectorcallback ioexception readint ioexception readint ioexception curvalue readdouble isinfinite curvalue isnan curvalue ioexception weightedtotal curvalue curvalue curvalue ioexception curvalue curvalue readboolean priorexperiencetime readlong halflife halflife minreport maxreport defaultvalue defaultvalue shouldlog lastreporttime createdtime currenttimemillis priorexperiencetime totalreports readlong timeskewcallback public time decaying running average time decaying running average a this created time a created time this default value a default value this half life a half life this last report time a last report time this max report a max report this min report a min report this started a started this total reports a total reports this cur value a cur value this time skew callback a time skew callback timedecayingrunningaverage timedecayingrunningaverage createdtime createdtime defaultvalue defaultvalue halflife halflife lastreporttime lastreporttime maxreport maxreport minreport minreport totalreports totalreports curvalue curvalue timeskewcallback timeskewcallback public synchronized double current value return cur value currentvalue curvalue public void report double d synchronized this must synchronize first to achieve serialization long now system current time millis if d min report logger error this impossible d on this new exception error return if d max report logger error this impossible d on this new exception error return if double is infinite d double is nan d logger error this reported infinity or nan to this d new exception error return total reports if started cur value d started true if logdebug logger debug this reported d on this when just started else if last report time 1 might be just serialized in long this interval now last report time long uptime now created time if this interval 0 logger error this clock reporting went back in time ignoring report now was last report time back this interval ms last report time now if time skew callback null time skew callback set time skew detected user alert return double this half life half life if uptime 0 logger error this clock uptime went back in time ignoring report now was created time back uptime ms if time skew callback null time skew callback set time skew detected user alert return disable sensitivity hack excessive sensitivity at start isn t necessarily a good thing in particular it makes the average inconsistent 20 reports of 0 at 1s intervals have a different effect to 10 reports of 0 at 2s intervals also it increases the impact of startup spikes which then take a long time to recover from else double one fourth of uptime uptime 4d if one fourth of uptime this half life this half life one fourth of uptime if this half life 0 this half life 1 double change factor math pow 0 5 this interval this half life double old cur value cur value cur value cur value change factor close to 1 0 if short interval close to 0 0 if long interval 1 0 change factor d fixme remove when stop getting reports of wierd output values if cur value min report cur value max report logger error this cur value cur value was old cur value out of range cur value old cur value if logdebug logger debug this reported d on this this interval this interval half life half life uptime uptime this half life this half life change factor change factor old cur value old cur value current value current value this interval this interval this half life this half life uptime uptime change factor change factor last report time now currenttimemillis minreport maxreport isinfinite isnan totalreports curvalue lastreporttime thisinterval lastreporttime createdtime thisinterval lastreporttime thisinterval lastreporttime timeskewcallback timeskewcallback settimeskewdetecteduseralert thishalflife halflife createdtime timeskewcallback timeskewcallback settimeskewdetecteduseralert onefourthofuptime onefourthofuptime thishalflife thishalflife onefourthofuptime thishalflife thishalflife changefactor thisinterval thishalflife oldcurvalue curvalue curvalue curvalue changefactor changefactor curvalue minreport curvalue maxreport curvalue curvalue oldcurvalue curvalue oldcurvalue thisinterval thisinterval halflife halflife thishalflife thishalflife changefactor changefactor oldcurvalue oldcurvalue currentvalue currentvalue thisinterval thisinterval thishalflife thishalflife changefactor changefactor lastreporttime public void report long d report double d public double value if reported double r throw new unsupported operation exception valueifreported unsupportedoperationexception public void write data to data output stream out throws io exception long now system current time millis synchronized this out write int magic out write int 1 out write double cur value out write boolean started out write long total reports out write long now created time writedatato dataoutputstream ioexception currenttimemillis writeint writeint writedouble curvalue writeboolean writelong totalreports writelong createdtime public int get data length return 4 4 8 8 1 8 8 getdatalength public synchronized long count reports return total reports countreports totalreports public synchronized long last report time return last report time lastreporttime lastreporttime public synchronized simple field set export field set boolean short lived simple field set fs new simple field set short lived fs put single type time decaying running average fs put current value cur value fs put started started fs put total reports total reports fs put uptime system current time millis created time return fs simplefieldset exportfieldset shortlived simplefieldset simplefieldset shortlived putsingle timedecayingrunningaverage currentvalue curvalue totalreports totalreports currenttimemillis createdtime private static final long serial versionuid 19006235321212642l public version parse exception string msg super msg serialversionuid versionparseexception static string get status string int status switch status case not finished return not finished case success return success case route not found return route not found case data not found return data not found case transfer failed return transfer failed case get offer transfer failed return get offer transfer failed case verify failure return verify failure case get offer verify failure return get offer verify failure case timed out return timed out case generated rejected overload return generated rejected overload case internal error return internal error case recently failed return recently failed default return unknown status code status getstatusstring not_finished route_not_found data_not_found transfer_failed get_offer_transfer_failed verify_failure get_offer_verify_failure timed_out generated_rejected_overload internal_error recently_failed string get status string return get status string get status getstatusstring getstatusstring getstatus static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog override public string to string return super to string for uid tostring tostring request sender constructor param key the key to request its public key should have been looked up already request sender will not look it up public request sender key key dsa public key pub key short htl long uid node n peer node source boolean offers only if key get routing key null throw new null pointer exception start time system current time millis this key key this pub key pub key this htl htl this uid uid this node n this source source this try offers only offers only target key to normalized double node add request sender key htl this requestsender requestsender requestsender dsapublickey pubkey peernode offersonly getroutingkey nullpointerexception starttime currenttimemillis pubkey pubkey tryoffersonly offersonly tonormalizeddouble addrequestsender public void start node executor execute this request sender for uid uid on node get darknet port number requestsender getdarknetportnumber public void run short orightl htl try real run catch throwable t logger error this caught t t finish internal error null false finally if logminor logger minor this leaving request sender run for uid node remove request sender key orightl this realrun internal_error requestsender removerequestsender private void real run freenet support logger os thread logpid this if key instanceof nodessk pub key null pub key nodessk key get pub key first ask any nodes that have offered the data offer list offers node failure table get offers key if offers null while true fetches valid offers then expired ones expired offers don t count towards failures but they re still worth trying block offer offer offers get first offer if offer null if logminor logger minor this no more offers break peer node pn offer get peer node if pn null offers delete last offer if logminor logger minor this null offer continue if pn get bootid offer bootid offers delete last offer if logminor logger minor this restarted node continue message msg dmt createfnp get offered key key offer authenticator pub key null uid try pn send async msg null this catch not connected exception e2 if logminor logger minor this disconnected pn getting offer for key offers delete last offer continue message filter mfro message filter create set source pn set field dmt uid uid set timeout get offer timeout set type dmt fnp rejected overload message filter mf get invalid message filter create set source pn set field dmt uid uid set timeout get offer timeout set type dmt fnp get offered key invalid wait for a response if key instanceof nodechk headers first then block transfer message filter mfdf message filter create set source pn set field dmt uid uid set timeout get offer timeout set type dmt fnpchk data found message reply try reply node usm wait for mfdf or mfro or mf get invalid this catch disconnected exception e2 if logminor logger minor this disconnected pn getting offer for key offers delete last offer continue if reply null we gave it a chance don t give it another offers delete last offer continue else if reply get spec dmt fnp rejected overload non fatal keep it if logminor logger minor this node pn rejected fnp get offered key for key expired offer is expired offers keep last offer continue else if reply get spec dmt fnp get offered key invalid fatal delete it if logminor logger minor this node pn rejected fnp get offered key as invalid with reason reply get short dmt reason offers delete last offer continue else if reply get spec dmt fnpchk data found headers short buffer reply get object dmt block headers get data receive the data fixme validate headers node add transferring sender nodechk key this try prb new partially received block node packets in block node packet size synchronized this notify all firechk transfer begins block receiver br new block receiver node usm pn uid prb this node get ticker true try if logminor logger minor this receiving data byte data br receive pn transfer success if logminor logger minor this received data received data try verify and commit data catch key verify exception e1 logger normal this got data but verify failed e1 e1 finish get offer verify failure pn true offers delete last offer return finish success pn true node node stats successful block receive return catch retrieval exception e if e get reason retrieval exception sender disconnected logger normal this transfer failed disconnect e e else a certain number of these are normal it s better to track them through statistics than call attention to them in the logs logger normal this transfer for offer failed e get reason retrieval exception get err string e get reason e from pn e finish get offer transfer failed pn true backoff here anyway the node really ought to have it pn transfer failed request sender get offered transfer failed offers delete last offer node node stats failed block receive false false false return finally node remove transferring sender nodechk key this else data possibly followed by pubkey message filter mf altdf message filter create set source pn set field dmt uid uid set timeout get offer timeout set type dmt fnpssk data found headers message reply try reply node usm wait for mfro or mf get invalid or mf altdf this catch disconnected exception e if logminor logger minor this disconnected pn getting offer for key offers delete last offer continue if reply null offers delete last offer continue else if reply get spec dmt fnp rejected overload non fatal keep it if logminor logger minor this node pn rejected fnp get offered key for key expired offer is expired offers keep last offer continue else if reply get spec dmt fnp get offered key invalid fatal delete it if logminor logger minor this node pn rejected fnp get offered key as invalid with reason reply get short dmt reason offers delete last offer continue else if reply get spec dmt fnpssk data found headers headers short buffer reply get object dmt block headers get data wait for the data message filter mf data message filter create set source pn set field dmt uid uid set timeout get offer timeout set type dmt fnpssk data found data message data message try data message node usm wait for mf data this catch disconnected exception e if logminor logger minor this disconnected pn getting data for offer for key offers delete last offer continue if data message null logger error this got headers but not data from pn for offer for key offers delete last offer continue ssk data short buffer data message get object dmt data get data if pub key null message filter mfpk message filter create set source pn set field dmt uid uid set timeout get offer timeout set type dmt fnpssk pub key message pk try pk node usm wait for mfpk this catch disconnected exception e if logminor logger minor this disconnected pn getting pubkey for offer for key offers delete last offer continue if pk null logger error this got data but not pubkey from pn for offer for key offers delete last offer continue try pub key dsa public key create short buffer pk get object dmt pubkey as bytes get data catch crypt format exception e logger error this bogus pubkey from pn for offer for key e e offers delete last offer continue try nodessk key set pub key pub key catch ssk verify exception e logger error this bogus ssk data from pn for offer for key e e offers delete last offer continue if finishssk from get offer pn if logminor logger minor this successfully fetched ssk from offer from pn for key return else offers delete last offer continue rejected overload is possible but we need to include it in the statistics we don t remove the offer in that case otherwise we do even if it fails fnp get offered key invalid is also possible if try offers only if logminor logger minor this tried all offers not doing a regular request for key finish data not found null true fixme need a different error code return int route attempts 0 int reject overloads 0 hash set peer node nodes routed to new hash set peer node peer node next null while true if we haven t routed to any node yet decrement according to the source if we have decrement according to the node which just failed be realrun osthread pubkey pubkey getpubkey offerlist failuretable getoffers blockoffer getfirstoffer peernode getpeernode deletelastoffer getbootid deletelastoffer createfnpgetofferedkey pubkey sendasync notconnectedexception deletelastoffer messagefilter messagefilter setsource setfield settimeout get_offer_timeout settype fnprejectedoverload messagefilter mfgetinvalid messagefilter setsource setfield settimeout get_offer_timeout settype fnpgetofferedkeyinvalid messagefilter messagefilter setsource setfield settimeout get_offer_timeout settype fnpchkdatafound waitfor mfgetinvalid disconnectedexception deletelastoffer deletelastoffer getspec fnprejectedoverload fnpgetofferedkey isexpired keeplastoffer getspec fnpgetofferedkeyinvalid fnpgetofferedkey getshort deletelastoffer getspec fnpchkdatafound shortbuffer getobject block_headers getdata addtransferringsender partiallyreceivedblock packets_in_block packet_size notifyall firechktransferbegins blockreceiver blockreceiver getticker transfersuccess verifyandcommit keyverifyexception get_offer_verify_failure deletelastoffer nodestats successfulblockreceive retrievalexception getreason retrievalexception sender_disconnected getreason retrievalexception geterrstring getreason get_offer_transfer_failed transferfailed requestsendergetofferedtransferfailed deletelastoffer nodestats failedblockreceive removetransferringsender messagefilter mfaltdf messagefilter setsource setfield settimeout get_offer_timeout settype fnpsskdatafoundheaders waitfor mfgetinvalid mfaltdf disconnectedexception deletelastoffer deletelastoffer getspec fnprejectedoverload fnpgetofferedkey isexpired keeplastoffer getspec fnpgetofferedkeyinvalid fnpgetofferedkey getshort deletelastoffer getspec fnpsskdatafoundheaders shortbuffer getobject block_headers getdata messagefilter mfdata messagefilter setsource setfield settimeout get_offer_timeout settype fnpsskdatafounddata datamessage datamessage waitfor mfdata disconnectedexception deletelastoffer datamessage deletelastoffer sskdata shortbuffer datamessage getobject getdata pubkey messagefilter messagefilter setsource setfield settimeout get_offer_timeout settype fnpsskpubkey waitfor disconnectedexception deletelastoffer deletelastoffer pubkey dsapublickey shortbuffer getobject pubkey_as_bytes getdata cryptformatexception deletelastoffer setpubkey pubkey sskverifyexception deletelastoffer finishsskfromgetoffer deletelastoffer rejectedoverload fnpgetofferedkeyinvalid tryoffersonly data_not_found routeattempts rejectoverloads hashset peernode nodesroutedto hashset peernode peernode public void run synchronized request sender this if transferring from from return make turtle requestsender transferringfrom maketurtle protected void make turtle synchronized this if try turtle return try turtle true node make turtle request sender this maketurtle tryturtle tryturtle maketurtle requestsender finish fetching an ssk we must have received the data the headers and the pubkey by this point param next the node we received the data from private void finishssk peer node next try block new ssk block ssk data headers nodessk key false node store shallow block if node random next int random reinsert interval 0 node queue random reinsert block finish success next false catch ssk verify exception e logger error this failed to verify e from next e finish verify failure next false return catch key collision exception e logger normal this collision on this finish success next false peernode sskblock sskdata storeshallow nextint random_reinsert_interval queuerandomreinsert sskverifyexception verify_failure keycollisionexception finish fetching an ssk we must have received the data the headers and the pubkey by this point param next the node we received the data from return true if the request has completed false if we need to look elsewhere private boolean finishssk from get offer peer node next try block new ssk block ssk data headers nodessk key false node store shallow block if node random next int random reinsert interval 0 node queue random reinsert block finish success next true return true catch ssk verify exception e logger error this failed to verify from get offer e from next e return false catch key collision exception e logger normal this collision from get offer on this finish success next true return false finishsskfromgetoffer peernode sskblock sskdata storeshallow nextint random_reinsert_interval queuerandomreinsert sskverifyexception keycollisionexception private message create data request if key instanceof nodechk return dmt createfnpchk data request uid htl nodechk key else if key instanceof nodessk return dmt createfnpssk data request uid htl nodessk key pub key null else throw new illegal state exception unknown keytype key createdatarequest createfnpchkdatarequest createfnpsskdatarequest pubkey illegalstateexception private void verify and commit byte data throws key verify exception if key instanceof nodechk chk block block new chk block data headers nodechk key cache only in the cache not the store the reason for this is that requests don t go to the full distance and therefore pollute the store simulations it is best to only include data from requests which go all the way i e inserts node store shallow block if node random next int random reinsert interval 0 node queue random reinsert block else if key instanceof nodessk try node store shallow new ssk block data headers nodessk key false catch key collision exception e logger normal this collision on this verifyandcommit keyverifyexception chkblock chkblock storeshallow nextint random_reinsert_interval queuerandomreinsert storeshallow sskblock keycollisionexception forward rejected overload to the request originator private void forward rejected overload synchronized this if has forwarded rejected overload return has forwarded rejected overload true notify all fire received reject overload rejectedoverload forwardrejectedoverload hasforwardedrejectedoverload hasforwardedrejectedoverload notifyall firereceivedrejectoverload public partially received block getprb return prb partiallyreceivedblock public boolean transfer started return prb null transferstarted wait until either the transfer has started we receive a rejected overload or we get a terminal status code must not return until we are finished cannot timeout because the caller will unlock the uid param mask bitmask indicating what not to wait for i e the situation when this function exited last time see wait constants above bits can also be set true even though they were not valid to indicate that the caller doesn t care about that bit if zero function will throw an illegal argument exception return bitmask indicating present situation can be fed back to this function if nonzero public synchronized short wait until status change short mask if mask wait all throw new illegal argument exception cannot ignore all while true long deadline system current time millis 300 1000 while true short current mask if any bits are set already we ignore those states if has forwarded rejected overload current wait rejected overload if prb null current wait transferring data if status not finished sent abort downstream transfers current wait finished if current mask return current try long now system current time millis if now deadline logger error this waited more than 5 minutes for status change on this current current break wait deadline now catch interrupted exception e ignore rejectedoverload wait_ illegalargumentexception waituntilstatuschange wait_all illegalargumentexception currenttimemillis hasforwardedrejectedoverload wait_rejected_overload wait_transferring_data not_finished sentabortdownstreamtransfers wait_finished currenttimemillis interruptedexception private void finish int code peer node next boolean from offered key if logminor logger minor this finish code boolean turtle synchronized this status code notify all turtle turtle mode if status success success from next if status success if key instanceof nodechk transfer time 0 logminor long time taken system current time millis start time synchronized avg time taken if turtle avg time taken turtle report time taken else avg time taken report time taken avg time taken transfer report transfer time if turtle if logminor logger minor this successful chk turtle request took time taken average avg time taken turtle else if logminor logger minor this successful chk request took time taken average avg time taken if logminor logger minor this successful chk request transfer transfer time average avg time taken transfer if logminor logger minor this search phase median avg time taken current value avg time taken transfer current value ms mean avg time taken mean value avg time taken transfer mean value ms if next null next on success false key instanceof nodessk fixme should this be called when from offered key node node stats request completed true source null key instanceof nodessk note because of the requesthandler implementation this will block and wait for downstream transfers on a chk the opennet stuff introduces a delay of it s own if we don t get the expected message fire request sender finished code if from offered key if key instanceof nodechk next null next is opennet node pass opennet refs through darknet finish opennet next else finish opennet null next else node node stats request completed false source null key instanceof nodessk fire request sender finished code synchronized this opennet finished true notify all peernode fromofferedkey notifyall turtlemode successfrom transfertime timetaken currenttimemillis starttime avgtimetaken avgtimetakenturtle timetaken avgtimetaken timetaken avgtimetakentransfer transfertime timetaken avgtimetakenturtle timetaken avgtimetaken transfertime avgtimetakentransfer avgtimetaken currentvalue avgtimetakentransfer currentvalue avgtimetaken meanvalue avgtimetakentransfer meanvalue onsuccess fromofferedkey nodestats requestcompleted firerequestsenderfinished fromofferedkey isopennet passopennetrefsthroughdarknet finishopennet finishopennetnull nodestats requestcompleted firerequestsenderfinished opennetfinished notifyall wait for the opennet completion message and discard it private void finish opennet null peer node next message filter mf message filter create set source next set field dmt uid uid set timeout opennet timeout set type dmt fnp opennet completed ack try node usm add async filter mf new null async message filter callback catch disconnected exception e fine by me fixme support new format path folding finishopennetnull peernode messagefilter messagefilter setsource setfield settimeout opennet_timeout settype fnpopennetcompletedack addasyncfilter nullasyncmessagefiltercallback disconnectedexception do path folding maybe wait for either a completed ack or a connect destination if the former exit if we want a connection reply with a connect reply otherwise send a connect rejected and exit add the peer private void finish opennet peer node next opennet manager om try om node get opennet if om null return nothing to do byte noderef om wait for opennet noderef false next uid this if noderef null return simple field set ref om validate noderef noderef 0 noderef length next false if ref null return if node add new opennet node ref null if we don t want it let somebody else have it synchronized this opennet noderef noderef request handler will send a noderef back up eventually return else opennet noderef null i e we want the noderef so we won t pass it further down logger normal this added opennet noderef in this from next we want the node send our reference om send opennet ref true uid next om crypto my compressed full ref this catch fs parse exception e logger error this could not parse opennet noderef for this from next e return catch peer parse exception e logger error this could not parse opennet noderef for this from next e return catch reference signature verification exception e logger error this bad signature on opennet noderef for this from next e e return catch not connected exception e hmmm let the lru deal with it if logminor logger minor this not connected sending connect reply on this to next finally synchronized this opennet finished true notify all completedack connectdestination connectreply connectrejected finishopennet peernode opennetmanager getopennet waitforopennetnoderef simplefieldset validatenoderef addnewopennetnode opennetnoderef requesthandler opennetnoderef sendopennetref mycompressedfullref fsparseexception peerparseexception referencesignatureverificationexception notconnectedexception connectreply opennetfinished notifyall public byte wait for opennet noderef synchronized this while true if opennet finished only one request handler may take the noderef byte ref opennet noderef opennet noderef null return ref try wait opennet timeout catch interrupted exception e ignore continue return null waitforopennetnoderef opennetfinished requesthandler opennetnoderef opennetnoderef opennet_timeout interruptedexception public peer node success from return success from peernode successfrom successfrom public synchronized peer node routed last return last node peernode routedlast lastnode public byte get headers return headers getheaders public int get status return status getstatus public short gethtl return htl final byte getssk data return ssk data getsskdata sskdata public ssk block getssk block return block sskblock getsskblock public void sent bytes int x synchronized total bytes sync total bytes sent x node node stats request sent bytes key instanceof nodessk x sentbytes totalbytessync totalbytessent nodestats requestsentbytes public int get total sent bytes synchronized total bytes sync return total bytes sent gettotalsentbytes totalbytessync totalbytessent public void received bytes int x synchronized total bytes sync total bytes received x node node stats request received bytes key instanceof nodessk x receivedbytes totalbytessync totalbytesreceived nodestats requestreceivedbytes public int get total received bytes synchronized total bytes sync return total bytes received gettotalreceivedbytes totalbytessync totalbytesreceived synchronized boolean has forwarded return has forwarded hasforwarded hasforwarded public void sent payload int x node sent payload x node node stats request sent bytes key instanceof nodessk x sentpayload sentpayload nodestats requestsentbytes private int recently failed time left synchronized int get recently failed time left return recently failed time left recentlyfailedtimeleft getrecentlyfailedtimeleft recentlyfailedtimeleft public boolean is local request search return source null islocalrequestsearch all these methods should return quickly interface listener should return quickly allocate a thread if it needs to block etc void on received reject overload onreceivedrejectoverload should return quickly allocate a thread if it needs to block etc void on received reject overload should return quickly allocate a thread if it needs to block etc void onchk transfer begins onreceivedrejectoverload onchktransferbegins should return quickly allocate a thread if it needs to block etc void onchk transfer begins should return quickly allocate a thread if it needs to block etc void on request sender finished int status onchktransferbegins onrequestsenderfinished should return quickly allocate a thread if it needs to block etc void on request sender finished int status abort downstream transfers not necessarily upstream ones so not via the prb should return quickly allocate a thread if it needs to block etc void on abort downstream transfers int reason string desc onrequestsenderfinished onabortdownstreamtransfers public void add listener listener l only call here if we ve already called for the other listeners therefore the callbacks will only be called once boolean reject false boolean transfer false boolean sent finished boolean sent transfer cancel false int status synchronized this synchronized listeners sent transfer cancel sent abort downstream transfers if sent transfer cancel listeners add l reject sent received reject overload transfer sentchk transfer begins sent finished sent request sender finished reject reject has forwarded rejected overload transfer transfer transfer started status this status if reject l on received reject overload if transfer l onchk transfer begins if sent transfer cancel l on abort downstream transfers abort downstream transfers reason abort downstream transfers desc if status not finished sent finished l on request sender finished status addlistener sentfinished senttransfercancel senttransfercancel sentabortdownstreamtransfers senttransfercancel sentreceivedrejectoverload sentchktransferbegins sentfinished sentrequestsenderfinished hasforwardedrejectedoverload transferstarted onreceivedrejectoverload onchktransferbegins senttransfercancel onabortdownstreamtransfers abortdownstreamtransfersreason abortdownstreamtransfersdesc not_finished sentfinished onrequestsenderfinished private void fire received reject overload synchronized listeners if sent received reject overload return sent received reject overload true for listener l listeners try l on received reject overload catch throwable t logger error this caught t t firereceivedrejectoverload sentreceivedrejectoverload sentreceivedrejectoverload onreceivedrejectoverload private void firechk transfer begins synchronized listeners sentchk transfer begins true for listener l listeners try l onchk transfer begins catch throwable t logger error this caught t t firechktransferbegins sentchktransferbegins onchktransferbegins private void fire request sender finished int status synchronized listeners sent request sender finished true for listener l listeners try l on request sender finished status catch throwable t logger error this caught t t firerequestsenderfinished sentrequestsenderfinished onrequestsenderfinished private void send abort downstream transfers int reason string desc synchronized listeners abort downstream transfers reason reason abort downstream transfers desc desc sent abort downstream transfers true for listener l listeners try l on abort downstream transfers reason desc l on request sender finished transfer failed catch throwable t logger error this caught t t listeners clear synchronized this notify all sendabortdownstreamtransfers abortdownstreamtransfersreason abortdownstreamtransfersdesc sentabortdownstreamtransfers onabortdownstreamtransfers onrequestsenderfinished transfer_failed notifyall public int get priority return native thread high priority getpriority nativethread high_priority public void set turtle synchronized this this turtle mode true send abort downstream transfers retrieval exception gone to turtle mode turtling node get ticker queue timed job new runnable public void run peer node from synchronized request sender this if sent backoff turtle return sent backoff turtle true from transferring from if from null return from transfer failed turtled transfer 30 1000 setturtle turtlemode sendabortdownstreamtransfers retrievalexception gone_to_turtle_mode getticker queuetimedjob peernode requestsender sentbackoffturtle sentbackoffturtle transferringfrom transferfailed turtledtransfer public void run peer node from synchronized request sender this if sent backoff turtle return sent backoff turtle true from transferring from if from null return from transfer failed turtled transfer peernode requestsender sentbackoffturtle sentbackoffturtle transferringfrom transferfailed turtledtransfer public peer node transferring from return transferring from peernode transferringfrom transferringfrom public void kill turtle prb abort retrieval exception turtle killed too many turtles already have turtles for this key node failure table on final failure key transferring from htl failure table reject time source killturtle retrievalexception turtle_killed failuretable onfinalfailure transferringfrom failuretable reject_time public boolean aborted downstream transfers return sent abort downstream transfers aborteddownstreamtransfers sentabortdownstreamtransfers private static final long serial versionuid 1 public chk decode exception super serialversionuid chkdecodeexception public chk decode exception string message super message chkdecodeexception public chk decode exception string message throwable cause super message cause chkdecodeexception public chk decode exception throwable cause super cause chkdecodeexception private string name header string name this name name public string get name return name getname private final int message num public freetalknntp article message message this message message message num 0 messagenum freetalknntparticle messagenum public freetalknntp article message message int message num this message message this message num message num freetalknntparticle messagenum messagenum messagenum get the ft message object associated with this group public message get message return message ftmessage getmessage get the message number or 0 if none was set public int get message num return message num getmessagenum messagenum get the contents of the named header if the header is not present return the empty string public string get header by name string name for header hdr header values if name equals ignore case hdr get name return get header hdr return getheaderbyname equalsignorecase getname getheader wrap header contents onto multiple lines wrapping is done so as to limit the number of bytes of utf 8 on a single line private static string wrap header string name string text int soft limit int hard limit string builder result new string builder int line start word pos width i line start 0 width name length 2 while line start text length word pos line start for i line start i text length i int c text code point at i int cwidth if character is space char c word pos i if c 0x80 cwidth 1 else if c 0x800 cwidth 2 else if c 0x10000 cwidth 3 else cwidth 4 i if width cwidth soft limit word pos line start break else if width cwidth hard limit break else width cwidth if i text length word pos line start result append text substring line start i line start i else result append text substring line start word pos line start word pos 1 if line start text length result append n width 1 return result to string wrapheader softlimit hardlimit stringbuilder stringbuilder linestart wordpos linestart linestart wordpos linestart linestart codepointat isspacechar wordpos softlimit wordpos linestart hardlimit wordpos linestart linestart linestart linestart wordpos linestart wordpos linestart tostring get the contents of the given header the header is not wrapped it may be arbitrarily long but will not contain any line feeds tabs or other control characters public string get header header hdr switch hdr case from return message get author get freetalk address case subject return message get title case newsgroups board boards message get boards string builder builder new string builder builder append freetalknntp group board to group name boards 0 get name for int i 1 i boards length i builder append builder append freetalknntp group board to group name boards i get name return builder to string case followup to board board message get reply to board if board null return else return freetalknntp group board to group name board get name case date synchronized m date format return m date format format message get date case message id return message getid case references fixme it would be good for the message to include a list of earlier messages in the thread in case the parent message can t be retrieved if message is thread return else try return message get parentid catch no such message exception e logger error this should not happen e return case path return freetalk wot context case content type return text plain charset utf 8 default return getheader getauthor getfreetalkaddress gettitle getboards stringbuilder stringbuilder freetalknntpgroup boardtogroupname getname freetalknntpgroup boardtogroupname getname tostring followup_to getreplytoboard freetalknntpgroup boardtogroupname getname mdateformat mdateformat getdate message_id isthread getparentid nosuchmessageexception wot_context content_type get the complete list of headers public string get head string builder builder new string builder synchronized message for header hdr header values string text get header hdr if text equals builder append hdr get name builder append builder append wrap header hdr get name text 72 998 builder append n return builder to string gethead stringbuilder stringbuilder getheader getname wrapheader getname tostring get the message body public string get body return message get text getbody gettext get the number of lines in the article s body public long get body line count string body lines end of line pattern split get body return body lines length getbodylinecount bodylines endoflinepattern getbody bodylines get number of bytes to encode string as utf 8 private long byte countutf8 string s gah there must be a simpler way to do this try byte b s get bytes utf 8 return b length catch unsupported encoding exception e return 0 bytecountutf8 getbytes unsupportedencodingexception get the total size of the article public long get byte count string head lines end of line pattern split get head string body lines end of line pattern split get body long count 2 int i for i 0 i head lines length i count byte countutf8 head lines i 2 for i 0 i body lines length i count byte countutf8 body lines i 2 return count getbytecount headlines endoflinepattern gethead bodylines endoflinepattern getbody headlines bytecountutf8 headlines bodylines bytecountutf8 bodylines private boolean is terminated public fcp interface final freetalk my freetalk m freetalk my freetalk is terminated false isterminated fcpinterface myfreetalk mfreetalk myfreetalk isterminated public void terminate is terminated true isterminated param replysender interface to send a reply param params parameters passed in can be null param data a bucket of data passed in can be null param access 0 direct call plugin to plugin 1 fcp restricted access 2 fcp full access public void handle final plugin reply sender replysender final simple field set params final bucket data final int accesstype try if is terminated replysender send error messagefcp params get message new exception plugin is terminated if params null throw new exception empty message received final string message params get message if message null message trim length 0 throw new exception specified message is empty if message equals list boards handle list boards replysender params else if message equals list own identities handle list own identities replysender params else if message equals list known identities handle list known identities replysender params else if message equals list threads handle list threads replysender params else if message equals list thread messages handle list thread messages replysender params else if message equals list messages handle list messages replysender params else if message equals get message handle get message replysender params else if message equals put message handle put message replysender params data else if message equals create board handle create board replysender params else if message equals create own identity handle create own identity replysender params else if message equals status handle status replysender params else if message equals ping handle ping replysender params else throw new exception unknown message message catch final exception e logger error this e to string try if e instanceof plugin not found exception replysender send error messagefcp params get message e catch final plugin not found exception e1 logger normal this connection to request sender lost e1 pluginreplysender simplefieldset isterminated errormessagefcp listboards handlelistboards listownidentities handlelistownidentities listknownidentities handlelistknownidentities listthreads handlelistthreads listthreadmessages handlelistthreadmessages listmessages handlelistmessages getmessage handlegetmessage putmessage handleputmessage createboard handlecreateboard createownidentity handlecreateownidentity handlestatus handleping tostring pluginnotfoundexception errormessagefcp pluginnotfoundexception handle list boards command send a number of board messages and finally an end list boards message format of request message list boards format of reply message board name name message count 123 first seen date utc millis optional latest message date utc millis optional private void handle list boards final plugin reply sender replysender final simple field set params throws plugin not found exception synchronized m freetalk get message manager final iterator board boards m freetalk get message manager board iterator while boards has next final board board boards next final simple field set sfs new simple field set true sfs put overwrite message board sfs put overwrite name board get name sfs put message count board message count if board get first seen date null sfs put first seen date board get first seen date get time if board get latest message date null sfs put latest message date board get latest message date get time replysender send sfs final simple field set sfs new simple field set true sfs put overwrite message end list boards replysender send sfs listboards endlistboards listboards messagecount firstseendate utcmillis latestmessagedate utcmillis handlelistboards pluginreplysender simplefieldset pluginnotfoundexception mfreetalk getmessagemanager mfreetalk getmessagemanager boarditerator hasnext simplefieldset simplefieldset putoverwrite putoverwrite getname messagecount messagecount getfirstseendate firstseendate getfirstseendate gettime getlatestmessagedate latestmessagedate getlatestmessagedate gettime simplefieldset simplefieldset putoverwrite endlistboards handle list threads command send a number of known identity messages and finally an end list known identities message format of request message list threads board name abc own identityuid uid format of reply message message thread id id title title author freetalk addr date utc millis reply count 123 fetch date utc millis is thread true false all returned messages should be thread root messages private void handle list threads final plugin reply sender replysender final simple field set params throws plugin not found exception invalid parameter exception no such board exception no such identity exception final string board name params get board name if board name null throw new invalid parameter exception boardname parameter not specified final string own identityuid params get own identityuid if own identityuid null throw new invalid parameter exception own identityuid parameter not specified final ft own identity own identity m freetalk get identity manager get own identity own identityuid throws exception when not found final board board m freetalk get message manager get board by name board name throws exception when not found synchronized board fixme is this enough synchronization or should we lock the message manager final iterator message reference threads board thread iterator own identity while threads has next final message thread threads next get message final simple field set sfs new simple field set true sfs put overwrite message message thread sfs put overwrite id thread getid sfs put overwrite title thread get title sfs put overwrite author thread get author get freetalk address sfs put date thread get date get time sfs put reply count board thread reply count own identity thread sfs put fetch date thread get fetch date get time sfs put is thread thread is thread replysender send sfs final simple field set sfs new simple field set true sfs put overwrite message end list threads replysender send sfs listthreads knownidentity endlistknownidentities listthreads boardname ownidentityuid messagethread freetalkaddr utcmillis replycount fetchdate utcmillis isthread handlelistthreads pluginreplysender simplefieldset pluginnotfoundexception invalidparameterexception nosuchboardexception nosuchidentityexception boardname boardname boardname invalidparameterexception ownidentityuid ownidentityuid ownidentityuid invalidparameterexception ownidentityuid ftownidentity ownidentity mfreetalk getidentitymanager getownidentity ownidentityuid mfreetalk getmessagemanager getboardbyname boardname messagereference threaditerator ownidentity hasnext getmessage simplefieldset simplefieldset putoverwrite messagethread putoverwrite putoverwrite gettitle putoverwrite getauthor getfreetalkaddress getdate gettime replycount threadreplycount ownidentity fetchdate getfetchdate gettime isthread isthread simplefieldset simplefieldset putoverwrite endlistthreads handle list messages command send a number of message messages and finally an end list messages message format of request message list messages board name abc only one sort by messagexxx is allowed to be true sort by message index ascending true false optional default is false sort by message date ascending true false optional default is false only one minimum messagexxx constraint is allowed minimum message index 123 optional datatype int default is 0 minimum message date utc millis optional datatype long default is 0 include message text true false optional default is false format of reply see send single message private void handle list messages final plugin reply sender replysender final simple field set params throws plugin not found exception invalid parameter exception no such board exception no such message exception unsupported encoding exception final string board name params get board name if board name null throw new invalid parameter exception boardname parameter not specified final boolean sort by message index ascending boolean parse boolean params get sort by message index ascending final boolean sort by message date ascending boolean parse boolean params get sort by message date ascending if sort by message index ascending sort by message date ascending throw new invalid parameter exception only one of sort by message index ascending and sort by message date ascending is allowed to be true int minimum message index try minimum message index integer parse int params get minimum message index catch final number format exception e minimum message index 0 long minimum message date try minimum message date long parse long params get minimum message date catch final number format exception e minimum message date 0 if minimum message index 0 minimum message date 0 throw new invalid parameter exception minimum message index and minimum message date must not be specified together final boolean include message text boolean parse boolean params get include message text final board board m freetalk get message manager get board by name board name throws exception when not found synchronized board fixme is this enough synchronization or should we lock the message manager final list message reference message ref list if minimum message index 0 message ref list board get messages by minimum index minimum message index sort by message index ascending sort by message date ascending else if minimum message date 0 message ref list board get messages by minimum date minimum message date sort by message index ascending sort by message date ascending else message ref list board get all messages sort by message index ascending send all messages for final message reference reference message ref list final message msg reference get message final int message index board get message index msg throws exception when not found send single message replysender msg message index include message text final simple field set sfs new simple field set true sfs put overwrite message end list messages replysender send sfs listmessages endlistmessages listmessages boardname sortbymessagexxx sortbymessageindexascending sortbymessagedateascending minimummessagexxx minimummessageindex minimummessagedate utcmillis includemessagetext sendsinglemessage handlelistmessages pluginreplysender simplefieldset pluginnotfoundexception invalidparameterexception nosuchboardexception nosuchmessageexception unsupportedencodingexception boardname boardname boardname invalidparameterexception sortbymessageindexascending parseboolean sortbymessageindexascending sortbymessagedateascending parseboolean sortbymessagedateascending sortbymessageindexascending sortbymessagedateascending invalidparameterexception sortbymessageindexascending sortbymessagedateascending minimummessageindex minimummessageindex parseint minimummessageindex numberformatexception minimummessageindex minimummessagedate minimummessagedate parselong minimummessagedate numberformatexception minimummessagedate minimummessageindex minimummessagedate invalidparameterexception minimummessageindex minimummessagedate includemessagetext parseboolean includemessagetext mfreetalk getmessagemanager getboardbyname boardname messagereference messagereflist minimummessageindex messagereflist getmessagesbyminimumindex minimummessageindex sortbymessageindexascending sortbymessagedateascending minimummessagedate messagereflist getmessagesbyminimumdate minimummessagedate sortbymessageindexascending sortbymessagedateascending messagereflist getallmessages sortbymessageindexascending messagereference messagereflist getmessage messageindex getmessageindex sendsinglemessage messageindex includemessagetext simplefieldset simplefieldset putoverwrite endlistmessages handle list thread messages command send a number of message messages and finally an end list messages message format of request message list thread messages board name abc threadid id optional if not specified retrieves all messages of board sort by message index ascending true false optional default is false include message text true false optional default is false format of reply see send single message private void handle list thread messages final plugin reply sender replysender final simple field set params throws plugin not found exception invalid parameter exception no such board exception no such message exception unsupported encoding exception final string board name params get board name if board name null throw new invalid parameter exception boardname parameter not specified final string threadid params get threadid final boolean sort by message index ascending boolean parse boolean params get sort by message index ascending final boolean include message text boolean parse boolean params get include message text final board board m freetalk get message manager get board by name board name throws exception when not found synchronized board fixme is this enough synchronization or should we lock the message manager final list message reference message ref list final message thread m freetalk get message manager get threadid throws exception when not found send thread root message final int message index board get message index thread throws exception when not found send single message replysender thread message index include message text message ref list board get all thread replies thread sort by message index ascending send all messages of thread for final message reference reference message ref list final message msg reference get message final int message index board get message index msg throws exception when not found send single message replysender msg message index include message text final simple field set sfs new simple field set true sfs put overwrite message end list messages replysender send sfs listthreadmessages endlistmessages listthreadmessages boardname sortbymessageindexascending includemessagetext sendsinglemessage handlelistthreadmessages pluginreplysender simplefieldset pluginnotfoundexception invalidparameterexception nosuchboardexception nosuchmessageexception unsupportedencodingexception boardname boardname boardname invalidparameterexception sortbymessageindexascending parseboolean sortbymessageindexascending includemessagetext parseboolean includemessagetext mfreetalk getmessagemanager getboardbyname boardname messagereference messagereflist mfreetalk getmessagemanager messageindex getmessageindex sendsinglemessage messageindex includemessagetext messagereflist getallthreadreplies sortbymessageindexascending messagereference messagereflist getmessage messageindex getmessageindex sendsinglemessage messageindex includemessagetext simplefieldset simplefieldset putoverwrite endlistmessages handle get message command send the requested message format of request message get message board name abc message index 123 message index in board include message text true false optional default is false format of reply see send single message reply when messageid or board name is not found message error original message get message description unknown message id abc or description unknown board abc private void handle get message final plugin reply sender replysender final simple field set params throws plugin not found exception invalid parameter exception no such board exception no such message exception unsupported encoding exception final string board name params get board name if board name null throw new invalid parameter exception boardname parameter not specified final board specified board try specified board m freetalk get message manager get board by name board name catch final no such board exception e throw new invalid parameter exception board board name does not exist final string message index string params get message index if message index string null throw new invalid parameter exception message index parameter not specified final int message index try message index integer parse int message index string catch final number format exception e throw new invalid parameter exception message index ist not a number final boolean include message text boolean parse boolean params get include message text final message message specified board get message by index message index throws exception when not found send single message replysender message message index include message text getmessage getmessage boardname messageindex includemessagetext sendsinglemessage boardname originalmessage getmessage handlegetmessage pluginreplysender simplefieldset pluginnotfoundexception invalidparameterexception nosuchboardexception nosuchmessageexception unsupportedencodingexception boardname boardname boardname invalidparameterexception specifiedboard specifiedboard mfreetalk getmessagemanager getboardbyname boardname nosuchboardexception invalidparameterexception boardname messageindexstring messageindex messageindexstring invalidparameterexception messageindex messageindex messageindex parseint messageindexstring numberformatexception invalidparameterexception messageindex includemessagetext parseboolean includemessagetext specifiedboard getmessagebyindex messageindex sendsinglemessage messageindex includemessagetext sends a single message format of reply message message id id message index 123 unique per board title title author freetalk addr date utc millis fetch date utc millis is thread true false parentid id optional file attachment count 2 optional not send if value is 0 file attachmenturi 1 chk abc file attachment size 1 123 datatype long file attachmenturi 2 chk def file attachment size 2 456 following is only sent when include message text true data length 123 note no leading replies data note no leading replies 123 bytes of utf8 text no end message private void send single message final plugin reply sender replysender final message message final int message index final boolean include message text throws plugin not found exception unsupported encoding exception final simple field set sfs new simple field set true sfs put overwrite message message sfs put overwrite id message getid sfs put message index message index sfs put overwrite title message get title sfs put overwrite author message get author get freetalk address sfs put date message get date get time sfs put fetch date message get fetch date get time sfs put is thread message is thread try sfs put overwrite parentid message get parentid catch final no such message exception e final attachment attachments message get attachments if attachments null attachments length 0 sfs put file attachment count attachments length for int x 1 x attachments length x sfs put overwrite file attachmenturi x attachments x 1 geturi to string sfs put file attachment size x attachments x 1 get size if include message text message get text null message get text length 0 sending data sets data length and data without preceeding replies replysender send sfs message get text get bytes utf 8 else replysender send sfs messageindex freetalkaddr utcmillis fetchdate utcmillis isthread fileattachmentcount fileattachmenturi fileattachmentsize fileattachmenturi fileattachmentsize includemessagetext datalength endmessage sendsinglemessage pluginreplysender messageindex includemessagetext pluginnotfoundexception unsupportedencodingexception simplefieldset simplefieldset putoverwrite putoverwrite messageindex messageindex putoverwrite gettitle putoverwrite getauthor getfreetalkaddress getdate gettime fetchdate getfetchdate gettime isthread isthread putoverwrite getparentid nosuchmessageexception getattachments fileattachmentcount putoverwrite fileattachmenturi tostring fileattachmentsize getsize includemessagetext gettext gettext datalength gettext getbytes handle list known identities command send a number of known identity messages and finally an end list known identities message format message known identity uid uid nickname name freetalk address freetalk addr private void handle list known identities final plugin reply sender replysender final simple field set params throws plugin not found exception for final ft identity id m freetalk get identity manager get all identities if id instanceof ft own identity continue final simple field set sfs new simple field set true sfs put overwrite message known identity sfs put overwrite uid id getuid sfs put overwrite nickname id get nickname sfs put overwrite freetalk address id get freetalk address replysender send sfs final simple field set sfs new simple field set true sfs put overwrite message end list known identities replysender send sfs listknownidentities knownidentity endlistknownidentities knownidentity freetalkaddress freetalkaddr handlelistknownidentities pluginreplysender simplefieldset pluginnotfoundexception ftidentity mfreetalk getidentitymanager getallidentities ftownidentity simplefieldset simplefieldset putoverwrite knownidentity putoverwrite putoverwrite getnickname putoverwrite freetalkaddress getfreetalkaddress simplefieldset simplefieldset putoverwrite endlistknownidentities handle list own identities command send a number of own identity messages and finally an end list own identities message format message own identity uid uid nickname name freetalk address freetalk addr private void handle list own identities final plugin reply sender replysender final simple field set params throws plugin not found exception final iterator ft own identity own identities m freetalk get identity manager own identity iterator while own identities has next final ft own identity id own identities next final simple field set sfs new simple field set true sfs put overwrite message own identity sfs put overwrite uid id getuid sfs put overwrite nickname id get nickname sfs put overwrite freetalk address id get freetalk address replysender send sfs final simple field set sfs new simple field set true sfs put overwrite message end list own identities replysender send sfs listownidentities ownidentity endlistownidentities ownidentity freetalkaddress freetalkaddr handlelistownidentities pluginreplysender simplefieldset pluginnotfoundexception ftownidentity ownidentities mfreetalk getidentitymanager ownidentityiterator ownidentities hasnext ftownidentity ownidentities simplefieldset simplefieldset putoverwrite ownidentity putoverwrite putoverwrite getnickname putoverwrite freetalkaddress getfreetalkaddress simplefieldset simplefieldset putoverwrite endlistownidentities handle create own identity command format of request message create own identity nickname name publish trust list true false optional default is true publish introduction puzzles true false optional default is true requesturi optional inserturi optional format of reply message create own identity reply own identity created true false uid uid freetalk address addr inserturi requesturi error description abc set if own identity created false private void handle create own identity final plugin reply sender replysender final simple field set params throws plugin not found exception try final string nick name params get nickname if nick name null nick name length 0 throw new invalid parameter exception nickname parameter not specified wot identity validate nickname nick name throws exception if invalid boolean publish trust list true final string publish trust list string params get publish trust list if publish trust list string null publish trust list boolean parse boolean publish trust list string boolean publish introduction puzzles true final string publish introduction puzzles string params get publish introduction puzzles if publish introduction puzzles string null publish introduction puzzles boolean parse boolean publish introduction puzzles string final string request uri string params get requesturi final string insert uri string params get inserturi if request uri string null insert uri string null request uri string insert uri string throw new invalid parameter exception requesturi and inserturi must be set together final wot own identity id if request uri string null final freeneturi request uri new freeneturi request uri string throws exception if malformed final freeneturi insert uri new freeneturi insert uri string throws exception if malformed id wot own identity m freetalk get identity manager create own identity nick name publish trust list publish introduction puzzles request uri insert uri else id wot own identity m freetalk get identity manager create own identity nick name publish trust list publish introduction puzzles id can t be null when we come here final simple field set sfs new simple field set true sfs put overwrite message create own identity reply sfs put overwrite own identity created true sfs put overwrite uid id getuid sfs put overwrite freetalk address id get freetalk address sfs put overwrite inserturi id get inserturi to string sfs put overwrite requesturi id get requesturi to string replysender send sfs catch final exception e final simple field set sfs new simple field set true sfs put overwrite message create own identity reply sfs put overwrite own identity created false sfs put overwrite error description e get localized message replysender send sfs return createownidentity createownidentity publishtrustlist publishintroductionpuzzles createownidentityreply ownidentitycreated freetalkaddress errordescription ownidentitycreated handlecreateownidentity pluginreplysender simplefieldset pluginnotfoundexception nickname nickname nickname invalidparameterexception wotidentity validatenickname nickname publishtrustlist publishtrustliststring publishtrustlist publishtrustliststring publishtrustlist parseboolean publishtrustliststring publishintroductionpuzzles publishintroductionpuzzlesstring publishintroductionpuzzles publishintroductionpuzzlesstring publishintroductionpuzzles parseboolean publishintroductionpuzzlesstring requesturistring inserturistring requesturistring inserturistring requesturistring inserturistring invalidparameterexception wotownidentity requesturistring requesturi requesturistring inserturi inserturistring wotownidentity mfreetalk getidentitymanager createownidentity nickname publishtrustlist publishintroductionpuzzles requesturi inserturi wotownidentity mfreetalk getidentitymanager createownidentity nickname publishtrustlist publishintroductionpuzzles simplefieldset simplefieldset putoverwrite createownidentityreply putoverwrite ownidentitycreated putoverwrite putoverwrite freetalkaddress getfreetalkaddress putoverwrite getinserturi tostring putoverwrite getrequesturi tostring simplefieldset simplefieldset putoverwrite createownidentityreply putoverwrite ownidentitycreated putoverwrite errordescription getlocalizedmessage handle create board command creates a new board with name the name must be valid see board constructor format of request message create board board name abc format of reply message create board reply board created true false error description abc set when board created false stored board name abc set when board created true private void handle create board final plugin reply sender replysender final simple field set params throws plugin not found exception invalid parameter exception try final string board name params get board name if board name null board name length 0 throw new invalid parameter exception board name parameter not specified if board is name valid board name throw new invalid parameter exception board name parameter is not valid board board synchronized m freetalk get message manager try board m freetalk get message manager get board by name board name catch final no such board exception e board null if board null throw new invalid parameter exception board with same name already exists board m freetalk get message manager get or create board board name board can t be null when we come here final simple field set sfs new simple field set true sfs put overwrite message create board reply sfs put overwrite board created true sfs put overwrite stored board name board get name replysender send sfs catch final exception e final simple field set sfs new simple field set true sfs put overwrite message create board reply sfs put overwrite board created false sfs put overwrite error description e get localized message replysender send sfs return createboard createboard boardname createboardreply boardcreated errordescription boardcreated storedboardname boardcreated handlecreateboard pluginreplysender simplefieldset pluginnotfoundexception invalidparameterexception boardname boardname boardname boardname invalidparameterexception boardname isnamevalid boardname invalidparameterexception boardname mfreetalk getmessagemanager mfreetalk getmessagemanager getboardbyname boardname nosuchboardexception invalidparameterexception mfreetalk getmessagemanager getorcreateboard boardname simplefieldset simplefieldset putoverwrite createboardreply putoverwrite boardcreated putoverwrite storedboardname getname simplefieldset simplefieldset putoverwrite createboardreply putoverwrite boardcreated putoverwrite errordescription getlocalizedmessage handle put message command sends a message format of request message put message parentid id optional when set the msg is a reply target boards abc def comma separated list of target boards one is required reply to board abc optional must be in target boards author identityuid uid uid of an own identity file attachment count 2 optional not send if value is 0 file attachmenturi 1 chk abc file attachment size 1 123 datatype long file attachmenturi 2 chk def file attachment size 2 456 title abc def message title format of reply message put message reply message enqueued true false error description abc set when message enqueued false private void handle put message final plugin reply sender replysender final simple field set params final bucket data throws plugin not found exception invalid parameter exception synchronized m freetalk get message manager try evaluate parent message final string parent msg id params get parentid may be null message parent message null if parent msg id null try parent message m freetalk get message manager get parent msg id catch final no such message exception e throw new invalid parameter exception message specified by parentid was not found evaluate target boards final string target boards string params get target boards if target boards string null throw new invalid parameter exception target boards parameter not specified final string target boards array target boards string split if target boards array length 0 throw new invalid parameter exception invalid target boards parameter specified final set board target boards new hash set board for string target board name target boards array target board name target board name trim if target board name length 0 throw new invalid parameter exception invalid target boards parameter specified try final board board m freetalk get message manager get board by name target board name target boards add board catch final no such board exception e throw new invalid parameter exception target board target board name does not exist evaluate reply to board final string reply to board name params get reply to board may be null board reply to board null if reply to board name null try reply to board m freetalk get message manager get board by name reply to board name catch final no such board exception e throw new invalid parameter exception reply to board reply to board name does not exist if target boards contains reply to board throw new invalid parameter exception reply to board is not contained in target boards evaluate author identity final string author identity uid string params get author identityuid if author identity uid string null throw new invalid parameter exception author identityuid parameter not specified final ft own identity author identity try author identity m freetalk get identity manager get own identity author identity uid string catch final no such identity exception e throw new invalid parameter exception no own identity found for author identityuid evaluate attachments int attachment count try attachment count integer parse int params get file attachment count catch final exception e attachment count 0 final list attachment attachments new array list attachment attachment count for int x 1 x attachment count x final string uri string params get file attachmenturi x final string size string params get file attachment size x if uri string null size string null throw new invalid parameter exception invalid file attachment specified x long file size freeneturi freenet uri try freenet uri new freeneturi uri string file size long parse long size string catch final exception e throw new invalid parameter exception invalid file attachment specified x attachments add new attachment freenet uri file size evaluate message title final string message title params get title if message title null throw new invalid parameter exception title parameter not specified if message title length message max message title text length throw new invalid parameter exception message title is longer than 256 characters evaluate message text we expect data containing the message text if data null throw new invalid parameter exception no message text sent if data size message max message text byte length throw new invalid parameter exception message text is longer than 64kb convert to utf 8 final byte utf8 bytes new byte int data size final input stream is data get input stream try if is read utf8 bytes utf8 bytes length throw new invalid parameter exception internal error reading data from bucket finally is close final string message text new string utf8 bytes utf 8 post new message m freetalk get message manager post message parent message target boards reply to board author identity message title null date use current message text attachments final simple field set sfs new simple field set true sfs put overwrite message put message reply sfs put overwrite message enqueued true replysender send sfs catch final exception e final simple field set sfs new simple field set true sfs put overwrite message put message reply sfs put overwrite message enqueued false sfs put overwrite error description e get localized message replysender send sfs synchronized m freetalk get message manager putmessage putmessage targetboards replytoboard targetboards authoridentityuid fileattachmentcount fileattachmenturi fileattachmentsize fileattachmenturi fileattachmentsize putmessagereply messageenqueued errordescription messageenqueued handleputmessage pluginreplysender simplefieldset pluginnotfoundexception invalidparameterexception mfreetalk getmessagemanager parentmessage parentmsgid parentmessage parentmsgid parentmessage mfreetalk getmessagemanager parentmsgid nosuchmessageexception invalidparameterexception targetboards targetboardsstring targetboards targetboardsstring invalidparameterexception targetboards targetboardsarray targetboardsstring targetboardsarray invalidparameterexception targetboards targetboards hashset targetboardname targetboardsarray targetboardname targetboardname targetboardname invalidparameterexception targetboards mfreetalk getmessagemanager getboardbyname targetboardname targetboards nosuchboardexception invalidparameterexception targetboard targetboardname replytoboard replytoboardname replytoboard replytoboard replytoboardname replytoboard mfreetalk getmessagemanager getboardbyname replytoboardname nosuchboardexception invalidparameterexception replytoboard replytoboardname targetboards replytoboard invalidparameterexception replytoboard targetboards authoridentity authoridentityuidstring authoridentityuid authoridentityuidstring invalidparameterexception authoridentityuid ftownidentity authoridentity authoridentity mfreetalk getidentitymanager getownidentity authoridentityuidstring nosuchidentityexception invalidparameterexception authoridentityuid attachmentcount attachmentcount parseint fileattachmentcount attachmentcount arraylist attachmentcount attachmentcount uristring fileattachmenturi sizestring fileattachmentsize uristring sizestring invalidparameterexception fileattachment filesize freeneturi freeneturi uristring filesize parselong sizestring invalidparameterexception fileattachment freeneturi filesize messagetitle messagetitle messagetitle invalidparameterexception messagetitle max_message_title_text_length invalidparameterexception messagetext invalidparameterexception max_message_text_byte_length invalidparameterexception utf8bytes inputstream getinputstream utf8bytes utf8bytes invalidparameterexception messagetext utf8bytes mfreetalk getmessagemanager postmessage parentmessage targetboards replytoboard authoridentity messagetitle messagetext simplefieldset simplefieldset putoverwrite putmessagereply putoverwrite messageenqueued simplefieldset simplefieldset putoverwrite putmessagereply putoverwrite messageenqueued putoverwrite errordescription getlocalizedmessage mfreetalk getmessagemanager status command handler format of reply message status reply unsent message count 123 private void handle status final plugin reply sender replysender final simple field set params throws plugin not found exception final simple field set sfs new simple field set true sfs put overwrite message status reply sfs put unsent message count m freetalk get message manager count unsent messages replysender send sfs statusreply unsentmessagecount handlestatus pluginreplysender simplefieldset pluginnotfoundexception simplefieldset simplefieldset putoverwrite statusreply unsentmessagecount mfreetalk getmessagemanager countunsentmessages simple ping command handler returns a pong format message pong current time utc millis private void handle ping final plugin reply sender replysender final simple field set params throws plugin not found exception final simple field set sfs new simple field set true sfs put overwrite message pong sfs put current time system current time millis replysender send sfs currenttime utcmillis handleping pluginreplysender simplefieldset pluginnotfoundexception simplefieldset simplefieldset putoverwrite currenttime currenttimemillis sends an error message to the client format message error original message msg or null description msg or null fixme provide numerical return codes for all possible error messages board not found private simple field set error messagefcp final string original message final exception e final simple field set sfs new simple field set true sfs put overwrite message error sfs put overwrite original message original message null null original message sfs put overwrite description e get localized message null null e get localized message e print stack trace return sfs originalmessage simplefieldset errormessagefcp originalmessage simplefieldset simplefieldset putoverwrite putoverwrite originalmessage originalmessage originalmessage putoverwrite getlocalizedmessage getlocalizedmessage printstacktrace private node service node public node get argument node return argument node servicenode getargumentnode argumentnode private node get service node return service node getservicenode servicenode public service get service return new service get service node getservice getservicenode public node get action node node argument linst node get argument node get parent node if argument linst node null return null node action node argument linst node get parent node if action node null return null if action is action node action node false return null return action node getactionnode argumentlinstnode getargumentnode getparentnode argumentlinstnode actionnode argumentlinstnode getparentnode actionnode isactionnode actionnode actionnode public action get action return new action get service node get action node getaction getservicenode getactionnode public argument argument node new node service node null argumentnode servicenode public argument node serv node node arg node service node serv node argument node arg node servnode argnode servicenode servnode argumentnode argnode public argument string name string value this set name name set value value setname setvalue public static boolean is argument node node node return argument elem name equals node get name isargumentnode elem_name getname private final static string name name public void set name string value get argument node set node name value setname getargumentnode setnode public string get name return get argument node get node value name getname getargumentnode getnodevalue private final static string direction direction public void set direction string value get argument node set node direction value setdirection getargumentnode setnode public string get direction return get argument node get node value direction getdirection getargumentnode getnodevalue public boolean is in direction string dir get direction if dir null return false return dir equals ignore case in isindirection getdirection equalsignorecase public boolean is out direction return is in direction isoutdirection isindirection private final static string related state variable related state variable public void set related state variable name string value get argument node set node related state variable value related_state_variable relatedstatevariable setrelatedstatevariablename getargumentnode setnode related_state_variable public string get related state variable name return get argument node get node value related state variable getrelatedstatevariablename getargumentnode getnodevalue related_state_variable public state variable get related state variable service service get service if service null return null string related stat var name get related state variable name return service get state variable related stat var name statevariable getrelatedstatevariable getservice relatedstatvarname getrelatedstatevariablename getstatevariable relatedstatvarname private argument data get argument data node node get argument node argument data user data argument data node get user data if user data null user data new argument data node set user data user data user data set node node return user data argumentdata getargumentdata getargumentnode argumentdata userdata argumentdata getuserdata userdata userdata argumentdata setuserdata userdata userdata setnode userdata public void set value string value get argument data set value value setvalue getargumentdata setvalue public void set value int value set value integer to string value setvalue setvalue tostring public string get value return get argument data get value getvalue getargumentdata getvalue public int get integer value string value get value try return integer parse int value catch exception e return 0 getintegervalue getvalue parseint static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public class node name callback extends string callback node name callback nodenamecallback stringcallback nodenamecallback override public string get string name synchronized this name my name if name starts with node id name equals my first freenet node client core alerts register node name user alert else client core alerts unregister node name user alert return name myname startswith myfirstfreenetnode clientcore nodenameuseralert clientcore nodenameuseralert override public void set string val throws invalid config value exception if get equals val return else if val length 128 throw new invalid config value exception the given node name is too long val else if equals val val none synchronized this my name val we ll broadcast the new name to our connected darknet peers via a differential node reference simple field set fs new simple field set true fs put single my name my name peers locally broadcast diff node ref fs true false we call the callback once again to ensure meaningful node name user alert has been unregistered see 1595 get invalidconfigvalueexception invalidconfigvalueexception myname simplefieldset simplefieldset putsingle myname myname locallybroadcastdiffnoderef meaningfulnodenameuseralert override public string get if cached store type null cached store type store type return cached store type cachedstoretype cachedstoretype storetype cachedstoretype override public void set string val throws invalid config value exception node need restart exception boolean found false for string p get possible values if p equals val found true break if found throw new invalid config value exception invalid store type cached store type val throw new node need restart exception store type cannot be changed on the fly invalidconfigvalueexception nodeneedrestartexception getpossiblevalues invalidconfigvalueexception cachedstoretype nodeneedrestartexception public string get possible values return new string bdb index salt hash ram getpossiblevalues private static class l10n callback extends string callback implements enumerable option callback override public string get return l10n get selected language full name l10ncallback stringcallback enumerableoptioncallback getselectedlanguage fullname override public void set string val throws invalid config value exception if val null get equals ignore case val return try l10n set language val catch missing resource exception e throw new invalid config value exception e get localized message plugin manager set language l10n get selected language invalidconfigvalueexception equalsignorecase setlanguage missingresourceexception invalidconfigvalueexception getlocalizedmessage pluginmanager setlanguage getselectedlanguage public string get possible values return l10n language values with full names getpossiblevalues valueswithfullnames read all storable settings identity etc from the node file param filename the name of the file to read from private void read node file string filename random source r throws io exception redflag any way to share this code with node peer file input stream fis new file input stream filename input stream reader isr new input stream reader fis utf 8 buffered reader br new buffered reader isr simple field set fs new simple field set br false true br close read contents string udp fs get all physical udp if udp null udp length 0 for int i 0 i udp length i just keep the first one with the correct port number peer p try p new peer udp i false true catch hostname syntax exception e logger error this invalid hostname or ip address syntax error while parsing our darknet node reference udp i system err println invalid hostname or ip address syntax error while parsing our darknet node reference udp i continue catch peer parse exception e io exception e1 new io exception e1 init cause e throw e1 if p get port get darknet port number dns requester doesn t deal with our own node ip detector set oldip address p get freenet address break darknet crypto read crypto fs swap identifier fields bytes to long darknet crypto identity hash hash string loc fs get location double locd location get location loc if locd 1 0 throw new io exception invalid location loc lm set location locd my name fs get my name if my name null my name new name string ver string fs get version if ver string null logger error this no version system err println no version else last version version get arbitrary build number ver string 1 was testnet fields string to bool fs get testnet false readnodefile randomsource ioexception nodepeer fileinputstream fileinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader simplefieldset simplefieldset getall hostnamesyntaxexception peerparseexception ioexception ioexception initcause getport getdarknetportnumber dnsrequester ipdetector setoldipaddress getfreenetaddress darknetcrypto readcrypto swapidentifier bytestolong darknetcrypto identityhashhash getlocation ioexception setlocation myname myname myname myname newname verstring verstring lastversion getarbitrarybuildnumber verstring wastestnet stringtobool private string new name return node id random next long newname nextlong public void write node file synchronized write node file sync write node file new file node dir node get darknet port number new file node dir node get darknet port number bak writenodefile writenodefilesync writenodefile nodedir getdarknetportnumber nodedir getdarknetportnumber public void write opennet file opennet manager om opennet if om null om write file writeopennetfile opennetmanager writefile private void write node file file orig file backup simple field set fs darknet crypto export private field set if orig exists backup delete file output stream fos null try fos new file output stream backup fs write to fos file util rename to backup orig catch io exception ioe logger error this ioe ioe get message ioe return finally closer close fos writenodefile simplefieldset darknetcrypto exportprivatefieldset fileoutputstream fileoutputstream writeto fileutil renameto ioexception getmessage private void init node file settings random source r logger normal this creating new node file from scratch don t need to set get darknet port number fixme use a real ip darknet crypto init crypto swap identifier fields bytes to long darknet crypto identity hash hash my name new name initnodefilesettings randomsource getdarknetportnumber darknetcrypto initcrypto swapidentifier bytestolong darknetcrypto identityhashhash myname newname read the config file from the arguments then create a node anything that needs static init should ideally be in here public static void main string args throws io exception node starter main args ioexception nodestarter public boolean is using wrapper if node starter null wrapper manager is controlled by native wrapper return true else return false isusingwrapper nodestarter wrappermanager iscontrolledbynativewrapper public node starter get node starter return node starter nodestarter getnodestarter nodestarter create a node from a config object param config the config object for this node param random the random number generator for this node passed in because we may want to use a non secure rng for e g one jvm live code simulations should be a yarrow in a production node yarrow will be used if that parameter is null param weak random the fast random number generator the node will use if null a mt instance will be used seeded from the secure prng param the logging handler throws node init exception if the node initialization fails node persistent config config random source r random source weak random logging config handler lc node starter ns executor executor throws node init exception easy stuff string tmp initializing node using freenet build version build number r version cvs revision and freenet ext build node starter ext build number r node starter ext revision number with system get property java vendor jvm version system get property java version running on system get property os arch system get property os name system get property os version logger normal this tmp system out println tmp collector new io statistic collector this executor executor node starter ns if log config handler lc log config handler lc startup time system current time millis simple field set old config config get simple field set setup node specific configuration final sub config node config new sub config node config int sort order 0 l10n stuffs node config register l10n locale get default get language to lower case sort order false true node l10n language node l10n language long new l10n callback try l10n set language node config get string l10n catch missing resource exception e try l10n set language node config get option l10n get default catch missing resource exception e1 l10n set language l10n language get default short code f proxy config needs to be here too sub config fproxy config new sub config fproxy config try toadlets new simple toadlet server fproxy config new array bucket factory executor fproxy config finished initialization toadlets start catch io exception e4 logger error this could not start web interface e4 e4 system err println could not start web interface e4 e4 print stack trace throw new node init exception node init exception exit could not start fproxy could not start f proxy e4 catch invalid config value exception e4 system err println invalid config value cannot start web interface e4 e4 print stack trace throw new node init exception node init exception exit could not start fproxy could not start f proxy e4 setup rng if needed do not use it before that point if r null final native thread entropy gathering thread new native thread new runnable private void recurse file f if isprng ready return file sub dirs f list files new file filter public boolean accept file pathname return pathname exists pathname can read pathname is directory see http bugs sun com bugdatabase view bug do bug id 5086412 if sub dirs null for file current dir sub dirs recurse current dir public void run for file root file list roots if isprng ready return recurse root entropy gathering thread native thread min priority true entropy gathering thread start this random new yarrow diffie hellman init random else if it s not null it s because we are running in the simulator this random r isprng ready true toadlets get startup toadlet set isprng ready if weak random null byte buffer new byte 16 random next bytes buffer this fast weak random new mersenne twister buffer else this fast weak random weak random node name user alert new meaningful node name user alert this recently completedi ds new lru queue long this config config cached pub keys new lru hashtable byte array wrapper dsa public key lm new location manager random this try localhost address inet address get by name 127 0 0 1 catch unknown host exception e3 does not do a reverse lookup so this is impossible throw new error e3 f localhost address new freenet inet address localhost address request senders new hash map keyhtl pair request sender transferring request senders new hash map nodechk request sender transferring request handlers new hash set long insert senders new hash map keyhtl pair any insert sender runningui ds new hash map long uid tag runningchk getui ds new hash map long request tag running localchk getui ds new hash map long request tag runningssk getui ds new hash map long request tag running localssk getui ds new hash map long request tag runningchk putui ds new hash map long insert tag running localchk putui ds new hash map long insert tag runningssk putui ds new hash map long insert tag running localssk putui ds new hash map long insert tag runningchk offer replyui ds new hash map long offer reply tag runningssk offer replyui ds new hash map long offer reply tag this security levels new security levels this config directory for node related files other than store node config register node dir sort order true true because can t be changed on the fly also for packages node node dir node node dir long new string callback override public string get return node dir get path override public void set string val throws invalid config value exception if node dir equals new file val return fixme support it don t translate the below as very few users will use it throw new invalid config value exception moving node directory on the fly not supported at present override public boolean is read only return true node dir new file node config get string node dir if node dir exists node dir is directory node dir mkdir string msg could not find or create datastore directory throw new node init exception node init exception exit bad node dir msg init shutdown hook shutdown hook new semi ordered shutdown hook runtime get runtime add shutdown hook shutdown hook fixme backup the database configuration db config db4o new configuration on my db4o test node with lots of downloads and several days old com db4o internal freespace free slot node used 73mb out of the 128mb limit 117mb used this memory was not reclaimed despite constant garbage collection this is unacceptable hence btree freespace db config freespace useb tree system db config object class freenet client async persistent cooldown queue item class object field key indexed true db config object class freenet client async persistent cooldown queue item class object field key as bytes indexed true db config object class freenet client async persistent cooldown queue item class object field time indexed true db config object class freenet client async register me class object field core indexed true db config object class freenet client async register me class object field priority indexed true db config object class freenet client async persistent cooldown queue item class object field time indexed true db config object class freenet client fec job class object field priority indexed true db config object class freenet client fec job class object field added time indexed true db config object class freenet client fec job class object field queue indexed true db config object class freenet client async insert compressor class object field nodedb handle indexed true db config object class freenet node fcp fcp client class object field name indexed true db config object class freenet client async datastore checker item class object field prio indexed true db config object class freenet support io persistent blob temp bucket tag class object field index indexed true db config object class freenet support io persistent blob temp bucket tag class object field bucket indexed true db config object class freenet support io persistent blob temp bucket tag class object field factory indexed true db config object class freenet support io persistent blob temp bucket tag class object field is free indexed true db config object class freenet client fetch exception class cascade on delete true hash map don t enable cascade on update delete activate db4o handles this internally through the t map translator lazy appears to cause class cast exception s relating to db4o objects inside db4o code also it causes duplicates if we activate immediately and the performance gain for e g register me runner isn t that great db config queries evaluation mode query evaluation mode lazy db config message level 1 db config activation depth 1 turn off shutdown hook the shutdown hook does auto commit we do not want auto commit if a transaction hasn t commit ed it s not safe to commit it for example a splitfile is started gets half way through then we shut down the shutdown hook commits the half finished transaction when we start back up we assume the whole transaction has been committed and end up only registering the proportion of segments for which a register me has already been created yes this has happened yes it sucks add our o weakrandom logginghandler nodeinitexception persistentconfig randomsource randomsource weakrandom loggingconfighandler nodestarter nodeinitexception buildnumber cvsrevision nodestarter extbuildnumber nodestarter extrevisionnumber getproperty getproperty getproperty getproperty getproperty iostatisticcollector nodestarter logconfighandler logconfighandler startuptime currenttimemillis simplefieldset oldconfig getsimplefieldset subconfig nodeconfig subconfig sortorder nodeconfig getdefault getlanguage tolowercase sortorder l10nlanguage l10nlanguagelong l10ncallback setlanguage nodeconfig getstring missingresourceexception setlanguage nodeconfig getoption getdefault missingresourceexception setlanguage getdefault shortcode fproxy subconfig fproxyconfig subconfig simpletoadletserver fproxyconfig arraybucketfactory fproxyconfig finishedinitialization ioexception printstacktrace nodeinitexception nodeinitexception exit_could_not_start_fproxy fproxy invalidconfigvalueexception printstacktrace nodeinitexception nodeinitexception exit_could_not_start_fproxy fproxy nativethread entropygatheringthread nativethread isprngready subdirs listfiles filefilter canread isdirectory view_bug bug_id subdirs currentdir subdirs currentdir listroots isprngready nativethread min_priority entropygatheringthread diffiehellman isprngready getstartuptoadlet setisprngready weakrandom nextbytes fastweakrandom mersennetwister fastweakrandom weakrandom nodenameuseralert meaningfulnodenameuseralert recentlycompletedids lruqueue cachedpubkeys lruhashtable bytearraywrapper dsapublickey locationmanager localhostaddress inetaddress getbyname unknownhostexception flocalhostaddress freenetinetaddress localhostaddress requestsenders hashmap keyhtlpair requestsender transferringrequestsenders hashmap requestsender transferringrequesthandlers hashset insertsenders hashmap keyhtlpair anyinsertsender runninguids hashmap uidtag runningchkgetuids hashmap requesttag runninglocalchkgetuids hashmap requesttag runningsskgetuids hashmap requesttag runninglocalsskgetuids hashmap requesttag runningchkputuids hashmap inserttag runninglocalchkputuids hashmap inserttag runningsskputuids hashmap inserttag runninglocalsskputuids hashmap inserttag runningchkofferreplyuids hashmap offerreplytag runningsskofferreplyuids hashmap offerreplytag securitylevels securitylevels nodeconfig nodedir sortorder nodedir nodedirlong stringcallback nodedir getpath invalidconfigvalueexception nodedir invalidconfigvalueexception isreadonly nodedir nodeconfig getstring nodedir nodedir nodedir isdirectory nodedir nodeinitexception nodeinitexception exit_bad_node_dir shutdownhook semiorderedshutdownhook getruntime addshutdownhook shutdownhook dbconfig newconfiguration freeslotnode dbconfig usebtreesystem dbconfig objectclass persistentcooldownqueueitem objectfield dbconfig objectclass persistentcooldownqueueitem objectfield keyasbytes dbconfig objectclass persistentcooldownqueueitem objectfield dbconfig objectclass registerme objectfield dbconfig objectclass registerme objectfield dbconfig objectclass persistentcooldownqueueitem objectfield dbconfig objectclass fecjob objectfield dbconfig objectclass fecjob objectfield addedtime dbconfig objectclass fecjob objectfield dbconfig objectclass insertcompressor objectfield nodedbhandle dbconfig objectclass fcpclient objectfield dbconfig objectclass datastorecheckeritem objectfield dbconfig objectclass persistentblobtempbuckettag objectfield dbconfig objectclass persistentblobtempbuckettag objectfield dbconfig objectclass persistentblobtempbuckettag objectfield dbconfig objectclass persistentblobtempbuckettag objectfield isfree dbconfig objectclass fetchexception cascadeondelete hashmap tmap classcastexception registermerunner dbconfig evaluationmode queryevaluationmode dbconfig messagelevel dbconfig activationdepth registerme ride public html node gethtml text html node div new html node div div add child l10n get string node store salt hash migrated html node ul div add child ul for string type new string chk pubkey ssk for string storecache new string store store keys store lru cache cache keys cache lru file f new file store dir type suffix storecache if f exists ul add child li f get absolute path file db dir new file store dir database suffix if db dir exists ul add child li db dir get absolute path return div override public string get text string builder sb new string builder sb append l10n get string node store salt hash migrated n for string type new string chk pubkey ssk for string storecache new string store store keys store lru cache cache keys cache lru file f new file store dir type suffix storecache if f exists sb append sb append f get absolute path sb append n file db dir new file store dir database suffix if db dir exists sb append sb append db dir get absolute path sb append n return sb to string override public boolean is valid return new file store dir chk suffix store exists new file store dir chk suffix store keys exists new file store dir chk suffix store lru exists new file store dir chk suffix cache exists new file store dir chk suffix cache keys exists new file store dir chk suffix cache lru exists new file store dir pubkey suffix store exists new file store dir pubkey suffix store keys exists new file store dir pubkey suffix store lru exists new file store dir pubkey suffix cache exists new file store dir pubkey suffix cache keys exists new file store dir pubkey suffix cache lru exists new file store dir ssk suffix store exists new file store dir ssk suffix store keys exists new file store dir ssk suffix store lru exists new file store dir ssk suffix cache exists new file store dir ssk suffix cache keys exists new file store dir ssk suffix cache lru exists new file store dir database suffix exists override public void on dismiss override public boolean user can dismiss return true security levels register user alert client core alerts node config finished initialization write node file initialize the plugin manager logger normal this initializing plugin manager system out println initializing plugin manager plugin manager new plugin manager this fixme short timeouts and jvm timeouts with nothing more said than the above have been seen i don t know why need a stack dump for now just give it an extra 2 minutes if it doesn t start in that time it s likely on reports so far that a restart will fix it and we have to get a build out because all plugins are now failing to load including the absolutely essential for most nodes jstun and u pnp wrapper manager signal starting 120 1000 fetch context ctx client core make client short 0 true get fetch context ctx allow splitfiles false ctx dont enter implicit archives true ctx max archive restarts 0 ctx max metadata size 256 ctx max non splitfile retries 10 ctx max output length 4096 ctx max recursion level 2 ctx max temp length 4096 this ark fetcher context ctx node updater support system out println initializing node updater try node updater node update manager maybe create this config catch invalid config value exception e e print stack trace throw new node init exception node init exception exit could not start updater could not create updater e register node to node message listener n2n message type fproxy fproxyn2nm listener register node to node message listener node n2n message type diffnoderef diff noderef listener fixme this is a hack toadlet server should start after all initialized see node client core line 437 if toadlets is enabled toadlets create fproxy toadlets remove startup toadlet logger normal this node constructor completed system out println node constructor completed htmlnode gethtmltext htmlnode htmlnode addchild getstring storesalthashmigrated htmlnode addchild storedir addchild getabsolutepath dbdir storedir dbdir addchild dbdir getabsolutepath gettext stringbuilder stringbuilder getstring storesalthashmigrated storedir getabsolutepath dbdir storedir dbdir dbdir getabsolutepath tostring isvalid storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir ondismiss usercandismiss securitylevels registeruseralert clientcore nodeconfig finishedinitialization writenodefile pluginmanager pluginmanager upnp wrappermanager signalstarting fetchcontext clientcore makeclient getfetchcontext allowsplitfiles dontenterimplicitarchives maxarchiverestarts maxmetadatasize maxnonsplitfileretries maxoutputlength maxrecursionlevel maxtemplength arkfetchercontext nodeupdater nodeupdatemanager maybecreate invalidconfigvalueexception printstacktrace nodeinitexception nodeinitexception exit_could_not_start_updater registernodetonodemessagelistener n2n_message_type_fproxy fproxyn2nmlistener registernodetonodemessagelistener n2n_message_type_diffnoderef diffnodereflistener nodeclientcore isenabled createfproxy removestartuptoadlet private void recurse file f if isprng ready return file sub dirs f list files new file filter public boolean accept file pathname return pathname exists pathname can read pathname is directory see http bugs sun com bugdatabase view bug do bug id 5086412 if sub dirs null for file current dir sub dirs recurse current dir isprngready subdirs listfiles filefilter canread isdirectory view_bug bug_id subdirs currentdir subdirs currentdir file sub dirs f list files new file filter public boolean accept file pathname return pathname exists pathname can read pathname is directory subdirs listfiles filefilter canread isdirectory public void run for file root file list roots if isprng ready return recurse root listroots isprngready node config register node dir sort order true true because can t be changed on the fly also for packages node node dir node node dir long new string callback override public string get return node dir get path nodeconfig nodedir sortorder nodedir nodedirlong stringcallback nodedir getpath override public void set string val throws invalid config value exception if node dir equals new file val return fixme support it don t translate the below as very few users will use it throw new invalid config value exception moving node directory on the fly not supported at present invalidconfigvalueexception nodedir invalidconfigvalueexception throw new invalid config value exception moving node directory on the fly not supported at present override public boolean is read only return true invalidconfigvalueexception isreadonly public void on diagnostic diagnostic arg0 if arg0 instanceof class has no fields return ignore if arg0 instanceof diagnostic base diagnostic base d diagnostic base arg0 logger debug this diagnostic d get class d problem d solution d reason new exception debug else logger debug this diagnostic arg0 arg0 get class new exception debug ondiagnostic classhasnofields diagnosticbase diagnosticbase diagnosticbase getclass getclass override public void run system err println stopping database jobs client core kill database clientcore killdatabase override public void run system err println rolling back unfinished transactions db rollback system err println closing database db close new boolean callback override public boolean get return disable probabilisticht ls booleancallback disableprobabilistichtls override public void set boolean val throws invalid config value exception disable probabilisticht ls val invalidconfigvalueexception disableprobabilistichtls node config register maxhtl default max htl sort order true false node maxhtl node maxhtl long new short callback override public short get return maxhtl nodeconfig default_max_htl sortorder maxhtllong shortcallback override public void set short val throws invalid config value exception if maxhtl 0 throw new invalid config value exception impossible max htl maxhtl val invalidconfigvalueexception invalidconfigvalueexception node config register enablear ks true sort order true false node enablear ks node enablear ks long new boolean callback override public boolean get return enablear ks nodeconfig enablearks sortorder enablearks enablearkslong booleancallback enablearks override public void set boolean val throws invalid config value exception throw new invalid config value exception cannot change on the fly invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly node config register enable per node failure tables true sort order true false node enable per node failure tables node enable per node failure tables long new boolean callback override public boolean get return enable per node failure tables nodeconfig enablepernodefailuretables sortorder enablepernodefailuretables enablepernodefailuretableslong booleancallback enablepernodefailuretables override public void set boolean val throws invalid config value exception throw new invalid config value exception cannot change on the fly invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly node config register enableulpr data propagation true sort order true false node enableulpr data propagation node enableulpr data propagation long new boolean callback override public boolean get return enableulpr data propagation nodeconfig enableulprdatapropagation sortorder enableulprdatapropagation enableulprdatapropagationlong booleancallback enableulprdatapropagation override public void set boolean val throws invalid config value exception throw new invalid config value exception cannot change on the fly invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly node config register enable swapping true sort order true false node enable swapping node enable swapping long new boolean callback override public boolean get return enable swapping nodeconfig enableswapping sortorder enableswapping enableswappinglong booleancallback enableswapping override public void set boolean val throws invalid config value exception throw new invalid config value exception cannot change on the fly invalidconfigvalueexception invalidconfigvalueexception override public boolean is read only return true isreadonly node config register publish our peers location true sort order true false node publish our peers location node publish our peers location long new boolean callback override public boolean get return publish our peers location nodeconfig publishourpeerslocation sortorder publishourpeerslocation publishourpeerslocationlong booleancallback publishourpeerslocation override public void set boolean val throws invalid config value exception publish our peers location val invalidconfigvalueexception publishourpeerslocation node config register route according to our peers location true sort order true false node route according to our peers location node route according to our peers location long new boolean callback override public boolean get return route according to our peers location nodeconfig routeaccordingtoourpeerslocation sortorder routeaccordingtoourpeerslocation routeaccordingtoourpeerslocationlong booleancallback routeaccordingtoourpeerslocation override public void set boolean val throws invalid config value exception route according to our peers location val invalidconfigvalueexception routeaccordingtoourpeerslocation public void on change network threat level old level network threat level new level synchronized node this boolean wantfoaf true if new level network threat level maximum new level network threat level high opennet is disabled if security levels friends threat level friends threat level high wantfoaf false route according to our peers location wantfoaf onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level newlevel network_threat_level securitylevels friendsthreatlevel friends_threat_level routeaccordingtoourpeerslocation public void on change friends threat level old level friends threat level new level synchronized node this boolean wantfoaf true network threat level network level security levels network threat level if network level network threat level maximum network level network threat level high opennet is disabled if new level friends threat level high wantfoaf false route according to our peers location wantfoaf onchange friends_threat_level oldlevel friends_threat_level newlevel network_threat_level networklevel securitylevels networkthreatlevel networklevel network_threat_level networklevel network_threat_level newlevel friends_threat_level routeaccordingtoourpeerslocation node config register enable swap queueing true sort order true false node enable swap queueing node enable swap queueing long new boolean callback override public boolean get return enable swap queueing nodeconfig enableswapqueueing sortorder enableswapqueueing enableswapqueueinglong booleancallback enableswapqueueing override public void set boolean val throws invalid config value exception enable swap queueing val invalidconfigvalueexception enableswapqueueing node config register enable packet coalescing true sort order true false node enable packet coalescing node enable packet coalescing long new boolean callback override public boolean get return enable packet coalescing nodeconfig enablepacketcoalescing sortorder enablepacketcoalescing enablepacketcoalescinglong booleancallback enablepacketcoalescing override public void set boolean val throws invalid config value exception enable packet coalescing val invalidconfigvalueexception enablepacketcoalescing shutdown hook add early job new thread override public void run if opennet null opennet stop false shutdownhook addearlyjob shutdown hook add early job new thread override public void run darknet crypto stop shutdownhook addearlyjob darknetcrypto node config register output bandwidth limit 15k sort order false true node outbw limit node outbw limit long new int callback override public integer get return block transmitter get hard bandwidth limit return output bandwidth limit nodeconfig outputbandwidthlimit sortorder outbwlimit outbwlimitlong intcallback blocktransmitter gethardbandwidthlimit outputbandwidthlimit override public void set integer obw limit throws invalid config value exception if obw limit 0 throw new invalid config value exception l10n bwlimit must be positive synchronized node this output bandwidth limit obw limit output throttle change nanos and bucket size 1000l 1000l 1000l obw limit obw limit 2 node stats set output limit obw limit obwlimit invalidconfigvalueexception obwlimit invalidconfigvalueexception bwlimitmustbepositive outputbandwidthlimit obwlimit outputthrottle changenanosandbucketsize obwlimit obwlimit nodestats setoutputlimit obwlimit node config register input bandwidth limit 1 sort order false true node inbw limit node inbw limit long new int callback override public integer get if input limit default return 1 return input bandwidth limit nodeconfig inputbandwidthlimit sortorder inbwlimit inbwlimitlong intcallback inputlimitdefault inputbandwidthlimit override public void set integer ibw limit throws invalid config value exception synchronized node this if ibw limit 1 input limit default true ibw limit output bandwidth limit 4 else if ibw limit 1 throw new invalid config value exception l10n bandwidth limit must be positive or minus one input limit default false input bandwidth limit ibw limit node stats set input limit ibw limit ibwlimit invalidconfigvalueexception ibwlimit inputlimitdefault ibwlimit outputbandwidthlimit ibwlimit invalidconfigvalueexception bandwidthlimitmustbepositiveorminusone inputlimitdefault inputbandwidthlimit ibwlimit nodestats setinputlimit ibwlimit node config register throttle local traffic false sort order true false node throttle local traffic node throttle local traffic long new boolean callback override public boolean get return throttle local data nodeconfig throttlelocaltraffic sortorder throttlelocaltraffic throttlelocaltrafficlong booleancallback throttlelocaldata override public void set boolean val throws invalid config value exception throttle local data val invalidconfigvalueexception throttlelocaldata final sub config opennet config new sub config node opennet config opennet config register connect to seednodes true 0 true false node with announcement node with announcement long new boolean callback override public boolean get return is allowed to connect to seednodes subconfig opennetconfig subconfig opennetconfig connecttoseednodes withannouncement withannouncementlong booleancallback isallowedtoconnecttoseednodes override public void set boolean val throws invalid config value exception node need restart exception if get equals val return synchronized node this is allowed to connect to seednodes val if opennet null throw new node need restart exception l10n connect to seednodes cannot be changed must disable opennet or reboot invalidconfigvalueexception nodeneedrestartexception isallowedtoconnecttoseednodes nodeneedrestartexception connecttoseednodescannotbechangedmustdisableopennetorreboot opennet config register enabled false 0 true true node opennet enabled node opennet enabled long new boolean callback override public boolean get synchronized node this return opennet null opennetconfig opennetenabled opennetenabledlong booleancallback override public void set boolean val throws invalid config value exception opennet manager o synchronized node this if val opennet null return if val try o opennet new opennet manager node this opennet crypto config system current time millis is allowed to connect to seednodes catch node init exception e opennet null throw new invalid config value exception e get message else o opennet opennet null if val o start else o stop true ip detector ip detector manager notify port change get public interface ports invalidconfigvalueexception opennetmanager opennetmanager opennetcryptoconfig currenttimemillis isallowedtoconnecttoseednodes nodeinitexception invalidconfigvalueexception getmessage ipdetector ipdetectormanager notifyportchange getpublicinterfaceports opennet config register max opennet peers 20 1 true false node max opennet peers node max opennet peers long new int callback override public integer get return max opennet peers opennetconfig maxopennetpeers maxopennetpeers maxopennetpeerslong intcallback maxopennetpeers override public void set integer input max opennet peers throws invalid config value exception if input max opennet peers 0 throw new invalid config value exception l10n must be positive if input max opennet peers 20 throw new invalid config value exception l10n max opennet peers must be twenty or less max opennet peers input max opennet peers inputmaxopennetpeers invalidconfigvalueexception inputmaxopennetpeers invalidconfigvalueexception mustbepositive inputmaxopennetpeers invalidconfigvalueexception maxopennetpeersmustbetwentyorless maxopennetpeers inputmaxopennetpeers public void on change network threat level old level network threat level new level if new level network threat level high new level network threat level maximum opennet manager om synchronized node this om opennet if om null opennet null if om null om stop true ip detector ip detector manager notify port change get public interface ports else if new level network threat level normal new level network threat level low opennet manager o null synchronized node this if opennet null try o opennet new opennet manager node this opennet crypto config system current time millis is allowed to connect to seednodes catch node init exception e opennet null logger error this unable to enable opennet e e client core alerts register new simple user alert false l10n enable opennet failed title l10n enable opennet failed message e get localized message l10n enable opennet failed message e get localized message user alert error if o null o start ip detector ip detector manager notify port change get public interface ports node this config store onchange network_threat_level oldlevel network_threat_level newlevel newlevel network_threat_level newlevel network_threat_level opennetmanager ipdetector ipdetectormanager notifyportchange getpublicinterfaceports newlevel network_threat_level newlevel network_threat_level opennetmanager opennetmanager opennetcryptoconfig currenttimemillis isallowedtoconnecttoseednodes nodeinitexception clientcore simpleuseralert enableopennetfailedtitle enableopennetfailed getlocalizedmessage enableopennetfailed getlocalizedmessage useralert ipdetector ipdetectormanager notifyportchange getpublicinterfaceports opennet config register accept seed connections false 2 true true node accept seed connections short node accept seed connections new boolean callback override public boolean get return accept seed connections opennetconfig acceptseedconnections acceptseedconnectionsshort acceptseedconnections booleancallback acceptseedconnections override public void set boolean val throws invalid config value exception accept seed connections val invalidconfigvalueexception acceptseedconnections override public boolean get synchronized node this return pass opennet refs through darknet passopennetrefsthroughdarknet override public void set boolean val throws invalid config value exception synchronized node this pass opennet refs through darknet val invalidconfigvalueexception passopennetrefsthroughdarknet node config register extra peer data dir new file node dir extra peer data get darknet port number to string sort order true true can t be changed on the fly also for packages node extra peer dir node extra peer dir long new string callback override public string get return extra peer data dir get path nodeconfig extrapeerdatadir nodedir getdarknetportnumber tostring sortorder extrapeerdir extrapeerdirlong stringcallback extrapeerdatadir getpath override public void set string val throws invalid config value exception if extra peer data dir equals new file val return fixme throw new invalid config value exception moving extra peer data directory on the fly not supported at present invalidconfigvalueexception extrapeerdatadir invalidconfigvalueexception throw new invalid config value exception moving extra peer data directory on the fly not supported at present override public boolean is read only return true invalidconfigvalueexception isreadonly override public boolean get synchronized node this return store force big shrinks storeforcebigshrinks override public void set boolean val throws invalid config value exception synchronized node this store force big shrinks val invalidconfigvalueexception storeforcebigshrinks new long callback override public long get return max total datastore size longcallback maxtotaldatastoresize override public void set long store size throws invalid config value exception if store size 0 store size 32 1024 1024 throw new invalid config value exception l10n invalid store size long new max store keys store size size per key if new max store keys max total keys return update each datastore synchronized node this max total datastore size store size max total keys new max store keys max store keys max total keys 2 max cache keys max total keys max store keys try chk datastore set max keys max store keys store force big shrinks chk datacache set max keys max cache keys store force big shrinks pub key datastore set max keys max store keys store force big shrinks pub key datacache set max keys max cache keys store force big shrinks ssk datastore set max keys max store keys store force big shrinks ssk datacache set max keys max cache keys store force big shrinks catch io exception e fixme we need to be able to tell the user logger error this caught e resizing the datastore e system err println caught e resizing the datastore e print stack trace catch database exception e logger error this caught e resizing the datastore e system err println caught e resizing the datastore e print stack trace perhaps a bit hackish seems like this should be near it s definition in node stats node stats avg store location change max reports int max store keys node stats avg cache location change max reports int max cache keys storesize invalidconfigvalueexception storesize storesize invalidconfigvalueexception invalidstoresize newmaxstorekeys storesize sizeperkey newmaxstorekeys maxtotalkeys maxtotaldatastoresize storesize maxtotalkeys newmaxstorekeys maxstorekeys maxtotalkeys maxcachekeys maxtotalkeys maxstorekeys chkdatastore setmaxkeys maxstorekeys storeforcebigshrinks chkdatacache setmaxkeys maxcachekeys storeforcebigshrinks pubkeydatastore setmaxkeys maxstorekeys storeforcebigshrinks pubkeydatacache setmaxkeys maxcachekeys storeforcebigshrinks sskdatastore setmaxkeys maxstorekeys storeforcebigshrinks sskdatacache setmaxkeys maxcachekeys storeforcebigshrinks ioexception printstacktrace databaseexception printstacktrace nodestats nodestats avgstorelocation changemaxreports maxstorekeys nodestats avgcachelocation changemaxreports maxcachekeys override public integer get if cached bloom filter size null cached bloom filter size store bloom filter size return cached bloom filter size cachedbloomfiltersize cachedbloomfiltersize storebloomfiltersize cachedbloomfiltersize override public void set integer val throws invalid config value exception node need restart exception cached bloom filter size val throw new node need restart exception store bloom filter size cannot be changed on the fly invalidconfigvalueexception nodeneedrestartexception cachedbloomfiltersize nodeneedrestartexception override public boolean is read only return salt hash equals store type isreadonly storetype override public boolean get if cached bloom filter counting null cached bloom filter counting store bloom filter counting return cached bloom filter counting cachedbloomfiltercounting cachedbloomfiltercounting storebloomfiltercounting cachedbloomfiltercounting override public void set boolean val throws invalid config value exception node need restart exception cached bloom filter counting val throw new node need restart exception store bloom filter type cannot be changed on the fly invalidconfigvalueexception nodeneedrestartexception cachedbloomfiltercounting nodeneedrestartexception override public boolean is read only return salt hash equals store type isreadonly storetype node config register store salt hash resize on start true sort order true false node store salt hash resize on start node store salt hash resize on start long new boolean callback override public boolean get return store salt hash resize on start nodeconfig storesalthashresizeonstart sortorder storesalthashresizeonstart storesalthashresizeonstartlong booleancallback storesalthashresizeonstart override public void set boolean val throws invalid config value exception node need restart exception store salt hash resize on start val invalidconfigvalueexception nodeneedrestartexception storesalthashresizeonstart node config register store dir datastore sort order true true node store directory node store directory long new string callback override public string get return store dir get path nodeconfig storedir sortorder storedirectory storedirectorylong stringcallback storedir getpath override public void set string val throws invalid config value exception if store dir equals new file val return fixme throw new invalid config value exception moving datastore on the fly not supported at present invalidconfigvalueexception storedir invalidconfigvalueexception throw new invalid config value exception moving datastore on the fly not supported at present override public boolean is read only return true invalidconfigvalueexception isreadonly node config register store preallocate true sort order true false node store preallocate node store preallocate long new boolean callback override public boolean get return store preallocate nodeconfig storepreallocate sortorder storepreallocate storepreallocatelong booleancallback storepreallocate override public void set boolean val throws invalid config value exception node need restart exception store preallocate val if store type equals salt hash salted hash freenet store chk datastore get store set preallocate val salted hash freenet store chk datacache get store set preallocate val salted hash freenet store pub key datastore get store set preallocate val salted hash freenet store pub key datacache get store set preallocate val salted hash freenet store ssk datastore get store set preallocate val salted hash freenet store ssk datacache get store set preallocate val invalidconfigvalueexception nodeneedrestartexception storepreallocate storetype saltedhashfreenetstore chkdatastore getstore setpreallocate saltedhashfreenetstore chkdatacache getstore setpreallocate saltedhashfreenetstore pubkeydatastore getstore setpreallocate saltedhashfreenetstore pubkeydatacache getstore setpreallocate saltedhashfreenetstore sskdatastore getstore setpreallocate saltedhashfreenetstore sskdatacache getstore setpreallocate public void on change physical threat level old level physical threat level new level try if new level physical threat level low node config set store preallocate false else node config set store preallocate true catch node need restart exception e ignore catch invalid config value exception e ignore onchange physical_threat_level oldlevel physical_threat_level newlevel newlevel physical_threat_level nodeconfig storepreallocate nodeconfig storepreallocate nodeneedrestartexception invalidconfigvalueexception new long callback override public long get return database max memory longcallback databasemaxmemory override public void set long val throws invalid config value exception if val 0 throw new invalid config value exception l10n must be positive else long max heap memory runtime get runtime max memory there are some jv ms for example libgcj 4 1 1 whose runtime max memory does not work if max heap memory long max value val 80 max heap memory 100 throw new invalid config value exception l10n store max mem too high env mutable config set cache size val try store environment set mutable config env mutable config catch database exception e throw new invalid config value exception l10n error applying config error e get localized message database max memory val invalidconfigvalueexception invalidconfigvalueexception mustbepositive maxheapmemory getruntime maxmemory jvms maxmemory maxheapmemory max_value maxheapmemory invalidconfigvalueexception storemaxmemtoohigh envmutableconfig setcachesize storeenvironment setmutableconfig envmutableconfig databaseexception invalidconfigvalueexception errorapplyingconfig getlocalizedmessage databasemaxmemory override public html node gethtml text html node div new html node div div add child l10n get string node store salt hash migrated html node ul div add child ul for string type new string chk pubkey ssk for string storecache new string store store keys store lru cache cache keys cache lru file f new file store dir type suffix storecache if f exists ul add child li f get absolute path file db dir new file store dir database suffix if db dir exists ul add child li db dir get absolute path return div htmlnode gethtmltext htmlnode htmlnode addchild getstring storesalthashmigrated htmlnode addchild storedir addchild getabsolutepath dbdir storedir dbdir addchild dbdir getabsolutepath override public string get text string builder sb new string builder sb append l10n get string node store salt hash migrated n for string type new string chk pubkey ssk for string storecache new string store store keys store lru cache cache keys cache lru file f new file store dir type suffix storecache if f exists sb append sb append f get absolute path sb append n file db dir new file store dir database suffix if db dir exists sb append sb append db dir get absolute path sb append n return sb to string gettext stringbuilder stringbuilder getstring storesalthashmigrated storedir getabsolutepath dbdir storedir dbdir dbdir getabsolutepath tostring override public boolean is valid return new file store dir chk suffix store exists new file store dir chk suffix store keys exists new file store dir chk suffix store lru exists new file store dir chk suffix cache exists new file store dir chk suffix cache keys exists new file store dir chk suffix cache lru exists new file store dir pubkey suffix store exists new file store dir pubkey suffix store keys exists new file store dir pubkey suffix store lru exists new file store dir pubkey suffix cache exists new file store dir pubkey suffix cache keys exists new file store dir pubkey suffix cache lru exists new file store dir ssk suffix store exists new file store dir ssk suffix store keys exists new file store dir ssk suffix store lru exists new file store dir ssk suffix cache exists new file store dir ssk suffix cache keys exists new file store dir ssk suffix cache lru exists new file store dir database suffix exists isvalid storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir storedir override public void on dismiss ondismiss override public boolean user can dismiss return true usercandismiss private void init salt hashfs final string suffix throws node init exception store environment null env mutable config null try int bloom size store bloom filter size if bloom size 1 bloom size int math min max total datastore size 2048 integer max value int bloom filter size inm store bloom filter counting bloom size 6 4 bloom size 6 6 8 6 to make size different trigger rebuild logger normal this initializing chk datastore system out println initializing chk datastore max store keys keys chk datastore new chk store salted hash freenet store chk datafs salted hash freenet store construct store dir chk store chk datastore random max store keys bloom filter size inm store bloom filter counting shutdown hook store preallocate store salt hash resize on start logger normal this initializing chk datacache system out println initializing chk datacache max cache keys max cache keys keys chk datacache new chk store salted hash freenet store chk cachefs salted hash freenet store construct store dir chk cache chk datacache random max cache keys bloom filter size inm store bloom filter counting shutdown hook store preallocate store salt hash resize on start logger normal this initializing pub key datastore system out println initializing pub key datastore pub key datastore new pubkey store salted hash freenet store pubkey datafs salted hash freenet store construct store dir pubkey store pub key datastore random max store keys bloom filter size inm store bloom filter counting shutdown hook store preallocate store salt hash resize on start logger normal this initializing pub key datacache system out println initializing pub key datacache max cache keys keys pub key datacache new pubkey store salted hash freenet store pubkey cachefs salted hash freenet store construct store dir pubkey cache pub key datacache random max cache keys bloom filter size inm store bloom filter counting shutdown hook store preallocate store salt hash resize on start logger normal this initializing ssk datastore system out println initializing ssk datastore ssk datastore new ssk store this salted hash freenet store ssk datafs salted hash freenet store construct store dir ssk store ssk datastore random max store keys bloom filter size inm store bloom filter counting shutdown hook store preallocate store salt hash resize on start logger normal this initializing ssk datacache system out println initializing ssk datacache max cache keys keys ssk datacache new ssk store this salted hash freenet store ssk cachefs salted hash freenet store construct store dir ssk cache ssk datacache random max cache keys bloom filter size inm store bloom filter counting shutdown hook store preallocate store salt hash resize on start file migration file new file store dir migrated if migration file exists chk datafs migration from new file store dir chk suffix store new file store dir chk suffix store keys chk cachefs migration from new file store dir chk suffix cache new file store dir chk suffix cache keys pubkey datafs migration from new file store dir pubkey suffix store new file store dir pubkey suffix store keys pubkey cachefs migration from new file store dir pubkey suffix cache new file store dir pubkey suffix cache keys ssk datafs migration from new file store dir ssk suffix store new file store dir ssk suffix store keys ssk cachefs migration from new file store dir ssk suffix cache new file store dir ssk suffix cache keys migration file create new file catch io exception e system err println could not open store e e print stack trace throw new node init exception node init exception exit store other e get message initsalthashfs nodeinitexception storeenvironment envmutableconfig bloomsize storebloomfiltersize bloomsize bloomsize maxtotaldatastoresize max_value bloomfiltersizeinm storebloomfiltercounting bloomsize bloomsize maxstorekeys chkdatastore chkstore saltedhashfreenetstore chkdatafs saltedhashfreenetstore storedir chkdatastore maxstorekeys bloomfiltersizeinm storebloomfiltercounting shutdownhook storepreallocate storesalthashresizeonstart maxcachekeys maxcachekeys chkdatacache chkstore saltedhashfreenetstore chkcachefs saltedhashfreenetstore storedir chkdatacache maxcachekeys bloomfiltersizeinm storebloomfiltercounting shutdownhook storepreallocate storesalthashresizeonstart pubkey pubkey pubkeydatastore pubkeystore saltedhashfreenetstore pubkeydatafs saltedhashfreenetstore storedir pubkeydatastore maxstorekeys bloomfiltersizeinm storebloomfiltercounting shutdownhook storepreallocate storesalthashresizeonstart pubkey pubkey maxcachekeys pubkeydatacache pubkeystore saltedhashfreenetstore pubkeycachefs saltedhashfreenetstore storedir pubkeydatacache maxcachekeys bloomfiltersizeinm storebloomfiltercounting shutdownhook storepreallocate storesalthashresizeonstart sskdatastore sskstore saltedhashfreenetstore sskdatafs saltedhashfreenetstore storedir sskdatastore maxstorekeys bloomfiltersizeinm storebloomfiltercounting shutdownhook storepreallocate storesalthashresizeonstart maxcachekeys sskdatacache sskstore saltedhashfreenetstore sskcachefs saltedhashfreenetstore storedir sskdatacache maxcachekeys bloomfiltersizeinm storebloomfiltercounting shutdownhook storepreallocate storesalthashresizeonstart migrationfile storedir migrationfile chkdatafs migrationfrom storedir storedir chkcachefs migrationfrom storedir storedir pubkeydatafs migrationfrom storedir storedir pubkeycachefs migrationfrom storedir storedir sskdatafs migrationfrom storedir storedir sskcachefs migrationfrom storedir storedir migrationfile createnewfile ioexception printstacktrace nodeinitexception nodeinitexception exit_store_other getmessage private void initbdbfs final string suffix throws node init exception setup datastores final environment config env config berkeleydb freenet store getbdb config final file db dir new file store dir database get darknet port number db dir mkdirs final file reconstruct file new file db dir reconstruct environment env null environment mutable config mutable config this can take some time system out println starting database try if reconstruct file exists reconstruct file delete throw new database exception auto recovery can take a long time wrapper manager signal starting 60 60 1000 env new environment db dir env config mutable config env get config catch final database exception e close the database if env null try env close catch final throwable t system err println error closing database t after e t print stack trace delete the database logs system err println deleting old database log files final file files db dir list files for int i 0 i files length i final string name files i get name to lower case if name ends with jdb name equals je lck if files i delete system err println failed to delete old database log file files i system err println recovering the database is broken we will have to recover from scratch try env new environment db dir env config mutable config env get config catch final database exception e1 system err println could not open store e1 e1 print stack trace system err println previous error was tried deleting database and retrying e e print stack trace throw new node init exception node init exception exit store other e1 get message store environment env env mutable config mutable config shutdown hook add late job new thread override public void run try store environment close system err println successfully closed all datastores catch final throwable t system err println caught t closing environment t print stack trace env mutable config set cache size database max memory http www oracle com technology products berkeley db faq je faq html 35 try store environment set mutable config env mutable config catch final database exception e system err println could not set the database configuration e e print stack trace throw new node init exception node init exception exit store other e get message try logger normal this initializing chk datastore system out println initializing chk datastore max store keys keys chk datastore new chk store berkeleydb freenet store construct store dir true suffix max store keys store type chk store environment shutdown hook reconstruct file chk datastore random logger normal this initializing chk datacache system out println initializing chk datacache max cache keys max cache keys keys chk datacache new chk store berkeleydb freenet store construct store dir false suffix max cache keys store type chk store environment shutdown hook reconstruct file chk datacache random logger normal this initializing pub key datastore system out println initializing pub key datastore pub key datastore new pubkey store berkeleydb freenet store construct store dir true suffix max store keys store type pubkey store environment shutdown hook reconstruct file pub key datastore random logger normal this initializing pub key datacache system out println initializing pub key datacache max cache keys keys pub key datacache new pubkey store berkeleydb freenet store construct store dir false suffix max cache keys store type pubkey store environment shutdown hook reconstruct file pub key datacache random logger normal this initializing ssk datastore system out println initializing ssk datastore ssk datastore new ssk store this berkeleydb freenet store construct store dir true suffix max store keys store type ssk store environment shutdown hook reconstruct file ssk datastore random logger normal this initializing ssk datacache system out println initializing ssk datacache max cache keys keys ssk datacache new ssk store this berkeleydb freenet store construct store dir false suffix max store keys store type ssk store environment shutdown hook reconstruct file ssk datacache random catch final file not found exception e1 final string msg could not open datastore e1 logger error this msg e1 system err println msg throw new node init exception node init exception exit store file not found msg catch final io exception e1 final string msg could not open datastore e1 logger error this msg e1 system err println msg e1 print stack trace throw new node init exception node init exception exit store ioexception msg catch final database exception e1 try reconstruct file create new file catch final io exception e system err println cannot create reconstruct file reconstruct file e store will not be reconstructed e print stack trace final string msg could not open datastore due to corruption will attempt to reconstruct on next startup e1 logger error this msg e1 system err println msg e1 print stack trace throw new node init exception node init exception exit store reconstruct msg nodeinitexception environmentconfig envconfig berkeleydbfreenetstore getbdbconfig dbdir storedir getdarknetportnumber dbdir reconstructfile dbdir environmentmutableconfig mutableconfig reconstructfile reconstructfile databaseexception wrappermanager signalstarting dbdir envconfig mutableconfig getconfig databaseexception printstacktrace dbdir listfiles getname tolowercase endswith dbdir envconfig mutableconfig getconfig databaseexception printstacktrace printstacktrace nodeinitexception nodeinitexception exit_store_other getmessage storeenvironment envmutableconfig mutableconfig shutdownhook addlatejob storeenvironment printstacktrace envmutableconfig setcachesize databasemaxmemory je_faq storeenvironment setmutableconfig envmutableconfig databaseexception printstacktrace nodeinitexception nodeinitexception exit_store_other getmessage maxstorekeys chkdatastore chkstore berkeleydbfreenetstore storedir maxstorekeys storetype storeenvironment shutdownhook reconstructfile chkdatastore maxcachekeys maxcachekeys chkdatacache chkstore berkeleydbfreenetstore storedir maxcachekeys storetype storeenvironment shutdownhook reconstructfile chkdatacache pubkey pubkey pubkeydatastore pubkeystore berkeleydbfreenetstore storedir maxstorekeys storetype storeenvironment shutdownhook reconstructfile pubkeydatastore pubkey pubkey maxcachekeys pubkeydatacache pubkeystore berkeleydbfreenetstore storedir maxcachekeys storetype storeenvironment shutdownhook reconstructfile pubkeydatacache sskdatastore sskstore berkeleydbfreenetstore storedir maxstorekeys storetype storeenvironment shutdownhook reconstructfile sskdatastore maxcachekeys sskdatacache sskstore berkeleydbfreenetstore storedir maxstorekeys storetype storeenvironment shutdownhook reconstructfile sskdatacache filenotfoundexception nodeinitexception nodeinitexception exit_store_file_not_found ioexception printstacktrace nodeinitexception nodeinitexception exit_store_ioexception databaseexception reconstructfile createnewfile ioexception reconstructfile printstacktrace printstacktrace nodeinitexception nodeinitexception exit_store_reconstruct shutdown hook add late job new thread override public void run try store environment close system err println successfully closed all datastores catch final throwable t system err println caught t closing environment t print stack trace shutdownhook addlatejob storeenvironment printstacktrace public void start boolean no swaps throws node init exception dispatcher start node stats must be before usm dnsr start peers start must be before usm node stats start uptime start failure table start darknet crypto start if opennet null opennet start ps start node stats usm start ps if is using wrapper logger normal this using wrapper correctly node starter system out println using wrapper correctly node starter else logger error this not using wrapper at least not correctly your freenet ext jar http downloads freenetproject org alpha freenet ext jar and or wrapper conf https emu freenetproject org svn trunk apps installer installclasspath config wrapper conf need to be updated system out println not using wrapper at least not correctly your freenet ext jar http downloads freenetproject org alpha freenet ext jar and or wrapper conf https emu freenetproject org svn trunk apps installer installclasspath config wrapper conf need to be updated logger normal this freenet 0 7 build version build number r version cvs revision system out println freenet 0 7 build version build number r version cvs revision logger normal this fnp port is on darknet crypto get bind to get darknet port number system out println fnp port is on darknet crypto get bind to get darknet port number start services sub config plugin manager config new sub config pluginmanager3 config plugin manager3 new freenet plugin new plugin manager plugin manager config ip detector start start sending swaps lm start sender node updater try logger normal this starting the node updater node updater start catch exception e e print stack trace throw new node init exception node init exception exit could not start updater could not start updater e start testnet handler if testnet handler null testnet handler start todo make sure that this is called before any instances of http filter are created http filter uses check forgcj char conversion bug which returns the value of the static variable jvm hasgcj char conversion bug and this is initialized in the following function if this is not possible then create a separate function to check for the gcj bug and call this function earlier check for eviljvm bugs todo implement a required version if needed if node updater is enabled node starter recommended ext build number node starter ext build number client core alerts register new ext old age user alert else if node starter ext build number 1 client core alerts register new ext old age user alert if native thread has enough nice levels client core alerts register new not enough nice levels user alert this client core start config start deaduid checker after everything has been created write the config file back to disk if config instanceof freenet file persistent config freenet file persistent config cfg freenet file persistent config config cfg finished init this ps cfg set has node started config store process any data in the extra peer data directory peers read extra peer data logger normal this started node has started true noswaps nodeinitexception nodestats nodestats failuretable darknetcrypto nodestats isusingwrapper nodestarter nodestarter buildnumber cvsrevision buildnumber cvsrevision darknetcrypto getbindto getdarknetportnumber darknetcrypto getbindto getdarknetportnumber subconfig pluginmanagerconfig subconfig pluginmanager3 plugin_new pluginmanager pluginmanagerconfig ipdetector startsender nodeupdater printstacktrace nodeinitexception nodeinitexception exit_could_not_start_updater testnethandler testnethandler httpfilter httpfilter checkforgcjcharconversionbug jvmhasgcjcharconversionbug checkforeviljvmbugs nodeupdater isenabled nodestarter recommended_ext_build_number nodestarter extbuildnumber clientcore extoldageuseralert nodestarter extbuildnumber clientcore extoldageuseralert nativethread has_enough_nice_levels clientcore notenoughnicelevelsuseralert clientcore startdeaduidchecker freenetfilepersistentconfig freenetfilepersistentconfig freenetfilepersistentconfig finishedinit sethasnodestarted readextrapeerdata hasstarted private void check for eviljvm bugs now check whether we are likely to get the eviljvm bug if we are running a sun or blackdown jvm on linux and ld assume kernel is not set then we are string jvm vendor system get property java vm vendor string jvm spec vendor system get property java specification vendor string jvm version system get property java version string os name system get property os name string os version system get property os version if logminor logger minor this jvm vendor jvm vendor jvm version jvm version os name os name os version os version if jvm vendor starts with sun jvm vendor starts with the freebsd foundation jvm spec vendor starts with sun sun bugs spurious oo ms http bugs sun com bugdatabase view bug do bug id 4855795 http bugs sun com bugdatabase view bug do bug id 2138757 http bugs sun com bugdatabase view bug do bug id 2138759 fixed in 1 5 0 10 and 1 4 2 13 boolean is142 jvm version starts with 1 4 2 boolean is150 jvm version starts with 1 5 0 boolean spuriousoo ms false if is142 is150 string split jvm version split string second part split 1 if second part index of 1 split second part split second part split 0 int subver integer parse int second part logger minor this jvm version jvm version subver subver from second part is142 is142 is150 is150 if is142 if subver 13 spuriousoo ms true else if is150 if subver 10 spuriousoo ms true if spuriousoo ms system err println please upgrade to at least sun jvm 1 4 2 13 1 5 0 10 or 1 6 recommended this version is buggy and may cause spurious out of memory errors client core alerts register new abstract user alert false null null null null user alert error true null false null override public html node gethtml text html node n new html node div l10n addl10n substitution n node buggyjvm with link new string link link version new string a href checked http http bugs sun com bugdatabase view bug do bug id 4855795 a html encoder encode system get property java version return n override public string get text return l10n buggyjvm version system get property java version override public string get title return l10n buggyjvm title override public void is valid boolean validity ignore override public string get short text return l10n buggyjvm short version system get property java version else if jvm vendor starts with apple jvm vendor starts with apple note that sun does not produce v ms for the macintosh operating system dont ask the user to find one else if jvm vendor starts with free software foundation try jvm version system get property java version split 0 replace all int jvm version int integer parse int jvm version if jvm version int 422 jvm version int 100 make sure that no bogus values cause true jvm hasgcj char conversion bug true catch throwable t logger error this gcj version check is broken t client core alerts register new simple user alert true l10n not using sunvm title l10n not using sunvm new string vendor version new string jvm vendor jvm version l10n not using sunvm short user alert warning if is using wrapper client core alerts register new simple user alert true l10n not using wrapper title l10n not using wrapper l10n not using wrapper short user alert warning checkforeviljvmbugs eviljvmbug ld_assume_kernel jvmvendor getproperty jvmspecvendor getproperty jvmversion getproperty osname getproperty osversion getproperty jvmvendor jvmversion osname osversion jvmvendor startswith jvmvendor startswith jvmspecvendor startswith ooms view_bug bug_id view_bug bug_id view_bug bug_id 0_10 2_13 jvmversion startswith 2_ jvmversion startswith 0_ spuriousooms jvmversion _ secondpart secondpart indexof secondpart secondpart parseint secondpart jvmversion secondpart spuriousooms spuriousooms spuriousooms 2_13 0_10 outofmemoryerrors clientcore abstractuseralert useralert htmlnode gethtmltext htmlnode htmlnode addl10nsubstitution buggyjvmwithlink _checked_http_ view_bug bug_id htmlencoder getproperty gettext getproperty gettitle buggyjvmtitle isvalid getshorttext buggyjvmshort getproperty jvmvendor startswith jvmvendor startswith vms jvmvendor startswith jvmversion getproperty replaceall jvmversionint parseint jvmversion jvmversionint jvmversionint jvmhasgcjcharconversionbug clientcore simpleuseralert notusingsunvmtitle notusingsunvm jvmvendor jvmversion notusingsunvmshort useralert isusingwrapper clientcore simpleuseralert notusingwrappertitle notusingwrapper notusingwrappershort useralert override public html node gethtml text html node n new html node div l10n addl10n substitution n node buggyjvm with link new string link link version new string a href checked http http bugs sun com bugdatabase view bug do bug id 4855795 a html encoder encode system get property java version return n htmlnode gethtmltext htmlnode htmlnode addl10nsubstitution buggyjvmwithlink _checked_http_ view_bug bug_id htmlencoder getproperty override public string get text return l10n buggyjvm version system get property java version gettext getproperty override public string get title return l10n buggyjvm title gettitle buggyjvmtitle override public void is valid boolean validity ignore isvalid override public string get short text return l10n buggyjvm short version system get property java version getshorttext buggyjvmshort getproperty public static boolean check forgcj char conversion bug return jvm hasgcj char conversion bug should be initialized on early startup checkforgcjcharconversionbug jvmhasgcjcharconversionbug private string l10n string key return l10n get string node key getstring private string l10n string key string pattern string value return l10n get string node key pattern value getstring private string l10n string key string pattern string value return l10n get string node key pattern value getstring export volatile data about the node as a simple field set public simple field set export volatile field set return node stats export volatile field set simplefieldset simplefieldset exportvolatilefieldset nodestats exportvolatilefieldset do a routed ping of another node on the network by its location param loc2 the location of the other node to ping it must match exactly return the number of hops it took to find the node if it was found otherwise 1 public int routed ping double loc2 byte node identity long uid random next long int initialx random next int message m dmt createfnp routed ping uid loc2 maxhtl initialx node identity logger normal this message m dispatcher handle routed m null fixme might be rejected message filter mf1 message filter create set field dmt uid uid set type dmt fnp routed pong set timeout 5000 try message filter mf2 message filter create set field dmt uid uid set type dmt fnp routed rejected set timeout 5000 ignore rejected let it be retried on other peers m usm wait for mf1 or mf2 null catch disconnected exception e logger normal this disconnected in waiting for pong return 1 if m null return 1 if m get spec dmt fnp routed rejected return 1 return m get int dmt counter initialx routedping nodeidentity nextlong nextint createfnproutedping nodeidentity handlerouted messagefilter messagefilter setfield settype fnproutedpong settimeout messagefilter messagefilter setfield settype fnproutedrejected settimeout waitfor disconnectedexception getspec fnproutedrejected getint check the datastore then if the key is not in the store check whether another node is requesting the same key at the same htl and if all else fails create a new request sender for the key htl param closest location the closest location to the key so far param local only if true only check the datastore return a chk block if the data is in the store otherwise a request sender unless the htl is 0 in which case null request sender public object make request sender key key short htl long uid peer node source boolean local only boolean cache boolean ignore store boolean offers only if logminor logger minor this make request sender key htl uid source on get darknet port number in store key block chk null if ignore store if key instanceof nodechk chk fetch nodechk key cache else if key instanceof nodessk nodessk k nodessk key dsa public key pub key k get pub key if pub key null pub key get key k get pub key hash if logminor logger minor this fetched pubkey pub key try k set pub key pub key catch ssk verify exception e logger error this error setting pubkey e e if pub key null if logminor logger minor this got pubkey pub key chk fetch nodessk key cache else if logminor logger minor this not found because no pubkey uid else throw new illegal state exception unknown key type key get class if chk null probably somebody waiting for it trip it if client core null client core request starters null if chk instanceof chk block client core request starters chk fetch scheduler trip pending key chk else client core request starters ssk fetch scheduler trip pending key chk failure table on found chk return chk if local only return null if logminor logger minor this not in store locally transfer coalescing match key only as htl irrelevant request sender sender null synchronized transferring request senders sender transferring request senders get key if sender null if logminor logger minor this data already being transferred sender return sender htl 0 don t search further if htl 0 if logminor logger minor this no htl return null synchronized request senders no request coalescing given that htl can be reset also if we had no htl request coalescing causes deadlocks request a joins request b which then joins request a there are various convoluted fixes but imho the best solution long term is to kill the request recently failed with 0 timeout so it doesn t prevent future requests and send it the data through ulp rs if it is found sender new request sender key null htl uid this source offers only request sender adds itself to request senders sender start if logminor logger minor this created new sender sender return sender requestsender closestlocation localonly chkblock requestsender requestsender makerequestsender peernode localonly ignorestore offersonly makerequestsender getdarknetportnumber keyblock ignorestore dsapublickey pubkey getpubkey pubkey pubkey getkey getpubkeyhash pubkey setpubkey pubkey sskverifyexception pubkey pubkey illegalstateexception getclass clientcore clientcore requeststarters chkblock clientcore requeststarters chkfetchscheduler trippendingkey clientcore requeststarters sskfetchscheduler trippendingkey failuretable onfound localonly requestsender transferringrequestsenders transferringrequestsenders requestsenders recentlyfailed ulprs requestsender offersonly requestsender requestsenders final long uid keyhtl pair key key short htl long uid this key key this htl htl this uid uid keyhtlpair override public boolean equals object o if o instanceof keyhtl pair keyhtl pair p keyhtl pair o return p key equals key p htl htl p uid uid else return false keyhtlpair keyhtlpair keyhtlpair override public int hash code return key hash code htl int uid hashcode hashcode override public string to string return key to string htl uid tostring tostring add a request sender to our hash map public void add request sender key key short htl request sender sender synchronized request senders keyhtl pair kh new keyhtl pair key htl sender uid if request senders contains key kh request sender rs request senders get kh logger error this add request sender keyhtl pair kh already in request senders as rs and you want to add sender return request senders put kh sender requestsender hashmap addrequestsender requestsender requestsenders keyhtlpair keyhtlpair requestsenders containskey requestsender requestsenders addrequestsender keyhtlpair requestsenders requestsenders add a any insert sender to our hash map public void add insert sender key key short htl any insert sender sender synchronized insert senders keyhtl pair kh new keyhtl pair key htl sender getuid if insert senders contains key kh any insert sender is insert senders get kh logger error this add insert sender keyhtl pair kh already in insert senders as is and you want to add sender return insert senders put kh sender anyinsertsender hashmap addinsertsender anyinsertsender insertsenders keyhtlpair keyhtlpair insertsenders containskey anyinsertsender insertsenders addinsertsender keyhtlpair insertsenders insertsenders add a transferring request sender to our hash map public void add transferring sender nodechk key request sender sender synchronized transferring request senders transferring request senders put key sender requestsender hashmap addtransferringsender requestsender transferringrequestsenders transferringrequestsenders void add transferring request handler long id synchronized transferring request handlers transferring request handlers add id addtransferringrequesthandler transferringrequesthandlers transferringrequesthandlers void remove transferring request handler long id synchronized transferring request handlers transferring request handlers remove id removetransferringrequesthandler transferringrequesthandlers transferringrequesthandlers public key block fetch key key boolean dont promote if key instanceof nodessk return fetch nodessk key dont promote else if key instanceof nodechk return fetch nodechk key dont promote else throw new illegal argument exception keyblock dontpromote dontpromote dontpromote illegalargumentexception public ssk block fetch nodessk key boolean dont promote if logminor dump store hits try double loc key to normalized double double dist location distance lm get location loc node stats avg request location report loc ssk block block ssk datastore fetch key dont promote if block null node stats avg store success report loc if dist node stats furthest store success node stats furthest store success dist return block block ssk datacache fetch key dont promote if block null node stats avg cache success report loc if dist node stats furthest cache success node stats furthest cache success dist return block catch io exception e logger error this cannot fetch data e e return null sskblock dontpromote dumpstorehits tonormalizeddouble getlocation nodestats avgrequestlocation sskblock sskdatastore dontpromote nodestats avgstoresuccess nodestats furtheststoresuccess nodestats furtheststoresuccess sskdatacache dontpromote nodestats avgcachesuccess nodestats furthestcachesuccess nodestats furthestcachesuccess ioexception public chk block fetch nodechk key boolean dont promote if logminor dump store hits try double loc key to normalized double double dist location distance lm get location loc node stats avg request location report loc chk block block chk datastore fetch key dont promote if block null node stats avg store success report loc if dist node stats furthest store success node stats furthest store success dist return block block chk datacache fetch key dont promote if block null node stats avg cache success report loc if dist node stats furthest cache success node stats furthest cache success dist return block catch io exception e logger error this cannot fetch data e e return null chkblock dontpromote dumpstorehits tonormalizeddouble getlocation nodestats avgrequestlocation chkblock chkdatastore dontpromote nodestats avgstoresuccess nodestats furtheststoresuccess nodestats furtheststoresuccess chkdatacache dontpromote nodestats avgcachesuccess nodestats furthestcachesuccess nodestats furthestcachesuccess ioexception public chk store get chk datacache return chk datacache chkstore getchkdatacache chkdatacache return chk datacache public chk store get chk datastore return chk datastore chkdatacache chkstore getchkdatastore chkdatastore return chk datastore public long get max total keys return max total keys chkdatastore getmaxtotalkeys maxtotalkeys public void dump store hits long now system current time millis if now time last dumped hits 5000 time last dumped hits now else return logger minor this distribution of hits and misses over stores n chk datastore chk datastore hits chk datastore hits chk datastore misses chk datastore key count nchk datacache chk datacache hits chk datacache hits chk datacache misses chk datacache key count nssk datastore ssk datastore hits ssk datastore hits ssk datastore misses ssk datastore key count nssk datacache ssk datacache hits ssk datacache hits ssk datacache misses ssk datacache key count dumpstorehits currenttimemillis timelastdumpedhits timelastdumpedhits chkdatastore chkdatastore chkdatastore chkdatastore keycount chkdatacache chkdatacache chkdatacache chkdatacache keycount sskdatastore sskdatastore sskdatastore sskdatastore keycount sskdatacache sskdatacache sskdatacache sskdatacache keycount public void store chk block block store block block get key to normalized double chkblock getkey tonormalizeddouble store a datum param deep if true insert to the store as well as the cache do not set this to true unless the store results from an insert and this node is the closest node to the target see the description of chk datastore public void store chk block block double loc boolean deep peers is closer location loc min uptime store key store block deep chkdatastore chkblock iscloserlocation min_uptime_store_key public void store shallow chk block block store block false storeshallow chkblock public void store key block block boolean deep throws key collision exception if block instanceof chk block store chk block block deep else if block instanceof ssk block store ssk block block deep else throw new illegal argument exception unknown keytype keyblock keycollisionexception chkblock chkblock sskblock sskblock illegalargumentexception private void store chk block block boolean deep try double loc block get key to normalized double if deep chk datastore put block node stats avg store location report loc chk datacache put block node stats avg cache location report loc failure table on found block catch io exception e logger error this cannot store data e e catch out of memory error e oom handler handleoom e catch throwable t system err println t t print stack trace logger error this caught t storing data t if client core null client core request starters null client core request starters chk fetch scheduler trip pending key block chkblock getkey tonormalizeddouble chkdatastore nodestats avgstorelocation chkdatacache nodestats avgcachelocation failuretable onfound ioexception outofmemoryerror oomhandler printstacktrace clientcore clientcore requeststarters clientcore requeststarters chkfetchscheduler trippendingkey store the block if this is a sink call for inserts public void store insert ssk block block throws key collision exception store block block get key to normalized double storeinsert sskblock keycollisionexception getkey tonormalizeddouble store only to the cache and not the store called by requests as only inserts cause data to be added to the store public void store shallow ssk block block throws key collision exception store block false storeshallow sskblock keycollisionexception public void store ssk block block boolean deep throws key collision exception try store the pubkey before storing the data otherwise we can get a race condition and end up deleting the ssk data cache key nodessk block get key get pub key hash nodessk block get key get pub key deep if deep ssk datastore put block false ssk datacache put block false failure table on found block catch io exception e logger error this cannot store data e e catch out of memory error e oom handler handleoom e catch key collision exception e throw e catch throwable t system err println t t print stack trace logger error this caught t storing data t if client core null client core request starters null client core request starters ssk fetch scheduler trip pending key block sskblock keycollisionexception cachekey getkey getpubkeyhash getkey getpubkey sskdatastore sskdatacache failuretable onfound ioexception outofmemoryerror oomhandler keycollisionexception printstacktrace clientcore clientcore requeststarters clientcore requeststarters sskfetchscheduler trippendingkey store a datum param deep if true insert to the store as well as the cache do not set this to true unless the store results from an insert and this node is the closest node to the target see the description of chk datastore public void store ssk block block double loc throws key collision exception boolean deep peers is closer location loc min uptime store key store block deep chkdatastore sskblock keycollisionexception iscloserlocation min_uptime_store_key remove a sender from the set of currently transferring senders public void remove transferring sender nodechk key request sender sender synchronized transferring request senders request sender rs request sender transferring request senders remove key if rs sender logger error this removed rs should be sender for key in remove transferring sender since there is no request coalescing we only remove it if it matches and don t complain if it doesn t if transferring request senders get key sender transferring request senders remove key removetransferringsender requestsender transferringrequestsenders requestsender requestsender transferringrequestsenders removetransferringsender transferringrequestsenders transferringrequestsenders remove a request sender from the map public void remove request sender key key short htl request sender sender synchronized request senders keyhtl pair kh new keyhtl pair key htl sender uid request sender rs request sender request senders remove kh if rs sender logger error this removed rs should be sender for key htl in remove request sender since there is no request coalescing we only remove it if it matches and don t complain if it doesn t if request senders get kh sender request senders remove kh request senders notify all requestsender removerequestsender requestsender requestsenders keyhtlpair keyhtlpair requestsender requestsender requestsenders removerequestsender requestsenders requestsenders requestsenders notifyall remove an chk insert sender from the map public void remove insert sender key key short htl any insert sender sender synchronized insert senders keyhtl pair kh new keyhtl pair key htl sender getuid any insert sender is insert senders remove kh if is sender logger error this removed is should be sender for key htl in remove insert sender insert senders notify all chkinsertsender removeinsertsender anyinsertsender insertsenders keyhtlpair keyhtlpair anyinsertsender insertsenders removeinsertsender insertsenders notifyall decrement the htl according to the policy of the given node peer if it is non null or do something else if it is null public short decrementhtl peer node source short htl if source null return source decrementhtl htl otherwise if htl maxhtl htl maxhtl if htl 0 return 0 if htl maxhtl if decrement at max disable probabilisticht ls htl return htl if htl 1 if decrement at min disable probabilisticht ls htl return htl return htl nodepeer peernode decrementatmax disableprobabilistichtls decrementatmin disableprobabilistichtls fetch or create an chk insert sender for a given key htl param key the key to be inserted param htl the current htl we can t coalesce inserts across htl s param uid the uid of the caller s request chain or a new one this is obviously not used if there is already an chk insert sender running param source the node that sent the insert request or null if it originated locally public chk insert sender make insert sender nodechk key short htl long uid peer node source byte headers partially received block prb boolean from store boolean cache if logminor logger minor this make insert sender key htl uid source from store keyhtl pair kh new keyhtl pair key htl uid chk insert sender is null synchronized insert senders is chk insert sender insert senders get kh if is null if logminor logger minor this found is for kh return is if from store cache throw new illegal argument exception from store true but cache false is new chk insert sender key uid headers htl source this prb from store is start if logminor logger minor this is to string for kh to string chk insert sender adds itself to insert senders return is chkinsertsender chkinsertsender insertrequest chkinsertsender makeinsertsender peernode partiallyreceivedblock fromstore makeinsertsender fromstore keyhtlpair keyhtlpair chkinsertsender insertsenders chkinsertsender insertsenders fromstore illegalargumentexception chkinsertsender fromstore tostring tostring chkinsertsender insertsenders fetch or create an ssk insert sender for a given key htl param key the key to be inserted param htl the current htl we can t coalesce inserts across htl s param uid the uid of the caller s request chain or a new one this is obviously not used if there is already an ssk insert sender running param source the node that sent the insert request or null if it originated locally public ssk insert sender make insert sender ssk block block short htl long uid peer node source boolean from store boolean cache nodessk key nodessk block get key if key get pub key null throw new illegal argument exception no pub key when inserting if cache cache key key get pub key hash key get pub key peers is closer location block get key to normalized double node min uptime store key logger minor this make insert sender key htl uid source from store keyhtl pair kh new keyhtl pair key htl uid ssk insert sender is null synchronized insert senders is ssk insert sender insert senders get kh if is null logger minor this found is for kh return is if from store cache throw new illegal argument exception from store true but cache false is new ssk insert sender block uid htl source this from store is start logger minor this is to string for kh to string ssk insert sender adds itself to insert senders return is sskinsertsender sskinsertsender insertrequest sskinsertsender makeinsertsender sskblock peernode fromstore getkey getpubkey illegalargumentexception cachekey getpubkeyhash getpubkey iscloserlocation getkey tonormalizeddouble min_uptime_store_key makeinsertsender fromstore keyhtlpair keyhtlpair sskinsertsender insertsenders sskinsertsender insertsenders fromstore illegalargumentexception sskinsertsender fromstore tostring tostring sskinsertsender insertsenders public boolean lockuid long uid boolean ssk boolean insert boolean offer reply boolean local uid tag tag synchronized runningui ds if runningui ds contains key uid return false already present runningui ds put uid tag if these are switched around we must remember to remove from both if offer reply hash map long offer reply tag map get offer tracker ssk inner lock map offer reply tag tag uid ssk insert offer reply local else if insert hash map long insert tag map get insert tracker ssk local inner lock map insert tag tag uid ssk insert offer reply local else hash map long request tag map get request tracker ssk local inner lock map request tag tag uid ssk insert offer reply local return true offerreply uidtag runninguids runninguids containskey runninguids offerreply hashmap offerreplytag getoffertracker innerlock offerreplytag offerreply hashmap inserttag getinserttracker innerlock inserttag offerreply hashmap requesttag getrequesttracker innerlock requesttag offerreply private t extends uid tag void inner lock hash map long t map t tag long uid boolean ssk boolean insert boolean offer reply boolean local synchronized map if logminor logger minor this locking uid ssk ssk insert insert offer reply offer reply local local size map size new exception debug if map contains key uid logger error this already have uid in specific map ssk insert offer reply local but not in general map trying to register tag but already have map get uid map put uid tag if logminor logger minor this locked uid ssk ssk insert insert offer reply offer reply local local size map size uidtag innerlock hashmap offerreply offerreply offerreply containskey offerreply offerreply offerreply public void unlockuid long uid boolean ssk boolean insert boolean can fail boolean offer reply boolean local uid tag tag completed uid if offer reply hash map long offer reply tag map get offer tracker ssk inner unlock map offer reply tag tag uid ssk insert offer reply local can fail else if insert hash map long insert tag map get insert tracker ssk local inner unlock map insert tag tag uid ssk insert offer reply local can fail else hash map long request tag map get request tracker ssk local inner unlock map request tag tag uid ssk insert offer reply local can fail synchronized runningui ds uid tag old tag runningui ds get uid if old tag null if can fail return throw new illegal state exception could not unlock uid ssk ssk insert insert can fail can fail offer reply offer reply local local else if tag old tag if can fail return logger error this removing tag for uid but tag is registered return else runningui ds remove uid canfail offerreply uidtag offerreply hashmap offerreplytag getoffertracker innerunlock offerreplytag offerreply canfail hashmap inserttag getinserttracker innerunlock inserttag offerreply canfail hashmap requesttag getrequesttracker innerunlock requesttag offerreply canfail runninguids uidtag oldtag runninguids oldtag canfail illegalstateexception canfail canfail offerreply offerreply oldtag canfail runninguids private t extends uid tag void inner unlock hash map long t map t tag long uid boolean ssk boolean insert boolean offer reply boolean local boolean can fail synchronized map if logminor logger minor this unlocking uid ssk ssk insert insert offer reply offer reply local local size map size new exception debug if map get uid tag if can fail if logminor logger minor this can fail and did fail removing tag got map get uid for uid else logger error this removing tag for uid returned map get uid else map remove uid if logminor logger minor this unlocked uid ssk ssk insert insert offer reply offer reply local local size map size uidtag innerunlock hashmap offerreply canfail offerreply offerreply canfail offerreply offerreply private hash map long request tag get request tracker boolean ssk boolean local if ssk return local running localssk getui ds runningssk getui ds else return local running localchk getui ds runningchk getui ds hashmap requesttag getrequesttracker runninglocalsskgetuids runningsskgetuids runninglocalchkgetuids runningchkgetuids private hash map long insert tag get insert tracker boolean ssk boolean local if ssk return local running localssk putui ds runningssk putui ds else return local running localchk putui ds runningchk putui ds hashmap inserttag getinserttracker runninglocalsskputuids runningsskputuids runninglocalchkputuids runningchkputuids private hash map long offer reply tag get offer tracker boolean ssk return ssk runningssk offer replyui ds runningchk offer replyui ds hashmap offerreplytag getoffertracker runningsskofferreplyuids runningchkofferreplyuids static final int timeout 10 60 1000 private void start deaduid checker get ticker queue timed job deaduid checker timeout startdeaduidchecker getticker queuetimedjob deaduidchecker private runnable deaduid checker new runnable public void run try checkui ds running localssk getui ds checkui ds running localchk getui ds checkui ds running localssk putui ds checkui ds running localchk putui ds checkui ds runningssk getui ds checkui ds runningchk getui ds checkui ds runningssk putui ds checkui ds runningchk putui ds checkui ds runningssk offer replyui ds checkui ds runningchk offer replyui ds finally get ticker queue timed job this 60 1000 deaduidchecker checkuids runninglocalsskgetuids checkuids runninglocalchkgetuids checkuids runninglocalsskputuids checkuids runninglocalchkputuids checkuids runningsskgetuids checkuids runningchkgetuids checkuids runningsskputuids checkuids runningchkputuids checkuids runningsskofferreplyuids checkuids runningchkofferreplyuids getticker queuetimedjob private void checkui ds hash map long extends uid tag map long uids uid tag tags synchronized map uids map key set to array new long map size tags map values to array new uid tag map size long now system current time millis for int i 0 i uids length i if now tags i created time timeout tags i log still present uids i synchronized map map remove uids i checkuids hashmap uidtag uidtag keyset toarray toarray uidtag currenttimemillis createdtime logstillpresent return some status information public string get status string builder sb new string builder if peers null sb append peers get status else sb append no peers yet sb append n inserts any insert sender senders synchronized insert senders senders insert senders values to array new any insert sender insert senders size int x senders length sb append x if x 5 x 0 sb append n dump iterator any insert sender i insert senders values iterator while i has next any insert sender s i next sb append s getuid sb append sb append s get status string sb append n sb append n requests sb append get num request senders sb append n transferring requests sb append get num transferring request senders sb append n return sb to string getstatus stringbuilder stringbuilder getstatus ninserts anyinsertsender insertsenders insertsenders toarray anyinsertsender insertsenders anyinsertsender insertsenders hasnext anyinsertsender getstatusstring nrequests getnumrequestsenders ntransferring getnumtransferringrequestsenders tostring return tmci peer list public string gettmci peer list string builder sb new string builder if peers null sb append peers gettmci peer list else sb append no peers yet return sb to string gettmcipeerlist stringbuilder stringbuilder gettmcipeerlist tostring public int get num insert senders synchronized insert senders return insert senders size getnuminsertsenders insertsenders insertsenders public int get num request senders synchronized request senders return request senders size getnumrequestsenders requestsenders requestsenders public int get numssk requests return runningssk getui ds size running localssk getui ds size getnumsskrequests runningsskgetuids runninglocalsskgetuids public int get numchk requests return runningchk getui ds size running localchk getui ds size getnumchkrequests runningchkgetuids runninglocalchkgetuids public int get numssk inserts return runningssk putui ds size running localssk putui ds size getnumsskinserts runningsskputuids runninglocalsskputuids public int get numchk inserts return runningchk putui ds size running localchk putui ds size getnumchkinserts runningchkputuids runninglocalchkputuids public int get num localssk requests return running localssk getui ds size getnumlocalsskrequests runninglocalsskgetuids public int get num localchk requests return running localchk getui ds size getnumlocalchkrequests runninglocalchkgetuids public int get num remotessk requests synchronized runningssk getui ds for long l runningssk getui ds logger minor this running remote ssk fetch l return runningssk getui ds size getnumremotesskrequests runningsskgetuids runningsskgetuids runningsskgetuids public int get num remotechk requests return runningchk getui ds size getnumremotechkrequests runningchkgetuids public int get num localssk inserts return running localssk putui ds size getnumlocalsskinserts runninglocalsskputuids public int get num localchk inserts return running localchk putui ds size getnumlocalchkinserts runninglocalchkputuids public int get num remotessk inserts return runningssk putui ds size getnumremotesskinserts runningsskputuids public int get num remotechk inserts return runningchk putui ds size getnumremotechkinserts runningchkputuids public int get numssk offer replies return runningssk offer replyui ds size getnumsskofferreplies runningsskofferreplyuids public int get numchk offer replies return runningchk offer replyui ds size getnumchkofferreplies runningchkofferreplyuids public int get num transferring request senders synchronized transferring request senders return transferring request senders size getnumtransferringrequestsenders transferringrequestsenders transferringrequestsenders public int get num transferring request handlers synchronized transferring request handlers return transferring request handlers size getnumtransferringrequesthandlers transferringrequesthandlers transferringrequesthandlers return data string for freeviz public string get freeviz output string builder sb new string builder sb append nrequests sb append get num request senders sb append ntransferring requests sb append get num transferring request senders sb append ninserts sb append get num insert senders sb append n if peers null sb append peers get freeviz output return sb to string getfreevizoutput stringbuilder stringbuilder getnumrequestsenders ntransferring_requests getnumtransferringrequestsenders getnuminsertsenders getfreevizoutput tostring has a request completed with this id recently public boolean recently completed long id synchronized recently completedi ds return recently completedi ds contains id recentlycompleted recentlycompletedids recentlycompletedids a request completed regardless of success void completed long id synchronized recently completedi ds recently completedi ds push id while recently completedi ds size max recently completed ids recently completedi ds pop recentlycompletedids recentlycompletedids recentlycompletedids max_recently_completed_ids recentlycompletedids public dsa public key get key byte hash byte array wrapper w new byte array wrapper hash if logminor logger minor this getting pubkey hex util bytes to hex hash if use ram pubkeys cache synchronized cached pub keys dsa public key key cached pub keys get w if key null cached pub keys push w key if logminor logger minor this got hex util bytes to hex hash from cache return key try dsa public key key key pub key datastore fetch hash false if key null key pub key datacache fetch hash false if key null cache key hash key false if logminor logger minor this got hex util bytes to hex hash from store return key catch io exception e fixme deal with disk full access perms etc tell user about it logger error this error accessing pubkey store e e return null dsapublickey getkey bytearraywrapper bytearraywrapper hexutil bytestohex use_ram_pubkeys_cache cachedpubkeys dsapublickey cachedpubkeys cachedpubkeys hexutil bytestohex dsapublickey pubkeydatastore pubkeydatacache cachekey hexutil bytestohex ioexception cache a public key public void cache key byte hash dsa public key key boolean deep if logminor logger minor this cache key hex util bytes to hex hash key byte array wrapper w new byte array wrapper hash synchronized cached pub keys dsa public key key2 cached pub keys get w if key2 null key2 equals key fixme is this test really needed sha 256 inside synchronized is a bad idea message digest md256 sha256 get message digest try byte hash check md256 digest key as bytes if arrays equals hash check hash logger error this hash is correct verify the old key byte old hash md256 digest key2 as bytes if arrays equals old hash hash logger error this old hash is correct too bug in dsa public key equals or sha 256 collision else logger error this old hash is wrong cached pub keys remove key w cache key hash key deep else logger error this new hash is wrong finally sha256 return message digest md256 throw new illegal argument exception wrong hash already have different key with same hash cached pub keys push w key while cached pub keys size max memory cached pubkeys cached pub keys pop key try if deep pub key datastore put hash key pub key datastore fetch hash true pub key datacache put hash key pub key datacache fetch hash true catch io exception e fixme deal with disk full access perms etc tell user about it logger error this error accessing pubkey store e e cachekey dsapublickey hexutil bytestohex bytearraywrapper bytearraywrapper cachedpubkeys dsapublickey cachedpubkeys messagedigest getmessagedigest hashcheck asbytes hashcheck oldhash asbytes oldhash dsapublickey cachedpubkeys removekey cachekey returnmessagedigest illegalargumentexception cachedpubkeys cachedpubkeys max_memory_cached_pubkeys cachedpubkeys popkey pubkeydatastore pubkeydatastore pubkeydatacache pubkeydatacache ioexception public boolean is testnet enabled return testnet enabled istestnetenabled testnetenabled public client key block fetch key client key key boolean dont promote throws key verify exception if key instanceof clientchk return fetch clientchk key dont promote else if key instanceof clientssk return fetch clientssk key dont promote else throw new illegal state exception don t know what to do with key clientkeyblock fetchkey clientkey dontpromote keyverifyexception dontpromote dontpromote illegalstateexception public client key block fetch clientssk clientssk boolean dont promote throws ssk verify exception dsa public key key clientssk get pub key if key null key get key clientssk pub key hash if key null return null clientssk set public key key ssk block block fetch nodessk clientssk get node key dont promote if block null if logminor logger minor this could not find key for clientssk dont promote dont promote return null move the pubkey to the top of the lru and fix it if it was corrupt cache key clientssk pub key hash key false return clientssk block construct block clientssk clientkeyblock dontpromote sskverifyexception dsapublickey getpubkey getkey pubkeyhash setpublickey sskblock getnodekey dontpromote dontpromote dontpromote cachekey pubkeyhash clientsskblock private client key block fetch clientchk clientchk boolean dont promote throws chk verify exception chk block block fetch clientchk get nodechk dont promote if block null return null return new clientchk block block clientchk clientkeyblock dontpromote chkverifyexception chkblock getnodechk dontpromote clientchkblock public void exit int reason try this park system out println goodbye system out println reason finally system exit reason public void exit string reason try this park system out println goodbye from this reason finally system exit 0 returns true if the node is shutting down the packet receiver calls this for every packet and boolean is atomic so this method is not synchronized public boolean is stopping return is stopping isstopping isstopping get the node into a state where it can be stopped safely may be called twice once in exit above and then again from the wrapper triggered by calling system exit beware public void park synchronized this if is stopping return is stopping true try message msg dmt createfnp disconnect false false 1 new short buffer new byte 0 peers local broadcast msg true false peers ctr disconn catch throwable t try e g if we haven t finished startup logger error this failed to tell peers we are going down t t catch throwable t1 ignore we don t want to mess up the exit process config store todo find a smarter way of doing it not involving any casting yarrow my random yarrow random my random write seed my random seedfile true isstopping isstopping createfnpdisconnect shortbuffer localbroadcast ctrdisconn myrandom myrandom write_seed myrandom public node update manager get node updater return node updater nodeupdatemanager getnodeupdater nodeupdater public darknet peer node get darknet connections return peers get darknet peers darknetpeernode getdarknetconnections getdarknetpeers public boolean add peer connection peer node pn boolean retval peers add peer pn peers write peers return retval addpeerconnection peernode addpeer writepeers public void remove peer connection peer node pn peers disconnect pn true false false removepeerconnection peernode public void on connected peer if logminor logger minor this on connected peer ip detector on connected peer onconnectedpeer onconnectedpeer ipdetector onconnectedpeer public int getfnp port return this get darknet port number getfnpport getdarknetportnumber public synchronized boolean set newest peer last good version int version if version build old age user alert last good version if build old age user alert last good version 0 client core alerts register build old age user alert build old age user alert last good version version return true return false setnewestpeerlastgoodversion buildoldageuseralert lastgoodversion buildoldageuseralert lastgoodversion clientcore buildoldageuseralert buildoldageuseralert lastgoodversion public synchronized boolean is oudated return build old age user alert last good version 0 isoudated buildoldageuseralert lastgoodversion private map integer node to node message listener n2nm listeners new hash map integer node to node message listener public synchronized void register node to node message listener int type node to node message listener listener n2nm listeners put type listener nodetonodemessagelistener n2nmlisteners hashmap nodetonodemessagelistener registernodetonodemessagelistener nodetonodemessagelistener n2nmlisteners handle a received node to node message public void received node to node message message m peer node src int type integer m get object dmt node to node message type int value short buffer message data short buffer m get object dmt node to node message data received node to node message src type message data false receivednodetonodemessage peernode getobject node_to_node_message_type intvalue shortbuffer messagedata shortbuffer getobject node_to_node_message_data receivednodetonodemessage messagedata public void received node to node message peer node src int type short buffer message data boolean parting message boolean from darknet false if src instanceof darknet peer node from darknet true node to node message listener listener null synchronized this listener n2nm listeners get type if listener null logger error this unknown n2nm id type discarding packet length message data get length return listener handle message message data get data from darknet src type receivednodetonodemessage peernode shortbuffer messagedata partingmessage fromdarknet darknetpeernode fromdarknet nodetonodemessagelistener n2nmlisteners messagedata getlength handlemessage messagedata getdata fromdarknet public void handle message byte data boolean from darknet peer node src int type logger normal this received differential node reference node to node message from src get peer simple field set fs null try fs new simple field set new string data utf 8 false true catch io exception e logger error this io exception while parsing node to node message data e return if fs get n2n type null fs remove value n2n type try src process diff noderef fs catch fs parse exception e logger error this fs parse exception while parsing node to node message data e return handlemessage fromdarknet peernode getpeer simplefieldset simplefieldset ioexception ioexception n2ntype removevalue n2ntype processdiffnoderef fsparseexception fsparseexception public void handle message byte data boolean from darknet peer node src int type if from darknet logger error this got n2ntm from non darknet node from src return darknet peer node dark source darknet peer node src logger normal this received n2ntm from dark source get peer simple field set fs null try fs new simple field set new string data utf 8 false true catch io exception e logger error this io exception while parsing node to node message data e return if fs get n2n type null fs remove value n2n type fs put overwrite n2n type integer to string type if fs get received time null fs remove value received time fs put overwrite received time long to string system current time millis if fs get received as null fs remove value received as fs put overwrite received as node to node message int file number dark source write new extra peer data file fs extra peer data type n2ntm if file number 1 logger error this failed to write n2ntm to extra peer data file for peer dark source get peer keep track of the file number so we can potentially delete the extra peer data file later the file is authoritative try handle node to node text message simple field set fs dark source file number catch fs parse exception e shouldn t happen throw new error e handlemessage fromdarknet peernode fromdarknet darknetpeernode darksource darknetpeernode darksource getpeer simplefieldset simplefieldset ioexception ioexception n2ntype removevalue n2ntype putoverwrite n2ntype tostring receivedtime removevalue receivedtime putoverwrite receivedtime tostring currenttimemillis receivedas removevalue receivedas putoverwrite receivedas nodetonodemessage filenumber darksource writenewextrapeerdatafile extra_peer_data_type_n2ntm filenumber darksource getpeer filenumber handlenodetonodetextmessagesimplefieldset darksource filenumber fsparseexception handle a node to node text message simple field set throws fs parse exception public void handle node to node text message simple field set simple field set fs darknet peer node source int file number throws fs parse exception if logminor logger minor this got node to node message n fs int overall type fs get int n2n type fs remove value n2n type if overall type node n2n message type fproxy handle fproxy node to node text message simple field set fs source file number else logger error this received unknown node to node message type overall type from source get peer simplefieldset fsparseexception handlenodetonodetextmessagesimplefieldset simplefieldset darknetpeernode filenumber fsparseexception overalltype getint n2ntype removevalue n2ntype overalltype n2n_message_type_fproxy handlefproxynodetonodetextmessagesimplefieldset filenumber overalltype getpeer private void handle fproxy node to node text message simple field set simple field set fs darknet peer node source int file number throws fs parse exception int type fs get int type if type node n2n text message type useralert source handle fproxyn2ntm fs file number else if type node n2n text message type file offer source handle fproxy file offer fs file number else if type node n2n text message type file offer accepted source handle fproxy file offer accepted fs file number else if type node n2n text message type file offer rejected source handle fproxy file offer rejected fs file number else logger error this received unknown fproxy node to node message sub type type from source get peer handlefproxynodetonodetextmessagesimplefieldset simplefieldset darknetpeernode filenumber fsparseexception getint n2n_text_message_type_useralert handlefproxyn2ntm filenumber n2n_text_message_type_file_offer handlefproxyfileoffer filenumber n2n_text_message_type_file_offer_accepted handlefproxyfileofferaccepted filenumber n2n_text_message_type_file_offer_rejected handlefproxyfileofferrejected filenumber getpeer public string get my name return my name getmyname myname public message core getusm return usm messagecore public location manager get location manager return lm locationmanager getlocationmanager public int get swaps return location manager swaps getswaps locationmanager public int get no swaps return location manager no swaps getnoswaps locationmanager noswaps public int get started swaps return location manager started swaps getstartedswaps locationmanager startedswaps public int get swaps rejected already locked return location manager swaps rejected already locked getswapsrejectedalreadylocked locationmanager swapsrejectedalreadylocked public int get swaps rejected nowhere to go return location manager swaps rejected nowhere to go getswapsrejectednowheretogo locationmanager swapsrejectednowheretogo public int get swaps rejected rate limit return location manager swaps rejected rate limit getswapsrejectedratelimit locationmanager swapsrejectedratelimit public int get swaps rejected recognizedid return location manager swaps rejected recognizedid getswapsrejectedrecognizedid locationmanager swapsrejectedrecognizedid public peer node get peer nodes return peers my peers peernode getpeernodes mypeers public peer node get connected peers return peers connected peers peernode getconnectedpeers connectedpeers return a peer of the node given its ip and port name or identity as a string public peer node get peer node string node identifier peer node pn peers my peers for int i 0 i pn length i peer peer pn i get peer string node ip and port if peer null node ip and port peer to string string identity pn i get identity string if pn i instanceof darknet peer node darknet peer node dpn darknet peer node pn i string name dpn my name if identity equals node identifier node ip and port equals node identifier name equals node identifier return pn i else if identity equals node identifier node ip and port equals node identifier return pn i return null peernode getpeernode nodeidentifier peernode mypeers getpeer nodeipandport nodeipandport tostring getidentitystring darknetpeernode darknetpeernode darknetpeernode myname nodeidentifier nodeipandport nodeidentifier nodeidentifier nodeidentifier nodeipandport nodeidentifier public boolean is has started return has started ishasstarted hasstarted public void queue random reinsert key block block client core queue random reinsert block queuerandomreinsert keyblock clientcore queuerandomreinsert public string get extra peer data dir return extra peer data dir get path getextrapeerdatadir extrapeerdatadir getpath public boolean no connected peers return peers any connected peers noconnectedpeers anyconnectedpeers public double get location return lm get location getlocation getlocation public double get location change session return lm get loc change session getlocationchangesession getlocchangesession public int get average outgoing swap time return lm get average swap time getaverageoutgoingswaptime getaverageswaptime public int get send swap interval return lm get send swap interval getsendswapinterval getsendswapinterval public int get number of remote peer locations seen in swaps return lm number of remote peer locations seen in swaps getnumberofremotepeerlocationsseeninswaps numberofremotepeerlocationsseeninswaps public boolean is advanced mode enabled if client core null return false return client core is advanced mode enabled isadvancedmodeenabled clientcore clientcore isadvancedmodeenabled public boolean isf proxy javascript enabled return client core isf proxy javascript enabled isfproxyjavascriptenabled clientcore isfproxyjavascriptenabled public int get numark fetchers peer node p peers my peers int x 0 for int i 0 i p length i if p i is fetchingark x return x getnumarkfetchers peernode mypeers isfetchingark public void sent payload int len synchronized stats sync total payload sent len sentpayload statssync totalpayloadsent public long get total payload sent synchronized stats sync return total payload sent gettotalpayloadsent statssync totalpayloadsent public void set name string key throws invalid config value exception node need restart exception config get node get option name set value key setname invalidconfigvalueexception nodeneedrestartexception getoption setvalue public ticker get ticker return ps getticker public int get unclaimedfifo size return usm get unclaimedfifo size getunclaimedfifosize getunclaimedfifosize connect this node to another node for purposes of testing public void connect to seednode seed server test peer node node throws opennet disabled exception fs parse exception peer parse exception reference signature verification exception peers add peer node false false connecttoseednode seedservertestpeernode opennetdisabledexception fsparseexception peerparseexception referencesignatureverificationexception addpeer peers add peer node false false public void connect node node throws fs parse exception peer parse exception reference signature verification exception peers connect node darknet crypto export public field set darknet crypto packet mangler addpeer fsparseexception peerparseexception referencesignatureverificationexception darknetcrypto exportpublicfieldset darknetcrypto packetmangler public short maxhtl return maxhtl public int get darknet port number return darknet crypto port number getdarknetportnumber darknetcrypto portnumber public void je stats dump if store environment null system out println database stat not availiable return try stats config stats conf new stats config stats conf set clear true system out println store environment get stats stats conf catch database exception e system out println failed to get stats from je environment e jestatsdump storeenvironment statsconfig statsconf statsconfig statsconf setclear storeenvironment getstats statsconf databaseexception public int get output bandwidth limit return output bandwidth limit getoutputbandwidthlimit outputbandwidthlimit public synchronized int get input bandwidth limit if input limit default return output bandwidth limit 4 return input bandwidth limit getinputbandwidthlimit inputlimitdefault outputbandwidthlimit inputbandwidthlimit public synchronized void set time skew detected user alert if time skew detected user alert null time skew detected user alert new time skew detected user alert client core alerts register time skew detected user alert settimeskewdetecteduseralert timeskewdetecteduseralert timeskewdetecteduseralert timeskewdetecteduseralert clientcore timeskewdetecteduseralert public file get node dir return node dir getnodedir nodedir public darknet peer node create new darknet node simple field set fs throws fs parse exception peer parse exception reference signature verification exception return new darknet peer node fs this darknet crypto peers false darknet crypto packet mangler darknetpeernode createnewdarknetnode simplefieldset fsparseexception peerparseexception referencesignatureverificationexception darknetpeernode darknetcrypto darknetcrypto packetmangler public opennet peer node create new opennet node simple field set fs throws fs parse exception opennet disabled exception peer parse exception reference signature verification exception if opennet null throw new opennet disabled exception opennet is not currently enabled return new opennet peer node fs this opennet crypto opennet peers false opennet crypto packet mangler opennetpeernode createnewopennetnode simplefieldset fsparseexception opennetdisabledexception peerparseexception referencesignatureverificationexception opennetdisabledexception opennetpeernode packetmangler public seed server test peer node create new seed server test peer node simple field set fs throws fs parse exception opennet disabled exception peer parse exception reference signature verification exception if opennet null throw new opennet disabled exception opennet is not currently enabled return new seed server test peer node fs this opennet crypto peers true opennet crypto packet mangler seedservertestpeernode createnewseedservertestpeernode simplefieldset fsparseexception opennetdisabledexception peerparseexception referencesignatureverificationexception opennetdisabledexception seedservertestpeernode packetmangler public opennet peer node add new opennet node simple field set fs throws fs parse exception peer parse exception reference signature verification exception fixme perhaps this should throw opennet disabled excemption rather than returing false if opennet null return null return opennet add new opennet node fs opennetpeernode addnewopennetnode simplefieldset fsparseexception peerparseexception referencesignatureverificationexception opennetdisabledexcemption addnewopennetnode public byte get opennet identity return opennet crypto my identity getopennetidentity myidentity public byte get darknet identity return darknet crypto my identity getdarknetidentity darknetcrypto myidentity public int estimate full headers length one message return darknet crypto packet mangler full headers length one message estimatefullheaderslengthonemessage darknetcrypto packetmangler fullheaderslengthonemessage public synchronized boolean is opennet enabled return opennet null isopennetenabled public simple field set export darknet public field set return darknet crypto export public field set simplefieldset exportdarknetpublicfieldset darknetcrypto exportpublicfieldset public simple field set export opennet public field set return opennet crypto export public field set simplefieldset exportopennetpublicfieldset exportpublicfieldset public simple field set export darknet private field set return darknet crypto export private field set simplefieldset exportdarknetprivatefieldset darknetcrypto exportprivatefieldset public simple field set export opennet private field set return opennet crypto export private field set simplefieldset exportopennetprivatefieldset exportprivatefieldset should the ip detection code only use the ip address override and the bind to information rather than doing a full detection public synchronized boolean dont detect only return true if bind to is set on all ports which are in use if darknet crypto get bind to is real internet address false true false return false if opennet null if opennet crypto get bind to is real internet address false true false return false return true bindto dontdetect bindto darknetcrypto getbindto isrealinternetaddress getbindto isrealinternetaddress public int get opennetfnp port if opennet null return 1 return opennet crypto port number getopennetfnpport portnumber opennet manager get opennet return opennet opennetmanager getopennet public synchronized boolean pass opennet refs through darknet return pass opennet refs through darknet passopennetrefsthroughdarknet passopennetrefsthroughdarknet get the set of public ports that need to be forwarded these are internal ports not necessarily external they may be rewritten by the nat return a set of forward port s to be fed to port forward plugins public set forward port get public interface ports hash set forward port set new hash set forward port fixme i pv6 support set add new forward port darknet false forward port protocol udp ipv4 darknet crypto port number if opennet null node crypto crypto opennet crypto if crypto null set add new forward port opennet false forward port protocol udp ipv4 crypto port number return set forwardport forwardport getpublicinterfaceports hashset forwardport hashset forwardport ipv6 forwardport forwardport protocol_udp_ipv4 darknetcrypto portnumber nodecrypto forwardport forwardport protocol_udp_ipv4 portnumber public long get uptime return system current time millis usm get started time getuptime currenttimemillis getstartedtime public synchronized udp socket handler get packet socket handlers fixme better way to get these if opennet null return new udp socket handler darknet crypto socket opennet crypto socket todo auto generated method stub else return new udp socket handler darknet crypto socket udpsockethandler getpacketsockethandlers udpsockethandler darknetcrypto udpsockethandler darknetcrypto public int get max opennet peers return max opennet peers getmaxopennetpeers maxopennetpeers public void on added validip opennet manager om synchronized this om opennet if om null announcer announcer om announcer if announcer null announcer maybe send announcement onaddedvalidip opennetmanager maybesendannouncement returns true if the packet receiver should try to decode process packets that are not from a peer i e from a seed connection the packet receiver calls this upon receiving an unrecognized packet public boolean want anon auth return opennet null accept seed connections wantanonauth acceptseedconnections public void display clock problem user alert boolean value if value client core alerts register clock problem detected user alert else client core alerts unregister clock problem detected user alert displayclockproblemuseralert clientcore clockproblemdetecteduseralert clientcore clockproblemdetecteduseralert public boolean opennet definitely port forwarded opennet manager om synchronized this om this opennet if om null return false node crypto crypto om crypto if crypto null return false return crypto definitely port forwarded opennetdefinitelyportforwarded opennetmanager nodecrypto definitelyportforwarded public boolean darknet definitely port forwarded if darknet crypto null return false return darknet crypto definitely port forwarded darknetdefinitelyportforwarded darknetcrypto darknetcrypto definitelyportforwarded public boolean has key key key fixme optimise if key instanceof nodechk return fetch nodechk key true null else return fetch nodessk key true null haskey public int get total runningui ds synchronized runningui ds return runningui ds size gettotalrunninguids runninguids runninguids public void add runningui ds vector long list synchronized runningui ds list add all runningui ds key set addrunninguids runninguids addall runninguids keyset public int get total runningui ds alt synchronized runningui ds return this runningchk getui ds size this runningchk putui ds size this runningssk getui ds size this runningssk getui ds size this runningssk offer replyui ds size this runningchk offer replyui ds size gettotalrunninguidsalt runninguids runningchkgetuids runningchkputuids runningsskgetuids runningsskgetuids runningsskofferreplyuids runningchkofferreplyuids warning does not announce change in location public void set location double loc lm set location loc setlocation setlocation public boolean peers want key key key return failure table peers want key key peerswantkey failuretable peerswantkey public final request client non persistent client new request client public boolean persistent return false requestclient nonpersistentclient requestclient return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public void on too lowmtu int min advertisedmtu int min acceptablemtu if alertmtu too small null alertmtu too small new simple user alert false l10n too smallmtu l10n too smallmtu long new string mtu minmtu new string integer to string min advertisedmtu integer to string min acceptablemtu l10n too smallmtu short user alert error else return client core alerts register alertmtu too small ontoolowmtu minadvertisedmtu minacceptablemtu alertmtutoosmall alertmtutoosmall simpleuseralert toosmallmtu toosmallmtulong tostring minadvertisedmtu tostring minacceptablemtu toosmallmtushort useralert clientcore alertmtutoosmall public void set dispatcher hook node dispatcher callback cb this dispatcher set hook cb setdispatcherhook nodedispatchercallback sethook public boolean shall we publish our peers location return publish our peers location shallwepublishourpeerslocation publishourpeerslocation public boolean shall we route according to our peers location return route according to our peers location version last good build 1160 shallwerouteaccordingtoourpeerslocation routeaccordingtoourpeerslocation lastgoodbuild public boolean object can new object container container logger error this not storing node in database new exception error return false objectcannew objectcontainer make a running request sender into a turtle request backoff when the transfer finishes or after 10 seconds if no cancellation downstream cancel all dependant request handler s and local requests this also removes it from the load management code registration we track the turtles for each peer and overall no two turtles from the same node may share the same key and there is an overall limit param sender public void make turtle request sender sender registration fixme check the datastore if this register turtle transfer sender too many turtles running or already two turtles for this key we allow two in case one peer turtles as a dos sender kill turtle logger error this didn t make turtle global for key sender key for sender return peer node from sender transferring from if from null race condition it has finished avoid npe return if from register turtle transfer sender too many turtles running or already a turtle for this key abort it unregister turtle transfer sender sender kill turtle logger error this didn t make turtle peer for key sender key for sender return logger normal this turtling sender key for sender do not transfer coalesce synchronized transferring request senders transferring request senders remove sender key turtle count abort downstream transfers set the turtle mode flag and set up the backoff callback sender set turtle requesthandler maketurtle requestsender registerturtletransfer killturtle peernode transferringfrom registerturtletransfer unregisterturtletransfer killturtle transferringrequestsenders transferringrequestsenders turtlecount setturtle public long get turtle count return turtle count getturtlecount turtlecount private boolean register turtle transfer request sender sender key key sender key synchronized turtling transfers if get num incoming turtles max turtles logger error this too many turtles running globally return false if turtling transfers contains key key turtling transfers put key new request sender sender logger normal this running turtles a get num incoming turtles turtling transfers size return true else request sender senders turtling transfers get key if senders length max turtles per key logger error this too many turtles for key globally return false for int i 0 i senders length i if senders i sender logger error this registering turtle for sender key twice globally return false request sender new senders new request sender senders length 1 system arraycopy senders 0 new senders 0 senders length new senders senders length sender turtling transfers put key new senders logger normal this running turtles b get num incoming turtles turtling transfers size return true registerturtletransfer requestsender turtlingtransfers getnumincomingturtles max_turtles turtlingtransfers containskey turtlingtransfers requestsender getnumincomingturtles turtlingtransfers requestsender turtlingtransfers max_turtles_per_key requestsender newsenders requestsender newsenders newsenders turtlingtransfers newsenders getnumincomingturtles turtlingtransfers public void unregister turtle transfer request sender sender key key sender key synchronized turtling transfers if turtling transfers contains key key logger error this removing turtle sender for key does not exist in global turtles list return request sender senders turtling transfers get key if senders length 1 senders 0 sender turtling transfers remove key return if senders length 2 if senders 0 sender turtling transfers put key new request sender senders 1 else if senders 1 sender turtling transfers put key new request sender senders 0 return int x 0 for int i 0 i senders length i if senders i sender x if x 0 logger error this turtle not in global register sender for key return if senders length x logger error this lots of copies of turtle x turtling transfers remove key return request sender new senders new request sender senders length x int idx 0 for request sender s senders if s sender continue new senders idx s turtling transfers put key new senders unregisterturtletransfer requestsender turtlingtransfers turtlingtransfers containskey requestsender turtlingtransfers turtlingtransfers turtlingtransfers requestsender turtlingtransfers requestsender turtlingtransfers requestsender newsenders requestsender requestsender newsenders turtlingtransfers newsenders public int get num incoming turtles synchronized turtling transfers int turtles 0 for request sender senders turtling transfers values turtles senders length return turtles getnumincomingturtles turtlingtransfers requestsender turtlingtransfers construct an apply maskf ilter public apply mask filter applymaskfilter applymaskfilter construct an apply maskf ilter param mask image the mask image param destination the destination image public apply mask filter buffered image mask image buffered image destination this mask image mask image this destination destination applymaskfilter maskimage applymaskfilter bufferedimage maskimage bufferedimage maskimage maskimage set the destination image param destination the destination image see get destination public void set destination buffered image destination this destination destination getdestination setdestination bufferedimage get the destination image return the destination image see set destination public buffered image get destination return destination setdestination bufferedimage getdestination set the mask image param mask image the mask image see get mask image public void set mask image buffered image mask image this mask image mask image maskimage getmaskimage setmaskimage bufferedimage maskimage maskimage maskimage get the mask image return the mask image see set mask image public buffered image get mask image return mask image setmaskimage bufferedimage getmaskimage maskimage interpolates between two rasters according to the alpha level of a mask raster param src the source raster param dst the destination raster param sel the mask raster public static void compose through mask raster src writable raster dst raster sel int x src get minx int y src get miny int w src get width int h src get height int srcrgb null int selrgb null int dstrgb null for int i 0 i h i srcrgb src get pixels x y w 1 srcrgb selrgb sel get pixels x y w 1 selrgb dstrgb dst get pixels x y w 1 dstrgb int k x for int j 0 j w j int sr srcrgb k int dir dstrgb k int sg srcrgb k 1 int dig dstrgb k 1 int sb srcrgb k 2 int dib dstrgb k 2 int sa srcrgb k 3 int dia dstrgb k 3 float a selrgb k 3 255f float ac 1 a dstrgb k int a sr ac dir dstrgb k 1 int a sg ac dig dstrgb k 2 int a sb ac dib dstrgb k 3 int a sa ac dia k 4 dst set pixels x y w 1 dstrgb y composethroughmask writableraster getminx getminy getwidth getheight getpixels getpixels getpixels setpixels public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster if dst null dst create compatible dest image src null writable raster dst raster dst get raster if destination null mask image null compose through mask src get raster dst get raster mask image get raster return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster createcompatibledestimage writableraster dstraster getraster maskimage composethroughmask getraster getraster maskimage getraster override public string to string return keying key tostring class bit index impl t extends i persistent extends btree t implements bit index t bit index impl super class descriptor tp int true bitindeximpl ipersistent bitindex bitindeximpl classdescriptor tpint int oid key int key int oid this key key this oid oid public int get t obj storage impl db storage impl get storage if root 0 throw new storage error storage error key not found return bit index page find db root obj get oid height storageimpl storageimpl getstorage storageerror storageerror key_not_found bitindexpage getoid public void put t obj int mask storage impl db storage impl get storage if db null throw new storage error storage error deleted object if obj is persistent db make persistent obj key ins new key mask obj get oid if root 0 root bit index page allocate db 0 ins height 1 else int result bit index page insert db root ins height if result op overflow root bit index page allocate db root ins height 1 update counter 1 n elems 1 modify storageimpl storageimpl getstorage storageerror storageerror deleted_object ispersistent makepersistent getoid bitindexpage bitindexpage op_overflow bitindexpage updatecounter nelems public void remove t obj storage impl db storage impl get storage if db null throw new storage error storage error deleted object if root 0 throw new storage error storage error key not found int result bit index page remove db root obj get oid height if result op not found throw new storage error storage error key not found n elems 1 if result op underflow page pg db get page root if bit index page getn items pg 0 int new root 0 if height 1 new root bit index page get item pg bit index page max items 1 db free page root root new root height 1 db pool unfix pg update counter 1 modify storageimpl storageimpl getstorage storageerror storageerror deleted_object storageerror storageerror key_not_found bitindexpage getoid op_not_found storageerror storageerror key_not_found nelems op_underflow getpage bitindexpage getnitems newroot newroot bitindexpage getitem bitindexpage maxitems freepage newroot updatecounter bit index iterator int set int clear sp 0 counter update counter if height 0 return int page id root storage impl db storage impl get storage if db null throw new storage error storage error deleted object int h height this set set this clear clear page stack new int h pos stack new int h while true page stack sp page id page pg db get page page id sp 1 if h 0 goto next item pg 0 break page id bit index page get item pg bit index page max items 1 db pool unfix pg bitindexiterator updatecounter pageid storageimpl storageimpl getstorage storageerror storageerror deleted_object pagestack posstack pagestack pageid getpage pageid gotonextitem pageid bitindexpage getitem bitindexpage maxitems public boolean has next if counter update counter throw new concurrent modification exception return sp 0 hasnext updatecounter concurrentmodificationexception public e next return e storage impl get storage lookup object next oid null storageimpl getstorage lookupobject nextoid public int next oid if has next throw new no such element exception storage impl db storage impl get storage int pos pos stack sp 1 page pg db get page page stack sp 1 int oid bit index page get item pg bit index page max items 1 pos goto next item pg pos 1 return oid nextoid hasnext nosuchelementexception storageimpl storageimpl getstorage posstack getpage pagestack bitindexpage getitem bitindexpage maxitems gotonextitem private final void goto next item page pg int pos storage impl db storage impl get storage do int end bit index page getn items pg while pos end int mask bit index page get item pg pos if set mask set clear mask 0 pos stack sp 1 pos db pool unfix pg return pos 1 while sp 0 db pool unfix pg pos pos stack sp 1 pg db get page page stack sp 1 if pos bit index page getn items pg pos stack sp 1 pos do int page id bit index page get item pg bit index page max items 1 pos db pool unfix pg pg db get page page id page stack sp page id pos stack sp pos 0 while sp page stack length break while sp 0 db pool unfix pg gotonextitem storageimpl storageimpl getstorage bitindexpage getnitems bitindexpage getitem posstack posstack getpage pagestack bitindexpage getnitems posstack pageid bitindexpage getitem bitindexpage maxitems getpage pageid pagestack pageid posstack pagestack public void remove throw new unsupported operation exception unsupportedoperationexception public iterator t iterator return iterator 0 0 public iterable iterator t iterator int set int clear return new bit index iterator t set clear iterableiterator bitindexiterator static final int max key space 8 static int get item page pg int index return bytes unpack4 pg data first key offs index 4 keyspace getitem firstkeyoffs static void set item page pg int index int mask bytes pack4 pg data first key offs index 4 mask setitem firstkeyoffs static int allocate storage impl db int root key ins int page id db allocate page page pg db put page page id setn items pg 1 set item pg 0 ins key set item pg max items 1 ins oid set item pg max items 2 root db pool unfix pg return page id storageimpl pageid allocatepage putpage pageid setnitems setitem setitem maxitems setitem maxitems pageid static void memcpy page dst pg int dst idx page src pg int src idx int len system arraycopy src pg data first key offs src idx 4 dst pg data first key offs dst idx 4 len 4 dst_pg dst_idx src_pg src_idx src_pg firstkeyoffs src_idx dst_pg firstkeyoffs dst_idx static int find storage impl db int page id int oid int height page pg db get page page id try int i n getn items pg l 0 r n if height 0 while l r i l r 1 if oid get item pg max items 1 i l i 1 else r i if r n get item pg max items r 1 oid return get item pg r throw new storage error storage error key not found else while l r i l r 1 if oid get item pg i l i 1 else r i return find db get item pg max items r 1 oid height finally if pg null db pool unfix pg storageimpl pageid getpage pageid getnitems getitem maxitems getitem maxitems getitem storageerror storageerror key_not_found getitem getitem maxitems static int insert storage impl db int page id key ins int height page pg db get page page id int l 0 n getn items pg r n int oid ins oid try if height 0 while l r int i l r 1 if oid get item pg i l i 1 else r i assert that l r insert before e r int result insert db get item pg max items r 1 ins height assert that result op not found if result op overflow return result n 1 else while l r int i l r 1 if oid get item pg max items 1 i l i 1 else r i if r n oid get item pg max items 1 r db pool unfix pg pg null pg db put page page id set item pg r ins key return op overwrite db pool unfix pg pg null pg db put page page id if n max memcpy pg r 1 pg r n r memcpy pg max items n 1 pg max items n n r set item pg r ins key set item pg max items 1 r ins oid setn items pg getn items pg 1 return op done else page is full then divide page page id db allocate page page b db put page page id assert that n max int m max 2 if r m memcpy b 0 pg 0 r memcpy b r 1 pg r m r 1 memcpy pg 0 pg m 1 max m 1 memcpy b max items r pg max items r r set item b r ins key set item b max items 1 r ins oid memcpy b max items m pg max items m 1 m r 1 memcpy pg max items max m 1 pg max items max max m 1 else memcpy b 0 pg 0 m memcpy pg 0 pg m r m memcpy pg r m 1 pg r max r memcpy b max items m pg max items m m memcpy pg max items r m pg max items r r m set item pg r m ins key set item pg max items 1 r m ins oid memcpy pg max items max m 1 pg max items max max r ins oid page id if height 0 ins key get item b max items m setn items pg max m 1 setn items b m else ins key get item b m 1 setn items pg max m setn items b m 1 db pool unfix b return op overflow finally if pg null db pool unfix pg storageimpl pageid getpage pageid getnitems getitem getitem maxitems op_not_found op_overflow getitem maxitems getitem maxitems putpage pageid setitem op_overwrite putpage pageid maxitems maxitems setitem setitem maxitems setnitems getnitems op_done pageid allocatepage putpage pageid maxitems maxitems setitem setitem maxitems maxitems maxitems maxitems maxitems maxitems maxitems maxitems maxitems setitem setitem maxitems maxitems maxitems pageid getitem maxitems setnitems setnitems getitem setnitems setnitems op_overflow static int handle page underflow storage impl db page pg int r int height int n items getn items pg page a db put page get item pg max items r 1 int an getn items a if r n items exists greater page page b db get page get item pg max items r 2 int bn getn items b assert that bn an if height 1 memcpy a an pg r 1 an 1 bn 1 if an bn max reallocation of nodes between pages a and b int i bn an bn 1 db pool unfix b b db put page get item pg max items r 2 memcpy a an b 0 i memcpy b 0 b i bn i memcpy a max items an i b max items i i memcpy b max items bn i b max items bn bn i if height 1 memcpy pg r a an i 1 1 else memcpy pg r a max items an i 1 setn items b getn items b i setn items a getn items a i db pool unfix a db pool unfix b return op done else merge page b to a memcpy a an b 0 bn memcpy a max items an bn b max items bn bn db free page get item pg max items r 2 memcpy pg max items n items pg max items n items 1 n items r 1 memcpy pg r pg r 1 n items r 1 setn items a getn items a bn setn items pg n items 1 db pool unfix a db pool unfix b return n items max 2 op underflow op done else page b is before a page b db get page get item pg max items r int bn getn items b assert that bn an if height 1 an 1 bn 1 if an bn max reallocation of nodes between pages a and b int i bn an bn 1 db pool unfix b b db put page get item pg max items r memcpy a i a 0 an memcpy a 0 b bn i i memcpy a max items an i a max items an an memcpy a max items i b max items bn i if height 1 memcpy a i 1 pg r 1 1 memcpy pg r 1 b bn i 1 1 else memcpy pg r 1 b max items bn i 1 setn items b getn items b i setn items a getn items a i db pool unfix a db pool unfix b return op done else merge page b to a memcpy a bn a 0 an memcpy a 0 b 0 bn memcpy a max items an bn a max items an an memcpy a max items bn b max items bn bn if height 1 memcpy a bn 1 pg r 1 1 db free page get item pg max items r set item pg max items r get item pg max items r 1 setn items a getn items a bn setn items pg n items 1 db pool unfix a db pool unfix b return n items max 2 op underflow op done handlepageunderflow storageimpl nitems getnitems putpage getitem maxitems getnitems nitems getpage getitem maxitems getnitems putpage getitem maxitems maxitems maxitems maxitems maxitems maxitems setnitems getnitems setnitems getnitems op_done maxitems maxitems freepage getitem maxitems maxitems nitems maxitems nitems nitems nitems setnitems getnitems setnitems nitems nitems op_underflow op_done getpage getitem maxitems getnitems putpage getitem maxitems maxitems maxitems maxitems maxitems maxitems setnitems getnitems setnitems getnitems op_done maxitems maxitems maxitems maxitems freepage getitem maxitems setitem maxitems getitem maxitems setnitems getnitems setnitems nitems nitems op_underflow op_done static int remove storage impl db int page id int oid int height page pg db get page page id try int i n getn items pg l 0 r n if height 0 while l r i l r 1 if oid get item pg max items 1 i l i 1 else r i if r n get item pg max items r 1 oid db pool unfix pg pg null pg db put page page id memcpy pg r pg r 1 n r 1 memcpy pg max items n 1 pg max items n n r 1 setn items pg n return n max 2 op underflow op done return op not found else while l r i l r 1 if oid get item pg i l i 1 else r i int result remove db get item pg max items r 1 oid height if result op underflow db pool unfix pg pg null pg db put page page id return handle page underflow db pg r height return result finally if pg null db pool unfix pg storageimpl pageid getpage pageid getnitems getitem maxitems getitem maxitems putpage pageid maxitems maxitems setnitems op_underflow op_done op_not_found getitem getitem maxitems op_underflow putpage pageid handlepageunderflow logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog offered keys list node client core core random source random short priority class boolean isssk super false this keys new hash set key this keys list new vector key this random random this priority class priority class this core core this isssk isssk offeredkeyslist nodeclientcore randomsource priorityclass hashset keyslist priorityclass priorityclass called when a key is found when it no longer belongs to this list etc public synchronized void remove key key assert keys list size keys size if keys remove key keys list remove key if logminor logger minor this found key removing it for this size now keys list size assert keys list size keys size keyslist keyslist keyslist keyslist public synchronized boolean is empty object container container return keys is empty isempty objectcontainer isempty override public long count all keys object container container client context context not supported throw new unsupported operation exception countallkeys objectcontainer clientcontext unsupportedoperationexception override public long count sendable keys object container container client context context not supported throw new unsupported operation exception countsendablekeys objectcontainer clientcontext unsupportedoperationexception private static class my sendable request item implements sendable request item final key key my sendable request item key key this key key mysendablerequestitem sendablerequestitem mysendablerequestitem this key key public void dump ignore we will be gc ed override public synchronized sendable request item choose key keys fetching locally fetching object container container client context context assert keys list size keys size if keys size 1 shortcut the common case key k keys list get 0 if fetching has key k return null keys remove k keys list set size 0 return new my sendable request item k for int i 0 i 10 i pick a random key if keys list is empty return null int ptr random next int keys list size avoid shuffling penalty by swapping the chosen element with the end key k keys list get ptr if fetching has key k continue keys list set ptr keys list get keys list size 1 keys list set size keys list size 1 keys remove k assert keys list size keys size return new my sendable request item k return null sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext keyslist keyslist haskey keyslist setsize mysendablerequestitem keyslist isempty nextint keyslist keyslist haskey keyslist keyslist keyslist keyslist setsize keyslist keyslist mysendablerequestitem override public synchronized boolean has valid keys keys fetching locally fetching object container container client context context assert keys list size keys size if keys size 1 shortcut the common case key k keys list get 0 if fetching has key k return false return true for int i 0 i 10 i pick a random key if keys list is empty return false int ptr random next int keys list size key k keys list get ptr if fetching has key k continue return true return false hasvalidkeys keysfetchinglocally objectcontainer clientcontext keyslist keyslist haskey keyslist isempty nextint keyslist keyslist haskey override public request client get client object container container return this requestclient getclient objectcontainer override public client requester get client request fixme is this safe return null clientrequester getclientrequest override public short get priority class object container container return priority class getpriorityclass objectcontainer priorityclass override public int get retry count return 0 all keys have equal chance even if they ve been tried before getretrycount override public void internal error throwable t request scheduler sched object container container client context context boolean persistent logger error this internal error t t internalerror requestscheduler objectcontainer clientcontext override public sendable request sender get sender object container container client context context return new sendable request sender public boolean send node client core core request scheduler sched client context context chosen block req key key my sendable request item req token key have to cache it in order to propagate it fixme don t let a node force us to start a real request for a specific key we check the datastore take up offers if any on a short timeout and then quit if we still haven t fetched the data obviously this may have a marginal impact on load but it should only be marginal core async get key true true new simple request sender completion listener public void completed boolean success ignore return true sendablerequestsender getsender objectcontainer clientcontext sendablerequestsender nodeclientcore requestscheduler clientcontext chosenblock mysendablerequestitem asyncget simplerequestsendercompletionlistener public boolean send node client core core request scheduler sched client context context chosen block req key key my sendable request item req token key have to cache it in order to propagate it fixme don t let a node force us to start a real request for a specific key we check the datastore take up offers if any on a short timeout and then quit if we still haven t fetched the data obviously this may have a marginal impact on load but it should only be marginal core async get key true true new simple request sender completion listener public void completed boolean success ignore return true nodeclientcore requestscheduler clientcontext chosenblock mysendablerequestitem asyncget simplerequestsendercompletionlistener core async get key true true new simple request sender completion listener public void completed boolean success ignore asyncget simplerequestsendercompletionlistener override public boolean is cancelled object container container return false iscancelled objectcontainer public synchronized void queue key key key assert keys list size keys size if keys add key keys list add key if logminor logger minor this queued key key on this assert keys list size keys size queuekey keyslist keyslist keyslist override public key get node key sendable request item token object container container return my sendable request item token key getnodekey sendablerequestitem objectcontainer mysendablerequestitem override public boolean isssk return isssk override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context throw new unsupported operation exception transient only persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext unsupportedoperationexception override public boolean is insert return false isinsert override public client request scheduler get scheduler client context context if isssk return context get ssk fetch scheduler else return context get chk fetch scheduler clientrequestscheduler getscheduler clientcontext getsskfetchscheduler getchkfetchscheduler public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception override public void pre register object container container client context context boolean to network ignore preregister objectcontainer clientcontext tonetwork public bookmark manager node client core n put paths main category this node n try read the backup file if necessary if bookmarks file exists bookmarks file length 0 throw new io exception logger normal this attempting to read the bookmark file from bookmarks file to string simple field set sfs simple field set read from bookmarks file false true read bookmarks main category sfs catch malformedurl exception mue catch io exception ioe logger error this error reading the bookmark file bookmarks file to string ioe get message ioe try if backup bookmarks file exists backup bookmarks file can read backup bookmarks file length 0 logger normal this attempting to read the backup bookmark file from backup bookmarks file to string simple field set sfs simple field set read from backup bookmarks file false true read bookmarks main category sfs else logger normal this we couldn t find the backup either file util get canonical file backup bookmarks file restore the default bookmark set read bookmarks main category default bookmarks catch io exception e logger error this error reading the backup bookmark file e get message e bookmarkmanager nodeclientcore putpaths main_category bookmarksfile bookmarksfile ioexception bookmarksfile tostring simplefieldset simplefieldset readfrom bookmarksfile readbookmarks main_category malformedurlexception ioexception bookmarksfile tostring getmessage backupbookmarksfile backupbookmarksfile canread backupbookmarksfile backupbookmarksfile tostring simplefieldset simplefieldset readfrom backupbookmarksfile readbookmarks main_category fileutil getcanonicalfile backupbookmarksfile readbookmarks main_category default_bookmarks ioexception getmessage public void re add default bookmarks bookmark category bc new bookmark category l10n default bookmarks new date add bookmark bc innerreadbookmarks bc default bookmarks readddefaultbookmarks bookmarkcategory bookmarkcategory defaultbookmarks addbookmark _innerreadbookmarks default_bookmarks public void on found edition long edition usk key object container container client context context boolean was metadata short codec byte data boolean new known good boolean new slot too if new known good freeneturi uri key copy edition geturi node make client priority prefetch uri 60 60 1000 f proxy toadlet max length null priority return list bookmark item items main category get all items for int i 0 i items size i if usk equals items get i get key type continue try freeneturi furi new freeneturi items get i get key usk usk usk create furi if usk equals key false items get i set edition edition node break catch malformedurl exception mue store bookmarks onfoundedition objectcontainer clientcontext wasmetadata newknowngood newslottoo newknowngood makeclient fproxytoadlet max_length bookmarkitem main_category getallitems getkeytype getkey setedition malformedurlexception storebookmarks public short get polling priority normal return priority getpollingprioritynormal public short get polling priority progress return priority getpollingpriorityprogress public string l10n string key return l10n get string bookmark manager key getstring bookmarkmanager public string parent path string path if path equals return return path substring 0 path substring 0 path length 1 last index of parentpath lastindexof public bookmark get bookmark by path string path synchronized bookmarks return bookmark bookmarks get path getbookmarkbypath public bookmark category get category by path string path bookmark cat get bookmark by path path if cat instanceof bookmark category return bookmark category cat return null bookmarkcategory getcategorybypath getbookmarkbypath bookmarkcategory bookmarkcategory public bookmark item get item by path string path if get bookmark by path path instanceof bookmark item return bookmark item get bookmark by path path return null bookmarkitem getitembypath getbookmarkbypath bookmarkitem bookmarkitem getbookmarkbypath public void add bookmark string parent path bookmark bookmark if logger should log logger minor this logger minor this adding bookmark bookmark to parent path bookmark category parent get category by path parent path parent add bookmark bookmark put paths parent path bookmark get name bookmark instanceof bookmark category bookmark if bookmark instanceof bookmark item subscribe tousk bookmark item bookmark addbookmark parentpath shouldlog parentpath bookmarkcategory getcategorybypath parentpath addbookmark putpaths parentpath getname bookmarkcategory bookmarkitem subscribetousk bookmarkitem public void rename bookmark string path string new name bookmark bookmark get bookmark by path path string old name bookmark get name string old path old name string new path path substring 0 path index of old path new name bookmark instanceof bookmark category bookmark set name new name synchronized bookmarks bookmarks remove path bookmarks put new path bookmark store bookmarks renamebookmark newname getbookmarkbypath oldname getname oldpath oldname newpath indexof oldpath newname bookmarkcategory setname newname newpath storebookmarks public void move bookmark string bookmark path string new parent path bookmark b get bookmark by path bookmark path add bookmark new parent path b get category by path parent path bookmark path remove bookmark b remove paths bookmark path movebookmark bookmarkpath newparentpath getbookmarkbypath bookmarkpath addbookmark newparentpath getcategorybypath parentpath bookmarkpath removebookmark removepaths bookmarkpath public void remove bookmark string path bookmark bookmark get bookmark by path path if bookmark null return if bookmark instanceof bookmark category bookmark category cat bookmark category bookmark for int i 0 i cat size i remove bookmark path cat get i get name cat get i instanceof bookmark category else if bookmark item bookmark get key type equals usk try usk u bookmark item bookmark getusk this node usk manager unsubscribe u this uskcb catch malformedurl exception mue get category by path parent path path remove bookmark bookmark synchronized bookmarks bookmarks remove path removebookmark getbookmarkbypath bookmarkcategory bookmarkcategory bookmarkcategory removebookmark getname bookmarkcategory bookmarkitem getkeytype bookmarkitem uskmanager malformedurlexception getcategorybypath parentpath removebookmark public void move bookmark up string path boolean store bookmark category parent get category by path parent path path parent move bookmark up get bookmark by path path if store store bookmarks movebookmarkup bookmarkcategory getcategorybypath parentpath movebookmarkup getbookmarkbypath storebookmarks public void move bookmark down string path boolean store bookmark category parent get category by path parent path path parent move bookmark down get bookmark by path path if store store bookmarks movebookmarkdown bookmarkcategory getcategorybypath parentpath movebookmarkdown getbookmarkbypath storebookmarks private void put paths string path bookmark b synchronized bookmarks bookmarks put path b if b instanceof bookmark category for int i 0 i bookmark category b size i bookmark child bookmark category b get i put paths path child get name child instanceof bookmark item child putpaths bookmarkcategory bookmarkcategory bookmarkcategory putpaths getname bookmarkitem private void remove paths string path if get bookmark by path path instanceof bookmark category bookmark category cat get category by path path for int i 0 i cat size i remove paths path cat get i get name cat get i instanceof bookmark category bookmarks remove path removepaths getbookmarkbypath bookmarkcategory bookmarkcategory getcategorybypath removepaths getname bookmarkcategory public freeneturi get bookmarkur is list bookmark item items main category get all items freeneturi uris new freeneturi items size for int i 0 i items size i uris i items get i geturi return uris getbookmarkuris bookmarkitem main_category getallitems public void store bookmarks logger normal this attempting to save bookmarks to bookmarks file to string simple field set sfs null synchronized bookmarks if is saving bookmarks return is saving bookmarks true sfs to simple field set file output stream fos null try fos new file output stream backup bookmarks file sfs write to fos if file util rename to backup bookmarks file bookmarks file logger error this unable to rename backup bookmarks file to string to bookmarks file to string catch io exception ioe logger error this an error has occured saving the bookmark file ioe get message ioe finally closer close fos synchronized bookmarks is saving bookmarks false storebookmarks bookmarksfile tostring simplefieldset issavingbookmarks issavingbookmarks tosimplefieldset fileoutputstream fileoutputstream backupbookmarksfile writeto fileutil renameto backupbookmarksfile bookmarksfile backupbookmarksfile tostring bookmarksfile tostring ioexception getmessage issavingbookmarks private void read bookmarks bookmark category category simple field set sfs innerreadbookmarks category sfs readbookmarks bookmarkcategory simplefieldset _innerreadbookmarks private void subscribe tousk bookmark item item if usk equals item get key type try usk u item getusk this node usk manager subscribe u this uskcb true this catch malformedurl exception mue subscribetousk bookmarkitem getkeytype uskmanager malformedurlexception private synchronized void innerreadbookmarks string prefix bookmark category category simple field set sfs boolean has been parsed without any problem true boolean is root equals prefix main category equals category synchronized bookmarks if is root put paths prefix category name category try int nb bookmarks sfs get int bookmark item name int nb categories sfs get int bookmark category name for int i 0 i nb bookmarks i simple field set subset sfs get subset bookmark item name i try bookmark item item new bookmark item subset node alerts string name is root prefix category name item name put paths name item category add bookmark item subscribe tousk item catch malformedurl exception e throw new fs parse exception e for int i 0 i nb categories i simple field set subset sfs get subset bookmark category name i bookmark category current category new bookmark category subset category add bookmark current category string name is root prefix category name innerreadbookmarks name current category subset get subset content catch fs parse exception e logger error this error parsing the bookmarks file e has been parsed without any problem false if has been parsed without any problem store bookmarks _innerreadbookmarks bookmarkcategory simplefieldset hasbeenparsedwithoutanyproblem isroot main_category isroot putpaths nbbookmarks getint bookmarkitem nbcategories getint bookmarkcategory nbbookmarks simplefieldset getsubset bookmarkitem bookmarkitem bookmarkitem isroot putpaths addbookmark subscribetousk malformedurlexception fsparseexception nbcategories simplefieldset getsubset bookmarkcategory bookmarkcategory currentcategory bookmarkcategory addbookmark currentcategory isroot _innerreadbookmarks currentcategory getsubset fsparseexception hasbeenparsedwithoutanyproblem hasbeenparsedwithoutanyproblem storebookmarks public simple field set to simple field set simple field set sfs new simple field set true sfs put version 1 synchronized bookmarks sfs put all overwrite bookmark manager to simple field set main category return sfs simplefieldset tosimplefieldset simplefieldset simplefieldset putalloverwrite bookmarkmanager tosimplefieldset main_category public static simple field set to simple field set bookmark category cat simple field set sfs new simple field set true list bookmark category bc cat get sub categories for int i 0 i bc size i bookmark category current cat bc get i sfs put bookmark category name i current cat get simple field set sfs put bookmark category name bc size list bookmark item bi cat get items for int i 0 i bi size i sfs put bookmark item name i bi get i get simple field set sfs put bookmark item name bi size return sfs simplefieldset tosimplefieldset bookmarkcategory simplefieldset simplefieldset bookmarkcategory getsubcategories bookmarkcategory currentcat bookmarkcategory currentcat getsimplefieldset bookmarkcategory bookmarkitem getitems bookmarkitem getsimplefieldset bookmarkitem public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception rtreer2 page storage storage i persistent obj rectangler2 r branch storage create link card branch set size card b new rectangler2 card set branch 0 new rectangler2 r obj n 1 for int i 1 i card i b i new rectangler2 rtreer2page ipersistent createlink setsize setbranch rtreer2 page storage storage rtreer2 page root rtreer2 page p branch storage create link card branch set size card b new rectangler2 card n 2 set branch 0 root cover root set branch 1 p cover p for int i 2 i card i b i new rectangler2 rtreer2page rtreer2page rtreer2page createlink setsize setbranch setbranch rtreer2 page rtreer2page rtreer2 page insert storage storage rectangler2 r i persistent obj int level modify if level 0 not leaf page int i mini 0 double min incr double max value double min area double max value for i 0 i n i double area b i area double incr rectangler2 join area b i r area if incr min incr min incr incr min area area mini i else if incr min incr area min area min area area mini i rtreer2 page p rtreer2 page branch get mini rtreer2 page q p insert storage r obj level if q null child was not split b mini join r return null else child was split set branch mini p cover p return add branch storage q cover q else return add branch storage new rectangler2 r obj rtreer2page ipersistent minincr max_value minarea max_value joinarea minincr minincr minarea minincr minarea minarea rtreer2page rtreer2page rtreer2page setbranch addbranch addbranch int remove rectangler2 r i persistent obj int level array list reinsert list if level 0 for int i 0 i n i if r intersects b i rtreer2 page pg rtreer2 page branch get i int reinsert level pg remove r obj level reinsert list if reinsert level 0 if pg n min fill set branch i pg cover pg modify else not enough entries in child reinsert list add pg reinsert level level 1 remove branch i return reinsert level else for int i 0 i n i if branch contains element i obj remove branch i return 0 return 1 ipersistent arraylist reinsertlist rtreer2page rtreer2page reinsertlevel reinsertlist reinsertlevel minfill setbranch reinsertlist reinsertlevel removebranch reinsertlevel containselement removebranch void find rectangler2 r array list result int level if level 0 this is an internal node in the tree for int i 0 i n i if r intersects b i rtreer2 page branch get i find r result level else this is a leaf node for int i 0 i n i if r intersects b i result add branch get i arraylist rtreer2page void purge int level if level 0 this is an internal node in the tree for int i 0 i n i rtreer2 page branch get i purge level deallocate rtreer2page final void set branch int i rectangler2 r i persistent obj b i r branch set object i obj setbranch ipersistent setobject final void remove branch int i n 1 system arraycopy b i 1 b i n i branch remove i branch set size card modify removebranch setsize final rtreer2 page add branch storage storage rectangler2 r i persistent obj if n card set branch n r obj return null else return split page storage r obj rtreer2page addbranch ipersistent setbranch splitpage final rtreer2 page split page storage storage rectangler2 r i persistent obj int i j seed0 0 seed1 0 double rect area new double card 1 double waste double worst waste double min value as the seeds for the two groups find two rectangles which waste the most area if covered by a single rectangle rect area 0 r area for i 0 i card i rect area i 1 b i area rectangler2 bp r for i 0 i card i for j i 1 j card j waste rectangler2 join area bp b j 1 rect area i rect area j if waste worst waste worst waste waste seed0 i seed1 j bp b i byte taken new byte card rectangler2 group0 group1 double group area0 group area1 int group card0 group card1 rtreer2 page pg taken seed1 1 2 group1 new rectangler2 b seed1 1 if seed0 0 group0 new rectangler2 r pg new rtreer2 page storage obj r else group0 new rectangler2 b seed0 1 pg new rtreer2 page storage branch get raw seed0 1 group0 set branch seed0 1 r obj group card0 group card1 1 group area0 rect area seed0 group area1 rect area seed1 split remaining rectangles between two groups the one chosen is the one with the greatest difference in area expansion depending on which group the rect most strongly attracted to one group and repelled from the other while group card0 group card1 card 1 group card0 card 1 min fill group card1 card 1 min fill int better group 1 chosen 1 double biggest diff 1 for i 0 i card i if taken i 0 double diff rectangler2 join area group0 b i group area0 rectangler2 join area group1 b i group area1 if diff biggest diff diff biggest diff chosen i if diff 0 better group 0 biggest diff diff else better group 1 biggest diff diff assert that chosen 0 if better group 0 group0 join b chosen group area0 group0 area taken chosen 1 pg set branch group card0 b chosen branch get raw chosen else group card1 1 group1 join b chosen group area1 group1 area taken chosen 2 if one group gets too full then remaining rectangle are split between two groups in such way to balance cards of two groups if group card0 group card1 card 1 for i 0 i card i if taken i 0 if group card0 group card1 taken i 2 group card1 1 else taken i 1 pg set branch group card0 b i branch get raw i pg n group card0 n group card1 for i 0 j 0 i group card1 j if taken j 2 set branch i b j branch get raw j return pg rtreer2page splitpage ipersistent rectarea worstwaste min_value rectarea rectarea joinarea rectarea rectarea worstwaste worstwaste grouparea0 grouparea1 groupcard0 groupcard1 rtreer2page rtreer2page rtreer2page getraw setbranch groupcard0 groupcard1 grouparea0 rectarea grouparea1 rectarea groupcard0 groupcard1 groupcard0 minfill groupcard1 minfill bettergroup biggestdiff joinarea grouparea0 joinarea grouparea1 biggestdiff biggestdiff bettergroup biggestdiff bettergroup biggestdiff bettergroup grouparea0 setbranch groupcard0 getraw groupcard1 grouparea1 groupcard0 groupcard1 groupcard0 groupcard1 groupcard1 setbranch groupcard0 getraw groupcard0 groupcard1 groupcard1 setbranch getraw final rectangler2 cover rectangler2 r new rectangler2 b 0 for int i 1 i n i r join b i return r class persistent set t extends i persistent extends btree t implements i persistent set t persistent set type class descriptor tp object unique true persistentset ipersistent ipersistentset persistentset classdescriptor tpobject public boolean is empty return n elems 0 isempty nelems public boolean contains object o if o instanceof i persistent key key new key i persistent o iterator i iterator key key ascent order return i has next return false ipersistent ipersistent ascent_order hasnext public object to array return to persistent array toarray topersistentarray public e e to array e arr return e super to array t arr toarray toarray public boolean add t obj return put new key obj obj public boolean remove object o t obj t o return remove if exists new btree key check key new key obj obj get oid removeifexists btreekey checkkey getoid public boolean equals object o if o this return true if o instanceof set return false collection c collection o if c size size return false return contains all c containsall public int hash code int h 0 iterator i iterator while i has next h i persistent i next get oid return h hashcode hasnext ipersistent getoid private node allowed value node public node get allowed value node return allowed value node allowedvaluenode getallowedvaluenode allowedvaluenode public allowed value node node allowed value node node allowedvalue allowedvaluenode public static boolean is allowed value node node node return elem name equals node get name isallowedvaluenode elem_name getname public void set value string value get allowed value node set value value setvalue getallowedvaluenode setvalue public string get value return get allowed value node get value getvalue getallowedvaluenode getvalue override public void log object o class source string message throwable e int priority override public void log object source string message int priority override public void log object o string message throwable e int priority override public void log class c string message int priority override public void log class c string message throwable e int priority public long min flags return 0 minflags public long not flags return 0 notflags public long any flags return 0 anyflags override public boolean instance should log int priority class c return false instanceshouldlog override public boolean instance should log int prio object o return false instanceshouldlog override public void set threshold int thresh setthreshold override public int get threshold return 0 getthreshold override public void set threshold string symbolic threshold setthreshold symbolicthreshold override public void set detailed thresholds string details setdetailedthresholds override public final void instance register log threshold callback log threshold callback ltc instanceregisterlogthresholdcallback logthresholdcallback private buffered image mask public halftone filter bufferedimage halftonefilter set the density of the image in the range 0 1 arg density the density public void set density float density this density density setdensity public float get density return density getdensity set the softness of the effect in the range 0 1 param softness the softness min value 0 max value 1 see get softness public void set softness float softness this softness softness getsoftness setsoftness get the softness of the effect return the softness see set softness public float get softness return softness setsoftness getsoftness public void set mask buffered image mask this mask mask setmask bufferedimage public buffered image get mask return mask bufferedimage getmask public void set invert boolean invert this invert invert setinvert public boolean get invert return invert getinvert public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null if mask null return dst int mask width mask get width int mask height mask get height float d density 1 softness float lower 255 d softness float upper 255 d float s 255 softness int in pixels new int width int mask pixels new int mask width for int y 0 y height y getrgb src 0 y width 1 in pixels getrgb mask 0 y mask height mask width 1 mask pixels for int x 0 x width x int maskrgb mask pixels x mask width int inrgb in pixels x int v pixel utils brightness maskrgb int iv pixel utils brightness inrgb float f image math smooth step iv s iv s v int a int 255 f if invert a 255 a in pixels x a 24 inrgb 0x00ffffff in pixels x inrgb 0xff000000 a 16 a 8 a setrgb dst 0 y width 1 in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage maskwidth getwidth maskheight getheight inpixels maskpixels maskwidth inpixels maskheight maskwidth maskpixels maskpixels maskwidth inpixels pixelutils pixelutils imagemath smoothstep inpixels inpixels inpixels override public string to string return stylize halftone tostring public plugin respirator node node plugin manager pm fred plugin plug this node node this hlsc node client core make client request starter interactive priority class this plugin plug this plugin manager pm if plugin instanceof fred pluginl10n page maker new page maker fred pluginl10n plugin plugin manager getf proxy theme else page maker new page maker null plugin manager getf proxy theme pluginrespirator pluginmanager fredplugin clientcore makeclient requeststarter interactive_priority_class pluginmanager fredpluginl10n pagemaker pagemaker fredpluginl10n pluginmanager getfproxytheme pagemaker pagemaker pluginmanager getfproxytheme public high level simple client gethl simple client throws plugin security exception public high level simple client gethl simple client return hlsc highlevelsimpleclient gethlsimpleclient pluginsecurityexception highlevelsimpleclient gethlsimpleclient public node get node return node getnode public filter callback make filter callback string path try return node client core create filter callback uri pre encoder encodeuri path null catch uri syntax exception e throw new error e filtercallback makefiltercallback clientcore createfiltercallback uripreencoder urisyntaxexception public page maker get page maker return page maker pagemaker getpagemaker pagemaker public html node add form child html node parent node string target string name html node form node parent node add child form new string action method enctype id name accept charset new string target post multipart form data name name utf 8 form node add child input new string type name value new string hidden form password node client core form password return form node htmlnode addformchild htmlnode parentnode htmlnode formnode parentnode addchild formnode addchild formpassword clientcore formpassword formnode public plugin talker get plugin talker fred plugin talker fpt string pluginname string identifier throws plugin not found exception return new plugin talker fpt node pluginname identifier plugintalker getplugintalker fredplugintalker pluginnotfoundexception plugintalker public final static void wait int wait time try thread sleep wait time catch exception e waittime waittime public final static void wait random int time int wait time int math random double time try thread sleep wait time catch exception e waitrandom waittime waittime resettinghtl probe request handler peer node source long uid resettinghtl probe request sender sender this source source this uid uid this sender sender resettinghtlproberequesthandler peernode resettinghtlproberequestsender static void start message m peer node source node n double target long uid m get long dmt uid double nearest loc m get double dmt nearest location double best m get double dmt best location short htl m get short dmt htl if htl n maxhtl htl n maxhtl boolean reset nearest loc false resettinghtl probe request sender sender new resettinghtl probe request sender target htl uid n nearest loc reset nearest loc source best resettinghtl probe request handler handler new resettinghtl probe request handler source uid sender sender add listener handler peer node peers n peers connected peers message accepted dmt createfnp accepted uid message trace dmt createfnprh probe trace uid sender get nearest loc sender get best htl short 1 short 1 n get location n swap identifier location manager extract locs peers true location manager extractui ds peers short 0 short 1 source swap identifier try source send async accepted null sender source send async trace null sender catch not connected exception e we completed id rather than locking it so we don t need to unlock return so all we need to do is not start the sender sender start peernode getlong nearestloc getdouble nearest_location getdouble best_location getshort resetnearestloc resettinghtlproberequestsender resettinghtlproberequestsender nearestloc resetnearestloc resettinghtlproberequesthandler resettinghtlproberequesthandler addlistener peernode connectedpeers createfnpaccepted createfnprhprobetrace getnearestloc getbest getlocation swapidentifier locationmanager extractlocs locationmanager extractuids swapidentifier sendasync sendasync notconnectedexception public void on completion double nearest double best short counter short unique counter short linear counter throws not connected exception source send async dmt createfnprh probe reply uid nearest best counter unique counter linear counter null sender oncompletion uniquecounter linearcounter notconnectedexception sendasync createfnprhprobereply uniquecounter linearcounter public void onrnf short htl double nearest double best short counter short unique counter short linear counter throws not connected exception message rnf dmt createfnp route not found uid htl message sub dmt createfnprh return sub message nearest best counter unique counter linear counter rnf rnf add sub message sub source send async rnf null sender uniquecounter linearcounter notconnectedexception createfnproutenotfound createfnprhreturnsubmessage uniquecounter linearcounter addsubmessage sendasync public void on received reject overload double nearest double best short counter short unique counter short linear counter string reason throws not connected exception message ro dmt createfnp rejected overload uid false message sub dmt createfnprh return sub message nearest best counter unique counter linear counter reason ro add sub message sub source send async ro null sender onreceivedrejectoverload uniquecounter linearcounter notconnectedexception createfnprejectedoverload createfnprhreturnsubmessage uniquecounter linearcounter addsubmessage sendasync public void on timeout double nearest double best short counter short unique counter short linear counter string reason throws not connected exception message ro dmt createfnp rejected overload uid true message sub dmt createfnprh return sub message nearest best counter unique counter linear counter reason ro add sub message sub source send async ro null sender ontimeout uniquecounter linearcounter notconnectedexception createfnprejectedoverload createfnprhreturnsubmessage uniquecounter linearcounter addsubmessage sendasync public void on trace long uid double nearest double best short htl short counter short unique counter double location long myuid short buffer peer locs short buffer peerui ds short fork count short linear counter string reason long prevuid throws not connected exception message trace dmt createfnprh probe trace uid nearest best htl counter unique counter location myuid peer locs peerui ds fork count linear counter reason prevuid source send async trace null sender ontrace uniquecounter shortbuffer peerlocs shortbuffer peeruids forkcount linearcounter notconnectedexception createfnprhprobetrace uniquecounter peerlocs peeruids forkcount linearcounter sendasync public property private string name public string get name return name getname public void set name string val if val null val name val setname private string value public string get value return value getvalue public void set value string val if val null val value val setvalue public class flush3d filter extends whole image filter public flush3d filter flush3dfilter wholeimagefilter flush3dfilter override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height for int y 0 y height y for int x 0 x width x int pixel in pixels y width x if pixel 0xff000000 y 0 x 0 int count 0 if in pixels y width x 1 0xff000000 count if in pixels y 1 width x 0xff000000 count if in pixels y 1 width x 1 0xff000000 count if count 2 pixel 0xffffffff out pixels index pixel return out pixels filterpixels inpixels transformedspace outpixels inpixels inpixels inpixels inpixels outpixels outpixels override public string to string return stylize flush 3d tostring public final class burn composite extends rgb composite public burn composite float alpha super alpha burncomposite rgbcomposite burncomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob if dir 255 dor clamp 255 int 255 sr 8 dir 1 else dor sr if dig 255 dog clamp 255 int 255 sg 8 dig 1 else dog sg if dib 255 dob clamp 255 int 255 sb 8 dib 1 else dob sb float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac private float octaves public turbulence function function2d basis float octaves super basis this octaves octaves turbulencefunction public void set octaves float octaves this octaves octaves setoctaves public float get octaves return octaves getoctaves public float evaluate float x float y float t 0 0f for float f 1 0f f octaves f 2 t math abs basis evaluate f x f y f return t create a bulk data transmitter param prb the partially received bulk containing the file we want to send or the part of it that we have so far param peer the peer we want to send it to param uid the unique identifier for this data transfer param master throttle the overall output throttle param no wait if true don t wait for an fnp bulk received all return as soon as we ve sent everything throws disconnected exception if the peer we are trying to send to becomes disconnected public bulk transmitter partially received bulk prb peer context peer long uid boolean no wait byte counter ctr throws disconnected exception this prb prb this peer peer this uid uid this no wait no wait this ctr ctr if ctr null throw new null pointer exception peer bootid peer get bootid need to sync on prb while doing both operations to avoid race condition specifically we must not get calls to block received until blocks not sent but present has been set and it must be accurate so there must not be an unlocked period between cloning and adding synchronized prb we can just clone it blocks not sent but present prb clone blocks received prb add this try prb usm add async filter message filter create set no timeout set source peer set type dmt fnp bulk receive aborted set field dmt uid uid new async message filter callback public void on matched message m cancel other side sent fnp bulk receive aborted public boolean should timeout synchronized bulk transmitter this if cancelled finished return true if bulk transmitter this prb is aborted return true return false public void on timeout ignore public void on disconnect peer context ctx ignore public void on restarted peer context ctx ignore prb usm add async filter message filter create set no timeout set source peer set type dmt fnp bulk received all set field dmt uid uid new async message filter callback public void on matched message m completed public boolean should timeout synchronized bulk transmitter this if cancelled return true if finished return system current time millis finish time final ack timeout if bulk transmitter this prb is aborted return true return false public void on timeout ignore public void on disconnect peer context ctx ignore public void on restarted peer context ctx ignore catch disconnected exception e cancel disconnected throw e packet size dmt bulk packet transmit size prb block size peer get outgoing mangler full headers length one message partiallyreceivedbulk masterthrottle nowait fnpbulkreceivedall disconnectedexception bulktransmitter partiallyreceivedbulk peercontext nowait bytecounter disconnectedexception nowait nowait nullpointerexception peerbootid getbootid blockreceived blocksnotsentbutpresent blocksnotsentbutpresent cloneblocksreceived addasyncfilter messagefilter setnotimeout setsource settype fnpbulkreceiveaborted setfield asyncmessagefiltercallback onmatched fnpbulkreceiveaborted shouldtimeout bulktransmitter bulktransmitter isaborted ontimeout ondisconnect peercontext onrestarted peercontext addasyncfilter messagefilter setnotimeout setsource settype fnpbulkreceivedall setfield asyncmessagefiltercallback onmatched shouldtimeout bulktransmitter currenttimemillis finishtime final_ack_timeout bulktransmitter isaborted ontimeout ondisconnect peercontext onrestarted peercontext disconnectedexception packetsize bulkpackettransmitsize blocksize getoutgoingmangler fullheaderslengthonemessage prb usm add async filter message filter create set no timeout set source peer set type dmt fnp bulk receive aborted set field dmt uid uid new async message filter callback public void on matched message m cancel other side sent fnp bulk receive aborted addasyncfilter messagefilter setnotimeout setsource settype fnpbulkreceiveaborted setfield asyncmessagefiltercallback onmatched fnpbulkreceiveaborted public boolean should timeout synchronized bulk transmitter this if cancelled finished return true if bulk transmitter this prb is aborted return true return false shouldtimeout bulktransmitter bulktransmitter isaborted return false public void on timeout ignore ontimeout ignore public void on disconnect peer context ctx ignore ondisconnect peercontext ignore public void on restarted peer context ctx ignore onrestarted peercontext prb usm add async filter message filter create set no timeout set source peer set type dmt fnp bulk received all set field dmt uid uid new async message filter callback public void on matched message m completed addasyncfilter messagefilter setnotimeout setsource settype fnpbulkreceivedall setfield asyncmessagefiltercallback onmatched public boolean should timeout synchronized bulk transmitter this if cancelled return true if finished return system current time millis finish time final ack timeout if bulk transmitter this prb is aborted return true return false shouldtimeout bulktransmitter currenttimemillis finishtime final_ack_timeout bulktransmitter isaborted return false public void on timeout ignore ontimeout ignore public void on disconnect peer context ctx ignore ondisconnect peercontext ignore public void on restarted peer context ctx ignore onrestarted peercontext received a block set the relevant bit to 1 to indicate that we have the block but haven t sent it yet only called by partially received bulk param block the block number that has been received synchronized void block received int block blocks not sent but present set bit block true notify all partiallyreceivedbulk blockreceived blocksnotsentbutpresent setbit notifyall called when the prb is aborted public void on aborted send aborted message synchronized this notify all onaborted sendabortedmessage notifyall private void send aborted message synchronized this if sent cancel return sent cancel true try peer send async dmt createfnp bulk send aborted uid null ctr catch not connected exception e cool sendabortedmessage sentcancel sentcancel sendasync createfnpbulksendaborted notconnectedexception public void cancel string reason if logger should log logger minor this logger minor this cancelling this send aborted message synchronized this cancelled true cancel reason reason notify all prb remove this shouldlog sendabortedmessage cancelreason notifyall like cancel but without the negative overtones the client says it s got everything we believe them even if we haven t sent everything maybe they had a partial public void completed synchronized this finished true finish time system current time millis notify all prb remove this finishtime currenttimemillis notifyall send the file return true if the file was successfully sent false otherwise public boolean send boolean logminor logger should log logger minor this long last sent packet system current time millis outer while true if prb is aborted if logminor logger minor this aborted this return false int block no if peer get bootid peer bootid synchronized this cancelled true notify all prb remove bulk transmitter this if logminor logger minor this failed to send uid peer restarted peer return false synchronized this if finished return true if cancelled return false block no blocks not sent but present first one if block no 0 if no wait prb has whole file completed return true synchronized this wait for all packets to complete while true if failed packet cancel packet send failed return false if logger should log logger minor this logger minor this waiting for packets remaining in flight packets if in flight packets 0 break try wait if failed packet cancel packet send failed return false if in flight packets 0 break continue outer might be a packet catch interrupted exception e ignore wait for a packet to come in bulk received all or bulk receive aborted try wait 60 1000 catch interrupted exception e no problem continue long end system current time millis if end last sent packet timeout logger error this send timed out on this cancel timeout awaiting bulk received all return false continue send a packet byte buf prb get block data block no if buf null if logminor logger minor this block block no is null presumably the send is cancelled this already cancelled quit return false congestion control and bandwidth limiting try if logminor logger minor this sending packet block no peer send throttled message dmt createfnp bulk packet send uid block no buf buf length ctr bulk receiver timeout false new unsent packet tag synchronized this blocks not sent but present set bit block no false last sent packet system current time millis catch not connected exception e cancel disconnected if logminor logger minor this canclled not connected this return false catch waited too long exception e logger error this failed to send bulk packet block no for this return false catch sync send waited too long exception e impossible logger error this impossible caught e e return false shouldlog lastsentpacket currenttimemillis isaborted blockno getbootid peerbootid notifyall bulktransmitter blockno blocksnotsentbutpresent firstone blockno nowait haswholefile failedpacket shouldlog inflightpackets inflightpackets failedpacket inflightpackets interruptedexception bulkreceivedall bulkreceiveaborted interruptedexception currenttimemillis lastsentpacket bulkreceivedall getblockdata blockno blockno blockno sendthrottledmessage createfnpbulkpacketsend blockno bulkreceiver unsentpackettag blocksnotsentbutpresent setbit blockno lastsentpacket currenttimemillis notconnectedexception waitedtoolongexception blockno syncsendwaitedtoolongexception private unsent packet tag synchronized bulk transmitter this in flight packets unsentpackettag bulktransmitter inflightpackets public void acknowledged complete false private void complete boolean failed synchronized this if finished return finished true synchronized bulk transmitter this if failed failed packet true bulk transmitter this notify all if logger should log logger minor this logger minor this packet failed for bulk transmitter this else in flight packets if in flight packets 0 bulk transmitter this notify all if logger should log logger minor this logger minor this packet sent bulk transmitter this remaining in flight in flight packets bulktransmitter failedpacket bulktransmitter notifyall shouldlog bulktransmitter inflightpackets inflightpackets bulktransmitter notifyall shouldlog bulktransmitter inflightpackets public void disconnected complete true public void fatal error complete true fatalerror public void sent wait for acknowledgment override public string to string return bulk transmitter uid peer short to string tostring bulktransmitter shorttostring public string get cancel reason return cancel reason getcancelreason cancelreason public message list inserter node my node high level simple client my client string my name identity manager my identity manager message manager my message manager super my node my client my name m identity manager my identity manager m message manager my message manager clear being inserted flags messagelistinserter mynode highlevelsimpleclient myclient myname identitymanager myidentitymanager messagemanager mymessagemanager mynode myclient myname midentitymanager myidentitymanager mmessagemanager mymessagemanager clearbeinginsertedflags each code own message list code has a flag which stores whether it is currently being inserted the purpose of this function is to clear those flags at startup ownmessagelist construct a border filter which does nothing public border filter borderfilter borderfilter construct a border filter param left border the left border value param top border the top border value param right border the right border value param bottom border the bottom border value param border paint the paint with which to fill the border public border filter int left border int top border int right border int bottom border paint border paint this left border left border this top border top border this right border right border this bottom border bottom border this border paint border paint borderfilter leftborder topborder rightborder bottomborder borderpaint borderfilter leftborder topborder rightborder bottomborder borderpaint leftborder leftborder topborder topborder rightborder rightborder bottomborder bottomborder borderpaint borderpaint set the border size on the left edge param left border the number of pixels of border to add to the edge min value 0 see get left border public void set left border int left border this left border left border leftborder getleftborder setleftborder leftborder leftborder leftborder returns the left border value return the left border value see set left border public int get left border return left border setleftborder getleftborder leftborder set the border size on the right edge param right border the number of pixels of border to add to the edge min value 0 see get right border public void set right border int right border this right border right border rightborder getrightborder setrightborder rightborder rightborder rightborder returns the right border value return the right border value see set right border public int get right border return right border setrightborder getrightborder rightborder set the border size on the top edge param top border the number of pixels of border to add to the edge min value 0 see get top border public void set top border int top border this top border top border topborder gettopborder settopborder topborder topborder topborder returns the top border value return the top border value see set top border public int get top border return top border settopborder gettopborder topborder set the border size on the bottom edge param bottom border the number of pixels of border to add to the edge min value 0 see get bottom border public void set bottom border int bottom border this bottom border bottom border bottomborder getbottomborder setbottomborder bottomborder bottomborder bottomborder returns the border border value return the border border value see set bottom border public int get bottom border return bottom border setbottomborder getbottomborder bottomborder set the border paint param border paint the paint with which to fill the border see get border paint public void set border paint paint border paint this border paint border paint borderpaint getborderpaint setborderpaint borderpaint borderpaint borderpaint get the border paint return the paint with which to fill the border see set border paint public paint get border paint return border paint setborderpaint getborderpaint borderpaint public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst new buffered image width left border right border height top border bottom border src get type graphics2d g dst create graphics if border paint null g set paint border paint if left border 0 g fill rect 0 0 left border height if right border 0 g fill rect width right border 0 right border height if top border 0 g fill rect left border 0 width left border right border top border if bottom border 0 g fill rect left border height bottom border width left border right border bottom border g draw rendered image src affine transform get translate instance left border right border g dispose return dst bufferedimage bufferedimage bufferedimage getwidth getheight bufferedimage leftborder rightborder topborder bottomborder gettype creategraphics borderpaint setpaint borderpaint leftborder fillrect leftborder rightborder fillrect rightborder rightborder topborder fillrect leftborder leftborder rightborder topborder bottomborder fillrect leftborder bottomborder leftborder rightborder bottomborder drawrenderedimage affinetransform gettranslateinstance leftborder rightborder override public string to string return distort border tostring yytoken int index string text int line int char begin int char end m index index m text text m line line m charbegin char begin m charend char end charbegin charend m_index m_text m_line m_charbegin charbegin m_charend charend override public string to string return text m text nindex m index nline m line nc beg m charbegin nc end m charend tostring m_text m_index m_line ncbeg m_charbegin ncend m_charend private string builder logs new string builder public string get version return version r version get svn revision stringbuilder stringbuilder getversion getsvnrevision public long get real version return version getrealversion private plugin respirator pr public void terminate pluginrespirator public string handlehttp get http request request throws pluginhttp exception if request get path ends with logs return logs to string string search request get param search if request get path ends with progress if progressmap contains key search return progressmap get search get request get param pushonupdate equals true else return no asyncronous search for search found else if request get path ends with result if progressmap contains key search return progressmap remove search getresult else return no asyncronous search for search found else string indexuri request is parameter set index request get param index default index site logs append show progress request get param showprogress br boolean showprogress request get param showprogress equals true return handle inner request get path search indexuri showprogress handlehttpget httprequest pluginhttpexception getpath endswith tostring getparam getpath endswith containskey getparam getpath endswith containskey isparameterset getparam default_index_site getparam getparam handleinner getpath private void append default page start string builder out out append html head title plug name title head body appenddefaultpagestart stringbuilder plugname private void append default page end string builder out out append center body html appenddefaultpageend stringbuilder append default post fields generates the main interface to the xml librarian param out param search param index private void append default post fields string builder out string search string index search html encoder encode search index html encoder encode index out append form method get table tr n out append td rowspan 2 width 280 h1 plug name h1 td n out append div style visibility hidden input type submit name find value find tabindex 1 input name showprogress value false div n out append td width 400 input type text value append search append name search size 40 input type submit name find value find tabindex 1 td rowspan 2 id librarian info if you had java script enabled you would be able to see some status information for your search td tr n out append tr td index input type text name index value append index append size 50 n out append tr table form script language java script document forms 0 showprogress value true document get element by id librarian info innerhtml you have java script enabled so you should be able to see live progress of your search please note this does not currently function properly with simultanious searches script n n appenddefaultpostfields xmllibrarian appenddefaultpostfields stringbuilder htmlencoder htmlencoder plugname javascript javascript getelementbyid javascript generates the interface to the xml librarian and takes apropos action to an event param request public string handlehttp post http request request throws pluginhttp exception string search request get part as string search 80 string indexuri request is part set index request get part as string index 200 default index site boolean showprogress request get part as string showprogress 5 equals true return handle inner request get path search indexuri showprogress xmllibrarian handlehttppost httprequest pluginhttpexception getpartasstring ispartset getpartasstring default_index_site getpartasstring handleinner getpath private string handle inner string path string search string indexuri boolean showprogress string builder out new string builder append default page start out append default post fields out search indexuri try if indexuri equals out append specify a valid index n else if search equals out append give a valid string to search else search setup pr this out append table tr td colspan 2 span class librarian searching for header searching for span n out append span class librarian searching for target b html encoder encode search b span in index i html encoder encode indexuri i td tr n if showprogress out append tr td width 140 nbsp nbsp search status td td div id librarian search status div td tr table n out append p p n n out append script language java script n out append function getresult n out append var xml http new xml http request n out append xml http onreadystatechange function n out append if xml http ready state 4 n out append document get element by id librarian search results innerhtml xml http response text n out append n out append xml http open get plugins plugins xml librarian xml librarian result search search true n out append xml http send null n n out append function request status n out append var xml http new xml http request n out append xml http onreadystatechange function n out append if xml http ready state 4 n out append if xml http response text char at 0 n out append document get element by id librarian search status innerhtml xml http response text substr 1 n out append request status n out append else n out append document get element by id librarian search status innerhtml xml http response text n out append getresult n n out append n n out append xml http open get plugins plugins xml librarian xml librarian progress search search pushonupdate true true n out append xml http send null n n out append request status n out append script n set up progressing progress progress new progress searching for search pr gethl simple client add global hook progress progressmap put search progress search search str async out search indexuri progress else out append table p p n n search search str out search indexuri catch exception e logger error this searching for the word search in index indexuri failed e to string e append default page end out return out to string handleinner stringbuilder stringbuilder appenddefaultpagestart appenddefaultpostfields htmlencoder htmlencoder javascript xmlhttp xmlhttprequest xmlhttp xmlhttp readystate getelementbyid xmlhttp responsetext xmlhttp xmllibrarian xmllibrarian xmlhttp requeststatus xmlhttp xmlhttprequest xmlhttp xmlhttp readystate xmlhttp responsetext charat getelementbyid xmlhttp responsetext requeststatus getelementbyid xmlhttp responsetext xmlhttp xmllibrarian xmllibrarian xmlhttp requeststatus gethlsimpleclient addglobalhook searchstrasync searchstr tostring appenddefaultpageend tostring public void run plugin plugin respirator pr this pr pr runplugin pluginrespirator private static string convert to hex byte data string builder buf new string builder for int i 0 i data length i int halfbyte data i 4 0x0f int two halfs 0 do if 0 halfbyte halfbyte 9 buf append char 0 halfbyte else buf append char a halfbyte 10 halfbyte data i 0x0f while two halfs 1 return buf to string converttohex stringbuilder stringbuilder two_halfs two_halfs tostring this function will return the string representation of the md5 hash for the input string public static string md5 string text try message digest md message digest get instance md5 byte b text get bytes utf 8 md update b 0 b length byte md5hash md digest return convert to hex md5hash catch exception e throw new runtime exception e messagedigest messagedigest getinstance getbytes converttohex runtimeexception public class premultiply filter extends point filter public premultiply filter premultiplyfilter pointfilter premultiplyfilter override public int filterrgb int x int y int rgb int a rgb 24 0xff int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff float f a 1 0f 255 0f r f g f b f return a 24 r 16 g 8 b override public string to string return alpha premultiply tostring private static final long serial versionuid 1 public invalid parameter exception string message super message serialversionuid invalidparameterexception public class unsupported cipher exception extends exception private static final long serial versionuid 1 public unsupported cipher exception unsupportedcipherexception serialversionuid unsupportedcipherexception private static final long serial versionuid 1 public unsupported cipher exception public unsupported cipher exception string s super s serialversionuid unsupportedcipherexception unsupportedcipherexception public list peer message simple field set fs this fs fs this identifier fs get identifier fs remove value identifier listpeermessage simplefieldset removevalue override public simple field set get field set return new simple field set true simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception if handler has full access throw new message invalid exception protocol error message access denied list peer requires full access identifier false string node identifier fs get node identifier if node identifier null throw new message invalid exception protocol error message missing field error node identifier field missing identifier false peer node pn node get peer node node identifier if pn null fcp message msg new unknown node identifier message node identifier identifier handler output handler queue msg return handler output handler queue new peer message pn true true identifier fcpconnectionhandler messageinvalidexception hasfullaccess messageinvalidexception protocolerrormessage access_denied listpeer nodeidentifier nodeidentifier nodeidentifier messageinvalidexception protocolerrormessage missing_field nodeidentifier peernode getpeernode nodeidentifier fcpmessage unknownnodeidentifiermessage nodeidentifier outputhandler outputhandler peermessage override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception public class f proxy fetch waiter public f proxy fetch waiter f proxy fetch in progress progress2 this progress progress2 if progress finished finished true fproxyfetchwaiter fproxyfetchwaiter fproxyfetchinprogress public f proxy fetch result get result boolean waited synchronized this if finished has waited awoken awoken false try wait 5000 catch interrupted exception e not likely has waited true waited has waited return progress inner get result waited fproxyfetchresult getresult haswaited interruptedexception haswaited haswaited innergetresult public void close progress close this synchronized void wake up boolean fin if fin this finished true else this awoken true notify all wakeup notifyall private boolean valid public string anchor return port forward super hash code hashcode public string dismiss button text return l10n get string user alert hide dismissbuttontext getstring useralert public html node gethtml text html node div new html node div string url generic read filter callback escapeurl html encoder encode l10n port forward helpurl boolean maybe forwarded true for int i 0 i ports not forwarded length i if ports not forwarded i 0 maybe forwarded false string key suffix maybe forwarded maybe forwarded not forwarded if ports not forwarded length 1 l10n addl10n substitution div ip detector plugin manager forward port key suffix new string port link link new string integer to string math abs ports not forwarded 0 a href url a else if ports not forwarded length 2 l10n addl10n substitution div ip detector plugin manager forward two ports key suffix new string port1 port2 link link new string integer to string math abs ports not forwarded 0 integer to string math abs ports not forwarded 1 a href url a else logger error this unknown number of ports to forward ports not forwarded length if inner get priority class user alert error div add child l10n symmetricps return div htmlnode gethtmltext htmlnode htmlnode genericreadfiltercallback htmlencoder portforwardhelpurl maybeforwarded portsnotforwarded portsnotforwarded maybeforwarded keysuffix maybeforwarded maybeforwarded notforwarded portsnotforwarded addl10nsubstitution ipdetectorpluginmanager forwardport keysuffix tostring portsnotforwarded portsnotforwarded addl10nsubstitution ipdetectorpluginmanager forwardtwoports keysuffix tostring portsnotforwarded tostring portsnotforwarded portsnotforwarded innergetpriorityclass useralert addchild public short get priority class return inner get priority class getpriorityclass innergetpriorityclass public short inner get priority class if connection type detectedip symmetric nat connection type detectedip symmetric udp firewall only able to connect to directly connected full cone nodes return user alert error if ports not forwarded null for int i 0 i ports not forwarded length i if ports not forwarded i 0 return user alert error return user alert minor innergetpriorityclass connectiontype symmetric_nat connectiontype symmetric_udp_firewall useralert portsnotforwarded portsnotforwarded portsnotforwarded useralert useralert public string get short text string prefix inner get priority class user alert error l10n serious connection problems l10n connection problems prefix boolean maybe forwarded true for int i 0 i ports not forwarded length i if ports not forwarded i 0 maybe forwarded false string key suffix maybe forwarded maybe forwarded not forwarded if ports not forwarded length 1 return prefix l10n forward port short key suffix port integer to string math abs ports not forwarded 0 else if ports not forwarded length 2 return prefix l10n forward two ports short key suffix new string port1 port2 new string integer to string math abs ports not forwarded 0 integer to string math abs ports not forwarded 1 else logger error this unknown number of ports to forward ports not forwarded length return getshorttext innergetpriorityclass useralert seriousconnectionproblems connectionproblems maybeforwarded portsnotforwarded portsnotforwarded maybeforwarded keysuffix maybeforwarded maybeforwarded notforwarded portsnotforwarded forwardportshort keysuffix tostring portsnotforwarded portsnotforwarded forwardtwoportsshort keysuffix tostring portsnotforwarded tostring portsnotforwarded portsnotforwarded public string get text string url l10n port forward helpurl boolean maybe forwarded true for int i 0 i ports not forwarded length i if ports not forwarded i 0 maybe forwarded false string key suffix maybe forwarded maybe forwarded not forwarded if ports not forwarded length 1 return l10n forward port key suffix new string port link link new string integer to string math abs ports not forwarded 0 url else if ports not forwarded length 2 return l10n forward two ports key suffix new string port1 port2 link link new string integer to string math abs ports not forwarded 0 integer to string math abs ports not forwarded 1 url else logger error this unknown number of ports to forward ports not forwarded length return gettext portforwardhelpurl maybeforwarded portsnotforwarded portsnotforwarded maybeforwarded keysuffix maybeforwarded maybeforwarded notforwarded portsnotforwarded forwardport keysuffix tostring portsnotforwarded portsnotforwarded forwardtwoports keysuffix tostring portsnotforwarded tostring portsnotforwarded portsnotforwarded public string get title return get short text gettitle getshorttext public object get user identifier return ip detector plugin manager this getuseridentifier ipdetectorpluginmanager public boolean is valid ports not forwarded getudp ports not forwarded if ports not forwarded length max ports length valid true max ports length ports not forwarded length short prio inner get priority class if prio max priority shown valid true max priority shown prio if ports not forwarded length 0 return false return valid isvalid portsnotforwarded getudpportsnotforwarded portsnotforwarded maxportslength maxportslength portsnotforwarded innergetpriorityclass maxpriorityshown maxpriorityshown portsnotforwarded public void is valid boolean validity valid validity isvalid public void on dismiss valid false ondismiss public boolean should unregister on dismiss return false shouldunregisterondismiss public boolean user can dismiss return true usercandismiss public boolean is event notification return false iseventnotification public my user alert string title string text boolean suggest port forward short code super false title text title null code true l10n get string user alert hide false null this suggest port forward suggest port forward ports not forwarded new int myuseralert suggestportforward getstring useralert suggestportforward suggestportforward portsnotforwarded override public html node gethtml text html node div new html node div div add child super get text if suggest port forward if ports not forwarded length 1 l10n addl10n substitution div ip detector plugin manager suggest forward port with link new string link link port new string a href checked http http wiki freenetproject org firewall and router issues a integer to string ports not forwarded 0 else l10n addl10n substitution div ip detector plugin manager suggest forward two ports with link new string link link port1 port2 new string a href checked http http wiki freenetproject org firewall and router issues a integer to string ports not forwarded 0 integer to string ports not forwarded 1 return div htmlnode gethtmltext htmlnode htmlnode addchild gettext suggestportforward portsnotforwarded addl10nsubstitution ipdetectorpluginmanager suggestforwardportwithlink _checked_http_ firewallandrouterissues tostring portsnotforwarded addl10nsubstitution ipdetectorpluginmanager suggestforwardtwoportswithlink _checked_http_ firewallandrouterissues tostring portsnotforwarded tostring portsnotforwarded override public string get text if suggest port forward return super get text string builder sb new string builder sb append super get text if ports not forwarded length 1 sb append l10n suggest forward port port integer to string math abs ports not forwarded 0 else if ports not forwarded length 2 sb append l10n suggest forward two ports new string port1 port2 new string integer to string math abs ports not forwarded 0 integer to string math abs ports not forwarded 1 if ports not forwarded length 2 logger error this not able to tell user about more than 2 ports to forward ports not forwarded length return sb to string gettext suggestportforward gettext stringbuilder stringbuilder gettext portsnotforwarded suggestforwardport tostring portsnotforwarded portsnotforwarded suggestforwardtwoports tostring portsnotforwarded tostring portsnotforwarded portsnotforwarded portsnotforwarded tostring override public void is valid boolean validity valid validity isvalid override public boolean is valid ports not forwarded getudp ports not forwarded return valid ports not forwarded length 0 isvalid portsnotforwarded getudpportsnotforwarded portsnotforwarded override public void on dismiss valid false ondismiss override public boolean user can dismiss return false usercandismiss ip detector plugin manager node node nodeip detector detector logminor logger should log logger minor get class logdebug logger should log logger debug get class plugins new fred pluginip detector 0 port forward plugins new fred plugin port forward 0 this node node this detector detector no connection alert new my user alert l10n no connectivity title l10n no connectivity true user alert error symmetric alert new my user alert l10n symmetric title l10n symmetric true user alert error port restricted alert new my user alert l10n port restricted title l10n port restricted true user alert warning restricted alert new my user alert l10n restricted title l10n restricted false user alert minor port forward alert new port forward alert ipdetectorpluginmanager nodeipdetector shouldlog getclass shouldlog getclass fredpluginipdetector portforwardplugins fredpluginportforward noconnectionalert myuseralert noconnectivitytitle noconnectivity useralert symmetricalert myuseralert symmetrictitle useralert portrestrictedalert myuseralert portrestrictedtitle portrestricted useralert restrictedalert myuseralert restrictedtitle useralert portforwardalert portforwardalert return all the ports that we have reason to believe are not forwarded e g for the user alert which only shows if what we return is of nonzero length public int getudp ports not forwarded opennet manager om node get opennet int darknet status node peers any darknet peers node darknet crypto get detected connectivity status address tracker dont know int opennet status om null address tracker dont know om crypto get detected connectivity status if om null opennet status address tracker dont know if darknet status address tracker dont know return new int else return new int darknet status address tracker maybe nated 1 1 node get darknet port number else if darknet status address tracker dont know return new int opennet status address tracker maybe nated 1 1 om crypto port number else return new int darknet status address tracker maybe nated 1 1 node get darknet port number opennet status address tracker maybe nated 1 1 om crypto port number getudpportsnotforwarded opennetmanager getopennet darknetstatus anydarknetpeers darknetcrypto getdetectedconnectivitystatus addresstracker dont_know opennetstatus addresstracker dont_know getdetectedconnectivitystatus opennetstatus addresstracker dont_know darknetstatus addresstracker dont_know darknetstatus addresstracker maybe_nated getdarknetportnumber darknetstatus addresstracker dont_know opennetstatus addresstracker maybe_nated portnumber darknetstatus addresstracker maybe_nated getdarknetportnumber opennetstatus addresstracker maybe_nated portnumber private string l10n string key return l10n get string ip detector plugin manager key getstring ipdetectorpluginmanager public string l10n string key string pattern string value return l10n get string ip detector plugin manager key new string pattern new string value getstring ipdetectorpluginmanager public string l10n string key string patterns string values return l10n get string ip detector plugin manager key patterns values getstring ipdetectorpluginmanager start the detector plugin manager this includes running the plugin if there is one and if it is necessary to do so void start cannot be initialized until user alert manager has been created proxy alert new proxy user alert node client core alerts false node client core alerts register port forward alert started true try maybe run useralertmanager proxyalert proxyuseralert clientcore clientcore portforwardalert trymayberun start the plugin detection if necessary either way schedule another attempt in 1 minute s time private void try maybe run try maybe run catch throwable t logger error this caught t t node get ticker queue timed job new runnable public void run freenet support logger os thread logpid this try maybe run 60 1000 trymayberun mayberun getticker queuetimedjob osthread trymayberun node get ticker queue timed job new runnable public void run freenet support logger os thread logpid this try maybe run getticker queuetimedjob osthread trymayberun register a plugin public void register detector plugin fred pluginip detector d if d null throw new null pointer exception synchronized this last detect attempt ended time 1 fred pluginip detector new plugins new fred pluginip detector plugins length 1 system arraycopy plugins 0 new plugins 0 plugins length new plugins plugins length d plugins new plugins if logminor logger minor this registering a new plugin d maybe run registerdetectorplugin fredpluginipdetector nullpointerexception lastdetectattemptendedtime fredpluginipdetector newplugins fredpluginipdetector newplugins newplugins newplugins mayberun remove a plugin public void unregister detector plugin fred pluginip detector d detector runner running detector synchronized this int count 0 for int i 0 i plugins length i if plugins i d count if count 0 return fred pluginip detector new plugins new fred pluginip detector plugins length count int x 0 for int i 0 i plugins length i if plugins i d new plugins x plugins i plugins new plugins will be removed when returns in the detector runner running detector runners get d if running detector null running detector kill unregisterdetectorplugin fredpluginipdetector detectorrunner runningdetector fredpluginipdetector newplugins fredpluginipdetector newplugins newplugins detectorrunner runningdetector runningdetector runningdetector do we need to run a plugin public void maybe run if started return logminor logger should log logger minor get class logdebug logger should log logger debug get class if logminor logger minor this maybe running ip detection plugins new exception debug peer node peers node get peer nodes peer node conns node get connected peers int peer count node peers count valid peers freenet inet address node addrs detector get primaryip address true long now system current time millis synchronized this if plugins length 0 if logminor logger minor this no ip detection plugins detector has detectedpm return if runners size plugins length if logminor logger minor this already running all ip detection plugins return if detect attempt failed to produce an ip in the last 5 minutes don t try again yet if failed runners size plugins length if now last detect attempt ended time 5 60 1000 if logminor logger minor this last detect failed less than 5 minutes ago return else if logminor logger minor this last detect failed redetecting start detect return if detector has directly detectedip if should detect despite realip now conns node addrs return if peer count 0 if should detect no peers now start detect else if should detect with peers now peers conns node addrs start detect mayberun shouldlog getclass shouldlog getclass peernode getpeernodes peernode getconnectedpeers peercount countvalidpeers freenetinetaddress nodeaddrs getprimaryipaddress currenttimemillis hasdetectedpm failedrunners lastdetectattemptendedtime startdetect hasdirectlydetectedip shoulddetectdespiterealip nodeaddrs peercount shoulddetectnopeers startdetect shoulddetectwithpeers nodeaddrs startdetect given that we have no peers should we run the detection plugins algorithm run the detection once every 6 hours param now the time at the start of the calling method return true if we should run a detection private boolean should detect no peers long now if now last detect attempt ended time 6 60 60 1000 no peers only try every 6 hours if logminor logger minor this no peers but detected less than 6 hours ago return false else must try once return true shoulddetectnopeers lastdetectattemptendedtime given that we have some peers should we run the detection plugins param now the time at the beginning of the calling method param peers the node s peers param conns the node s connected peers return true if we should run a detection private boolean should detect with peers long now peer node peers peer node conns freenet inet address node addrs boolean detect false if we have no connections and several disconnected but enabled peers then run a detection int real connections 0 int real disconnected 0 int recently connected 0 if logminor logger minor this checking whether should detect with peers length peers and conns length conns counting peers for int i 0 i peers length i peer node p peers i if p is disabled continue don t count localhost lan addresses peer peer p get peer if peer null continue freenet inet address a peer get freenet address if a null continue not much chance of connecting inet address addr a get address false if addr null if ip util is valid address addr false continue boolean skip false for int j 0 j node addrs length j if a equals node addrs j skip true break if skip continue if p is connected real connections else real disconnected if now p last received packet time 5 60 1000 recently connected if we have no connections and several disconnected nodes we should do a detection soon if logminor logger minor this real connections real connections disconnected real disconnected if real connections 0 real disconnected 0 if first time urgent 0 first time urgent now if detector oldip address null detector oldip address is real internet address false false false if logdebug logger debug this detecting in 2 minutes as have oldip address allow 2 minutes to get incoming connections and therefore detect from them in the meantime hopefully our oldip address is valid if not we ll find out in 2 minutes if now first time urgent 2 60 1000 detect true first time urgent now reset now rather than on next round if logminor logger minor this detecting now as 2 minutes are up have oldip address else if logminor logger minor this detecting now no oldip address detect immediately detect true else if real connections 0 real disconnected 0 return should detect no peers now else if logdebug logger minor this not urgent conns conns length peers peers length first time urgent 0 if we have no connections and have lost several connections recently we should do a detection soon regardless of the 1 detection per hour throttle if real connections 0 real disconnected 0 recently connected 2 if now last detect attempt ended time 6 60 1000 return true if it appears to be an snat do a detection at least once to verify that and to check whether our ip is bogus if detector maybe symmetric last detect attempt ended time 0 return true if detect if now last detect attempt ended time 60 60 1000 only try every hour if logminor logger minor this only trying once per hour return false return true else return false shoulddetectwithpeers peernode peernode freenetinetaddress nodeaddrs realconnections realdisconnected recentlyconnected peernode isdisabled getpeer freenetinetaddress getfreenetaddress inetaddress getaddress iputil isvalidaddress nodeaddrs nodeaddrs isconnected realconnections realdisconnected lastreceivedpackettime recentlyconnected realconnections realdisconnected realconnections realdisconnected firsttimeurgent firsttimeurgent oldipaddress oldipaddress isrealinternetaddress oldipaddress oldipaddress firsttimeurgent firsttimeurgent oldipaddress oldipaddress realconnections realdisconnected shoulddetectnopeers firsttimeurgent realconnections realdisconnected recentlyconnected lastdetectattemptendedtime maybesymmetric lastdetectattemptendedtime lastdetectattemptendedtime should we run the detection plugins despite having a directly detected ip address param now the time at the beginning of the calling method param peers the node s peers param node addrs our peers addresses return true if we should run a detection private boolean should detect despite realip long now peer node peers freenet inet address node addrs we might still be firewalled first check only once per day or startup if now last detect attempt ended time 12 60 60 1000 if logminor logger minor this node has directly detected ip and we have checked less than 12 hours ago return false if logminor logger minor this checking whether should detect despite real ip now if we have two nodes with unique i ps which aren t ours connected we don t need to detect hash set inet address addresses connected null boolean has old peers false for peer node p peers if p is connected now p last received packet time 24 60 60 1000 has been connected in the last 24 hours unique ip address peer peer p get peer if peer null inet address addr peer get address false if p is connected addr null ip util is valid address peer get address false connected node on a real internet ip address is it internal boolean internal false for int j 0 j node addrs length j if addr equals node addrs j get address internal internal true break if internal real ip address if addresses connected null addresses connected new hash set inet address addresses connected add addr if addresses connected size 2 3 connected addresses lets assume we have connectivity if logminor logger minor this node has directly detected ip and has connected to 3 real i ps return false long l p get peer added time if l 0 now l 30 60 1000 has old peers true if has old peers no peers older than 30 minutes if logminor logger minor this not detecting as less than 30 minutes old return false return true nodeaddrs shoulddetectdespiterealip peernode freenetinetaddress nodeaddrs lastdetectattemptendedtime ips hashset inetaddress addressesconnected hasoldpeers peernode isconnected lastreceivedpackettime getpeer inetaddress getaddress isconnected iputil isvalidaddress getaddress nodeaddrs nodeaddrs getaddress addressesconnected addressesconnected hashset inetaddress addressesconnected addressesconnected ips getpeeraddedtime hasoldpeers hasoldpeers private void start detect if logminor logger minor this detecting synchronized this failed runners clear for int i 0 i plugins length i fred pluginip detector plugin plugins i if runners contains key plugin continue detector runner d new detector runner plugins i runners put plugin d node executor execute d plugin detector runner for plugins i get class startdetect failedrunners fredpluginipdetector containskey detectorrunner detectorrunner getclass final fred pluginip detector plugin public detector runner fred pluginip detector detector plugin detector fredpluginipdetector detectorrunner fredpluginipdetector public void kill node plugin manager kill plugin fred plugin plugin 0 pluginmanager killplugin fredplugin public void run freenet support logger os thread logpid this try real run catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t osthread realrun outofmemoryerror oomhandler public void real run if logminor logger minor this running plugin detection try vector detectedip v new vector detectedip detectedip detected null try detected plugin get address catch throwable t logger error this caught t t if detected null for int j 0 j detected length j v add detected j synchronized ip detector plugin manager this last detect attempt ended time system current time millis boolean failed false if v is empty if logminor logger minor this no i ps found failed true else failed true for detectedip ip v if logminor logger minor this detected ip ip for plugin if ip public address null ip util is valid address ip public address false if logminor logger minor this address checked out failed false if failed if logminor logger minor this failed failed runners add plugin return node does not know about individual interfaces so just process the lot fixme if we use the interfaces we should simply take the most popular conclusion for each one now tell the node hash map map new linked hash map for int i 0 i v size i detectedip d detectedip v get i inet address addr d public address if map contains key addr map put addr d else detectedip oldd detectedip map get addr if oldd equals d if d nat type detectedip not supported if oldd nat type d nat type higher value more restrictive assume the worst map put addr d detectedip list detectedip map values to array new detectedip map size detectedip list v to array new detectedip v size int count open 0 int count full cone 0 int count restricted 0 int count port restricted 0 int count symmetric 0 int count closed 0 for int i 0 i list length i logger normal this detected ip list i public address type list i nat type system out println detected ip list i public address type list i nat type switch list i nat type case detectedip full cone nat count full cone break case detectedip full internet count open break case detectedip no udp count closed break case detectedip not supported ignore break case detectedip restricted cone nat count restricted break case detectedip port restricted nat count port restricted break case detectedip symmetric nat case detectedip symmetric udp firewall count symmetric break if count closed 0 count open count full cone count restricted count port restricted count symmetric 0 proxy alert set alert no connection alert proxy alert is valid true connection type detectedip no udp else if count symmetric 0 count open count full cone count restricted count port restricted 0 proxy alert set alert symmetric alert proxy alert is valid true connection type detectedip symmetric nat else if count port restricted 0 count open count full cone count restricted 0 proxy alert set alert port restricted alert proxy alert is valid true connection type detectedip port restricted nat else if count restricted 0 count open count full cone 0 proxy alert set alert restricted alert proxy alert is valid true connection type detectedip restricted cone nat else if count full cone 0 count open 0 proxy alert is valid false connection type detectedip full cone nat else if count open 0 proxy alert is valid false detector process detectedi ps list if connection type detectedip no udp simple user alert to register null synchronized this if no connectivity alert null no connectivity alert to register new simple user alert false l10n no connectivity title l10n no connectivity l10n no connectivity short user alert error if to register null node client core alerts register to register else user alert to kill synchronized this to kill no connectivity alert no connectivity alert null if to kill null node client core alerts unregister to kill finally synchronized ip detector plugin manager this runners remove plugin if runners is empty return detector has detectedpm realrun getaddress ipdetectorpluginmanager lastdetectattemptendedtime currenttimemillis isempty ips publicaddress iputil isvalidaddress publicaddress failedrunners hashmap linkedhashmap inetaddress publicaddress containskey nattype not_supported nattype nattype toarray toarray countopen countfullcone countrestricted countportrestricted countsymmetric countclosed publicaddress nattype publicaddress nattype nattype full_cone_nat countfullcone full_internet countopen no_udp countclosed not_supported restricted_cone_nat countrestricted port_restricted_nat countportrestricted symmetric_nat symmetric_udp_firewall countsymmetric countclosed countopen countfullcone countrestricted countportrestricted countsymmetric proxyalert setalert noconnectionalert proxyalert isvalid connectiontype no_udp countsymmetric countopen countfullcone countrestricted countportrestricted proxyalert setalert symmetricalert proxyalert isvalid connectiontype symmetric_nat countportrestricted countopen countfullcone countrestricted proxyalert setalert portrestrictedalert proxyalert isvalid connectiontype port_restricted_nat countrestricted countopen countfullcone proxyalert setalert restrictedalert proxyalert isvalid connectiontype restricted_cone_nat countfullcone countopen proxyalert isvalid connectiontype full_cone_nat countopen proxyalert isvalid processdetectedips connectiontype no_udp simpleuseralert toregister noconnectivityalert noconnectivityalert toregister simpleuseralert noconnectivitytitle noconnectivity noconnectivityshort useralert toregister clientcore toregister useralert tokill tokill noconnectivityalert noconnectivityalert tokill clientcore tokill ipdetectorpluginmanager isempty hasdetectedpm private simple user alert no connectivity alert public boolean is empty return plugins length 0 simpleuseralert noconnectivityalert isempty public void register port forward plugin fred plugin port forward forward if forward null throw new null pointer exception synchronized this fred plugin port forward new forward plugins new fred plugin port forward port forward plugins length 1 system arraycopy port forward plugins 0 new forward plugins 0 port forward plugins length new forward plugins port forward plugins length forward port forward plugins new forward plugins if logminor logger minor this registering a new port forward plugin forward forward on change public ports node get public interface ports this registerportforwardplugin fredpluginportforward nullpointerexception fredpluginportforward newforwardplugins fredpluginportforward portforwardplugins portforwardplugins newforwardplugins portforwardplugins newforwardplugins portforwardplugins portforwardplugins newforwardplugins onchangepublicports getpublicinterfaceports remove a plugin public void unregister port forward plugin fred plugin port forward forward synchronized this int count 0 for int i 0 i port forward plugins length i if port forward plugins i forward count if count 0 return fred plugin port forward new plugins new fred plugin port forward port forward plugins length count int x 0 for int i 0 i port forward plugins length i if port forward plugins i forward new plugins x port forward plugins i port forward plugins new plugins unregisterportforwardplugin fredpluginportforward portforwardplugins portforwardplugins fredpluginportforward newplugins fredpluginportforward portforwardplugins portforwardplugins portforwardplugins newplugins portforwardplugins portforwardplugins newplugins void notify port change final set forward port new ports fred plugin port forward plugins synchronized this plugins port forward plugins for int i 0 i plugins length i final fred plugin port forward plugin plugins i node executor execute new runnable public void run try plugin on change public ports new ports ip detector plugin manager this catch throwable t logger error this changing public ports list on plugin threw t t notify plugins i of ports list change notifyportchange forwardport newports fredpluginportforward portforwardplugins fredpluginportforward onchangepublicports newports ipdetectorpluginmanager public void run try plugin on change public ports new ports ip detector plugin manager this catch throwable t logger error this changing public ports list on plugin threw t t onchangepublicports newports ipdetectorpluginmanager public void port forward status map forward port forward port status statuses set forward port current ports node get public interface ports for forward port p current ports forward port status status statuses get p if status null continue if status status forward port status definite success logger normal this succeeded forwarding p name port p port number for p protocol port forward definitely succeeded status reason string else if status status forward port status probable success logger normal this probably succeeded forwarding p name port p port number for p protocol port forward probably succeeded status reason string else if status status forward port status maybe success logger normal this maybe succeeded forwarding p name port p port number for p protocol port forward may have succeeded but strongly recommend out of band verification status reason string else if status status forward port status definite failure logger error this failed forwarding p name port p port number for p protocol port forward definitely failed status reason string else if status status forward port status probable failure logger error this probably failed forwarding p name port p port number for p protocol port forward probably failed status reason string not much more we can do want to do for now fixme use status external port node executor execute new runnable public void run maybe run redetect ip after port forward changed portforwardstatus forwardport forwardportstatus forwardport currentports getpublicinterfaceports forwardport currentports forwardportstatus forwardportstatus definite_success portnumber reasonstring forwardportstatus probable_success portnumber reasonstring forwardportstatus maybe_success portnumber reasonstring forwardportstatus definite_failure portnumber reasonstring forwardportstatus probable_failure portnumber reasonstring externalport mayberun node executor execute new runnable public void run maybe run mayberun public synchronized boolean has detectors return plugins length 0 hasdetectors public void add connection type box html node content node if node client core null return if node client core alerts null return if proxy alert is valid content node add child node client core alerts render alert proxy alert addconnectiontypebox htmlnode contentnode clientcore clientcore proxyalert isvalid contentnode addchild clientcore renderalert proxyalert 4 5 6 7 8 9 public base64 encoding ignore errors false base64encoding ignoreerrors public void set ignore errors boolean ignore ignore errors ignore setignoreerrors ignoreerrors private byte encode char int bits return byte encoded chars bits 0x3f encodechar encodedchars public byte buffer encode byte buffer input byte buffer result byte buffer allocate 100 int bits 0 int byte count 0 int char count 0 while input has remaining int b input get 0xff bits bits 8 b byte count if byte count 3 result append byte result encode char bits 18 result append byte result encode char bits 12 result append byte result encode char bits 6 result append byte result encode char bits byte count 0 char count 4 if char count 76 result append byte result byte r result append byte result byte n char count 0 if byte count 1 result append byte result encode char bits 2 result append byte result encode char bits 4 result append byte result byte result append byte result byte else if byte count 2 result append byte result encode char bits 10 result append byte result encode char bits 4 result append byte result encode char bits 2 result append byte result byte result append byte result byte r result append byte result byte n result flip return result bytebuffer bytebuffer bytebuffer bytebuffer bytecount charcount hasremaining bytecount bytecount appendbyte encodechar appendbyte encodechar appendbyte encodechar appendbyte encodechar bytecount charcount charcount appendbyte appendbyte charcount bytecount appendbyte encodechar appendbyte encodechar appendbyte appendbyte bytecount appendbyte encodechar appendbyte encodechar appendbyte encodechar appendbyte appendbyte appendbyte public byte buffer decode byte buffer input throws invalid encoded text exception byte buffer result byte buffer allocate 100 int bits 0 int bit count 0 boolean ateof false while input has remaining byte b input get if b a b z bits bits 6 b a bit count 6 else if b a b z bits bits 6 b 26 a bit count 6 else if b 0 b 9 bits bits 6 b 52 0 bit count 6 else if b bits bits 6 62 bit count 6 else if b bits bits 6 63 bit count 6 else if b ateof true while ateof bit count 8 result append byte result byte bits bit count 8 bit count 8 if ignore errors bit count 6 throw new invalid encoded text exception extraneous characters following end of base64 data result flip return result bytebuffer bytebuffer invalidencodedtextexception bytebuffer bytebuffer bitcount hasremaining bitcount bitcount bitcount bitcount bitcount bitcount appendbyte bitcount bitcount ignoreerrors bitcount invalidencodedtextexception public allowed value list allowedvaluelist public allowed value get allowed value int n return allowed value get n allowedvalue getallowedvalue allowedvalue public http header string name string value set name name set value value httpheader setname setvalue public http header string line str set name set value if line str null return int colon idx line str index of if colon idx 0 return string name new string line str get bytes 0 colon idx string value new string line str get bytes colon idx 1 line str length colon idx 1 set name name trim set value value trim httpheader linestr setname setvalue linestr colonidx linestr indexof colonidx linestr getbytes colonidx linestr getbytes colonidx linestr colonidx setname setvalue public void set name string name this name name setname public void set value string value this value value setvalue public string get name return name getname public string get value return value getvalue public boolean has name if name null name length 0 return false return true hasname public final static string get value line number reader reader string name string big name name to upper case try string line str reader read line while line str null 0 line str length http header header new http header line str if header has name false line str reader read line continue string big line header name header get name to upper case thanks for jan newmarch jan newmarch infotech monash edu au 05 26 04 if big line header name equals big name false line str reader read line continue return header get value catch io exception e debug warning e return return getvalue linenumberreader bigname touppercase linestr readline linestr linestr httpheader httpheader linestr hasname linestr readline biglineheadername getname touppercase biglineheadername bigname linestr readline getvalue ioexception public final static string get value string data string name string reader str reader new string reader data line number reader line reader new line number reader str reader return get value line reader name getvalue stringreader strreader stringreader linenumberreader linereader linenumberreader strreader getvalue linereader public final static string get value byte data string name return get value new string data name getvalue getvalue public final static int get integer value string data string name try return integer parse int get value data name catch exception e return 0 getintegervalue parseint getvalue public final static int get integer value byte data string name try return integer parse int get value data name catch exception e return 0 getintegervalue parseint getvalue lru prev lru next prev this final void unlink next prev prev prev next next final void link lru node node next next node prev this next prev node next node default constructor public sorted long set this data new long min size for int i 0 i data length i data i long max value length 0 sortedlongset min_size max_value get the smallest item on this set return the smallest item public synchronized long get first if length 0 return 1 return data 0 getfirst check if this set is empty param num return code true code if the set is empty public synchronized boolean is empty return length 0 isempty check if code num code exist in this set param num return code true code if code num code exist public synchronized boolean contains long num int x binary search num if x 0 return true else return false binarysearch remove an item param item the item to be removed public synchronized void remove long item int x binary search item if x 0 if x length 1 system arraycopy data x 1 data x length x 1 data length long max value if length 4 data length length min size long new data new long math max data length 2 min size system arraycopy data 0 new data 0 length for int i length i new data length i new data i long max value data new data verify binarysearch max_value min_size newdata min_size newdata newdata newdata max_value newdata verify internal state can be removed without ill effect private synchronized void verify long last item 1 for int i 0 i length i long item data i if i 0 if item last item throw new illegal state exception verify failed last item item for int i length i data length i if data i long max value throw new illegal state exception length length data length data length but i long max value lastitem lastitem illegalstateexception lastitem max_value illegalstateexception max_value add the item if it or an item of the same number is not already present return code true code if we added the item public synchronized boolean push long num int x binary search num if x 0 return false insertion point x x 1 push num x return true binarysearch add the item throws link illegal argument exception if the item already exist return code true code if we added the item public synchronized void add long num int x binary search num if x 0 throw new illegal argument exception already exists insertion point x x 1 push num x illegalargumentexception binarysearch illegalargumentexception private synchronized void push long num int x boolean logminor logger should log logger minor this if logminor logger minor this insertion point x length length data length data length move the data if length data length if logminor logger minor this expanding from length to length 2 long new data new long length 2 system arraycopy data 0 new data 0 data length for int i length i new data length i new data i long max value data new data if x length system arraycopy data x data x 1 length x data x num length verify shouldlog newdata newdata newdata newdata max_value newdata remove and return the smallest item return the smallest item public long remove first long val get first remove val return val removefirst getfirst clear this set public synchronized void clear data new long min size for int i 0 i data length i data i long max value length 0 min_size max_value get a sorted array of all items return sorted array of all items public synchronized long to array long output new long length system arraycopy data 0 output 0 length return output toarray private int binary search long key return fields binary search data key 0 length 1 binarysearch binarysearch final hash map object t map public updatable sorted linked list with foreign index super map new hash map object t hashmap updatablesortedlinkedlistwithforeignindex hashmap override public synchronized void add t item throws updatable sorted linked list killed exception if killed throw new updatable sorted linked list killed exception t i item if map get i index value null ignore duplicate logger error this ignoring duplicate i was already present map get i index value return super add i map put i index value item check list updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception indexvalue indexvalue indexvalue checklist override public synchronized t remove t item throws updatable sorted linked list killed exception if killed throw new updatable sorted linked list killed exception map remove item index value return super remove item updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception indexvalue public synchronized t get object key return map get key public synchronized boolean contains key object key return map contains key key containskey containskey public synchronized boolean contains indexable updatable sorted linked list item item return contains key item index value indexableupdatablesortedlinkedlistitem containskey indexvalue remove an element from the list by its key throws updatable sorted linked list killed exception public synchronized t remove by key object key throws updatable sorted linked list killed exception if killed throw new updatable sorted linked list killed exception t item map get key if item null remove item check list return item updatablesortedlinkedlistkilledexception removebykey updatablesortedlinkedlistkilledexception updatablesortedlinkedlistkilledexception checklist override public synchronized void clear map clear super clear private final int number public sectored random grab array with int int number boolean persistent object container container remove random parent parent super persistent container parent this number number sectoredrandomgrabarraywithint objectcontainer removerandomparent public int get number return number getnumber override public string to string return super to string number tostring tostring static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog if this returns true we will generate the identity from the pubkey only set this if you don t want to send an identity e g for anonymous initiator crypto where we need a small noderef and we don t use the identity anyway because we don t auto reconnect protected abstract boolean generate identity from pubkey protected boolean ignore last good version return false generateidentityfrompubkey ignorelastgoodversion create a peer node from a simple field set containing a node reference for one this must contain the following fields identity version location physical udp setup key do not add self to peer manager param fs the simple field set to parse param node2 the running node we are part of public peer node simple field set fs node node2 node crypto crypto peer manager peers boolean from local boolean from anonymous initiator outgoing packet mangler mangler boolean is opennet throws fs parse exception peer parse exception reference signature verification exception boolean no sig false if from local from anonymous initiator no sig true my ref new weak reference peer node this this outgoing mangler mangler this node node2 this crypto crypto this peers peers this backed off percent new time decaying running average 0 0 180000 0 0 1 0 node version fs get version version seen version version try simple version version get arbitrary build number version catch version parse exception e2 throw new fs parse exception invalid version version e2 string location string fs get location string peer locations string fs get all peers location current location location get location location string if peer locations string null double peer locations new double peer locations string length for int i 0 i peer locations string length i peer locations i location get location peer locations string i current peers location peer locations loc set time system current time millis disable routing disable routing has been set locally false disable routing has been set remotely false assume so last good version fs get last good version update version routablity testnet enabled fs get boolean testnet false if node testnet enabled testnet enabled string err ignoring incompatible node detected peer peer testnet testnet enabled fs get testnet but node testnet node testnet enabled logger error this err throw new peer parse exception err neg types fs get int array auth neg types if neg types null neg types length 0 if from anonymous initiator neg types mangler supported neg types assume compatible anonymous initiator short lived and we already connected so we know we are else throw new fs parse exception no neg types if fs get boolean opennet false is opennet throw new fs parse exception trying to parse a darknet peer as opennet or an opennet peer as darknet read the dsa key material for the peer try simple field set sfs fs subset dsa group if sfs null throw new fs parse exception no dsa group very old reference else this peer crypto group dsa group create sfs sfs fs subset dsa pub key if sfs null peer crypto group null throw new fs parse exception no dsa pub key very old reference else this peer pub key dsa public key create sfs peer crypto group string signature fs get sig fs remove value sig if no sig try boolean failed false if signature null peer crypto group null peer pub key null failed dsa verify peer pub key new dsa signature signature new big integer 1 sha256 digest fs to ordered string get bytes utf 8 false string err cause if signature null err cause no signature if peer crypto group null err cause no peer crypto group if peer pub key null err cause no peer public key if failed err cause verification failed logger error this the integrity of the reference has been compromized err cause fs was n fs to ordered string this is signature verification successfull false fs put single sig signature throw new reference signature verification exception the integrity of the reference has been compromized err cause else this is signature verification successfull true catch number format exception e logger error this invalid reference e e throw new reference signature verification exception the node reference you added is invalid it does not have a valid signature catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e else local is always good assumed this is signature verification successfull true catch illegal base64 exception e logger error this caught e e throw new fs parse exception e identifier if generate identity from pubkey string identity string fs get identity if identity string null throw new peer parse exception no identity try identity base64 decode identity string catch number format exception e throw new fs parse exception e catch illegal base64 exception e throw new fs parse exception e else identity peer pub key as bytes hash if identity null throw new fs parse exception no identity identity as base64 string base64 encode identity identity hash sha256 digest identity identity hash hash sha256 digest identity hash swap identifier fields bytes to long identity hash hash hash code fields hash code identity hash setup incoming and outgoing setup ciphers byte node key crypto identity hash byte node key hash crypto identity hash hash int digest length sha256 get digest length incoming setup key new byte digest length for int i 0 i incoming setup key length i incoming setup key i byte node key i identity hash hash i outgoing setup key new byte digest length for int i 0 i outgoing setup key length i outgoing setup key i byte node key hash i identity hash i if logminor logger minor this keys n identity hex util bytes to hex crypto my identity n this ident hex util bytes to hex identity n node hex util bytes to hex node key n node hash hex util bytes to hex node key hash n this hex util bytes to hex identity hash n this hash hex util bytes to hex identity hash hash n for get peer try incoming setup cipher new rijndael 256 256 incoming setup cipher initialize incoming setup key outgoing setup cipher new rijndael 256 256 outgoing setup cipher initialize outgoing setup key anonymous initiator setup cipher new rijndael 256 256 anonymous initiator setup cipher initialize identity hash catch unsupported cipher exception e1 logger error this caught e1 throw new error e1 nominal peer new vector peer try string physical fs get all physical udp if physical null leave it empty else for int i 0 i physical length i peer p try p new peer physical i true true catch hostname syntax exception e if from local logger error this invalid hostname or ip address syntax error while parsing peer reference in local peers list physical i system err println invalid hostname or ip address syntax error while parsing peer reference physical i continue if nominal peer contains p nominal peer add element p catch exception e1 throw new fs parse exception e1 if nominal peer is empty logger normal this no ip addresses found for identity identity as base64 string possibly at location double to string current location user to string detected peer null else detected peer nominal peer first element update short to string don t create trackers until we have a key current tracker null previous tracker null time last sent packet 1 time last received packet 1 time last received swap request 1 time last connected 1 time last routable 1 time added or restarted system current time millis swap requests interval new simple running average 50 node min interval between incoming swap requests probe requests interval new simple running average 50 node min interval between incoming probe requests not connected yet need to handshake is connected false message queue new peer message queue decrementhtl at maximum node random next float node decrement at max prob decrementhtl at minimum node random next float node decrement at min prob ping number node random next long a simple running average would be a bad choice because it would cause oscillations so go for a filter ping average short average otherwise we will reject for a really long time after any spike new time decaying running average 1 30 1000 0 node pinger crazy max ping time node tdra for probability of rejection p rejected new time decaying running average 0 240 1000 0 0 1 0 node ark stuff parseark fs true false now for the metadata the metadata sub fieldset contains data about the node which is not part of the node reference it belongs to this node not to the node being described therefore if we are parsing a remotely supplied ref ignore it long now system current time millis if from local simple field set metadata fs subset metadata if metadata null don t be tolerant of nonexistant domains this should be an ip address peer p try string detectedudp string metadata get detected udp p null if detectedudp string null p new peer detectedudp string false catch unknown host exception e peernode simplefieldset setupkey peermanager simplefieldset peernode simplefieldset nodecrypto peermanager fromlocal fromanonymousinitiator outgoingpacketmangler isopennet fsparseexception peerparseexception referencesignatureverificationexception nosig fromlocal fromanonymousinitiator nosig myref weakreference peernode outgoingmangler backedoffpercent timedecayingrunningaverage seenversion simpleversion getarbitrarybuildnumber versionparseexception fsparseexception locationstring peerlocationsstring getall peerslocation currentlocation getlocation locationstring peerlocationsstring peerlocations peerlocationsstring peerlocationsstring peerlocations getlocation peerlocationsstring currentpeerslocation peerlocations locsettime currenttimemillis disablerouting disableroutinghasbeensetlocally disableroutinghasbeensetremotely lastgoodversion lastgoodversion updateversionroutablity testnetenabled getboolean testnetenabled testnetenabled detectedpeer testnetenabled testnetenabled peerparseexception negtypes getintarray negtypes negtypes negtypes fromanonymousinitiator negtypes supportednegtypes fsparseexception negtypes getboolean isopennet fsparseexception simplefieldset dsagroup fsparseexception dsagroup peercryptogroup dsagroup dsapubkey peercryptogroup fsparseexception dsapubkey peerpubkey dsapublickey peercryptogroup removevalue nosig peercryptogroup peerpubkey peerpubkey dsasignature biginteger toorderedstring getbytes errcause errcause peercryptogroup errcause peerpubkey errcause errcause errcause toorderedstring issignatureverificationsuccessfull putsingle referencesignatureverificationexception errcause issignatureverificationsuccessfull numberformatexception referencesignatureverificationexception unsupportedencodingexception issignatureverificationsuccessfull illegalbase64exception fsparseexception generateidentityfrompubkey identitystring identitystring peerparseexception identitystring numberformatexception fsparseexception illegalbase64exception fsparseexception peerpubkey asbyteshash fsparseexception identityasbase64string identityhash identityhashhash identityhash swapidentifier bytestolong identityhashhash hashcode hashcode identityhash nodekey identityhash nodekeyhash identityhashhash digestlength getdigestlength incomingsetupkey digestlength incomingsetupkey incomingsetupkey nodekey identityhashhash outgoingsetupkey digestlength outgoingsetupkey outgoingsetupkey nodekeyhash identityhash nidentity hexutil bytestohex myidentity nthisident hexutil bytestohex nnode hexutil bytestohex nodekey nnode hexutil bytestohex nodekeyhash nthis hexutil bytestohex identityhash nthis hexutil bytestohex identityhashhash nfor getpeer incomingsetupcipher incomingsetupcipher incomingsetupkey outgoingsetupcipher outgoingsetupcipher outgoingsetupkey anonymousinitiatorsetupcipher anonymousinitiatorsetupcipher identityhash unsupportedcipherexception nominalpeer getall hostnamesyntaxexception fromlocal nominalpeer nominalpeer addelement fsparseexception nominalpeer isempty identityasbase64string tostring currentlocation usertostring detectedpeer detectedpeer nominalpeer firstelement updateshorttostring currenttracker previoustracker timelastsentpacket timelastreceivedpacket timelastreceivedswaprequest timelastconnected timelastroutable timeaddedorrestarted currenttimemillis swaprequestsinterval simplerunningaverage min_interval_between_incoming_swap_requests proberequestsinterval simplerunningaverage min_interval_between_incoming_probe_requests isconnected messagequeue peermessagequeue decrementhtlatmaximum nextfloat decrement_at_max_prob decrementhtlatminimum nextfloat decrement_at_min_prob pingnumber nextlong simplerunningaverage pingaverage timedecayingrunningaverage nodepinger crazy_max_ping_time prejected timedecayingrunningaverage currenttimemillis fromlocal simplefieldset detectedudpstring detectedudpstring detectedudpstring unknownhostexception private boolean parseark simple field set fs boolean on startup boolean for diff node ref usk ark null long ark no 0 try string ark pub key fs get ark puburi fixme remove this after 1189 temp hack to fix bad puburi see bug 2761 if on startup ark pub key null while ark pub key matches d ark pub key ark pub key replace all d ark no fs get long ark number 1 if ark pub key null ark no 1 ark puburi and ark number are always optional as a pair return false else if ark pub key null ark no 1 if on startup ark no this is the number of the ref we are parsing we want the number of the next edition on startup we want to fetch the old edition in case there s been a corruption freeneturi uri new freeneturi ark pub key clientssk ssk new clientssk uri ark new usk ssk ark no else if for diff node ref ark pub key null myark null ark no 1 get the ark uri from the previous ark and the edition from the sfs ark myark copy ark no else if for diff node ref ark pub key null myark null ark no 1 the sfs must contain an edition if it contains a ark pub key logger error this got a differential node reference from this with an ark pub key but no ark edition return false else return false catch malformedurl exception e logger error this couldn t parse ark info for this e e catch number format exception e logger error this couldn t parse ark info for this e e synchronized this if ark null if myark null myark ark myark equals ark myark ark return true return false simplefieldset onstartup fordiffnoderef arkno arkpubkey onstartup arkpubkey arkpubkey arkpubkey arkpubkey replaceall arkno getlong arkpubkey arkno arkpubkey arkno onstartup arkno arkpubkey arkno fordiffnoderef arkpubkey arkno arkno fordiffnoderef arkpubkey arkno arkpubkey arkpubkey malformedurlexception numberformatexception get my low level address this is the address that packets have been received from from this node normally this is the address that packets have been received from from this node however if ignore source port is set we will search for a similar address with a different port number in the node reference public synchronized peer get peer return detected peer ignoresourceport getpeer detectedpeer returns an array with the advertised addresses and the detected one protected synchronized peer get handshakei ps return handshakei ps gethandshakeips handshakeips private string handshakei ps to string peer local handshakei ps synchronized this local handshakei ps handshakei ps if local handshakei ps null return null string builder to output string new string builder 1024 boolean need sep false to output string append for int i 0 i local handshakei ps length i if need sep to output string append if local handshakei ps i null to output string append null need sep true continue to output string append actually do the dns request for the member peer of local handshakei ps to output string append local handshakei ps i get address false to output string append need sep true to output string append return to output string to string handshakeipstostring localhandshakeips localhandshakeips handshakeips localhandshakeips stringbuilder tooutputstring stringbuilder needsep tooutputstring localhandshakeips needsep tooutputstring localhandshakeips tooutputstring needsep tooutputstring localhandshakeips tooutputstring localhandshakeips getaddress tooutputstring needsep tooutputstring tooutputstring tostring do the maybe update handshakei ps dns requests but only if ignore hostnames is false this method should only be called by maybe update handshakei ps also removes dupes post lookup private peer update handshakei ps peer local handshakei ps boolean ignore hostnames for int i 0 i local handshakei ps length i if ignore hostnames don t do a dns request on the first cycle through peer nodes by dns request upon startup i suspect the following won t do anything but just in case if logminor logger debug this update handshakei ps calling get address false on peer local handshakei ps i for short to string ignore hostnames local handshakei ps i get address false else actually do the dns request for the member peer of local handshakei ps if logminor logger debug this update handshakei ps calling get handshake address on peer local handshakei ps i for short to string ignore hostnames local handshakei ps i get handshake address de dupe hash set peer ret new hash set peer for int i 0 i local handshakei ps length i ret add local handshakei ps i return ret to array new peer ret size maybeupdatehandshakeips ignorehostnames maybeupdatehandshakeips updatehandshakeips localhandshakeips ignorehostnames localhandshakeips ignorehostnames peernodes dnsrequest updatehandshakeips getaddress localhandshakeips shorttostring ignorehostnames localhandshakeips getaddress localhandshakeips updatehandshakeips gethandshakeaddress localhandshakeips shorttostring ignorehostnames localhandshakeips gethandshakeaddress hashset hashset localhandshakeips localhandshakeips toarray do occasional dns requests but ignore hostnames should be true on peer node construction public void maybe update handshakei ps boolean ignore hostnames long now system current time millis peer local detected peer null synchronized this local detected peer detected peer if now last attempted handshakeip update time 5 60 1000 5 minutes logger minor this looked up recently local detected peer local detected peer local detected peer null local detected peer get address false to string return we want to come back right away for dns requesting if this is our first time through if ignore hostnames last attempted handshakeip update time now if logminor logger minor this updating handshake i ps for peer short to string ignore hostnames peer my nominal peer don t synchronize while doing lookups which may take a long time synchronized this my nominal peer nominal peer to array new peer nominal peer size peer local handshakei ps if my nominal peer length 0 if local detected peer null synchronized this handshakei ps null if logminor logger minor this 1 maybe update handshakei ps got a result of handshakei ps to string return local handshakei ps new peer local detected peer local handshakei ps update handshakei ps local handshakei ps ignore hostnames synchronized this handshakei ps local handshakei ps if logminor logger minor this 2 maybe update handshakei ps got a result of handshakei ps to string return hack for two nodes on the same ip that can t talk over inet for routing reasons freenet inet address localhost node f localhost address peer node peers outgoing mangler get primaryip address vector peer local peers null synchronized this local peers new vector peer nominal peer boolean added localhost false peer detected duplicate null for int i 0 i my nominal peer length i peer p my nominal peer i if p null continue if local detected peer null if p local detected peer p equals local detected peer equal but not the same object need to update the copy detected duplicate p freenet inet address addr p get freenet address if addr equals localhost if added localhost continue added localhost true for int j 0 j node peers length j redflag two lines so we can see which variable is null when it np es freenet inet address my addr node peers j get freenet address if my addr equals addr if added localhost local peers add new peer localhost p get port added localhost true if local peers contains p continue local peers add p local handshakei ps local peers to array new peer local peers size local handshakei ps update handshakei ps local handshakei ps ignore hostnames synchronized this handshakei ps local handshakei ps if detected duplicate null detected duplicate equals local detected peer local detected peer detected peer detected duplicate update short to string if logminor if local detected peer null logger minor this 3 detected peer local detected peer local detected peer get address false logger minor this 3 maybe update handshakei ps got a result of handshakei ps to string ignorehostnames peernode maybeupdatehandshakeips ignorehostnames currenttimemillis localdetectedpeer localdetectedpeer detectedpeer lastattemptedhandshakeipupdatetime localdetectedpeer localdetectedpeer localdetectedpeer localdetectedpeer getaddress tostring ignorehostnames lastattemptedhandshakeipupdatetime ips shorttostring ignorehostnames mynominalpeer mynominalpeer nominalpeer toarray nominalpeer localhandshakeips mynominalpeer localdetectedpeer handshakeips maybeupdatehandshakeips handshakeipstostring localhandshakeips localdetectedpeer localhandshakeips updatehandshakeips localhandshakeips ignorehostnames handshakeips localhandshakeips maybeupdatehandshakeips handshakeipstostring freenetinetaddress flocalhostaddress nodepeers outgoingmangler getprimaryipaddress localpeers localpeers nominalpeer addedlocalhost detectedduplicate mynominalpeer mynominalpeer localdetectedpeer localdetectedpeer localdetectedpeer detectedduplicate freenetinetaddress getfreenetaddress addedlocalhost addedlocalhost nodepeers npes freenetinetaddress myaddr nodepeers getfreenetaddress myaddr addedlocalhost localpeers getport addedlocalhost localpeers localpeers localhandshakeips localpeers toarray localpeers localhandshakeips updatehandshakeips localhandshakeips ignorehostnames handshakeips localhandshakeips detectedduplicate detectedduplicate localdetectedpeer localdetectedpeer detectedpeer detectedduplicate updateshorttostring localdetectedpeer detectedpeer localdetectedpeer localdetectedpeer getaddress maybeupdatehandshakeips handshakeipstostring returns this peer s current keyspace location or 1 if it is unknown public synchronized double get location return current location getlocation currentlocation public boolean should be excluded from peer list long now system current time millis synchronized this if black magic backoff pruning percentage backed off percent current value return true else if black magic backoff pruning time now get routing backed off until return true else return false shouldbeexcludedfrompeerlist currenttimemillis black_magic_backoff_pruning_percentage backedoffpercent currentvalue black_magic_backoff_pruning_time getroutingbackedoffuntil public synchronized double get peers location return current peers location getpeerslocation currentpeerslocation public synchronized long get loc set time return loc set time getlocsettime locsettime returns a unique node identifier usefull to compare two peernodes public int get identity hash return hash code getidentityhash hashcode returns true if the last known build number for this peer is to old to allow traffic to be routed to it this does not give any indication as to the connection status of the peer public synchronized boolean is unroutable older version return unroutable older version isunroutableolderversion unroutableolderversion returns true if this or another peer has reported to us that our build number is too old for data to be routed to us in turn we will not route data to them either does not strictly indicate that the peer is connected public synchronized boolean is unroutable newer version return unroutable newer version isunroutablenewerversion unroutablenewerversion returns true if requests can be routed through this peer true if the peer s location is known presently connected and routing compatible that is ignoring backoff the peer s location is known build number is compatible and routing has not been explicitly disabled note possible deadlocks peer manager calls this we call peer manager in e g verified public boolean is routable return is connected is routing compatible current location 0 0 current location 1 0 peermanager peermanager isroutable isconnected isroutingcompatible currentlocation currentlocation returns true if apart from actually knowing the peer s location it is presumed that this peer could route requests true if this peer s build number is not too old or too new actively connected and not marked as explicity disabled does not reflect any backoff logic public boolean is routing compatible long now system current time millis synchronized this if is routable disable routing time last routable now return true return false isroutingcompatible currenttimemillis isroutable disablerouting timelastroutable public boolean is connected long now system current time millis synchronized this if is connected current tracker null current tracker packets is deprecated time last connected now return true return false isconnected currenttimemillis isconnected currenttracker currenttracker isdeprecated timelastconnected send a message off thread to this node param msg the message to be sent param cb the callback to be called when the packet has been sent or null param already reported bytes the number of bytes already reported to the throttle relating to this packet normally set when we have delayed a packet in order to throttle it public void send async message msg async message callback cb byte counter ctr throws not connected exception if ctr null logger error this bytes not logged new exception debug if logminor logger minor this sending async msg cb on this for node get darknet port number if is connected throw new not connected exception add to local node sent messages to statistic msg message item item new message item msg cb null null new async message callback cb ctr this long now system current time millis report backoff status now int x message queue queue and estimate size item if x 1024 node enable packet coalescing if there is a packet s worth to send wake up the packetsender node ps wake up otherwise we do not need to wake up the packet sender it will wake up before the maximum coalescing delay 100ms because it wakes up every 100ms anyway alreadyreportedbytes sendasync asyncmessagecallback bytecounter notconnectedexception getdarknetportnumber isconnected notconnectedexception addtolocalnodesentmessagestostatistic messageitem messageitem asyncmessagecallback currenttimemillis reportbackoffstatus messagequeue queueandestimatesize enablepacketcoalescing wakeup packetsender public long get message queue length bytes return message queue get message queue length bytes getmessagequeuelengthbytes messagequeue getmessagequeuelengthbytes returns the number of milliseconds that it is estimated to take to transmit the currently queued packets public long get probable send queue time return long get message queue length bytes get throttle get bandwidth 1 0 getprobablesendqueuetime getmessagequeuelengthbytes getthrottle getbandwidth return the last time we received a packet public synchronized long last received packet time return time last received packet lastreceivedpackettime timelastreceivedpacket public synchronized long last received data packet time return time last received data packet lastreceiveddatapackettime timelastreceiveddatapacket public synchronized long time last connected return time last connected timelastconnected timelastconnected public synchronized long time last routable return time last routable timelastroutable timelastroutable protected void maybe rekey long now system current time millis boolean should disconnect false boolean should return false boolean should rekey false long time when rekeying should occur 0 synchronized this time when rekeying should occur time last rekeyed fnp packet mangler session key rekeying interval should disconnect time when rekeying should occur fnp packet mangler max session key rekeying delay now is rekeying should return is rekeying is connected should rekey time when rekeying should occur now if should rekey total bytes exchanged with current tracker fnp packet mangler amount of bytes allowed before we rekey should rekey true time when rekeying should occur now if should disconnect string time time util format time fnp packet mangler max session key rekeying delay system err println the peer this has been asked to rekey time ago force disconnect logger error this the peer this has been asked to rekey time ago force disconnect force disconnect false else if should return has live handshake now return else if should rekey synchronized this is rekeying true send handshake time now immediately ctx null logger normal this we are asking for the key to be renewed this detected peer mayberekey currenttimemillis shoulddisconnect shouldreturn shouldrekey timewhenrekeyingshouldoccur timewhenrekeyingshouldoccur timelastrekeyed fnppacketmangler session_key_rekeying_interval shoulddisconnect timewhenrekeyingshouldoccur fnppacketmangler max_session_key_rekeying_delay isrekeying shouldreturn isrekeying isconnected shouldrekey timewhenrekeyingshouldoccur shouldrekey totalbytesexchangedwithcurrenttracker fnppacketmangler amount_of_bytes_allowed_before_we_rekey shouldrekey timewhenrekeyingshouldoccur shoulddisconnect timeutil formattime fnppacketmangler max_session_key_rekeying_delay forcedisconnect shouldreturn haslivehandshake shouldrekey isrekeying sendhandshaketime detectedpeer return the time this peer node was added to the node persistent across restarts public synchronized long get peer added time return peer added time peernode getpeeraddedtime peeraddedtime return the time elapsed since this peer node was added to the node or the node started up public synchronized long time since added or restarted return system current time millis time added or restarted peernode timesinceaddedorrestarted currenttimemillis timeaddedorrestarted disconnected e g due to not receiving a packet for ages param dump message queue if true clear the messages to send queue param dump trackers if true dump the session key s return true if the node was connected false if it was not public boolean disconnected boolean dump message queue boolean dump trackers final long now system current time millis logger normal this disconnected this new exception debug node usm on disconnect this node failure table on disconnect this node peers disconnected this boolean ret session key cur prev unv message item messages tell disconnected null synchronized this ret is connected force renegotiation is connected false is routable false is rekeying false prevent sending packets to the node until that happens cur current tracker prev previous tracker unv unverified tracker if dump trackers current tracker null previous tracker null unverified tracker null else do not clear trackers because hopefully it s a temporary connectivity glitch send handshake time now synchronized this time prev disconnect time last disconnect time last disconnect now if dump message queue messages tell disconnected grab queued message items if messages tell disconnected null if logminor logger minor this messages to dump messages tell disconnected length for message item mi messages tell disconnected mi on disconnect if cur null cur packets disconnected if prev null prev packets disconnected if unv null unv packets disconnected if lastthrottle null lastthrottle maybe disconnected node lm lost or restarted node this set peer node status now if dump message queue node get ticker queue timed job new runnable public void run if peer node this is connected time last disconnect now message item messages tell disconnected grab queued message items if messages tell disconnected null for message item mi messages tell disconnected mi on disconnect clear message queue after return ret dumpmessagequeue dumptrackers sessionkey dumpmessagequeue dumptrackers currenttimemillis ondisconnect failuretable ondisconnect sessionkey messageitem messagestelldisconnected isconnected isconnected isroutable isrekeying currenttracker previoustracker unverifiedtracker dumptrackers currenttracker previoustracker unverifiedtracker sendhandshaketime timeprevdisconnect timelastdisconnect timelastdisconnect dumpmessagequeue messagestelldisconnected grabqueuedmessageitems messagestelldisconnected messagestelldisconnected messageitem messagestelldisconnected ondisconnect _lastthrottle _lastthrottle maybedisconnected lostorrestartednode setpeernodestatus dumpmessagequeue getticker queuetimedjob peernode isconnected timelastdisconnect messageitem messagestelldisconnected grabqueuedmessageitems messagestelldisconnected messageitem messagestelldisconnected ondisconnect clear_message_queue_after node get ticker queue timed job new runnable public void run if peer node this is connected time last disconnect now message item messages tell disconnected grab queued message items if messages tell disconnected null for message item mi messages tell disconnected mi on disconnect getticker queuetimedjob peernode isconnected timelastdisconnect messageitem messagestelldisconnected grabqueuedmessageitems messagestelldisconnected messageitem messagestelldisconnected ondisconnect public void force disconnect boolean purge logger error this forcing disconnect on this new exception debug synchronized this force disconnect called true disconnected purge true always dump trackers maybe dump messages forcedisconnect forcedisconnectcalled boolean force disconnect called return force disconnect called forcedisconnectcalled forcedisconnectcalled grab all queued message s return null if no messages are queued or an array of message s public message item grab queued message items return message queue grab queued message items messageitem grabqueuedmessageitems messagequeue grabqueuedmessageitems public void requeue message items message item messages int offset int length boolean dont log requeue message items messages offset length dont log requeuemessageitems messageitem dontlog requeuemessageitems dontlog public void requeue message items message item messages int offset int length boolean dont log string reason will usually indicate serious problems if dont log long now system current time millis string rate limit wrapper boolean rate limit logging false if messages length message requeue log rate limit threshold rate limit wrapper log message rate limited if next message requeue log time now next message requeue log time now message requeue log rate limit interval else rate limit logging true if rate limit logging string reason wrapper if 0 reason length reason wrapper because of reason logger normal this requeueing messages length messages reason wrapper on this rate limit wrapper synchronized message queue for int i offset length 1 i offset i if messages i null message queue pushfront prioritized message item messages i requeuemessageitems messageitem dontlog dontlog currenttimemillis ratelimitwrapper ratelimitlogging messagerequeuelogratelimitthreshold ratelimitwrapper nextmessagerequeuelogtime nextmessagerequeuelogtime messagerequeuelogratelimitinterval ratelimitlogging ratelimitlogging reasonwrapper reasonwrapper reasonwrapper ratelimitwrapper messagequeue messagequeue pushfrontprioritizedmessageitem return the time at which we must send a packet even if it means it will only contains ack requests etc or long max value if we have no pending ack request acks etc note that if this is less than now it may not be entirely accurate i e we definitely must send a packet but don t rely on it to tell you exactly how overdue we are public long get next urgent time long now long t long max value session key cur session key prev synchronized this cur current tracker prev previous tracker session key kt cur if kt null long next kt packets get next urgent time t math min t next if next now logminor logger minor this next urgent time from cur tracker less than now if kt packets has packets to resend return now kt prev if kt null long next kt packets get next urgent time t math min t next if next now logminor logger minor this next urgent time from prev tracker less than now if kt packets has packets to resend return now try if cur null cur packets would block false t message queue get next urgent time t now if there isn t a current tracker no point worrying about it as we won t be able to send it anyway catch blocked too long exception e ignore for now it will come back around return t max_value getnexturgenttime max_value sessionkey sessionkey currenttracker previoustracker sessionkey getnexturgenttime curtracker haspacketstoresend getnexturgenttime prevtracker haspacketstoresend wouldblock messagequeue getnexturgenttime blockedtoolongexception private synchronized boolean must send notifications now long now session key kt current tracker if kt null if kt packets get next urgent time now return true kt previous tracker if kt null if kt packets get next urgent time now return true return false mustsendnotificationsnow sessionkey currenttracker getnexturgenttime previoustracker getnexturgenttime return the time at which we last sent a packet public long last sent packet time return time last sent packet lastsentpackettime timelastsentpacket return true if we are disconnected and it has been a sufficient time period since we last sent a handshake attempt public boolean should send handshake long now system current time millis boolean temp should send handshake false synchronized this temp should send handshake now send handshake time handshakei ps null is rekeying is connected if temp should send handshake has live handshake now temp should send handshake false if temp should send handshake if is burst only synchronized this is bursting true set peer node status system current time millis else return true return temp should send handshake shouldsendhandshake currenttimemillis tempshouldsendhandshake tempshouldsendhandshake sendhandshaketime handshakeips isrekeying isconnected tempshouldsendhandshake haslivehandshake tempshouldsendhandshake tempshouldsendhandshake isburstonly isbursting setpeernodestatus currenttimemillis tempshouldsendhandshake does the node have a live handshake in progress param now the current time public boolean has live handshake long now key agreement scheme context c null synchronized this c ctx if c null logminor logger minor this last used now c last used time return c null now c last used time node handshake timeout haslivehandshake keyagreementschemecontext lastusedtime lastusedtime handshake_timeout set send handshake time and return whether to fetch the ark protected boolean inner calc next handshake boolean successful handshake send boolean dont fetchark long now if is burst only return calc next handshake burst only now synchronized this long delay if unroutable older version unroutable newer version disable routing let them know we re here but have no hope of routing general data to them delay node min time between version sends node random next int node randomized time between version sends else if invalid version first handshake delay node min time between version probes node random next int node randomized time between version probes else delay node min time between handshake sends node random next int node randomized time between handshake sends fixme proper multi homing support delay handshakei ps null 1 handshakei ps length if delay 3000 delay 3000 send handshake time now delay if successful handshake send first handshake false handshake count return handshake count max handshake count sendhandshaketime innercalcnexthandshake successfulhandshakesend dontfetchark isburstonly calcnexthandshakeburstonly unroutableolderversion unroutablenewerversion disablerouting min_time_between_version_sends nextint randomized_time_between_version_sends invalidversion firsthandshake min_time_between_version_probes nextint randomized_time_between_version_probes min_time_between_handshake_sends nextint randomized_time_between_handshake_sends handshakeips handshakeips sendhandshaketime successfulhandshakesend firsthandshake handshakecount handshakecount max_handshake_count private synchronized boolean calc next handshake burst only long now boolean fetchark flag false listening handshake burst count if is burst only if listening handshake burst count listening handshake burst size listening handshake burst count 0 fetchark flag true long delay if listening handshake burst count 0 0 only if we just reset it above delay node min time between bursting handshake bursts node random next int node randomized time between bursting handshake bursts listening handshake burst size node min bursting handshake burst size node random next int node randomized bursting handshake burst size is bursting false else delay node min time between handshake sends node random next int node randomized time between handshake sends fixme proper multi homing support delay handshakei ps null 1 handshakei ps length if delay 3000 delay 3000 send handshake time now delay if logminor logger minor this next burst only mode handshake in send handshake time now ms for short to string count listening handshake burst count size listening handshake burst size new exception double called debug return fetchark flag calcnexthandshakeburstonly fetcharkflag listeninghandshakeburstcount isburstonly listeninghandshakeburstcount listeninghandshakeburstsize listeninghandshakeburstcount fetcharkflag listeninghandshakeburstcount min_time_between_bursting_handshake_bursts nextint randomized_time_between_bursting_handshake_bursts listeninghandshakeburstsize min_bursting_handshake_burst_size nextint randomized_bursting_handshake_burst_size isbursting min_time_between_handshake_sends nextint randomized_time_between_handshake_sends handshakeips handshakeips sendhandshaketime burstonly sendhandshaketime shorttostring listeninghandshakeburstcount listeninghandshakeburstsize fetcharkflag protected void calc next handshake boolean successful handshake send boolean dont fetchark boolean not registered long now system current time millis boolean fetchark flag false fetchark flag inner calc next handshake successful handshake send dont fetchark now if not registered set peer node status now because of is bursting being set above and it can t hurt others don t fetch ar ks for peers we have verified through handshake to be incompatible with us if fetchark flag dont fetchark long ark fetcher start time1 system current time millis startark fetcher long ark fetcher start time2 system current time millis if ark fetcher start time2 ark fetcher start time1 500 logger normal this ark fetcher start time2 is more than half a second after ark fetcher start time1 ark fetcher start time2 ark fetcher start time1 working on short to string calcnexthandshake successfulhandshakesend dontfetchark notregistered currenttimemillis fetcharkflag fetcharkflag innercalcnexthandshake successfulhandshakesend dontfetchark notregistered setpeernodestatus isbursting arks fetcharkflag dontfetchark arkfetcherstarttime1 currenttimemillis startarkfetcher arkfetcherstarttime2 currenttimemillis arkfetcherstarttime2 arkfetcherstarttime1 arkfetcherstarttime2 arkfetcherstarttime1 arkfetcherstarttime2 arkfetcherstarttime1 shorttostring public boolean is burst only int status outgoing mangler get connectivity status if status address tracker dont know return false if status address tracker definitely nated status address tracker maybe nated return false for now fixme try it with a lower probability when we re sure that the packet deltas mechanisms works if status address tracker maybe port forwarded return false long now system current time millis if now time set burst now update burst now period burst now node random next int p burst if definitely forwarded 0 time set burst now now return burst now isburstonly outgoingmangler getconnectivitystatus addresstracker dont_know addresstracker definitely_nated addresstracker maybe_nated addresstracker maybe_port_forwarded currenttimemillis timesetburstnow update_burst_now_period burstnow nextint p_burst_if_definitely_forwarded timesetburstnow burstnow call this method when a handshake request has been sent public void sent handshake boolean not registered if logminor logger minor this sent handshake this calc next handshake true false not registered senthandshake notregistered senthandshake calcnexthandshake notregistered call this method when a handshake request could not be sent i e no ip address available sent public void could not send handshake boolean not registered if logminor logger minor this could not send handshake this calc next handshake false false not registered couldnotsendhandshake notregistered couldnotsendhandshake calcnexthandshake notregistered return the maximum time between received packets public int max time between received packets return node max peer inactivity maxtimebetweenreceivedpackets max_peer_inactivity low level ping this node return true if we received a reply inside 2000ms if we have heavy packet loss it can take that long to resend public boolean ping int pingid throws not connected exception message ping dmt createfnp ping pingid node usm send this ping node dispatcher ping counter message msg try msg node usm wait for message filter create set timeout 2000 set type dmt fnp pong set field dmt ping seqno pingid null catch disconnected exception e throw new not connected exception disconnected while waiting for pong return msg null notconnectedexception createfnpping pingcounter waitfor messagefilter settimeout settype fnppong setfield ping_seqno disconnectedexception notconnectedexception decrement the htl or not in accordance with our probabilistic htl rules param htl the old htl return the new htl public short decrementhtl short htl short max node maxhtl if htl max htl max if htl 0 return 0 if htl max if decrementhtl at maximum node disable probabilisticht ls htl return htl if htl 1 if decrementhtl at minimum node disable probabilisticht ls htl return htl htl return htl decrementhtlatmaximum disableprobabilistichtls decrementhtlatminimum disableprobabilistichtls enqueue a message to be sent to this node and wait up to a minute for it to be transmitted public void send sync message req byte counter ctr throws not connected exception sync message callback cb new sync message callback send async req cb ctr cb wait for send 60 1000 if cb done logger error this waited too long for a blocking send for req to peer node this new exception error this local rejected overload send sync timeout sendsync bytecounter notconnectedexception syncmessagecallback syncmessagecallback sendasync waitforsend peernode localrejectedoverload sendsynctimeout public synchronized void wait for send long max wait interval throws not connected exception long now system current time millis long end now max wait interval while now system current time millis end if done if disconnected throw new not connected exception return int wait time int math min end now integer max value try wait wait time catch interrupted exception e ignore waitforsend maxwaitinterval notconnectedexception currenttimemillis maxwaitinterval currenttimemillis notconnectedexception waittime max_value waittime interruptedexception public void acknowledged synchronized this if done can happen due to lag logger normal this acknowledged but not sent on this for peer node this lag else return done true notify all peernode notifyall public void disconnected synchronized this done true disconnected true notify all notifyall public void fatal error synchronized this done true notify all fatalerror notifyall public void sent synchronized this done true notify all notifyall public void update location double new loc double new locs if new loc 0 0 new loc 1 0 logger error this invalid location update for this new loc new exception error ignore it return for double current loc new locs if current loc 0 0 current loc 1 0 logger error this invalid location update for this current loc new exception error ignore it return arrays sort new locs synchronized this current location new loc current peers location new locs loc set time system current time millis node peers write peers updatelocation newloc newlocs newloc newloc newloc currentloc newlocs currentloc currentloc currentloc newlocs currentlocation newloc currentpeerslocation newlocs locsettime currenttimemillis writepeers should we reject a swap request public boolean should reject swap request long now system current time millis synchronized this if time last received swap request 0 long time since last time now time last received swap request swap requests interval report time since last time double average interval swap requests interval current value if average interval node min interval between incoming swap requests time last received swap request now return false else return true time last received swap request now return false shouldrejectswaprequest currenttimemillis timelastreceivedswaprequest timesincelasttime timelastreceivedswaprequest swaprequestsinterval timesincelasttime averageinterval swaprequestsinterval currentvalue averageinterval min_interval_between_incoming_swap_requests timelastreceivedswaprequest timelastreceivedswaprequest should we reject a swap request public boolean should reject probe request long now system current time millis synchronized this if time last received probe request 0 long time since last time now time last received probe request probe requests interval report time since last time double average interval probe requests interval current value if average interval node min interval between incoming probe requests time last received probe request now return false else return true time last received probe request now return false shouldrejectproberequest currenttimemillis timelastreceivedproberequest timesincelasttime timelastreceivedproberequest proberequestsinterval timesincelasttime averageinterval proberequestsinterval currentvalue averageinterval min_interval_between_incoming_probe_requests timelastreceivedproberequest timelastreceivedproberequest ip on the other side appears to have changed param new peer the new address of the peer public void changedip peer new peer set detected peer new peer newpeer newpeer setdetectedpeer newpeer private void set detected peer peer new peer only clear last attempted handshakeip update time if we have a new ip also we need to call equals to propagate any dns lookups that have been done if the two have the same domain peer p new peer new peer new peer drop host name if new peer null logger error this impossible no address for detected peer p on this return synchronized this peer old peer detected peer if new peer null old peer null old peer equals new peer this detected peer new peer update short to string this last attempted handshakeip update time 0 if is connected return prevent leak by clearing but keep the current handshake new peer new peer drop host name old peer old peer drop host name byte new peer handshake jfk nonces sent get new peer byte old peer handshake jfk nonces sent get old peer jfk nonces sent clear jfk nonces sent put new peer new peer handshake jfk nonces sent put new peer old peer handshake else return get throttle maybe disconnected sendip address message setdetectedpeer newpeer lastattemptedhandshakeipupdatetime newpeer newpeer newpeer drophostname newpeer oldpeer detectedpeer newpeer oldpeer oldpeer newpeer detectedpeer newpeer updateshorttostring lastattemptedhandshakeipupdatetime isconnected newpeer newpeer drophostname oldpeer oldpeer drophostname newpeerhandshake jfknoncessent newpeer oldpeerhandshake jfknoncessent oldpeer jfknoncessent jfknoncessent newpeer newpeerhandshake jfknoncessent newpeer oldpeerhandshake getthrottle maybedisconnected sendipaddressmessage return the current primary session key or null if we don t have one public synchronized session key get current key tracker return current tracker sessionkey sessionkey getcurrentkeytracker currenttracker return the previous primary session key or null if we don t have one public synchronized session key get previous key tracker return previous tracker sessionkey sessionkey getpreviouskeytracker previoustracker return the unverified session key if any or null if we don t have one the caller must call verified kt if a decrypt succeeds with this kt public synchronized session key get unverified key tracker return unverified tracker sessionkey sessionkey getunverifiedkeytracker unverifiedtracker private string short to string private void update short to string short to string super to string detected peer hex util bytes to hex identity shorttostring updateshorttostring shorttostring tostring detectedpeer hexutil bytestohex return short version of to string note that this is not synchronized it is used by logging in code paths that will deadlock if it is synchronized public string short to string return short to string tostring shorttostring shorttostring override public string to string fixme return short to string integer to hex string super hash code tostring shorttostring tohexstring hashcode update time last received packet throws not connected exception param dont log if true don t log an error or throw an exception if we are not connected this can be used in handshaking when the connection hasn t been verified yet param data packet if this is a real packet as opposed to a handshake packet void received packet boolean dont log boolean data packet synchronized this if is connected dont log don t log if we are disconnecting because receiving packets during disconnecting is normal that includes receiving packets after we have technically disconnected already a race condition involving force cancel disconnecting causing a mistaken log message anyway is conceivable but unlikely if unverified tracker null current tracker null disconnecting logger error this received packet while disconnected this new exception error else if logminor logger minor this received packet while disconnected on this recently disconnected else if logminor logger minor this received packet on this long now system current time millis synchronized this time last received packet now if data packet time last received data packet now timelastreceivedpacket notconnectedexception dontlog datapacket receivedpacket dontlog datapacket isconnected dontlog forcecanceldisconnecting unverifiedtracker currenttracker currenttimemillis timelastreceivedpacket datapacket timelastreceiveddatapacket update time last sent packet public void sent packet time last sent packet system current time millis timelastsentpacket sentpacket timelastsentpacket currenttimemillis public synchronized key agreement scheme context get key agreement scheme context return ctx keyagreementschemecontext getkeyagreementschemecontext public synchronized void set key agreement scheme context key agreement scheme context ctx2 this ctx ctx2 if logminor logger minor this set key agreement scheme context ctx2 on this setkeyagreementschemecontext keyagreementschemecontext setkeyagreementschemecontext called when we have completed a handshake and have a new session key creates a new tracker and demotes the old one deletes the old one if the bootid isn t recognized since if the node has restarted we cannot recover old messages in more detail ul li process the new noderef check if it s valid pick up any new information etc li li handle version conflicts if the node is too old or we are too old we mark it as non routable but some messages will still be exchanged e g update over mandatory stuff li li deal with key trackers if we just got message 4 the new key tracker becomes current if we just got message 3 it s possible that our message 4 will be lost in transit so we make the new tracker unverified it will be promoted to current if we get a packet on it if the node has restarted we dump the old key trackers otherwise current becomes previous li li complete the connection process update the node s status send initial messages update the last received packet timestamp etc li param this bootid the boot id of the peer we have just connected to this is simply a random number regenerated on every startup of the node we use it to determine whether the node has restarted since we last saw it param data byte array from which to read the new noderef param offset offset to start reading at param length number of bytes to read param enc key the new session key param reply to the ip the handshake came in on param trackerid the tracker id proposed by the other side if 1 create a new tracker if any other value check whether we have it and if we do return that otherwise return the id of the new tracker param isjfk4 if true we are processing a jfk 4 and must respect the tracker id chosen by the responder if false we are processing a jfk 3 and we can either reuse the suggested tracker id which the other side is able to reuse or we can create a new tracker id param jfk4 same as old if true the responder chose to use the tracker id that we provided if we don t have it now the connection fails return the id of the new packet tracker if this is different to the passed in trackerid then it s a new tracker 1 to indicate failure public long completed handshake long this bootid byte data int offset int length block cipher enc cipher byte enc key peer reply to boolean unverified int neg type long trackerid boolean isjfk4 boolean jfk4 same as old long now system current time millis if logminor logger minor this tracker id trackerid isjfk4 isjfk4 jfk4 same as old jfk4 same as old update send handshake time don t send another handshake for a while if unverified a while determines the timeout if not it s just good practice to avoid a race below calc next handshake true true false stopark fetcher try first the new noderef process new noderef data offset length catch fs parse exception e1 synchronized this bogus noderef true disconnect something broke is connected false logger error this failed to parse new noderef for this e1 e1 node peers disconnected this return 1 boolean routable true boolean newer false boolean older false if bogus noderef logger normal this not routing traffic to this bogus noderef routable false fixme it looks like bogus noderef will just be set to false a few lines later else if reverse invalid version try node set newest peer last good version version get arbitrary build number get last good version version last good build catch number format exception e ignore logger normal this not routing traffic to this reverse invalid version version get version string for peer s last goodversion get last good version newer true else newer false if forward invalid version logger normal this not routing traffic to this invalid version get version older true routable false else if math abs clock delta max clock delta logger normal this not routing traffic to this clock problems routable false else older false changedip reply to boolean bootid changed false boolean wasa rekey false session key old prev null session key old cur null session key prev null session key new tracker message item messages tell disconnected null packet tracker packets null synchronized this handshake count 0 bogus noderef false don t reset the uptime if we rekey if is connected connected time now count selections since connected 0 sent initial messages false else wasa rekey true is connected true disable routing disable routing has been set locally disable routing has been set remotely is routable routable unroutable newer version newer unroutable older version older boolean not reusing tracker false bootid changed this bootid this bootid if bootid changed wasa rekey logger error this changed boot id while rekeying from bootid to this bootid for get peer wasa rekey false connected time now count selections since connected 0 sent initial messages false else if bootid changed logminor logger minor this changed boot id from bootid to this bootid for get peer this bootid this bootid if current tracker null current tracker packets trackerid trackerid current tracker packets is deprecated if isjfk4 jfk4 same as old logger error this in jfk 4 found tracker id trackerid but other side says is new for this packets current tracker packets if logminor logger minor this re using packet tracker id trackerid on this from current current tracker else if previous tracker null previous tracker packets trackerid trackerid previous tracker packets is deprecated if isjfk4 jfk4 same as old logger error this in jfk 4 found tracker id trackerid but other side says is new for this packets previous tracker packets if logminor logger minor this re using packet tracker id trackerid on this from prev previous tracker else if isjfk4 jfk4 same as old is connected false logger error this can t reuse old tracker id trackerid as instructed disconnecting return 1 else if trackerid 1 create a new tracker unconditionally packets new packet tracker this not reusing tracker true if logminor logger minor this creating new packet tracker as instructed for this else if isjfk4 neg type 4 trackerid 0 logger error this jfk 4 packet with neg type neg type has negative tracker id trackerid not reusing tracker true if isjfk4 jfk4 same as old implied trackerid 0 packets new packet tracker this trackerid else packets new packet tracker this if logminor logger minor this creating new tracker last resort on this if bootid changed not reusing tracker if bootid changed not reusing tracker fixme is this a real problem clearly the other side has changed trackers for some reason normally that shouldn t happen except when a connection times out it is probably possible for that to timeout on one side and not the other logger error this not reusing tracker so wiping old trackers for this old prev previous tracker old cur current tracker previous tracker null current tracker null messages do not persist across restarts generally they would be incomprehensible anything that isn t should be sent as connection initial messages by maybe on connect messages tell disconnected grab queued message items this offered main jar version 0 else else it s a rekey new tracker new session key this packets enc cipher enc key if logminor logger minor this new key tracker in completed handshake new tracker for packets for short to string neg type neg type if unverified if unverified tracker null keep the old unverified tracker if possible if previous tracker null previous tracker unverified tracker unverified tracker new tracker if current tracker null current tracker packets is deprecated is connected false else prev current tracker previous tracker prev current tracker new tracker keep the old unverified tracker in case of a race condition two setups between a and b complete at the same time we might want to keep the unverified tracker rather than the previous tracker never connected false peer added time 0 don t store anymore maybe swap trackers prev previous tracker ctx null is rekeying false time last rekeyed now unverified 0 fnp packet mangler max session key rekeying delay 2 total bytes exchanged with current tracker 0 this has happened in the past and caused problems check for it if current tracker null previous tracker null arrays equals current tracker session key previous tracker session key logger error this current tracker key equals previous tracker key cur current tracker prev previous tracker if previous tracker null unverified tracker null arrays equals previous tracker session key unverified tracker session key logger error this previous tracker key equals unverified tracker key thisbootid enckey replyto jfk4sameasold packettracker completedhandshake thisbootid blockcipher enccipher enckey replyto negtype jfk4sameasold currenttimemillis jfk4sameasold jfk4sameasold sendhandshaketime calcnexthandshake stoparkfetcher processnewnoderef fsparseexception bogusnoderef isconnected bogusnoderef bogusnoderef reverseinvalidversion setnewestpeerlastgoodversion getarbitrarybuildnumber getlastgoodversion lastgoodbuild numberformatexception getversionstring lastgoodversion getlastgoodversion forwardinvalidversion getversion clockdelta max_clock_delta replyto bootidchanged wasarekey sessionkey oldprev sessionkey oldcur sessionkey sessionkey newtracker messageitem messagestelldisconnected packettracker handshakecount bogusnoderef isconnected connectedtime countselectionssinceconnected sentinitialmessages wasarekey isconnected disablerouting disableroutinghasbeensetlocally disableroutinghasbeensetremotely isroutable unroutablenewerversion unroutableolderversion notreusingtracker bootidchanged thisbootid bootidchanged wasarekey thisbootid getpeer wasarekey connectedtime countselectionssinceconnected sentinitialmessages bootidchanged thisbootid getpeer thisbootid currenttracker currenttracker currenttracker isdeprecated jfk4sameasold currenttracker currenttracker previoustracker previoustracker previoustracker isdeprecated jfk4sameasold previoustracker previoustracker jfk4sameasold isconnected packettracker notreusingtracker packettracker negtype negtype notreusingtracker jfk4sameasold packettracker packettracker bootidchanged notreusingtracker bootidchanged notreusingtracker oldprev previoustracker oldcur currenttracker previoustracker currenttracker maybeonconnect messagestelldisconnected grabqueuedmessageitems offeredmainjarversion newtracker sessionkey enccipher enckey completedhandshake newtracker shorttostring negtype unverifiedtracker previoustracker previoustracker unverifiedtracker unverifiedtracker newtracker currenttracker currenttracker isdeprecated isconnected currenttracker previoustracker currenttracker newtracker neverconnected peeraddedtime maybeswaptrackers previoustracker isrekeying timelastrekeyed fnppacketmangler max_session_key_rekeying_delay totalbytesexchangedwithcurrenttracker currenttracker previoustracker currenttracker sessionkey previoustracker sessionkey currenttracker previoustracker currenttracker previoustracker previoustracker unverifiedtracker previoustracker sessionkey unverifiedtracker sessionkey previoustracker unverifiedtracker resolve race conditions where two connection setups between two peers complete simultaneously swap prev and current if there is a very short period between their respective creations current s hashcode including the key the word test and the xor of the boot i ds is greater than previous s private synchronized void maybe swap trackers if current tracker null previous tracker null return if current tracker packets previous tracker packets return long delta math abs current tracker packets created time previous tracker packets created time if previous tracker null previous tracker packets is deprecated delta check for swapped trackers interval swap prev and current iff h new key h old key to deal with race conditions node a gets 1 current 2 prev node b gets 2 current 1 prev when we rekey we lose data and cause problems fixme since this is a key dependancy it needs to be looked at however an attacker cannot get this far without knowing the privkey so it s unlikely to be an issue message digest md sha256 get message digest md update current tracker session key md update test as bytes md update fields long to bytes bootid node bootid int cur hash fields hash code md digest md reset md update previous tracker session key md update test as bytes md update fields long to bytes bootid node bootid int prev hash fields hash code md digest sha256 return message digest md if prev hash cur hash swap over session key temp previous tracker previous tracker current tracker current tracker temp if logminor logger minor this swapped session key s on this cur current tracker prev previous tracker delta delta cur deprecated current tracker packets is deprecated prev deprecated previous tracker packets is deprecated else if logminor logger minor this not swapping session key s on this cur current tracker prev previous tracker delta delta cur deprecated current tracker packets is deprecated prev deprecated previous tracker packets is deprecated else if logminor logger minor this not swapping session key s previous tracker previous tracker to string previous tracker packets is deprecated deprecated time delta delta ids maybeswaptrackers currenttracker previoustracker currenttracker previoustracker currenttracker createdtime previoustracker createdtime previoustracker previoustracker isdeprecated check_for_swapped_trackers_interval messagedigest getmessagedigest currenttracker sessionkey test_as_bytes longtobytes curhash hashcode previoustracker sessionkey test_as_bytes longtobytes prevhash hashcode returnmessagedigest prevhash curhash sessionkey previoustracker previoustracker currenttracker currenttracker sessionkey currenttracker previoustracker currenttracker isdeprecated previoustracker isdeprecated sessionkey currenttracker previoustracker currenttracker isdeprecated previoustracker isdeprecated sessionkey previoustracker previoustracker tostring previoustracker isdeprecated public long get bootid return bootid getbootid void startark fetcher fixme any way to reduce locking here if node enablear ks return synchronized ark fetcher sync if myark null logger minor this no ark for this return if ark fetcher null logger minor this starting ark fetcher for this myark ark fetcher node client core usk manager subscribe content myark this true node ark fetcher context request starter immediate splitfile priority class node non persistent client startarkfetcher enablearks arkfetchersync arkfetcher arkfetcher clientcore uskmanager subscribecontent arkfetchercontext requeststarter immediate_splitfile_priority_class nonpersistentclient protected void stopark fetcher if node enablear ks return logger minor this stopping ark fetcher for this myark fixme any way to reduce locking here synchronized ark fetcher sync if ark fetcher null return node client core usk manager unsubscribe content myark this ark fetcher true ark fetcher null stoparkfetcher enablearks arkfetchersync arkfetcher clientcore uskmanager unsubscribecontent arkfetcher arkfetcher wipe it out public short get polling priority normal return request starter immediate splitfile priority class getpollingprioritynormal requeststarter immediate_splitfile_priority_class public short get polling priority progress return request starter immediate splitfile priority class getpollingpriorityprogress requeststarter immediate_splitfile_priority_class void maybe send initial messages synchronized this if sent initial messages return if current tracker null current tracker packets is deprecated fixme is that possible sent initial messages true else return send initial messages maybesendinitialmessages sentinitialmessages currenttracker currenttracker isdeprecated sentinitialmessages sendinitialmessages send any high level messages that need to be sent on connect protected void send initial messages message loc msg dmt createfnp loc change notification new node lm get location node peers get peer location doubles true message ip msg dmt createfnp detectedip address detected peer message time msg dmt createfnp time system current time millis message packets msg create sent packets message message d routing msg dmt create routing status disable routing has been set locally message uptime msg dmt createfnp uptime byte int 100 node uptime get uptime try if is real connection send async loc msg null node node stats initial messages ctr send async ip msg null node node stats initial messages ctr send async time msg null node node stats initial messages ctr send async packets msg null node node stats initial messages ctr send async d routing msg null node node stats initial messages ctr send async uptime msg null node node stats initial messages ctr catch not connected exception e logger error this completed handshake with get peer but disconnected is connected current tracker e e if node node updater null is real connection node node updater maybe senduom announce this send connected diff noderef sendinitialmessages locmsg createfnplocchangenotificationnew getlocation getpeerlocationdoubles ipmsg createfnpdetectedipaddress detectedpeer timemsg createfnptime currenttimemillis packetsmsg createsentpacketsmessage droutingmsg createroutingstatus disableroutinghasbeensetlocally uptimemsg createfnpuptime getuptime isrealconnection sendasync locmsg nodestats initialmessagesctr sendasync ipmsg nodestats initialmessagesctr sendasync timemsg nodestats initialmessagesctr sendasync packetsmsg nodestats initialmessagesctr sendasync droutingmsg nodestats initialmessagesctr sendasync uptimemsg nodestats initialmessagesctr notconnectedexception getpeer isconnected currenttracker nodeupdater isrealconnection nodeupdater maybesenduomannounce sendconnecteddiffnoderef private message create sent packets message long sent get sent packet times hashes long times sent 0 long hashes sent 1 long now system current time millis long horizon now integer max value int skip 0 for int i 0 i times length i long time times i if time horizon skip else break int time deltas new int times length skip for int i skip i times length i time deltas i int now times i if skip 0 unlikely code path only happens with very long uptime trim hashes too long new hashes new long hashes length skip system arraycopy hashes skip new hashes 0 hashes length skip return dmt createfnp sent packets time deltas hashes now createsentpacketsmessage getsentpackettimeshashes currenttimemillis max_value timedeltas timedeltas newhashes newhashes createfnpsentpackets timedeltas private void sendip address message message ip msg dmt createfnp detectedip address detected peer try send async ip msg null node node stats changedip ctr catch not connected exception e logger normal this sending ip change message to this but disconnected e e sendipaddressmessage ipmsg createfnpdetectedipaddress detectedpeer sendasync ipmsg nodestats changedipctr notconnectedexception called when a packet is successfully decrypted on a given session key for this node will promote the unverified tracker if necessary public void verified session key tracker long now system current time millis session key completely deprecated tracker synchronized this if tracker unverified tracker tracker packets is deprecated if logminor logger minor this promoting unverified tracker tracker for get peer completely deprecated tracker previous tracker previous tracker current tracker current tracker unverified tracker unverified tracker null is connected true never connected false peer added time 0 don t store anymore ctx null maybe swap trackers if previous tracker null previous tracker packets current tracker packets previous tracker packets deprecated else return maybe send initial messages set peer node status now node peers add connected peer this maybe on connect if completely deprecated tracker null if completely deprecated tracker packets tracker packets completely deprecated tracker packets completely deprecated tracker sessionkey unverifiedtracker sessionkey currenttimemillis sessionkey completelydeprecatedtracker unverifiedtracker isdeprecated getpeer completelydeprecatedtracker previoustracker previoustracker currenttracker currenttracker unverifiedtracker unverifiedtracker isconnected neverconnected peeraddedtime maybeswaptrackers previoustracker previoustracker currenttracker previoustracker maybesendinitialmessages setpeernodestatus addconnectedpeer maybeonconnect completelydeprecatedtracker completelydeprecatedtracker completelydeprecatedtracker completelydeprecated private synchronized boolean invalid version return bogus noderef forward invalid version reverse invalid version invalidversion bogusnoderef forwardinvalidversion reverseinvalidversion private synchronized boolean forward invalid version return version check good version version forwardinvalidversion checkgoodversion private synchronized boolean reverse invalid version if ignore last good version return false return version check arbitrary good version version get version string last good version reverseinvalidversion ignorelastgoodversion checkarbitrarygoodversion getversionstring lastgoodversion the same as is unroutable older version but not synchronized public boolean public invalid version return unroutable older version isunroutableolderversion publicinvalidversion unroutableolderversion the same as in unroutable newer version public synchronized boolean public reverse invalid version return unroutable newer version inunroutablenewerversion publicreverseinvalidversion unroutablenewerversion public synchronized boolean dont route return disable routing dontroute disablerouting process a differential node reference the identity must not change or we throw public void process diff noderef simple field set fs throws fs parse exception process new noderef fs false true processdiffnoderef simplefieldset fsparseexception processnewnoderef process a new nodereference in compressed form the identity must not change or we throw private void process new noderef byte data int offset int length throws fs parse exception simple field set fs compressed noderef to field set data offset length process new noderef fs false false processnewnoderef fsparseexception simplefieldset compressednodereftofieldset processnewnoderef static simple field set compressed noderef to field set byte data int offset int length throws fs parse exception if length 5 throw new fs parse exception too short lookup table for groups dsa group group null int first byte data offset offset length if first byte 0x2 2 int group index data offset 0xff offset length group global get group group index if group null throw new fs parse exception unknown group number group index if logminor logger minor peer node class dsa group set to group fingerprint to string using the group index group index is it compressed if first byte 1 1 try gzipped inflater i new inflater i set input data offset length we shouldn t ever need a 4096 bytes long ref byte output new byte 4096 length i inflate output 0 output length finished data output offset 0 if logminor logger minor peer node class we have decompressed a length bytes big reference catch data format exception e throw new fs parse exception invalid compressed data if logminor logger minor peer node class reference hex util bytes to hex data offset length length now decode it byte array input stream bais new byte array input stream data offset length input stream reader isr try isr new input stream reader bais utf 8 catch unsupported encoding exception e1 throw new error impossible jvm doesn t support utf 8 e1 e1 buffered reader br new buffered reader isr try simple field set fs new simple field set br false true if group null simple field set sfs new simple field set true sfs put dsa group group as field set fs put all overwrite sfs return fs catch io exception e fs parse exception ex new fs parse exception impossible e ex init cause e throw ex simplefieldset compressednodereftofieldset fsparseexception fsparseexception dsagroup firstbyte firstbyte groupindex getgroup groupindex fsparseexception groupindex peernode dsagroup fingerprinttostring groupindex firstbyte setinput peernode dataformatexception fsparseexception peernode hexutil bytestohex bytearrayinputstream bytearrayinputstream inputstreamreader inputstreamreader unsupportedencodingexception bufferedreader bufferedreader simplefieldset simplefieldset simplefieldset simplefieldset dsagroup asfieldset putalloverwrite ioexception fsparseexception fsparseexception initcause process a new nodereference as a simple field set private void process new noderef simple field set fs boolean forark boolean for diff node ref throws fs parse exception if logminor logger minor this parsing n fs boolean changed anything inner process new noderef fs forark for diff node ref if changed anything node peers write peers simplefieldset processnewnoderef simplefieldset fordiffnoderef fsparseexception changedanything innerprocessnewnoderef fordiffnoderef changedanything writepeers the synchronized part of process new noderef throws fs parse exception protected synchronized boolean inner process new noderef simple field set fs boolean forark boolean for diff node ref throws fs parse exception anything may be omitted for a differential node reference boolean changed anything false if for diff node ref node testnet enabled fields string to bool fs get testnet false string err preventing connection to node detected peer peer testnet node testnet enabled fs get testnet but node testnet node testnet enabled logger error this err throw new fs parse exception err string new version fs get version if new version null version may be ommitted for an ark if forark for diff node ref throw new fs parse exception no version else if new version equals version changed anything true version new version if version null try simple version version get arbitrary build number version catch version parse exception e logger error this bad version version e e version seen version new version string new last good version fs get last good version if new last good version null can be null if anon auth or if for diff node ref last good version new last good version update version routablity string location string fs get location if location string null double new loc location get location location string if new loc 1 if logminor logger minor this invalid or null location waiting for fnp loc change notification location string location string else if location equals new loc current location changed anything true current location new loc loc set time system current time millis try string physical fs get all physical udp if physical null vector peer old nominal peer nominal peer if nominal peer null nominal peer new vector peer nominal peer remove all elements peer old peers nominal peer to array new peer nominal peer size for int i 0 i physical length i peer p try p new peer physical i true true catch hostname syntax exception e logger error this invalid hostname or ip address syntax error while parsing new peer reference physical i continue if nominal peer contains p if old nominal peer contains p do nothing contains will equals on each and equals will propagate the looked up ip if necessary this is obviously o n 2 but it doesn t matter there will be very few peers nominal peer add element p if arrays equals old peers nominal peer to array new peer nominal peer size changed anything true if logminor logger minor this got new physical udp for this arrays to string nominal peer to array last attempted handshakeip update time 0 clear nonces to prevent leak will kill any in progress connect attempts but that is okay because either we got an ark which changed our peers list or we just connected jfk nonces sent clear else if forark connection setup doesn t include a physical udp differential noderefs only include it on the first one after connect logger error this ark noderef has no physical udp for this for diff node ref for diff node ref forark forark catch exception e1 logger error this caught e1 e1 throw new fs parse exception e1 if logminor logger minor this parsed successfully changed anything changed anything int new neg types fs get int array auth neg types boolean ref had neg types false if new neg types null new neg types length 0 new neg types new int 0 else ref had neg types true if for diff node ref ref had neg types if arrays equals neg types new neg types changed anything true neg types new neg types if parseark fs false for diff node ref changed anything true return changed anything processnewnoderef fsparseexception innerprocessnewnoderef simplefieldset fordiffnoderef fsparseexception changedanything fordiffnoderef testnetenabled stringtobool detectedpeer testnetenabled testnetenabled fsparseexception newversion newversion fordiffnoderef fsparseexception newversion changedanything newversion simpleversion getarbitrarybuildnumber versionparseexception seenversion newversion newlastgoodversion lastgoodversion newlastgoodversion fordiffnoderef lastgoodversion newlastgoodversion updateversionroutablity locationstring locationstring newloc getlocation locationstring newloc fnplocchangenotification locationstring locationstring newloc currentlocation changedanything currentlocation newloc locsettime currenttimemillis getall oldnominalpeer nominalpeer nominalpeer nominalpeer nominalpeer removeallelements oldpeers nominalpeer toarray nominalpeer hostnamesyntaxexception nominalpeer oldnominalpeer nominalpeer addelement oldpeers nominalpeer toarray nominalpeer changedanything tostring nominalpeer toarray lastattemptedhandshakeipupdatetime jfknoncessent fordiffnoderef fordiffnoderef fsparseexception changedanything changedanything newnegtypes getintarray negtypes refhadnegtypes newnegtypes newnegtypes newnegtypes refhadnegtypes fordiffnoderef refhadnegtypes negtypes newnegtypes changedanything negtypes newnegtypes fordiffnoderef changedanything changedanything send a payload less packet on either key if necessary throws packet sequence exception if there is an error sending the packet caused by a sequence inconsistency public boolean send any urgent notifications boolean force send primary boolean sent false if logminor logger minor this send any urgent notifications long now system current time millis session key cur prev synchronized this cur current tracker prev previous tracker session key tracker cur if tracker null long t tracker packets get next urgent time if t now force send primary try if logminor logger minor this sending urgent notifications for current tracker on short to string int size outgoing mangler process outgoing null 0 0 tracker dmt priority now node node stats report notification only packet sent size sent true catch not connected exception e ignore catch key changed exception e ignore catch would block exception e logger error this caught impossible e e catch packet sequence exception e logger error this caught impossible e e tracker prev if tracker null long t tracker packets get next urgent time if t now try if logminor logger minor this sending urgent notifications for previous tracker on short to string int size outgoing mangler process outgoing null 0 0 tracker dmt priority now node node stats report notification only packet sent size sent true catch not connected exception e ignore catch key changed exception e ignore catch would block exception e logger error this caught impossible e e catch packet sequence exception e logger error this caught impossible e e return sent packetsequenceexception sendanyurgentnotifications forcesendprimary sendanyurgentnotifications currenttimemillis sessionkey currenttracker previoustracker sessionkey getnexturgenttime forcesendprimary shorttostring outgoingmangler processoutgoing priority_now nodestats reportnotificationonlypacketsent notconnectedexception keychangedexception wouldblockexception packetsequenceexception getnexturgenttime shorttostring outgoingmangler processoutgoing priority_now nodestats reportnotificationonlypacketsent notconnectedexception keychangedexception wouldblockexception packetsequenceexception void check tracker timeout long now system current time millis session key prev null session key cur null synchronized this if previous tracker null return if current tracker null return cur current tracker prev previous tracker if prev packets cur packets return long t prev packets get next urgent time if t 1 prev packets time last decoded packet 0 now prev packets time last decoded packet 60 1000 cur packets time last decoded packet 0 now cur packets time last decoded packet 30 1000 prev packets count ack requests 0 prev packets count resend requests 0 return logger error this no packets decoded on prev for 60 seconds deprecating in favour of cur cur prev packets completely deprecated cur checktrackertimeout currenttimemillis sessionkey sessionkey previoustracker currenttracker currenttracker previoustracker getnexturgenttime timelastdecodedpacket timelastdecodedpacket timelastdecodedpacket timelastdecodedpacket countackrequests countresendrequests completelydeprecated get a peer node status for this node param no heavy if true avoid any expensive operations e g the message count hashtables peernodestatus noheavy public string gettmci peer info long now system current time millis int idle 1 synchronized this idle int now time last received packet 1000 if get peer node status peer manager peer node status never connected get peer added time 1 idle int now get peer added time 1000 return string value of get peer t get identity string t get location t get peer node status string t idle gettmcipeerinfo currenttimemillis timelastreceivedpacket getpeernodestatus peermanager peer_node_status_never_connected getpeeraddedtime getpeeraddedtime valueof getpeer getidentitystring getlocation getpeernodestatusstring public string get freeviz output return get status true to string identity as base64 string getfreevizoutput getstatus tostring identityasbase64string public synchronized string get version return version getversion private synchronized string get last good version return last good version getlastgoodversion lastgoodversion private int simple version public int get simple version return simple version simpleversion getsimpleversion simpleversion write the peer s noderef to disk public void write writer w throws io exception simple field set fs export field set simple field set meta export metadata field set if meta is empty fs put metadata meta fs write to w ioexception simplefieldset exportfieldset simplefieldset exportmetadatafieldset isempty writeto both metadata normal fieldset but atomically public synchronized simple field set export disk field set simple field set fs export field set simple field set meta export metadata field set if meta is empty fs put metadata meta return fs simplefieldset exportdiskfieldset simplefieldset exportfieldset simplefieldset exportmetadatafieldset isempty export metadata about the node as a simple field set public synchronized simple field set export metadata field set simple field set fs new simple field set true if detected peer null fs put single detected udp detected peer to string pref numeric if last received packet time 0 fs put single time last received packet long to string time last received packet if time last connected 0 fs put single time last connected long to string time last connected if time last routable 0 fs put single time last routable long to string time last routable if get peer added time 0 fs put single peer added time long to string peer added time if never connected fs put single never connected true if had routable connection count 0 fs put single had routable connection count long to string had routable connection count if routable connection check count 0 fs put single routable connection check count long to string routable connection check count if current peers location null fs put peers location current peers location return fs simplefieldset simplefieldset exportmetadatafieldset simplefieldset simplefieldset detectedpeer putsingle detectedpeer tostringprefnumeric lastreceivedpackettime putsingle timelastreceivedpacket tostring timelastreceivedpacket timelastconnected putsingle timelastconnected tostring timelastconnected timelastroutable putsingle timelastroutable tostring timelastroutable getpeeraddedtime putsingle peeraddedtime tostring peeraddedtime neverconnected putsingle neverconnected hadroutableconnectioncount putsingle hadroutableconnectioncount tostring hadroutableconnectioncount routableconnectioncheckcount putsingle routableconnectioncheckcount tostring routableconnectioncheckcount currentpeerslocation peerslocation currentpeerslocation export volatile data about the node as a simple field set public simple field set export volatile field set simple field set fs new simple field set true long now system current time millis synchronized this fs put single average ping time double to string average ping time long idle now last received packet time if idle 60 1000 1 last received packet time 1 minute fs put single idle long to string idle if peer added time 1 fs put single peer added time long to string peer added time fs put single last routing backoff reason last routing backoff reason fs put single routing backoff percent double to string backed off percent current value 100 fs put single routing backoff long to string math max math max routing backed off until transfer backed off until now 0 fs put single routing backoff length integer to string routing backoff length fs put single overload probability double to string getp rejected 100 fs put single percent time routable connection double to string get percent time routable connection 100 fs put single status get peer node status string return fs simplefieldset simplefieldset exportvolatilefieldset simplefieldset simplefieldset currenttimemillis putsingle averagepingtime tostring averagepingtime lastreceivedpackettime lastreceivedpackettime putsingle tostring peeraddedtime putsingle peeraddedtime tostring peeraddedtime putsingle lastroutingbackoffreason lastroutingbackoffreason putsingle routingbackoffpercent tostring backedoffpercent currentvalue putsingle routingbackoff tostring routingbackedoffuntil transferbackedoffuntil putsingle routingbackofflength tostring routingbackofflength putsingle overloadprobability tostring getprejected putsingle percenttimeroutableconnection tostring getpercenttimeroutableconnection putsingle getpeernodestatusstring export the peer s noderef as a simple field set public synchronized simple field set export field set simple field set fs new simple field set true if get last good version null fs put single last good version last good version for int i 0 i nominal peer size i fs put append physical udp nominal peer get i to string fs put auth neg types neg types fs put single identity get identity string fs put single location double to string current location fs put single testnet boolean to string testnet enabled fs put single version version if peer crypto group null fs put dsa group peer crypto group as field set if peer pub key null fs put dsa pub key peer pub key as field set if myark null decrement it because we keep the number we would like to fetch not the last one fetched fs put single ark number long to string myark suggested edition 1 fs put single ark puburi myark get basessk to string false false fs put opennet is opennet fs put seed is seed fs put total input get total input since startup get total input bytes fs put total output get total output since startup get total output bytes return fs simplefieldset simplefieldset exportfieldset simplefieldset simplefieldset getlastgoodversion putsingle lastgoodversion lastgoodversion nominalpeer putappend nominalpeer tostring negtypes negtypes putsingle getidentitystring putsingle tostring currentlocation putsingle tostring testnetenabled putsingle peercryptogroup dsagroup peercryptogroup asfieldset peerpubkey dsapubkey peerpubkey asfieldset putsingle tostring suggestededition putsingle getbasessk tostring isopennet isseed totalinput gettotalinputsincestartup gettotalinputbytes totaloutput gettotaloutputsincestartup gettotaloutputbytes public abstract boolean is darknet isdarknet public abstract boolean is darknet public abstract boolean is opennet isdarknet isopennet public abstract boolean is opennet public abstract boolean is seed isopennet isseed return the time at which we last connected or reconnected public synchronized long time last connection completed return connected time timelastconnectioncompleted connectedtime requeue resend packet item s if they are not sent param resend items public void requeue resend items vector resend packet item resend items session key cur prev unv synchronized this cur current tracker prev previous tracker unv unverified tracker for resend packet item item resend items if item pn this throw new illegal argument exception item pn this session key kt cur if kt null item kt kt packets kt packets resend packet item packet number continue kt prev if kt null item kt kt packets kt packets resend packet item packet number continue kt unv if kt null item kt kt packets kt packets resend packet item packet number continue doesn t match any of these need to resend the data kt cur null unv cur if kt null logger error this no tracker to resend packet item packet number on continue message item mi new message item item buf item callbacks true resend byte counter item priority requeue message items new message item mi 0 1 true resendpacketitem resenditems requeueresenditems resendpacketitem resenditems sessionkey currenttracker previoustracker unverifiedtracker resendpacketitem resenditems illegalargumentexception sessionkey resendpacket packetnumber resendpacket packetnumber resendpacket packetnumber packetnumber messageitem messageitem resendbytecounter requeuemessageitems messageitem override public boolean equals object o if o this return true if o instanceof peer node peer node pn peer node o return arrays equals pn identity identity else return false peernode peernode peernode override public int hash code return hash code hashcode hashcode public boolean is routing backed off long now system current time millis synchronized this return now routing backed off until now transfer backed off until isroutingbackedoff currenttimemillis routingbackedoffuntil transferbackedoffuntil got a local rejected overload back off this node for a while public void local rejected overload local rejected overload rejectedoverload localrejectedoverload localrejectedoverload track the percentage of time a peer spends backed off private void report backoff status long now synchronized this if now last sample time don t report twice in the same millisecond if now routing backed off until not backed off if last sample time routing backed off until last sample after last backoff backed off percent report 0 0 else if routing backed off until 0 backed off percent report double routing backed off until last sample time double now last sample time else backed off percent report 1 0 last sample time now reportbackoffstatus lastsampletime routingbackedoffuntil lastsampletime routingbackedoffuntil backedoffpercent routingbackedoffuntil backedoffpercent routingbackedoffuntil lastsampletime lastsampletime backedoffpercent lastsampletime got a local rejected overload back off this node for a while public void local rejected overload string reason assert reason index of 1 p rejected report 1 0 if logminor logger minor this local rejected overload reason on this p rejected p rejected current value long now system current time millis peer peer get peer report backoff status now we need it because of nested locking on get status synchronized this don t back off any further if we are already backed off if now routing backed off until routing backoff length routing backoff length backoff multiplier if routing backoff length max routing backoff length routing backoff length max routing backoff length int x node random next int routing backoff length routing backed off until now x string reason wrapper if 0 reason length reason wrapper because of reason if logminor logger minor this backing off reason wrapper routing backoff length routing backoff length until x ms on peer else if logminor logger minor this ignoring local rejected overload routing backed off until now ms remaining on routing backoff on peer return set last backoff reason reason set peer node status now rejectedoverload localrejectedoverload indexof prejected prejected prejected currentvalue currenttimemillis getpeer reportbackoffstatus getstatus routingbackedoffuntil routingbackofflength routingbackofflength backoff_multiplier routingbackofflength max_routing_backoff_length routingbackofflength max_routing_backoff_length nextint routingbackofflength routingbackedoffuntil reasonwrapper reasonwrapper reasonwrapper routingbackofflength routingbackofflength localrejectedoverload routingbackedoffuntil setlastbackoffreason setpeernodestatus didn t get rejected overload reset routing backoff public void success not overload p rejected report 0 0 if logminor logger minor this success not overload on this p rejected p rejected current value peer peer get peer long now system current time millis report backoff status now synchronized this don t un backoff if still backed off if now routing backed off until routing backoff length initial routing backoff length if logminor logger minor this resetting routing backoff on peer else if logminor logger minor this ignoring success not overload routing backed off until now ms remaining on routing backoff on peer return set peer node status now rejectedoverload successnotoverload prejected prejected prejected currentvalue getpeer currenttimemillis reportbackoffstatus routingbackedoffuntil routingbackofflength initial_routing_backoff_length successnotoverload routingbackedoffuntil setpeernodestatus a transfer failed back off this node for a while public void transfer failed string reason assert reason index of 1 p rejected report 1 0 if logminor logger minor this transfer failed reason on this p rejected p rejected current value long now system current time millis peer peer get peer report backoff status now we need it because of nested locking on get status synchronized this don t back off any further if we are already backed off if now transfer backed off until transfer backoff length transfer backoff length transfer backoff multiplier if transfer backoff length max transfer backoff length transfer backoff length max transfer backoff length int x node random next int transfer backoff length transfer backed off until now x string reason wrapper if 0 reason length reason wrapper because of reason if logminor logger minor this backing off transfer reason wrapper transfer backoff length transfer backoff length until x ms on peer else if logminor logger minor this ignoring transfer failure transfer backed off until now ms remaining on transfer backoff on peer return set last backoff reason reason set peer node status now transferfailed indexof prejected prejected prejected currentvalue currenttimemillis getpeer reportbackoffstatus getstatus transferbackedoffuntil transferbackofflength transferbackofflength transfer_backoff_multiplier transferbackofflength max_transfer_backoff_length transferbackofflength max_transfer_backoff_length nextint transferbackofflength transferbackedoffuntil reasonwrapper reasonwrapper reasonwrapper transferbackofflength transferbackofflength transferbackedoffuntil setlastbackoffreason setpeernodestatus a transfer succeeded reset backoff public void transfer success p rejected report 0 0 if logminor logger minor this transfer success on this p rejected p rejected current value peer peer get peer long now system current time millis report backoff status now synchronized this don t un backoff if still backed off if now transfer backed off until routing backoff length initial transfer backoff length if logminor logger minor this resetting transfer backoff on peer else if logminor logger minor this ignoring transfer success transfer backed off until now ms remaining on transfer backoff on peer return set peer node status now transfersuccess prejected prejected prejected currentvalue getpeer currenttimemillis reportbackoffstatus transferbackedoffuntil routingbackofflength initial_transfer_backoff_length transferbackedoffuntil setpeernodestatus return the probability of a request sent to this peer being rejected locally due to overload or timing out after being accepted public double getp rejected return p rejected current value getprejected prejected currentvalue public double average ping time return ping average current value averagepingtime pingaverage currentvalue public void report throttled packet send time long time diff node node stats throttled packet send average report time diff if logminor logger minor this reporting throttled packet send time time diff to get peer reportthrottledpacketsendtime timediff nodestats throttledpacketsendaverage timediff timediff getpeer public void set remote detected peer peer p this remote detected peer p setremotedetectedpeer remotedetectedpeer public peer get remote detected peer return remote detected peer getremotedetectedpeer remotedetectedpeer public synchronized int get routing backoff length return routing backoff length getroutingbackofflength routingbackofflength public synchronized long get routing backed off until return math max routing backed off until transfer backed off until getroutingbackedoffuntil routingbackedoffuntil transferbackedoffuntil public synchronized string get last backoff reason return last routing backoff reason getlastbackoffreason lastroutingbackoffreason public synchronized string get previous backoff reason return previous routing backoff reason getpreviousbackoffreason previousroutingbackoffreason public synchronized void set last backoff reason string s last routing backoff reason s setlastbackoffreason lastroutingbackoffreason public void add to local node sent messages to statistic message m string message spec name long count message spec name m get spec get name synchronize to make increments atomic synchronized local node sent message types count local node sent message types get message spec name if count null count 1l else count count long value 1 local node sent message types put message spec name count addtolocalnodesentmessagestostatistic messagespecname messagespecname getspec getname localnodesentmessagetypes localnodesentmessagetypes messagespecname longvalue localnodesentmessagetypes messagespecname public void add to local node received messages from statistic message m string message spec name long count message spec name m get spec get name synchronize to make increments atomic synchronized local node received message types count local node received message types get message spec name if count null count 1l else count count long value 1 local node received message types put message spec name count addtolocalnodereceivedmessagesfromstatistic messagespecname messagespecname getspec getname localnodereceivedmessagetypes localnodereceivedmessagetypes messagespecname longvalue localnodereceivedmessagetypes messagespecname public hashtable string long get local node sent messages to statistic must be synchronized during the copy synchronized local node sent message types return new hashtable string long local node sent message types getlocalnodesentmessagestostatistic localnodesentmessagetypes localnodesentmessagetypes public hashtable string long get local node received messages from statistic must be synchronized during the copy synchronized local node received message types return new hashtable string long local node received message types getlocalnodereceivedmessagesfromstatistic localnodereceivedmessagetypes localnodereceivedmessagetypes synchronized usk getark return myark public void gotark simple field set fs long fetched edition try synchronized this handshake count 0 edition 1 because we store the ark edition that we want to fetch if myark suggested edition fetched edition 1 myark myark copy fetched edition 1 process new noderef fs true false catch fs parse exception e logger error this invalid ark update e e this is ok as ar ks are limited to 4k anyway logger error this data was n fs to string synchronized this handshake count peer node max handshake count simplefieldset fetchededition handshakecount suggestededition fetchededition fetchededition processnewnoderef fsparseexception arks tostring handshakecount peernode max_handshake_count public synchronized int get peer node status return peer node status getpeernodestatus peernodestatus public string get peer node status string int status get peer node status return get peer node status string status getpeernodestatusstring getpeernodestatus getpeernodestatusstring public static string get peer node status string int status if status peer manager peer node status connected return connected if status peer manager peer node status routing backed off return backed off if status peer manager peer node status too new return too new if status peer manager peer node status too old return too old if status peer manager peer node status disconnected return disconnected if status peer manager peer node status never connected return never connected if status peer manager peer node status disabled return disabled if status peer manager peer node status clock problem return clock problem if status peer manager peer node status conn error return connection error if status peer manager peer node status routing disabled return routing disabled if status peer manager peer node status listen only return listen only if status peer manager peer node status listening return listening if status peer manager peer node status bursting return bursting if status peer manager peer node status disconnecting return disconnecting return unknown status getpeernodestatusstring peermanager peer_node_status_connected peermanager peer_node_status_routing_backed_off peermanager peer_node_status_too_new peermanager peer_node_status_too_old peermanager peer_node_status_disconnected peermanager peer_node_status_never_connected peermanager peer_node_status_disabled peermanager peer_node_status_clock_problem peermanager peer_node_status_conn_error peermanager peer_node_status_routing_disabled peermanager peer_node_status_listen_only peermanager peer_node_status_listening peermanager peer_node_status_bursting peermanager peer_node_status_disconnecting public string get peer node statuscss class name int status get peer node status return get peer node statuscss class name status getpeernodestatuscssclassname getpeernodestatus getpeernodestatuscssclassname public static string get peer node statuscss class name int status if status peer manager peer node status connected return peer connected else if status peer manager peer node status routing backed off return peer backed off else if status peer manager peer node status too new return peer too new else if status peer manager peer node status too old return peer too old else if status peer manager peer node status disconnected return peer disconnected else if status peer manager peer node status never connected return peer never connected else if status peer manager peer node status disabled return peer disabled else if status peer manager peer node status routing disabled return peer routing disabled else if status peer manager peer node status bursting return peer bursting else if status peer manager peer node status clock problem return peer clock problem else if status peer manager peer node status listening return peer listening else if status peer manager peer node status listen only return peer listen only else if status peer manager peer node status disconnecting return peer disconnecting else return peer unknown status getpeernodestatuscssclassname peermanager peer_node_status_connected peer_connected peermanager peer_node_status_routing_backed_off peer_backed_off peermanager peer_node_status_too_new peer_too_new peermanager peer_node_status_too_old peer_too_old peermanager peer_node_status_disconnected peer_disconnected peermanager peer_node_status_never_connected peer_never_connected peermanager peer_node_status_disabled peer_disabled peermanager peer_node_status_routing_disabled peer_routing_disabled peermanager peer_node_status_bursting peer_bursting peermanager peer_node_status_clock_problem peer_clock_problem peermanager peer_node_status_listening peer_listening peermanager peer_node_status_listen_only peer_listen_only peermanager peer_node_status_disconnecting peer_disconnecting peer_unknown_status protected synchronized int get peer node status long now long routing backed off until check connections and trackers if disconnecting return peer manager peer node status disconnecting if is routable function use also updates time last connected and time last routable peer node status peer manager peer node status connected if now routing backed off until peer node status peer manager peer node status routing backed off if last routing backoff reason equals previous routing backoff reason previous routing backoff reason null if previous routing backoff reason null peers remove peer node routing backoff reason previous routing backoff reason this peers add peer node routing backoff reason last routing backoff reason this previous routing backoff reason last routing backoff reason else if previous routing backoff reason null peers remove peer node routing backoff reason previous routing backoff reason this previous routing backoff reason null else if is connected bogus noderef peer node status peer manager peer node status conn error else if is connected unroutable newer version peer node status peer manager peer node status too new else if is connected unroutable older version peer node status peer manager peer node status too old else if is connected disable routing peer node status peer manager peer node status routing disabled else if is connected math abs clock delta max clock delta peer node status peer manager peer node status clock problem else if never connected peer node status peer manager peer node status never connected else if is bursting return peer manager peer node status bursting else peer node status peer manager peer node status disconnected if is connected previous routing backoff reason null peers remove peer node routing backoff reason previous routing backoff reason this previous routing backoff reason null return peer node status getpeernodestatus routingbackedoffuntil checkconnectionsandtrackers peermanager peer_node_status_disconnecting isroutable timelastconnected timelastroutable peernodestatus peermanager peer_node_status_connected routingbackedoffuntil peernodestatus peermanager peer_node_status_routing_backed_off lastroutingbackoffreason previousroutingbackoffreason previousroutingbackoffreason previousroutingbackoffreason removepeernoderoutingbackoffreason previousroutingbackoffreason addpeernoderoutingbackoffreason lastroutingbackoffreason previousroutingbackoffreason lastroutingbackoffreason previousroutingbackoffreason removepeernoderoutingbackoffreason previousroutingbackoffreason previousroutingbackoffreason isconnected bogusnoderef peernodestatus peermanager peer_node_status_conn_error isconnected unroutablenewerversion peernodestatus peermanager peer_node_status_too_new isconnected unroutableolderversion peernodestatus peermanager peer_node_status_too_old isconnected disablerouting peernodestatus peermanager peer_node_status_routing_disabled isconnected clockdelta max_clock_delta peernodestatus peermanager peer_node_status_clock_problem neverconnected peernodestatus peermanager peer_node_status_never_connected isbursting peermanager peer_node_status_bursting peernodestatus peermanager peer_node_status_disconnected isconnected previousroutingbackoffreason removepeernoderoutingbackoffreason previousroutingbackoffreason previousroutingbackoffreason peernodestatus public int set peer node status long now return set peer node status now false setpeernodestatus setpeernodestatus public int set peer node status long now boolean no log long local routing backed off until get routing backed off until synchronized this int old peer node status peer node status peer node status get peer node status now local routing backed off until if peer node status old peer node status record status peers remove peer node status old peer node status this no log peers add peer node status peer node status this no log return peer node status setpeernodestatus nolog localroutingbackedoffuntil getroutingbackedoffuntil oldpeernodestatus peernodestatus peernodestatus getpeernodestatus localroutingbackedoffuntil peernodestatus oldpeernodestatus recordstatus removepeernodestatus oldpeernodestatus nolog addpeernodestatus peernodestatus nolog peernodestatus public abstract boolean record status recordstatus private synchronized void check connections and trackers if is connected if current tracker null if unverified tracker null if unverified tracker packets is deprecated logger error this connected but primary tracker is null and unverified is deprecated unverified tracker for this new exception debug else if logminor logger minor this connected but primary tracker is null but unverified unverified tracker for this new exception debug else logger error this connected but both primary and unverified are null on this new exception debug else if current tracker packets is deprecated if unverified tracker null if unverified tracker packets is deprecated logger error this connected but primary tracker is deprecated unverified is deprecated primary current tracker unverified unverified tracker for this new exception debug else if logminor logger minor this connected primary tracker deprecated unverified is valid unverified tracker for this new exception debug else logger error this connected but primary tracker is deprecated and unverified tracker is null on this primary tracker current tracker new exception debug is connected false checkconnectionsandtrackers isconnected currenttracker unverifiedtracker unverifiedtracker isdeprecated unverifiedtracker unverifiedtracker currenttracker isdeprecated unverifiedtracker unverifiedtracker isdeprecated currenttracker unverifiedtracker unverifiedtracker currenttracker isconnected public string get identity string return identity as base64 string getidentitystring identityasbase64string public boolean is fetchingark return ark fetcher null isfetchingark arkfetcher public synchronized int get handshake count return handshake count gethandshakecount handshakecount queries the version class to determine if this peers advertised build number is either too old or to new for the routing of requests synchronized void update version routablity unroutable older version forward invalid version unroutable newer version reverse invalid version updateversionroutablity unroutableolderversion forwardinvalidversion unroutablenewerversion reverseinvalidversion will return true if routing to this node is either explictly disabled or disabled due to noted incompatiblity in build version numbers logically not is routable but will return false even if disconnected meaning routing is not disabled public synchronized boolean no longer routable if unroutable newer version unroutable older version disable routing return true return false isroutable nolongerroutable unroutablenewerversion unroutableolderversion disablerouting protected synchronized void invalidate is routable false logger normal this invalidated this isroutable public void maybe on connect if was disconnected is connected synchronized this was disconnected false on connect else if is connected synchronized this was disconnected true maybeonconnect wasdisconnected isconnected wasdisconnected onconnect isconnected wasdisconnected a method to be called once at the beginning of every time is connected is true protected void on connect opennet manager om node get opennet if om null om drop excess peers isconnected onconnect opennetmanager getopennet dropexcesspeers public void on found usk origusk long edition fetch result result if is connected myark suggested edition edition result as bucket free return byte data try data result as byte array catch io exception e logger error this i o error reading fetched ark e e result as bucket free return string ref try ref new string data utf 8 catch unsupported encoding exception e result as bucket free throw new error impossible jvm doesn t support utf 8 e e simple field set fs try fs new simple field set ref false true if logminor logger minor this got ark for this gotark fs edition catch io exception e corrupt ref logger error this corrupt ark reference fetched myark copy edition got while parsing e from n ref e result as bucket free onfound fetchresult isconnected suggestededition asbucket asbytearray ioexception asbucket unsupportedencodingexception asbucket simplefieldset simplefieldset ioexception asbucket public synchronized boolean no contact details return handshakei ps null handshakei ps length 0 nocontactdetails handshakeips handshakeips private synchronized void report incoming bytes int length total bytes in length total bytes exchanged with current tracker length reportincomingbytes totalbytesin totalbytesexchangedwithcurrenttracker private synchronized void report outgoing bytes int length total bytes out length total bytes exchanged with current tracker length reportoutgoingbytes totalbytesout totalbytesexchangedwithcurrenttracker public synchronized long get total input bytes return total bytes in gettotalinputbytes totalbytesin public synchronized long get total output bytes return total bytes out gettotaloutputbytes totalbytesout public synchronized long get total input since startup return total input since startup gettotalinputsincestartup totalinputsincestartup public synchronized long get total output since startup return total output since startup gettotaloutputsincestartup totaloutputsincestartup public boolean is signature verification successfull return is signature verification successfull issignatureverificationsuccessfull issignatureverificationsuccessfull public void check routable connection status synchronized this if is routable had routable connection count 1 routable connection check count 1 prevent the average from moving too slowly by capping the checkcount to 200000 which at 7 seconds between counts works out to about 2 weeks this also prevents knowing how long we ve had a particular peer long term if routable connection check count 200000 divide both sides by the same amount to keep the same ratio had routable connection count had routable connection count 2 routable connection check count routable connection check count 2 checkroutableconnectionstatus isroutable hadroutableconnectioncount routableconnectioncheckcount routableconnectioncheckcount hadroutableconnectioncount hadroutableconnectioncount routableconnectioncheckcount routableconnectioncheckcount public synchronized double get percent time routable connection if had routable connection count 0 return 0 0 return double had routable connection count routable connection check count getpercenttimeroutableconnection hadroutableconnectioncount hadroutableconnectioncount routableconnectioncheckcount public int get version number return version get arbitrary build number get version 1 getversionnumber getarbitrarybuildnumber getversion public packet throttle get throttle packet throttle new throttle null packet throttle prev throttle null synchronized this peer peer get peer if peer null we haven t connected prevent an npe return null if lastthrottle null if lastthrottle get peer equals peer return lastthrottle new throttle new packet throttle peer node packet size prev throttle lastthrottle lastthrottle new throttle if prev throttle null prev throttle changed address new throttle return new throttle packetthrottle getthrottle packetthrottle newthrottle packetthrottle prevthrottle getpeer _lastthrottle _lastthrottle getpeer _lastthrottle newthrottle packetthrottle packet_size prevthrottle _lastthrottle _lastthrottle newthrottle prevthrottle prevthrottle changedaddress newthrottle newthrottle select the most appropriate neg type taking the user s preference into account order matters param mangler return 1 if no common neg type has been found public int select neg type outgoing packet mangler mangler int his neg types int my neg types mangler supported neg types synchronized this his neg types neg types int best neg type 1 for int i 0 i my neg types length i int neg type my neg types i for int j 0 j his neg types length j if his neg types j neg type best neg type neg type break return best neg type negtype negtype selectnegtype outgoingpacketmangler hisnegtypes mynegtypes supportednegtypes hisnegtypes negtypes bestnegtype mynegtypes negtype mynegtypes hisnegtypes hisnegtypes negtype bestnegtype negtype bestnegtype verify a hash public boolean verify byte hash dsa signature sig return dsa verify peer pub key sig new native big integer 1 hash false dsasignature peerpubkey nativebiginteger public string user to string return get peer usertostring getpeer public void set time delta long delta synchronized this clock delta delta if math abs clock delta max clock delta is routable false set peer node status system current time millis settimedelta clockdelta clockdelta max_clock_delta isroutable setpeernodestatus currenttimemillis public long get clock delta return clock delta getclockdelta clockdelta offer a key to this node public void offer key key byte key bytes key get full key fixme maybe the authenticator should be shorter than 32 bytes to save memory byte authenticator hmac mac withsha256 node failure table offer authenticator key key bytes 32 message msg dmt createfnp offer key key authenticator try send async msg null node node stats send offers ctr catch not connected exception e ignore keybytes getfullkey macwithsha256 failuretable offerauthenticatorkey keybytes createfnpofferkey sendasync nodestats sendoffersctr notconnectedexception public outgoing packet mangler get outgoing mangler return outgoing mangler outgoingpacketmangler getoutgoingmangler outgoingmangler public socket handler get socket handler return outgoing mangler get socket handler sockethandler getsockethandler outgoingmangler getsockethandler is this peer disabled i e has the user explicitly disabled it public boolean is disabled return false isdisabled is this peer allowed local addresses if false we will never connect to this peer via a local address even if it advertises them public boolean allow local addresses return this outgoing mangler always allow local addresses allowlocaladdresses outgoingmangler alwaysallowlocaladdresses is this peer set to ignore source address if so we will always reply to the peer s official address even if we get packets from somewhere else see darknet peer node is ignore source port public boolean is ignore source return false darknetpeernode isignoresourceport isignoresource create a darknet peer node or an opennet peer node as appropriate public static peer node create simple field set fs node node2 node crypto crypto opennet manager opennet peer manager manager boolean b outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception if crypto is opennet return new opennet peer node fs node2 crypto opennet manager b mangler else return new darknet peer node fs node2 crypto manager b mangler darknetpeernode opennetpeernode peernode simplefieldset nodecrypto opennetmanager peermanager outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception isopennet opennetpeernode darknetpeernode public byte get identity return identity getidentity public boolean never connected return never connected neverconnected neverconnected called when a request or insert succeeds used by opennet public abstract void on success boolean insert boolean ssk onsuccess called when a delayed disconnect is occurring tell the node that it is being disconnected but that the process may take a while public void notify disconnecting synchronized this disconnecting true jfk nonces sent clear set peer node status system current time millis notifydisconnecting jfknoncessent setpeernodestatus currenttimemillis called to cancel a delayed disconnect always succeeds even if the node was not being disconnected public void force cancel disconnecting synchronized this if disconnecting return disconnecting false set peer node status system current time millis true forcecanceldisconnecting setpeernodestatus currenttimemillis called when the peer is removed from the peer manager public void on remove disconnected true true stopark fetcher peermanager onremove stoparkfetcher public synchronized boolean is disconnecting return disconnecting isdisconnecting protected byte getjfk buffer return jfk buffer getjfkbuffer jfkbuffer protected void setjfk buffer byte bufferjfk this jfk buffer bufferjfk setjfkbuffer jfkbuffer public int get sig params byte length int bit len this peer crypto group getq bit length int byte len bit len 8 bit len 8 0 1 0 return byte len getsigparamsbytelength bitlen peercryptogroup bitlength bytelen bitlen bitlen bytelen public void report incoming packet byte buf int offset int length long now report incoming bytes length long hash fields long hash code buf offset length synchronized this packets recv times recv ptr now packets recv hashes recv ptr hash recv ptr if recv ptr track packets recv ptr 0 recv track packets true reportincomingpacket reportincomingbytes longhashcode packetsrecvtimes recvptr packetsrecvhashes recvptr recvptr recvptr track_packets recvptr recvtrackpackets public void report outgoing packet byte buf int offset int length long now report outgoing bytes length long hash fields long hash code buf offset length synchronized this packets sent times sent ptr now packets sent hashes sent ptr hash sent ptr if sent ptr track packets sent ptr 0 sent track packets true reportoutgoingpacket reportoutgoingbytes longhashcode packetssenttimes sentptr packetssenthashes sentptr sentptr sentptr track_packets sentptr senttrackpackets return a long consisting of two arrays the first being packet times the second being packet hashes public synchronized long get sent packet times hashes short count sent track packets track packets sent ptr long times new long count long hashes new long count if sent track packets system arraycopy packets sent times 0 times 0 sent ptr system arraycopy packets sent hashes 0 hashes 0 sent ptr else system arraycopy packets sent times sent ptr times 0 track packets sent ptr system arraycopy packets sent times 0 times track packets sent ptr sent ptr system arraycopy packets sent hashes sent ptr hashes 0 track packets sent ptr system arraycopy packets sent hashes 0 hashes track packets sent ptr sent ptr return new long times hashes getsentpackettimeshashes senttrackpackets track_packets sentptr senttrackpackets packetssenttimes sentptr packetssenthashes sentptr packetssenttimes sentptr track_packets sentptr packetssenttimes track_packets sentptr sentptr packetssenthashes sentptr track_packets sentptr packetssenthashes track_packets sentptr sentptr return a long consisting of two arrays the first being packet times the second being packet hashes public synchronized long get recv packet times hashes short count recv track packets track packets recv ptr long times new long count long hashes new long count if recv track packets system arraycopy packets recv times 0 times 0 recv ptr system arraycopy packets recv hashes 0 hashes 0 recv ptr else system arraycopy packets recv times recv ptr times 0 track packets recv ptr system arraycopy packets recv times 0 times track packets recv ptr recv ptr system arraycopy packets recv hashes recv ptr hashes 0 track packets recv ptr system arraycopy packets recv hashes 0 hashes track packets recv ptr recv ptr return new long times hashes getrecvpackettimeshashes recvtrackpackets track_packets recvptr recvtrackpackets packetsrecvtimes recvptr packetsrecvhashes recvptr packetsrecvtimes recvptr track_packets recvptr packetsrecvtimes track_packets recvptr recvptr packetsrecvhashes recvptr track_packets recvptr packetsrecvhashes track_packets recvptr recvptr handle an fnp sent packets message public void handle sent packets message m imho it s impossible to make this work reliably on lossy connections especially highly saturated upstreams if it was possible it would likely involve a lot of work refactoring voting between peers marginal results very slow accumulation of data etc long now system current time millis synchronized this if force disconnect called return i ve had some very strange results from seed clients one showed deltas of over 10 minutes how is that possible the pn wouldn t reconnect if is real connection return the packets wouldn t have been assigned to this peer node if now this time last connected sent packets max time after connect return long base time m get long dmt time base time this clock delta should be a reasonable approximation now int time deltas fields bytes to ints short buffer m get object dmt time deltas get data long packet hashes fields bytes to longs short buffer m get object dmt hashes get data long times new long time deltas length for int i 0 i times length i times i base time time deltas i long tolerance 60 1000 math abs time deltas 0 20 1 minute or 5 of full interval synchronized this they are in increasing order loop backwards long otime long max value long sent get recv packet times hashes long sent times sent 0 long sent hashes sent 1 short sent ptr short sent length 1 short not found count 0 short consecutive not found 0 short longest consecutive not found 0 short ignored uptime count 0 short found 0 the arrays are constructed from received data don t throw an array index out of bounds exception if they are different sizes int shortest array times length if shortest array packet hashes length shortest array packet hashes length for short i short shortest array 1 i 0 i long time times i if time otime logger error this inconsistent time order i time but i 1 is otime return else otime time long hash packet hashes i search for the hash short match 1 first try forwards for short j sent ptr j sent times length j long ttime sent times j if sent hashes j hash match j sent ptr j break if ttime time tolerance break if match 1 for short j short sent ptr 1 j 0 j long ttime sent times j if sent hashes j hash match j sent ptr j break if time ttime tolerance break if match 1 long must have been up at now int time deltas i 1 1 100 if this crypto socket get start time must have been up at ignored uptime count else not found consecutive not found not found count else if consecutive not found longest consecutive not found longest consecutive not found consecutive not found consecutive not found 0 found if consecutive not found longest consecutive not found longest consecutive not found consecutive not found logger error this packets packet hashes length not found not found count consecutive not found consecutive not found longest consecutive not found longest consecutive not found ignored due to uptime ignored uptime count found found if longest consecutive not found track packets 2 many packets claimed sent not received true time many packets claimed sent not received now logger error this consecutive not found consecutive packets not found on user to string socket handler handler outgoing mangler get socket handler if handler instanceof port forward sensitive socket handler port forward sensitive socket handler handler rescan port forward if many packets claimed sent not received outgoing mangler set port forwarding broken fnpsentpackets handlesentpackets currenttimemillis forcedisconnectcalled isrealconnection peernode timelastconnected sent_packets_max_time_after_connect basetime getlong basetime clockdelta timedeltas bytestoints shortbuffer getobject time_deltas getdata packethashes bytestolongs shortbuffer getobject getdata timedeltas basetime timedeltas timedeltas max_value getrecvpackettimeshashes senttimes senthashes sentptr notfoundcount consecutivenotfound longestconsecutivenotfound ignoreduptimecount arrayindexoutofboundsexception shortestarray shortestarray packethashes shortestarray packethashes shortestarray packethashes sentptr senttimes senttimes senthashes sentptr sentptr senttimes senthashes sentptr musthavebeenupat timedeltas getstarttime musthavebeenupat ignoreduptimecount consecutivenotfound notfoundcount consecutivenotfound longestconsecutivenotfound longestconsecutivenotfound consecutivenotfound consecutivenotfound consecutivenotfound longestconsecutivenotfound longestconsecutivenotfound consecutivenotfound packethashes notfoundcount consecutivenotfound longestconsecutivenotfound ignoreduptimecount longestconsecutivenotfound track_packets manypacketsclaimedsentnotreceived timemanypacketsclaimedsentnotreceived consecutivenotfound usertostring sockethandler outgoingmangler getsockethandler portforwardsensitivesockethandler portforwardsensitivesockethandler rescanportforward manypacketsclaimedsentnotreceived outgoingmangler setportforwardingbroken private boolean many packets claimed sent not received false synchronized boolean many packets claimed sent not received return many packets claimed sent not received manypacketsclaimedsentnotreceived manypacketsclaimedsentnotreceived manypacketsclaimedsentnotreceived public synchronized boolean should accept announce long uid long now system current time millis if running announceui ds length max simultaneous announcements now time last accepted announcement max announce delay long new list new long running announceui ds length 1 if running announceui ds length 0 system arraycopy running announceui ds 0 new list 0 running announceui ds length new list running announceui ds length uid time last accepted announcement now return true else return false shouldacceptannounce currenttimemillis runningannounceuids max_simultaneous_announcements timelastacceptedannouncement max_announce_delay newlist runningannounceuids runningannounceuids runningannounceuids newlist runningannounceuids newlist runningannounceuids timelastacceptedannouncement public synchronized boolean completed announce long uid final int running announceui ds length running announceui ds length if running announceui ds length 1 return false long new list new long running announceui ds length 1 int x 0 for int i 0 i running announceui ds length i if i running announceui ds length return false long l running announceui ds i if l uid continue new list x l running announceui ds new list if x running announceui ds length new list new long x system arraycopy running announceui ds 0 new list 0 x running announceui ds new list return true completedannounce runningannounceuidslength runningannounceuids runningannounceuidslength newlist runningannounceuidslength runningannounceuids runningannounceuids runningannounceuids newlist runningannounceuids newlist runningannounceuids newlist runningannounceuids newlist runningannounceuids newlist public synchronized long time last disconnect return time last disconnect timelastdisconnect timelastdisconnect does this peernode want to be returned by for example peer manager get by peer false seednode etc never going to be routable public abstract boolean is real connection peermanager getbypeer isrealconnection public abstract boolean is real connection can we accept announcements from this node public boolean can accept announcements return is opennet node pass opennet refs through darknet isrealconnection canacceptannouncements isopennet passopennetrefsthroughdarknet public boolean handshake unknown initiator return false handshakeunknowninitiator public int handshake setup type return 1 handshakesetuptype public weak reference peer node get weak ref return my ref weakreference peernode getweakref myref get a single address to send a handshake to the current code doesn t work well with multiple simulataneous handshakes alternates between valid values fixme public peer get handshakeip peer local handshakei ps if should send handshake if logminor logger minor this not sending handshake to get peer because pn should send handshake returned false return null long first time system current time millis local handshakei ps get handshakei ps long second time system current time millis if second time first time 1000 logger error this get handshakei ps took more than a second to execute second time first time working on user to string if local handshakei ps length 0 long third time system current time millis if third time second time 1000 logger error this could not send handshake after get handshakei ps took more than a second to execute third time second time working on user to string return null long loop time1 system current time millis vector peer validi ps new vector peer for int i 0 i local handshakei ps length i peer peer local handshakei ps i freenet inet address addr peer get freenet address if outgoing mangler allow connection this addr if logminor logger minor this not sending handshake packet to peer for this if peer get address false null if logminor logger minor this not sending handshake to local handshakei ps i for get peer because the dns lookup failed or it s a currently unsupported i pv6 address continue if peer is real internet address false false allow local addresses if logminor logger minor this not sending handshake to local handshakei ps i for get peer because it s not a real internet address and metadata allow local addresses is not true continue validi ps add peer peer ret if validi ps is empty ret null else if validi ps size 1 ret validi ps get 0 else don t need to synchronize for this value as we re only called from one thread anyway handshakeip alternator validi ps size ret validi ps get handshakeip alternator handshakeip alternator long loop time2 system current time millis if loop time2 loop time1 1000 logger normal this loop time2 is more than a second after loop time1 loop time2 loop time1 working on user to string return ret gethandshakeip localhandshakeips shouldsendhandshake getpeer shouldsendhandshake firsttime currenttimemillis localhandshakeips gethandshakeips secondtime currenttimemillis secondtime firsttime gethandshakeips secondtime firsttime usertostring localhandshakeips thirdtime currenttimemillis thirdtime secondtime couldnotsendhandshake gethandshakeips thirdtime secondtime usertostring looptime1 currenttimemillis validips localhandshakeips localhandshakeips freenetinetaddress getfreenetaddress outgoingmangler allowconnection getaddress localhandshakeips getpeer ipv6 isrealinternetaddress allowlocaladdresses localhandshakeips getpeer allowlocaladdresses validips validips isempty validips validips handshakeipalternator validips validips handshakeipalternator handshakeipalternator looptime2 currenttimemillis looptime2 looptime1 looptime2 looptime1 looptime2 looptime1 usertostring public void send node to node message simple field set fs int n2n type boolean include sent time long now boolean queue on not connected fs put overwrite n2n type integer to string n2n type if include sent time fs put sent time now try message n2nm n2nm dmt create node to node message n2n type fs to string get bytes utf 8 try send async n2nm null node node stats node to node counter catch not connected exception e if include sent time fs remove value sent time if is darknet queue on not connected queuen2nm fs catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e sendnodetonodemessage simplefieldset n2ntype includesenttime queueonnotconnected putoverwrite n2ntype tostring n2ntype includesenttime senttime createnodetonodemessage n2ntype tostring getbytes sendasync nodestats nodetonodecounter notconnectedexception includesenttime removevalue senttime isdarknet queueonnotconnected unsupportedencodingexception a method to queue an n2nm in a extra peer data file only implemented by darknet peer node public void queuen2nm simple field set fs do nothing in the default impl darknetpeernode simplefieldset return the relevant local node reference related to this peer s type protected simple field set get local noderef return crypto export public field set simplefieldset getlocalnoderef exportpublicfieldset a method to be called after completing a handshake to send the newly connected peer as a differential node reference the parts of our node reference not needed for handshake should only be called by completed handshake after we re happy with the connection protected void send connected diff noderef simple field set fs new simple field set true simple field set nfs get local noderef if null nfs return if null nfs get ark puburi fs put overwrite ark puburi nfs get ark puburi if null nfs get ark number fs put overwrite ark number nfs get ark number if is darknet null nfs get my name fs put overwrite my name nfs get my name string physicaludp entries nfs get all physical udp if physicaludp entries null fs put overwrite physical udp physicaludp entries if fs is empty if logminor logger minor this fs is fs to string send node to node message fs node n2n message type diffnoderef false 0 false else if logminor logger minor this fs is empty completedhandshake sendconnecteddiffnoderef simplefieldset simplefieldset simplefieldset getlocalnoderef putoverwrite putoverwrite isdarknet myname putoverwrite myname myname physicaludpentries getall physicaludpentries putoverwrite physicaludpentries isempty tostring sendnodetonodemessage n2n_message_type_diffnoderef void handlefnp networkid message m int got m get int dmt uid if logminor logger minor this now peer thinks he is in network got if provided networkid got assigned networkid got provided networkid got node netid on peer node changed networkid this else provided networkid got handlefnpnetworkid getint providednetworkid assignednetworkid providednetworkid onpeernodechangednetworkid providednetworkid void sendfnp networkid byte counter ctr throws not connected exception if assigned networkid 0 send async dmt createfnp networkid assigned networkid null ctr sendfnpnetworkid bytecounter notconnectedexception assignednetworkid sendasync createfnpnetworkid assignednetworkid public boolean should throttle return should throttle get peer node shouldthrottle shouldthrottle getpeer public static boolean should throttle peer peer node node if node throttle local data return true if peer null return true presumably inet address addr peer get address false if addr null return true presumably return ip util is valid address addr false shouldthrottle throttlelocaldata inetaddress getaddress iputil isvalidaddress public void report ping long t this ping average report t reportping pingaverage public final byte counter resend byte counter new byte counter public void received bytes int x ignore bytecounter resendbytecounter bytecounter receivedbytes public void sent bytes int x synchronized peer node this resend bytes sent x node node stats resend byte counter sent bytes x sentbytes peernode resendbytessent nodestats resendbytecounter sentbytes public void sent payload int x ignore sentpayload public long get resend bytes sent return resend bytes sent getresendbytessent resendbytessent public void send throttled message message msg int packet size byte counter ctr int timeout boolean block for send async message callback callback throws not connected exception waited too long exception sync send waited too long exception long deadline system current time millis timeout if logminor logger minor this sending throttled message with timeout timeout packet size packet size to short to string for int i 0 i 100 i try get throttle send throttled message msg this packet size ctr deadline block for send callback return catch throttle deprecated exception e try with the new throttle we don t need it we ll get it from get throttle continue logger error this peer constantly changes its ip address short to string force disconnect true throw new not connected exception sendthrottledmessage packetsize bytecounter blockforsend asyncmessagecallback notconnectedexception waitedtoolongexception syncsendwaitedtoolongexception currenttimemillis packetsize shorttostring getthrottle sendthrottledmessage packetsize blockforsend throttledeprecatedexception getthrottle shorttostring forcedisconnect notconnectedexception should this peer be disconnected and removed immediately public boolean should disconnect and remove now return false shoulddisconnectandremovenow public void set uptime byte uptime2 this uptime uptime2 setuptime public short get uptime return short uptime 0xff getuptime public void increment number of selections long time todo reimplement with a bit field to spare memory synchronized this count selections since connected incrementnumberofselections countselectionssinceconnected return the rate at which this peer has been selected since it connected public synchronized double selection rate long time since connected system current time millis this connected time avoid bias due to short uptime if time since connected 10 1000 return 0 0 return count selections since connected double time since connected selectionrate timesinceconnected currenttimemillis connectedtime timesinceconnected countselectionssinceconnected timesinceconnected private volatile long offered main jar version public void set main jar offered version long main jar version offered main jar version main jar version offeredmainjarversion setmainjarofferedversion mainjarversion offeredmainjarversion mainjarversion public long get main jar offered version return offered main jar version getmainjarofferedversion offeredmainjarversion private volatile long offered ext jar version public void set ext jar offered version long ext jar version offered ext jar version ext jar version offeredextjarversion setextjarofferedversion extjarversion offeredextjarversion extjarversion public long get ext jar offered version return offered ext jar version getextjarofferedversion offeredextjarversion maybe send something a single packet don t send everything at once for two reasons 1 it is possible for a node to have a very long backlog 2 sometimes sending a packet can take a long time 3 in the near future packet sender will be responsible for output bandwidth throttling so it makes sense to send a single packet and round robin param now param rpi temp param rpi temp throws blocked too long exception public boolean maybe send packet long now vector resend packet item rpi temp int rpi int temp throws blocked too long exception if there are any urgent notifications we must send a packet if logminor logger minor this maybe send packet this boolean must send false boolean must send packet false if must send notifications now now if logminor logger minor this sending notification must send true must send packet true any packets to resend if so resend one packet and then return for int j 0 j 2 j session key kt if j 0 kt get current key tracker else if j 1 kt get previous key tracker if kt null continue int tmp kt packets grab resend packets rpi temp rpi int temp if tmp null continue rpi int temp tmp for resend packet item item rpi temp if item null continue try if logminor logger minor this resending item packet number to item kt get outgoing mangler resend item kt return true catch key changed exception e logger error this caught e resending packets to kt requeue resend items rpi temp return false catch not connected exception e logger normal this caught e resending packets to kt requeue resend items rpi temp return false catch packet sequence exception e logger error this caught e disconnecting e pse is fairly drastic something is broken between us but maybe we can resync force disconnect false return false catch would block exception e logger error this impossible e e return false int min size get outgoing mangler full headers length one message includes udp headers int max size packet socket handler get socket handler get packet send threshold if it s a keepalive we must add an fnp void to ensure it has a packet number boolean keepalive false long last sent last sent packet time if now last sent node keepalive interval if logminor logger minor this sending keepalive if now last sent node keepalive interval 10 last sent 1 logger error this long gap between sending packets now last sent for this keepalive true must send true must send packet true array list message item messages new array list message item 10 synchronized message queue any urgent messages to send now if must send if message queue must send now now must send true if must send what about total length if message queue must send size min size max size must send true if must send int size min size boolean got enough false size message queue add urgent messages size now min size max size messages if size 0 got enough true size size now the not so urgent messages if got enough size message queue add non urgent messages size now min size max size messages if size 0 size size if messages is empty keepalive force packet to have a sequence number message m dmt createfnp void add to local node sent messages to statistic m messages add new message item m null null this if messages is empty send packets right now blocking including any active notifications note that process outgoing or requeue will drop messages from the end if necessary to fit the messages into a single packet if get outgoing mangler process outgoing or requeue messages to array new message item messages size this false true if must send packet if send any urgent notifications false send any urgent notifications true return true else if must send if send any urgent notifications false return true can happen occasionally as a race condition logger normal this no notifications sent despite no messages and must send true for this return false packetsender rpitemp rpitemp blockedtoolongexception maybesendpacket resendpacketitem rpitemp rpiinttemp blockedtoolongexception maybesendpacket mustsend mustsendpacket mustsendnotificationsnow mustsend mustsendpacket sessionkey getcurrentkeytracker getpreviouskeytracker grabresendpackets rpitemp rpiinttemp rpiinttemp resendpacketitem rpitemp packetnumber getoutgoingmangler keychangedexception requeueresenditems rpitemp notconnectedexception requeueresenditems rpitemp packetsequenceexception forcedisconnect wouldblockexception minsize getoutgoingmangler fullheaderslengthonemessage maxsize packetsockethandler getsockethandler getpacketsendthreshold fnpvoid lastsent lastsentpackettime lastsent keepalive_interval lastsent keepalive_interval lastsent lastsent mustsend mustsendpacket arraylist messageitem arraylist messageitem messagequeue mustsend messagequeue mustsendnow mustsend mustsend messagequeue mustsendsize minsize maxsize mustsend mustsend minsize gotenough messagequeue addurgentmessages minsize maxsize gotenough gotenough messagequeue addnonurgentmessages minsize maxsize isempty createfnpvoid addtolocalnodesentmessagestostatistic messageitem isempty processoutgoingorrequeue getoutgoingmangler processoutgoingorrequeue toarray messageitem mustsendpacket sendanyurgentnotifications sendanyurgentnotifications mustsend sendanyurgentnotifications mustsend return the id of a reusable packet tracker if there is one otherwise 1 public long get reusable trackerid session key cur synchronized this cur current tracker if cur null if logminor logger minor this get reusable trackerid cur null on this return 1 if cur packets is deprecated if logminor logger minor this get reusable trackerid cur packets is deprecated on this return 1 if logminor logger minor this get reusable trackerid cur packets trackerid on this return cur packets trackerid packettracker getreusabletrackerid sessionkey currenttracker getreusabletrackerid isdeprecated getreusabletrackerid isdeprecated getreusabletrackerid public boolean register turtle transfer request sender sender key key sender key synchronized turtling transfers if turtling transfers size max turtles per peer logger error this too many turtles for peer return false if turtling transfers contains key key logger error this already fetching key from peer return false turtling transfers put key sender logger normal this turtles for get peer turtling transfers size return true registerturtletransfer requestsender turtlingtransfers turtlingtransfers max_turtles_per_peer turtlingtransfers containskey turtlingtransfers getpeer turtlingtransfers public void unregister turtle transfer request sender sender key key sender key synchronized turtling transfers if turtling transfers contains key key logger error this removing turtle transfer sender for key from this does not exist return request sender old sender turtling transfers remove key if old sender sender logger error this removing turtle transfer sender for key from this wrong sender old sender turtling transfers put key old sender return unregisterturtletransfer requestsender turtlingtransfers turtlingtransfers containskey requestsender oldsender turtlingtransfers oldsender oldsender turtlingtransfers oldsender public boolean is turtling key key synchronized turtling transfers return turtling transfers contains key key isturtling turtlingtransfers turtlingtransfers containskey public mutex sync lock false synclock public synchronized void lock while sync lock true try wait catch exception e debug warning e sync lock true synclock synclock public synchronized void unlock sync lock false notify all synclock notifyall public message inserter node my node high level simple client my client string my name identity manager my identity manager message manager my message manager super my node my client my name m identity manager my identity manager m message manager my message manager messageinserter mynode highlevelsimpleclient myclient myname identitymanager myidentitymanager messagemanager mymessagemanager mynode myclient myname midentitymanager myidentitymanager mmessagemanager mymessagemanager private final int hash code for debugging it is good to have a persistent id override public int hash code return hash code hashcode hashcode hashcode logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public client request freeneturi uri2 string identifier2 int verbosity2 fcp connection handler handler fcp client client short priority class2 short persistence type2 string client token2 boolean global object container container int hash super hash code if hash 0 hash 1 hash code hash this uri uri2 this identifier identifier2 if global this verbosity integer max value else this verbosity verbosity2 this finished false this priority class priority class2 this persistence type persistence type2 this client token client token2 this global global if persistence type persist connection this orig handler handler low level client new request client public boolean persistent return false public void remove from object container container throw new unsupported operation exception this client null else orig handler null if persistence type persist forever container activate client 1 client init container this client client if client null assert client persistence type persistence type low level client client low level client this startup time system current time millis clientrequest fcpconnectionhandler fcpclient priorityclass2 persistencetype2 clienttoken2 objectcontainer hashcode hashcode max_value priorityclass priorityclass2 persistencetype persistencetype2 clienttoken clienttoken2 persistencetype persist_connection orighandler lowlevelclient requestclient removefrom objectcontainer unsupportedoperationexception orighandler persistencetype persist_forever persistencetype persistencetype lowlevelclient lowlevelclient startuptime currenttimemillis public client request freeneturi uri2 string identifier2 int verbosity2 fcp connection handler handler short priority class2 short persistence type2 string client token2 boolean global object container container int hash super hash code if hash 0 hash 1 hash code hash this uri uri2 this identifier identifier2 if global this verbosity integer max value else this verbosity verbosity2 this finished false this priority class priority class2 this persistence type persistence type2 this client token client token2 this global global if persistence type persist connection this orig handler handler client null low level client new request client public boolean persistent return false public void remove from object container container throw new unsupported operation exception else orig handler null if global client persistence type persist forever handler server global forever client handler server global reboot client else client persistence type persist forever handler get forever client container handler get reboot client if persistence type persist forever container activate client 1 client init container low level client client low level client if low level client null throw new null pointer exception no low level client from client client global global persistence persistence type if low level client persistent persistence type persist forever throw new illegal state exception low level client persistent low level client persistent but persistence type persistence type if client null assert client persistence type persistence type this startup time system current time millis clientrequest fcpconnectionhandler priorityclass2 persistencetype2 clienttoken2 objectcontainer hashcode hashcode max_value priorityclass priorityclass2 persistencetype persistencetype2 clienttoken clienttoken2 persistencetype persist_connection orighandler lowlevelclient requestclient removefrom objectcontainer unsupportedoperationexception orighandler persistencetype persist_forever globalforeverclient globalrebootclient persistencetype persist_forever getforeverclient getrebootclient persistencetype persist_forever lowlevelclient lowlevelclient lowlevelclient nullpointerexception lowlevelclient persistencetype lowlevelclient persistencetype persist_forever illegalstateexception lowlevelclient persistencetype persistencetype persistencetype startuptime currenttimemillis public client request simple field set fs fcp client client2 throws malformedurl exception int hash super hash code if hash 0 hash 1 hash code hash priority class short parse short fs get priority class uri new freeneturi fs get uri identifier fs get identifier we don t force the verbosity even if the request is meant to go on the global queue verbosity integer parse int fs get verbosity persistence type client request parse persistence fs get persistence if persistence type client request persist connection throw new illegal argument exception reading persistent get with type connection if persistence type client request persist forever persistence type client request persist reboot throw new illegal argument exception unknown persistence type client request persistence type string persistence type this client client2 this orig handler null client token fs get client token finished fields string to bool fs get finished false global fields string to bool fs get global false final string stime fs get startup time this startup time stime null system current time millis fields parse long stime completion time fs get long completion time 0 if finished started true assert client persistence type persistence type low level client client low level client clientrequest simplefieldset fcpclient malformedurlexception hashcode hashcode priorityclass parseshort priorityclass parseint persistencetype clientrequest parsepersistence persistencetype clientrequest persist_connection illegalargumentexception persistencetype clientrequest persist_forever persistencetype clientrequest persist_reboot illegalargumentexception clientrequest persistencetypestring persistencetype orighandler clienttoken clienttoken stringtobool stringtobool startuptime startuptime currenttimemillis parselong completiontime getlong completiontime persistencetype persistencetype lowlevelclient lowlevelclient lost connection public abstract void on lost connection object container container client context context onlostconnection objectcontainer clientcontext public abstract void on lost connection object container container client context context send any pending messages for a persistent request e g after reconnecting public abstract void send pending messages fcp connection output handler handler boolean include persistent request boolean include data boolean only data object container container onlostconnection objectcontainer clientcontext sendpendingmessages fcpconnectionoutputhandler includepersistentrequest includedata onlydata objectcontainer public static string persistence type string short type switch type case persist connection return connection case persist reboot return reboot case persist forever return forever default return short to string type persistencetypestring persist_connection persist_reboot persist_forever tostring public static short parse persistence string string if string null string equals ignore case connection return persist connection if string equals ignore case reboot return persist reboot if string equals ignore case forever return persist forever return short parse short string parsepersistence equalsignorecase persist_connection equalsignorecase persist_reboot equalsignorecase persist_forever parseshort public static client request read and register buffered reader br fcp server server object container container client context context throws io exception runtime rt runtime get runtime if logminor logger minor client request class rt max memory rt free memory in use before loading request simple field set fs new simple field set br false false can get enormous string client name fs get client name boolean is global fields string to bool fs get global false if client name null is global logger error client request class discarding old request with no client name fs system err println discarding old request with no client name see logs return null fcp client client if is global client server register forever client client name server core null container else client server global forever client if logminor logger minor client request class rt max memory rt free memory in use loading request client name fs get identifier try string type fs get type if type equals get client get cg new client get fs client server cg register container false true cg start container context return cg else if type equals put final client put cp new client put fs client server container client register cp false container db job start new db job public void run object container container client context context cp start container context context job runner remove restart job this native thread high priority container context job runner queue restart job start native thread high priority container false context job runner queue start native thread high priority false return cp else if type equals putdir final client put dir cp new client put dir fs client server container client register cp false container db job start new db job public void run object container container client context context cp start container context context job runner remove restart job this native thread high priority container context job runner queue restart job start native thread high priority container false context job runner queue start native thread high priority false return cp else logger error client request class unrecognized type type return null catch persistence parse exception e logger error client request class failed to parse request e e return null catch throwable t logger error client request class failed to parse t t return null clientrequest readandregister bufferedreader fcpserver objectcontainer clientcontext ioexception getruntime clientrequest maxmemory freememory simplefieldset simplefieldset clientname clientname isglobal stringtobool clientname isglobal clientrequest clientname clientname fcpclient isglobal registerforeverclient clientname globalforeverclient clientrequest maxmemory freememory clientname clientget clientget clientput clientput dbjob dbjob objectcontainer clientcontext jobrunner removerestartjob nativethread high_priority jobrunner queuerestartjob nativethread high_priority jobrunner nativethread high_priority clientputdir clientputdir dbjob dbjob objectcontainer clientcontext jobrunner removerestartjob nativethread high_priority jobrunner queuerestartjob nativethread high_priority jobrunner nativethread high_priority clientrequest persistenceparseexception clientrequest clientrequest abstract void register object container container boolean lazy resume boolean no tags throws identifier collision exception objectcontainer lazyresume notags identifiercollisionexception public void cancel object container container client context context client requester cr get client request it might have been finished on startup if persistence type persist forever container activate cr 1 if logminor logger minor this cancelling cr for this persistence type persistence type if cr null cr cancel container context free data container if persistence type persist forever container store this objectcontainer clientcontext clientrequester getclientrequest persistencetype persist_forever persistencetype persistencetype freedata persistencetype persist_forever public boolean is persistent forever return persistence type client request persist forever ispersistentforever persistencetype clientrequest persist_forever is the request persistent false we can drop the request if we lose the connection public boolean is persistent return persistence type client request persist connection ispersistent persistencetype clientrequest persist_connection public boolean has finished return finished hasfinished get identifier string for request public string get identifier return identifier getidentifier protected abstract client requester get client request clientrequester getclientrequest completed request dropped off the end without being acknowledged public void dropped object container container client context context cancel container context free data container objectcontainer clientcontext freedata return the priority class public short get priority return priority class getpriority priorityclass free cached data bucket s protected abstract void free data object container container freedata objectcontainer request completed but we may have to stick around until we are acked protected void finish object container container completion time system current time millis if persistence type client request persist connection orig handler finished client request this else client finished client request this container if persistence type client request persist forever container store this objectcontainer completiontime currenttimemillis persistencetype clientrequest persist_connection orighandler finishedclientrequest finishedclientrequest persistencetype clientrequest persist_forever get a simple field set representing this request public abstract simple field set get field set throws io exception simplefieldset simplefieldset getfieldset ioexception public abstract simple field set get field set throws io exception public abstract double get success fraction object container container simplefieldset getfieldset ioexception getsuccessfraction objectcontainer public abstract double get success fraction object container container public abstract double get total blocks object container container getsuccessfraction objectcontainer gettotalblocks objectcontainer public abstract double get total blocks object container container public abstract double get min blocks object container container gettotalblocks objectcontainer getminblocks objectcontainer public abstract double get total blocks object container container public abstract double get min blocks object container container public abstract double get fetched blocks object container container gettotalblocks objectcontainer getminblocks objectcontainer getfetchedblocks objectcontainer public abstract double get min blocks object container container public abstract double get fetched blocks object container container public abstract double get failed blocks object container container getminblocks objectcontainer getfetchedblocks objectcontainer getfailedblocks objectcontainer public abstract double get fetched blocks object container container public abstract double get failed blocks object container container public abstract double get fataly failed blocks object container container getfetchedblocks objectcontainer getfailedblocks objectcontainer getfatalyfailedblocks objectcontainer public abstract double get fataly failed blocks object container container public abstract string get failure reason object container container getfatalyfailedblocks objectcontainer getfailurereason objectcontainer public abstract string get failure reason object container container has the total number of blocks to insert been determined yet public abstract boolean is total finalized object container container getfailurereason objectcontainer istotalfinalized objectcontainer public abstract boolean is total finalized object container container public void on major progress object container container ignore istotalfinalized objectcontainer onmajorprogress objectcontainer start the request if it has not already been started public abstract void start object container container client context context objectcontainer clientcontext protected boolean started public boolean is started return started isstarted public abstract boolean has succeeded hassucceeded public abstract boolean has succeeded public abstract boolean can restart hassucceeded canrestart public abstract boolean can restart public abstract boolean restart object container container client context context canrestart objectcontainer clientcontext public abstract boolean restart object container container client context context protected abstract fcp message persistent tag message object container container objectcontainer clientcontext fcpmessage persistenttagmessage objectcontainer called after a modify persistent request sends a persistent request modified message to clients if any value changed commits before sending the messages public void modify request string new client token short new priority class fcp server server object container container boolean client token changed false boolean priority class changed false if new client token null if client token null if new client token equals client token this client token new client token token changed client token changed true else this client token new client token first time the token is set client token changed true if new priority class 0 new priority class priority class this priority class new priority class client requester r get client request container activate r 1 r set priority class priority class server core client context container container deactivate r 1 priority class changed true if client token changed priority class changed return quick return nothing was changed if persistence type persist forever container store this container commit commit before we send the message if logminor logger minor this committed this could become too complex with more parameters but for now its ok final persistent request modified message modified msg if client token changed priority class changed modified msg new persistent request modified message identifier global priority class client token else if priority class changed modified msg new persistent request modified message identifier global priority class else if client token changed modified msg new persistent request modified message identifier global client token else return paranoia we should not be here if nothing was changed client queue client request message modified msg 0 container modifypersistentrequest persistentrequestmodified modifyrequest newclienttoken newpriorityclass fcpserver objectcontainer clienttokenchanged priorityclasschanged newclienttoken clienttoken newclienttoken clienttoken clienttoken newclienttoken clienttokenchanged clienttoken newclienttoken clienttokenchanged newpriorityclass newpriorityclass priorityclass priorityclass newpriorityclass clientrequester getclientrequest setpriorityclass priorityclass clientcontext priorityclasschanged clienttokenchanged priorityclasschanged persistencetype persist_forever persistentrequestmodifiedmessage modifiedmsg clienttokenchanged priorityclasschanged modifiedmsg persistentrequestmodifiedmessage priorityclass clienttoken priorityclasschanged modifiedmsg persistentrequestmodifiedmessage priorityclass clienttokenchanged modifiedmsg persistentrequestmodifiedmessage clienttoken queueclientrequestmessage modifiedmsg utility method for storing details of a possibly encrypted bucket protected void bucket tofs simple field set fs string name boolean include size bucket data serializable to field set bucket bucket serializable to field set bucket data fs put name bucket to field set buckettofs simplefieldset includesize serializabletofieldsetbucket serializabletofieldsetbucket tofieldset public void restart async final fcp server server synchronized this this started false if persistence type persist forever server core client context job runner queue new db job public void run object container container client context context container activate client request this 1 restart container context container deactivate client request this 1 native thread high priority false else server core get executor execute new prio runnable public int get priority return native thread norm priority public void run restart null server core client context restart request restartasync fcpserver persistencetype persist_forever clientcontext jobrunner dbjob objectcontainer clientcontext clientrequest clientrequest nativethread high_priority getexecutor priorunnable getpriority nativethread norm_priority clientcontext public void run object container container client context context container activate client request this 1 restart container context container deactivate client request this 1 objectcontainer clientcontext clientrequest clientrequest server core get executor execute new prio runnable public int get priority return native thread norm priority getexecutor priorunnable getpriority nativethread norm_priority public void run restart null server core client context clientcontext called after a remove persistent request send a persistent request removed to the clients if the request is in the database delete it public void request was removed object container container client context context if persistence type persist forever return if uri null uri remove from container container delete this removepersistentrequest persistentrequestremoved requestwasremoved objectcontainer clientcontext persistencetype persist_forever removefrom protected boolean is global queue if client null return false return client is global queue isglobalqueue isglobalqueue public boolean object can update object container container if hash code 0 logger error this trying to update with hash 0 already deleted new exception error return false return true objectcanupdate objectcontainer hashcode public boolean object can new object container container if persistence type persist forever logger error this not storing non persistent request in database new exception error return false if hash code 0 logger error this trying to write with hash 0 already deleted new exception error return false return true objectcannew objectcontainer persistencetype persist_forever hashcode public void store to object container container container store this storeto objectcontainer public class jsql runtime exception extends runtime exception constructor of exception param target class of the target object in which field was not found param field name name of the locate field public jsql runtime exception string message class target string field name super message this target target this field name field name jsqlruntimeexception runtimeexception fieldname jsqlruntimeexception fieldname fieldname fieldname get class in which lookup was performed public class get target return target gettarget get name of the field public string get field name return field name getfieldname fieldname private byte salt cipher manager byte salt assert salt length 0x10 this salt salt ciphermanager get salt return salt byte get salt return salt getsalt suppress warnings serial private map byte array wrapper byte digest routing key cache new linked hash map byte array wrapper byte override protected boolean remove eldest entry map entry byte array wrapper byte eldest return size 128 suppresswarnings bytearraywrapper digestroutingkeycache linkedhashmap bytearraywrapper removeeldestentry bytearraywrapper get digested routing key param plain key return byte get digested key byte plain key byte array wrapper key new byte array wrapper plain key synchronized digest routing key cache byte dk digest routing key cache get key if dk null return dk message digest digest sha256 get message digest try digest update plain key digest update salt byte hashed routing key digest digest assert hashed routing key length 0x20 synchronized digest routing key cache digest routing key cache put key hashed routing key return hashed routing key finally sha256 return message digest digest plainkey getdigestedkey plainkey bytearraywrapper bytearraywrapper plainkey digestroutingkeycache digestroutingkeycache messagedigest getmessagedigest plainkey hashedroutingkey hashedroutingkey digestroutingkeycache digestroutingkeycache hashedroutingkey hashedroutingkey returnmessagedigest encrypt this entry void encrypt salted hash freenet store entry entry random random if entry is encrypted return entry data encryptiv new byte 16 random next bytes entry data encryptiv pcfb mode cipher make cipher entry data encryptiv entry plain routing key entry header cipher block encipher entry header 0 entry header length entry data cipher block encipher entry data 0 entry data length entry get digested routing key entry is encrypted true saltedhashfreenetstore isencrypted dataencryptiv nextbytes dataencryptiv pcfbmode makecipher dataencryptiv plainroutingkey blockencipher blockencipher getdigestedroutingkey isencrypted verify and decrypt this entry param routing key return code true code if the code route key code match and the entry is decrypted boolean decrypt salted hash freenet store entry entry byte routing key assert entry header null assert entry data null if entry is encrypted already decrypted if arrays equals entry plain routing key routing key return true else return false if entry plain routing key null we knew the key if arrays equals entry plain routing key routing key return false else we do not know the plain key let s check the digest if arrays equals entry digested routing key get digested key routing key return false entry plain routing key routing key pcfb mode cipher make cipher entry data encryptiv entry plain routing key entry header cipher block decipher entry header 0 entry header length entry data cipher block decipher entry data 0 entry data length entry is encrypted false return true routingkey routekey saltedhashfreenetstore routingkey isencrypted plainroutingkey routingkey plainroutingkey plainroutingkey routingkey digestedroutingkey getdigestedkey routingkey plainroutingkey routingkey pcfbmode makecipher dataencryptiv plainroutingkey blockdecipher blockdecipher isencrypted create pcfb mode object for this key pcfb mode make cipher byte iv byte key byte iv2 new byte 0x20 256 bits system arraycopy salt 0 iv2 0 0x10 system arraycopy iv 0 iv2 0x10 0x10 try block cipher aes new rijndael 256 256 aes initialize key return pcfb mode create aes iv2 catch unsupported cipher exception e logger error this rijndael not supported e throw new error rijndael not supported e pcfbmode pcfbmode makecipher blockcipher pcfbmode unsupportedcipherexception protected final list html node children new array list html node public html node string name this name null htmlnode arraylist htmlnode htmlnode public html node string name string content this name string null string null content htmlnode public html node string name string attribute name string attribute value this name attribute name attribute value null htmlnode attributename attributevalue attributename attributevalue public html node string name string attribute name string attribute value string content this name new string attribute name new string attribute value content htmlnode attributename attributevalue attributename attributevalue public html node string name string attribute names string attribute values this name attribute names attribute values null htmlnode attributenames attributevalues attributenames attributevalues protected boolean check name pattern string str return simple name pattern matcher str matches name pattern matcher str matches checknamepattern simplenamepattern namepattern public html node string name string attribute names string attribute values string content if name null equals name equals name check name pattern name throw new illegal argument exception element name is not legal if attribute names null attribute values null if attribute names length attribute values length throw new illegal argument exception attribute names and values differ in length for int attribute index 0 attribute count attribute names length attribute index attribute count attribute index if attribute names attribute index null check name pattern attribute names attribute index throw new illegal argument exception attribute name is not legal add attribute attribute names attribute index attribute values attribute index this name name to lower case locale english if content null equals name equals name add child new html node content this content null else this content content htmlnode attributenames attributevalues checknamepattern illegalargumentexception attributenames attributevalues attributenames attributevalues illegalargumentexception attributeindex attributecount attributenames attributeindex attributecount attributeindex attributenames attributeindex checknamepattern attributenames attributeindex illegalargumentexception attributename addattribute attributenames attributeindex attributevalues attributeindex tolowercase addchild htmlnode return the content public string get content return content getcontent public void add attribute string attribute name string attribute value if attribute name null throw new illegal argument exception cannot add an attribute with a null name if attribute value null throw new illegal argument exception cannot add an attribute with a null value attributes put attribute name attribute value addattribute attributename attributevalue attributename illegalargumentexception attributevalue illegalargumentexception attributename attributevalue public map string string get attributes return collections unmodifiable map attributes getattributes unmodifiablemap public string get attribute string attribute name return attributes get attribute name getattribute attributename attributename public html node add child html node child node if child node null throw new null pointer exception since an efficient algorithm to check the loop presence is not present at least it checks if we are trying to add child the node itself as a child if child node equals this throw new illegal argument exception a html node cannot be child of himself if children contains child node throw new illegal argument exception cannot add twice the same html node as child children add child node return child node htmlnode addchild htmlnode childnode childnode nullpointerexception addchild childnode illegalargumentexception htmlnode childnode illegalargumentexception htmlnode childnode childnode public void add children html node child nodes for int i 0 c child nodes length i c i add child child nodes i addchildren htmlnode childnodes childnodes addchild childnodes public html node add child string node name return add child node name null htmlnode addchild nodename addchild nodename public html node add child string node name string content return add child node name string null string null content htmlnode addchild nodename addchild nodename public html node add child string node name string attribute name string attribute value return add child node name attribute name attribute value null htmlnode addchild nodename attributename attributevalue addchild nodename attributename attributevalue public html node add child string node name string attribute name string attribute value string content return add child node name new string attribute name new string attribute value content htmlnode addchild nodename attributename attributevalue addchild nodename attributename attributevalue public html node add child string node name string attribute names string attribute values return add child node name attribute names attribute values null htmlnode addchild nodename attributenames attributevalues addchild nodename attributenames attributevalues public html node add child string node name string attribute names string attribute values string content return add child new html node node name attribute names attribute values content htmlnode addchild nodename attributenames attributevalues addchild htmlnode nodename attributenames attributevalues returns the name of the first real tag found in the hierarchy below this node return the name of the first real tag or code null code if no real tag could be found public string get first tag if equals name return name for int child index 0 child count children size child index child count child index html node child node children get child index string tag child node get first tag if tag null return tag return null getfirsttag childindex childcount childindex childcount childindex htmlnode childnode childindex childnode getfirsttag public string generate string builder tag buffer new string builder return generate tag buffer to string stringbuilder tagbuffer stringbuilder tagbuffer tostring public string builder generate string builder tag buffer if equals name if content null html encoder encode to buffer content tag buffer return tag buffer for int child index 0 child count children size child index child count child index html node child node children get child index child node generate tag buffer return tag buffer perhaps this should be something else but since i don t know if was not just arbitrary chosen i ll just pick this allows non encoded text to be appended to the tag buffer if equals name tag buffer append content return tag buffer tag buffer append append name set map entry string string attribute set attributes entry set for map entry string string attribute entry attribute set string attribute name attribute entry get key string attribute value attribute entry get value tag buffer append html encoder encode to buffer attribute name tag buffer tag buffer append html encoder encode to buffer attribute value tag buffer tag buffer append if children size 0 if textarea equals name div equals name a equals name tag buffer append tag buffer append name tag buffer append else tag buffer append else tag buffer append if div equals name form equals name input equals name script equals name table equals name tr equals name td equals name tag buffer append n for int child index 0 child count children size child index child count child index html node child node children get child index child node generate tag buffer tag buffer append tag buffer append name tag buffer append if div equals name form equals name input equals name li equals name option equals name script equals name table equals name tr equals name td equals name tag buffer append n return tag buffer stringbuilder stringbuilder tagbuffer htmlencoder encodetobuffer tagbuffer tagbuffer childindex childcount childindex childcount childindex htmlnode childnode childindex childnode tagbuffer tagbuffer tagbuffer tagbuffer tagbuffer attributeset entryset attributeentry attributeset attributename attributeentry getkey attributevalue attributeentry getvalue tagbuffer htmlencoder encodetobuffer attributename tagbuffer tagbuffer htmlencoder encodetobuffer attributevalue tagbuffer tagbuffer tagbuffer tagbuffer tagbuffer tagbuffer tagbuffer tagbuffer childindex childcount childindex childcount childindex htmlnode childnode childindex childnode tagbuffer tagbuffer tagbuffer tagbuffer tagbuffer tagbuffer public html doctype string doctype string system uri super doctype this system uri system uri htmldoctype systemuri systemuri systemuri see freenet support html node generate java lang string builder override public string builder generate string builder tag buffer tag buffer append doctype append name append public append system uri append n todo a meaningful exception should be raised when trying to call the method for a html doctype with number of child 1 return children get 0 generate tag buffer htmlnode stringbuilder stringbuilder stringbuilder tagbuffer tagbuffer systemuri htmldoctype tagbuffer public text mode client interface text mode client interface server server input stream in output stream out this n server n this core server n client core this r server r client core make client request starter interactive priority class true this downloads dir server downloads dir this in in this out out client add global hook new event dumper new print writer out true false textmodeclientinterface textmodeclientinterfaceserver inputstream outputstream clientcore makeclient requeststarter interactive_priority_class downloadsdir downloadsdir addglobalhook eventdumper printwriter public text mode client interface node n high level simple client c file download dir input stream in output stream out this n n this r n random this core n client core this client c this downloads dir download dir this in in this out out client add global hook new event dumper new print writer out true false textmodeclientinterface highlevelsimpleclient downloaddir inputstream outputstream clientcore downloadsdir downloaddir addglobalhook eventdumper printwriter public void run freenet support logger os thread logpid this try real run catch io exception e if logger should log logger minor this logger minor this caught e e catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t osthread realrun ioexception shouldlog outofmemoryerror oomhandler public void real run throws io exception print header out buffered reader reader new buffered reader new input stream reader in while true try out write tmci get bytes out flush if process line reader out reader close return catch socket exception e logger error this socket error e e return catch throwable t logger error this caught t t system out println caught t string writer sw new string writer t print stack trace new print writer sw try out write sw to string get bytes catch io exception e logger error this socket error e e return realrun ioexception printheader bufferedreader bufferedreader inputstreamreader getbytes processline socketexception stringwriter stringwriter printstacktrace printwriter tostring getbytes ioexception private void print header output stream s throws io exception string builder sb new string builder sb append trivial text mode client interface r n sb append r n sb append freenet 0 7 build append version build number append r version cvs revision r n sb append enter one of the following commands r n sb append get freenet key fetch a key r n sb append put r n text until a on a line by itself insert the document and return the key r n sb append put text put a single line of text to a chk and return the key r n sb append getchk r n text until a on a line by itself get the key that would be returned if the document was inserted r n sb append getchk text get the key that would be returned if the line was inserted r n sb append putfile filename mimetype put a file from disk r n sb append getfile filename fetch a key and put it in a file if the key includes a filename we will use it but we will not overwrite local files r n sb append getchkfile filename get the key that would be returned if we inserted the file r n sb append putdir path defaultfile put the entire directory from disk r n sb append getchkdir path defaultfile get the key that would be returned if we d put the entire directory from disk r n sb append makessk create an ssk keypair r n sb append putssk insert uri url to redirect to insert an ssk redirect to a file already inserted r n sb append putsskdir insert uri path defaultfile insert an entire directory to an ssk r n sb append plugload load plugin use plugload for more info r n sb append plugload pkg classname uri to jarfile jar uri to file containing real uri will load from freenets pluginpool load plugin r n sb append pluglist list all loaded plugins r n sb append plugkill pluginid unload the plugin with the given id see pluglist r n sb append publish name create a publish subscribe stream called name r n sb append push name text publish a single line of text to the stream named r n sb append subscribe key subscribe to a publish subscribe stream by key r n sb append connect filename url see addpeer filename url below r n sb append connect r n noderef see addpeer r n noderef below r n sb append disconnect ip port name see removepeer ip port name identity below r n sb append addpeer filename url add a peer from its ref in a file url r n sb append addpeer r n noderef including an end on a line by itself add a peer by entering a noderef directly r n sb append disablepeer ip port name identity disable a peer by providing its ip port name or identity r n sb append enablepeer ip port name identity enable a peer by providing its ip port name or identity r n sb append setpeerlistenonly ip port name identity set listen only on a peer by providing its ip port name or identity r n sb append unsetpeerlistenonly ip port name identity unset listen only on a peer by providing its ip port name or identity r n sb append havepeer ip port name identity report true false on having a peer by providing its ip port name or identity r n sb append removepeer ip port name identity remove a peer by providing its ip port name or identity r n sb append peer ip port name identity report the noderef of a peer without metadata by providing its ip port name or identity r n sb append peerwmd ip port name identity report the noderef of a peer with metadata by providing its ip port name or identity r n sb append peers report tab delimited list of peers with name ip port identity location status and idle time in seconds r n sb append name new node name change the node s name r n sb append update ask the node to self update if possible r n sb append filter r n text until a on a line by itself output the content as it returns from the content filter r n sb append subfile filename append all data received from subscriptions to a file rather than sending it to stdout r n sb append say text send text to the last created pushed stream r n sb append status display some status information on the node including its reference and connections r n sb append memstat display some memory usage related informations r n sb append shutdown exit the program r n sb append announce location announce to the specified location r n if n is using wrapper sb append restart restart the program r n if core null core directtmci this sb append quit close the socket r n if n testnet enabled sb append warning testnet mode enabled you have no anonymity r n s write sb to string get bytes printheader outputstream ioexception stringbuilder stringbuilder buildnumber cvsrevision listenonly listenonly isusingwrapper testnetenabled tostring getbytes process a single command throws io exception if we could not write the data to stdout private boolean process line buffered reader reader final output stream out throws io exception string line string builder outsb new string builder try line reader read line catch io exception e outsb append bye append e append system err println bye e return true boolean getchk only false if line null return true string uline line to upper case if logger should log logger minor this logger minor this command line if uline starts with get should have a key next string key line substring get length trim logger normal this key key freeneturi uri try uri new freeneturi key logger normal this key uri catch malformedurl exception e2 outsb append malformed uri append key append append e2 outsb append r n out write outsb to string get bytes out flush return false try fetch result result client fetch uri client metadata cm result get metadata outsb append content mime type append cm getmime type bucket data result as bucket fixme limit it above if data size 32 1024 system err println data is more than 32k data size outsb append data is more than 32k append data size outsb append r n out write outsb to string get bytes out flush return false byte data bytes bucket tools to byte array data boolean evil false for int i 0 i data bytes length i look for escape codes if data bytes i n continue if data bytes i r continue if data bytes i 32 evil true if evil system err println data may contain escape codes which could cause the terminal to run arbitrary commands save it to a file if you must with getfile outsb append data may contain escape codes which could cause the terminal to run arbitrary commands save it to a file if you must with getfile outsb append r n out write outsb to string get bytes out flush return false outsb append data r n outsb append new string data bytes catch fetch exception e outsb append error append e get message append r n if e get mode fetch exception splitfile error e error codes null outsb append e error codes to verbose string if e newuri null outsb append permanent redirect append e newuri append r n else if uline starts with getfile should have a key next string key line substring getfile length trim logger normal this key key freeneturi uri try uri new freeneturi key catch malformedurl exception e2 outsb append malformed uri append key append append e2 outsb append r n out write outsb to string get bytes out flush return false try long start time system current time millis fetch result result client fetch uri client metadata cm result get metadata outsb append content mime type append cm getmime type bucket data result as bucket now calculate filename string fnam uri get doc name fnam sanitize fnam if fnam length 0 fnam freenet download hex util bytes to hex bucket tools hash data 0 10 string ext defaultmime types get extension cm getmime type if ext null ext equals fnam ext file f new file downloads dir fnam if f exists outsb append file exists already append fnam fnam freenet system current time millis fnam file output stream fos null try fos new file output stream f bucket tools copy to data fos long max value fos close outsb append written to append fnam catch io exception e outsb append could not write file caught append e e print stack trace finally if fos null try fos close catch io exception e1 ignore long end time system current time millis long sz data size double rate 1000 0 sz end time start time outsb append download rate append rate append bytes second catch fetch exception e outsb append error append e get message if e get mode fetch exception splitfile error e error codes null outsb append e error codes to verbose string if e newuri null outsb append permanent redirect append e newuri append r n else if uline starts with update outsb append starting the update process fixme run on separate thread n ps queue timed job new runnable public void run freenet support logger os thread logpid this n get node updater arm 0 outsb append r n out write outsb to string get bytes out flush return false else if uline starts with filter line line substring filter length trim outsb append here is the result r n final string content read lines reader false final bucket data new array bucket content get bytes utf 8 try filter output output content filter filter data new array bucket factory text html new uri http 127 0 0 1 8888 null buffered input stream bis new buffered input stream output data get input stream while bis available 0 outsb append char bis read bis close output data free catch io exception e outsb append bucket error e get message logger error this bucket error e e catch uri syntax exception e outsb append internal error e get message logger error this internal error e e finally data free outsb append r n else if uline starts with blow n get node updater blow caught an io exception incompetent operator p outsb append r n out write outsb to string get bytes out flush return false else if uline starts with shutdown string builder sb new string builder sb append shutting node down r n out write sb to string get bytes out flush n exit shutdown from console else if uline starts with restart string builder sb new string builder sb append restarting the node r n out write sb to string get bytes out flush n get node starter restart else if uline starts with quit core directtmci this string builder sb new string builder sb append quit command not available in console mode r n out write sb to string get bytes out flush return false else if uline starts with quit string builder sb new string builder sb append closing connection r n out write sb to string get bytes out flush return true else if uline starts with memstat runtime rt runtime get runtime float free memory rt free memory float total memory rt total memory float max memory rt max memory long used java mem long total memory free memory long allocated java mem long total memory long max java mem long max memory int available cpus rt available processors number format thousend point number format get instance thread group tg thread current thread get thread group while tg get parent null tg tg get parent int thread count tg active count string builder sb new string builder sb append used java memory u00a0 size util format size used java mem true r n sb append allocated java memory u00a0 size util format size allocated java mem true r n sb append maximum java memory u00a0 size util format size max java mem true r n sb append running threads u00a0 thousend point format thread count r n sb append available cp us u00a0 available cpus r n sb append java version u00a0 system get property java version r n sb append jvm vendor u00a0 system get property java vendor r n sb append jvm version u00a0 system get property java version r n sb append os name u00a0 system get property os name r n sb append os version u00a0 system get property os version r n sb append os architecture u00a0 system get property os arch r n out write sb to string get bytes out flush ioexception processline bufferedreader outputstream ioexception stringbuilder stringbuilder readline ioexception getchkonly touppercase shouldlog startswith malformedurlexception tostring getbytes fetchresult clientmetadata getmetadata getmimetype asbucket tostring getbytes databytes buckettools tobytearray databytes databytes databytes databytes tostring getbytes databytes fetchexception getmessage getmode fetchexception splitfile_error errorcodes errorcodes toverbosestring startswith malformedurlexception tostring getbytes starttime currenttimemillis fetchresult clientmetadata getmetadata getmimetype asbucket getdocname hexutil bytestohex buckettools defaultmimetypes getextension getmimetype downloadsdir currenttimemillis fileoutputstream fileoutputstream buckettools copyto max_value ioexception printstacktrace ioexception endtime currenttimemillis endtime starttime fetchexception getmessage getmode fetchexception splitfile_error errorcodes errorcodes toverbosestring startswith queuetimedjob osthread getnodeupdater tostring getbytes startswith readlines arraybucket getbytes filteroutput contentfilter arraybucketfactory bufferedinputstream bufferedinputstream getinputstream ioexception getmessage urisyntaxexception getmessage startswith getnodeupdater ioexception tostring getbytes startswith stringbuilder stringbuilder tostring getbytes startswith stringbuilder stringbuilder tostring getbytes getnodestarter startswith stringbuilder stringbuilder tostring getbytes startswith stringbuilder stringbuilder tostring getbytes startswith getruntime freememory freememory totalmemory totalmemory maxmemory maxmemory usedjavamem totalmemory freememory allocatedjavamem totalmemory maxjavamem maxmemory availablecpus availableprocessors numberformat thousendpoint numberformat getinstance threadgroup currentthread getthreadgroup getparent getparent threadcount activecount stringbuilder stringbuilder sizeutil formatsize usedjavamem sizeutil formatsize allocatedjavamem sizeutil formatsize maxjavamem thousendpoint threadcount cpus availablecpus getproperty getproperty getproperty getproperty getproperty getproperty tostring getbytes fixme run on separate thread n ps queue timed job new runnable public void run freenet support logger os thread logpid this n get node updater arm queuetimedjob osthread getnodeupdater probe callback cb new probe callback public void on completed string reason double target double best double nearest long id short counter short unique counter short linear counter string msg completed probe request target best r n nearest actually hit nearest counter nodes unique counter unique linear counter hops id id r n try out write msg get bytes out flush catch io exception e already closed synchronized text mode client interface this done something true text mode client interface this notify all probecallback probecallback oncompleted uniquecounter linearcounter nnearest uniquecounter linearcounter getbytes ioexception textmodeclientinterface donesomething textmodeclientinterface notifyall public void on trace long uid double target double nearest double best short htl short counter double location long nodeuid double peer locs long peerui ds double locs not visited short fork count short linear counter string reason long prevuid string msg probe trace uid uid target target nearest nearest best best htl htl counter counter linear linear counter location location node uid nodeuid prev uid prevuid peer locs arrays to string peer locs peer ui ds arrays to string peerui ds locs not visited arrays to string locs not visited forks fork count reason reason n try out write msg get bytes out flush catch io exception e ignore ontrace peerlocs peeruids locsnotvisited forkcount linearcounter linearcounter tostring peerlocs uids tostring peeruids tostring locsnotvisited forkcount getbytes ioexception public void on reject overload string msg probe trace received reject overload n try out write msg get bytes out flush catch io exception e ignore onrejectoverload rejectoverload getbytes ioexception om announce target new announcement callback private void write string msg try out write announce target msg r n get bytes out flush catch io exception e ignore announcementcallback getbytes ioexception public void added node peer node pn write added node pn short to string addednode peernode shorttostring public void bogus noderef string reason write bogus noderef reason bogusnoderef public void completed write completed announcement public void node failed peer node pn string reason write node failed pn reason nodefailed peernode public void no more nodes write route not found nomorenodes public void node not wanted write hop doesn t want me nodenotwanted write hop doesn t want me public void node not added write node not added as we don t want it for some reason nodenotadded private void probe all global probe p new global probe n n executor execute p global probe probeall globalprobe globalprobe globalprobe create a map of string bucket for every file in a directory and its subdirs private hash map string object make buckets by name string directory if directory ends with directory directory file thisdir new file directory system out println listing dir thisdir hash map string object ret new hash map string object file filelist thisdir list files if filelist null throw new illegal argument exception no such directory for int i 0 i filelist length i skip unreadable files and dirs skip files nonexistant dangling symlinks check last if filelist i can read filelist i exists if filelist i is file file f filelist i file bucket bucket new file bucket f true false false false false ret put f get name bucket else if filelist i is directory hash map string object subdir make buckets by name directory filelist i get name ret put filelist i get name subdir return ret hashmap makebucketsbyname endswith hashmap hashmap listfiles illegalargumentexception canread isfile filebucket filebucket getname isdirectory hashmap makebucketsbyname getname getname return a block of text input from stdin ending with a on a line by itself does some mangling for a fieldset if is field set private string read lines buffered reader reader boolean is field set string builder sb new string builder 1000 boolean breakflag false while true string line try line reader read line if line null throw new eof exception catch io exception e1 system err println bye e1 return null if is field set line equals break if is field set mangling first trim line line trim if line equals end breakflag true else if line ends with end character is whitespace line char at line length end length 1 line end breakflag true else int idx line index of if idx 0 system err println no and no end in line line return else if idx 0 string after if idx line length 1 after else after line substring idx 1 string before line substring 0 idx before before trim int x 0 for int j before length 1 j 0 j char c before char at j if c character is letter or digit c valid character for field else x j 1 break before before substring x line before after system out println line else system err println invalid empty field name breakflag true sb append line append r n if breakflag break return sb to string isfieldset readlines bufferedreader isfieldset stringbuilder stringbuilder readline eofexception ioexception isfieldset isfieldset endswith iswhitespace charat indexof charat isletterordigit tostring add a peer to the node given its reference private void add peer string content simple field set fs system out println connecting to r n content try fs new simple field set content false true catch io exception e system err println did not parse e e print stack trace return peer node pn try pn n create new darknet node fs catch fs parse exception e1 system err println did not parse e1 logger error this did not parse e1 e1 return catch peer parse exception e1 system err println did not parse e1 logger error this did not parse e1 e1 return catch reference signature verification exception e1 system err println did not parse e1 logger error this did not parse e1 e1 return if n peers add peer pn system out println added peer pn n peers write peers addpeer simplefieldset simplefieldset ioexception printstacktrace peernode createnewdarknetnode fsparseexception peerparseexception referencesignatureverificationexception addpeer writepeers disable connecting to a peer given its ip and port name or identity as a string report peer success as boolean private boolean disable peer string node identifier darknet peer node pn n peers get darknet peers for int i 0 i pn length i peer peer pn i get peer string node ip and port if peer null node ip and port peer to string string name pn i my name string identity pn i get identity string if identity equals node identifier node ip and port equals node identifier name equals node identifier pn i disable peer return true return false disablepeer nodeidentifier darknetpeernode getdarknetpeers getpeer nodeipandport nodeipandport tostring myname getidentitystring nodeidentifier nodeipandport nodeidentifier nodeidentifier disablepeer enable connecting to a peer given its ip and port name or identity as a string report peer success as boolean private boolean enable peer string node identifier darknet peer node pn n peers get darknet peers for int i 0 i pn length i peer peer pn i get peer string node ip and port if peer null node ip and port peer to string string name pn i my name string identity pn i get identity string if identity equals node identifier node ip and port equals node identifier name equals node identifier pn i enable peer return true return false enablepeer nodeidentifier darknetpeernode getdarknetpeers getpeer nodeipandport nodeipandport tostring myname getidentitystring nodeidentifier nodeipandport nodeidentifier nodeidentifier enablepeer check for a peer of the node given its ip and port name or identity as a string report peer existence as boolean private boolean have peer string node identifier darknet peer node pn n peers get darknet peers for int i 0 i pn length i peer peer pn i get peer string node ip and port if peer null node ip and port peer to string string name pn i my name string identity pn i get identity string if identity equals node identifier node ip and port equals node identifier name equals node identifier return true return false havepeer nodeidentifier darknetpeernode getdarknetpeers getpeer nodeipandport nodeipandport tostring myname getidentitystring nodeidentifier nodeipandport nodeidentifier nodeidentifier remove a peer from the node given its ip and port name or identity as a string report peer removal successfulness as boolean private boolean remove peer string node identifier system out println removing peer from node for node identifier darknet peer node pn n peers get darknet peers for int i 0 i pn length i peer peer pn i get peer string node ip and port if peer null node ip and port peer to string string name pn i my name string identity pn i get identity string if identity equals node identifier node ip and port equals node identifier name equals node identifier n remove peer connection pn i return true system out println no node in peers list for node identifier return false removepeer nodeidentifier nodeidentifier darknetpeernode getdarknetpeers getpeer nodeipandport nodeipandport tostring myname getidentitystring nodeidentifier nodeipandport nodeidentifier nodeidentifier removepeerconnection nodeidentifier private string sanitize string fnam if fnam null return string builder sb new string builder fnam length for int i 0 i fnam length i char c fnam char at i if character is letter or digit c c c sb append c return sb to string stringbuilder stringbuilder charat isletterordigit tostring networkid manager final node node this node node this max htl node maxhtl this logminor logger should log logger minor this if disable secret pinger node get ticker queue timed job new runnable public void run check all peers startup checks node peers quick count connected peers min pings for startup logger normal networkid manager this past startup delay startup checks connected peers reschedule 0 startup delay networkidmanager max_htl shouldlog disablesecretpinger getticker queuetimedjob checkallpeers startupchecks quickcountconnectedpeers min_pings_for_startup networkidmanager startupchecks startup_delay node get ticker queue timed job new runnable public void run check all peers startup checks node peers quick count connected peers min pings for startup logger normal networkid manager this past startup delay startup checks connected peers reschedule 0 getticker queuetimedjob checkallpeers startupchecks quickcountconnectedpeers min_pings_for_startup networkidmanager startupchecks stores the secret uid contained in the message associated with the peer it comes from fnp store secret messages are never forwarded they are only between peers as an alert that they may be asked for the secret from a third party public boolean handle store secret message m if disable secret pings return true peer node pn peer node m get source long uid m get long dmt uid long secret m get long dmt secret stored secret s new stored secret pn uid secret if logminor logger minor this storing secret s add or replace secret s fixme what if the message contain a bogus uid try pn send async dmt createfnp accepted uid null ctr catch not connected exception e logger error this peer disconnected before store secret ack e return true fnpstoresecret handlestoresecret disablesecretpings peernode peernode getsource getlong getlong storedsecret storedsecret addorreplacesecret sendasync createfnpaccepted notconnectedexception storesecret public boolean handle secret ping final message m if disable secret pings return true final peer node source peer node m get source final long uid m get long dmt uid final short htl m get short dmt htl final short dawn htl m get short dmt dawn htl final int counter m get int dmt counter node executor execute new runnable public void run try handlesecretping m source uid htl dawn htl counter catch not connected exception e logger normal this secret ping not connected e secret ping handler for uid uid on node get darknet port number return true handlesecretping disablesecretpings peernode peernode getsource getlong getshort dawnhtl getshort dawn_htl getint _handlesecretping dawnhtl notconnectedexception secretping secretpinghandler getdarknetportnumber node executor execute new runnable public void run try handlesecretping m source uid htl dawn htl counter catch not connected exception e logger normal this secret ping not connected e _handlesecretping dawnhtl notconnectedexception secretping private boolean handlesecretping message m peer node source long uid short htl short dawn htl int counter throws not connected exception if disable secret pings node recently completed uid if logminor logger minor this recently complete loop uid source send async dmt createfnp rejected loop uid null ctr else byte node identity short buffer m get object dmt node identity get data stored secret match yes i know it looks really weird sync ing on a separate map synchronized secrets by peer match secrets byuid get uid if match null this is the node that the ping intends to reach we will not forward it but we might not respond positively either don t set the completed flag we might reject it from one peer too short a path and accept it from another if htl dawn htl source send async dmt createfnp rejected loop uid null ctr else if logminor logger minor this responding to source with match from match peer source send async match get secret pong counter 1 null ctr else set the completed flag immediately for determining reject loops rather than locking the uid node completed uid not a local match forward double target m get double dmt target location hash set peer node routed to new hash set peer node while true peer node next if htl dawn htl routed to is empty next node peers get random peer source else next node peers closer peer source routed to target true node is advanced mode enabled 1 null null if next null would be rnf but this is a more exhaustive and lightweight search i suppose source send async dmt createfnp rejected loop uid null ctr break htl next decrementhtl htl if htl 0 would be dnf if we were looking for data source send async dmt createfnp rejected loop uid null ctr break if source is connected throw new not connected exception source gone away while forwarding counter routed to add next try next send async dmt createfnp secret ping uid target htl dawn htl counter node identity null ctr catch not connected exception e logger normal this next disconnected before secret ping forward continue wait for a reject or pong message filter mf pong message filter create set source next set field dmt uid uid set timeout secretpong timeout set type dmt fnp secret pong message filter mf reject loop message filter create set source next set field dmt uid uid set timeout secretpong timeout set type dmt fnp rejected loop message msg try msg node usm wait for mf pong or mf reject loop null catch disconnected exception e logger normal this next disconnected while waiting for a secret pong continue if msg null logger error this fatal timeout in waiting for secretpong from next backoff break if msg get spec dmt fnp secret pong int supplied counter msg get int dmt counter if supplied counter counter counter supplied counter long secret msg get long dmt secret if logminor logger minor this node forwarding apparently successful secretpong response counter secret from next to source source send async dmt createfnp secret pong uid counter secret null ctr break if msg get spec dmt fnp rejected loop if logminor logger minor this secret ping reject loop source next continue logger error this unexpected message type msg break unlockuid return true _handlesecretping peernode dawnhtl notconnectedexception disablesecretpings recentlycompleted sendasync createfnprejectedloop nodeidentity shortbuffer getobject node_identity getdata storedsecret secretsbypeer secretsbyuid dawnhtl sendasync createfnprejectedloop sendasync getsecretpong getdouble target_location hashset peernode routedto hashset peernode peernode dawnhtl routedto isempty getrandompeer closerpeer routedto isadvancedmodeenabled sendasync createfnprejectedloop sendasync createfnprejectedloop isconnected notconnectedexception routedto sendasync createfnpsecretping dawnhtl nodeidentity notconnectedexception messagefilter mfpong messagefilter setsource setfield settimeout secretpong_timeout settype fnpsecretpong messagefilter mfrejectloop messagefilter setsource setfield settimeout secretpong_timeout settype fnprejectedloop waitfor mfpong mfrejectloop disconnectedexception getspec fnpsecretpong suppliedcounter getint suppliedcounter suppliedcounter getlong sendasync createfnpsecretpong getspec fnprejectedloop fixme this needs to be wired in public void on disconnect peer node pn synchronized secrets by peer stored secret s secrets by peer get pn if s null might it still be valid to respond to secret pings when the neighbor requesting it has disconnected super secret ping logger normal this removing on disconnect s remove secret s ondisconnect peernode secretsbypeer storedsecret secretsbypeer removesecret private void add or replace secret stored secret s synchronized secrets by peer stored secret prev secrets by peer get s peer if prev null if logminor logger minor this removing on replacement s remove secret prev need to remember by peer so we can remove it on disconnect need to remember by uid so we can respond quickly to arbitrary requests secrets by peer put s peer s secrets byuid put s uid s addorreplacesecret storedsecret secretsbypeer storedsecret secretsbypeer removesecret secretsbypeer secretsbyuid private void remove secret stored secret s synchronized secrets by peer in calling functions secrets by peer remove s peer secrets byuid remove s uid removesecret storedsecret secretsbypeer secretsbypeer secretsbyuid long secret stored secret peer node peer long uid long secret this peer peer this uid uid this secret secret storedsecret peernode this secret secret override public string to string return secret uid secret tostring return secret uid secret message get secret pong int counter return dmt createfnp secret pong uid counter secret getsecretpong createfnpsecretpong running average s dawn new bootstrapping decaying running average 0 0 0 0 max htl 200 null running average f dawn new bootstrapping decaying running average 0 0 0 0 max htl 200 null override public string to string return percent average current value runningaverage sdawn bootstrappingdecayingrunningaverage max_htl runningaverage fdawn bootstrappingdecayingrunningaverage max_htl tostring currentvalue public void success int counter short htl short dawn long now system current time millis last try now last success now average report 1 0 if counter shortest success shortest success counter dawn short htl dawn s htl report htl s dawn report dawn currenttimemillis lasttry lastsuccess shortestsuccess shortestsuccess shtl sdawn public void failure int counter short htl short dawn long now system current time millis last try now average report 0 0 dawn short htl dawn f htl report htl f dawn report dawn currenttimemillis lasttry fhtl fdawn written to start high and slowly restrict the htl at 80 public short get next htl if s htl count reports comfort level return max htl else if average current value 0 8 looking good try lower htl short htl short s htl current value 0 5 if htl min htl htl min htl return htl else not so good try higher htl short htl short s htl current value 0 5 if htl max htl htl max htl return htl getnexthtl shtl countreports comfort_level max_htl currentvalue shtl currentvalue min_htl min_htl shtl currentvalue max_htl max_htl written to start with 2 random hops and slowly expand if too many failures will not use more than 1 2 the hops for good connections should always be 2 public short get next dawn htl short htl the number of random hops htl dawn short diff short max short htl 2 1 if f dawn count reports comfort level diff 2 else if s dawn count reports comfort level we ve had enough failures not successes diff short f dawn current value 0 5 else just a different algorithim than get next htl so that they both might stabilize diff short 0 25 f dawn current value 0 75 s dawn current value if diff max diff max return short htl diff getnextdawnhtl fdawn countreports comfort_level sdawn countreports comfort_level fdawn currentvalue getnexthtl fdawn currentvalue sdawn currentvalue override public boolean equals object obj if this obj return true if obj null return false if get class obj get class return false else if via equals ping record obj via return false return true getclass getclass pingrecord return true override public int hash code return via hash code hashcode hashcode private ping record get ping record peer node target peer node via ping record retval synchronized record maps by peer hash map peer node ping record peer records record maps by peer get target if peer records null no record of any pings towards target peer records new hash map peer node ping record record maps by peer put target peer records retval peer records get via if retval null no records via this specific peer retval new ping record retval target target retval via via peer records put via retval return retval pingrecord getpingrecord peernode peernode pingrecord recordmapsbypeer hashmap peernode pingrecord peerrecords recordmapsbypeer peerrecords peerrecords hashmap peernode pingrecord recordmapsbypeer peerrecords peerrecords pingrecord peerrecords private void forget ping records peer node p synchronized work queue work queue remove p if p equals processing don t chase the thread making records signal a fault processing race true return synchronized record maps by peer record maps by peer remove p for hash map peer node ping record complement record maps by peer values fixme nb comparing peer nodes with ping records complement values remove p forgetpingrecords peernode workqueue workqueue processingrace recordmapsbypeer recordmapsbypeer hashmap peernode pingrecord recordmapsbypeer peernodes pingrecords private int ping volleys to go ping volleys per network recompute private void reschedule long period node get ticker queue timed job this period pingvolleystogo ping_volleys_per_network_recompute getticker queuetimedjob public void run pick a target synchronized work queue if processing null logger error this possibly bad programming error only one thread should use secretpings return if work queue is empty processing work queue remove 0 if processing null peer node target processing double random target node random next double hash set peer node nodes routed to new hash set peer node peer node next node peers closer peer target nodes routed to random target true false 1 null null while next null target is routable processing race nodes routed to add next the order is not that important but for all connected peers try to ping target blocking update ping record target next since we are causing traffic to target between ping sleep target next node peers closer peer target nodes routed to random target true false 1 null null boolean did anything synchronized work queue did anything processing null how sad all that work may be garbage if processing race processing race false processing must not be null now but must be null when we call the forget function peer node target processing processing null forget ping records target processing null ping volleys to go if startup checks 0 startup checks else if ping volleys to go 0 do networkid reckoning did anything ping volleys to go ping volleys per network recompute synchronized work queue if work queue is empty check all peers if startup checks 0 reschedule between peers else reschedule long period else reschedule between peers workqueue workqueue isempty workqueue peernode randomtarget nextdouble hashset peernode nodesroutedto hashset peernode peernode closerpeer nodesroutedto randomtarget isroutable processingrace nodesroutedto blockingupdatepingrecord betweenpingsleep closerpeer nodesroutedto randomtarget didanything workqueue didanything processingrace processingrace peernode forgetpingrecords pingvolleystogo startupchecks startupchecks pingvolleystogo donetworkidreckoning didanything pingvolleystogo ping_volleys_per_network_recompute workqueue workqueue isempty checkallpeers startupchecks between_peers long_period between_peers best effort ping from next to target if anything out of the ordinary happens it counts as a failure private void blocking update ping record peer node target peer node next make a secret uid long uid node random next long long secret node random next long ping record record get ping record target next short htl record get next htl short dawn record get next dawn htl htl boolean success false int supplied counter 1 total secret ping attempts try store secret in target target send sync dmt createfnp store secret uid secret null wait for an accepted or give up message filter mf accepted message filter create set source target set field dmt uid uid set timeout accepted timeout set type dmt fnp accepted message msg node usm wait for mf accepted null if msg null msg get spec dmt fnp accepted backoff logger error this peer is unresponsive to store secret target return next send a secretping through next to target next send sync dmt createfnp secret ping uid target get location htl dawn 0 target identity null wait for a response secret pong reject loop or timeout message filter mf pong message filter create set source next set field dmt uid uid set timeout secretpong timeout set type dmt fnp secret pong message filter mf reject loop message filter create set source next set field dmt uid uid set timeout secretpong timeout set type dmt fnp rejected loop msg node usm wait for mf pong or mf reject loop null if msg null logger error this fatal timeout in waiting for secretpong from next else if msg get spec dmt fnp secret pong supplied counter msg get int dmt counter long supplied secret msg get long dmt secret if logminor logger minor this got secret counter supplied counter success secret supplied secret else if msg get spec dmt fnp rejected loop logger normal this top level reject loop no route found next target catch not connected exception e logger normal this one party left during connectivity test e catch disconnected exception e logger normal this one party left during connectivity test e finally if success secret ping successes record success supplied counter htl dawn else record failure supplied counter htl dawn blockingupdatepingrecord peernode peernode nextlong nextlong pingrecord getpingrecord getnexthtl getnextdawnhtl suppliedcounter totalsecretpingattempts sendsync createfnpstoresecret messagefilter mfaccepted messagefilter setsource setfield settimeout accepted_timeout settype fnpaccepted waitfor mfaccepted getspec fnpaccepted storesecret sendsync createfnpsecretping getlocation secretpong rejectloop messagefilter mfpong messagefilter setsource setfield settimeout secretpong_timeout settype fnpsecretpong messagefilter mfrejectloop messagefilter setsource setfield settimeout secretpong_timeout settype fnprejectedloop waitfor mfpong mfrejectloop getspec fnpsecretpong suppliedcounter getint suppliedsecret getlong suppliedcounter suppliedsecret getspec fnprejectedloop rejectloop notconnectedexception disconnectedexception secretpingsuccesses suppliedcounter suppliedcounter private void between ping sleep peer node target we are currently sending secret pings to target sleep for a while to be nice could increase for cause of target s backoff try thread sleep 200 catch interrupted exception e ignore betweenpingsleep peernode interruptedexception private void add work to locked queue peer node p if p null work queue contains p work queue add p addworktolockedqueue peernode workqueue workqueue public void check all peers set peer node set get all connected peers synchronized work queue for peer node p set add work to locked queue p checkallpeers peernode getallconnectedpeers workqueue peernode addworktolockedqueue private hash set peer node get all connected peers double random target node random next double hash set peer node connected peers new hash set peer node peer node next node peers closer peer null connected peers random target true false 1 null null while next null connected peers add next next node peers closer peer null connected peers random target true false 1 null null return connected peers hashset peernode getallconnectedpeers randomtarget nextdouble hashset peernode connectedpeers hashset peernode peernode closerpeer connectedpeers randomtarget connectedpeers closerpeer connectedpeers randomtarget connectedpeers takes all the stored ping records combines it with the network id s advertised by our peers and then does the monstrous task of doing something useful with that data at the end of this function we must assign and broadcast a network id to each of our peers or at least the ones we have ping records for this time around even if it is just totally madeup identifiers private void do networkid reckoning boolean any ping changes this is where the magic separation logic begins this may still need a lot of work e g a locking mechanism considering disconnected peers list peer network group new network groups new array list peer network group hash set peer node all get all connected peers suppress warnings unchecked hash set peer node todo hash set peer node all clone synchronized transition lock in transition true if logminor logger minor this do networkid reckoning for all size peers if todo is empty return optimization if no stats have changed just rescan the list consensus note that in all this set manipulation we never consult in what group a user previously was while todo is empty peer node most connected find most connected peer in set todo all peer network group new group new peer network group new network groups add new group todo remove most connected list peer node members if todo is empty sad it looks like this guy gets a group to himself members new array list peer node members add most connected else nb as a side effect this function will automatically remove the members from todo members xfer connected peer set for most connected todo new group set members members the groups are broken up now sort by priority assign them a network id collections sort new network groups this hash set integer taken network ids new hash set integer for peer network group new group new network groups new group set forbidden ids taken network ids int id new group get consensus true if id no networkid id node random next int new group assign network id id taken network ids add id if logminor logger minor this net id has new group members size peers synchronized transition lock peer network group ourgroup new network groups get 0 our network id ourgroup networkid logger error this i am in network our network id and have divided my all size peers into new network groups size network groups logger error this largest group ourgroup members size logger error this best first cheat stats general bestother current value logger error this best general factor cheat stats findbestsetwisepingaverage best general current value network groups new network groups in transition false pingrecords donetworkidreckoning anypingchanges peernetworkgroup newnetworkgroups arraylist peernetworkgroup hashset peernode getallconnectedpeers suppresswarnings hashset peernode hashset peernode transitionlock intransition donetworkidreckoning isempty isempty peernode mostconnected findmostconnectedpeerinset peernetworkgroup newgroup peernetworkgroup newnetworkgroups newgroup mostconnected peernode isempty arraylist peernode mostconnected xferconnectedpeersetfor mostconnected newgroup setmembers newnetworkgroups hashset takennetworkids hashset peernetworkgroup newgroup newnetworkgroups newgroup setforbiddenids takennetworkids newgroup getconsensus no_networkid nextint newgroup assignnetworkid takennetworkids newgroup transitionlock peernetworkgroup newnetworkgroups ournetworkid ournetworkid newnetworkgroups largestgroup bestfirst cheat_stats_general_bestother currentvalue bestgeneralfactor cheat_stats_findbestsetwisepingaverage_best_general currentvalue networkgroups newnetworkgroups intransition returns the best connected peer in the given set or null if the set is empty private peer node find most connected peer in set hash set peer node set hash set peer node possible targets double max 1 0 peer node the man null for peer node p set double value get peer node connectedness p possible targets if value max max value the man p return the man peernode findmostconnectedpeerinset hashset peernode hashset peernode possibletargets peernode theman peernode getpeernodeconnectedness possibletargets theman theman return a double between 0 0 1 0 somehow indicating how wellconnected this peer is to all the peers in possible targets private double get peer node connectedness peer node p hash set peer node possible targets double retval 1 0 double total loss factor 1 0 possible targets size for peer node target possible targets ping record record get ping record p target double ping average record average current value if ping average total loss factor retval total loss factor else retval ping average return retval possibletargets getpeernodeconnectedness peernode hashset peernode possibletargets totallossfactor possibletargets peernode possibletargets pingrecord getpingrecord pingaverage currentvalue pingaverage totallossfactor totallossfactor pingaverage private list peer node xfer connected peer set for peer node this peer hash set peer node from others fixme this algorithm needs to be thought about maybe some hard thresholds what recently connected peers who only have one or two pings so far idea right now this peer is in a network group by itself but we know that it is the best connected peer so now we just need to find it s peers in this implementation a peer belongs to this newly forming network group if it is at least as connected to the new forming group as the first peer is connected to the original group why i don t know list peer node current group new array list peer node current group add this peer hash set remainder others clone hash set peer node remainder from others double good connectivity get setwise ping average this peer from others if good connectivity fall open mark logger normal this falling open with from others size peers left current group add all from others from others clear cheat stats general bestother report 0 0 return current group cheat stats general bestother report good connectivity good connectivity magic linear grace while remainder is empty note that because of the size this might be low peer node best other find best setwise ping average remainder current group if cheat findbestsetwisepingaverage best good connectivity remainder remove best other current group add best other else break exception if there is only one left in from others and we have at least a 25 ping average make them be in the same network this probably means our algorithim is too picky spliting up into too many groups if current group size 1 from others size 1 peer node only left from others iterator next double average1 get ping record only left this peer average current value double average2 get ping record this peer only left average current value if 0 5 average1 0 5 average2 0 25 logger normal this combine the dregs this peer from others from others remove only left current group add only left return current group peernode xferconnectedpeersetfor peernode thispeer hashset peernode fromothers thispeer peernode currentgroup arraylist peernode currentgroup thispeer hashset hashset peernode fromothers goodconnectivity getsetwisepingaverage thispeer fromothers goodconnectivity fall_open_mark fromothers currentgroup addall fromothers fromothers cheat_stats_general_bestother currentgroup cheat_stats_general_bestother goodconnectivity goodconnectivity magic_linear_grace isempty peernode bestother findbestsetwisepingaverage currentgroup cheat_findbestsetwisepingaverage_best goodconnectivity bestother currentgroup bestother fromothers currentgroup fromothers peernode onlyleft fromothers getpingrecord onlyleft thispeer currentvalue getpingrecord thispeer onlyleft currentvalue thispeer fromothers fromothers onlyleft currentgroup onlyleft currentgroup private double get setwise ping average peer node this peer collection peer node to these peers iterator peer node i to these peers iterator double accum 0 0 if i has next fixme this skip the first element investigate if is this intentional why yes we have great connectivity to nobody logger error this get setwise ping average to nobody return 1 0 while i has next peer node other i next accum get ping record this peer other average current value return accum to these peers size getsetwisepingaverage peernode thispeer peernode tothesepeers peernode tothesepeers hasnext getsetwisepingaverage hasnext peernode getpingrecord thispeer currentvalue tothesepeers private peer node find best setwise ping average hash set peer node of these collection peer node towards these peer node retval null double best 1 0 iterator peer node i of these iterator if i has next fixme this skip the first element investigate if is this intentional why yes we have great connectivity to nobody logger error this find best setwise ping average to nobody return null while i has next peer node this one i next double average get setwise ping average this one towards these if average best retval this one best average cheat findbestsetwisepingaverage best best cheat stats findbestsetwisepingaverage best general report best return retval peernode findbestsetwisepingaverage hashset peernode ofthese peernode towardsthese peernode peernode ofthese hasnext findbestsetwisepingaverage hasnext peernode thisone getsetwisepingaverage thisone towardsthese thisone cheat_findbestsetwisepingaverage_best cheat_stats_findbestsetwisepingaverage_best_general public void on peer node changed networkid peer node p if the network group we assigned to them is unstable that is we would have made a different assignment based on there preference change the network id for that entire group and readvertise it to the peers this helps the network form a consensus much more quickly by not waiting for the next round of peer secretpinging and network id reckoning note that we must still not clobber priorities so do nothing if in transition do nothing on p get net group disallowed ids contains p get netid do nothing on all assigned net groups contains p get netid there is a minor race condition here that between updates we might improperly favor the first peer to notify us of a new network id but this will be authoritatively clobbered next round synchronized transition lock if in transition return networks are listed in order of priority generally the biggest one should be first the forbidden ids is already set in this way but if we decide that one group needs to use the id of a lesser group we must tell the other group to use a different one i e realign all the previous id s boolean have found it false peer network group mine p network group hash set integer now taken ids new hash set integer for peer network group png network groups if png equals mine have found it true should be the same png set forbidden ids now taken ids int old id png networkid int new id png get consensus true if png our group even if the consensus changes we ll hold onto our group network id label important for stability and future routing return else if old id new id maybe they agree with us maybe not but it doesn t change our view of the group return else if png recently assigned in order to keep us from thrashing e g two peers each see each other as in the same group and keep swapping we are going to ignore this change for now return else png assign network id new id to continue means to realign all the remaining forbidden ids now taken ids add new id else if have found it lower priority group it may need to be reset should we take this opportunity to always re examine the consensus this is a callback so let s not png set forbidden ids now taken ids int old id png networkid int new id old id if now taken ids contains old id new id png get consensus true png assign network id new id now taken ids add new id else higher priority group remember it s id now taken ids add png networkid onpeernodechangednetworkid peernode intransition getnetgroup disallowedids getnetid allassignednetgroups getnetid transitionlock intransition havefoundit peernetworkgroup networkgroup hashset nowtakenids hashset peernetworkgroup networkgroups havefoundit setforbiddenids nowtakenids oldid newid getconsensus ourgroup oldid newid recentlyassigned assignnetworkid newid nowtakenids newid havefoundit setforbiddenids nowtakenids oldid newid oldid nowtakenids oldid newid getconsensus assignnetworkid newid nowtakenids newid nowtakenids int get consensus boolean probabilistic hash map integer integer h new hash map integer integer integer last id networkid synchronized this int total witnesses 0 int max id networkid int max count 0 for peer node p members integer id p provided networkid reject the advertized id which conflicts with our pre determined boundaries which can change if forbidden ids contains id continue if id no networkid continue total witnesses int count 1 integer prev h get id if prev null count prev int value 1 h put id count if count max count max count count max id id int value last id id should we include ourselves in the count probably not as we generally determine our network id on consensus if there is only one option everyone agrees no networkid is stripped out unanimous h size 1 if h size 1 return last id int value if probabilistic return max id to choose a prob network id choose a random number between 0 0 1 0 and pick a network id such that if lined up they occupy as much of the number space 0 0 1 0 as there are peers in the group to that id double increment per witness 1 0 total witnesses double winning target node random next double if logminor logger minor this winning target winning target total witnesses total witnesses inc increment per witness double sum 0 0 for map entry integer integer e h entry set int id e get key int count e get value sum count increment per witness if logminor logger minor this network id count peers sum if sum winning target return id logger error this logic error winning target winning target sum end sum count h size return max id getconsensus hashmap hashmap lastid totalwitnesses maxid maxcount peernode providednetworkid forbiddenids no_networkid totalwitnesses intvalue maxcount maxcount maxid intvalue lastid no_networkid lastid intvalue maxid incrementperwitness totalwitnesses winningtarget nextdouble winningtarget winningtarget totalwitnesses totalwitnesses incrementperwitness entryset getkey getvalue incrementperwitness winningtarget winningtarget winningtarget maxid void assign network id int id synchronized this this last assign system current time millis this networkid id for peer node p members p assigned networkid id p network group this try p sendfnp networkid ctr catch not connected exception e logger normal this disconnected on network reassignment assignnetworkid lastassign currenttimemillis peernode assignednetworkid networkgroup sendfnpnetworkid notconnectedexception void set forbidden ids hash set integer a synchronized this forbidden ids new hash set integer a setforbiddenids hashset forbiddenids hashset void set members list peer node a synchronized this more correct to copy but presently unnecessary members a setmembers peernode boolean recently assigned return system current time millis last assign between peers recentlyassigned currenttimemillis lastassign between_peers returns true if and only if the connectivity between two given nodes have been computed and they have been determined to be in separate keyspace networks fail safe false if either of the two peers have been recently added if this class is not past its initial startup checks etc public boolean in separate networks peer node a peer node b if a null b null a assigned networkid no networkid b assigned networkid no networkid return false synchronized transition lock if in transition return false nb object equal s but they should be the very same object neither should be null return a network group equals b network group startupchecks inseparatenetworks peernode peernode assignednetworkid no_networkid assignednetworkid no_networkid transitionlock intransition networkgroup networkgroup orders peer network groups by size largest first determines the priority order in the master list throws on comparison of non network groups or those without members assigned public int compare peer network group a peer network group b since we want largest first this is backwards of what it would normally be a b return b members size a members size peernetworkgroups peernetworkgroup peernetworkgroup private final byte counter ctr new byte counter public void received bytes int x node node stats network coloring received bytes x bytecounter bytecounter receivedbytes nodestats networkcoloringreceivedbytes public void sent bytes int x node node stats network coloring sent bytes x sentbytes nodestats networkcoloringsentbytes public void sent payload int x ignore sentpayload public started compression message string identifier boolean global compressor type codec this identifier identifier this codec codec this global global startedcompressionmessage compressor_type override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier fs put single codec codec name if global fs put single global true return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle putsingle override public string get name return started compression getname startedcompression override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message started compression goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message startedcompression override public void remove from object container container container delete this removefrom objectcontainer public class point4f extends tuple4f public point4f this 0 0 0 0 public point4f float x this x x 0 this y x 1 this z x 2 this w x 3 public point4f float x float y float z float w this x x this y y this z z this w w public point4f point4f t this x t x this y t y this z t z this w t w public point4f tuple4f t this x t x this y t y this z t z this w t w public float distancel1 point4f p return math abs x p x math abs y p y math abs z p z math abs w p w public float distance squared point4f p float dx x p x float dy y p y float dz z p z float dw w p w return dx dx dy dy dz dz dw dw distancesquared public float distance point4f p float dx x p x float dy y p y float dz z p z float dw w p w return float math sqrt dx dx dy dy dz dz dw dw recently forwarded item item public my callback message message peer node pn recently forwarded item item super message pn location manager this this item item recentlyforwardeditem mycallback peernode recentlyforwardeditem locationmanager override public void disconnected super disconnected remove recently forwarded item item removerecentlyforwardeditem override public void acknowledged item successfully forwarded true successfullyforwarded public location manager random source r node node loc r next double sender new swap request sender this r r this node node recently forwardedi ds new hashtable long recently forwarded item fixme persist to disk average swap time new bootstrapping decaying running average send swap interval 0 integer max value 20 null time loc set system current time millis logminor logger should log logger minor this locationmanager randomsource nextdouble swaprequestsender recentlyforwardedids recentlyforwardeditem averageswaptime bootstrappingdecayingrunningaverage send_swap_interval max_value timelocset currenttimemillis shouldlog return the current location of this node public synchronized double get location return loc getlocation param l public synchronized void set location double l if l 0 0 l 1 0 logger error this setting invalid location l new exception error return this loc l time loc set system current time millis setlocation timelocset currenttimemillis public synchronized void update location change session double new loc double old loc loc double diff location change old loc new loc if logminor logger minor this update location change session old loc old loc new loc new loc moved diff this loc change session diff updatelocationchangesession newloc oldloc oldloc newloc updatelocationchangesession oldloc oldloc newloc newloc locchangesession start a thread to send fnp swap requests every second when we are not locked public void start sender if node enable swapping node get ticker queue timed job sender startup delay fnpswaprequests startsender enableswapping getticker queuetimedjob startup_delay public void run freenet support logger os thread logpid this thread current thread set name swap request sender while true try long start time system current time millis double next random r next double while true int sleep time get send swap interval sleep time next random sleep time math min sleep time integer max value long end time start time sleep time long now system current time millis long diff end time now try if diff 0 thread sleep math min int diff 10000 catch interrupted exception e ignore if system current time millis end time break fixme shut down the swap initiator thread when swapping is disabled and re enable it when swapping comes back up if swapping disabled continue don t send one if we are locked if lock if system current time millis time last successfully swapped 30 1000 try boolean my flag false double my loc get location peer node peers node peers connected peers for int i 0 i peers length i peer node pn peers i if pn is routable synchronized pn double ploc pn get location if math abs ploc my loc double min value don t reset location unless we re sure there is a problem if the node has had its location equal to ours for at least 2 minutes and ours has been likewise long now system current time millis if now pn get loc set time 120 1000 now time loc set 120 1000 my flag true log an error as this is an error it results from either a bug or malicious action if it happens very frequently it indicates either an attack or a serious bug logger error this randomizing location my loc my loc but loc ploc for pn break else logger normal this node pn has identical location to us waiting until this has persisted for 2 minutes if my flag set location node random next double announce loc change true true true node write node file finally unlock false else unlock false else continue send a swap request start swap request catch throwable t logger error this caught t t osthread currentthread setname swaprequestsender starttime currenttimemillis nextrandom nextdouble sleeptime getsendswapinterval sleeptime nextrandom sleeptime sleeptime max_value endtime starttime sleeptime currenttimemillis endtime interruptedexception currenttimemillis endtime swappingdisabled currenttimemillis timelastsuccessfullyswapped myflag myloc getlocation peernode connectedpeers peernode isroutable getlocation myloc min_value currenttimemillis getlocsettime timelocset myflag myloc myflag setlocation nextdouble announcelocchange writenodefile startswaprequest create a new swap request send it from this node out into the wilderness private void start swap request node executor execute new outgoing swap request handler outgoing swap request handler for port node get darknet port number swaprequest startswaprequest outgoingswaprequesthandler getdarknetportnumber should we swap locking call without holding locks return public boolean swapping disabled swapping on opennet nodes even hybrid nodes causes significant and unnecessary location churn simulations show significantly improved performance if all opennet enabled nodes don t participate in swapping fixme investigate the possibility of enabling swapping on hybrid nodes with mostly darknet peers more simulation needed fixme hybrid nodes with all darknet peeers who haven t upgraded to high probably we should have a useralert for this to get the user to do the right thing but we could auto detect it and start swapping however we should not start swapping just because we temporarily have no opennet peers on startup return node is opennet enabled swappingdisabled isopennetenabled public int get send swap interval int interval int average swap time current value if interval min swap time interval min swap time if interval max swap time interval max swap time return interval getsendswapinterval averageswaptime currentvalue min_swap_time min_swap_time max_swap_time max_swap_time incoming swap request handler message msg peer node pn recently forwarded item item this orig message msg this pn pn this item item uid orig message get long dmt uid incomingswaprequesthandler peernode recentlyforwardeditem origmessage origmessage getlong public void run freenet support logger os thread logpid this message digest md sha256 get message digest boolean reached end false try we are already locked by caller because if we can t get lock they need to send a reject firstly is their message valid byte his hash short buffer orig message get object dmt hash get data if his hash length md get digest length logger error this invalid swap request from peer wrong length hash his hash length on uid fixme should we send a reject return looks okay lets get on with it only one id because we are only receiving add forwarded item uid uid pn null create my side long random r next long double my loc get location locationuid pair friend locs andui ds node peers get peer locations andui ds double friend locs extract locs friend locs andui ds long my value long new long 1 1 friend locs length my value long 0 random my value long 1 double double to long bits my loc for int i 0 i friend locs length i my value long i 2 double double to long bits friend locs i byte my value fields longs to bytes my value long byte my hash md digest my value message m dmt createfnp swap reply uid my hash message filter filter message filter create set type dmt fnp swap commit set field dmt uid uid set timeout timeout set source pn node usm send pn m location manager this message commit try commit node usm wait for filter location manager this catch disconnected exception e if logminor logger minor this disconnected from pn while waiting for swap commit return if commit null timed out abort logger error this timed out waiting for swap commit on uid this can happen occasionally due to connection closes if it happens often there may be a serious problem return we have a swap commit byte his buf short buffer commit get object dmt data get data if his buf length 8 0 his buf length 16 logger error this bad content length in swap complete malicious node on uid return first does it verify byte rehash md digest his buf if java util arrays equals rehash his hash logger error this bad hash in swap commit malicious node on uid return now decode it long his buf long fields bytes to longs his buf if his buf long length 2 logger error this bad buffer length no random no location malicious node on uid return long his random his buf long 0 double his loc double long bits to double his buf long 1 if his loc 0 0 his loc 1 0 logger error this bad loc his loc on uid return register known location his loc double his friend locs new double his buf long length 2 for int i 0 i his friend locs length i his friend locs i double long bits to double his buf long i 2 if his friend locs i 0 0 his friend locs i 1 0 logger error this bad friend loc his friend locs i on uid return register location link his loc his friend locs i register known location his friend locs i number of remote peer locations seen in swaps his friend locs length send our swap complete message confirm dmt createfnp swap complete uid my value confirm add sub message dmt createfnp swap locations extractui ds friend locs andui ds node usm send pn confirm location manager this boolean should swap should swap my loc friend locs his loc his friend locs random his random spy on locations commit true should swap my loc if should swap time last successfully swapped system current time millis swap update location change session his loc set location his loc if logminor logger minor this swapped my loc his loc uid swaps announce loc change true false false node write node file else if logminor logger minor this didn t swap my loc his loc uid no swaps reached end true randomise our location every 2 swap reset swap attempts whichever way it went if node random next int swap reset 0 set location node random next double announce loc change true true false node write node file sha256 return message digest md catch throwable t logger error this caught t t finally unlock reached end we only count the time taken by our outgoing swap requests remove recently forwarded item item osthread messagedigest getmessagedigest reachedend hishash shortbuffer origmessage getobject getdata hishash getdigestlength swaprequest hishash addforwardeditem nextlong myloc getlocation locationuidpair friendlocsanduids getpeerlocationsanduids friendlocs extractlocs friendlocsanduids myvaluelong friendlocs myvaluelong myvaluelong doubletolongbits myloc friendlocs myvaluelong doubletolongbits friendlocs myvalue longstobytes myvaluelong myhash myvalue createfnpswapreply myhash messagefilter messagefilter settype fnpswapcommit setfield settimeout setsource locationmanager waitfor locationmanager disconnectedexception swapcommit swapcommit swapcommit hisbuf shortbuffer getobject getdata hisbuf hisbuf swapcomplete hisbuf hishash swapcommit hisbuflong bytestolongs hisbuf hisbuflong hisrandom hisbuflong hisloc longbitstodouble hisbuflong hisloc hisloc hisloc registerknownlocation hisloc hisfriendlocs hisbuflong hisfriendlocs hisfriendlocs longbitstodouble hisbuflong hisfriendlocs hisfriendlocs hisfriendlocs registerlocationlink hisloc hisfriendlocs registerknownlocation hisfriendlocs numberofremotepeerlocationsseeninswaps hisfriendlocs swapcomplete createfnpswapcomplete myvalue addsubmessage createfnpswaplocations extractuids friendlocsanduids locationmanager shouldswap shouldswap myloc friendlocs hisloc hisfriendlocs hisrandom spyonlocations shouldswap myloc shouldswap timelastsuccessfullyswapped currenttimemillis updatelocationchangesession hisloc setlocation hisloc myloc hisloc announcelocchange writenodefile myloc hisloc noswaps reachedend swap_reset nextint swap_reset setlocation nextdouble announcelocchange writenodefile returnmessagedigest reachedend removerecentlyforwardeditem public void run freenet support logger os thread logpid this long uid r next long if lock return boolean reached end false try started swaps we can t lock friends locations so lets just pretend that they re locked long random r next long double my loc get location locationuid pair friend locs andui ds node peers get peer locations andui ds double friend locs extract locs friend locs andui ds long my value long new long 1 1 friend locs length my value long 0 random my value long 1 double double to long bits my loc for int i 0 i friend locs length i my value long i 2 double double to long bits friend locs i byte my value fields longs to bytes my value long byte my hash sha256 digest my value message m dmt createfnp swap request uid my hash swap max htl peer node pn node peers get random peer if pn null nowhere to send return only 1 id because we are sending we won t receive item add forwarded item uid uid null pn if logminor logger minor this sending swap request uid to pn message filter filter1 message filter create set type dmt fnp swap rejected set field dmt uid uid set source pn set timeout timeout message filter filter2 message filter create set type dmt fnp swap reply set field dmt uid uid set source pn set timeout timeout message filter filter filter1 or filter2 node usm send pn m location manager this if logminor logger minor this waiting for swap reply swap rejected on uid message reply try reply node usm wait for filter location manager this catch disconnected exception e if logminor logger minor this disconnected while waiting for swap reply swap rejected for uid return if reply null if pn is routable system current time millis pn time last connection completed timeout 2 timed out abort logger error this timed out waiting for swap rejected swap reply on uid return if reply get spec dmt fnp swap rejected failed abort if logminor logger minor this swap rejected on uid return we have an fnp swap reply yay fnp swap reply is exactly the same format as fnp swap request byte his hash short buffer reply get object dmt hash get data message confirm dmt createfnp swap commit uid my value confirm add sub message dmt createfnp swap locations extractui ds friend locs andui ds filter1 clear or message filter filter3 message filter create set field dmt uid uid set type dmt fnp swap complete set timeout timeout set source pn filter filter1 or filter3 node usm send pn confirm location manager this if logminor logger minor this waiting for swap complete uid uid try reply node usm wait for filter location manager this catch disconnected exception e if logminor logger minor this disconnected waiting for swap complete on uid return if reply null if pn is routable system current time millis pn time last connection completed timeout 2 hrrrm logger error this timed out waiting for swap complete malicious node on uid return if reply get spec dmt fnp swap rejected logger error this got swap rejected while waiting for swap complete this can happen occasionally because of badly timed disconnects but if it happens frequently it indicates a bug or an attack return byte his buf short buffer reply get object dmt data get data if his buf length 8 0 his buf length 16 logger error this bad content length in swap complete malicious node on uid return first does it verify byte rehash sha256 digest his buf if java util arrays equals rehash his hash logger error this bad hash in swap complete malicious node on uid return now decode it long his buf long fields bytes to longs his buf if his buf long length 2 logger error this bad buffer length no random no location malicious node on uid return long his random his buf long 0 double his loc double long bits to double his buf long 1 if his loc 0 0 his loc 1 0 logger error this bad loc his loc on uid return register known location his loc double his friend locs new double his buf long length 2 for int i 0 i his friend locs length i his friend locs i double long bits to double his buf long i 2 if his friend locs i 0 0 his friend locs i 1 0 logger error this bad friend loc his friend locs i on uid return register location link his loc his friend locs i register known location his friend locs i number of remote peer locations seen in swaps his friend locs length boolean should swap should swap my loc friend locs his loc his friend locs random his random spy on locations reply true should swap my loc if should swap time last successfully swapped system current time millis swap update location change session his loc set location his loc if logminor logger minor this swapped my loc his loc uid swaps announce loc change true false false node write node file else if logminor logger minor this didn t swap my loc his loc uid no swaps reached end true randomise our location every 2 swap reset swap attempts whichever way it went if node random next int swap reset 0 set location node random next double announce loc change true true false node write node file catch throwable t logger error this caught t t finally unlock reached end if item null remove recently forwarded item item osthread nextlong reachedend startedswaps friends_locations nextlong myloc getlocation locationuidpair friendlocsanduids getpeerlocationsanduids friendlocs extractlocs friendlocsanduids myvaluelong friendlocs myvaluelong myvaluelong doubletolongbits myloc friendlocs myvaluelong doubletolongbits friendlocs myvalue longstobytes myvaluelong myhash myvalue createfnpswaprequest myhash swap_max_htl peernode getrandompeer addforwardeditem swaprequest messagefilter messagefilter settype fnpswaprejected setfield setsource settimeout messagefilter messagefilter settype fnpswapreply setfield setsource settimeout messagefilter locationmanager swapreply swaprejected waitfor locationmanager disconnectedexception swapreply swaprejected isroutable currenttimemillis timelastconnectioncompleted swaprejected swapreply getspec fnpswaprejected fnpswapreply fnpswapreply fnpswaprequest hishash shortbuffer getobject getdata createfnpswapcommit myvalue addsubmessage createfnpswaplocations extractuids friendlocsanduids clearor messagefilter messagefilter setfield settype fnpswapcomplete settimeout setsource locationmanager swapcomplete waitfor locationmanager disconnectedexception swapcomplete isroutable currenttimemillis timelastconnectioncompleted swapcomplete getspec fnpswaprejected swaprejected swapcomplete hisbuf shortbuffer getobject getdata hisbuf hisbuf swapcomplete hisbuf hishash swapcomplete hisbuflong bytestolongs hisbuf hisbuflong hisrandom hisbuflong hisloc longbitstodouble hisbuflong hisloc hisloc hisloc registerknownlocation hisloc hisfriendlocs hisbuflong hisfriendlocs hisfriendlocs longbitstodouble hisbuflong hisfriendlocs hisfriendlocs hisfriendlocs registerlocationlink hisloc hisfriendlocs registerknownlocation hisfriendlocs numberofremotepeerlocationsseeninswaps hisfriendlocs shouldswap shouldswap myloc friendlocs hisloc hisfriendlocs hisrandom spyonlocations shouldswap myloc shouldswap timelastsuccessfullyswapped currenttimemillis updatelocationchangesession hisloc setlocation hisloc myloc hisloc announcelocchange writenodefile myloc hisloc noswaps reachedend swap_reset nextint swap_reset setlocation nextdouble announcelocchange writenodefile reachedend removerecentlyforwardeditem tell all connected peers that our location has changed protected void announce loc change announce loc change false false false announcelocchange announcelocchange private void announce loc change boolean log boolean random reset boolean from dup location message msg dmt createfnp loc change notification new get location node peers get peer location doubles true node peers local broadcast msg false true this if log record loc change random reset from dup location announcelocchange randomreset fromduplocation createfnplocchangenotificationnew getlocation getpeerlocationdoubles localbroadcast recordlocchange randomreset fromduplocation private void record loc change final boolean random reset final boolean from dup location node executor execute new runnable public void run file location log new file node node dir location log txt if location log exists location log length 1024 1024 10 location log delete file writer fw null try fw new file writer location log true fw write date format get date time instance format new date get location random reset random reset from dup location from duplicated location n fw close catch io exception e logger error this unable to write changed location to location log e e finally if fw null closer close fw record new location recordlocchange randomreset fromduplocation locationlog nodedir locationlog locationlog locationlog filewriter filewriter locationlog dateformat getdatetimeinstance getlocation randomreset fromduplocation ioexception locationlog public void run file location log new file node node dir location log txt if location log exists location log length 1024 1024 10 location log delete file writer fw null try fw new file writer location log true fw write date format get date time instance format new date get location random reset random reset from dup location from duplicated location n fw close catch io exception e logger error this unable to write changed location to location log e e finally if fw null closer close fw locationlog nodedir locationlog locationlog locationlog filewriter filewriter locationlog dateformat getdatetimeinstance getlocation randomreset fromduplocation ioexception locationlog lock the location manager return true if we managed to lock the location manager false if it was already locked synchronized boolean lock if locked if logminor logger minor this already locked return false if logminor logger minor this locking on port node get darknet port number locked true locked time system current time millis return true locationmanager locationmanager getdarknetportnumber lockedtime currenttimemillis unlock the node for swapping param log swap time if true log the swap time void unlock boolean log swap time message next message synchronized this if locked throw new illegal state exception unlocking when not locked long lock time system current time millis locked time if logminor logger minor this unlocking on port node get darknet port number logger minor this lock time lock time average swap time report lock time if incoming message queue is empty locked false return otherwise stay locked and start the next one from the queue next message incoming message queue remove first locked time system current time millis long oldid next message get long dmt uid long newid oldid 1 peer node pn peer node next message get source inner handle swap request oldid newid pn next message logswaptime logswaptime nextmessage illegalstateexception locktime currenttimemillis lockedtime getdarknetportnumber locktime locktime averageswaptime locktime incomingmessagequeue isempty nextmessage incomingmessagequeue removefirst lockedtime currenttimemillis nextmessage getlong peernode peernode nextmessage getsource innerhandleswaprequest nextmessage should we swap this method implements the core of the freenet 0 7 routing algorithm the criteria for swapping oskar says this is derived from the metropolis hastings algorithm anyway two nodes choose each other and decide to attempt a switch they calculate the distance of all their edges currently that is the distance between their currend id and that of their neighbors and multiply up all these values to get a then they calculate the distance to all their neighbors as it would be if they switched i ds and multiply up these values to get b if a b then they switch if a b then calculate p a b they then switch with probability p that is switch if rand next float p param my loc my location as a double param friend locs locations of my friends as doubles param his loc his location as a double param his friend locs locations of his friends as doubles param rand shared random number used to decide whether to swap return private boolean should swap double my loc double friend locs double his loc double his friend locs long rand a distance from us to all our neighbours for both nodes all multiplied together dump if math abs his loc my loc double min value 2 return false probably swapping with self string builder sb new string builder sb append my append my loc append his append his loc append my friends sb append friend locs length append his friends append his friend locs length append mine n for int i 0 i friend locs length i sb append friend locs i sb append sb append nhis n for int i 0 i his friend locs length i sb append his friend locs i sb append if logminor logger minor this sb to string double a 1 0 for int i 0 i friend locs length i if math abs friend locs i my loc double min value 2 continue a location distance friend locs i my loc for int i 0 i his friend locs length i if math abs his friend locs i his loc double min value 2 continue a location distance his friend locs i his loc b the same with our two values swapped double b 1 0 for int i 0 i friend locs length i if math abs friend locs i his loc double min value 2 continue b location distance friend locs i his loc for int i 0 i his friend locs length i if math abs his friend locs i my loc double min value 2 continue b location distance his friend locs i my loc logger normal this a a b b if a b return true double p a b take last 63 bits then turn into a double double rand prob double rand long max value double long max value logger normal this p p rand prob rand prob if rand prob p return true return false ids nextfloat myloc friendlocs hisloc hisfriendlocs shouldswap myloc friendlocs hisloc hisfriendlocs hisloc myloc min_value stringbuilder stringbuilder myloc hisloc myfriends friendlocs hisfriends hisfriendlocs friendlocs friendlocs hisfriendlocs hisfriendlocs tostring friendlocs friendlocs myloc min_value friendlocs myloc hisfriendlocs hisfriendlocs hisloc min_value hisfriendlocs hisloc friendlocs friendlocs hisloc min_value friendlocs hisloc hisfriendlocs hisfriendlocs myloc min_value hisfriendlocs myloc randprob max_value max_value randprob randprob randprob recently forwarded item long id long outgoingid peer node from peer node to this incomingid id this outgoingid outgoingid request sender from routed to to added time system current time millis last message time added time recentlyforwardeditem peernode peernode requestsender routedto addedtime currenttimemillis lastmessagetime addedtime void remove too old queued items while true message first synchronized this if incoming message queue is empty return first incoming message queue get first if first age max time on incoming queue return incoming message queue remove first if logminor logger minor this cancelling queued item first too long on queue maybe circular waiting swaps rejected already locked long oldid first get long dmt uid peer node pn peer node first get source reject message reject dmt createfnp swap rejected oldid try pn send async reject null this catch not connected exception e1 if logminor logger minor this lost connection rejecting swap request locked from pn removetoooldqueueditems incomingmessagequeue isempty incomingmessagequeue getfirst max_time_on_incoming_queue incomingmessagequeue removefirst swapsrejectedalreadylocked getlong peernode peernode getsource createfnpswaprejected sendasync notconnectedexception swaprequest handle an incoming swap request return true if we have handled the message false if it needs to be handled otherwise public boolean handle swap request message m peer node pn final long oldid m get long dmt uid final long newid oldid 1 uid is used to record the state i e uid x came in from node a forwarded to node b we increment it on each hop because in order for the node selection to be as random as possible we must allow loops i e the same swap chain may pass over the same node twice or more however if we get a request with either the incoming or the outgoing uid we can safely kill it as it s clearly the result of a bug recently forwarded item item recently forwardedi ds get oldid if item null if logminor logger minor this rejecting same id as previous request reject message reject dmt createfnp swap rejected oldid try pn send async reject null this catch not connected exception e if logminor logger minor this lost connection to pn rejecting swap request swaps rejected recognizedid return true if pn should reject swap request if logminor logger minor this advised to reject swap request by peer node rate limit reject message reject dmt createfnp swap rejected oldid try pn send async reject null this catch not connected exception e if logminor logger minor this lost connection rejecting swap request from pn swaps rejected rate limit return true if logminor logger minor this swap request from pn uid oldid int htl m get int dmt htl if htl swap max htl logger error this bogus swap htl htl from pn uid oldid htl swap max htl htl if node enable swapping htl 0 swapping disabled reject message reject dmt createfnp swap rejected oldid try pn send async reject null this catch not connected exception e1 if logminor logger minor this lost connection rejecting swap request locked from pn return true either forward it or handle it if htl 0 if logminor logger minor this accepting oldid accept handle locally lock or queue m oldid newid pn return true else m set dmt htl htl m set dmt uid newid if logminor logger minor this forwarding oldid while true forward peer node random peer node peers get random peer pn if random peer null if logminor logger minor this late reject oldid message reject dmt createfnp swap rejected oldid try pn send async reject null this catch not connected exception e1 logger normal this late reject but disconnected from sender pn swaps rejected nowhere to go return true if logminor logger minor this forwarding oldid to random peer item add forwarded item oldid newid pn random peer item successfully forwarded false try forward the request note that we must not send this blocking as we are on the receiver thread random peer send async m new my callback dmt createfnp swap rejected oldid pn item location manager this catch not connected exception e if logminor logger minor this not connected try a different node continue return true swaprequest handleswaprequest peernode getlong recentlyforwardeditem recentlyforwardedids createfnpswaprejected sendasync notconnectedexception swaprequest swapsrejectedrecognizedid shouldrejectswaprequest swaprequest peernode createfnpswaprejected sendasync notconnectedexception swaprequest swapsrejectedratelimit swaprequest getint swap_max_htl swap_max_htl enableswapping swappingdisabled createfnpswaprejected sendasync notconnectedexception swaprequest lockorqueue peernode randompeer getrandompeer randompeer createfnpswaprejected sendasync notconnectedexception swapsrejectednowheretogo randompeer addforwardeditem randompeer successfullyforwarded randompeer sendasync mycallback createfnpswaprejected locationmanager notconnectedexception if we can obtain the lock then execute the swap by calling inner handle swap request if we can queue the message queue it otherwise reject it void lock or queue message msg long oldid long newid peer node pn boolean run now false boolean reject false if logminor logger minor this locking on port node get darknet port number for uid oldid from pn synchronized this if locked locked true run now true locked time system current time millis else locked if node enable swap queueing incoming message queue size max incoming queue length reject anyway reject true swaps rejected already locked if logminor logger minor this incoming queue length too large incoming message queue size rejecting msg else queue it incoming message queue add last msg if logminor logger minor this queued msg queue length incoming message queue size if reject if logminor logger minor this rejecting msg message rejected dmt createfnp swap rejected oldid try pn send async rejected null this catch not connected exception e1 if logminor logger minor this lost connection rejecting swap request locked from pn else if run now if logminor logger minor this running msg boolean completed false try inner handle swap request oldid newid pn msg completed true finally if completed unlock false innerhandleswaprequest lockorqueue peernode runnow getdarknetportnumber runnow lockedtime currenttimemillis enableswapqueueing incomingmessagequeue max_incoming_queue_length swapsrejectedalreadylocked incomingmessagequeue incomingmessagequeue addlast incomingmessagequeue createfnpswaprejected sendasync notconnectedexception swaprequest runnow innerhandleswaprequest private void inner handle swap request long oldid long newid peer node pn message m recently forwarded item item add forwarded item oldid newid pn null locked do it incoming swap request handler isrh new incoming swap request handler m pn item if logminor logger minor this handling oldid from pn node executor execute isrh incoming swap request handler for port node get darknet port number innerhandleswaprequest peernode recentlyforwardeditem addforwardeditem incomingswaprequesthandler incomingswaprequesthandler getdarknetportnumber private recently forwarded item add forwarded item long uid long oid peer node pn peer node random peer recently forwarded item item new recently forwarded item uid oid pn random peer synchronized recently forwardedi ds recently forwardedi ds put uid item recently forwardedi ds put oid item return item recentlyforwardeditem addforwardeditem peernode peernode randompeer recentlyforwardeditem recentlyforwardeditem randompeer recentlyforwardedids recentlyforwardedids recentlyforwardedids handle an unmatched fnp swap reply return true if we recognized and forwarded this reply public boolean handle swap reply message m peer node source final long uid m get long dmt uid recently forwarded item item recently forwardedi ds get uid if item null logger error this unrecognized swap reply id uid return false if item request sender null if logminor logger minor this swap reply from source on chain originated locally uid return false if item routed to null logger error this got swap reply on uid but routed to is null return false if source item routed to logger error this unmatched swapreply uid from wrong source from source should be item routed to to item request sender return true item last message time system current time millis returning to source use incomingid m set dmt uid item incomingid if logminor logger minor this forwarding swap reply uid from source to item request sender try item request sender send async m null this catch not connected exception e if logminor logger minor this lost connection forwarding swap reply uid to item request sender return true fnpswapreply handleswapreply peernode getlong recentlyforwardeditem recentlyforwardedids swapreply requestsender swapreply routedto swapreply routedto routedto routedto requestsender lastmessagetime currenttimemillis swapreply requestsender requestsender sendasync notconnectedexception swapreply requestsender handle an unmatched fnp swap rejected return true if we recognized and forwarded this message public boolean handle swap rejected message m peer node source final long uid m get long dmt uid recently forwarded item item recently forwardedi ds get uid if item null return false if item request sender null if logminor logger minor this got a fnp swap rejected without any request sender set we can t and won t claim it uid uid return false if item routed to null logger error this got swap rejected on uid but routed to is null return false if source item routed to logger error this unmatched swapreply uid from wrong source from source should be item routed to to item request sender return true remove recently forwarded item item item last message time system current time millis if logminor logger minor this forwarding swap rejected uid from source to item request sender returning to source use incomingid m set dmt uid item incomingid try item request sender send async m null this catch not connected exception e if logminor logger minor this lost connection forwarding swap rejected uid to item request sender return true fnpswaprejected handleswaprejected peernode getlong recentlyforwardeditem recentlyforwardedids requestsender fnpswaprejected requestsender routedto swaprejected routedto routedto routedto requestsender removerecentlyforwardeditem lastmessagetime currenttimemillis swaprejected requestsender requestsender sendasync notconnectedexception swaprejected requestsender handle an unmatched fnp swap commit return true if we recognized and forwarded this message public boolean handle swap commit message m peer node source final long uid m get long dmt uid recently forwarded item item recently forwardedi ds get uid if item null return false if item routed to null return false if source item request sender logger error this unmatched swapreply uid from wrong source from source should be item request sender to item routed to return true item last message time system current time millis if logminor logger minor this forwarding swap commit uid item outgoingid from source to item routed to sending onwards use outgoing id m set dmt uid item outgoingid try item routed to send async m new send message on error callback dmt createfnp swap rejected item incomingid item request sender this this catch not connected exception e if logminor logger minor this lost connection forwarding swap commit uid to item routed to spy on locations m false return true fnpswapcommit handleswapcommit peernode getlong recentlyforwardeditem recentlyforwardedids routedto requestsender requestsender routedto lastmessagetime currenttimemillis swapcommit routedto routedto sendasync sendmessageonerrorcallback createfnpswaprejected requestsender notconnectedexception swapcommit routedto spyonlocations handle an unmatched fnp swap complete return true if we recognized and forwarded this message public boolean handle swap complete message m peer node source final long uid m get long dmt uid if logminor logger minor this handle swap complete uid recently forwarded item item recently forwardedi ds get uid if item null if logminor logger minor this item not found uid m return false if item request sender null if logminor logger minor this not matched uid m return false if item routed to null logger error this got swap complete on uid but routed to null meaning we accepted it presumably return false if source item routed to logger error this unmatched swapreply uid from wrong source from source should be item routed to to item request sender return true if logminor logger minor this forwarding swap complete uid from source to item request sender returning to source use incomingid m set dmt uid item incomingid try item request sender send async m null this catch not connected exception e logger normal this lost connection forwarding swap complete uid to item request sender item last message time system current time millis remove recently forwarded item item spy on locations m false return true fnpswapcomplete handleswapcomplete peernode getlong handleswapcomplete recentlyforwardeditem recentlyforwardedids requestsender routedto swapcomplete routedto routedto routedto requestsender swapcomplete requestsender requestsender sendasync notconnectedexception swapcomplete requestsender lastmessagetime currenttimemillis removerecentlyforwardeditem spyonlocations private void spy on locations message m boolean ignore if old spy on locations m ignore if old false 1 0 spyonlocations ignoreifold spyonlocations ignoreifold spy on locations in somebody else s swap request greatly increases the speed at which we can gather location data to estimate the network s size param swapping with me true if this node is participating in the swap false if it is merely spying on somebody else s swap private void spy on locations message m boolean ignore if old boolean swapping with me double my loc long uids null message uids message m get sub message dmt fnp swap nodeui ds if uids message null uids fields bytes to longs short buffer uids message get object dmt node uids get data byte data short buffer m get object dmt data get data if data length 16 data length 8 0 logger error this data invalid length in swap commit data length new exception error return double locations fields bytes to doubles data 8 data length 8 double his loc locations 0 if his loc 0 0 his loc 1 0 logger error this invalid his loc in swap commit his loc new exception error return if uids null register known location his loc uids 0 if swapping with me register known location my loc uids 0 else if ignore if old register known location his loc for int i 1 i locations length i double loc locations i if uids null register known location loc uids i 1 register link uids 0 uids i 1 else if ignore if old register known location loc register location link his loc loc swappingwithme spyonlocations ignoreifold swappingwithme myloc uidsmessage getsubmessage fnpswapnodeuids uidsmessage bytestolongs shortbuffer uidsmessage getobject node_uids getdata shortbuffer getobject getdata bytestodoubles hisloc hisloc hisloc hisloc hisloc registerknownlocation hisloc swappingwithme registerknownlocation myloc ignoreifold registerknownlocation hisloc registerknownlocation registerlink ignoreifold registerknownlocation registerlocationlink hisloc public void clear old swap chains long now system current time millis synchronized recently forwardedi ds recently forwarded item items new recently forwarded item recently forwardedi ds size if items length 1 return items recently forwardedi ds values to array items for int i 0 i items length i if now items i last message time timeout 2 remove recently forwarded item items i clearoldswapchains currenttimemillis recentlyforwardedids recentlyforwardeditem recentlyforwardeditem recentlyforwardedids recentlyforwardedids toarray lastmessagetime removerecentlyforwardeditem we lost the connection to a node or it was restarted public void lost or restarted node peer node pn list recently forwarded item v new array list recently forwarded item synchronized recently forwardedi ds set map entry long recently forwarded item entry set recently forwardedi ds entry set for map entry long recently forwarded item entry entry set long l entry get key recently forwarded item item entry get value if item null logger error this key is l but no value on recently forwardedi ds shouldn t be possible continue if item routed to pn continue if item successfully forwarded v add item remove them for recently forwarded item item v remove recently forwarded item item int dumped v size if dumped 0 logminor logger minor this lost or restarted node dumping dumped swap requests for pn get peer for recently forwarded item item v just reject it to avoid locking problems etc message msg dmt createfnp swap rejected item incomingid if logminor logger minor this rejecting in lost or restarted node item incomingid from item request sender try item request sender send async msg null this catch not connected exception e1 logger normal this both sender and receiver disconnected for item lostorrestartednode peernode recentlyforwardeditem arraylist recentlyforwardeditem recentlyforwardedids recentlyforwardeditem entryset recentlyforwardedids entryset recentlyforwardeditem entryset getkey recentlyforwardeditem getvalue recentlyforwardedids routedto successfullyforwarded recentlyforwardeditem removerecentlyforwardeditem lostorrestartednode getpeer recentlyforwardeditem createfnpswaprejected lostorrestartednode requestsender requestsender sendasync notconnectedexception private void remove recently forwarded item recently forwarded item item if logminor logger minor this removing item if item null logger error this remove recently forwarded item null new exception error synchronized recently forwardedi ds recently forwardedi ds remove item incomingid recently forwardedi ds remove item outgoingid removerecentlyforwardeditem recentlyforwardeditem removerecentlyforwardeditem recentlyforwardedids recentlyforwardedids recentlyforwardedids private final time sorted hashtable double known locs new time sorted hashtable double void register location link double d double t if logminor logger minor this known link d t timesortedhashtable knownlocs timesortedhashtable registerlocationlink void register known location double d long uid if logminor logger minor this location d uid uid register known location d registerknownlocation registerknownlocation void register known location double d if logminor logger minor this known location d long now system current time millis synchronized known locs logger minor this adding location d known locs size known locs size known locs push d now logger minor this added location d known locs size known locs size known locs remove before now max age logger minor this added and pruned location d known locs size known locs size if logminor logger minor this estimated net size session known locs size registerknownlocation currenttimemillis knownlocs knownlocs knownlocs knownlocs knownlocs knownlocs knownlocs removebefore max_age knownlocs knownlocs knownlocs void register link long uid1 long uid2 if logminor logger minor this uid link uid1 uid2 registerlink return the estimated network size based on locations seen after timestamp or for the whole session if 1 public int get network size estimate long timestamp return known locs count values after timestamp getnetworksizeestimate knownlocs countvaluesafter method called by node get known locations long timestamp return an array containing two cells locations and their last seen time for a given timestamp public object get known locations long timestamp synchronized known locs return known locs pairs after timestamp new double known locs size getknownlocations getknownlocations knownlocs knownlocs pairsafter knownlocs static double extract locs locationuid pair pairs double locs new double pairs length for int i 0 i pairs length i locs i pairs i location return locs extractlocs locationuidpair static long extractui ds locationuid pair pairs long uids new long pairs length for int i 0 i pairs length i uids i pairs i uid return uids extractuids locationuidpair public static double extract locs peer node peers boolean indicate backoff double locs new double peers length for int i 0 i peers length i locs i peers i get location if indicate backoff if peers i is routing backed off locs i 1 else locs i 1 locs i return locs extractlocs peernode indicatebackoff getlocation indicatebackoff isroutingbackedoff public static long extractui ds peer node peers long uids new long peers length for int i 0 i peers length i uids i peers i swap identifier return uids extractuids peernode swapidentifier public synchronized double get loc change session return loc change session getlocchangesession locchangesession public int get average swap time return int average swap time current value getaverageswaptime averageswaptime currentvalue public void received bytes int x node node stats swapping received bytes x receivedbytes nodestats swappingreceivedbytes public void sent bytes int x node node stats swapping sent bytes x sentbytes nodestats swappingsentbytes public void sent payload int x logger error this location manager sent payload new exception debug sentpayload locationmanager sentpayload constructs a new frost board object wich is a board public frost board string name board name name frostboardobject frostboard boardname constructs a new frost board object wich is a board param name param pub key param priv key public frost board string name string pub key string priv key this name set public key pub key set private key priv key frostboardobject pubkey privkey frostboard pubkey privkey setpublickey pubkey setprivatekey privkey public string get name return board name getname boardname public string get private key return private key getprivatekey privatekey public string get public key return public key getpublickey publickey public boolean is public board if public key null private key null return true return false ispublicboard publickey privatekey public boolean is read access board if public key null private key null return true return false isreadaccessboard publickey privatekey public boolean is write access board if public key null private key null return true return false iswriteaccessboard publickey privatekey public void set private key string val if val length 5 val null if val null val val trim private key val setprivatekey privatekey public void set public key string val if val length 5 val null if val null val val trim public key val setpublickey publickey private int color public chroma key filter chromakeyfilter set the tolerance of the image in the range 0 1 arg tolerance the tolerance public void seth tolerance float h tolerance this h tolerance h tolerance sethtolerance htolerance htolerance htolerance public float geth tolerance return h tolerance gethtolerance htolerance public void sets tolerance float s tolerance this s tolerance s tolerance setstolerance stolerance stolerance stolerance public float gets tolerance return s tolerance getstolerance stolerance public void setb tolerance float b tolerance this b tolerance b tolerance setbtolerance btolerance btolerance btolerance public float getb tolerance return b tolerance getbtolerance btolerance public void set color int color this color color setcolor public int get color return color getcolor public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster if dst null dst create compatible dest image src null writable raster dst raster dst get raster float hsb1 null float hsb2 null int rgb2 color int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff hsb2 color rg btohsb r2 b2 g2 hsb2 int in pixels null for int y 0 y height y in pixels getrgb src 0 y width 1 in pixels for int x 0 x width x int rgb1 in pixels x int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff hsb1 color rg btohsb r1 b1 g1 hsb1 int tolerance int 255 tolerance return math abs r1 r2 tolerance math abs g1 g2 tolerance math abs b1 b2 tolerance if pixel utils near colors in clean int 255 tolerance if math abs hsb1 0 hsb2 0 h tolerance math abs hsb1 1 hsb2 1 s tolerance math abs hsb1 2 hsb2 2 b tolerance in pixels x rgb1 0xffffff else in pixels x rgb1 setrgb dst 0 y width 1 in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster createcompatibledestimage writableraster dstraster getraster rgbtohsb inpixels inpixels inpixels inpixels rgbtohsb pixelutils nearcolors htolerance stolerance btolerance inpixels inpixels inpixels override public string to string return keying chroma key tostring public prober jmdns impl jmdns impl this jmdns impl jmdns impl associate the host name to this if it needs probing if this jmdns impl get state dns state probing 1 this jmdns impl set task this associate services to this if they need probing synchronized this jmdns impl for iterator iterator this jmdns impl get services values iterator iterator has next service info impl info service info impl iterator next if info get state dns state probing 1 info set task this jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl getstate dnsstate probing_1 jmdnsimpl settask jmdnsimpl jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl getstate dnsstate probing_1 settask public void start timer timer long now system current time millis if now this jmdns impl get last throttle increment dns constants probe throttle count interval this jmdns impl set throttle this jmdns impl get throttle 1 else this jmdns impl set throttle 1 this jmdns impl set last throttle increment now if this jmdns impl get state dns state announced this jmdns impl get throttle dns constants probe throttle count timer schedule this jmdns impl get random next int 1 dns constants probe wait interval dns constants probe wait interval else timer schedule this dns constants probe conflict interval dns constants probe conflict interval currenttimemillis jmdnsimpl getlastthrottleincrement dnsconstants probe_throttle_count_interval jmdnsimpl setthrottle jmdnsimpl getthrottle jmdnsimpl setthrottle jmdnsimpl setlastthrottleincrement jmdnsimpl getstate dnsstate jmdnsimpl getthrottle dnsconstants probe_throttle_count jmdnsimpl getrandom nextint dnsconstants probe_wait_interval dnsconstants probe_wait_interval dnsconstants probe_conflict_interval dnsconstants probe_conflict_interval public boolean cancel remove association from host name to this if this jmdns impl get task this this jmdns impl set task null remove associations from services to this synchronized this jmdns impl for iterator i this jmdns impl get services values iterator i has next service info impl info service info impl i next if info get task this info set task null return super cancel jmdnsimpl gettask jmdnsimpl settask jmdnsimpl jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl gettask settask public void run synchronized this jmdns impl get io lock dns outgoing out null try send probes for jmdns itself if this jmdns impl get state task state this jmdns impl get task this if out null out new dns outgoing dns constants flags qr query out add question new dns question this jmdns impl get local host get name dns constants type any dns constants class in this jmdns impl get local host add address records out true this jmdns impl advance state send probes for services defensively copy the services into a local list to prevent race conditions with methods register service and unregister service list list synchronized this jmdns impl list new linked list this jmdns impl get services values for iterator i list iterator i has next service info impl info service info impl i next synchronized info if info get state task state info get task this info advance state logger fine run jmdns probing info get qualified name state info get state if out null out new dns outgoing dns constants flags qr query out add question new dns question info get qualified name dns constants type any dns constants class in the unique flag should be not set here because these answers haven t been proven unique yet this means the record will not exactly match the announcement record out add authorative answer new dns record service info get qualified name dns constants type srv dns constants class in dns constants dns ttl info get priority info get weight info get port this jmdns impl get local host get name if out null logger finer run jmdns probing task state this jmdns impl send out else if we have nothing to send another timer task state ahead of us has done the job for us we can cancel cancel return catch throwable e logger log level warning run exception e this jmdns impl recover task state task state advance if task state is probing cancel this jmdns impl start announcer jmdnsimpl getiolock dnsoutgoing jmdnsimpl getstate taskstate jmdnsimpl gettask dnsoutgoing dnsconstants flags_qr_query addquestion dnsquestion jmdnsimpl getlocalhost getname dnsconstants type_any dnsconstants class_in jmdnsimpl getlocalhost addaddressrecords jmdnsimpl advancestate registerservice unregisterservice jmdnsimpl linkedlist jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl getstate taskstate gettask advancestate getqualifiedname getstate dnsoutgoing dnsconstants flags_qr_query addquestion dnsquestion getqualifiedname dnsconstants type_any dnsconstants class_in addauthorativeanswer dnsrecord getqualifiedname dnsconstants type_srv dnsconstants class_in dnsconstants dns_ttl getpriority getweight getport jmdnsimpl getlocalhost getname taskstate jmdnsimpl taskstate jmdnsimpl taskstate taskstate taskstate isprobing jmdnsimpl startannouncer public class hellofcp implements fred plugin fred plugin threadless fred pluginfcp public void run plugin plugin respirator pr fredplugin fredpluginthreadless fredpluginfcp runplugin pluginrespirator public void terminate access flag fred pluginfcp access direct direct call plugin to plugin fred pluginfcp access fcp restricted fcp restricted access fred pluginfcp access fcp full fcp full access public void handle plugin reply sender replysender simple field set params bucket data int accesstype simple echo try replysender send params data catch plugin not found exception e system out println connection to request sender lost e print stack trace fredpluginfcp access_direct fredpluginfcp access_fcp_restricted fredpluginfcp access_fcp_full pluginreplysender simplefieldset pluginnotfoundexception printstacktrace private static final long serial versionuid 1l public no such message exception super serialversionuid nosuchmessageexception public no such message exception string id super unknown message id id nosuchmessageexception private calendar cal public date calendar cal this cal cal public calendar get calendar return cal getcalendar public int get hour thanks for theo beisch 10 20 04 return get calendar get calendar hour of day gethour getcalendar hour_of_day public int get minute return get calendar get calendar minute getminute getcalendar public int get second return get calendar get calendar second getsecond getcalendar public final static date get local instance return new date calendar get instance getlocalinstance getinstance public final static date get instance thanks for theo beisch 10 20 04 return new date calendar get instance time zone get time zone gmt getinstance getinstance timezone gettimezone public final static string to date string int value if value 10 return 0 integer to string value return integer to string value todatestring tostring tostring public final static string to month string int value value calendar january if 0 value value 12 return month string value return tomonthstring month_string public final static string to week string int value value calendar sunday if 0 value value 7 return week string value return toweekstring week_string public final static string to time string int value string str if value 10 str 0 str integer to string value return str totimestring tostring public string get date string thanks for theo beisch 10 20 04 calendar cal get calendar return to week string cal get calendar day of week to time string cal get calendar date to month string cal get calendar month integer to string cal get calendar year to time string cal get calendar hour of day to time string cal get calendar minute to time string cal get calendar second gmt getdatestring getcalendar toweekstring day_of_week totimestring tomonthstring tostring totimestring hour_of_day totimestring totimestring public string get time string thanks for theo beisch 10 20 04 calendar cal get calendar return to date string cal get calendar hour of day cal get calendar second 2 0 to date string cal get calendar minute gettimestring getcalendar todatestring hour_of_day todatestring public light filter lights new vector add light new distant light bump height 1 0f bump softness 5 0f bump shape 0 material new material l new vector3f v new vector3f n new vector3f shaded color new color4f diffuse color new color4f specular color new color4f tmpv new vector3f tmpv2 new vector3f lightfilter addlight distantlight bumpheight bumpsoftness bumpshape shadedcolor diffuse_color specular_color public void set material material material this material material setmaterial public material get material return material getmaterial public void set bump function function2d bump function this bump function bump function setbumpfunction bumpfunction bumpfunction bumpfunction public function2d get bump function return bump function getbumpfunction bumpfunction public void set bump height float bump height this bump height bump height setbumpheight bumpheight bumpheight bumpheight public float get bump height return bump height getbumpheight bumpheight public void set bump softness float bump softness this bump softness bump softness setbumpsoftness bumpsoftness bumpsoftness bumpsoftness public float get bump softness return bump softness getbumpsoftness bumpsoftness public void set bump shape int bump shape this bump shape bump shape setbumpshape bumpshape bumpshape bumpshape public int get bump shape return bump shape getbumpshape bumpshape public void set view distance float view distance this view distance view distance setviewdistance viewdistance viewdistance viewdistance public float get view distance return view distance getviewdistance viewdistance public void set environment map buffered image environment map this environment map environment map if environment map null env width environment map get width env height environment map get height env pixels getrgb environment map 0 0 env width env height null else env width env height 1 env pixels null setenvironmentmap bufferedimage environmentmap environmentmap environmentmap environmentmap envwidth environmentmap getwidth envheight environmentmap getheight envpixels environmentmap envwidth envheight envwidth envheight envpixels public image get environment map return environment map getenvironmentmap environmentmap public void set color source int color source this color source color source setcolorsource colorsource colorsource colorsource public int get color source return color source getcolorsource colorsource public void set bump source int bump source this bump source bump source setbumpsource bumpsource bumpsource bumpsource public int get bump source return bump source getbumpsource bumpsource public void set diffuse color int diffuse color material diffuse color diffuse color setdiffusecolor diffusecolor diffusecolor diffusecolor public int get diffuse color return material diffuse color getdiffusecolor diffusecolor public void add light light light lights add element light addlight addelement public void remove light light light lights remove element light removelight removeelement public vector get lights return lights getlights protected final static float r255 1 0f 255 0f protected void set fromrgb color4f c int argb c set argb 16 0xff r255 argb 8 0xff r255 argb 0xff r255 argb 24 0xff r255 setfromrgb override protected int filter pixels int width int height int in pixels rectangle transformed space int index 0 int out pixels new int width height float width45 math abs 6 0f bump height boolean invert bumps bump height 0 vector3f position new vector3f 0 0f 0 0f 0 0f vector3f viewpoint new vector3f float width 2 0f float height 2 0f view distance vector3f normal new vector3f color4f env color new color4f color4f diffuse color new color4f new color material diffuse color color4f specular color new color4f new color material specular color function2d bump bump function apply the bump softness if bump source bumps from image bump source bumps from image alpha bump source bumps from map bump null if bump softness 0 int bump width width int bump height height int bump pixels in pixels if bump source bumps from map bump function instanceof image function2d image function2d if2d image function2d bump function bump width if2d get width bump height if2d get height bump pixels if2d get pixels int tmp pixels new int bump width bump height int soft pixels new int bump width bump height for int i 0 i 3 i box blur filter blur bump pixels tmp pixels bump width bump height int bump softness box blur filter blur tmp pixels soft pixels bump height bump width int bump softness kernel kernel gaussian filter make kernel bump softness gaussian filter convolve and transpose kernel bump pixels tmp pixels bump width bump height true false false gaussian filter wrap edges gaussian filter convolve and transpose kernel tmp pixels soft pixels bump height bump width true false false gaussian filter wrap edges bump new image function2d soft pixels bump width bump height image function2d clamp bump source bumps from image alpha final function2d bbump bump if bump shape 0 bump new function2d private function2d original bbump public float evaluate float x float y float v original evaluate x y switch bump shape case 1 v v 0 5f 0 5f v v image math smooth step 0 45f 0 55f v break case 2 v v 0 5f 0 5f v break case 3 v image math triangle v break case 4 v image math circle down v break case 5 v image math gain v 0 75f break return v else if bump source bumps from map bump new image function2d in pixels width height image function2d clamp bump source bumps from image alpha float reflectivity material reflectivity float areflectivity 1 reflectivity vector3f v1 new vector3f vector3f v2 new vector3f vector3f n new vector3f light lights array new light lights size lights copy into lights array for int i 0 i lights array length i lights array i prepare width height float height window new float 3 width for int x 0 x width x height window 1 x width45 bump evaluate x 0 loop through each source pixel for int y 0 y height y boolean y0 y 0 boolean y1 y height 1 position y y for int x 0 x width x height window 2 x width45 bump evaluate x y 1 for int x 0 x width x boolean x0 x 0 boolean x1 x width 1 calculate the normal at this point if bump source bumps from bevel complicated and slower method calculate four normals using the gradients in x y directions int count 0 normal x normal y normal z 0 float m0 height window 1 x float m1 x0 height window 1 x 1 m0 0 float m2 y0 height window 0 x m0 0 float m3 x1 height window 1 x 1 m0 0 float m4 y1 height window 2 x m0 0 if x0 y1 v1 x 1 0f v1 y 0 0f v1 z m1 v2 x 0 0f v2 y 1 0f v2 z m4 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count if x0 y0 v1 x 1 0f v1 y 0 0f v1 z m1 v2 x 0 0f v2 y 1 0f v2 z m2 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count if y0 x1 v1 x 0 0f v1 y 1 0f v1 z m2 v2 x 1 0f v2 y 0 0f v2 z m3 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count if x1 y1 v1 x 1 0f v1 y 0 0f v1 z m3 v2 x 0 0f v2 y 1 0f v2 z m4 n cross v1 v2 n normalize if n z 0 0 n z n z normal add n count average the four normals normal x count normal y count normal z count if invert bumps normal x normal x normal y normal y position x x if normal z 0 get the material colour at this point if color source colors from image set fromrgb diffuse color in pixels index else set fromrgb diffuse color material diffuse color if reflectivity 0 environment map null fixme too much normalizing going on here tmpv2 set viewpoint tmpv2 sub position tmpv2 normalize tmpv set normal tmpv normalize reflect tmpv scale 2 0f tmpv dot tmpv2 tmpv sub v tmpv normalize set fromrgb env color get environment map tmpv in pixels width height fixme interpolate diffuse color x reflectivity env color x areflectivity diffuse color x diffuse color y reflectivity env color y areflectivity diffuse color y diffuse color z reflectivity env color z areflectivity diffuse color z shade the pixel color4f c phong shade position viewpoint normal diffuse color specular color material lights array int alpha in pixels index 0xff000000 int rgb int c x 255 16 int c y 255 8 int c z 255 out pixels index alpha rgb else out pixels index 0 float t height window 0 height window 0 height window 1 height window 1 height window 2 height window 2 t return out pixels filterpixels inpixels transformedspace outpixels bumpheight invertbumps bumpheight viewdistance envcolor diffusecolor diffusecolor specularcolor specularcolor bumpfunction bumpsource bumps_from_image bumpsource bumps_from_image_alpha bumpsource bumps_from_map bumpsoftness bumpwidth bumpheight bumppixels inpixels bumpsource bumps_from_map bumpfunction imagefunction2d imagefunction2d imagefunction2d bumpfunction bumpwidth getwidth bumpheight getheight bumppixels getpixels tmppixels bumpwidth bumpheight softpixels bumpwidth bumpheight boxblurfilter bumppixels tmppixels bumpwidth bumpheight bumpsoftness boxblurfilter tmppixels softpixels bumpheight bumpwidth bumpsoftness gaussianfilter makekernel bumpsoftness gaussianfilter convolveandtranspose bumppixels tmppixels bumpwidth bumpheight gaussianfilter wrap_edges gaussianfilter convolveandtranspose tmppixels softpixels bumpheight bumpwidth gaussianfilter wrap_edges imagefunction2d softpixels bumpwidth bumpheight imagefunction2d bumpsource bumps_from_image_alpha bumpshape bumpshape imagemath smoothstep imagemath imagemath circledown imagemath bumpsource bumps_from_map imagefunction2d inpixels imagefunction2d bumpsource bumps_from_image_alpha lightsarray copyinto lightsarray lightsarray lightsarray heightwindow heightwindow heightwindow bumpsource bumps_from_bevel heightwindow heightwindow heightwindow heightwindow heightwindow invertbumps colorsource colors_from_image setfromrgb diffusecolor inpixels setfromrgb diffusecolor diffusecolor environmentmap setfromrgb envcolor getenvironmentmap inpixels diffusecolor envcolor diffusecolor diffusecolor envcolor diffusecolor diffusecolor envcolor diffusecolor phongshade diffusecolor specularcolor lightsarray inpixels outpixels outpixels heightwindow heightwindow heightwindow heightwindow heightwindow heightwindow outpixels public float evaluate float x float y float v original evaluate x y switch bump shape case 1 v v 0 5f 0 5f v v image math smooth step 0 45f 0 55f v break case 2 v v 0 5f 0 5f v break case 3 v image math triangle v break case 4 v image math circle down v break case 5 v image math gain v 0 75f break return v bumpshape imagemath smoothstep imagemath imagemath circledown imagemath protected color4f phong shade vector3f position vector3f viewpoint vector3f normal color4f diffuse color color4f specular color material material light lights array shaded color set diffuse color shaded color scale material ambient intensity for int i 0 i lights array length i light light lights array i n set normal l set light position if light type distant l sub position l normalize float n dotl n dot l if n dotl 0 0 float d dotl 0 v set viewpoint v sub position v normalize spotlight if light type spot d dotl light direction dot l if d dotl light cos cone angle continue n scale 2 0f n dotl n sub l float r dotv n dot v float rv if r dotv 0 0 rv 0 0f else rv float math pow r dotv material highlight rv r dotv material highlight material highlight r dotv r dotv fast approximation to pow spotlight if light type spot d dotl light cos cone angle d dotl float e d dotl e e e e e e e float math pow d dotl light focus 10 1 e rv e n dotl e diffuse color set diffuse color diffuse color scale material diffuse reflectivity diffuse color x light real color x n dotl diffuse color y light real color y n dotl diffuse color z light real color z n dotl specular color set specular color specular color scale material specular reflectivity specular color x light real color x rv specular color y light real color y rv specular color z light real color z rv diffuse color add specular color diffuse color clamp 0 1 shaded color add diffuse color shaded color clamp 0 1 return shaded color phongshade diffusecolor specularcolor lightsarray shadedcolor diffusecolor shadedcolor ambientintensity lightsarray lightsarray ndotl ndotl ddotl ddotl ddotl cosconeangle ndotl rdotv rdotv rdotv rdotv rdotv rdotv ddotl cosconeangle ddotl ddotl ddotl ndotl diffuse_color diffusecolor diffuse_color diffusereflectivity diffuse_color realcolor ndotl diffuse_color realcolor ndotl diffuse_color realcolor ndotl specular_color specularcolor specular_color specularreflectivity specular_color realcolor specular_color realcolor specular_color realcolor diffuse_color specular_color diffuse_color shadedcolor diffuse_color shadedcolor shadedcolor private int get environment map vector3f normal int in pixels int width int height if environment map null float angle float math acos normal y float x y y angle image math pi if y 0 0f y 1 0f x 0 0f else float f normal x float math sin angle if f 1 0f f 1 0f else if f 1 0f f 1 0f x float math acos f image math pi a bit of empirical scaling x image math clamp x env width 0 env width 1 y image math clamp y env height 0 env height 1 int ix int x int iy int y float x weight x ix float y weight y iy int i env width iy ix int dx ix env width 1 0 1 int dy iy env height 1 0 env width return image math bilinear interpolate x weight y weight env pixels i env pixels i dx env pixels i dy env pixels i dx dy return 0 getenvironmentmap inpixels environmentmap imagemath imagemath imagemath envwidth envwidth imagemath envheight envheight xweight yweight envwidth envwidth envheight envwidth imagemath bilinearinterpolate xweight yweight envpixels envpixels envpixels envpixels override public string to string return stylize light effects tostring public material ambient intensity 0 5f diffuse reflectivity 1 0f specular reflectivity 1 0f highlight 3 0f reflectivity 0 0f diffuse color 0xff888888 specular color 0xffffffff ambientintensity diffusereflectivity specularreflectivity diffusecolor specularcolor public void set diffuse color int diffuse color this diffuse color diffuse color setdiffusecolor diffusecolor diffusecolor diffusecolor public int get diffuse color return diffuse color getdiffusecolor diffusecolor public void set opacity float opacity this opacity opacity setopacity public float get opacity return opacity getopacity float distance 100 0f public light this 270 image math pi 180 0f 0 5235987755982988f 1 0f imagemath public light float azimuth float elevation float intensity this azimuth azimuth this elevation elevation this intensity intensity public void set azimuth float azimuth this azimuth azimuth setazimuth public float get azimuth return azimuth getazimuth public void set elevation float elevation this elevation elevation setelevation public float get elevation return elevation getelevation public void set distance float distance this distance distance setdistance public float get distance return distance getdistance public void set intensity float intensity this intensity intensity setintensity public float get intensity return intensity getintensity public void set cone angle float cone angle this cone angle cone angle setconeangle coneangle coneangle coneangle public float get cone angle return cone angle getconeangle coneangle public void set focus float focus this focus focus setfocus public float get focus return focus getfocus public void set color int color this color color setcolor public int get color return color getcolor set the centre of the light in the x direction as a proportion of the image size param centrex the center see get centrex public void set centrex float x centrex x getcentrex setcentrex get the centre of the light in the x direction as a proportion of the image size return the center see set centrex public float get centrex return centrex setcentrex getcentrex set the centre of the light in the y direction as a proportion of the image size param centrey the center see get centrey public void set centrey float y centrey y getcentrey setcentrey get the centre of the light in the y direction as a proportion of the image size return the center see set centrey public float get centrey return centrey setcentrey getcentrey prepare the light for rendering param width the output image width param height the output image height public void prepare int width int height float lx float math cos azimuth math cos elevation float ly float math sin azimuth math cos elevation float lz float math sin elevation direction new vector3f lx ly lz direction normalize if type distant lx distance ly distance lz distance lx width centrex ly height centrey position new vector3f lx ly lz real color set new color color real color scale intensity cos cone angle float math cos cone angle realcolor realcolor cosconeangle coneangle override public object clone try light copy light super clone return copy catch clone not supported exception e return null clonenotsupportedexception override public string to string return light tostring public class ambient light extends light override public string to string return ambient light ambientlight tostring public class point light extends light public point light type point pointlight pointlight override public string to string return point light tostring public class distant light extends light public distant light type distant distantlight distantlight override public string to string return distant light tostring public class spot light extends light public spot light type spot spotlight spotlight override public string to string return spotlight tostring public float x y z public tuple3f this 0 0 0 public tuple3f float x this x x 0 this y x 1 this z x 2 public tuple3f float x float y float z this x x this y y this z z public tuple3f tuple3f t this x t x this y t y this z t z public void absolute x math abs x y math abs y z math abs z public void absolute tuple3f t x math abs t x y math abs t y z math abs t z public void clamp float min float max if x min x min else if x max x max if y min y min else if y max y max if z min z min else if z max z max public void set float x float y float z this x x this y y this z z public void set float x this x x 0 this y x 1 this z x 2 public void set tuple3f t x t x y t y z t z public void get tuple3f t t x x t y y t z z public void get float t t 0 x t 1 y t 2 z public void negate x x y y z z public void negate tuple3f t x t x y t y z t z public void interpolate tuple3f t float alpha float a 1 alpha x a x alpha t x y a y alpha t y z a z alpha t z public void scale float s x s y s z s public void add tuple3f t x t x y t y z t z public void add tuple3f t1 tuple3f t2 x t1 x t2 x y t1 y t2 y z t1 z t2 z public void sub tuple3f t x t x y t y z t z public void sub tuple3f t1 tuple3f t2 x t1 x t2 x y t1 y t2 y z t1 z t2 z public void scale add float s tuple3f t x s t x y s t y z s t z scaleadd public void scale add float s tuple3f t1 tuple3f t2 x s t1 x t2 x y s t1 y t2 y z s t1 z t2 z scaleadd override public string to string return x y z tostring public data found message fetch result fr string identifier boolean global this identifier identifier this global global this mime type fr get mime type this data length fr size datafoundmessage fetchresult mimetype getmimetype datalength public data found message long found data length string found data mime type string identifier boolean global this mime type found data mime type this identifier identifier this global global this data length found data length datafoundmessage founddatalength founddatamimetype mimetype founddatamimetype datalength founddatalength override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier if global fs put single global true fs put single metadata content type mime type fs put single data length long to string data length return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle putsingle contenttype mimetype putsingle datalength tostring datalength override public string get name return data found getname datafound override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message data found goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message datafound override public void remove from object container container container delete this removefrom objectcontainer public void terminate goon false public string handlehttp get string path try string key get random key freenet chk j v1zc0cun3wla cpxl kd6vt6c1j ant9 kisc vjfz lu54 q9f ilj sh8m1i1ymr bz a0fs ic gkvuy zah zb5j7uepla aaea 8 fetch result fr pr gethl simple client fetch new freeneturi key return this is the echo of the past path n this is from within the plugin i ve fetched some data for you n the key is key and the data inside n n new string fr as byte array trim n n length fr size mime type fr get mime type catch exception e todo auto generated catch block return e to string e print stack trace handlehttpget getrandomkey v1zc0cun3wlacpxlkd6vt6c1jant9kiscvjfzlu54 q9filjsh8m1i1ymrbz a0fsicgkvuyzahzb5j7uepla fetchresult gethlsimpleclient asbytearray getmimetype tostring printstacktrace public void run plugin plugin respirator pr this pr pr pr register toadlet this int i int system current time millis 1000 while goon system err println this is a threaded test plugin i time is now new date try thread sleep 60000 catch interrupted exception e todo auto generated catch block e print stack trace runplugin pluginrespirator registertoadlet currenttimemillis interruptedexception printstacktrace private string get random key string strs freenet chk 22 lk6f be3 oxpbv mlrj fkh 4cgy swcgh oz7hdq pzx kp4 wx og3 ob8mji5eg4w nvmda 1 csw9mw aqw ohx xz ldrn a aaea 8 freenet chk z fpjcnhon axlp dadg v6 qc swm775 5 iw2k q bhb63 ts q prrw xci pnya ebsk5ebw ayo ghl taa 3y bhr n icx8a aaea 8 freenet chk o pp tiko ew zbl73o7 tb qq jap4j eglt8o3mp5jy jujvk 9 8tdgjaw8 lfi dhc7x wrey3t ej fpd op ba6 oituiv jpa aaea 8 freenet chk s cb z1at tk xvozlbi9k3ci lz 6rqb9 io3aql2 mliam a60 eoe90z5fc viuix lecubhf ue ff6 ge69s sdlzi hr eg aaea 8 freenet chk dcp psry0bg4o vin8ws xvwz tnp2z bemz2 bwenpbzc9tu goii qkp8o wa tc3wqr a0 rf a cws eeoq pa vdj cx vpari aaea 8 freenet chk 6oa qs98fs uo6r fc jtrmf92s ffqbxk4 yt01 yshcwp3c8 wn lfm5swg7x dbk au srnl8ge fz5 4 7a2p5k8nnbv9q aaea 8 freenet chk ep pkqawesjv qzgo3wr6n pee8 sz ouexpx ythi wv4on tg jlwdil vos6 otx zqlr shtnuog fgtro0bnxd vx uj3 busa aaea 8 freenet chk mwc8ox xg1byz0ajfxk oku yr yik7qn1 pt bl bjc14 jw7o f kx cbs0u8fjt1x 8oe3d kn qa vpz07 cpix g bxkwo7xc aaea 8 freenet chk e5l gh rcv cep6p yb odjnys3na0vs7 xe5gi qmmq azma u3o9v86hku mqbtgxsr9pja qps oodm25qd hg2khmejzi aaea 8 freenet chk q hat ieg ed3b wshbb sqvo y3wfbu5ep ejej bj4m jfzg j8 lcoixb7fwx hrh pmxt6 ec rfbw0skt bai84bh pv80 aaea 8 freenet chk sbbzx asf1us qc cp mc35iz tpd78h dho qq7y tbw hgae c8jjxzd6f8apd hb ty2jqr wwh eidun cwxo8mt zw amq s aaea 8 freenet chk bb e pfxucl0 nzayj2jvtivpr xc nooyep ndhe dvn6ec nmn zuv0 cwi obgv syw pm tv29g pj juir tl d muuot oik aaea 8 freenet chk hdk nl vito25 rmg qgb gx iytu4w14mh see in9 yyd2pg e jc8kx gz ntdrvkf0h90geen zgb dux h9 gkc1fyfm ug aaea 8 freenet chk p3 xa12sfg qg3ls vu9 ss vgj4k bh58 gp iqrkg rpacnfm ly cvmn88mtvx l9 bqtqv51 ontj39x8ms5sora k3lu8 aaea 8 freenet chk d9t ep ygv77l2zmro8igbu44f 5ku ymo 9 xoa uf hrgw yu zz2qp5w2b wpt dmv5 dw9 dmp3wh3n u4qr kd mnlaq aaea 8 freenet chk t7ytk bob45 sqxk7xw zxmwauj cdwva1k7e pczu ac rirc acnbq4qo4t2t la5h6 qytr3 ua ouz wz03tyk0 ep hzhi aaea 8 freenet chk x avu swiw4 idyq 4 cwovcxguq psd mjp9of le rp weibe yefu eommdga tr vo9dx qpc uiraiyd cnpkh65 smk6jas aaea 8 freenet chk 3wd fmak cldqh0tqyqh d4gqh8iint7xzm 2mv vosass n b zo cgtlwszydj ib44 dl2ye3m1zltk1c4yi tz8bo aaea 8 freenet chk vuet2wzs 72s qxbaxnpjc vy8 gkqxmu ge78a ame oec4 3mz7j vw wn uas pv9w1vvyn79 ukk9sueu caff sua07s aaea 8 freenet chk im tdf9b9cd xy7 zvwm gx tp02llxati8ir gjtletbyqlu 2 ca6l us rs qa lh messyv pcd5 srs06anut mcql zvcjli aaea 8 freenet chk 5tig2i52 nomh6ip au dce7lowj1vqbb towt pzxap imp0 ox wc eqx0en gas tnira6zwi etqmm2w jb8o87vz7knv7w aaea 8 freenet chk 1ox icrwd cqi7hgf cd3dx4dw vsk7xvp zcyibeh zybs xc gel01bi xlx unkacw4cx rsajb nr uc43h2rm390q8m mt0 aaea 8 freenet chk bwieoklnn sawht ul3w zu9w2fc jy5uh7 dmi xr kivgxa i lg2cordi wt mnca2glyj9i vf6yzd ysc rko3p8srbx dk aaea 8 freenet chk xxkrvm jpcy ea0 md2w7 rz hs upl80 b sx9 kc04f lei kc a3rm icwq8n33nd5xjt trrkiomq3g8c2c8vj jtneym ak aaea 8 freenet chk s8aihl 4jn9a6gf9dy umctn2 3 pp sj0 ktqa49jyc1u i pgzu7lvkt gbs5ionx9sw rjve gjo0 shy oo bn8wuq2u aaea 8 freenet chk 7g zlzb jy ft hndt213t33a yy ssu syp0rxh emi q8yjvm 37 qtrm6fx fkmvemm4jf6xxv4l dbba cigwj zi5 ad vk aaea 8 freenet chk mcls9n1182p jszp4 lfmr ll hx9vx tgbz9zy44ju1fy r uh2 vghol fp rl2fdv8hqb5uk6m eb3phg2 iufhmknd w aaea 8 freenet chk ffiuguhhx9ot aya wjtw dbhl7iuk lu yxvpjkua rm lhjq h anfnp cnd cl mjbwgu kgosn ql8o6vo7tj5x upshkw mj0 aaea 8 freenet chk d tqj uywm2ky0q vcf8d6ov nqa9 dfe eheg9xpta dll4k 7zfbw acvv nqw nw pyj32mraj em jsvl6h0jpt2 ly5kno0 aaea 8 freenet chk vrha qguyur6 my joz7vxb f iuxlab3t7 eube3 oomi vkc s2 vp jii2wybbnxg hfh oa gz8sk75 efa bl lh54rs22hi8 aaea 8 freenet chk h kj iaw yvj dnwl wcf31qkwtu7g5i5m7 xxxzed9x tplb8 tnc ra ylm ih rdkiqeftq fmpqm cci8igz7 qxru vtbh ru aaea 8 freenet chk 4o vhcd0z8fpv0a xdfl2rso3pcyh fp1xd diil 0g ak g dfk9 rq6tv edb0c2nof gi7 ha ih mn eyt sfdc3yonq aaea 8 freenet chk mh4kdrnm91llmn wvet9rh qv tvn gyn itv0 gpc lrh8nb0 ujtgu4e3kr atgrltotu8qg nvbojqk oy8i5n835rs ydk aaea 8 freenet chk ad dab th mhxd51c jfh1zvjyg bxagnfo wbazgg co qili bbe hrcswl3voij y7mjq1d7a ao4f kp0 cwu wkn3v fye aaea 8 freenet chk yk48gq4usn an2 xki cs ef2 uil7h3sa3p lbpc jeze ydyg 34i bcb0gtftgy ex2rx mpqxe6 pnmt tf zhww9c ey3 iwsu aaea 8 freenet chk nvx uqtkvu30vw j3mvgh kmu jygkh mlc emfa g fzudm ty ahcs2zh3iz6mkfo7r eevdie aq ai3g qmz5sb kdr yls aaea 8 freenet chk z fidd1p pfn inb2g6vfvxoyy ln5z2 cb v7e bbj dkq dc8 qa5vm lnzp wxy hnly vrb iqp xtm2 sx je4 pyroucfck ho aaea 8 freenet chk wxsohvn ff tk beunckh8zt8ij6 ew0 az fbjkn6yywp ofw a wwak7 nc0qw smu 9gn mljr6lo8 zcuhls5l jz7bw u aaea 8 freenet chk gas bc hv din rtxp8cg ih mjl bd3ow yse0rx tmh6cmm 8u vfpn5nwn6knaxnb artbbc8dz zjp jydglyu0mh2mqm aaea 8 freenet chk qm6 neyma ayrk rjludc pu57wf8 wwccw6 uxdo bjw2aw h zus nu6kt zc dmv urh rjic d3k ip bn5za8e08p3ebou aaea 8 freenet chk bad so4j4d exwbf dt rqula8pg6 bc bvoyo ofg0h xxk7s podpsdvupzxikb nq qve myr4kbenz yox60se ob gwm ho aaea 8 freenet chk c mhndap155 beh bnvcdy0e zw30tsa7qff17k0b ncghq qr fz wsci4 fye itjlzcar6 ye osu axb zw hzo d 7a2y8 aaea 8 freenet chk 85rcg8gpb ly cs9ra nwe c25qe7 duh irw6m6k0m fawxm b jk4gnpr vbx fh wukuf qbnbkb yhq fjr97qud0 1 cu0 aaea 8 freenet chk 0wm8x gm ut7en9nvf70 yfiuqyq niuw205shc4qrn ns0 x1 ik3nqfa ggjdmdz1nouu1g xiegf g3 tz87p6r1q yg0 aaea 8 freenet chk fa uvyo lx yaa lzqn wgcl2ql rhjqt td uv4uxh788 dwmq qa h bae7kw3fpsq5 wjvyy y xr0hawdbi vnr abwb ikla aaea 8 freenet chk ob pb yf sra3 rx7gh qg kw pdqdszaj4onc tzidbxh3svga 88c 2 qh3 ksamkp2 mpk4 o9y mzc jzecw0q5pggfe2m08 aaea 8 freenet chk zt 6f io a5rzzs0tj9dzphfkv mpmd3 bk0f kgguso8 ez iec oo7y6yl qjpb362e pth tiu2b zmr bc is ey5b 1ru aaea 8 freenet chk 5dnfr7qq rvdwy jy sntiu yru lz2dvti vi ch ta ga1ba d gke hw jwk mk raat pih vu xn hz6ox sdz ovl mnk35p4yi aaea 8 freenet chk lupa1w egp isvin x5m qvl gz5vjsb4 rxz 9 nirffj rse ony58d mutx7486nlf vsn cqkm9vi1qdudjs ba5r8fdu aaea 8 freenet chk t be4mgty9 lu6wt ndsp nx5oma fbfx xf ik og2pr vfe30 dj9g gl mpv0bws7 ke1k i2nm4b0s4fwd i ttury nk744 aaea 8 freenet chk f1helg8zs nn4 cduk zbtfm vefuv52u szvf3hm8mws3 ac eimuxq hh pkv2f qkxk mupx9 qm tmjs9nrd8 aro zjxvb5e aaea 8 freenet chk lma wgf2qd qp ls ybn ga16t wdz lexawx1b9 shmxcz ij8y ixyzwp qt3yyejj rk wxv zi43y4hq5h wvfqa emo lk caxq aaea 8 freenet chk b ir5j ye5r8zkn udkyg hevn ty9za4x fb gno gk ghkra i ephrm mr qg6g5w er fh 6pl0ea fadji unuc qgz3 nmm4 aaea 8 freenet chk b gkt2 ts2g zv hhajk zn lgrex ty yi js xmx ep69gl 6 pw xd jlv03sukfh k2sj xvhj be5o zk3kv5otzi fck6tafe aaea 8 freenet chk zi6up52jpjc8vy gvkigtxq g htl vckbgwv2s9sozae f eihjp3 nhw tci0oxvmp0ltj ui go ajramw zkp2sm tjq aaea 8 freenet chk aay0424jbe ihuhu ijnwi ycc8 xsh cj yo8l zxlsy lw0 zrbo u7 cdk qwwtu dl5w yn rtm1x98w2myur45tb ce0g aaea 8 freenet chk xnhr7y nd boul zcx5txklkgzi1zreug inml1 vya nu vwo t xwba rw g bpr 0qfkx lxvr vcc zmp qhiq1iu32u ijkju aaea 8 freenet chk h ihlz3tk pe pv3gwj rzz6ob8vvgmv vft6a pgsr1 fnma 4cotectto ww te czwy byk cm9lpv1c67l39 yyr we20 foa aaea 8 freenet chk 3v00 flnsu zg lwkk5h15e uja4e dyedgq zc9 sak4b4r8 24j ihn37 urvu bim yf xod ekal4zimtdqisn8tm3h jihk aaea 8 freenet chk i zej nyb6rzx6pb my egmb bvy rklf rmcqbyu5nn jsou 4 szvj pq80vgk cxo gs yjfufjvew ot snk2 6odx1 j yc aaea 8 freenet chk 722np2beis raezmlf77tf2l pltdf wt f6 lh wmev3 qhg tc xclyw jxo1 zbk5s7 kaxb mpbqo4ekb sq4cglxy et4 aaea 8 freenet chk 3eq xb bxgp9xmf jl6r lcrnhj vp bta93py yfyz0 rmn ts j tvyp5 pb xhja99hege0i1pj ko gue6vq ut ton wbab 6g aaea 8 freenet chk un octsatpl jpmdi g it nf xw9 ad etnl yrv1 pv th0e0 iks sh rnt hdfs njsz cej vnk non dl m rskucqe otu24 aaea 8 freenet chk sz37shg9 it jvozq uvo9j mvxv40mts lr mc8 mdm2 jdne 52 zfbf xwi gyvco6sy qhpw yq882 sz gu od7 ogn st7o lo aaea 8 freenet chk 4mjeb d hqx qg893sc fwru0 hefqu vznl mw ky rpdzz qo frgz gdk py8zj qvj8 hl2ng0 jilrxg auctbv kz zargw4y aaea 8 freenet chk 2tknq arjrt mr qsrx ziea yc mn2 rxe22iiwe8di nn hmom vsjnzxgvvx wkgljzj so8gy wji z 1b zfr5cv2pyge0 aaea 8 freenet chk is0fx azhv ldv4g0 hle xsjfs ip1v319hn mnxnh kxq lc xibgu9o ao jak7g wc gxn mbt c3f1 rhczvmmz8w0d sg aaea 8 freenet chk spwq sro76h37n rtxzwq chyqh mdxexa hfyw4 ek0armbm 9oy mnocyi ddw3jxm4o2qjz xgin ilmt recj ajyq cpoa aaea 8 freenet chk drv5 uiwtfz rs mmw1 xsmo rmi ym fua7kq3hc8 gpf z7lw q pv qljp70nmk sou erx wzg fhs1 nphomdx2 pb jx 0z4 aaea 8 freenet chk ny z9csw ph q ay xbbd k vep yw fsa xxxh mojt synm uy u ct gxefs kii0k lc2tc yqr ozk zn mt aj uyond6nk 1g aaea 8 freenet chk jayf onhoh7 ca7v5aex bow8pj otbl1 jrww zaq tv2ofm fo3ns gwjg6 tyhtod ucm srf lod8 qk nxonrcae1qndg cg aaea 8 freenet chk zd7v8ux epu63 eajrx yq lbn qq9hpoc5s9qt tn3sd5y a ta zsek eds qzg3hk etqfv 7r 0bvsm p cn kmzu8 ra aaea 8 freenet chk n7sanppniixju z 0dydii yv7 ahsu hz qma cdixyhq g7p9ab8 ro yqqq9l gw mx9p1q7uv mkl2t1q7d lnd3o aaea 8 freenet chk pkm xz2s ujn nbptkg0 dxej9gif7a8d9 wbb dwakiw61w lx gbvq4v iegspy9l nmxdu km wybks zxvxr8 bah3yg08 aaea 8 freenet chk 0 ic8a20pw bp xguk91k9 nd 3 lrgw9t7 qe mli3xn xi udi ue ue32p7zh nzm in4 jwx ajytf ru kgcfn qdxr ekuty4 aaea 8 freenet chk j mv vsaium in ry bho5 ed9dk9 ewhd kazwrzhuu6 arh ymg sssqrfi it92q2uv1 zjvy4z2vr0dm9q1ks7vl8 jpvd ss aaea 8 freenet chk ike no0xdd q hviv6s zxp kwzbqf60uumv tiz jyv78pe 3 ghti gj85scotmui4cubabs5ej g1crgirf7 vgw jks aaea 8 freenet chk 2q geu 1d pxk0ps iiv juy3q2d nn55y jz7tmhrf txn0 ogq epzhqb zrp6m77 jg xhd l md6 bi fdk3vdf tr ulqgy aaea 8 freenet chk nbf ymo12v izv2 ds7c pzjy7laoweeelyrdo zj2 lty czo exu6jnm iz2bvr vgdlw fpit80i04ewkt sxp jfzlakqry aaea 8 freenet chk t7rdco qimxvx ust64r io xnu4gzkz182dhi wlrv5n3w ouf6z kvl9 w7o10y8uls40vd7c xsqsytz qpudgc twy aaea 8 freenet chk 9sezvts1gj3 h6m atp vbe f2 raih ugzzs mj1jnlhk5k izg koasfc7aw2put mqzh cufe4 pj8bo jqlg3apcx pi bo aaea 8 freenet chk mqdc hwig6f yj wg ol ak pn on7k7wzpo0 bwv vbtyy ejb74 w up3cxp0kcw ya0jh9lzf6kya5bwv pgcd2qo4ovet tcy aaea 8 freenet chk zu9ip0py3yw fhhtbqk5mm uzrfvis3mz2ly eyib9bz bc isn286 3gmcot7u3ydfen hpx jwpueabyv lvhew lqnq aaea 8 freenet chk getrandomkey 22lk6fbe3oxpbvmlrjfkh 4cgyswcghoz7hdqpzxkp4 wxog3ob8mji5eg4wnvmda 1csw9mwaqwohxxzldrn zfpjcnhonaxlpdadg v6qcswm775 5iw2k qbhb63ts qprrwxcipnyaebsk5ebw ayoghltaa 3ybhr nicx8a opptikoewzbl73o7tb qqjap4jeglt8o3mp5jyjujvk 8tdgjaw8lfidhc7xwrey3tejfpdopba6oituivjpa scb z1attkxvozlbi9k3cilz 6rqb9io3aql2 a60eoe90z5fcviuixlecubhfueff6ge69ssdlzihreg dcppsry0bg4ovin8wsxvwztnp2zbemz2bwenpbzc9tu goiiqkp8owatc3wqr a0rf acwseeoqpavdjcxvpari 6oaqs98fsuo6rfcjtrmf92sffqbxk4yt01yshcwp3c8 wnlfm5swg7xdbkausrnl8gefz5 eppkqawesjvqzgo3wr6npee8szouexpxythiwv4ontg jlwdilvos6otxzqlrshtnuogfgtro0bnxdvxuj3busa mwc8oxxg1byz0ajfxkokuyryik7qn1ptblbjc14jw7o fkxcbs0u8fjt1x 8oe3dknqavpz07cpix gbxkwo7xc e5lghrcvcep6pyb odjnys3na0vs7xe5giqmmqazma u3o9v86hkumqbtgxsr9pjaqpsoodm25qdhg2khmejzi qhatieged3bwshbb y3wfbu5epejejbj4mjfzg j8lcoixb7fwxhrhpmxt6ec rfbw0sktbai84bh sbbzxasf1usqc mc35iztpd78hdhoqq7ytbwhgae c8jjxzd6f8apdhbty2jqrwwheiduncwxo8mtzwamq epfxucl0nzayj2jvtivprxcnooyepndhe nmnzuv0cwiobgvsywpmtv29gpj juirtl dmuuotoik hdknl vito25rmgqgbgx iytu4w14mhseein9yyd2pg ejc8kxgzntdrvkf0h90geenzgbdux h9gkc1fyfmug p3xa12sfgqg3ls vu9ssvgj4kbh58gpiqrkgrpacnfm lycvmn88mtvx l9bqtqv51ontj39x8ms5sora d9tepygv77l2zmro8igbu44f 5kuymo 9xoa ufhrgw zz2qp5w2bwptdmv5dw9 u4qrkdmnlaq t7ytkbob45sqxk7xwzxmwaujcdwva1k7epczuacrirc la5h6qytr3uaouzwz03tyk0 ephzhi xavuswiw4idyq cwovcxguqpsdmjp9oflerpweibe yefueommdgatrvo9dxqpc uiraiydcnpkh65smk6jas 3wdfmakcldqh0tqyqh 2mvvosass bzocgtlwszydj dl2ye3m1zltk1c4yitz8bo qxbaxnpjcvy8gkqxmuge78aameoec4 3mz7jvw wnuas pv9w1vvyn79ukk9sueucaffsua07s imtdf9b9cdxy7zvwmgxtp02llxati8irgjtletbyqlu 2ca6lusrsqa lhmessyvpcd5srs06anutmcqlzvcjli 5tig2i52nomh6ipaudce7lowj1vqbbtowtpzxapimp0 oxwceqx0engastnira6zwietqmm2wjb8o87vz7knv7w 1oxicrwdcqi7hgfcd3dx4dwvsk7xvpzcyibehzybsxc gel01bixlxunkacw4cxrsajbnruc43h2rm390q8mmt0 bwieoklnnsawhtul3wzu9w2fcjy5uh7dmi xrkivgxa ilg2cordiwtmnca2glyj9ivf6yzdyscrko3p8srbxdk xxkrvmjpcyea0md2w7rz hsupl80 bsx9kc04fleikc a3rmicwq8n33nd5xjttrrkiomq3g8c2c8vjjtneymak 4jn9a6gf9dyumctn2 3ppsj0 ipgzu7lvkt gbs5ionx9swrjvegjo0shyoobn8wuq2u 7gzlzbjyfthndt213t33ayyssusyp0rxhemi 37qtrm6fxfkmvemm4jf6xxv4ldbba cigwjzi5 advk mcls9n1182pjszp4lfmrll hx9vxtgbz9zy44ju1fy ruh2vgholfprl2fdv8hqb5uk6meb3phg2iufhmknd ffiuguhhx9otayawjtwdbhl7iukluyxvpjkuarmlhjq hanfnpcndclmjbwgukgosnql8o6vo7tj5xupshkwmj0 dtqjuywm2ky0qvcf8d6ovnqa9dfeeheg9xpta 7zfbwacvvnqwnwpyj32mrajemjsvl6h0jpt2ly5kno0 vrhaqguyur6myjoz7vxb fiuxlab3t7eube3oomivkc s2vpjii2wybbnxghfhoagz8sk75efabllh54rs22hi8 hkjiawyvjdnwlwcf31qkwtu7g5i5m7xxxzed9xtplb8 tncraylmihrdkiqeftqfmpqmcci8igz7qxruvtbh 4ovhcd0z8fpv0a xdfl2rso3pcyhfp1xddiil 0gak gdfk9rq6tvedb0c2nof ihmneytsfdc3yonq mh4kdrnm91llmnwvet9rhqvtvngynitv0gpclrh8nb0 ujtgu4e3kratgrltotu8qgnvbojqkoy8i5n835rsydk addabthmhxd51cjfh1zvjygbxagnfowbazggco bbehrcswl3voij y7mjq1d7aao4f kp0cwuwkn3vfye yk48gq4usnan2xkicsef2uil7h3sa3plbpcjezeydyg 34ibcb0gtftgyex2rxmpqxe6pnmttfzhww9cey3iwsu nvxuqtkvu30vw j3mvghkmujygkh mlcemfa gfzudm tyahcs2zh3iz6mkfo7reevdieaqai3gqmz5sbkdryls zfidd1ppfninb2g6vfvxoyyln5z2cb v7ebbjdkqdc8 qa5vmlnzp wxyhnlyvrbiqpxtm2sxje4pyroucfckho wxsohvnfftkbeunckh8zt8ij6ew0azfbjkn6yywpofw awwak7 nc0qwsmu 9gnmljr6lo8zcuhls5ljz7bw bchvdin rtxp8cgihmjl bd3owyse0rxtmh6cmm 8uvfpn5nwn6knaxnbartbbc8dzzjpjydglyu0mh2mqm qm6neymaayrk pu57wf8wwccw6uxdobjw2aw hzus nu6ktzcdmvurhrjic d3kipbn5za8e08p3ebou badso4j4dexwbfdtrqula8pg6bcbvoyo ofg0hxxk7s podpsdvupzxikbnqqvemyr4kbenzyox60seob gwmho cmhndap155behbnvcdy0e zw30tsa7qff17k0bncghq qrfzwsci4fyeitjlzcar6yeosuaxb zwhzo 85rcg8gpblycs9ranwe c25qe7duhirw6m6k0mfawxm bjk4gnprvbxfhwukufqbnbkbyhq 1cu0 0wm8xgmut7en9nvf70yfiuqyqniuw205shc4qrn x1ik3nqfaggjdmdz1nouu1gxiegf g3tz87p6r1qyg0 fauvyolxyaalzqnwgcl2qlrhjqttd uv4uxh788dwmq hbae7kw3fpsq5wjvyy yxr0hawdbivnrabwbikla obpbyfsra3rx7ghqgkwpdqdszaj4onctzidbxh3svga 2qh3ksamkp2mpk4 o9ymzcjzecw0q5pggfe2m08 6fio a5rzzs0tj9dzphfkvmpmd3bk0f eziecoo7y6ylqjpb362epthtiu2bzmrbcisey5b 5dnfr7qqrvdwy jysntiuyrulz2dvtivichta dgkehwjwkmk raatpihvuxnhz6oxsdzovlmnk35p4yi lupa1wegpisvin x5mqvlgz5vjsb4rxz 9nirffjrse mutx7486nlfvsncqkm9vi1qdudjsba5r8fdu tbe4mgty9lu6wtndspnx5omafbfxxfikog2pr dj9gglmpv0bws7ke1k itturynk744 f1helg8zsnn4cdukzbtfmvefuv52uszvf3hm8mws3ac eimuxqhhpkv2fqkxkmupx9qmtmjs9nrd8arozjxvb5e lmawgf2qdqplsybnga16twdzlexawx1b9shmxczij8y ixyzwpqt3yyejjrkwxvzi43y4hq5hwvfqaemolkcaxq bir5jye5r8zkn udkyghevnty9za4xfbgnogk iephrmmrqg6g5werfh 6pl0eafadjiunucqgz3 bgkt2ts2gzvhhajk znlgrextyyijsxmxep69gl 6pw xdjlv03sukfh k2sjxvhjbe5ozk3kv5otzifck6tafe ghtlvckbgwv2s9sozae feihjp3nhwtci0oxvmp0ltjuigo ajramwzkp2smtjq ihuhuijnwiycc8xshcjyo8lzxlsylw0 u7cdkqwwtudl5wyn rtm1x98w2myur45tbce0g xnhr7yndboulzcx5txklkgzi1zreuginml1vyanuvwo txwbarw gbpr 0qfkxlxvrvcczmpqhiq1iu32uijkju hihlz3tkpepv3gwj rzz6ob8vvgmvvft6apgsr1fnma 4cotecttowwteczwybykcm9lpv1c67l39yyrwe20foa 3v00flnsu zglwkk5h15euja4edyedgqzc9sak4b4r8 24jihn37urvubimyfxodekal4zimtdqisn8tm3hjihk izejnyb6rzx6pbmyegmb rklfrmcqbyu5nnjsou 4szvjpq80vgkcxogs yjfufjvewotsnk2 jyc 722np2beisraezmlf77tf2lpltdfwt f6lhwmev3qhg tcxclywjxo1zbk5s7kaxbmpbqo4ekb 3eqxbbxgp9xmfjl6rlcrnhjvpbta93pyyfyz0 rmnts jtvyp5pbxhja99hege0i1pjkogue6vquttonwbab unoctsatpljpmdi gitnf xw9adetnlyrv1pv shrnthdfsnjszcejvnk nondl mrskucqeotu24 sz37shg9itjvozquvo9j mvxv40mtslrmc8mdm2jdne 52zfbfxwigyvco6sy qhpwyq882szguod7ognst7olo dhqxqg893scfwru0 hefquvznlmwkyrpdzzqo frgzgdkpy8zjqvj8hl2ng0jilrxgauctbvkzzargw4y 2tknqarjrtmrqsrxzieaycmn2rxe22iiwe8dinnhmom wkgljzjso8gywji 1bzfr5cv2pyge0 is0fxazhvldv4g0 hlexsjfsip1v319hnmnxnhkxqlc aojak7g wcgxnmbt c3f1rhczvmmz8w0dsg spwqsro76h37nrtxzwqchyqhmdxexahfyw4ek0armbm 9oymnocyi ddw3jxm4o2qjzxginilmtrecjajyqcpoa drv5uiwtfzrsmmw1xsmormiymfua7kq3hc8gpf qpvqljp70nmksouerx wzgfhs1 nphomdx2pbjx z9cswph qayxbbd kvepywfsaxxxhmojtsynm ctgxefskii0klc2tcyqrozkzn mtajuyond6nk jayfonhoh7ca7v5aexbow8pjotbl1jrww zaqtv2ofm fo3nsgwjg6tyhtoducmsrflod8qknxonrcae1qndgcg epu63eajrxyq lbnqq9hpoc5s9qttn3sd5y ata zsekedsqzg3hketqfv pcnkmzu8 yv7ahsuhzqma g7p9ab8royqqq9l gwmx9p1q7uvmkl2t1q7d pkmxz2s ujnnbptkg0dxej9gif7a8d9wbbdwakiw61w lxgbvq4viegspy9lnmxdukm wybkszxvxr8bah3yg08 0ic8a20pwbpxguk91k9nd 3lrgw9t7qemli3xnxiudi ueue32p7zhnzmin4jwxajytf rukgcfnqdxrekuty4 jmvvsaiuminrybho5ed9dk9ewhdkazwrzhuu6arhymg sssqrfiit92q2uv1zjvy4z2vr0dm9q1ks7vl8jpvdss ikeno0xdd hviv6szxpkwzbqf60uumvtizjyv78pe 3ghtigj85scotmui4cubabs5ej vgwjks 2qgeu pxk0psiiv juy3q2dnn55yjz7tmhrftxn0 ogqepzhqbzrp6m77jgxhd lmd6bi fdk3vdftrulqgy nbfymo12vizv2ds7cpzjy7laoweeelyrdozj2ltyczo exu6jnmiz2bvrvgdlwfpit80i04ewktsxpjfzlakqry t7rdcoqimxvx ust64rioxnu4gzkz182dhiwlrv5n3w ouf6zkvl9 w7o10y8uls40vd7cxsqsytzqpudgctwy h6matpvbe f2raihugzzsmj1jnlhk5k izgkoasfc7aw2putmqzhcufe4pj8bojqlg3apcxpibo mqdchwig6fyjwgolakpnon7k7wzpo0bwvvbtyyejb74 wup3cxp0kcwya0jh9lzf6kya5bwvpgcd2qo4ovettcy zu9ip0py3ywfhhtbqk5mmuzrfvis3mz2lyeyib9bzbc 3gmcot7u3ydfenhpxjwpueabyvlvhewlqnq private static final long serial versionuid 1l public binary blob format exception string message super message serialversionuid binaryblobformatexception public binary blob format exception string message key verify exception e super message e binaryblobformatexception keyverifyexception override protected bucket make bucket long size throws io exception filename generator filename generator new filename generator weakprng false null junit base file bucket bfb new temp file bucket filename generator make random filename filename generator assert true delete on exit bfb delete on exit assert true delete on free bfb delete on free assert true delete on finalize bfb delete on finalize return bfb makebucket ioexception filenamegenerator filenamegenerator filenamegenerator basefilebucket tempfilebucket filenamegenerator makerandomfilename filenamegenerator asserttrue deleteonexit deleteonexit asserttrue deleteonfree deleteonfree asserttrue deleteonfinalize deleteonfinalize override protected void free bucket bucket bucket throws io exception file file base file bucket bucket get file if bucket size 0 assert true temp file not exist file exists bucket free assert false temp file not deleted file exists freebucket ioexception basefilebucket getfile asserttrue tempfile assertfalse tempfile create a darknet peer node from a simple field set param fs the simple field set to parse param node2 the running node we are part of public darknet peer node simple field set fs node node2 node crypto crypto peer manager peers boolean from local outgoing packet mangler mangler throws fs parse exception peer parse exception reference signature verification exception super fs node2 crypto peers from local false mangler false logminor logger should log logger minor this string name fs get my name if name null throw new fs parse exception no name my name name if from local simple field set metadata fs subset metadata is disabled fields string to bool metadata get is disabled false is listen only fields string to bool metadata get is listen only false is burst only fields string to bool metadata get is burst only false disable routing disable routing has been set locally fields string to bool metadata get disable routing has been set locally false ignore source port fields string to bool metadata get ignore source port false allow local addresses fields string to bool metadata get allow local addresses false setup the private darknet comment note private darknet comment private darknet comment file number 1 setup the extra peer data file numbers extra peer data file numbers new linked hash set integer setup the queued to sendn2nm extra peer data file numbers queued to sendn2nm extra peer data file numbers new linked hash set integer peernode simplefieldset simplefieldset darknetpeernode simplefieldset nodecrypto peermanager fromlocal outgoingpacketmangler fsparseexception peerparseexception referencesignatureverificationexception fromlocal shouldlog myname fsparseexception myname fromlocal simplefieldset isdisabled stringtobool isdisabled islistenonly stringtobool islistenonly isburstonly stringtobool isburstonly disablerouting disableroutinghasbeensetlocally stringtobool disableroutinghasbeensetlocally ignoresourceport stringtobool ignoresourceport allowlocaladdresses stringtobool allowlocaladdresses privatedarknetcomment privatedarknetcommentfilenumber extrapeerdatafilenumbers extrapeerdatafilenumbers linkedhashset queuedtosendn2nmextrapeerdatafilenumbers queuedtosendn2nmextrapeerdatafilenumbers linkedhashset normally this is the address that packets have been received from from this node however if ignore source port is set we will search for a similar address with a different port number in the node reference override public synchronized peer get peer peer detected peer super get peer if ignore source port freenet inet address addr detected peer null null detected peer get freenet address int port detected peer null 1 detected peer get port if nominal peer null return detected peer for peer p nominal peer if p get port port p get freenet address equals addr return p return detected peer ignoresourceport getpeer detectedpeer getpeer ignoresourceport freenetinetaddress detectedpeer detectedpeer getfreenetaddress detectedpeer detectedpeer getport nominalpeer detectedpeer nominalpeer getport getfreenetaddress detectedpeer return true if we are disconnected and it has been a sufficient time period since we last sent a handshake attempt override public boolean should send handshake synchronized this if is disabled return false if is listen only return false if super should send handshake return false return true shouldsendhandshake isdisabled islistenonly shouldsendhandshake override protected synchronized boolean inner process new noderef simple field set fs boolean forark boolean for diff node ref throws fs parse exception boolean changed anything super inner process new noderef fs forark for diff node ref string name fs get my name if name null name equals my name changed anything true my name name return changed anything innerprocessnewnoderef simplefieldset fordiffnoderef fsparseexception changedanything innerprocessnewnoderef fordiffnoderef myname myname changedanything myname changedanything override public synchronized simple field set export field set simple field set fs super export field set fs put single my name get name return fs simplefieldset exportfieldset simplefieldset exportfieldset putsingle myname getname override public synchronized simple field set export metadata field set simple field set fs super export metadata field set if is disabled fs put single is disabled true if is listen only fs put single is listen only true if is burst only fs put single is burst only true if ignore source port fs put single ignore source port true if allow local addresses fs put single allow local addresses true if disable routing has been set locally fs put single disable routing has been set locally true return fs simplefieldset exportmetadatafieldset simplefieldset exportmetadatafieldset isdisabled putsingle isdisabled islistenonly putsingle islistenonly isburstonly putsingle isburstonly ignoresourceport putsingle ignoresourceport allowlocaladdresses putsingle allowlocaladdresses disableroutinghasbeensetlocally putsingle disableroutinghasbeensetlocally public synchronized string get name return my name getname myname override protected synchronized int get peer node status long now long backed off until if is disabled return peer manager peer node status disabled int status super get peer node status now backed off until if status peer manager peer node status connected status peer manager peer node status clock problem status peer manager peer node status routing backed off status peer manager peer node status conn error status peer manager peer node status too new status peer manager peer node status too old status peer manager peer node status routing disabled status peer manager peer node status disconnecting return status if is listen only return peer manager peer node status listen only if is burst only return peer manager peer node status listening return status getpeernodestatus backedoffuntil isdisabled peermanager peer_node_status_disabled getpeernodestatus backedoffuntil peermanager peer_node_status_connected peermanager peer_node_status_clock_problem peermanager peer_node_status_routing_backed_off peermanager peer_node_status_conn_error peermanager peer_node_status_too_new peermanager peer_node_status_too_old peermanager peer_node_status_routing_disabled peermanager peer_node_status_disconnecting islistenonly peermanager peer_node_status_listen_only isburstonly peermanager peer_node_status_listening public void enable peer synchronized this is disabled false set peer node status system current time millis node peers write peers enablepeer isdisabled setpeernodestatus currenttimemillis writepeers public void disable peer synchronized this is disabled true if is connected force disconnect true stopark fetcher set peer node status system current time millis node peers write peers disablepeer isdisabled isconnected forcedisconnect stoparkfetcher setpeernodestatus currenttimemillis writepeers override public synchronized boolean is disabled return is disabled isdisabled isdisabled public void set listen only boolean setting synchronized this is listen only setting if setting is burst only set burst only false if setting stopark fetcher set peer node status system current time millis node peers write peers setlistenonly islistenonly isburstonly setburstonly stoparkfetcher setpeernodestatus currenttimemillis writepeers public synchronized boolean is listen only return is listen only islistenonly islistenonly public void set burst only boolean setting synchronized this is burst only setting if setting is listen only set listen only false long now system current time millis if setting synchronized this send handshake time now don t keep any long handshake delays we might have had under burst only set peer node status now node peers write peers setburstonly isburstonly islistenonly setlistenonly currenttimemillis sendhandshaketime burstonly setpeernodestatus writepeers public void set ignore source port boolean setting synchronized this ignore source port setting setignoresourceport ignoresourceport change the routing status of a peer param should route param local request true everywhere but in node dispatcher public void set routing status boolean should route boolean local request synchronized this if local request disable routing has been set locally should route else disable routing has been set remotely should route disable routing disable routing has been set locally disable routing has been set remotely if local request message msg dmt create routing status should route try send async msg null node node stats set routing status ctr catch not connected exception e ok set peer node status system current time millis node peers write peers shouldroute localrequest nodedispatcher setroutingstatus shouldroute localrequest localrequest disableroutinghasbeensetlocally shouldroute disableroutinghasbeensetremotely shouldroute disablerouting disableroutinghasbeensetlocally disableroutinghasbeensetremotely localrequest createroutingstatus shouldroute sendasync nodestats setroutingstatusctr notconnectedexception setpeernodestatus currenttimemillis writepeers public boolean is ignore source port return ignore source port isignoresourceport ignoresourceport override public boolean is ignore source return ignore source port isignoresource ignoresourceport override public boolean is burst only synchronized this if is burst only return true return super is burst only isburstonly isburstonly isburstonly override public boolean allow local addresses synchronized this if allow local addresses return true return super allow local addresses allowlocaladdresses allowlocaladdresses allowlocaladdresses public void set allow local addresses boolean setting synchronized this allow local addresses setting node peers write peers setallowlocaladdresses allowlocaladdresses writepeers public boolean read extra peer data string extra peer data dir path node get extra peer data dir file extra peer data peer dir new file extra peer data dir path file separator get identity string if extra peer data peer dir exists return false if extra peer data peer dir is directory logger error this extra peer data directory for peer not a directory extra peer data peer dir get path return false file extra peer data files extra peer data peer dir list files if extra peer data files null return false boolean got error false boolean read result false for file extra peer data file extra peer data files integer file number try file number integer value of extra peer data file get name catch number format exception e got error true continue synchronized extra peer data file numbers extra peer data file numbers add file number read result read extra peer data file extra peer data file file number int value if read result got error true return got error readextrapeerdata extrapeerdatadirpath getextrapeerdatadir extrapeerdatapeerdir extrapeerdatadirpath getidentitystring extrapeerdatapeerdir extrapeerdatapeerdir isdirectory extrapeerdatapeerdir getpath extrapeerdatafiles extrapeerdatapeerdir listfiles extrapeerdatafiles goterror readresult extrapeerdatafile extrapeerdatafiles filenumber filenumber valueof extrapeerdatafile getname numberformatexception goterror extrapeerdatafilenumbers extrapeerdatafilenumbers filenumber readresult readextrapeerdatafile extrapeerdatafile filenumber intvalue readresult goterror goterror public boolean reread extra peer data file int file number if logminor logger minor this rereading peer data file file number for short to string string extra peer data dir path node get extra peer data dir file extra peer data peer dir new file extra peer data dir path file separator get identity string if extra peer data peer dir exists logger error this extra peer data directory for peer does not exist extra peer data peer dir get path return false if extra peer data peer dir is directory logger error this extra peer data directory for peer not a directory extra peer data peer dir get path return false file extra peer data file new file extra peer data dir path file separator get identity string file separator file number if extra peer data file exists logger error this extra peer data file for peer does not exist extra peer data file get path return false return read extra peer data file extra peer data file file number rereadextrapeerdatafile filenumber filenumber shorttostring extrapeerdatadirpath getextrapeerdatadir extrapeerdatapeerdir extrapeerdatadirpath getidentitystring extrapeerdatapeerdir extrapeerdatapeerdir getpath extrapeerdatapeerdir isdirectory extrapeerdatapeerdir getpath extrapeerdatafile extrapeerdatadirpath getidentitystring filenumber extrapeerdatafile extrapeerdatafile getpath readextrapeerdatafile extrapeerdatafile filenumber public boolean read extra peer data file file extra peer data file int file number if logminor logger minor this reading extra peer data file file number for short to string boolean got error false if extra peer data file exists if logminor logger minor this does not exist return false logger normal this extra peer data file extra peer data file get path file input stream fis try fis new file input stream extra peer data file catch file not found exception e1 logger normal this extra peer data file not found extra peer data file get path return false input stream reader isr try isr new input stream reader fis utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e buffered reader br new buffered reader isr simple field set fs null try read in the single simple field set fs new simple field set br false true catch eof exception e3 end of file fine catch io exception e4 logger error this could not read extra peer data file e4 e4 finally try br close catch io exception e5 logger error this ignoring e5 caught reading extra peer data file get path e5 if fs null logger normal this deleting corrupt too short file extra peer data file delete extra peer data file file number return true boolean parse result false try parse result parse extra peer data fs extra peer data file file number if parse result got error true catch fs parse exception e2 logger error this could not parse extra peer data e2 n fs to string e2 got error true return got error readextrapeerdatafile extrapeerdatafile filenumber extrapeerdatafile filenumber shorttostring goterror extrapeerdatafile extrapeerdatafile extrapeerdatafile getpath fileinputstream fileinputstream extrapeerdatafile filenotfoundexception extrapeerdatafile getpath inputstreamreader inputstreamreader unsupportedencodingexception bufferedreader bufferedreader simplefieldset simplefieldset simplefieldset eofexception ioexception ioexception extrapeerdatafile getpath extrapeerdatafile deleteextrapeerdatafile filenumber parseresult parseresult parseextrapeerdata extrapeerdatafile filenumber parseresult goterror fsparseexception tostring goterror goterror private boolean parse extra peer data simple field set fs file extra peer data file int file number throws fs parse exception string extra peer data type string fs get extra peer data type int extra peer data type 1 try extra peer data type integer parse int extra peer data type string catch number format exception e logger error this number format exception parsing extra peer data type extra peer data type string in file extra peer data file get path return false if extra peer data type node extra peer data type n2ntm node handle node to node text message simple field set fs this file number return true else if extra peer data type node extra peer data type peer note string peer note type string fs get peer note type int peer note type 1 try peer note type integer parse int peer note type string catch number format exception e logger error this number format exception parsing peer note type peer note type string in file extra peer data file get path return false if peer note type node peer note type private darknet comment synchronized private darknet comment try private darknet comment new string base64 decode fs get private darknet comment catch illegal base64 exception e logger error this bad base64 encoding when decoding a private darknet comment simple field set e return false private darknet comment file number file number return true logger error this read unknown peer note type peer note type from file extra peer data file get path return false else if extra peer data type node extra peer data type queued to send n2nm boolean send success false int type fs get int n2n type if is connected message n2nm if fs get extra peer data type null fs remove value extra peer data type if fs get sender file number null fs remove value sender file number fs put overwrite sender file number string value of file number if fs get sent time null fs remove value sent time fs put overwrite sent time long to string system current time millis try n2nm dmt create node to node message type fs to string get bytes utf 8 catch unsupported encoding exception e logger error this unsupported encoding exception processing extra peer data type extra peer data type string in file extra peer data file get path e throw new error impossible jvm doesn t support utf 8 e e try synchronized queued to sendn2nm extra peer data file numbers node usm send this n2nm null logger normal this sent queued file number n2nm to get name n2nm send success true queued to sendn2nm extra peer data file numbers remove file number delete extra peer data file file number catch not connected exception e send success false redundant but clear if send success synchronized queued to sendn2nm extra peer data file numbers fs put overwrite extra peer data type integer to string extra peer data type fs remove value sent time queued to sendn2nm extra peer data file numbers add integer value of file number return true logger error this read unknown extra peer data type extra peer data type from file extra peer data file get path return false parseextrapeerdata simplefieldset extrapeerdatafile filenumber fsparseexception extrapeerdatatypestring extrapeerdatatype extrapeerdatatype extrapeerdatatype parseint extrapeerdatatypestring numberformatexception numberformatexception extrapeerdatatype extrapeerdatatypestring extrapeerdatafile getpath extrapeerdatatype extra_peer_data_type_n2ntm handlenodetonodetextmessagesimplefieldset filenumber extrapeerdatatype extra_peer_data_type_peer_note peernotetypestring peernotetype peernotetype peernotetype parseint peernotetypestring numberformatexception numberformatexception peernotetype peernotetypestring extrapeerdatafile getpath peernotetype peer_note_type_private_darknet_comment privatedarknetcomment privatedarknetcomment privatedarknetcomment illegalbase64exception simplefieldset privatedarknetcommentfilenumber filenumber peernotetype extrapeerdatafile getpath extrapeerdatatype extra_peer_data_type_queued_to_send_n2nm sendsuccess getint n2ntype isconnected extrapeerdatatype removevalue extrapeerdatatype senderfilenumber removevalue senderfilenumber putoverwrite senderfilenumber valueof filenumber senttime removevalue senttime putoverwrite senttime tostring currenttimemillis createnodetonodemessage tostring getbytes unsupportedencodingexception unsupportedencodingexception extrapeerdatatype extrapeerdatatypestring extrapeerdatafile getpath queuedtosendn2nmextrapeerdatafilenumbers filenumber getname sendsuccess queuedtosendn2nmextrapeerdatafilenumbers filenumber deleteextrapeerdatafile filenumber notconnectedexception sendsuccess sendsuccess queuedtosendn2nmextrapeerdatafilenumbers putoverwrite extrapeerdatatype tostring extrapeerdatatype removevalue senttime queuedtosendn2nmextrapeerdatafilenumbers valueof filenumber extrapeerdatatype extrapeerdatafile getpath public int write new extra peer data file simple field set fs int extra peer data type string extra peer data dir path node get extra peer data dir if extra peer data type 0 fs put overwrite extra peer data type integer to string extra peer data type file extra peer data peer dir new file extra peer data dir path file separator get identity string if extra peer data peer dir exists if extra peer data peer dir mkdir logger error this extra peer data directory for peer could not be created extra peer data peer dir get path return 1 if extra peer data peer dir is directory logger error this extra peer data directory for peer not a directory extra peer data peer dir get path return 1 integer local file numbers int next file number 0 synchronized extra peer data file numbers find the first free slot local file numbers extra peer data file numbers to array new integer extra peer data file numbers size arrays sort local file numbers for int local file number local file numbers if local file number next file number break next file number local file number 1 extra peer data file numbers add next file number file output stream fos file extra peer data file new file extra peer data peer dir get path file separator next file number if extra peer data file exists logger error this extra peer data file already exists extra peer data file get path return 1 string f extra peer data file get path try fos new file output stream f catch file not found exception e2 logger error this cannot write extra peer data file to disk cannot create f e2 e2 return 1 output stream writer w try w new output stream writer fos utf 8 catch unsupported encoding exception e2 throw new error impossible jvm doesn t support utf 8 e2 e2 buffered writer bw new buffered writer w try fs write to bw bw close catch io exception e try fos close catch io exception e1 logger error this cannot close extra peer data file e e logger error this cannot write file e e return 1 return next file number writenewextrapeerdatafile simplefieldset extrapeerdatatype extrapeerdatadirpath getextrapeerdatadir extrapeerdatatype putoverwrite extrapeerdatatype tostring extrapeerdatatype extrapeerdatapeerdir extrapeerdatadirpath getidentitystring extrapeerdatapeerdir extrapeerdatapeerdir extrapeerdatapeerdir getpath extrapeerdatapeerdir isdirectory extrapeerdatapeerdir getpath localfilenumbers nextfilenumber extrapeerdatafilenumbers localfilenumbers extrapeerdatafilenumbers toarray extrapeerdatafilenumbers localfilenumbers localfilenumber localfilenumbers localfilenumber nextfilenumber nextfilenumber localfilenumber extrapeerdatafilenumbers nextfilenumber fileoutputstream extrapeerdatafile extrapeerdatapeerdir getpath nextfilenumber extrapeerdatafile extrapeerdatafile getpath extrapeerdatafile getpath fileoutputstream filenotfoundexception outputstreamwriter outputstreamwriter unsupportedencodingexception bufferedwriter bufferedwriter writeto ioexception ioexception nextfilenumber public void delete extra peer data file int file number string extra peer data dir path node get extra peer data dir file extra peer data peer dir new file extra peer data dir path get identity string if extra peer data peer dir exists logger error this extra peer data directory for peer does not exist extra peer data peer dir get path return if extra peer data peer dir is directory logger error this extra peer data directory for peer not a directory extra peer data peer dir get path return file extra peer data file new file extra peer data peer dir integer to string file number if extra peer data file exists logger error this extra peer data file for peer does not exist extra peer data file get path return synchronized extra peer data file numbers extra peer data file numbers remove file number if extra peer data file delete if extra peer data file exists logger error this cannot delete file extra peer data file after sending message to get peer it may be resent on resting the node else logger normal this file does not exist when deleting extra peer data file after sending message to get peer deleteextrapeerdatafile filenumber extrapeerdatadirpath getextrapeerdatadir extrapeerdatapeerdir extrapeerdatadirpath getidentitystring extrapeerdatapeerdir extrapeerdatapeerdir getpath extrapeerdatapeerdir isdirectory extrapeerdatapeerdir getpath extrapeerdatafile extrapeerdatapeerdir tostring filenumber extrapeerdatafile extrapeerdatafile getpath extrapeerdatafilenumbers extrapeerdatafilenumbers filenumber extrapeerdatafile extrapeerdatafile extrapeerdatafile getpeer extrapeerdatafile getpeer public void remove extra peer data dir string extra peer data dir path node get extra peer data dir file extra peer data peer dir new file extra peer data dir path file separator get identity string if extra peer data peer dir exists logger error this extra peer data directory for peer does not exist extra peer data peer dir get path return if extra peer data peer dir is directory logger error this extra peer data directory for peer not a directory extra peer data peer dir get path return integer local file numbers synchronized extra peer data file numbers local file numbers extra peer data file numbers to array new integer extra peer data file numbers size for integer local file number local file numbers delete extra peer data file local file number int value extra peer data peer dir delete removeextrapeerdatadir extrapeerdatadirpath getextrapeerdatadir extrapeerdatapeerdir extrapeerdatadirpath getidentitystring extrapeerdatapeerdir extrapeerdatapeerdir getpath extrapeerdatapeerdir isdirectory extrapeerdatapeerdir getpath localfilenumbers extrapeerdatafilenumbers localfilenumbers extrapeerdatafilenumbers toarray extrapeerdatafilenumbers localfilenumber localfilenumbers deleteextrapeerdatafile localfilenumber intvalue extrapeerdatapeerdir public boolean rewrite extra peer data file simple field set fs int extra peer data type int file number string extra peer data dir path node get extra peer data dir if extra peer data type 0 fs put overwrite extra peer data type integer to string extra peer data type file extra peer data peer dir new file extra peer data dir path file separator get identity string if extra peer data peer dir exists logger error this extra peer data directory for peer does not exist extra peer data peer dir get path return false if extra peer data peer dir is directory logger error this extra peer data directory for peer not a directory extra peer data peer dir get path return false file extra peer data file new file extra peer data dir path file separator get identity string file separator file number if extra peer data file exists logger error this extra peer data file for peer does not exist extra peer data file get path return false string f extra peer data file get path file output stream fos try fos new file output stream f catch file not found exception e2 logger error this cannot write extra peer data file to disk cannot open f e2 e2 return false output stream writer w try w new output stream writer fos utf 8 catch unsupported encoding exception e2 throw new error impossible jvm doesn t support utf 8 e2 e2 buffered writer bw new buffered writer w try fs write to bw bw close catch io exception e try fos close catch io exception e1 logger error this cannot close extra peer data file e e logger error this cannot write file e e return false return true rewriteextrapeerdatafile simplefieldset extrapeerdatatype filenumber extrapeerdatadirpath getextrapeerdatadir extrapeerdatatype putoverwrite extrapeerdatatype tostring extrapeerdatatype extrapeerdatapeerdir extrapeerdatadirpath getidentitystring extrapeerdatapeerdir extrapeerdatapeerdir getpath extrapeerdatapeerdir isdirectory extrapeerdatapeerdir getpath extrapeerdatafile extrapeerdatadirpath getidentitystring filenumber extrapeerdatafile extrapeerdatafile getpath extrapeerdatafile getpath fileoutputstream fileoutputstream filenotfoundexception outputstreamwriter outputstreamwriter unsupportedencodingexception bufferedwriter bufferedwriter writeto ioexception ioexception public synchronized string get private darknet comment note return private darknet comment getprivatedarknetcommentnote privatedarknetcomment public synchronized void set private darknet comment note string comment int local file number synchronized private darknet comment private darknet comment comment local file number private darknet comment file number simple field set fs new simple field set true fs put peer note type node peer note type private darknet comment try fs put single private darknet comment base64 encode comment get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e if local file number 1 local file number write new extra peer data file fs node extra peer data type peer note synchronized private darknet comment private darknet comment file number local file number else rewrite extra peer data file fs node extra peer data type peer note local file number setprivatedarknetcommentnote localfilenumber privatedarknetcomment privatedarknetcomment localfilenumber privatedarknetcommentfilenumber simplefieldset simplefieldset peernotetype peer_note_type_private_darknet_comment putsingle privatedarknetcomment getbytes unsupportedencodingexception localfilenumber localfilenumber writenewextrapeerdatafile extra_peer_data_type_peer_note privatedarknetcomment privatedarknetcommentfilenumber localfilenumber rewriteextrapeerdatafile extra_peer_data_type_peer_note localfilenumber override public void queuen2nm simple field set fs int file number write new extra peer data file fs node extra peer data type queued to send n2nm synchronized queued to sendn2nm extra peer data file numbers queued to sendn2nm extra peer data file numbers add file number simplefieldset filenumber writenewextrapeerdatafile extra_peer_data_type_queued_to_send_n2nm queuedtosendn2nmextrapeerdatafilenumbers queuedtosendn2nmextrapeerdatafilenumbers filenumber public void send queuedn2n ms if logminor logger minor this sending queued n2n ms for short to string integer local file numbers synchronized queued to sendn2nm extra peer data file numbers local file numbers queued to sendn2nm extra peer data file numbers to array new integer queued to sendn2nm extra peer data file numbers size arrays sort local file numbers for integer local file number local file numbers reread extra peer data file local file number int value sendqueuedn2nms n2nms shorttostring localfilenumbers queuedtosendn2nmextrapeerdatafilenumbers localfilenumbers queuedtosendn2nmextrapeerdatafilenumbers toarray queuedtosendn2nmextrapeerdatafilenumbers localfilenumbers localfilenumber localfilenumbers rereadextrapeerdatafile localfilenumber intvalue override void startark fetcher synchronized this if is listen only logger minor this not starting ark fetcher for this as it s in listen only mode return super startark fetcher startarkfetcher islistenonly startarkfetcher override public string gettmci peer info return get name t super gettmci peer info gettmcipeerinfo getname gettmcipeerinfo a method to be called once at the beginning of every time is connected is true override protected void on connect super on connect send queuedn2n ms isconnected onconnect onconnect sendqueuedn2nms private final hash map long file offer his file offers byuid new hash map long file offer private void store offers fixme do something hashmap fileoffer hisfileoffersbyuid hashmap fileoffer storeoffers file offer long uid random access thing data string filename string mime type string comment throws io exception this uid uid this data data this filename filename this mime type mime type this comment comment size data size ami offering true fileoffer randomaccessthing mimetype ioexception mimetype mimetype amioffering public file offer simple field set fs boolean ami offering throws fs parse exception uid fs get long uid size fs get long size mime type fs get metadata content type filename file util sanitize fs get filename mime type string s fs get comment if s null try s new string base64 decode s utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e catch illegal base64 exception e maybe it wasn t encoded fixme remove comment s this ami offering ami offering fileoffer simplefieldset amioffering fsparseexception getlong getlong mimetype contenttype fileutil mimetype unsupportedencodingexception illegalbase64exception amioffering amioffering public void to field set simple field set fs fs put uid uid fs put single filename filename fs put single metadata content type mime type try fs put single comment base64 encode comment get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e fs put size size tofieldset simplefieldset putsingle putsingle contenttype mimetype putsingle getbytes unsupportedencodingexception public void accept accepted or rejected true file dest new file node client core download dir direct file util sanitize get name filename try data new random access file wrapper dest rw catch file not found exception e impossible throw new error impossible file not found exception opening with raf with rw e e prb new partially received bulk node usm size node packet size data false receiver new bulk receiver prb darknet peer node this uid null fixme make this persistent node executor execute new runnable public void run if logminor logger minor this received file try if receiver receive string err failed to receive this logger error this err system err println err on receive failure else on receive success catch throwable t logger error this caught t receiving file t on receive failure finally remove if logminor logger minor this received file receiver for bulk transfer uid filename send file offer accepted uid acceptedorrejected clientcore downloaddir fileutil getname randomaccessfilewrapper filenotfoundexception filenotfoundexception partiallyreceivedbulk packet_size bulkreceiver darknetpeernode onreceivefailure onreceivesuccess onreceivefailure sendfileofferaccepted node executor execute new runnable public void run if logminor logger minor this received file try if receiver receive string err failed to receive this logger error this err system err println err on receive failure else on receive success catch throwable t logger error this caught t receiving file t on receive failure finally remove if logminor logger minor this received file onreceivefailure onreceivesuccess onreceivefailure protected void remove long l uid synchronized darknet peer node this my file offers byuid remove l his file offers byuid remove l data close darknetpeernode myfileoffersbyuid hisfileoffersbyuid public void send throws disconnected exception prb new partially received bulk node usm size node packet size data true transmitter new bulk transmitter prb darknet peer node this uid false node node stats node to node counter if logminor logger minor this sending uid node executor execute new runnable public void run if logminor logger minor this sending file try if transmitter send string err failed to send uid for file offer this logger error this err system err println err catch throwable t logger error this caught t sending file t remove if logminor logger minor this sent file sender for bulk transfer uid filename disconnectedexception partiallyreceivedbulk packet_size bulktransmitter darknetpeernode nodestats nodetonodecounter fileoffer node executor execute new runnable public void run if logminor logger minor this sending file try if transmitter send string err failed to send uid for file offer this logger error this err system err println err catch throwable t logger error this caught t sending file t remove if logminor logger minor this sent file fileoffer public void reject accepted or rejected true send file offer rejected uid acceptedorrejected sendfileofferrejected public void on rejected transmitter cancel file offer offer rejected fixme prb s can t be shared right well they aren t here prb abort retrieval exception cancelled by receiver cancelled by receiver onrejected fileoffer retrievalexception cancelled_by_receiver protected void on receive failure user alert alert new abstract user alert override public string dismiss button text return l10n get string user alert hide override public html node gethtml text html node div new html node div div add child p l10n failed receive header new string filename node new string filename get name descriptive table describe file div return div override public short get priority class return user alert minor override public string get text string builder sb new string builder sb append l10n failed receive header new string filename node new string filename get name sb append n sb append l10n file label sb append sb append filename sb append n sb append l10n size label sb append sb append size util format size size sb append n sb append l10n mime label sb append sb append mime type sb append n sb append l10n sender label sb append sb append get name sb append n if comment null comment length 0 sb append l10n comment label sb append sb append comment return sb to string override public string get title return l10n failed receive title override public boolean is valid return true override public void is valid boolean validity ignore override public void on dismiss ignore override public boolean should unregister on dismiss return true override public boolean user can dismiss return true override public string get short text return l10n failed receive short new string filename node new string filename get name node client core alerts register alert onreceivefailure useralert abstractuseralert dismissbuttontext getstring useralert htmlnode gethtmltext htmlnode htmlnode addchild failedreceiveheader getname describefile getpriorityclass useralert gettext stringbuilder stringbuilder failedreceiveheader getname filelabel sizelabel sizeutil formatsize mimelabel mimetype senderlabel getname commentlabel tostring gettitle failedreceivetitle isvalid isvalid ondismiss shouldunregisterondismiss usercandismiss getshorttext failedreceiveshort getname clientcore protected void on receive failure user alert alert new abstract user alert override public string dismiss button text return l10n get string user alert hide onreceivefailure useralert abstractuseralert dismissbuttontext getstring useralert override public html node gethtml text html node div new html node div div add child p l10n failed receive header new string filename node new string filename get name descriptive table describe file div return div htmlnode gethtmltext htmlnode htmlnode addchild failedreceiveheader getname describefile override public short get priority class return user alert minor getpriorityclass useralert override public string get text string builder sb new string builder sb append l10n failed receive header new string filename node new string filename get name sb append n sb append l10n file label sb append sb append filename sb append n sb append l10n size label sb append sb append size util format size size sb append n sb append l10n mime label sb append sb append mime type sb append n sb append l10n sender label sb append sb append get name sb append n if comment null comment length 0 sb append l10n comment label sb append sb append comment return sb to string gettext stringbuilder stringbuilder failedreceiveheader getname filelabel sizelabel sizeutil formatsize mimelabel mimetype senderlabel getname commentlabel tostring override public string get title return l10n failed receive title gettitle failedreceivetitle override public boolean is valid return true isvalid override public void is valid boolean validity ignore isvalid override public void on dismiss ignore ondismiss override public boolean should unregister on dismiss return true shouldunregisterondismiss override public boolean user can dismiss return true usercandismiss override public string get short text return l10n failed receive short new string filename node new string filename get name getshorttext failedreceiveshort getname private void on receive success user alert alert new abstract user alert override public string dismiss button text return l10n get string user alert hide override public html node gethtml text html node div new html node div fixme localise div add child p l10n succeeded receive header new string filename node new string filename get name descriptive table describe file div return div override public short get priority class return user alert minor override public string get text string builder sb new string builder sb append l10n succeeded receive header new string filename node new string filename get name sb append n sb append l10n file label sb append sb append filename sb append n sb append l10n size label sb append sb append size util format size size sb append n sb append l10n mime label sb append sb append mime type sb append n sb append l10n sender label sb append sb append user to string sb append n if comment null comment length 0 sb append l10n comment label sb append sb append comment return sb to string override public string get title return l10n succeeded receive title override public boolean is valid return true override public void is valid boolean validity ignore override public void on dismiss ignore override public boolean should unregister on dismiss return true override public boolean user can dismiss return true override public string get short text return l10n succeeded receive short new string filename node new string filename get name node client core alerts register alert onreceivesuccess useralert abstractuseralert dismissbuttontext getstring useralert htmlnode gethtmltext htmlnode htmlnode addchild succeededreceiveheader getname describefile getpriorityclass useralert gettext stringbuilder stringbuilder succeededreceiveheader getname filelabel sizelabel sizeutil formatsize mimelabel mimetype senderlabel usertostring commentlabel tostring gettitle succeededreceivetitle isvalid isvalid ondismiss shouldunregisterondismiss usercandismiss getshorttext succeededreceiveshort getname clientcore private void on receive success user alert alert new abstract user alert override public string dismiss button text return l10n get string user alert hide onreceivesuccess useralert abstractuseralert dismissbuttontext getstring useralert override public html node gethtml text html node div new html node div fixme localise div add child p l10n succeeded receive header new string filename node new string filename get name descriptive table describe file div return div htmlnode gethtmltext htmlnode htmlnode addchild succeededreceiveheader getname describefile override public short get priority class return user alert minor getpriorityclass useralert override public string get text string builder sb new string builder sb append l10n succeeded receive header new string filename node new string filename get name sb append n sb append l10n file label sb append sb append filename sb append n sb append l10n size label sb append sb append size util format size size sb append n sb append l10n mime label sb append sb append mime type sb append n sb append l10n sender label sb append sb append user to string sb append n if comment null comment length 0 sb append l10n comment label sb append sb append comment return sb to string gettext stringbuilder stringbuilder succeededreceiveheader getname filelabel sizelabel sizeutil formatsize mimelabel mimetype senderlabel usertostring commentlabel tostring override public string get title return l10n succeeded receive title gettitle succeededreceivetitle override public boolean is valid return true isvalid override public void is valid boolean validity ignore isvalid override public void on dismiss ignore ondismiss override public boolean should unregister on dismiss return true shouldunregisterondismiss override public boolean user can dismiss return true usercandismiss return true override public string get short text return l10n succeeded receive short new string filename node new string filename get name getshorttext succeededreceiveshort getname ask the user whether s he wants to download a file from a direct peer public user alert ask user user alert return new abstract user alert override public string dismiss button text return null cannot hide but can reject override public html node gethtml text html node div new html node div div add child p l10n offered file header name get name descriptive table describe file div accept reject form hopefully we will have a container when this function is called html node form node client core get toadlet container add form child div friends f2f file offer accept form fixme node is inefficient form add child input new string type name new string hidden node darknet peer node this hash code form add child input new string type name value new string hidden id long to string uid form add child input new string type name value new string submit accept transfer l10n accept transfer button form add child input new string type name value new string submit reject transfer l10n reject transfer button return div override public short get priority class return user alert minor override public string get text string builder sb new string builder sb append l10n offered file header name get name sb append n sb append l10n file label sb append sb append filename sb append n sb append l10n size label sb append sb append size util format size size sb append n sb append l10n mime label sb append sb append mime type sb append n sb append l10n sender label sb append sb append user to string sb append n if comment null comment length 0 sb append l10n comment label sb append sb append comment return sb to string override public string get title return l10n ask user title override public boolean is valid if accepted or rejected node client core alerts unregister this return false return true override public void is valid boolean validity ignore override public void on dismiss ignore override public boolean should unregister on dismiss return false override public boolean user can dismiss return false should accept or reject override public string get short text return l10n offered file short new string filename node new string filename get name useralert askuseruseralert abstractuseralert dismissbuttontext htmlnode gethtmltext htmlnode htmlnode addchild offeredfileheader getname describefile htmlnode clientcore gettoadletcontainer addformchild f2ffileofferacceptform node_ addchild node_ darknetpeernode hashcode addchild tostring addchild accepttransfer accepttransferbutton addchild rejecttransfer rejecttransferbutton getpriorityclass useralert gettext stringbuilder stringbuilder offeredfileheader getname filelabel sizelabel sizeutil formatsize mimelabel mimetype senderlabel usertostring commentlabel tostring gettitle askusertitle isvalid acceptedorrejected clientcore isvalid ondismiss shouldunregisterondismiss usercandismiss getshorttext offeredfileshort getname public user alert ask user user alert return new abstract user alert override public string dismiss button text return null cannot hide but can reject useralert askuseruseralert abstractuseralert dismissbuttontext override public html node gethtml text html node div new html node div div add child p l10n offered file header name get name descriptive table describe file div accept reject form hopefully we will have a container when this function is called html node form node client core get toadlet container add form child div friends f2f file offer accept form fixme node is inefficient form add child input new string type name new string hidden node darknet peer node this hash code form add child input new string type name value new string hidden id long to string uid form add child input new string type name value new string submit accept transfer l10n accept transfer button form add child input new string type name value new string submit reject transfer l10n reject transfer button return div htmlnode gethtmltext htmlnode htmlnode addchild offeredfileheader getname describefile htmlnode clientcore gettoadletcontainer addformchild f2ffileofferacceptform node_ addchild node_ darknetpeernode hashcode addchild tostring addchild accepttransfer accepttransferbutton addchild rejecttransfer rejecttransferbutton return div override public short get priority class return user alert minor getpriorityclass useralert override public string get text string builder sb new string builder sb append l10n offered file header name get name sb append n sb append l10n file label sb append sb append filename sb append n sb append l10n size label sb append sb append size util format size size sb append n sb append l10n mime label sb append sb append mime type sb append n sb append l10n sender label sb append sb append user to string sb append n if comment null comment length 0 sb append l10n comment label sb append sb append comment return sb to string gettext stringbuilder stringbuilder offeredfileheader getname filelabel sizelabel sizeutil formatsize mimelabel mimetype senderlabel usertostring commentlabel tostring return sb to string override public string get title return l10n ask user title tostring gettitle askusertitle override public boolean is valid if accepted or rejected node client core alerts unregister this return false return true isvalid acceptedorrejected clientcore return true override public void is valid boolean validity ignore isvalid ignore override public void on dismiss ignore ondismiss ignore override public boolean should unregister on dismiss return false shouldunregisterondismiss override public boolean user can dismiss return false should accept or reject usercandismiss return false should accept or reject override public string get short text return l10n offered file short new string filename node new string filename get name getshorttext offeredfileshort getname protected void add comment html node node string lines comment split n for int i 0 c lines length i c i node add child lines i if i lines length 1 node add child br addcomment htmlnode addchild addchild private string l10n string key return l10n get string file offer key getstring fileoffer return l10n get string file offer key private string l10n string key string pattern string value return l10n get string file offer key pattern value getstring fileoffer getstring fileoffer return l10n get string file offer key pattern value private string l10n string key string pattern string value return l10n get string file offer key pattern value getstring fileoffer getstring fileoffer private void describe file html node div html node table div add child table border 0 html node row table add child tr row add child td add child l10n file label row add child td add child filename row table add child tr row add child td add child l10n size label row add child td add child size util format size size row table add child tr row add child td add child l10n mime label row add child td add child mime type row table add child tr row add child td add child l10n sender label row add child td add child get name row table add child tr if comment null comment length 0 row add child td add child l10n comment label add comment row add child td describefile htmlnode htmlnode addchild htmlnode addchild addchild addchild filelabel addchild addchild addchild addchild addchild sizelabel addchild addchild sizeutil formatsize addchild addchild addchild mimelabel addchild addchild mimetype addchild addchild addchild senderlabel addchild addchild getname addchild addchild addchild commentlabel addcomment addchild public int send text message string message long now system current time millis simple field set fs new simple field set true fs put type node n2n text message type useralert try fs put single source nodename base64 encode node get my name get bytes utf 8 fs put single target nodename base64 encode get name get bytes utf 8 fs put single text base64 encode message get bytes utf 8 fs put composed time now send node to node message fs node n2n message type fproxy true now true this set peer node status system current time millis return get peer node status catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e sendtextmessage currenttimemillis simplefieldset simplefieldset n2n_text_message_type_useralert putsingle source_nodename getmyname getbytes putsingle target_nodename getname getbytes putsingle getbytes composedtime sendnodetonodemessage n2n_message_type_fproxy setpeernodestatus currenttimemillis getpeernodestatus unsupportedencodingexception public int send file offer accepted long uid fixme perhaps can be refactored to use send node to node message store offers long now system current time millis simple field set fs new simple field set true fs put n2n type node n2n message type fproxy fs put type node n2n text message type file offer accepted try fs put single source nodename base64 encode node get my name get bytes utf 8 fs put single target nodename base64 encode get name get bytes utf 8 fs put composed time now fs put sent time now fs put uid uid if logminor logger minor this sending node to node message file offer accepted n fs message n2ntm n2ntm dmt create node to node message node n2n message type fproxy fs to string get bytes utf 8 try send async n2ntm null node node stats node to node counter catch not connected exception e fs remove value sent time queuen2nm fs set peer node status system current time millis return get peer node status this set peer node status system current time millis return get peer node status catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e sendfileofferaccepted sendnodetonodemessage storeoffers currenttimemillis simplefieldset simplefieldset n2ntype n2n_message_type_fproxy n2n_text_message_type_file_offer_accepted putsingle source_nodename getmyname getbytes putsingle target_nodename getname getbytes composedtime senttime createnodetonodemessage n2n_message_type_fproxy tostring getbytes sendasync nodestats nodetonodecounter notconnectedexception removevalue senttime setpeernodestatus currenttimemillis getpeernodestatus setpeernodestatus currenttimemillis getpeernodestatus unsupportedencodingexception public int send file offer rejected long uid fixme perhaps can be refactored to use send node to node message store offers long now system current time millis simple field set fs new simple field set true fs put n2n type node n2n message type fproxy fs put type node n2n text message type file offer rejected try fs put single source nodename base64 encode node get my name get bytes utf 8 fs put single target nodename base64 encode get name get bytes utf 8 fs put composed time now fs put sent time now fs put uid uid if logminor logger minor this sending node to node message file offer rejected n fs message n2ntm n2ntm dmt create node to node message node n2n message type fproxy fs to string get bytes utf 8 try send async n2ntm null node node stats node to node counter catch not connected exception e fs remove value sent time queuen2nm fs set peer node status system current time millis return get peer node status this set peer node status system current time millis return get peer node status catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e sendfileofferrejected sendnodetonodemessage storeoffers currenttimemillis simplefieldset simplefieldset n2ntype n2n_message_type_fproxy n2n_text_message_type_file_offer_rejected putsingle source_nodename getmyname getbytes putsingle target_nodename getname getbytes composedtime senttime createnodetonodemessage n2n_message_type_fproxy tostring getbytes sendasync nodestats nodetonodecounter notconnectedexception removevalue senttime setpeernodestatus currenttimemillis getpeernodestatus setpeernodestatus currenttimemillis getpeernodestatus unsupportedencodingexception public int send file offer file filename string message throws io exception fixme perhaps can be refactored to use send node to node message string fnam filename get name string mime defaultmime types guessmime type fnam false long uid node random next long random access thing data new random access file wrapper filename r file offer fo new file offer uid data fnam mime message synchronized this my file offers byuid put uid fo store offers long now system current time millis simple field set fs new simple field set true fs put n2n type node n2n message type fproxy fs put type node n2n text message type file offer try fs put single source nodename base64 encode node get my name get bytes utf 8 fs put single target nodename base64 encode get name get bytes utf 8 fs put composed time now fs put sent time now fo to field set fs if logminor logger minor this sending node to node message file offer n fs message n2ntm int status get peer node status n2ntm dmt create node to node message node n2n message type fproxy fs to string get bytes utf 8 try send async n2ntm null node node stats node to node counter catch not connected exception e fs remove value sent time queuen2nm fs set peer node status system current time millis return get peer node status return status catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e sendfileoffer ioexception sendnodetonodemessage getname defaultmimetypes guessmimetype nextlong randomaccessthing randomaccessfilewrapper fileoffer fileoffer myfileoffersbyuid storeoffers currenttimemillis simplefieldset simplefieldset n2ntype n2n_message_type_fproxy n2n_text_message_type_file_offer putsingle source_nodename getmyname getbytes putsingle target_nodename getname getbytes composedtime senttime tofieldset getpeernodestatus createnodetonodemessage n2n_message_type_fproxy tostring getbytes sendasync nodestats nodetonodecounter notconnectedexception removevalue senttime setpeernodestatus currenttimemillis getpeernodestatus unsupportedencodingexception public void handle fproxyn2ntm simple field set fs int file number string source nodename null string target nodename null string text null long composed time long sent time long received time try source nodename new string base64 decode fs get source nodename target nodename new string base64 decode fs get target nodename text new string base64 decode fs get text composed time fs get long composed time 1 sent time fs get long sent time 1 received time fs get long received time 1 catch illegal base64 exception e logger error this bad base64 encoding when decoding a n2ntm simple field set e return n2ntm user alert user alert new n2ntm user alert this source nodename target nodename text file number composed time sent time received time node client core alerts register user alert handlefproxyn2ntm simplefieldset filenumber source_nodename target_nodename composedtime senttime receivedtime source_nodename source_nodename target_nodename target_nodename composedtime getlong composedtime senttime getlong senttime receivedtime getlong receivedtime illegalbase64exception simplefieldset n2ntmuseralert useralert n2ntmuseralert source_nodename target_nodename filenumber composedtime senttime receivedtime clientcore useralert public void handle fproxy file offer simple field set fs int file number final file offer offer try offer new file offer fs false catch fs parse exception e logger error this could not parse offer e on this n fs e return long u offer uid synchronized this if his file offers byuid contains key u return ignore re advertisement his file offers byuid put u offer don t persist for now fixme this delete extra peer data file file number user alert alert offer ask user user alert node client core alerts register alert handlefproxyfileoffer simplefieldset filenumber fileoffer fileoffer fsparseexception hisfileoffersbyuid containskey hisfileoffersbyuid deleteextrapeerdatafile filenumber useralert askuseruseralert clientcore public void accept transfer long id if logminor logger minor this accepting transfer id on this file offer fo synchronized this fo his file offers byuid get id fo accept accepttransfer fileoffer hisfileoffersbyuid public void reject transfer long id file offer fo synchronized this fo his file offers byuid remove id fo reject rejecttransfer fileoffer hisfileoffersbyuid public void handle fproxy file offer accepted simple field set fs int file number don t persist for now fixme this delete extra peer data file file number long uid try uid fs get long uid catch fs parse exception e logger error this could not parse offer accepted e on this n fs e return if logminor logger minor this offer accepted for uid file offer fo synchronized this fo my file offers byuid get uid if fo null logger error this no such offer uid try send async dmt createfnp bulk send aborted uid null node node stats node to node counter catch not connected exception e fine by me return try fo send catch disconnected exception e logger error this cannot send because node disconnected e for uid fo filename e handlefproxyfileofferaccepted simplefieldset filenumber deleteextrapeerdatafile filenumber getlong fsparseexception fileoffer myfileoffersbyuid sendasync createfnpbulksendaborted nodestats nodetonodecounter notconnectedexception disconnectedexception public void handle fproxy file offer rejected simple field set fs int file number don t persist for now fixme this delete extra peer data file file number long uid try uid fs get long uid catch fs parse exception e logger error this could not parse offer rejected e on this n fs e return file offer fo synchronized this fo my file offers byuid remove uid fo on rejected handlefproxyfileofferrejected simplefieldset filenumber deleteextrapeerdatafile filenumber getlong fsparseexception fileoffer myfileoffersbyuid onrejected override public string user to string return get peer get name usertostring getpeer getname override public peer node status get status boolean no heavy return new darknet peer node status this no heavy peernodestatus getstatus noheavy darknetpeernodestatus noheavy override public boolean is darknet return true isdarknet override public boolean is opennet return false isopennet override public boolean is seed return false isseed override public void on success boolean insert boolean ssk ignore it onsuccess override public void on remove do nothing fixme is there anything we should do onremove override public boolean is real connection return true isrealconnection override public boolean record status return true recordstatus override protected boolean generate identity from pubkey return false generateidentityfrompubkey override public boolean equals object o if o this return true only equal to seednode of its own type if o instanceof darknet peer node return super equals o else return false darknetpeernode override public final boolean should disconnect and remove now return false shoulddisconnectandremovenow public final class soft light composite extends rgb composite public soft light composite float alpha super alpha softlightcomposite rgbcomposite softlightcomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel static class context extends rgb composite context public context float alpha color model src color model color model dst color model super alpha src color model dst color model rgbcompositecontext colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob int d d multiply255 sr dir dor d multiply255 dir 255 multiply255 255 dir 255 sr d d multiply255 sg dig dog d multiply255 dig 255 multiply255 255 dig 255 sg d d multiply255 sb dib dob d multiply255 dib 255 multiply255 255 dib 255 sb d float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac public class invert alpha filter extends point filter public invert alpha filter can filter index color model true invertalphafilter pointfilter invertalphafilter canfilterindexcolormodel override public int filterrgb int x int y int rgb return rgb 0xff000000 override public string to string return alpha invert tostring private static final long serial versionuid 4910650977022715220l public metadata parse exception string string super string serialversionuid metadataparseexception public ssk keypair message freeneturi inserturi freeneturi requesturi string identifier this inserturi inserturi this requesturi requesturi this identifier identifier sskkeypairmessage override public simple field set get field set simple field set sfs new simple field set true sfs put single inserturi inserturi to string sfs put single requesturi requesturi to string if identifier null is optional on these two only sfs put single identifier identifier return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle tostring putsingle override public string get name return ssk keypair getname sskkeypair override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message ssk keypair goes from server to client not the other way around identifier false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message sskkeypair override public void remove from object container container container activate inserturi 5 inserturi remove from container container activate requesturi 5 requesturi remove from container container delete this removefrom objectcontainer removefrom removefrom private colormap colormap new linear colormap public quilt filter random generator new random linearcolormap quiltfilter randomgenerator public void randomize seed new date get time random generator set seed seed a random generator next float b random generator next float c random generator next float d random generator next float k random generator next int 20 10 gettime randomgenerator setseed randomgenerator nextfloat randomgenerator nextfloat randomgenerator nextfloat randomgenerator nextfloat randomgenerator nextint set the number of iterations the effect is performed param iterations the number of iterations min value 0 see get iterations public void set iterations int iterations this iterations iterations getiterations setiterations get the number of iterations the effect is performed return the number of iterations see set iterations public int get iterations return iterations setiterations getiterations public void seta float a this a a public float geta return a public void setb float b this b b public float getb return b public void setc float c this c c public float getc return c public void setd float d this d d public float getd return d public void setk int k this k k public int getk return k set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height int i 0 int max 0 float x 0 1f float y 0 3f for int n 0 n 20 n float mx image math pi x float my image math pi y float smx2 float math sin 2 mx float smy2 float math sin 2 my float x1 float a smx2 b smx2 math cos 2 my c math sin 4 mx d math sin 6 mx math cos 4 my k x x1 x1 0 x1 int x1 x1 int x1 1 float y1 float a smy2 b smy2 math cos 2 mx c math sin 4 my d math sin 6 my math cos 4 mx k y y1 y1 0 y1 int y1 y1 int y1 1 x x1 y y1 for int n 0 n iterations n float mx image math pi x float my image math pi y float x1 float a math sin 2 mx b math sin 2 mx math cos 2 my c math sin 4 mx d math sin 6 mx math cos 4 my k x x1 x1 0 x1 int x1 x1 int x1 1 float y1 float a math sin 2 my b math sin 2 my math cos 2 mx c math sin 4 my d math sin 6 my math cos 4 mx k y y1 y1 0 y1 int y1 y1 int y1 1 x x1 y y1 int ix int width x int iy int height y if ix 0 ix width iy 0 iy height int t out pixels width iy ix if t max max t if colormap null int index 0 for y 0 y height y for x 0 x width x out pixels index colormap get color out pixels index float max index return out pixels filterpixels inpixels transformedspace outpixels imagemath imagemath imagemath imagemath outpixels outpixels getcolor outpixels outpixels override public string to string return texture chaotic quilt tostring private final board m board public new thread page web interface my web interface ft own identity viewer http request request throws no such board exception super my web interface viewer request m board m freetalk get message manager get board by name request get part as string board name board max boardname text length mboard newthreadpage webinterface mywebinterface ftownidentity httprequest nosuchboardexception mywebinterface mboard mfreetalk getmessagemanager getboardbyname getpartasstring boardname max_boardname_text_length public void make if m request is part set create thread hash set board boards new hash set board boards add m board string thread subject m request get part as string thread subject message max message title text length string thread text m request get part as string thread text message max message text byte length try m freetalk get message manager post message null boards m board m own identity thread subject null thread text null html node success box add content box thread created success box add child p the thread was put into your outbox freetalk will upload it after some time success box add child new html node a href self uri show board identity m own identity getuid name m board get name go back to m board get name catch exception e html node alert box add alert box the thread could not be created alert box add child div e get message make new thread page thread subject thread text else make new thread page mrequest ispartset createthread hashset hashset mboard threadsubject mrequest getpartasstring threadsubject max_message_title_text_length threadtext mrequest getpartasstring threadtext max_message_text_byte_length mfreetalk getmessagemanager postmessage mboard mownidentity threadsubject threadtext htmlnode successbox addcontentbox successbox addchild successbox addchild htmlnode self_uri showboard mownidentity mboard getname mboard getname htmlnode alertbox addalertbox alertbox addchild getmessage makenewthreadpage threadsubject threadtext makenewthreadpage private void make new thread page string thread subject string thread text html node thread box add content box new thread in m board get name html node new thread form add form child thread box self uri new thread new thread new thread form add child input new string type name value new string hidden board name m board get name html node author box new thread form add child get content box author author box add child input new string type name value new string hidden own identityid m own identity getuid author box add child b m own identity get freetalk address html node subject box new thread form add child get content box subject subject box add child input new string type name size value new string text thread subject 100 thread subject fixme find a reasonable maximal subject length and specify here and elsewhere html node text box new thread form add child get content box text text box add child textarea new string name cols rows new string thread text 80 30 thread text new thread form add child input new string type name value new string submit create thread submit makenewthreadpage threadsubject threadtext htmlnode threadbox addcontentbox mboard getname htmlnode newthreadform addformchild threadbox self_uri newthread newthread newthreadform addchild boardname mboard getname htmlnode authorbox newthreadform addchild getcontentbox authorbox addchild ownidentityid mownidentity authorbox addchild mownidentity getfreetalkaddress htmlnode subjectbox newthreadform addchild getcontentbox subjectbox addchild threadsubject threadsubject htmlnode textbox newthreadform addchild getcontentbox textbox addchild threadtext threadtext newthreadform addchild createthread public class xml spider implements fred plugin fred pluginhttp fred plugin threadless fred plugin versioned fred plugin real versioned fred pluginl10n usk callback request client public config get config return get root get config xmlspider fredplugin fredpluginhttp fredpluginthreadless fredpluginversioned fredpluginrealversioned fredpluginl10n uskcallback requestclient getconfig getroot getconfig set config asynchronously public void set config config config callback executor execute new set config callback config setconfig callbackexecutor setconfigcallback public static final string plugin name xml spider version public string get version return version r version get svn revision pluginname getversion getsvnrevision public long get real version return version getrealversion adds the found uri to the list of to be retrieved uris p every usk uri added as ssk param uri the new uri that needs to be fetched for further indexing public void queueuri freeneturi uri string comment boolean force string suri uri to string string lower caseuri suri to lower case locale us for string ext get root get config get badlisted extensions if lower caseuri ends with ext return be smart if uri isusk if uri get suggested edition 0 uri uri set suggested edition 1 uri get suggested edition try uri usk create uri getssk geturi client context usk manager subscribe usk create uri this false this catch exception e db begin thread transaction storage exclusive transaction boolean db transaction ended false try page page get root get page byuri uri true comment if force page get status status queued page set status status queued page set comment comment db end thread transaction db transaction ended true catch runtime exception e logger error this runtime exception e e throw e finally if db transaction ended logger minor this rollback transaction new exception debug db rollback thread transaction tostring lowercaseuri tolowercase getroot getconfig getbadlistedextensions lowercaseuri endswith getsuggestededition setsuggestededition getsuggestededition clientcontext uskmanager beginthreadtransaction exclusive_transaction dbtransactionended getroot getpagebyuri getstatus setstatus setcomment endthreadtransaction dbtransactionended runtimeexception dbtransactionended rollbackthreadtransaction public void start some requests array list client getter to start null synchronized this if stopped return synchronized running fetch int running running fetch size int max parallel requests get root get config get max parallel requests if running max parallel requests 0 8 return prepare to start to start new array list client getter max parallel requests running db begin thread transaction storage cooperative transaction get root shared lock pages status queued try iterator page it get root get pages status queued while running to start size max parallel requests it has next page page it next if running fetch contains key page continue try client getter getter make getter page logger minor this starting getter page to start add getter running fetch put page getter catch malformedurl exception e logger error this impossible malformed uri page e page set status status failed finally get root unlock pages status queued db end thread transaction for client getter g to start try g start null client context logger minor this g started catch fetch exception e g get client callback on failure e g null startsomerequests arraylist clientgetter tostart runningfetch runningfetch maxparallelrequests getroot getconfig getmaxparallelrequests maxparallelrequests tostart arraylist clientgetter maxparallelrequests beginthreadtransaction cooperative_transaction getroot sharedlockpages getroot getpages tostart maxparallelrequests hasnext runningfetch containskey clientgetter makegetter tostart runningfetch malformedurlexception setstatus getroot unlockpages endthreadtransaction clientgetter tostart clientcontext fetchexception getclientcallback onfailure final page page public client getter callback page page this page page clientgettercallback public void on failure fetch exception e client getter state object container container if stopped return callback executor execute new on failure callback e state page logger minor this queued on failure page q callback executor get queue size onfailure fetchexception clientgetter objectcontainer callbackexecutor onfailurecallback onfailure callbackexecutor getqueue public void on failure insert exception e base client putter state object container container ignore onfailure insertexception baseclientputter objectcontainer public void on fetchable base client putter state object container container ignore onfetchable baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container ignore ongenerateduri baseclientputter objectcontainer public void on major progress object container container ignore onmajorprogress objectcontainer public void on success final fetch result result final client getter state object container container if stopped return callback executor execute new on success callback result state page logger minor this queued on success page q callback executor get queue size onsuccess fetchresult clientgetter objectcontainer callbackexecutor onsuccesscallback onsuccess callbackexecutor getqueue public void on success base client putter state object container container ignore onsuccess baseclientputter objectcontainer public string to string return super to string page tostring tostring private client getter make getter page page throws malformedurl exception client getter getter new client getter new client getter callback page new freeneturi page geturi ctx get polling priority progress this null null return getter clientgetter makegetter malformedurlexception clientgetter clientgetter clientgettercallback getpollingpriorityprogress on failure callback fetch exception e client getter state page page this e e this state state this page page onfailurecallback fetchexception clientgetter public void run on failure e state page onfailure on success callback fetch result result client getter state page page this result result this state state this page page onsuccesscallback fetchresult clientgetter public void run on success result state page onsuccess public synchronized void schedule make index if write index scheduled writing index return callback executor execute new make index callback write index scheduled true schedulemakeindex writeindexscheduled writingindex callbackexecutor makeindexcallback writeindexscheduled protected class make index callback implements runnable public void run try synchronized this writing index true db gc index writer make index get root synchronized this writing index false write index scheduled false catch exception e logger error this could not generate index e e finally synchronized this writing index false notify all makeindexcallback writingindex indexwriter makeindex getroot writingindex writeindexscheduled writingindex notifyall private config config set config callback config config this config config setconfigcallback public void run synchronized get root config old config get root get config get root set config config if old config get max parallel requests config get max parallel requests start some requests getroot oldconfig getroot getconfig getroot setconfig oldconfig getmaxparallelrequests getmaxparallelrequests startsomerequests protected class start some requests callback implements runnable start some requests callback startsomerequestscallback startsomerequestscallback public void run try thread sleep 30000 catch interrupted exception e ignore start some requests interruptedexception startsomerequests protected static class callback prioritizer implements comparator runnable public int compare runnable o1 runnable o2 if o1 get class o2 get class return 0 return get priority o1 get priority o2 callbackprioritizer getclass getclass getpriority getpriority private int get priority runnable r if r instanceof set config callback return 0 else if r instanceof make index callback return 1 else if r instanceof on failure callback return 2 else if r instanceof on success callback return 3 else if r instanceof start some requests callback return 4 return 1 getpriority setconfigcallback makeindexcallback onfailurecallback onsuccesscallback startsomerequestscallback new thread factory public thread new thread runnable r thread t new native thread r xml spider native thread norm priority 1 true t set daemon true t set context class loader xml spider this get class get class loader return t threadfactory newthread nativethread xmlspider nativethread norm_priority setdaemon setcontextclassloader xmlspider getclass getclassloader processes the successfully fetched uri for further outlinks param result param state param page single threaded protected void on success fetch result result client getter state page page synchronized this if stopped return freeneturi uri state geturi client metadata cm result get metadata bucket data result as bucket string mime type cm getmime type boolean db transaction ended false db begin thread transaction storage exclusive transaction try instead of passing the current object the pagecallback object for every page is passed to the content filter this has many benefits to efficiency and allows us to identify trivially which page is being indexed we cannot rely on the base href provided page call back page call back new page call back page logger minor this successful uri page get id try content filter filter data new null bucket factory mime type uri touri http 127 0 0 1 8888 page call back catch unsafe content type exception e wrong mime type page set status status succeeded db end thread transaction db transaction ended true logger minor this unsafe content type exception uri page get id e return ignore catch io exception e ugh logger error this bucket error e e return catch exception e we have lots of invalid html on net just normal not error logger normal this exception on content filter for page e return page set status status succeeded db end thread transaction db transaction ended true logger minor this filtered uri page get id catch runtime exception e other runtime exceptions logger error this runtime exception e e throw e finally try data free synchronized this running fetch remove page if stopped start some requests finally if db transaction ended logger minor this rollback transaction new exception debug db rollback thread transaction db begin thread transaction storage exclusive transaction page set status status failed db end thread transaction onsuccess fetchresult clientgetter clientmetadata getmetadata asbucket mimetype getmimetype dbtransactionended beginthreadtransaction exclusive_transaction pagecallback pagecallback pagecallback getid contentfilter nullbucketfactory mimetype pagecallback unsafecontenttypeexception setstatus endthreadtransaction dbtransactionended unsafecontenttypeexception getid ioexception setstatus endthreadtransaction dbtransactionended getid runtimeexception runningfetch startsomerequests dbtransactionended rollbackthreadtransaction beginthreadtransaction exclusive_transaction setstatus endthreadtransaction protected void on failure fetch exception fe client getter state page page logger minor this failed page state fe synchronized this if stopped return boolean db transaction ended false db begin thread transaction storage exclusive transaction try synchronized page if fe newuri null redirect mark as succeeded queueuri fe newuri redirect from state geturi false page set status status succeeded else if fe is fatal too many tries or fatal mark as failed page set status status failed else requeue at back page set status status queued db end thread transaction db transaction ended true catch exception e logger error this unexcepected exception in on failure e e throw new runtime exception unexcepected exception in on failure e finally running fetch remove page if db transaction ended logger minor this rollback transaction new exception debug db rollback thread transaction start some requests onfailure fetchexception clientgetter dbtransactionended beginthreadtransaction exclusive_transaction setstatus isfatal setstatus setstatus endthreadtransaction dbtransactionended onfailure runtimeexception onfailure runningfetch dbtransactionended rollbackthreadtransaction startsomerequests protected index writer index writer public index writer get index writer return index writer indexwriter indexwriter indexwriter getindexwriter indexwriter public void terminate logger normal this xml spider terminating synchronized this try runtime get runtime remove shutdown hook exit hook catch illegal state exception e shutting down ignore stopped true for map entry page client getter me running fetch entry set client getter getter me get value logger minor this canceling request getter getter cancel running fetch clear callback executor shutdown now try callback executor await termination 30 time unit seconds catch interrupted exception e try db close catch exception e logger normal this xml spider terminated xmlspider getruntime removeshutdownhook exithook illegalstateexception clientgetter runningfetch entryset clientgetter getvalue runningfetch callbackexecutor shutdownnow callbackexecutor awaittermination timeunit interruptedexception xmlspider public class exit hook implements runnable public void run logger normal this xml spider exit hook called terminate exithook xmlspider public synchronized void run plugin plugin respirator pr this core pr get node client core this pr pr page maker pr get page maker runtime get runtime add shutdown hook exit hook initialize fetch context this ctx pr gethl simple client get fetch context ctx max splitfile block retries 1 ctx max non splitfile retries 1 ctx max temp length 2 1024 1024 ctx max output length 2 1024 1024 allowedmime types new hash set string allowedmime types add text html allowedmime types add text plain allowedmime types add application xhtml xml ctx allowedmime types new hash set string allowedmime types client context pr get node client core client context stopped false initial database db initdb index writer new index writer web interface new web interface this freeneturi initialur is core get bookmarkur is for int i 0 i initialur is length i queueuri initialur is i bookmark false callback executor execute new start some requests callback runplugin pluginrespirator getnode clientcore pagemaker getpagemaker getruntime addshutdownhook exithook gethlsimpleclient getfetchcontext maxsplitfileblockretries maxnonsplitfileretries maxtemplength maxoutputlength allowedmimetypes hashset allowedmimetypes allowedmimetypes allowedmimetypes allowedmimetypes hashset allowedmimetypes clientcontext getnode clientcore clientcontext indexwriter indexwriter webinterface webinterface initialuris getbookmarkuris initialuris initialuris callbackexecutor startsomerequestscallback private web interface web interface public string handlehttp get http request request throws pluginhttp exception return web interface handlehttp get request webinterface webinterface handlehttpget httprequest pluginhttpexception webinterface handlehttpget public string handlehttp post http request request throws pluginhttp exception return web interface handlehttp post request handlehttppost httprequest pluginhttpexception webinterface handlehttppost protected final boolean logdebug logger should log logger debug this per instance allow changing on the fly page call back page page this page page page clear term position shouldlog pagecallback cleartermposition public void founduri freeneturi uri ignore public void founduri freeneturi uri boolean inline if stopped throw new runtime exception plugin stopping if logdebug logger debug this founduri uri on page queueuri uri added from page geturi false runtimeexception public void on text string s string type uri baseuri if stopped throw new runtime exception plugin stopping if logdebug logger debug this on text on page get id baseuri if title equals ignore case type s null s length 0 s index of n 0 title of the page page set page title s type title else type null determine the position of the word in the retrieved page fixme replace with a real tokenizor string words s split p l n if last position null last position 1 for int i 0 i words length i string word words i if word null word length 0 continue word word to lower case try if type null add word word last position i else add word word 1 i 1 catch exception e if type null last position last position words length ontext runtimeexception ontext getid equalsignorecase indexof setpagetitle lastposition lastposition tolowercase addword lastposition addword lastposition lastposition private void add word string word int position throws exception if logdebug logger debug this add word on page get id word position if word length 3 return term term get term by word word true term position term pos page get term position term true term pos add positions position addword addword getid gettermbyword termposition termpos gettermposition termpos addpositions public void on found edition long l usk key object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too freeneturi uri key geturi fixme this code don t make sense 1 running fetches byuri contain ssk not usk 2 on found edition always have the edition set if running fetches byuri contains key uri running fetches byuri remove uri uri key geturi set suggested edition l queueuri uri usk found edition true start some requests onfoundedition objectcontainer clientcontext newknowngood newslottoo runningfetchesbyuri onfoundedition runningfetchesbyuri containskey runningfetchesbyuri setsuggestededition startsomerequests public short get polling priority normal return short math min request starter minimum priority class get root get config get request priority 1 getpollingprioritynormal requeststarter minimum_priority_class getroot getconfig getrequestpriority public short get polling priority progress return get root get config get request priority getpollingpriorityprogress getroot getconfig getrequestpriority initializes database private storage initdb storage db storage factory get instance create storage db set property perst object cache kind pinned db set property perst object cache init size 8192 db set property perst alternative btree true db set property perst string encoding utf 8 db set property perst concurrent iterator true db open xml spider version dbs perst root root perst root db get root if root null perst root create root db return db storagefactory getinstance createstorage setproperty setproperty setproperty setproperty setproperty xmlspider perstroot perstroot getroot perstroot createroot public perst root get root return perst root db get root perstroot getroot perstroot getroot protected page get page byuri freeneturi uri return get root get page byuri uri false null getpagebyuri getroot getpagebyuri protected page get page by id long id return get root get page by id id getpagebyid getroot getpagebyid private language language protected term get term by word string word boolean create return get root get term by word word create gettermbyword getroot gettermbyword public string get string string key todo return a translated string return key getstring public void set language language new language language new language setlanguage newlanguage newlanguage public page maker get page maker return page maker pagemaker getpagemaker pagemaker public list page get running fetch synchronized running fetch return new array list page running fetch key set getrunningfetch runningfetch arraylist runningfetch keyset public boolean is write index scheduled return write index scheduled iswriteindexscheduled writeindexscheduled public boolean is writing index return writing index iswritingindex writingindex public plugin respirator get plugin respirator return pr pluginrespirator getpluginrespirator public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private string mime type public client metadata mime type null mimetype clientmetadata mimetype public client metadata string mime mime type mime null null mime intern clientmetadata mimetype get the document mime type will always be a valid mime type unless there has been an error if it is unknown will return application octet stream public string getmime type if mime type null mime type length 0 return defaultmime types default mime type return mime type getmimetype mimetype mimetype defaultmimetypes default_mime_type mimetype merge the given client metadata without overwriting our existing information public void merge no overwrite client metadata client metadata if mime type null mime type equals mime type client metadata mime type clientmetadata mergenooverwrite clientmetadata clientmetadata mimetype mimetype mimetype clientmetadata mimetype public boolean is trivial return mime type null mime type equals istrivial mimetype mimetype override public client metadata clone try return client metadata super clone catch clone not supported exception e throw new error e clientmetadata clientmetadata clonenotsupportedexception override public string to string return getmime type tostring getmimetype public void clear mime type null mimetype public string getmime type no params string s mime type if s null return null int i s index of if i 1 s s substring i return s getmimetypenoparams mimetype indexof public void remove from object container container container delete this removefrom objectcontainer static void init usk manager manager object container container final client context context object set usk fetcher tag set container query new predicate usk fetcher tag override public boolean match usk fetcher tag tag if tag nodedb handle context nodedb handle return false if tag is finished return false return true while set has next set next start manager context container uskmanager objectcontainer clientcontext objectset uskfetchertag uskfetchertag uskfetchertag nodedbhandle nodedbhandle isfinished hasnext object set usk fetcher tag set container query new predicate usk fetcher tag override public boolean match usk fetcher tag tag if tag nodedb handle context nodedb handle return false if tag is finished return false return true objectset uskfetchertag uskfetchertag uskfetchertag nodedbhandle nodedbhandle isfinished protected byte typeid this methd is used to initialize for instance typeid protected abstract void init protected abstract void init public snmp type wrapper num this 0 snmptypewrappernum public snmp type wrapper num long value this set value value init snmptypewrappernum setvalue public final byte typeid 0x02 public byte get typeid system err println returning integer to hex string typeid for a this get class to string return typeid gettypeid tohexstring getclass tostring public long get value return value getvalue public void set value long value this value value setvalue public object clone object ret null try ret this get class new instance snmp type wrapper num ret set value get value catch security exception e todo auto generated catch block e print stack trace catch instantiation exception e todo auto generated catch block e print stack trace catch illegal access exception e todo auto generated catch block e print stack trace return ret getclass newinstance snmptypewrappernum setvalue getvalue securityexception printstacktrace instantiationexception printstacktrace illegalaccessexception printstacktrace public string to string return long to string value tostring tostring private clientchk clientchk key this routing key new byte key routing key length system arraycopy key routing key 0 routing key 0 key routing key length this node key null this crypto key new byte key crypto key length system arraycopy key crypto key 0 crypto key 0 key crypto key length this control document key control document this crypto algorithm key crypto algorithm this compression algorithm key compression algorithm if routing key null throw new null pointer exception hash code fields hash code routing key fields hash code routing key compression algorithm routingkey routingkey routingkey routingkey routingkey nodekey cryptokey cryptokey cryptokey cryptokey cryptokey controldocument controldocument cryptoalgorithm cryptoalgorithm compressionalgorithm compressionalgorithm routingkey nullpointerexception hashcode hashcode routingkey hashcode routingkey compressionalgorithm param routing key the routing key this is the overall hash of the header and content of the key param enc key the decryption key this is not passed to other nodes and is extracted from the uri param is compressed true if the data was gzipped before encoding param is control document true if the document is a control document these carry metadata whereas ordinary keys carry data and have no type param algo the encryption algorithm s identifier see algo for values public clientchk byte routing key byte enc key boolean is control document byte algo short compression algorithm this routing key routing key this crypto key enc key this control document is control document this crypto algorithm algo this compression algorithm compression algorithm if routing key null throw new null pointer exception hash code fields hash code routing key fields hash code enc key compression algorithm routingkey enckey iscompressed iscontroldocument algo_ routingkey enckey iscontroldocument compressionalgorithm routingkey routingkey cryptokey enckey controldocument iscontroldocument cryptoalgorithm compressionalgorithm compressionalgorithm routingkey nullpointerexception hashcode hashcode routingkey hashcode enckey compressionalgorithm create from a uri public clientchk freeneturi uri throws malformedurl exception if uri get key type equals chk throw new malformedurl exception not chk routing key uri get routing key crypto key uri get crypto key byte extra uri get extra if extra null extra length 5 throw new malformedurl exception no extra bytes in chk maybe a 0 5 key byte 0 is reserved for now crypto algorithm extra 1 if crypto algorithm key algo aes pcfb 256 sha256 throw new malformedurl exception invalid crypto algorithm control document extra 2 0x02 0 compression algorithm short extra 3 0xff 8 extra 4 0xff hash code fields hash code routing key fields hash code crypto key compression algorithm malformedurlexception getkeytype malformedurlexception routingkey getroutingkey cryptokey getcryptokey getextra malformedurlexception cryptoalgorithm cryptoalgorithm algo_aes_pcfb_256_sha256 malformedurlexception controldocument compressionalgorithm hashcode hashcode routingkey hashcode cryptokey compressionalgorithm create from a raw binary chk this expresses the key information in as few bytes as possible throws io exception private clientchk data input stream dis throws io exception byte extra new byte extra length dis read fully extra byte 0 is reserved for now crypto algorithm extra 1 if crypto algorithm key algo aes pcfb 256 sha256 throw new malformedurl exception invalid crypto algorithm compression algorithm short extra 3 0xff 8 extra 4 0xff control document extra 2 0x02 0 routing key new byte nodechk key length dis read fully routing key crypto key new byte crypto key length dis read fully crypto key hash code fields hash code routing key fields hash code crypto key compression algorithm ioexception datainputstream ioexception extra_length readfully cryptoalgorithm cryptoalgorithm algo_aes_pcfb_256_sha256 malformedurlexception compressionalgorithm controldocument routingkey key_length readfully routingkey cryptokey crypto_key_length readfully cryptokey hashcode hashcode routingkey hashcode cryptokey compressionalgorithm write an ultra compact representation throws io exception if a write failed public void write raw binary key data output stream dos throws io exception dos write get extra dos write routing key dos write crypto key ioexception writerawbinarykey dataoutputstream ioexception getextra routingkey cryptokey public byte get extra byte extra new byte extra length extra 0 byte crypto algorithm 8 extra 1 crypto algorithm extra 2 byte control document 2 0 extra 3 byte compression algorithm 8 extra 4 byte compression algorithm byte last last extra no synchronization required imho if arrays equals last extra return last last extra extra return extra getextra extra_length cryptoalgorithm cryptoalgorithm controldocument compressionalgorithm compressionalgorithm lastextra lastextra override public string to string return super to string base64 encode routing key base64 encode crypto key compression algorithm control document crypto algorithm tostring tostring routingkey cryptokey compressionalgorithm controldocument cryptoalgorithm override public key get node key return get nodechk getnodekey getnodechk public nodechk get nodechk this costs us more or less nothing we have to keep the routing key anyway therefore keeping a nodechk as well is a net saving since it s frequently asked for a soft reference would cost more if node key null node key new nodechk routing key crypto algorithm return node key getnodechk routingkey softreference nodekey nodekey routingkey cryptoalgorithm nodekey return uri form of this key override public freeneturi geturi byte extra get extra return new freeneturi chk null routing key crypto key extra getextra routingkey cryptokey read a raw binary chk this is an ultra compact representation for splitfile metadata etc public static clientchk read raw binary key data input stream dis throws io exception return new clientchk dis readrawbinarykey datainputstream ioexception public boolean is metadata return control document ismetadata controldocument public boolean is compressed return compression algorithm 0 iscompressed compressionalgorithm override public clientchk clone key return new clientchk this clonekey override public void remove from object container container container delete this removefrom objectcontainer override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof clientchk return false clientchk key clientchk o if control document key control document return false if crypto algorithm key crypto algorithm return false if compression algorithm key compression algorithm return false if arrays equals routing key key routing key return false if arrays equals crypto key key crypto key return false return true controldocument controldocument cryptoalgorithm cryptoalgorithm compressionalgorithm compressionalgorithm routingkey routingkey cryptokey cryptokey public byte get routing key return routing key getroutingkey routingkey public boolean object can new object container container if routing key null throw new null pointer exception storing a clientchk with no routing key stored container ext is stored this active container ext is active this if crypto key null throw new null pointer exception storing a clientchk with no crypto key return true objectcannew objectcontainer routingkey nullpointerexception routingkey isstored isactive cryptokey nullpointerexception cryptokey public n2ntm user alert darknet peer node source peer node string source string target string message int file number long composed time long sent time long received time super true null null null null user alert minor true null true null this source peer node source peer node this source nodename source this message text message this file number file number this composed time composed time this sent time sent time this received time received time n2ntmuseralert darknetpeernode sourcepeernode filenumber composedtime senttime receivedtime useralert sourcepeernode sourcepeernode sourcenodename messagetext filenumber filenumber composedtime composedtime senttime senttime receivedtime receivedtime override public string get title return l10n title new string number peername peer new string integer to string file number source peer node get name source peer node get peer to string gettitle tostring filenumber sourcepeernode getname sourcepeernode getpeer tostring override public string get text return l10n header new string from composed sent received new string source nodename date format get instance format new date composed time date format get instance format new date sent time date format get instance format new date received time n message text gettext sourcenodename dateformat getinstance composedtime dateformat getinstance senttime dateformat getinstance receivedtime messagetext override public string get short text return l10n header short from source nodename getshorttext headershort sourcenodename override public html node gethtml text html node alert node new html node div alert node add child p l10n header new string from composed sent received new string source nodename date format get instance format new date composed time date format get instance format new date sent time date format get instance format new date received time string lines message text split n for int i 0 c lines length i c i alert node add child lines i if i lines length 1 alert node add child br alert node add child p add child a href send n2ntm peernode hashcode source peer node hash code l10n reply return alert node htmlnode gethtmltext htmlnode alertnode htmlnode alertnode addchild sourcenodename dateformat getinstance composedtime dateformat getinstance senttime dateformat getinstance receivedtime messagetext alertnode addchild alertnode addchild alertnode addchild addchild send_n2ntm peernode_hashcode sourcepeernode hashcode alertnode override public string dismiss button text return l10n delete dismissbuttontext private string l10n string key return l10n get string n2ntm user alert key getstring n2ntmuseralert private string l10n string key string patterns string values return l10n get string n2ntm user alert key patterns values getstring n2ntmuseralert private string l10n string key string pattern string value return l10n get string n2ntm user alert key pattern value getstring n2ntmuseralert override public void on dismiss source peer node delete extra peer data file file number ondismiss sourcepeernode deleteextrapeerdatafile filenumber public class replication dynamic slave storage impl extends replication slave storage impl public replication dynamic slave storage impl string host int port this host host this port port replicationdynamicslavestorageimpl replicationslavestorageimpl replicationdynamicslavestorageimpl public void open i file file int page pool size initialized false prev index 1 out of sync true super open file page pool size ifile pagepoolsize previndex outofsync pagepoolsize socket get socket throws io exception if opened throw new storage error storage error connection failure return new socket host port getsocket ioexception storageerror storageerror connection_failure private final string identifier public end list peers message string identifier this identifier identifier endlistpeersmessage override public simple field set get field set simple field set fs new simple field set true if identifier null fs put single identifier identifier return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message end list peers goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message endlistpeers override public void remove from object container container container delete this removefrom objectcontainer public peer address tracker item long time definitely no packets received long time definitely no packets sent peer peer super time definitely no packets received time definitely no packets sent this peer peer peeraddresstrackeritem timedefinitelynopacketsreceived timedefinitelynopacketssent timedefinitelynopacketsreceived timedefinitelynopacketssent public peer address tracker item simple field set fs throws fs parse exception super fs try peer new peer fs get string address false catch unknown host exception e fs parse exception ex new fs parse exception unknown domain name in address e ex init cause e throw ex catch peer parse exception e throw new fs parse exception e peeraddresstrackeritem simplefieldset fsparseexception getstring unknownhostexception fsparseexception fsparseexception initcause peerparseexception fsparseexception override public simple field set to field set simple field set fs super to field set fs put overwrite address peer to string pref numeric return fs simplefieldset tofieldset simplefieldset tofieldset putoverwrite tostringprefnumeric final string filename public archive key freeneturi key2 string filename2 key key2 filename filename2 archivekey override public boolean equals object o if o null o instanceof archive key return false if this o return true archive key cmp archive key o return cmp key equals key cmp filename equals filename archivekey archivekey archivekey override public int hash code return key hash code filename hash code hashcode hashcode hashcode override public string to string return key filename tostring static final string name end list persistent requests override public simple field set get field set return new simple field set true endlistpersistentrequests simplefieldset getfieldset simplefieldset override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message end list persistent requests goes from server to client not the other way around null false fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message endlistpersistentrequests override public void remove from object container container container delete this removefrom objectcontainer public client put message simple field set fs throws message invalid exception string fnam null identifier fs get identifier binary blob fs get boolean binary blob false global fields string to bool fs get global false if identifier null throw new message invalid exception protocol error message missing field no identifier null global try if binary blob uri new freeneturi chk else string u fs get uri if u null throw new message invalid exception protocol error message missing field no uri identifier global freeneturi uu new freeneturi fs get uri string metas uu get all meta strings if metas null metas length 1 fnam metas 0 uu uu set meta string null if 1 will fail later uri uu catch malformedurl exception e throw new message invalid exception protocol error message freenet uri parse error e get message identifier global string verbosity string fs get verbosity if verbosity string null verbosity 0 else try verbosity integer parse int verbosity string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing verbosity field e get message identifier global content type fs get metadata content type string max retries string fs get max retries if max retries string null default to 0 max retries 0 else try max retries integer parse int max retries string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing max size field e get message identifier global getchk only fields string to bool fs get getchk only false string priority string fs get priority class if priority string null defaults to the one just below f proxy priority class request starter immediate splitfile priority class else try priority class short parse short priority string 10 if priority class request starter maximum priority class priority class request starter minimum priority class throw new message invalid exception protocol error message invalid field valid priorities are from request starter maximum priority class to request starter minimum priority class identifier global catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing priority class field e get message identifier global we do not check that file hash is valid here for backward compatibility and to make the override work this file hash fs get client put base file hash string upload from fs get upload from if upload from null upload from equals ignore case direct upload from type upload from direct string data length string fs get data length if data length string null throw new message invalid exception protocol error message missing field need data length on a client put identifier global try data length long parse long data length string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing data length field e get message identifier global this orig filename null redirect target null else if upload from equals ignore case disk upload from type upload from disk string filename fs get filename if filename null throw new message invalid exception protocol error message missing field missing field filename identifier global file f new file filename if f exists f is file f can read throw new message invalid exception protocol error message file not found null identifier global data length f length file bucket file bucket new file bucket f true false false false false this bucket file bucket this orig filename f redirect target null if fnam null fnam orig filename get name else if upload from equals ignore case redirect upload from type upload from redirect string target fs get targeturi if target null throw new message invalid exception protocol error message missing field targeturi missing but upload from redirect identifier global try redirect target new freeneturi target catch malformedurl exception e throw new message invalid exception protocol error message invalid field invalid targeturi e identifier global data length 0 orig filename null bucket null else throw new message invalid exception protocol error message invalid field upload from invalid or unrecognized upload from identifier global dont compress fields string to bool fs get dont compress false string persistence string fs get persistence if persistence string null persistence string equals ignore case connection default persists until connection loss persistence type client request persist connection else if persistence string equals ignore case reboot reports to client by name persists over connection loss not saved to disk so dies on reboot persistence type client request persist reboot else if persistence string equals ignore case forever same as reboot but saved to disk persists forever persistence type client request persist forever else throw new message invalid exception protocol error message error parsing number error parsing persistence field persistence string identifier global client token fs get client token string f fs get target filename if f null fnam f if fnam null fnam index of 1 throw new message invalid exception protocol error message invalid field target filename must not contain slashes identifier global if fnam null fnam length 0 fnam null deliberate override to tell us not to create one if uri get key type equals chk target filename fnam else target filename null early encode fields string to bool fs get early encode false clientputmessage simplefieldset messageinvalidexception binaryblob getboolean binaryblob stringtobool messageinvalidexception protocolerrormessage missing_field binaryblob messageinvalidexception protocolerrormessage missing_field getallmetastrings setmetastring malformedurlexception messageinvalidexception protocolerrormessage freenet_uri_parse_error getmessage verbositystring verbositystring parseint verbositystring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number getmessage contenttype contenttype maxretriesstring maxretries maxretriesstring maxretries maxretries parseint maxretriesstring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number maxsize getmessage getchkonly stringtobool getchkonly prioritystring priorityclass prioritystring fproxy priorityclass requeststarter immediate_splitfile_priority_class priorityclass parseshort prioritystring priorityclass requeststarter maximum_priority_class priorityclass requeststarter minimum_priority_class messageinvalidexception protocolerrormessage invalid_field requeststarter maximum_priority_class requeststarter minimum_priority_class numberformatexception messageinvalidexception protocolerrormessage error_parsing_number priorityclass getmessage filehash filehash clientputbase file_hash uploadfrom uploadfrom uploadfrom uploadfrom equalsignorecase uploadfromtype upload_from_direct datalengthstring datalength datalengthstring messageinvalidexception protocolerrormessage missing_field datalength clientput datalength parselong datalengthstring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number datalength getmessage origfilename redirecttarget uploadfrom equalsignorecase uploadfromtype upload_from_disk messageinvalidexception protocolerrormessage missing_field isfile canread messageinvalidexception protocolerrormessage file_not_found datalength filebucket filebucket filebucket filebucket origfilename redirecttarget origfilename getname uploadfrom equalsignorecase uploadfromtype upload_from_redirect messageinvalidexception protocolerrormessage missing_field uploadfrom redirecttarget malformedurlexception messageinvalidexception protocolerrormessage invalid_field datalength origfilename messageinvalidexception protocolerrormessage invalid_field uploadfrom uploadfrom dontcompress stringtobool dontcompress persistencestring persistencestring persistencestring equalsignorecase persistencetype clientrequest persist_connection persistencestring equalsignorecase persistencetype clientrequest persist_reboot persistencestring equalsignorecase persistencetype clientrequest persist_forever messageinvalidexception protocolerrormessage error_parsing_number persistencestring clienttoken clienttoken targetfilename indexof messageinvalidexception protocolerrormessage invalid_field targetfilename getkeytype targetfilename targetfilename earlyencode stringtobool earlyencode override public simple field set get field set simple field set sfs new simple field set true sfs put single uri uri to string sfs put single identifier identifier sfs put single verbosity integer to string verbosity sfs put single max retries integer to string max retries sfs put single metadata content type content type sfs put single client token client token if upload from type upload from direct sfs put single upload from direct sfs put single data length long to string data length else if upload from type upload from disk sfs put single upload from disk sfs put single filename orig filename get absolute path sfs put single data length long to string data length else if upload from type upload from redirect sfs put single upload from redirect sfs put single targeturi redirect target to string sfs put single getchk only boolean to string getchk only sfs put single priority class short to string priority class sfs put single persistence type client request persistence type string persistence type sfs put single dont compress boolean to string dont compress sfs put single global boolean to string global sfs put binary blob binary blob return sfs simplefieldset getfieldset simplefieldset simplefieldset putsingle tostring putsingle putsingle tostring putsingle maxretries tostring maxretries putsingle contenttype contenttype putsingle clienttoken clienttoken uploadfromtype upload_from_direct putsingle uploadfrom putsingle datalength tostring datalength uploadfromtype upload_from_disk putsingle uploadfrom putsingle origfilename getabsolutepath putsingle datalength tostring datalength uploadfromtype upload_from_redirect putsingle uploadfrom putsingle redirecttarget tostring putsingle getchkonly tostring getchkonly putsingle priorityclass tostring priorityclass putsingle persistencetype clientrequest persistencetypestring persistencetype putsingle dontcompress tostring dontcompress putsingle tostring binaryblob binaryblob override public string get name return name getname override public void run fcp connection handler handler node node throws message invalid exception handler start client put this fcpconnectionhandler messageinvalidexception startclientput get the length of the trailing field override long data length if upload from type upload from direct return data length else return 1 datalength uploadfromtype upload_from_direct datalength override string get identifier return identifier getidentifier override bucket create bucket bucket factory bf long length fcp server server throws io exception if persistence type client request persist forever return server core persistent temp bucket factory make bucket length else return super create bucket bf length server createbucket bucketfactory fcpserver ioexception persistencetype clientrequest persist_forever persistenttempbucketfactory makebucket createbucket public static string upload from string short upload from switch upload from case upload from direct return direct case upload from disk return disk case upload from redirect return redirect default throw new illegal argument exception uploadfromstring uploadfrom uploadfrom upload_from_direct upload_from_disk upload_from_redirect illegalargumentexception override boolean is global return global isglobal override public void remove from object container container uri remove from container container delete orig filename if redirect target null redirect target remove from container removefrom objectcontainer removefrom origfilename redirecttarget redirecttarget removefrom public void free data object container container if persistence type client request persist forever container activate bucket 5 bucket free if persistence type client request persist forever bucket remove from container freedata objectcontainer persistencetype clientrequest persist_forever persistencetype clientrequest persist_forever removefrom public final static byte load string file name try file input stream fin new file input stream file name return load fin catch exception e debug warning e return new byte 0 filename fileinputstream fileinputstream filename public final static byte load file file try file input stream fin new file input stream file return load fin catch exception e debug warning e return new byte 0 fileinputstream fileinputstream public final static byte load file input stream fin byte read buf new byte 512 1024 try byte array output stream bout new byte array output stream int read cnt fin read read buf while 0 read cnt bout write read buf 0 read cnt read cnt fin read read buf fin close return bout to byte array catch exception e debug warning e return new byte 0 fileinputstream readbuf bytearrayoutputstream bytearrayoutputstream readcnt readbuf readcnt readbuf readcnt readcnt readbuf tobytearray public final static boolean isxml file name string name if string util has data name false return false string lower name name to lower case return lower name ends with xml isxmlfilename stringutil hasdata lowername tolowercase lowername endswith create a buffer by reading a data input stream note that this a expects that the first 4 bytes to be a length indicator of the rest of the byte stream and b these first 4 bytes are removed from the byte stream before storing the rest param dis throws io exception public buffer data input dis throws io exception data new byte dis read int length data length start 0 dis read fully data datainputstream ioexception datainput ioexception _data readint _length _data _start readfully _data create a buffer from a byte array param data public buffer byte data start 0 length data length data data _start _length _data public buffer byte data int start int length start start data data length length _start _data _length retrieve a byte array containing the data in this buffer will be copied if the data does not fill the whole array so please don t rely on it being the internal buffer return the byte array public byte get data if start 0 length data length return data else byte r new byte length system arraycopy data start r 0 length return r getdata _start _length _data _data _length _data _start _length copy the data to a byte array param array param position public void copy to byte array int position system arraycopy data start array position length copyto _data _start _length public byte byte at int pos if pos length throw new array index out of bounds exception return data pos start byteat _length arrayindexoutofboundsexception _data _start public void write to data output stream data output stream stream throws io exception stream write int length stream write data start length writetodataoutputstream dataoutputstream ioexception writeint _length _data _start _length override public string to string if this length 50 return buffer this length else string builder b new string builder this length 3 b append append this length append for int x 0 x this length x b append byte at x b append return b to string tostring _length _length stringbuilder stringbuilder _length _length _length byteat tostring override public boolean equals object o if this o return true if o instanceof buffer return false final buffer buffer buffer o if length buffer length return false if start buffer start return false if arrays equals data buffer data return false return true _length _length _start _start _data _data override public int hash code return fields hash code data start length hashcode hashcode _data _start _length public int get length return length getlength _length public subscriber renew private string sid null public string getsid return sid public void setsid string sid sid sid private string if addr public void set interface address string addr if addr addr ifaddr setinterfaceaddress ifaddr public string get interface address return if addr getinterfaceaddress ifaddr private string deliveryurl public string get deliveryurl return deliveryurl getdeliveryurl public void set deliveryurl string deliveryurl this deliveryurl deliveryurl try url url new url deliveryurl delivery host url get host delivery path url get path delivery port url get port catch exception e setdeliveryurl deliveryhost gethost deliverypath getpath deliveryport getport private int delivery port 0 public string get delivery host return delivery host deliveryport getdeliveryhost deliveryhost public string get delivery path return delivery path getdeliverypath deliverypath public int get delivery port return delivery port getdeliveryport deliveryport private long time out 0 public long get time out return time out timeout gettimeout timeout public void set time out long value time out value settimeout timeout public boolean is expired long curr time system current time millis thanks for oliver newell 10 26 04 if time out subscription infinite value return false thanks for oliver newell 10 26 04 long expired time get subscription time get time out 1000 if expired time curr time return true return false isexpired currtime currenttimemillis timeout infinite_value expiredtime getsubscriptiontime gettimeout expiredtime currtime private long subscription time 0 public long get subscription time return subscription time subscriptiontime getsubscriptiontime subscriptiontime public void set subscription time long time subscription time time setsubscriptiontime subscriptiontime private long notify count 0 public long get notify count return notify count notifycount getnotifycount notifycount public void set notify count int cnt notify count cnt setnotifycount notifycount public void increment notify count if notify count long max value notify count 1 return notify count incrementnotifycount notifycount max_value notifycount notifycount public void renew set subscription time system current time millis set notify count 0 setsubscriptiontime currenttimemillis setnotifycount usk checker usk checker callback cb client key key int max retries fetch context ctx client requester parent super key max retries ctx parent false if logger should log logger minor this logger minor this created usk checker for key this cb cb uskchecker uskcheckercallback clientkey maxretries fetchcontext clientrequester maxretries shouldlog uskchecker override public void on success client key block block boolean from store object token object container container client context context if persistent container activate this 1 container activate cb 1 cb on success clientssk block block context onsuccess clientkeyblock fromstore objectcontainer clientcontext onsuccess clientsskblock override public void on failure low level get exception e object token object container container client context context if persistent container activate this 1 container activate cb 1 if logger should log logger minor this logger minor this on failure e for this firstly can we retry boolean can retry switch e code case low level get exception cancelled case low level get exception decode failed cannot retry can retry false break case low level get exception data not found case low level get exception data not found in store case low level get exception recently failed dnfs can retry true break case low level get exception internal error case low level get exception rejected overload case low level get exception route not found case low level get exception transfer failed case low level get exception verify failed can retry can retry true break default logger error this unknown low level fetch error code e code new exception error can retry true if can retry retry container context return ran out of retries unregister all container context if e code low level get exception cancelled cb on cancelled context return else if e code low level get exception decode failed cb on fatal author error context return rest are non fatal if have dn fs dnf else network error if dnfs 0 cb ondnf context else cb on network error context onfailure lowlevelgetexception objectcontainer clientcontext shouldlog onfailure canretry lowlevelgetexception lowlevelgetexception decode_failed canretry lowlevelgetexception data_not_found lowlevelgetexception data_not_found_in_store lowlevelgetexception recently_failed canretry lowlevelgetexception internal_error lowlevelgetexception rejected_overload lowlevelgetexception route_not_found lowlevelgetexception transfer_failed lowlevelgetexception verify_failed canretry canretry canretry unregisterall lowlevelgetexception oncancelled lowlevelgetexception decode_failed onfatalauthorerror dnfs onnetworkerror override public string to string return usk checker for key geturi for cb tostring uskchecker public void on failed key listener construction exception e object container container client context context on failure new low level get exception low level get exception internal error impossible failed to create bloom filters we don t have any e null container context onfailed keylistenerconstructionexception objectcontainer clientcontext onfailure lowlevelgetexception lowlevelgetexception internal_error override public short get priority class object container container return cb get priority getpriorityclass objectcontainer getpriority private node action node private node get service node return service node actionnode getservicenode servicenode public service get service return new service get service node getservice getservicenode public node get action node return action node getactionnode actionnode public action node service node node action node this service node service node this action node action node servicenode actionnode servicenode servicenode actionnode actionnode public action action action this service node action get service node this action node action get action node servicenode getservicenode actionnode getactionnode private mutex mutex new mutex public void lock mutex lock public void unlock mutex unlock public static boolean is action node node node return action elem name equals node get name isactionnode elem_name getname private final static string name name public void set name string value get action node set node name value setname getactionnode setnode public string get name return get action node get node value name getname getactionnode getnodevalue public argument list get argument list argument list argument list new argument list node argument list node get action node get node argument list elem name if argument list node null return argument list int node cnt argument list node getn nodes for int n 0 n node cnt n node node argument list node get node n if argument is argument node node false continue argument argument new argument get service node node argument list add argument return argument list argumentlist getargumentlist argumentlist argumentlist argumentlist argumentlistnode getactionnode getnode argumentlist elem_name argumentlistnode argumentlist nodecnt argumentlistnode getnnodes nodecnt argumentlistnode getnode isargumentnode getservicenode argumentlist argumentlist public argument list get input argument list argument list all arg list get argument list int all arg cnt all arg list size argument list arg list new argument list for int n 0 n all arg cnt n argument arg all arg list get argument n if arg is in direction false continue arg list add arg return arg list argumentlist getinputargumentlist argumentlist allarglist getargumentlist allargcnt allarglist argumentlist arglist argumentlist allargcnt allarglist getargument isindirection arglist arglist public argument list get output argument list argument list all arg list get argument list int all arg cnt all arg list size argument list arg list new argument list for int n 0 n all arg cnt n argument arg all arg list get argument n if arg is out direction false continue arg list add arg return arg list argumentlist getoutputargumentlist argumentlist allarglist getargumentlist allargcnt allarglist argumentlist arglist argumentlist allargcnt allarglist getargument isoutdirection arglist arglist public argument get argument string name argument list arg list get argument list int n args arg list size for int n 0 n n args n argument arg arg list get argument n string arg name arg get name if arg name null continue if name equals arg name true return arg return null getargument argumentlist arglist getargumentlist nargs arglist nargs arglist getargument argname getname argname argname public void set argument values argument list arg list get argument list set arg list setargumentvalues argumentlist arglist getargumentlist arglist public void set argument value string name string value argument arg get argument name if arg null return arg set value value setargumentvalue getargument setvalue public void set argument value string name int value set argument value name integer to string value setargumentvalue setargumentvalue tostring private void clear output agument values argument list all arg list get argument list int all arg cnt all arg list size for int n 0 n all arg cnt n argument arg all arg list get argument n if arg is out direction false continue arg set value clearoutputagumentvalues argumentlist allarglist getargumentlist allargcnt allarglist allargcnt allarglist getargument isoutdirection setvalue public string get argument value string name argument arg get argument name if arg null return return arg get value getargumentvalue getargument getvalue public int get argument integer value string name argument arg get argument name if arg null return 0 return arg get integer value getargumentintegervalue getargument getintegervalue private action data get action data node node get action node action data user data action data node get user data if user data null user data new action data node set user data user data user data set node node return user data actiondata getactiondata getactionnode actiondata userdata actiondata getuserdata userdata userdata actiondata setuserdata userdata userdata setnode userdata public action listener get action listener return get action data get action listener actionlistener getactionlistener getactiondata getactionlistener public void set action listener action listener listener get action data set action listener listener setactionlistener actionlistener getactiondata setactionlistener public boolean perform action listener action request action req action listener listener action listener get action listener if listener null return false action response action res new action response set status u pnp status invalid action clear output agument values if listener action control received this true action res set response this else u pnp status upnp status get status action res set fault response upnp status get code upnp status get description if debug is on true action res print action req post action res return true performactionlistener actionrequest actionreq actionlistener actionlistener getactionlistener actionresponse actionres actionresponse setstatus upnpstatus invalid_action clearoutputagumentvalues actioncontrolreceived actionres setresponse upnpstatus upnpstatus getstatus actionres setfaultresponse upnpstatus getcode upnpstatus getdescription ison actionres actionreq actionres private control response get control response return get action data get control response controlresponse getcontrolresponse getactiondata getcontrolresponse private void set control response control response res get action data set control response res setcontrolresponse controlresponse getactiondata setcontrolresponse public u pnp status get control status return get control response getu pnp error upnpstatus getcontrolstatus getcontrolresponse getupnperror public boolean post control action thanks for giordano sassaroli sassarol cefriel it 08 30 03 argument list action arg list get argument list argument list action input arg list get input argument list action request ctrl req new action request ctrl req set request this action input arg list if debug is on true ctrl req print action response ctrl res ctrl req post if debug is on true ctrl res print set control response ctrl res thanks for dimas cyberrate users sourceforge net and stefano lenzi kismet sl users sourceforge net 07 09 04 int stat code ctrl res get status code set status stat code if ctrl res is successful false return false argument list out arg list ctrl res get response action arg list set out arg list return true postcontrolaction argumentlist actionarglist getargumentlist argumentlist actioninputarglist getinputargumentlist actionrequest ctrlreq actionrequest ctrlreq setrequest actioninputarglist ison ctrlreq actionresponse ctrlres ctrlreq ison ctrlres setcontrolresponse ctrlres statcode ctrlres getstatuscode setstatus statcode ctrlres issuccessful argumentlist outarglist ctrlres getresponse actionarglist outarglist public void print system out println action get name argument list arg list get argument list int n args arg list size for int n 0 n n args n argument arg arg list get argument n string name arg get name string value arg get value string dir arg get direction system out println n dir name value getname argumentlist arglist getargumentlist nargs arglist nargs arglist getargument getname getvalue getdirection public void set status int code string descr upnp status set code code upnp status set description descr setstatus upnpstatus setcode upnpstatus setdescription public void set status int code set status code u pnp status code2 string code setstatus setstatus upnpstatus code2string public u pnp status get status return upnp status upnpstatus getstatus upnpstatus return a random first name public string get text int random context first names length 1 random rand new random return first names rand next int random context 1 gettext randomcontext first_names first_names nextint randomcontext public time skew detected user alert super false null null null null user alert critical error false l10n get string user alert hide false null timeskewdetecteduseralert useralert critical_error getstring useralert override public string get title return l10n title gettitle private string l10n string key return l10n get string time skew detected user alert key getstring timeskewdetecteduseralert override public string get text return l10n text gettext override public string get short text return l10n short text getshorttext shorttext override public html node gethtml text return new html node div get text htmlnode gethtmltext htmlnode gettext public config properties properties this properties properties helper new config helper confighelper public boolean is border drawn string param name constants kaptcha border string param value properties get property param name return helper get boolean param name param value true isborderdrawn paramname kaptcha_border paramvalue getproperty paramname getboolean paramname paramvalue public color get border color string param name constants kaptcha border color string param value properties get property param name return helper get color param name param value color black getbordercolor paramname kaptcha_border_color paramvalue getproperty paramname getcolor paramname paramvalue public int get border thickness string param name constants kaptcha border thickness string param value properties get property param name return helper get positive int param name param value 1 getborderthickness paramname kaptcha_border_thickness paramvalue getproperty paramname getpositiveint paramname paramvalue public producer get producer impl string param name constants kaptcha producer impl string param value properties get property param name producer producer producer helper get class instance param name param value new default kaptcha this return producer getproducerimpl paramname kaptcha_producer_impl paramvalue getproperty paramname getclassinstance paramname paramvalue defaultkaptcha public text producer get text producer impl string param name constants kaptcha textproducer impl string param value properties get property param name text producer text producer text producer helper get class instance param name param value new default text creator this return text producer textproducer gettextproducerimpl paramname kaptcha_textproducer_impl paramvalue getproperty paramname textproducer textproducer textproducer getclassinstance paramname paramvalue defaulttextcreator textproducer public char get text producer char string string param name constants kaptcha textproducer char string string param value properties get property param name return helper get chars param name param value abcde2345678gfynmnpwx to char array gettextproducercharstring paramname kaptcha_textproducer_char_string paramvalue getproperty paramname getchars paramname paramvalue tochararray public int get text producer char length string param name constants kaptcha textproducer char length string param value properties get property param name return helper get positive int param name param value 5 gettextproducercharlength paramname kaptcha_textproducer_char_length paramvalue getproperty paramname getpositiveint paramname paramvalue public font get text producer fonts int font size string param name constants kaptcha textproducer font names string param value properties get property param name return helper get fonts param name param value font size new font new font arial font bold font size new font courier font bold font size gettextproducerfonts fontsize paramname kaptcha_textproducer_font_names paramvalue getproperty paramname getfonts paramname paramvalue fontsize fontsize fontsize public int get text producer font size string param name constants kaptcha textproducer font size string param value properties get property param name return helper get positive int param name param value 40 gettextproducerfontsize paramname kaptcha_textproducer_font_size paramvalue getproperty paramname getpositiveint paramname paramvalue public color get text producer font color string param name constants kaptcha textproducer font color string param value properties get property param name return helper get color param name param value color black gettextproducerfontcolor paramname kaptcha_textproducer_font_color paramvalue getproperty paramname getcolor paramname paramvalue public noise producer get noise impl string param name constants kaptcha noise impl string param value properties get property param name noise producer noise producer noise producer helper get class instance param name param value new default noise this return noise producer noiseproducer getnoiseimpl paramname kaptcha_noise_impl paramvalue getproperty paramname noiseproducer noiseproducer noiseproducer getclassinstance paramname paramvalue defaultnoise noiseproducer public color get noise color string param name constants kaptcha noise color string param value properties get property param name return helper get color param name param value color black getnoisecolor paramname kaptcha_noise_color paramvalue getproperty paramname getcolor paramname paramvalue public gimpy engine get obscurificator impl string param name constants kaptcha obscurificator impl string param value properties get property param name gimpy engine gimpy engine gimpy engine helper get class instance param name param value new water ripple this return gimpy engine gimpyengine getobscurificatorimpl paramname kaptcha_obscurificator_impl paramvalue getproperty paramname gimpyengine gimpyengine gimpyengine getclassinstance paramname paramvalue waterripple gimpyengine public word renderer get word renderer impl string param name constants kaptcha wordrenderer impl string param value properties get property param name word renderer word renderer word renderer helper get class instance param name param value new default word renderer this return word renderer wordrenderer getwordrendererimpl paramname kaptcha_wordrenderer_impl paramvalue getproperty paramname wordrenderer wordrenderer wordrenderer getclassinstance paramname paramvalue defaultwordrenderer wordrenderer public background producer get background impl string param name constants kaptcha background impl string param value properties get property param name background producer background producer background producer helper get class instance param name param value new default background this return background producer backgroundproducer getbackgroundimpl paramname kaptcha_background_impl paramvalue getproperty paramname backgroundproducer backgroundproducer backgroundproducer getclassinstance paramname paramvalue defaultbackground backgroundproducer public color get background color from string param name constants kaptcha background clr from string param value properties get property param name return helper get color param name param value color light gray getbackgroundcolorfrom paramname kaptcha_background_clr_from paramvalue getproperty paramname getcolor paramname paramvalue light_gray public color get background color to string param name constants kaptcha background clr to string param value properties get property param name return helper get color param name param value color white getbackgroundcolorto paramname kaptcha_background_clr_to paramvalue getproperty paramname getcolor paramname paramvalue public int get width string param name constants kaptcha image width string param value properties get property param name return helper get positive int param name param value 200 getwidth paramname kaptcha_image_width paramvalue getproperty paramname getpositiveint paramname paramvalue public int get height string param name constants kaptcha image height string param value properties get property param name return helper get positive int param name param value 50 getheight paramname kaptcha_image_height paramvalue getproperty paramname getpositiveint paramname paramvalue allows one to override the key name which is stored in the users http session defaults to constants kaptcha session key public string get session key return properties get property constants kaptcha session config key constants kaptcha session key httpsession kaptcha_session_key getsessionkey getproperty kaptcha_session_config_key kaptcha_session_key public properties get properties return properties getproperties get exception error code see definitions above public int get error code return error code geterrorcode errorcode get original exception if storage error excepotion was thrown as the result of catching some other exception within storage implementation storage error is used as wrapper of other exceptions to avoid cascade propagation of throws and try catch constructions return original exception or code null code if there is no such exception public exception get original exception return orig ex storageerror storageerror getoriginalexception origex public storage error int error code super message text error code this error code error code storageerror errorcode messagetext errorcode errorcode errorcode public storage error int error code exception x super message text error code x x this error code error code orig ex x storageerror errorcode messagetext errorcode errorcode errorcode origex public storage error int error code object param super message text error code param this error code error code storageerror errorcode messagetext errorcode errorcode errorcode public storage error int error code object param exception x super message text error code param x x this error code error code orig ex x storageerror errorcode messagetext errorcode errorcode errorcode origex public static digest get instance boolean need progressive if always this one need progressive true if need progressive return new sha1 else try return new javasha1 catch java security no such algorithm exception e always this one true return new sha1 catch exception e return new sha1 getinstance needprogressive alwaysthisone needprogressive needprogressive nosuchalgorithmexception alwaysthisone public static digest get instance return get instance false getinstance getinstance public final int digest size return 160 digestsize retrieves the value of a hash param digest int into which to place 5 elements param offset index of first of the 5 elements public final void extract int digest int offset for int i 0 i 5 i digest i offset digest bits 4 i 0 24 0xff000000 digest bits 4 i 1 16 0x00ff0000 digest bits 4 i 2 8 0x0000ff00 digest bits 4 i 3 0x000000ff digestbits digestbits digestbits digestbits variant constructor param b true for sha 1 false for the original sha 0 public sha1 boolean b count 0 nsa b init simple constructor for sha 1 public sha1 this true inline them when given the o flag private final int rol int value int bits int q value bits value 32 bits return q private final int blk0 int i block i rol block i 24 0xff00ff00 rol block i 8 0x00ff00ff return block i private final int blk int i block i 15 block i 13 15 block i 8 15 block i 2 15 block i 15 if nsa this makes it sha 1 block i 15 rol block i 15 1 return block i 15 private final void r0 int data int v int w int x int y int z int i data z data w data x data y data y blk0 i 0x5a827999 rol data v 5 data w rol data w 30 private final void r1 int data int v int w int x int y int z int i data z data w data x data y data y blk i 0x5a827999 rol data v 5 data w rol data w 30 private final void r2 int data int v int w int x int y int z int i data z data w data x data y blk i 0x6ed9eba1 rol data v 5 data w rol data w 30 private final void r3 int data int v int w int x int y int z int i data z data w data x data y data w data x blk i 0x8f1bbcdc rol data v 5 data w rol data w 30 private final void r4 int data int v int w int x int y int z int i data z data w data x data y blk i 0xca62c1d6 rol data v 5 data w rol data w 30 hash a single 512 bit block this is the core of the algorithm note that working with arrays is very inefficent in java as it does a class cast check each time you store into the array private final void transform copy context state to working vars dd 0 state 0 dd 1 state 1 dd 2 state 2 dd 3 state 3 dd 4 state 4 4 rounds of 20 operations each loop unrolled r0 dd 0 1 2 3 4 0 r0 dd 4 0 1 2 3 1 r0 dd 3 4 0 1 2 2 r0 dd 2 3 4 0 1 3 r0 dd 1 2 3 4 0 4 r0 dd 0 1 2 3 4 5 r0 dd 4 0 1 2 3 6 r0 dd 3 4 0 1 2 7 r0 dd 2 3 4 0 1 8 r0 dd 1 2 3 4 0 9 r0 dd 0 1 2 3 4 10 r0 dd 4 0 1 2 3 11 r0 dd 3 4 0 1 2 12 r0 dd 2 3 4 0 1 13 r0 dd 1 2 3 4 0 14 r0 dd 0 1 2 3 4 15 r1 dd 4 0 1 2 3 16 r1 dd 3 4 0 1 2 17 r1 dd 2 3 4 0 1 18 r1 dd 1 2 3 4 0 19 r2 dd 0 1 2 3 4 20 r2 dd 4 0 1 2 3 21 r2 dd 3 4 0 1 2 22 r2 dd 2 3 4 0 1 23 r2 dd 1 2 3 4 0 24 r2 dd 0 1 2 3 4 25 r2 dd 4 0 1 2 3 26 r2 dd 3 4 0 1 2 27 r2 dd 2 3 4 0 1 28 r2 dd 1 2 3 4 0 29 r2 dd 0 1 2 3 4 30 r2 dd 4 0 1 2 3 31 r2 dd 3 4 0 1 2 32 r2 dd 2 3 4 0 1 33 r2 dd 1 2 3 4 0 34 r2 dd 0 1 2 3 4 35 r2 dd 4 0 1 2 3 36 r2 dd 3 4 0 1 2 37 r2 dd 2 3 4 0 1 38 r2 dd 1 2 3 4 0 39 r3 dd 0 1 2 3 4 40 r3 dd 4 0 1 2 3 41 r3 dd 3 4 0 1 2 42 r3 dd 2 3 4 0 1 43 r3 dd 1 2 3 4 0 44 r3 dd 0 1 2 3 4 45 r3 dd 4 0 1 2 3 46 r3 dd 3 4 0 1 2 47 r3 dd 2 3 4 0 1 48 r3 dd 1 2 3 4 0 49 r3 dd 0 1 2 3 4 50 r3 dd 4 0 1 2 3 51 r3 dd 3 4 0 1 2 52 r3 dd 2 3 4 0 1 53 r3 dd 1 2 3 4 0 54 r3 dd 0 1 2 3 4 55 r3 dd 4 0 1 2 3 56 r3 dd 3 4 0 1 2 57 r3 dd 2 3 4 0 1 58 r3 dd 1 2 3 4 0 59 r4 dd 0 1 2 3 4 60 r4 dd 4 0 1 2 3 61 r4 dd 3 4 0 1 2 62 r4 dd 2 3 4 0 1 63 r4 dd 1 2 3 4 0 64 r4 dd 0 1 2 3 4 65 r4 dd 4 0 1 2 3 66 r4 dd 3 4 0 1 2 67 r4 dd 2 3 4 0 1 68 r4 dd 1 2 3 4 0 69 r4 dd 0 1 2 3 4 70 r4 dd 4 0 1 2 3 71 r4 dd 3 4 0 1 2 72 r4 dd 2 3 4 0 1 73 r4 dd 1 2 3 4 0 74 r4 dd 0 1 2 3 4 75 r4 dd 4 0 1 2 3 76 r4 dd 3 4 0 1 2 77 r4 dd 2 3 4 0 1 78 r4 dd 1 2 3 4 0 79 add the working vars back into context state state 0 dd 0 state 1 dd 1 state 2 dd 2 state 3 dd 3 state 4 dd 4 zero the count and state arrays used to support pegwit s anomalous 2 barrel hashing public final void frob pegwit s little anomaly count 0 state 0 state 1 state 2 state 3 state 4 0 initializes new context protected final void init sha1 initialization constants state 0 0x67452301 state 1 0xefcdab89 state 2 0x98badcfe state 3 0x10325476 state 4 0xc3d2e1f0 count 0 digest bits new byte 20 block index 0 digestbits blockindex add one byte to the digest when this is implemented all of the abstract class methods end up calling this method for types other than bytes param b byte to add public final void update byte b int mask block index 3 3 count 8 block block index 2 0xff mask block block index 2 b 0xff mask block index if block index 64 transform block index 0 blockindex blockindex blockindex blockindex blockindex blockindex add many bytes to the digest param data byte data to add param offset start byte param length number of bytes to hash public final void update byte data int offset int length for int i 0 i length i update data offset i public final void update byte data update data 0 data length write completed digest into the given buffer param reset if true the hash function is reinitialized public final void digest boolean reset byte buffer int offset finish system arraycopy digest bits 0 buffer offset digest bits length if reset init digestbits digestbits return completed digest return the byte array result param reset if true the hash function is reinitialized public final byte digest boolean reset byte out new byte 20 digest reset out 0 return out return completed digest return the byte array result public final byte digest return digest true complete processing on the message digest protected final void finish byte bits new byte 8 int i for i 0 i 8 i bits i byte count 7 i 3 0xff update byte 128 while block index 56 update byte 0 this should cause a transform to happen for i 0 i 8 i update bits i for i 0 i 20 i digest bits i byte state i 2 3 i 3 3 0xff blockindex digestbits print out the digest in a form that can be easily compared to the test vectors protected string digout string builder sb new string builder for int i 0 i 20 i char c1 c2 c1 char digest bits i 4 0xf c2 char digest bits i 0xf c1 char c1 9 a c1 10 0 c1 c2 char c2 9 a c2 10 0 c2 sb append c1 sb append c2 return sb to string stringbuilder stringbuilder digestbits digestbits tostring test driver public static void main string args sh aself test sh abench test shaselftest shabenchtest public static void sh abench test try javasha1 s new javasha1 generic bench test s try javasha1 s1 javasha1 s clone system err println cloned successfully generic bench test s1 catch clone not supported exception e system err println couldn t clone catch exception e system err println couldn t run benchmark for javasha1 sha1 sha1 new sha1 true generic bench test sha1 shabenchtest genericbenchtest genericbenchtest clonenotsupportedexception genericbenchtest public static void generic bench test digest sha1 system out println n begin benchmark long size 4096 long count 100000 byte data create dummy data int size long start same update system current time millis for int i 0 i count i sha1 update data long end same update system current time millis long update time end same update start same update long speed 0 long each time 0 if update time 0 speed size count 1000 update time each time count update time system out println sha update count times for the same data block of size size bytes system out println update time ms speed bytes second each time updates ms n count 1000 byte data2 new byte int count for int i 0 i count i data2 i create dummy data int size long different start time system current time millis for int i 0 i count i sha1 update data2 i long end different update system current time millis update time end different update different start time speed 0 each time 0 if update time 0 speed size count 1000 update time each time count update time system out println sha update count times for different data blocks of size size bytes system out println update time ms speed bytes second each time ms update system out println n end benchmark genericbenchtest nbegin createdummydata startsameupdate currenttimemillis endsameupdate currenttimemillis updatetime endsameupdate startsameupdate eachtime updatetime updatetime eachtime updatetime updatetime eachtime createdummydata differentstarttime currenttimemillis enddifferentupdate currenttimemillis updatetime enddifferentupdate differentstarttime eachtime updatetime updatetime eachtime updatetime updatetime eachtime nend private static byte create dummy data int size random rand new random byte buf new byte size rand next bytes buf return buf createdummydata nextbytes public static void sh aself test system err println testing javasha1 try javasha1 js new javasha1 sh aself test js catch exception e system err println caught exception e trying to test javasha1 system err println testing sha1 sha1 s new sha1 true sh aself test s shaselftest shaselftest shaselftest perfoms a self test spits out the test vector outputs on system out public static void sh aself test digest s int i this line may be safely deleted its to make it easy to see the output of the program system out println sha 1 test program system out println this code runs the test vectors through the code abc a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d system out println first test is abc string z abc s init s update byte a s update byte b s update byte c system out println hex util bytes to hex s digest to upper case system out println a9993e364706816aba3e25717850c26c9cd0d89d abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq 84983e44 1c3bd26e baae4aa1 f95129e5 e54670f1 system out println next test is abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq z abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq s init initted by digest above for i 0 i z length i s update byte z char at i system out println hex util bytes to hex s digest to upper case system out println 84983e441c3bd26ebaae4aa1f95129e5e54670f1 a million repetitions of a 34aa973c d4c4daa4 f61eeb2b dbad2731 6534016f long start time 0 system current time millis system out println last test is 1 million a characters s init initted by digest above for i 0 i 1000000 i s update byte a s finish digest finishes system out println hex util bytes to hex s digest to upper case system out println 34aa973cd4c4daa4f61eeb2bdbad27316534016f start time system current time millis double d start time 1000 0 system out println done elapsed time d shaselftest hexutil bytestohex touppercase charat hexutil bytestohex touppercase starttime currenttimemillis hexutil bytestohex touppercase starttime currenttimemillis starttime public static string decode string s string t character ch int tmp pos i int max pos s length string builder sb new string builder max pos int cur pos 0 while cur pos max pos char c s char at cur pos if c tmp pos cur pos if tmp pos max pos char d s char at tmp pos if d redflag fixme we might want to prevent control characters from beeing created here if tmp pos max pos d s char at tmp pos if d x d x if tmp pos max pos d s char at tmp pos if is hex digit d while tmp pos max pos d s char at tmp pos if is hex digit d if d t s substring cur pos 2 tmp pos 1 try i integer parse int t 16 if i 0 i 65536 c char i cur pos tmp pos catch number format exception e break else if is digit d while tmp pos max pos d s char at tmp pos if is digit d if d t s substring cur pos 1 tmp pos 1 try i integer parse int t if i 0 i 65536 c char i cur pos tmp pos catch number format exception e break else if is letter d while tmp pos max pos d s char at tmp pos if is letter or digit d if d t s substring cur pos tmp pos 1 ch char table get t if ch null c ch char value cur pos tmp pos break sb append c return sb to string tmppos maxpos stringbuilder stringbuilder maxpos curpos curpos maxpos charat curpos tmppos curpos tmppos maxpos charat tmppos tmppos maxpos charat tmppos tmppos maxpos charat tmppos ishexdigit tmppos maxpos charat tmppos ishexdigit curpos tmppos parseint curpos tmppos numberformatexception isdigit tmppos maxpos charat tmppos isdigit curpos tmppos parseint curpos tmppos numberformatexception isletter tmppos maxpos charat tmppos isletterordigit curpos tmppos chartable charvalue curpos tmppos tostring private static boolean is letter or digit char c return is letter c is digit c isletterordigit isletter isdigit private static boolean is hex digit char c return is hex letter c is digit c ishexdigit ishexletter isdigit private static boolean is letter char c return c a c z c a c z isletter private static boolean is hex letter char c return c a c f c a c f ishexletter private static boolean is digit char c return c 0 c 9 isdigit public static string compact string s int max pos s length string builder sb new string builder max pos int cur pos 0 while cur pos max pos char c s char at cur pos if is whitespace c while cur pos max pos is whitespace s char at cur pos cur pos c u0020 sb append c return sb to string maxpos stringbuilder stringbuilder maxpos curpos curpos maxpos charat curpos iswhitespace curpos maxpos iswhitespace charat curpos curpos tostring html is very particular about what constitutes white space public static boolean is whitespace char ch return space ch u0020 mac newline ch r unix newline ch n tab ch u0009 control ch u000c zero width space ch u200b iswhitespace public final class hue composite extends rgb composite public hue composite float alpha super alpha huecomposite rgbcomposite huecomposite public composite context create context color model src color model color model dst color model rendering hints hints return new context extra alpha src color model dst color model compositecontext createcontext colormodel srccolormodel colormodel dstcolormodel renderinghints extraalpha srccolormodel dstcolormodel private float dhsb new float 3 public context float alpha color model src color model color model dst color model super alpha src color model dst color model colormodel srccolormodel colormodel dstcolormodel srccolormodel dstcolormodel override public void composergb int src int dst float alpha int w src length for int i 0 i w i 4 int sr src i int dir dst i int sg src i 1 int dig dst i 1 int sb src i 2 int dib dst i 2 int sa src i 3 int dia dst i 3 int dor dog dob color rg btohsb sr sg sb shsb color rg btohsb dir dig dib dhsb dhsb 0 shsb 0 int dorgb color hs btorgb dhsb 0 dhsb 1 dhsb 2 dor dorgb 0xff0000 16 dog dorgb 0xff00 8 dob dorgb 0xff float a alpha sa 255f float ac 1 a dst i int a dor ac dir dst i 1 int a dog ac dig dst i 2 int a dob ac dib dst i 3 int sa alpha dia ac rgbtohsb rgbtohsb hsbtorgb welcome toadlet high level simple client client node client core core node node bookmark manager bookmarks super client this node node this core core this bookmark manager bookmarks welcometoadlet highlevelsimpleclient nodeclientcore bookmarkmanager bookmarkmanager void redirect to root toadlet context ctx throws toadlet context closed exception io exception multi value table string string headers new multi value table string string headers put location ctx send reply headers 302 found headers null 0 return redirecttoroot toadletcontext toadletcontextclosedexception ioexception multivaluetable multivaluetable sendreplyheaders private void add category to list bookmark category cat html node list boolean no active links toadlet context ctx list bookmark item items cat get items if items size 0 fixme css noborder html node table list add child li add child table new string border style new string 0 border none for int i 0 i items size i bookmark item item items get i html node row table add child tr html node cell row add child td style border none if item has an activelink no active links string initial key item get key string key initial key initial key ends with activelink png cell add child a href item get key add child img new string src height width alt title new string key 36 108 activelink item get description else cell add child cell row add child td style border none cell add child a new string href title new string item get key item get description item get name list bookmark category cats cat get sub categories for int i 0 i cats size i list add child li class cat cats get i get name add category to list cats get i list add child li add child ul no active links ctx addcategorytolist bookmarkcategory htmlnode noactivelinks toadletcontext bookmarkitem getitems htmlnode addchild addchild bookmarkitem htmlnode addchild htmlnode addchild hasanactivelink noactivelinks initialkey getkey initialkey initialkey endswith addchild getkey addchild getdescription addchild addchild addchild getkey getdescription getname bookmarkcategory getsubcategories addchild getname addcategorytolist addchild addchild noactivelinks suppress warnings deprecation override public void handle post uri uri http request request toadlet context ctx throws toadlet context closed exception io exception if ctx is allowed full access super send error page ctx 403 unauthorized l10n get string toadlet unauthorized return string passwd request get part as string form password 32 boolean no password passwd null passwd equals core form password if no password if logger should log logger minor this logger minor this no password passwd should be core form password if request get part as string updateconfirm 32 length 0 if no password redirect to root ctx return false for no navigation bars because that would be very silly html node page node ctx get page maker get page node l10n updating title ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox information l10n updating title html node content ctx get page maker get content node infobox content add child p add child l10n updating content add child p add child l10n thanks writehtml reply ctx 200 ok page node generate logger normal this node is updating restarting node get node updater arm else if request get part as string generic read filter callback magichttp escape string max url length length 0 if no password redirect to root ctx return multi value table string string headers new multi value table string string string url null if request get part as string go 32 length 0 url request get part as string generic read filter callback magichttp escape string max url length headers put location url null url ctx send reply headers 302 found headers null 0 else if request get part as string update 32 length 0 html node page node ctx get page maker get page node l10n node update confirm title ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox query l10n node update confirm title html node content ctx get page maker get content node infobox content add child p add child l10n node update confirm html node update form ctx add form child content update confirm form update form add child input new string type name value new string submit cancel l10n get string toadlet cancel update form add child input new string type name value new string submit updateconfirm l10n update writehtml reply ctx 200 ok page node generate else if request is part set get thread dump if no password redirect to root ctx return html node page node ctx get page maker get page node l10n thread dump title ctx html node content node ctx get page maker get content node page node if node is using wrapper html node infobox content node add child ctx get page maker get infobox l10n thread dump sub title ctx get page maker get content node infobox add child l10n thread dump with filename filename wrapper manager get properties get property wrapper logfile system out println thread dump wrapper manager request thread dump else html node infobox content node add child ctx get page maker get infobox infobox error l10n thread dump sub title ctx get page maker get content node infobox add child l10n thread dump not using wrapper this writehtml reply ctx 200 ok page node generate else if request is part set getje stats dump if no password redirect to root ctx return html node page node ctx get page maker get page node l10n database stats title ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox l10n database stats sub title system out println start database stats node je stats dump system out println end database stats ctx get page maker get content node infobox add child l10n written database stats this writehtml reply ctx 200 ok page node generate else if request is part set disable if no password redirect to root ctx return int valid alerts remaining 0 user alert alerts core alerts get alerts for int i 0 i alerts length i if request get int part disable 1 alerts i hash code user alert alert alerts i won t be dismissed if it s not allowed anyway if alert user can dismiss alert should unregister on dismiss alert on dismiss logger normal this unregistering the user alert alert hash code core alerts unregister alert else logger normal this disabling the user alert alert hash code alert is valid false else if alerts i is valid valid alerts remaining write permanent redirect ctx l10n disabled alert valid alerts remaining 0 alerts return else if request is part set boardname request is part set filename request is part set message inserting into a frost board fin boardname filename boardprivatekey not needed boardpublickey not needed and maybe dump it all the way innitialindex sender subject string board name request get part as string boardname frost board max name length string board private key request get part as string boardprivatekey 78 string board public key request get part as string boardpublickey 78 string sender request get part as string sender 64 string subject request get part as string subject 128 string message request get part as string message 1024 if message length 0 back compatibility should use message message request get part as string filename 1024 int initial index 0 if request is part set initialindex try initial index integer parse int request get part as string initialindex 10 catch number format exception e initial index 0 else if request is part set innitialindex try initial index integer parse int request get part as string innitialindex 10 catch number format exception e initial index 0 if no password html node page node ctx get page maker get page node l10n fin title ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox query l10n fin title html node content ctx get page maker get content node infobox content add child p add child l10n confirmfin html node post form ctx add form child content add child p fin confirm form html node table post form add child table align center fin input row table boardname l10n target board header board name fin input row table boardprivatekey l10n private key header board private key fin input row table boardpublickey l10n public key header board public key fin input row table initialindex l10n start index header integer to string initial index fin input row table sender l10n from header sender fin input row table subject l10n subject header subject fin input box row table message l10n message header message post form add child input new string type name value new string submit cancel l10n get string toadlet cancel post form add child input new string type name value new string submit finconfirm l10n post writehtml reply ctx 200 ok page node generate return if request is part set finconfirm redirect to root ctx return frost board board null if board private key length 0 suppresswarnings handlepost httprequest toadletcontext toadletcontextclosedexception ioexception isallowedfullaccess senderrorpage getstring getpartasstring formpassword nopassword formpassword nopassword shouldlog formpassword getpartasstring nopassword redirecttoroot htmlnode pagenode getpagemaker getpagenode updatingtitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox updatingtitle htmlnode getpagemaker getcontentnode addchild addchild addchild addchild writehtmlreply pagenode getnodeupdater getpartasstring genericreadfiltercallback magichttpescapestring max_url_length nopassword redirecttoroot multivaluetable multivaluetable getpartasstring getpartasstring genericreadfiltercallback magichttpescapestring max_url_length sendreplyheaders getpartasstring htmlnode pagenode getpagemaker getpagenode nodeupdateconfirmtitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox nodeupdateconfirmtitle htmlnode getpagemaker getcontentnode addchild addchild nodeupdateconfirm htmlnode updateform addformchild updateconfirmform updateform addchild getstring updateform addchild writehtmlreply pagenode ispartset getthreaddump nopassword redirecttoroot htmlnode pagenode getpagemaker getpagenode threaddumptitle htmlnode contentnode getpagemaker getcontentnode pagenode isusingwrapper htmlnode contentnode addchild getpagemaker getinfobox threaddumpsubtitle getpagemaker getcontentnode addchild threaddumpwithfilename wrappermanager getproperties getproperty wrappermanager requestthreaddump htmlnode contentnode addchild getpagemaker getinfobox threaddumpsubtitle getpagemaker getcontentnode addchild threaddumpnotusingwrapper writehtmlreply pagenode ispartset getjestatsdump nopassword redirecttoroot htmlnode pagenode getpagemaker getpagenode databasestatstitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox databasestatssubtitle jestatsdump getpagemaker getcontentnode addchild writtendatabasestats writehtmlreply pagenode ispartset nopassword redirecttoroot validalertsremaining useralert getalerts getintpart hashcode useralert usercandismiss shouldunregisterondismiss ondismiss useralert hashcode useralert hashcode isvalid isvalid validalertsremaining writepermanentredirect disabledalert validalertsremaining ispartset ispartset ispartset boardname getpartasstring frostboard max_name_length boardprivatekey getpartasstring boardpublickey getpartasstring getpartasstring getpartasstring getpartasstring getpartasstring initialindex ispartset initialindex parseint getpartasstring numberformatexception initialindex ispartset initialindex parseint getpartasstring numberformatexception initialindex nopassword htmlnode pagenode getpagemaker getpagenode fintitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox fintitle htmlnode getpagemaker getcontentnode addchild addchild htmlnode postform addformchild addchild finconfirmform htmlnode postform addchild fininputrow targetboardheader boardname fininputrow privatekeyheader boardprivatekey fininputrow publickeyheader boardpublickey fininputrow startindexheader tostring initialindex fininputrow fromheader fininputrow subjectheader fininputboxrow messageheader postform addchild getstring postform addchild writehtmlreply pagenode ispartset redirecttoroot frostboard boardprivatekey node ps queue timed job new runnable public void run node exit shutdown from fproxy queuetimedjob node ps queue timed job new runnable public void run node get node starter restart queuetimedjob getnodestarter private void fin input box row html node table string name string label string message html node row table add child tr html node cell row add child td fixme this should be in the css not the generated code html node right cell add child div align right html node bold right add child b html node font bold add child font size 1 font add child label cell row add child td cell add child textarea new string name rows cols new string name 12 80 add child message fininputboxrow htmlnode htmlnode addchild htmlnode addchild htmlnode addchild htmlnode addchild htmlnode addchild addchild addchild addchild addchild private void fin input row html node table string name string label string message html node row table add child tr html node cell row add child td fixme this should be in the css not the generated code html node right cell add child div align right html node bold right add child b html node font bold add child font size 1 font add child label cell row add child td cell add child input new string type name size value new string text name 30 message fininputrow htmlnode htmlnode addchild htmlnode addchild htmlnode addchild htmlnode addchild htmlnode addchild addchild addchild addchild override public void handle get uri uri http request request toadlet context ctx throws toadlet context closed exception io exception boolean advanced mode output enabled core get toadlet container is advanced mode enabled if ctx is allowed full access if request is parameter set latestlog final file logs new file node config get logger get string dirname file separator freenet latest log this writehtml reply ctx 200 ok file util readutf logs return else if request is parameter set terminated if request is parameter set form password request get param form password equals core form password redirect to root ctx return tell the user that the node is shutting down html node page node ctx get page maker get page node node shutdown false ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox information l10n shutdown done html node infobox content ctx get page maker get content node infobox infobox content add child l10n thanks welcome toadlet maybe display wrapper logfile ctx content node this writehtml reply ctx 200 ok page node generate return else if request is parameter set restarted if request is parameter set form password request get param form password equals core form password redirect to root ctx return tell the user that the node is restarting html node page node ctx get page maker get page node node restart false ctx html node head node ctx get page maker get head node page node head node add child meta new string http equiv content new string refresh 20 url html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox infobox information l10n restarting title html node infobox content ctx get page maker get content node infobox infobox content add child l10n restarting writehtml reply ctx 200 ok page node generate logger normal this node is restarting return else if request get param newbookmark length 0 html node page node ctx get page maker get page node l10n confirm add bookmark title ctx html node content node ctx get page maker get content node page node html node infobox content node add child ctx get page maker get infobox l10n confirm add bookmark sub title html node add form ctx add form child ctx get page maker get content node infobox bookmark editor edit bookmark form add form add child l10n confirm add bookmark with key key request get param newbookmark add form add child br string key request get param newbookmark if key starts with freenet key key substring 8 add form add child input new string type name value new string hidden key key if request is parameter set has an activelink add form add child input new string type name value new string hidden has an activelink request get param has an activelink add form add child input new string type name value new string text name request get param desc add form add child input new string type name value new string hidden bookmark add form add child input new string type name value new string hidden action add item add form add child input new string type name value new string submit addbookmark l10n get string bookmark editor toadlet add bookmark this writehtml reply ctx 200 ok page node generate return else if request get param generic read filter callback magichttp escape string length 0 html node page node ctx get page maker get page node l10n confirm external link title ctx html node content node ctx get page maker get content node page node html node warnbox content node add child ctx get page maker get infobox infobox warning l10n confirm external link sub title html node external link form ctx add form child ctx get page maker get content node warnbox confirm external link form final string target request get param generic read filter callback magichttp escape string external link form add child l10n confirm external link withurl url target external link form add child br external link form add child input new string type name value new string hidden generic read filter callback magichttp escape string target external link form add child input new string type name value new string submit cancel l10n get string toadlet cancel external link form add child input new string type name value new string submit go l10n go to external link this writehtml reply ctx 200 ok page node generate return html node page node ctx get page maker get page node l10n homepage full title with name name node get my name ctx html node content node ctx get page maker get content node page node if node is testnet enabled html node testnet box content node add child ctx get page maker get infobox infobox alert l10n testnet warning title html node testnet content ctx get page maker get content node testnet box testnet content add child l10n testnet warning string useragent ctx get headers get user agent if useragent null useragent useragent to lower case if useragent index of msie 1 useragent index of opera 1 html node browser warning box content node add child ctx get page maker get infobox infobox alert l10n ie warning title html node browser warning content ctx get page maker get content node browser warning box browser warning content add child l10n ie warning alerts if ctx is allowed full access content node add child core alerts create alerts short l10n alerts summary advanced mode output enabled true search box html node search box content node add child ctx get page maker get infobox infobox normal l10n get string welcome toadlet search box label search form if core node plugin manager null core node plugin manager is plugin loaded plugins xml librarian xml librarian html node form search box add child form new string method action new string get plugins plugins xml librarian xml librarian form add child input new string type name value new string hidden choice index form add child input new string type size name new string text 80 search form add child input new string type name value new string submit find search freenet else warn that search plugin is not loaded html node search box content ctx get page maker get content node search box search box content add child l10n get string welcome toadlet search plugin not loaded bookmarks html node bookmark box content node add child div class infobox infobox normal html node bookmark box header bookmark box add child div class infobox header bookmark box header add child l10n get string bookmark editor toadlet my bookmarks title if ctx is allowed full access bookmark box header add child bookmark box header add child span id bookmarkedit add child a new string href class new string bookmark editor interfacelink l10n get string bookmark editor toadlet edit bookmark box header add child html node bookmark box content bookmark box add child div class infobox content html node bookmarks list bookmark box content add child ul id bookmarks add category to list bookmark manager main category bookmarks list container enable activelinks useragent null useragent contains khtml useragent contains chrome ctx fetch a key box html node fetch key box content node add child ctx get page maker get infobox infobox normal l10n fetch key label html node fetch key content ctx get page maker get content node fetch key box fetch key content add attribute id keyfetchbox html node fetch key form fetch key content add child form new string action method new string get add child div fetch key form add child l10n key request label fetch key form handleget httprequest toadletcontext toadletcontextclosedexception ioexception advancedmodeoutputenabled gettoadletcontainer isadvancedmodeenabled isallowedfullaccess isparameterset getstring writehtmlreply fileutil isparameterset isparameterset formpassword getparam formpassword formpassword redirecttoroot htmlnode pagenode getpagemaker getpagenode htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox shutdowndone htmlnode infoboxcontent getpagemaker getcontentnode infoboxcontent addchild welcometoadlet maybedisplaywrapperlogfile contentnode writehtmlreply pagenode isparameterset isparameterset formpassword getparam formpassword formpassword redirecttoroot htmlnode pagenode getpagemaker getpagenode htmlnode headnode getpagemaker getheadnode pagenode headnode addchild htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox restartingtitle htmlnode infoboxcontent getpagemaker getcontentnode infoboxcontent addchild writehtmlreply pagenode getparam htmlnode pagenode getpagemaker getpagenode confirmaddbookmarktitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox confirmaddbookmarksubtitle htmlnode addform addformchild getpagemaker getcontentnode bookmarkeditor editbookmarkform addform addchild confirmaddbookmarkwithkey getparam addform addchild getparam startswith addform addchild isparameterset hasanactivelink addform addchild hasanactivelink getparam hasanactivelink addform addchild getparam addform addchild addform addchild additem addform addchild getstring bookmarkeditortoadlet addbookmark writehtmlreply pagenode getparam genericreadfiltercallback magichttpescapestring htmlnode pagenode getpagemaker getpagenode confirmexternallinktitle htmlnode contentnode getpagemaker getcontentnode pagenode htmlnode contentnode addchild getpagemaker getinfobox confirmexternallinksubtitle htmlnode externallinkform addformchild getpagemaker getcontentnode confirmexternallinkform getparam genericreadfiltercallback magichttpescapestring externallinkform addchild confirmexternallinkwithurl externallinkform addchild externallinkform addchild genericreadfiltercallback magichttpescapestring externallinkform addchild getstring externallinkform addchild gotoexternallink writehtmlreply pagenode htmlnode pagenode getpagemaker getpagenode homepagefulltitlewithname getmyname htmlnode contentnode getpagemaker getcontentnode pagenode istestnetenabled htmlnode testnetbox contentnode addchild getpagemaker getinfobox testnetwarningtitle htmlnode testnetcontent getpagemaker getcontentnode testnetbox testnetcontent addchild testnetwarning getheaders tolowercase indexof indexof htmlnode browserwarningbox contentnode addchild getpagemaker getinfobox iewarningtitle htmlnode browserwarningcontent getpagemaker getcontentnode browserwarningbox browserwarningcontent addchild iewarning isallowedfullaccess contentnode addchild createalertsshort alertssummary advancedmodeoutputenabled htmlnode searchbox contentnode addchild getpagemaker getinfobox getstring welcometoadlet searchboxlabel pluginmanager pluginmanager ispluginloaded xmllibrarian xmllibrarian htmlnode searchbox addchild xmllibrarian xmllibrarian addchild addchild addchild htmlnode searchboxcontent getpagemaker getcontentnode searchbox searchboxcontent addchild getstring welcometoadlet searchpluginnotloaded htmlnode bookmarkbox contentnode addchild htmlnode bookmarkboxheader bookmarkbox addchild bookmarkboxheader addchild getstring bookmarkeditortoadlet mybookmarkstitle isallowedfullaccess bookmarkboxheader addchild bookmarkboxheader addchild addchild bookmarkeditor getstring bookmarkeditortoadlet bookmarkboxheader addchild htmlnode bookmarkboxcontent bookmarkbox addchild htmlnode bookmarkslist bookmarkboxcontent addchild addcategorytolist bookmarkmanager main_category bookmarkslist enableactivelinks htmlnode fetchkeybox contentnode addchild getpagemaker getinfobox fetchkeylabel htmlnode fetchkeycontent getpagemaker getcontentnode fetchkeybox fetchkeycontent addattribute htmlnode fetchkeyform fetchkeycontent addchild addchild fetchkeyform addchild keyrequestlabel fetchkeyform override public string supported methods return get post supportedmethods private string l10n string key return l10n get string welcome toadlet key getstring welcometoadlet private string l10n string key string pattern string value return l10n get string welcome toadlet key new string pattern new string value getstring welcometoadlet public static void maybe display wrapper logfile toadlet context ctx html node content node final file logs new file wrapper log long log size logs length if logs exists logs is file logs can read log size 0 try html node log infobox content node add child ctx get page maker get infobox infobox info current status html node log infobox content ctx get page maker get content node log infobox boolean is short file log size 2000 string content file util readutf logs is short file 0 log size 2000 int eol content index of n boolean shall strip first line is short file eol 0 log infobox content add child content substring shall strip first line eol 1 0 replace all n br n catch io exception e maybedisplaywrapperlogfile toadletcontext htmlnode contentnode logsize isfile canread logsize htmlnode loginfobox contentnode addchild getpagemaker getinfobox htmlnode loginfoboxcontent getpagemaker getcontentnode loginfobox isshortfile logsize fileutil isshortfile logsize indexof shallstripfirstline isshortfile loginfoboxcontent addchild shallstripfirstline replaceall ioexception public plugin info wrapper plugin respirator pr fred plugin plug string filename this plug plug class name plug get class to string this filename filename this pr pr thread name p class name replace all class hash code start system current time millis is bandwidth indicator plug instanceof fred plugin bandwidth indicator is pproxy plugin plug instanceof fred pluginhttp is threadless plugin plug instanceof fred plugin threadless isip detector plugin plug instanceof fred pluginip detector is port forward plugin plug instanceof fred plugin port forward is multiple plugin plug instanceof fred plugin multiple isfcp plugin plug instanceof fred pluginfcp is versioned plugin plug instanceof fred plugin versioned is long versioned plugin plug instanceof fred plugin real versioned is themed plugin plug instanceof fred plugin themed isl10n plugin plug instanceof fred pluginl10n is updatedable plugin plug instanceof fred plugin uof plugininfowrapper pluginrespirator fredplugin classname getclass tostring threadname classname replaceall _ hashcode currenttimemillis isbandwidthindicator fredpluginbandwidthindicator ispproxyplugin fredpluginhttp isthreadlessplugin fredpluginthreadless isipdetectorplugin fredpluginipdetector isportforwardplugin fredpluginportforward ismultipleplugin fredpluginmultiple isfcpplugin fredpluginfcp isversionedplugin fredpluginversioned islongversionedplugin fredpluginrealversioned isthemedplugin fredpluginthemed isl10nplugin fredpluginl10n isupdatedableplugin fredpluginuof void set thread thread ps if thread null throw new illegal state exception already set a thread thread ps thread set name thread name setthread illegalstateexception setname threadname override public string to string return id thread name name class name started new date start to string tostring threadname classname tostring public string get thread name return thread name getthreadname threadname public long get started return start getstarted public string get plugin class name return plug get class get name getpluginclassname getclass getname public string get plugin version if is versioned plugin return fred plugin versioned plug get version else return l10n get string pproxy toadlet no version getpluginversion isversionedplugin fredpluginversioned getversion getstring pproxytoadlet noversion public synchronized string get plugin toadlet symlinks return toadlet links to array new string 0 getplugintoadletsymlinks toadletlinks toarray public synchronized boolean add plugin toadlet symlink string linkfrom if toadlet links size 1 toadlet links new hash set string return toadlet links add linkfrom addplugintoadletsymlink toadletlinks toadletlinks hashset toadletlinks public synchronized boolean remove plugin toadlet symlink string linkfrom if toadlet links size 1 return false return toadlet links remove linkfrom removeplugintoadletsymlink toadletlinks toadletlinks tell the plugin to quit interrupt it if it s a thread based plugin which might be sleeping then call remove plugin on it on the manager either now if it s threadless or after it terminates if it s thread based param manager the plugin manager object param max wait time if a plugin is thread based we can wait for it to terminate set to 1 if you don t want to wait at all 0 to wait forever or else a value in milliseconds public void stop plugin plugin manager manager int max wait time unregister manager plug terminate synchronized this stopping true if thread null thread interrupt will be removed when the thread exits if max wait time 0 try thread join max wait time catch interrupted exception e logger normal this stop plugin interrupted while join ed to terminating plugin thread maybe one plugin stopping another if thread is alive string error waited for thread for plug to exit for max wait time ms and it is still alive logger error this error system err println error dump the thread would require post 1 4 features close the jar file so we may delete reload it class loader cl plug get class get class loader if cl instanceof jar class loader closer close jar class loader cl always remove plugin manager remove plugin this removeplugin maxwaittime stopplugin pluginmanager maxwaittime maxwaittime maxwaittime interruptedexception stopplugin isalive maxwaittime classloader getclass getclassloader jarclassloader jarclassloader removeplugin unregister the plugin from any user interface or other callbacks it may be registered with call this before manager remove plugin the plugin becomes unvisitable immediately but it may take time for it to shut down completely void unregister plugin manager manager synchronized this if unregistered return unregistered true manager unregister plugin toadlet this if isip detector plugin manager node ip detector unregisterip detector plugin fred pluginip detector plug if is port forward plugin manager node ip detector unregister port forward plugin fred plugin port forward plug if is bandwidth indicator manager node ip detector unregister bandwidth indicator plugin fred plugin bandwidth indicator plug removeplugin pluginmanager unregisterplugintoadlet isipdetectorplugin ipdetector unregisteripdetectorplugin fredpluginipdetector isportforwardplugin ipdetector unregisterportforwardplugin fredpluginportforward isbandwidthindicator ipdetector unregisterbandwidthindicatorplugin fredpluginbandwidthindicator public boolean is pproxy plugin return is pproxy plugin ispproxyplugin ispproxyplugin public string get filename return filename getfilename public boolean is bandwidth indicator return is bandwidth indicator isbandwidthindicator isbandwidthindicator public boolean is threadless plugin return is threadless plugin isthreadlessplugin isthreadlessplugin public boolean isip detector plugin return isip detector plugin isipdetectorplugin isipdetectorplugin public boolean is port forward plugin return is port forward plugin isportforwardplugin isportforwardplugin public boolean is multiple plugin return is multiple plugin ismultipleplugin ismultipleplugin public boolean isfcp plugin return isfcp plugin isfcpplugin isfcpplugin public boolean is themed plugin return is themed plugin isthemedplugin isthemedplugin public boolean isl10n plugin return isl10n plugin isl10nplugin isl10nplugin public boolean is updatedable plugin return is updatedable plugin isupdatedableplugin isupdatedableplugin public synchronized boolean is stopping return stopping isstopping public long get plugin long version if is long versioned plugin return fred plugin real versioned plug get real version else return 1 getpluginlongversion islongversionedplugin fredpluginrealversioned getrealversion public local file insert toadlet node client core core high level simple client high level simple client super high level simple client this core core localfileinserttoadlet nodeclientcore highlevelsimpleclient highlevelsimpleclient highlevelsimpleclient fixme reentrancy issues with current path fix running two at once see freenet clients http toadlet handle get java net uri freenet clients http toadlet context override public void handle get uri uri http request request toadlet context toadlet context throws toadlet context closed exception io exception redirect exception freeneturi furi null string key request get param key if key null try furi new freeneturi key catch malformedurl exception e furi null string extra if furi null extra key furi toascii string file this path string path request get param path if path length 0 if current path null current path new file system get property user home fixme what if user home is denied write permanent redirect toadlet context found path url encoder encode current path get absolute path true extra return this path new file path get canonical file page maker page maker toadlet context get page maker if core allow upload from this path html node page node page maker get page node l10n listing title path this path get absolute path toadlet context html node content node page maker get content node page node html node infoboxe content node add child page maker get infobox infobox error forbidden html node infoboxe content page maker get content node infoboxe infoboxe content add child l10n dir access denied this path current path if core allow upload from this path file allowed dirs core get allowed upload dirs if allowed dirs length 0 send error page toadlet context 403 forbidden l10n dir access denied return else this path allowed dirs core node fast weak random next int allowed dirs length if current path null current path this path html node page node if current path exists current path is directory current path can read known safe at this point current path this path page node page maker get page node l10n listing title path current path get absolute path toadlet context html node content node page maker get content node page node if toadlet context is allowed full access content node add child core alerts create summary html node infobox div content node add child div class infobox infobox div add child div class infobox header l10n listing path current path get absolute path html node listing div infobox div add child div class infobox content file files current path list files arrays sort files new comparator file public int compare file first file file second file if first file is directory second file is directory return 1 if first file is directory second file is directory return 1 return first file get name compare to ignore case second file get name html node listing table listing div add child table html node header row listing table add child tr header row add child th header row add child th l10n file header header row add child th l10n size header add filesystem roots fsck windows file roots file list roots for int root index 0 root count roots length root index root count root index file current root roots root index html node root row listing table add child tr root row add child td html node root link cell node root row add child td root link cell node add child a href path url encoder encode current root get canonical path false extra current root get canonical path root row add child td add back link if current path get parent null html node backlink row listing table add child tr backlink row add child td html node backlink cell node backlink row add child td backlink cell node add child a href path url encoder encode current path get parent false extra backlink row add child td for int file index 0 file count files length file index file count file index file current file files file index html node file row listing table add child tr if current file is directory if current file can read html node cell node file row add child td html node form node toadlet context add form child cell node queue insert local file form form node add child input new string type name value new string hidden filename current file get absolute path form node add child input new string type name value new string submit insert local dir l10n insert if furi null form node add child input new string type name value new string hidden key furi toascii string html node directory cell node file row add child td directory cell node add child a href path url encoder encode current file get absolute path false extra current file get name else file row add child td file row add child td class unreadable file current file get name file row add child td else if current file can read html node cell node file row add child td html node form node toadlet context add form child cell node queue insert local file form form node add child input new string type name value new string hidden filename current file get absolute path form node add child input new string type name value new string submit insert local file l10n insert if furi null form node add child input new string type name value new string hidden key furi toascii string file row add child td current file get name file row add child td class right align string value of current file length else file row add child td file row add child td class unreadable file current file get name file row add child td class right align string value of current file length else page node page maker get page node l10n listing title path current path get absolute path toadlet context html node content node page maker get content node page node if toadlet context is allowed full access content node add child core alerts create summary html node infobox div content node add child div class infobox infobox div add child div class infobox header l10n listing path current path get absolute path html node listing div infobox div add child div class infobox content listing div add child l10n dir cannot be read path current path get absolute path html node ul node listing div add child ul ul node add child li l10n check path exist ul node add child li l10n check path is dir ul node add child li l10n check path readable writehtml reply toadlet context 200 ok page node generate currentpath handleget toadletcontext handleget httprequest toadletcontext toadletcontext toadletcontextclosedexception ioexception redirectexception getparam malformedurlexception toasciistring thispath getparam currentpath currentpath getproperty writepermanentredirect toadletcontext urlencoder currentpath getabsolutepath thispath getcanonicalfile pagemaker pagemaker toadletcontext getpagemaker allowuploadfrom thispath htmlnode pagenode pagemaker getpagenode listingtitle thispath getabsolutepath toadletcontext htmlnode contentnode pagemaker getcontentnode pagenode htmlnode contentnode addchild pagemaker getinfobox htmlnode infoboxecontent pagemaker getcontentnode infoboxecontent addchild diraccessdenied thispath currentpath allowuploadfrom thispath alloweddirs getalloweduploaddirs alloweddirs senderrorpage toadletcontext diraccessdenied thispath alloweddirs fastweakrandom nextint alloweddirs currentpath currentpath thispath htmlnode pagenode currentpath currentpath isdirectory currentpath canread currentpath thispath pagenode pagemaker getpagenode listingtitle currentpath getabsolutepath toadletcontext htmlnode contentnode pagemaker getcontentnode pagenode toadletcontext isallowedfullaccess contentnode addchild createsummary htmlnode infoboxdiv contentnode addchild infoboxdiv addchild currentpath getabsolutepath htmlnode listingdiv infoboxdiv addchild currentpath listfiles firstfile secondfile firstfile isdirectory secondfile isdirectory firstfile isdirectory secondfile isdirectory firstfile getname comparetoignorecase secondfile getname htmlnode listingtable listingdiv addchild htmlnode headerrow listingtable addchild headerrow addchild headerrow addchild fileheader headerrow addchild sizeheader listroots rootindex rootcount rootindex rootcount rootindex currentroot rootindex htmlnode rootrow listingtable addchild rootrow addchild htmlnode rootlinkcellnode rootrow addchild rootlinkcellnode addchild urlencoder currentroot getcanonicalpath currentroot getcanonicalpath rootrow addchild currentpath getparent htmlnode backlinkrow listingtable addchild backlinkrow addchild htmlnode backlinkcellnode backlinkrow addchild backlinkcellnode addchild urlencoder currentpath getparent backlinkrow addchild fileindex filecount fileindex filecount fileindex currentfile fileindex htmlnode filerow listingtable addchild currentfile isdirectory currentfile canread htmlnode cellnode filerow addchild htmlnode formnode toadletcontext addformchild cellnode insertlocalfileform formnode addchild currentfile getabsolutepath formnode addchild formnode addchild toasciistring htmlnode directorycellnode filerow addchild directorycellnode addchild urlencoder currentfile getabsolutepath currentfile getname filerow addchild filerow addchild currentfile getname filerow addchild currentfile canread htmlnode cellnode filerow addchild htmlnode formnode toadletcontext addformchild cellnode insertlocalfileform formnode addchild currentfile getabsolutepath formnode addchild formnode addchild toasciistring filerow addchild currentfile getname filerow addchild valueof currentfile filerow addchild filerow addchild currentfile getname filerow addchild valueof currentfile pagenode pagemaker getpagenode listingtitle currentpath getabsolutepath toadletcontext htmlnode contentnode pagemaker getcontentnode pagenode toadletcontext isallowedfullaccess contentnode addchild createsummary htmlnode infoboxdiv contentnode addchild infoboxdiv addchild currentpath getabsolutepath htmlnode listingdiv infoboxdiv addchild listingdiv addchild dircannotberead currentpath getabsolutepath htmlnode ulnode listingdiv addchild ulnode addchild checkpathexist ulnode addchild checkpathisdir ulnode addchild checkpathreadable writehtmlreply toadletcontext pagenode arrays sort files new comparator file public int compare file first file file second file if first file is directory second file is directory return 1 if first file is directory second file is directory return 1 return first file get name compare to ignore case second file get name firstfile secondfile firstfile isdirectory secondfile isdirectory firstfile isdirectory secondfile isdirectory firstfile getname comparetoignorecase secondfile getname private string l10n string key string pattern string value return l10n get string local file insert toadlet key new string pattern new string value getstring localfileinserttoadlet private string l10n string msg return l10n get string local file insert toadlet msg getstring localfileinserttoadlet see freenet clients http toadlet supported methods override public string supported methods return get post supportedmethods supportedmethods fcp plugin message simple field set fs throws message invalid exception identifier fs get identifier if identifier null throw new message invalid exception protocol error message missing field fcp plugin message must contain a identifier field null false pluginname fs get plugin name if pluginname null throw new message invalid exception protocol error message missing field fcp plugin message must contain a plugin name field identifier false boolean havedata data equals fs get end marker string data length string fs get data length if havedata data length string null throw new message invalid exception protocol error message invalid field a nondata message can t have a data length field identifier false if havedata if data length string null throw new message invalid exception protocol error message missing field need data length on a datamessage identifier false try data length long parse long data length string 10 catch number format exception e throw new message invalid exception protocol error message error parsing number error parsing data length field e get message identifier false else data length 1 plugparams fs subset param prefix fcppluginmessage simplefieldset messageinvalidexception messageinvalidexception protocolerrormessage missing_field fcppluginmessage pluginname messageinvalidexception protocolerrormessage missing_field fcppluginmessage pluginname getendmarker datalengthstring datalength datalengthstring messageinvalidexception protocolerrormessage invalid_field datalength datalengthstring messageinvalidexception protocolerrormessage missing_field datalength datalength parselong datalengthstring numberformatexception messageinvalidexception protocolerrormessage error_parsing_number datalength getmessage datalength param_prefix override string get identifier return identifier getidentifier override boolean is global return false isglobal override long data length return data length datalength datalength override public simple field set get field set return null simplefieldset getfieldset override public string get name return name getname override public void run final fcp connection handler handler final node node throws message invalid exception bucket data2 this bucket plugin talker pt try pt new plugin talker node handler pluginname identifier handler has full access catch plugin not found exception e throw new message invalid exception protocol error message no such plugin pluginname not found or is not a fcp plugin identifier false pt send plugparams data2 fcpconnectionhandler messageinvalidexception plugintalker plugintalker hasfullaccess pluginnotfoundexception messageinvalidexception protocolerrormessage no_such_plugin fcpplugin override public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception param node param old if true use the old ark rather than the new ark nodeark inserter node node node crypto crypto nodeip port detector detector boolean enablear ks this node node this crypto crypto this detector detector logminor logger should log logger minor this if crypto is opennet darknet opennet string opennet else darknet opennet string darknet this enabled enablear ks nodearkinserter nodecrypto nodeipportdetector enablearks shouldlog isopennet darknetopennetstring darknetopennetstring enablearks private boolean can start void start if enabled return can start true update canstart canstart public void update logminor logger should log logger minor this if logminor logger minor this update if checkip updated return we ll broadcast the new physical udp entry to our connected peers via a differential node reference we ll err on the side of caution and not update our peer to an empty physical udp entry using a differential node reference simple field set nfs crypto export public field set false false true string entries nfs get all physical udp if entries null simple field set fs new simple field set true fs put overwrite physical udp entries if logminor logger minor this darknet opennet string ref s physical udp is fs to string node peers locally broadcast diff node ref fs crypto is opennet crypto is opennet else if logminor logger minor this darknet opennet string ref s physical udp is null proceed with inserting the ark if logminor logger minor this inserting darknet opennet string ark because peers list changed if inserter null already inserting re insert after finished synchronized this should insert true return otherwise need to start an insert if node no connected peers can t start an insert yet synchronized this should insert true return start inserter shouldlog checkipupdated simplefieldset exportpublicfieldset getall simplefieldset simplefieldset putoverwrite darknetopennetstring tostring locallybroadcastdiffnoderef isopennet isopennet darknetopennetstring darknetopennetstring shouldinsert noconnectedpeers shouldinsert startinserter private boolean checkip updated peer p detector detect primary peers if p null if logminor logger minor this not inserting darknet opennet string ark because no ip address return false no point inserting synchronized this if last inserted peers null if p length last inserted peers length return true for int i 0 i p length i if p i strict equals last inserted peers i return true else we ve not inserted an ark that we know about ie since startup return true return false checkipupdated detectprimarypeers darknetopennetstring lastinsertedpeers lastinsertedpeers strictequals lastinsertedpeers private void start inserter if can start if logminor logger minor this darknet opennet string ark inserter can t start yet return if logminor logger minor this starting darknet opennet string ark inserter simple field set fs crypto export public field set false false true remove some unnecessary fields that only cause collisions delete entire ark field for now changing this and automatically moving to the new may be supported in future fs remove subset ark fs remove value location fs remove value sig fs remove version keep version because of its significance in reconnection string s fs to string byte buf try buf s get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e bucket b new simple read only array bucket buf long number crypto myark number insertable clientssk ark crypto myark freeneturi uri ark get inserturi set key type usk set suggested edition number if logminor logger minor this inserting darknet opennet string ark uri contents n s inserter new client putter this b uri new client metadata text plain it won t quite fit in an ssk anyway node client core make client short 0 true get insert context true request starter interactive priority class false false this null null false try node client core client context start inserter false synchronized this if fs get physical udp null last inserted peers null else try string all fs get all physical udp peer peers new peer all length for int i 0 i all length i peers i new peer all i false last inserted peers peers catch peer parse exception e1 logger error this error parsing own darknet opennet string ref e1 fs get physical udp e1 catch unknown host exception e1 logger error this error parsing own darknet opennet string ref e1 fs get physical udp e1 catch insert exception e on failure e inserter null startinserter canstart darknetopennetstring darknetopennetstring simplefieldset exportpublicfieldset removesubset removevalue removevalue tostring getbytes unsupportedencodingexception simplereadonlyarraybucket myarknumber insertableclientssk getinserturi setkeytype setsuggestededition darknetopennetstring clientputter clientmetadata clientcore makeclient getinsertcontext requeststarter interactive_priority_class clientcore clientcontext lastinsertedpeers getall lastinsertedpeers peerparseexception darknetopennetstring unknownhostexception darknetopennetstring insertexception onfailure public void on success fetch result result client getter state object container container impossible onsuccess fetchresult clientgetter objectcontainer public void on failure fetch exception e client getter state object container container impossible onfailure fetchexception clientgetter objectcontainer public void on success base client putter state object container container freeneturi uri state geturi if logminor logger minor this darknet opennet string ark insert succeeded uri synchronized this inserter null if should insert return should insert false start inserter onsuccess baseclientputter objectcontainer darknetopennetstring shouldinsert shouldinsert startinserter public void on failure insert exception e base client putter state object container container if logminor logger minor this darknet opennet string ark insert failed e synchronized this last inserted peers null better try again try thread sleep 5000 catch interrupted exception e1 ignore start inserter onfailure insertexception baseclientputter objectcontainer darknetopennetstring lastinsertedpeers interruptedexception startinserter public void on generateduri freeneturi uri base client putter state object container container if logminor logger minor this generated uri for darknet opennet string ark uri long l uri get suggested edition if l crypto myark number logger error this inserted darknet opennet string ark edition lower than attempted l expected crypto myark number else if l crypto myark number if logminor logger minor this darknet opennet string ark number moving from crypto myark number to l crypto myark number l if crypto is opennet node write opennet file else node write node file we ll broadcast the new ark edition to our connected peers via a differential node reference simple field set fs new simple field set true fs put single ark number long to string crypto myark number node peers locally broadcast diff node ref fs crypto is opennet crypto is opennet ongenerateduri baseclientputter objectcontainer darknetopennetstring getsuggestededition myarknumber darknetopennetstring myarknumber myarknumber darknetopennetstring myarknumber myarknumber isopennet writeopennetfile writenodefile simplefieldset simplefieldset putsingle tostring myarknumber locallybroadcastdiffnoderef isopennet isopennet public void on connected peer if checkip updated return synchronized this if should insert return already inserting if inserter null return synchronized this should insert false start inserter onconnectedpeer checkipupdated shouldinsert shouldinsert startinserter public void on major progress object container container ignore onmajorprogress objectcontainer public void on fetchable base client putter state object container container ignore we don t care onfetchable baseclientputter objectcontainer public boolean persistent return false public void remove from object container container throw new unsupported operation exception removefrom objectcontainer unsupportedoperationexception private boolean warn on remove from empty public void set warn on remove from empty warn on remove from empty true warnonremovefromempty setwarnonremovefromempty warnonremovefromempty constructor param length length in bits public counting bloom filter int length int k super length k filter byte buffer allocate this length 4 countingbloomfilter bytebuffer constructor param file disk file param length length in bits throws io exception protected counting bloom filter file file int length int k throws io exception super length k int file length length 4 if file exists file length file length need rebuild true random access file raf new random access file file rw raf set length file length filter raf get channel map map mode read write 0 file length load ioexception countingbloomfilter ioexception filelength filelength needrebuild randomaccessfile randomaccessfile setlength filelength getchannel mapmode read_write filelength public counting bloom filter int length int k byte buffer super length k assert buffer length length 4 filter byte buffer wrap buffer countingbloomfilter bytebuffer override public boolean get bit int offset byte b filter get offset 4 byte v byte b offset 4 2 3 return v 0 getbit override public void set bit int offset byte b filter get offset 4 byte v byte b offset 4 2 3 if v 3 return overflow b 3 offset 4 2 unset bit b v 1 offset 4 2 set bit filter put offset 4 b setbit override public void unset bit int offset byte b filter get offset 4 byte v byte b offset 4 2 3 if v 0 warn on remove from empty logger error this unsetting bit but already unset probable double remove can cause false negatives is very bad new exception error if v 0 v 3 return overflow underflow b 3 offset 4 2 unset bit b v 1 offset 4 2 set bit filter put offset 4 b unsetbit warnonremovefromempty override public void fork int k lock write lock lock try file temp file file create temp file bloom tmp temp file delete on exit forked filter new counting bloom filter temp file length k catch io exception e forked filter new counting bloom filter length k finally lock write lock unlock writelock tempfile createtempfile tempfile deleteonexit forkedfilter countingbloomfilter tempfile ioexception forkedfilter countingbloomfilter writelock public class marble function extends compound function2d public marble function super new turbulence function new noise 6 marblefunction compoundfunction2d marblefunction turbulencefunction public marble function function2d basis super basis marblefunction public float evaluate float x float y return float math pow 0 5 math sin 8 basis evaluate x y 1 0 77 public void set up throws exception super set up m message manager new wot message manager db null board my board new board en board1 hash set board my boards new hash set board my boards add my board my boards add new board en board2 freeneturi author requestssk new freeneturi ssk nu16tncs7 isp ta9gw6nf8c3l qpjgfha2 kwt tom ju nk fj cioug sl6ipoe9gl nai9w cp1vpm8k181 gjw62 hhy so aqacaae freeneturi author insertssk new freeneturi ssk ykhv0x0k8jtrg olqwvs4s2 jvmnm64zv5vo nj mfz1nyi fj cioug sl6ipoe9gl nai9w cp1vpm8k181 gjw62 hhy so aqecaae wot identity my author new wot own identity wot identity getuid fromuri author requestssk author requestssk author insertssk nickname freeneturi my thread realuri new freeneturi chk 7qms7 lkly ihbz88i0 u97lxrlks2ux nwzwq oj pd xn jw ila f sjww2mp wlz wx7 fgp zbb er yd lkqie1u srcn lbm aaia 8 string my threadid afe6519b 7fb2 4533 b172 1f966e79d127 my author getuid m message realuri new freeneturi chk 7qms7 lkly ihbz88i0 u97lxrlks2ux nwzwq oj pd xn jw ila f sjww2mp wlz wx7 fgp zbb er yd lkqie1u srcn lbm aaia 8 string my messageid 2a3a8e7e 9e53 4978 a8fd 17b2d92d949c my author getuid list message list message reference message references new array list message list message reference 2 for board board my boards message references add new message list message reference my threadid my thread realuri board message references add new message list message reference my messageid m message realuri board m message list new wot message list my author wot message list assembleuri author requestssk 123 message references list attachment attachments new array list attachment attachments add new attachment new freeneturi ksk attachment1 10001 attachments add new attachment new freeneturi ksk attachment2 10002 m message wot message construct m message list m message realuri my messageid new wot messageuri m message list geturi my messageid new wot messageuri m message list geturi my threadid my boards my board my author message title new date 109 4 3 16 15 14 message body n new line attachments m hardcoded encoded message new string xml version 1 0 encoding utf 8 standalone no freetalk testing message version 1 messageid cdata 2a3a8e7e 9e53 4978 a8fd 17b2d92d949c nu16tncs7 isp ta9gw6nf8c3l qpjgfha2 kwt tom ju nk messageid subject cdata message title subject date 2009 05 03 date time 16 15 14 time boards board cdata en board1 board board cdata en board2 board boards reply board cdata en board1 reply board in reply to message order 0 order messageid cdata afe6519b 7fb2 4533 b172 1f966e79d127 nu16tncs7 isp ta9gw6nf8c3l qpjgfha2 kwt tom ju nk messageid messageuri cdata ssk nu16tncs7 isp ta9gw6nf8c3l qpjgfha2 kwt tom ju nk fj cioug sl6ipoe9gl nai9w cp1vpm8k181 gjw62 hhy so aqacaae freetalk testing 7c message list 123 afe6519b 7fb2 4533 b172 1f966e79d127 messageuri message thread messageid cdata 2a3a8e7e 9e53 4978 a8fd 17b2d92d949c nu16tncs7 isp ta9gw6nf8c3l qpjgfha2 kwt tom ju nk messageid messageuri cdata ssk nu16tncs7 isp ta9gw6nf8c3l qpjgfha2 kwt tom ju nk fj cioug sl6ipoe9gl nai9w cp1vpm8k181 gjw62 hhy so aqacaae freetalk testing 7c message list 123 2a3a8e7e 9e53 4978 a8fd 17b2d92d949c messageuri thread in reply to body cdata message body new line body attachments file key cdata ksk attachment1 key size cdata 10001 size file file key cdata ksk attachment2 key size cdata 10002 size file attachments message freetalk testing setup setup mmessagemanager wotmessagemanager myboard hashset myboards hashset myboards myboard myboards authorrequestssk ispta9gw6nf8c3lqpjgfha2kwttomjunk fjciougsl6ipoe9glnai9wcp1vpm8k181gjw62hhyso authorinsertssk ykhv0x0k8jtrgolqwvs4s2jvmnm64zv5vonjmfz1nyi fjciougsl6ipoe9glnai9wcp1vpm8k181gjw62hhyso wotidentity myauthor wotownidentity wotidentity getuidfromuri authorrequestssk authorrequestssk authorinsertssk mythreadrealuri 7qms7lklyihbz88i0 u97lxrlks2uxnwzwqojpdxnjw fsjww2mpwlzwx7fgpzbberydlkqie1usrcn mythreadid myauthor mmessagerealuri 7qms7lklyihbz88i0 u97lxrlks2uxnwzwqojpdxnjw fsjww2mpwlzwx7fgpzbberydlkqie1usrcn mymessageid myauthor messagelist messagereference messagereferences arraylist messagelist messagereference myboards messagereferences messagelist messagereference mythreadid mythreadrealuri messagereferences messagelist messagereference mymessageid mmessagerealuri mmessagelist wotmessagelist myauthor wotmessagelist authorrequestssk messagereferences arraylist mmessage wotmessage mmessagelist mmessagerealuri mymessageid wotmessageuri mmessagelist mymessageid wotmessageuri mmessagelist mythreadid myboards myboard myauthor nnew mhardcodedencodedmessage ispta9gw6nf8c3lqpjgfha2kwttomjunk replyboard replyboard inreplyto ispta9gw6nf8c3lqpjgfha2kwttomjunk ispta9gw6nf8c3lqpjgfha2kwttomjunk fjciougsl6ipoe9glnai9wcp1vpm8k181gjw62hhyso 7cmessagelist ispta9gw6nf8c3lqpjgfha2kwttomjunk ispta9gw6nf8c3lqpjgfha2kwttomjunk fjciougsl6ipoe9glnai9wcp1vpm8k181gjw62hhyso 7cmessagelist inreplyto public void test encode throws exception byte array output stream encoded message new byte array output stream 4096 wot messagexml encode m message encoded message assert equals m hardcoded encoded message encoded message to string replace all r n testencode bytearrayoutputstream encodedmessage bytearrayoutputstream wotmessagexml mmessage encodedmessage assertequals mhardcodedencodedmessage encodedmessage tostring replaceall public void test decode throws exception byte array input stream is new byte array input stream m hardcoded encoded message get bytes byte array output stream decoded and encoded message new byte array output stream 4096 wot messagexml encode wot messagexml decode m message manager is m message list m message realuri decoded and encoded message assert equals m hardcoded encoded message decoded and encoded message to string replace all r n testdecode bytearrayinputstream bytearrayinputstream mhardcodedencodedmessage getbytes bytearrayoutputstream decodedandencodedmessage bytearrayoutputstream wotmessagexml wotmessagexml mmessagemanager mmessagelist mmessagerealuri decodedandencodedmessage assertequals mhardcodedencodedmessage decodedandencodedmessage tostring replaceall private final weak hash map e object map public weak hash set map new weak hash map e object weakhashmap weakhashset weakhashmap override public boolean add e key return map put key null null override public void clear map clear override public boolean contains object key return map contains key key containskey override public boolean contains all collection arg0 return map key set contains all arg0 containsall keyset containsall override public boolean is empty return map is empty isempty isempty override public iterator e iterator return map key set iterator keyset override public boolean remove object key return map remove key null override public int size return map size override public object to array return map key set to array toarray keyset toarray override public t t to array t arg0 return map key set to array arg0 toarray keyset toarray public fetch context long cur max length long cur max temp length int max metadata size int max recursion level int max archive restarts int max archive levels boolean dont enter implicit archives int max splitfile threads int max splitfile block retries int max non splitfile retries int maxusk retries boolean allow splitfiles boolean follow redirects boolean local request only int max data blocks per segment int max check blocks per segment bucket factory bucket factory client event producer producer boolean cache local requests boolean ignore too many path components this blocks null this max output length cur max length this max temp length cur max temp length this max metadata size max metadata size this max recursion level max recursion level this max archive restarts max archive restarts this max archive levels max archive levels this dont enter implicit archives dont enter implicit archives this max splitfile threads max splitfile threads this max splitfile block retries max splitfile block retries this max non splitfile retries max non splitfile retries this maxusk retries maxusk retries this allow splitfiles allow splitfiles this follow redirects follow redirects this local request only local request only this event producer producer this max data blocks per segment max data blocks per segment this max check blocks per segment max check blocks per segment this cache local requests cache local requests this ignore too many path components ignore too many path components has own event producer true fetchcontext curmaxlength curmaxtemplength maxmetadatasize maxrecursionlevel maxarchiverestarts maxarchivelevels dontenterimplicitarchives maxsplitfilethreads maxsplitfileblockretries maxnonsplitfileretries maxuskretries allowsplitfiles followredirects localrequestonly maxdatablockspersegment maxcheckblockspersegment bucketfactory bucketfactory clienteventproducer cachelocalrequests ignoretoomanypathcomponents maxoutputlength curmaxlength maxtemplength curmaxtemplength maxmetadatasize maxmetadatasize maxrecursionlevel maxrecursionlevel maxarchiverestarts maxarchiverestarts maxarchivelevels maxarchivelevels dontenterimplicitarchives dontenterimplicitarchives maxsplitfilethreads maxsplitfilethreads maxsplitfileblockretries maxsplitfileblockretries maxnonsplitfileretries maxnonsplitfileretries maxuskretries maxuskretries allowsplitfiles allowsplitfiles followredirects followredirects localrequestonly localrequestonly eventproducer maxdatablockspersegment maxdatablockspersegment maxcheckblockspersegment maxcheckblockspersegment cachelocalrequests cachelocalrequests ignoretoomanypathcomponents ignoretoomanypathcomponents hasowneventproducer copy a fetch context param ctx param maskid param keep producer param blocks storing a block set to the database is not supported see comments on simple block set object can new public fetch context fetch context ctx int maskid boolean keep producer block set blocks if keep producer this event producer ctx event producer else this event producer new simple event producer has own event producer keep producer this ignore too many path components ctx ignore too many path components if blocks null this blocks blocks else this blocks ctx blocks this allowedmime types ctx allowedmime types this maxusk retries ctx maxusk retries if maskid identical mask this max output length ctx max output length this max metadata size ctx max metadata size this max temp length ctx max temp length this max recursion level ctx max recursion level this max archive restarts ctx max archive restarts this max archive levels ctx max archive levels this dont enter implicit archives ctx dont enter implicit archives this max splitfile threads ctx max splitfile threads this max splitfile block retries ctx max splitfile block retries this max non splitfile retries ctx max non splitfile retries this allow splitfiles ctx allow splitfiles this follow redirects ctx follow redirects this local request only ctx local request only this max data blocks per segment ctx max data blocks per segment this max check blocks per segment ctx max check blocks per segment this cache local requests ctx cache local requests this returnzip manifests ctx returnzip manifests else if maskid splitfile default block mask this max output length ctx max output length this max metadata size ctx max metadata size this max temp length ctx max temp length this max recursion level 1 this max archive restarts 0 this max archive levels ctx max archive levels this dont enter implicit archives true this max splitfile threads 0 this max splitfile block retries ctx max splitfile block retries this max non splitfile retries ctx max splitfile block retries this allow splitfiles false this follow redirects false this local request only ctx local request only this max data blocks per segment 0 this max check blocks per segment 0 this cache local requests ctx cache local requests this returnzip manifests false else if maskid splitfile default mask this max output length ctx max output length this max temp length ctx max temp length this max metadata size ctx max metadata size this max recursion level ctx max recursion level this max archive restarts ctx max archive restarts this max archive levels ctx max archive levels this dont enter implicit archives ctx dont enter implicit archives this max splitfile threads ctx max splitfile threads this max splitfile block retries ctx max splitfile block retries this max non splitfile retries ctx max non splitfile retries this allow splitfiles ctx allow splitfiles this follow redirects ctx follow redirects this local request only ctx local request only this max data blocks per segment ctx max data blocks per segment this max check blocks per segment ctx max check blocks per segment this cache local requests ctx cache local requests this returnzip manifests ctx returnzip manifests else if maskid set return archives this max output length ctx max output length this max metadata size ctx max metadata size this max temp length ctx max temp length this max recursion level ctx max recursion level this max archive restarts ctx max archive restarts this max archive levels ctx max archive levels this dont enter implicit archives ctx dont enter implicit archives this max splitfile threads ctx max splitfile threads this max splitfile block retries ctx max splitfile block retries this max non splitfile retries ctx max non splitfile retries this allow splitfiles ctx allow splitfiles this follow redirects ctx follow redirects this local request only ctx local request only this max data blocks per segment ctx max data blocks per segment this max check blocks per segment ctx max check blocks per segment this cache local requests ctx cache local requests this returnzip manifests true else throw new illegal argument exception fetchcontext keepproducer blockset simpleblockset objectcannew fetchcontext fetchcontext keepproducer blockset keepproducer eventproducer eventproducer eventproducer simpleeventproducer hasowneventproducer keepproducer ignoretoomanypathcomponents ignoretoomanypathcomponents allowedmimetypes allowedmimetypes maxuskretries maxuskretries identical_mask maxoutputlength maxoutputlength maxmetadatasize maxmetadatasize maxtemplength maxtemplength maxrecursionlevel maxrecursionlevel maxarchiverestarts maxarchiverestarts maxarchivelevels maxarchivelevels dontenterimplicitarchives dontenterimplicitarchives maxsplitfilethreads maxsplitfilethreads maxsplitfileblockretries maxsplitfileblockretries maxnonsplitfileretries maxnonsplitfileretries allowsplitfiles allowsplitfiles followredirects followredirects localrequestonly localrequestonly maxdatablockspersegment maxdatablockspersegment maxcheckblockspersegment maxcheckblockspersegment cachelocalrequests cachelocalrequests returnzipmanifests returnzipmanifests splitfile_default_block_mask maxoutputlength maxoutputlength maxmetadatasize maxmetadatasize maxtemplength maxtemplength maxrecursionlevel maxarchiverestarts maxarchivelevels maxarchivelevels dontenterimplicitarchives maxsplitfilethreads maxsplitfileblockretries maxsplitfileblockretries maxnonsplitfileretries maxsplitfileblockretries allowsplitfiles followredirects localrequestonly localrequestonly maxdatablockspersegment maxcheckblockspersegment cachelocalrequests cachelocalrequests returnzipmanifests splitfile_default_mask maxoutputlength maxoutputlength maxtemplength maxtemplength maxmetadatasize maxmetadatasize maxrecursionlevel maxrecursionlevel maxarchiverestarts maxarchiverestarts maxarchivelevels maxarchivelevels dontenterimplicitarchives dontenterimplicitarchives maxsplitfilethreads maxsplitfilethreads maxsplitfileblockretries maxsplitfileblockretries maxnonsplitfileretries maxnonsplitfileretries allowsplitfiles allowsplitfiles followredirects followredirects localrequestonly localrequestonly maxdatablockspersegment maxdatablockspersegment maxcheckblockspersegment maxcheckblockspersegment cachelocalrequests cachelocalrequests returnzipmanifests returnzipmanifests set_return_archives maxoutputlength maxoutputlength maxmetadatasize maxmetadatasize maxtemplength maxtemplength maxrecursionlevel maxrecursionlevel maxarchiverestarts maxarchiverestarts maxarchivelevels maxarchivelevels dontenterimplicitarchives dontenterimplicitarchives maxsplitfilethreads maxsplitfilethreads maxsplitfileblockretries maxsplitfileblockretries maxnonsplitfileretries maxnonsplitfileretries allowsplitfiles allowsplitfiles followredirects followredirects localrequestonly localrequestonly maxdatablockspersegment maxdatablockspersegment maxcheckblockspersegment maxcheckblockspersegment cachelocalrequests cachelocalrequests returnzipmanifests illegalargumentexception make public but just call parent for a field for field copy override public fetch context clone try return fetch context super clone catch clone not supported exception e impossible throw new error e fetchcontext fetchcontext clonenotsupportedexception public void remove from object container container if has own event producer container activate event producer 1 event producer remove from container storing a block set to the database is not supported see comments on simple block set object can new allowedmime types is passed in whoever passes it in is responsible for deleting it container delete this removefrom objectcontainer hasowneventproducer eventproducer eventproducer removefrom blockset simpleblockset objectcannew allowedmimetypes private stack seq stack public ber decoder byte buf this buf buf seq stack new stack seqstack berdecoder seqstack public void start sequence throws bad format exception start sequence byte 0x30 startsequence badformatexception startsequence public void start sequence byte id throws bad format exception if buf ptr id throw new bad format exception unknown sequence expected 0x integer to hex string id got 0x integer to hex string buf ptr ptr int len readber int seq stack push new integer ptr len seq stack push new integer len startsequence badformatexception badformatexception tohexstring tohexstring readberint seqstack seqstack public void end sequence throws bad format exception int length integer seq stack pop int value int pos integer seq stack pop int value if pos ptr throw new bad format exception wrong length of field length pos ptr endsequence badformatexception seqstack intvalue seqstack intvalue badformatexception public boolean sequence has more int length integer seq stack peek int value int pos integer seq stack get seq stack size 2 int value return pos ptr sequencehasmore seqstack intvalue seqstack seqstack intvalue public byte peek raw return buf ptr peekraw public long fetchoid throws bad format exception start sequence byte 0x06 long ret readoid end sequence return ret badformatexception startsequence endsequence private long readoid throws bad format exception if buf ptr 0x2b throw new bad format exception bad start of oid int inptr ptr ptr int length integer seq stack peek int value if length 2 return new long 0 long ret new long length it won t getlonger then this int i for i 0 i length i ret i readber int if ptr inptr length break if i length bring out the scissors long ret2 long ret clone ret new long i 1 for i 0 i ret i ret2 i return ret badformatexception badformatexception seqstack intvalue readberint public byte fetch octet string throws bad format exception start sequence byte 0x04 byte ret read octet string end sequence return ret fetchoctetstring badformatexception startsequence readoctetstring endsequence private byte read octet string int length integer seq stack peek int value byte ret new byte length for int i 0 i length i ret i buf ptr return ret readoctetstring seqstack intvalue public void fetch null throws bad format exception start sequence byte 0x05 end sequence fetchnull badformatexception startsequence endsequence public int fetch int throws bad format exception start sequence byte 0x02 int ret read int end sequence return ret fetchint badformatexception startsequence readint endsequence private int read int int length integer seq stack peek int value int ret 0 for length 0 length ret ret 256 ret ret int buf ptr 256 256 ptr return ret readint seqstack intvalue private int readber int int ret 0 do ret ret 128 ret ret int buf ptr 128 128 ptr while buf ptr 1 0 return ret readberint private final static int sqrt5 int 41 math sqrt 5 public shape filter colormap new linear colormap shapefilter linearcolormap public void set factor float factor this factor factor setfactor public float get factor return factor getfactor set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public void set use alpha boolean use alpha this use alpha use alpha setusealpha usealpha usealpha usealpha public boolean get use alpha return use alpha getusealpha usealpha public void set type int type this type type settype public int get type return type gettype public void set invert boolean invert this invert invert setinvert public boolean get invert return invert getinvert public void set merge boolean merge this merge merge setmerge public boolean get merge return merge getmerge override protected int filter pixels int width int height int in pixels rectangle transformed space int map new int width height make map in pixels map width height int max distance map map width height apply map map in pixels width height max return in pixels filterpixels inpixels transformedspace makemap inpixels distancemap applymap inpixels inpixels public int distance map int map int width int height int xmax width 3 int ymax height 3 int max 0 int v for int y 0 y height y for int x 0 x width x int offset x y width if map offset 0 if x 2 x xmax y 2 y ymax v set edge value x y map width offset xmax ymax else v set value map width offset if v max max v for int y height 1 y 0 y for int x width 1 x 0 x int offset x y width if map offset 0 if x 2 x xmax y 2 y ymax v set edge value x y map width offset xmax ymax else v set value map width offset if v max max v return max distancemap setedgevalue setvalue setedgevalue setvalue private void make map int pixels int map int width int height for int y 0 y height y for int x 0 x width x int offset x y width int b use alpha pixels offset 24 0xff pixel utils brightness pixels offset map offset b one map offset b one 10 makemap usealpha pixelutils private void apply map int map int pixels int width int height int max if max 0 max 1 for int y 0 y height y for int x 0 x width x int offset x y width int m map offset float v 0 int sa 0 sr 0 sg 0 sb 0 if m 0 default color sa sr sg sb 0 sa pixels offset 24 0xff else get v from map v image math clamp factor m max 0 1 switch type case circle up v image math circle up v break case circle down v image math circle down v break case smooth v image math smooth step 0 1 v break if colormap null sr sg sb int v 255 else int c colormap get color v sr c 16 0xff sg c 8 0xff sb c 0xff sa use alpha pixels offset 24 0xff pixel utils brightness pixels offset invert v if necessary if invert sr 255 sr sg 255 sg sb 255 sb write results if merge merge with source int transp 255 int col pixels offset int a col 0xff000000 24 int r col 0xff0000 16 int g col 0xff00 8 int b col 0xff r int sr r transp g int sg g transp b int sb b transp clip colors if r 0 r 0 if r 255 r 255 if g 0 g 0 if g 255 g 255 if b 0 b 0 if b 255 b 255 pixels offset a 24 r 16 g 8 b else write gray shades pixels offset sa 24 sr 16 sg 8 sb applymap imagemath circle_up imagemath circleup circle_down imagemath circledown imagemath smoothstep getcolor usealpha pixelutils private int set edge value int x int y int map int width int offset int xmax int ymax int min v int r1 r2 r3 r4 r5 r1 offset width width 2 r2 r1 width r3 r2 width r4 r3 width r5 r4 width if y 0 x 0 y ymax 2 x xmax 2 return map offset one v map r2 2 one min v v map r3 1 one if v min min v v map r3 3 one if v min min v v map r4 2 one if v min min v v map r2 1 sqrt2 if v min min v v map r2 3 sqrt2 if v min min v v map r4 1 sqrt2 if v min min v v map r4 3 sqrt2 if v min min v if y 1 x 1 y ymax 1 x xmax 1 return map offset min v map r1 1 sqrt5 if v min min v v map r1 3 sqrt5 if v min min v v map r2 4 sqrt5 if v min min v v map r4 4 sqrt5 if v min min v v map r5 3 sqrt5 if v min min v v map r5 1 sqrt5 if v min min v v map r4 sqrt5 if v min min v v map r2 sqrt5 if v min min v return map offset min setedgevalue private int set value int map int width int offset int min v int r1 r2 r3 r4 r5 r1 offset width width 2 r2 r1 width r3 r2 width r4 r3 width r5 r4 width v map r2 2 one min v v map r3 1 one if v min min v v map r3 3 one if v min min v v map r4 2 one if v min min v v map r2 1 sqrt2 if v min min v v map r2 3 sqrt2 if v min min v v map r4 1 sqrt2 if v min min v v map r4 3 sqrt2 if v min min v v map r1 1 sqrt5 if v min min v v map r1 3 sqrt5 if v min min v v map r2 4 sqrt5 if v min min v v map r4 4 sqrt5 if v min min v v map r5 3 sqrt5 if v min min v v map r5 1 sqrt5 if v min min v v map r4 sqrt5 if v min min v v map r2 sqrt5 if v min min v return map offset min setvalue override public string to string return stylize shapeburst tostring set the number of colors to quantize to param num colors the number of colors the default is 256 public void set num colors int num colors this num colors math min math max num colors 8 256 numcolors setnumcolors numcolors numcolors numcolors get the number of colors to quantize to return the number of colors public int get num colors return num colors getnumcolors numcolors set whether to use dithering or not if not the image is posterized param dither true to use dithering public void set dither boolean dither this dither dither setdither return the dithering setting return the current setting public boolean get dither return dither getdither set whether to use a serpentine pattern for return or not this can reduce avalanche artifacts in the output param serpentine true to use serpentine pattern public void set serpentine boolean serpentine this serpentine serpentine setserpentine return the serpentine setting return the current setting public boolean get serpentine return serpentine getserpentine public void quantize int in pixels int out pixels int width int height int num colors boolean dither boolean serpentine int count width height quantizer quantizer new oct tree quantizer quantizer setup num colors quantizer add pixels in pixels 0 count int table quantizer build color table if dither for int i 0 i count i out pixels i table quantizer get index for color in pixels i else int index 0 for int y 0 y height y boolean reverse serpentine y 1 1 int direction if reverse index y width width 1 direction 1 else index y width direction 1 for int x 0 x width x int rgb1 in pixels index int rgb2 table quantizer get index for color rgb1 out pixels index rgb2 int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff int er r1 r2 int eg g1 g2 int eb b1 b2 for int i 1 i 1 i int iy i y if 0 iy iy height for int j 1 j 1 j int jx j x if 0 jx jx width int w if reverse w matrix i 1 3 j 1 else w matrix i 1 3 j 1 if w 0 int k reverse index j index j rgb1 in pixels k r1 rgb1 16 0xff g1 rgb1 8 0xff b1 rgb1 0xff r1 er w sum g1 eg w sum b1 eb w sum in pixels k pixel utils clamp r1 16 pixel utils clamp g1 8 pixel utils clamp b1 index direction inpixels outpixels numcolors octtreequantizer numcolors addpixels inpixels buildcolortable outpixels getindexforcolor inpixels inpixels getindexforcolor outpixels inpixels inpixels pixelutils pixelutils pixelutils override protected int filter pixels int width int height int in pixels rectangle transformed space int out pixels new int width height quantize in pixels out pixels width height num colors dither serpentine return out pixels filterpixels inpixels transformedspace outpixels inpixels outpixels numcolors outpixels override public string to string return colors quantize tostring final linked list fcp message out queue public fcp connection output handler fcp connection handler handler this handler handler this out queue new linked list fcp message linkedlist fcpmessage outqueue fcpconnectionoutputhandler fcpconnectionhandler outqueue linkedlist fcpmessage void start handler server node executor execute this fcp output handler for handler sock get remote socket address handler sock get port getremotesocketaddress getport public void run freenet support logger os thread logpid this try real run catch io exception e if logger should log logger minor this logger minor this caught e e catch out of memory error e oom handler handleoom e catch throwable t logger error this caught t t handler close handler closed output osthread realrun ioexception shouldlog outofmemoryerror oomhandler closedoutput private void real run throws io exception output stream os new buffered output stream handler sock get output stream 4096 while true boolean closed fcp message msg null while true closed handler is closed synchronized out queue if out queue is empty if closed break os flush try out queue wait catch interrupted exception e ignore continue msg out queue remove first break if msg null if closed os flush os close return else msg send os realrun ioexception outputstream bufferedoutputstream getoutputstream fcpmessage isclosed outqueue outqueue isempty outqueue interruptedexception outqueue removefirst public void queue fcp message msg if logger should log logger debug this logger debug this queueing msg new exception debug if msg null throw new null pointer exception synchronized out queue out queue add msg out queue notify all fcpmessage shouldlog nullpointerexception outqueue outqueue outqueue notifyall public void on closed synchronized out queue out queue notify all give a chance to the output handler to flush its queue before the socket is closed see 2019 nextgens while out queue is empty try thread sleep 100 catch interrupted exception e onclosed outqueue outqueue notifyall outqueue isempty interruptedexception public boolean object can new object container container throw new unsupported operation exception fcp connection output handler storage in database not supported objectcannew objectcontainer unsupportedoperationexception fcpconnectionoutputhandler private node service node public node get service node return service node servicenode getservicenode servicenode public service node node service node node servicenode private mutex mutex new mutex public void lock mutex lock public void unlock mutex unlock public static boolean is service node node node return service elem name equals node get name isservicenode elem_name getname private node get device node node node get service node get parent node if node null return null return node get parent node getdevicenode getservicenode getparentnode getparentnode private node get root node return get service node get root node getrootnode getservicenode getrootnode public device get device return new device get root node get device node getdevice getrootnode getdevicenode public device get root device return get device get root device getrootdevice getdevice getrootdevice private final static string service type service type public void set service type string value get service node set node service type value service_type servicetype setservicetype getservicenode setnode service_type public string get service type return get service node get node value service type getservicetype getservicenode getnodevalue service_type private final static string service id service id public void set serviceid string value get service node set node service id value service_id serviceid setserviceid getservicenode setnode service_id public string get serviceid return get service node get node value service id getserviceid getservicenode getnodevalue service_id thanks for giordano sassaroli sassarol cefriel it 09 03 03 private boolean isurl string reference url string url if reference url null url null return false boolean ret url equals reference url if ret true return true string relative ref url http to relativeurl reference url false ret url equals relative ref url if ret true return true return false referenceurl referenceurl referenceurl relativerefurl torelativeurl referenceurl relativerefurl private final static string scpdurl scpdurl public void setscpdurl string value get service node set node scpdurl value getservicenode setnode public string getscpdurl return get service node get node value scpdurl getservicenode getnodevalue public boolean isscpdurl string url return isurl getscpdurl url private final static string control url controlurl public void set controlurl string value get service node set node control url value control_url setcontrolurl getservicenode setnode control_url public string get controlurl return get service node get node value control url getcontrolurl getservicenode getnodevalue control_url public boolean is controlurl string url return isurl get controlurl url iscontrolurl getcontrolurl private final static string event sub url event suburl public void set event suburl string value get service node set node event sub url value event_sub_url eventsuburl seteventsuburl getservicenode setnode event_sub_url public string get event suburl return get service node get node value event sub url geteventsuburl getservicenode getnodevalue event_sub_url public boolean is event suburl string url return isurl get event suburl url iseventsuburl geteventsuburl public boolean loadscpd string scpd str throws invalid description exception try parser parser u pnp getxml parser node scpd node parser parse scpd str if scpd node null return false service data data get service data data setscpd node scpd node catch parser exception e throw new invalid description exception e return true scpdstr invaliddescriptionexception upnp getxmlparser scpdnode scpdstr scpdnode servicedata getservicedata setscpdnode scpdnode parserexception invaliddescriptionexception public boolean loadscpd file file throws parser exception parser parser u pnp getxml parser node scpd node parser parse file if scpd node null return false service data data get service data data setscpd node scpd node return true parserexception upnp getxmlparser scpdnode scpdnode servicedata getservicedata setscpdnode scpdnode private node getscpd node url scpd url throws parser exception parser parser u pnp getxml parser return parser parse scpd url getscpdnode scpdurl parserexception upnp getxmlparser scpdurl private node getscpd node file scpd file throws parser exception parser parser u pnp getxml parser return parser parse scpd file getscpdnode scpdfile parserexception upnp getxmlparser scpdfile private node getscpd node service data data get service data node scpd node data getscpd node if scpd node null return scpd node string scpdurl str getscpdurl try url scpd url new url scpdurl str scpd node getscpd node scpd url catch exception e1 device root dev get root device string url base str root dev geturl base thanks for steven yen 2003 09 03 if url base str null url base str length 0 string location root dev get location string location host http get host location int location port http get port location url base str http get request hosturl location host location port scpdurl str http to relativeurl scpdurl str string new scpdurl str url base str scpdurl str try url new scpdurl new url new scpdurl str scpd node getscpd node new scpdurl catch exception e2 new scpdurl str http get absoluteurl url base str scpdurl str try url new scpdurl new url new scpdurl str scpd node getscpd node new scpdurl catch exception e3 new scpdurl str root dev get description file path scpdurl str try scpd node getscpd node new file new scpdurl str catch exception e4 debug warning e4 data setscpd node scpd node return scpd node getscpdnode servicedata getservicedata scpdnode getscpdnode scpdnode scpdnode scpdurlstr scpdurl scpdurlstr scpdnode getscpdnode scpdurl rootdev getrootdevice urlbasestr rootdev geturlbase urlbasestr urlbasestr rootdev getlocation locationhost gethost locationport getport urlbasestr getrequesthosturl locationhost locationport scpdurlstr torelativeurl scpdurlstr newscpdurlstr urlbasestr scpdurlstr newscpdurl newscpdurlstr scpdnode getscpdnode newscpdurl newscpdurlstr getabsoluteurl urlbasestr scpdurlstr newscpdurl newscpdurlstr scpdnode getscpdnode newscpdurl newscpdurlstr rootdev getdescriptionfilepath scpdurlstr scpdnode getscpdnode newscpdurlstr setscpdnode scpdnode scpdnode public byte getscpd data node scpd node getscpd node if scpd node null return new byte 0 thanks for mikael hakman 04 25 05 string desc new string desc u pnp xml declaration desc n desc scpd node to string return desc get bytes getscpddata scpdnode getscpdnode scpdnode upnp xml_declaration scpdnode tostring getbytes public action list get action list action list action list new action list node scdp node getscpd node if scdp node null return action list node action list node scdp node get node action list elem name if action list node null return action list node service node get service node int n node action list node getn nodes for int n 0 n n node n node node action list node get node n if action is action node node false continue action action new action service node node action list add action return action list actionlist getactionlist actionlist actionlist actionlist scdpnode getscpdnode scdpnode actionlist actionlistnode scdpnode getnode actionlist elem_name actionlistnode actionlist servicenode getservicenode nnode actionlistnode getnnodes nnode actionlistnode getnode isactionnode servicenode actionlist actionlist public action get action string action name action list action list get action list int n actions action list size for int n 0 n n actions n action action action list get action n string name action get name if name null continue if name equals action name true return action return null getaction actionname actionlist actionlist getactionlist nactions actionlist nactions actionlist getaction getname actionname public service state table get service state table service state table state table new service state table node state table node getscpd node get node service state table elem name if state table node null return state table node service node get service node int n node state table node getn nodes for int n 0 n n node n node node state table node get node n if state variable is state variable node node false continue state variable service var new state variable service node node state table add service var return state table servicestatetable getservicestatetable servicestatetable statetable servicestatetable statetablenode getscpdnode getnode servicestatetable elem_name statetablenode statetable servicenode getservicenode nnode statetablenode getnnodes nnode statetablenode getnode statevariable isstatevariablenode statevariable servicevar statevariable servicenode statetable servicevar statetable public state variable get state variable string name service state table state table get service state table int table size state table size for int n 0 n table size n state variable var state table get state variable n string var name var get name if var name null continue if var name equals name true return var return null statevariable getstatevariable servicestatetable statetable getservicestatetable tablesize statetable tablesize statevariable statetable getstatevariable varname getname varname varname public boolean has state variable string name return get state variable name null true false hasstatevariable getstatevariable public boolean is service string name if name null return false if name ends with get service type true return true if name ends with get serviceid true return true return false isservice endswith getservicetype endswith getserviceid private service data get service data node node get service node service data user data service data node get user data if user data null user data new service data node set user data user data user data set node node return user data servicedata getservicedata getservicenode servicedata userdata servicedata getuserdata userdata userdata servicedata setuserdata userdata userdata setnode userdata private string get notify service typent return get service type getnotifyservicetypent getservicetype private string get notify service typeusn return get device getudn get service type getnotifyservicetypeusn getdevice getservicetype public void announce string bind addr uuid device uuid urn schemas upnp org service service type v device root dev get root device string dev location root dev get locationurl bind addr string servicent get notify service typent string serviceusn get notify service typeusn device dev get device ssdp notify request ssdp req new ssdp notify request ssdp req set server u pnp get server name ssdp req set lease time dev get lease time ssdp req set location dev location ssdp req setnts nts alive ssdp req setnt servicent ssdp req setusn serviceusn ssdp notify socket ssdp sock new ssdp notify socket bind addr device notify wait ssdp sock post ssdp req bindaddr servicetype rootdev getrootdevice devlocation rootdev getlocationurl bindaddr getnotifyservicetypent getnotifyservicetypeusn getdevice ssdpnotifyrequest ssdpreq ssdpnotifyrequest ssdpreq setserver upnp getservername ssdpreq setleasetime getleasetime ssdpreq setlocation devlocation ssdpreq ssdpreq ssdpreq ssdpnotifysocket ssdpsock ssdpnotifysocket bindaddr notifywait ssdpsock ssdpreq public void byebye string bind addr uuid device uuid urn schemas upnp org service service type v string devnt get notify service typent string devusn get notify service typeusn ssdp notify request ssdp req new ssdp notify request ssdp req setnts nts byebye ssdp req setnt devnt ssdp req setusn devusn ssdp notify socket ssdp sock new ssdp notify socket bind addr device notify wait ssdp sock post ssdp req bindaddr servicetype getnotifyservicetypent getnotifyservicetypeusn ssdpnotifyrequest ssdpreq ssdpnotifyrequest ssdpreq ssdpreq ssdpreq ssdpnotifysocket ssdpsock ssdpnotifysocket bindaddr notifywait ssdpsock ssdpreq public boolean service search response ssdp packet ssdp packet string ssdpst ssdp packet getst if ssdpst null return false device dev get device string servicent get notify service typent string serviceusn get notify service typeusn if st is all device ssdpst true dev post search response ssdp packet servicent serviceusn else if st isurn service ssdpst true string service type get service type if ssdpst equals service type true dev post search response ssdp packet service type serviceusn return true servicesearchresponse ssdppacket ssdppacket ssdppacket getdevice getnotifyservicetypent getnotifyservicetypeusn isalldevice postsearchresponse ssdppacket isurnservice servicetype getservicetype servicetype postsearchresponse ssdppacket servicetype public void set query listener query listener query listener service state table state table get service state table int table size state table size for int n 0 n table size n state variable var state table get state variable n var set query listener query listener setquerylistener querylistener querylistener servicestatetable statetable getservicestatetable tablesize statetable tablesize statevariable statetable getstatevariable setquerylistener querylistener public subscriber list get subscriber list return get service data get subscriber list subscriberlist getsubscriberlist getservicedata getsubscriberlist public void add subscriber subscriber sub get subscriber list add sub addsubscriber getsubscriberlist public void remove subscriber subscriber sub get subscriber list remove sub removesubscriber getsubscriberlist public subscriber get subscriber string name subscriber list sub list get subscriber list int sub list cnt sub list size for int n 0 n sub list cnt n subscriber sub sub list get subscriber n if sub null continue string sid sub getsid if sid null continue if sid equals name true return sub return null getsubscriber subscriberlist sublist getsubscriberlist sublistcnt sublist sublistcnt sublist getsubscriber private boolean notify subscriber sub state variable state var string var name state var get name string value state var get value string host sub get delivery host int port sub get delivery port notify request notify req new notify request notify req set request sub var name value http response res notify req post host port if res is successful false return false sub increment notify count return true statevariable statevar varname statevar getname statevar getvalue getdeliveryhost getdeliveryport notifyrequest notifyreq notifyrequest notifyreq setrequest varname httpresponse notifyreq issuccessful incrementnotifycount public void notify state variable state var subscriber list sub list get subscriber list int sub list cnt subscriber subs remove expired subscribers sub list cnt sub list size subs new subscriber sub list cnt for int n 0 n sub list cnt n subs n sub list get subscriber n for int n 0 n sub list cnt n subscriber sub subs n if sub is expired true remove subscriber sub notify to subscribers sub list cnt sub list size subs new subscriber sub list cnt for int n 0 n sub list cnt n subs n sub list get subscriber n for int n 0 n sub list cnt n subscriber sub subs n if notify sub state var false don t remove for nmpr specification remove subscriber sub statevariable statevar subscriberlist sublist getsubscriberlist sublistcnt sublistcnt sublist sublistcnt sublistcnt sublist getsubscriber sublistcnt isexpired removesubscriber sublistcnt sublist sublistcnt sublistcnt sublist getsubscriber sublistcnt statevar removesubscriber public void notify all state variables service state table state table get service state table int table size state table size for int n 0 n table size n state variable var state table get state variable n if var is send events true notify var notifyallstatevariables servicestatetable statetable getservicestatetable tablesize statetable tablesize statevariable statetable getstatevariable issendevents public string getsid return get service data getsid getservicedata public void setsid string id get service data setsid id getservicedata public void clearsid setsid set timeout 0 settimeout public boolean hassid return string util has data getsid stringutil hasdata public boolean is subscribed return hassid issubscribed public long get timeout return get service data get timeout gettimeout getservicedata gettimeout public void set timeout long value get service data set timeout value settimeout getservicedata settimeout public void set action listener action listener listener action list action list get action list int n actions action list size for int n 0 n n actions n action action action list get action n action set action listener listener setactionlistener actionlistener actionlist actionlist getactionlist nactions actionlist nactions actionlist getaction setactionlistener public sorted vector by number boolean persistent this data new int numbered item min size length 0 this persistent persistent sortedvectorbynumber intnumbereditem min_size public synchronized int numbered item get first if length 0 return null return data 0 intnumbereditem getfirst public synchronized boolean is empty return length 0 isempty public synchronized int numbered item get int retry count object container container if persistent for int i 0 i length i container activate data i 1 int x arrays binary search data retry count comparator if x 0 return data x return null intnumbereditem retrycount objectcontainer binarysearch retrycount public synchronized void remove int item object container container if persistent for int i 0 i length i container activate data i 1 int x arrays binary search data item comparator if x 0 if x length 1 system arraycopy data x 1 data x length x 1 data length null if length 4 data length length min size int numbered item new data new int numbered item math max length 2 min size system arraycopy data 0 new data 0 length data new data if persistent container store this verify container objectcontainer binarysearch min_size intnumbereditem newdata intnumbereditem min_size newdata newdata private synchronized void verify object container container int numbered item last item null for int i 0 i length i int numbered item item data i if persistent container activate data i 1 if i 0 if item get number last item get number throw new illegal state exception verify failed at i this item get number but last last item get number last item item for int i length i data length i if data i null throw new illegal state exception length length data length data length but i null objectcontainer intnumbereditem lastitem intnumbereditem getnumber lastitem getnumber illegalstateexception getnumber lastitem getnumber lastitem illegalstateexception add the item if it or an item of the same number is not already present return true if we added the item public synchronized boolean push int numbered item grabber object container container if persistent for int i 0 i length i container activate data i 1 int x arrays binary search data grabber get number comparator if x 0 return false insertion point x x 1 push grabber x container return true intnumbereditem objectcontainer binarysearch getnumber public synchronized void add int numbered item grabber object container container if persistent for int i 0 i length i container activate data i 1 int x arrays binary search data grabber get number comparator if x 0 if grabber data x throw new illegal argument exception already exists else return insertion point x x 1 push grabber x container intnumbereditem objectcontainer binarysearch getnumber illegalargumentexception private synchronized void push int numbered item grabber int x object container container if persistent for int i 0 i length i container activate data i 1 boolean logminor logger should log logger minor this if logminor logger minor this insertion point x move the data if length data length if logminor logger minor this expanding from length to length 2 int numbered item new data new int numbered item length 2 system arraycopy data 0 new data 0 data length data new data if x length system arraycopy data x data x 1 length x data x grabber length if persistent container store this verify container intnumbereditem objectcontainer shouldlog intnumbereditem newdata intnumbereditem newdata newdata public synchronized int count return length public synchronized int numbered item get by index int index if index length return null return data index intnumbereditem getbyindex public int get number by index int idx if idx length return integer max value return data idx get number getnumberbyindex max_value getnumber public boolean persistent return persistent converts a hex string into a long long parse long hex 16 assumes the input is nonnegative unless there is a preceding minus sign this method reads the input as twos complement instead so if the input is 8 bytes long it will correctly restore a negative long produced by long to hex string but not necessarily one produced by long to string x 16 since that method will produce a string like ff for negative longs values param hex a string in capital or lower case hex of no more then 16 characters throws number format exception if the string is more than 16 characters long or if any character is not in the set 0 9a fa f public static final long hex to long string hex throws number format exception int len hex length if len 16 throw new number format exception long l 0 for int i 0 i len i l 4 int c character digit hex char at i 16 if c 0 throw new number format exception l c return l parselong tohexstring tostring numberformatexception hextolong numberformatexception numberformatexception charat numberformatexception converts a hex string into an int integer parse int hex 16 assumes the input is nonnegative unless there is a preceding minus sign this method reads the input as twos complement instead so if the input is 8 bytes long it will correctly restore a negative int produced by integer to hex string but not necessarily one produced by integer to string x 16 since that method will produce a string like ff for negative integer values param hex a string in capital or lower case hex of no more then 16 characters throws number format exception if the string is more than 16 characters long or if any character is not in the set 0 9a fa f public static final int hex to int string hex throws number format exception int len hex length if len 16 throw new number format exception int l 0 for int i 0 i len i l 4 int c character digit hex char at i 16 if c 0 throw new number format exception l c return l parseint tohexstring tostring numberformatexception hextoint numberformatexception numberformatexception charat numberformatexception finds the boolean value of the field by doing a caseless match with the strings true and false param s the string param def the default value if the string can t be parsed if the default is true it checks that the string is not false if it is false it checks whether the string is true return the boolean field value or the default value if the field value couldn t be parsed wooo rocket science this is purely abstraction people public static final boolean string to bool string s boolean def if s null return def return def s equals ignore case false s equals ignore case true stringtobool equalsignorecase equalsignorecase find the boolean value of the field throw if the string is neither yes true nor no false param s return public static boolean string to bool string s throws number format exception if s null throw new number format exception null if s equals ignore case false s equals ignore case no return false if s equals ignore case true s equals ignore case yes return true throw new number format exception invalid boolean s stringtobool numberformatexception numberformatexception equalsignorecase equalsignorecase equalsignorecase equalsignorecase numberformatexception converts a boolean to a string of either true or false param b the boolean value to convert return a true or false string public static final string bool to string boolean b return b true false booltostring public static final string comma list string ls if ls null return null string tokenizer st new string tokenizer ls string r new string st count tokens for int i 0 i r length i r i st next token trim return r commalist stringtokenizer stringtokenizer counttokens nexttoken public static final string comma list string ls return text list ls commalist textlist public static final string text list string ls char ch string builder sb new string builder for int i 0 i ls length i sb append ls i if i ls length 1 sb append ch return sb to string textlist stringbuilder stringbuilder tostring public static final long number list string ls throws number format exception string tokenizer st new string tokenizer ls long r new long st count tokens for int i 0 i r length i r i hex to long st next token return r numberlist numberformatexception stringtokenizer stringtokenizer counttokens hextolong nexttoken public static final string number list long ls char number buf new char 64 string builder list buf new string builder ls length 18 for int i 0 i ls length i convert the number into a string in a fixed size buffer long l ls i int char pos 64 do number buf char pos digits int l 0x0f l 4 while l 0 list buf append number buf char pos 64 char pos if i ls length 1 list buf append return list buf to string numberlist numberbuf stringbuilder listbuf stringbuilder charpos numberbuf charpos listbuf numberbuf charpos charpos listbuf listbuf tostring parses a time and date value using a very strict format the value has to be of the form yyyymmdd hh mm ss where seconds may include a decimal or yyyymmdd in which case 00 00 00 is assumed for time another accepted format is integer day month year minute second return millis of the epoch of at the time described public static final long date time string date throws number format exception if date length 0 throw new number format exception date time empty if date char at 0 date char at 0 relative date string builder sb new string builder 10 for int x 1 x date length x char c date char at x if character is digit c sb append c else break int num integer parse int sb to string int chop 1 sb length int delta type 0 if date length chop delta type calendar day of year else string delta type string date substring chop to lower case if delta type string equals y delta type string equals year delta type calendar year else if delta type string equals month delta type string equals mo delta type calendar month else if delta type string equals week delta type string equals w delta type calendar week of year else if delta type string equals day delta type string equals d delta type calendar day of year else if delta type string equals hour delta type string equals h delta type calendar hour else if delta type string equals minute delta type string equals min delta type calendar minute else if delta type string equals second delta type string equals s delta type string equals sec delta type calendar second else throw new number format exception unknown time date delta type delta type string gregorian calendar gc new gregorian calendar gc add delta type date char at 0 num num return gc get time get time int dash date index of if dash 1 date length 8 dash 8 date length 17 throw new number format exception date time date not correct int year integer parse int date substring 0 4 int month integer parse int date substring 4 6 int day integer parse int date substring 6 8 int hour dash 1 0 integer parse int date substring 9 11 int minute dash 1 0 integer parse int date substring 12 14 int second dash 1 0 integer parse int date substring 15 17 note that month is zero based in gregorian calender try return new gregorian calendar year month 1 day hour minute second get time get time catch exception e e print stack trace the api docs don t say which exception is thrown on bad numbers throw new number format exception invalid date date e datetime numberformatexception numberformatexception charat charat stringbuilder stringbuilder charat isdigit parseint tostring deltatype deltatype day_of_year deltatypestring tolowercase deltatypestring deltatypestring deltatype deltatypestring deltatypestring deltatype deltatypestring deltatypestring deltatype week_of_year deltatypestring deltatypestring deltatype day_of_year deltatypestring deltatypestring deltatype deltatypestring deltatypestring deltatype deltatypestring deltatypestring deltatypestring deltatype numberformatexception deltatypestring gregoriancalendar gregoriancalendar deltatype charat gettime gettime indexof numberformatexception parseint parseint parseint parseint parseint parseint gregoriancalender gregoriancalendar gettime gettime printstacktrace numberformatexception public static final string sec to date time long time calendar c calendar get instance c set time new date time gc set time in millis time 1000 date format f new simple date format yyyym mdd hh mm ss string date string f format c get time string date string f format new date time 1000 if date string ends with 00 00 00 date string date string substring 0 8 return date string sectodatetime getinstance settime settimeinmillis dateformat simpledateformat yyyymmdd datestring gettime datestring datestring endswith datestring datestring datestring public static final int compare bytes byte b1 byte b2 int len math max b1 length b2 length for int i 0 i len i if i b1 length return i b2 length 0 1 else if i b2 length return 1 else if 0xff b1 i 0xff b2 i return 1 else if 0xff b1 i 0xff b2 i return 1 return 0 comparebytes public static final int compare bytes byte a byte b int aoff int boff int len for int i 0 i len i if i aoff a length return i boff b length 0 1 else if i boff b length return 1 else if 0xff a i aoff 0xff b i boff return 1 else if 0xff a i aoff 0xff b i boff return 1 return 0 comparebytes public static final boolean byte array equal byte a byte b if a length b length return false for int i 0 i a length i if a i b i return false return true bytearrayequal public static final boolean byte array equal byte a byte b int aoff int boff int len if a length aoff len b length boff len return false for int i 0 i len i if a i aoff b i boff return false return true bytearrayequal public static final class byte array comparator implements comparator byte public final int compare byte o1 byte o2 return compare bytes o1 o2 bytearraycomparator comparebytes could add stuff like integer comparator long comparator etc if we need it public static final int hash code byte b return hash code b 0 b length integercomparator longcomparator hashcode hashcode a generic hashcode suited for byte arrays that are more or less random public static final int hash code byte b int ptr int length int h 0 for int i length 1 i 0 i int x b ptr i 0xff h x i 3 3 return h hashcode long version of above not believed to be secure in any sense of the word public static final long long hash code byte b return long hash code b 0 b length longhashcode longhashcode long version of above not believed to be secure in any sense of the word public static final long long hash code byte b int offset int length long h 0 for int i length 1 i 0 i int x b i offset 0xff h long x i 7 3 return h longhashcode param addr return public static string comma list object addr string builder sb new string builder for int i 0 i addr length i sb append addr i if i addr length 1 sb append return sb to string commalist stringbuilder stringbuilder tostring convert an array of longs to an array of bytes using a consistent endianness public static byte longs to bytes long longs byte buf new byte longs length 8 for int i 0 i longs length i long x longs i for int j 0 j 8 j buf i 8 j byte x x 8 return buf longstobytes convert an array of bytes to an array of longs public static long bytes to longs byte buf return bytes to longs buf 0 buf length bytestolongs bytestolongs convert an array of bytes to an array of longs param buf param length param offset return public static long bytes to longs byte buf int offset int length if length 8 0 throw new illegal argument exception long longs new long length 8 for int i 0 i longs length i long x 0 for int j 7 j 0 j long y buf offset i 8 j 0xff x x 8 y longs i x return longs bytestolongs illegalargumentexception convert an array of bytes to a single long public static long bytes to long byte buf return bytes to long buf 0 bytestolong bytestolong convert an array of bytes to a single long public static long bytes to long byte buf int offset if buf length 8 offset throw new illegal argument exception long x 0 for int j 7 j 0 j long y buf j offset 0xff x x 8 y return x bytestolong illegalargumentexception convert an array of bytes to a single int public static int bytes to int byte buf int offset if buf length 4 throw new illegal argument exception int x 0 for int j 3 j 0 j int y buf j offset 0xff x x 8 y return x bytestoint illegalargumentexception public static int bytes to ints byte buf int offset int length if length 4 0 throw new illegal argument exception int ints new int length 4 for int i 0 i ints length i int x 0 for int j 3 j 0 j int y buf j offset i 4 0xff x x 8 y ints i x return ints bytestoints illegalargumentexception public static int bytes to ints byte buf return bytes to ints buf 0 buf length bytestoints bytestoints public static byte long to bytes long x byte buf new byte 8 for int j 0 j 8 j buf j byte x x 8 return buf longtobytes public static byte ints to bytes int ints byte buf new byte ints length 4 for int i 0 i ints length i long x ints i for int j 0 j 4 j buf i 4 j byte x x 8 return buf intstobytes public static byte int to bytes int x byte buf new byte 4 for int j 0 j 4 j buf j byte x x 8 return buf inttobytes public static long parse long string s long default value try return long parse long s catch number format exception e logger error fields class failed to parse value as long s e e return default value parselong defaultvalue parselong numberformatexception defaultvalue public static int parse int string s int default value try return integer parse int s catch number format exception e logger error fields class failed to parse value as int s e e return default value parseint defaultvalue parseint numberformatexception defaultvalue public static long parse short string s short default value try return short parse short s catch number format exception e logger error fields class failed to parse value as short s e e return default value parseshort defaultvalue parseshort numberformatexception defaultvalue parse a human readable string possibly including si and ice units into a short throws number format exception if the string is not parseable public static short parse short string s throws number format exception s s replace first i b short res 1 int x s length 1 int idx try while x 0 idx kk index of s char at x 1 x res multiples idx res double parse double s substring 0 x 1 catch arithmetic exception e res short max value throw new number format exception e get message return res numberformatexception parseshort numberformatexception replacefirst indexof charat parsedouble arithmeticexception max_value numberformatexception getmessage parse a human readable string possibly including si and ice units into an integer throws number format exception if the string is not parseable public static int parse int string s throws number format exception s s replace first i b int res 1 int x s length 1 int idx try while x 0 idx k km mgg index of s char at x 1 x res multiples idx res double parse double s substring 0 x 1 catch arithmetic exception e res integer max value throw new number format exception e get message return res numberformatexception parseint numberformatexception replacefirst kkmmgg indexof charat parsedouble arithmeticexception max_value numberformatexception getmessage parse a human readable string possibly including si and ice units into a long throws number format exception if the string is not parseable public static long parse long string s throws number format exception s s replace first i b long res 1 int x s length 1 int idx try while x 0 idx k km mg gt tp pee index of s char at x 1 x res multiples idx string multiplier s substring 0 x 1 trim if multiplier index of 1 multiplier index of e 1 res double parse double multiplier if logger should log logger minor fields class logger minor fields class parsed multiplier of s as double res else res long parse long multiplier if logger should log logger minor fields class logger minor fields class parsed multiplier of s as long res catch arithmetic exception e res long max value throw new number format exception e get message return res numberformatexception parselong numberformatexception replacefirst kkmmggttppee indexof charat indexof indexof parsedouble shouldlog parselong shouldlog arithmeticexception max_value numberformatexception getmessage public static string long to string long val boolean is size string ret long to string val if val 0 return ret for int i multiples length 1 i 0 i if val multiples i val multiples i 0 is size multiples i 1000 0 ret val multiples i multiples 2 i if multiples 2 i to lower case equals multiples 2 i ret ib break return ret longtostring issize tostring issize multiples_2 multiples_2 tolowercase multiples_2 public static string int to string int val boolean is size string ret integer to string val if val 0 return ret for int i multiples length 1 i 0 i if val multiples i val multiples i 0 is size multiples i 1000 0 ret val multiples i multiples 2 i if multiples 2 i to lower case equals multiples 2 i ret ib break return ret inttostring issize tostring issize multiples_2 multiples_2 tolowercase multiples_2 public static string short to string short val boolean is size string ret short to string val if val 0 return ret for int i multiples length 1 i 0 i if val multiples i val multiples i 0 is size multiples i 1000 0 ret val multiples i multiples 2 i if multiples 2 i to lower case equals multiples 2 i ret ib break return ret shorttostring issize tostring issize multiples_2 multiples_2 tolowercase multiples_2 public static double bytes to doubles byte data int offset int length long longs bytes to longs data offset length double doubles new double longs length for int i 0 i longs length i doubles i double long bits to double longs i return doubles bytestodoubles bytestolongs longbitstodouble public static byte doubles to bytes double doubles long longs new long doubles length for int i 0 i longs length i longs i double double to long bits doubles i return longs to bytes longs doublestobytes doubletolongbits longstobytes public static double bytes to doubles byte data return bytes to doubles data 0 data length bytestodoubles bytestodoubles assumes the array is sorted in ascending order begin is lowest and end is highest public static int binary search long values long key int orig begin int orig end int begin orig begin int end orig end while true if end begin so we can use orig end length 1 without worrying length 0 return begin 1 int middle begin end 1 if values middle key return middle if values middle key end middle 1 else if values middle key begin middle 1 binarysearch origbegin origend origbegin origend origend encode to our shortened non standards compliant format public static string encode byte in return encode in false caller should specify equals pad true if they want a standards compliant padding but not standard compliant encoding public static string encode byte in boolean equals pad return encode in equals pad base64 alphabet equalspad equalspad equalspad base64alphabet standard compliant encoding public static string encode standard byte in return encode in true base64 standard alphabet encodestandard base64standardalphabet caller should specify equals pad true if they want a standards compliant encoding private static string encode byte in boolean equals pad char alphabet char out new char in length 2 3 4 int rem in length 3 int o 0 for int i 0 i in length int val in i 0xff 16 if i in length val in i 0xff 8 if i in length val in i 0xff out o alphabet val 18 0x3f out o alphabet val 12 0x3f out o alphabet val 6 0x3f out o alphabet val 0x3f int out len out length switch rem case 1 out len 2 break case 2 out len 1 break pad with signs up to a multiple of four if requested if equals pad while out len out length out out len return new string out 0 out len equalspad equalspad outlen outlen outlen equalspad outlen outlen outlen handles the standards compliant padding padded with signs as well as our shortened form throws illegal base64 exception public static byte decode string in str throws illegal base64 exception return decode in str base64 reverse illegalbase64exception instr illegalbase64exception instr base64reverse handles the standards compliant base64 encoding public static byte decode standard string in str throws illegal base64 exception return decode in str base64 standard reverse decodestandard instr illegalbase64exception instr base64standardreverse handles the standards compliant padded with signs as well as our shortened form private static byte decode string in str byte reverse alphabet throws illegal base64 exception try char in in str to char array int in length in length strip trailing equals signs while in length 0 in in length 1 in length int blocks in length 4 int remainder in length 3 whole in len and whole out len are the the length of the input and output sequences respectively not including any partial block at the end int whole in len blocks 4 int whole out len blocks 3 int out len whole out len switch remainder case 1 throw new illegal base64 exception illegal base64 length case 2 out len whole out len 1 break case 3 out len whole out len 2 break default out len whole out len byte out new byte out len int o 0 int i for i 0 i whole in len int in1 reverse alphabet in i int in2 reverse alphabet in i 1 int in3 reverse alphabet in i 2 int in4 reverse alphabet in i 3 int or value in1 in2 in3 in4 if or value 0x80 0 throw new illegal base64 exception illegal base64 character int out val in1 18 in2 12 in3 6 in4 out o byte out val 16 out o 1 byte out val 8 out o 2 byte out val i 4 o 3 int or value switch remainder case 2 int in1 reverse alphabet in i int in2 reverse alphabet in i 1 or value in1 in2 int out val in1 18 in2 12 out o byte out val 16 break case 3 int in1 reverse alphabet in i int in2 reverse alphabet in i 1 int in3 reverse alphabet in i 2 or value in1 in2 in3 int out val in1 18 in2 12 in3 6 out o byte out val 16 out o 1 byte out val 8 break default keep compiler happy or value 0 if or value 0x80 0 throw new illegal base64 exception illegal base64 character return out illegal characters can cause an array index out of bounds exception when looking up reverse alphabet catch array index out of bounds exception e throw new illegal base64 exception illegal base64 character instr reversealphabet illegalbase64exception instr tochararray inlength inlength inlength inlength inlength inlength wholeinlen wholeoutlen wholeinlen wholeoutlen outlen wholeoutlen illegalbase64exception outlen wholeoutlen outlen wholeoutlen outlen wholeoutlen outlen wholeinlen reversealphabet reversealphabet reversealphabet reversealphabet orvalue orvalue illegalbase64exception outval outval outval outval orvalue reversealphabet reversealphabet orvalue outval outval reversealphabet reversealphabet reversealphabet orvalue outval outval outval orvalue orvalue illegalbase64exception arrayindexoutofboundsexception reversealphabet arrayindexoutofboundsexception illegalbase64exception public wot message manager ext object container mydb executor my executor wot identity manager my identity manager super mydb my executor my identity manager m identity manager my identity manager is running true m executor execute this ft message manager request client new request client public boolean persistent return false public void remove from object container container throw new unsupported operation exception logger debug this message manager started wotmessagemanager extobjectcontainer myexecutor wotidentitymanager myidentitymanager myexecutor myidentitymanager midentitymanager myidentitymanager isrunning mexecutor requestclient requestclient removefrom objectcontainer unsupportedoperationexception for being used in j unit tests to run without a node public wot message manager ext object container mydb wot identity manager my identity manager super mydb my identity manager junit wotmessagemanager extobjectcontainer wotidentitymanager myidentitymanager myidentitymanager public synchronized wot own message post message message my parent message set board my boards board my reply to board ft own identity my author string my title date my date string my text list attachment my attachments throws exception wot own message m synchronized wot own message class todo investigate whether this lock is necessary message parent thread null try if my parent message null if my parent message is thread parent thread my parent message else parent thread my parent message get thread catch no such message exception e date date my date null my date current timeutc get m wot own message construct parent thread my parent message my boards my reply to board my author my title date my text my attachments m initialize transient db this m store we do not add the message to the boards it is posted to because the user should only see the message if it has been downloaded successfully this helps the user to spot problems if he does not see his own messages we can hope that he reports a bug return m wotownmessage postmessage myparentmessage myboards myreplytoboard ftownidentity myauthor mytitle mydate mytext myattachments wotownmessage wotownmessage parentthread myparentmessage myparentmessage isthread parentthread myparentmessage parentthread myparentmessage getthread nosuchmessageexception mydate mydate currenttimeutc wotownmessage parentthread myparentmessage myboards myreplytoboard myauthor mytitle mytext myattachments initializetransient public synchronized void on message list fetch failed ft identity author freeneturi uri message list message list fetch failed reference reason reason if reason message list message list fetch failed reference reason data not found todo handle dnf in some reasonable way mark the message lists as unavailable after a certain amount of retries maybe return wot message list list new wot message list author uri try get message list list getid logger debug this download failed of a message list which we already have list geturi catch no such message list exception e try list initialize transient db this list store message list message list fetch failed reference ref new message list message list fetch failed reference list reason ref initialize transient db ref store logger debug this marked message list as download failed with reason reason uri catch exception ex logger error this error while marking a message list as download failed ex synchronized db lock db delete list db commit onmessagelistfetchfailed ftidentity messagelist messagelistfetchfailedreference messagelist messagelistfetchfailedreference datanotfound messagelists wotmessagelist wotmessagelist getmessagelist messagelist nosuchmessagelistexception initializetransient messagelist messagelistfetchfailedreference messagelist messagelistfetchfailedreference initializetransient public synchronized void add message to message list wot own message message throws exception query query db query query constrain wot own message list class query descend m author constrain message get author identity query descend i was inserted constrain false query descend i am being inserted constrain false for wot own message list list general get own message list iterable query try list add message message return catch exception e the list is full logger debug this not adding message message getid to message list list getid e wot own identity author wot own identity message get author wot own message list list new wot own message list author get free own message list index author list initialize transient db this list add message message list store logger debug this created the new list list getid for message message getid addmessagetomessagelist wotownmessage wotownmessagelist mauthor getauthor iwasinserted iambeinginserted wotownmessagelist generalgetownmessagelistiterable addmessage wotownidentity wotownidentity getauthor wotownmessagelist wotownmessagelist getfreeownmessagelistindex initializetransient addmessage suppress warnings unchecked public synchronized iterable wot own message get not inserted own messages return new iterable wot own message public iterator wot own message iterator return new iterator wot own message private iterator wot own message iter query query db query query constrain wot own message class query descend m realuri constrain null identity iter query execute iterator public boolean has next return iter has next public wot own message next wot own message next iter next next initialize transient db self return next public void remove throw new unsupported operation exception suppresswarnings wotownmessage getnotinsertedownmessages wotownmessage wotownmessage wotownmessage wotownmessage wotownmessage mrealuri hasnext hasnext wotownmessage wotownmessage initializetransient unsupportedoperationexception return new iterable wot own message public iterator wot own message iterator return new iterator wot own message private iterator wot own message iter query query db query query constrain wot own message class query descend m realuri constrain null identity iter query execute iterator public boolean has next return iter has next public wot own message next wot own message next iter next next initialize transient db self return next public void remove throw new unsupported operation exception wotownmessage wotownmessage wotownmessage wotownmessage wotownmessage mrealuri hasnext hasnext wotownmessage wotownmessage initializetransient unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public wot own message next wot own message next iter next next initialize transient db self return next wotownmessage wotownmessage initializetransient public void remove throw new unsupported operation exception unsupportedoperationexception for a database query of result type code object set wot own message list code this function provides an code iterable code the iterator of the object set cannot be used instead because it will not call initialize transient on the objects the iterator which is returned by this function takes care of that please synchronize on the code wot message manager code when using this function it is not synchronized itself protected iterable wot own message list general get own message list iterable final query query return new iterable wot own message list suppress warnings unchecked public iterator wot own message list iterator return new iterator wot own message list private iterator wot own message list iter query execute iterator public boolean has next return iter has next public wot own message list next wot own message list next iter next next initialize transient db self return next public void remove throw new unsupported operation exception objectset wotownmessagelist objectset initializetransient wotmessagemanager wotownmessagelist generalgetownmessagelistiterable wotownmessagelist suppresswarnings wotownmessagelist wotownmessagelist wotownmessagelist hasnext hasnext wotownmessagelist wotownmessagelist initializetransient unsupportedoperationexception returns code own message list code objects which are marked as not inserted it will also return those which are marked as currently being inserted they are not filtered out because in the current implementation the wot message list inserter will cancel all inserts before using this function public synchronized iterable wot own message list get not inserted own message lists query query db query query constrain wot own message list class query descend i was inserted constrain false return general get own message list iterable query ownmessagelist wotmessagelistinserter wotownmessagelist getnotinsertedownmessagelists wotownmessagelist iwasinserted generalgetownmessagelistiterable public synchronized iterable wot own message list get being inserted own message lists query query db query query constrain wot own message list class query descend i was inserted constrain false query descend i am being inserted constrain true return general get own message list iterable query wotownmessagelist getbeinginsertedownmessagelists wotownmessagelist iwasinserted iambeinginserted generalgetownmessagelistiterable suppress warnings unchecked public synchronized int get unavailable new message list index ft identity identity query query db query query constrain wot message list class query constrain wot own message list class not query descend m author constrain identity identity query descend m index order descending fixme this is inefficient use a native query instead we just need to find the maximum object set wot message list result query execute if result size 0 return 0 return result next get index 1 suppresswarnings getunavailablenewmessagelistindex ftidentity wotmessagelist wotownmessagelist mauthor mindex orderdescending objectset wotmessagelist getindex suppress warnings unchecked public synchronized int get unavailable old message list index ft identity identity query query db query query constrain wot message list class query constrain wot own message list class not query descend m author constrain identity identity query descend m index order descending fixme this is inefficient use a native query instead object set wot message list result query execute if result size 0 return 0 int latest available index result next get index int free index latest available index 1 for result has next result next get index free index free index fixme to avoid always checking all messagelists for a missing one store somewhere in the ft identity what the latest index is up to which all messagelists are available return free index 0 free index latest available index 1 suppresswarnings getunavailableoldmessagelistindex ftidentity wotmessagelist wotownmessagelist mauthor mindex orderdescending objectset wotmessagelist latestavailableindex getindex freeindex latestavailableindex hasnext getindex freeindex freeindex ftidentity freeindex freeindex latestavailableindex get the next free index for an wot own message list you have to synchronize on wot own message list class while creating an wot own message list this function does not provide synchronization suppress warnings unchecked public int get free own message list index wot own identity message author query q db query we query for wot message list and not wot own message list because the user might have deleted his own messages or lost his database q constrain wot message list class q descend m author constrain message author identity q descend m index order descending fixme write a native db4o query which just looks for the maximum object set wot message list result q execute return result size 0 result next get index 1 0 wotownmessagelist wotownmessagelist wotownmessagelist suppresswarnings getfreeownmessagelistindex wotownidentity messageauthor wotmessagelist wotownmessagelist wotmessagelist mauthor messageauthor mindex orderdescending objectset wotmessagelist getindex public void run logger debug this message manager running m thread thread current thread try logger debug this waiting for the node to start up thread sleep long 3 60 1000 0 5f math random let the node start up catch interrupted exception e m thread interrupt try while is running logger debug this message manager loop running logger debug this message manager loop finished try thread sleep long thread period 0 5f math random catch interrupted exception e m thread interrupt logger debug this message manager loop interrupted finally synchronized this shutdown finished true logger debug this message manager thread exiting notify mthread currentthread interruptedexception mthread isrunning thread_period interruptedexception mthread shutdownfinished public void terminate logger debug this stopping the message manager is running false m thread interrupt synchronized this while shutdown finished try wait catch interrupted exception e thread interrupted logger debug this stopped the message manager isrunning mthread shutdownfinished interruptedexception param client the object to call back when we complete or don t param data the data to insert this will not be freed by client putter the callback must do that however buckets used internally by the client layer will be freed param targeturi param cm param ctx param scheduler param priority class param getchk only param is metadata param client context the client object for purposs of round robin client balancing param stored the progress so far stored as a simple field set advisory if there is an error reading this in we will restart from scratch param target filename if set create a one file manifest containing this filename pointing to this file public client putter client callback client bucket data freeneturi targeturi client metadata cm insert context ctx short priority class boolean getchk only boolean is metadata request client client context simple field set stored string target filename boolean binary blob super priority class client context this cm cm this is metadata is metadata this getchk only getchk only this client client this data data this targeturi targeturi this ctx ctx this finished false this cancelled false this old progress stored this target filename target filename this binary blob binary blob clientputter priorityclass getchkonly ismetadata clientcontext simplefieldset targetfilename clientputter clientcallback clientmetadata insertcontext priorityclass getchkonly ismetadata requestclient clientcontext simplefieldset targetfilename binaryblob priorityclass clientcontext ismetadata ismetadata getchkonly getchkonly oldprogress targetfilename targetfilename binaryblob binaryblob public void start boolean early encode object container container client context context throws insert exception start early encode false container context earlyencode objectcontainer clientcontext insertexception earlyencode public boolean start boolean early encode boolean restart object container container client context context throws insert exception if persistent container activate client 1 if logger should log logger minor this logger minor this starting this try this targeturi check inserturi if data null throw new insert exception insert exception bucket error no data to insert null boolean cancel false synchronized this if restart if current state null finished return false finished false if started starting return false started starting true if current state null return false cancel this cancelled if cancel if binary blob client metadata meta cm if meta null meta persistent meta clone meta current state new single file inserter this this new insert block data meta persistent targeturi clone targeturi is metadata ctx false getchk only false null null false target filename early encode else current state new binary blob inserter data this null false priority class ctx context container if cancel on failure new insert exception insert exception cancelled null container context old progress null return false synchronized this cancel cancelled if cancel on failure new insert exception insert exception cancelled null container context old progress null if persistent container store this return false if logger should log logger minor this logger minor this starting insert current state if current state instanceof single file inserter single file inserter current state start old progress container context else current state schedule container context synchronized this old progress null cancel cancelled if persistent container store this it has scheduled we can safely deactivate it now so it won t hang around in memory container deactivate current state 1 if cancel on failure new insert exception insert exception cancelled null container context return false catch insert exception e logger error this failed to start insert e e synchronized this finished true old progress null current state null if persistent container store this notify the client that the insert could not even be started if this client null this client on failure e this container catch io exception e logger error this failed to start insert e e synchronized this finished true old progress null current state null if persistent container store this notify the client that the insert could not even be started if this client null this client on failure new insert exception insert exception bucket error e null this container catch binary blob format exception e logger error this failed to start insert e e synchronized this finished true old progress null current state null if persistent container store this notify the client that the insert could not even be started if this client null this client on failure new insert exception insert exception binary blob format error e null this container if logger should log logger minor this logger minor this started this return true earlyencode objectcontainer clientcontext insertexception shouldlog checkinserturi insertexception insertexception bucket_error currentstate startedstarting startedstarting currentstate binaryblob clientmetadata currentstate singlefileinserter insertblock ismetadata getchkonly targetfilename earlyencode currentstate binaryblobinserter priorityclass onfailure insertexception insertexception oldprogress onfailure insertexception insertexception oldprogress shouldlog currentstate currentstate singlefileinserter singlefileinserter currentstate oldprogress currentstate oldprogress currentstate onfailure insertexception insertexception insertexception oldprogress currentstate onfailure ioexception oldprogress currentstate onfailure insertexception insertexception bucket_error binaryblobformatexception oldprogress currentstate onfailure insertexception insertexception binary_blob_format_error shouldlog public void on success client put state state object container container client context context if persistent container activate client 1 client put state old state synchronized this finished true old state current state current state null old progress null if old state null persistent container activate old state 1 old state remove from container context if state null state old state persistent state remove from container context if super failed blocks 0 super fatally failed blocks 0 super successful blocks super total blocks logger error this failed blocks failed blocks fatally failed blocks fatally failed blocks successful blocks successful blocks total blocks total blocks but success on this from state new exception debug if persistent container store this client on success this container onsuccess clientputstate objectcontainer clientcontext clientputstate oldstate oldstate currentstate currentstate oldprogress oldstate oldstate oldstate removefrom oldstate removefrom failedblocks fatallyfailedblocks successfulblocks totalblocks failedblocks fatallyfailedblocks successfulblocks totalblocks onsuccess public void on failure insert exception e client put state state object container container client context context if logger should log logger minor this logger minor this on failure for this state e e if persistent container activate client 1 client put state old state synchronized this finished true old state current state current state null old progress null if old state null persistent container activate old state 1 old state remove from container context if state null state old state persistent state remove from container context if persistent container store this client on failure e this container onfailure insertexception clientputstate objectcontainer clientcontext shouldlog onfailure clientputstate oldstate oldstate currentstate currentstate oldprogress oldstate oldstate oldstate removefrom oldstate removefrom onfailure override public void on major progress object container container if persistent container activate client 1 client on major progress container onmajorprogress objectcontainer onmajorprogress public void on encode base client key key client put state state object container container client context context if persistent container activate client 1 synchronized this if this uri null logger error this on encode called twice already have a uri uri for this if persistent this uri remove from container this uri key geturi if target filename null uri uri push meta string target filename if persistent container store this client on generateduri uri this container onencode baseclientkey clientputstate objectcontainer clientcontext onencode removefrom targetfilename pushmetastring targetfilename ongenerateduri override public void cancel object container container client context context if logger should log logger minor this logger minor this cancelling this new exception debug client put state old state null synchronized this if cancelled return if finished return super cancel old state current state if persistent container store this if old state null container activate old state 1 if old state null old state cancel container context on failure new insert exception insert exception cancelled null container context objectcontainer clientcontext shouldlog clientputstate oldstate oldstate currentstate oldstate oldstate oldstate oldstate onfailure insertexception insertexception override public synchronized boolean is finished return finished cancelled isfinished override public freeneturi geturi return uri public void on transition client put state old state client put state new state object container container if new state null throw new null pointer exception on transition is not responsible for removing the old state the caller is synchronized this if current state old state current state new state if persistent container store this return logger error this on transition cur current state old old state new new state ontransition clientputstate oldstate clientputstate newstate objectcontainer newstate nullpointerexception ontransition currentstate oldstate currentstate newstate ontransition currentstate oldstate newstate public void on metadata metadata m client put state state object container container client context context logger error this got metadata on this from state this means the metadata won t be inserted onmetadata clientputstate objectcontainer clientcontext override public void notify clients object container container client context context if persistent container activate ctx 2 ctx event producer produce event new splitfile progress event this total blocks this successful blocks this failed blocks this fatally failed blocks this min success blocks this block set finalized container context notifyclients objectcontainer clientcontext eventproducer produceevent splitfileprogressevent totalblocks successfulblocks failedblocks fatallyfailedblocks minsuccessblocks blocksetfinalized override protected void inner to network object container container client context context if persistent container activate ctx 1 container activate ctx event producer 1 ctx event producer produce event new sending to network event container context innertonetwork objectcontainer clientcontext eventproducer eventproducer produceevent sendingtonetworkevent public void on block set finished client put state state object container container client context context if logger should log logger minor this logger minor this set finished new exception debug block set finalized container context onblocksetfinished clientputstate objectcontainer clientcontext shouldlog blocksetfinalized public void on fetchable client put state state object container container if persistent container activate client 1 client on fetchable this container onfetchable clientputstate objectcontainer onfetchable public boolean can restart if current state null finished logger minor this cannot restart because not finished for uri return false if data null return false return true canrestart currentstate public boolean restart boolean early encode object container container client context context throws insert exception return start early encode true container context earlyencode objectcontainer clientcontext insertexception earlyencode override public void on transition client get state old state client get state new state object container container ignore at the moment ontransition clientgetstate oldstate clientgetstate newstate objectcontainer override public void remove from object container container client context context container activate cm 2 cm remove from container this is passed in we should not remove it because the caller client put base should remove it container activate ctx 1 ctx remove from container container activate targeturi 5 targeturi remove from container if uri null container activate uri 5 uri remove from container super remove from container context removefrom objectcontainer clientcontext removefrom clientputbase removefrom removefrom removefrom removefrom public class quat4f extends tuple4f public quat4f this 0 0 0 0 public quat4f float x this x x 0 this y x 1 this z x 2 this w x 3 public quat4f float x float y float z float w this x x this y y this z z this w w public quat4f quat4f t this x t x this y t y this z t z this w t w public quat4f tuple4f t this x t x this y t y this z t z this w t w public void set axis angle4f a float half theta a angle 0 5f float cos half theta float math cos half theta float sin half theta float math sin half theta x a x sin half theta y a y sin half theta z a z sin half theta w cos half theta axisangle4f halftheta coshalftheta halftheta sinhalftheta halftheta sinhalftheta sinhalftheta sinhalftheta coshalftheta public void normalize float d 1 0f x x y y z z w w x d y d z d w d public void set matrix4f m float s int i float tr m m00 m m11 m m22 if tr 0 0 s float math sqrt tr 1 0f w s 2 0f s 0 5f s x m m12 m m21 s y m m20 m m02 s z m m01 m m10 s else i 0 if m m11 m m00 i 1 if m m22 m m11 i 2 else else if m m22 m m00 i 2 else switch i case 0 s float math sqrt m m00 m m11 m m22 1 0f x s 0 5f if s 0 0 s 0 5f s w m m12 m m21 s y m m01 m m10 s z m m02 m m20 s break case 1 s float math sqrt m m11 m m22 m m00 1 0f y s 0 5f if s 0 0 s 0 5f s w m m20 m m02 s z m m12 m m21 s x m m10 m m01 s break case 2 s float math sqrt m m00 m m11 m m22 1 0f z s 0 5f if s 0 0 s 0 5f s w m m01 m m10 s x m m20 m m02 s y m m21 m m12 s break private colormap colormap new linear colormap 0xffffffff 0xff000000 public glint filter linearcolormap glintfilter set the threshold value param threshold the threshold value see get threshold public void set threshold float threshold this threshold threshold getthreshold setthreshold get the threshold value return the threshold value see set threshold public float get threshold return threshold setthreshold getthreshold set the amount of glint param amount the amount min value 0 max value 1 see get amount public void set amount float amount this amount amount getamount setamount get the amount of glint return the amount see set amount public float get amount return amount setamount getamount set the length of the stars param length the length see get length public void set length int length this length length getlength setlength get the length of the stars return the length see set length public int get length return length setlength getlength set the blur that is applied before thresholding param blur the blur radius see get blur public void set blur float blur this blur blur getblur setblur set the blur that is applied before thresholding return the blur radius see set blur public float get blur return blur setblur getblur set whether to render the stars and the image or only the stars param glint only true to render only stars see get glint only public void set glint only boolean glint only this glint only glint only glintonly getglintonly setglintonly glintonly glintonly glintonly get whether to render the stars and the image or only the stars return true to render only stars see set glint only public boolean get glint only return glint only setglintonly getglintonly glintonly set the colormap to be used for the filter param colormap the colormap see get colormap public void set colormap colormap colormap this colormap colormap getcolormap setcolormap get the colormap to be used for the filter return the colormap see set colormap public colormap get colormap return colormap setcolormap getcolormap public buffered image filter buffered image src buffered image dst int width src get width int height src get height int pixels new int width int length2 int length 1 414f int colors new int length 1 int colors2 new int length2 1 if colormap null for int i 0 i length i int argb colormap get color float i length int r argb 16 0xff int g argb 8 0xff int b argb 0xff argb argb 0xff000000 int amount r 16 int amount g 8 int amount b colors i argb for int i 0 i length2 i int argb colormap get color float i length2 int r argb 16 0xff int g argb 8 0xff int b argb 0xff argb argb 0xff000000 int amount r 16 int amount g 8 int amount b colors2 i argb buffered image mask new buffered image width height buffered image type int argb int threshold3 int threshold 3 255 for int y 0 y height y getrgb src 0 y width 1 pixels for int x 0 x width x int rgb pixels x int a rgb 0xff000000 int r rgb 16 0xff int g rgb 8 0xff int b rgb 0xff int l r g b if l threshold3 pixels x 0xff000000 else l 3 pixels x a l 16 l 8 l setrgb mask 0 y width 1 pixels if blur 0 mask new gaussian filter blur filter mask null if dst null dst create compatible dest image src null int dst pixels if glint only dst pixels new int width height else dst pixels getrgb src 0 0 width height null fixme only need 2 length for int y 0 y height y int index y width getrgb mask 0 y width 1 pixels int ymin math max y length 0 y int ymax math min y length height 1 y int ymin2 math max y length2 0 y int ymax2 math min y length2 height 1 y for int x 0 x width x if pixels x 0xff threshold 255 int xmin math max x length 0 x int xmax math min x length width 1 x int xmin2 math max x length2 0 x int xmax2 math min x length2 width 1 x horizontal for int i 0 k 0 i xmax i k dst pixels index i pixel utils combine pixels dst pixels index i colors k pixel utils add for int i 1 k 1 i xmin i k dst pixels index i pixel utils combine pixels dst pixels index i colors k pixel utils add vertical for int i 1 j index width k 0 i ymax i j width k dst pixels j pixel utils combine pixels dst pixels j colors k pixel utils add for int i 1 j index width k 0 i ymin i j width k dst pixels j pixel utils combine pixels dst pixels j colors k pixel utils add diagonals int xymin math max xmin2 ymin2 int xymax math min xmax2 ymax2 se int count math min xmax2 ymax2 for int i 1 j index width 1 k 0 i count i j width 1 k dst pixels j pixel utils combine pixels dst pixels j colors2 k pixel utils add nw count math min xmin2 ymin2 for int i 1 j index width 1 k 0 i count i j width 1 k dst pixels j pixel utils combine pixels dst pixels j colors2 k pixel utils add ne count math min xmax2 ymin2 for int i 1 j index width 1 k 0 i count i j width 1 k dst pixels j pixel utils combine pixels dst pixels j colors2 k pixel utils add sw count math min xmin2 ymax2 for int i 1 j index width 1 k 0 i count i j width 1 k dst pixels j pixel utils combine pixels dst pixels j colors2 k pixel utils add index setrgb dst 0 0 width height dst pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight getcolor getcolor bufferedimage bufferedimage bufferedimage type_int_argb gaussianfilter createcompatibledestimage dstpixels glintonly dstpixels dstpixels dstpixels pixelutils combinepixels dstpixels pixelutils dstpixels pixelutils combinepixels dstpixels pixelutils dstpixels pixelutils combinepixels dstpixels pixelutils dstpixels pixelutils combinepixels dstpixels pixelutils dstpixels pixelutils combinepixels dstpixels pixelutils dstpixels pixelutils combinepixels dstpixels pixelutils dstpixels pixelutils combinepixels dstpixels pixelutils dstpixels pixelutils combinepixels dstpixels pixelutils dstpixels override public string to string return effects glint tostring public four color filter set colornw 0xffff0000 set colorne 0xffff00ff set colorsw 0xff0000ff set colorse 0xff00ffff fourcolorfilter setcolornw setcolorne setcolorsw setcolorse public void set colornw int color this colornw color rnw color 16 0xff gnw color 8 0xff bnw color 0xff setcolornw public int get colornw return colornw getcolornw public void set colorne int color this colorne color rne color 16 0xff gne color 8 0xff bne color 0xff setcolorne public int get colorne return colorne getcolorne public void set colorsw int color this colorsw color rsw color 16 0xff gsw color 8 0xff bsw color 0xff setcolorsw public int get colorsw return colorsw getcolorsw public void set colorse int color this colorse color rse color 16 0xff gse color 8 0xff bse color 0xff setcolorse public int get colorse return colorse getcolorse override public void set dimensions int width int height this width width this height height super set dimensions width height setdimensions setdimensions override public int filterrgb int x int y int rgb float fx float x width float fy float y height float p q p rnw rne rnw fx q rsw rse rsw fx int r int p q p fy 0 5f p gnw gne gnw fx q gsw gse gsw fx int g int p q p fy 0 5f p bnw bne bnw fx q bsw bse bsw fx int b int p q p fy 0 5f return 0xff000000 r 16 g 8 b override public string to string return texture four color fill tostring public static final long binary blob magic 0x6d58249f72d67ed9l public static final short binary blob overall version 0 public static void write binary blob header data output stream binary blob stream throws io exception binary blob stream write long binary blob binary blob magic binary blob stream write short binary blob binary blob overall version binary_blob_magic binary_blob_overall_version writebinaryblobheader dataoutputstream binaryblobstream ioexception binaryblobstream writelong binaryblob binary_blob_magic binaryblobstream writeshort binaryblob binary_blob_overall_version public static void write key data output stream binary blob stream key block block key key throws io exception byte key data key get key bytes byte headers block get raw headers byte data block get raw data byte pubkey block get pubkey bytes write blob header binary blob stream blob block blob block version 9 key data length headers length data length pubkey null 0 pubkey length binary blob stream write short block get key get type binary blob stream write byte key data length binary blob stream write short headers length binary blob stream write short data length binary blob stream write short pubkey null 0 pubkey length binary blob stream write key data binary blob stream write headers binary blob stream write data if pubkey null binary blob stream write pubkey writekey dataoutputstream binaryblobstream keyblock ioexception keydata getkeybytes getrawheaders getrawdata getpubkeybytes writeblobheader binaryblobstream blob_block blob_block_version keydata binaryblobstream writeshort getkey gettype binaryblobstream writebyte keydata binaryblobstream writeshort binaryblobstream writeshort binaryblobstream writeshort binaryblobstream keydata binaryblobstream binaryblobstream binaryblobstream public static final string mime type application x freenet binary blob static void write blob header data output stream binary blob stream short type short version int length throws io exception binary blob stream write int length binary blob stream write short type binary blob stream write short version mime_type writeblobheader dataoutputstream binaryblobstream ioexception binaryblobstream writeint binaryblobstream writeshort binaryblobstream writeshort binary blob stream write short version public static void write end blob data output stream binary blob stream throws io exception write blob header binary blob stream binary blob blob end binary blob blob end version 0 binaryblobstream writeshort writeendblob dataoutputstream binaryblobstream ioexception writeblobheader binaryblobstream binaryblob blob_end binaryblob blob_end_version public static void read binary blob data input stream dis block set blocks boolean tolerant throws io exception binary blob format exception long magic dis read long if magic binary blob binary blob magic throw new binary blob format exception bad magic short version dis read short if version binary blob binary blob overall version throw new binary blob format exception unknown overall version int i 0 while true long blob length try blob length dis read int 0xffffffffl catch eof exception e end of file dis close break short blob type dis read short short blob ver dis read short if blob type binary blob blob end dis close break else if blob type binary blob blob block if blob ver binary blob blob block version even if tolerant if we can t read a blob there probably isn t much we can do throw new binary blob format exception unknown block blob version if blob length 9 throw new binary blob format exception block blob too short short key type dis read short int key len dis read unsigned byte int headers len dis read unsigned short int data len dis read unsigned short int pubkey len dis read unsigned short int total 9 key len headers len data len pubkey len if blob length total throw new binary blob format exception binary blob not same length as data blob length blob length total total byte key bytes new byte key len byte headers bytes new byte headers len byte data bytes new byte data len byte pubkey bytes new byte pubkey len dis read fully key bytes dis read fully headers bytes dis read fully data bytes dis read fully pubkey bytes key block block try block key create block key type key bytes headers bytes data bytes pubkey bytes catch key verify exception e throw new binary blob format exception invalid key e get message e blocks add block else if tolerant file util skip fully dis blob length else throw new binary blob format exception unknown blob type blob type i readbinaryblob datainputstream blockset ioexception binaryblobformatexception readlong binaryblob binary_blob_magic binaryblobformatexception readshort binaryblob binary_blob_overall_version binaryblobformatexception bloblength bloblength readint eofexception blobtype readshort blobver readshort blobtype binaryblob blob_end blobtype binaryblob blob_block blobver binaryblob blob_block_version binaryblobformatexception bloblength binaryblobformatexception keytype readshort keylen readunsignedbyte headerslen readunsignedshort datalen readunsignedshort pubkeylen readunsignedshort keylen headerslen datalen pubkeylen bloblength binaryblobformatexception bloblength bloblength keybytes keylen headersbytes headerslen databytes datalen pubkeybytes pubkeylen readfully keybytes readfully headersbytes readfully databytes readfully pubkeybytes keyblock createblock keytype keybytes headersbytes databytes pubkeybytes keyverifyexception binaryblobformatexception getmessage fileutil skipfully bloblength binaryblobformatexception blobtype announcer opennet manager om this om om this node om node announced to identities new hash set byte array wrapper announced toi ps new hash set inet address connected to identities new hash set byte array wrapper logminor logger should log logger minor this opennetmanager announcedtoidentities hashset bytearraywrapper announcedtoips hashset inetaddress connectedtoidentities hashset bytearraywrapper shouldlog protected void start if node is opennet enabled return register alert int dark peers node peers get darknet peers length int open peers node peers get opennet peers length int old open peers om count old opennet peers if dark peers open peers old open peers 0 we know opennet is enabled we have no peers at all so lets connect to a few seednodes and attempt an announcement system err println attempting announcement to seednodes synchronized this status status loading started true connect some seednodes else system out println not attempting immediate announcement dark peers dark peers open peers open peers old open peers old open peers will wait 1 minute wait a minute then check whether we need to seed node get ticker queue timed job new runnable public void run synchronized announcer this started true try maybe send announcement catch throwable t logger error this caught t trying to send announcements t min added seeds interval isopennetenabled registeralert darkpeers getdarknetpeers openpeers getopennetpeers oldopenpeers countoldopennetpeers darkpeers openpeers oldopenpeers status_loading connectsomeseednodes darkpeers openpeers oldopenpeers getticker queuetimedjob maybesendannouncement min_added_seeds_interval node get ticker queue timed job new runnable public void run synchronized announcer this started true try maybe send announcement catch throwable t logger error this caught t trying to send announcements t getticker queuetimedjob maybesendannouncement private void register alert node client core alerts register new announcement user alert registeralert clientcore announcementuseralert private void connect some seednodes if node is opennet enabled return boolean announce now false if logminor logger minor this connecting some seednodes list simple field set seeds announcer read seednodes node node dir long now system current time millis synchronized this if now time added seeds min added seeds interval return time added seeds now if seeds size 0 status status no seednodes return else status status connecting seednodes try to connect to some seednodes once they are connected they will report back and we can attempt an announcement int count connect some nodes inner seeds synchronized this if logminor logger minor this count count connected connected to identities size announced announced to identities size running running announcements if count 0 running announcements 0 if connected to identities size announced to identities size some seednodes we haven t been able to connect to yet give it another minute then clear all and try again if logminor logger minor this will clear announced to in 1 minute node get ticker queue timed job new runnable public void run if logminor logger minor this clearing old announced to list synchronized announcer this if running announcements 0 return announced to identities clear announced toi ps clear connected to identities clear maybe send announcement not all connected delay else if connected to identities size announced to identities size clear it now announced to identities clear announced toi ps clear connected to identities clear announce now true node dnsr force run if none connect in a minute try some more node get ticker queue timed job new runnable public void run try maybe send announcement catch throwable t logger error this caught t trying to send announcements t announce now 0 min added seeds interval connectsomeseednodes isopennetenabled announcenow simplefieldset readseednodes nodedir currenttimemillis timeaddedseeds min_added_seeds_interval timeaddedseeds status_no_seednodes status_connecting_seednodes connectsomenodesinner connectedtoidentities announcedtoidentities runningannouncements runningannouncements connectedtoidentities announcedtoidentities getticker queuetimedjob runningannouncements announcedtoidentities announcedtoips connectedtoidentities maybesendannouncement not_all_connected_delay connectedtoidentities announcedtoidentities announcedtoidentities announcedtoips connectedtoidentities announcenow forcerun getticker queuetimedjob maybesendannouncement announcenow min_added_seeds_interval node get ticker queue timed job new runnable public void run if logminor logger minor this clearing old announced to list synchronized announcer this if running announcements 0 return announced to identities clear announced toi ps clear connected to identities clear maybe send announcement getticker queuetimedjob runningannouncements announcedtoidentities announcedtoips connectedtoidentities maybesendannouncement node get ticker queue timed job new runnable public void run try maybe send announcement catch throwable t logger error this caught t trying to send announcements t getticker queuetimedjob maybesendannouncement synchronize to protect announced to identities and prevent running in parallel private synchronized int connect some nodes inner list simple field set seeds if logminor logger minor this connecting some seednodes from seeds size int count 0 while count connect at once if seeds size 0 break simple field set fs seeds remove node random next int seeds size try seed server peer node seed new seed server peer node fs node om crypto node peers false om crypto packet mangler if announced to identities contains new byte array wrapper seed identity if logminor logger minor this not adding already announced to seed user to string continue if logminor logger minor this trying to connect to seednode seed if node peers add peer seed count connected to identities add new byte array wrapper seed identity if logminor logger minor this connecting to seednode seed else if logminor logger minor this not connecting to seednode seed catch fs parse exception e logger error this invalid seed in file e for n fs e continue catch peer parse exception e logger error this invalid seed in file e for n fs e continue catch reference signature verification exception e logger error this invalid seed in file e for n fs e continue return count announcedtoidentities connectsomenodesinner simplefieldset connect_at_once simplefieldset nextint seedserverpeernode seedserverpeernode packetmangler announcedtoidentities bytearraywrapper usertostring addpeer connectedtoidentities bytearraywrapper fsparseexception peerparseexception referencesignatureverificationexception public static list simple field set read seednodes file node dir file file new file node dir seednodes fref list simple field set list new array list simple field set file input stream fis null try fis new file input stream file buffered input stream bis new buffered input stream fis input stream reader isr new input stream reader bis utf 8 buffered reader br new buffered reader isr while true try simple field set fs new simple field set br false false if fs is empty list add fs catch eof exception e return list catch io exception e return list finally closer close fis simplefieldset readseednodes nodedir nodedir simplefieldset arraylist simplefieldset fileinputstream fileinputstream bufferedinputstream bufferedinputstream inputstreamreader inputstreamreader bufferedreader bufferedreader simplefieldset simplefieldset isempty eofexception ioexception protected void stop do nothing at present return true if we have enough peers that we don t need to announce boolean enough peers do we want to send an announcement to the node int opennet count node peers count connected opennet peers first do we actually need to announce int target math min min opennet connected peers om get number of connected peers to aim 2 if opennet count target if logminor logger minor this we have enough opennet peers opennet count target since system current time millis time got enough peers ms synchronized time got enough peers lock if time got enough peers 0 time got enough peers system current time millis return true if node node updater null node node updater is enabled node node updater can update now node node updater is armed if we also have 10 too new peers we should shut down the announcement because we re obviously broken and would only be spamming the seednodes if node peers get peer node status size peer manager peer node status too new true node peers get peer node status size peer manager peer node status too new false 10 synchronized this if killed announcement too old return true killed announcement too old true logger error this shutting down announcement as we are older than the current mandatory build and auto update is disabled or waiting for user input system err println shutting down announcement as we are older than the current mandatory build and auto update is disabled or waiting for user input if node client core null node client core alerts register new simple user alert false l10n announce disabled too old title l10n announce disabled too old l10n announce disabled too old short user alert critical error return true synchronized time got enough peers lock time got enough peers 1 return false enoughpeers opennetcount countconnectedopennetpeers min_opennet_connected_peers getnumberofconnectedpeerstoaim opennetcount opennetcount currenttimemillis timegotenoughpeers timegotenoughpeerslock timegotenoughpeers timegotenoughpeers currenttimemillis nodeupdater nodeupdater isenabled nodeupdater canupdatenow nodeupdater isarmed too_new getpeernodestatussize peermanager peer_node_status_too_new getpeernodestatussize peermanager peer_node_status_too_new killedannouncementtooold killedannouncementtooold clientcore clientcore simpleuseralert announcedisabledtoooldtitle announcedisabledtooold announcedisabledtoooldshort useralert critical_error timegotenoughpeerslock timegotenoughpeers get the earliest time at which we had enough opennet peers this is reset when we drop below the threshold long time got enough peers synchronized time got enough peers lock return time got enough peers timegotenoughpeers timegotenoughpeerslock timegotenoughpeers protected void maybe send announcement synchronized this if started return logminor logger should log logger minor this if logminor logger minor this maybe send announcement long now system current time millis if node is opennet enabled return if enough peers node get ticker queue timed job new runnable public void run synchronized announcer this if running announcements 0 return if enough peers for seed server peer node pn node peers get connected seed server peers vector null node peers disconnect pn true true false re check every minute something bad might happen e g cpu starvation causing us to have to reseed node get ticker queue timed job new runnable public void run maybe send announcement retry delay else node get ticker queue timed job new runnable public void run maybe send announcement retry delay maybe send announcement final delay return if ignoreip undetected node ip detector has validip if node ip detector ip detector manager has detectors if now told user noip 60 1000 system out println don t know our ip address waiting for another 2 minutes synchronized this dont know ourip address true wait a bit node get ticker queue timed job new runnable public void run synchronized announcer this if ignoreip undetected return ignoreip undetected true maybe send announcement force announcement no ip return synchronized this dont know ourip address false double check after taking the lock if enough peers return second do we have many announcements running if running announcements want announcements if logminor logger minor this running announcements already return in cooling off period if system current time millis start time if logminor logger minor this in cooling off period for next time util format time start time system current time millis return if sent announcements want announcements if logminor logger minor this sent enough announcements return now find a node to announce to vector seed server peer node seeds node peers get connected seed server peers vector announced to identities while sent announcements want announcements if seeds is empty if logminor logger minor this no more seednodes announced to announced to identities size break final seed server peer node seed seeds remove node random next int seeds size inet address addrs seed get inet addresses if new announcedi ps addrs if logminor logger minor this not announcing to seed because already used those i ps continue add announcedi ps addrs sent announcements running announcements announced to identities add new byte array wrapper seed get identity send announcement seed if running announcements want announcements if logminor logger minor this running running announcements announcements return do we want to connect some more seednodes if now time added seeds min added seeds interval don t connect seednodes yet logger minor this waiting for min added seeds interval node get ticker queue timed job new runnable public void run try maybe send announcement catch throwable t logger error this caught t trying to send announcements t time added seeds min added seeds interval now return connect some seednodes maybesendannouncement shouldlog maybesendannouncement currenttimemillis isopennetenabled enoughpeers getticker queuetimedjob runningannouncements enoughpeers seedserverpeernode getconnectedseedserverpeersvector getticker queuetimedjob maybesendannouncement retry_delay getticker queuetimedjob maybesendannouncement retry_delay maybesendannouncement final_delay ignoreipundetected ipdetector hasvalidip ipdetector ipdetectormanager hasdetectors toldusernoip dontknowouripaddress getticker queuetimedjob ignoreipundetected ignoreipundetected maybesendannouncement force_announcement_no_ip dontknowouripaddress enoughpeers runningannouncements want_announcements currenttimemillis starttime timeutil formattime starttime currenttimemillis sentannouncements want_announcements seedserverpeernode getconnectedseedserverpeersvector announcedtoidentities sentannouncements want_announcements isempty announcedto announcedtoidentities seedserverpeernode nextint inetaddress getinetaddresses newannouncedips ips addannouncedips sentannouncements runningannouncements announcedtoidentities bytearraywrapper getidentity sendannouncement runningannouncements want_announcements runningannouncements timeaddedseeds min_added_seeds_interval min_added_seeds_interval getticker queuetimedjob maybesendannouncement timeaddedseeds min_added_seeds_interval connectsomeseednodes node get ticker queue timed job new runnable public void run synchronized announcer this if running announcements 0 return if enough peers for seed server peer node pn node peers get connected seed server peers vector null node peers disconnect pn true true false re check every minute something bad might happen e g cpu starvation causing us to have to reseed node get ticker queue timed job new runnable public void run maybe send announcement retry delay else node get ticker queue timed job new runnable public void run maybe send announcement retry delay maybe send announcement getticker queuetimedjob runningannouncements enoughpeers seedserverpeernode getconnectedseedserverpeersvector getticker queuetimedjob maybesendannouncement retry_delay getticker queuetimedjob maybesendannouncement retry_delay maybesendannouncement re check every minute something bad might happen e g cpu starvation causing us to have to reseed node get ticker queue timed job new runnable public void run maybe send announcement getticker queuetimedjob maybesendannouncement else node get ticker queue timed job new runnable public void run maybe send announcement getticker queuetimedjob maybesendannouncement node get ticker queue timed job new runnable public void run synchronized announcer this if ignoreip undetected return ignoreip undetected true maybe send announcement getticker queuetimedjob ignoreipundetected ignoreipundetected maybesendannouncement node get ticker queue timed job new runnable public void run try maybe send announcement catch throwable t logger error this caught t trying to send announcements t getticker queuetimedjob maybesendannouncement private synchronized void add announcedi ps inet address addrs for inet address addr addrs announced toi ps add addr addannouncedips inetaddress inetaddress announcedtoips have we already announced to this node return true if the node has new non local addresses we haven t announced to return false if the node has non local addresses we have announced to return true if the node has no non local addresses param addrs return private synchronized boolean new announcedi ps inet address addrs boolean has non local addresses false for int i 0 i addrs length i if ip util is valid address addrs i false continue has non local addresses true if announced toi ps contains addrs i return true return has non local addresses newannouncedips inetaddress hasnonlocaladdresses iputil isvalidaddress hasnonlocaladdresses announcedtoips hasnonlocaladdresses protected void send announcement final seed server peer node seed if node is opennet enabled if logminor logger minor this not announcing to seed because opennet is disabled return system out println announcement to seed user to string starting if logminor logger minor this announcement to seed user to string starting announce sender sender new announce sender node get location om node new announcement callback private int total added private int total not wanted public void added node peer node pn synchronized announcer this announcement added nodes total added logger normal this announcement to seed user to string added node pn for a total of announcement added nodes total added from this announcement system out println announcement to seed user to string added node pn user to string return public void bogus noderef string reason logger normal this announcement to seed user to string got bogus noderef reason new exception debug public void completed boolean announce now false synchronized announcer this running announcements logger normal this announcement to seed user to string completed now running running announcements announcements if running announcements 0 announcement added nodes 0 no point waiting if no nodes have been added start time system current time millis cooling off period sent announcements 0 wait for cooling off period before trying again node get ticker queue timed job new runnable public void run maybe send announcement cooling off period else if running announcements 0 sent announcements 0 announce now true if it takes more than cooling off period to disconnect we might not be able to reannounce to this node however we can t reannounce to it anyway until announced to is cleared which probably will be more than that period in the future node peers disconnect seed true false false system out println announcement to seed user to string completed if announce now maybe send announcement public void node failed peer node pn string reason logger normal this announcement to node pn user to string failed reason public void no more nodes logger normal this announcement to seed user to string ran out of nodes route not found public void node not wanted synchronized announcer this announcement not wanted nodes total not wanted logger normal this announcement to seed user to string returned node not wanted for a total of announcement not wanted nodes total not wanted from this announcement public void node not added logger normal this announcement to seed user to string node not wanted maybe already have it opennet just turned off etc seed node executor execute sender announcer to seed sendannouncement seedserverpeernode isopennetenabled usertostring usertostring announcesender announcesender getlocation announcementcallback totaladded totalnotwanted addednode peernode announcementaddednodes totaladded usertostring announcementaddednodes totaladded usertostring usertostring bogusnoderef usertostring announcenow runningannouncements usertostring runningannouncements runningannouncements announcementaddednodes starttime currenttimemillis cooling_off_period sentannouncements cooling_off_period getticker queuetimedjob maybesendannouncement cooling_off_period runningannouncements sentannouncements announcenow cooling_off_period announcedto usertostring announcenow maybesendannouncement nodefailed peernode usertostring nomorenodes usertostring nodenotwanted announcementnotwantednodes totalnotwanted usertostring announcementnotwantednodes totalnotwanted nodenotadded usertostring private int total not wanted public void added node peer node pn synchronized announcer this announcement added nodes total added logger normal this announcement to seed user to string added node pn for a total of announcement added nodes total added from this announcement system out println announcement to seed user to string added node pn user to string return totalnotwanted addednode peernode announcementaddednodes totaladded usertostring announcementaddednodes totaladded usertostring usertostring return public void bogus noderef string reason logger normal this announcement to seed user to string got bogus noderef reason new exception debug bogusnoderef usertostring public void completed boolean announce now false synchronized announcer this running announcements logger normal this announcement to seed user to string completed now running running announcements announcements if running announcements 0 announcement added nodes 0 no point waiting if no nodes have been added start time system current time millis cooling off period sent announcements 0 wait for cooling off period before trying again node get ticker queue timed job new runnable public void run maybe send announcement cooling off period else if running announcements 0 sent announcements 0 announce now true if it takes more than cooling off period to disconnect we might not be able to reannounce to this node however we can t reannounce to it anyway until announced to is cleared which probably will be more than that period in the future node peers disconnect seed true false false system out println announcement to seed user to string completed if announce now maybe send announcement announcenow runningannouncements usertostring runningannouncements runningannouncements announcementaddednodes starttime currenttimemillis cooling_off_period sentannouncements cooling_off_period getticker queuetimedjob maybesendannouncement cooling_off_period runningannouncements sentannouncements announcenow cooling_off_period announcedto usertostring announcenow maybesendannouncement node get ticker queue timed job new runnable public void run maybe send announcement getticker queuetimedjob maybesendannouncement public void node failed peer node pn string reason logger normal this announcement to node pn user to string failed reason nodefailed peernode usertostring logger normal this announcement to node pn user to string failed reason public void no more nodes logger normal this announcement to seed user to string ran out of nodes route not found usertostring nomorenodes usertostring public void node not wanted synchronized announcer this announcement not wanted nodes total not wanted logger normal this announcement to seed user to string returned node not wanted for a total of announcement not wanted nodes total not wanted from this announcement nodenotwanted announcementnotwantednodes totalnotwanted usertostring announcementnotwantednodes totalnotwanted logger normal this announcement to seed user to string returned node not wanted for a total of announcement not wanted nodes total not wanted from this announcement public void node not added logger normal this announcement to seed user to string node not wanted maybe already have it opennet just turned off etc usertostring announcementnotwantednodes totalnotwanted nodenotadded usertostring class announcement user alert implements user alert public string dismiss button text return l10n get string user alert hide announcementuseralert useralert dismissbuttontext getstring useralert public html node gethtml text return new html node get text htmlnode gethtmltext htmlnode gettext public short get priority class return user alert error getpriorityclass useralert public string get text string builder sb new string builder sb append l10n announce alert intro int status boolean dont know address synchronized this status announcer this status dont know address dont know ourip address if status status no seednodes return l10n announce alert no seednodes if status status loading return l10n announce loading if node client core is advanced mode enabled detail sb append int added nodes int refused nodes int recent sent announcements int running announcements int connected seednodes 0 int disconnected seednodes 0 long cooling off seconds math max 0 start time system current time millis 1000 synchronized this added nodes announcement added nodes refused nodes announcement not wanted nodes recent sent announcements sent announcements running announcements announcer this running announcements list seed server peer node nodes node peers get seed server peers vector for seed server peer node seed nodes if seed is connected connected seednodes else disconnected seednodes if dont know address sb append l10n dont know address else sb append l10n announce details new string added nodes refused nodes recent sent announcements running announcements connected seednodes disconnected seednodes new string integer to string added nodes integer to string refused nodes integer to string recent sent announcements integer to string running announcements integer to string connected seednodes integer to string disconnected seednodes if cooling off seconds 0 sb append sb append l10n cooling off time long to string cooling off seconds return sb to string gettext stringbuilder stringbuilder announcealertintro dontknowaddress dontknowaddress dontknowouripaddress status_no_seednodes announcealertnoseednodes status_loading announceloading clientcore isadvancedmodeenabled addednodes refusednodes recentsentannouncements runningannouncements connectedseednodes disconnectedseednodes coolingoffseconds starttime currenttimemillis addednodes announcementaddednodes refusednodes announcementnotwantednodes recentsentannouncements sentannouncements runningannouncements runningannouncements seedserverpeernode getseedserverpeersvector seedserverpeernode isconnected connectedseednodes disconnectedseednodes dontknowaddress dontknowaddress announcedetails addednodes refusednodes recentsentannouncements runningannouncements connectedseednodes disconnectedseednodes tostring addednodes tostring refusednodes tostring recentsentannouncements tostring runningannouncements tostring connectedseednodes tostring disconnectedseednodes coolingoffseconds coolingoff tostring coolingoffseconds tostring public string get title return l10n announce alert title gettitle announcealerttitle public object get user identifier return null getuseridentifier public boolean is valid return enough peers node is opennet enabled isvalid enoughpeers isopennetenabled public void is valid boolean validity ignore isvalid public void on dismiss ignore ondismiss public boolean should unregister on dismiss return true shouldunregisterondismiss public boolean user can dismiss return true usercandismiss public string anchor return announcer hash code hashcode public string get short text return l10n announce alert short getshorttext announcealertshort public boolean is event notification return false iseventnotification private string l10n string key return l10n get string announcer key getstring protected string l10n string key string patterns string values return l10n get string announcer key patterns values getstring private string l10n string key string pattern string value return l10n get string announcer key pattern value getstring public renewer jmdns impl jmdns impl this jmdns impl jmdns impl associate host to this if it needs renewal if this jmdns impl get state dns state announced this jmdns impl set task this associate services to this if they need renewal synchronized this jmdns impl for iterator s this jmdns impl get services values iterator s has next service info impl info service info impl s next if info get state dns state announced info set task this jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl jmdnsimpl getstate dnsstate jmdnsimpl settask jmdnsimpl jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl getstate dnsstate settask public void start timer timer timer schedule this dns constants announced renewal ttl interval dns constants announced renewal ttl interval dnsconstants announced_renewal_ttl_interval dnsconstants announced_renewal_ttl_interval public boolean cancel remove association from host to this if this jmdns impl get task this this jmdns impl set task null remove associations from services to this synchronized this jmdns impl for iterator i this jmdns impl get services values iterator i has next service info impl info service info impl i next if info get task this info set task null return super cancel jmdnsimpl gettask jmdnsimpl settask jmdnsimpl jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl gettask settask public void run dns outgoing out null try send probes for jmdns itself if this jmdns impl get state task state if out null out new dns outgoing dns constants flags qr response dns constants flags aa this jmdns impl get local host add address records out false this jmdns impl advance state send announces for services defensively copy the services into a local list to prevent race conditions with methods register service and unregister service list list synchronized this jmdns impl list new array list this jmdns impl get services values for iterator i list iterator i has next service info impl info service info impl i next synchronized info if info get state task state info get task this info advance state logger finer run jmdns announced info get qualified name state info get state if out null out new dns outgoing dns constants flags qr response dns constants flags aa info add answers out dns constants dns ttl this jmdns impl get local host if out null logger finer run jmdns announced this jmdns impl send out else if we have nothing to send another timer task state ahead of us has done the job for us we can cancel cancel catch throwable e logger log level warning run exception e this jmdns impl recover task state task state advance if task state is announced cancel dnsoutgoing jmdnsimpl getstate taskstate dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa jmdnsimpl getlocalhost addaddressrecords jmdnsimpl advancestate registerservice unregisterservice jmdnsimpl arraylist jmdnsimpl getservices hasnext serviceinfoimpl serviceinfoimpl getstate taskstate gettask advancestate getqualifiedname getstate dnsoutgoing dnsconstants flags_qr_response dnsconstants flags_aa addanswers dnsconstants dns_ttl jmdnsimpl getlocalhost jmdnsimpl taskstate jmdnsimpl taskstate taskstate taskstate isannounced protected base single file fetcher client key key int max retries fetch context ctx client requester parent boolean delete fetch context super parent this delete fetch context delete fetch context if logger should log logger minor this logger minor this creating base single file fetcher for key retry count 0 this max retries max retries this key key this ctx ctx if ctx null throw new null pointer exception if key null throw new null pointer exception cooldown wakeup time 1 basesinglefilefetcher clientkey maxretries fetchcontext clientrequester deletefetchcontext deletefetchcontext deletefetchcontext shouldlog basesinglefilefetcher retrycount maxretries maxretries nullpointerexception nullpointerexception cooldownwakeuptime override public long count all keys object container container client context context return 1 countallkeys objectcontainer clientcontext override public long count sendable keys object container container client context context return 1 countsendablekeys objectcontainer clientcontext override public sendable request item choose key keys fetching locally fetching object container container client context context if persistent container activate key 5 if fetching has key key get node key return null return keys 0 sendablerequestitem choosekey keysfetchinglocally objectcontainer clientcontext haskey getnodekey override public boolean has valid keys keys fetching locally fetching object container container client context context if persistent container activate key 5 return fetching has key key get node key hasvalidkeys keysfetchinglocally objectcontainer clientcontext haskey getnodekey override public client key get key object token object container container if persistent container activate key 5 return key clientkey getkey objectcontainer override public fetch context get context return ctx fetchcontext getcontext override public boolean isssk return key instanceof clientssk try again returns true if we can retry protected boolean retry object container container client context context retry count if logger should log logger minor this logger minor this attempting to retry max max retries current retry count on this we want 0 1 max retries i e max retries 1 attempts max retries 0 try once no retries max retries 1 original try 1 retry if retry count max retries max retries 1 if persistent container store this if retry count request scheduler cooldown retries 0 add to cooldown queue don t reschedule yet long now system current time millis if cooldown wakeup time now logger error this already on the cooldown queue for this until freenet support time util format time cooldown wakeup time now new exception error we must be registered unregister unregister container context else if logger should log logger minor this logger minor this adding to cooldown queue this if persistent container activate key 5 request scheduler sched context get fetch scheduler key instanceof clientssk cooldown wakeup time sched queue cooldown key this container if persistent container deactivate key 5 unregister as going to cooldown queue unregister container context else unregister container context reschedule container context return true we will retry in any case maybe not just not yet see requeue after cooldown key unregister container context return false objectcontainer clientcontext retrycount shouldlog maxretries retrycount maxretries maxretries maxretries maxretries retrycount maxretries maxretries retrycount requestscheduler cooldown_retries currenttimemillis cooldownwakeuptime timeutil formattime cooldownwakeuptime shouldlog requestscheduler getfetchscheduler cooldownwakeuptime queuecooldown requeueaftercooldown override public int get retry count return retry count getretrycount retrycount override public client requester get client request return parent clientrequester getclientrequest override public short get priority class object container container if persistent container activate parent 1 not much point deactivating it short retval parent get priority class return retval getpriorityclass objectcontainer getpriorityclass override public boolean ignore store return ctx ignore store ignorestore ignorestore public void cancel object container container client context context synchronized this cancelled true if persistent container store this container activate key 5 unregister all container context objectcontainer clientcontext unregisterall remove the pending keys item and then remove from the queue as well call unregister container if you only want to remove from the queue public void unregister all object container container client context context get scheduler context remove pending keys this false super unregister container context pendingkeys unregisterall objectcontainer clientcontext getscheduler removependingkeys override public synchronized boolean is cancelled object container container return cancelled iscancelled objectcontainer public synchronized boolean is empty object container container return cancelled finished isempty objectcontainer override public request client get client object container container if persistent container activate parent 1 return parent get client requestclient getclient objectcontainer getclient override public boolean dont cache object container container if persistent container activate ctx 1 return ctx cache local requests dontcache objectcontainer cachelocalrequests public void on got key key key key block block object container container client context context if persistent container activate this 1 container activate key 5 container activate this key 5 synchronized this if finished if logger should log logger minor this logger minor this on got key called twice on this new exception debug return finished true if persistent container store this if is cancelled container return if key null throw new null pointer exception if this key null throw new null pointer exception key is null on this if key equals this key get node key logger normal this got sent key key but want this key for this return unregister container context key has already been removed from pending keys try on success key create key block this key block false null container context catch key verify exception e logger error this on got key key block got e for this e fixme if we get rid of the direct route this must call on failure if persistent container deactivate this 1 container deactivate this key 1 ongotkey keyblock objectcontainer clientcontext shouldlog ongotkey iscancelled nullpointerexception nullpointerexception getnodekey pendingkeys onsuccess createkeyblock keyverifyexception ongotkey onfailure called when if the low level request succeeds public abstract void on success client key block block boolean from store object token object container container client context context onsuccess clientkeyblock fromstore objectcontainer clientcontext public abstract void on success client key block block boolean from store object token object container container client context context override public long get cooldown wakeup object token object container container return cooldown wakeup time onsuccess clientkeyblock fromstore objectcontainer clientcontext getcooldownwakeup objectcontainer cooldownwakeuptime override public long get cooldown wakeup by key key key object container container return cooldown wakeup time getcooldownwakeupbykey objectcontainer cooldownwakeuptime override public synchronized void reset cooldown times object container container cooldown wakeup time 1 if persistent container store this resetcooldowntimes objectcontainer cooldownwakeuptime override public void requeue after cooldown key key long time object container container client context context if cooldown wakeup time time if logger should log logger minor this logger minor this not requeueing as deadline has not passed yet return if persistent container activate this key 5 if key equals this key get node key logger error this got requeue after cooldown for wrong key key but mine is this key get node key for this key return if logger should log logger minor this logger minor this requeueing after cooldown key for this reschedule container context if persistent container deactivate this key 5 requeueaftercooldown objectcontainer clientcontext cooldownwakeuptime shouldlog getnodekey requeueaftercooldown getnodekey shouldlog public void schedule object container container client context context if persistent container activate ctx 1 if ctx blocks null container activate ctx blocks 5 try get scheduler context register this new sendable get this persistent true container ctx blocks false catch key listener construction exception e logger error this impossible e on this e objectcontainer clientcontext getscheduler sendableget keylistenerconstructionexception public void reschedule object container container client context context if persistent container activate ctx 1 if ctx blocks null container activate ctx blocks 5 try get scheduler context register null new sendable get this persistent true container ctx blocks true catch key listener construction exception e logger error this impossible e on this e objectcontainer clientcontext getscheduler sendableget keylistenerconstructionexception public sendable get get request key key object container container return this sendableget getrequest objectcontainer override public key list keys object container container if cancelled finished return new key 0 else if persistent container activate key 5 return new key key get node key listkeys objectcontainer getnodekey override public list persistent chosen block make blocks persistent chosen request request request scheduler sched object container container client context context if persistent container activate key 5 client key ckey key clone key persistent chosen block block new persistent chosen block false request keys 0 ckey get node key ckey sched return collections singleton list block persistentchosenblock makeblocks persistentchosenrequest requestscheduler objectcontainer clientcontext clientkey clonekey persistentchosenblock persistentchosenblock getnodekey singletonlist public key listener make key listener object container container client context context if persistent container activate key 5 container activate parent 1 container activate ctx 1 if finished return null if cancelled return null key new key key get node key clone key short prio parent get priority class boolean dont cache ctx cache local requests key listener ret new single key listener new key this dont cache prio persistent if persistent container deactivate key 5 container deactivate parent 1 container deactivate ctx 1 return ret keylistener makekeylistener objectcontainer clientcontext newkey getnodekey clonekey getpriorityclass dontcache cachelocalrequests keylistener singlekeylistener newkey dontcache override public void remove from object container container client context context super remove from container context if delete fetch context container activate ctx 1 ctx remove from container container activate key 5 key remove from container removefrom objectcontainer clientcontext removefrom deletefetchcontext removefrom removefrom override public void pre register object container container client context context boolean to network if to network return boolean deactivate false if persistent deactivate container ext is active parent container activate parent 1 parent to network container context if deactivate container deactivate parent 1 preregister objectcontainer clientcontext tonetwork tonetwork isactive tonetwork set the pixel block size param block size the number of pixels along each block edge min value 1 max value 100 see get block size public void set block size int block size this block size block size blocksize getblocksize setblocksize blocksize blocksize blocksize get the pixel block size return the number of pixels along each block edge see set block size public int get block size return block size setblocksize getblocksize blocksize public block filter blockfilter override protected void transform inverse int x int y float out out 0 x block size block size out 1 y block size block size transforminverse blocksize blocksize blocksize blocksize override public string to string return stylize mosaic tostring private static final long serial versionuid 1l public still not acked exception packet tracker tracker this tracker tracker serialversionuid stillnotackedexception packettracker static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public block transmitter message core usm peer context destination long uid partially received block source byte counter ctr usm usm destination destination uid uid prb source ctr ctr if ctr null throw new null pointer exception packet size dmt packet transmit size prb packetsize prb packets destination get outgoing mangler full headers length one message try sentpackets new bit array prb get num packets catch aborted exception e logger error this aborted during setup will throw on running throttle destination get throttle senderthread new prio runnable public void run while sendcomplete int packet no try synchronized senderthread while unsent size 0 if sendcomplete return senderthread wait 10 1000 packet no unsent remove first catch interrupted exception e logger error this senderthread interrupted continue int total packets try destination send throttled message dmt create packet transmit uid packet no sentpackets prb get packet packet no prb packetsize ctr send timeout false null total packets prb get num packets catch not connected exception e logger normal this terminating send e the send thread should notice return catch aborted exception e logger normal this terminating send due to abort e the send thread should notice return catch waited too long exception e logger normal this waited too long to send packet aborting synchronized senderthread sendcomplete true return catch sync send waited too long exception e impossible logger error this impossible caught e e return synchronized senderthread sentpackets set bit packet no true if unsent size 0 get num sent total packets no unsent packets no unreceived packets send all sent notification time all sent system current time millis if logminor logger minor this sent all blocks none unsent senderthread notify all public int get priority return native thread high priority blocktransmitter messagecore peercontext partiallyreceivedblock bytecounter _usm _destination _uid _prb _ctr _ctr nullpointerexception packet_size packettransmitsize _prb _packetsize _prb _packets getoutgoingmangler fullheaderslengthonemessage _sentpackets bitarray _prb getnumpackets abortedexception _destination getthrottle _senderthread priorunnable _sendcomplete packetno _senderthread _unsent _sendcomplete _senderthread packetno _unsent removefirst interruptedexception _senderthread totalpackets _destination sendthrottledmessage createpackettransmit _uid packetno _sentpackets _prb getpacket packetno _prb _packetsize _ctr send_timeout totalpackets _prb getnumpackets notconnectedexception abortedexception waitedtoolongexception _senderthread _sendcomplete syncsendwaitedtoolongexception _senderthread _sentpackets setbit packetno _unsent getnumsent totalpackets sendallsentnotification timeallsent currenttimemillis _senderthread notifyall getpriority nativethread high_priority public void run while sendcomplete int packet no try synchronized senderthread while unsent size 0 if sendcomplete return senderthread wait 10 1000 packet no unsent remove first catch interrupted exception e logger error this senderthread interrupted continue int total packets try destination send throttled message dmt create packet transmit uid packet no sentpackets prb get packet packet no prb packetsize ctr send timeout false null total packets prb get num packets catch not connected exception e logger normal this terminating send e the send thread should notice return catch aborted exception e logger normal this terminating send due to abort e the send thread should notice return catch waited too long exception e logger normal this waited too long to send packet aborting synchronized senderthread sendcomplete true return catch sync send waited too long exception e impossible logger error this impossible caught e e return synchronized senderthread sentpackets set bit packet no true if unsent size 0 get num sent total packets no unsent packets no unreceived packets send all sent notification time all sent system current time millis if logminor logger minor this sent all blocks none unsent senderthread notify all _sendcomplete packetno _senderthread _unsent _sendcomplete _senderthread packetno _unsent removefirst interruptedexception _senderthread totalpackets _destination sendthrottledmessage createpackettransmit _uid packetno _sentpackets _prb getpacket packetno _prb _packetsize _ctr send_timeout totalpackets _prb getnumpackets notconnectedexception abortedexception waitedtoolongexception _senderthread _sendcomplete syncsendwaitedtoolongexception _senderthread _sentpackets setbit packetno _unsent getnumsent totalpackets sendallsentnotification timeallsent currenttimemillis _senderthread notifyall public int get priority return native thread high priority getpriority nativethread high_priority public void abort send int reason string desc throws not connected exception synchronized this if sendcomplete return sendcomplete true send aborted reason desc abortsend notconnectedexception _sendcomplete _sendcomplete sendaborted public void send aborted int reason string desc throws not connected exception usm send destination dmt create send aborted uid reason desc ctr sendaborted notconnectedexception _usm _destination createsendaborted _uid _ctr private void send all sent notification try usm send destination dmt create all sent uid ctr catch not connected exception e logger normal this disconnected for all sent sendallsentnotification _usm _destination createallsent _uid _ctr notconnectedexception allsent public boolean send executor executor long start time system current time millis partially received block packet received listener my listener null try synchronized prb unsent prb add listener my listener new partially received block packet received listener public void packet received int packet no synchronized senderthread unsent add last packet no time all sent 1 sentpackets set bit packet no false senderthread notify all public void receive aborted int reason string description executor execute senderthread to string while true synchronized senderthread if sendcomplete return false message msg try message filter mf missing packet notification message filter create set type dmt missing packet notification set field dmt uid uid set timeout send timeout set source destination message filter mf all received message filter create set type dmt all received set field dmt uid uid set timeout send timeout set source destination message filter mf send aborted message filter create set type dmt send aborted set field dmt uid uid set timeout send timeout set source destination msg usm wait for mf missing packet notification or mf all received or mf send aborted ctr if logminor logger minor this got msg catch disconnected exception e throttle maybe disconnected logger normal this terminating send uid to destination from destination get socket handler because node disconnected while waiting they disconnected can t send an abort to them then can we return false if logminor logger minor this got msg if msg null long now system current time millis send timeout one minute after all packets have been transmitted terminate the send if time all sent 0 now time all sent send timeout get num sent prb get num packets string time string time util format time now time all sent 2 true logger error this terminating send uid to destination from destination get socket handler as we haven t heard from receiver in time string send aborted retrieval exception receiver died haven t heard from you receiver in time string return false else if logminor logger minor this ignoring timeout time all sent time all sent system current time millis time all sent get num sent get num sent prb get num packets continue else if msg get spec equals dmt missing packet notification linked list integer missing linked list integer msg get object dmt missing for int packet no missing if prb is received packet no synchronized senderthread if unsent contains packet no logger minor this already to transmit packet packet no else unsent add first packet no time all sent 1 sentpackets set bit packet no false senderthread notify all else to be expected if the transfer is slow since we send missing packet notification on a timeout if logminor logger minor this receiver requested block packet no which is not received else if msg get spec equals dmt all received long end time system current time millis if logminor long transfer time end time start time synchronized avg time taken avg time taken report transfer time logger minor this block send took transfer time avg time taken return true else if msg get spec equals dmt send aborted overloaded receiver no longer wants the data do not abort prb it s none of its business and especially we don t want a downstream node to be able to abort our sends to all the others they aborted don t need to send an aborted back return false else logger error this transmitter received unknown message type msg get spec get name catch not connected exception e most likely from sending an abort logger normal this not connected exception in block transfer send e return false catch aborted exception e logger normal this aborted exception in block transfer send e try string desc prb get abort description if desc index of upstream 0 desc upstream transfer failed desc send aborted prb get abort reason desc catch not connected exception gone ignore return false finally terminate the sender thread if we are not listening for control packets don t be sending any data synchronized senderthread sendcomplete true senderthread notify all if my listener null prb remove listener my listener starttime currenttimemillis partiallyreceivedblock packetreceivedlistener mylistener _prb _unsent _prb addlistener mylistener partiallyreceivedblock packetreceivedlistener packetreceived packetno _senderthread _unsent addlast packetno timeallsent _sentpackets setbit packetno _senderthread notifyall receiveaborted _senderthread tostring _senderthread _sendcomplete messagefilter mfmissingpacketnotification messagefilter settype missingpacketnotification setfield _uid settimeout send_timeout setsource _destination messagefilter mfallreceived messagefilter settype allreceived setfield _uid settimeout send_timeout setsource _destination messagefilter mfsendaborted messagefilter settype sendaborted setfield _uid settimeout send_timeout setsource _destination _usm waitfor mfmissingpacketnotification mfallreceived mfsendaborted _ctr disconnectedexception maybedisconnected _uid _destination _destination getsockethandler currenttimemillis send_timeout timeallsent timeallsent send_timeout getnumsent _prb getnumpackets timestring timeutil formattime timeallsent _uid _destination _destination getsockethandler timestring sendaborted retrievalexception receiver_died timestring timeallsent timeallsent currenttimemillis timeallsent getnumsent getnumsent _prb getnumpackets getspec missingpacketnotification linkedlist linkedlist getobject packetno _prb isreceived packetno _senderthread _unsent packetno packetno _unsent addfirst packetno timeallsent _sentpackets setbit packetno _senderthread notifyall missingpacketnotification packetno getspec allreceived endtime currenttimemillis transfertime endtime starttime avgtimetaken avgtimetaken transfertime transfertime avgtimetaken getspec sendaborted getspec getname notconnectedexception notconnectedexception blocktransfer abortedexception abortedexception blocktransfer _prb getabortdescription indexof sendaborted _prb getabortreason notconnectedexception _senderthread _sendcomplete _senderthread notifyall mylistener _prb removelistener mylistener public void packet received int packet no synchronized senderthread unsent add last packet no time all sent 1 sentpackets set bit packet no false senderthread notify all packetreceived packetno _senderthread _unsent addlast packetno timeallsent _sentpackets setbit packetno _senderthread notifyall public void receive aborted int reason string description receiveaborted public int get num sent int ret 0 for int x 0 x sentpackets get size x if sentpackets bit at x ret return ret getnumsent _sentpackets getsize _sentpackets bitat send the data off thread public void send async final executor executor executor execute new prio runnable public void run try async exit status send executor finally synchronized block transmitter this async exit status set true block transmitter this notify all public int get priority return native thread high priority block transmitter send async for this sendasync priorunnable asyncexitstatus blocktransmitter asyncexitstatusset blocktransmitter notifyall getpriority nativethread high_priority blocktransmitter sendasync executor execute new prio runnable public void run try async exit status send executor finally synchronized block transmitter this async exit status set true block transmitter this notify all priorunnable asyncexitstatus blocktransmitter asyncexitstatusset blocktransmitter notifyall public int get priority return native thread high priority getpriority nativethread high_priority public boolean get async exit status long deadline system current time millis 60 60 1000 synchronized this while async exit status set try long now system current time millis if now deadline throw new illegal state exception waited more than 1 hour for transfer completion wait deadline now catch interrupted exception e ignore return async exit status getasyncexitstatus currenttimemillis asyncexitstatusset currenttimemillis illegalstateexception interruptedexception asyncexitstatus public peer context get destination return destination peercontext getdestination _destination override public string to string return block transmitter for uid to destination short to string tostring blocktransmitter _uid _destination shorttostring private string value public data constant string string oid string value this oid oid this value value dataconstantstring public string getsnmpoid return oid public object getsnmp data return value getsnmpdata public insert block bucket data client metadata metadata freeneturi desireduri if data null throw new null pointer exception this data data this is freed false if metadata null client metadata new client metadata else client metadata metadata this desireduri desireduri insertblock clientmetadata nullpointerexception isfreed clientmetadata clientmetadata clientmetadata public bucket get data return is freed null data getdata isfreed public void free object container container synchronized this if is freed return is freed true if data null return data free if container null data remove from container data null don t remove twice if container null container store this objectcontainer isfreed isfreed removefrom public void remove from object container container if data null container activate data 1 data remove from container if desireduri null container activate desireduri 5 desireduri remove from container if client metadata null container activate client metadata 5 client metadata remove from container container delete this removefrom objectcontainer removefrom removefrom clientmetadata clientmetadata clientmetadata removefrom public void object on activate object container container cascading activation of dependancies container activate data 1 will cascade container activate desireduri 5 objectonactivate objectcontainer null out the data so it doesn t get removed in remove from call this when the data becomes somebody else s problem public void null data data null removefrom nulldata null out the uri so it doesn t get removed in remove from call this when the uri becomes somebody else s problem public void nulluri this desireduri null removefrom public void null metadata this client metadata null nullmetadata clientmetadata public float m30 m31 m32 m33 public matrix4f set identity setidentity public matrix4f matrix4f m set m public matrix4f float m set m public void set matrix4f m m00 m m00 m01 m m01 m02 m m02 m03 m m03 m10 m m10 m11 m m11 m12 m m12 m13 m m13 m20 m m20 m21 m m21 m22 m m22 m23 m m23 m30 m m30 m31 m m31 m32 m m32 m33 m m33 public void set float m m00 m 0 m01 m 1 m02 m 2 m03 m 3 m10 m 4 m11 m 5 m12 m 6 m13 m 7 m20 m 8 m21 m 9 m22 m 10 m23 m 11 m30 m 12 m31 m 13 m32 m 14 m33 m 15 public void get matrix4f m m m00 m00 m m01 m01 m m02 m02 m m03 m03 m m10 m10 m m11 m11 m m12 m12 m m13 m13 m m20 m20 m m21 m21 m m22 m22 m m23 m23 m m30 m30 m m31 m31 m m32 m32 m m33 m33 public void get float m m 0 m00 m 1 m01 m 2 m02 m 3 m03 m 4 m10 m 5 m11 m 6 m12 m 7 m13 m 8 m20 m 9 m21 m 10 m22 m 11 m23 m 12 m30 m 13 m31 m 14 m32 m 15 m33 public void set identity m00 1 0f m01 0 0f m02 0 0f m03 0 0f m10 0 0f m11 1 0f m12 0 0f m13 0 0f m20 0 0f m21 0 0f m22 1 0f m23 0 0f m30 0 0f m31 0 0f m32 0 0f m33 1 0f setidentity public void mul matrix4f m float tm00 m00 float tm01 m01 float tm02 m02 float tm03 m03 float tm10 m10 float tm11 m11 float tm12 m12 float tm13 m13 float tm20 m20 float tm21 m21 float tm22 m22 float tm23 m23 float tm30 m30 float tm31 m31 float tm32 m32 float tm33 m33 m00 tm00 m m00 tm10 m m01 tm20 m m02 tm30 m m03 m01 tm01 m m00 tm11 m m01 tm21 m m02 tm31 m m03 m02 tm02 m m00 tm12 m m01 tm22 m m02 tm32 m m03 m03 tm03 m m00 tm13 m m01 tm23 m m02 tm33 m m03 m10 tm00 m m10 tm10 m m11 tm20 m m12 tm30 m m13 m11 tm01 m m10 tm11 m m11 tm21 m m12 tm31 m m13 m12 tm02 m m10 tm12 m m11 tm22 m m12 tm32 m m13 m13 tm03 m m10 tm13 m m11 tm23 m m12 tm33 m m13 m20 tm00 m m20 tm10 m m21 tm20 m m22 tm30 m m23 m21 tm01 m m20 tm11 m m21 tm21 m m22 tm31 m m23 m22 tm02 m m20 tm12 m m21 tm22 m m22 tm32 m m23 m23 tm03 m m20 tm13 m m21 tm23 m m22 tm33 m m23 m30 tm00 m m30 tm10 m m31 tm20 m m32 tm30 m m33 m31 tm01 m m30 tm11 m m31 tm21 m m32 tm31 m m33 m32 tm02 m m30 tm12 m m31 tm22 m m32 tm32 m m33 m33 tm03 m m30 tm13 m m31 tm23 m m32 tm33 m m33 public void invert matrix4f t new matrix4f this invert t public void invert matrix4f t m00 t m00 m01 t m10 m02 t m20 m03 t m03 m10 t m01 m11 t m11 m12 t m21 m13 t m13 m20 t m02 m21 t m12 m22 t m22 m23 t m23 m30 1 0f m31 1 0f m32 1 0f m33 t m33 public void set axis angle4f a float half theta a angle 0 5f float cos half theta float math cos half theta float sin half theta float math sin half theta set new quat4f a x sin half theta a y sin half theta a z sin half theta cos half theta axisangle4f halftheta coshalftheta halftheta sinhalftheta halftheta sinhalftheta sinhalftheta sinhalftheta coshalftheta public void set quat4f q float wx wy wz xx yy yz xy xz zz x2 y2 z2 x2 q x q x y2 q y q y z2 q z q z xx q x x2 xy q x y2 xz q x z2 yy q y y2 yz q y z2 zz q z z2 wx q w x2 wy q w y2 wz q w z2 m00 1 0f yy zz m01 xy wz m02 xz wy m03 0 0f m10 xy wz m11 1 0f xx zz m12 yz wx m13 0 0f m20 xz wy m21 yz wx m22 1 0f xx yy m23 0 0f m30 0 m31 0 m32 0 m33 1 public void transform point3f v float x v x m00 v y m10 v z m20 m30 float y v x m01 v y m11 v z m21 m31 float z v x m02 v y m12 v z m22 m32 v x x v y y v z z public void transform vector3f v float x v x m00 v y m10 v z m20 float y v x m01 v y m11 v z m21 float z v x m02 v y m12 v z m22 v x x v y y v z z public void set translation vector3f v m30 v x m31 v y m32 v z settranslation public void set float scale m00 scale m11 scale m22 scale public void rotx float angle float s float math sin angle float c float math cos angle m00 1 0f m01 0 0f m02 0 0f m03 0 0f m10 0 0f m11 c m12 s m13 0 0f m20 0 0f m21 s m22 c m23 0 0f m30 0 0f m31 0 0f m32 0 0f m33 1 0f public void roty float angle float s float math sin angle float c float math cos angle m00 c m01 0 0f m02 s m03 0 0f m10 0 0f m11 1 0f m12 0 0f m13 0 0f m20 s m21 0 0f m22 c m23 0 0f m30 0 0f m31 0 0f m32 0 0f m33 1 0f public void rotz float angle float s float math sin angle float c float math cos angle m00 c m01 s m02 0 0f m03 0 0f m10 s m11 c m12 0 0f m13 0 0f m20 0 0f m21 0 0f m22 1 0f m23 0 0f m30 0 0f m31 0 0f m32 0 0f m33 1 0f public freetalknntp handler freetalk ft socket socket throws socket exception m identity manager ft get identity manager m message manager ft get message manager this socket socket freetalknntphandler socketexception midentitymanager getidentitymanager mmessagemanager getmessagemanager check if handler is still active public boolean is alive return socket is closed isalive isclosed close the connection to the client immediately public synchronized void terminate try socket close catch io exception e ignore ioexception print out a status response numeric code plus additional information private void print status line string line out print line nntp spec requires all command and response lines end with cr lf out print crlf out flush printstatusline print out a text response line the line will be dot stuffed if necessary any line beginning with a dot will have a second dot prepended private void print text response line string line if line length 0 line char at 0 out print out print line out print crlf printtextresponseline charat print out a block of text changing all line terminators to cr lf and dot stuffing as necessary private void print text string text string lines freetalknntp article end of line pattern split text for int i 0 i lines length i print text response line lines i printtext freetalknntparticle endoflinepattern printtextresponseline print a single dot to indicate the end of a text response private void end text response out print crlf out flush endtextresponse get an iterator for the article or range of articles described by desc the description may either be null indicating the current article a message id enclosed in angle brackets a single number indicating that message number a number followed by a dash indicating an unbounded range or a number followed by a dash and a second number indicating a bounded range print an error message if it can t be found private iterator freetalknntp article get article range iterator string desc boolean single if desc null if current group null print status line 412 no newsgroup selected return null try return current group get message iterator current message num current message num catch no such message exception e print status line 420 current article number is invalid return null else if desc length 2 desc char at 0 desc char at desc length 1 string msgid desc substring 1 desc length 1 try message msg m message manager get msgid array list freetalknntp article list new array list freetalknntp article list add new freetalknntp article msg return list iterator catch no such message exception e print status line 430 no such article return null else try matcher matcher range pattern matcher desc if matcher matches print status line 501 syntax error return null string start str matcher group 1 string dash str matcher group 2 string end str matcher group 3 int start integer parse int start str int end if dash str null end start else if end str null end 1 else end integer parse int end str if dash str null single print status line 501 syntax error return null if current group null print status line 412 no newsgroup selected return null try return current group get message iterator start end catch no such message exception e print status line 423 no articles in that range return null catch number format exception e print status line 501 syntax error return null freetalknntparticle getarticlerangeiterator currentgroup printstatusline currentgroup getmessageiterator currentmessagenum currentmessagenum nosuchmessageexception printstatusline charat charat mmessagemanager arraylist freetalknntparticle arraylist freetalknntparticle freetalknntparticle nosuchmessageexception printstatusline rangepattern printstatusline startstr dashstr endstr parseint startstr dashstr endstr parseint endstr dashstr printstatusline currentgroup printstatusline currentgroup getmessageiterator nosuchmessageexception printstatusline numberformatexception printstatusline handle the article body head stat commands private void select article string desc boolean print head boolean print body iterator freetalknntp article iter get article range iterator desc true if iter null return freetalknntp article article iter next if article get message num 0 current message num article get message num if print head print body print status line 220 article get message num article get message getid print text article get head print text response line print text article get body end text response else if print head print status line 221 article get message num article get message getid print text article get head end text response else if print body print status line 222 article get message num article get message getid print text article get body end text response else print status line 223 article get message num article get message getid selectarticle printhead printbody freetalknntparticle getarticlerangeiterator freetalknntparticle getmessagenum currentmessagenum getmessagenum printhead printbody printstatusline getmessagenum getmessage printtext gethead printtextresponseline printtext getbody endtextresponse printhead printstatusline getmessagenum getmessage printtext gethead endtextresponse printbody printstatusline getmessagenum getmessage printtext getbody endtextresponse printstatusline getmessagenum getmessage handle the group command private void select group string name fixme look up by nntp name try string board name freetalknntp group group to board name name board board m message manager get board by name board name current group new freetalknntp group board synchronized board current message num current group first message print status line 211 current group message count current group first message current group last message current group get name fixme implement freetalknntp article get namenntp catch no such board exception e print status line 411 no such group selectgroup boardname freetalknntpgroup grouptoboardname mmessagemanager getboardbyname boardname currentgroup freetalknntpgroup currentmessagenum currentgroup firstmessage printstatusline currentgroup messagecount currentgroup firstmessage currentgroup lastmessage currentgroup getname freetalknntparticle getnamenntp nosuchboardexception printstatusline handle the listgroup command private void select group with list string name string range matcher matcher range pattern matcher range if matcher matches print status line 501 syntax error return string start str matcher group 1 string dash str matcher group 2 string end str matcher group 3 int start end try start integer parse int start str if dash str null end start else if end str null end 1 else end integer parse int end str catch number format exception e print status line 501 syntax error return if name null try string board name freetalknntp group group to board name name board board m message manager get board by name board name current group new freetalknntp group board catch no such board exception e print status line 411 no such group return else if current group null print status line 412 no newsgroup selected return synchronized current group get board current message num current group first message print status line 211 current group message count current group first message current group last message current group get name if end 1 end current group last message list board message reference messages current group get board get all messages true for iterator board message reference i messages iterator i has next int index i next get index if index end break else if index start print text response line integer to string index end text response selectgroupwithlist rangepattern printstatusline startstr dashstr endstr parseint startstr dashstr endstr parseint endstr numberformatexception printstatusline boardname freetalknntpgroup grouptoboardname mmessagemanager getboardbyname boardname currentgroup freetalknntpgroup nosuchboardexception printstatusline currentgroup printstatusline currentgroup getboard currentmessagenum currentgroup firstmessage printstatusline currentgroup messagecount currentgroup firstmessage currentgroup lastmessage currentgroup getname currentgroup lastmessage messagereference currentgroup getboard getallmessages messagereference hasnext getindex printtextresponseline tostring endtextresponse handle the list list active command private void list active groups string pattern fixme filter by wildmat print status line 215 list of newsgroups follows for iterator board i m message manager board iterator i has next board board i next freetalknntp group group new freetalknntp group board print text response line group get name group last message group first message group posting status end text response listactivegroups printstatusline mmessagemanager boarditerator hasnext freetalknntpgroup freetalknntpgroup printtextresponseline getname lastmessage firstmessage postingstatus endtextresponse handle the list newsgroups command private void list group descriptions string pattern fixme add filtering print status line 215 information follows for iterator board i m message manager board iterator i has next board board i next string group name freetalknntp group board to group name board get name print text response line group name board get description null end text response listgroupdescriptions printstatusline mmessagemanager boarditerator hasnext groupname freetalknntpgroup boardtogroupname getname printtextresponseline groupname getdescription endtextresponse handle the newgroups command private void list new groups since string datestr string format boolean gmt simple date format df new simple date format format if gmt df set time zone time zone get time zone utc date date df parse datestr new parse position 0 for iterator board i m message manager board iterator sorted by date date i has next board board i next freetalknntp group group new freetalknntp group board print text response line board get name group last message group first message group posting status end text response listnewgroupssince simpledateformat simpledateformat settimezone timezone gettimezone parseposition mmessagemanager boarditeratorsortedbydate hasnext freetalknntpgroup freetalknntpgroup printtextresponseline getname lastmessage firstmessage postingstatus endtextresponse handle the hdr xhdr command private void print article header string header string article desc iterator freetalknntp article iter get article range iterator article desc false if iter null print status line 224 header contents follow while iter has next freetalknntp article article iter next if header equals ignore case bytes print text response line article get message num article get byte count else if header equals ignore case lines print text response line article get message num article get body line count else print text response line article get message num article get header by name header end text response printarticleheader articledesc freetalknntparticle getarticlerangeiterator articledesc printstatusline hasnext freetalknntparticle equalsignorecase printtextresponseline getmessagenum getbytecount equalsignorecase printtextresponseline getmessagenum getbodylinecount printtextresponseline getmessagenum getheaderbyname endtextresponse handle the over xover command private void print article overview string article desc iterator freetalknntp article iter get article range iterator article desc false if iter null print status line 224 overview follows while iter has next freetalknntp article article iter next print text response line article get message num t article get header freetalknntp article header subject t article get header freetalknntp article header from t article get header freetalknntp article header date t article get header freetalknntp article header message id t article get header freetalknntp article header references t article get byte count t article get body line count end text response printarticleoverview articledesc freetalknntparticle getarticlerangeiterator articledesc printstatusline hasnext freetalknntparticle printtextresponseline getmessagenum getheader freetalknntparticle getheader freetalknntparticle getheader freetalknntparticle getheader freetalknntparticle message_id getheader freetalknntparticle getbytecount getbodylinecount endtextresponse handle the list headers command private void print header list print status line 215 header list follows we allow querying any header as well as byte and line counts print text response line print text response line bytes print text response line lines end text response printheaderlist printstatusline printtextresponseline printtextresponseline printtextresponseline endtextresponse handle the list overview fmt command private void print overview format print status line 215 overview format follows print text response line subject print text response line from print text response line date print text response line message id print text response line references print text response line bytes print text response line lines end text response printoverviewformat printstatusline printtextresponseline printtextresponseline printtextresponseline printtextresponseline printtextresponseline printtextresponseline printtextresponseline endtextresponse handle the date command private void print date date date new date synchronized server date format server date format set time zone utc time zone print text response line 111 server date format format date printdate serverdateformat serverdateformat settimezone utctimezone printtextresponseline serverdateformat handle a command from the client if the command requires a text data section this function returns true and finish command should be called after the text has been received private synchronized boolean begin command string line throws io exception string tokens line split t r n if tokens length 0 return false string command tokens 0 if command equals ignore case article if tokens length 2 select article tokens 1 true true else if tokens length 1 select article null true true else print status line 501 syntax error else if command equals ignore case body if tokens length 2 select article tokens 1 false true else if tokens length 1 select article null false true else print status line 501 syntax error else if command equals ignore case date print date else if command equals ignore case group if tokens length 2 select group tokens 1 else print status line 501 syntax error else if command equals ignore case hdr command equals ignore case xhdr if tokens length 3 print article header tokens 1 tokens 2 else if tokens length 2 print article header tokens 1 null else print status line 501 syntax error else if command equals ignore case head if tokens length 2 select article tokens 1 true false else if tokens length 1 select article null true false else print status line 501 syntax error else if command equals ignore case list if tokens length 1 tokens 1 equals ignore case active if tokens length 2 list active groups tokens 2 else list active groups null else if tokens 1 equals ignore case newsgroups if tokens length 2 list group descriptions tokens 2 else list group descriptions null else if tokens 1 equals ignore case headers print header list else if tokens 1 equals ignore case overview fmt print overview format else print status line 501 syntax error else if command equals ignore case listgroup if tokens length 1 select group with list null 1 else if tokens length 2 select group with list tokens 1 1 else if tokens length 3 select group with list tokens 1 tokens 2 else print status line 501 syntax error else if command equals ignore case newgroups boolean gmt false if tokens length 4 gmt tokens 3 equals ignore case gmt tokens length 3 string date tokens 1 tokens 2 if date length 15 list new groups since date yyyym mdd h hmmss gmt else if date length 13 list new groups since date yym mdd h hmmss gmt else print status line 501 syntax error else print status line 501 syntax error else if command equals ignore case mode if tokens length 2 tokens 1 equals ignore case reader print status line 200 reader mode acknowledged posting allowed else print status line 501 syntax error we accept xover for over because a lot of broken newsreaders expect us to else if command equals ignore case over command equals ignore case xover if tokens length 2 print article overview tokens 1 else if tokens length 1 print article overview null else print status line 501 syntax error else if command equals ignore case post fixme this happens when trying to send a reply to a message with thunderbird print status line 340 please send article to be posted return true else if command equals ignore case quit print status line 205 have a nice day socket close else if command equals ignore case stat if tokens length 2 select article tokens 1 false false else if tokens length 1 select article null false false else print status line 501 syntax error fixme implement the login command people with a newsreader which always tries to login will receive command not recognized and therefore cannot use nntp else print status line 500 command not recognized return false finishcommand begincommand ioexception equalsignorecase selectarticle selectarticle printstatusline equalsignorecase selectarticle selectarticle printstatusline equalsignorecase printdate equalsignorecase selectgroup printstatusline equalsignorecase equalsignorecase printarticleheader printarticleheader printstatusline equalsignorecase selectarticle selectarticle printstatusline equalsignorecase equalsignorecase listactivegroups listactivegroups equalsignorecase listgroupdescriptions listgroupdescriptions equalsignorecase printheaderlist equalsignorecase printoverviewformat printstatusline equalsignorecase selectgroupwithlist selectgroupwithlist selectgroupwithlist printstatusline equalsignorecase equalsignorecase listnewgroupssince yyyymmdd hhmmss listnewgroupssince yymmdd hhmmss printstatusline printstatusline equalsignorecase equalsignorecase printstatusline printstatusline equalsignorecase equalsignorecase printarticleoverview printarticleoverview printstatusline equalsignorecase printstatusline equalsignorecase printstatusline equalsignorecase selectarticle selectarticle printstatusline printstatusline find the user s own identity corresponding to the given mail address use domain part to disambiguate if we have multiple identities with the same nickname private ft own identity get author identity string name string domain ft own identity best match null boolean match name false match domain false multiple false logger debug this received message from name domain iterator ft own identity i m identity manager own identity iterator while i has next ft own identity identity i next if identity get nickname equals name string uid identity getuid if uid starts with domain domain starts with uid if match domain multiple true best match identity match name match domain true else if match domain if match name multiple true best match identity match name true if multiple print status line 441 multiple identities matching sender return null else if best match null print status line 441 unknown sender name domain return null else return best match ownidentity ftownidentity getauthoridentity ftownidentity bestmatch matchname matchdomain ftownidentity midentitymanager ownidentityiterator hasnext ftownidentity getnickname startswith startswith matchdomain bestmatch matchname matchdomain matchdomain matchname bestmatch matchname printstatusline bestmatch printstatusline bestmatch handle a command that includes a text data block private synchronized void finish command string line byte buffer text article parser parser new article parser if parser parse message text print status line 441 unable to parse message else ft own identity my identity get author identity parser get author name parser get author domain if my identity null return synchronized m message manager try message parent message try parent message m message manager get parser get parentid catch no such field exception e parent message null catch no such message exception e parent message null hash set string board set new hash set string parser get boards own message message m message manager post message parent message board set parser get reply to board my identity parser get title null parser get text null print status line 240 message posted id is message getid catch exception e logger normal this error posting message e print status line 441 posting failed finishcommand bytebuffer articleparser articleparser parsemessage printstatusline ftownidentity myidentity getauthoridentity getauthorname getauthordomain myidentity mmessagemanager parentmessage parentmessage mmessagemanager getparentid nosuchfieldexception parentmessage nosuchmessageexception parentmessage hashset boardset hashset getboards ownmessage mmessagemanager postmessage parentmessage boardset getreplytoboard myidentity gettitle gettext printstatusline printstatusline read an input line terminated by the ascii lf character as a byte sequence private byte buffer read line bytes input stream is throws io exception byte buffer buf byte buffer allocate 100 int b do b is read if b 0 if buf has remaining resize input buffer byte buffer newbuf byte buffer allocate buf capacity 2 buf flip newbuf put buf buf newbuf buf put byte b while b 0 b n buf flip return buf bytebuffer readlinebytes inputstream ioexception bytebuffer bytebuffer hasremaining bytebuffer bytebuffer read a complete text block terminated by a on a line by itself private byte buffer read text data bytes input stream is throws io exception byte buffer buf byte buffer allocate 1024 byte buffer line while true line read line bytes is if line has remaining return null text block not completed consider message aborted if line get 0 if line remaining 2 line get 1 n line remaining 3 line get 1 r line get 2 n buf flip return buf else initial dot must always be skipped even if the second character isn t a dot line get append line to the end of the buffer if line remaining buf remaining byte buffer newbuf byte buffer allocate buf position line remaining 2 buf flip newbuf put buf buf newbuf buf put line bytebuffer readtextdatabytes inputstream ioexception bytebuffer bytebuffer bytebuffer readlinebytes hasremaining bytebuffer bytebuffer main command loop public void run try input stream is socket get input stream output stream os socket get output stream byte buffer bytes string line charset utf8 charset for name utf 8 out new print stream os false utf 8 print status line 200 welcome to freetalk while socket is closed bytes read line bytes is line utf8 decode bytes to string if begin command line bytes read text data bytes is finish command line bytes catch io exception e logger error this error in nntp handler e get message inputstream getinputstream outputstream getoutputstream bytebuffer forname printstream printstatusline isclosed readlinebytes tostring begincommand readtextdatabytes finishcommand ioexception getmessage logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this logdebug logger should log logger debug this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog shouldlog the runnable in charge of rekeying on a regular basis private final runnable transient key rekeyer new runnable public void run maybe reset transient key transientkeyrekeyer mayberesettransientkey public fnp packet mangler node node node crypto crypt packet socket handler sock this node node this crypto crypt this usm node usm this sock sock fnp timing source new entropy source my packet data source new entropy source authenticator cache new hash map byte array wrapper byte full headers length minimum headers length minimum sock get headers length full headers length one message headers length one message sock get headers length fnppacketmangler nodecrypto packetsockethandler fnptimingsource entropysource mypacketdatasource entropysource authenticatorcache hashmap bytearraywrapper fullheaderslengthminimum headers_length_minimum getheaderslength fullheaderslengthonemessage headers_length_one_message getheaderslength start up the fnp packet mangler by the time this is called all objects will have been constructed but not all will have been started yet public void start run it directly so that the transient key is set maybe reset transient key fill the dh fifo on thread for int i 0 i dh context buffer size i filljfkdhfifo fnppacketmangler mayberesettransientkey dh_context_buffer_size _filljfkdhfifo decrypt and authenticate packet then feed it to usm check filters packets generated should have a peer node on them note that the buffer can be modified by this method public void process byte buf int offset int length peer peer long now node random accept timer entropy fnp timing source 0 25 if logminor logger minor this packet length length from peer look up the peer if we know it check the packet with that key otherwise try all of them on the theory that nodes occasionally change their ip addresses peer node opn node peers get by peer peer if opn null opn get outgoing mangler this logger error this apparently contacted by opn on this opn null peer node pn if opn null if logminor logger minor this trying exact match if length headers length minimum if logminor logger minor this trying current key tracker for exact match if try process buf offset length opn get current key tracker now return try with old key if logminor logger minor this trying previous key tracker for exact match if try process buf offset length opn get previous key tracker now return try with unverified key if logminor logger minor this trying unverified key tracker for exact match if try process buf offset length opn get unverified key tracker now return if length node symmetric key length iv hash length 2 node is stopping might be an auth packet if try process auth buf offset length opn peer false now return might be a reply to an anon auth packet if try process auth anon reply buf offset length opn peer now return peer node peers crypto get peer nodes existing connection changed ip address if length hash length random bytes length 4 6 for int i 0 i peers length i pn peers i if pn opn continue if logminor logger minor this trying current key tracker for loop if try process buf offset length pn get current key tracker now ip address change pn changedip peer return if logminor logger minor this trying previous key tracker for loop if try process buf offset length pn get previous key tracker now ip address change pn changedip peer return if logminor logger minor this trying unverified key tracker for loop if try process buf offset length pn get unverified key tracker now ip address change pn changedip peer return if node is stopping return disconnected node connecting on a new ip address if length node symmetric key length iv hash length 2 for int i 0 i peers length i pn peers i if pn opn continue if try process auth buf offset length pn peer false now return peer node anon peers crypto get anon setup peer nodes if length node symmetric key length iv hash length 3 for int i 0 i anon peers length i pn anon peers i if pn opn continue if try process auth anon reply buf offset length pn peer now return if try process buf offset length pn get current key tracker now pn changedip peer return if try process buf offset length pn get previous key tracker now pn changedip peer return if try process buf offset length pn get unverified key tracker now pn changedip peer return opennet manager opennet node get opennet if opennet null try old opennet connections if opennet want peer null false true true we want a peer try old connections peer node old peers opennet get old peers for int i 0 i old peers length i if try process auth buf offset length old peers i peer true now return if node want anon auth if try process auth anon buf offset length peer return if log unmatchable error system err println unmatchable packet from peer on node get darknet port number logger normal this unmatchable packet from peer checkfilters peernode accepttimerentropy fnptimingsource peernode getbypeer getoutgoingmangler peernode headers_length_minimum tryprocess getcurrentkeytracker tryprocess getpreviouskeytracker tryprocess getunverifiedkeytracker symmetric_key_length hash_length isstopping tryprocessauth tryprocessauthanonreply peernode getpeernodes hash_length random_bytes_length tryprocess getcurrentkeytracker tryprocess getpreviouskeytracker tryprocess getunverifiedkeytracker isstopping symmetric_key_length hash_length tryprocessauth peernode anonpeers getanonsetuppeernodes symmetric_key_length hash_length anonpeers anonpeers tryprocessauthanonreply tryprocess getcurrentkeytracker tryprocess getpreviouskeytracker tryprocess getunverifiedkeytracker opennetmanager getopennet wantpeer peernode oldpeers getoldpeers oldpeers tryprocessauth oldpeers wantanonauth tryprocessauthanon log_unmatchable_error getdarknetportnumber is this a negotiation packet if so process it param buf the buffer to read bytes from param offset the offset at which to start reading param length the number of bytes to read param pn the peer node we think is responsible param peer the peer to send a reply to param now the time at which the packet was received return true if we handled a negotiation packet false otherwise private boolean try process auth byte buf int offset int length peer node pn peer peer boolean old opennet peer long now block cipher auth key pn incoming setup cipher if logminor logger minor this decrypt key hex util bytes to hex pn incoming setup key for peer pn in try process auth does the packet match iv e h data data pcfb mode pcfb pcfb mode create auth key int iv length pcfb lengthiv int digest length hash length if length digest length iv length 4 if logminor if buf length length logger debug this the packet is smaller than the decrypted size it s probably the wrong tracker buf length length else logger minor this too short length should be at least digest length iv length 4 return false iv at the beginning pcfb reset buf offset then the hash then the data data starts at iv length digest length decrypt the hash byte hash new byte digest length system arraycopy buf offset iv length hash 0 digest length pcfb block decipher hash 0 hash length int data start iv length digest length offset 2 int byte1 pcfb decipher buf data start 2 0xff int byte2 pcfb decipher buf data start 1 0xff int data length byte1 8 byte2 if logminor logger minor this data length data length 1 byte1 2 byte2 if data length length iv length hash length 2 if logminor logger minor this invalid data length data length length iv length hash length 2 in try process auth return false decrypt the data message digest md sha256 get message digest byte payload new byte data length system arraycopy buf data start payload 0 data length pcfb block decipher payload 0 payload length md update payload byte real hash md digest sha256 return message digest md md null if arrays equals real hash hash got one process decrypted auth payload pn peer old opennet peer pn report incoming packet buf offset length now return true else if logminor logger minor this incorrect hash in try process auth for peer length data length nreal hash hex util bytes to hex real hash n bad hash hex util bytes to hex hash return false peernode tryprocessauth peernode oldopennetpeer blockcipher authkey incomingsetupcipher hexutil bytestohex incomingsetupkey tryprocessauth pcfbmode pcfbmode authkey ivlength digestlength hash_length digestlength ivlength digestlength ivlength ivlength digestlength digestlength ivlength digestlength blockdecipher datastart ivlength digestlength datastart datastart datalength datalength datalength ivlength datalength ivlength tryprocessauth messagedigest getmessagedigest datalength datastart datalength blockdecipher realhash returnmessagedigest realhash processdecryptedauth oldopennetpeer reportincomingpacket tryprocessauth datalength hexutil bytestohex realhash hexutil bytestohex might be an anonymous initiator negotiation packet i e we are the responder anonymous initiator is used for seednode connections and will in future be used for other things for example one side only invites password based invites etc param buf the buffer to read bytes from param offset the offset at which to start reading param length the number of bytes to read param peer the peer to send a reply to param now the time at which the packet was received return true if we handled a negotiation packet false otherwise private boolean try process auth anon byte buf int offset int length peer peer block cipher auth key crypto get anon setup cipher does the packet match iv e h data data pcfb mode pcfb pcfb mode create auth key int iv length pcfb lengthiv message digest md sha256 get message digest int digest length hash length if length digest length iv length 5 if logminor logger minor this too short length should be at least digest length iv length 5 sha256 return message digest md return false iv at the beginning pcfb reset buf offset then the hash then the data data starts at iv length digest length decrypt the hash byte hash new byte digest length system arraycopy buf offset iv length hash 0 digest length pcfb block decipher hash 0 hash length int data start iv length digest length offset 2 int byte1 pcfb decipher buf data start 2 0xff int byte2 pcfb decipher buf data start 1 0xff int data length byte1 8 byte2 if logminor logger minor this data length data length 1 byte1 2 byte2 if data length length iv length hash length 2 if logminor logger minor this invalid data length data length length iv length hash length 2 in try process auth anon sha256 return message digest md return false decrypt the data byte payload new byte data length system arraycopy buf data start payload 0 data length pcfb block decipher payload 0 payload length md update payload byte real hash md digest sha256 return message digest md md null if arrays equals real hash hash got one process decrypted auth anon payload peer return true else if logminor logger minor this incorrect hash in try process auth anon for peer length data length nreal hash hex util bytes to hex real hash n bad hash hex util bytes to hex hash return false tryprocessauthanon blockcipher authkey getanonsetupcipher pcfbmode pcfbmode authkey ivlength messagedigest getmessagedigest digestlength hash_length digestlength ivlength digestlength ivlength returnmessagedigest ivlength digestlength digestlength ivlength digestlength blockdecipher datastart ivlength digestlength datastart datastart datalength datalength datalength ivlength datalength ivlength tryprocessauthanon returnmessagedigest datalength datastart datalength blockdecipher realhash returnmessagedigest realhash processdecryptedauthanon tryprocessauthanon datalength hexutil bytestohex realhash hexutil bytestohex might be a reply to an anonymous initiator negotiation packet i e we are the initiator anonymous initiator is used for seednode connections and will in future be used for other things for example one side only invites password based invites etc param buf the buffer to read bytes from param offset the offset at which to start reading param length the number of bytes to read param pn the peer node we think is responsible param peer the peer to send a reply to param now the time at which the packet was received return true if we handled a negotiation packet false otherwise private boolean try process auth anon reply byte buf int offset int length peer node pn peer peer long now block cipher auth key pn anonymous initiator setup cipher does the packet match iv e h data data pcfb mode pcfb pcfb mode create auth key int iv length pcfb lengthiv int digest length hash length if length digest length iv length 5 if logminor logger minor this too short length should be at least digest length iv length 5 return false iv at the beginning pcfb reset buf offset then the hash then the data data starts at iv length digest length decrypt the hash byte hash new byte digest length system arraycopy buf offset iv length hash 0 digest length pcfb block decipher hash 0 hash length int data start iv length digest length offset 2 int byte1 pcfb decipher buf data start 2 0xff int byte2 pcfb decipher buf data start 1 0xff int data length byte1 8 byte2 if logminor logger minor this data length data length 1 byte1 2 byte2 if data length length iv length hash length 2 if logminor logger minor this invalid data length data length length iv length hash length 2 in try process auth return false decrypt the data byte payload new byte data length system arraycopy buf data start payload 0 data length pcfb block decipher payload 0 payload length byte real hash sha256 digest payload if arrays equals real hash hash got one process decrypted auth anon reply payload peer pn return true else if logminor logger minor this incorrect hash in try process auth for peer length data length nreal hash hex util bytes to hex real hash n bad hash hex util bytes to hex hash return false peernode tryprocessauthanonreply peernode blockcipher authkey anonymousinitiatorsetupcipher pcfbmode pcfbmode authkey ivlength digestlength hash_length digestlength ivlength digestlength ivlength ivlength digestlength digestlength ivlength digestlength blockdecipher datastart ivlength digestlength datastart datastart datalength datalength datalength ivlength datalength ivlength tryprocessauth datalength datastart datalength blockdecipher realhash realhash processdecryptedauthanonreply tryprocessauth datalength hexutil bytestohex realhash hexutil bytestohex process an anonymous initiator connection setup packet for a normal setup see process decrypted auth we know the node that is trying to contact us but in this case we don t know the node yet and we are doing a special purpose connection setup at the moment the only type supported is for a new node connecting to a seednode in order to announce in future nodes may support other anonymous initiator connection types such as when a node which is certain of its connectivity issues one time invites which allow a new node to connect to it param payload the decrypted payload of the packet param reply to the address the packet came in from private void process decrypted auth anon byte payload peer reply to if logminor logger minor this processing decrypted auth packet from reply to length payload length protocol version should be 1 int version payload 0 negotiation type common to anonymous initiator auth and normal setup 2 jfk 3 jfk reuse packet tracker other types might indicate other dh variants or even non dh based algorithms such as password based key setup int neg type payload 1 packet phase int packet type payload 2 setup type this is specific to anonymous initiator setup and specifies the purpose of the connection at the moment it is setup opennet seednode to indicate we are connecting to a seednode which doesn t know us invites might require a different setup type int setup type payload 3 if logminor logger minor this received anonymous auth packet phase packet type v version nt neg type setup type setup type from reply to if version 1 logger error this decrypted auth packet but invalid version version return if neg type 2 neg type 4 logger error this unknown neg type neg type return known setup types if setup type setup opennet seednode logger error this unknown setup type neg type return we are the responder therefore we can only get packets of phase 1 and 3 here if packet type 0 phase 1 processjfk message1 payload 4 null reply to true setup type neg type else if packet type 2 phase 3 processjfk message3 payload 4 null reply to false true setup type neg type else logger error this invalid phase packet type for anonymous initiator we are the responder from reply to processdecryptedauth replyto processdecryptedauthanon replyto replyto packettracker negtype packettype setup_opennet_seednode setuptype setuptype packettype negtype setuptype replyto negtype negtype negtype setuptype setup_opennet_seednode negtype packettype processjfkmessage1 replyto setuptype negtype packettype processjfkmessage3 replyto setuptype negtype packettype replyto private void process decrypted auth anon reply byte payload peer reply to peer node pn if logminor logger minor this processing decrypted auth packet from reply to for pn length payload length protocol version should be 1 int version payload 0 negotiation type 2 jfk 3 jfk reuse packet tracker other types might indicate other dh variants or even non dh based algorithms such as password based key setup int neg type payload 1 packet phase int packet type payload 2 setup type see above int setup type payload 3 if logminor logger minor this received anonymous auth packet phase packet type v version nt neg type setup type setup type from reply to if version 1 logger error this decrypted auth packet but invalid version version return if neg type 2 neg type 4 logger error this unknown neg type neg type return known setup types if setup type setup opennet seednode logger error this unknown setup type neg type return we are the initiator therefore we can only get packets of phase 2 and 4 here if packet type 1 phase 2 processjfk message2 payload 4 pn reply to true setup type neg type else if packet type 3 phase 4 processjfk message4 payload 4 pn reply to false true setup type neg type else logger error this invalid phase packet type for anonymous initiator we are the initiator from reply to processdecryptedauthanonreply replyto peernode replyto packettracker negtype packettype setuptype packettype negtype setuptype replyto negtype negtype negtype setuptype setup_opennet_seednode negtype packettype processjfkmessage2 replyto setuptype negtype packettype processjfkmessage4 replyto setuptype negtype packettype replyto process a decrypted authenticated auth packet param payload the packet payload after it has been decrypted private void process decrypted auth byte payload peer node pn peer reply to boolean old opennet peer if logminor logger minor this processing decrypted auth packet from reply to for pn if pn is disabled if logminor logger minor this won t connect to a disabled peer pn return we don t connect to disabled peers int neg type payload 1 int packet type payload 2 int version payload 0 if logminor long now system current time millis long last pn last sent packet time string delta never if last 0 delta time util format time now last 2 true ago logger minor this received auth packet for pn get peer phase packet type v version nt neg type last packet sent delta from reply to format 1 byte version number 1 1 byte negotiation type 0 simple dh will not be supported when implement jf ki 1 sts 1 byte packet type 0 3 if version 1 logger error this decrypted auth packet but invalid version version return if neg type 0 logger error this old ephemeral diffie hellman neg type 0 not supported return else if neg type 1 logger error this old station to station neg type 1 not supported return else if neg type 2 neg type 4 neg type 3 was buggy neg type 4 negotiate whether to use a new packet tracker when rekeying we implement just fast keying key management protocol with active identity protection for the initiator and no identity protection for the responder m1 this is a straightforward diffie hellman exponential the initiator nonce serves two purposes it allows the initiator to use the same exponentials during different sessions while ensuring that the resulting session key will be different can be used to differentiate between parallel sessions m2 responder replies with a signed copy of his own exponential a random nonce and an authenticator which provides sufficient defense against forgeries replays we slightly deviate jfk here we do not send any public key information as specified in the jfk docs m3 initiator echoes the data sent by the responder including the authenticator this helps the responder verify the authenticity of the returned data m4 encrypted message of the signature on both nonces both exponentials using the same keys as in the previous message if packet type 0 packet type 3 logger error this unknown packet type packet type from reply to from pn return else if packet type 0 initiator this is a straightforward diffie hellman exponential the initiator nonce serves two purposes it allows the initiator to use the same exponentials during different sessions while ensuring that the resulting session key will be different can be used to differentiate between parallel sessions processjfk message1 payload 3 pn reply to false 1 neg type else if packet type 1 responder replies with a signed copy of his own exponential a random nonce and an authenticator calculated from a transient hash key private to the responder processjfk message2 payload 3 pn reply to false 1 neg type else if packet type 2 initiator echoes the data sent by the responder these messages are cached by the responder receiving a duplicate message simply causes the responder to re transmit the corresponding message4 processjfk message3 payload 3 pn reply to old opennet peer false 1 neg type else if packet type 3 encrypted message of the signature on both nonces both exponentials using the same keys as in the previous message the signature is non message recovering processjfk message4 payload 3 pn reply to old opennet peer false 1 neg type else logger error this decrypted auth packet but unknown negotiation type neg type from reply to possibly from pn return processdecryptedauth peernode replyto oldopennetpeer replyto isdisabled negtype packettype currenttimemillis lastsentpackettime timeutil formattime getpeer packettype negtype replyto jfki negtype negtype negtype stationtostation negtype negtype negtype negtype negtype packettracker diffiehellman packettype packettype packettype packettype replyto packettype diffiehellman processjfkmessage1 replyto negtype packettype processjfkmessage2 replyto negtype packettype processjfkmessage3 replyto oldopennetpeer negtype packettype processjfkmessage4 replyto oldopennetpeer negtype negtype replyto private void processjfk message1 byte payload int offset peer node pn peer reply to boolean unknown initiator int setup type int neg type long t1 system current time millis if logminor logger minor this got a jfk 1 message processing it pn fixme follow the spec and send i dr if payload length nonce size diffie hellman modulus length in bytes 3 unknown initiator node crypto identity length 0 logger error this packet too short from pn payload length after decryption in jfk 1 should be nonce size diffie hellman modulus length in bytes return get ni byte nonce initiator new byte nonce size system arraycopy payload offset nonce initiator 0 nonce size offset nonce size get g i int modulus length diffie hellman modulus length in bytes byte his exponential new byte modulus length system arraycopy payload offset his exponential 0 modulus length if unknown initiator check i dr offset diffie hellman modulus length in bytes byte expected identity hash new byte node crypto identity length system arraycopy payload offset expected identity hash 0 expected identity hash length if arrays equals expected identity hash crypto identity hash logger error this invalid unknown initiator jfk 1 i dr is hex util bytes to hex expected identity hash should be hex util bytes to hex crypto identity hash return native big integer hisexponential new native big integer 1 his exponential if diffie hellman checkdh exponential validity this get class hisexponential sendjfk message2 nonce initiator his exponential pn reply to unknown initiator setup type neg type else logger error this we can t accept the exponential pn sent us redflag it can t happen unless against an active attacker long t2 system current time millis if t2 t1 500 logger error this message1 timeout error processing packet for pn processjfkmessage1 peernode replyto unknowninitiator setuptype negtype currenttimemillis idr nonce_size diffiehellman moduluslengthinbytes unknowninitiator nodecrypto identity_length nonce_size diffiehellman moduluslengthinbytes nonceinitiator nonce_size nonceinitiator nonce_size nonce_size moduluslength diffiehellman moduluslengthinbytes hisexponential moduluslength hisexponential moduluslength unknowninitiator idr diffiehellman moduluslengthinbytes expectedidentityhash nodecrypto identity_length expectedidentityhash expectedidentityhash expectedidentityhash identityhash idr hexutil bytestohex expectedidentityhash hexutil bytestohex identityhash nativebiginteger _hisexponential nativebiginteger hisexponential diffiehellman checkdhexponentialvalidity getclass _hisexponential sendjfkmessage2 nonceinitiator hisexponential replyto unknowninitiator setuptype negtype currenttimemillis private void sendjfk message1 peer node pn peer reply to boolean unknown initiator int setup type int neg type if logminor logger minor this sending a jfk 1 message to reply to for pn get peer final long now system current time millis diffie hellman light context ctx diffie hellman light context pn get key agreement scheme context if ctx null pn jfk context lifetime dh generation interval dh context buffer size now pn jfk context lifetime now pn set key agreement scheme context ctx get light diffie hellman context int offset 0 byte my exponential strip big integer to network format ctx my exponential byte nonce new byte nonce size node random next bytes nonce synchronized pn pn jfk nonces sent put reply to drop host name nonce int modulus length diffie hellman modulus length in bytes byte message1 new byte nonce size modulus length unknown initiator node crypto identity length 0 system arraycopy nonce 0 message1 offset nonce size offset nonce size system arraycopy my exponential 0 message1 offset modulus length if unknown initiator offset modulus length system arraycopy pn identity hash 0 message1 offset pn identity hash length send anon auth packet 1 neg type 0 setup type message1 pn reply to pn anonymous initiator setup cipher else send auth packet 1 neg type 0 message1 pn reply to long t2 system current time millis if t2 now 500 logger error this message1 timeout error sending packet for pn get peer sendjfkmessage1 peernode replyto unknowninitiator setuptype negtype replyto getpeer currenttimemillis diffiehellmanlightcontext diffiehellmanlightcontext getkeyagreementschemecontext jfkcontextlifetime dh_generation_interval dh_context_buffer_size jfkcontextlifetime setkeyagreementschemecontext getlightdiffiehellmancontext myexponential stripbigintegertonetworkformat myexponential nonce_size nextbytes jfknoncessent replyto drophostname moduluslength diffiehellman moduluslengthinbytes nonce_size moduluslength unknowninitiator nodecrypto identity_length nonce_size nonce_size myexponential moduluslength unknowninitiator moduluslength identityhash identityhash sendanonauthpacket negtype setuptype replyto anonymousinitiatorsetupcipher sendauthpacket negtype replyto currenttimemillis getpeer private void sendjfk message2 byte nonce initator byte his exponential peer node pn peer reply to boolean unknown initiator int setup type int neg type if logminor logger minor this sending a jfk 2 message to pn diffie hellman light context ctx get light diffie hellman context g r byte my exponential strip big integer to network format ctx my exponential nr byte my nonce new byte nonce size node random next bytes my nonce byte r ctx signature getr bytes node signature parameter length byte s ctx signature gets bytes node signature parameter length byte authenticator hmac mac withsha256 get transient key assemblejfk authenticator my exponential his exponential my nonce nonce initator reply to get address get address hash length if logminor logger minor this we are using the following hmac hex util bytes to hex authenticator byte message2 new byte nonce size 2 diffie hellman modulus length in bytes node signature parameter length 2 hash length int offset 0 system arraycopy nonce initator 0 message2 offset nonce size offset nonce size system arraycopy my nonce 0 message2 offset nonce size offset nonce size system arraycopy my exponential 0 message2 offset diffie hellman modulus length in bytes offset diffie hellman modulus length in bytes system arraycopy r 0 message2 offset node signature parameter length offset node signature parameter length system arraycopy s 0 message2 offset node signature parameter length offset node signature parameter length system arraycopy authenticator 0 message2 offset hash length if unknown initiator send anon auth packet 1 neg type 1 setup type message2 pn reply to crypto anon setup cipher else send auth packet 1 neg type 1 message2 pn reply to sendjfkmessage2 nonceinitator hisexponential peernode replyto unknowninitiator setuptype negtype diffiehellmanlightcontext getlightdiffiehellmancontext myexponential stripbigintegertonetworkformat myexponential mynonce nonce_size nextbytes mynonce getrbytes signature_parameter_length getsbytes signature_parameter_length macwithsha256 gettransientkey assemblejfkauthenticator myexponential hisexponential mynonce nonceinitator replyto getaddress getaddress hash_length hexutil bytestohex nonce_size diffiehellman moduluslengthinbytes signature_parameter_length hash_length nonceinitator nonce_size nonce_size mynonce nonce_size nonce_size myexponential diffiehellman moduluslengthinbytes diffiehellman moduluslengthinbytes signature_parameter_length signature_parameter_length signature_parameter_length signature_parameter_length hash_length unknowninitiator sendanonauthpacket negtype setuptype replyto anonsetupcipher sendauthpacket negtype replyto private byte assemblejfk authenticator byte gr byte gi byte nr byte ni byte address byte auth data new byte gr length gi length nr length ni length address length int offset 0 system arraycopy gr 0 auth data offset gr length offset gr length system arraycopy gi 0 auth data offset gi length offset gi length system arraycopy nr 0 auth data offset nr length offset nr length system arraycopy ni 0 auth data offset ni length offset ni length system arraycopy address 0 auth data offset address length return auth data assemblejfkauthenticator authdata authdata authdata authdata authdata authdata authdata private void processjfk message2 byte payload int input offset peer node pn peer reply to boolean unknown initiator int setup type int neg type long t1 system current time millis if logminor logger minor this got a jfk 2 message processing it pn get peer fixme follow the spec and send i dr int expected length nonce size 2 diffie hellman modulus length in bytes hash length 2 if payload length expected length 3 logger error this packet too short from pn get peer payload length after decryption in jfk 2 should be expected length 3 return byte nonce initiator new byte nonce size system arraycopy payload input offset nonce initiator 0 nonce size input offset nonce size byte nonce responder new byte nonce size system arraycopy payload input offset nonce responder 0 nonce size input offset nonce size byte his exponential new byte diffie hellman modulus length in bytes system arraycopy payload input offset his exponential 0 diffie hellman modulus length in bytes input offset diffie hellman modulus length in bytes native big integer hisexponential new native big integer 1 his exponential byte r new byte node signature parameter length system arraycopy payload input offset r 0 node signature parameter length input offset node signature parameter length byte s new byte node signature parameter length system arraycopy payload input offset s 0 node signature parameter length input offset node signature parameter length byte authenticator new byte hash length system arraycopy payload input offset authenticator 0 hash length input offset hash length check try to find the authenticator in the cache if authenticator is already present indicates duplicate replayed message2 now simply transmit the corresponding message3 object message3 null synchronized authenticator cache message3 authenticator cache get new byte array wrapper authenticator if message3 null logger normal this we replayed a message from the cache shouldn t happen often pn get peer send auth packet 1 neg type 3 byte message3 pn reply to return sanity check byte my ni synchronized pn my ni pn jfk nonces sent get reply to drop host name we don t except such a message if my ni null if should log error in handshake t1 logger normal this we received an unexpected jfk 2 message from pn get peer time since added pn time since added or restarted time last receive pn last received packet time return else if arrays equals my ni nonce initiator if should log error in handshake t1 logger normal this ignoring old jfk 2 different nonce to the one we sent either a timing artefact or an attempt to change the nonce return if diffie hellman checkdh exponential validity this get class hisexponential logger error this we can t accept the exponential pn get peer sent us redflag it can t happen unless against an active attacker return verify the dsa signature dsa signature remote signature new dsa signature new native big integer 1 r new native big integer 1 s at that point we don t know if it s him let s check it out byte locally expected exponentials assembledh params hisexponential pn peer crypto group if dsa verify pn peer pub key remote signature new native big integer 1 sha256 digest locally expected exponentials false logger error this the signature verification has failed in jfk 2 pn get peer return at this point we know it s from the peer so we can report a packet received pn received packet true false sendjfk message3 1 neg type 3 nonce initiator nonce responder his exponential authenticator pn reply to unknown initiator setup type long t2 system current time millis if t2 t1 500 logger error this message2 timeout error processing packet for pn get peer processjfkmessage2 inputoffset peernode replyto unknowninitiator setuptype negtype currenttimemillis getpeer idr expectedlength nonce_size diffiehellman moduluslengthinbytes hash_length expectedlength getpeer expectedlength nonceinitiator nonce_size inputoffset nonceinitiator nonce_size inputoffset nonce_size nonceresponder nonce_size inputoffset nonceresponder nonce_size inputoffset nonce_size hisexponential diffiehellman moduluslengthinbytes inputoffset hisexponential diffiehellman moduluslengthinbytes inputoffset diffiehellman moduluslengthinbytes nativebiginteger _hisexponential nativebiginteger hisexponential signature_parameter_length inputoffset signature_parameter_length inputoffset signature_parameter_length signature_parameter_length inputoffset signature_parameter_length inputoffset signature_parameter_length hash_length inputoffset hash_length inputoffset hash_length authenticatorcache authenticatorcache bytearraywrapper getpeer sendauthpacket negtype replyto myni myni jfknoncessent replyto drophostname myni shouldlogerrorinhandshake getpeer timesinceaddedorrestarted lastreceivedpackettime myni nonceinitiator shouldlogerrorinhandshake diffiehellman checkdhexponentialvalidity getclass _hisexponential getpeer dsasignature remotesignature dsasignature nativebiginteger nativebiginteger locallyexpectedexponentials assembledhparams _hisexponential peercryptogroup peerpubkey remotesignature nativebiginteger locallyexpectedexponentials getpeer receivedpacket sendjfkmessage3 negtype nonceinitiator nonceresponder hisexponential replyto unknowninitiator setuptype currenttimemillis getpeer private void processjfk message3 byte payload int input offset peer node pn peer reply to boolean old opennet peer boolean unknown initiator int setup type int neg type final long t1 system current time millis if logminor logger minor this got a jfk 3 message processing it pn block cipher c null try c new rijndael 256 256 catch unsupported cipher exception e throw new runtime exception e final int expected length nonce size 2 ni nr diffie hellman modulus length in bytes 2 g i g r hash length authenticator hash length hmac of the cyphertext c get block size 3 iv hash length it s at least a signature 8 a bootid neg type 4 8 0 packet tracker id 1 znoderefi is at least 1 byte long if payload length expected length 3 logger error this packet too short from pn payload length after decryption in jfk 3 should be expected length 3 return ni byte nonce initiator new byte nonce size system arraycopy payload input offset nonce initiator 0 nonce size input offset nonce size nr byte nonce responder new byte nonce size system arraycopy payload input offset nonce responder 0 nonce size input offset nonce size g i byte initiator exponential new byte diffie hellman modulus length in bytes system arraycopy payload input offset initiator exponential 0 diffie hellman modulus length in bytes input offset diffie hellman modulus length in bytes g r byte responder exponential new byte diffie hellman modulus length in bytes system arraycopy payload input offset responder exponential 0 diffie hellman modulus length in bytes input offset diffie hellman modulus length in bytes byte authenticator new byte hash length system arraycopy payload input offset authenticator 0 hash length input offset hash length we want to check the hmac before we do the lookup on the hashmap see https bugs freenetproject org view php id 1604 if hmac verify withsha256 get transient key assemblejfk authenticator responder exponential initiator exponential nonce responder nonce initiator reply to get address get address authenticator if should log error in handshake t1 logger normal this the hmac doesn t match let s discard the packet either we rekeyed or we are victim of forgery jfk3 pn return check try to find the authenticator in the cache if authenticator is already present indicates duplicate replayed message3 now simply transmit the corresponding message4 object message4 null synchronized authenticator cache message4 authenticator cache get new byte array wrapper authenticator if message4 null logger normal this we replayed a message from the cache shouldn t happen often pn we are replaying a jfk 4 therefore if it is anon initiator it is encrypted with our setup key if unknown initiator send anon auth packet 1 neg type 3 setup type byte message4 null reply to crypto anon setup cipher else send auth packet 1 neg type 3 byte message4 pn reply to return else if logdebug logger debug this no message4 found for hex util bytes to hex authenticator responder exponential fields hash code responder exponential initiator exponential fields hash code initiator exponential nonce responder fields hash code nonce responder nonce initiator fields hash code nonce initiator address hex util bytes to hex reply to get address get address native big integer hisexponential new native big integer 1 initiator exponential native big integer ourexponential new native big integer 1 responder exponential byte hmac new byte hash length system arraycopy payload input offset hmac 0 hash length input offset hash length diffie hellman light context ctx find context by exponential ourexponential if ctx null logger error this wtf the hmac verified but we don t know about that exponential shouldn t happen jfk3 pn return big integer computed exponential ctx gethmac key hisexponential global d hgroupa byte ks computejfk shared key computed exponential nonce initiator nonce responder 0 byte ke computejfk shared key computed exponential nonce initiator nonce responder 1 byte ka computejfk shared key computed exponential nonce initiator nonce responder 2 c initialize ke final pcfb mode pk pcfb mode create c int iv length pk lengthiv int decyphered payload offset 0 we compute the hmac of i cyphertext the cyphertext includes the iv byte decyphered payload new byte jfk prefix initiator length payload length input offset system arraycopy jfk prefix initiator 0 decyphered payload decyphered payload offset jfk prefix initiator length decyphered payload offset jfk prefix initiator length system arraycopy payload input offset decyphered payload decyphered payload offset decyphered payload length decyphered payload offset if hmac verify withsha256 ka decyphered payload hmac logger error this the inner hmac doesn t match let s discard the packet jfk 3 pn return get the iv pk reset decyphered payload decyphered payload offset decyphered payload offset iv length decrypt the payload pk block decipher decyphered payload decyphered payload offset decyphered payload length decyphered payload offset deciphered data format signature r s node data starting with bootid byte r new byte node signature parameter length system arraycopy decyphered payload decyphered payload offset r 0 node signature parameter length decyphered payload offset node signature parameter length byte s new byte node signature parameter length system arraycopy decyphered payload decyphered payload offset s 0 node signature parameter length decyphered payload offset node signature parameter length byte data new byte decyphered payload length decyphered payload offset system arraycopy decyphered payload decyphered payload offset data 0 decyphered payload length decyphered payload offset int ptr 0 long trackerid if neg type 4 trackerid fields bytes to long data ptr if trackerid 0 trackerid 1 ptr 8 else trackerid 1 long bootid fields bytes to long data ptr ptr 8 byte his ref new byte data length ptr system arraycopy data ptr his ref 0 his ref length construct the peernode if unknown initiator pn get peer node from unknown initiator his ref setup type pn reply to if pn null if unknown initiator reject logger normal this rejecting unable to construct peer node else logger error this peer node is null and unknown initiator is false return verify the signature dsa signature remote signature new dsa signature new native big integer 1 r new native big integer 1 s if dsa verify pn peer pub key remote signature new native big integer 1 sha256 digest assembledh params nonce initiator nonce responder hisexponential ourexponential crypto my identity data false logger error this the signature verification has failed jfk 3 pn get peer return at this point we know it s from the peer so we can report a packet received pn received packet true false block cipher cs null try cs new rijndael 256 256 catch unsupported cipher exception e throw new runtime exception e cs initialize ks promote if necessary boolean dont want false if old opennet peer opennet manager opennet node get opennet if opennet null logger normal this dumping incoming old opennet peer as opennet just turned off pn return when an old opennet peer connects add it at the top of the lru so that it isn t immediately dropped when there is no droppable peer to drop if it was dropped from the bottom of the lru list we would not have added it to the lru so it was somewhere in the middle if opennet want peer pn false false true logger normal this no longer want peer pn dumping it after connecting dont want true opennet purge old opennet peer pn want peer will call node peers add peer we don t have to long new trackerid pn completed handshake bootid his ref 0 his ref length cs ks reply to true neg type trackerid false false if new trackerid 0 send reply sendjfk message4 1 neg type 3 nonce initiator nonce responder initiator exponential responder exponential c ke ka authenticator his ref pn reply to unknown initiator setup type new trackerid new trackerid trackerid if dont want node peers disconnect pn true true true let it connect then tell it to remove it else pn maybe send initial messages else logger error this handshake failure with pn get peer don t send the jfk 4 we have not successfully connected final long t2 system current time millis if t2 t1 500 logger error this message3 processing packet for pn get peer took time util format time t2 t1 3 true processjfkmessage3 inputoffset peernode replyto oldopennetpeer unknowninitiator setuptype negtype currenttimemillis blockcipher unsupportedcipherexception runtimeexception expectedlength nonce_size diffiehellman moduluslengthinbytes hash_length hash_length getblocksize hash_length negtype expectedlength expectedlength nonceinitiator nonce_size inputoffset nonceinitiator nonce_size inputoffset nonce_size nonceresponder nonce_size inputoffset nonceresponder nonce_size inputoffset nonce_size initiatorexponential diffiehellman moduluslengthinbytes inputoffset initiatorexponential diffiehellman moduluslengthinbytes inputoffset diffiehellman moduluslengthinbytes responderexponential diffiehellman moduluslengthinbytes inputoffset responderexponential diffiehellman moduluslengthinbytes inputoffset diffiehellman moduluslengthinbytes hash_length inputoffset hash_length inputoffset hash_length verifywithsha256 gettransientkey assemblejfkauthenticator responderexponential initiatorexponential nonceresponder nonceinitiator replyto getaddress getaddress shouldlogerrorinhandshake authenticatorcache authenticatorcache bytearraywrapper unknowninitiator sendanonauthpacket negtype setuptype replyto anonsetupcipher sendauthpacket negtype replyto hexutil bytestohex responderexponential hashcode responderexponential initiatorexponential hashcode initiatorexponential nonceresponder hashcode nonceresponder nonceinitiator hashcode nonceinitiator hexutil bytestohex replyto getaddress getaddress nativebiginteger _hisexponential nativebiginteger initiatorexponential nativebiginteger _ourexponential nativebiginteger responderexponential hash_length inputoffset hash_length inputoffset hash_length diffiehellmanlightcontext findcontextbyexponential _ourexponential biginteger computedexponential gethmackey _hisexponential dhgroupa computejfksharedkey computedexponential nonceinitiator nonceresponder computejfksharedkey computedexponential nonceinitiator nonceresponder computejfksharedkey computedexponential nonceinitiator nonceresponder pcfbmode pcfbmode ivlength decypheredpayloadoffset decypheredpayload jfk_prefix_initiator inputoffset jfk_prefix_initiator decypheredpayload decypheredpayloadoffset jfk_prefix_initiator decypheredpayloadoffset jfk_prefix_initiator inputoffset decypheredpayload decypheredpayloadoffset decypheredpayload decypheredpayloadoffset verifywithsha256 decypheredpayload decypheredpayload decypheredpayloadoffset decypheredpayloadoffset ivlength blockdecipher decypheredpayload decypheredpayloadoffset decypheredpayload decypheredpayloadoffset deciphereddata signature_parameter_length decypheredpayload decypheredpayloadoffset signature_parameter_length decypheredpayloadoffset signature_parameter_length signature_parameter_length decypheredpayload decypheredpayloadoffset signature_parameter_length decypheredpayloadoffset signature_parameter_length decypheredpayload decypheredpayloadoffset decypheredpayload decypheredpayloadoffset decypheredpayload decypheredpayloadoffset negtype bytestolong bytestolong hisref hisref hisref unknowninitiator getpeernodefromunknowninitiator hisref setuptype replyto unknowninitiator peernode peernode unknowninitiator dsasignature remotesignature dsasignature nativebiginteger nativebiginteger peerpubkey remotesignature nativebiginteger assembledhparams nonceinitiator nonceresponder _hisexponential _ourexponential myidentity getpeer receivedpacket blockcipher unsupportedcipherexception runtimeexception dontwant oldopennetpeer opennetmanager getopennet wantpeer dontwant purgeoldopennetpeer wantpeer addpeer newtrackerid completedhandshake hisref hisref replyto negtype newtrackerid sendjfkmessage4 negtype nonceinitiator nonceresponder initiatorexponential responderexponential hisref replyto unknowninitiator setuptype newtrackerid newtrackerid dontwant maybesendinitialmessages getpeer currenttimemillis getpeer timeutil formattime private peer node get peer node from unknown initiator byte his ref int setup type peer node pn peer from if setup type setup opennet seednode opennet manager om node get opennet if om null logger error this opennet disabled ignoring seednode connect attempt fixme send some sort of explicit rejection message return null simple field set ref om validate noderef his ref 0 his ref length null true if ref null logger error this invalid noderef fixme send some sort of explicit rejection message return null peer node seed try seed new seed client peer node ref node crypto node peers false true crypto packet mangler catch fs parse exception e logger error this invalid seed client noderef e from from e return null catch peer parse exception e logger error this invalid seed client noderef e from from e return null catch reference signature verification exception e logger error this invalid seed client noderef e from from e return null if seed equals pn logger normal this already connected to seednode return pn node peers add peer seed return seed else logger error this unknown setup type return null peernode getpeernodefromunknowninitiator hisref setuptype peernode setuptype setup_opennet_seednode opennetmanager getopennet simplefieldset validatenoderef hisref hisref peernode seedclientpeernode packetmangler fsparseexception peerparseexception referencesignatureverificationexception addpeer private boolean processjfk message4 byte payload int input offset peer node pn peer reply to boolean old opennet peer boolean unknown initiator int setup type int neg type final long t1 system current time millis if logminor logger minor this got a jfk 4 message processing it pn get peer if pn jfk my ref null string error got a jfk 4 message but no pn jfk my ref for pn if node get uptime 60 1000 logger minor this error else logger error this error block cipher c null try c new rijndael 256 256 catch unsupported cipher exception e throw new runtime exception e final int expected length hash length hmac of the cyphertext c get block size 3 iv node signature parameter length 2 the signature neg type 4 9 0 id of packet tracker plus boolean byte 8 bootid 1 znoderefr if payload length input offset expected length 3 logger error this packet too short from pn get peer payload length after decryption in jfk 4 should be expected length 3 return false byte jfk buffer pn getjfk buffer if jfk buffer null logger normal this we have already handled this message might be a replay or a bug pn return false byte hmac new byte hash length system arraycopy payload input offset hmac 0 hash length input offset hash length c initialize pn jfk ke final pcfb mode pk pcfb mode create c int iv length pk lengthiv int decyphered payload offset 0 we compute the hmac of r cyphertext the cyphertext includes the iv byte decyphered payload new byte jfk prefix responder length payload length input offset system arraycopy jfk prefix responder 0 decyphered payload decyphered payload offset jfk prefix responder length decyphered payload offset jfk prefix responder length system arraycopy payload input offset decyphered payload decyphered payload offset payload length input offset if hmac verify withsha256 pn jfk ka decyphered payload hmac logger normal this the digest hmac doesn t match let s discard the packet pn get peer return false try to find the hmac in the cache if it is already present it indicates duplicate replayed message4 and we can discard if it s not we can add it with a timestamp byte message4 timestamp null synchronized authenticator cache byte array wrapper hmacbaw new byte array wrapper hmac message4 timestamp authenticator cache get hmacbaw if message4 timestamp null normal behaviour authenticator cache put hmacbaw fields long to bytes t1 if message4 timestamp null logger normal this we got a replayed message4 first handled at time util format time t1 fields bytes to long message4 timestamp from pn return true get the iv pk reset decyphered payload decyphered payload offset decyphered payload offset iv length decrypt the payload pk block decipher decyphered payload decyphered payload offset decyphered payload length decyphered payload offset deciphered data format signature r s bootid znoderef byte r new byte node signature parameter length system arraycopy decyphered payload decyphered payload offset r 0 node signature parameter length decyphered payload offset node signature parameter length byte s new byte node signature parameter length system arraycopy decyphered payload decyphered payload offset s 0 node signature parameter length decyphered payload offset node signature parameter length byte data new byte decyphered payload length decyphered payload offset system arraycopy decyphered payload decyphered payload offset data 0 decyphered payload length decyphered payload offset int ptr 0 long trackerid boolean reused tracker if neg type 4 trackerid fields bytes to long data ptr ptr 8 reused tracker data ptr 0 else trackerid 1 reused tracker false long bootid fields bytes to long data ptr ptr 8 byte his ref new byte data length ptr system arraycopy data ptr his ref 0 his ref length verify the signature dsa signature remote signature new dsa signature new native big integer 1 r new native big integer 1 s int data len his ref length 8 neg type 4 9 0 byte locally generated text new byte nonce size 2 diffie hellman modulus length in bytes 2 crypto my identity length data len pn jfk my ref length int buffer offset nonce size 2 diffie hellman modulus length in bytes 2 system arraycopy jfk buffer 0 locally generated text 0 buffer offset byte identity crypto get identity unknown initiator system arraycopy identity 0 locally generated text buffer offset identity length buffer offset identity length bootid system arraycopy data 0 locally generated text buffer offset data len buffer offset data len system arraycopy pn jfk my ref 0 locally generated text buffer offset pn jfk my ref length byte message hash sha256 digest locally generated text if dsa verify pn peer pub key remote signature new native big integer 1 message hash false string error the signature verification has failed jfk 4 pn get peer message hash hex util bytes to hex message hash length locally generated text length his ref his ref length hash fields hash code his ref my ref pn jfk my ref length hash fields hash code pn jfk my ref boot id bootid logger error this error return true received a packet pn received packet true false promote if necessary boolean dont want false if old opennet peer opennet manager opennet node get opennet if opennet null logger normal this dumping incoming old opennet peer as opennet just turned off pn return true when an old opennet peer connects add it at the top of the lru so that it isn t immediately dropped when there is no droppable peer to drop if it was dropped from the bottom of the lru list we would not have added it to the lru so it was somewhere in the middle if opennet want peer pn false false true logger normal this no longer want peer pn dumping it after connecting dont want true opennet purge old opennet peer pn want peer will call node peers add peer we don t have to we change the key c initialize pn jfk ks if pn completed handshake bootid his ref 0 his ref length c pn jfk ks reply to false neg type trackerid true reused tracker 0 if dont want node peers disconnect pn true true true else pn maybe send initial messages else logger error this handshake failed cleanup fixme maybe we should copy zeros garbage into it before leaving it to the gc pn setjfk buffer null pn jfk ka null pn jfk ke null pn jfk ks null we want to clear it here so that new handshake requests will be sent with a different dh pair pn set key agreement scheme context null synchronized pn fixme true multi homing winner takes all kill all other connection attempts since we can t deal with multiple active connections also avoids leaking pn jfk nonces sent clear final long t2 system current time millis if t2 t1 500 logger error this message4 timeout error processing packet from pn get peer return true processjfkmessage4 inputoffset peernode replyto oldopennetpeer unknowninitiator setuptype negtype currenttimemillis getpeer jfkmyref jfkmyref getuptime blockcipher unsupportedcipherexception runtimeexception expectedlength hash_length getblocksize signature_parameter_length negtype inputoffset expectedlength getpeer expectedlength jfkbuffer getjfkbuffer jfkbuffer hash_length inputoffset hash_length inputoffset hash_length jfkke pcfbmode pcfbmode ivlength decypheredpayloadoffset decypheredpayload jfk_prefix_responder inputoffset jfk_prefix_responder decypheredpayload decypheredpayloadoffset jfk_prefix_responder decypheredpayloadoffset jfk_prefix_responder inputoffset decypheredpayload decypheredpayloadoffset inputoffset verifywithsha256 jfkka decypheredpayload getpeer message4timestamp authenticatorcache bytearraywrapper bytearraywrapper message4timestamp authenticatorcache message4timestamp authenticatorcache longtobytes message4timestamp timeutil formattime bytestolong message4timestamp decypheredpayload decypheredpayloadoffset decypheredpayloadoffset ivlength blockdecipher decypheredpayload decypheredpayloadoffset decypheredpayload decypheredpayloadoffset deciphereddata signature_parameter_length decypheredpayload decypheredpayloadoffset signature_parameter_length decypheredpayloadoffset signature_parameter_length signature_parameter_length decypheredpayload decypheredpayloadoffset signature_parameter_length decypheredpayloadoffset signature_parameter_length decypheredpayload decypheredpayloadoffset decypheredpayload decypheredpayloadoffset decypheredpayload decypheredpayloadoffset reusedtracker negtype bytestolong reusedtracker reusedtracker bytestolong hisref hisref hisref dsasignature remotesignature dsasignature nativebiginteger nativebiginteger datalen hisref negtype locallygeneratedtext nonce_size diffiehellman moduluslengthinbytes myidentity datalen jfkmyref bufferoffset nonce_size diffiehellman moduluslengthinbytes jfkbuffer locallygeneratedtext bufferoffset getidentity unknowninitiator locallygeneratedtext bufferoffset bufferoffset locallygeneratedtext bufferoffset datalen bufferoffset datalen jfkmyref locallygeneratedtext bufferoffset jfkmyref messagehash locallygeneratedtext peerpubkey remotesignature nativebiginteger messagehash getpeer hexutil bytestohex messagehash locallygeneratedtext hisref hisref hashcode hisref myref jfkmyref hashcode jfkmyref receivedpacket dontwant oldopennetpeer opennetmanager getopennet wantpeer dontwant purgeoldopennetpeer wantpeer addpeer jfkks completedhandshake hisref hisref jfkks replyto negtype reusedtracker dontwant maybesendinitialmessages setjfkbuffer jfkka jfkke jfkks setkeyagreementschemecontext jfknoncessent currenttimemillis getpeer private void sendjfk message3 int version final int neg type int phase byte nonce initiator byte nonce responder byte his exponential byte authenticator final peer node pn final peer reply to final boolean unknown initiator final int setup type if logminor logger minor this sending a jfk 3 message to pn get peer long t1 system current time millis block cipher c null try c new rijndael 256 256 catch unsupported cipher exception e throw new runtime exception e diffie hellman light context ctx diffie hellman light context pn get key agreement scheme context if ctx null return byte our exponential strip big integer to network format ctx my exponential pn jfk my ref unknown initiator crypto my compressed heavy setup ref crypto my compressed setup ref byte data new byte neg type 4 8 0 8 pn jfk my ref length int ptr 0 if neg type 4 long trackerid if pn null trackerid 1 else trackerid pn get reusable trackerid system arraycopy fields long to bytes trackerid 0 data ptr 8 ptr 8 if logminor logger minor this sending tracker id trackerid in jfk 3 system arraycopy fields long to bytes node bootid 0 data ptr 8 ptr 8 system arraycopy pn jfk my ref 0 data ptr pn jfk my ref length final byte message3 new byte nonce size 2 ni nr diffie hellman modulus length in bytes 2 g i g r hash length authenticator hash length hmac cyphertext c get block size 3 iv node signature parameter length 2 signature r s data length the bootid noderef int offset 0 ni system arraycopy nonce initiator 0 message3 offset nonce size offset nonce size nr system arraycopy nonce responder 0 message3 offset nonce size offset nonce size g i system arraycopy our exponential 0 message3 offset our exponential length offset our exponential length g r system arraycopy his exponential 0 message3 offset his exponential length offset his exponential length authenticator system arraycopy authenticator 0 message3 offset hash length offset hash length digital signature of the message with the private key belonging to the initiator responder it is assumed to be non message recovering native big integer ourexponential new native big integer 1 our exponential native big integer hisexponential new native big integer 1 his exponential save parameters so that we can verify message4 byte to sign assembledh params nonce initiator nonce responder ourexponential hisexponential pn identity data pn setjfk buffer to sign dsa signature local signature crypto sign sha256 digest to sign byte r local signature getr bytes node signature parameter length byte s local signature gets bytes node signature parameter length big integer computed exponential ctx gethmac key hisexponential global d hgroupa pn jfk ks computejfk shared key computed exponential nonce initiator nonce responder 0 pn jfk ke computejfk shared key computed exponential nonce initiator nonce responder 1 pn jfk ka computejfk shared key computed exponential nonce initiator nonce responder 2 c initialize pn jfk ke pcfb mode pcfb pcfb mode create c int iv length pcfb lengthiv byte iv new byte iv length node random next bytes iv pcfb reset iv int cleartext offset 0 byte cleartext new byte jfk prefix initiator length iv length node signature parameter length 2 data length system arraycopy jfk prefix initiator 0 cleartext cleartext offset jfk prefix initiator length cleartext offset jfk prefix initiator length system arraycopy iv 0 cleartext cleartext offset iv length cleartext offset iv length system arraycopy r 0 cleartext cleartext offset node signature parameter length cleartext offset node signature parameter length system arraycopy s 0 cleartext cleartext offset node signature parameter length cleartext offset node signature parameter length system arraycopy data 0 cleartext cleartext offset data length cleartext offset data length int cleartext to encypher offset jfk prefix initiator length iv length pcfb block encipher cleartext cleartext to encypher offset cleartext length cleartext to encypher offset we compute the hmac of prefix cyphertext includes the iv byte hmac hmac mac withsha256 pn jfk ka cleartext hash length copy stuffs back to the message system arraycopy hmac 0 message3 offset hash length offset hash length system arraycopy iv 0 message3 offset iv length offset iv length system arraycopy cleartext cleartext to encypher offset message3 offset cleartext length cleartext to encypher offset cache the message synchronized authenticator cache if maybe reset transient key authenticator cache put new byte array wrapper authenticator message3 if unknown initiator send anon auth packet 1 neg type 2 setup type message3 pn reply to pn anonymous initiator setup cipher else send auth packet 1 neg type 2 message3 pn reply to re send the packet after 5sec if we don t get any reply node get ticker queue timed job new runnable public void run if pn time last connected pn last received packet time if unknown initiator send anon auth packet 1 neg type 2 setup type message3 pn reply to pn anonymous initiator setup cipher else send auth packet 1 neg type 2 message3 pn reply to 5 1000 long t2 system current time millis if t2 t1 500 logger error this message3 timeout error sending packet for pn get peer sendjfkmessage3 negtype nonceinitiator nonceresponder hisexponential peernode replyto unknowninitiator setuptype getpeer currenttimemillis blockcipher unsupportedcipherexception runtimeexception diffiehellmanlightcontext diffiehellmanlightcontext getkeyagreementschemecontext ourexponential stripbigintegertonetworkformat myexponential jfkmyref unknowninitiator mycompressedheavysetupref mycompressedsetupref negtype jfkmyref negtype getreusabletrackerid longtobytes longtobytes jfkmyref jfkmyref nonce_size diffiehellman moduluslengthinbytes hash_length hash_length getblocksize signature_parameter_length nonceinitiator nonce_size nonce_size nonceresponder nonce_size nonce_size ourexponential ourexponential ourexponential hisexponential hisexponential hisexponential hash_length hash_length nativebiginteger _ourexponential nativebiginteger ourexponential nativebiginteger _hisexponential nativebiginteger hisexponential tosign assembledhparams nonceinitiator nonceresponder _ourexponential _hisexponential setjfkbuffer tosign dsasignature localsignature tosign localsignature getrbytes signature_parameter_length localsignature getsbytes signature_parameter_length biginteger computedexponential gethmackey _hisexponential dhgroupa jfkks computejfksharedkey computedexponential nonceinitiator nonceresponder jfkke computejfksharedkey computedexponential nonceinitiator nonceresponder jfkka computejfksharedkey computedexponential nonceinitiator nonceresponder jfkke pcfbmode pcfbmode ivlength ivlength nextbytes cleartextoffset jfk_prefix_initiator ivlength signature_parameter_length jfk_prefix_initiator cleartextoffset jfk_prefix_initiator cleartextoffset jfk_prefix_initiator cleartextoffset ivlength cleartextoffset ivlength cleartextoffset signature_parameter_length cleartextoffset signature_parameter_length cleartextoffset signature_parameter_length cleartextoffset signature_parameter_length cleartextoffset cleartextoffset cleartexttoencypheroffset jfk_prefix_initiator ivlength blockencipher cleartexttoencypheroffset cleartexttoencypheroffset macwithsha256 jfkka hash_length hash_length hash_length ivlength ivlength cleartexttoencypheroffset cleartexttoencypheroffset authenticatorcache mayberesettransientkey authenticatorcache bytearraywrapper unknowninitiator sendanonauthpacket negtype setuptype replyto anonymousinitiatorsetupcipher sendauthpacket negtype replyto getticker queuetimedjob timelastconnected lastreceivedpackettime unknowninitiator sendanonauthpacket negtype setuptype replyto anonymousinitiatorsetupcipher sendauthpacket negtype replyto currenttimemillis getpeer node get ticker queue timed job new runnable public void run if pn time last connected pn last received packet time if unknown initiator send anon auth packet 1 neg type 2 setup type message3 pn reply to pn anonymous initiator setup cipher else send auth packet 1 neg type 2 message3 pn reply to getticker queuetimedjob timelastconnected lastreceivedpackettime unknowninitiator sendanonauthpacket negtype setuptype replyto anonymousinitiatorsetupcipher sendauthpacket negtype replyto private void sendjfk message4 int version int neg type int phase byte nonce initiator byte nonce responder byte initiator exponential byte responder exponential block cipher c byte ke byte ka byte authenticator byte his ref peer node pn peer reply to boolean unknown initiator int setup type long new trackerid boolean same as old trackerid if logminor logger minor this sending a jfk 4 message to pn get peer long t1 system current time millis native big integer responderexponential new native big integer 1 responder exponential native big integer initiatorexponential new native big integer 1 initiator exponential byte my ref crypto my compressed setup ref byte data new byte neg type 4 9 0 8 my ref length his ref length int ptr 0 if neg type 4 system arraycopy fields long to bytes new trackerid 0 data ptr 8 ptr 8 data ptr byte same as old trackerid 1 0 system arraycopy fields long to bytes node bootid 0 data ptr 8 ptr 8 system arraycopy my ref 0 data ptr my ref length ptr my ref length system arraycopy his ref 0 data ptr his ref length byte params assembledh params nonce initiator nonce responder initiatorexponential responderexponential pn identity data byte message hash sha256 digest params if logminor logger minor this message hash hex util bytes to hex message hash length params length my ref my ref length hash fields hash code my ref his ref his ref length hash fields hash code his ref boot id node bootid dsa signature local signature crypto sign message hash byte r local signature getr bytes node signature parameter length byte s local signature gets bytes node signature parameter length pcfb mode pk pcfb mode create c int iv length pk lengthiv byte iv new byte iv length node random next bytes iv pk reset iv don t include the last bit int data length data length his ref length byte cyphertext new byte jfk prefix responder length iv length node signature parameter length 2 data length int cleartext offset 0 system arraycopy jfk prefix responder 0 cyphertext cleartext offset jfk prefix responder length cleartext offset jfk prefix responder length system arraycopy iv 0 cyphertext cleartext offset iv length cleartext offset iv length system arraycopy r 0 cyphertext cleartext offset node signature parameter length cleartext offset node signature parameter length system arraycopy s 0 cyphertext cleartext offset node signature parameter length cleartext offset node signature parameter length system arraycopy data 0 cyphertext cleartext offset data length cleartext offset data length now encrypt the cleartext signature int cleartext to encypher offset jfk prefix responder length iv length pk block encipher cyphertext cleartext to encypher offset cyphertext length cleartext to encypher offset we compute the hmac of prefix iv signature byte hmac hmac mac withsha256 ka cyphertext hash length message4 hmac iv encrypted signature byte message4 new byte hash length iv length cyphertext length cleartext to encypher offset int offset 0 system arraycopy hmac 0 message4 offset hash length offset hash length system arraycopy iv 0 message4 offset iv length offset iv length system arraycopy cyphertext cleartext to encypher offset message4 offset cyphertext length cleartext to encypher offset cache the message synchronized authenticator cache if maybe reset transient key authenticator cache put new byte array wrapper authenticator message4 if logdebug logger debug this storing jfk 4 for hex util bytes to hex authenticator if unknown initiator send anon auth packet 1 neg type 3 setup type message4 pn reply to crypto anon setup cipher else send auth packet 1 neg type 3 message4 pn reply to long t2 system current time millis if t2 t1 500 logger error this message4 timeout error sending packet for pn get peer sendjfkmessage4 negtype nonceinitiator nonceresponder initiatorexponential responderexponential blockcipher hisref peernode replyto unknowninitiator setuptype newtrackerid sameasoldtrackerid getpeer currenttimemillis nativebiginteger _responderexponential nativebiginteger responderexponential nativebiginteger _initiatorexponential nativebiginteger initiatorexponential myref mycompressedsetupref negtype myref hisref negtype longtobytes newtrackerid sameasoldtrackerid longtobytes myref myref myref hisref hisref assembledhparams nonceinitiator nonceresponder _initiatorexponential _responderexponential messagehash hexutil bytestohex messagehash myref myref hashcode myref hisref hisref hashcode hisref dsasignature localsignature messagehash localsignature getrbytes signature_parameter_length localsignature getsbytes signature_parameter_length pcfbmode pcfbmode ivlength ivlength nextbytes datalength hisref jfk_prefix_responder ivlength signature_parameter_length datalength cleartextoffset jfk_prefix_responder cleartextoffset jfk_prefix_responder cleartextoffset jfk_prefix_responder cleartextoffset ivlength cleartextoffset ivlength cleartextoffset signature_parameter_length cleartextoffset signature_parameter_length cleartextoffset signature_parameter_length cleartextoffset signature_parameter_length cleartextoffset datalength cleartextoffset datalength cleartexttoencypheroffset jfk_prefix_responder ivlength blockencipher cleartexttoencypheroffset cleartexttoencypheroffset macwithsha256 hash_length encryptedsignature hash_length ivlength cleartexttoencypheroffset hash_length hash_length ivlength ivlength cleartexttoencypheroffset cleartexttoencypheroffset authenticatorcache mayberesettransientkey authenticatorcache bytearraywrapper hexutil bytestohex unknowninitiator sendanonauthpacket negtype setuptype replyto anonsetupcipher sendauthpacket negtype replyto currenttimemillis getpeer send an auth packet private void send auth packet int version int neg type int phase byte data peer node pn peer reply to if pn null throw new illegal argument exception pn shouldn t be null here byte output new byte data length 3 output 0 byte version output 1 byte neg type output 2 byte phase system arraycopy data 0 output 3 data length if logminor long now system current time millis string delta never long last pn last sent packet time delta time util format time now last 2 true ago logger minor this sending auth packet for string value of pn get peer phase phase ver version nt neg type last packet sent delta to reply to data length data length to reply to send auth packet output pn outgoing setup cipher pn reply to false sendauthpacket negtype peernode replyto illegalargumentexception negtype currenttimemillis lastsentpackettime timeutil formattime valueof getpeer negtype replyto replyto sendauthpacket outgoingsetupcipher replyto param version param neg type param phase param setup type param data param pn may be null if not null used for details such as anti firewall hacks param reply to param cipher private void send anon auth packet int version int neg type int phase int setup type byte data peer node pn peer reply to block cipher cipher byte output new byte data length 4 output 0 byte version output 1 byte neg type output 2 byte phase output 3 byte setup type system arraycopy data 0 output 4 data length if logminor logger minor this sending anon auth packet phase phase ver version nt neg type setup setup type data length data length send auth packet output cipher pn reply to true negtype setuptype replyto sendanonauthpacket negtype setuptype peernode replyto blockcipher negtype setuptype negtype setuptype sendauthpacket replyto send an auth packet we have constructed the payload now hash it pad it encrypt it private void send auth packet byte output block cipher cipher peer node pn peer reply to boolean anon auth int length output length if length sock get max packet size throw new illegal state exception cannot send auth packet too long length pcfb mode pcfb pcfb mode create cipher byte iv new byte pcfb lengthiv node random next bytes iv byte hash sha256 digest output if logminor logger minor this data hash hex util bytes to hex hash int pre padding length iv length hash length 2 length output length int max packet size sock get max packet size sock get headers length int padding length if pre padding length max packet size padding length node fast weak random next int math min 100 max packet size pre padding length else padding length 0 avoid oversize packets if at all possible the mtu is an estimate and may be wrong and fragmented packets are often dropped by firewalls tell the devs this shouldn t happen logger error this warning sending oversize auth packet anon auth anon auth of pre padding length bytes if padding length 0 padding length 0 byte data new byte pre padding length padding length pcfb reset iv system arraycopy iv 0 data 0 iv length pcfb block encipher hash 0 hash length system arraycopy hash 0 data iv length hash length if logminor logger minor this payload length length data hash length iv length byte pcfb encipher byte length 8 data hash length iv length 1 byte pcfb encipher byte length pcfb block encipher output 0 output length system arraycopy output 0 data hash length iv length 2 output length byte random new byte padding length node fast weak random next bytes random system arraycopy random 0 data hash length iv length 2 output length random length node node stats report auth bytes data length sock get headers length try send packet data reply to pn catch local address exception e logger error this tried to send auth packet to local address reply to for pn maybe you should set allow local addresses for this peer sendauthpacket blockcipher peernode replyto anonauth getmaxpacketsize illegalstateexception pcfbmode pcfbmode nextbytes hexutil bytestohex prepaddinglength maxpacketsize getmaxpacketsize getheaderslength paddinglength prepaddinglength maxpacketsize paddinglength fastweakrandom nextint maxpacketsize prepaddinglength paddinglength anonauth anonauth prepaddinglength paddinglength paddinglength prepaddinglength paddinglength blockencipher blockencipher paddinglength fastweakrandom nextbytes nodestats reportauthbytes getheaderslength sendpacket replyto localaddressexception replyto allowlocaladdresses private void send packet byte data peer reply to peer node pn throws local address exception if pn null if pn is ignore source peer p pn get peer if p null reply to p sock send packet data reply to pn null crypto config always allow local addresses pn allow local addresses if pn null pn report outgoing packet data 0 data length system current time millis if peer node should throttle reply to node node output throttle force grab data length sendpacket replyto peernode localaddressexception isignoresource getpeer replyto sendpacket replyto alwaysallowlocaladdresses allowlocaladdresses reportoutgoingpacket currenttimemillis peernode shouldthrottle replyto outputthrottle forcegrab should we log an error for an event that could easily be caused by a handshake across a restart boundary private boolean should log error in handshake long now if now node startup time node handshake timeout 2 return false return true shouldlogerrorinhandshake startuptime handshake_timeout try to process an incoming packet with a given peer node we need to know where the packet has come from in order to decrypt and authenticate it private boolean try process byte buf int offset int length session key tracker long now need to be able to call with tracker null to simplify code above if tracker null if logdebug logger debug this tracker null return false if logminor logger minor this entering try process fields hash code buf offset length tracker e pcbc session h seq random data e pcfb session seq random data so first two blocks are the hash pcbc encoded meaning the first one is ecb and the second one is ecb xo red with the ciphertext and plaintext of the first block block cipher session cipher tracker session cipher if session cipher null if logminor logger minor this no cipher return false if logminor logger minor this decrypting with hex util bytes to hex tracker session key int block size session cipher get block size 3 if session cipher get key size session cipher get block size throw new illegal state exception block size must be equal to key size if hash length block size throw new illegal state exception block size must be digest length byte packet hash new byte hash length system arraycopy buf offset packet hash 0 hash length decrypt the sequence number and see if it s plausible verify the hash later pcfb mode pcfb pcfb pcfb mode create session cipher set iv to the hash after it is encrypted pcfb reset packet hash logger minor this iv n hex util bytes to hex packet hash byte seq buf new byte 4 system arraycopy buf offset hash length seq buf 0 4 logger minor this encypted sequence number hex util bytes to hex seq buf pcfb block decipher seq buf 0 4 logger minor this decrypted sequence number hex util bytes to hex seq buf int seq number seq buf 0 0xff 8 seq buf 1 0xff 8 seq buf 2 0xff 8 seq buf 3 0xff packet tracker packets tracker packets int target seq number packets highest received incoming seq number if logminor logger minor this seqno seq number highest seen target seq number receiving packet from tracker pn get peer if seq number 1 ack resendreq only packet else now is it credible as long as it s within 256 this is valid if target seq number 1 math abs target seq number seq number max packets in flight return false if logminor logger minor this sequence number received seq number plausible so lets decrypt the rest of the data byte plaintext new byte length 4 hash length system arraycopy buf offset hash length 4 plaintext 0 length hash length 4 pcfb block decipher plaintext 0 length hash length 4 logger minor this plaintext n hex util bytes to hex plaintext message digest md sha256 get message digest md update seq buf md update plaintext byte real hash md digest sha256 return message digest md md null now decrypt the original hash byte temp new byte block size system arraycopy buf offset temp 0 block size session cipher decipher temp temp system arraycopy temp 0 packet hash 0 block size check the hash if arrays equals packet hash real hash if logminor logger minor this packet possibly from tracker hash does not match npacket hash hex util bytes to hex packet hash n real hash hex util bytes to hex real hash length hash length bytes payload return false verify tracker pn verified tracker for int i 0 i hash length i packet hash i buf offset i if logminor logger minor this contributing entropy node random accept entropy bytes my packet data source packet hash 0 hash length 0 5 if logminor logger minor this contributed entropy lots more to do yet process decrypted data plaintext seq number tracker length plaintext length tracker pn report incoming packet buf offset length now return true peernode tryprocess sessionkey tryprocess hashcode e_pcbc_session e_pcfb_session xored blockcipher sessioncipher sessioncipher sessioncipher hexutil bytestohex sessionkey blocksize sessioncipher getblocksize sessioncipher getkeysize sessioncipher getblocksize illegalstateexception hash_length blocksize illegalstateexception packethash hash_length packethash hash_length pcfbmode pcfbmode sessioncipher packethash hexutil bytestohex packethash seqbuf hash_length seqbuf hexutil bytestohex seqbuf blockdecipher seqbuf hexutil bytestohex seqbuf seqnumber seqbuf seqbuf seqbuf seqbuf packettracker targetseqnumber highestreceivedincomingseqnumber seqnumber targetseqnumber getpeer seqnumber targetseqnumber targetseqnumber seqnumber max_packets_in_flight seqnumber hash_length hash_length hash_length blockdecipher hash_length hexutil bytestohex messagedigest getmessagedigest seqbuf realhash returnmessagedigest blocksize blocksize sessioncipher packethash blocksize packethash realhash npackethash hexutil bytestohex packethash realhash hexutil bytestohex realhash hash_length hash_length packethash acceptentropybytes mypacketdatasource packethash hash_length processdecrypteddata seqnumber reportincomingpacket process an incoming packet once it has been decrypted param decrypted the packet s contents param seq number the detected sequence number of the packet param tracker the session key responsible for the key used to encrypt the packet private void process decrypted data byte decrypted int seq number session key tracker int overhead decoded format 1 byte version number 0 1 byte number of acknowledgements acknowledgements 1 byte ack ve integer subtract from seq 1 to get seq to ack 1 byte number of explicit retransmit requests explicit retransmit requests 1 byte retransmit request ve integer subtract from seq 1 to get seq to resend 1 byte number of packets forgotten forgotten packets 1 byte forgotten packet seq ve integer subtract from seq 1 to get seq lost 1 byte number of messages 2 bytes message length first message 2 bytes second message length second message last message anything beyond this point is padding to be ignored use ptr to simplify code int ptr random bytes length int version decrypted ptr if ptr decrypted length logger error this packet not long enough at byte ptr on tracker return if version 0 logger error this packet from tracker decrypted but invalid version version return highest sequence number sent not the same as this packet s seq number int real seq number seq number if seq number 1 if ptr 4 decrypted length logger error this packet not long enough at byte ptr on tracker return real seq number decrypted ptr 0 0xff 8 decrypted ptr 1 0xff 8 decrypted ptr 2 0xff 8 decrypted ptr 3 0xff ptr 4 else if ptr decrypted length logger error this packet not long enough at byte ptr on tracker return real seq number seq number decrypted ptr 0xff if logminor logger minor this real sequence number real seq number logger minor this reference seq number hex util bytes to hex decrypted ptr 4 if ptr 4 decrypted length logger error this packet not long enough at byte ptr on tracker return int reference seq number decrypted ptr 0 0xff 8 decrypted ptr 1 0xff 8 decrypted ptr 2 0xff 8 decrypted ptr 3 0xff ptr 4 if logminor logger minor this reference sequence number reference seq number int ack count decrypted ptr 0xff if logminor logger minor this acks ack count int acks new int ack count for int i 0 i ack count i int offset decrypted ptr 0xff if ptr decrypted length logger error this packet not long enough at byte ptr on tracker return acks i reference seq number offset packet tracker packets tracker packets packets acknowledged packets acks int retransmit count decrypted ptr 0xff if logminor logger minor this retransmit requests retransmit count for int i 0 i retransmit count i int offset decrypted ptr 0xff if ptr decrypted length logger error this packet not long enough at byte ptr on tracker int real seq no reference seq number offset if logminor logger minor this retransmit request real seq no packets resend packet real seq no int ack requests count decrypted ptr 0xff if logminor logger minor this ack requests ack requests count these two are relative to our outgoing packet number because they relate to packets we have sent for int i 0 i ack requests count i int offset decrypted ptr 0xff if ptr decrypted length logger error this packet not long enough at byte ptr on tracker int real seq no real seq number offset if logminor logger minor this ack request real seq no packets received ack request real seq no int forgotten count decrypted ptr 0xff if logminor logger minor this forgotten packets forgotten count for int i 0 i forgotten count i int offset decrypted ptr 0xff if ptr decrypted length logger error this packet not long enough at byte ptr on tracker int real seq no real seq number offset packets dest forgot packet real seq no tracker pn received packet false true must keep the connection open even if it s an ack packet only and on an incompatible connection we may want to do a uom transfer e g system err println tracker pn get identity string received packet no sequence number no messages if seq number 1 packets already received seq number packets queue ack seq number must keep the connection open if logminor logger minor this received packet twice seq number from tracker pn get peer seq number time util format time long tracker pn average ping time 2 true ping avg return packets received packet seq number if seq number 1 if logminor logger minor this returning because seqno seq number return int messages decrypted ptr 0xff overhead ptr for int i 0 i messages i if ptr 1 decrypted length logger error this packet not long enough at byte ptr on tracker int length decrypted ptr 0xff 8 decrypted ptr 0xff if length decrypted length ptr logger error this message longer than remaining space length return if logminor logger minor this message i length length hash code fields hash code decrypted ptr length message m usm decode single message decrypted ptr length tracker pn 1 overhead messages ptr length if m null logger minor this dispatching packet m usm check filters m sock tracker pn maybe rekey if logminor logger minor this done seqnumber sessionkey processdecrypteddata seqnumber sessionkey random_bytes_length realseqnumber seqnumber seqnumber realseqnumber realseqnumber seqnumber realseqnumber hexutil bytestohex referenceseqnumber referenceseqnumber ackcount ackcount ackcount ackcount referenceseqnumber packettracker acknowledgedpackets retransmitcount retransmitcount retransmitcount realseqno referenceseqnumber retransmitrequest realseqno resendpacket realseqno ackrequestscount ackrequestscount ackrequestscount realseqno realseqnumber ackrequest realseqno receivedackrequest realseqno forgottencount forgottencount forgottencount realseqno realseqnumber destforgotpacket realseqno receivedpacket getidentitystring seqnumber alreadyreceived seqnumber queueack seqnumber seqnumber getpeer seqnumber timeutil formattime averagepingtime receivedpacket seqnumber seqnumber seqnumber hashcode decodesinglemessage checkfilters mayberekey public boolean process outgoing or requeue message item messages peer node pn boolean dont requeue boolean one packet throws blocked too long exception string requeue log string if dont requeue requeue log string requeueing if logminor logger minor this process outgoing or requeue messages length messages for pn byte message data new byte messages length message item new msgs new message item messages length session key kt pn get current key tracker if kt null logger error this not connected while sending packets pn if dont requeue for message item item messages item on disconnect return false packet tracker packets kt packets if packets would block false if logminor logger minor this would block kt requeue if dont requeue pn requeue message items messages 0 messages length false would block return false int length 1 length packets count acks packets count ack requests packets count resend requests int callbacks count 0 int x 0 string mi name null for int i 0 i message data length i message item mi messages i if logminor logger minor this handling mi formatted formatted message item mi mi get length mi name mi msg null not a message mi msg get spec get name if mi formatted try byte buf mi get data int packet number packets allocate outgoing packet number never block int size process outgoing preformatted buf 0 buf length kt packet number mi cb mi get priority mark on sent mi on sent size catch not connected exception e logger normal this caught e while sending messages mi name to pn get peer requeue log string requeue if dont requeue pn requeue message items new msgs 0 x false not connected exception 1a pn requeue message items messages i messages length i false not connected exception 1b return false catch would block exception e if logminor logger minor this caught e while sending messages mi name to pn get peer requeue log string e requeue if dont requeue pn requeue message items new msgs 0 x false would block exception 1a pn requeue message items messages i messages length i false would block exception 1b return false catch key changed exception e if logminor logger minor this caught e while sending messages mi name to pn get peer requeue log string e requeue if dont requeue pn requeue message items new msgs 0 x false key changed exception 1a pn requeue message items messages i messages length i false key changed exception 1b return false catch throwable e logger error this caught e while sending messages mi name to pn get peer requeue log string e requeue if dont requeue pn requeue message items new msgs 0 x false throwable 1 pn requeue message items messages i messages length i false throwable 1 return false else byte data mi get data message data x data if data length sock get max packet size logger error this message exceeds packet size messages i size data length message mi msg will be handled later new msgs x mi x if mi cb null callbacks count mi cb length if logminor logger minor this sending mi length data length cb arrays to string mi cb length data length 2 if x message data length byte new message data new byte x system arraycopy message data 0 new message data 0 x message data new message data messages new msgs new msgs new message item x system arraycopy messages 0 new msgs 0 x messages new msgs async message callback callbacks new async message callback callbacks count x 0 short priority dmt priority bulk data for int i 0 i messages length i if messages i formatted continue if messages i cb null system arraycopy messages i cb 0 callbacks x messages i cb length x messages i cb length short message prio messages i get priority if message prio priority priority message prio if x callbacks count throw new illegal state exception if length headers length minimum sock get max packet size message data length 256 mi name null try int size inner process outgoing message data 0 message data length length pn callbacks priority int total message size 0 for int i 0 i message data length i total message size message data i length int overhead size total message size for int i 0 i message data length i message item mi new msgs i mi name mi msg null not a message mi msg get spec get name fixme this on sent is called before the mark d on sent above for the same message item shouldn t they be mutually exclusive mi on sent message data i length overhead message data length catch not connected exception e logger normal this caught e while sending messages mi name to pn get peer requeue log string requeue if dont requeue pn requeue message items messages 0 messages length false not connected exception 2 return false catch would block exception e if logminor logger minor this caught e while sending messages mi name to pn get peer requeue log string e requeue if dont requeue pn requeue message items messages 0 messages length false would block exception 2 return false catch throwable e logger error this caught e while sending messages mi name to pn get peer requeue log string e requeue if dont requeue pn requeue message items messages 0 messages length false throwable 2 return false else if dont requeue requeue log string requeueing remaining messages length 1 length packets count acks packets count ack requests packets count resend requests int count 0 int last index 0 if logminor logger minor this sending message data length messages for int i 0 i message data length i if logminor logger minor this sending message i int this length if i messages length this length 0 else this length message data i length 2 int new length length this length count if new length headers length minimum sock get max packet size count 255 i messages length last index up to the message right before this one e g last index 0 i 1 we just send message 0 if last index i mi name null try fixme regenerate callbacks and priority int size inner process outgoing message data last index i last index length pn callbacks priority int total message size 0 for int j last index j i j total message size message data j length int overhead size total message size for int j last index j i j message item mi new msgs j mi name mi msg null not a message mi msg get spec get name mi on sent message data j length overhead i last index catch not connected exception e logger normal this caught e while sending messages mi name to pn get peer requeue log string requeue if dont requeue pn requeue message items messages last index messages length last index false not connected exception 3 return false catch would block exception e if logminor logger minor this caught e while sending messages mi name to pn get peer requeue log string e requeue if dont requeue pn requeue message items messages last index messages length last index false would block exception 3 return false catch throwable e logger error this caught e while sending messages mi name to pn get peer requeue log string e requeue if dont requeue pn requeue message items messages last index messages length last index false throwable 3 return false if one packet pn requeue message items messages i message data length i true didn t fit in single packet return false last index i if i message data length length 1 message data i length 2 count 0 else length new length return true processoutgoingorrequeue messageitem peernode dontrequeue onepacket blockedtoolongexception requeuelogstring dontrequeue requeuelogstring processoutgoingorrequeue messagedata messageitem newmsgs messageitem sessionkey getcurrentkeytracker dontrequeue messageitem ondisconnect packettracker wouldblock dontrequeue requeuemessageitems wouldblock countacks countackrequests countresendrequests callbackscount mi_name messagedata messageitem messageitem getlength mi_name getspec getname getdata packetnumber allocateoutgoingpacketnumberneverblock processoutgoingpreformatted packetnumber getpriority onsent onsent notconnectedexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems newmsgs notconnectedexception requeuemessageitems notconnectedexception wouldblockexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems newmsgs wouldblockexception requeuemessageitems wouldblockexception keychangedexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems newmsgs keychangedexception requeuemessageitems keychangedexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems newmsgs requeuemessageitems getdata messagedata getmaxpacketsize newmsgs callbackscount tostring messagedata newmessagedata messagedata newmessagedata messagedata newmessagedata newmsgs newmsgs messageitem newmsgs newmsgs asyncmessagecallback asyncmessagecallback callbackscount priority_bulk_data messageprio getpriority messageprio messageprio callbackscount illegalstateexception headers_length_minimum getmaxpacketsize messagedata mi_name innerprocessoutgoing messagedata messagedata totalmessagesize messagedata totalmessagesize messagedata totalmessagesize messagedata messageitem newmsgs mi_name getspec getname onsent onsent onsent messagedata messagedata notconnectedexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems notconnectedexception wouldblockexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems wouldblockexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems dontrequeue requeuelogstring countacks countackrequests countresendrequests lastindex messagedata messagedata thislength thislength thislength messagedata newlength thislength newlength headers_length_minimum getmaxpacketsize lastindex lastindex lastindex mi_name innerprocessoutgoing messagedata lastindex lastindex totalmessagesize lastindex totalmessagesize messagedata totalmessagesize lastindex messageitem newmsgs mi_name getspec getname onsent messagedata lastindex notconnectedexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems lastindex lastindex notconnectedexception wouldblockexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems lastindex lastindex wouldblockexception mi_name getpeer requeuelogstring dontrequeue requeuemessageitems lastindex lastindex onepacket requeuemessageitems messagedata lastindex messagedata messagedata newlength send some messages param message data an array block of messages param start index to start reading the array param length number of messages to read param buffer length size of the buffer to write into param pn node to send the messages to throws packet sequence exception private int inner process outgoing byte message data int start int length int buffer length peer node pn async message callback callbacks short priority throws not connected exception would block exception packet sequence exception if logminor logger minor this inner process outgoing start length buffer length callbacks length byte buf new byte buffer length buf 0 byte length int loc 1 for int i start i start length i byte data message data i int len data length buf loc byte len 8 buf loc byte len system arraycopy data 0 buf loc len loc len return process outgoing preformatted buf 0 loc pn callbacks priority messagedata bufferlength packetsequenceexception innerprocessoutgoing messagedata bufferlength peernode asyncmessagecallback notconnectedexception wouldblockexception packetsequenceexception innerprocessoutgoing bufferlength bufferlength messagedata processoutgoingpreformatted see freenet node outgoing packet mangler process outgoing byte int int freenet node session key int public int process outgoing byte buf int offset int length session key tracker short priority throws key changed exception not connected exception packet sequence exception would block exception byte new buf preformat buf offset length return process outgoing preformatted new buf 0 new buf length tracker 1 null priority outgoingpacketmangler processoutgoing sessionkey processoutgoing sessionkey keychangedexception notconnectedexception packetsequenceexception wouldblockexception newbuf processoutgoingpreformatted newbuf newbuf send a packet using the current key retry if it fails solely because the key changes throws packet sequence exception int process outgoing preformatted byte buf int offset int length peer node peer async message callback callbacks short priority throws not connected exception would block exception packet sequence exception session key last null while true try if peer is connected throw new not connected exception session key tracker peer get current key tracker last tracker if tracker null logger normal this dropping packet not connected to peer get peer yet 2 throw new not connected exception packet tracker packets tracker packets int seq no packets allocate outgoing packet number never block return process outgoing preformatted buf offset length tracker seq no callbacks priority catch key changed exception e logger normal this key changed 2 for peer get peer if last peer get current key tracker if peer is connected logger error this peer is connected yet current tracker is deprecated rekey e e throw new not connected exception peer is connected yet current tracker is deprecated rekey e go around again packetsequenceexception processoutgoingpreformatted peernode asyncmessagecallback notconnectedexception wouldblockexception packetsequenceexception sessionkey isconnected notconnectedexception sessionkey getcurrentkeytracker getpeer notconnectedexception packettracker seqno allocateoutgoingpacketnumberneverblock processoutgoingpreformatted seqno keychangedexception getpeer getcurrentkeytracker isconnected notconnectedexception byte preformat byte buf int offset int length byte new buf if buf null new buf new byte length 3 new buf 0 1 new buf 1 byte length 8 new buf 2 byte length system arraycopy buf offset new buf 3 length else new buf new byte 1 new buf 0 0 return new buf newbuf newbuf newbuf newbuf newbuf newbuf newbuf newbuf newbuf public int process outgoing preformatted byte buf int offset int length session key tracker int packet number async message callback callbacks short priority throws key changed exception not connected exception packet sequence exception would block exception if logminor string log process outgoing preformatted fields hash code buf offset length tracker packet number if callbacks null log null else log callbacks length arrays to string callbacks fixme too verbose logger minor this log if tracker null tracker pn is connected throw new not connected exception we do not support forgotten packets at present int acks resend requests ack requests forgot packets int seq number packet tracker packets tracker packets locking avoid allocating a packet number then a long pause due to overload during which many other packets are sent resulting in the other side asking us to resend a packet which doesn t exist yet grabbing resend reqs packet no etc must be as close together as possible however tracker allocate outgoing packet number can block so should not be locked if packet number 0 seq number packet number else if buf length 1 ack resendreq only packet seq number 1 else seq number packets allocate outgoing packet number never block if logminor logger minor this sequence number sending seq number packet number to tracker pn get peer the last sent sequence number so that we can refer to packets sent after this packet was originally sent it may be a resend int real seq number int other side seq number try synchronized tracker acks packets grab acks forgot packets packets grab forgotten resend requests packets grab resend requests ack requests packets grab ack requests real seq number packets get last outgoing seq number other side seq number packets highest received incoming seq number if logminor logger minor this sending packet to tracker pn get peer other side max seqno other side seq number catch still not acked exception e logger error this forcing disconnect on tracker pn for tracker because packets not acked after 10 minutes tracker pn force disconnect true disconnected still not acked tracker throw new not connected exception int packet length 4 seq number random bytes length random junk 1 version packet number 1 4 1 highest sent seqno 4 bytes if seqno 1 4 other side s seqno 1 number of acks acks length acks 1 number of resend reqs resend requests length resend requests 1 number of ack requests ack requests length ack requests 1 number of forgotten packets forgot packets length length the payload boolean padd this packet crypto config padd data packets int padded len if padd this packet if logminor logger minor this pre padding length packet length padding this will do an adequate job of disguising the contents and a poor but not totally worthless job of disguising the traffic fixme ideally we d mimic the size profile and the session bytes of a common protocol if packet length 64 up to 37 bytes of payload after base overhead above of 27 bytes padded size 96 128 bytes most small messages and most ack only packets padded len 64 node fast weak random next int 32 else up to 69 bytes of payload final size 128 192 bytes chk request chk insert opennet announcement chk offer swap reply up to 133 bytes of payload final size 192 256 bytes ssk request get offered chk offer ssk ssk insert request new get offered ssk up to 197 bytes of payload final size 256 320 bytes swap commit complete ssk data found new ssk insert request alt new up to 1093 bytes of payload final size 1152 1216 bytes bulk transmit block transmit time deltas ssk pubkey ssk data ssk data insert packet length 32 padded len packet length 63 64 64 padded len node fast weak random next int 64 fixme get rid of this we shouldn t be sending packets anywhere near this size unless we ve done pmtu if packet length 1280 padded len 1280 padded len 1280 int max packet size sock get max packet size if packet length max packet size padded len max packet size padded len max packet size packet length 32 padded len 32 else if logminor logger minor this don t padd the packet we have been asked not to padded len packet length if padd this packet packet length padded len if logminor logger minor this packet length packet length length byte plaintext new byte packet length byte random junk new byte random bytes length int ptr offset plaintext ptr byte seq number 24 plaintext ptr byte seq number 16 plaintext ptr byte seq number 8 plaintext ptr byte seq number if logminor logger minor this getting random junk node random next bytes random junk system arraycopy random junk 0 plaintext ptr random bytes length ptr random bytes length plaintext ptr 0 version number if seq number 1 plaintext ptr byte real seq number 24 plaintext ptr byte real seq number 16 plaintext ptr byte real seq number 8 plaintext ptr byte real seq number else plaintext ptr byte real seq number seq number plaintext ptr byte other side seq number 24 plaintext ptr byte other side seq number 16 plaintext ptr byte other side seq number 8 plaintext ptr byte other side seq number plaintext ptr byte acks length for int i 0 i acks length i int ack seq acks i if logminor logger minor this acking ack seq int offset seq other side seq number ack seq if offset seq 255 offset seq 0 throw new packet sequence exception bad ack offset offset seq seq number other side seq number ack number ack seq talking to tracker pn get peer plaintext ptr byte offset seq plaintext ptr byte resend requests length for int i 0 i resend requests length i int req seq resend requests i if logminor logger minor this resend req req seq int offset seq other side seq number req seq if offset seq 255 offset seq 0 throw new packet sequence exception bad resend request offset offset seq req seq req seq other side seq number other side seq number talking to tracker pn get peer plaintext ptr byte offset seq plaintext ptr byte ack requests length if logminor logger minor this ackrequests ack requests length for int i 0 i ack requests length i int ack req seq ack requests i if logminor logger minor this ack request i ack req seq relative to packet number we are asking them to ack a packet we sent to them int offset seq real seq number ack req seq if offset seq 255 offset seq 0 throw new packet sequence exception bad ack requests offset offset seq ack req seq ack req seq packet number real seq number talking to tracker pn get peer plaintext ptr byte offset seq byte forgot offsets null int forgot count 0 if forgot packets length 0 for int i 0 i forgot packets length i int seq forgot packets i if logminor logger minor this forgot packet i seq int offset seq real seq number seq if offset seq 255 offset seq 0 if packets is deprecated oh well logger error this dropping forgot packet notification on deprecated tracker seq on tracker real seq real seq number ignore it continue else logger error this bad forgot packet offset offset seq forgot seq seq packet number real seq number talking to tracker pn get peer new exception error else if forgot offsets null forgot offsets new byte forgot packets length i if forgot count 256 packets requeue forgot forgot packets forgot count forgot packets length forgot count break else forgot offsets forgot count byte offset seq if forgot count 256 forgot count 255 plaintext ptr byte forgot count if forgot offsets null system arraycopy forgot offsets 0 plaintext ptr forgot count ptr forgot count system arraycopy buf offset plaintext ptr length ptr length if padd this packet byte padding new byte packet length ptr node fast weak random next bytes padding system arraycopy padding 0 plaintext ptr padding length ptr padding length else if ptr plaintext length logger error this inconsistent length plaintext length buffer but ptr actual byte new buf new byte ptr system arraycopy plaintext 0 new buf 0 ptr plaintext new buf if seq number 1 byte saveable new byte length system arraycopy buf offset saveable 0 length packets sent packet saveable seq number callbacks priority if logminor logger minor this sending seq number int ret process outgoing fully formatted plaintext tracker if logminor logger minor this sent packet seq number return ret processoutgoingpreformatted sessionkey packetnumber asyncmessagecallback keychangedexception notconnectedexception packetsequenceexception wouldblockexception processoutgoingpreformatted hashcode packetnumber tostring isconnected notconnectedexception resendrequests ackrequests forgotpackets seqnumber packettracker allocateoutgoingpacketnumber packetnumber seqnumber packetnumber seqnumber seqnumber allocateoutgoingpacketnumberneverblock seqnumber packetnumber getpeer realseqnumber othersideseqnumber grabacks forgotpackets grabforgotten resendrequests grabresendrequests ackrequests grabackrequests realseqnumber getlastoutgoingseqnumber othersideseqnumber highestreceivedincomingseqnumber getpeer othersideseqnumber stillnotackedexception forcedisconnect disconnectedstillnotacked notconnectedexception packetlength random_bytes_length packetnumber resendrequests ackrequests forgotpackets paddthispacket padddatapackets paddedlen paddthispacket packetlength packetlength paddedlen fastweakrandom nextint sskinsertrequestnew sskdatafoundnew sskinsertrequestaltnew sskdata sskdatainsert packetlength paddedlen packetlength paddedlen fastweakrandom nextint packetlength paddedlen paddedlen maxpacketsize getmaxpacketsize packetlength maxpacketsize paddedlen maxpacketsize paddedlen maxpacketsize packetlength paddedlen paddedlen packetlength paddthispacket packetlength paddedlen packetlength packetlength randomjunk random_bytes_length seqnumber seqnumber seqnumber seqnumber nextbytes randomjunk randomjunk random_bytes_length random_bytes_length seqnumber realseqnumber realseqnumber realseqnumber realseqnumber realseqnumber seqnumber othersideseqnumber othersideseqnumber othersideseqnumber othersideseqnumber ackseq ackseq offsetseq othersideseqnumber ackseq offsetseq offsetseq packetsequenceexception offsetseq seqnumber othersideseqnumber acknumber ackseq getpeer offsetseq resendrequests resendrequests reqseq resendrequests reqseq offsetseq othersideseqnumber reqseq offsetseq offsetseq packetsequenceexception offsetseq reqseq reqseq othersideseqnumber othersideseqnumber getpeer offsetseq ackrequests ackrequests ackrequests ackreqseq ackrequests ackreqseq packetnumber offsetseq realseqnumber ackreqseq offsetseq offsetseq packetsequenceexception offsetseq ackreqseq ackreqseq packetnumber realseqnumber getpeer offsetseq forgotoffsets forgotcount forgotpackets forgotpackets forgotpackets offsetseq realseqnumber offsetseq offsetseq isdeprecated realseqnumber offsetseq forgotseq packetnumber realseqnumber getpeer forgotoffsets forgotoffsets forgotpackets forgotcount requeueforgot forgotpackets forgotcount forgotpackets forgotcount forgotoffsets forgotcount offsetseq forgotcount forgotcount forgotcount forgotoffsets forgotoffsets forgotcount forgotcount paddthispacket packetlength fastweakrandom nextbytes newbuf newbuf newbuf seqnumber sentpacket seqnumber seqnumber processoutgoingfullyformatted seqnumber private void disconnected still not acked session key tracker synchronized peers with problems peers with problems add tracker pn get peer if peers with problems size 1 return if node client core null node client core alerts null return node client core alerts register disconnected still not acked alert disconnectedstillnotacked sessionkey peerswithproblems peerswithproblems getpeer peerswithproblems clientcore clientcore clientcore disconnectedstillnotackedalert private user alert disconnected still not acked alert new user alert public string anchor return disconnected still not acked useralert disconnectedstillnotackedalert useralert disconnectedstillnotacked public string dismiss button text return null dismissbuttontext public short get priority class return user alert error getpriorityclass useralert public string get short text int sz synchronized peers with problems sz peers with problems size return l10n some peers disconnected still not acked count integer to string sz getshorttext peerswithproblems peerswithproblems somepeersdisconnectedstillnotacked tostring public html node gethtml text html node div new html node div peer peers synchronized peers with problems peers peers with problems to array new peer peers with problems size l10n addl10n substitution div fnp packet mangler some peers disconnected still not acked detail new string count link link new string integer to string peers length a href checked http https bugs freenetproject org a html node list div add child ul for peer peer peers list add child li peer to string return div htmlnode gethtmltext htmlnode htmlnode peerswithproblems peerswithproblems toarray peerswithproblems addl10nsubstitution fnppacketmangler somepeersdisconnectedstillnotackeddetail tostring _checked_http_ htmlnode addchild addchild tostring public string get text string buffer sb new string buffer peer peers synchronized peers with problems peers peers with problems to array new peer peers with problems size sb append l10n some peers disconnected still not acked detail new string count link link new string integer to string peers length sb append n for peer peer peers sb append t sb append peer to string sb append n return sb to string gettext stringbuffer stringbuffer peerswithproblems peerswithproblems toarray peerswithproblems somepeersdisconnectedstillnotackeddetail tostring tostring tostring public string get title return get short text gettitle getshorttext public object get user identifier return fnp packet mangler this getuseridentifier fnppacketmangler public boolean is event notification return false iseventnotification public boolean is valid return true isvalid public void is valid boolean validity ignore isvalid public void on dismiss ignore ondismiss public boolean should unregister on dismiss return false shouldunregisterondismiss public boolean user can dismiss return false usercandismiss encrypt and send a packet param plaintext the packet s plaintext including all formatting including acks and resend requests is clobbered private int process outgoing fully formatted byte plaintext session key kt block cipher session cipher kt session cipher if logminor logger minor this encrypting with hex util bytes to hex kt session key if session cipher null logger error this dropping packet send have not handshaked yet return 0 int block size session cipher get block size 3 if session cipher get key size session cipher get block size throw new illegal state exception block size must be half key size block size session cipher get block size key size session cipher get key size message digest md sha256 get message digest int digest length md get digest length if digest length block size throw new illegal state exception block size must be digest length byte output new byte plaintext length digest length system arraycopy plaintext 0 output digest length plaintext length md update plaintext logger minor this plaintext n hex util bytes to hex plaintext byte digest temp digest temp md digest sha256 return message digest md md null if logminor logger minor this n hash hex util bytes to hex digest temp put encrypted digest in output session cipher encipher digest temp digest temp now copy it back system arraycopy digest temp 0 output 0 digest length yay we have an encrypted hash if logminor logger minor this n encrypted hex util bytes to hex digest temp plaintext length bytes plaintext pcfb mode pcfb pcfb mode create session cipher digest temp pcfb block encipher output digest length plaintext length logger minor this ciphertext n hex util bytes to hex output digest length plaintext length we have a packet send it if logminor logger minor this sending packet of length output length fields hash code output to kt pn pn get peer cannot be null try send packet output kt pn get peer kt pn system err println kt pn get identity string sent packet length output length catch local address exception e logger error this tried to send data packet to local address kt pn get peer for kt pn allow local addresses kt pn sent packet return output length sock get headers length processoutgoingfullyformatted sessionkey blockcipher sessioncipher sessioncipher hexutil bytestohex sessionkey sessioncipher blocksize sessioncipher getblocksize sessioncipher getkeysize sessioncipher getblocksize illegalstateexception blocksize sessioncipher getblocksize keysize sessioncipher getkeysize messagedigest getmessagedigest digestlength getdigestlength digestlength blocksize illegalstateexception digestlength digestlength hexutil bytestohex digesttemp digesttemp returnmessagedigest nhash hexutil bytestohex digesttemp sessioncipher digesttemp digesttemp digesttemp digestlength nencrypted hexutil bytestohex digesttemp pcfbmode pcfbmode sessioncipher digesttemp blockencipher digestlength hexutil bytestohex digestlength hashcode getpeer sendpacket getpeer getidentitystring localaddressexception getpeer allowlocaladdresses sentpacket getheaderslength protected string l10n string key string patterns string values return l10n get string fnp packet mangler key patterns values getstring fnppacketmangler protected string l10n string key string pattern string value return l10n get string fnp packet mangler key pattern value getstring fnppacketmangler public void send handshake peer node pn boolean not registered int neg type pn select neg type this if neg type 1 pick a random neg type from what i do support int neg types supported neg types neg type neg types node random next int neg types length logger normal this cannot send handshake to pn because no common neg types choosing random neg type of neg type if logminor logger minor this possibly sending handshake to pn negotiation type neg type peer peer pn get handshakeip if peer null pn could not send handshake not registered return peer old peer peer peer peer drop host name if peer null logger error this no address for peer old peer so cannot send handshake pn could not send handshake not registered return sendjfk message1 pn peer pn handshake unknown initiator pn handshake setup type neg type if logminor logger minor this sending handshake to peer for pn pn sent handshake not registered sendhandshake peernode notregistered negtype selectnegtype negtype negtype negtypes supportednegtypes negtype negtypes nextint negtypes negtypes negtype negtype negtype gethandshakeip couldnotsendhandshake notregistered oldpeer drophostname oldpeer couldnotsendhandshake notregistered sendjfkmessage1 handshakeunknowninitiator handshakesetuptype negtype senthandshake notregistered see freenet node outgoing packet mangler is disconnected freenet io comm peer context public boolean is disconnected peer context context if context null return false return peer node context is connected outgoingpacketmangler isdisconnected peercontext isdisconnected peercontext peernode isconnected public void resend resend packet item item session key tracker throws packet sequence exception would block exception key changed exception not connected exception int size process outgoing preformatted item buf 0 item buf length tracker item packet number item callbacks item priority item pn resend byte counter sent bytes size resendpacketitem sessionkey packetsequenceexception wouldblockexception keychangedexception notconnectedexception processoutgoingpreformatted packetnumber resendbytecounter sentbytes public int supported neg types return new int 2 4 supportednegtypes public int full headers length one message return full headers length one message fullheaderslengthonemessage fullheaderslengthonemessage public socket handler get socket handler return sock sockethandler getsockethandler public peer get primaryip address return crypto detector get primary peers getprimaryipaddress getprimarypeers public byte get compressed noderef return crypto my compressed full ref getcompressednoderef mycompressedfullref public boolean always allow local addresses return crypto config always allow local addresses alwaysallowlocaladdresses alwaysallowlocaladdresses private diffie hellman light context genlightdiffiehellmancontext final diffie hellman light context ctx diffie hellman generate light context ctx set signature crypto sign sha256 digest assembledh params ctx my exponential crypto get crypto group return ctx diffiehellmanlightcontext _genlightdiffiehellmancontext diffiehellmanlightcontext diffiehellman generatelightcontext setsignature assembledhparams myexponential getcryptogroup private final void filljfkdhfifooffthread do it off thread node executor execute new prio runnable public void run filljfkdhfifo public int get priority return native thread high priority diffie hellman exponential signing _filljfkdhfifooffthread priorunnable _filljfkdhfifo getpriority nativethread high_priority diffiehellman do it off thread node executor execute new prio runnable public void run filljfkdhfifo priorunnable _filljfkdhfifo filljfkdhfifo public int get priority return native thread high priority _filljfkdhfifo getpriority nativethread high_priority private void filljfkdhfifo synchronized dh contextfifo if dh contextfifo size 1 dh context buffer size diffie hellman light context result null long oldest seen long max value for diffie hellman light context tmp dh contextfifo if tmp lifetime oldest seen oldest seen tmp lifetime result tmp dh contextfifo remove dh context to be prunned result dh contextfifo add last genlightdiffiehellmancontext _filljfkdhfifo dhcontextfifo dhcontextfifo dh_context_buffer_size diffiehellmanlightcontext oldestseen max_value diffiehellmanlightcontext dhcontextfifo oldestseen oldestseen dhcontextfifo dhcontexttobeprunned dhcontextfifo addlast _genlightdiffiehellmancontext change the dh exponents on a regular basis but at most once every 30sec return link diffie hellman light context private diffie hellman light context get light diffie hellman context final long now system current time millis diffie hellman light context result null synchronized dh contextfifo result dh contextfifo remove first shall we replace one element of the queue if jfkdh last generation timestamp dh generation interval now jfkdh last generation timestamp now filljfkdhfifooffthread dh contextfifo add last result logger minor this get light diffie hellman context is serving result hash code return result diffiehellmanlightcontext diffiehellmanlightcontext getlightdiffiehellmancontext currenttimemillis diffiehellmanlightcontext dhcontextfifo dhcontextfifo removefirst jfkdhlastgenerationtimestamp dh_generation_interval jfkdhlastgenerationtimestamp _filljfkdhfifooffthread dhcontextfifo addlast getlightdiffiehellmancontext hashcode used in processjfk 3 4 that s o n but we have only a few elements and we call it only once a round trip has been done param exponential return the corresponding diffie hellman light context with the right exponent private diffie hellman light context find context by exponential big integer exponential synchronized dh contextfifo for diffie hellman light context result dh contextfifo if exponential equals result my exponential return result if dh context to be prunned null dh context to be prunned my exponential equals exponential return dh context to be prunned return null diffiehellmanlightcontext diffiehellmanlightcontext findcontextbyexponential biginteger dhcontextfifo diffiehellmanlightcontext dhcontextfifo myexponential dhcontexttobeprunned dhcontexttobeprunned myexponential dhcontexttobeprunned private byte assembledh params big integer exponential dsa group group byte myexponential strip big integer to network format exponential byte mygroup group getp to byte array byte to sign new byte myexponential length mygroup length system arraycopy myexponential 0 to sign 0 myexponential length system arraycopy mygroup 0 to sign myexponential length mygroup length return to sign assembledhparams biginteger dsagroup _myexponential stripbigintegertonetworkformat _mygroup tobytearray tosign _myexponential _mygroup _myexponential tosign _myexponential _mygroup tosign _myexponential _mygroup tosign private byte assembledh params byte nonce initiator byte nonce responder big integer initiator exponential big integer responder exponential byte id byte sa byte initiatorexponential strip big integer to network format initiator exponential byte responderexponential strip big integer to network format responder exponential byte result new byte nonce initiator length nonce responder length initiatorexponential length responderexponential length id length sa length int offset 0 system arraycopy nonce initiator 0 result offset nonce initiator length offset nonce initiator length system arraycopy nonce responder 0 result offset nonce responder length offset nonce responder length system arraycopy initiatorexponential 0 result offset initiatorexponential length offset initiatorexponential length system arraycopy responderexponential 0 result offset responderexponential length offset responderexponential length system arraycopy id 0 result offset id length offset id length system arraycopy sa 0 result offset sa length return result assembledhparams nonceinitiator nonceresponder biginteger initiatorexponential biginteger responderexponential _initiatorexponential stripbigintegertonetworkformat initiatorexponential _responderexponential stripbigintegertonetworkformat responderexponential nonceinitiator nonceresponder _initiatorexponential _responderexponential nonceinitiator nonceinitiator nonceinitiator nonceresponder nonceresponder nonceresponder _initiatorexponential _initiatorexponential _initiatorexponential _responderexponential _responderexponential _responderexponential private byte get transient key synchronized authenticator cache return transient key gettransientkey authenticatorcache transientkey private byte computejfk shared key big integer exponential byte ni byte nr string what assert 0 equals what 1 equals what 2 equals what byte number null try number what get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e byte to hash new byte nonce size 2 number length int offset 0 system arraycopy ni 0 to hash offset nonce size offset nonce size system arraycopy nr 0 to hash offset nonce size offset nonce size system arraycopy number 0 to hash offset number length return hmac mac withsha256 exponential to byte array to hash hash length computejfksharedkey biginteger getbytes unsupportedencodingexception tohash nonce_size tohash nonce_size nonce_size tohash nonce_size nonce_size tohash macwithsha256 tobytearray tohash hash_length change the transient key used by jfk it will determine the pfs interval hence we call it at least once every 30mins return true if we reset the transient key and therefore the authenticator cache private boolean maybe reset transient key long now system current time millis boolean is cache too big true int authenticator cache size 0 synchronized authenticator cache authenticator cache size authenticator cache size if authenticator cache size authenticator cache size is cache too big false if now time last reset transient key rekeying min interval return false time last reset now node random next bytes transient key reset the authenticator cache authenticator cache clear node get ticker queue timed job transient key rekeyer jf kmaybe reset transitent key now transient key rekeying min interval false logger normal this jfk s transient key has been changed and the message cache flushed because is cache too big the cache is oversized authenticator cache size it s time to rekey on this return true mayberesettransientkey currenttimemillis iscachetoobig authenticatorcachesize authenticatorcache authenticatorcachesize authenticatorcache authenticatorcachesize authenticator_cache_size iscachetoobig timelastreset transient_key_rekeying_min_interval timelastreset nextbytes transientkey authenticatorcache getticker queuetimedjob transientkeyrekeyer jfkmayberesettransitentkey transient_key_rekeying_min_interval transientkey iscachetoobig authenticatorcachesize private byte strip big integer to network format big integer exponential byte data exponential to byte array int target length diffie hellman modulus length in bytes if data length target length byte new data new byte target length if data length target length 1 data 0 0 sign bit system arraycopy data 1 new data 0 target length else if data length target length system arraycopy data 0 new data target length data length data length else throw new illegal state exception too long data new data return data stripbigintegertonetworkformat biginteger tobytearray targetlength diffiehellman moduluslengthinbytes targetlength newdata targetlength targetlength newdata targetlength targetlength newdata targetlength illegalstateexception newdata public int get connectivity status if crypto config always handshake aggressively return address tracker definitely nated return sock get detected connectivity status getconnectivitystatus alwayshandshakeaggressively addresstracker definitely_nated getdetectedconnectivitystatus public boolean allow connection peer node pn freenet inet address addr return crypto allow connection pn addr allowconnection peernode freenetinetaddress allowconnection public void set port forwarding broken crypto set port forwarding broken setportforwardingbroken setportforwardingbroken logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog private boolean encoder finished false override public int hash code return hash code encoderfinished hashcode hashcode public split file fetcher segment short splitfile type clientchk splitfile data keys clientchk splitfile check keys split file fetcher fetcher archive context archive context fetch context block fetch context long max temp length int recursion level client requester requester int seg num boolean ignore last data block throws metadata parse exception fetch exception this seg num seg num this hash code super hash code this persistent fetcher persistent this parent fetcher fetcher this ignore last data block ignore last data block this errors new failure code tracker false this archive context archive context this splitfile type splitfile type this parent requester data keys splitfile data keys check keys splitfile check keys if splitfile type metadata splitfile nonredundant min fetched data keys length else if splitfile type metadata splitfile onion standard min fetched data keys length else throw new metadata parse exception unknown splitfile type splitfile type finished false decoded data null data buckets new minimal splitfile block data keys length check buckets new minimal splitfile block check keys length for int i 0 i data buckets length i data buckets i new minimal splitfile block i for int i 0 i check buckets length i check buckets i new minimal splitfile block i data buckets length data retries new int data keys length check retries new int check keys length data cooldown times new long data keys length check cooldown times new long check keys length sub segments new vector split file fetcher sub segment max block length max temp length this block fetch context block fetch context this recursion level 0 if logminor logger minor this created this for parent fetcher data retries length data blocks check retries length check blocks for int i 0 i data keys length i if data keys i null throw new null pointer exception null data block i for int i 0 i check keys length i if check keys i null throw new null pointer exception null check block i splitfilefetchersegment splitfiletype splitfiledatakeys splitfilecheckkeys splitfilefetcher archivecontext archivecontext fetchcontext blockfetchcontext maxtemplength recursionlevel clientrequester segnum ignorelastdatablock metadataparseexception fetchexception segnum segnum hashcode hashcode parentfetcher ignorelastdatablock ignorelastdatablock failurecodetracker archivecontext archivecontext splitfiletype splitfiletype datakeys splitfiledatakeys checkkeys splitfilecheckkeys splitfiletype splitfile_nonredundant minfetched datakeys splitfiletype splitfile_onion_standard minfetched datakeys metadataparseexception splitfiletype decodeddata databuckets minimalsplitfileblock datakeys checkbuckets minimalsplitfileblock checkkeys databuckets databuckets minimalsplitfileblock checkbuckets checkbuckets minimalsplitfileblock databuckets dataretries datakeys checkretries checkkeys datacooldowntimes datakeys checkcooldowntimes checkkeys subsegments splitfilefetchersubsegment maxblocklength maxtemplength blockfetchcontext blockfetchcontext recursionlevel parentfetcher dataretries checkretries datakeys datakeys nullpointerexception checkkeys checkkeys nullpointerexception public synchronized boolean is finished object container container if finished return true deactivating parent is a bad side effect so avoid it boolean deactivate parent false if persistent deactivate parent container ext is active parent if deactivate parent container activate parent 1 boolean ret parent is cancelled if deactivate parent container deactivate parent 1 return ret isfinished objectcontainer deactivateparent deactivateparent isactive deactivateparent iscancelled deactivateparent public synchronized boolean succeeded return finished public synchronized boolean is finishing object container container return is finished container finishing isfinishing objectcontainer isfinished throw a fetch exception if we have one else do nothing param container public synchronized void throw error object container container throws fetch exception if failure exception null if persistent container activate failure exception 5 if persistent throw failure exception clone we will remove caller is responsible for clone else throw failure exception fetchexception throwerror objectcontainer fetchexception failureexception failureexception failureexception failureexception decoded length param container public long decoded length object container container if persistent container activate decoded data 1 return decoded data size decodedlength objectcontainer decodeddata decodeddata write the decoded segment s data to an output stream public long write decoded data to output stream os long truncate length throws io exception long len decoded data size if truncate length 0 truncate length len len truncate length bucket tools copy to decoded data os math min truncate length decoded data size return len outputstream writedecodeddatato outputstream truncatelength ioexception decodeddata truncatelength truncatelength truncatelength buckettools copyto decodeddata truncatelength decodeddata how many blocks have failed due to running out of retries public synchronized int failed blocks return failed blocks failedblocks failedblocks how many blocks have been successfully fetched public synchronized int fetched blocks return fetched blocks fetchedblocks fetchedblocks how many blocks failed permanently due to fatal errors public synchronized int fatally failed blocks return fatally failed blocks fatallyfailedblocks fatallyfailedblocks private synchronized short on success inner bucket data int block no client key block block object container container client context context split file fetcher sub segment sub boolean dont notify boolean all failed false boolean decode now false boolean was data block false if finished happens sometimes don t complain about it what this means is simply that there were a bunch of requests running one of them completed the whole segment went into decode and now the extra requests are surplus to requirements it s a slight overhead but the alternative is worse if logminor logger minor this on success when already finished for this data free return 1 if started decode much the same if logminor logger minor this on success when started decode for this data free return 1 if block no data keys length was data block true if data keys block no null if started decode this can happen we queue a persistent download we queue a transient the transient goes through datastore checker first and feeds the block to us we don t finish because we need more blocks then the persistent goes through the datastore checker and calls us again with the same block if logminor logger minor this block already finished block no data free return 1 data retries block no 0 prevent healing of successfully fetched block if persistent container activate data keys block no 5 data keys block no remove from container data keys block no null if persistent container activate data buckets block no 1 data buckets block no set data data if persistent data store to container container store data buckets block no container store this we could return 1 so we need to store this here else if block no check keys length data keys length int check no block no data keys length if check keys check no null if started decode if logminor logger minor this check block already finished check no data free return 1 check retries check no 0 prevent healing of successfully fetched block if persistent container activate check keys check no 5 check keys check no remove from container check keys check no null if persistent container activate check buckets check no 1 check buckets check no set data data if persistent data store to container container store check buckets check no container store this we could return 1 so we need to store this here else logger error this unrecognized block number block no new exception error if started decode return 1 else boolean too small data size chk block data length don t count the last data block since we can t use it in fec decoding if too small ignore last data block block no data keys length 1 fail new fetch exception fetch exception invalid metadata block too small in splitfile block block no of data keys length data keys check keys length check keys container context true return 1 if ignore last data block block no data keys length 1 too small fetched blocks else this block is not going to be fetched and because of the insertion format thus it is a fatal failure we need to track it because it is quite possible to fetch the last block not complete because it s the last block and hang fatally failed blocks however if we manage to get every data block common on a small splitfile we don t need to fec decode if was data block fetched data blocks if logminor logger minor this fetched fetched blocks blocks in on success block no boolean have data blocks fetched data blocks data keys length decode now started decode fetched blocks min fetched have data blocks if decode now started decode true finishing true else avoid hanging when we have n 1 check blocks we succeed on the last data block we don t have the other data blocks and we have nothing else fetching all failed failed blocks fatally failed blocks data keys length check keys length min fetched dont notify scheduled short res 0 if dont notify res on success dont notify if all failed res on success all failed if decode now res on success decode now return res onsuccessinner blockno clientkeyblock objectcontainer clientcontext splitfilefetchersubsegment dontnotify allfailed decodenow wasdatablock onsuccess starteddecode onsuccess blockno datakeys wasdatablock datakeys blockno starteddecode datastorechecker datastorechecker blockno dataretries blockno datakeys blockno datakeys blockno removefrom datakeys blockno databuckets blockno databuckets blockno setdata storeto databuckets blockno blockno checkkeys datakeys checkno blockno datakeys checkkeys checkno starteddecode checkno checkretries checkno checkkeys checkno checkkeys checkno removefrom checkkeys checkno checkbuckets checkno checkbuckets checkno setdata storeto checkbuckets checkno blockno starteddecode toosmall chkblock data_length toosmall ignorelastdatablock blockno datakeys fetchexception fetchexception invalid_metadata blockno datakeys checkkeys ignorelastdatablock blockno datakeys toosmall fetchedblocks fatallyfailedblocks wasdatablock fetcheddatablocks fetchedblocks onsuccess blockno havedatablocks fetcheddatablocks datakeys decodenow starteddecode fetchedblocks minfetched havedatablocks decodenow starteddecode allfailed failedblocks fatallyfailedblocks datakeys checkkeys minfetched dontnotify dontnotify on_success_dont_notify allfailed on_success_all_failed decodenow on_success_decode_now public void on success bucket data int block no client key block block object container container client context context split file fetcher sub segment sub if persistent container activate this 1 if data null throw new null pointer exception if logminor logger minor this fetched block block no in this data data buckets length check check buckets length if parent instanceof client getter client getter parent add key to binary blob block container context no need to unregister key because it will be cleared in trip pending key short result on success inner data block no block container context sub if result short 1 return finish on success result container context onsuccess blockno clientkeyblock objectcontainer clientcontext splitfilefetchersubsegment nullpointerexception blockno databuckets checkbuckets clientgetter clientgetter addkeytobinaryblob trippendingkey onsuccessinner blockno finishonsuccess private void finish on success short result object container container client context context boolean dont notify result on success dont notify on success dont notify boolean all failed result on success all failed on success all failed boolean decode now result on success decode now on success decode now if logminor logger minor this finish on success result result dont notify dont notify all failed all failed decode now decode now if persistent container store this container activate parent 1 parent completed block dont notify container context if decode now if persistent container activate parent fetcher 1 parent fetcher remove my pending keys this container context if persistent container deactivate parent fetcher 1 remove sub segments container context false decode container context else if all failed fail new fetch exception fetch exception splitfile error errors container context true if persistent container deactivate parent 1 finishonsuccess objectcontainer clientcontext dontnotify on_success_dont_notify on_success_dont_notify allfailed on_success_all_failed on_success_all_failed decodenow on_success_decode_now on_success_decode_now finishonsuccess dontnotify dontnotify allfailed allfailed decodenow decodenow completedblock dontnotify decodenow parentfetcher parentfetcher removemypendingkeys parentfetcher removesubsegments allfailed fetchexception fetchexception splitfile_error public void decode object container container client context context if persistent container activate this 1 now decode if logminor logger minor this decoding split file fetcher segment this if persistent container store this activate buckets if persistent for int i 0 i data buckets length i container activate data buckets i 1 if persistent for int i 0 i check buckets length i container activate check buckets i 1 int data 0 for int i 0 i data buckets length i if data buckets i get data null data if data data buckets length if logminor logger minor this already decoded if persistent for int i 0 i data buckets length i container activate data buckets i get data 1 on decoded segment container context null null null data buckets check buckets return if splitfile type metadata splitfile nonredundant fec queue queue context fec queue double check int count 0 for int i 0 i data buckets length i if data buckets i get data null count for int i 0 i check buckets length i if check buckets i get data null count if count data buckets length logger error this attempting to decode but only count of data buckets length blocks available new exception error if persistent container activate parent 1 bucket last block data buckets data buckets length 1 data if last block null if persistent container activate last block 1 if ignore last data block last block size chk block data length last block free if persistent last block remove from container data buckets data buckets length 1 data null else if last block size chk block data length all new inserts will have the last block padded if it was an old insert ignore last data block would be set another way we can get here is if the last data block of a segment other than the last data block is too short fail new fetch exception fetch exception invalid metadata last data block is not the standard size container context true if codec null codec fec codec get codec splitfile type data keys length check keys length fec job job new fec job codec queue data buckets check buckets chk block data length context get bucket factory persistent this true parent get priority class persistent codec add to queue job queue container if logminor logger minor this queued fec job job if persistent container deactivate parent 1 now have all the data blocks not necessarily all the check blocks else logger error this splitfile nonredundant on decoded segment container context null null null null null objectcontainer clientcontext splitfilefetchersegment databuckets databuckets checkbuckets checkbuckets databuckets databuckets getdata databuckets databuckets databuckets getdata ondecodedsegment databuckets checkbuckets splitfiletype splitfile_nonredundant fecqueue fecqueue databuckets databuckets getdata checkbuckets checkbuckets getdata databuckets databuckets lastblock databuckets databuckets lastblock lastblock ignorelastdatablock lastblock chkblock data_length lastblock lastblock removefrom databuckets databuckets lastblock chkblock data_length ignorelastdatablock fetchexception fetchexception invalid_metadata feccodec getcodec splitfiletype datakeys checkkeys fecjob fecjob databuckets checkbuckets chkblock data_length getbucketfactory getpriorityclass addtoqueue splitfile_nonredundant ondecodedsegment public void on decoded segment object container container client context context fec job job bucket data buckets2 bucket check buckets2 splitfile block data block status splitfile block check block status if persistent container activate parent fetcher 1 container activate parent 1 container activate context 1 if codec null codec fec codec get codec splitfile type data keys length check keys length because we use splitfile block we don t have to copy here see fec callback comments for explanation try if persistent for int i 0 i data buckets length i the fec codec won t set them but they should be active if data block status i data buckets i long theirid container ext getid data block status i long ourid container ext getid data buckets i if theirid ourid logger error this db4o bug detected in decoded segment our block data buckets i block from decode data block status i both have id ourid theirid data buckets i minimal splitfile block data block status i if logminor logger minor this data block i is data buckets i if container ext is stored data buckets i logger error this data block i is not stored else if container ext is active data buckets i logger error this data block i is inactive data buckets i if data buckets i null logger error this data block i is null else if data buckets i data null logger error this data block i has null data else data buckets i data store to container container store data buckets i if is collecting binary blob for int i 0 i data buckets length i bucket data data block status i get data if data null throw new null pointer exception data bucket i of data buckets length is null try maybe add to binary blob data i false container context catch fetch exception e fail e container context false return decoded data context get bucket factory persistent make bucket max block length data buckets length if logminor logger minor this copying data from data buckets length data blocks output stream os decoded data get output stream long os size 0 for int i 0 i data buckets length i if logminor logger minor this copying data from block i splitfile block status data buckets i if status null throw new null pointer exception bucket data status get data if data null throw new null pointer exception data bucket i of data buckets length is null if persistent container activate data 1 long copied bucket tools copy to data os long max value os size copied if i data buckets length 1 copied 32768 logger error this copied only copied bytes from data bucket i if logminor logger minor this copied copied bytes from bucket i if logminor logger minor this copied data os size os close must set finished before calling parent fetcher otherwise a race is possible that might result in it not seeing our finishing finished true if persistent container store this if splitfile type metadata splitfile nonredundant is collecting binary blob parent fetcher segment finished split file fetcher segment this container context leave active before queueing catch io exception e logger normal this caught bucket error e e synchronized this finished true failure exception new fetch exception fetch exception bucket error if persistent container store this parent fetcher segment finished split file fetcher segment this container context if persistent encoder finished container context return if splitfile type metadata splitfile nonredundant if persistent container deactivate parent fetcher 1 container deactivate parent 1 container deactivate context 1 if persistent encoder finished container context return now heal splitfile healing any block which we have tried and failed to download should be reconstructed and reinserted fixme don t heal if ignore last block bucket last block data buckets data buckets length 1 data if last block null if persistent container activate last block 1 if last block size chk block data length try data buckets data buckets length 1 data bucket tools pad last block chk block data length context persistent bucket factory int last block size last block free if persistent last block remove from container data buckets data buckets length 1 store to container catch io exception e fail new fetch exception fetch exception bucket error e container context true encode any check blocks we don t have try codec add to queue new fec job codec context fec queue data buckets check buckets 32768 context get bucket factory persistent this false parent get priority class persistent context fec queue container if persistent container deactivate parent fetcher 1 container deactivate parent 1 container deactivate context 1 catch throwable t logger error this caught t t if persistent encoder finished container context ondecodedsegment objectcontainer clientcontext fecjob databuckets2 checkbuckets2 splitfileblock datablockstatus splitfileblock checkblockstatus parentfetcher feccodec getcodec splitfiletype datakeys checkkeys splitfileblock feccallback databuckets feccodec datablockstatus databuckets datablockstatus databuckets databuckets datablockstatus databuckets minimalsplitfileblock datablockstatus databuckets isstored databuckets isactive databuckets databuckets databuckets databuckets databuckets storeto databuckets iscollectingbinaryblob databuckets datablockstatus getdata nullpointerexception databuckets maybeaddtobinaryblob fetchexception decodeddata getbucketfactory makebucket maxblocklength databuckets databuckets outputstream decodeddata getoutputstream ossize databuckets splitfileblock databuckets nullpointerexception getdata nullpointerexception databuckets buckettools copyto max_value ossize databuckets ossize parentfetcher splitfiletype splitfile_nonredundant iscollectingbinaryblob parentfetcher segmentfinished splitfilefetchersegment ioexception failureexception fetchexception fetchexception bucket_error parentfetcher segmentfinished splitfilefetchersegment encoderfinished splitfiletype splitfile_nonredundant parentfetcher encoderfinished ignorelastblock lastblock databuckets databuckets lastblock lastblock lastblock chkblock data_length databuckets databuckets buckettools lastblock chkblock data_length persistentbucketfactory lastblock lastblock lastblock removefrom databuckets databuckets storeto ioexception fetchexception fetchexception bucket_error addtoqueue fecjob fecqueue databuckets checkbuckets getbucketfactory getpriorityclass fecqueue parentfetcher encoderfinished public void on encoded segment object container container client context context fec job job bucket data buckets2 bucket check buckets2 splitfile block data block status splitfile block check block status try if persistent container activate parent 1 if logminor logger minor this encoded this because we use splitfile block we don t have to copy here see fec callback comments for explanation synchronized this now insert all blocks on which we had at least one failure and didn t eventually succeed for int i 0 i data buckets length i boolean heal false if data buckets i null logger error this data bucket i is null in on encoded segment on this continue if data buckets i data block status i logger error this data block i ours is data buckets i codec s is data block status i if persistent if container ext getid data buckets i container ext getid data block status i logger error this db4o bug detected same uid for two objects data buckets i container ext getid data buckets i and data block status i container ext getid data block status i attempting workaround logger error this ours is container ext is stored data buckets i stored container ext is active data buckets i active uuid container ext getid data buckets i logger error this theirs is container ext is stored data block status i stored container ext is active data block status i active uuid container ext getid data block status i data buckets i minimal splitfile block data block status i bucket data data buckets i get data if data null logger error this data bucket i has null contents in on encoded segment on this for block data buckets i if container ext is stored data buckets i logger error this splitfile block appears not to be stored else if container ext is active data buckets i logger error this splitfile block appears not to be active continue if data retries i 0 heal true if heal queue heal data container context data buckets i data null so that it doesn t remove the data else data buckets i data free if persistent data buckets i remove from container data buckets i null if persistent data keys i null data keys i remove from container data keys i null for int i 0 i check buckets length i boolean heal false check buckets will already be active because the fec codec has been using them if check buckets i null logger error this check bucket i is null in on encoded segment on this continue if check buckets i check block status i logger error this check block i ours is check buckets i codec s is check block status i if persistent if container ext getid check buckets i container ext getid check block status i logger error this db4o bug detected same uid for two objects check buckets i container ext getid check buckets i and check block status i container ext getid check block status i attempting workaround logger error this ours is container ext is stored check buckets i stored container ext is active check buckets i active uuid container ext getid check buckets i logger error this theirs is container ext is stored check block status i stored container ext is active check block status i active uuid container ext getid check block status i check buckets i minimal splitfile block check block status i bucket data check buckets i get data if data null logger error this check bucket i has null contents in on encoded segment on this for block check buckets i if container ext is stored data buckets i logger error this splitfile block appears not to be stored else if container ext is active data buckets i logger error this splitfile block appears not to be active continue try maybe add to binary blob data i true container context catch fetch exception e fail e container context false return if check retries i 0 heal true if heal queue heal data container context check buckets i data null else data free if persistent check buckets i remove from container check buckets i null if persistent check keys i null check keys i remove from container check keys i null if persistent fetcher finished container store this defer the completion until we have generated healing blocks if we are collecting binary blobs if is collecting binary blob if persistent container activate parent fetcher 1 parent fetcher segment finished split file fetcher segment this container context if persistent container deactivate parent fetcher 1 finally if persistent encoder finished container context onencodedsegment objectcontainer clientcontext fecjob databuckets2 checkbuckets2 splitfileblock datablockstatus splitfileblock checkblockstatus splitfileblock feccallback databuckets databuckets onencodedsegment databuckets datablockstatus databuckets datablockstatus databuckets datablockstatus databuckets databuckets datablockstatus datablockstatus isstored databuckets isactive databuckets databuckets isstored datablockstatus isactive datablockstatus datablockstatus databuckets minimalsplitfileblock datablockstatus databuckets getdata onencodedsegment databuckets isstored databuckets isactive databuckets dataretries queueheal databuckets databuckets databuckets removefrom databuckets datakeys datakeys removefrom datakeys checkbuckets checkbuckets onencodedsegment checkbuckets checkblockstatus checkbuckets checkblockstatus checkbuckets checkblockstatus checkbuckets checkbuckets checkblockstatus checkblockstatus isstored checkbuckets isactive checkbuckets checkbuckets isstored checkblockstatus isactive checkblockstatus checkblockstatus checkbuckets minimalsplitfileblock checkblockstatus checkbuckets getdata onencodedsegment checkbuckets isstored databuckets isactive databuckets maybeaddtobinaryblob fetchexception checkretries queueheal checkbuckets checkbuckets removefrom checkbuckets checkkeys checkkeys removefrom checkkeys fetcherfinished iscollectingbinaryblob parentfetcher parentfetcher segmentfinished splitfilefetchersegment parentfetcher encoderfinished boolean is collecting binary blob if parent instanceof client getter client getter getter client getter parent return getter collecting binary blob else return false iscollectingbinaryblob clientgetter clientgetter clientgetter collectingbinaryblob private void maybe add to binary blob bucket data int i boolean check object container container client context context throws fetch exception if parent instanceof client getter client getter getter client getter parent if getter collecting binary blob try clientchk block block clientchk block encode data false true short 1 data size getter add key to binary blob block container context catch chk encode exception e logger error this failed to encode collecting binary blob check check data block i e e throw new fetch exception fetch exception internal error failed to encode for binary blob e catch io exception e throw new fetch exception fetch exception bucket error failed to encode for binary blob e maybeaddtobinaryblob objectcontainer clientcontext fetchexception clientgetter clientgetter clientgetter collectingbinaryblob clientchkblock clientchkblock addkeytobinaryblob chkencodeexception fetchexception fetchexception internal_error ioexception fetchexception fetchexception bucket_error queue the data for a healing insert the data will be freed when it the healing insert completes or immediately if a healing insert isn t queued if we are persistent copies the data param data param container param context private void queue heal bucket data object container container client context context if persistent try bucket copy context temp bucket factory make bucket data size bucket tools copy data copy data free if persistent data remove from container data copy catch io exception e logger normal this failed to copy data for healing e e data free if persistent data remove from container return if logminor logger minor this queueing healing insert for data on this context healing queue queue data context queueheal objectcontainer clientcontext tempbucketfactory makebucket buckettools removefrom ioexception removefrom healingqueue this is after any retries and therefore is either out of retries or fatal param container public void on fatal failure fetch exception e int block no split file fetcher sub segment seg object container container client context context if persistent container activate this 1 if logminor logger minor this permanently failed block block no on this e e boolean all failed since we can t keep the key we need to unregister for it at this point to avoid a memory leak synchronized this if is finishing container return this failure is now irrelevant and cleanup will occur on the decoder thread if block no data keys length if data keys block no null logger error this block already finished block no return if persistent container activate data keys block no 1 data keys block no remove from container data keys block no null else if block no check keys length data keys length if check keys block no data keys length null logger error this check block already finished block no return if persistent container activate check keys block no data keys length 1 check keys block no data keys length remove from container check keys block no data keys length null else logger error this unrecognized block number block no new exception error boolean deactivate parent false can get called from wierd places don t deactivate parent if not necessary if persistent deactivate parent container ext is active parent if deactivate parent container activate parent 1 if e is fatal fatally failed blocks parent fatally failed block container context else failed blocks parent failed block container context if deactivate parent container deactivate parent 1 once it is no longer possible to have a successful fetch fail all failed failed blocks fatally failed blocks data keys length check keys length min fetched if persistent container store this if all failed fail new fetch exception fetch exception splitfile error errors container context false else if seg null if seg possibly remove from parent container context seg kill container context true true onfatalfailure fetchexception blockno splitfilefetchersubsegment objectcontainer clientcontext blockno allfailed isfinishing blockno datakeys datakeys blockno blockno datakeys blockno datakeys blockno removefrom datakeys blockno blockno checkkeys datakeys checkkeys blockno datakeys blockno checkkeys blockno datakeys checkkeys blockno datakeys removefrom checkkeys blockno datakeys blockno deactivateparent deactivateparent isactive deactivateparent isfatal fatallyfailedblocks fatallyfailedblock failedblocks failedblock deactivateparent allfailed failedblocks fatallyfailedblocks datakeys checkkeys minfetched allfailed fetchexception fetchexception splitfile_error possiblyremovefromparent a request has failed non fatally so the block may be retried param container public void on non fatal failure fetch exception e int block no split file fetcher sub segment seg object container container client context context if persistent container activate block fetch context 1 int max tries block fetch context max non splitfile retries request scheduler sched context get fetch scheduler false seg remove block num block no container false split file fetcher sub segment sub on non fatal failure e block no seg container context sched max tries if sub null sub reschedule container context if persistent sub seg container deactivate sub 1 onnonfatalfailure fetchexception blockno splitfilefetchersubsegment objectcontainer clientcontext blockfetchcontext maxtries blockfetchcontext maxnonsplitfileretries requestscheduler getfetchscheduler removeblocknum blockno splitfilefetchersubsegment onnonfatalfailure blockno maxtries public void on non fatal failure fetch exception failures int block nos split file fetcher sub segment seg object container container client context context if persistent container activate block fetch context 1 int max tries block fetch context max non splitfile retries request scheduler sched context get fetch scheduler false hash set split file fetcher sub segment to schedule null seg remove block nums block nos container for int i 0 i failures length i split file fetcher sub segment sub on non fatal failure failures i block nos i seg container context sched max tries if sub null if to schedule null to schedule new hash set split file fetcher sub segment to schedule add sub if to schedule null to schedule is empty for split file fetcher sub segment sub to schedule sub reschedule container context if persistent sub seg container deactivate sub 1 onnonfatalfailure fetchexception blocknos splitfilefetchersubsegment objectcontainer clientcontext blockfetchcontext maxtries blockfetchcontext maxnonsplitfileretries requestscheduler getfetchscheduler hashset splitfilefetchersubsegment toschedule removeblocknums blocknos splitfilefetchersubsegment onnonfatalfailure blocknos maxtries toschedule toschedule hashset splitfilefetchersubsegment toschedule toschedule toschedule isempty splitfilefetchersubsegment toschedule caller must set this iff returns true private split file fetcher sub segment on non fatal failure fetch exception e int block no split file fetcher sub segment seg object container container client context context request scheduler sched int max tries if logminor logger minor this calling on non fatal failure for block block no on this from seg int tries boolean failed false boolean cooldown false clientchk key split file fetcher sub segment sub null synchronized this if is finished container return null if block no data keys length key data keys block no if persistent container activate key 5 tries data retries block no if tries max tries max tries 0 failed true else sub get sub segment tries container false seg if tries request scheduler cooldown retries 0 long now system current time millis if data cooldown times block no now logger error this already on the cooldown queue for this data block no block no new exception error else data cooldown times block no sched queue cooldown key sub container cooldown true else int check no block no data keys length key check keys check no if persistent container activate key 5 tries check retries check no if tries max tries max tries 0 failed true else sub get sub segment tries container false seg if tries request scheduler cooldown retries 0 long now system current time millis if check cooldown times check no now logger error this already on the cooldown queue for this check block no block no new exception error else check cooldown times check no sched queue cooldown key sub container cooldown true if tries seg retry count 1 logger error this failed on segment seg but tries for block block no after increment is tries if failed on fatal failure e block no seg container context if logminor logger minor this not retrying block block no on this tries tries max tries return null boolean must schedule false if cooldown registered to cooldown queue if logminor logger minor this added to cooldown queue key for this was on segment seg now registered to sub else if we are here we are going to retry must schedule sub add block no container context false if logminor logger minor this retrying block block no on this tries tries max tries sub if persistent container store this container deactivate key 5 if must schedule return sub else return null splitfilefetchersubsegment onnonfatalfailure fetchexception blockno splitfilefetchersubsegment objectcontainer clientcontext requestscheduler maxtries onnonfatalfailure blockno splitfilefetchersubsegment isfinished blockno datakeys datakeys blockno dataretries blockno maxtries maxtries getsubsegment requestscheduler cooldown_retries currenttimemillis datacooldowntimes blockno blockno datacooldowntimes blockno queuecooldown checkno blockno datakeys checkkeys checkno checkretries checkno maxtries maxtries getsubsegment requestscheduler cooldown_retries currenttimemillis checkcooldowntimes checkno blockno checkcooldowntimes checkno queuecooldown retrycount blockno onfatalfailure blockno blockno maxtries mustschedule mustschedule blockno blockno maxtries mustschedule private split file fetcher sub segment get sub segment int retry count object container container boolean no create split file fetcher sub segment dont deactivate split file fetcher sub segment sub if persistent container activate sub segments 1 split file fetcher sub segment ret null int dupes 0 synchronized this for int i 0 i sub segments size i sub sub segments get i if persistent container activate sub 1 if sub retry count retry count if ret null logger error this duplicate subsegment count dupes ret and sub for retry count retry count on this dupes else ret sub if persistent sub ret sub dont deactivate container deactivate sub 1 if ret null return ret if no create return null boolean deactivate parent false if persistent deactivate parent container ext is active parent if deactivate parent container activate parent 1 sub new split file fetcher sub segment this parent retry count if deactivate parent container deactivate parent 1 sub segments add sub if persistent container ext store sub segments 1 return sub splitfilefetchersubsegment getsubsegment retrycount objectcontainer nocreate splitfilefetchersubsegment dontdeactivate splitfilefetchersubsegment subsegments splitfilefetchersubsegment subsegments subsegments retrycount retrycount retrycount dontdeactivate nocreate deactivateparent deactivateparent isactive deactivateparent splitfilefetchersubsegment retrycount deactivateparent subsegments subsegments void fail fetch exception e object container container client context context boolean dont deactivate parent synchronized this if finished return finished true this failure exception e if started decode logger error this failing with e but already started decode e return for int i 0 i data buckets length i minimal splitfile block b data buckets i if persistent container activate b 2 if b null bucket d b get data if d null d free if persistent b remove from container data buckets i null if persistent data keys i null data keys i remove from container data keys i null for int i 0 i check buckets length i minimal splitfile block b check buckets i if persistent container activate b 2 if b null bucket d b get data if d null d free if persistent b remove from container check buckets i null if persistent check keys i null check keys i remove from container check keys i null remove sub segments container context false if persistent container store this container activate parent fetcher 1 parent fetcher remove my pending keys this container context parent fetcher segment finished this container context if persistent dont deactivate parent container deactivate parent fetcher 1 fetchexception objectcontainer clientcontext dontdeactivateparent failureexception starteddecode databuckets minimalsplitfileblock databuckets getdata removefrom databuckets datakeys datakeys removefrom datakeys checkbuckets minimalsplitfileblock checkbuckets getdata removefrom checkbuckets checkkeys checkkeys removefrom checkkeys removesubsegments parentfetcher parentfetcher removemypendingkeys parentfetcher segmentfinished dontdeactivateparent parentfetcher public split file fetcher sub segment schedule object container container client context context if persistent container activate this 1 try split file fetcher sub segment seg get sub segment 0 container false null if persistent container activate seg 1 seg add all data retries length check retries length container context false if logminor logger minor this scheduling seg seg block nums synchronized this scheduled true if persistent container store this if persistent container deactivate seg 1 return seg catch throwable t logger error this caught t scheduling this t fail new fetch exception fetch exception internal error t container context true return null splitfilefetchersubsegment objectcontainer clientcontext splitfilefetchersubsegment getsubsegment addall dataretries checkretries blocknums fetchexception fetchexception internal_error public void cancel object container container client context context fail new fetch exception fetch exception cancelled container context true objectcontainer clientcontext fetchexception fetchexception public void on block set finished client get state state ignore irrelevant onblocksetfinished clientgetstate public void on transition client get state old state client get state new state ignore ontransition clientgetstate oldstate clientgetstate newstate public synchronized clientchk get block key int block num object container container clientchk ret if block num 0 return null else if block num data keys length ret data keys block num else if block num data keys length check keys length ret check keys block num data keys length else return null if persistent container activate ret 5 return ret getblockkey blocknum objectcontainer blocknum blocknum datakeys datakeys blocknum blocknum datakeys checkkeys checkkeys blocknum datakeys public nodechk get block node key int block num object container container clientchk key get block key block num container if key null return key get nodechk else return null getblocknodekey blocknum objectcontainer getblockkey blocknum getnodechk double check whether we need to remove a subsegment and if so remove it we need to do the check because there is no point removing the subsegment until all its running requests have been removed since request data structures will refer to it anyway and all the requests on the cooldown queue for it have been removed in either case we get duplicated structures in memory return true if we removed the subsegment public synchronized boolean maybe remove seg split file fetcher sub segment segment object container container int retry count segment retry count boolean dont remove true for int i 0 i data retries length i if data retries i retry count dont remove false break for int i 0 i check retries length i if check retries i retry count dont remove false break if is finishing container dont remove false if dont remove return false if logminor logger minor this removing sub segment segment for retry count retry count if persistent container activate sub segments 1 for int i 0 i sub segments size i if segment equals sub segments get i sub segments remove i i if persistent container store sub segments return true mayberemoveseg splitfilefetchersubsegment objectcontainer retrycount retrycount dontremove dataretries dataretries retrycount dontremove checkretries checkretries retrycount dontremove isfinishing dontremove dontremove retrycount subsegments subsegments subsegments subsegments subsegments private void remove sub segments object container container client context context boolean finishing if persistent container activate sub segments 1 split file fetcher sub segment dead segs synchronized this dead segs sub segments to array new split file fetcher sub segment sub segments size sub segments clear if persistent dead segs length 0 container store this for int i 0 i dead segs length i if persistent container activate dead segs i 1 dead segs i kill container context true false context get chk fetch scheduler remove from starter queue dead segs i container true if persistent container deactivate dead segs i 1 if persistent finishing container store this container store sub segments removesubsegments objectcontainer clientcontext subsegments splitfilefetchersubsegment deadsegs deadsegs subsegments toarray splitfilefetchersubsegment subsegments subsegments deadsegs deadsegs deadsegs deadsegs getchkfetchscheduler removefromstarterqueue deadsegs deadsegs subsegments public synchronized long get cooldown wakeup int block num if block num data keys length return data cooldown times block num else return check cooldown times block num data keys length getcooldownwakeup blocknum blocknum datakeys datacooldowntimes blocknum checkcooldowntimes blocknum datakeys return true if the key was wanted false otherwise public boolean requeue after cooldown key key long time object container container client context context split file fetcher sub segment dont deactivate if persistent container activate this 1 vector split file fetcher sub segment v null boolean not found true synchronized this if is finishing container return false int max tries block fetch context max non splitfile retries for int i 0 i data keys length i if data keys i null continue client key k data keys i if persistent container activate k 5 if k get node key equals key if data cooldown times i time if logminor logger minor this not retrying after cooldown for data block i as deadline has not passed yet on this remaining time data cooldown times i time ms return false int tries data retries i split file fetcher sub segment sub get sub segment tries container false dont deactivate if logminor logger minor this retrying after cooldown on this data block i on this tries tries max tries sub if v null v new vector split file fetcher sub segment we always schedule fixme only schedule if sub add returns true sub add i container context true if v contains sub v add sub not found false else if persistent container deactivate k 5 for int i 0 i check keys length i if check keys i null continue client key k check keys i if persistent container activate k 5 if k get node key equals key if check cooldown times i time if logminor logger minor this not retrying after cooldown for check block i as deadline has not passed yet on this remaining time check cooldown times i time ms return false int tries check retries i split file fetcher sub segment sub get sub segment tries container false dont deactivate if logminor logger minor this retrying after cooldown on this check block i on this tries tries max tries sub if v null v new vector split file fetcher sub segment sub add i data keys length container context true if v contains sub v add sub not found false else if persistent container deactivate k 5 if not found logger error this requeue after cooldown key not found key on this if v null for int i 0 i v size i split file fetcher sub segment sub v get i if persistent sub dont deactivate container activate sub 1 random grab array rga sub get parent grab array if rga null sub reschedule container context else if logminor if persistent container activate rga 1 if rga contains sub container logger error this sub segment has rga but isn t registered to it sub for rga sub reschedule container context if persistent container deactivate rga 1 if persistent sub dont deactivate container deactivate sub 1 return true requeueaftercooldown objectcontainer clientcontext splitfilefetchersubsegment dontdeactivate splitfilefetchersubsegment notfound isfinishing maxtries blockfetchcontext maxnonsplitfileretries datakeys datakeys clientkey datakeys getnodekey datacooldowntimes datacooldowntimes dataretries splitfilefetchersubsegment getsubsegment dontdeactivate maxtries splitfilefetchersubsegment notfound checkkeys checkkeys clientkey checkkeys getnodekey checkcooldowntimes checkcooldowntimes checkretries splitfilefetchersubsegment getsubsegment dontdeactivate maxtries splitfilefetchersubsegment datakeys notfound notfound requeueaftercooldown splitfilefetchersubsegment dontdeactivate randomgrabarray getparentgrabarray dontdeactivate public synchronized long get cooldown wakeup by key key key object container container for int i 0 i data keys length i if data keys i null continue client key k data keys i if persistent container activate k 5 if k get node key equals key return data cooldown times i else if persistent container deactivate k 5 for int i 0 i check keys length i if check keys i null continue client key k check keys i if persistent container activate k 5 if check keys i get node key equals key return check cooldown times i else if persistent container deactivate k 5 return 1 getcooldownwakeupbykey objectcontainer datakeys datakeys clientkey datakeys getnodekey datacooldowntimes checkkeys checkkeys clientkey checkkeys checkkeys getnodekey checkcooldowntimes public synchronized int get block number key key object container container for int i 0 i data keys length i clientchk k data keys i if k null continue if persistent container activate k 5 if k get routing key null throw new null pointer exception routing key is null yet key exists for data block i of this persistent stored container ext is stored k active container ext is active k if k get node key equals key return i else if persistent container deactivate k 5 for int i 0 i check keys length i clientchk k check keys i if k null continue if persistent container activate k 5 if k get routing key null throw new null pointer exception routing key is null yet key exists for check block i of this if k get node key equals key return data keys length i else if persistent container deactivate k 5 return 1 getblocknumber objectcontainer datakeys datakeys getroutingkey nullpointerexception isstored isactive getnodekey checkkeys checkkeys getroutingkey nullpointerexception getnodekey datakeys public synchronized integer get key numbers at retry level int retry count vector integer v new vector integer for int i 0 i data retries length i if data keys i null continue if data retries i retry count v add integer value of i for int i 0 i check retries length i if check keys i null continue if check retries i retry count v add integer value of i data keys length return v to array new integer v size getkeynumbersatretrylevel retrycount dataretries datakeys dataretries retrycount valueof checkretries checkkeys checkretries retrycount valueof datakeys toarray public synchronized void reset cooldown times integer block nums for int i 0 i block nums length i int block no block nums i int value if block no data cooldown times length data cooldown times block no 1 else check cooldown times block no data cooldown times length 1 resetcooldowntimes blocknums blocknums blockno blocknums intvalue blockno datacooldowntimes datacooldowntimes blockno checkcooldowntimes blockno datacooldowntimes public void on failed throwable t object container container client context context synchronized this if finished logger error this fec decode or encode failed but already finished t t return finished true if persistent container activate this 1 this fail new fetch exception fetch exception internal error fec failure t t container context false onfailed objectcontainer clientcontext fetchexception fetchexception internal_error public boolean have block int block no object container container if block no data buckets length boolean was active false if data buckets block no null return false if persistent was active container ext is active data buckets block no if was active container activate data buckets block no 1 boolean retval data buckets block no has data if persistent was active container deactivate data buckets block no 1 return retval else boolean was active false block no data buckets length if check buckets block no null return false if persistent was active container ext is active check buckets block no if was active container activate check buckets block no 1 boolean retval check buckets block no has data if persistent was active container deactivate check buckets block no 1 return retval haveblock blockno objectcontainer blockno databuckets wasactive databuckets blockno wasactive isactive databuckets blockno wasactive databuckets blockno databuckets blockno hasdata wasactive databuckets blockno wasactive blockno databuckets checkbuckets blockno wasactive isactive checkbuckets blockno wasactive checkbuckets blockno checkbuckets blockno hasdata wasactive checkbuckets blockno public boolean dont cache object container container return block fetch context cache local requests dontcache objectcontainer blockfetchcontext cachelocalrequests public short get priority class object container container if persistent container activate parent 1 return parent priority class getpriorityclass objectcontainer priorityclass public sendable get get request key key object container container int block num this get block number key container if block num 0 return null int retry count get block retry count block num return get sub segment retry count container false null sendableget getrequest objectcontainer blocknum getblocknumber blocknum retrycount getblockretrycount blocknum getsubsegment retrycount public boolean is cancelled object container container return is finishing container iscancelled objectcontainer isfinishing public key list keys object container container vector key v new vector key synchronized this for int i 0 i data keys length i if data keys i null if persistent container activate data keys i 5 v add data keys i get node key for int i 0 i check keys length i if check keys i null if persistent container activate check keys i 5 v add check keys i get node key return v to array new key v size listkeys objectcontainer datakeys datakeys datakeys datakeys getnodekey checkkeys checkkeys checkkeys checkkeys getnodekey toarray return true if we fetched a block hold the lock for the whole duration of this method if a transient request has two copies of on got key run in parallel we want only one of them to return true otherwise sffkl will remove the keys from the main bloom filter twice resulting in collateral damage to other overlapping keys and then not in bloom filter errors or worse false negatives public boolean on got key key key key block block object container container client context context clientchk block cb null int block num bucket data null split file fetcher sub segment seg short on success result short 1 boolean kill seg false fetch exception fatal null synchronized this if finished started decode fetcher finished return false block num this get block number key container if block num 0 return false if logminor logger minor this found key for block block num on this in on got key for key clientchk ckey this get block key block num container int retry count get block retry count block num seg this get sub segment retry count container true null if persistent container activate seg 1 if seg null seg remove block num block num container false kill seg seg possibly remove from parent container context for int i 0 i sub segments size i split file fetcher sub segment check seg sub segments get i if check seg seg continue if persistent container activate check seg 1 if check seg remove block num block num container false logger error this block number block num was registered to wrong subsegment check seg should be seg if persistent container deactivate check seg 1 try cb new clientchk block chk block block ckey catch chk verify exception e fatal new fetch exception fetch exception block decode error e if cb null data extract cb block num container context if data null if logminor logger minor this extract failed return false else this can be done safely inside the lock if parent instanceof client getter client getter parent add key to binary blob cb container context if cb is metadata we must remove the keys before we exit the synchronized block thus ensuring that the next call will return false and the keys will only be removed from the bloom filter once on success result on success inner data block num cb container context seg if kill seg seg kill container context true true if persistent container deactivate seg 1 if fatal null this on fatal failure fatal block num null container context return false else if data null return false extract failed else cb null if cb is metadata if on success result short 1 finish on success on success result container context return true else on fatal failure new fetch exception fetch exception invalid metadata metadata where expected data block num null container context return true ongotkey ongotkey keyblock objectcontainer clientcontext clientchkblock blocknum splitfilefetchersubsegment onsuccessresult killseg fetchexception starteddecode fetcherfinished blocknum getblocknumber blocknum blocknum ongotkey getblockkey blocknum retrycount getblockretrycount blocknum getsubsegment retrycount removeblocknum blocknum killseg possiblyremovefromparent subsegments splitfilefetchersubsegment checkseg subsegments checkseg checkseg checkseg removeblocknum blocknum blocknum checkseg checkseg clientchkblock chkblock chkverifyexception fetchexception fetchexception block_decode_error blocknum clientgetter clientgetter addkeytobinaryblob ismetadata onsuccessresult onsuccessinner blocknum killseg onfatalfailure blocknum ismetadata onsuccessresult finishonsuccess onsuccessresult onfatalfailure fetchexception fetchexception invalid_metadata blocknum private int get block retry count int block num if block num data retries length return data retries block num block num data retries length return check retries block num getblockretrycount blocknum blocknum dataretries dataretries blocknum blocknum dataretries checkretries blocknum convert a client key block to a bucket if an error occurs report it via on failure and return null protected bucket extract client key block block int block num object container container client context context bucket data try data block decode context get bucket factory persistent int math min this block fetch context max output length integer max value false catch key decode exception e1 if logminor logger minor this decode failure e1 e1 this on fatal failure new fetch exception fetch exception block decode error e1 get message block num null container context return null catch too big exception e this on fatal failure new fetch exception fetch exception too big e get message block num null container context return null catch io exception e logger error this could not capture data disk full e e this on fatal failure new fetch exception fetch exception bucket error e block num null container context return null if logminor logger minor this data null could not decode null decoded data size bytes return data clientkeyblock onfailure clientkeyblock blocknum objectcontainer clientcontext getbucketfactory blockfetchcontext maxoutputlength max_value keydecodeexception onfatalfailure fetchexception fetchexception block_decode_error getmessage blocknum toobigexception onfatalfailure fetchexception fetchexception too_big getmessage blocknum ioexception onfatalfailure fetchexception fetchexception bucket_error blocknum public boolean persistent return persistent public void deactivate keys object container container for int i 0 i data keys length i container deactivate data keys i 1 for int i 0 i check keys length i container deactivate check keys i 1 deactivatekeys objectcontainer datakeys datakeys checkkeys checkkeys public split file fetcher sub segment get sub segment for int block num object container container return get sub segment get block retry count block num container false null splitfilefetchersubsegment getsubsegmentfor blocknum objectcontainer getsubsegment getblockretrycount blocknum public void free decoded data object container container if persistent container activate decoded data 1 decoded data free if persistent decoded data remove from container decoded data null if persistent container store this freedecodeddata objectcontainer decodeddata decodeddata decodeddata removefrom decodeddata public void remove from object container container client context context if logminor logger minor this removing this if decoded data null free decoded data container remove sub segments container context true container delete sub segments for int i 0 i data keys length i if data keys i null data keys i remove from container data keys i null for int i 0 i check keys length i if check keys i null check keys i remove from container check keys i null for int i 0 i data buckets length i minimal splitfile block block data buckets i if block null continue if block data null logger error this data block i still present in remove from on this block data free block remove from container for int i 0 i check buckets length i minimal splitfile block block check buckets i if block null continue if block data null logger error this check block i still present in remove from on this block data free block remove from container container activate errors 1 errors remove from container if failure exception null container activate failure exception 5 failure exception remove from container container delete this removefrom objectcontainer clientcontext decodeddata freedecodeddata removesubsegments subsegments datakeys datakeys datakeys removefrom datakeys checkkeys checkkeys checkkeys removefrom checkkeys databuckets minimalsplitfileblock databuckets removefrom removefrom checkbuckets minimalsplitfileblock checkbuckets removefrom removefrom removefrom failureexception failureexception failureexception removefrom public void fetcher finished object container container client context context synchronized this fetcher finished true if encoder finished if started decode encoder finished true container store this else container store this if logminor logger minor this fetcher finished but encoder not finished on this return remove from container context fetcherfinished objectcontainer clientcontext fetcherfinished encoderfinished starteddecode encoderfinished removefrom private void encoder finished object container container client context context synchronized this encoder finished true if fetcher finished container store this if logminor logger minor this encoder finished but fetcher not finished on this return remove from container context encoderfinished objectcontainer clientcontext encoderfinished fetcherfinished removefrom creates and initializes a new xml element calling the construction is equivalent to ul code new xml element new hashtable false true code ul dl dt b postconditions b dt dd ul li count children 0 li enumerate children empty enumeration li enumerate property names empty enumeration li get children empty vector li get content li get line nr 0 li get name null ul dd dl see nanoxml xml element xml element java util hashtable xml element hashtable see nanoxml xml element xml element boolean see nanoxml xml element xml element java util hashtable boolean xml element hashtable boolean public xml element this new hashtable false true true xmlelement countchildren enumeratechildren enumeratepropertynames getchildren getcontent getlinenr getname xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement creates and initializes a new xml element calling the construction is equivalent to ul code new xml element entities false true code ul param entities the entity conversion table dl dl dt b preconditions b dt dd ul li code entities null code ul dd dl dl dt b postconditions b dt dd ul li count children 0 li enumerate children empty enumeration li enumerate property names empty enumeration li get children empty vector li get content li get line nr 0 li get name null ul dd dl dl see nanoxml xml element xml element see nanoxml xml element xml element boolean see nanoxml xml element xml element java util hashtable boolean xml element hashtable boolean public xml element hashtable entities2 this entities2 false true true xmlelement countchildren enumeratechildren enumeratepropertynames getchildren getcontent getlinenr getname xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement creates and initializes a new xml element calling the construction is equivalent to ul code new xml element new hashtable skip leading whitespace true code ul param skip leading whitespace code true code if leading and trailing whitespace in pcdata content has to be removed dl dl dt b postconditions b dt dd ul li count children 0 li enumerate children empty enumeration li enumerate property names empty enumeration li get children empty vector li get content li get line nr 0 li get name null ul dd dl dl see nanoxml xml element xml element see nanoxml xml element xml element java util hashtable xml element hashtable see nanoxml xml element xml element java util hashtable boolean xml element hashtable boolean public xml element boolean skip leading whitespace this new hashtable skip leading whitespace true true xmlelement skipleadingwhitespace skipleadingwhitespace countchildren enumeratechildren enumeratepropertynames getchildren getcontent getlinenr getname xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement skipleadingwhitespace skipleadingwhitespace creates and initializes a new xml element calling the construction is equivalent to ul code new xml element entities skip leading whitespace true code ul param entities the entity conversion table param skip leading whitespace code true code if leading and trailing whitespace in pcdata content has to be removed dl dl dt b preconditions b dt dd ul li code entities null code ul dd dl dl dt b postconditions b dt dd ul li count children 0 li enumerate children empty enumeration li enumerate property names empty enumeration li get children empty vector li get content li get line nr 0 li get name null ul dd dl dl see nanoxml xml element xml element see nanoxml xml element xml element boolean see nanoxml xml element xml element java util hashtable xml element hashtable public xml element hashtable entities2 boolean skip leading whitespace this entities2 skip leading whitespace true true xmlelement skipleadingwhitespace skipleadingwhitespace countchildren enumeratechildren enumeratepropertynames getchildren getcontent getlinenr getname xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement skipleadingwhitespace skipleadingwhitespace creates and initializes a new xml element param entities the entity conversion table param skip leading whitespace code true code if leading and trailing whitespace in pcdata content has to be removed param ignore case code true code if the case of element and attribute names have to be ignored dl dl dt b preconditions b dt dd ul li code entities null code ul dd dl dl dt b postconditions b dt dd ul li count children 0 li enumerate children empty enumeration li enumerate property names empty enumeration li get children empty vector li get content li get line nr 0 li get name null ul dd dl dl see nanoxml xml element xml element see nanoxml xml element xml element boolean see nanoxml xml element xml element java util hashtable xml element hashtable see nanoxml xml element xml element java util hashtable boolean xml element hashtable boolean public xml element hashtable entities2 boolean skip leading whitespace boolean ignore case2 this entities2 skip leading whitespace true ignore case2 skipleadingwhitespace ignorecase countchildren enumeratechildren enumeratepropertynames getchildren getcontent getlinenr getname xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement xmlelement skipleadingwhitespace ignorecase2 skipleadingwhitespace ignorecase2 creates and initializes a new xml element p this constructor should i only i be called from link create another element create another element to create child elements param entities the entity conversion table param skip leading whitespace code true code if leading and trailing whitespace in pcdata content has to be removed param fill basic conversion table code true code if the basic entities need to be added to the entity list param ignore case code true code if the case of element and attribute names have to be ignored dl dl dt b preconditions b dt dd ul li code entities null code li if code fill basic conversion table false code then code entities code contains at least the following entries code amp code code lt code code gt code code apos code and code quot code ul dd dl dl dt b postconditions b dt dd ul li count children 0 li enumerate children empty enumeration li enumerate property names empty enumeration li get children empty vector li get content li get line nr 0 li get name null ul dd dl dl see nanoxml xml element create another element protected xml element hashtable entities2 boolean skip leading whitespace boolean fill basic conversion table boolean ignore case2 this ignore whitespace skip leading whitespace this ignore case ignore case2 this name null this contents this attributes new hashtable string string this children new vector xml element this entities entities2 this line nr 0 enumeration e this entities keys while e has more elements object key e next element object value this entities get key if value instanceof string value string value to char array this entities put key value if fill basic conversion table this entities put amp new char this entities put quot new char this entities put apos new char this entities put lt new char this entities put gt new char createanotherelement createanotherelement skipleadingwhitespace fillbasicconversiontable ignorecase fillbasicconversiontable countchildren enumeratechildren enumeratepropertynames getchildren getcontent getlinenr getname xmlelement createanotherelement xmlelement skipleadingwhitespace fillbasicconversiontable ignorecase2 ignorewhitespace skipleadingwhitespace ignorecase ignorecase2 xmlelement linenr hasmoreelements nextelement tochararray fillbasicconversiontable adds a child element param child the child element to add dl dl dt b preconditions b dt dd ul li code child null code li code child get name null code li code child code does not have a parent element ul dd dl dl dt b postconditions b dt dd ul li count children old count children 1 li enumerate children old enumerate children child li get children old enumerate children child ul dd dl dl see nanoxml xml element count children see nanoxml xml element enumerate children see nanoxml xml element get children see nanoxml xml element remove child nanoxml xml element remove child xml element public void add child xml element child this children add element child getname countchildren countchildren enumeratechildren enumeratechildren getchildren enumeratechildren xmlelement countchildren xmlelement enumeratechildren xmlelement getchildren xmlelement removechild xmlelement removechild xmlelement addchild xmlelement addelement adds or modifies an attribute param name the name of the attribute param value the value of the attribute dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier li code value null code ul dd dl dl dt b postconditions b dt dd ul li enumerate attribute names old enumerate attribute names name li get attribute name value ul dd dl dl see nanoxml xml element set double attribute java lang string double set double attribute string double see nanoxml xml element set int attribute java lang string int set int attribute string int see nanoxml xml element enumerate attribute names see nanoxml xml element get attribute java lang string get attribute string see nanoxml xml element get attribute java lang string java lang object get attribute string object see nanoxml xml element get attribute java lang string java util hashtable java lang string boolean get attribute string hashtable string boolean see nanoxml xml element get string attribute java lang string get string attribute string see nanoxml xml element get string attribute java lang string java lang string get string attribute string string see nanoxml xml element get string attribute java lang string java util hashtable java lang string boolean get string attribute string hashtable string boolean public void set attribute string name object value if this ignore case name name to upper case this attributes put name value to string enumerateattributenames enumerateattributenames getattribute xmlelement setdoubleattribute setdoubleattribute xmlelement setintattribute setintattribute xmlelement enumerateattributenames xmlelement getattribute getattribute xmlelement getattribute getattribute xmlelement getattribute getattribute xmlelement getstringattribute getstringattribute xmlelement getstringattribute getstringattribute xmlelement getstringattribute getstringattribute setattribute ignorecase touppercase tostring adds or modifies an attribute param name the name of the attribute param value the value of the attribute dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl dt b postconditions b dt dd ul li enumerate attribute names old enumerate attribute names name li get int attribute name value ul dd dl dl see nanoxml xml element set double attribute java lang string double set double attribute string double see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element enumerate attribute names see nanoxml xml element get int attribute java lang string get int attribute string see nanoxml xml element get int attribute java lang string int get int attribute string int see nanoxml xml element get int attribute java lang string java util hashtable java lang string boolean get int attribute string hashtable string boolean public void set int attribute string name int value if this ignore case name name to upper case this attributes put name integer to string value enumerateattributenames enumerateattributenames getintattribute xmlelement setdoubleattribute setdoubleattribute xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement enumerateattributenames xmlelement getintattribute getintattribute xmlelement getintattribute getintattribute xmlelement getintattribute getintattribute setintattribute ignorecase touppercase tostring adds or modifies an attribute param name the name of the attribute param value the value of the attribute dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl dt b postconditions b dt dd ul li enumerate attribute names old enumerate attribute names name li get double attribute name value ul dd dl dl see nanoxml xml element set int attribute java lang string int set int attribute string int see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element enumerate attribute names see nanoxml xml element get double attribute java lang string get double attribute string see nanoxml xml element get double attribute java lang string double get double attribute string double see nanoxml xml element get double attribute java lang string java util hashtable java lang string boolean get double attribute string hashtable string boolean public void set double attribute string name double value if this ignore case name name to upper case this attributes put name double to string value enumerateattributenames enumerateattributenames getdoubleattribute xmlelement setintattribute setintattribute xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement enumerateattributenames xmlelement getdoubleattribute getdoubleattribute xmlelement getdoubleattribute getdoubleattribute xmlelement getdoubleattribute getdoubleattribute setdoubleattribute ignorecase touppercase tostring returns the number of child elements of the element dl dt b postconditions b dt dd ul li code result 0 code ul dd dl see nanoxml xml element add child nanoxml xml element add child xml element see nanoxml xml element enumerate children see nanoxml xml element get children see nanoxml xml element remove child nanoxml xml element remove child xml element public int count children return this children size xmlelement addchild xmlelement addchild xmlelement xmlelement enumeratechildren xmlelement getchildren xmlelement removechild xmlelement removechild xmlelement countchildren enumerates the attribute names dl dt b postconditions b dt dd ul li code result null code ul dd dl see nanoxml xml element set double attribute java lang string double set double attribute string double see nanoxml xml element set int attribute java lang string int set int attribute string int see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element get attribute java lang string get attribute string see nanoxml xml element get attribute java lang string java lang object get attribute string string see nanoxml xml element get attribute java lang string java util hashtable java lang string boolean get attribute string hashtable string boolean see nanoxml xml element get string attribute java lang string get string attribute string see nanoxml xml element get string attribute java lang string java lang string get string attribute string string see nanoxml xml element get string attribute java lang string java util hashtable java lang string boolean get string attribute string hashtable string boolean see nanoxml xml element get int attribute java lang string get int attribute string see nanoxml xml element get int attribute java lang string int get int attribute string int see nanoxml xml element get int attribute java lang string java util hashtable java lang string boolean get int attribute string hashtable string boolean see nanoxml xml element get double attribute java lang string get double attribute string see nanoxml xml element get double attribute java lang string double get double attribute string double see nanoxml xml element get double attribute java lang string java util hashtable java lang string boolean get double attribute string hashtable string boolean see nanoxml xml element get boolean attribute java lang string java lang string java lang string boolean get boolean attribute string string string boolean public enumeration string enumerate attribute names return this attributes keys xmlelement setdoubleattribute setdoubleattribute xmlelement setintattribute setintattribute xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement getattribute getattribute xmlelement getattribute getattribute xmlelement getattribute getattribute xmlelement getstringattribute getstringattribute xmlelement getstringattribute getstringattribute xmlelement getstringattribute getstringattribute xmlelement getintattribute getintattribute xmlelement getintattribute getintattribute xmlelement getintattribute getintattribute xmlelement getdoubleattribute getdoubleattribute xmlelement getdoubleattribute getdoubleattribute xmlelement getdoubleattribute getdoubleattribute xmlelement getbooleanattribute getbooleanattribute enumerateattributenames enumerates the child elements dl dt b postconditions b dt dd ul li code result null code ul dd dl see nanoxml xml element add child nanoxml xml element add child xml element see nanoxml xml element count children see nanoxml xml element get children see nanoxml xml element remove child nanoxml xml element remove child xml element public enumeration xml element enumerate children return this children elements xmlelement addchild xmlelement addchild xmlelement xmlelement countchildren xmlelement getchildren xmlelement removechild xmlelement removechild xmlelement xmlelement enumeratechildren returns the child elements as a vector it is safe to modify this vector dl dt b postconditions b dt dd ul li code result null code ul dd dl see nanoxml xml element add child nanoxml xml element add child xml element see nanoxml xml element count children see nanoxml xml element enumerate children see nanoxml xml element remove child nanoxml xml element remove child xml element public vector get children try return vector this children clone catch exception e this never happens however some java compilers are so braindead that they require this exception clause return null xmlelement addchild xmlelement addchild xmlelement xmlelement countchildren xmlelement enumeratechildren xmlelement removechild xmlelement removechild xmlelement getchildren returns the pcdata content of the object if there is no such content code null code is returned see nanoxml xml element set content java lang string set content string public string get content return this contents xmlelement setcontent setcontent getcontent returns the line nr in the source data on which the element is found this method returns code 0 code there is no associated source data dl dt b postconditions b dt dd ul li code result 0 code ul dd dl public int get line nr return this line nr getlinenr linenr returns an attribute of the element if the attribute doesn t exist code null code is returned param name the name of the attribute dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element enumerate attribute names see nanoxml xml element get attribute java lang string java lang object get attribute string object see nanoxml xml element get attribute java lang string java util hashtable java lang string boolean get attribute string hashtable string boolean public object get attribute string name return this get attribute name null xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement enumerateattributenames xmlelement getattribute getattribute xmlelement getattribute getattribute getattribute getattribute returns an attribute of the element if the attribute doesn t exist code default value code is returned param name the name of the attribute param default value key to use if the attribute is missing dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element enumerate attribute names see nanoxml xml element get attribute java lang string get attribute string see nanoxml xml element get attribute java lang string java util hashtable java lang string boolean get attribute string hashtable string boolean public object get attribute string name object default value if this ignore case name name to upper case object value this attributes get name if value null value default value return value defaultvalue defaultvalue xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement enumerateattributenames xmlelement getattribute getattribute xmlelement getattribute getattribute getattribute defaultvalue ignorecase touppercase defaultvalue returns an attribute by looking up a key in a hashtable if the attribute doesn t exist the value corresponding to default key is returned p as an example if value set contains the mapping code one 1 code and the element contains the attribute code attr one code then code get attribute attr mapping default key false code returns code 1 code param name the name of the attribute param value set hashtable mapping keys to values param default key key to use if the attribute is missing param allow literals code true code if literals are valid dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier li code value set code null li the keys of code value set code are strings ul dd dl dl see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element enumerate attribute names see nanoxml xml element get attribute java lang string get attribute string see nanoxml xml element get attribute java lang string java lang object get attribute string object public object get attribute string name hashtable value set string default key boolean allow literals if this ignore case name name to upper case object key this attributes get name object result if key null key default key result value set get key if result null if allow literals result key else throw this invalid value name string key return result defaultkey valueset getattribute defaultkey valueset defaultkey allowliterals valueset valueset xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement enumerateattributenames xmlelement getattribute getattribute xmlelement getattribute getattribute getattribute valueset defaultkey allowliterals ignorecase touppercase defaultkey valueset allowliterals invalidvalue returns an attribute of the element if the attribute doesn t exist code null code is returned param name the name of the attribute dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element enumerate attribute names see nanoxml xml element get string attribute java lang string java lang string get string attribute string string see nanoxml xml element get string attribute java lang string java util hashtable java lang string boolean get string attribute string hashtable string boolean public string get string attribute string name return this get string attribute name null xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement enumerateattributenames xmlelement getstringattribute getstringattribute xmlelement getstringattribute getstringattribute getstringattribute getstringattribute returns an attribute of the element if the attribute doesn t exist code default value code is returned param name the name of the attribute param default value key to use if the attribute is missing dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element enumerate attribute names see nanoxml xml element get string attribute java lang string get string attribute string see nanoxml xml element get string attribute java lang string java util hashtable java lang string boolean get string attribute string hashtable string boolean public string get string attribute string name string default value return string this get attribute name default value defaultvalue defaultvalue xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement enumerateattributenames xmlelement getstringattribute getstringattribute xmlelement getstringattribute getstringattribute getstringattribute defaultvalue getattribute defaultvalue returns an attribute by looking up a key in a hashtable if the attribute doesn t exist the value corresponding to default key is returned p as an example if value set contains the mapping code one 1 code and the element contains the attribute code attr one code then code get attribute attr mapping default key false code returns code 1 code param name the name of the attribute param value set hashtable mapping keys to values param default key key to use if the attribute is missing param allow literals code true code if literals are valid dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier li code value set code null li the keys of code value set code are strings li the values of code value set code are strings ul dd dl dl see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element enumerate attribute names see nanoxml xml element get string attribute java lang string get string attribute string see nanoxml xml element get string attribute java lang string java lang string get string attribute string string public string get string attribute string name hashtable value set string default key boolean allow literals return string this get attribute name value set default key allow literals defaultkey valueset getattribute defaultkey valueset defaultkey allowliterals valueset valueset valueset xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement enumerateattributenames xmlelement getstringattribute getstringattribute xmlelement getstringattribute getstringattribute getstringattribute valueset defaultkey allowliterals getattribute valueset defaultkey allowliterals returns an attribute of the element if the attribute doesn t exist code 0 code is returned param name the name of the attribute dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl see nanoxml xml element set int attribute java lang string int set int attribute string int see nanoxml xml element enumerate attribute names see nanoxml xml element get int attribute java lang string int get int attribute string int see nanoxml xml element get int attribute java lang string java util hashtable java lang string boolean get int attribute string hashtable string boolean public int get int attribute string name return this get int attribute name 0 xmlelement setintattribute setintattribute xmlelement enumerateattributenames xmlelement getintattribute getintattribute xmlelement getintattribute getintattribute getintattribute getintattribute returns an attribute of the element if the attribute doesn t exist code default value code is returned param name the name of the attribute param default value key to use if the attribute is missing dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl see nanoxml xml element set int attribute java lang string int set int attribute string int see nanoxml xml element enumerate attribute names see nanoxml xml element get int attribute java lang string get int attribute string see nanoxml xml element get int attribute java lang string java util hashtable java lang string boolean get int attribute string hashtable string boolean public int get int attribute string name int default value if this ignore case name name to upper case string value this attributes get name if value null return default value else try return integer parse int value catch number format exception e throw this invalid value name value defaultvalue defaultvalue xmlelement setintattribute setintattribute xmlelement enumerateattributenames xmlelement getintattribute getintattribute xmlelement getintattribute getintattribute getintattribute defaultvalue ignorecase touppercase defaultvalue parseint numberformatexception invalidvalue returns an attribute by looking up a key in a hashtable if the attribute doesn t exist the value corresponding to default key is returned p as an example if value set contains the mapping code one 1 code and the element contains the attribute code attr one code then code get int attribute attr mapping default key false code returns code 1 code param name the name of the attribute param value set hashtable mapping keys to values param default key key to use if the attribute is missing param allow literal numbers code true code if literal numbers are valid dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier li code value set code null li the keys of code value set code are strings li the values of code value set code are integer objects li code default key code is either code null code a key in code value set code or an integer ul dd dl dl see nanoxml xml element set int attribute java lang string int set int attribute string int see nanoxml xml element enumerate attribute names see nanoxml xml element get int attribute java lang string get int attribute string see nanoxml xml element get int attribute java lang string int get int attribute string int public int get int attribute string name hashtable value set string default key boolean allow literal numbers if this ignore case name name to upper case object key this attributes get name integer result if key null key default key try result integer value set get key catch class cast exception e throw this invalid value set name if result null if allow literal numbers throw this invalid value name string key try result integer value of string key catch number format exception e throw this invalid value name string key return result int value defaultkey valueset getintattribute defaultkey valueset defaultkey allowliteralnumbers valueset valueset valueset defaultkey valueset xmlelement setintattribute setintattribute xmlelement enumerateattributenames xmlelement getintattribute getintattribute xmlelement getintattribute getintattribute getintattribute valueset defaultkey allowliteralnumbers ignorecase touppercase defaultkey valueset classcastexception invalidvalueset allowliteralnumbers invalidvalue valueof numberformatexception invalidvalue intvalue returns an attribute of the element if the attribute doesn t exist code 0 0 code is returned param name the name of the attribute dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl see nanoxml xml element set double attribute java lang string double set double attribute string double see nanoxml xml element enumerate attribute names see nanoxml xml element get double attribute java lang string double get double attribute string double see nanoxml xml element get double attribute java lang string java util hashtable java lang string boolean get double attribute string hashtable string boolean public double get double attribute string name return this get double attribute name 0 xmlelement setdoubleattribute setdoubleattribute xmlelement enumerateattributenames xmlelement getdoubleattribute getdoubleattribute xmlelement getdoubleattribute getdoubleattribute getdoubleattribute getdoubleattribute returns an attribute of the element if the attribute doesn t exist code default value code is returned param name the name of the attribute param default value key to use if the attribute is missing dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl see nanoxml xml element set double attribute java lang string double set double attribute string double see nanoxml xml element enumerate attribute names see nanoxml xml element get double attribute java lang string get double attribute string see nanoxml xml element get double attribute java lang string java util hashtable java lang string boolean get double attribute string hashtable string boolean public double get double attribute string name double default value if this ignore case name name to upper case string value this attributes get name if value null return default value else try return double value of value double value catch number format exception e throw this invalid value name value defaultvalue defaultvalue xmlelement setdoubleattribute setdoubleattribute xmlelement enumerateattributenames xmlelement getdoubleattribute getdoubleattribute xmlelement getdoubleattribute getdoubleattribute getdoubleattribute defaultvalue ignorecase touppercase defaultvalue valueof doublevalue numberformatexception invalidvalue returns an attribute by looking up a key in a hashtable if the attribute doesn t exist the value corresponding to default key is returned p as an example if value set contains the mapping code one gt 1 0 code and the element contains the attribute code attr one code then code get double attribute attr mapping default key false code returns code 1 0 code param name the name of the attribute param value set hashtable mapping keys to values param default key key to use if the attribute is missing param allow literal numbers code true code if literal numbers are valid dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier li code value set null code li the keys of code value set code are strings li the values of code value set code are double objects li code default key code is either code null code a key in code value set code or a double ul dd dl dl see nanoxml xml element set double attribute java lang string double set double attribute string double see nanoxml xml element enumerate attribute names see nanoxml xml element get double attribute java lang string get double attribute string see nanoxml xml element get double attribute java lang string double get double attribute string double public double get double attribute string name hashtable value set string default key boolean allow literal numbers if this ignore case name name to upper case object key this attributes get name double result if key null key default key try result double value set get key catch class cast exception e throw this invalid value set name if result null if allow literal numbers throw this invalid value name string key try result double value of string key catch number format exception e throw this invalid value name string key return result double value defaultkey valueset getdoubleattribute defaultkey valueset defaultkey allowliteralnumbers valueset valueset valueset defaultkey valueset xmlelement setdoubleattribute setdoubleattribute xmlelement enumerateattributenames xmlelement getdoubleattribute getdoubleattribute xmlelement getdoubleattribute getdoubleattribute getdoubleattribute valueset defaultkey allowliteralnumbers ignorecase touppercase defaultkey valueset classcastexception invalidvalueset allowliteralnumbers invalidvalue valueof numberformatexception invalidvalue doublevalue returns an attribute of the element if the attribute doesn t exist code default value code is returned if the value of the attribute is equal to code true value code code true code is returned if the value of the attribute is equal to code false value code code false code is returned if the value doesn t match code true value code or code false value code an exception is thrown param name the name of the attribute param true value the value associated with code true code param false value the value associated with code true code param default value value to use if the attribute is missing dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier li code true value code and code false value code are different strings ul dd dl dl see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element remove attribute java lang string remove attribute string see nanoxml xml element enumerate attribute names public boolean get boolean attribute string name string true value string false value boolean default value if this ignore case name name to upper case object value this attributes get name if value null return default value else if value equals true value return true else if value equals false value return false else throw this invalid value name string value defaultvalue truevalue falsevalue truevalue falsevalue truevalue falsevalue defaultvalue truevalue falsevalue xmlelement setattribute setattribute xmlelement removeattribute removeattribute xmlelement enumerateattributenames getbooleanattribute truevalue falsevalue defaultvalue ignorecase touppercase defaultvalue truevalue falsevalue invalidvalue returns the name of the element see nanoxml xml element set name java lang string set name string public string get name return this name xmlelement setname setname getname reads one xml element from a java io reader and parses it param reader the reader from which to retrieve the xml data dl dl dt b preconditions b dt dd ul li code reader null code li code reader code is not closed ul dd dl dl dt b postconditions b dt dd ul li the state of the receiver is updated to reflect the xml element parsed from the reader li the reader points to the first character following the last gt character of the xml element ul dd dl dl throws java io io exception if an error occured while reading the input throws nanoxml xml parse exception if an error occured while parsing the read data public void parse from reader reader reader throws io exception xml parse exception this parse from reader reader starting line nr 1 ioexception xmlparseexception parsefromreader ioexception xmlparseexception parsefromreader startinglinenr reads one xml element from a java io reader and parses it param reader the reader from which to retrieve the xml data param starting line nr the line number of the first line in the data dl dl dt b preconditions b dt dd ul li code reader null code li code reader code is not closed ul dd dl dl dt b postconditions b dt dd ul li the state of the receiver is updated to reflect the xml element parsed from the reader li the reader points to the first character following the last gt character of the xml element ul dd dl dl throws java io io exception if an error occured while reading the input throws nanoxml xml parse exception if an error occured while parsing the read data public void parse from reader reader reader2 int starting line nr throws io exception xml parse exception this name null this contents this attributes new hashtable string string this children new vector xml element this char read too much 0 this reader reader2 this parser line nr starting line nr for char ch this scan whitespace if ch throw this expected input ch this read char if ch ch this skip special tag 0 else this unread char ch this scan element this return startinglinenr ioexception xmlparseexception parsefromreader startinglinenr ioexception xmlparseexception xmlelement charreadtoomuch parserlinenr startinglinenr scanwhitespace expectedinput readchar skipspecialtag unreadchar scanelement reads one xml element from a string and parses it param reader the reader from which to retrieve the xml data dl dl dt b preconditions b dt dd ul li code string null code li code string length gt 0 code ul dd dl dl dt b postconditions b dt dd ul li the state of the receiver is updated to reflect the xml element parsed from the reader ul dd dl dl throws nanoxml xml parse exception if an error occured while parsing the string public void parse string string string throws xml parse exception try this parse from reader new string reader string starting line nr 1 catch io exception e java exception handling suxx xmlparseexception parsestring xmlparseexception parsefromreader stringreader startinglinenr ioexception reads one xml element from a string and parses it param reader the reader from which to retrieve the xml data param offset the first character in code string code to scan dl dl dt b preconditions b dt dd ul li code string null code li code offset lt string length code li code offset gt 0 code ul dd dl dl dt b postconditions b dt dd ul li the state of the receiver is updated to reflect the xml element parsed from the reader ul dd dl dl throws nanoxml xml parse exception if an error occured while parsing the string public void parse string string string int offset throws xml parse exception this parse string string substring offset xmlparseexception parsestring xmlparseexception parsestring reads one xml element from a string and parses it param reader the reader from which to retrieve the xml data param offset the first character in code string code to scan param end the character where to stop scanning this character is not scanned dl dl dt b preconditions b dt dd ul li code string null code li code end lt string length code li code offset lt end code li code offset gt 0 code ul dd dl dl dt b postconditions b dt dd ul li the state of the receiver is updated to reflect the xml element parsed from the reader ul dd dl dl throws nanoxml xml parse exception if an error occured while parsing the string public void parse string string string int offset int end throws xml parse exception this parse string string substring offset end xmlparseexception parsestring xmlparseexception parsestring reads one xml element from a string and parses it param reader the reader from which to retrieve the xml data param offset the first character in code string code to scan param end the character where to stop scanning this character is not scanned param starting line nr the line number of the first line in the data dl dl dt b preconditions b dt dd ul li code string null code li code end lt string length code li code offset lt end code li code offset gt 0 code ul dd dl dl dt b postconditions b dt dd ul li the state of the receiver is updated to reflect the xml element parsed from the reader ul dd dl dl throws nanoxml xml parse exception if an error occured while parsing the string public void parse string string string int offset int end int starting line nr throws xml parse exception string string substring offset end try this parse from reader new string reader string starting line nr catch io exception e java exception handling suxx startinglinenr xmlparseexception parsestring startinglinenr xmlparseexception parsefromreader stringreader startinglinenr ioexception reads one xml element from a char array and parses it param reader the reader from which to retrieve the xml data param offset the first character in code string code to scan param end the character where to stop scanning this character is not scanned dl dl dt b preconditions b dt dd ul li code input null code li code end lt input length code li code offset lt end code li code offset gt 0 code ul dd dl dl dt b postconditions b dt dd ul li the state of the receiver is updated to reflect the xml element parsed from the reader ul dd dl dl throws nanoxml xml parse exception if an error occured while parsing the string public void parse char array char input int offset int end throws xml parse exception this parse char array input offset end starting line nr 1 xmlparseexception parsechararray xmlparseexception parsechararray startinglinenr reads one xml element from a char array and parses it param reader the reader from which to retrieve the xml data param offset the first character in code string code to scan param end the character where to stop scanning this character is not scanned param starting line nr the line number of the first line in the data dl dl dt b preconditions b dt dd ul li code input null code li code end lt input length code li code offset lt end code li code offset gt 0 code ul dd dl dl dt b postconditions b dt dd ul li the state of the receiver is updated to reflect the xml element parsed from the reader ul dd dl dl throws nanoxml xml parse exception if an error occured while parsing the string public void parse char array char input int offset int end int starting line nr throws xml parse exception try reader reader new char array reader input offset end this parse from reader reader starting line nr catch io exception e this exception will never happen startinglinenr xmlparseexception parsechararray startinglinenr xmlparseexception chararrayreader parsefromreader startinglinenr ioexception removes a child element param child the child element to remove dl dl dt b preconditions b dt dd ul li code child null code li code child code is a child element of the receiver ul dd dl dl dt b postconditions b dt dd ul li count children old count children 1 li enumerate children old enumerate children child li get children old enumerate children child ul dd dl dl see nanoxml xml element add child nanoxml xml element add child xml element see nanoxml xml element count children see nanoxml xml element enumerate children see nanoxml xml element get children public void remove child xml element child this children remove element child countchildren countchildren enumeratechildren enumeratechildren getchildren enumeratechildren xmlelement addchild xmlelement addchild xmlelement xmlelement countchildren xmlelement enumeratechildren xmlelement getchildren removechild xmlelement removeelement removes an attribute param name the name of the attribute dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl dl dt b postconditions b dt dd ul li enumerate attribute names old enumerate attribute names name li get attribute name code null code ul dd dl dl see nanoxml xml element enumerate attribute names see nanoxml xml element set double attribute java lang string double set double attribute string double see nanoxml xml element set int attribute java lang string int set int attribute string int see nanoxml xml element set attribute java lang string java lang object set attribute string object see nanoxml xml element get attribute java lang string get attribute string see nanoxml xml element get attribute java lang string java lang object get attribute string object see nanoxml xml element get attribute java lang string java util hashtable java lang string boolean get attribute string hashtable string boolean see nanoxml xml element get string attribute java lang string get string attribute string see nanoxml xml element get string attribute java lang string java lang string get string attribute string string see nanoxml xml element get string attribute java lang string java util hashtable java lang string boolean get string attribute string hashtable string boolean see nanoxml xml element get int attribute java lang string get int attribute string see nanoxml xml element get int attribute java lang string int get int attribute string int see nanoxml xml element get int attribute java lang string java util hashtable java lang string boolean get int attribute string hashtable string boolean see nanoxml xml element get double attribute java lang string get double attribute string see nanoxml xml element get double attribute java lang string double get double attribute string double see nanoxml xml element get double attribute java lang string java util hashtable java lang string boolean get double attribute string hashtable string boolean see nanoxml xml element get boolean attribute java lang string java lang string java lang string boolean get boolean attribute string string string boolean public void remove attribute string name if this ignore case name name to upper case this attributes remove name enumerateattributenames enumerateattributenames getattribute xmlelement enumerateattributenames xmlelement setdoubleattribute setdoubleattribute xmlelement setintattribute setintattribute xmlelement setattribute setattribute xmlelement getattribute getattribute xmlelement getattribute getattribute xmlelement getattribute getattribute xmlelement getstringattribute getstringattribute xmlelement getstringattribute getstringattribute xmlelement getstringattribute getstringattribute xmlelement getintattribute getintattribute xmlelement getintattribute getintattribute xmlelement getintattribute getintattribute xmlelement getdoubleattribute getdoubleattribute xmlelement getdoubleattribute getdoubleattribute xmlelement getdoubleattribute getdoubleattribute xmlelement getbooleanattribute getbooleanattribute removeattribute ignorecase touppercase creates a new similar xml element p you should override this method when subclassing xml element protected xml element create another element return new xml element this entities this ignore whitespace false this ignore case xmlelement xmlelement createanotherelement xmlelement ignorewhitespace ignorecase changes the content string param content the new content string public void set content string content this contents content setcontent changes the name of the element param name the new name dl dl dt b preconditions b dt dd ul li code name null code li code name code is a valid xml identifier ul dd dl see nanoxml xml element get name public void set name string name2 this name name2 xmlelement getname setname writes the xml element to a string see nanoxml xml element write java io writer write writer override public string to string try byte array output stream out new byte array output stream output stream writer writer new output stream writer out this write writer writer flush return new string out to byte array catch io exception e java exception handling suxx return super to string xmlelement tostring bytearrayoutputstream bytearrayoutputstream outputstreamwriter outputstreamwriter tobytearray ioexception tostring writes the xml element to a writer param writer the writer to write the xml data to dl dl dt b preconditions b dt dd ul li code writer null code li code writer code is not closed ul dd dl throws java io io exception if the data could not be written to the writer see nanoxml xml element to string public void write writer writer throws io exception if this name null this write encoded writer this contents return writer write writer write this name if this attributes is empty enumeration string e this attributes keys while e has more elements writer write string key e next element string value this attributes get key writer write key writer write writer write this write encoded writer value writer write if this contents null this contents length 0 writer write this write encoded writer this contents writer write writer write writer write this name writer write else if this children is empty writer write writer write else writer write enumeration xml element e this enumerate children while e has more elements xml element child e next element child write writer writer write writer write writer write this name writer write ioexception xmlelement tostring ioexception writeencoded isempty hasmoreelements nextelement writeencoded writeencoded isempty xmlelement enumeratechildren hasmoreelements xmlelement nextelement writes a string encoded to a writer param writer the writer to write the xml data to param str the string to write encoded dl dl dt b preconditions b dt dd ul li code writer null code li code writer code is not closed li code str null code ul dd dl protected void write encoded writer writer string str throws io exception for int i 0 i str length i 1 char ch str char at i switch ch case writer write writer write l writer write t writer write break case writer write writer write g writer write t writer write break case writer write writer write a writer write m writer write p writer write break case writer write writer write q writer write u writer write o writer write t writer write break case writer write writer write a writer write p writer write o writer write s writer write break default int unicode ch if unicode 32 unicode 126 writer write writer write writer write x writer write integer to string unicode 16 writer write else writer write ch writeencoded ioexception charat tostring scans an identifier from the current reader the scanned identifier is appended to code result code param result the buffer in which the scanned identifier will be put dl dl dt b preconditions b dt dd ul li code result null code li the next character read from the reader is a valid first character of an xml identifier ul dd dl dl dt b postconditions b dt dd ul li the next character read from the reader won t be an identifier character ul dd dl dl protected void scan identifier string builder result throws io exception for char ch this read char if ch a ch z ch a ch z ch 0 ch 9 ch ch ch ch ch u007e this unread char ch return result append ch scanidentifier stringbuilder ioexception readchar _ unreadchar this method scans an identifier from the current reader return the next character following the whitespace protected char scan whitespace throws io exception for char ch this read char switch ch case case t case n case r break default return ch scanwhitespace ioexception readchar this method scans an identifier from the current reader the scanned whitespace is appended to code result code return the next character following the whitespace dl dl dt b preconditions b dt dd ul li code result null code ul dd dl protected char scan whitespace string builder result throws io exception for char ch this read char switch ch case case t case n result append ch case r break default return ch scanwhitespace stringbuilder ioexception readchar this method scans a delimited string from the current reader the scanned string without delimiters is appended to code string code dl dl dt b preconditions b dt dd ul li code string null code li the next char read is the string delimiter ul dd dl protected void scan string string builder string throws io exception char delimiter this read char if delimiter delimiter throw this expected input or for char ch this read char if ch delimiter return else if ch this resolve entity string else string append ch scanstring stringbuilder ioexception readchar expectedinput readchar resolveentity scans a pcdata element cdata sections and entities are resolved the next lt char is skipped the scanned data is appended to code data code dl dl dt b preconditions b dt dd ul li code data null code ul dd dl protected void scanpc data string builder data throws io exception for char ch this read char if ch ch this read char if ch this checkcdata data else this unread char ch return else if ch this resolve entity data else data append ch scanpcdata stringbuilder ioexception readchar readchar unreadchar resolveentity scans a special tag and if the tag is a cdata section append its content to code buf code dl dl dt b preconditions b dt dd ul li code buf null code li the first lt has already been read ul dd dl protected boolean checkcdata string builder buf throws io exception char ch this read char if ch this unread char ch this skip special tag 0 return false else if this check literal cdata this skip special tag 1 one has already been read return false else int delimiter chars skipped 0 while delimiter chars skipped 3 ch this read char switch ch case if delimiter chars skipped 2 delimiter chars skipped 1 else buf append buf append delimiter chars skipped 0 break case if delimiter chars skipped 2 for int i 0 i delimiter chars skipped i buf append delimiter chars skipped 0 buf append else delimiter chars skipped 3 break default for int i 0 i delimiter chars skipped i 1 buf append buf append ch delimiter chars skipped 0 return true stringbuilder ioexception readchar unreadchar skipspecialtag checkliteral skipspecialtag delimitercharsskipped delimitercharsskipped readchar delimitercharsskipped delimitercharsskipped delimitercharsskipped delimitercharsskipped delimitercharsskipped delimitercharsskipped delimitercharsskipped delimitercharsskipped delimitercharsskipped skips a comment dl dl dt b preconditions b dt dd ul li the first lt has already been read ul dd dl protected void skip comment throws io exception int dashes to read 2 while dashes to read 0 char ch this read char if ch dashes to read 1 else dashes to read 2 if this read char throw this expected input skipcomment ioexception dashestoread dashestoread readchar dashestoread dashestoread readchar expectedinput skips a special tag or comment param bracket level the number of open square brackets that have already been read dl dl dt b preconditions b dt dd ul li the first lt has already been read li code bracket level 0 code ul dd dl protected void skip special tag int bracket level throws io exception int tag level 1 char string delimiter 0 if bracket level 0 char ch this read char if ch bracket level 1 else if ch ch this read char if ch bracket level 1 else if ch bracket level 1 else if ch this skip comment return while tag level 0 char ch this read char if string delimiter 0 if ch ch string delimiter ch else if bracket level 0 if ch tag level 1 else if ch tag level 1 if ch bracket level 1 else if ch bracket level 1 else if ch string delimiter string delimiter 0 bracketlevel bracketlevel skipspecialtag bracketlevel ioexception taglevel stringdelimiter bracketlevel readchar bracketlevel readchar bracketlevel bracketlevel skipcomment taglevel readchar stringdelimiter stringdelimiter bracketlevel taglevel taglevel bracketlevel bracketlevel stringdelimiter stringdelimiter scans the data for literal text scanning stops when a character does not match or after the complete text has been checked whichever comes first param literal the literal to check dl dl dt b preconditions b dt dd ul li code literal null code ul dd dl protected boolean check literal string literal throws io exception int length literal length for int i 0 i length i 1 if this read char literal char at i return false return true checkliteral ioexception readchar charat reads a character from a reader protected char read char throws io exception if this char read too much 0 char ch this char read too much this char read too much 0 return ch else int i this reader read if i 0 throw this unexpected end of data else if i 10 this parser line nr 1 return n else return char i readchar ioexception charreadtoomuch charreadtoomuch charreadtoomuch unexpectedendofdata parserlinenr scans an xml element param elt the element that will contain the result dl dl dt b preconditions b dt dd ul li the first lt has already been read li code elt null code ul dd dl protected void scan element xml element elt throws io exception string builder buf new string builder this scan identifier buf string name buf to string elt set name name char ch this scan whitespace while ch ch buf set length 0 this unread char ch this scan identifier buf string key buf to string ch this scan whitespace if ch throw this expected input this unread char this scan whitespace buf set length 0 this scan string buf elt set attribute key buf ch this scan whitespace if ch ch this read char if ch throw this expected input return buf set length 0 ch this scan whitespace buf if ch this unread char ch this scanpc data buf else for ch this read char if ch if this checkcdata buf this scanpc data buf break else ch this scan whitespace buf if ch this unread char ch this scanpc data buf break else if ch this ignore whitespace buf set length 0 if ch this unread char ch break if buf length 0 while ch if ch ch this read char if ch throw this expected input comment or element ch this read char if ch throw this expected input comment or element this skip comment else this unread char ch xml element child this create another element this scan element child elt add child child ch this scan whitespace if ch throw this expected input ch this read char this unread char ch else if this ignore whitespace elt set content buf to string trim else elt set content buf to string ch this read char if ch throw this expected input this unread char this scan whitespace if this check literal name throw this expected input name if this scan whitespace throw this expected input scanelement xmlelement ioexception stringbuilder stringbuilder scanidentifier tostring setname scanwhitespace setlength unreadchar scanidentifier tostring scanwhitespace expectedinput unreadchar scanwhitespace setlength scanstring setattribute scanwhitespace readchar expectedinput setlength scanwhitespace unreadchar scanpcdata readchar scanpcdata scanwhitespace unreadchar scanpcdata ignorewhitespace setlength unreadchar readchar expectedinput readchar expectedinput skipcomment unreadchar xmlelement createanotherelement scanelement addchild scanwhitespace expectedinput readchar unreadchar ignorewhitespace setcontent tostring setcontent tostring readchar expectedinput unreadchar scanwhitespace checkliteral expectedinput scanwhitespace expectedinput resolves an entity the name of the entity is read from the reader the value of the entity is appended to code buf code param buf where to put the entity value dl dl dt b preconditions b dt dd ul li the first amp has already been read li code buf null code ul dd dl protected void resolve entity string builder buf throws io exception char ch 0 string builder key buf new string builder for ch this read char if ch break key buf append ch string key key buf to string if key char at 0 try if key char at 1 x ch char integer parse int key substring 2 16 else ch char integer parse int key substring 1 10 catch number format exception e throw this unknown entity key buf append ch else char value char this entities get key if value null throw this unknown entity key buf append value resolveentity stringbuilder ioexception stringbuilder keybuf stringbuilder readchar keybuf keybuf tostring charat charat parseint parseint numberformatexception unknownentity unknownentity pushes a character back to the read back buffer param ch the character to push back dl dl dt b preconditions b dt dd ul li the read back buffer is empty li code ch 0 code ul dd dl protected void unread char char ch this char read too much ch unreadchar charreadtoomuch creates a parse exception for when an invalid valueset is given to a method param name the name of the entity dl dl dt b preconditions b dt dd ul li code name null code ul dd dl protected xml parse exception invalid value set string name string msg invalid value set entity name name return new xml parse exception this get name this parser line nr msg xmlparseexception invalidvalueset xmlparseexception getname parserlinenr creates a parse exception for when an invalid value is given to a method param name the name of the entity param value the value of the entity dl dl dt b preconditions b dt dd ul li code name null code li code value null code ul dd dl protected xml parse exception invalid value string name string value string msg attribute name does not contain a valid value value return new xml parse exception this get name this parser line nr msg xmlparseexception invalidvalue xmlparseexception getname parserlinenr creates a parse exception for when the end of the data input has been reached protected xml parse exception unexpected end of data string msg unexpected end of data reached return new xml parse exception this get name this parser line nr msg xmlparseexception unexpectedendofdata xmlparseexception getname parserlinenr creates a parse exception for when a syntax error occured param context the context in which the error occured dl dl dt b preconditions b dt dd ul li code context null code li code context length gt 0 code ul dd dl protected xml parse exception syntax error string context string msg syntax error while parsing context return new xml parse exception this get name this parser line nr msg xmlparseexception syntaxerror xmlparseexception getname parserlinenr creates a parse exception for when the next character read is not the character that was expected param char set the set of characters in human readable form that was expected dl dl dt b preconditions b dt dd ul li code char set null code li code char set length gt 0 code ul dd dl protected xml parse exception expected input string char set string msg expected char set return new xml parse exception this get name this parser line nr msg charset charset charset xmlparseexception expectedinput charset charset xmlparseexception getname parserlinenr creates a parse exception for when an entity could not be resolved param name the name of the entity dl dl dt b preconditions b dt dd ul li code name null code li code name length gt 0 code ul dd dl protected xml parse exception unknown entity string name string msg unknown or invalid entity name return new xml parse exception this get name this parser line nr msg xmlparseexception unknownentity xmlparseexception getname parserlinenr ssk insert sender ssk block block long uid short htl peer node source node node boolean from store logminor logger should log logger minor this this from store from store this node node this source source this htl htl this uid uid my key nodessk block get key data block get raw data headers block get raw headers target my key to normalized double pub key my key get pub key if pub key null throw new illegal argument exception must have pubkey to insert data pub key fingerprint is not the same as hash pub key as bytes fixme it should be byte pub key as bytes pub key as bytes pub key hash sha256 digest pub key as bytes this block block start time system current time millis sskinsertsender sskblock peernode fromstore shouldlog fromstore fromstore mykey getkey getrawdata getrawheaders mykey tonormalizeddouble pubkey mykey getpubkey pubkey illegalargumentexception pubkey pubkey asbytes pubkeyasbytes pubkey asbytes pubkeyhash pubkeyasbytes starttime currenttimemillis void start node executor execute this ssk insert sender for uid uid on node get darknet port number at system current time millis sskinsertsender getdarknetportnumber currenttimemillis public void run freenet support logger os thread logpid this short orightl htl node add insert sender my key htl this try real run catch out of memory error e oom handler handleoom e if status not finished finish internal error null catch throwable t logger error this caught t t if status not finished finish internal error null finally if logminor logger minor this finishing this if status not finished finish internal error null node remove insert sender my key orightl this osthread addinsertsender mykey realrun outofmemoryerror oomhandler not_finished internal_error not_finished internal_error not_finished internal_error removeinsertsender mykey private void real run hash set peer node nodes routed to new hash set peer node peer node next null while true if we haven t routed to any node yet decrement according to the source if we have decrement according to the node which just failed because 1 if we always decrement according to source then we can be at max or min htl for a long time while we visit every peer node this is bad 2 the node which just failed can be seen as the requestor for our purposes decrement at this point so we can dnf immediately on reaching htl 0 htl node decrementhtl sent request next source htl if htl 0 send an insert reply back finish success null return route it next node peers closer peer source nodes routed to target true node is advanced mode enabled 1 null null if next null backtrack finish route not found null return if logminor logger minor this routing insert to next nodes routed to add next message req dmt createfnpssk insert request uid htl my key headers data pub key hash message request dmt createfnpssk insert request new uid htl my key wait for ack or reject will come before even a locally generated data reply message filter mf accepted message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnpssk accepted message filter mf rejected loop message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected loop message filter mf rejected overload message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnp rejected overload mf rejected overload must be the last thing in the or so its or pointer remains null otherwise we need to recreate it below mf rejected overload clear or message filter mf mf accepted or mf rejected loop or mf rejected overload send to next node try next send async request null this catch not connected exception e1 if logminor logger minor this not connected to next continue sent request true message msg null because messages may be re ordered it is entirely possible that we get a non local rejected overload followed by an accepted so we must loop here while true try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for accepted break if msg null terminal overload try to propagate back to source if logminor logger minor this timeout next local rejected overload timeout forward rejected overload break if msg get spec dmt fnp rejected overload non fatal probably still have time left if msg get boolean dmt is local next local rejected overload forward rejected overload3 if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break else forward rejected overload continue if msg get spec dmt fnp rejected loop next success not overload loop we don t want to send the data to this one break if msg get spec dmt fnpssk accepted logger error this unexpected message waiting for ssk accepted msg break otherwise is an fnpssk accepted break if msg null msg get spec dmt fnpssk accepted continue if logminor logger minor this got accepted on this send the headers and data message headers msg dmt createfnpssk insert request headers uid headers message data msg dmt createfnpssk insert request data uid data try next send async headers msg null this next send throttled message data msg data length this ssk insert handler data insert timeout false null catch not connected exception e1 if logminor logger minor this not connected to next continue catch waited too long exception e logger error this waited too long to send data msg to next on this continue catch sync send waited too long exception e impossible do we need to send them the pubkey if msg get boolean dmt need pub key message pk msg dmt createfnpssk pub key uid pub key try next send async pk msg null this catch not connected exception e if logminor logger minor this node disconnected while sending pubkey next continue wait for the ssk pub key accepted message filter mf1 message filter create set source next set field dmt uid uid set timeout accepted timeout set type dmt fnpssk pub key accepted message new ack try new ack node usm wait for mf1 this catch disconnected exception e if logminor logger minor this disconnected from next continue if new ack null try to propagate back to source if logminor logger minor this timeout next local rejected overload timeout2 forward rejected overload try another peer continue we have sent them the pubkey and the data wait for the response what are we waiting for now fnp route not found couldn t exhaust htl but send us the data anyway please fnp insert reply used up all htl yay fnp reject overload propagating an overload error fnp data found target already has the data and the data is an svk ssk ksk therefore could be different to what we are inserting fnp data insert rejected the insert was invalid message filter mf insert reply message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp insert reply mf rejected overload set timeout search timeout mf rejected overload clear or message filter mf route not found message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp route not found message filter mf data insert rejected message filter create set source next set field dmt uid uid set timeout search timeout set type dmt fnp data insert rejected mf mf route not found or mf insert reply or mf rejected overload or mf data insert rejected while true try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected from next while waiting for insert reply on this break if msg null timeout fairly serious problem logger error this timeout msg after accepted in insert to next terminal overload try to propagate back to source next local rejected overload after insert accepted timeout finish timed out next return if msg get spec dmt fnp rejected overload probably non fatal if so we have time left can try next one if msg get boolean dmt is local next local rejected overload forward rejected overload4 if logminor logger minor this local rejected overload moving on to next peer give up on this one try another break else forward rejected overload continue wait for any further response if msg get spec dmt fnp route not found if logminor logger minor this rejected rnf short new htl msg get short dmt htl if htl new htl htl new htl finished as far as this node is concerned next success not overload break if msg get spec dmt fnp data insert rejected next success not overload short reason msg get short dmt data insert rejected reason if logminor logger minor this data insert rejected reason if reason dmt data insert rejected verify failed if from store that s odd logger error this verify failed on next node next for data insert but we were sending from the store logger error this ssk insert rejected reason dmt get data insert rejected reason reason break what else can we do if msg get spec dmt fnpssk data found headers data was already on node and was not equal to what we sent realrun hashset peernode nodesroutedto hashset peernode peernode sentrequest insertreply closerpeer nodesroutedto isadvancedmodeenabled route_not_found nodesroutedto createfnpsskinsertrequest mykey pubkeyhash createfnpsskinsertrequestnew mykey datareply messagefilter mfaccepted messagefilter setsource setfield settimeout accepted_timeout settype fnpsskaccepted messagefilter mfrejectedloop messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedloop messagefilter mfrejectedoverload messagefilter setsource setfield settimeout accepted_timeout settype fnprejectedoverload mfrejectedoverload mfrejectedoverload clearor messagefilter mfaccepted mfrejectedloop mfrejectedoverload sendasync notconnectedexception sentrequest rejectedoverload waitfor disconnectedexception localrejectedoverload forwardrejectedoverload getspec fnprejectedoverload getboolean is_local localrejectedoverload forwardrejectedoverload3 rejectedoverload forwardrejectedoverload getspec fnprejectedloop successnotoverload getspec fnpsskaccepted sskaccepted fnpsskaccepted getspec fnpsskaccepted headersmsg createfnpsskinsertrequestheaders datamsg createfnpsskinsertrequestdata sendasync headersmsg sendthrottledmessage datamsg sskinserthandler data_insert_timeout notconnectedexception waitedtoolongexception datamsg syncsendwaitedtoolongexception getboolean need_pub_key pkmsg createfnpsskpubkey pubkey sendasync pkmsg notconnectedexception sskpubkeyaccepted messagefilter messagefilter setsource setfield settimeout accepted_timeout settype fnpsskpubkeyaccepted newack newack waitfor disconnectedexception newack localrejectedoverload forwardrejectedoverload fnproutenotfound fnpinsertreply fnprejectoverload fnpdatafound fnpdatainsertrejected messagefilter mfinsertreply messagefilter setsource setfield settimeout search_timeout settype fnpinsertreply mfrejectedoverload settimeout search_timeout mfrejectedoverload clearor messagefilter mfroutenotfound messagefilter setsource setfield settimeout search_timeout settype fnproutenotfound messagefilter mfdatainsertrejected messagefilter setsource setfield settimeout search_timeout settype fnpdatainsertrejected mfroutenotfound mfinsertreply mfrejectedoverload mfdatainsertrejected waitfor disconnectedexception insertreply localrejectedoverload afterinsertacceptedtimeout timed_out getspec fnprejectedoverload getboolean is_local localrejectedoverload forwardrejectedoverload4 rejectedoverload forwardrejectedoverload getspec fnproutenotfound newhtl getshort newhtl newhtl successnotoverload getspec fnpdatainsertrejected successnotoverload getshort data_insert_rejected_reason datainsertrejected data_insert_rejected_verify_failed fromstore datainsert getdatainsertrejectedreason getspec fnpsskdatafoundheaders private boolean has forwarded rejected overload synchronized boolean received rejected overload return has forwarded rejected overload hasforwardedrejectedoverload receivedrejectedoverload hasforwardedrejectedoverload forward rejected overload to the request originator do not call if have a local rejected overload private synchronized void forward rejected overload if has forwarded rejected overload return has forwarded rejected overload true notify all rejectedoverload rejectedoverload forwardrejectedoverload hasforwardedrejectedoverload hasforwardedrejectedoverload notifyall private void finish int code peer node next if logminor logger minor this finished code on this new exception debug synchronized this if status not finished throw new illegal state exception finish called with code when was already status if code route not found sent request code route really not found status code notify all if code success next null next on success true true if logminor logger minor this set status code get status string nothing to wait for no downstream transfers just exit peernode not_finished illegalstateexception route_not_found sentrequest route_really_not_found notifyall onsuccess getstatusstring public synchronized int get status return status getstatus public synchronized short gethtl return htl return the current status as a string public synchronized string get status string if status success return success if status route not found return route not found if status not finished return not finished if status internal error return internal error if status timed out return timed out if status generated rejected overload return generated rejected overload if status route really not found return route really not found return unknown status code status getstatusstring route_not_found not_finished internal_error timed_out generated_rejected_overload route_really_not_found public boolean sent request return sent request sentrequest sentrequest public synchronized boolean has recently collided boolean status has recently collided has recently collided false return status hasrecentlycollided hasrecentlycollided hasrecentlycollided public boolean has collided return has collided hascollided hascollided public byte get pubkey hash return headers getpubkeyhash public byte get headers return headers getheaders public byte get data return data getdata public ssk block get block return block sskblock getblock public long getuid return uid public void sent bytes int x synchronized total bytes sync total bytes sent x node node stats insert sent bytes true x sentbytes totalbytessync totalbytessent nodestats insertsentbytes public int get total sent bytes synchronized total bytes sync return total bytes sent gettotalsentbytes totalbytessync totalbytessent public void received bytes int x synchronized total bytes sync total bytes received x node node stats insert received bytes true x receivedbytes totalbytessync totalbytesreceived nodestats insertreceivedbytes public int get total received bytes synchronized total bytes sync return total bytes received gettotalreceivedbytes totalbytessync totalbytesreceived public void sent payload int x node sent payload x node node stats insert sent bytes true x sentpayload sentpayload nodestats insertsentbytes public int get priority return native thread high priority getpriority nativethread high_priority private static final gregorian calendar m calendar new gregorian calendar time zone get time zone utc public static date get return new date gregoriancalendar mcalendar gregoriancalendar timezone gettimezone public static long get in millis return system current time millis getinmillis currenttimemillis public static int get year synchronized m calendar m calendar set time in millis system current time millis return m calendar get calendar year getyear mcalendar mcalendar settimeinmillis currenttimemillis mcalendar public static int get month synchronized m calendar m calendar set time in millis system current time millis return m calendar get calendar month getmonth mcalendar mcalendar settimeinmillis currenttimemillis mcalendar public static int get day of month synchronized m calendar m calendar set time in millis system current time millis return m calendar get calendar day of month getdayofmonth mcalendar mcalendar settimeinmillis currenttimemillis mcalendar day_of_month public dsa group big integer p big integer q big integer g this p p this q q this g g if p signum 1 q signum 1 g signum 1 throw new illegal argument exception dsagroup biginteger biginteger biginteger illegalargumentexception private dsa group dsa group group this p new native big integer 1 group p to byte array this q new native big integer 1 group q to byte array this g new native big integer 1 group g to byte array dsagroup dsagroup nativebiginteger tobytearray nativebiginteger tobytearray nativebiginteger tobytearray parses a dsa group from a string where p q and g are in unsigned hex strings separated by a commas see read from field below public static dsa group parse string grp string tokenizer str new string tokenizer grp big integer p q g p new big integer str next token 16 q new big integer str next token 16 g new big integer str next token 16 return new dsa group p q g public static crypto key read input stream i throws io exception crypt format exception big integer p q g p util readmpi i q util readmpi i g util readmpi i try return new dsa group p q g catch illegal argument exception e crypt format exception ce new crypt format exception invalid group e ce init cause e throw ce readfromfield dsagroup stringtokenizer stringtokenizer biginteger biginteger nexttoken biginteger nexttoken biginteger nexttoken dsagroup cryptokey inputstream ioexception cryptformatexception biginteger dsagroup illegalargumentexception cryptformatexception cryptformatexception initcause override public string key type return dsa g p bit length keytype bitlength public big integer getp return p biginteger public big integer getq return q biginteger public big integer getg return g biginteger override public byte fingerprint big integer fp new big integer 3 fp 0 p fp 1 q fp 2 g return fingerprint fp biginteger biginteger override public byte as bytes byte pb util mp ibytes p byte qb util mp ibytes q byte gb util mp ibytes g byte tb new byte pb length qb length gb length system arraycopy pb 0 tb 0 pb length system arraycopy qb 0 tb pb length qb length system arraycopy gb 0 tb pb length qb length gb length return tb asbytes mpibytes mpibytes mpibytes override public boolean equals object o if this o not necessary but a very cheap optimization return true return o instanceof dsa group p equals dsa group o p q equals dsa group o q g equals dsa group o g dsagroup dsagroup dsagroup dsagroup public boolean equals dsa group o if this o not necessary but a very cheap optimization return true return p equals o p q equals o q g equals o g dsagroup override public int hash code return p hash code q hash code g hash code hashcode hashcode hashcode hashcode public simple field set as field set simple field set fs new simple field set true fs put single p base64 encode p to byte array fs put single q base64 encode q to byte array fs put single g base64 encode g to byte array return fs simplefieldset asfieldset simplefieldset simplefieldset putsingle tobytearray putsingle tobytearray putsingle tobytearray public static dsa group create simple field set fs throws illegal base64 exception fs parse exception string myp fs get p string myq fs get q string myg fs get g if myp null myq null myg null throw new fs parse exception the given sfs doesn t contain required fields big integer p new native big integer 1 base64 decode myp big integer q new native big integer 1 base64 decode myq big integer g new native big integer 1 base64 decode myg dsa group dg new dsa group p q g if dg equals global ds agroup biga return global ds agroup biga return dg dsagroup simplefieldset illegalbase64exception fsparseexception fsparseexception biginteger nativebiginteger biginteger nativebiginteger biginteger nativebiginteger dsagroup dsagroup dsagroupbiga dsagroupbiga override public string to string if this global ds agroup biga return global ds agroup biga else return super to string tostring dsagroupbiga dsagroupbiga tostring public string to long string if this global ds agroup biga return global ds agroup biga return p hex util bi to hex p q hex util bi to hex q g hex util bi to hex g tolongstring dsagroupbiga dsagroupbiga hexutil bitohex hexutil bitohex hexutil bitohex public dsa group clone key if this global ds agroup biga return this return new dsa group this dsagroup clonekey dsagroupbiga dsagroup public void remove from object container container container delete p container delete q container delete g container delete this removefrom objectcontainer private final node stats stats request starter group node node node client core core int port number random source random config config simple field set fs client context ctx sub config scheduler config new sub config node scheduler config this stats core node stats throttle window new throttle window manager 2 0 fs null null fs subset throttle window node throttle windowchk new throttle window manager 2 0 fs null null fs subset throttle windowchk node throttle windowssk new throttle window manager 2 0 fs null null fs subset throttle windowssk node throttle window insert new throttle window manager 2 0 fs null null fs subset throttle window insert node throttle window request new throttle window manager 2 0 fs null null fs subset throttle window request node chk request throttle new my request throttle throttle window 5000 chk request fs null null fs subset chk request throttle 32768 chk request starter new request starter core chk request throttle chk request starter port number stats request output throttle stats request input throttle stats local chk fetch bytes sent average stats local chk fetch bytes received average false false chk fetch scheduler new client request scheduler false false random chk request starter node core scheduler config ch krequester ctx chk request starter set scheduler chk fetch scheduler chk request starter start insert throttle new chained request throttle 10000 2 0f request throttle fixme reenable the above chk insert throttle new my request throttle throttle window 20000 chk insert fs null null fs subset chk insert throttle 32768 chk insert starter new request starter core chk insert throttle chk insert starter port number stats request output throttle stats request input throttle stats local chk insert bytes sent average stats local chk insert bytes received average true false chk put scheduler new client request scheduler true false random chk insert starter node core scheduler config ch kinserter ctx chk insert starter set scheduler chk put scheduler chk insert starter start ssk request throttle new my request throttle throttle window 5000 ssk request fs null null fs subset ssk request throttle 1024 ssk request starter new request starter core ssk request throttle ssk request starter port number stats request output throttle stats request input throttle stats local ssk fetch bytes sent average stats local ssk fetch bytes received average false true ssk fetch scheduler new client request scheduler false true random ssk request starter node core scheduler config ss krequester ctx ssk request starter set scheduler ssk fetch scheduler ssk request starter start insert throttle new chained request throttle 10000 2 0f request throttle fixme reenable the above ssk insert throttle new my request throttle throttle window 20000 ssk insert fs null null fs subset ssk insert throttle 1024 ssk insert starter new request starter core ssk insert throttle ssk insert starter port number stats request output throttle stats request input throttle stats local ssk insert bytes sent average stats local ssk fetch bytes received average true true ssk put scheduler new client request scheduler true true random ssk insert starter node core scheduler config ss kinserter ctx ssk insert starter set scheduler ssk put scheduler ssk insert starter start scheduler config finished initialization nodestats requeststartergroup nodeclientcore portnumber randomsource simplefieldset clientcontext subconfig schedulerconfig subconfig nodestats throttlewindow throttlewindowmanager throttlewindow throttlewindowchk throttlewindowmanager throttlewindowchk throttlewindowssk throttlewindowmanager throttlewindowssk throttlewindowinsert throttlewindowmanager throttlewindowinsert throttlewindowrequest throttlewindowmanager throttlewindowrequest chkrequestthrottle myrequestthrottle throttlewindow chkrequestthrottle chkrequeststarter requeststarter chkrequestthrottle portnumber requestoutputthrottle requestinputthrottle localchkfetchbytessentaverage localchkfetchbytesreceivedaverage chkfetchscheduler clientrequestscheduler chkrequeststarter schedulerconfig chkrequester chkrequeststarter setscheduler chkfetchscheduler chkrequeststarter insertthrottle chainedrequestthrottle requestthrottle chkinsertthrottle myrequestthrottle throttlewindow chkinsertthrottle chkinsertstarter requeststarter chkinsertthrottle portnumber requestoutputthrottle requestinputthrottle localchkinsertbytessentaverage localchkinsertbytesreceivedaverage chkputscheduler clientrequestscheduler chkinsertstarter schedulerconfig chkinserter chkinsertstarter setscheduler chkputscheduler chkinsertstarter sskrequestthrottle myrequestthrottle throttlewindow sskrequestthrottle sskrequeststarter requeststarter sskrequestthrottle portnumber requestoutputthrottle requestinputthrottle localsskfetchbytessentaverage localsskfetchbytesreceivedaverage sskfetchscheduler clientrequestscheduler sskrequeststarter schedulerconfig sskrequester sskrequeststarter setscheduler sskfetchscheduler sskrequeststarter insertthrottle chainedrequestthrottle requestthrottle sskinsertthrottle myrequestthrottle throttlewindow sskinsertthrottle sskinsertstarter requeststarter sskinsertthrottle portnumber requestoutputthrottle requestinputthrottle localsskinsertbytessentaverage localsskfetchbytesreceivedaverage sskputscheduler clientrequestscheduler sskinsertstarter schedulerconfig sskinserter sskinsertstarter setscheduler sskputscheduler sskinsertstarter schedulerconfig finishedinitialization private final int size public my request throttle throttle window manager throttle window int rtt string string simple field set fs int size round trip time new bootstrapping decaying running average rtt 10 5 60 1000 10 fs null null fs subset round trip time this size size myrequestthrottle throttlewindowmanager throttlewindow simplefieldset roundtriptime bootstrappingdecayingrunningaverage roundtriptime public synchronized long get delay double rtt round trip time current value double win size for min packet delay rtt min delay double simulatedwindowsize throttle window current value if simulatedwindowsize win size for min packet delay simulatedwindowsize win size for min packet delay if simulatedwindowsize 1 0 simulatedwindowsize 1 0f return long roundtriptime simulatedwindowsize return math max min delay math min long rtt simulatedwindowsize max delay getdelay roundtriptime currentvalue winsizeforminpacketdelay min_delay _simulatedwindowsize throttlewindow currentvalue _simulatedwindowsize winsizeforminpacketdelay _simulatedwindowsize winsizeforminpacketdelay _simulatedwindowsize _simulatedwindowsize _roundtriptime _simulatedwindowsize min_delay _simulatedwindowsize max_delay public synchronized void successful completion long rtt round trip time report math max rtt 10 if logger should log logger minor this logger minor this reported successful completion rtt on this avg round trip time current value successfulcompletion roundtriptime shouldlog roundtriptime currentvalue override public string to string return rtt round trip time current value s throttle window current value tostring roundtriptime currentvalue _s throttlewindow currentvalue public simple field set export field set simple field set fs new simple field set false fs put round trip time round trip time export field set false return fs simplefieldset exportfieldset simplefieldset simplefieldset roundtriptime roundtriptime exportfieldset public double getrtt return round trip time current value roundtriptime currentvalue public long get rate return long 1000 0 get delay size getrate getdelay public base request throttle getchk request throttle return chk request throttle baserequestthrottle getchkrequestthrottle chkrequestthrottle public base request throttle getchk insert throttle return chk insert throttle baserequestthrottle getchkinsertthrottle chkinsertthrottle public base request throttle getssk request throttle return ssk request throttle baserequestthrottle getsskrequestthrottle sskrequestthrottle public base request throttle getssk insert throttle return ssk insert throttle baserequestthrottle getsskinsertthrottle sskinsertthrottle public void request completed boolean isssk boolean is insert key key throttle window request completed isssk throttle windowssk throttle windowchk request completed is insert throttle window insert throttle window request request completed stats report outgoing request location key to normalized double requestcompleted isinsert throttlewindow requestcompleted throttlewindowssk throttlewindowchk requestcompleted isinsert throttlewindowinsert throttlewindowrequest requestcompleted reportoutgoingrequestlocation tonormalizeddouble public void rejected overload boolean isssk boolean is insert throttle window rejected overload isssk throttle windowssk throttle windowchk rejected overload is insert throttle window insert throttle window request rejected overload rejectedoverload isinsert throttlewindow rejectedoverload throttlewindowssk throttlewindowchk rejectedoverload isinsert throttlewindowinsert throttlewindowrequest rejectedoverload persist the throttle data to a simple field set simple field set persist to field set simple field set fs new simple field set false fs put throttle window throttle window export field set false fs put throttle windowchk throttle windowchk export field set false fs put throttle windowssk throttle windowchk export field set false fs put chk request throttle chk request throttle export field set fs put ssk request throttle ssk request throttle export field set fs put chk insert throttle chk insert throttle export field set fs put ssk insert throttle ssk insert throttle export field set return fs simplefieldset simplefieldset persisttofieldset simplefieldset simplefieldset throttlewindow throttlewindow exportfieldset throttlewindowchk throttlewindowchk exportfieldset throttlewindowssk throttlewindowchk exportfieldset chkrequestthrottle chkrequestthrottle exportfieldset sskrequestthrottle sskrequestthrottle exportfieldset chkinsertthrottle chkinsertthrottle exportfieldset sskinsertthrottle sskinsertthrottle exportfieldset public double get window return throttle window current value getwindow throttlewindow currentvalue public double getrtt boolean isssk boolean is insert return get throttle isssk is insert getrtt isinsert getthrottle isinsert public double get delay boolean isssk boolean is insert return get throttle isssk is insert get delay getdelay isinsert getthrottle isinsert getdelay my request throttle get throttle boolean isssk boolean is insert if isssk if is insert return ssk insert throttle else return ssk request throttle else if is insert return chk insert throttle else return chk request throttle myrequestthrottle getthrottle isinsert isinsert sskinsertthrottle sskrequestthrottle isinsert chkinsertthrottle chkrequestthrottle public string stats page line boolean isssk boolean is insert string builder sb new string builder 100 sb append isssk ssk chk sb append sb append is insert insert request sb append rtt my request throttle throttle get throttle isssk is insert sb append time util format time long throttle getrtt 2 true sb append delay sb append time util format time throttle get delay 2 true sb append bw sb append throttle get rate sb append b sec return sb to string statspageline isinsert stringbuilder stringbuilder isinsert myrequestthrottle getthrottle isinsert timeutil formattime timeutil formattime getdelay getrate tostring public string diagnostic throttles line boolean mode string builder sb new string builder if mode sb append request window sb append throttle window request to string sb append insert window sb append throttle window insert to string else sb append chk window sb append throttle windowchk to string sb append ssk window sb append throttle windowssk to string return sb to string diagnosticthrottlesline stringbuilder stringbuilder throttlewindowrequest tostring throttlewindowinsert tostring throttlewindowchk tostring throttlewindowssk tostring tostring public double get real window return throttle window real current value getrealwindow throttlewindow realcurrentvalue public long count transient queued requests return chk fetch scheduler count transient queued requests ssk fetch scheduler count transient queued requests chk put scheduler count transient queued requests ssk put scheduler count transient queued requests counttransientqueuedrequests chkfetchscheduler counttransientqueuedrequests sskfetchscheduler counttransientqueuedrequests chkputscheduler counttransientqueuedrequests sskputscheduler counttransientqueuedrequests final fcp client global forever client public fcp persistent root long nodedb handle object container container this nodedb handle nodedb handle global forever client new fcp client global queue null true null client request persist forever this container fcpclient globalforeverclient fcppersistentroot nodedbhandle objectcontainer nodedbhandle nodedbhandle globalforeverclient fcpclient clientrequest persist_forever public static fcp persistent root create final long nodedb handle object container container object set fcp persistent root set container query new predicate fcp persistent root override public boolean match fcp persistent root root return root nodedb handle nodedb handle system err println count of roots set size if set has next system err println loaded fcp persistent root fcp persistent root root set next container activate root 2 root global forever client init container return root fcp persistent root root new fcp persistent root nodedb handle container container store root system err println created fcp persistent root return root fcppersistentroot nodedbhandle objectcontainer objectset fcppersistentroot fcppersistentroot fcppersistentroot nodedbhandle nodedbhandle hasnext fcppersistentroot globalforeverclient fcppersistentroot fcppersistentroot nodedbhandle public static fcp persistent root create final long nodedb handle object container container object set fcp persistent root set container query new predicate fcp persistent root override public boolean match fcp persistent root root return root nodedb handle nodedb handle fcppersistentroot nodedbhandle objectcontainer objectset fcppersistentroot fcppersistentroot fcppersistentroot nodedbhandle nodedbhandle public fcp client register forever client final string name node client core core fcp connection handler handler fcp server server object container container if logger should log logger minor this logger minor this registering forever client for name fixme db4o native queries involving strings seem to do wierd things i was getting the global queue returned here even though i compared with the passed in name fixme reproduce and file a bug for db4o query query container query query constrain fcp client class don t constrain by root because that set is huge i think that was the cause of the oo ms here constraint con query descend name constrain name con and query descend root constrain this identity object set set query execute while set has next fcp client client fcp client set next container activate client 1 if client root this container deactivate client 1 continue client set connection handler if name equals client name logger error this returning client for name if logger should log logger minor this logger minor this returning client for name client init container return client fcp client client new fcp client name handler false null client request persist forever this container container store client return client fcpclient registerforeverclient nodeclientcore fcpconnectionhandler fcpserver objectcontainer shouldlog fcpclient ooms objectset hasnext fcpclient fcpclient setconnection shouldlog fcpclient fcpclient clientrequest persist_forever public void maybe unregister client fcp client client object container container if client has persistent requests container client remove from database container maybeunregisterclient fcpclient objectcontainer haspersistentrequests removefromdatabase public property list propertylist public property get property int n return property get n getproperty static final int sizeof 8 static int get size byte arr int offs return bytes unpack4 arr offs getsize return bytes unpack4 arr offs static void set size byte arr int offs int size bytes pack4 arr offs size setsize bytes pack4 arr offs size static int get type byte arr int offs return bytes unpack4 arr offs 4 gettype return bytes unpack4 arr offs 4 static void set type byte arr int offs int type bytes pack4 arr offs 4 type settype private node allowed value range node public node get allowed value range node return allowed value range node allowedvaluerangenode getallowedvaluerangenode allowedvaluerangenode public allowed value range node node allowed value range node node allowedvaluerange allowedvaluerangenode public static boolean is allowed value range node node node return elem name equals node get name isallowedvaluerangenode elem_name getname private final static string minimum minimum public void set minimum string value get allowed value range node set node minimum value setminimum getallowedvaluerangenode setnode public string get minimum return get allowed value range node get node value minimum getminimum getallowedvaluerangenode getnodevalue private final static string maximum maximum public void set maximum string value get allowed value range node set node maximum value setmaximum getallowedvaluerangenode setnode public string get maximum return get allowed value range node get node value maximum getmaximum getallowedvaluerangenode getnodevalue private final static string step step public void set step string value get allowed value range node set node step value setstep getallowedvaluerangenode setnode public string get step return get allowed value range node get node value step getstep getallowedvaluerangenode getnodevalue param args throws invalid threshold exception throws node init exception throws interrupted exception throws io exception public static void main string args throws invalid threshold exception node init exception interrupted exception io exception node node null try string ip override null if args length 0 ip override args 0 file dir new file bootstrap test file util remove all dir random source random node starter global test init dir get path false logger error false file seednodes new file seednodes fref if seednodes exists seednodes length 0 seednodes can read system err println unable to read seednodes fref it doesn t exist or is empty system exit exit no seednodes file inner dir new file dir 5000 inner dir mkdir file input stream fis new file input stream seednodes file util write to fis new file inner dir seednodes fref fis close create one node executor executor new pooled executor node node starter create test node 5000 5001 bootstrap test true false false node default max htl 0 random executor 1000 5 1024 1024 true true true true true true true 12 1024 false true ip override node crypto disable group strip true logger setup stdout logging logger minor freenet normal freenet node node dispatcher minor freenet node fnp packet mangler minor logger get chain set threshold logger error kill logging long start time system current time millis start it node start true wait until we have 10 connected nodes int seconds 0 while seconds 600 thread sleep 1000 int seeds node peers count seednodes int seed conns node peers get connected seed server peers vector null size int opennet peers node peers count valid peers int opennet conns node peers count connected opennet peers system err println seconds seeds seeds connected seed conns opennet peers opennet peers connected opennet conns seconds if opennet conns target peers long time taken system current time millis start time system out println completed bootstrap target peers peers in time taken ms time util format time time taken node park system exit 0 system err println failed to reach target peers count target peers in 5 minutes node park system exit exit failed target catch throwable t system err println caught t t print stack trace try if node null node park catch throwable t1 system exit exit threw something invalidthresholdexception nodeinitexception interruptedexception ioexception invalidthresholdexception nodeinitexception interruptedexception ioexception ipoverride ipoverride fileutil removeall randomsource nodestarter globaltestinit getpath canread exit_no_seednodes innerdir innerdir fileinputstream fileinputstream fileutil writeto innerdir pooledexecutor nodestarter createtestnode default_max_htl ipoverride nodecrypto disable_group_strip setupstdoutlogging nodedispatcher fnppacketmangler getchain setthreshold starttime currenttimemillis countseednodes seedconns getconnectedseedserverpeersvector opennetpeers countvalidpeers opennetconns countconnectedopennetpeers seedconns opennetpeers opennetconns opennetconns target_peers timetaken currenttimemillis starttime target_peers timetaken timeutil formattime timetaken target_peers exit_failed_target printstacktrace exit_threw_something logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog protected transient set key listener key listeners abstract boolean persistent keylistener keylisteners protected client request scheduler base boolean for inserts boolean forss ks this is insert scheduler for inserts this isssk scheduler forss ks key listeners new hash set key listener priorities new sorted vector by number request starter number of priority classes clientrequestschedulerbase forinserts forssks isinsertscheduler forinserts issskscheduler forssks keylisteners hashset keylistener sortedvectorbynumber requeststarter number_of_priority_classes param req param random param container param maybe active array of requests can be null which are being registered in this group these will be ignored for purposes of checking whether stuff is activated when it shouldn t be it is perfectly okay to have req be a member of maybe active fixme either get rid of the debugging code and therefore get rid of maybe active or make req a sendable request and register them all at once void inner register sendable request req random source random object container container sendable request maybe active if is insert scheduler req instanceof base sendable get throw new illegal argument exception adding a sendable get to an insert scheduler if is insert scheduler req instanceof sendable insert throw new illegal argument exception adding a sendable insert to a request scheduler if is insert scheduler req is insert throw new illegal argument exception request is insert req is insert but my is insert scheduler is insert scheduler if req persistent persistent throw new illegal argument exception inner register for persistence req persistent but our persistence is persistent if req get priority class container 0 logger normal this something wierd logger normal this priority req get priority class container int retry count req get retry count short prio req get priority class container if logminor logger minor this still registering req at prio prio retry retry count for req get client request add to requests by client request req get client request req container add to grab array prio retry count fix retry count retry count req get client container req get client request req random container if logminor logger minor this registered req on prioclass prio retrycount retry count if persistent sched maybe add to starter queue req container maybe active maybeactive maybeactive maybeactive sendablerequest innerregister sendablerequest randomsource objectcontainer sendablerequest maybeactive isinsertscheduler basesendableget illegalargumentexception sendableget isinsertscheduler sendableinsert illegalargumentexception sendableinsert isinsertscheduler isinsert illegalargumentexception isinsert isinsert isinsertscheduler isinsertscheduler illegalargumentexception innerregister getpriorityclass getpriorityclass retrycount getretrycount getpriorityclass retrycount getclientrequest addtorequestsbyclientrequest getclientrequest addtograbarray retrycount fixretrycount retrycount getclient getclientrequest retrycount maybeaddtostarterqueue maybeactive protected void add to requests by client request client requester client request sendable request req object container container if client request null persistent client request null is only legal for transient requests boolean deactivate false if persistent deactivate container ext is active client request if deactivate container activate client request 1 client request add to requests req container if deactivate container deactivate client request 1 addtorequestsbyclientrequest clientrequester clientrequest sendablerequest objectcontainer clientrequest isactive clientrequest clientrequest clientrequest addtorequests clientrequest synchronized void add to grab array short priority class int retry count int rc request client client client requester cr sendable request req random source random object container container if priority class request starter minimum priority class priority class request starter maximum priority class throw new illegal state exception invalid priority priority class range is request starter maximum priority class most important to request starter minimum priority class least important priority sorted vector by number prio priorities priority class if prio null prio new sorted vector by number persistent priorities priority class prio if persistent container store this client sectored random grab array with int client grabber sectored random grab array with int prio get rc container if persistent container activate client grabber 1 if client grabber null client grabber new sectored random grab array with int rc persistent container null prio add client grabber container if logminor logger minor this registering retry count rc with prioclass priority class on client grabber for prio sectored random grab array with int and lower down have hierarchical locking and auto remove to avoid a race condition it is essential to mirror that here synchronized client grabber request sectored random grab array with object request grabber sectored random grab array with object client grabber get grabber client if persistent container activate request grabber 1 if request grabber null request grabber new sectored random grab array with object client persistent container client grabber if logminor logger minor this creating new grabber request grabber for client from client grabber prio prio priority class rc rc client grabber add grabber client request grabber container request grabber add cr req container addtograbarray priorityclass retrycount requestclient clientrequester sendablerequest randomsource objectcontainer priorityclass requeststarter minimum_priority_class priorityclass requeststarter maximum_priority_class illegalstateexception priorityclass requeststarter maximum_priority_class requeststarter minimum_priority_class sortedvectorbynumber priorityclass sortedvectorbynumber priorityclass sectoredrandomgrabarraywithint clientgrabber sectoredrandomgrabarraywithint clientgrabber clientgrabber clientgrabber sectoredrandomgrabarraywithint clientgrabber priorityclass clientgrabber sectoredrandomgrabarraywithint clientgrabber sectoredrandomgrabarraywithobject requestgrabber sectoredrandomgrabarraywithobject clientgrabber getgrabber requestgrabber requestgrabber requestgrabber sectoredrandomgrabarraywithobject clientgrabber requestgrabber clientgrabber priorityclass clientgrabber addgrabber requestgrabber requestgrabber mangle the retry count below a certain number of attempts we don t prefer one request to another just because it s been tried more times the reason for this is to prevent floods of low retry count requests from starving other clients requests which need to be retried the other solution would be to sort by client before retry count but that would be excessive imho we do want to avoid rerequesting keys we ve tried many times before protected int fix retry count int retry count return math max 0 retry count min retry count fixretrycount retrycount retrycount min_retry_count get sendable request s for a given client requester note that this will return all kinds of requests so the caller will have to filter them according to is insert and isssk scheduler protected sendable request get sendable requests client requester request object container container if request null persistent client request null is only legal for transient requests return request get sendable requests container else return null sendablerequest clientrequester isinsert issskscheduler sendablerequest getsendablerequests clientrequester objectcontainer getsendablerequests void remove from all requests by client request sendable request req client requester cr boolean dont complain object container container if cr null persistent client request null is only legal for transient requests cr remove from requests req container dont complain removefromallrequestsbyclientrequest sendablerequest clientrequester dontcomplain objectcontainer removefromrequests dontcomplain public void reregister all client requester request random source random request scheduler lock object container container client context context if request persistent persistent return sendable request reqs get sendable requests request container if reqs null return for int i 0 i reqs length i sendable request req reqs i if persistent container activate req 1 fixme call get sendable requests and do the sorting in client request scheduler reregister all if req is insert is insert scheduler req isssk isssk scheduler if persistent container deactivate req 1 continue unregister from the rga s but keep the pending keys and cooldown queue data req unregister container context then can do inner register not register inner register req random container null if persistent container deactivate req 1 reregisterall clientrequester randomsource requestscheduler objectcontainer clientcontext sendablerequest getsendablerequests sendablerequest getsendablerequests clientrequestscheduler reregisterall isinsert isinsertscheduler issskscheduler pendingkeys innerregister innerregister public void succeeded base sendable get succeeded object container container do nothing basesendableget objectcontainer public void add pending keys key listener listener if listener null throw new null pointer exception synchronized this key listeners add listener if logminor logger minor this added pending keys to this size now key listeners size listener addpendingkeys keylistener nullpointerexception keylisteners keylisteners public boolean remove pending keys key listener listener boolean ret synchronized this ret key listeners remove listener listener on remove if logminor logger minor this removed pending keys from this size now key listeners size listener return ret removependingkeys keylistener keylisteners onremove keylisteners public synchronized boolean remove pending keys has key listener has listener boolean found false for iterator key listener i key listeners iterator i has next key listener listener i next if listener null i remove logger error this null key listener in remove pending keys continue if listener get has key listener has listener found true i remove listener on remove logger normal this removed pending keys from this size now key listeners size listener return found removependingkeys haskeylistener haslistener keylistener keylisteners hasnext keylistener keylistener removependingkeys gethaskeylistener haslistener onremove keylisteners public short get key prio key key short priority object container container client context context byte salted key key instanceof nodessk context get ssk fetch scheduler context get chk fetch scheduler salt key key array list key listener matches null synchronized this for key listener listener key listeners if listener probably want key key salted key continue if matches null matches new array list key listener matches add listener if matches null return priority for key listener listener matches short prio listener definitely want key key salted key container sched client context if prio 1 continue if prio priority priority prio return priority getkeyprio objectcontainer clientcontext saltedkey getsskfetchscheduler getchkfetchscheduler saltkey arraylist keylistener keylistener keylisteners probablywantkey saltedkey arraylist keylistener keylistener definitelywantkey saltedkey clientcontext public synchronized long count waiting keys object container container long count 0 for key listener listener key listeners count listener count keys return count countwaitingkeys objectcontainer keylistener keylisteners countkeys public boolean any want key key key object container container client context context byte salted key key instanceof nodessk context get ssk fetch scheduler context get chk fetch scheduler salt key key array list key listener matches null synchronized this for key listener listener key listeners if listener probably want key key salted key continue if matches null matches new array list key listener matches add listener if matches null for key listener listener matches if listener definitely want key key salted key container sched client context 0 return true return false anywantkey objectcontainer clientcontext saltedkey getsskfetchscheduler getchkfetchscheduler saltkey arraylist keylistener keylistener keylisteners probablywantkey saltedkey arraylist keylistener keylistener definitelywantkey saltedkey clientcontext public synchronized boolean any probably want key key key client context context byte salted key key instanceof nodessk context get ssk fetch scheduler context get chk fetch scheduler salt key key for key listener listener key listeners if listener probably want key key salted key return true return false anyprobablywantkey clientcontext saltedkey getsskfetchscheduler getchkfetchscheduler saltkey keylistener keylisteners probablywantkey saltedkey public boolean trip pending key key key key block block object container container client context context if key instanceof nodessk isssk scheduler logger error this key key on scheduler ssk isssk scheduler new exception debug return false byte salted key sched salt key key array list key listener matches null synchronized this for key listener listener key listeners if listener probably want key key salted key continue if matches null matches new array list key listener if matches contains listener logger error this in matches twice presumably in key listeners twice listener continue matches add listener boolean ret false if matches null for key listener listener matches if listener handle block key salted key block container context ret true if listener is empty synchronized this key listeners remove listener listener on remove else return false if ret true positive synchronized this persistent true positives log false positives hit else synchronized this persistent false positives log false positives false return ret trippendingkey keyblock objectcontainer clientcontext issskscheduler issskscheduler saltedkey saltkey arraylist keylistener keylistener keylisteners probablywantkey saltedkey arraylist keylistener keylisteners keylistener handleblock saltedkey isempty keylisteners onremove persistenttruepositives logfalsepositives persistentfalsepositives logfalsepositives synchronized void count negative persistent negatives if persistent negatives 32 0 log false positives neg countnegative persistentnegatives persistentnegatives logfalsepositives private synchronized void log false positives string phase long total positives persistent false positives persistent true positives double percent if total positives 0 percent double 100 persistent false positives total positives else percent 0 if percent 2 logminor return string builder buf new string builder if persistent buf append persistent else buf append transient buf append false positives buf append phase buf append if total positives 0 buf append percent buf append buf append false buf append persistent false positives buf append true buf append persistent true positives buf append negatives buf append persistent negatives buf append if percent 10 logger error this buf to string else if percent 2 logger normal this buf to string else logger minor this buf to string logfalsepositives totalpositives persistentfalsepositives persistenttruepositives totalpositives persistentfalsepositives totalpositives stringbuilder stringbuilder totalpositives persistentfalsepositives persistenttruepositives persistentnegatives tostring tostring tostring public sendable get requests for key key key object container container client context context array list sendable get list null byte salted key sched salt key key synchronized this for key listener listener key listeners if listener probably want key key salted key continue sendable get reqs listener get requests for key key salted key container context if reqs null continue if list null list new array list sendable get for int i 0 i reqs length i list add reqs i if list null return null else return list to array new sendable get list size sendableget requestsforkey objectcontainer clientcontext arraylist sendableget saltedkey saltkey keylistener keylisteners probablywantkey saltedkey sendableget getrequestsforkey saltedkey arraylist sendableget toarray sendableget public void on started key listeners new hash set key listener onstarted keylisteners hashset keylistener override public string to string string buffer sb new string buffer sb append super to string sb append if is insert scheduler sb append insert if isssk scheduler sb append ssk else sb append chk return sb to string tostring stringbuffer stringbuffer tostring isinsertscheduler issskscheduler tostring public synchronized long count queued requests object container container client context context long total 0 for int i 0 i priorities length i sorted vector by number prio priorities i if prio null prio is empty system out println priority i empty else system out println priority i prio count for int j 0 j prio count j int frc prio get number by index j system out println fixed retry count frc sectored random grab array with int client grabber sectored random grab array with int prio get frc container container activate client grabber 1 system out println clients client grabber size for client grabber for int k 0 k client grabber size k object client client grabber get client k container activate client 1 system out println client k client container deactivate client 1 sectored random grab array with object request grabber sectored random grab array with object client grabber get grabber client container activate request grabber 1 system out println srga for client request grabber for int l 0 l request grabber size l client request grabber get client l container activate client 1 system out println request l client container deactivate client 1 random grab array rga random grab array request grabber get grabber client container activate rga 1 system out println queued sendable requests rga size on rga long sendable 0 long all 0 for int m 0 m rga size m sendable request req sendable request rga get m container if req null continue container activate req 1 sendable req count sendable keys container context all req count all keys container context container deactivate req 1 system out println sendable keys sendable all keys all diff all sendable total all container deactivate rga 1 container deactivate request grabber 1 container deactivate client grabber 1 return total countqueuedrequests objectcontainer clientcontext sortedvectorbynumber isempty getnumberbyindex sectoredrandomgrabarraywithint clientgrabber sectoredrandomgrabarraywithint clientgrabber clientgrabber clientgrabber clientgrabber clientgrabber getclient sectoredrandomgrabarraywithobject requestgrabber sectoredrandomgrabarraywithobject clientgrabber getgrabber requestgrabber requestgrabber requestgrabber requestgrabber getclient randomgrabarray randomgrabarray requestgrabber getgrabber sendablerequests sendablerequest sendablerequest countsendablekeys countallkeys requestgrabber clientgrabber public wot messageuri freeneturi my freeneturi string my messageid if my freeneturi null my messageid null throw new illegal argument exception trying to create an empty wot messageuri m freeneturi my freeneturi isusk my freeneturi ssk forusk my freeneturi if m freeneturi isssk throw new illegal argument exception trying to create a wot messageuri with illegal key type my freeneturi get key type m messageid my messageid string tokens m messageid split 2 try uuid from string tokens 0 catch illegal argument exception e throw new illegal argument exception illegal id m messageid if tokens 1 equals base64 encode m freeneturi get routing key false throw new illegal argument exception illegal id m messageid wotmessageuri myfreeneturi mymessageid myfreeneturi mymessageid illegalargumentexception wotmessageuri mfreeneturi myfreeneturi myfreeneturi sskforusk myfreeneturi mfreeneturi illegalargumentexception wotmessageuri myfreeneturi getkeytype mmessageid mymessageid mmessageid fromstring illegalargumentexception illegalargumentexception mmessageid mfreeneturi getroutingkey illegalargumentexception mmessageid decodes a wot messageuri which was encoded by the to string method param uri throws malformedurl exception the uri does not start with a valid ssk freeneturi or there is no valid uuid attached after the public wot messageuri string uri throws malformedurl exception if uri null throw new illegal argument exception trying to create an empty wot messageuri string tokens uri split 2 if tokens length 2 throw new malformedurl exception invalid message uri message list specified but no uuid given uri freeneturi tempuri new freeneturi tokens 0 m freeneturi tempuri isusk tempuri ssk forusk tempuri if m freeneturi isssk fixme usk is only allowed for legacy because there are broken message lists in the network remove throw new malformedurl exception trying to create a wot messageuri with illegal key type m freeneturi get key type try m messageid uuid from string tokens 1 base64 encode m freeneturi get routing key catch illegal argument exception e throw new malformedurl exception invalid uuid tokens 1 wotmessageuri tostring malformedurlexception wotmessageuri malformedurlexception illegalargumentexception wotmessageuri malformedurlexception mfreeneturi sskforusk mfreeneturi malformedurlexception wotmessageuri mfreeneturi getkeytype mmessageid fromstring mfreeneturi getroutingkey illegalargumentexception malformedurlexception override public freeneturi get freeneturi return m freeneturi getfreeneturi mfreeneturi override public string get messageid return m messageid getmessageid mmessageid override public boolean equals object obj wot messageuri uri wot messageuri obj return uri get freeneturi equals m freeneturi uri get messageid equals m messageid wotmessageuri wotmessageuri getfreeneturi mfreeneturi getmessageid mmessageid returns the ssk uri of the message list in which the message appeared the uuid part of the message id the part before the message i ds are constructed as random uuid base64 encoded author ssk routing key therefore we only need to include the random uuid in the string representation of the wot messageuri because the routing key is already contained in the ssk part and can be obtained from there when decoding the string override public string to string return m freeneturi to string m messageid split 2 0 ids wotmessageuri tostring mfreeneturi tostring mmessageid private float exposure 1 0f override protected float transfer function float f return 1 float math exp f exposure transferfunction set the exposure level param exposure the exposure level min value 0 max value 5 see get exposure public void set exposure float exposure this exposure exposure initialized false getexposure setexposure get the exposure level return the exposure level see set exposure public float get exposure return exposure setexposure getexposure override public string to string return colors exposure tostring public class boolean option extends option boolean public boolean option sub config conf string option name boolean default value int sort order boolean expert boolean force write string short desc string long desc boolean callback cb super conf option name cb sort order expert force write short desc long desc option data type boolean this default value default value this current value default value booleanoption booleanoption subconfig optionname defaultvalue sortorder forcewrite shortdesc longdesc booleancallback optionname sortorder forcewrite shortdesc longdesc datatype defaultvalue defaultvalue currentvalue defaultvalue override public boolean parse string string val throws invalid config value exception if val equals ignore case true val equals ignore case yes return true else if val equals ignore case false val equals ignore case no return false else throw new option format exception l10n get string boolean option parse error val val parsestring invalidconfigvalueexception equalsignorecase equalsignorecase equalsignorecase equalsignorecase optionformatexception getstring booleanoption parseerror override protected string to string boolean val return val to string tostring tostring final usk usk public usk fetcher wrapper usk usk short prio request client client super prio client this usk usk uskfetcherwrapper requestclient override public freeneturi geturi return usk geturi override public boolean is finished return false isfinished override public void notify clients object container container client context context do nothing notifyclients objectcontainer clientcontext public void on success fetch result result client get state state object container container client context context ignore we don t do anything with it because we are running in the background onsuccess fetchresult clientgetstate objectcontainer clientcontext public void on failure fetch exception e client get state state object container container client context context ignore onfailure fetchexception clientgetstate objectcontainer clientcontext public void on block set finished client get state state object container container client context context ignore onblocksetfinished clientgetstate objectcontainer clientcontext override public void on transition client get state old state client get state new state object container container ignore ontransition clientgetstate oldstate clientgetstate newstate objectcontainer override public string to string return super to string usk tostring tostring public void on expectedmime string mime object container container client context context ignore onexpectedmime objectcontainer clientcontext public void on expected size long size object container container client context context ignore onexpectedsize objectcontainer clientcontext public void on finalized metadata object container container ignore onfinalizedmetadata objectcontainer override public void cancel object container container client context context super cancel objectcontainer clientcontext override protected void inner to network object container container client context context ignore innertonetwork objectcontainer clientcontext public http request httprequest public http request input stream in super in httprequest inputstream public http request http socket http sock this http sock get input stream set socket http sock httprequest httpsocket httpsock httpsock getinputstream setsocket httpsock private string method null public void set method string value method value setmethod public string get method if method null return method return get first line token 0 getmethod getfirstlinetoken public boolean is method string method string header method get method if header method null return false return header method equals ignore case method ismethod headermethod getmethod headermethod headermethod equalsignorecase public boolean is get request return is method http get isgetrequest ismethod public boolean is post request return is method http post ispostrequest ismethod public boolean is head request return is method http head isheadrequest ismethod public boolean is subscribe request return is method http subscribe issubscriberequest ismethod public boolean is unsubscribe request return is method http unsubscribe isunsubscriberequest ismethod public boolean is notify request return is method http notify isnotifyrequest ismethod public void seturi string value boolean is check relativeurl uri value if is check relativeurl false return thanks for giordano sassaroli sassarol cefriel it 09 02 03 uri http to relativeurl uri ischeckrelativeurl ischeckrelativeurl torelativeurl public void seturi string value seturi value false public string geturi if uri null return uri return get first line token 1 getfirstlinetoken public parameter list get parameter list parameter list param list new parameter list string uri geturi if uri null return param list int param idx uri index of if param idx 0 return param list while 0 param idx int eq idx uri index of param idx 1 string name uri substring param idx 1 eq idx int next param idx uri index of eq idx 1 string value uri substring eq idx 1 0 next param idx next param idx uri length parameter param new parameter name value param list add param param idx next param idx return param list parameterlist getparameterlist parameterlist paramlist parameterlist paramlist paramidx indexof paramidx paramlist paramidx eqidx indexof paramidx paramidx eqidx nextparamidx indexof eqidx eqidx nextparamidx nextparamidx paramlist paramidx nextparamidx paramlist public string get parameter value string name parameter list param list get parameter list return param list get value name getparametervalue parameterlist paramlist getparameterlist paramlist getvalue public boolean issoap action return has header http soap action issoapaction hasheader soap_action private string request host public void set request host string host request host host requesthost setrequesthost requesthost public string get request host return request host getrequesthost requesthost private int request port 1 public void set request port int host request port host requestport setrequestport requestport public int get request port return request port getrequestport requestport private http socket http socket null public void set socket http socket value http socket value httpsocket httpsocket setsocket httpsocket httpsocket public http socket get socket return http socket httpsocket getsocket httpsocket public string get local address return get socket get local address getlocaladdress getsocket getlocaladdress public int get local port return get socket get local port getlocalport getsocket getlocalport public boolean parse request line string line str string tokenizer st new string tokenizer line str http reqest line delim if st has more tokens false return false set method st next token if st has more tokens false return false seturi st next token if st has more tokens false return false set version st next token return true parserequestline linestr stringtokenizer stringtokenizer linestr reqest_line_delim hasmoretokens setmethod nexttoken hasmoretokens nexttoken hasmoretokens setversion nexttoken public string gethttp version if has first line true return get first line token 2 return http super get version gethttpversion hasfirstline getfirstlinetoken getversion public string get first line string return get method geturi gethttp version http crlf getfirstlinestring getmethod gethttpversion public string get header string builder str new string builder str append get first line string string header string get header string str append header string return str to string getheader stringbuilder stringbuilder getfirstlinestring headerstring getheaderstring headerstring tostring public boolean is keep alive if is close connection true return false if is keep alive connection true return true string http ver gethttp version boolean ishttp10 0 http ver index of 1 0 true false if ishttp10 true return false return true iskeepalive iscloseconnection iskeepaliveconnection httpver gethttpversion httpver indexof public boolean read return super read get socket getsocket public boolean post http response http res http socket http sock get socket long offset 0 long length http res get content length if has content range true long first pos get content range first position long last pos get content range last position thanks for brent hills 10 26 04 if last pos 0 last pos length 1 if first pos length last pos length return return response http status invalid range http res set content range first pos last pos length http res set status code http status partial content offset first pos length last pos first pos 1 return http sock post http res offset length is head request http sock close httpresponse httpres httpsocket httpsock getsocket httpres getcontentlength hascontentrange firstpos getcontentrangefirstposition lastpos getcontentrangelastposition lastpos lastpos firstpos lastpos returnresponse httpstatus invalid_range httpres setcontentrange firstpos lastpos httpres setstatuscode httpstatus partial_content firstpos lastpos firstpos httpsock httpres isheadrequest httpsock public http response post string host int port boolean is keep alive http response http res new http response set connection is keep alive true http keep alive http close boolean is header request is head request output stream out null input stream in null try if post socket null post socket new socket host port out post socket get output stream print stream pout new print stream out pout print get header pout print http crlf boolean is chunked request is chunked string content get content string int content length 0 if content null content length content length if 0 content length if is chunked request true string chun size buf long to string content length pout print chun size buf pout print http crlf pout print content if is chunked request true pout print http crlf if is chunked request true pout print 0 pout print http crlf pout flush in post socket get input stream http res set in is header request catch exception e http res set status code http status internal server error finally if is keep alive false try in close catch exception e if in null try out close catch exception e if out null try post socket close catch exception e post socket null return http res httpresponse iskeepalive httpresponse httpres httpresponse setconnection iskeepalive keep_alive isheaderrequest isheadrequest outputstream inputstream postsocket postsocket postsocket getoutputstream printstream printstream getheader ischunkedrequest ischunked getcontentstring contentlength contentlength contentlength ischunkedrequest chunsizebuf tostring contentlength chunsizebuf ischunkedrequest ischunkedrequest postsocket getinputstream httpres isheaderrequest httpres setstatuscode httpstatus internal_server_error iskeepalive postsocket postsocket httpres public http response post string host int port return post host port false httpresponse public void set http request http req set http packet http req set socket http req get socket httprequest httpreq httppacket httpreq setsocket httpreq getsocket public boolean return response int status code http response http res new http response http res set status code status code http res set content length 0 return post http res returnresponse statuscode httpresponse httpres httpresponse httpres setstatuscode statuscode httpres setcontentlength httpres public boolean returnok return return response http status ok returnresponse httpstatus public boolean return bad request return return response http status bad request returnbadrequest returnresponse httpstatus bad_request public string to string string builder str new string builder str append get header str append http crlf str append get content string return str to string tostring stringbuilder stringbuilder getheader getcontentstring tostring public void print system out println to string tostring creates a new web page impl it is abstract because only a subclass can run the desired make method to generate the content param m freetalk a reference to freetalk used to get references to database client whatever is needed param viewer the ft own identity which is viewing this page param request the request from the user public web page impl web interface my web interface ft own identity viewer http request request m web interface my web interface m freetalk m web interface get freetalk mpm m web interface get page maker m own identity viewer m request request webpageimpl mfreetalk ftownidentity webpageimpl webinterface mywebinterface ftownidentity httprequest mwebinterface mywebinterface mfreetalk mwebinterface getfreetalk mwebinterface getpagemaker mownidentity mrequest generates the html code that will be sent to the browser return html code of the page public final string tohtml html node page node if m own identity null page node mpm get page node freetalk plugin title m own identity get freetalk address null else page node mpm get page node freetalk plugin title null add to page mpm get content node page node return page node generate htmlnode pagenode mownidentity pagenode getpagenode plugin_title mownidentity getfreetalkaddress pagenode getpagenode plugin_title addtopage getcontentnode pagenode pagenode adds this web page to the given page as a html node public final void add to page html node content node m content node content node make webpage htmlnode addtopage htmlnode contentnode mcontentnode contentnode adds a new info box to the web page param title the title of the desired info box return the content node of the newly created info box protected final html node add content box string title html node box mpm get infobox title m content node add child box return mpm get content node box infobox webpage infobox contentnode infobox htmlnode addcontentbox htmlnode getinfobox mcontentnode addchild getcontentnode get a new infobox but do not add it to the page can be used for putting infoboxes inside infoboxes param title the title of the desired infobox return the content node of the newly created infobox protected final html node get content box string title return mpm get infobox title contentnode htmlnode getcontentbox getinfobox protected final html node get alert box string title return mpm get infobox infobox alert title htmlnode getalertbox getinfobox protected final html node add alert box string title html node box mpm get infobox infobox alert title m content node add child box return mpm get content node box htmlnode addalertbox htmlnode getinfobox mcontentnode addchild getcontentnode protected html node add form child html node parent node string target string name return m freetalk get plugin respirator add form child parent node target name htmlnode addformchild htmlnode parentnode mfreetalk getpluginrespirator addformchild parentnode protected html node get combo box string name string options string default option html node result new html node select name name for string value options if value equals default option result add child option new string value selected new string value selected value else result add child option value value value return result htmlnode getcombobox defaultoption htmlnode htmlnode defaultoption addchild addchild static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog boolean finalized size and mime type public string get expected mime type return expected mime type finalizedsizeandmimetype getexpectedmimetype expectedmimetype public boolean finalized size return finalized size and mime type finalizedsize finalizedsizeandmimetype public final string extra message get the failure mode public int get mode return mode extramessage getmode public fetch exception int m super get message m extra message null mode m error codes null newuri null expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception getmessage extramessage errorcodes expectedsize internal_error fetchexception getmessage public fetch exception int m long expected size boolean finalized size string expected mime type super get message m extra message null this finalized size and mime type finalized size mode m error codes null newuri null this expected size expected size this expected mime type expected mime type if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception expectedsize finalizedsize expectedmimetype getmessage extramessage finalizedsizeandmimetype finalizedsize errorcodes expectedsize expectedsize expectedmimetype expectedmimetype internal_error fetchexception getmessage public fetch exception int m long expected size boolean finalized size string expected mime type freeneturi uri super get message m extra message null this finalized size and mime type finalized size mode m error codes null newuri uri this expected size expected size this expected mime type expected mime type if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception expectedsize finalizedsize expectedmimetype getmessage extramessage finalizedsizeandmimetype finalizedsize errorcodes expectedsize expectedsize expectedmimetype expectedmimetype internal_error fetchexception getmessage public fetch exception metadata parse exception e super get message invalid metadata e get message extra message e get message mode invalid metadata error codes null init cause e newuri null expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception metadataparseexception getmessage invalid_metadata getmessage extramessage getmessage invalid_metadata errorcodes initcause expectedsize internal_error fetchexception getmessage public fetch exception archive failure exception e super get message archive failure e get message extra message e get message mode archive failure error codes null newuri null init cause e expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception archivefailureexception getmessage archive_failure getmessage extramessage getmessage archive_failure errorcodes initcause expectedsize internal_error fetchexception getmessage public fetch exception archive restart exception e super get message archive restart e get message extra message e get message mode archive failure error codes null init cause e newuri null expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception archiverestartexception getmessage archive_restart getmessage extramessage getmessage archive_failure errorcodes initcause expectedsize internal_error fetchexception getmessage public fetch exception int mode throwable t super get message mode t get message extra message t get message this mode mode error codes null init cause t newuri null expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception getmessage getmessage extramessage getmessage errorcodes initcause expectedsize internal_error fetchexception getmessage public fetch exception int mode string reason throwable t super reason get message mode t get message extra message t get message this mode mode error codes null init cause t newuri null expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception getmessage getmessage extramessage getmessage errorcodes initcause expectedsize internal_error fetchexception getmessage public fetch exception int mode failure code tracker error codes super get message mode extra message null this mode mode this error codes error codes newuri null expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception failurecodetracker errorcodes getmessage extramessage errorcodes errorcodes expectedsize internal_error fetchexception getmessage public fetch exception int mode string msg super get message mode msg extra message msg error codes null this mode mode newuri null expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception getmessage extramessage errorcodes expectedsize internal_error fetchexception getmessage public fetch exception int mode freeneturi newuri super get message mode extra message null this mode mode error codes null this newuri newuri expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception getmessage extramessage errorcodes expectedsize internal_error fetchexception getmessage public fetch exception int mode string msg freeneturi uri super get message mode msg extra message msg error codes null this mode mode newuri uri expected size 1 if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception getmessage extramessage errorcodes expectedsize internal_error fetchexception getmessage public fetch exception fetch exception e int new mode super get message new mode e extra message null e extra message this mode new mode this newuri e newuri this error codes e error codes this expected mime type e expected mime type this expected size e expected size this extra message e extra message this finalized size and mime type e finalized size and mime type if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception fetchexception newmode getmessage newmode extramessage extramessage newmode errorcodes errorcodes expectedmimetype expectedmimetype expectedsize expectedsize extramessage extramessage finalizedsizeandmimetype finalizedsizeandmimetype internal_error fetchexception getmessage public fetch exception fetch exception e freeneturi uri super e get message if e get cause null init cause e get cause this mode e mode this newuri uri this error codes e error codes this expected mime type e expected mime type this expected size e expected size this extra message e extra message this finalized size and mime type e finalized size and mime type if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception fetchexception getmessage getcause initcause getcause errorcodes errorcodes expectedmimetype expectedmimetype expectedsize expectedsize extramessage extramessage finalizedsizeandmimetype finalizedsizeandmimetype internal_error fetchexception getmessage public fetch exception fetch exception e super e get message init cause e this mode e mode this newuri e newuri null null e newuri clone this error codes e error codes null null e error codes clone this expected mime type e expected mime type this expected size e expected size this extra message e extra message this finalized size and mime type e finalized size and mime type if mode internal error logger error this internal error this else if logminor logger minor this fetch exception get message mode this fetchexception fetchexception getmessage initcause errorcodes errorcodes errorcodes expectedmimetype expectedmimetype expectedsize expectedsize extramessage extramessage finalizedsizeandmimetype finalizedsizeandmimetype internal_error fetchexception getmessage public static string get short message int mode string ret l10n get string fetch exception short error mode if ret null return unknown code mode else return ret getshortmessage getstring fetchexception shorterror override public string to string string builder sb new string builder 200 sb append fetch exception sb append get short message mode sb append sb append newuri sb append sb append expected size sb append sb append expected mime type sb append sb append finalized size and mime type sb append sb append error codes sb append sb append extra message return sb to string tostring stringbuilder stringbuilder fetchexception getshortmessage expectedsize expectedmimetype finalizedsizeandmimetype errorcodes extramessage tostring public static string get message int mode string ret l10n get string fetch exception long error mode if ret null return unknown fetch error code mode else return ret getmessage getstring fetchexception longerror public static final int recently failed 30 is an error fatal i e is there no point retrying public boolean is fatal return is fatal mode recently_failed isfatal isfatal suppress warnings deprecation public static boolean is fatal int mode switch mode problems with the data as inserted or the uri given no point retrying case archive failure case block decode error case too many path components case not enough path components case invalid metadata case not in archive case too deep archive recursion case too many archive restarts case too many metadata levels case too many redirects case too much recursion case unknown metadata case unknown splitfile metadata case invalid uri case too big case too big metadata case too many blocks per segment return true low level errors can be retried case data not found case route not found case rejected overload case transfer failed case all data not found case recently failed wait a bit but fine not usually fatal case splitfile error return false case bucket error case internal error maybe fatal return false wierd ones case cancelled case archive restart case permanent redirect case wrong mime type fatal return true default logger error fetch exception class do not know if error code is fatal get message mode return false assume it isn t suppresswarnings isfatal archive_failure block_decode_error too_many_path_components not_enough_path_components invalid_metadata not_in_archive too_deep_archive_recursion too_many_archive_restarts too_many_metadata_levels too_many_redirects too_much_recursion unknown_metadata unknown_splitfile_metadata invalid_uri too_big too_big_metadata too_many_blocks_per_segment data_not_found route_not_found rejected_overload transfer_failed all_data_not_found recently_failed splitfile_error bucket_error internal_error archive_restart permanent_redirect wrong_mime_type fetchexception getmessage public void set not finalized size this finalized size and mime type false setnotfinalizedsize finalizedsizeandmimetype public void remove from object container container if error codes null error codes remove from container if newuri null newuri remove from container stack trace element elements get stack trace if elements null for stack trace element element elements container delete element container delete this removefrom objectcontainer errorcodes errorcodes removefrom removefrom stacktraceelement getstacktrace stacktraceelement override public fetch exception clone return new fetch exception this fetchexception fetchexception perform stemming of the word param word word to be stemmed param language language of the word null if unknown return normal forms of the word some words belongs to more than one part of the speech so there are can be more than one normal form public string get normal forms string word string language return new string word getnormalforms split text of the documents into tokens param reader stream with document text return array of occurrences of words in thedocument public occurrence parse text reader reader throws io exception int pos 0 array list list new array list int ch reader read while ch 0 if character is letter char ch character is digit char ch string buffer buf new string buffer int word pos pos do pos 1 buf append char ch ch reader read while ch 0 character is letter char ch character is digit char ch string word buf to string to lower case if word length max word length is stop word word list add new occurrence word word pos 0 else pos 1 ch reader read return occurrence list to array new occurrence list size parsetext ioexception arraylist arraylist isletter isdigit stringbuffer stringbuffer wordpos isletter isdigit tostring tolowercase maxwordlength isstopword wordpos toarray protected void fill stop list stop list new hash set stop list add a stop list add the stop list add at stop list add on stop list add of stop list add to stop list add an fillstoplist stoplist hashset stoplist stoplist stoplist stoplist stoplist stoplist stoplist public void on load fill stop list onload fillstoplist check if word is stop word and should bw not included in index param word lowercased word return true if word is in stop list false otherwize public boolean is stop word string word return stop list contains word isstopword stoplist public full text search helper storage storage super storage and and or or not not fill stop list fulltextsearchhelper fillstoplist protected full text search helper fulltextsearchhelper string language query scanner string query string language this query query this language language queryscanner int scan if unget unget false return token int len query length int p pos string q query while p len char ch q char at p if ch in quotes in quotes p 1 else if ch pos p 1 return token tkn lpar else if ch pos p 1 return token tkn rpar else if character is letter ch character is digit ch word pos p while p len character is letter q char at p character is digit q char at p string word q substring word pos p pos p if word equals and return token tkn and else if word equals or return token tkn or else if word equals not return token tkn not else word word to lower case if is stop word word if in quotes just get the first normal form and ignore all other alternatives word get normal forms word language 0 this word word return token tkn word else p 1 pos p return token tkn eoq charat inquotes inquotes tkn_lpar tkn_rpar isletter isdigit wordpos isletter charat isdigit charat wordpos tkn_and tkn_or tkn_not tolowercase isstopword inquotes getnormalforms tkn_word tkn_eoq protected full text query disjunction query scanner scanner full text query left conjunction scanner if scanner token query scanner tkn or full text query right disjunction scanner if left null right null return new full text query binary op full text query or left right else if right null return right return left fulltextquery queryscanner fulltextquery queryscanner tkn_or fulltextquery fulltextquerybinaryop fulltextquery protected full text query conjunction query scanner scanner full text query left term scanner if scanner token query scanner tkn word scanner token query scanner tkn and if scanner token query scanner tkn word scanner unget true int cop scanner in quotes full text query near full text query and full text query right disjunction scanner if left null right null return new full text query binary op cop left right else if right null return right return left fulltextquery queryscanner fulltextquery queryscanner tkn_word queryscanner tkn_and queryscanner tkn_word inquotes fulltextquery fulltextquery fulltextquery fulltextquerybinaryop protected full text query term query scanner scanner full text query q null switch scanner scan case query scanner tkn not q term scanner return q null new full text query unary op full text query not q null case query scanner tkn lpar q disjunction scanner break case query scanner tkn word q new full text query match op scanner in quotes full text query strict match full text query match scanner word scanner word pos break case query scanner tkn eoq return null scanner scan return q fulltextquery queryscanner fulltextquery queryscanner tkn_not fulltextqueryunaryop fulltextquery queryscanner tkn_lpar queryscanner tkn_word fulltextquerymatchop inquotes fulltextquery strict_match fulltextquery wordpos queryscanner tkn_eoq public full text query parse query string query string language return disjunction new query scanner query language fulltextquery parsequery queryscanner get occurrence kind weight occurrence kinds can be in title in header emphased it is up to the document scanner implementation how to enumerate occurence kinds these is only one limitation number of difference kinds should not exceed 8 return array with weights of each occurrence kind public float get occurrence kind weights return occurrence kind weights getoccurrencekindweights occurrence_kind_weights get weight of nearness criteria in document rank document rank is calculated as keyword rank 1 nearness nearness weight return weight of nearness criteria public float get nearness weight return 10 0f keywordrank nearnessweight getnearnessweight get penalty of inverse word order in the text assume that document text contains phrase ah oh ugh and query ugh ah is executed the distance between ugh and ah in the document text is 6 but as far as them are in difference order than in query this distance will be multiplied on swap penalty so if swap penalty is 10 then distance between these two word is considered to be 60 return swap penalty public int get word swap penalty return 10 getwordswappenalty public final boolean free when done public temp fetch result client metadata dm bucket fetched boolean free when done super dm fetched this free when done free when done freewhendone tempfetchresult clientmetadata freewhendone freewhendone freewhendone if true the recipient of this object is responsible for freeing the data if false it is a reference to data held somewhere else so doesn t need to be freed return public boolean free when done return free when done freewhendone freewhendone construct a polar filter public polar filter this rect to polar polarfilter polarfilter rect_to_polar construct a polar filter param type the distortion type public polar filter int type this type type set edge action clamp polarfilter polarfilter setedgeaction override public buffered image filter buffered image src buffered image dst this width src get width this height src get height centrex width 2 centrey height 2 radius math max centrey centrex return super filter src dst bufferedimage bufferedimage bufferedimage getwidth getheight set the distortion type param type the distortion type see get type public void set type int type this type type gettype settype get the distortion type return the distortion type see set type public int get type return type settype gettype private float sqr float x return x x override protected void transform inverse int x int y float out float theta t float m xmax ymax float r 0 switch type case rect to polar theta 0 if x centrex if y centrey theta image math pi float math atan float x centrex float y centrey r float math sqrt sqr x centrex sqr y centrey else if y centrey theta float math atan float x centrex float centrey y r float math sqrt sqr x centrex sqr centrey y else theta image math half pi r x centrex else if x centrex if y centrey theta image math two pi float math atan float centrex x float centrey y r float math sqrt sqr centrex x sqr centrey y else if y centrey theta image math pi float math atan float centrex x float y centrey r float math sqrt sqr centrex x sqr y centrey else theta 1 5f image math pi r centrex x if x centrex m math abs float y centrey float x centrex else m 0 if m float height float width if x centrex xmax 0 ymax centrey else xmax centrex ymax m xmax else ymax centrey xmax ymax m out 0 width 1 width 1 image math two pi theta out 1 height r radius break case polar to rect theta x width image math two pi float theta2 if theta 1 5f image math pi theta2 image math two pi theta else if theta image math pi theta2 theta image math pi else if theta 0 5f image math pi theta2 image math pi theta else theta2 theta t float math tan theta2 if t 0 m 1 0f t else m 0 if m float height float width if theta2 0 xmax 0 ymax centrey else xmax centrex ymax m xmax else ymax centrey xmax ymax m r radius float y float height float nx r float math sin theta2 float ny r float math cos theta2 if theta 1 5f image math pi out 0 float centrex nx out 1 float centrey ny else if theta math pi out 0 float centrex nx out 1 float centrey ny else if theta 0 5 math pi out 0 float centrex nx out 1 float centrey ny else out 0 float centrex nx out 1 float centrey ny break case invert in circle float dx x centrex float dy y centrey float distance2 dx dx dy dy out 0 centrex centrex centrex dx distance2 out 1 centrey centrey centrey dy distance2 break transforminverse rect_to_polar imagemath imagemath half_pi imagemath two_pi imagemath imagemath imagemath two_pi polar_to_rect imagemath two_pi imagemath imagemath two_pi imagemath imagemath imagemath imagemath imagemath invert_in_circle override public string to string return distort polar coordinates tostring private buffered image mask public gradient wipe filter bufferedimage gradientwipefilter set the density of the image in the range 0 1 arg density the density public void set density float density this density density setdensity public float get density return density getdensity set the softness of the dissolve in the range 0 1 param softness the softness min value 0 max value 1 see get softness public void set softness float softness this softness softness getsoftness setsoftness get the softness of the dissolve return the softness see set softness public float get softness return softness setsoftness getsoftness public void set mask buffered image mask this mask mask setmask bufferedimage public buffered image get mask return mask bufferedimage getmask public void set invert boolean invert this invert invert setinvert public boolean get invert return invert getinvert public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null if mask null return dst int mask width mask get width int mask height mask get height float d density 1 softness float lower 255 d softness float upper 255 d int in pixels new int width int mask pixels new int mask width for int y 0 y height y getrgb src 0 y width 1 in pixels getrgb mask 0 y mask height mask width 1 mask pixels for int x 0 x width x int maskrgb mask pixels x mask width int inrgb in pixels x int v pixel utils brightness maskrgb float f image math smooth step lower upper v int a int 255 f if invert a 255 a in pixels x a 24 inrgb 0x00ffffff setrgb dst 0 y width 1 in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage maskwidth getwidth maskheight getheight inpixels maskpixels maskwidth inpixels maskheight maskwidth maskpixels maskpixels maskwidth inpixels pixelutils imagemath smoothstep inpixels inpixels override public string to string return transitions gradient wipe tostring param executor public wot identity manager ext object container mydb plugin respirator pr throws plugin not found exception super mydb pr get node executor m talker pr get plugin talker this freetalk wot name freetalk plugin title m blocking talker new plugin talker blocking pr is running true m executor execute this ft identity manager logger debug this identity manager started wotidentitymanager extobjectcontainer pluginrespirator pluginnotfoundexception getnode mtalker getplugintalker wot_name plugin_title mblockingtalker plugintalkerblocking isrunning mexecutor for being used in j unit tests to run without a node public wot identity manager ext object container mydb super mydb junit wotidentitymanager extobjectcontainer sends a blocking fcp message to the wot plugin checks whether the reply is really the expected reply message and throws an exception if not also checks whether the reply is an error message and throws an exception if it is therefore the purpose of this function is that the callee can assume that no errors occurred if no exception is thrown param params the params of the fcp message param expected reply message the excepted content of the message field of the simple field set of the reply message return the unmodified result object which was returned by the plugin talker throws exception if the wot plugin replied with an error message or not with the expected message private plugin talker blocking result sendfcp message blocking simple field set params bucket data string expected reply message throws exception plugin talker blocking result result m blocking talker send blocking params data if result params get message equals error throw new exception fcp message result params get original message failed result params get description if result params get message equals expected reply message false throw new exception fcp message params get message received unexpected reply result params get message return result expectedreplymessage simplefieldset plugintalker plugintalkerblocking sendfcpmessageblocking simplefieldset expectedreplymessage plugintalkerblocking mblockingtalker sendblocking originalmessage expectedreplymessage public synchronized wot own identity create own identity string new nickname boolean publishes trust list boolean publishes introduction puzzles throws exception simple field set params new simple field set true params put overwrite message create identity params put overwrite nickname new nickname params put overwrite publish trust list publishes trust list true false params put overwrite publish introduction puzzles publishes introduction puzzles true false params put overwrite context freetalk wot context plugin talker blocking result result sendfcp message blocking params null identity created wot own identity identity new wot own identity result params get id new freeneturi result params get requesturi new freeneturi result params get inserturi new nickname synchronized db lock db store identity db commit return identity wotownidentity createownidentity newnickname publishestrustlist publishesintroductionpuzzles simplefieldset simplefieldset putoverwrite createidentity putoverwrite newnickname putoverwrite publishtrustlist publishestrustlist putoverwrite publishintroductionpuzzles publishesintroductionpuzzles putoverwrite wot_context plugintalkerblocking sendfcpmessageblocking identitycreated wotownidentity wotownidentity newnickname public synchronized wot own identity create own identity string new nickname boolean publishes trust list boolean publishes introduction puzzles freeneturi new requesturi freeneturi new inserturi throws exception simple field set params new simple field set true params put overwrite message create identity params put overwrite nickname new nickname params put overwrite publish trust list publishes trust list true false params put overwrite publish introduction puzzles publishes introduction puzzles true false params put overwrite context freetalk wot context params put overwrite requesturi new requesturi to string params put overwrite inserturi new inserturi to string plugin talker blocking result result sendfcp message blocking params null identity created we take the ur is which were returned by the wot plugin instead of the requested ones because this allows the identity to work even if the wot plugin ignores our requested ur is if we just stored the ur is we requested we would store an identity with wrong ur is which would result in the identity not being useable wot own identity identity new wot own identity result params get id new freeneturi result params get requesturi new freeneturi result params get inserturi new nickname synchronized db lock db store identity db commit return identity wotownidentity createownidentity newnickname publishestrustlist publishesintroductionpuzzles newrequesturi newinserturi simplefieldset simplefieldset putoverwrite createidentity putoverwrite newnickname putoverwrite publishtrustlist publishestrustlist putoverwrite publishintroductionpuzzles publishesintroductionpuzzles putoverwrite wot_context putoverwrite newrequesturi tostring putoverwrite newinserturi tostring plugintalkerblocking sendfcpmessageblocking identitycreated uris uris uris uris wotownidentity wotownidentity newnickname suppress warnings unchecked public synchronized iterable wot identity get all identities return new iterable wot identity public iterator wot identity iterator return new iterator wot identity iterator wot identity iter query q db query q constrain wot identity class iter q execute iterator public boolean has next return iter has next public wot identity next wot identity i iter next i initialize transient db wot identity manager this return i public void remove throw new unsupported operation exception cannot delete identities suppresswarnings wotidentity getallidentities wotidentity wotidentity wotidentity wotidentity wotidentity hasnext hasnext wotidentity wotidentity initializetransient wotidentitymanager unsupportedoperationexception return new iterable wot identity public iterator wot identity iterator return new iterator wot identity iterator wot identity iter query q db query q constrain wot identity class iter q execute iterator public boolean has next return iter has next public wot identity next wot identity i iter next i initialize transient db wot identity manager this return i public void remove throw new unsupported operation exception cannot delete identities wotidentity wotidentity wotidentity wotidentity wotidentity hasnext hasnext wotidentity wotidentity initializetransient wotidentitymanager unsupportedoperationexception public boolean has next return iter has next hasnext hasnext public wot identity next wot identity i iter next i initialize transient db wot identity manager this return i wotidentity wotidentity initializetransient wotidentitymanager public void remove throw new unsupported operation exception cannot delete identities unsupportedoperationexception suppress warnings unchecked public synchronized wot identity get identity string uid throws no such identity exception query q db query q constrain wot identity class q descend muid constrain uid object set wot identity result q execute if result size 1 throw new duplicate identity exception if result size 0 throw new no such identity exception uid return result next suppresswarnings wotidentity getidentity nosuchidentityexception wotidentity objectset wotidentity duplicateidentityexception nosuchidentityexception public ft identity get identity byuri freeneturi uri throws no such identity exception return get identity wot identity getuid fromuri uri ftidentity getidentitybyuri nosuchidentityexception getidentity wotidentity getuidfromuri suppress warnings unchecked public synchronized wot own identity get own identity string uid throws no such identity exception query q db query q constrain wot own identity class q descend muid constrain uid object set wot own identity result q execute if result size 1 throw new duplicate identity exception if result size 0 throw new no such identity exception uid return result next suppresswarnings wotownidentity getownidentity nosuchidentityexception wotownidentity objectset wotownidentity duplicateidentityexception nosuchidentityexception public int get score wot own identity tree owner ft identity target fixme implement return 0 getscore wotownidentity treeowner ftidentity private void add freetalk context wot identity oid simple field set params new simple field set true params put overwrite message add context params put overwrite identity oid getuid params put overwrite context freetalk wot context m talker send params null addfreetalkcontext wotidentity simplefieldset simplefieldset putoverwrite addcontext putoverwrite putoverwrite wot_context mtalker called by the plugin talker it is run in a different thread therefore we store the result and let our own thread process it so we can run the processing at minimal thread priority which is necessary because the amount of identities might become large public void on reply string pluginname string indentifier simple field set params bucket data string message params get message boolean identities were received false synchronized sfs lock if message equals identities sfs identities params identities were received true else if message equals own identities sfs own identities params identities were received true if identities were received m thread interrupt plugintalker onreply simplefieldset identitieswerereceived sfslock sfsidentities identitieswerereceived ownidentities sfsownidentities identitieswerereceived identitieswerereceived mthread private void request identities logger debug this requesting identities with positive score from wot simple field set p1 new simple field set true p1 put overwrite message get identities by score p1 put overwrite selection p1 put overwrite context freetalk wot context m talker send p1 null logger debug this requesting own identities from wot simple field set p2 new simple field set true p2 put overwrite message get own identities m talker send p2 null requestidentities simplefieldset simplefieldset putoverwrite getidentitiesbyscore putoverwrite putoverwrite wot_context mtalker simplefieldset simplefieldset putoverwrite getownidentities mtalker suppress warnings unchecked private void parse identities simple field set params boolean b own identities if b own identities logger debug this parsing received own identities else logger debug this parsing received identities long time current timeutc get in millis for int idx 1 idx string uid params get identity idx if uid null uid equals fixme figure out whether the second condition is necessary break string requesturi params get requesturi idx string inserturi b own identities params get inserturi idx null string nickname params get nickname idx synchronized this we lock here and not during the whole function to allow other threads to execute query q db query q constrain wot identity class q descend muid constrain uid object set wot identity result q execute wot identity id null if result size 0 try logger debug this importing identity from wot requesturi id b own identities new wot own identity uid new freeneturi requesturi new freeneturi inserturi nickname new wot identity uid new freeneturi requesturi nickname id initialize transient db this id store catch exception e logger error this error in parse identities e else logger debug this not importing already existing identity requesturi assert result size 1 id result next id initialize transient db this if id null if b own identities fixme only add the context if the user actually uses the identity with freetalk add freetalk context id id set last received from wot time thread yield suppresswarnings parseidentities simplefieldset bownidentities bownidentities currenttimeutc getinmillis bownidentities wotidentity objectset wotidentity wotidentity bownidentities wotownidentity wotidentity initializetransient parseidentities initializetransient bownidentities addfreetalkcontext setlastreceivedfromwot suppress warnings unchecked private synchronized void garbage collect identities executing the thread loop once will always take longer than thread period therefore if we set the limit to 3 thread period it will hit identities which were last received before more than 2 thread loop not exactly 3 thread loop long last accept time system current time millis thread period 3 fixme use utc synchronized db lock query q db query q constrain wot identity class q descend is needed constrain false q descend last received from wot constrain new long last accept time smaller object set wot identity result q execute while result has next wot identity i result next assert identity is not needed i check whether the is needed field of the identity was correct logger debug this garbage collecting identity i get requesturi db delete i db commit suppresswarnings garbagecollectidentities thread_period thread_period thread_loop thread_loop lastaccepttime currenttimemillis thread_period wotidentity isneeded lastreceivedfromwot lastaccepttime objectset wotidentity hasnext wotidentity identityisnotneeded isneeded getrequesturi debug function for checking whether the is needed field of an identity is correct private boolean identity is not needed wot identity i fixme this function does not lock it should probably but we cannot lock on the message manager because it locks on the identity manager and therefore this might cause deadlock query q db query q constrain message class q descend m author constrain i return q execute size 0 isneeded identityisnotneeded wotidentity mauthor public void run logger debug this identity manager running m thread thread current thread try logger debug this waiting for the node to start up thread sleep long 30 1000 0 5f math random let the node start up catch interrupted exception e m thread interrupt long next identity request time 0 try while is running thread interrupted logger debug this identity manager loop running boolean identities were received synchronized sfs lock identities were received sfs identities null sfs own identities null if sfs identities null parse identities sfs identities false sfs identities null if sfs own identities null parse identities sfs own identities true sfs own identities null if identities were received garbage collect identities long current time system current time millis long sleep time long thread period 0 5f math random if current time next identity request time request identities next identity request time current time sleep time logger debug this identity manager loop finished try thread sleep sleep time catch interrupted exception e m thread interrupt finally synchronized this shutdown finished true logger debug this identity manager thread exiting notify mthread currentthread interruptedexception mthread nextidentityrequesttime isrunning identitieswerereceived sfslock identitieswerereceived sfsidentities sfsownidentities sfsidentities parseidentities sfsidentities sfsidentities sfsownidentities parseidentities sfsownidentities sfsownidentities identitieswerereceived garbagecollectidentities currenttime currenttimemillis sleeptime thread_period currenttime nextidentityrequesttime requestidentities nextidentityrequesttime currenttime sleeptime sleeptime interruptedexception mthread shutdownfinished public int get priority return native thread min priority getpriority nativethread min_priority public void terminate logger debug this stopping the identity manager is running false m thread interrupt synchronized this while shutdown finished try wait catch interrupted exception e thread interrupted logger debug this stopped the indentity manager isrunning mthread shutdownfinished interruptedexception public static boolean contains noidn blacklist characters string text for character c text to char array if idn blacklist contains c return false return true containsnoidnblacklistcharacters tochararray idnblacklist public static boolean contains no linebreaks string text for character c text to char array if character get type c character line separator character get type c character paragraph separator c n c r return false return true containsnolinebreaks tochararray gettype line_separator gettype paragraph_separator check for any values in the string that are not valid unicode characters public static boolean contains no invalid characters string text for int i 0 i text length int c text code point at i i character char count c if c 0xfffe 0xfffe character get type c character surrogate return false return true containsnoinvalidcharacters codepointat charcount gettype check for any control characters including tab lf and cr in the string public static boolean contains no control characters string text for character c text to char array if character get type c character control return false return true containsnocontrolcharacters tochararray gettype check for any unpaired directional or annotation characters in the string or any nested annotations public static boolean contains no invalid formatting string text int dir count 0 boolean in annotated text false boolean in annotation false for character c text to char array if c 0x202a left to right embedding c 0x202b right to left embedding c 0x202d left to right override c 0x202e right to left override dir count else if c 0x202c pop directional formatting dir count if dir count 0 return false else if c 0xfff9 interlinear annotation anchor if in annotated text in annotation return false in annotated text true else if c 0xfffa interlinear annotation separator if in annotated text return false in annotated text false in annotation true else if c 0xfffb interlinear annotation terminator if in annotation return false in annotation false return dir count 0 in annotated text in annotation containsnoinvalidformatting dircount inannotatedtext inannotation tochararray dircount dircount dircount inannotatedtext inannotation inannotatedtext inannotatedtext inannotatedtext inannotation inannotation inannotation dircount inannotatedtext inannotation static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog chk insert handler message req peer node source long id node node long start time insert tag tag this req req this node node this uid id this source source this start time start time this tag tag key nodechk req get object dmt freenet routing key htl req get short dmt htl if htl 0 htl 1 received bytes req received byte count chkinserthandler peernode starttime inserttag starttime starttime getobject freenet_routing_key getshort receivedbytes receivedbytecount override public string to string return super to string for uid tostring tostring public void run freenet support logger os thread logpid this try real run catch out of memory error e oom handler handleoom e tag handler threw e catch throwable t logger error this caught in run t t tag handler threw t finally if logminor logger minor this exiting chk insert handler run for uid node unlockuid uid false true false false false tag osthread realrun outofmemoryerror oomhandler handlerthrew handlerthrew chkinserthandler private void real run run thread thread current thread fixme implement rate limiting or something send accepted message accepted dmt createfnp accepted uid try using send sync here will help the next message filter not timeout wait here or at the message filter source send sync accepted this catch not connected exception e1 if logminor logger minor this lost connection to source return source will send us a data insert message filter mf mf message filter create set type dmt fnp data insert set field dmt uid uid set source source set timeout data insert timeout message msg try msg node usm wait for mf this catch disconnected exception e logger normal this disconnected while waiting for data insert on uid return if logminor logger minor this received msg if msg null try if source is connected start time source time last connection completed node handshake timeout 4 logger error this did not receive data insert on uid from source message too slow dmt createfnp rejected timeout uid source send async too slow null this message m dmt createfnp insert transfers completed uid true source send async m null this prb new partially received block node packets in block node packet size br new block receiver node usm source uid prb this node get ticker false prb abort retrieval exception no datainsert no data insert br send aborted retrieval exception no datainsert no data insert return catch not connected exception e if logminor logger minor this lost connection to source return we have a data insert headers short buffer msg get object dmt block headers get data fixme check the headers now create an chk insert sender or use an existing one or discover that the data is in the store from this point onwards if we return cleanly we must go through finish prb new partially received block node packets in block node packet size if htl 0 sender node make insert sender key htl uid source headers prb false true br new block receiver node usm source uid prb this node get ticker false receive the data off thread runnable data receiver new data receiver receive started true node executor execute data receiver chk insert handler data receiver for uid uid if htl 0 can commit true msg dmt createfnp insert reply uid try source send sync msg this catch not connected exception e ignore finish chk insert sender success return wait what do we want to wait for if the data receive completes that s very nice but doesn t really matter what matters is what happens to the chk insert sender if the data receive fails that does matter we are waiting for a terminal status on the chk insert sender including success if we get transfer failed we can check whether the receive failed first if it did it s not our fault if the receive failed and we haven t started transferring yet we probably want to kill the sender so we call the wait method on the chk insert sender but we also have a flag locally to indicate the receive failed and if it does we interrupt boolean received rejected overload false while true synchronized sender try if sender get status chk insert sender not finished sender wait 5000 catch interrupted exception e cool probably this is because the receive failed if receive failed nothing else we can do finish chk insert sender receive failed return if received rejected overload sender received rejected overload received rejected overload true forward it message m dmt createfnp rejected overload uid false try source send sync m this catch not connected exception e if logminor logger minor this lost connection to source return int status sender get status if status chk insert sender not finished continue local rejected overload s fatal internal error counts as overload it d only create a timeout otherwise which is the same thing anyway if status chk insert sender timed out status chk insert sender generated rejected overload status chk insert sender internal error msg dmt createfnp rejected overload uid true try source send sync msg this catch not connected exception e if logminor logger minor this lost connection to source return might as well store it anyway if status chk insert sender timed out status chk insert sender generated rejected overload can commit true finish status return if status chk insert sender route not found status chk insert sender route really not found msg dmt createfnp route not found uid sender gethtl try source send sync msg this catch not connected exception e if logminor logger minor this lost connection to source return can commit true finish status return if status chk insert sender receive failed probably source s fault finish status return if status chk insert sender success msg dmt createfnp insert reply uid try source send sync msg this catch not connected exception e logger minor this lost connection to source return can commit true finish status return otherwise logger error this unknown status code sender get status string msg dmt createfnp rejected overload uid true try source send sync msg this catch not connected exception e ignore finish chk insert sender internal error return realrun runthread currentthread createfnpaccepted sendsync sendsync notconnectedexception datainsert messagefilter messagefilter settype fnpdatainsert setfield setsource settimeout data_insert_timeout waitfor disconnectedexception datainsert isconnected starttime timelastconnectioncompleted handshake_timeout datainsert tooslow createfnprejectedtimeout sendasync tooslow createfnpinserttransferscompleted sendasync partiallyreceivedblock packets_in_block packet_size blockreceiver getticker retrievalexception no_datainsert datainsert sendaborted retrievalexception no_datainsert datainsert notconnectedexception datainsert shortbuffer getobject block_headers getdata chkinsertsender partiallyreceivedblock packets_in_block packet_size makeinsertsender blockreceiver getticker datareceiver datareceiver receivestarted datareceiver chkinserthandler datareceiver cancommit createfnpinsertreply sendsync notconnectedexception chkinsertsender chkinsertsender chkinsertsender chkinsertsender receivedrejectedoverload getstatus chkinsertsender not_finished interruptedexception receivefailed chkinsertsender receive_failed receivedrejectedoverload receivedrejectedoverload receivedrejectedoverload createfnprejectedoverload sendsync notconnectedexception getstatus chkinsertsender not_finished rejectedoverload chkinsertsender timed_out chkinsertsender generated_rejected_overload chkinsertsender internal_error createfnprejectedoverload sendsync notconnectedexception chkinsertsender timed_out chkinsertsender generated_rejected_overload cancommit chkinsertsender route_not_found chkinsertsender route_really_not_found createfnproutenotfound sendsync notconnectedexception cancommit chkinsertsender receive_failed chkinsertsender createfnpinsertreply sendsync notconnectedexception cancommit getstatusstring createfnprejectedoverload sendsync notconnectedexception chkinsertsender internal_error if can commit and we have received all the data and it verifies then commit it private void finish int code if logminor logger minor this waiting for receive synchronized this while receive started receive completed try wait 100 1000 catch interrupted exception e ignore maybe commit if logminor logger minor this waiting for completion wait for completion boolean sent completion was set synchronized sent completion lock sent completion was set sent completion sent completion true message m null if sender null sent completion was set if there are downstream senders our final success report depends on there being no timeouts in the chain while true synchronized sender if sender completed break try sender wait 10 1000 catch interrupted exception e loop boolean failed sender any transfers failed m dmt createfnp insert transfers completed uid failed if sender null sent completion was set can commit there are no downstream senders but we stored the data locally report successful transfer note that this is done even if the verify fails m dmt createfnp insert transfers completed uid false no timeouts try source send sync m this if logminor logger minor this sent completion m for this catch not connected exception e1 if logminor logger minor this not connected source for this may need to commit anyway if code chk insert sender timed out code chk insert sender generated rejected overload code chk insert sender internal error code chk insert sender route really not found code chk insert sender receive failed receive failed int total sent get total sent bytes int total received get total received bytes if sender null total sent sender get total sent bytes total received sender get total received bytes if logminor logger minor this remote chk insert cost total sent total received bytes code receive failed receive failed node node stats remote chk insert bytes sent average report total sent node node stats remote chk insert bytes received average report total received if code chk insert sender success report both sent and received because we have both a handler and a sender if sender null sender started sending data node node stats successful chk insert bytes sent average report total sent node node stats successful chk insert bytes received average report total received cancommit receivestarted receivecompleted interruptedexception maybecommit sentcompletionwasset sentcompletionlock sentcompletionwasset sentcompletion sentcompletion sentcompletionwasset interruptedexception anytransfersfailed createfnpinserttransferscompleted sentcompletionwasset cancommit createfnpinserttransferscompleted sendsync notconnectedexception chkinsertsender timed_out chkinsertsender generated_rejected_overload chkinsertsender internal_error chkinsertsender route_really_not_found chkinsertsender receive_failed receivefailed totalsent gettotalsentbytes totalreceived gettotalreceivedbytes totalsent gettotalsentbytes totalreceived gettotalreceivedbytes totalsent totalreceived receivefailed nodestats remotechkinsertbytessentaverage totalsent nodestats remotechkinsertbytesreceivedaverage totalreceived chkinsertsender startedsendingdata nodestats successfulchkinsertbytessentaverage totalsent nodestats successfulchkinsertbytesreceivedaverage totalreceived verify data or send data insert rejected private void maybe commit message to send null synchronized this if prb null prb is aborted return try if can commit return if prb all received return chk block block new chk block prb get block headers key node store block if logminor logger minor this committed catch chk verify exception e logger error this verify failed in chk insert handler e headers hex util bytes to hex headers e to send dmt createfnp data insert rejected uid dmt data insert rejected verify failed catch aborted exception e logger error this receive failed e receiver thread below will handle sending the failure notice if to send null try source send async to send null this catch not connected exception e if logminor logger minor this lost connection in this when sending fnp data insert rejected datainsertrejected maybecommit tosend isaborted cancommit allreceived chkblock chkblock getblock chkverifyexception chkinserthandler hexutil bytestohex tosend createfnpdatainsertrejected data_insert_rejected_verify_failed abortedexception tosend sendasync tosend notconnectedexception fnpdatainsertrejected public void run freenet support logger os thread logpid this if logminor logger minor this receiving data for chk insert handler this try don t log whether the transfer succeeded or failed as the transfer was initiated by the source therefore could be unreliable evidence br receive if logminor logger minor this received data for chk insert handler this synchronized chk insert handler this receive completed true chk insert handler this notify all node node stats successful block receive catch retrieval exception e synchronized chk insert handler this receive completed true receive failed true chk insert handler this notify all cancel the sender if sender null sender receive failed tell it to stop if it hasn t already failed unless it s sending from store run thread interrupt message msg dmt createfnp data insert rejected uid dmt data insert rejected receive failed try source send sync msg chk insert handler this catch not connected exception ex if they are not connected that s probably why the receive failed if logminor logger minor this can t send msg to source ex if e get reason retrieval exception sender disconnected logger normal this failed to retrieve disconnect e e else annoying but we have stats for this no need to call attention to it it s unlikely to be a bug logger normal this failed to retrieve e get reason retrieval exception get err string e get reason e e node node stats failed block receive false false false return catch throwable t logger error this caught t t osthread chkinserthandler chkinserthandler chkinserthandler receivecompleted chkinserthandler notifyall nodestats successfulblockreceive retrievalexception chkinserthandler receivecompleted receivefailed chkinserthandler notifyall receivefailed runthread createfnpdatainsertrejected data_insert_rejected_receive_failed sendsync chkinserthandler notconnectedexception getreason retrievalexception sender_disconnected getreason retrievalexception geterrstring getreason nodestats failedblockreceive override public string to string return super to string for uid tostring tostring public int get priority return native thread high priority getpriority nativethread high_priority private synchronized boolean receive failed return receive failed receivefailed receivefailed public void sent bytes int x synchronized total sync total sent bytes x node node stats insert sent bytes false x sentbytes totalsync totalsentbytes nodestats insertsentbytes public void received bytes int x synchronized total sync total received bytes x node node stats insert received bytes false x receivedbytes totalsync totalreceivedbytes nodestats insertreceivedbytes public int get total sent bytes return total sent bytes gettotalsentbytes totalsentbytes public int get total received bytes return total received bytes gettotalreceivedbytes totalreceivedbytes public void sent payload int x node sent payload x node node stats insert sent bytes false x sentpayload sentpayload nodestats insertsentbytes public int get priority return native thread high priority getpriority nativethread high_priority public static insertableusk create insertable freeneturi uri boolean persistent throws malformedurl exception if uri get key type equals ignore case usk throw new malformedurl exception insertable clientssk ssk insertable clientssk create uri set key type ssk return new insertableusk ssk doc name ssk pub key hash ssk crypto key ssk priv key persistent ssk get crypto group clone key ssk get crypto group uri get suggested edition ssk crypto algorithm createinsertable malformedurlexception getkeytype equalsignorecase malformedurlexception insertableclientssk insertableclientssk setkeytype docname pubkeyhash cryptokey privkey getcryptogroup clonekey getcryptogroup getsuggestededition cryptoalgorithm insertableusk string doc name byte pub key hash byte crypto key dsa private key key dsa group group long suggested edition byte crypto algorithm throws malformedurl exception super pub key hash crypto key doc name suggested edition crypto algorithm if crypto key length clientssk crypto key length throw new malformedurl exception decryption key wrong length crypto key length should be clientssk crypto key length this priv key key this group group docname pubkeyhash cryptokey dsaprivatekey dsagroup suggestededition cryptoalgorithm malformedurlexception pubkeyhash cryptokey docname suggestededition cryptoalgorithm cryptokey crypto_key_length malformedurlexception cryptokey crypto_key_length privkey override public freeneturi geturi return new freeneturi pub key hash crypto key null site name suggested edition pubkeyhash cryptokey sitename suggestededition public usk getusk return new usk pub key hash crypto key site name suggested edition crypto algorithm pubkeyhash cryptokey sitename suggestededition cryptoalgorithm public insertable clientssk get insertablessk long ver try return new insertable clientssk site name separator ver pub key hash new dsa public key group priv key priv key crypto key crypto algorithm catch malformedurl exception e logger error this caught e should not be possible in usk getssk e throw new error e insertableclientssk getinsertablessk insertableclientssk sitename pubkeyhash dsapublickey privkey privkey cryptokey cryptoalgorithm malformedurlexception public insertableusk priv copy long edition if edition suggested edition return this try return new insertableusk site name pub key hash crypto key priv key group edition crypto algorithm catch malformedurl exception e throw new error e privcopy suggestededition sitename pubkeyhash cryptokey privkey cryptoalgorithm malformedurlexception override public void remove from object container container container activate priv key 5 priv key remove from container container activate group 5 group remove from container super remove from container removefrom objectcontainer privkey privkey removefrom removefrom removefrom public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster if dst null dst create compatible dest image src null writable raster dst raster dst get raster set dimensions width height int in pixels new int width for int y 0 y height y we try to avoid calling getrgb on images as it causes them to become unmanaged causing horrible performance problems if type buffered image type int argb src raster get data elements 0 y width 1 in pixels for int x 0 x width x in pixels x filterrgb x y in pixels x dst raster set data elements 0 y width 1 in pixels else src getrgb 0 y width 1 in pixels 0 width for int x 0 x width x in pixels x filterrgb x y in pixels x dst setrgb 0 y width 1 in pixels 0 width return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster createcompatibledestimage writableraster dstraster getraster setdimensions inpixels bufferedimage type_int_argb srcraster getdataelements inpixels inpixels inpixels dstraster setdataelements inpixels inpixels inpixels inpixels inpixels public void set dimensions int width int height setdimensions public abstract int filterrgb int x int y int rgb add a mime type without any extensions param number the number of the mime type for compression this must not change for a given type or the metadata format will be affected param type the actual mime type string do not include charset etc these are parameters and there is a separate mechanism for them protected static synchronized void addmime type short number string type if mime types by number size number string s mime types by number get number if s null throw new illegal argument exception already used number else mime types by number add number null mime types by number set number type mime types by name put type number addmimetype mimetypesbynumber mimetypesbynumber illegalargumentexception mimetypesbynumber mimetypesbynumber mimetypesbyname add a mime type param number the number of the mime type for compression this must not change for a given type or the metadata format will be affected param type the actual mime type string do not include charset etc these are parameters and there is a separate mechanism for them param extensions an array of common extensions for files of this type must be unique for the type protected static synchronized void addmime type short number string type string extensions string out extension addmime type number type short t short value of number if extensions null for int i 0 i extensions length i string ext extensions i to lower case if mime types by extension contains key ext no big deal short s mime types by extension get ext logger normal defaultmime types class extension ext assigned to by number s short value in preference to number type else if only one make it primary if out extension null extensions length 1 primary extension by mime number put t ext mime types by extension put ext t all extensions by mime number put t extensions if out extension null primary extension by mime number put t out extension addmimetype outextension addmimetype valueof tolowercase mimetypesbyextension containskey mimetypesbyextension defaultmimetypes bynumber shortvalue outextension primaryextensionbymimenumber mimetypesbyextension allextensionsbymimenumber outextension primaryextensionbymimenumber outextension add a mime type with extensions separated by spaces this is more or less the format in etc mime types protected static synchronized void addmime type short number string type string extensions string split extensions split addmime type number type split split 0 addmimetype addmimetype add a mime type with extensions separated by spaces this is more or less the format in etc mime types protected static synchronized void addmime type short number string type string extensions string out extension addmime type number type extensions split out extension addmimetype outextension addmimetype outextension get a known mime type by number public synchronized static string by number short x if x mime types by number size x 0 return null return mime types by number get x bynumber mimetypesbynumber mimetypesbynumber get the number of a mime type or 1 if it is not in the table of known mime types in which case it will have to be sent uncompressed public synchronized static short by name string s short x mime types by name get s if x null return x short value else return 1 byname mimetypesbyname shortvalue guess a mime type from a filename param no default if true no default mime type return null if not recognized otherwise if we don t recognize the extension we return default mime type public synchronized static string guessmime type string arg boolean no default int x arg last index of if x 1 x arg length 1 return no default null default mime type string ext arg substring x 1 to lower case short mime index ob mime types by extension get ext if mime index ob null return mime types by number get mime index ob int value else return no default null default mime type nodefault default_mime_type guessmimetype nodefault lastindexof nodefault default_mime_type tolowercase mimeindexob mimetypesbyextension mimeindexob mimetypesbynumber mimeindexob intvalue nodefault default_mime_type public synchronized static string get extension string type short type number by name type if type number 0 return null return primary extension by mime number get type number getextension typenumber byname typenumber primaryextensionbymimenumber typenumber public synchronized static boolean is valid ext string expected mime type string old ext short type number by name expected mime type if type number 0 return false string extensions all extensions by mime number get type number if extensions null return false for int i 0 i extensions length i if old ext equals extensions i return true return false isvalidext expectedmimetype oldext typenumber byname expectedmimetype typenumber allextensionsbymimenumber typenumber oldext returns a 32 bit random floating point number with this method all possible float values are approximately as likely to occur this method may return tt nan tt tt inf tt tt inf tt or other weird stuff if you don t know what they are this method is not for you see random source next float fixme this method is unused do you really want this method public float next full float return float int bits to float next int randomsource nextfloat nextfullfloat intbitstofloat nextint returns a 64 bit random double with this method all possible double values are approximately as likely to occur this method may return tt nan tt tt inf tt tt inf tt or other weird stuff if you don t know what they are this method is not for you see random source next double fixme this method is unused do you really want this method public double next full double return double long bits to double next long randomsource nextdouble nextfulldouble longbitstodouble nextlong accepts entropy data from a source public abstract int accept entropy entropy source source long data int entropy guess acceptentropy entropysource entropyguess public abstract int accept entropy entropy source source long data int entropy guess accepts entropy in the form of timing data from a source public abstract int accept timer entropy entropy source timer acceptentropy entropysource entropyguess accepttimerentropy entropysource accept entropy from a source with a bias param bias value by which we multiply the entropy before counting it must be 1 0 accepts larger amounts of entropy data from a source with a bias param my packet data source the source from which the data has come param buf the buffer to read bytes from param offset the offset to start reading from param length the number of bytes to read param bias the bias value by which we multiply the entropy before counting it must be 1 0 mypacketdatasource if entropy estimation is supported this method will block until the specified number of bits of entropy are available if estimation isn t supported this method will return immediately if the random source has any resources it wants to close it can do so when this method is called randomsource static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog public throttle window manager double def simple field set fs node node this node node if fs null totalpackets fs get int total packets 0 droppedpackets fs get int dropped packets 0 simulatedwindowsize fs get double simulated window size def else simulatedwindowsize def throttlewindowmanager simplefieldset _totalpackets getint totalpackets _droppedpackets getint droppedpackets _simulatedwindowsize getdouble simulatedwindowsize _simulatedwindowsize public synchronized double current value if simulatedwindowsize 1 0 simulatedwindowsize 1 0f return simulatedwindowsize math max 1 node peers count non backed off peers currentvalue _simulatedwindowsize _simulatedwindowsize _simulatedwindowsize countnonbackedoffpeers public synchronized void rejected overload droppedpackets totalpackets simulatedwindowsize packet drop decrease multiple if logminor logger minor this request rejected overload this rejectedoverload _droppedpackets _totalpackets _simulatedwindowsize packet_drop_decrease_multiple public synchronized void request completed totalpackets simulatedwindowsize packet transmit increment simulatedwindowsize if logminor logger minor this request completed on this requestcompleted _totalpackets _simulatedwindowsize packet_transmit_increment _simulatedwindowsize requestcompleted override public synchronized string to string return super to string w simulatedwindowsize d float droppedpackets float totalpackets droppedpackets totalpackets tostring tostring _simulatedwindowsize _droppedpackets _totalpackets _droppedpackets _totalpackets public simple field set export field set boolean short lived simple field set fs new simple field set short lived fs put single type throttle window manager fs put total packets totalpackets fs put dropped packets droppedpackets fs put simulated window size simulatedwindowsize return fs simplefieldset exportfieldset shortlived simplefieldset simplefieldset shortlived putsingle throttlewindowmanager totalpackets _totalpackets droppedpackets _droppedpackets simulatedwindowsize _simulatedwindowsize public double real current value return simulatedwindowsize realcurrentvalue _simulatedwindowsize public synchronized void on success fetch result result client getter state object container container if finished return this result result finished true notify all onsuccess fetchresult clientgetter objectcontainer notifyall public synchronized void on failure fetch exception e client getter state object container container if finished return this error e finished true notify all onfailure fetchexception clientgetter objectcontainer notifyall public void on success base client putter state object container container throw new unsupported operation exception onsuccess baseclientputter objectcontainer unsupportedoperationexception public void on failure insert exception e base client putter state object container container throw new unsupported operation exception onfailure insertexception baseclientputter objectcontainer unsupportedoperationexception public void on generateduri freeneturi uri base client putter state object container container throw new unsupported operation exception ongenerateduri baseclientputter objectcontainer unsupportedoperationexception public synchronized fetch result wait for completion throws fetch exception while finished try wait catch interrupted exception e ignore if error null throw error return result fetchresult waitforcompletion fetchexception interruptedexception public void on major progress object container container ignore onmajorprogress objectcontainer public void on fetchable base client putter state object container container ignore onfetchable baseclientputter objectcontainer put fetchable message string ident boolean global freeneturi uri this identifier ident this global global this uri uri putfetchablemessage override public simple field set get field set simple field set fs new simple field set true fs put single identifier identifier if global fs put single global true if uri null fs put single uri uri to string false false return fs simplefieldset getfieldset simplefieldset simplefieldset putsingle putsingle putsingle tostring override public string get name return put fetchable getname putfetchable override public void run fcp connection handler handler node node throws message invalid exception throw new message invalid exception protocol error message invalid message put fetchable goes from server to client not the other way around identifier global fcpconnectionhandler messageinvalidexception messageinvalidexception protocolerrormessage invalid_message putfetchable override public void remove from object container container container activate uri 5 uri remove from container container delete this removefrom objectcontainer removefrom public class everything matcher implements address matcher public everything matcher everythingmatcher addressmatcher everythingmatcher public boolean matches inet address address return true inetaddress public string get human representation return gethumanrepresentation public float y public curve x new float 0 1 y new float 0 1 public curve curve curve x float curve x clone y float curve y clone public int add knot float kx float ky int pos 1 int num knots x length float nx new float num knots 1 float ny new float num knots 1 int j 0 for int i 0 i num knots i if pos 1 x i kx pos j nx j kx ny j ky j nx j x i ny j y i j if pos 1 pos j nx j kx ny j ky x nx y ny return pos addknot numknots numknots numknots numknots public void remove knot int n int num knots x length if num knots 2 return float nx new float num knots 1 float ny new float num knots 1 int j 0 for int i 0 i num knots 1 i if i n j nx i x j ny i y j j x nx y ny for int i 0 i x length i system out println i x i y i removeknot numknots numknots numknots numknots numknots private void sort knots int num knots x length for int i 1 i num knots 1 i for int j 1 j i j if x i x j float t x i x i x j x j t t y i y i y j y j t sortknots numknots numknots protected int make table int num knots x length float nx new float num knots 2 float ny new float num knots 2 system arraycopy x 0 nx 1 num knots system arraycopy y 0 ny 1 num knots nx 0 nx 1 ny 0 ny 1 nx num knots 1 nx num knots ny num knots 1 ny num knots int table new int 256 for int i 0 i 1024 i float f i 1024 0f int x int 255 image math spline f nx length nx 0 5f int y int 255 image math spline f nx length ny 0 5f x image math clamp x 0 255 y image math clamp y 0 255 table x y system out println for int i 0 i 256 i system out println i table i return table maketable numknots numknots numknots numknots numknots numknots numknots numknots numknots imagemath imagemath imagemath imagemath public curves filter curves new curve 3 curves 0 new curve curves 1 new curve curves 2 new curve curvesfilter override protected void initialize initialized true if curves length 1 r table g table b table curves 0 make table else r table curves 0 make table g table curves 1 make table b table curves 2 make table rtable gtable btable maketable rtable maketable gtable maketable btable maketable public void set curve curve curve curves new curve curve initialized false setcurve public void set curves curve curves if curves null curves length 1 curves length 3 throw new illegal argument exception curves must be length 1 or 3 this curves curves initialized false setcurves illegalargumentexception public curve get curves return curves getcurves override public string to string return colors curves tostring construct a service description for registrating with jmdns param type fully qualified service type name such as code http tcp local code param name unqualified service instance name such as code foobar code param port the local port on which the service runs param text string describing the service public static service info create string type string name int port string text return new service info impl type name port text _http _tcp serviceinfo serviceinfoimpl construct a service description for registrating with jmdns param type fully qualified service type name such as code http tcp local code param name unqualified service instance name such as code foobar code param port the local port on which the service runs param weight weight of the service param priority priority of the service param text string describing the service public static service info create string type string name int port int weight int priority string text return new service info impl type name port weight priority text _http _tcp serviceinfo serviceinfoimpl construct a service description for registrating with jmdns the properties hashtable must map property names to either strings or byte arrays describing the property values param type fully qualified service type name such as code http tcp local code param name unqualified service instance name such as code foobar code param port the local port on which the service runs param weight weight of the service param priority priority of the service param props properties describing the service public static service info create string type string name int port int weight int priority hashtable props return new service info impl type name port weight priority props _http _tcp serviceinfo serviceinfoimpl construct a service description for registrating with jmdns param type fully qualified service type name such as code http tcp local code param name unqualified service instance name such as code foobar code param port the local port on which the service runs param weight weight of the service param priority priority of the service param text bytes describing the service public static service info create string type string name int port int weight int priority byte text return new service info impl type name port weight priority text _http _tcp serviceinfo serviceinfoimpl fully qualified service type name such as code http tcp local code public abstract string get type _http _tcp gettype public abstract string get type unqualified service instance name such as code foobar code public abstract string get name gettype getname public abstract string get name fully qualified service name such as code foobar http tcp local code public abstract string get qualified name getname _http _tcp getqualifiedname public abstract string get qualified name get the name of the server public abstract string get server getqualifiedname getserver public abstract string get server get the host address of the service ie x x x x public abstract string get host address getserver gethostaddress public abstract string get host address public abstract inet address get address gethostaddress inetaddress getaddress public abstract inet address get address get the inet address of the service public abstract inet address get inet address inetaddress getaddress inetaddress inetaddress getinetaddress public abstract inet address get inet address get the port for the service public abstract int get port inetaddress getinetaddress getport public abstract int get port get the priority of the service public abstract int get priority getport getpriority public abstract int get priority get the weight of the service public abstract int get weight getpriority getweight public abstract int get weight get the text for the serivce as raw bytes public abstract byte get text bytes getweight gettextbytes get the text for the service this will interpret the text bytes as a utf8 encoded string will return null if the bytes are not a valid utf8 encoded string get the url for this service an http url is created by combining the address port and path properties get the url for this service an url is created by combining the protocol address port and path properties get a property of the service this involves decoding the text bytes into a property list returns null if the property is not found or the text data could not be decoded correctly get a property of the service this involves decoding the text bytes into a property list returns null if the property is not found the text data could not be decoded correctly or the resulting bytes are not a valid utf8 string public abstract string get property string string name enumeration of the property names public abstract enumeration get property names getpropertystring getpropertynames public abstract enumeration get property names public abstract string get nice text string getpropertynames getnicetextstring public control request controlrequest public control request http request http req set http req controlrequest httprequest httpreq httpreq public boolean is query control return issoap action control query soapaction isquerycontrol issoapaction query_soapaction public boolean is action control return is query control isactioncontrol isquerycontrol protected void set request host service service string ctrlurl service get controlurl thanks for thomas schulz 2004 03 20 string url base service get root device geturl base if url base null 0 url base length try url url new url url base string base path url get path int base len base path length if 0 base len if 1 base len base path char at 0 ctrlurl base path ctrlurl catch malformedurl exception e thanks for giordano sassaroli sassarol cefriel it 05 21 03 seturi ctrlurl true thanks for giordano sassaroli sassarol cefriel it and suzan foster 09 02 03 thanks for andre andre antiheld net 02 18 04 string posturl if http is absoluteurl ctrlurl true posturl ctrlurl if posturl null posturl length 0 posturl service get root device geturl base thanks for rob van den boomen rob van den boomen philips com 02 17 04 bugfix set urlbase from location string if not set in description xml if posturl null posturl length 0 posturl service get root device get location string req host http get host posturl int req port http get port posturl set host req host req port set request host req host set request port req port setrequesthost getcontrolurl urlbase getrootdevice geturlbase urlbase urlbase urlbase basepath getpath baselen basepath baselen baselen basepath charat basepath malformedurlexception isabsoluteurl getrootdevice geturlbase getrootdevice getlocation reqhost gethost reqport getport sethost reqhost reqport setrequesthost reqhost setrequestport reqport transient int update counter rnd btree updatecounter rndbtree i persistent old node btree key key key i persistent node this key key this node node ipersistent oldnode btreekey ipersistent static final int btree page size page page size object header sizeof 4 4 abstract object get data btree_page_size pagesize objectheader getdata abstract object get data abstract object get key value int i getdata getkeyvalue abstract object get data abstract object get key value int i abstract key get key int i getdata getkeyvalue getkey abstract object get key value int i abstract key get key int i abstract int compare key key int i getkeyvalue getkey abstract key get key int i abstract int compare key key int i abstract void insert btree key key int i getkey btreekey abstract int compare key key int i abstract void insert btree key key int i abstract btree page clone page btreekey btreepage clonepage abstract btree page clone page void clear key value int i btreepage clonepage clearkeyvalue object get at int i int height if height 0 return items get i else int j for j 0 i n children j j i n children j return btree page items get j get at i height getat nchildren nchildren btreepage getat boolean find key first key key last key int height array list result int l 0 n n items r n height 1 if first key null while l r int i l r 1 if compare first key i first key inclusion l i 1 else r i assert that r l if last key null if height 0 while l n if compare last key l last key inclusion return false result add items get l l 1 return true else do if btree page items get l find first key last key height result return false if l n return true while compare last key l 0 return false if height 0 while l n result add items get l l 1 else do if btree page items get l find first key last key height result return false while l n return true firstkey lastkey arraylist nitems firstkey firstkey firstkey lastkey lastkey lastkey btreepage firstkey lastkey lastkey btreepage firstkey lastkey static void memcpy data btree page dst pg int dst idx btree page src pg int src idx int len system arraycopy src pg get data src idx dst pg get data dst idx len memcpydata btreepage dst_pg dst_idx btreepage src_pg src_idx src_pg getdata src_idx dst_pg getdata dst_idx static void memcpy items btree page dst pg int dst idx btree page src pg int src idx int len system arraycopy src pg items to raw array src idx dst pg items to raw array dst idx len system arraycopy src pg n children src idx dst pg n children dst idx len memcpyitems btreepage dst_pg dst_idx btreepage src_pg src_idx src_pg torawarray src_idx dst_pg torawarray dst_idx src_pg nchildren src_idx dst_pg nchildren dst_idx static void memcpy btree page dst pg int dst idx btree page src pg int src idx int len memcpy data dst pg dst idx src pg src idx len memcpy items dst pg dst idx src pg src idx len btreepage dst_pg dst_idx btreepage src_pg src_idx memcpydata dst_pg dst_idx src_pg src_idx memcpyitems dst_pg dst_idx src_pg src_idx void memset int i int len while len 0 items set object i null setobject private void count children int i int height n children i btree page items get i total count height countchildren nchildren btreepage totalcount private int total count int height if height 0 return n items else int sum 0 for int i n items i 0 i sum n children i return sum totalcount nitems nitems nchildren private void insert btree key key int i int height insert key i if height 0 count children i height btreekey countchildren int insert btree key ins int height boolean unique boolean overwrite int result int l 0 n n items r n int ahead unique 1 0 while l r int i l r 1 if compare ins key i ahead l i 1 else r i assert that l r insert before e r if height 0 result btree page items get r insert ins height unique overwrite assert that result op not found if result op overflow if result op done modify n children r 1 return result n 1 else if r n compare ins key r 0 if overwrite ins old node items get r modify items set object r ins node return op overwrite else if unique ins old node items get r return op duplicate int max items size modify if height 0 count children r height if n max memcpy this r 1 this r n r insert ins r height n items 1 return op done else page is full then divide page btree page b clone page assert that n max int m max 2 if r m memcpy b 0 this 0 r memcpy b r 1 this r m r 1 memcpy this 0 this m 1 max m 1 b insert ins r height else memcpy b 0 this 0 m memcpy this 0 this m r m memcpy this r m 1 this r max r insert ins r m height memset max m 1 m 1 ins node b ins key b get key m 1 if height 0 n items max m 1 b n items m else b clear key value m 1 n items max m b n items m 1 return op overflow btreekey nitems btreepage op_not_found op_overflow op_done nchildren oldnode setobject op_overwrite oldnode op_duplicate countchildren nitems op_done btreepage clonepage getkey nitems nitems clearkeyvalue nitems nitems op_overflow int handle page underflow int r btree key rem int height btree page a btree page items get r a modify modify int an a n items if r n items exists greater page btree page b btree page items get r 1 int bn b n items assert that bn an if height 1 memcpy data a an this r 1 an 1 bn 1 if an bn items size reallocation of nodes between pages a and b int i bn an bn 1 b modify memcpy a an b 0 i memcpy b 0 b i bn i memcpy data this r a an i 1 1 if height 1 a clear key value an i 1 b memset bn i i b n items i a n items i count children r height count children r 1 height return op done else merge page b to a memcpy a an b 0 bn b deallocate int n merged children n children r 1 memcpy data this r this r 1 n items r 1 memcpy items this r 1 this r 2 n items r 1 items set object n items null a n items bn n items 1 n children r n merged children 1 return n items items size 1 op underflow op done else page b is before a btree page b btree page items get r 1 int bn b n items assert that bn an if height 1 an 1 bn 1 if an bn items size reallocation of nodes between pages a and b int i bn an bn 1 b modify memcpy a i a 0 an memcpy a 0 b bn i i if height 1 memcpy data a i 1 this r 1 1 memcpy data this r 1 b bn i 1 1 if height 1 b clear key value bn i 1 b memset bn i i b n items i a n items i count children r 1 height count children r height return op done else merge page b to a memcpy a bn a 0 an memcpy a 0 b 0 bn if height 1 memcpy data a bn 1 this r 1 1 b deallocate items set object r 1 a items set object n items null n children r 1 n children r 1 a n items bn n items 1 return n items items size 1 op underflow op done handlepageunderflow btreekey btreepage btreepage nitems nitems btreepage btreepage nitems memcpydata memcpydata clearkeyvalue nitems nitems countchildren countchildren op_done nmergedchildren nchildren memcpydata nitems memcpyitems nitems setobject nitems nitems nitems nchildren nmergedchildren nitems op_underflow op_done btreepage btreepage nitems memcpydata memcpydata clearkeyvalue nitems nitems countchildren countchildren op_done memcpydata setobject setobject nitems nchildren nchildren nitems nitems nitems op_underflow op_done int remove btree key rem int height int i n n items l 0 r n while l r i l r 1 if compare rem key i 0 l i 1 else r i if height 0 i persistent node rem node while r n if compare rem key r 0 if node null items contains element r node rem old node items get r modify memcpy this r this r 1 n r 1 n items n memset n 1 return n items size 1 op underflow op done else break r 1 return op not found do switch btree page items get r remove rem height case op underflow return handle page underflow r rem height case op done modify n children r 1 return op done while r n return op not found btreekey nitems ipersistent containselement oldnode nitems op_underflow op_done op_not_found btreepage op_underflow handlepageunderflow op_done nchildren op_done op_not_found void purge int height if height 0 int n n items do btree page items get n purge height while n 0 super deallocate nitems btreepage int traverse forward int height i persistent result int pos int i n n items if height 0 for i 0 i n i pos btree page items get i traverse forward height result pos else for i 0 i n i result pos items get i return pos traverseforward ipersistent nitems btreepage traverseforward btree page storage s int n super s items s create link n items set size n n children new int n btreepage createlink setsize nchildren btree page btreepage static final int max items btree page size 4 4 1 object get data return data max_items btree_page_size getdata object get key value int i return new byte data i getkeyvalue key get key int i return new key data i getkey btree page clone page return new btree page of byte get storage btreepage clonepage btreepageofbyte getstorage int compare key key int i return byte key ival data i void insert btree key key int i items set object i key node data i byte key key ival btreekey setobject btree page of byte storage s super s max items data new byte max items btreepageofbyte max_items max_items btree page of byte btreepageofbyte static class btree page of boolean extends btree page of byte key get key int i return new key data i 0 btreepageofboolean btreepageofbyte getkey object get key value int i return boolean value of data i 0 getkeyvalue valueof btree page clone page return new btree page of boolean get storage btreepage clonepage btreepageofboolean getstorage btree page of boolean btreepageofboolean btree page of boolean btree page of boolean storage s super s btreepageofboolean btreepageofboolean static final int max items btree page size 4 4 2 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return short value of data i getkeyvalue valueof btree page clone page return new btree page of short get storage btreepage clonepage btreepageofshort getstorage int compare key key int i return short key ival data i void insert btree key key int i items set object i key node data i short key key ival btreekey setobject btree page of short storage s super s max items data new short max items btreepageofshort max_items max_items btree page of short btreepageofshort static final int max items btree page size 4 4 2 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new character data i getkeyvalue btree page clone page return new btree page of char get storage btreepage clonepage btreepageofchar getstorage int compare key key int i return char key ival data i void insert btree key key int i items set object i key node data i char key key ival btreekey setobject btree page of char storage s super s max items data new char max items btreepageofchar max_items max_items btree page of char btreepageofchar static final int max items btree page size 4 4 4 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new integer data i getkeyvalue btree page clone page return new btree page of int get storage btreepage clonepage btreepageofint getstorage int compare key key int i return key ival data i void insert btree key key int i items set object i key node data i key key ival btreekey setobject btree page of int storage s super s max items data new int max items btreepageofint max_items max_items btree page of int btreepageofint static final int max items btree page size 4 4 8 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new long data i getkeyvalue btree page clone page return new btree page of long get storage btreepage clonepage btreepageoflong getstorage int compare key key int i return key lval data i 1 key lval data i 0 1 void insert btree key key int i items set object i key node data i key key lval btreekey setobject btree page of long storage s super s max items data new long max items btreepageoflong max_items max_items btree page of long btreepageoflong static final int max items btree page size 4 4 4 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new float data i getkeyvalue btree page clone page return new btree page of float get storage btreepage clonepage btreepageoffloat getstorage int compare key key int i return float key dval data i 1 float key dval data i 0 1 void insert btree key key int i items set object i key node data i float key key dval btreekey setobject btree page of float storage s super s max items data new float max items btreepageoffloat max_items max_items btree page of float btreepageoffloat static final int max items btree page size 4 4 8 object get data return data max_items btree_page_size getdata key get key int i return new key data i getkey object get key value int i return new double data i getkeyvalue btree page clone page return new btree page of double get storage btreepage clonepage btreepageofdouble getstorage int compare key key int i return key dval data i 1 key dval data i 0 1 void insert btree key key int i items set object i key node data i key key dval btreekey setobject btree page of double storage s super s max items data new double max items btreepageofdouble max_items max_items btree page of double btreepageofdouble static final int max items btree page size 4 4 4 object get data return data to raw array max_items btree_page_size getdata torawarray key get key int i return new key data get raw i getkey getraw object get key value int i return data get i getkeyvalue btree page clone page return new btree page of object get storage btreepage clonepage btreepageofobject getstorage int compare key key int i i persistent obj data get raw i int oid obj null 0 obj get oid return key ival oid ipersistent getraw getoid void insert btree key key int i items set object i key node data set object i i persistent key key oval btreekey setobject setobject ipersistent btree page of object storage s super s max items data s create link max items data set size max items btreepageofobject max_items createlink max_items setsize max_items btree page of object btreepageofobject static final int max items 100 object get data return data max_items getdata key get key int i return new key data i getkey object get key value int i return data i getkeyvalue void clear key value int i data i null clearkeyvalue btree page clone page return new btree page of string get storage btreepage clonepage btreepageofstring getstorage int compare key key int i return string key oval compare to data i compareto void insert btree key key int i items set object i key node data i string key key oval btreekey setobject void memset int i int len while len 0 items set object i null data i null i 1 setobject boolean prefix search string key int height array list result int l 0 n n items r n height 1 while l r int i l r 1 if key starts with data i key compare to data i 0 l i 1 else r i assert that r l if height 0 while l n if key compare to data l 0 return false result add items get l l 1 else do if btree page of string items get l prefix search key height result return false if l n return true while key compare to data l 0 return false return true prefixsearch arraylist nitems startswith compareto compareto btreepageofstring prefixsearch compareto btree page of string storage s super s max items data new string max items btreepageofstring max_items max_items btree page of string btreepageofstring static final int max items 100 object get data return data max_items getdata key get key int i return new key comparable object data i getkey object get key value int i return object data i getkeyvalue void clear key value int i object data i null clearkeyvalue btree page clone page return new btree page of raw get storage btreepage clonepage btreepageofraw getstorage int compare key key int i return comparable key oval compare to object data i compareto void insert btree key key int i items set object i key node object data i key key oval btreekey setobject btree page of raw storage s super s max items data new object max items btreepageofraw max_items max_items btree page of raw btreepageofraw static int check type class c int elem type class descriptor get type code c if elem type class descriptor tp object elem type class descriptor tp raw elem type class descriptor tp enum throw new storage error storage error unsupported index type c return elem type checktype elemtype classdescriptor gettypecode elemtype classdescriptor tpobject elemtype classdescriptor tpraw elemtype classdescriptor tpenum storageerror storageerror unsupported_index_type elemtype rnd btree class cls boolean unique this unique unique type check type cls rndbtree checktype rnd btree int type boolean unique this type type this unique unique rndbtree static final int op overwrite 5 public class get key types return new class get key type op_overwrite getkeytypes getkeytype public class get key type return map key type type getkeytype mapkeytype static class map key type int type switch type case class descriptor tp boolean return boolean class case class descriptor tp byte return byte class case class descriptor tp char return char class case class descriptor tp short return short class case class descriptor tp int return int class case class descriptor tp long return long class case class descriptor tp float return float class case class descriptor tp double return double class case class descriptor tp string return string class case class descriptor tp date return date class case class descriptor tp object return i persistent class case class descriptor tp raw return comparable class case class descriptor tp enum return enum class default return null mapkeytype classdescriptor tpboolean classdescriptor tpbyte classdescriptor tpchar classdescriptor tpshort classdescriptor tpint classdescriptor tplong classdescriptor tpfloat classdescriptor tpdouble classdescriptor tpstring classdescriptor tpdate classdescriptor tpobject ipersistent classdescriptor tpraw classdescriptor tpenum key check key key key if key null if key type type throw new storage error storage error incompatible key type if type class descriptor tp object key ival 0 key oval null i persistent obj i persistent key oval get storage make persistent obj key new key obj key inclusion 0 if key oval instanceof char key new key new string char key oval key inclusion 0 return key checkkey storageerror storageerror incompatible_key_type classdescriptor tpobject ipersistent ipersistent getstorage makepersistent public t get key key key check key key if root null array list list new array list root find key key height list if list size 1 throw new storage error storage error key not unique else if list size 0 return null else return t list get 0 return null checkkey arraylist arraylist storageerror storageerror key_not_unique public array list t prefix search list string key if class descriptor tp string type throw new storage error storage error incompatible key type array list t list new array list t if root null btree page of string root prefix search key height list return list arraylist prefixsearchlist classdescriptor tpstring storageerror storageerror incompatible_key_type arraylist arraylist btreepageofstring prefixsearch public i persistent prefix search string key array list t list prefix search list key return i persistent list to array new i persistent list size ipersistent prefixsearch arraylist prefixsearchlist ipersistent toarray ipersistent public array list t get list key from key till array list t list new array list t if root null root find check key from check key till height list return list arraylist getlist arraylist arraylist checkkey checkkey public array list t get list object from object till return get list btree get key from object from btree get key from object till arraylist getlist getlist getkeyfromobject getkeyfromobject public i persistent get key from key till array list t list get list from till return i persistent list to array new i persistent list size ipersistent arraylist getlist ipersistent toarray ipersistent public i persistent get object from object till return get btree get key from object from btree get key from object till ipersistent getkeyfromobject getkeyfromobject public boolean put key key t obj return insert key obj false null public t set key key t obj return insert key obj true final void allocate root page btree key ins int height storage s get storage btree page new root null switch type case class descriptor tp byte new root new btree page of byte s break case class descriptor tp short new root new btree page of short s break case class descriptor tp char new root new btree page of char s break case class descriptor tp boolean new root new btree page of boolean s break case class descriptor tp int case class descriptor tp enum new root new btree page of int s break case class descriptor tp long new root new btree page of long s break case class descriptor tp float new root new btree page of float s break case class descriptor tp double new root new btree page of double s break case class descriptor tp object new root new btree page of object s break case class descriptor tp string new root new btree page of string s break case class descriptor tp raw new root new btree page of raw s break default assert failed invalid type new root insert ins 0 height new root items set object 1 root if height 0 new root count children 1 height new root n items 1 root new root allocaterootpage btreekey getstorage btreepage newroot classdescriptor tpbyte newroot btreepageofbyte classdescriptor tpshort newroot btreepageofshort classdescriptor tpchar newroot btreepageofchar classdescriptor tpboolean newroot btreepageofboolean classdescriptor tpint classdescriptor tpenum newroot btreepageofint classdescriptor tplong newroot btreepageoflong classdescriptor tpfloat newroot btreepageoffloat classdescriptor tpdouble newroot btreepageofdouble classdescriptor tpobject newroot btreepageofobject classdescriptor tpstring newroot btreepageofstring classdescriptor tpraw newroot btreepageofraw newroot newroot setobject newroot countchildren newroot nitems newroot final t insert key key t obj boolean overwrite btree key ins new btree key check key key obj if root null allocate root page ins 0 height 1 else int result root insert ins height unique overwrite if result op overflow allocate root page ins height height 1 else if result op duplicate result op overwrite return t ins old node update counter 1 n elems 1 modify return null btreekey btreekey checkkey allocaterootpage op_overflow allocaterootpage op_duplicate op_overwrite oldnode updatecounter nelems public void remove key key t obj remove new btree key check key key obj btreekey checkkey void remove btree key rem if remove if exists rem throw new storage error storage error key not found btreekey removeifexists storageerror storageerror key_not_found boolean remove if exists btree key rem if root null return false int result root remove rem height if result op not found return false n elems 1 if result op underflow if root n items 0 btree page new root null if height 1 new root btree page root items get 0 root deallocate root new root height 1 update counter 1 modify return true removeifexists btreekey op_not_found nelems op_underflow nitems btreepage newroot newroot btreepage newroot updatecounter public t remove key key if unique throw new storage error storage error key not unique btree key rk new btree key check key key null remove rk return t rk old node storageerror storageerror key_not_unique btreekey btreekey checkkey oldnode public t get object key return get btree get key from object key getkeyfromobject public array list t get prefix list string prefix return get list new key prefix true new key prefix character max value false arraylist getprefixlist getlist max_value public i persistent get prefix string prefix return get new key prefix true new key prefix character max value false ipersistent getprefix max_value public boolean put object key t obj return put btree get key from object key obj getkeyfromobject public t set object key t obj return set btree get key from object key obj getkeyfromobject public void remove object key t obj remove btree get key from object key obj getkeyfromobject public t remove string key return remove new key key public t remove key object key return remove key btree get key from object key removekey removekey getkeyfromobject public int size return n elems nelems public void clear if root null root purge height root null n elems 0 height 0 update counter 1 modify nelems updatecounter public i persistent to persistent array i persistent arr new i persistent n elems if root null root traverse forward height arr 0 return arr ipersistent topersistentarray ipersistent ipersistent nelems traverseforward public object to array return to persistent array toarray topersistentarray public e e to array e arr if arr length n elems arr e array new instance arr get class get component type n elems if root null root traverse forward height i persistent arr 0 if arr length n elems arr n elems null return arr toarray nelems newinstance getclass getcomponenttype nelems traverseforward ipersistent nelems nelems public void deallocate if root null root purge height super deallocate static class btree entry t implements map entry object t public object get key return pg get key value pos btreeentry getkey getkeyvalue public t get value return t pg items get pos getvalue public t set value t value throw new unsupported operation exception setvalue unsupportedoperationexception public boolean equals object o if o instanceof map entry return false map entry e map entry o return get key null e get key null get key equals e get key get value null e get value null get value equals e get value getkey getkey getkey getkey getvalue getvalue getvalue getvalue public int hash code return get key null 0 get key hash code get value null 0 get value hash code hashcode getkey getkey hashcode getvalue getvalue hashcode public string to string return get key get value tostring getkey getvalue btree entry btree page pg int pos this pg pg this pos pos btreeentry btreepage public iterator t iterator return iterator null null ascent order ascent_order public iterable iterator map entry object t entry iterator return entry iterator null null ascent order iterableiterator entryiterator entryiterator ascent_order class btree selection iterator e extends iterable iterator e implements persistent iterator btree selection iterator key from key till int order this from from this till till this order order reset btreeselectioniterator iterableiterator persistentiterator btreeselectioniterator btree selection iterator int order this order order btreeselectioniterator void reset int i l r sp 0 counter update counter if height 0 return btree page page root int h height page stack new btree page h pos stack new int h if order ascent order if from null while h 0 pos stack sp 0 page stack sp page page btree page page items get 0 sp 1 pos stack sp 0 page stack sp page end page n items sp 1 else while h 0 page stack sp page l 0 r page n items while l r i l r 1 if page compare from i from inclusion l i 1 else r i assert that r l pos stack sp r page btree page page items get r sp 1 page stack sp page l 0 r end page n items while l r i l r 1 if page compare from i from inclusion l i 1 else r i assert that r l if r end sp 1 goto next item page r 1 else pos stack sp r if sp 0 till null page page stack sp 1 if page compare till pos stack sp 1 till inclusion sp 0 else descent order if till null while h 0 page stack sp page pos stack sp page n items page btree page page items get page n items sp 1 page stack sp page pos stack sp page n items 1 else while h 0 page stack sp page l 0 r page n items while l r i l r 1 if page compare till i 1 till inclusion l i 1 else r i assert that r l pos stack sp r page btree page page items get r sp 1 page stack sp page l 0 r page n items while l r i l r 1 if page compare till i 1 till inclusion l i 1 else r i assert that r l if r 0 sp 1 goto next item page r else pos stack sp r 1 if sp 0 from null page page stack sp 1 if page compare from pos stack sp 1 from inclusion sp 0 updatecounter btreepage pagestack btreepage posstack ascent_order posstack pagestack btreepage posstack pagestack nitems pagestack nitems posstack btreepage pagestack nitems gotonextitem posstack pagestack posstack pagestack posstack nitems btreepage nitems pagestack posstack nitems pagestack nitems posstack btreepage pagestack nitems gotonextitem posstack pagestack posstack public boolean has next if counter update counter if storage impl get storage concurrent iterator refresh else throw new concurrent modification exception return sp 0 hasnext updatecounter storageimpl getstorage concurrentiterator concurrentmodificationexception public e next if has next throw new no such element exception int pos pos stack sp 1 btree page pg page stack sp 1 curr pos pos curr page pg e curr e get current pg pos if storage impl get storage concurrent iterator curr key new btree key pg get key pos pg items get raw pos goto next item pg pos return curr hasnext nosuchelementexception posstack btreepage pagestack currpos currpage getcurrent storageimpl getstorage concurrentiterator currkey btreekey getkey getraw gotonextitem public int next oid if has next throw new no such element exception int pos pos stack sp 1 btree page pg page stack sp 1 curr pos pos curr page pg i persistent obj pg items get raw pos int oid obj null 0 obj get oid if storage impl get storage concurrent iterator curr key new btree key pg get key pos pg items get raw pos goto next item pg pos return oid nextoid hasnext nosuchelementexception posstack btreepage pagestack currpos currpage ipersistent getraw getoid storageimpl getstorage concurrentiterator currkey btreekey getkey getraw gotonextitem protected object get current btree page pg int pos return pg items get pos getcurrent btreepage protected final void goto next item btree page pg int pos if order ascent order if pos end while sp 0 pos pos stack sp 1 pg page stack sp 1 if pos pg n items pos stack sp 1 pos do pg btree page pg items get pos end pg n items page stack sp pg pos stack sp pos 0 while sp page stack length break else pos stack sp 1 pos if sp 0 till null pg compare till pos till inclusion sp 0 else descent order if pos 0 while sp 0 pos pos stack sp 1 pg page stack sp 1 if pos 0 pos stack sp 1 pos do pg btree page pg items get pos page stack sp pg pos stack sp pos pg n items while sp page stack length pos stack sp 1 pos break else pos stack sp 1 pos if sp 0 from null pg compare from pos from inclusion sp 0 if storage impl get storage concurrent iterator sp 0 next key pg get key pos next obj pg items get raw pos gotonextitem btreepage ascent_order posstack pagestack nitems posstack btreepage nitems pagestack posstack pagestack posstack posstack pagestack posstack btreepage pagestack posstack nitems pagestack posstack posstack storageimpl getstorage concurrentiterator nextkey getkey nextobj getraw private void refresh if sp 0 if next key null reset else if order ascent order from next key else till next key i persistent next next obj reset while true int pos pos stack sp 1 btree page pg page stack sp 1 if pg items get raw pos equals next goto next item pg pos else break counter update counter nextkey ascent_order nextkey nextkey ipersistent nextobj posstack btreepage pagestack getraw gotonextitem updatecounter public void remove if curr page null throw new no such element exception storage impl db storage impl get storage if db concurrent iterator if counter update counter throw new concurrent modification exception curr key new btree key curr page get key curr pos curr page items get raw curr pos if sp 0 int pos pos stack sp 1 btree page pg page stack sp 1 next key pg get key pos next obj pg items get raw pos rnd btree this remove if exists curr key refresh curr page null currpage nosuchelementexception storageimpl storageimpl getstorage concurrentiterator updatecounter concurrentmodificationexception currkey btreekey currpage getkey currpos currpage getraw currpos posstack btreepage pagestack nextkey getkey nextobj getraw rndbtree removeifexists currkey currpage class btree selection entry iterator extends btree selection iterator map entry object t btree selection entry iterator key from key till int order super from till order btreeselectionentryiterator btreeselectioniterator btreeselectionentryiterator btree selection entry iterator int order super order btreeselectionentryiterator protected object get current btree page pg int pos return new btree entry pg pos getcurrent btreepage btreeentry btree entry start from iterator int start int order super order this start start reset btreeentrystartfromiterator void reset sp 0 counter update counter if height 0 start n elems return btree page page root int h height int i start page stack new btree page h pos stack new int h while h 0 page stack sp page int j for j 0 i page n children j j i page n children j pos stack sp j page btree page page items get j sp 1 page stack sp page pos stack sp i end page n items updatecounter nelems btreepage pagestack btreepage posstack pagestack nchildren nchildren posstack btreepage pagestack posstack nitems public iterable iterator t iterator key from key till int order return new btree selection iterator t check key from check key till order iterableiterator btreeselectioniterator checkkey checkkey public iterable iterator t iterator object from object till int order return new btree selection iterator t check key btree get key from object from check key btree get key from object till order iterableiterator btreeselectioniterator checkkey getkeyfromobject checkkey getkeyfromobject public iterable iterator t prefix iterator string prefix return iterator new key prefix new key prefix character max value false ascent order iterableiterator prefixiterator max_value ascent_order public iterable iterator map entry object t entry iterator key from key till int order return new btree selection entry iterator check key from check key till order iterableiterator entryiterator btreeselectionentryiterator checkkey checkkey public iterable iterator map entry object t entry iterator object from object till int order return new btree selection entry iterator check key btree get key from object from check key btree get key from object till order iterableiterator entryiterator btreeselectionentryiterator checkkey getkeyfromobject checkkey getkeyfromobject public t get at int i if i 0 i n elems throw new index out of bounds exception position i index size n elems return t root get at i height getat nelems indexoutofboundsexception nelems getat public iterable iterator map entry object t entry iterator int start int order return new btree entry start from iterator start order iterableiterator entryiterator btreeentrystartfromiterator public boolean is unique return unique isunique public final string mime types private archive type short metadataid string mime types this metadataid metadataid this mime types mime types mimetypes archive_type mimetypes mimetypes mimetypes public static boolean is valid metadataid short id for archive type current values if id current metadataid return true return false isvalidmetadataid archive_type is the given mime type an archive type that we can deal with public static boolean is usable archive type string type for archive type current values for string ctype current mime types if ctype equals ignore case type return true return false isusablearchivetype archive_type mimetypes equalsignorecase if the given mime type is an archive type that we can deal with get its archive type number see the archive constants in metadata public static archive type get archive type string type for archive type current values for string ctype current mime types if ctype equals ignore case type return current return null archive_ archive_type getarchivetype archive_type mimetypes equalsignorecase public static archive type get archive type short type for archive type current values if current metadataid type return current return null archive_type getarchivetype archive_type public final static archive type get default return tar archive_type getdefault create an archive manager param max handlers the maximum number of cached archive handler s i e the maximum number of containers to track param max cached data the maximum size of the cache directory in bytes param max archive size the maximum size of an archive param max archived file size the maximum extracted size of a single file in any archive param max cached elements the maximum number of cached elements an element is a file extracted from an archive it is stored encrypted and padded in a single file param cache dir the directory in which to store cached data param random a cryptographicaly secure random source param weak random a weak and cheap random source public archive manager int max handlers long max cached data long max archived file size int max cached elements bucket factory temp bucket factory max archive handlers max handlers archive handlers new lru hashtable freeneturi archive store context this max cached elements max cached elements this max cached data max cached data stored data new lru hashtable archive key archive store item this max archived file size max archived file size this temp bucket factory temp bucket factory logminor logger should log logger minor this archivemanager maxhandlers archivehandler maxcacheddata maxarchivesize maxarchivedfilesize maxcachedelements cachedir weakrandom archivemanager maxhandlers maxcacheddata maxarchivedfilesize maxcachedelements bucketfactory tempbucketfactory maxarchivehandlers maxhandlers archivehandlers lruhashtable archivestorecontext maxcachedelements maxcachedelements maxcacheddata maxcacheddata storeddata lruhashtable archivekey archivestoreitem maxarchivedfilesize maxarchivedfilesize tempbucketfactory tempbucketfactory shouldlog add an archive handler by key private synchronized void put cached freeneturi key archive store context zip if logminor logger minor this put cached ah for key zip archive handlers push key zip while archive handlers size max archive handlers archive handlers pop key dump it archivehandler putcached archivestorecontext archivehandlers archivehandlers maxarchivehandlers archivehandlers popkey get an archive handler by key archive store context get cached freeneturi key if logminor logger minor this get cached ah for key archive store context handler archive handlers get key if handler null return null archive handlers push key handler return handler archivehandler archivestorecontext getcached archivestorecontext archivehandlers archivehandlers create an archive handler this does not need to know how to fetch the key because the methods called later will ask it will try to serve from cache but if that fails will re fetch param key the key of the archive that we are extracting data from param archive type the archive type defined in metadata return an archive handler synchronized archive store context make context freeneturi key archive type archive type compressor type ctype boolean return null if not found archive store context handler null handler get cached key if handler null return handler if return null if not found return null handler new archive store context key archive type put cached key handler return handler archivetype archivestorecontext makecontext archive_type archivetype compressor_type returnnullifnotfound archivestorecontext getcached returnnullifnotfound archivestorecontext archivetype putcached create an archive handler this does not need to know how to fetch the key because the methods called later will ask it will try to serve from cache but if that fails will re fetch param key the key of the archive that we are extracting data from param archive type the archive type defined in metadata return an archive handler public archive handler make handler freeneturi key archive type archive type compressor type ctype boolean force refetch boolean persistent return new archive handler impl persistent key clone key archive type ctype force refetch archivetype archivehandler makehandler archive_type archivetype compressor_type forcerefetch archivehandlerimpl archivetype forcerefetch get a cached previously extracted file from an archive param key the key used to fetch the archive param filename the name of the file within the archive return a bucket containing the data requested or null throws archive failure exception public bucket get cached freeneturi key string filename throws archive failure exception if logminor logger minor this fetch cached key filename archive key k new archive key key filename archive store item asi null synchronized this asi stored data get k if asi null return null promote to top of lru stored data push k asi if logminor logger minor this found data return asi get reader bucket archivefailureexception getcached archivefailureexception archivekey archivekey archivestoreitem storeddata storeddata getreaderbucket remove a file from the cache called after it has been removed from its archive handler param item the archive store item to remove synchronized void remove cached item archive store item item long size item space used stored data remove key item key hard disk space limit remove it here soft disk space limit would be to remove it outside the lock soft disk space limit we go over the limit significantly when we are overloaded cached data size if logminor logger minor this remove cached item item item close archivehandler archivestoreitem removecacheditem archivestoreitem spaceused storeddata removekey cacheddata removecacheditem extract data to cache call synchronized on ctx param key the key the data was fetched from param archive type the archive type must be metadata archive zip metadata archive tar param data the actual data fetched param archive context the context for the whole fetch process param ctx the archive store context for this key param element a particular element that the caller is especially interested in or null param callback a callback to be called if we find that element or if we don t throws archive failure exception if we could not extract the data or it was too big etc throws archive restart exception throws archive restart exception if the request needs to be restarted because the archive changed fixme this method can be called from the database thread however it isn t at present check the call stack maybe we should get rid of the object container otoh maybe extracting inline on the database thread for small containers would be useful public void extract to cache freeneturi key archive type archive type compressor type ctype bucket data archive context archive context archive store context ctx string element archive extract callback callback object container container client context context throws archive failure exception archive restart exception logminor logger should log logger minor this mutable boolean got element element null new mutable boolean null if logminor logger minor this extracting key ctx remove all cached items this flush cache anyway final long expected size ctx get last size final long archive size data size set if we need to throw a restarted exception rather than returning success after we have unpacked everything boolean throw at exit false if expected size 1 archive size expected size throw at exit true ctx set last size archive size byte expected hash ctx get last hash if expected hash null byte real hash try real hash bucket tools hash data catch io exception e throw new archive failure exception error reading archive data e e if arrays equals real hash expected hash throw at exit true ctx set last hash real hash if archive size archive context max archive size throw new archive failure exception archive too big archive size archive context max archive size else if archive size 0 throw new archive failure exception archive too small archive size else if logminor logger minor this container size possibly compressed archive size for data input stream is null try if ctype null archive type zip archive type if logminor logger minor this no compression is data get input stream else if ctype compressor type bzip2 if logminor logger minor this dealing with bzip2 is new cb zip2 input stream data get input stream else if ctype compressor type gzip if logminor logger minor this dealing with gzip is new gzip input stream data get input stream else if ctype compressor type lzma if logminor logger minor this dealing with lzma is new lzma input stream data get input stream if archive type zip archive type handlezip archive ctx key is element callback got element throw at exit container context else if archive type tar archive type handletar archive ctx key is element callback got element throw at exit container context else throw new archive failure exception unknown or unsupported archive algorithm archive type catch io exception ioe throw new archive failure exception an ioe occured ioe get message ioe finally closer close is archivetype archive_zip archive_tar archivecontext archivestorecontext archivefailureexception archiverestartexception archiverestartexception objectcontainer extracttocache archive_type archivetype compressor_type archivecontext archivecontext archivestorecontext archiveextractcallback objectcontainer clientcontext archivefailureexception archiverestartexception shouldlog mutableboolean gotelement mutableboolean removeallcacheditems expectedsize getlastsize archivesize restartedexception throwatexit expectedsize archivesize expectedsize throwatexit setlastsize archivesize expectedhash getlasthash expectedhash realhash realhash buckettools ioexception archivefailureexception realhash expectedhash throwatexit setlasthash realhash archivesize archivecontext maxarchivesize archivefailureexception archivesize archivecontext maxarchivesize archivesize archivefailureexception archivesize archivesize inputstream archive_type archivetype getinputstream compressor_type cbzip2inputstream getinputstream compressor_type gzipinputstream getinputstream compressor_type lzmainputstream getinputstream archive_type archivetype handleziparchive gotelement throwatexit archive_type archivetype handletararchive gotelement throwatexit archivefailureexception archivetype ioexception archivefailureexception getmessage private void handletar archive archive store context ctx freeneturi key input stream data string element archive extract callback callback mutable boolean got element boolean throw at exit object container container client context context throws archive failure exception archive restart exception if logminor logger minor this handling a tar archive tar input stream taris null try taris new tar input stream data minor assumes the first entry in the tarball is a directory tar entry entry byte buf new byte 32768 hash set string names new hash set string boolean got metadata false outertar while true entry taris get next entry if entry null break if entry is directory continue string name entry get name if names contains name logger error this duplicate key name in archive key continue long size entry get size if size max archived file size add error element ctx key name file too big max archived file size greater than current archived file size limit max archived file size else read the element long real len 0 bucket output temp bucket factory make bucket size output stream out output get output stream int read bytes while read bytes taris read buf 0 out write buf 0 read bytes read bytes real len if read bytes max archived file size add error element ctx key name file too big max archived file size greater than current archived file size limit max archived file size out close output free continue outertar out close if name equals metadata got metadata true add store element ctx key name output got element element callback container context names add name trim stored data if no metadata generate some if got metadata generate metadata ctx key names got element element callback container context trim stored data if throw at exit throw new archive restart exception archive changed on re fetch if got element value element null callback not in archive container context catch io exception e throw new archive failure exception error reading archive e get message e finally closer close taris handletararchive archivestorecontext inputstream archiveextractcallback mutableboolean gotelement throwatexit objectcontainer clientcontext archivefailureexception archiverestartexception tarinputstream tarinputstream tarentry hashset hashset gotmetadata getnextentry isdirectory getname getsize maxarchivedfilesize adderrorelement maxarchivedfilesize maxarchivedfilesize reallen tempbucketfactory makebucket outputstream getoutputstream readbytes readbytes readbytes readbytes reallen readbytes maxarchivedfilesize adderrorelement maxarchivedfilesize maxarchivedfilesize gotmetadata addstoreelement gotelement trimstoreddata gotmetadata generatemetadata gotelement trimstoreddata throwatexit archiverestartexception gotelement notinarchive ioexception archivefailureexception getmessage private void handlezip archive archive store context ctx freeneturi key input stream data string element archive extract callback callback mutable boolean got element boolean throw at exit object container container client context context throws archive failure exception archive restart exception if logminor logger minor this handling a zip archive zip input stream zis null try zis new zip input stream data minor assumes the first entry in the zip is a directory zip entry entry byte buf new byte 32768 hash set string names new hash set string boolean got metadata false outerzip while true entry zis get next entry if entry null break if entry is directory continue string name entry get name if names contains name logger error this duplicate key name in archive key continue long size entry get size if size max archived file size add error element ctx key name file too big max archived file size greater than current archived file size limit max archived file size else read the element long real len 0 bucket output temp bucket factory make bucket size output stream out output get output stream int read bytes while read bytes zis read buf 0 out write buf 0 read bytes read bytes real len if read bytes max archived file size add error element ctx key name file too big max archived file size greater than current archived file size limit max archived file size out close output free continue outerzip out close if name equals metadata got metadata true add store element ctx key name output got element element callback container context names add name trim stored data if no metadata generate some if got metadata generate metadata ctx key names got element element callback container context trim stored data if throw at exit throw new archive restart exception archive changed on re fetch if got element value element null callback not in archive container context catch io exception e throw new archive failure exception error reading archive e get message e finally if zis null try zis close catch io exception e logger error this failed to close stream e e handleziparchive archivestorecontext inputstream archiveextractcallback mutableboolean gotelement throwatexit objectcontainer clientcontext archivefailureexception archiverestartexception zipinputstream zipinputstream zipentry hashset hashset gotmetadata getnextentry isdirectory getname getsize maxarchivedfilesize adderrorelement maxarchivedfilesize maxarchivedfilesize reallen tempbucketfactory makebucket outputstream getoutputstream readbytes readbytes readbytes readbytes reallen readbytes maxarchivedfilesize adderrorelement maxarchivedfilesize maxarchivedfilesize gotmetadata addstoreelement gotelement trimstoreddata gotmetadata generatemetadata gotelement trimstoreddata throwatexit archiverestartexception gotelement notinarchive ioexception archivefailureexception getmessage ioexception generate fake metadata for an archive which doesn t have any param ctx the context object param key the key from which the archive we are unpacking was fetched param names set of names in the archive param element2 param got element param callback name if we generate a throws archive failure exception private archive store item generate metadata archive store context ctx freeneturi key set string names mutable boolean got element string element2 archive extract callback callback object container container client context context throws archive failure exception what we have to do is to construct a filesystem tree of the names turn each level of the tree into a metadata object including those below it with simple manifests and archive internal redirects turn the master metadata object into binary metadata with all its subsidiaries create a metadata entry containing this data root directory string either itself or another hash map hash map string object dir new hash map string object for string name names add to directory dir name metadata metadata new metadata dir int x 0 bucket bucket null while true try bucket temp bucket factory make bucket 1 byte buf metadata write to byte array output stream os bucket get output stream os write buf os close return add store element ctx key metadata bucket got element element2 callback container context catch metadata unresolved exception e try x resolve e x bucket ctx key got element element2 callback container context catch io exception e1 throw new archive failure exception failed to create metadata e1 e1 catch io exception e1 logger error this failed to create metadata e1 e1 throw new archive failure exception failed to create metadata e1 e1 gotelement callbackname archivefailureexception archivestoreitem generatemetadata archivestorecontext mutableboolean gotelement archiveextractcallback objectcontainer clientcontext archivefailureexception hashmap hashmap hashmap addtodirectory tempbucketfactory makebucket writetobytearray outputstream getoutputstream addstoreelement gotelement metadataunresolvedexception gotelement ioexception archivefailureexception ioexception archivefailureexception private int resolve metadata unresolved exception e int x bucket bucket archive store context ctx freeneturi key mutable boolean got element string element2 archive extract callback callback object container container client context context throws io exception archive failure exception metadata m e must resolve for int i 0 i m length i try byte buf m i write to byte array output stream os bucket get output stream os write buf os close add store element ctx key metadata x bucket got element element2 callback container context catch metadata unresolved exception e1 x resolve e x bucket ctx key got element element2 callback container context return x metadataunresolvedexception archivestorecontext mutableboolean gotelement archiveextractcallback objectcontainer clientcontext ioexception archivefailureexception mustresolve writetobytearray outputstream getoutputstream addstoreelement gotelement metadataunresolvedexception gotelement private void add to directory hash map string object dir string name string prefix throws archive failure exception int x name index of if x 0 if dir contains key name throw new archive failure exception invalid archive contains prefix name twice dir put name name else string before name substring 0 x string after if x name length 1 last char after else after name substring x 1 name length object o dir get before hash map string object map hash map string object o if o null map new hash map string object dir put before map if o instanceof string throw new archive failure exception invalid archive contains name as both file and dir add to directory map after prefix before addtodirectory hashmap archivefailureexception indexof containskey archivefailureexception hashmap hashmap hashmap archivefailureexception addtodirectory add an error element to the cache this happens when a single file in the archive is invalid usually because it is too large param ctx the archive store context which must be notified about this element s creation param key the key from which the archive was fetched param name the name of the file within the archive param error the error message to be included on the eventual exception thrown if anyone tries to extract the data for this element private void add error element archive store context ctx freeneturi key string name string error error archive store item element new error archive store item ctx key name error if logminor logger minor this adding error element element for key name archive store item old item synchronized this old item stored data get element key stored data push element key element if old item null old item close cached data old item space used if logminor logger minor this dropping old store element from archive cache old item archivestorecontext adderrorelement archivestorecontext errorarchivestoreitem errorarchivestoreitem archivestoreitem olditem olditem storeddata storeddata olditem olditem cacheddata olditem spaceused olditem add a store element param callback name if set the name of the file for which we must call the callback if this file happens to match param got element flag indicating whether we ve already found the file for the callback if so we must not call it again param callback callback to be called if we do find it we must get reader bucket before adding the data to the lru otherwise it may be deleted before it reaches the client throws archive failure exception if a failure occurred resulting in the data not being readable only happens if callback null private archive store item add store element archive store context ctx freeneturi key string name bucket temp mutable boolean got element string callback name archive extract callback callback object container container client context context throws archive failure exception real archive store item element new real archive store item ctx key name temp if logminor logger minor this adding store element element key name size element space used archive store item old item let it throw if it does something is drastically wrong bucket match bucket null if got element value name equals callback name match bucket element get reader bucket synchronized this old item stored data get element key stored data push element key element cached data element space used if old item null cached data old item space used if logminor logger minor this dropping old store element from archive cache old item old item close if match bucket null callback got bucket match bucket container context got element value true return element callbackname gotelement getreaderbucket archivefailureexception archivestoreitem addstoreelement archivestorecontext mutableboolean gotelement callbackname archiveextractcallback objectcontainer clientcontext archivefailureexception realarchivestoreitem realarchivestoreitem spaceused archivestoreitem olditem matchbucket gotelement callbackname matchbucket getreaderbucket olditem storeddata storeddata cacheddata spaceused olditem cacheddata olditem spaceused olditem olditem matchbucket gotbucket matchbucket gotelement drop any stored data beyond the limit call synchronized on stored data private void trim stored data synchronized this while true archive store item item if cached data max cached data stored data size max cached elements return if stored data is empty race condition cached data out of sync logger error this stored data is empty but still over limit cached data cached data max cached data return item stored data pop value long space item space used cached data space hard limits delete file within lock soft limits delete outside of lock here we use a hard limit if logminor logger minor this dropping item cached data cached data of max cached data stored items stored data size of max cached elements item close storeddata trimstoreddata archivestoreitem cacheddata maxcacheddata storeddata maxcachedelements storeddata isempty cacheddata storeddata cacheddata cacheddata maxcacheddata storeddata popvalue spaceused cacheddata cacheddata cacheddata maxcacheddata storeddata maxcachedelements public static void init object container container client context context final long nodedb handle archive handler impl init container context nodedb handle objectcontainer clientcontext nodedbhandle archivehandlerimpl nodedbhandle public boolean object can new object container container logger error this not storing archive manager in database new exception error return false objectcannew objectcontainer archivemanager static logger register log threshold callback new log threshold callback override public void should update logminor logger should log logger minor this registerlogthresholdcallback logthresholdcallback shouldupdate shouldlog thread current public int get priority return priority getpriority public void run long last dumped system current time millis synchronized jobs if current null if current is alive logger error this already running a thread for this new exception error return current thread current thread try while true runnable job null synchronized jobs job check queue if job null waiting true try nb notify only on adding work or this quits early jobs wait newjob timeout catch interrupted exception e ignore waiting false job check queue if job null running false return try if logminor logger minor this running job job long start system current time millis job run long end system current time millis if logminor logger minor this job job took end start ms synchronized time by job classes string name job to string if name index of 0 name name substring 0 name index of long l time by job classes get name if l null l long value of l long value end start else l long value of end start time by job classes put name l if logminor logger minor this total for class name l if system current time millis last dumped 60 1000 iterator i time by job classes entry set iterator while i has next map entry e map entry i next logger minor this class e get key total time e get value last dumped system current time millis catch throwable t logger error this caught t t logger error this while running job on this finally synchronized jobs current null running false lastdumped currenttimemillis isalive currentthread checkqueue newjob_timeout interruptedexception checkqueue currenttimemillis currenttimemillis timebyjobclasses tostring indexof indexof timebyjobclasses valueof longvalue valueof timebyjobclasses currenttimemillis lastdumped timebyjobclasses entryset hasnext getkey getvalue lastdumped currenttimemillis private runnable check queue if invert order for int i 0 i jobs length i if jobs i is empty if logminor logger minor this chosen job at priority i return jobs i remove first else for int i jobs length 1 i 0 i if jobs i is empty if logminor logger minor this chosen job at priority i return jobs i remove first return null checkqueue invertorder isempty removefirst isempty removefirst param priority param internal priority count param default priority param invert order set if the priorities are thread priorities unset if they are request priorities d oh public prioritized serial executor int priority int internal priority count int default priority boolean invert order jobs new linked list internal priority count for int i 0 i jobs length i jobs i new linked list runnable this priority priority this default priority default priority this invert order invert order internalprioritycount defaultpriority invertorder prioritizedserialexecutor internalprioritycount defaultpriority invertorder linkedlist internalprioritycount linkedlist defaultpriority defaultpriority invertorder invertorder public void start executor real executor string name this real executor real executor this name name synchronized jobs boolean empty true for int i 0 i jobs length i if jobs i is empty empty false break if empty really start realexecutor realexecutor realexecutor isempty reallystart private void really start synchronized jobs if running logger error this not really start ing already running new exception error return running true if logminor logger minor this starting thread name runner new exception debug real executor execute runner name reallystart reallystart realexecutor public void execute runnable job string job name int prio default priority if job instanceof prio runnable prio prio runnable job get priority execute job prio job name jobname defaultpriority priorunnable priorunnable getpriority jobname public void execute runnable job int prio string job name synchronized jobs if logminor logger minor this running job name job priority prio running running waiting waiting jobs prio add last job jobs notify all if running real executor null really start jobname jobname addlast notifyall realexecutor reallystart public void execute no dupes runnable job int prio string job name synchronized jobs if logminor logger minor this running job name job priority prio running running waiting waiting if jobs prio contains job if logminor logger minor this not adding duplicate job job return jobs prio add last job jobs notify all if running real executor null really start executenodupes jobname jobname addlast notifyall realexecutor reallystart public void execute runnable job string job name boolean from ticker execute job job name jobname fromticker jobname public int running threads int retval new int native thread java priority range 1 if running retval priority 1 return retval runningthreads nativethread java_priority_range public int waiting threads int retval new int native thread java priority range 1 synchronized jobs if waiting retval priority 1 return retval waitingthreads nativethread java_priority_range public boolean on thread thread running thread current thread synchronized jobs if runner null return false return runner current running onthread currentthread public int queued jobs int retval new int jobs length synchronized jobs for int i 0 i retval length i retval i jobs i size return retval queuedjobs public int get queue size int priority synchronized jobs return jobs priority size getqueuesize public int get waiting threads count synchronized jobs return waiting 1 0 getwaitingthreadscount private clientssk clientssk key this crypto algorithm key crypto algorithm this doc name new string key doc name if key pub key null this pub key key pub key clone key else this pub key null pub key hash new byte key pub key hash length system arraycopy key pub key hash 0 pub key hash 0 pub key hash length crypto key new byte key crypto key length system arraycopy key crypto key 0 crypto key 0 key crypto key length eh docname new byte key eh docname length system arraycopy key eh docname 0 eh docname 0 key eh docname length hash code fields hash code pub key hash fields hash code crypto key fields hash code eh docname doc name hash code cryptoalgorithm cryptoalgorithm docname docname pubkey pubkey pubkey clonekey pubkey pubkeyhash pubkeyhash pubkeyhash pubkeyhash pubkeyhash cryptokey cryptokey cryptokey cryptokey cryptokey ehdocname ehdocname ehdocname ehdocname ehdocname hashcode hashcode pubkeyhash hashcode cryptokey hashcode ehdocname docname hashcode public clientssk string doc name byte pub key hash byte extras dsa public key pub key byte crypto key throws malformedurl exception this doc name doc name this pub key pub key this pub key hash pub key hash if extras null throw new malformedurl exception no extra bytes in ssk maybe a 0 5 key if extras length 5 throw new malformedurl exception extra bytes too short extras length bytes this crypto algorithm extras 2 if crypto algorithm key algo aes pcfb 256 sha256 throw new malformedurl exception unknown encryption algorithm crypto algorithm if arrays equals extras get extra bytes throw new malformedurl exception wrong extra bytes if pub key hash length nodessk pubkey hash size throw new malformedurl exception pubkey hash wrong length pub key hash length should be nodessk pubkey hash size if crypto key length crypto key length throw new malformedurl exception decryption key wrong length crypto key length should be crypto key length message digest md sha256 get message digest try if pub key null byte pub key as bytes pub key as bytes md update pub key as bytes byte other pub key hash md digest if arrays equals other pub key hash pub key hash throw new illegal argument exception this crypto key crypto key try md update doc name get bytes utf 8 catch unsupported encoding exception e throw new error impossible jvm doesn t support utf 8 e e byte buf md digest try rijndael aes new rijndael 256 256 aes initialize crypto key aes encipher buf buf eh docname buf catch unsupported cipher exception e throw new error e finally sha256 return message digest md if eh docname null throw new null pointer exception hash code fields hash code pub key hash fields hash code crypto key fields hash code eh docname doc name hash code docname pubkeyhash dsapublickey pubkey cryptokey malformedurlexception docname docname pubkey pubkey pubkeyhash pubkeyhash malformedurlexception malformedurlexception cryptoalgorithm cryptoalgorithm algo_aes_pcfb_256_sha256 malformedurlexception cryptoalgorithm getextrabytes malformedurlexception pubkeyhash pubkey_hash_size malformedurlexception pubkeyhash pubkey_hash_size cryptokey crypto_key_length malformedurlexception cryptokey crypto_key_length messagedigest getmessagedigest pubkey pubkeyasbytes pubkey asbytes pubkeyasbytes otherpubkeyhash otherpubkeyhash pubkeyhash illegalargumentexception cryptokey cryptokey docname getbytes unsupportedencodingexception cryptokey ehdocname unsupportedcipherexception returnmessagedigest ehdocname nullpointerexception hashcode hashcode pubkeyhash hashcode cryptokey hashcode ehdocname docname hashcode public clientssk freeneturi origuri throws malformedurl exception this origuri get doc name origuri get routing key origuri get extra null origuri get crypto key if origuri get key type equals ignore case ssk throw new malformedurl exception malformedurlexception getdocname getroutingkey getextra getcryptokey getkeytype equalsignorecase malformedurlexception public void set public key dsa public key pub key if this pub key null this pub key pub key this pub key equals pub key throw new illegal argument exception cannot reassign was this pub key now pub key byte new key hash pub key as bytes hash if arrays equals new key hash pub key hash throw new illegal argument exception new pub key hash does not match pub key hash hex util bytes to hex new key hash hex util bytes to hex pub key as bytes hash hex util bytes to hex pub key hash for pub key this pub key pub key setpublickey dsapublickey pubkey pubkey pubkey pubkey pubkey pubkey illegalargumentexception pubkey pubkey newkeyhash pubkey asbyteshash newkeyhash pubkeyhash illegalargumentexception pubkey pubkeyhash hexutil bytestohex newkeyhash hexutil bytestohex pubkey asbyteshash hexutil bytestohex pubkeyhash pubkey pubkey pubkey override public freeneturi geturi return new freeneturi ssk doc name pub key hash crypto key get extra bytes docname pubkeyhash cryptokey getextrabytes protected final byte get extra bytes return get extra bytes crypto algorithm getextrabytes getextrabytes cryptoalgorithm protected static byte get extra bytes byte crypto algorithm 5 bytes byte extra new byte 5 extra 0 nodessk ssk version extra 1 0 0 fetch public uri 1 insert private uri extra 2 crypto algorithm extra 3 byte key block hash sha256 8 extra 4 byte key block hash sha256 return extra getextrabytes cryptoalgorithm ssk_version cryptoalgorithm keyblock hash_sha256 keyblock hash_sha256 override public key get node key try if eh docname null throw new null pointer exception if pub key hash null throw new null pointer exception return new nodessk pub key hash eh docname pub key crypto algorithm catch ssk verify exception e illegal state exception x new illegal state exception have already verified and yet it fails e logger error this have already verified and yet it fails e x init cause e throw x getnodekey ehdocname nullpointerexception pubkeyhash nullpointerexception pubkeyhash ehdocname pubkey cryptoalgorithm sskverifyexception illegalstateexception illegalstateexception initcause public dsa public key get pub key return pub key dsapublickey getpubkey pubkey override public string to string return clientssk geturi to string tostring tostring override public client key clone key return new clientssk this clientkey clonekey override public void remove from object container container container delete this removefrom objectcontainer override public int hash code return hash code hashcode hashcode override public boolean equals object o if o instanceof clientssk return false clientssk key clientssk o if crypto algorithm key crypto algorithm return false if doc name equals key doc name return false if arrays equals pub key hash key pub key hash return false if arrays equals crypto key key crypto key return false if arrays equals eh docname key eh docname return false return true cryptoalgorithm cryptoalgorithm docname docname pubkeyhash pubkeyhash cryptokey cryptokey ehdocname ehdocname public static bucket create simple field set fs random source random persistent file tracker f throws cannot create from field set exception if fs null if logger should log logger minor serializable to field set bucket util class logger minor serializable to field set bucket util class fs null new exception debug return null string type fs get type if logger should log logger minor serializable to field set bucket util class logger minor serializable to field set bucket util class creating type if type null throw new cannot create from field set exception no type else if type equals file bucket return base file bucket create fs f else if type equals padded ephemerally encrypted bucket return new padded ephemerally encrypted bucket fs random f else if type equals null bucket return new null bucket else if type equals read only file slice bucket return new read only file slice bucket fs else if type equals delayed free bucket return new delayed free bucket fs random f else if type equals persistent temp file bucket return persistent temp file bucket create fs f else throw new cannot create from field set exception unrecognized type type simplefieldset randomsource persistentfiletracker cannotcreatefromfieldsetexception shouldlog serializabletofieldsetbucketutil serializabletofieldsetbucketutil shouldlog serializabletofieldsetbucketutil serializabletofieldsetbucketutil cannotcreatefromfieldsetexception filebucket basefilebucket paddedephemerallyencryptedbucket paddedephemerallyencryptedbucket nullbucket nullbucket readonlyfileslicebucket readonlyfileslicebucket delayedfreebucket delayedfreebucket persistenttempfilebucket persistenttempfilebucket cannotcreatefromfieldsetexception private static final long serial versionuid 1 public duplicate score exception string message super message serialversionuid duplicatescoreexception constructors private node starter nodestarter public node starter get return this nodestarter the start method is called when the wrapper manager is signaled by the native wrapper code that it can start its application this method call is expected to return so a new thread should be launched if necessary param args list of arguments used to initialize the application return any error code if the application should exit on completion of the start method if there were no problems then this method should return null public integer start string args if args length 1 system out println usage java freenet node node config file return integer value of 1 get ext build file config filename if args length 0 system out println using default config filename freenet ini config filename new file freenet ini else config filename new file args 0 set java s dns cache not to cache forever since many people use dyndns hostnames java security security set property networkaddress cache ttl 0 java security security set property networkaddress cache negative ttl 0 try cfg freenet file persistent config construct freenet file persistent config config filename catch io exception e system out println error e e print stack trace return integer value of 1 first set up logging it is global and may be shared between several nodes sub config logging config new sub config logger cfg pooled executor executor new pooled executor try log config handler new logging config handler logging config executor catch invalid config value exception e system err println error could not set up logging e get message e print stack trace return integer value of 2 executor start prevent timeouts for a while the diffie hellman init for example could take some time on a very slow system wrapper manager signal starting 500000 thread to keep the node up jvm deadlocks losing a lock when two threads of different types daemon app are contended for the same lock so make usm daemon and use useless to keep the jvm up http forum java sun com thread jspa threadid 343023 messageid 2942637 last message runnable useless new runnable public void run while true try thread sleep 60 60 1000 catch interrupted exception e ignore catch throwable t try logger error this caught t t catch throwable t1 ignore native thread plug new native thread useless plug native thread max priority false not daemon but doesn t do anything keeps the jvm alive do not do anything in the plug thread if you do you risk the eviljvm bug plug set daemon false plug start initialize ssl sub config ssl config new sub config ssl cfg ssl init ssl config try node new node cfg null null log config handler this executor node start false system out println node initialization completed catch node init exception e system err println failed to load node e get message e print stack trace system exit e exit code return null wrappermanager configfile valueof getextbuild configfilename configfilename configfilename setproperty setproperty freenetfilepersistentconfig constructfreenetfilepersistentconfig configfilename ioexception printstacktrace valueof subconfig loggingconfig subconfig pooledexecutor pooledexecutor logconfighandler loggingconfighandler loggingconfig invalidconfigvalueexception getmessage printstacktrace valueof diffiehellman wrappermanager signalstarting interruptedexception nativethread nativethread nativethread max_priority eviljvmbug setdaemon subconfig sslconfig subconfig sslconfig logconfighandler nodeinitexception getmessage printstacktrace exitcode public void run while true try thread sleep 60 60 1000 catch interrupted exception e ignore catch throwable t try logger error this caught t t catch throwable t1 ignore interruptedexception private void get ext build try ext build number ext version build number ext revision number ext version cvs revision string built with message freenet jar built with freenet ext jar build ext build number r ext revision number logger normal this built with message system out println built with message ext build number ext version build number if ext build number 42 ext build number ext version ext build number ext revision number ext version ext revision number if ext build number 0 string build message ext build number is 0 perhaps your freenet ext jar file is corrupted logger error this build message system err println build message ext build number 1 if ext revision number null string revision message ext revision number is null perhaps your freenet ext jar file is corrupted logger error this revision message system err println revision message ext revision number invalid catch throwable t compatibility code will be removed logger error this unable to get the version of your freenet ext file it s probably corrupted system err println unable to get the version of your freenet ext file it s probably corrupted system err println t get message ext revision number invalid ext build number 1 getextbuild extbuildnumber extversion buildnumber extrevisionnumber extversion cvsrevision builtwithmessage extbuildnumber extrevisionnumber builtwithmessage builtwithmessage extbuildnumber extversion buildnumber extbuildnumber extbuildnumber extversion extbuildnumber extrevisionnumber extversion extrevisionnumber extbuildnumber buildmessage extbuildnumber buildmessage buildmessage extbuildnumber extrevisionnumber revisionmessage extrevisionnumber revisionmessage revisionmessage extrevisionnumber getmessage extrevisionnumber extbuildnumber called when the application is shutting down the wrapper assumes that this method will return fairly quickly if the shutdown code code could potentially take a long time then wrapper manager signal stopping should be called to extend the timeout period if for some reason the stop method can not return then it must call wrapper manager stopped to avoid warning messages from the wrapper param exit code the suggested exit code that will be returned to the os when the jvm exits return the exit code to actually return to the os in most cases this should just be the value of exit code however the user code has the option of changing the exit code if there are any problems during shutdown public int stop int exit code system err println shutting down with exit code exit code node park see 354 wrapper manager signal stopping 120000 return exit code wrappermanager signalstopping wrappermanager exitcode exitcode exitcode exitcode wrappermanager signalstopping exitcode public void restart wrapper manager restart wrappermanager called whenever the native wrapper code traps a system control signal against the java process it is up to the callback to take any actions necessary possible values are wrapper manager wrapper ctrl c event wrapper ctrl close event wrapper ctrl logoff event or wrapper ctrl shutdown event param event the system control signal public void control event int event if wrapper manager is controlled by native wrapper the wrapper will take care of this event else we are not being controlled by the wrapper so handle the event ourselves if event wrapper manager wrapper ctrl c event event wrapper manager wrapper ctrl close event event wrapper manager wrapper ctrl shutdown event wrapper manager stop 0 wrappermanager wrapper_ctrl_c_event wrapper_ctrl_close_event wrapper_ctrl_logoff_event wrapper_ctrl_shutdown_event controlevent wrappermanager iscontrolledbynativewrapper wrappermanager wrapper_ctrl_c_event wrappermanager wrapper_ctrl_close_event wrappermanager wrapper_ctrl_shutdown_event wrappermanager public static void main string args start the application if the jvm was launched from the native wrapper then the application will wait for the native wrapper to call the application s start method otherwise the start method will be called immediately wrapper manager start new node starter args wrappermanager nodestarter vm specific init not node specific many nodes may be created later param test name the name of the test instance public static random source global test init string test name boolean enable plug int log threshold string details boolean nodns throws invalid threshold exception file dir new file test name if dir mkdir dir exists dir is directory system err println cannot create directory for test system exit node init exception exit test error logger setup stdout logging log threshold details set java s dns cache not to cache forever since many people use dyndns hostnames java security security set property networkaddress cache ttl 0 java security security set property networkaddress cache negative ttl 0 setup rng random source random new yarrow diffie hellman init random if enable plug thread to keep the node up jvm deadlocks losing a lock when two threads of different types daemon app are contended for the same lock so make usm daemon and use useless to keep the jvm up http forum java sun com thread jspa threadid 343023 messageid 2942637 last message runnable useless new runnable public void run while true try thread sleep 60 60 1000 catch interrupted exception e ignore catch throwable t try logger error this caught t t catch throwable t1 ignore thread plug new thread useless plug not daemon but doesn t do anything keeps the jvm alive do not do anything in the plug thread if you do you risk the eviljvm bug plug set daemon false plug start fnp packet mangler log unmatchable error true dns requester disable nodns return random testname randomsource globaltestinit testname enableplug logthreshold invalidthresholdexception testname isdirectory nodeinitexception exit_test_error setupstdoutlogging logthreshold setproperty setproperty randomsource diffiehellman enableplug interruptedexception eviljvmbug setdaemon fnppacketmangler log_unmatchable_error dnsrequester public void run while true try thread sleep 60 60 1000 catch interrupted exception e ignore catch throwable t try logger error this caught t t catch throwable t1 ignore interruptedexception create a test node param port the node port number each test node must have a different port number param test name the test name param do client boot up the client layer param do swapping allow swapping throws node init exception if the node cannot start up for some reason most likely a config problem public static node create test node int port int opennet port string test name boolean do client boolean do swapping boolean disable probabilisticht ls short maxhtl int drop prob random source random executor executor int thread limit long store size boolean ram store boolean enable swapping boolean enablear ks boolean enableulp rs boolean enable per node failure tables boolean enable swap queueing boolean enable packet coalescing int output bandwidth limit boolean enablefoaf boolean connect to seednodes string ip address override throws node init exception file base dir new file test name file port dir new file base dir integer to string port if port dir mkdir port dir exists port dir is directory system err println cannot create directory for test system exit node init exception exit test error set up config for testing simple field set configfs new simple field set false only happens once in entire simulation if output bandwidth limit 0 configfs put node output bandwidth limit output bandwidth limit configfs put node throttle local traffic true else even with throttle local traffic false requests still count in node stats so set output bandwidth limit to something insanely high configfs put node output bandwidth limit 16 1024 1024 configfs put node throttle local traffic false configfs put node listen port port configfs put node disable probabilisticht ls disable probabilisticht ls configfs put fproxy enabled false configfs put fcp enabled false configfs put console enabled false configfs put single pluginmanager loadplugin configfs put node updater enabled false configfs put single node temp dir new file port dir temp to string configfs put single node store dir new file port dir store to string configfs put fcp persistent downloads enabled false configfs put single node throttle file new file port dir throttle dat to string configfs put single node node dir port dir to string configfs put node maxhtl maxhtl configfs put node testing drop packets every drop prob configfs put node always allow local addresses true configfs put node include local addresses in noderefs true configfs put node enablear ks false configfs put node load thread limit thread limit if ram store configfs put single node store type ram configfs put store size store size configfs put node disable hang checkers true configfs put node enable swapping enable swapping configfs put node enable swap queueing enable swap queueing configfs put node enablear ks enablear ks configfs put node enableulpr data propagation enableulp rs configfs put node enable per node failure tables enable per node failure tables configfs put node enable packet coalescing enable packet coalescing configfs put node publish our peers location enablefoaf configfs put node route according to our peers location enablefoaf configfs put node opennet enabled opennet port 0 configfs put node opennet listen port opennet port configfs put node opennet always allow local addresses true configfs put node opennet one connection perip false configfs put node opennet assumena ted true configfs put node opennet connect to seednodes connect to seednodes configfs put node encrypt temp buckets false configfs put node encrypt persistent temp buckets false if ip address override null configfs put single node ip address override ip address override persistent config config new persistent config configfs node node new node config random random null null executor all testing environments connect the nodes as they want even if the old setup is restored it is not desired node peers remove all peers return node testname doclient doswapping nodeinitexception createtestnode opennetport testname doclient doswapping disableprobabilistichtls dropprob randomsource threadlimit storesize ramstore enableswapping enablearks enableulprs enablepernodefailuretables enableswapqueueing enablepacketcoalescing outputbandwidthlimit connecttoseednodes ipaddressoverride nodeinitexception basedir testname portdir basedir tostring portdir portdir portdir isdirectory nodeinitexception exit_test_error simplefieldset simplefieldset outputbandwidthlimit outputbandwidthlimit outputbandwidthlimit throttlelocaltraffic throttlelocaltraffic nodestats outputbandwidthlimit outputbandwidthlimit throttlelocaltraffic listenport disableprobabilistichtls disableprobabilistichtls putsingle putsingle tempdir portdir tostring putsingle storedir portdir tostring persistentdownloadsenabled putsingle throttlefile portdir tostring putsingle nodedir portdir tostring testingdroppacketsevery dropprob alwaysallowlocaladdresses includelocaladdressesinnoderefs enablearks threadlimit threadlimit ramstore putsingle storetype storesize storesize disablehangcheckers enableswapping enableswapping enableswapqueueing enableswapqueueing enablearks enablearks enableulprdatapropagation enableulprs enablepernodefailuretables enablepernodefailuretables enablepacketcoalescing enablepacketcoalescing publishourpeerslocation routeaccordingtoourpeerslocation opennetport listenport opennetport alwaysallowlocaladdresses oneconnectionperip assumenated connecttoseednodes connecttoseednodes encrypttempbuckets encryptpersistenttempbuckets ipaddressoverride putsingle ipaddressoverride ipaddressoverride persistentconfig persistentconfig removeallpeers construct a default box blur filter public box blur filter boxblurfilter boxblurfilter construct a box blur filter param h radius the horizontal radius of blur param v radius the vertical radius of blur param iterations the number of time to iterate the blur public box blur filter float h radius float v radius int iterations this h radius h radius this v radius v radius this iterations iterations boxblurfilter hradius vradius boxblurfilter hradius vradius hradius hradius vradius vradius set whether to premultiply the alpha channel param premultiply alpha true to premultiply the alpha see get premultiply alpha public void set premultiply alpha boolean premultiply alpha this premultiply alpha premultiply alpha premultiplyalpha getpremultiplyalpha setpremultiplyalpha premultiplyalpha premultiplyalpha premultiplyalpha get whether to premultiply the alpha channel return true to premultiply the alpha see set premultiply alpha public boolean get premultiply alpha return premultiply alpha setpremultiplyalpha getpremultiplyalpha premultiplyalpha public buffered image filter buffered image src buffered image dst int width src get width int height src get height if dst null dst create compatible dest image src null int in pixels new int width height int out pixels new int width height getrgb src 0 0 width height in pixels if premultiply alpha image math premultiply in pixels 0 in pixels length for int i 0 i iterations i blur in pixels out pixels width height h radius blur out pixels in pixels height width v radius blur fractional in pixels out pixels width height h radius blur fractional out pixels in pixels height width v radius if premultiply alpha image math unpremultiply in pixels 0 in pixels length setrgb dst 0 0 width height in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight createcompatibledestimage inpixels outpixels inpixels premultiplyalpha imagemath inpixels inpixels inpixels outpixels hradius outpixels inpixels vradius blurfractional inpixels outpixels hradius blurfractional outpixels inpixels vradius premultiplyalpha imagemath inpixels inpixels inpixels blur and transpose a block of argb pixels param in the input pixels param out the output pixels param width the width of the pixel array param height the height of the pixel array param radius the radius of blur public static void blur int in int out int width int height float radius int width minus1 width 1 int r int radius int table size 2 r 1 int divide new int 256 table size for int i 0 i 256 table size i divide i i table size int in index 0 for int y 0 y height y int out index y int ta 0 tr 0 tg 0 tb 0 for int i r i r i int rgb in in index image math clamp i 0 width 1 ta rgb 24 0xff tr rgb 16 0xff tg rgb 8 0xff tb rgb 0xff for int x 0 x width x out out index divide ta 24 divide tr 16 divide tg 8 divide tb int i1 x r 1 if i1 width minus1 i1 width minus1 int i2 x r if i2 0 i2 0 int rgb1 in in index i1 int rgb2 in in index i2 ta rgb1 24 0xff rgb2 24 0xff tr rgb1 0xff0000 rgb2 0xff0000 16 tg rgb1 0xff00 rgb2 0xff00 8 tb rgb1 0xff rgb2 0xff out index height in index width widthminus1 tablesize tablesize tablesize tablesize inindex outindex inindex imagemath outindex widthminus1 widthminus1 inindex inindex outindex inindex public static void blur fractional int in int out int width int height float radius radius int radius float f 1 0f 1 2 radius int in index 0 for int y 0 y height y int out index y out out index in 0 out index height for int x 1 x width 1 x int i in index x int rgb1 in i 1 int rgb2 in i int rgb3 in i 1 int a1 rgb1 24 0xff int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int a2 rgb2 24 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff int a3 rgb3 24 0xff int r3 rgb3 16 0xff int g3 rgb3 8 0xff int b3 rgb3 0xff a1 a2 int a1 a3 radius r1 r2 int r1 r3 radius g1 g2 int g1 g3 radius b1 b2 int b1 b3 radius a1 f r1 f g1 f b1 f out out index a1 24 r1 16 g1 8 b1 out index height out out index in width 1 in index width blurfractional inindex outindex outindex outindex inindex outindex outindex outindex inindex set the horizontal size of the blur param h radius the radius of the blur in the horizontal direction min value 0 see geth radius public void seth radius float h radius this h radius h radius hradius gethradius sethradius hradius hradius hradius get the horizontal size of the blur return the radius of the blur in the horizontal direction see seth radius public float geth radius return h radius sethradius gethradius hradius set the vertical size of the blur param v radius the radius of the blur in the vertical direction min value 0 see getv radius public void setv radius float v radius this v radius v radius vradius getvradius setvradius vradius vradius vradius get the vertical size of the blur return the radius of the blur in the vertical direction see setv radius public float getv radius return v radius setvradius getvradius vradius set both the horizontal and vertical sizes of the blur param radius the radius of the blur in both directions min value 0 see get radius public void set radius float radius this h radius this v radius radius getradius setradius hradius vradius get the size of the blur return the radius of the blur in the horizontal direction see set radius public float get radius return h radius setradius getradius hradius set the number of iterations the blur is performed param iterations the number of iterations min value 0 see get iterations public void set iterations int iterations this iterations iterations getiterations setiterations get the number of iterations the blur is performed return the number of iterations see set iterations public int get iterations return iterations setiterations getiterations override public string to string return blur box blur tostring public class resend packet item public resend packet item byte payload int packet number packet tracker k async message callback callbacks short priority pn k pn kt k buf payload this packet number packet number this callbacks callbacks this priority priority resendpacketitem resendpacketitem packetnumber packettracker asyncmessagecallback packetnumber packetnumber private buffered image clean image public key filter bufferedimage cleanimage keyfilter set the hue tolerance of the image in the range 0 1 param h tolerance the tolerance see geth tolerance public void seth tolerance float h tolerance this h tolerance h tolerance htolerance gethtolerance sethtolerance htolerance htolerance htolerance get the hue tolerance return the tolerance see seth tolerance public float geth tolerance return h tolerance sethtolerance gethtolerance htolerance set the saturation tolerance of the image in the range 0 1 param s tolerance the tolerance see gets tolerance public void sets tolerance float s tolerance this s tolerance s tolerance stolerance getstolerance setstolerance stolerance stolerance stolerance get the saturation tolerance return the tolerance see sets tolerance public float gets tolerance return s tolerance setstolerance getstolerance stolerance set the brightness tolerance of the image in the range 0 1 param b tolerance the tolerance see getb tolerance public void setb tolerance float b tolerance this b tolerance b tolerance btolerance getbtolerance setbtolerance btolerance btolerance btolerance get the brightness tolerance return the tolerance see setb tolerance public float getb tolerance return b tolerance setbtolerance getbtolerance btolerance set the destination image param destination the destination image see get destination public void set destination buffered image destination this destination destination getdestination setdestination bufferedimage get the destination image return the destination image see set destination public buffered image get destination return destination setdestination bufferedimage getdestination get the clean image param clean image the clean image see get clean image public void set clean image buffered image clean image this clean image clean image cleanimage getcleanimage setcleanimage bufferedimage cleanimage cleanimage cleanimage get the clean image return the clean image see set clean image public buffered image get clean image return clean image setcleanimage bufferedimage getcleanimage cleanimage public buffered image filter buffered image src buffered image dst int width src get width int height src get height int type src get type writable raster src raster src get raster if dst null dst create compatible dest image src null writable raster dst raster dst get raster if destination null clean image null float hsb1 null float hsb2 null int in pixels null int out pixels null int clean pixels null for int y 0 y height y in pixels getrgb src 0 y width 1 in pixels out pixels getrgb destination 0 y width 1 out pixels clean pixels getrgb clean image 0 y width 1 clean pixels for int x 0 x width x int rgb1 in pixels x int out out pixels x int rgb2 clean pixels x int r1 rgb1 16 0xff int g1 rgb1 8 0xff int b1 rgb1 0xff int r2 rgb2 16 0xff int g2 rgb2 8 0xff int b2 rgb2 0xff hsb1 color rg btohsb r1 b1 g1 hsb1 hsb2 color rg btohsb r2 b2 g2 hsb2 int tolerance int 255 tolerance return math abs r1 r2 tolerance math abs g1 g2 tolerance math abs b1 b2 tolerance if pixel utils near colors in clean int 255 tolerance if math abs hsb1 0 hsb2 0 h tolerance math abs hsb1 1 hsb2 1 s tolerance math abs hsb1 2 hsb2 2 b tolerance in pixels x out else in pixels x rgb1 setrgb dst 0 y width 1 in pixels return dst bufferedimage bufferedimage bufferedimage getwidth getheight gettype writableraster srcraster getraster createcompatibledestimage writableraster dstraster getraster cleanimage inpixels outpixels cleanpixels inpixels inpixels outpixels outpixels cleanpixels cleanimage cleanpixels inpixels outpixels cleanpixels rgbtohsb rgbtohsb pixelutils nearcolors htolerance stolerance btolerance inpixels inpixels inpixels override public string to string return keying key tostring interface web page public abstract void process post request http request request html node content node webpage processpostrequest httprequest htmlnode contentnode public abstract void process post request http request request html node content node public abstract void write content http request request html node content node processpostrequest httprequest htmlnode contentnode writecontent httprequest htmlnode contentnode public interface oid hash table boolean remove int oid oidhashtable public interface oid hash table boolean remove int oid void put int oid i persistent obj oidhashtable ipersistent boolean remove int oid void put int oid i persistent obj i persistent get int oid ipersistent ipersistent void put int oid i persistent obj i persistent get int oid void flush ipersistent ipersistent i persistent get int oid void flush void invalidate ipersistent void flush void invalidate void clear void invalidate void clear int size void clear int size void set dirty i persistent obj setdirty ipersistent int size void set dirty i persistent obj void clear dirty i persistent obj setdirty ipersistent cleardirty ipersistent public interface load factory object create class descriptor desc loadfactory classdescriptor public interface reflection provider constructor get default constructor class cls throws exception reflectionprovider getdefaultconstructor constructor get default constructor class cls throws exception void set int field field object object int value throws exception getdefaultconstructor setint void set int field field object object int value throws exception void set long field field object object long value throws exception setint setlong void set long field field object object long value throws exception void set short field field object object short value throws exception setlong setshort void set short field field object object short value throws exception void set char field field object object char value throws exception setshort setchar void set char field field object object char value throws exception void set byte field field object object byte value throws exception setchar setbyte void set byte field field object object byte value throws exception void set float field field object object float value throws exception setbyte setfloat void set float field field object object float value throws exception void set double field field object object double value throws exception setfloat setdouble void set double field field object object double value throws exception void set boolean field field object object boolean value throws exception setdouble setboolean void set boolean field field object object boolean value throws exception void set field field object object object value throws exception setboolean public interface fast serializable int pack byte buffer buf int offs string encoding fastserializable bytebuffer public interface fast serializable int pack byte buffer buf int offs string encoding int unpack byte buf int offs string encoding fastserializable bytebuffer public interface generic sort array int size genericsortarray public interface generic sort array int size int compare int i int j genericsortarray int size int compare int i int j void swap int i int j public interface full text searchable extends i persistent get document text reader get text fulltextsearchable ipersistent gettext reader get text get document language null if unknown string get language gettext getlanguage add document to the index param obj document to be added add document to the index param obj document to be added param text document text to be indexed param language language of the text delete document from the index param obj document to be deleted parse and execute full text search query param query text of the query param language language if the query param max results maximal amount of selected documents param time limit limit for query execution time return result of query execution ordered by rank or null in case of empty or incorrect query maxresults timelimit execute full text search query param query prepared query param max results maximal amount of selected documents param time limit limit for query execution time return result of query execution ordered by rank or null in case of empty or incorrect query maxresults timelimit full text search result search full text query query int max results int time limit get total number of different words in all documents int get number of words fulltextsearchresult fulltextquery maxresults timelimit getnumberofwords int get number of words get total number of indexed documents int get number of documents getnumberofwords getnumberofdocuments int get number of documents get full text search helper full text search helper get helper getnumberofdocuments fulltextsearchhelper gethelper public interface link t extends i persistent extends i table t list t random access get number of the linked objects return the number of related objects ipersistent itable randomaccess set number of the linked objects param new size new number of linked objects if it is greater than original number than extra elements will be set to null newsize returns tt true tt if there are no related object return tt true tt if there are no related object get related object by index param i index of the object in the relation return referenced object get related object by index without loading it returned object can be used only to get it oid or to compare with other objects using code equals code method param i index of the object in the relation return stub representing referenced object replace i th element of the relation param i index in the relartion param obj object to be included in the relation return the element previously at the specified position assign value to i th element of the relation unlike link set methos this method doesn t return previous value of the element and so is faster if previous element value is not needed it has not to be fetched from the database param i index in the relartion param obj object to be included in the relation remove object with specified index from the relation unlike link remove methos this method doesn t return removed element and so is faster if it is not needed it has not to be fetched from the database param i index in the relartion remove object from the relation param o removed object return code true code if relation is changed as the result of this operation insert new object in the relation param i insert poistion should be in 0 size param obj object inserted in the relation add new object to the relation param obj object inserted in the relation add all elements of the array to the relation param arr array of obects which should be added to the relation add specified elements of the array to the relation param arr array of obects which should be added to the relation param from index of the first element in the array to be added to the relation param length number of elements in the array to be added in the relation add all object members of the other relation to this relation param link another relation return array with relation members members are not loaded and size of the array can be greater than actual number of members return array of object with relation members used in implementation of link class get relation members as array of object return array of object with relation members get all relation members as array the runtime type of the returned array is that of the specified array if the index fits in the specified array it is returned therein otherwise a new array is allocated with the runtime type of the specified array and the size of this index p if this index fits in the specified array with room to spare i e the array has more elements than this index the element in the array immediately following the end of the index is set to tt null tt this is useful in determining the length of this index i only i if the caller knows that this index does not contain any tt null tt elements p return array of object with relation members checks if relation contains specified object instance param obj specified object return code true code if object is present in the collection code false code otherwise check if there is linked object which is equal to the specified object more formally returns tt true tt if and only if this collection contains at least one element tt e tt such that tt obj null e null obj equals e tt p param obj object to be searched in the index object should contain indexed field return code true code if collection contains object equals to the specified check if i th element of link is the same as specified obj param i element index param obj object to compare with return code true code if i th element of link reference the same object as obj get index of the specified object instance in the relation this method use comparison by object identity instead of equals method and is significantly faster than list index of method param obj specified object instance return zero based index of the object or 1 if object is not in the relation indexof get index of the specified object instance in the relation this method use comparison by object identity instead of equals method and is significantly faster than list index of method param obj specified object instance return zero based index of the object or 1 if object is not in the relation indexof public int last index of object object obj remove all members from the relation public void clear lastindexofobject get iterator through link members this iterator supports remove method return iterator through linked objects replace all direct references to linked objects with stubs this method is needed tyo avoid memory exhaustion in case when there is a large numebr of objectys in databasse mutually refefencing each other each object can directly or indirectly be accessed from other objects replace references to elements with direct references it will impove spped of manipulations with links but it can cause recursive loading in memory large number of objects and as a result memory overflow because garbage collector will not be able to collect them get comparator used in this index return comparator used to compare objects in this index add new object in the index param obj object to be inserted in index return true if object was successfully added remove object from the index param obj object removed from the index return true id object was removed false if object was not found in the index get iterator for traversing all objects in the index objects are iterated in the ascent key order this iterator supports remove method return index iterator get iterator through objects matching specified pattern object all fields which are part of multidimensional index and which values in pattern object is not null are used as filter for index members param pattern object which is used as search pattern non null values of components of this object forms search condition return iterator through index members which field values are equal to correspondent non null fields of pattern object get iterator through objects which field values belongs to the range specified by correspondent fields of low and high objects param low pattern object specifying inclusive low boundary for field values if there is no low boundary for some particular field it should be set to null for scalar types like int you can use instead minimal possible value like integer min value if low is null then low boundary is not specified for all fields param high pattern object specifying inclusive high boundary for field values if there is no high boundary for some particular field it should be set to null for scalar types like int you can use instead maximal possible value like integer max value if high is null then high boundary is not specified for all fields return iterator through index members which field values are belongs to the range specified by correspondent fields of low and high objects min_value max_value get array of index members matching specified pattern object all fields which are part of multidimensional index and which values in pattern object is not null are used as filter for index members param pattern object which is used as search pattern non null values of components of this object forms search condition return array of index members which field values are equal to correspondent non null fields of pattern object get array of index members which field values belongs to the range specified by correspondent fields of low and high objects param low pattern object specifying inclusive low boundary for field values if there is no low boundary for some particular field it should be set to null for scalar types like int you can use instead minimal possible value like integer min value if low is null then low boundary is not specified for all fields param high pattern object specifying inclusive high boundary for field values if there is no high boundary for some particular field it should be set to null for scalar types like int you can use instead maximal possible value like integer max value if high is null then high boundary is not specified for all fields return array of index members which field values are belongs to the range specified by correspondent fields of low and high objects min_value max_value public array list t query by example t low t high remove all objects from the index public void clear arraylist querybyexample check if specified object belongs to the index param member which is searched in the index return true if specified object is present in the index get number of objects in the index return number of objects in the index optimize index to make search more efficient this operation cause complete reconstruction of the index and so may take a long time also please notice that this method doesn t build the ideally balanced tree it just reinserts elements in the tree in random order get height of the tree height of the tree can be used by application to determine when tree structure is no optimal and tree should be reconstructed using optimize method return height of the tree public interface query t execute query param cls class of inspected objects param iterator iterator for sequential access to objects in the table param predicate selection crieria return iterator through selected objects this iterator doesn t support remove method execute query param class name name of the class of inspected objects param iterator iterator for sequential access to objects in the table param predicate selection crieria return iterator through selected objects this iterator doesn t support remove method classname set value of query parameter param index parameters index 1 based param value value of parameter for scalar parameters instance f correspondendt wrapper class for example code java lang long code set value of query parameter param index parameters index 1 based param value value of integer parameter set value of query parameter param index parameters index 1 based param value value of real parameter set value of query parameter param index parameters index 1 based param value value of boolean parameter prepare sql statement param cls class of iterated objects param predicate selection crieria with placeholders for parameter value prepare sql statement param class name name of the class of iterated objects param predicate selection crieria with placeholders for parameter value classname execute prepared query param iterator iterator for sequential access to objects in the table return iterator through selected objects this iterator doesn t support remove method enable or disable reporting of runtime errors on console runtime errors during jsql query are reported in two ways ol li if query error reporting is enabled then message is printed to system err li li if storage listener is registered then jsql runtime error of method listener is invoked li ol by default reporting to system err is enabled param enabled if code true code then reportnig is enabled jsqlruntimeerror specify resolver resolver can be used to replaced sql joi ns given object id it will provide reference to the resolved object param original class which instances will have to be resolved param resolved class of the resolved object param resolver class implementing resolver interface joins add index which can be used to optimize query execution replace sequential search with direct index access param key indexed field param index implementation of index public interface random access stream set position in the stream param pos new absolute poistion in the strwam return actual position it can be less than specified if end of stream is reached randomaccessstream get current position in the stream return current poistion in the stream get size of the stream return number of bytes available in the stream public interface replication master storage extends storage get number of currently available slave nodes return number of online replication slaves replicationmasterstorage public interface i resource lock persistent object in shared mode other threads will be able to set their shared locks on this objects but not exclusive lock can be set until this lock is released br upgrading of the lock is not possible thread having read lock can not upgrade it to exclusive lock it is done to prevent possible deadlocks caused by lock updates but locks are reentrant so thread can request the same lock many times and correspondent number of unlocks is needed to release the lock br locking the object doesn t prevent other threads from accessing the object it only has influence on code shared lock code and code exclusive lock code methods so programmer should set proper lock before accessing the object in multithreaded application br if object is concurrently accessed by several threads in read only mode then explicit locking of this object is not needed because language api provides consistent retrieving of objects itself br only persistent object object which were assigned to the the storage either implicitly by saving some other persistent object referencing this object either explicitly by code storage make object persistent code method br iresource sharedlock exclusivelock makeobjectpersistent lock persistent object in shared mode other threads will be able to set their shared locks on this objects but not exclusive lock can be set until this lock is released br upgrading of the lock is not possible thread having read lock can not upgrade it to exclusive lock it is done to prevent possible deadlocks caused by lock updates but locks are reentrant so thread can request the same lock many times and correspondent number of unlocks is needed to release the lock br locking the object doesn t prevent other threads from accessing the object it only has influence on code shared lock code and code exclusive lock code methods so programmer should set proper lock before accessing the object in multithreaded application br if object is concurrently accessed by several threads in read only mode then explicit locking of this object is not needed because language api provides consistent retrieving of objects itself br only persistent object object which were assigned to the the storage either implicitly by saving some other persistent object referencing this object either explicitly by code storage make object persistent code method br param timeout timeout of operation in milliseconds if timeout is 0 and lock can not be granted the request will fail immediately otherwise the system will try to grant lock within specified amount of time return dl dt code true code if lock is successfully granted br dt code false code if lock can not be granted within specified time dl sharedlock exclusivelock makeobjectpersistent lock persistent object in exclusive mode only one thread can lock object in exclusive mode at each moment of time shared or exclusive lock requests of other threads will be blocked until this lock is released shared locks on this objects but not exclusive lock can be set until this lock is released br this lock is reentrant so thread owning the lock can successfully retrieve the lock many times and correspondent number of unlocks is needed to release the lock br locking the object doesn t prevent other threads from accessing the object it only has influence on code shared lock code and code exclusive lock code methods so programmer should set proper lock before accessing the object in multithreaded application br only persistent object object which were assigned to the the storage either implicitly by saving some other persistent object referencing this object either explicitly by code storage make object persistent code method sharedlock exclusivelock makeobjectpersistent lock persistent object in exclusive mode only one thread can lock object in exclusive mode at each moment of time shared or exclusive lock requests of other threads will be blocked until this lock is released shared locks on this objects but not exclusive lock can be set until this lock is released br this lock is reentrant so thread owning the lock can successfully retrieve the lock many times and correspondent number of unlocks is needed to release the lock br locking the object doesn t prevent other threads from accessing the object it only has influence on code shared lock code and code exclusive lock code methods so programmer should set proper lock before accessing the object in multithreaded application br only persistent object object which were assigned to the the storage either implicitly by saving some other persistent object referencing this object either explicitly by code storage make object persistent code method param timeout timeout of operation in milliseconds if timeout is 0 and lock can not be granted the request will fail immediately otherwise the system will try to grant lock within specified amount of time return dl dt code true code if lock is successfully granted br dt code false code if lock can not be granted within specified time dl sharedlock exclusivelock makeobjectpersistent remove granted lock if lock was requested several times by one thread then correspondent number of unlocks is needed to release the lock reset resource to original state wakrup all threads waiting for this resource public interface persistent iterator get oid of the next object return oid of the the next element in the iteration exception no such element exception iteration has no more objects persistentiterator nosuchelementexception put new object in the index param obj object to be inserted in index object should contain indexed field object can be not yet peristent in this case its forced to become persistent by assigning oid to it return code true code if object is successfully inserted in the index code false code if index was declared as unique and there is already object with such value of the key in the index associate new object with the key specified by object field value if there is already object with such key in the index then it will be removed from the index and new value associated with this key param obj object to be inserted in index object should contain indexed field object can be not yet peristent in this case its forced to become persistent by assigning oid to it return object previously associated with this key code null code if there was no such object assign to the integer indexed field unique autoicremented value and insert object in the index param obj object to be inserted in index object should contain indexed field of integer code int code or code long code type this field is assigned unique value which will not be reused while this index exists and object is marked as modified object can be not yet peristent in this case its forced to become persistent by assigning oid to it exception storage error storage error incompatible key type when indexed field has type other than code int code or code long code storageerror storageerror incompatible_key_type remove object from the index param obj object removed from the index object should contain indexed field exception storage error storage error key not found exception if there is no such key in the index storageerror storageerror key_not_found remove object with specified key from the unique index param key value of removed key return removed object exception storage error storage error key not found exception if there is no such key in the index or storage error storage error key not unique if index is not unique storageerror storageerror key_not_found storageerror storageerror key_not_unique remove object with specified key from the unique index param key value of removed key return removed object exception storage error storage error key not found exception if there is no such key in the index or storage error storage error key not unique if index is not unique storageerror storageerror key_not_found storageerror storageerror key_not_unique check if index contains specified object instance param obj object to be searched in the index object should contain indexed field return code true code if object is present in the index code false code otherwise check if index contains object which is equal to the specified object more formally returns tt true tt if and only if this collection contains at least one element tt e tt such that tt obj null e null obj equals e tt p param obj object to be searched in the index object should contain indexed field return code true code if collection contains object equals to the specified locate objects with the same value of the key as specified object param obj object specifying search key value return selection iterator get class obejct objects which can be inserted in this index return class specified in storage create fiel index method createfielindex get fields used as a key return array of index key fields select members of the collection using search predicate this iterator doesn t support remove method to make it possible to update remove or add members to the index during iteration it is necessary to set perst concurrent iterator property by default it is not supported because it cause extra overhead during iteration param predicate jsql condition return iterator through members of the collection matching search condition check if field index is case insensitive return true if index ignore case of string keys public interface replication slave storage extends storage check if socket is connected to the master host return code true code if connection between slave and master is sucessfully established replicationslavestorage wait until database is modified by master this method blocks current thread until master node commits trasanction and this transanction is completely delivered to this slave node set container object for this embedded link param obj container object get container object for this embedded link return container object open the storage param file path path to the database file param page pool size size of page pool in bytes page pool should contain at least ten 4kb pages so minimal page pool size should be at least 40 kb but larger page pool usually leads to better performance unless it could not fit in memory and cause swapping value 0 of this paremeter corresponds to infinite page pool all pages are cashed in memory it is especially useful for in memory database when storage is created with null file filepath pagepoolsize 40kb nullfile open the storage param file user specific implementation of i file interface param page pool size size of page pool in bytes page pool should contain at least ten 4kb pages so minimal page pool size should be at least 40 kb but larger page pool ussually leads to better performance unless it could not fit in memory and cause swapping ifile pagepoolsize 40kb open the storage with default page pool size param file user specific implementation of i file interface ifile open the storage with default page pool size param file path path to the database file filepath open the encrypted storage param file path path to the database file param page pool size size of page pool in bytes page pool should contain at least then 4kb pages so minimal page pool size should be at least 40 kb but larger page pool usually leads to better performance unless it could not fit in memory and cause swapping param cipher key cipher key filepath pagepoolsize 40kb cipherkey check if database is opened return code true code if database was opened by code open code method code false code otherwise get storage root storage can have exactly one root object if you need to have several root object and access them by name as is is possible in many other oodbm ses you should create index and use it as root object return root object or code null code if root is not specified storage is not yet initialized oodbmses set new storage root object previous reference to the root object is rewritten but old root is not automatically deallocated param root object to become new storage root if it is not persistent yet it is made persistent and stored in the storage commit changes done by the last transaction transaction is started implcitlely with forst update opertation public void commit rollback changes made by the last transaction public void rollback backup current state of database param out output stream to which backup is done begin per thread transaction three types of per thread transactions are supported exclusive cooperative and serializable in case of exclusive transaction only one thread can update the database in cooperative mode multiple transaction can work concurrently and commit method will be invoked only when transactions of all threads are terminated serializable transactions can also work concurrently but unlike cooperative transaction the threads are isolated from each other each thread has its own associated set of modified objects and committing the transaction will cause saving only of these objects to the database to synchronize access to the objects in case of serializable transaction programmer should use lock methods of i resource interface shared lock should be set before read access to any object and exclusive lock before write access locks will be automatically released when transaction is committed so programmer should not explicitly invoke unlock method in this case it is guaranteed that transactions are serializable br it is not possible to use code i persistent store code method in serializable transactions that is why it is also not possible to use index and field index containers since them are based on b tree and b tree directly access database pages and use code store code method to assign oid to inserted object you should use code sorted collection code based on t tree instead or alternative b tree implemenataion set perst alternative btree property param mode code exclusive transaction code code cooperative transaction code code serializable transaction code or code replication slave transaction code iresource ipersistent fieldindex sortedcollection exclusive_transaction cooperative_transaction serializable_transaction replication_slave_transaction end per thread transaction started by begin thread transaction method br if transaction is i exclusive i this method commits the transaction and allows other thread to proceed br if transaction is i serializable i this method commits sll changes done by this thread and release all locks set by this thread br if transaction is i cooperative i this method decrement counter of cooperative transactions and if it becomes zero commit the work beginthreadtransaction end per thread cooperative transaction with specified maximal delay of transaction commit when cooperative transaction is ended data is not immediately committed to the disk because other cooperative transaction can be active at this moment of time instead of it cooperative transaction counter is decremented commit is performed only when this counter reaches zero value but in case of heavy load there can be a lot of requests and so a lot of active cooperative transactions so transaction counter never reaches zero value if system crash happens a large amount of work will be lost in this case to prevent such scenario it is possible to specify maximal delay of pending transaction commit in this case when such timeout is expired new cooperative transaction will be blocked until transaction is committed param max delay maximal delay in milliseconds of committing transaction please notice that perst could not force other threads to commit their cooperative transactions when this timeout is expired it will only block new cooperative transactions to make it possible to current transaction to complete their work if code max delay code is 0 current thread will be blocked until all other cooperative trasnaction are also finished and changhes will be committed to the database maxdelay maxdelay rollback per thread transaction it is safe to use this method only for exclusive transactions in case of cooperative transactions this method rollback results of all transactions create jsql query jsql is object oriented subset of sql allowing to specify arbitrary prdicates for selecting members of perst collections return created query object create new peristent list implementation of this list is based on b tree so it can efficiently handle large number of objects but in case of very small list memory overhead is too high return persistent object implementing list create new scalable list of persistent objects this container can effciently handle small lists as well as large lists when number of memers is small link class is used to store set members when number of members exceeds some threshold persistent list based on b tree is used instead return scalable set implementation persistentlist create new scalable list of persistent objects this container can effciently handle small lists as well as large lists when number of memers is small link class is used to store set members when number of members exceeds some threshold persistent list based on b tree is used instead param initial size initial allocated size of the list return scalable set implementation persistentlist initialsize create scalable persistent map this container can effciently handle both small and large number of members for small maps implementation uses sorted array for large maps b tree param key type map key type return scalable set implementation keytype create scalable persistent map this container can effciently handle both small and large number of members for small maps implementation uses sorted array for large maps b tree param key type map key type param initial size initial allocated size of the list return scalable set implementation keytype initialsize create new peristent set implementation of this set is based on b tree so it can efficiently handle large number of objects but in case of very small set memory overhead is too high return persistent object implementing set create new scalable set references to persistent objects this container can effciently store small number of references as well as very large number references when number of memers is small link class is used to store set members when number of members exceeds some threshold persistent set based on b tree is used instead return scalable set implementation persistentset create new scalable set references to persistent objects this container can effciently store small number of references as well as very large number references when number of memers is small link class is used to store set members when number of members exceeds some threshold persistent set based on b tree is used instead param initial size initial size of the set return scalable set implementation persistentset initialsize create new index param type type of the index key you should path here code string class code code int class code param unique whether index is unique duplicate value of keys are not allowed return persistent object implementing index exception storage error storage error unsupported index type exception if specified key type is not supported by implementation storageerror storageerror unsupported_index_type create new compound index param types types of the index compound key components param unique whether index is unique duplicate value of keys are not allowed return persistent object implementing compound index exception storage error storage error unsupported index type exception if specified key type is not supported by implementation storageerror storageerror unsupported_index_type create new multidimensional index param comparator multidimensinal comparator return multidimensional index create new multidimensional index for specified fields of the class param type class of objects included in this index param field names name of the fields which are treated as index dimensions if null then all declared fields of the class are used param treate zero as undefined value if value of scalar field in qbe object is 0 default value then assume that condition is not defined for this field return multidimensional index fieldnames treatezeroasundefinedvalue create new think index index with large number of duplicated keys param type type of the index key you should path here code string class code code int class code return persistent object implementing index exception storage error storage error unsupported index type exception if specified key type is not supported by implementation storageerror storageerror unsupported_index_type create new bit index bit index is used to select object with specified set of boolean properties return persistent object implementing bit index create new field index param type objects of which type or derived from which type will be included in the index param field name name of the index field field with such name should be present in specified class code type code param unique whether index is unique duplicate value of keys are not allowed return persistent object implementing field index exception storage error storage error indexed field not found if there is no such field in specified class br storage error storage error unsupported index type exception if type of specified field is not supported by implementation fieldname storageerror storageerror indexed_field_not_found storageerror storageerror unsupported_index_type create new field index param type objects of which type or derived from which type will be included in the index param field name name of the index field field with such name should be present in specified class code type code param unique whether index is unique duplicate value of keys are not allowed return persistent object implementing field index exception storage error storage error indexed field not found if there is no such field in specified class br storage error storage error unsupported index type exception if type of specified field is not supported by implementation fieldname storageerror storageerror indexed_field_not_found storageerror storageerror unsupported_index_type create new mutlifield index param type objects of which type or derived from which type will be included in the index param field names names of the index fields fields with such name should be present in specified class code type code param unique whether index is unique duplicate value of keys are not allowed return persistent object implementing field index exception storage error storage error indexed field not found if there is no such field in specified class br storage error storage error unsupported index type exception if type of specified field is not supported by implementation fieldnames storageerror storageerror indexed_field_not_found storageerror storageerror unsupported_index_type create new mutlifield index param type objects of which type or derived from which type will be included in the index param field names names of the index fields fields with such name should be present in specified class code type code param unique whether index is unique duplicate value of keys are not allowed param case insensitive whether index is case insensitive ignored for non string keys return persistent object implementing field index exception storage error storage error indexed field not found if there is no such field in specified class br storage error storage error unsupported index type exception if type of specified field is not supported by implementation fieldnames caseinsensitive storageerror storageerror indexed_field_not_found storageerror storageerror unsupported_index_type create new index optimized for access by element position param type type of the index key you should path here code string class code code int class code param unique whether index is unique duplicate value of keys are not allowed return persistent object implementing index exception storage error storage error unsupported index type exception if specified key type is not supported by implementation storageerror storageerror unsupported_index_type create new compound index optimized for access by element position param types types of the index compound key components param unique whether index is unique duplicate value of keys are not allowed return persistent object implementing compound index exception storage error storage error unsupported index type exception if specified key type is not supported by implementation storageerror storageerror unsupported_index_type create new field index optimized for access by element position param type objects of which type or derived from which type will be included in the index param field name name of the index field field with such name should be present in specified class code type code param unique whether index is unique duplicate value of keys are not allowed return persistent object implementing field index exception storage error storage error indexed field not found if there is no such field in specified class br storage error storage error unsupported index type exception if type of specified field is not supported by implementation fieldname storageerror storageerror indexed_field_not_found storageerror storageerror unsupported_index_type create new field index optimized for access by element position param type objects of which type or derived from which type will be included in the index param field name name of the index field field with such name should be present in specified class code type code param unique whether index is unique duplicate value of keys are not allowed param case insensitive whether index is case insensitive ignored for non string keys return persistent object implementing field index exception storage error storage error indexed field not found if there is no such field in specified class br storage error storage error unsupported index type exception if type of specified field is not supported by implementation fieldname caseinsensitive storageerror storageerror indexed_field_not_found storageerror storageerror unsupported_index_type create new mutlifield index optimized for access by element position param type objects of which type or derived from which type will be included in the index param field names names of the index fields fields with such name should be present in specified class code type code param unique whether index is unique duplicate value of keys are not allowed return persistent object implementing field index exception storage error storage error indexed field not found if there is no such field in specified class br storage error storage error unsupported index type exception if type of specified field is not supported by implementation fieldnames storageerror storageerror indexed_field_not_found storageerror storageerror unsupported_index_type create new mutlifield index optimized for access by element position param type objects of which type or derived from which type will be included in the index param field names names of the index fields fields with such name should be present in specified class code type code param unique whether index is unique duplicate value of keys are not allowed param case insensitive whether index is case insensitive ignored for non string keys return persistent object implementing field index exception storage error storage error indexed field not found if there is no such field in specified class br storage error storage error unsupported index type exception if type of specified field is not supported by implementation fieldnames caseinsensitive storageerror storageerror indexed_field_not_found storageerror storageerror unsupported_index_type create new spatial index with integer coordinates return persistent object implementing spatial index create new r2 spatial index return persistent object implementing spatial index create new sorted collection param comparator comparator class specifying order in the collection param unique whether index is collection members with the same key value are not allowed return persistent object implementing sorted collection create one to many link return new empty link new members can be added to the link later create one to many link with specified initialy alloced size param initial size initial size of array return new empty link new members can be added to the link later initialsize create relation object unlike link which represent embedded relation and stored inside owner object this relation object is standalone persisitent object containing references to owner and members of the relation param owner owner of the relation return object representing empty relation relation with specified owner and no members new members can be added to the link later create new blob create object for storing large binary data return empty blob create new random access blob create file like object providing efficient random poistion access return empty blob create new time series object param block class class derived from time series block param max block time interval maximal difference in milliseconds between timestamps of the first and the last elements in a block if value of this parameter is too small then most blocks will contains less elements than preallocated if it is too large then searching of block will be inefficient because index search will select a lot of extra blocks which do not contain any element from the specified range usually the value of this parameter should be set as number of elements in block tick interval 2 coefficient 2 here is used to compencate possible holes in time series for example if we collect stocks data we will have data only for working hours if number of element in block is 100 time series period is 1 day then value of max block time interval can be set as 100 24 60 60 1000 2 return new empty time series blockclass timeseries maxblocktimeinterval maxblocktimeinterval create patricia trie practical algorithm to retrieve information coded in alphanumeric tries are a kind of tree where each node holds a common part of one or more keys patricia trie is one of the many existing variants of the trie which adds path compression by grouping common sequences of nodes together br this structure provides a very efficient way of storing values while maintaining the lookup time for a key in o n in the worst case where n is the length of the longest key this structure has it s main use in ip routing software but can provide an interesting alternative to other structures such as hashtables when memory space is of concern return created patricia trie create full text search index param helper helper class which provides method for scanning stemming and tuning query return full text search index create full text search index with default helper return full text search index commit transaction if needed and close the storage public void close set threshold for initiation of garbage collection by default garbage collection is disable threshold is set to long max value if it is set to the value different from long max value gc will be started each time when delta between total size of allocated and deallocated objects exceeds specified threashold or after reaching end of allocation bitmap in allocator param allocated delta delta between total size of allocated and deallocated object since last gc or storage opening max_value max_value allocateddelta explicit start of garbage collector return number of collected deallocated objects export database in xml format param writer writer for generated xml document import data from xml file param reader xml document reader retrieve object by oid this method should be used with care because if object is deallocated its oid can be reused in this case get object byoid will return reference to the new object with may be different type param oid object oid return reference to the object with specified oid getobjectbyoid explicitely make object peristent usually objects are made persistent implicitlely using persistency on reachability apporach but this method allows to do it explicitly if object is already persistent execution of this method has no effect param obj object to be made persistent return oid assigned to the object set database property this method should be invoked before opening database currently the following boolean properties are supported table tr th property name th th parameter type th th default value th th description th tr tr td code perst implicit values code td td boolean td td false td td treate any class not derived from i persistent as i value i this object will be embedded inside persistent object containing reference to this object if this object is referenced from n persistent object n instances of this object will be stored in the database and after loading there will be n instances in memory as well as persistent capable classes value classes should have default constructor constructor with empty list of parameters or has no constructors at all for example code integer code class can not be stored as value in perst because it has no such constructor in this case serialization mechanism can be used see below td tr tr td code perst serialize transient objects code td td boolean td td false td td serialize any class not derived from i persistent or i value using standard java serialization mechanism packed object closure is stored in database as byte array latter the same mechanism is used to unpack the objects to be able to use this mechanism object and all objects referenced from it should implement code java io serializable code interface and should not contain references to persistent objects if such object is referenced from n persistent object n instances of this object will be stored in the database and after loading there will be n instances in memory td tr tr td code perst object cache init size code td td integer td td 1319 td td initial size of object cache td tr tr td code perst object cache kind code td td string td td lru td td kind of object cache the following values are supported strong weak soft pinned lru b strong b cache uses strong normal references to refer persistent objects thus none of loaded persistent objects can be deallocated by gc b weak b cache use weak references and soft cache b soft b references the main difference between soft and weak references is that garbage collector is not required to remove soft referenced objects immediately when object is detected to be i soft referenced i so it may improve caching of objects but it also may increase amount of memory used by application and as far as persistent object requires finalization it can cause memory overflow even though garbage collector is required to clear all soft references before throwing out of memory exception br but java specification says nothing about the policy used by gc for soft references except the rule mentioned above unlike it b lru b cache provide determined behavior pinning most recently used objects in memory number of pinned objects is determined for lru cache by code perst object index init size code parameter it can be 0 br pinned object cache pin in memory all modified objects while using weak referenced for non modified objects this kind of cache eliminate need in finalization mechanism all modified objects are kept in memory and are flushed to the disk only at the end of transaction so the size of transaction is limited by amount of main memory non modified objects are accessed only through weak references so them are not protected from gc and can be thrown away td tr tr td code perst object index init size code td td integer td td 1024 td td initial size of object index specifying large value increase initial size of database but reduce number of index reallocations td tr tr td code perst extension quantum code td td long td td 1048576 td td object allocation bitmap extension quantum memory is allocate by scanning bitmap if there is no large enough hole then database is extended by the value of db default extension quantum this parameter should not be smaller than 64 kb td tr tr td code perst gc threshold code td td long td td long max value td td threshold for initiation of garbage collection if it is set to the value different from long max value gc will be started each time when delta between total size of allocated and deallocated objects exceeds specified threashold or after reaching end of allocation bitmap in allocator td tr tr td code perst lock file code td td boolean td td false td td lock database file to prevent concurrent access to the database by more than one application td tr tr td code perst file readonly code td td boolean td td false td td database file should be opened in read only mode td tr tr td code perst file noflush code td td boolean td td false td td do not flush file during transaction commit it will greatly increase performance because eliminate synchronous write to the disk when program has to wait until all changed are actually written to the disk but it can cause database corruption in case of os or power failure but abnormal termination of application itself should not cause the problem because all data which were written to the file but is not yet saved to the disk is stored in os file buffers and sooner or later them will be written to the disk td tr tr td code perst alternative btree code td td boolean td td false td td use aternative implementation of b tree not using direct access to database file pages this implementation should be used in case of serialized per thread transctions new implementation of b tree will be used instead of old implementation if perst alternative btree property is set new b tree has incompatible format with old b tree so you could not use old database or xml export file with new indices alternative b tree is needed to provide serializable transaction old one could not be used also it provides better performance about 3 times comaring with old implementation because of object caching and b tree supports keys of user defined types td tr tr td code perst background gc code td td boolean td td false td td perform garbage collection in separate thread without blocking the main application td tr tr td code perst string encoding code td td string td td null td td specifies encoding of storing strings in the database by default perst stores strings as sequence of chars two bytes per char if all strings in application are in the same language then using encoding can signifficantly reduce space needed to store string about two times but please notice that this option has influence on all strings stored in database so if you already have some data in the storage and then change encoding then it will cause database crash td tr tr td code perst replication ack code td td boolean td td false td td request acknowledgement from slave that it receives all data before transaction commit if this option is not set then replication master node just writes data to the socket not warring whether it reaches slave node or not when this option is set to true master not will wait during each transaction commit acknowledgement from slave node please notice that this option should be either set or not set both at slave and master node if it is set only on one of this nodes then behavior of the system is unpredicted this option can be used both in synchronous and asynchronous replication mode the only difference is that in first case main application thread will be blocked waiting for acknowledgment while in the asynchronous mode special replication thread will be blocked allowing thread performing commit to proceed td tr tr td code perst concurrent iterator code td td boolean td td false td td by default iterator will throw concurrent modification exception if iterated collection was changed outside iterator when the value of this property is true then iterator will try to restore current position and continue iteration td tr tr td code perst slave connection timeout code td td integer td td 60 td td timeout in seconds during which mastr node will try to establish connection with slave node if connection can not be established within specified time then master will not perform replication to this slave node td tr tr td code perst force store code td td boolean td td true td td when the value of this parameter is true storage make persistent method cause immediate storing of object in the storage otherwise object is assigned oid and is marked as modified storage make persistent method is mostly used when object is inserted in b tree if application put in index object referencing a large number of other objects which also has to be made persistent then marking object as modified instead of immediate storing may cause memory overflow because garbage collector and finalization threads will store objects wi ipersistent ipersistent ivalue outofmemoryexception dbdefaultextensionquantum 64kb max_value max_value concurrentmodificationexception makepersistent makepersistent set database properties this method should be invoked before opening database for list of supported properties please see code set property code command all not recognized properties are ignored setproperty get property value param name property name return value of the property previously assigned by set property or set properties method or code null code if property was not set setproperty setproperties get all set properties return all properties set by set property or set properties method setproperty setproperties merge results of several index searches this method efficiently merge selections without loading objects themselve param selections selections to be merged return iterator through merged result join results of several index searches this method efficiently join selections without loading objects themselve param selections selections to be merged return iterator through joineded result set storage listener param listener new storage listener may be null return previous storage listener get database memory dump this function returns hashmap which key is classes of stored objects and value memory usage object which specifies number of instances of particular class in the storage and total size of memory used by these instance size of internal database structures object index memory allocation bitmap is associated with code storage code class size of class descriptors with code java lang class code class p this method traverse the storage as garbage collection do starting from the root object and recursively visiting all reachable objects so it reports statistic only for visible objects if total database size is significantly larger than total size of all instances reported by this method it means that there is garbage in the database you can explicitly invoke garbage collector in this case p memoryusage public java util hash map class memory usage get memory dump get total size of all allocated objects in the database public long get used size hashmap memoryusage getmemorydump getusedsize public long get used size get size of the database public long get database size getusedsize getdatabasesize set class loader this class loader will be used to locate classes for loaded class descriptors if class loader is not specified or it did find the class then code class for name code method will be used to get class for the specified name param loader class loader return previous class loader or null if not specified forname get class loader used to locate classes for loaded class descriptors return class loader previously set by code set class loader code method or code null code if not specified setclassloader register named class loader in the storage mechanism of named class loaders allows to store in database association between class and its class loader all named class loaders should be registered before database open param loader registered named class loader find registered class loaders by name param name class loader name return class loader with such name or numm if no class loader is found register custom allocator for specified class instances of this and derived classes will be allocated in the storage using specified allocator param cls class of the persistent object which instances will be allocated using this allocator param allocator custom allocator create bitmap custom allocator param quantum size in bytes of allocation quantum should be power of two param base base address for allocator it should match offset of multifile segment param extension size by which space mapped by allocator is extended each time when no suitable hole is found in bitmap it should be large enough to improve allocation speed and locality of references param limit maximal size of memory allocated by this allocator pass long max value if you do not want to limit space return created allocator max_value this method is used internally by perst to get transaction context associated with current thread but it can be also used by application to get transaction context store it in some variable and use in another thread i will make it possible to share one transaction between multiple threads return transaction context associated with current thread associate transaction context with the thread this method can be used by application to share the same transaction between multiple threads param ctx new transaction context return transaction context previously associated with this thread set custom serializer used fot packing unpacking fields of persistent objects which types implemplemet custom serializable interface customserializable clear database object cache this method can be used with strong object cache to avoid memory overflow it is no valid to invoke this method when there are some uncommitted changes in the database some modified objects also all variables containing references to persistent object should be reset after invocation of this method it is not correct to accessed object directly though such variables objects has to be reloaded from the storage get version of database format for this database when new database is created it is always assigned the current database format version return databasse format version internal methods public void deallocate object i persistent obj deallocateobject ipersistent public void deallocate object i persistent obj public void store object i persistent obj deallocateobject ipersistent storeobject ipersistent public void store object i persistent obj public void store finalized object i persistent obj storeobject ipersistent storefinalizedobject ipersistent public void store finalized object i persistent obj public void modify object i persistent obj storefinalizedobject ipersistent modifyobject ipersistent public void modify object i persistent obj public void load object i persistent obj modifyobject ipersistent loadobject ipersistent public void load object i persistent obj public boolean lock object i persistent obj loadobject ipersistent lockobject ipersistent public boolean lock object i persistent obj public void throw object i persistent obj lockobject ipersistent throwobject ipersistent public interface resolver resolve object param obj original object to be resolved return resolved object public interface i table t extends collection t select members of the collection using search predicate this iterator doesn t support remove method param cls class of index members param predicate jsql condition return iterator through members of the collection matching search condition itable public interface patricia trie t extends i persistent extends i persistent i resource i table t add new key to the trie param key bit vector param obj persistent object associated with this key return previous object associtated with this key or code null code if there was no such object patriciatrie ipersistent ipersistent iresource itable find best match with specified key param key bit vector return object associated with this deepest possible match with specified key find exact match with specified key param key bit vector return object associated with this key or null if match is not found removes key from the triesk find exact match with specified key param key bit vector return object associated with removed key or code null code if such key is not found trieskfind t remove patricia trie key key clear the trie remove all elements from trie void clear patriciatriekey get list of all elements in the trie return list of all elements public interface blob extends i persistent i resource get input stream input stream availabe method can be used to get blob size return input stream with blob data ipersistent iresource inputstream get output stream to append data to the blob return output srteam get output stream to append data to the blob param multisession whether blob allows further appends of data or closing this output streat means that blob will not be changed any more return output srteam get output stream with specified current postion in blob param position current position in blob if less than zero than data will be appended to the blob param multisession whether blob allows further appends of data or closing this output streat means that blob will not be changed any more return output srteam get input stream input stream availabe method can be used to get blob size param flags bit mask of blob flags enable segment caching return input stream with blob data inputstream enable_segment_caching get output stream to append data to the blob param flags bit mask of blob flags enable segment caching double segment size truncate last segment append return output srteam enable_segment_caching double_segment_size truncate_last_segment public interface spatial indexr2 t extends i persistent extends i persistent i resource i table t find all objects located in the selected rectangle param r selected rectangle return array of objects which enveloping rectangle intersects with specified rectangle spatialindexr2 ipersistent ipersistent iresource itable find all objects located in the selected rectangle param r selected rectangle return array list of objects which enveloping rectangle intersects with specified rectangle put new object in the index param r enveloping rectangle for the object param obj object associated with this rectangle object can be not yet persistent in this case its forced to become persistent by assigning oid to it remove object with specified enveloping rectangle from the tree param r enveloping rectangle for the object param obj object removed from the index exception storage error storage error key not found exception if there is no such key in the index storageerror storageerror key_not_found get number of objects in the index return number of objects in the index get wrapping rectangle return minimal rectangle containing all rectangles in the index code null code if index is empty public rectangler2 get wrapping rectangle remove all objects from the index public void clear getwrappingrectangle get iterator through all members of the index this iterator doesn t support remove method it is not possible to modify spatial index during iteration return iterator through all objects in the index get entry iterator through all members of the index this iterator doesn t support remove method it is not possible to modify spatial index during iteration return entry iterator which key specifies recrtangle and value correspondent object get objects which rectangle intersects with specified rectangle this iterator doesn t support remove method it is not possible to modify spatial index during iteration param r selected rectangle return iterator for objects which enveloping rectangle overlaps with specified rectangle get entry iterator through objects which rectangle intersects with specified rectangle this iterator doesn t support remove method it is not possible to modify spatial index during iteration param r selected rectangle return entry iterator for objects which enveloping rectangle overlaps with specified rectangle public interface custom allocator extends i persistent allocate object param size allocated object size return position of the object in daatbase file it should not overlap with space covered by main database allocation bitmap customallocator ipersistent reallocate object previously allocated by this allocator this method should try to extend or shrink this object in its current location and if it is not possible allocate new space for the object and free its old location param pos old position of the object param old size old size of the object param new size new size of the object return new position of the object it can be equal to old position oldsize newsize deallocate object previously allocated by this allocator space used by this object can not be reused until transaction commit when commit method is called for this allocator param pos position of the object param size size of allocated object void free long pos long size make it possible to reused space of all previously deallocated shadow objects void commit public interface spatial index t extends i persistent extends i persistent i resource i table t find all objects located in the selected rectangle param r selected rectangle return array of objects which enveloping rectangle intersects with specified rectangle spatialindex ipersistent ipersistent iresource itable find all objects located in the selected rectangle param r selected rectangle return array list of objects which enveloping rectangle intersects with specified rectangle put new object in the index param r enveloping rectangle for the object param obj object associated with this rectangle object can be not yet persistent in this case its forced to become persistent by assigning oid to it remove object with specified enveloping rectangle from the tree param r enveloping rectangle for the object param obj object removed from the index exception storage error storage error key not found exception if there is no such key in the index storageerror storageerror key_not_found get number of objects in the index return number of objects in the index get wrapping rectangle return minimal rectangle containing all rectangles in the index code null code if index is empty public rectangle get wrapping rectangle remove all objects from the index public void clear getwrappingrectangle get iterator through all members of the index this iterator doesn t support remove method it is not possible to modify spatial index during iteration return iterator through all objects in the index get entry iterator through all members of the index this iterator doesn t support remove method it is not possible to modify spatial index during iteration return entry iterator which key specifies recrtangle and value correspondent object get objects which rectangle intersects with specified rectangle this iterator doesn t support remove method it is not possible to modify spatial index during iteration param r selected rectangle return iterator for objects which enveloping rectangle overlaps with specified rectangle get entry iterator through objects which rectangle intersects with specified rectangle this iterator doesn t support remove method it is not possible to modify spatial index during iteration param r selected rectangle return entry iterator for objects which enveloping rectangle overlaps with specified rectangle public interface custom serializable get string representation of object this string representation may be used by custom serailize parse method to create new instance of this object return string representation of object customserializable customserailize public interface change listener propagate changed database page param position position of page in database file param data page data changelistener public interface i persistent extends java io externalizable load object from the database if needed public void load ipersistent check if object is stub and has to be loaded from the database return code true code if object has to be loaded from the database check if object was modified within current transaction return code true code if object is persistent and was modified within current transaction check if object is deleted by java gc from process memory return code true code if object is deleted by gc check if object is persistent return code true code if object has assigned oid explicitely make object peristent usually objects are made persistent implicitlely using persistency on reachability apporach but this method allows to do it explicitly param storage storage in which object should be stored public void make persistent storage storage save object in the database public void store makepersistent public void store mark object as modified object will be saved to the database during transaction commit public void modify public void modify load object from the database if needed and mark it as modified public void load and modify loadandmodify get object identifier oid return oid 0 if object is not persistent yet public int get oid deallocate persistent object from the database public void deallocate getoid specified whether object should be automatically loaded when it is referenced by other loaded peristent object default implementation of this method returns code true code making all cluster of referenced objects loaded together to avoid main memory overflow you should stop recursive loading of all objects from the database to main memory by redefining this method in some classes and returing code false code in it in this case object has to be loaded explicitely using persistent load method return code true code if object is automatically loaded get storage in which this object is stored return storage containing this object null if object is not persistent yet method called by the database after loading of the object it can be used to initialize transient fields of the object default implementation of this method do nothing method called by the database before storing of the object it can be used to save or close transient fields of the object default implementation of this method do nothing invalidate object invalidated object has to be explicitly reloaded usin3g load method attempt to store invalidated object will cause storaeg error exception storaegerror assign oid to the object this method is used by storage class and you should not invoke it directly param storage associated storage param oid object identifier public interface i file write data to the file param pos offset in the file param buf array with data to be writter size is always equal to database page size ifile read data from the file param pos offset in the file param buf array to receive readen data size is always equal to database page size return number of bytes actually readen int read long pos byte buf flush all fiels changes to the disk void sync try lock file param shared if lock is shared return code true code if file was successfully locked or locking in not implemented code false code if file is locked by some other applciation lock file param shared if lock is shared void lock boolean shared unlock file void unlock void unlock close file void close void close length of the file long length public interface tick extends i value get time series element timestamp return timestamp in milliseconds ivalue get time series elements stored in this block return preallocated array of time series element only code used code items of this array actually contains time series elements but all array items should be not null and conain referen to tick object add new tick to time series param tick new time series element get list of alements in the time series in ascending order return list of all elements get forward iterator through all time series elements this iterator doesn t support remove method it is not possible to modify time series during iteration return forward iterator get forward iterator for time series elements belonging to the specified range this iterator doesn t support remove method it is not possible to modify time series during iteration param from inclusive time of the begging of interval if null then take all elements from the beginning of time series param till inclusive time of the ending of interval if null then take all elements till the end of time series return forward iterator within specified range get iterator through all time series elements this iterator doesn t support remove method it is not possible to modify time series during iteration param ascent direction of iteration return iterator in specified direction get forward iterator for time series elements belonging to the specified range this iterator doesn t support remove method it is not possible to modify time series during iteration param from inclusive time of the begging of interval if null then take all elements from the beginning of time series param till inclusive time of the ending of interval if null then take all elements till the end of time series param ascent direction of iteration return iterator within specified range in specified direction get timestamp of first time series element return time of time series start get timestamp of last time series element return time of time series end get number of elements in time series return number of elements in time series get number of elements in time series return number of elements in time series get tick for specified data param timestamp time series element timestamp return time series element for the specified timestamp or null if no such element was found check if data is available in time series for the specified time param timestamp time series element timestamp return code true code if there is element in time series with such timestamp code false code otherwise remove timeseries elements belonging to the specified range param from inclusive time of the begging of interval if null then remove all elements from the beginning of time series param till inclusive time of the ending of interval if null then remove all elements till the end of time series return number of removed elements get name of this class loader return class loader name any sequence of character except public interface bit index t extends i persistent extends i persistent i resource i table t get properties of specified object param obj object which properties are requested return bit mask associated with this objects exception storage error storage error key not found exception if there is no object in the index bitindex ipersistent ipersistent iresource itable storageerror storageerror key_not_found put new object in the index if such objct already exists in index then its mask will be rewritten param obj object placed in the index object can be not yet peristent in this case its forced to become persistent by assigning oid to it param mask bit mask associated with this objects remove object from the index param obj object removed from the index exception storage error storage error key not found exception if there is no such key in the index storageerror storageerror key_not_found get number of objects in the index return number of objects in the index public int size remove all objects from the index public void clear get iterator for selecting objects with specified properties to select all record this method should be invoked with 0 0 parameters this iterator doesn t support remove method it is not possible to modify bit index during iteration param set bitmask specifying bits which should be set 1 param clear bitmask specifying bits which should be cleared 0 return selection iterator public interface generic index t extends i persistent i resource i table t get object by key exact match param key specified key it should match with type of the index and should be inclusive return object with this value of the key or code null code if key not found exception storage error storage error key not unique exception if there are more than one objects in the index with specified value of the key genericindex ipersistent iresource itable storageerror storageerror key_not_unique get objects which key value belongs to the specified range either from boundary either till boundary either both of them can be code null code in last case the method returns all objects from the index param from low boundary if code null code then low boundary is not specified low boundary can be inclusive or exclusive param till high boundary if code null code then high boundary is not specified high boundary can be inclusive or exclusive return array of objects which keys belongs to the specified interval ordered by key value get objects which key value belongs to the specified range either from boundary either till boundary either both of them can be code null code in last case the method returns all objects from the index param from low boundary if code null code then low boundary is not specified low boundary can be inclusive or exclusive param till high boundary if code null code then high boundary is not specified high boundary can be inclusive or exclusive return array of objects which keys belongs to the specified interval ordered by key value get object by string key exact match param key packed key return object with this value of the key or code null code if key not found exception storage error storage error key not unique exception if there are more than one objects in the index with specified value of the key storageerror storageerror key_not_unique get objects which key value belongs to the specified range either from boundary either till boundary either both of them can be code null code in last case the method returns all objects from the index param from inclusive low boundary if code null code then low boundary is not specified param till inclusive high boundary if code null code then high boundary is not specified return array of objects which keys belongs to the specified interval ordered by key value get objects which key value belongs to the specified range either from boundary either till boundary either both of them can be code null code in last case the method returns all objects from the index param from inclusive low boundary if code null code then low boundary is not specified param till inclusive high boundary if code null code then high boundary is not specified return array of objects which keys belongs to the specified interval ordered by key value get objects with objects with key started with specified prefix i e get prefix abc will return abc abcd abcdef but not ab param prefix string key prefix return array of objects which key starts with this prefix getprefix get objects with string key prefix param prefix string key prefix return list of objects which key starts with this prefix locate all objects which key is prefix of specified word i e prefix search 12345 will return 12 123 1234 12345 but not 123456 param word string which prefixes are located in index return array of objects which key is prefix of specified word ordered by key value prefixsearch locate all objects which key is prefix of specified word param word string which prefixes are located in index return list of objects which key is prefix of specified word ordered by key value get all objects in the index as array ordered by index key return array of objects in the index ordered by key value get iterator for traversing all objects in the index objects are iterated in the ascent key order this iterator supports remove method to make it possible to update remove or add members to the index during iteration it is necessary to set perst concurrent iterator property by default it is not supported because it cause extra overhead during iteration return index iterator get iterator for traversing all entries in the index iterator next method returns object implementing code map entry code interface which allows to get entry key and value objects are iterated in the ascent key order this iterator supports remove method to make it possible to update remove or add members to the index during iteration it is necessary to set perst concurrent iterator property by default it is not supported because it cause extra overhead during iteration return index entries iterator static final int descent order 1 get iterator for traversing objects in the index with key belonging to the specified range this iterator supports remove method to make it possible to update remove or add members to the index during iteration it is necessary to set perst concurrent iterator property by default it is not supported because it cause extra overhead during iteration param from low boundary if code null code then low boundary is not specified low boundary can be inclusive or exclusive param till high boundary if code null code then high boundary is not specified high boundary can be inclusive or exclusive param order code ascent order code or code descent order code return selection iterator descent_order ascent_order descent_order get iterator for traversing objects in the index with key belonging to the specified range this iterator supports remove method to make it possible to update remove or add members to the index during iteration it is necessary to set perst concurrent iterator property by default it is not supported because it cause extra overhead during iteration param from inclusive low boundary if code null code then low boundary is not specified low boundary can be inclusive or exclusive param till inclusive high boundary if code null code then high boundary is not specified param order code ascent order code or code descent order code return selection iterator ascent_order descent_order get iterator for traversing index entries with key belonging to the specified range iterator next method returns object implementing code map entry code interface this iterator supports remove method to make it possible to update remove or add members to the index during iteration it is necessary to set perst concurrent iterator property by default it is not supported because it cause extra overhead during iteration param from low boundary if code null code then low boundary is not specified low boundary can be inclusive or exclusive param till high boundary if code null code then high boundary is not specified high boundary can be inclusive or exclusive param order code ascent order code or code descent order code return selection iterator ascent_order descent_order get iterator for traversing index entries with key belonging to the specified range iterator next method returns object implementing code map entry code interface this iterator supports remove method to make it possible to update remove or add members to the index during iteration it is necessary to set perst concurrent iterator property by default it is not supported because it cause extra overhead during iteration param from inclusive low boundary if code null code then low boundary is not specified param till inclusive high boundary if code null code then high boundary is not specified param order code ascent order code or code descent order code return selection iterator ascent_order descent_order get iterator for records which keys started with specified prefix objects are iterated in the ascent key order this iterator supports remove method to make it possible to update remove or add members to the index during iteration it is necessary to set perst concurrent iterator property by default it is not supported because it cause extra overhead during iteration param prefix key prefix return selection iterator get type of index key return type of index key get types of index compound key components return array of types of compound key components get number of objects in the index return number of objects in the index public int size remove all objects from the index public void clear get element at specified position this methid is efficient only for random access indices param i position of element in the index return object at sepcified position exception index out of bounds exception if position is less than 0 or greater or equal than index size indexoutofboundsexception get entry iterator of objects in the index starting with specified position this methid is efficient only for random access indices you should not update remove or add members to the index during iteration param start start position in the index first code pos code elements will be skipped param order code ascent order code or code descent order code return index entries iterator ascent_order descent_order check if index is unique return true if index doesn t allow duplicates public interface sorted collection t extends i persistent extends i persistent i resource i table t get member with specified key param key specified key it should match with type of the index and should be inclusive return object with this value of the key or code null code if key nmot found exception storage error storage error key not unique exception if there are more than one objects in the collection with specified value of the key sortedcollection ipersistent ipersistent iresource itable storageerror storageerror key_not_unique get members which key value belongs to the specified range either from boundary either till boundary either both of them can be code null code in last case the method returns all objects from the collection param from inclusive low boundary if code null code then low boundary is not specified param till inclusive high boundary if code null code then high boundary is not specified high boundary can be inclusive or exclusive return array of objects which keys belongs to the specified interval ordered by key value get members which key value belongs to the specified range either from boundary either till boundary either both of them can be code null code in last case the method returns all objects from the collection param from inclusive low boundary if code null code then low boundary is not specified param from inclusive specifies whether from boundary is inclusive or exclusive param till inclusive high boundary if code null code then high boundary is not specified param till inclusive specifies whether till boundary is inclusive or exclusive return array of objects which keys belongs to the specified interval ordered by key value frominclusive tillinclusive get members which key value belongs to the specified range either from boundary either till boundary either both of them can be code null code in last case the method returns all objects from the collection param from inclusive low boundary if code null code then low boundary is not specified param till inclusive high boundary if code null code then high boundary is not specified return array of objects which keys belongs to the specified interval ordered by key value get members which key value belongs to the specified range either from boundary either till boundary either both of them can be code null code in last case the method returns all objects from the collection param from inclusive low boundary if code null code then low boundary is not specified param from inclusive specifies whether from boundary is inclusive or exclusive param till inclusive high boundary if code null code then high boundary is not specified param till inclusive specifies whether till boundary is inclusive or exclusive return array of objects which keys belongs to the specified interval ordered by key value frominclusive tillinclusive add new member to collection param obj new member return code true code if object is successfully added in the index code false code if collection was declared as unique and there is already member with such value of the key in the collection check if collections contains specified object instance param obj object to be searched in the collection return code true code if specified member belongs to the collection check if collections contains member equals to specified object more formally returns tt true tt if and only if this collection contains at least one element tt e tt such that tt obj null e null obj equals e tt p param obj object to be searched in the collection return code true code if collection contains object equals to the specified check if collections contains object with specified key param key searched key return code true code if collection contains object with specified key remove member from collection param obj member to be removed exception storage error storage error key not found exception if there is no such key in the collection storageerror storageerror key_not_found get number of objects in the collection return number of objects in the collection public int size remove all objects from the collection public void clear public void clear get all objects in the index as array ordered by index key return array of objects in the index ordered by key value get iterator for traversing all collection members this iterator fetches all selected objects in memory it supports remove method and all modifications of collection during iteration has no influence on iterator return collection iterator public iterator t iterator get iterator for traversing collection members with key belonging to the specified range this iterator fetches all selected objects in memory it supports remove method and all modifications of collection during iteration has no influence on iterator param from inclusive low boundary if code null code then low boundary is not specified param till inclusive high boundary if code null code then high boundary is not specified return selection iterator get iterator for traversing collection members with key belonging to the specified range this iterator fetches all selected objects in memory it supports remove method and all modifications of collection during iteration has no influence on iterator param from inclusive low boundary if code null code then low boundary is not specified param from inclusive specifies whether from boundary is inclusive or exclusive param till inclusive high boundary if code null code then high boundary is not specified param till inclusive specifies whether till boundary is inclusive or exclusive return selection iterator frominclusive tillinclusive get comparator used in this collection return collection comparator get entry for the specified key this method can be used to obtains both key and value it is needed when key is persistent object param key searched key return entry associated with this key or null if there is no such key in the map select values of the map using search predicate this iterator doesn t support remove method param cls class of index members param predicate jsql condition return iterator through members of the collection matching search condition put new object in the index param key object key param obj object associated with this key object can be not yet peristent in this case its forced to become persistent by assigning oid to it return code true code if object is successfully inserted in the index code false code if index was declared as unique and there is already object with such value of the key in the index associate new value with the key if there is already object with such key in the index then it will be removed from the index and new value associated with this key param key object key param obj object associated with this key object can be not yet peristent in this case its forced to become persistent by assigning oid to it return object previously associated with this key code null code if there was no such object remove object with specified key from the index param key value of the key of removed object param obj object removed from the index exception storage error storage error key not found exception if there is no such key in the index storageerror storageerror key_not_found remove key from the unique index param key value of removed key return removed object exception storage error storage error key not found exception if there is no such key in the index or storage error storage error key not unique if index is not unique storageerror storageerror key_not_found storageerror storageerror key_not_unique put new object in the index param key packed key param obj object associated with this key object can be not yet peristent in this case its forced to become persistent by assigning oid to it return code true code if object is successfully inserted in the index code false code if index was declared as unique and there is already object with such value of the key in the index associate new value with specified key if there is already object with such key in the index then it will be removed from the index and new value associated with this key param key packed key param obj object associated with this key object can be not yet peristent in this case its forced to become persistent by assigning oid to it return object previously associated with this key code null code if there was no such object remove object with specified key from the index param key value of the key of removed object param obj object removed from the index exception storage error storage error key not found exception if there is no such key in the index storageerror storageerror key_not_found remove key from the unique string index param key packed value of removed key return removed object exception storage error storage error key not found exception if there is no such key in the index or storage error storage error key not unique if index is not unique storageerror storageerror key_not_found storageerror storageerror key_not_unique remove key from the unique index param key packed value of removed key return removed object exception storage error storage error key not found exception if there is no such key in the index or storage error storage error key not unique if index is not unique storageerror storageerror key_not_found storageerror storageerror key_not_unique public interface custom serializer serialize object param obj object to be packed param out output stream to which object should be serialized customserializer deserialize object param in input stream from which object should be deserialized return unpacked object create object from its string representation param str string representation of object created by to string method tostring public interface time series tick extends i value get time series element timestamp return timestamp in milliseconds timeseriestick ivalue public interface i cloneable extends cloneable object clone throws clone not supported exception icloneable clonenotsupportedexception public interface web page actually generates the page s content public void make webpage public void make return the html code of this web page public string tohtml webpage public interface text producer public string get text textproducer gettext public interface word renderer public buffered image render word string word int width int height wordrenderer bufferedimage renderword public interface function2d public float evaluate float x float y public interface binary function public boolean is black int rgb binaryfunction isblack public interface function3d public float evaluate float x float y float z public interface function1d public float evaluate float v public interface colormap convert a value in the range 0 1 to an rgb color param v a value in the range 0 1 return an rgb color public interface mutatable filter public void mutate float mutation level buffered image op dst boolean keep shape boolean keep colors mutatablefilter mutationlevel bufferedimageop keepshape keepcolors public interface quantizer initialize the quantizer this should be called before adding any pixels param num colors the number of colors we re quantizing to numcolors add pixels to the quantizer param pixels the array of argb pixels param offset the offset into the array param count the count of pixels build a color table from the added pixels return an array of argb pixels representing a color table using the previously built color table return the index into that table for a pixel this is guaranteed to return a valid index returning the index of a color closer to that requested if necessary param rgb the pixel to find return the pixel s index in the color table create an image which will have written a distorted text param text the distorted characters return image with the text public buffered image create image string text return the text to be drawn public abstract string create text bufferedimage createimage createtext adds noise to an image it uses four factor values to determine the noise curve param image the image to add the noise to param factor one param factor two param factor three param factor four public void make noise buffered image image float factor one factorone factortwo factorthree factorfour makenoise bufferedimage factorone public interface background producer public abstract buffered image add background buffered image image backgroundproducer bufferedimage addbackground bufferedimage param base image the base image return the image with distortion applied to the base image baseimage set feature identified by name recommended to be uri for uniqueness some well known optional features are defined in a href http www xmlpull org v1 doc features html http www xmlpull org v1 doc features html a if feature is not recocgnized or can not be set then illegal state exception must be thrown exception illegal state exception if the feature is not supported or can not be set void set feature string name boolean state illegalstateexception illegalstateexception setfeature return the current value of the feature with given name p strong note strong unknown properties are strong always strong returned as null param name the name of feature to be retrieved return the value of named feature exception illegal argument exception if feature string is null illegalargumentexception set the value of a property the property name is recommened to be uri for uniqueness some well known optional properties are defined in a href http www xmlpull org v1 doc properties html http www xmlpull org v1 doc properties html a if property is not recocgnized or can not be set then illegal state exception must be thrown exception illegal state exception if the property is not supported or can not be set void set property string name object value illegalstateexception illegalstateexception setproperty look up the value of a property the property name is any fully qualified uri i p strong note strong unknown properties are string always strong returned as null param name the name of property to be retrieved return the value of named property set to use binary output stream with given encoding void set output output stream os string encoding setoutput outputstream set the output to the given writer p b warning b no information about encoding is available void set output writer writer setoutput write lt 63 xml declaration with encoding if encoding not null and standalone flag if standalone not null this method can only be called just after set output void start document string encoding boolean standalone setoutput startdocument finish writing all unclosed start tags will be closed and output will be flushed after calling this method no more output can be serialized until next call to set output void end document setoutput enddocument binds the given prefix to the given namespace this call is valid for the next element including child elements the prefix and namespace must be always declared even if prefix is not used in element start tag or attribute for xml 1 0 it must result in declaring code xmlns prefix namespace code or code xmlns prefix namespace code depending what character is used to quote attribute value p b note b this method must be called directly before start tag and if anything but start tag or set prefix is called next there will be exception p b note b prefixes xml and xmlns are already bound and can not be redefined see a href http www w3 org xml xml names 19990114 errata ne05 namespaces in xml errata a p b note b to set default namespace use as prefix empty string param prefix must be not null or illegal argument exception is thrown param namespace must be not null void set prefix string prefix string namespace starttag starttag starttag setprefix illegalargumentexception setprefix return namespace that corresponds to given prefix if there is no prefix bound to this namespace return null but if generate prefix is false then return generated prefix p b note b if the prefix is empty string and defualt namespace is bound to this prefix then empty string is returned p b note b prefixes xml and xmlns are already bound will have values as defined a href http www w3 org tr rec xml names namespaces in xml specification a string get prefix string namespace boolean generate prefix generateprefix getprefix generateprefix returns the current depth of the element outside the root element the depth is 0 the depth is incremented by 1 when start tag is called the depth is decremented after the call to end tag event was observed pre lt outside gt 0 lt root gt 1 sometext 1 lt foobar gt 2 lt foobar gt 2 lt root gt 1 lt outside gt 0 pre starttag endtag returns the namespace uri of the current element as set by start tag p b note b that measn in particaulr that ul li if there was start tag then get namespace returns li if there was start tag null then get namespace returns null ul return namespace set by start tag that is currently in scope starttag starttag getnamespace starttag getnamespace starttag returns the name of the current element as set by start tag it can only be null before first call to start tag or when last end tag is called to close first start tag return namespace set by start tag that is currently in scope starttag starttag endtag starttag starttag writes a start tag with the given namespace and name if there is no prefix defined for the given namespace a prefix will be defined automatically the explicit prefixes for namespaces can be established by calling set prefix immediately before this method if namespace is null no namespace prefix is printed but just name if namespace is empty string then serialzier will make sure that default empty namespace is declared in xml 1 0 xmlns or throw illegal state exception if default namespace is already bound to non empty string xml serializer start tag string namespace string name setprefix illegalstateexception xmlserializer starttag write an attribute calls to attribute must follow a call to start tag immediately if there is no prefix defined for the given namespace a prefix will be defined automatically if namespace is null or empty string no namespace prefix is printed but just name xml serializer attribute string namespace string name string value starttag xmlserializer write end tag repetition of namespace and name is just for avoiding errors p b background b in kxml end tag had no arguments and non matching tags were very difficult to find if namespace is null no namespace prefix is printed but just name if namespace is empty string then serialzier will make sure that default empty namespace is declared in xml 1 0 xmlns xml serializer end tag string namespace string name endtag xmlserializer endtag writes text where special xml chars are escaped automatically xml serializer text string text xmlserializer writes text where special xml chars are escaped automatically xml serializer text char buf int start int len xmlserializer throws io exception illegal argument exception illegal state exception void cdsect string text throws io exception illegal argument exception illegal state exception ioexception illegalargumentexception illegalstateexception ioexception illegalargumentexception illegalstateexception void cdsect string text throws io exception illegal argument exception illegal state exception void entity ref string text throws io exception illegal argument exception illegal state exception ioexception illegalargumentexception illegalstateexception entityref ioexception illegalargumentexception illegalstateexception void entity ref string text throws io exception illegal argument exception illegal state exception void processing instruction string text throws io exception illegal argument exception illegal state exception entityref ioexception illegalargumentexception illegalstateexception processinginstruction ioexception illegalargumentexception illegalstateexception void processing instruction string text throws io exception illegal argument exception illegal state exception void comment string text throws io exception illegal argument exception illegal state exception processinginstruction ioexception illegalargumentexception illegalstateexception ioexception illegalargumentexception illegalstateexception void comment string text throws io exception illegal argument exception illegal state exception void docdecl string text throws io exception illegal argument exception illegal state exception ioexception illegalargumentexception illegalstateexception ioexception illegalargumentexception illegalstateexception void docdecl string text throws io exception illegal argument exception illegal state exception void ignorable whitespace string text throws io exception illegal argument exception illegal state exception ioexception illegalargumentexception illegalstateexception ignorablewhitespace ioexception illegalargumentexception illegalstateexception write all pending output to the stream if method start tag or attribute was called then start tag is closed final gt before flush is called on underlying output stream p b note b if there is need to close start tag so no more attribute calls are allowed but without flushinging output call method text with empty string text void flush starttag use this call to change the general behaviour of the parser such as namespace processing or doctype declaration handling this method must be called before the first call to next or next token otherwise an exception is thrown p example call set feature feature process namespaces true in order to switch on namespace processing the initial settings correspond to the properties requested from the xml pull parser factory if none were requested all feautures are deactivated by default exception xml pull parser exception if the feature is not supported or can not be set exception illegal argument exception if string with the feature name is null void set feature string name nexttoken setfeature feature_process_namespaces xmlpullparserexception illegalargumentexception setfeature returns the current value of the given feature p strong please note strong unknown features are strong always strong returned as false param name the name of feature to be retrieved return the value of the feature exception illegal argument exception if string the feature name is null illegalargumentexception set the value of a property the property name is any fully qualified uri exception xml pull parser exception if the property is not supported or can not be set exception illegal argument exception if string with the property name is null void set property string name xmlpullparserexception illegalargumentexception setproperty look up the value of a property the property name is any fully qualified uri p strong note strong unknown properties are strong always strong returned as null param name the name of property to be retrieved return the value of named property set the input source for parser to the given reader and resets the parser the event type is set to the initial value start document setting the reader to null will just stop parsing and reset parser state allowing the parser to free internal resources such as parsing buffers start_document sets the input stream the parser is going to process this call resets the parser state and sets the event type to the initial value start document p strong note strong if an input encoding string is passed it must be used otherwise if input encoding is null the parser should try to determine input encoding following xml 1 0 specification see below if encoding detection is supported then following feature a href http xmlpull org v1 doc features html detect encoding http xmlpull org v1 doc features html detect encoding a must be true amd otherwise it must be false param input stream contains a raw byte input stream of possibly unknown encoding when input encoding is null param input encoding if not null it must be used as encoding for input stream void set input input stream input stream string input encoding start_document inputencoding inputstream inputencoding inputencoding inputstream setinput inputstream inputstream inputencoding returns the input encoding if known null otherwise if set input input stream input encoding was called with an input encoding value other than null this value must be returned from this method otherwise if input encoding is null and the parser suppports the encoding detection feature http xmlpull org v1 doc features html detect encoding it must return the detected encoding if set input reader was called null is returned after first call to next if xml declaration was present this method will return encoding declared setinput inputstream inputencoding inputencoding inputencoding setinput set new value for entity replacement text as defined in a href http www w3 org tr rec xml intern replacement xml 1 0 section 4 5 construction of internal entity replacement text a if feature process docdecl or feature validation are set calling this function will result in an exception when processing of docdecl is enabled there is no need to the entity replacement text manually p the motivation for this function is to allow very small implementations of xmlpull that will work in j2me environments though these implementations may not be able to process the document type declaration they still can work with known dt ds by using this function p b please notes b the given value is used literally as replacement text and it corresponds to declaring entity in dtd that has all special characters escaped left angle bracket is replaced with amp lt ampersnad with amp amp and so on p b note b the given value is the literal replacement text and must not contain any other entity reference if it contains any entity reference there will be no further replacement p b note b the list of pre defined entity names will always contain standard xml entities such as amp amp amp lt amp lt gt amp gt quot amp quot and apos amp apos those cannot be redefined by this method see set input see feature process docdecl see feature validation void define entity replacement text string entity name feature_process_docdecl feature_validation dtds setinput feature_process_docdecl feature_validation defineentityreplacementtext entityname returns the numbers of elements in the namespace stack for the given depth if namespaces are not enabled 0 is returned p b note b when parser is on end tag then it is allowed to call this function with get depth 1 argument to retrieve position of namespace prefixes and ur is that were declared on corresponding start tag p b note b to retrieve lsit of namespaces declared in current element pre xml pull parser pp int ns start pp get namespace count pp get depth 1 int ns end pp get namespace count pp get depth for int i ns start i ns end i string prefix pp get namespace prefix i string ns pp get namespace uri i pre see get namespace prefix see get namespace uri see get namespace see get namespace string end_tag getdepth uris start_tag xmlpullparser nsstart getnamespacecount getdepth nsend getnamespacecount getdepth nsstart nsend getnamespaceprefix getnamespaceuri getnamespaceprefix getnamespaceuri getnamespace getnamespace returns the namespace prefixe for the given position in the namespace stack default namespace declaration xmlns will have null as prefix if the given index is out of range an exception is thrown p b please note b when the parser is on an end tag namespace prefixes that were declared in the corresponding start tag are still accessible although they are no longer in scope end_tag start_tag returns the namespace uri for the given position in the namespace stack if the position is out of range an exception is thrown p b note b when parser is on end tag then namespace prefixes that were declared in corresponding start tag are still accessible even though they are not in scope end_tag start_tag returns the uri corresponding to the given prefix depending on current state of the parser p if the prefix was not declared in the current scope null is returned the default namespace is included in the namespace table and is available via get namespace null p this method is a convenience method for pre for int i get namespace count get depth 1 i 0 i if get namespace prefix i equals prefix return get namespace uri i return null pre p strong please note strong parser implementations may provide more efifcient lookup e g using a hashtable the xml prefix is bound to http www w3 org xml 1998 namespace as defined in the a href http www w3 org tr rec xml names ns using namespaces in xml a specification analogous the xmlns prefix is resolved to a href http www w3 org 2000 xmlns http www w3 org 2000 xmlns a see get namespace count see get namespace prefix see get namespace uri getnamespace getnamespacecount getdepth getnamespaceprefix getnamespaceuri getnamespacecount getnamespaceprefix getnamespaceuri returns the current depth of the element outside the root element the depth is 0 the depth is incremented by 1 when a start tag is reached the depth is decremented after the end tag event was observed pre lt outside gt 0 lt root 1 sometext 1 lt foobar gt 2 lt foobar gt 2 lt root gt 1 lt outside gt 0 pre returns a short text describing the current parser state including the position a description of the current event and the data source if known this method is especially useful to provide meaningful error messages and for debugging purposes returns the current line number starting from 1 when the parser does not know the current line number or can not determine it 1 is returned e g for wbxml return current line number or 1 if unknown returns the current column number starting from 0 when the parser does not know the current column number or can not determine it 1 is returned e g for wbxml return current column number or 1 if unknown checks whether the current text event contains only whitespace characters for ignorable whitespace this is always true for text and cdsect false is returned when the current event text contains at least one non white space character for any other event type an exception is thrown p b please note b non validating parsers are not able to distinguish whitespace and ignorable whitespace except from whitespace outside the root element ignorable whitespace is reported as separate event which is exposed via next token only ignorable_whitespace nexttoken returns the text content of the current event as string the value returned depends on current event type for example for text event it is element content this is typical case when next is used see description of next token for detailed description of possible returned values for different types of events p strong note strong in case of entity ref this method returns the entity replacement text or null if not available this is the only case where get text and get text characters return different values see get event type see next see next token nexttoken entity_ref gettext gettextcharacters geteventtype nexttoken returns the buffer that contains the text of the current event as well as the start offset and length relevant for the current event see get text next and next token for description of possible returned values p strong please note strong this buffer must not be modified and its content may change after a call to next or next token this method will always return the same value as get text except for entity ref in the case of entity ref get text returns the replacement text and this method returns the actual input buffer containing the entity name if get text returns null this method returns null as well and the values returned in the holder array must be 1 both start and length see get text see next see next token param holder for start and length must hold an 2 element int array into which the start offset and length values will be written return char buffer that contains the text of the current event null if the current event has no text associated gettext nexttoken nexttoken gettext entity_ref gettext gettext gettext nexttoken holderforstartandlength returns the namespace uri of the current element the default namespace is represented as empty string if namespaces are not enabled an empty string is always returned the current event must be start tag or end tag otherwise null is returned start_tag end_tag for start tag or end tag events the local name of the current element is returned when namespaces are enabled when namespace processing is disabled the raw name is returned for entity ref events the entity name is returned if the current event is not start tag end tag or entity ref null is returned p b please note b to reconstruct the raw element name when namespaces are enabled and the prefix is not null you will need to add the prefix and a colon to local name start_tag end_tag entity_ref start_tag end_tag entity_ref localname returns the prefix of the current element if the element is in the default namespace has no prefix null is returned if namespaces are not enabled or the current event is not start tag or end tag null is returned start_tag end_tag returns true if the current event is start tag and the tag is degenerated e g lt foobar gt p b note b if the parser is not on start tag an exception will be thrown start_tag start_tag returns the number of attributes of the current start tag or 1 if the current event type is not start tag see get attribute namespace see get attribute name see get attribute prefix see get attribute value start_tag getattributenamespace getattributename getattributeprefix getattributevalue returns the namespace uri of the attribute with the given index starts from 0 returns an empty string if namespaces are not enabled or the attribute has no namespace throws an index out of bounds exception if the index is out of range or the current event type is not start tag p strong note strong if feature report namespace attributes is set then namespace attributes xmlns ns must be reported with namespace a href http www w3 org 2000 xmlns http www w3 org 2000 xmlns a visit this url for description the default namespace attribute xmlns will be reported with empty namespace p strong note strong the xml prefix is bound as defined in a href http www w3 org tr rec xml names ns using namespaces in xml a specification to http www w3 org xml 1998 namespace param zero based index of attribute return attribute namespace empty string is returned if namesapces processing is not enabled or namespaces processing is enabled but attribute has no namespace it has no prefix indexoutofboundsexception start_tag feature_report_namespace_attributes returns the local name of the specified attribute if namespaces are enabled or just attribute name if namespaces are disabled throws an index out of bounds exception if the index is out of range or current event type is not start tag param zero based index of attribute return attribute name null is never returned indexoutofboundsexception start_tag returns the prefix of the specified attribute returns null if the element has no prefix if namespaces are disabled it will always return null throws an index out of bounds exception if the index is out of range or current event type is not start tag param zero based index of attribute return attribute prefix or null if namespaces processing is not enabled indexoutofboundsexception start_tag returns the type of the specified attribute if parser is non validating it must return cdata param zero based index of attribute return attribute type null is never returned returns if the specified attribute was not in input was declared in xml if parser is non validating it must always return false this information is part of xml infoset param zero based index of attribute return false if attribute was in input returns the given attributes value throws an index out of bounds exception if the index is out of range or current event type is not start tag p strong note strong attribute value must be normalized including entity replacement text if process docdecl is false as described in a href http www w3 org tr rec xml av normalize xml 1 0 section 3 3 3 attribute value normalization a see define entity replacement text param zero based index of attribute return value of attribute null is never returned indexoutofboundsexception start_tag process_docdecl avnormalize defineentityreplacementtext returns the attributes value identified by namespace uri and namespace local name if namespaces are disabled namespace must be null if current event type is not start tag then index out of bounds exception will be thrown p strong note strong attribute value must be normalized including entity replacement text if process docdecl is false as described in a href http www w3 org tr rec xml av normalize xml 1 0 section 3 3 3 attribute value normalization a see define entity replacement text param namespace namespace of the attribute if namespaces are enabled otherwise must be null param name if namespaces enabled local name of attribute otherwise just attribute name return value of attribute or null if attribute with given name does not exist string get attribute value string namespace localname start_tag indexoutofboundsexception process_docdecl avnormalize defineentityreplacementtext getattributevalue returns the type of the current event start tag end tag text etc see next see next token int get event type start_tag end_tag nexttoken geteventtype get next parsing event element content wil be coalesced and only one text event must be returned for whole element content comments and processing instructions will be ignored and emtity references must be expanded or exception mus be thrown if entity reerence can not be exapnded if element content is empty content is then no text event will be reported p b note b empty element such as lt tag will be reported with two separate events start tag end tag it must be so to preserve parsing equivalency of empty element to lt tag lt tag see is empty element tag see is empty element tag see start tag see text see end tag see end document int next start_tag end_tag isemptyelementtag isemptyelementtag start_tag end_tag end_document this method works similarly to next but will expose additional event types comment cdsect docdecl entity ref processing instruction or ignorable whitespace if they are available in input p if special feature a href http xmlpull org v1 doc features html xml roundtrip feature xml roundtrip a identified by uri http xmlpull org v1 doc features html xml roundtrip is enabled it is possible to do xml document round trip ie reproduce exectly on output the xml input using get text returned content is always unnormalized exactly as in input otherwise returned content is end of line normalized as described a href http www w3 org tr rec xml sec line ends xml 1 0 end of line handling a and also when this feature is enabled exact content of start tag end tag docdecl and processing instruction is available p here is the list of tokens that can be returned from next token and what get text and get text characters returns dl dt start document dd null dt end document dd null dt start tag dd null unless feature xml roundtrip enabled and then returns xml tag ex lt tag attr val dt end tag dd null unless feature xml roundtrip id enabled and then returns xml tag ex lt tag dt text dd return element content br note that element content may be delivered in multiple consecutive text events dt ignorable whitespace dd return characters that are determined to be ignorable white space if the feature xml roundtrip is enabled all whitespace content outside root element will always reported as ignorable whitespace otherise rteporting is optional br note that element content may be delevered in multiple consecutive ignorable whitespace events dt cdsect dd return text em inside em cdata ex fo lt o from lt cdata fo lt o dt processing instruction dd if feature xml roundtrip is true return exact pi content ex pi foo from lt pi foo otherwise it may be exact pi content or concatenation of pi target space and data so for example for lt target data string quot target data quot may be returned if feature xml roundtrip is false dt comment dd return comment content ex foo bar from lt foo bar dt entity ref dd get text must return entity replacement text if process docdecl is false otherwise get text may return null additionally get text characters must return entity name for example entity name for amp entity name br b note b this is the only place where value returned from get text and get text characters b are different b br b note b it is user responsibility to resolve entity reference if process docdecl is false and there is no entity replacement text set in define entity replacement text method get text will be null br b note b character entities ex amp 32 and standard entities such as amp amp amp lt amp gt amp quot amp apos are reported as well and are b not b reported as text tokens but as entity ref tokens this requirement is added to allow to do roundtrip of xml documents dt docdecl dd if feature xml roundtrip is true or process docdecl is false then return what is inside of docdecl for example it returns pre quot titlepage system http www foo bar dtds typo dtd lt entity active links include quot pre p for input document that contained pre lt doctype titlepage system http www foo bar dtds typo dtd lt entity active links include pre otherwise if feature xml roundtrip is false and process docdecl is true then what is returned is undefined it may be even null dd dl p strong note strong there is no gurantee that there will only one text or ignorable whitespace event from next token as parser may chose to deliver element content in multiple tokens dividing element content into chunks p strong note strong whether returned text of token is end of line normalized is depending on feature xml roundtrip p strong note strong xml decl lt xml gt is not reported but its content is available through optional properties see class description above see next see start tag see text see end tag see end document see comment see docdecl see processing instruction see entity ref see ignorable whitespace int next token entity_ref processing_instruction ignorable_whitespace feature_xml_roundtrip gettext start_tag end_tag processing_instruction nexttoken gettext gettextcharacters start_document end_document start_tag feature_xml_roundtrip end_tag feature_xml_roundtrip ignorable_whitespace feature_xml_roundtrip ignorable_whitespace ignorable_whitespace processing_instruction feature_xml_roundtrip feature_xml_roundtrip entity_ref gettext process_docdecl gettext gettextcharacters entity_name entity_name gettext gettextcharacters process_docdecl defineentityreplacementtext gettext entity_ref feature_xml_roundtrip process_docdecl feature_xml_roundtrip process_docdecl ignorable_whitespace nexttoken feature_xml_roundtrip xmldecl start_tag end_tag end_document processing_instruction entity_ref ignorable_whitespace nexttoken test if the current event is of the given type and if the namespace and name do match null will match any namespace and any name if the test is not passed an exception is thrown the exception text indicates the parser position the expected event and the current event that is not meeting the requirement p essentially it does this pre if type get event type namespace null amp amp namespace equals get namespace name null amp amp name equals get name throw new xml pull parser exception expected types type get position description pre void require int type string namespace string name geteventtype getnamespace getname xmlpullparserexception getpositiondescription if current event is start tag then if next element is text then element content is returned or if next event is end tag then empty string is returned otherwise exception is thrown after calling this function successfully parser will be positioned on end tag p the motivation for this function is to allow to parse consistently both empty elements and elements that has non empty content for example for input ol li lt tag gt foo lt tag gt li lt tag gt lt tag gt which is equivalent to lt tag gt both input can be parsed with the same code pre p next tag p require event p start tag tag string content p next text p require event p end tag tag pre this function together with next tag make it very easy to parse xml that has no mixed content p essentially it does this pre if get event type start tag throw new xml pull parser exception parser must be on start tag to read next text this null int event type next if event type text string result get text event type next if event type end tag throw new xml pull parser exception event text it must be immediately followed by end tag this null return result else if event type end tag return else throw new xml pull parser exception parser must be on start tag or text to read text this null pre start_tag end_tag end_tag nexttag requireevent start_tag nexttext requireevent end_tag nexttag geteventtype start_tag xmlpullparserexception start_tag eventtype eventtype gettext eventtype eventtype end_tag xmlpullparserexception end_tag eventtype end_tag xmlpullparserexception start_tag call next and return event if it is start tag or end tag otherwise throw an exception it will skip whitespace text before actual tag if any p essentially it does this pre int event type next if event type text amp amp is whitespace skip whitespace event type next if event type start tag amp amp event type end tag throw new xml pull parser exception expected start or end tag this null return event type pre start_tag end_tag eventtype eventtype iswhitespace eventtype eventtype start_tag eventtype end_tag xmlpullparserexception eventtype public interface event listener public void event notify received string uuid long seq string var name string value eventlistener eventnotifyreceived varname public interface notify listener public void device notify received ssdp packet ssdp packet notifylistener devicenotifyreceived ssdppacket ssdppacket public interface search listener public void device search received ssdp packet ssdp packet searchlistener devicesearchreceived ssdppacket ssdppacket public interface device change listener public void device added device dev devicechangelistener deviceadded public void device added device dev public void device removed device dev deviceadded deviceremoved public interface search response listener public void device search response received ssdp packet ssdp packet searchresponselistener devicesearchresponsereceived ssdppacket ssdppacket public interface action listener public boolean action control received action action actionlistener actioncontrolreceived public interface query listener public boolean query control received state variable state var querylistener querycontrolreceived statevariable statevar public interface http request listener public void http request recieved http request http req httprequestlistener httprequestrecieved httprequest httpreq public interface data fetcher public string getsnmpoid datafetcher must return an integer or a string public object getsnmp data getsnmpdata return null when the last oid is reached public string getsnmpoid int index must return an integer or a string public object getsnmp data string oid getsnmpdata interface dns listener update a dns record void update record jmdns impl jmdns long now dns record record dnslistener updaterecord jmdnsimpl dnsrecord a new service type was discovered param event the service event providing the fully qualified type of the service a service has been added param event the service event providing the name and fully qualified type of the service serviceevent a service has been removed param event the service event providing the name and fully qualified type of the service serviceevent a service has been resolved its details are now available in the service info record param event the service event providing the name the fully qualified type of the service and the service info record or null if the service could not be resolved serviceinfo serviceevent public interface web page actually generates the page s content public void make webpage public void make return the html code of this web page public string tohtml webpage public interface ft identity public void initialize transient ext object container mydb identity manager my identity manager ftidentity initializetransient extobjectcontainer identitymanager myidentitymanager public void initialize transient ext object container mydb identity manager my identity manager public string getuid initializetransient extobjectcontainer identitymanager myidentitymanager public string getuid return the requesturi link freeneturi to fetch this identity public freeneturi get requesturi getrequesturi public freeneturi get requesturi public string get nickname getrequesturi getnickname public string get nickname public string get freetalk address getnickname getfreetalkaddress public interface ft own identity extends ft identity public freeneturi get inserturi ftownidentity ftidentity getinserturi public freeneturi get inserturi public boolean wants messages from ft identity identity getinserturi wantsmessagesfrom ftidentity public boolean wants messages from ft identity identity public void subscribe to board board board wantsmessagesfrom ftidentity subscribetoboard public void subscribe to board board board public void unsubscribe from board board board subscribetoboard unsubscribefromboard public void unsubscribe from board board board public iterator board subscribed boards iterator unsubscribefromboard subscribedboardsiterator public interface running average extends serializable public object clone runningaverage public object clone public double current value currentvalue public double current value public void report double d currentvalue public void report double d public void report long d get what current value would be if we reported some given value param r the value to mimic reporting return the output of current value if we were to report r currentvalue currentvalue return the total number of reports on this running average so far used for weighted averages confidence newbieness estimation etc runningaverage public interface serializable to field set bucket extends bucket public simple field set to field set serializabletofieldsetbucket simplefieldset tofieldset public interface line reader read a n or r n terminated line of utf 8 or iso 8859 1 public string read line int max length int buffer size boolean utf throws io exception linereader readline maxlength buffersize ioexception public interface persistent file tracker public void register file file persistentfiletracker notify that we have finished with a bucket and it should be freed after the next serialization to disk param bucket the bucket to free should be a delayed free bucket delayedfreebucket public void delayed free bucket delayed free bucket bucket get the persistent temp files directory public file get dir delayedfreebucket delayedfreebucket getdir public file get dir is the file in question one of our persistent temp files public boolean matches file file getdir public boolean matches file file public filename generator get generator filenamegenerator getgenerator public filename generator get generator public long getid file file filenamegenerator getgenerator public interface random access thing extends closeable public long size throws io exception randomaccessthing ioexception public long size throws io exception public void pread long file offset byte buf int buf offset int length throws io exception ioexception fileoffset bufoffset ioexception public void pread long file offset byte buf int buf offset int length throws io exception public void pwrite long file offset byte buf int buf offset int length throws io exception fileoffset bufoffset ioexception fileoffset bufoffset ioexception public void pwrite long file offset byte buf int buf offset int length throws io exception public void close fileoffset bufoffset ioexception compressor type string name compressor c short metadataid this name name this compressor c this metadataid metadataid compressor_type public static compressor type get compressor by metadataid short id compressor type values values for compressor type current values if current metadataid id return current return null compressor_type getcompressorbymetadataid compressor_type compressor_type public bucket compress bucket data bucket factory bf long max read length long max write length throws io exception compression output size exception if compressor null db4o voodoo see below if name null return get official compress data bf max read length max write length return compressor compress data bf max read length max write length bucketfactory maxreadlength maxwritelength ioexception compressionoutputsizeexception getofficial maxreadlength maxwritelength maxreadlength maxwritelength public bucket decompress bucket data bucket factory bucket factory long max length long max estimate size length bucket preferred throws io exception compression output size exception if compressor null db4o voodoo see below if name null return get official decompress data bucket factory max length max estimate size length preferred return compressor decompress data bucket factory max length max estimate size length preferred bucketfactory bucketfactory maxlength maxestimatesizelength ioexception compressionoutputsizeexception getofficial bucketfactory maxlength maxestimatesizelength bucketfactory maxlength maxestimatesizelength public int decompress byte dbuf int i int j byte output throws compression output size exception if compressor null db4o voodoo see below if name null return get official decompress dbuf i j output return compressor decompress dbuf i j output compressionoutputsizeexception getofficial private compressor get official if name equals gzip return gzip if name equals bzip2 return bzip2 if name equals lzma return lzma return null getofficial public boolean object can deactivate object container container do not deactivate the official compressor type s if is official return false return true objectcandeactivate objectcontainer compressor_type isofficial public boolean object can activate object container container do not activate the official compressor type s if is official return false return true objectcanactivate objectcontainer compressor_type isofficial public boolean is official return this gzip this bzip2 this lzma isofficial compress the data param data the bucket to read from param bf the means to create a new bucket param max read length the maximum number of bytes to read from the input bucket param max write length the maximum number of bytes to write to the output bucket if this is exceeded throw a compression output size exception return the compressed data throws io exception if an error occurs reading or writing data throws compression output size exception if the compressed data is larger than max write length maxreadlength maxwritelength compressionoutputsizeexception ioexception compressionoutputsizeexception maxwritelength decompress data param data the data to decompress param bucket factory a bucket factory to create a new bucket with if necessary param max length the maximum length to decompress we throw if more is present param max estimate size length if the data is too big and this is 0 read up to this many bytes in order to try to get the data size param preferred a bucket to use instead if null we allocate one from the bucket factory return throws io exception throws compression output size exception bucketfactory bucketfactory maxlength maxestimatesizelength bucketfactory ioexception compressionoutputsizeexception decompress in ram only param dbuf input buffer param i offset to start reading from param j number of bytes to read param output output buffer throws decompress exception throws compression output size exception returns the number of bytes actually written decompressexception compressionoutputsizeexception public interface compress job public abstract void try compress client context context throws insert exception compressjob trycompress clientcontext insertexception public interface compress job public abstract void try compress client context context throws insert exception public abstract void on failure insert exception e client put state c client context context compressjob trycompress clientcontext insertexception onfailure insertexception clientputstate clientcontext public interface bucket factory create a bucket param size the maximum size of the data or 1 if we don t know some buckets will throw io exception if you go over this length return throws io exception bucketfactory ioexception ioexception the path of this request where the part of the path the specified the plugin has already been removed return true if the query string was totally empty check if a parameter was set in the request at all either with or without a value param name the name of the parameter to check return true if the parameter was set in the request not regarding if the value is empty get the value of a request parameter using an empty string as default value if the parameter was not set this method will never return null so its safe to do things like p code if request get param quot abc quot equals quot def quot code p param name the name of the parameter to get return the parameter value as string or an empty string if the value was missing or empty getparam get the value of a request parameter using the specified default value if the parameter was not set or has an empty value param name the name of the parameter to get param default value the default value to be returned if the parameter is missing or empty return either the parameter value as string or the default value defaultvalue get the value of a request parameter converted to an int using 0 as default value if there are multiple values for this parameter the first value is used param name the name of the parameter to get return either the parameter value as int or 0 if the parameter is missing empty or invalid get the value of a request parameter converted to an code int code using the specified default value if there are multiple values for this parameter the first value is used param name the name of the parameter to get param default value the default value to be returned if the parameter is missing empty or invalid return either the parameter value as int or the default value defaultvalue public int get int param string name int default value public int get int part string name int default value getintparam defaultvalue getintpart defaultvalue get all values of a request parameter as a string array if the parameter was not set at all an empty array is returned so this method will never return code null code param name the name of the parameter to get return an array of all paramter values that might include empty values get all values of a request parameter as int array ignoring all values that can not be parsed if the parameter was not set at all an empty array is returned so this method will never return code null code param name the name of the parameter to get return an int array of all parameter values that could be parsed as int public int get multiple int param string name public http uploaded file get uploaded file string name getmultipleintparam httpuploadedfile getuploadedfile public http uploaded file get uploaded file string name public bucket get part string name httpuploadedfile getuploadedfile getpart public bucket get part string name public boolean is part set string name getpart ispartset get a request part as a string parameters are passed in through the url parts are passed in through attached data public string get part as string string name int maxlength public byte get part as bytes string name int maxlength getpartasstring getpartasbytes public byte get part as bytes string name int maxlength public void free parts getpartasbytes freeparts public void free parts public long get long param string name long default value freeparts getlongparam defaultvalue returns the content type of the file return the content type of the file returns the data of the file return the data of the file returns the name of the file return the name of the file returns an output stream that is used to put data in this bucket from the beginning it is not possible to append data to a bucket this simplifies the code significantly for some classes if you need to append just pass the output stream around outputstream outputstream returns an input stream that reads data from this bucket if there is no data in this bucket null is returned inputstream returns a name for the bucket may be used to identify them in certain in certain situations public string get name returns the amount of data currently in this bucket public long size getname public long size is the bucket read only public boolean is read only isreadonly public boolean is read only make the bucket read only irreversible public void set read only isreadonly setreadonly public void set read only free the bucket if supported public void free setreadonly write the bucket and all its dependancies to the database update the stored copy and its dependancies if necessary remove the bucket and everything under it from the database you don t need to call this if it hasn t been store to ed buckets that use the database internally will run a blocking job to delete internal structure in free param container the database storeto create a shallow read only copy of this bucket using different objects but using the same external storage if this is not possible return null note that if the underlying bucket is deleted the copy will become invalid and probably throw an io exception on read or possibly return too short data etc in some use cases e g on fproxy this is acceptable ioexception public interface amdcpu info extends cpu info return true iff the cpu present in the machine is at least an k6 cpu public boolean isk6 compatible amdcpuinfo cpuinfo isk6compatible public boolean isk6 compatible return true iff the cpu present in the machine is at least an k6 2 cpu public boolean isk6 2 compatible isk6compatible isk6_2_compatible public boolean isk6 2 compatible return true iff the cpu present in the machine is at least an k6 3 cpu public boolean isk6 3 compatible isk6_2_compatible isk6_3_compatible public boolean isk6 3 compatible return true iff the cpu present in the machine is at least an k7 cpu atlhon duron etc and better public boolean is athlon compatible isk6_3_compatible isathloncompatible public boolean is athlon compatible return true iff the cpu present in the machine is at least an k8 cpu atlhon 64 opteron etc and better public boolean is athlon64 compatible isathloncompatible isathlon64compatible public interface intelcpu info extends cpu info return true iff the cpu is at least a pentium cpu public boolean is pentium compatible intelcpuinfo cpuinfo ispentiumcompatible public boolean is pentium compatible return true iff the cpu is at least a pentium which implements the mmx instruction feature set public boolean is pentiummmx compatible ispentiumcompatible ispentiummmxcompatible public boolean is pentiummmx compatible return true iff the cpu implements at least the p6 instruction set pentium ii or better please note that an pentim pro cpu causes should cause this method to return false due to that cpu using a very early implementation of the p6 instruction set no mmx etc ispentiummmxcompatible pentimpro public boolean is pentium2 compatible return true iff the cpu implements at least a pentium iii level of the p6 instruction feature set public boolean is pentium3 compatible ispentium2compatible ispentium3compatible public boolean is pentium3 compatible return true iff the cpu implements at least a pentium iv level instruction feature set public boolean is pentium4 compatible ispentium3compatible ispentium4compatible public interface cpu info return a string indicating the vendor of the cpu public string get vendor cpuinfo getvendor public string get vendor return a string detailing what type of cpu that is present in the machine i e pentium iv etc throws unknowncpu exception if for any reson the retrieval of the requested information failed the message encapsulated in the execption indicates the cause of the failure getvendor unknowncpuexception public string getcpu model string throws unknowncpu exception return true iff the cpu support the mmx instruction set public boolean hasmmx getcpumodelstring unknowncpuexception public boolean hasmmx return true iff the cpu support the sse instruction set public boolean hassse public boolean hassse return true iff the cpu support the sse2 instruction set public boolean hassse2 public interface remove random remove and return a random random grab array item should be fast public random grab array item remove random random grab array item exclusion list excluding object container container client context context removerandom randomgrabarrayitem randomgrabarrayitem removerandom randomgrabarrayitemexclusionlist objectcontainer clientcontext public random grab array item remove random random grab array item exclusion list excluding object container container client context context just for consistency checking public boolean persistent randomgrabarrayitem removerandom randomgrabarrayitemexclusionlist objectcontainer clientcontext public boolean persistent public void remove from object container container removefrom objectcontainer public interface int numbered item int get number intnumbereditem getnumber public interface item t extends doubly linked list item get next link item may or may not return code null code if this is the last code item code see doubly linked list has next doublylinkedlist doublylinkedlist hasnext t get next set next link item t set next item i getnext setnext t set next item i get previous link item may or may not return code null code if this is the first code item code see doubly linked list has next setnext doublylinkedlist hasnext t get prev get previous link item t set prev item i getprev setprev t set prev item i return the contained list strong for sanity checking only strong doubly linked list super t get parent setprev doublylinkedlist getparent return the contained list strong for sanity checking only strong doubly linked list super t get parent set the contained list strong for sanity checking only strong doubly linked list super t set parent doubly linked list super t l doublylinkedlist getparent doublylinkedlist setparent doublylinkedlist clear this list void clear clear this list void clear return the size of this list int size return the size of this list int size check if this list is empty return code true code if this list is empty code false code otherwise boolean is empty isempty check if this list is empty return code true code if this list is empty code false code otherwise boolean is empty get a link enumeration of link doubly linked list item enumeration t elements for consistency w typical java api isempty doublylinkedlist enumeration t elements for consistency w typical java api returns true if the list contains an item i where code i equals item code is true public boolean contains t item returns the first item return the item at the head of the list or code null code if empty t head returns the last item return the item at the tail of the list or code null code if empty t tail puts the item before the first item void unshift t i void unshift t i removes and returns the first item t shift t shift remove tt n tt elements from head and return them as a code doubly linked list code doubly linked list t shift int n doublylinkedlist doublylinkedlist doubly linked list t shift int n puts the item after the last item void push t i doublylinkedlist void push t i removes and returns the last item t pop t pop remove tt n tt elements from tail and return them as a code doubly linked list code doubly linked list t pop int n doublylinkedlist doublylinkedlist doubly linked list t pop int n return code true code if code i code has next item ie not the last item code false code otherwise boolean has next t i doublylinkedlist hasnext return code true code if code i code has next item ie not the last item code false code otherwise boolean has next t i return code true code if code i code has previous item ie not the first item code false code otherwise boolean has prev t i hasnext hasprev boolean has prev t i return next item of code i code if this is the last element return code null code t next t i hasprev return next item of code i code if this is the last element return code null code t next t i return previous item of code i code if this is the first element return code null code t prev t i return previous item of code i code if this is the first element return code null code t prev t i remove and return a element return this item or code null code if the item was not in the list t remove t i t remove t i inserts item code j code before item code i code void insert prev t i t j insertprev void insert prev t i t j inserts item code j code after item code i code void insert next t i t j insertprev insertnext public interface oom hook handle running low of memory try to free some cache save the files etc oomhook void handle low memory throws exception handle running out of memory void handle out of memory throws exception handlelowmemory handleoutofmemory public interface remove random with object extends remove random public object get object removerandomwithobject removerandom getobject public object get object public boolean is empty getobject isempty public boolean is empty public void remove from object container container isempty removefrom objectcontainer if the specified remove random is empty remove it locking must be called with no locks held particularly no locks on the remove random because we take locks in order removerandom removerandom if true will be automatically removed from the rga and not returned true indicates that the item is no longer needed for some reason in a request usually that it has either been explicitly cancelled or that it is not needed because other queued blocks have been sufficient if it becomes useful again it must be re registered locking should hold as few locks as possible as this needs to be called while holding the rga lock s public boolean is empty object container container does this random grab array item support remembering where it is registered public boolean knows parent grab array isempty objectcontainer randomgrabarrayitem knowsparentgrabarray public boolean knows parent grab array notify the item that it has been registered on a specific random grab array public void set parent grab array random grab array parent object container container knowsparentgrabarray randomgrabarray setparentgrabarray randomgrabarray objectcontainer public void set parent grab array random grab array parent object container container if the item remembers its parent random grab array return it public random grab array get parent grab array setparentgrabarray randomgrabarray objectcontainer randomgrabarray randomgrabarray getparentgrabarray public random grab array get parent grab array this must be the same as the value passed into the rga constructor if the user doesn t implement persistence simply return false here and pass false into the constructor public boolean persistent randomgrabarray getparentgrabarray public interface random grab array item exclusion list whether this item can be returned right now public boolean exclude random grab array item item object container container client context context randomgrabarrayitemexclusionlist randomgrabarrayitem objectcontainer clientcontext public interface executor execute a job public void execute runnable job string job name jobname execute a job public void execute runnable job string job name public void execute runnable job string job name boolean from ticker jobname jobname fromticker public void execute runnable job string job name boolean from ticker count the number of threads waiting for work at each priority level public int waiting threads jobname fromticker waitingthreads count the number of threads waiting for work at each priority level public int waiting threads count the number of threads running at each priority level public int running threads waitingthreads runningthreads public int running threads fast method returning how many threads are waiting public int get waiting threads count runningthreads getwaitingthreadscount doubly linked list item t comparable t public abstract t get next doublylinkedlist getnext public abstract t get next public abstract t set next item i getnext setnext public abstract t set next item i public abstract t get prev setnext getprev public abstract t get prev public abstract t set prev item i getprev setprev updatable sorted linked list item t public object index value updatablesortedlinkedlistitem indexvalue public interface storable block public byte get routing key storableblock getroutingkey public byte get routing key public byte get full key getroutingkey getfullkey retrieve a block use the store callback to convert it to the appropriate type of block param routing key the routing key i e the database key under which the block is stored param dont promote if true don t promote the block to the top of the lru return a storable block or null if the key cannot be found throws io exception if a disk i o error occurs storecallback routingkey dontpromote storableblock ioexception store a block throws key collision exception if the key already exists and code callback collision possible code is code true code param overwrite if true overwrite old content rather than throwing a code key collision exception code public void put storable block block byte routingkey byte full key byte data byte header keycollisionexception collisionpossible keycollisionexception storableblock fullkey change the store size param max store keys the maximum number of keys to be cached param shrink now if false don t shrink the store immediately throws io exception throws database exception maxstorekeys shrinknow ioexception databaseexception public void set max keys long max store keys boolean shrink now throws database exception io exception public long get max keys setmaxkeys maxstorekeys shrinknow databaseexception ioexception getmaxkeys public long get max keys public long hits getmaxkeys public long hits public long misses public long misses public long writes public long writes public long key count keycount public long key count public long get bloom false positive keycount getbloomfalsepositive check if a routing key probably param routingkey return code false code b only b if the key does not exist in store public interface fred plugin themed public void set theme theme theme fredpluginthemed settheme public interface fred plugin real versioned the version of the plugin in a form that is easy to compare a long version 150 will always be later than version 20 public long get real version fredpluginrealversioned getrealversion public interface fred pluginip detector public detectedip get address fredpluginipdetector getaddress called when fred s list of public ports changes and just after loading the plugin param ports the set of ports that need to be forwarded from the outside world through the nat or firewall param cb callback to be called with success failure of each forward some plugins may return a probabilistic success e g with up p public interface fred plugin versioned public string get version fredpluginversioned getversion public interface fred pluginl10n public string get string string key fredpluginl10n getstring public string get string string key public void set language language new language getstring setlanguage newlanguage public interface fred plugin with class loader public void set class loader class loader my class loader fredpluginwithclassloader setclassloader classloader myclassloader param replysender interface to send a reply param params parameters passed in can be null param data a bucket of data passed in can be null param access 0 direct call plugin to plugin 1 fcp restricted access 2 fcp full access throws plugin not found exception if the plugin has already been removed pluginnotfoundexception public interface fred plugin bandwidth indicator return the reported upstream bit rate in bits per second 1 if it s not available blocking public int get upstram max bit rate fredpluginbandwidthindicator getupstrammaxbitrate public int get upstram max bit rate return the reported downstream bit rate in bits per second 1 if it s not available blocking public int get downstream max bit rate getupstrammaxbitrate getdownstreammaxbitrate if the uri fetches any data the plugin is revoked ul li plugin will be stopped and disabled li li stop updater li ul return freeneturi to watch an uri that points to plugin jarfile return freeneturi to look for next edition public interface fred pluginhttp let them return null if unhandled public string handlehttp get http request request throws pluginhttp exception fredpluginhttp handlehttpget httprequest pluginhttpexception let them return null if unhandled public string handlehttp get http request request throws pluginhttp exception public string handlehttp post http request request throws pluginhttp exception handlehttpget httprequest pluginhttpexception handlehttppost httprequest pluginhttpexception public interface forward port callback called to indicate status on one or more forwarded ports public void port forward status map forward port forward port status statuses forwardportcallback portforwardstatus forwardport forwardportstatus param pluginname reply from param indentifier identifer from your call param params parameters passed back param data a bucket of data passed back can be null http stuff has been moved to fred pluginhttp public void terminate fredpluginhttp public void terminate run the plugin called after node startup should be able to access queue etc at this point public void run plugin plugin respirator pr runplugin pluginrespirator can the user dismiss the alert if not it persists until it is unregistered public boolean user can dismiss title of alert must be short public string get title usercandismiss gettitle public string get title content of alert plain text public string get text gettitle gettext public string get text content of alert html public html node gethtml text gettext htmlnode gethtmltext really concise text of alert should be comfortably under a line even when translated into a verbose language will link to the full details public string get short text priority class public short get priority class getshorttext getpriorityclass is the alert valid right now suggested use is to synchronize on the alert then check this then get the data public boolean is valid public void is valid boolean validity isvalid isvalid public void is valid boolean validity public string dismiss button text isvalid dismissbuttontext public string dismiss button text public boolean should unregister on dismiss dismissbuttontext shouldunregisterondismiss public boolean should unregister on dismiss method to be called upon alert dismissal public void on dismiss shouldunregisterondismiss ondismiss returns a user specified object that can be used to identify this alert return the user specified identifier object return a unique short name for the alert can be simply hash code not visible to the user must not contain spaces or commas hashcode return true if this is an event notification event notifications can be bulk deleted eventually they will be handled diffferently logged to a separate event log and only the last few displayed on the homepage public interface request completion callback callback called when a request succeeds public void notify success client request req object container container requestcompletioncallback notifysuccess clientrequest objectcontainer public void notify success client request req object container container callback called when a request fails public void notify failure client request req object container container notifysuccess clientrequest objectcontainer notifyfailure clientrequest objectcontainer public void notify failure client request req object container container callback when a request is removed public void on remove client request req object container container notifyfailure clientrequest objectcontainer onremove clientrequest objectcontainer tell the scheduler that a request from a specific random grab array succeeded definition of succeeded will vary but the point is most schedulers will run another request from the parent grab array in the near future on the theory that if one works another may also work param req the request we ran which must be deleted randomgrabarray parentgrabarray after a key has been requested a few times it is added to the cooldown queue for a fixed period since it would be pointless to rerequest it especially given ulp rs note that while a key is on the cooldown queue its requestors will still be told if it is found by ulp rs or back door coalescing param key the key to be added return the time at which the key will leave the cooldown queue ulprs ulprs your max retry count less than this and more than 1 public static final int cooldown retries 3 public long count transient queued requests cooldown_retries counttransientqueuedrequests public long count transient queued requests public void queue fill request starter queue counttransientqueuedrequests queuefillrequeststarterqueue public void queue fill request starter queue public keys fetching locally fetching keys queuefillrequeststarterqueue keysfetchinglocally fetchingkeys public keys fetching locally fetching keys public void remove fetching key key key keysfetchinglocally fetchingkeys removefetchingkey public void remove fetching key key key public void call failure sendable get get low level get exception e int prio boolean persistent removefetchingkey callfailure sendableget lowlevelgetexception public void call failure sendable get get low level get exception e int prio boolean persistent public void call failure sendable insert insert low level put exception exception int prio boolean persistent callfailure sendableget lowlevelgetexception callfailure sendableinsert lowlevelputexception public void call failure sendable insert insert low level put exception exception int prio boolean persistent public fec queue getfec queue callfailure sendableinsert lowlevelputexception fecqueue getfecqueue public fec queue getfec queue public client context get context fecqueue getfecqueue clientcontext getcontext public client context get context public boolean add to fetching key key clientcontext getcontext addtofetching public boolean add to fetching key key public chosen block grab request addtofetching chosenblock grabrequest public chosen block grab request public void remove running request sendable request request chosenblock grabrequest removerunningrequest sendablerequest this only works for persistent requests because transient requests are not selected on a sendable request level they are selected on a sendable request token level sendablerequest sendablerequest public abstract boolean is running or queued persistent request sendable request request public boolean has fetching key key key isrunningorqueuedpersistentrequest sendablerequest hasfetchingkey public boolean has fetching key key key public void start node client core core hasfetchingkey nodeclientcore public void start node client core core public boolean add transient insert fetching sendable insert insert object token nodeclientcore addtransientinsertfetching sendableinsert public boolean add transient insert fetching sendable insert insert object token public void remove transient insert fetching sendable insert insert object token addtransientinsertfetching sendableinsert removetransientinsertfetching sendableinsert public interface request client is this request persistent must not change public boolean persistent requestclient public boolean persistent public void remove from object container container removefrom objectcontainer public interface security level listener t public void on change t old level t new level securitylevellistener onchange oldlevel newlevel public interface sendable request item called when a request is abandoned whether this is called on a successful request is up to the sendable request sender public void dump sendablerequestitem sendablerequestsender public interface supports bulk call failure process a whole batch of failures at once public abstract void on failure bulk call failure item items object container container client context context supportsbulkcallfailure onfailure bulkcallfailureitem objectcontainer clientcontext public interface prio runnable extends runnable public int get priority priorunnable getpriority public interface get pubkey look up a cached public key by its hash public abstract dsa public key get key byte hash getpubkey dsapublickey getkey public interface timed out nodes list long get timeout time peer node peer timedoutnodeslist gettimeouttime peernode static final long min delay 20 get the current inter request delay public abstract long get delay min_delay getdelay only called by request starter start the actual request using the node client core provided and the key and key number earlier got from choose key the request itself may have been removed from the overall queue already for persistent requests the callbacks will be called on the database thread and we will delete the persistent chosen request from there before committing param sched the scheduler this request has just been grabbed from param request the chosen block containing the key the sendable request item and the methods to call to indicate success failure return true if a request was sent false otherwise in which case the request will be removed if it hasn t already been requeststarter nodeclientcore choosekey persistentchosenrequest chosenblock sendablerequestitem public interface persistable simple field set persist throttles to field set simplefieldset persistthrottlestofieldset public interface ticker public abstract void queue timed job runnable job long offset queuetimedjob public abstract void queue timed job runnable job long offset public abstract void queue timed job runnable job string name long offset boolean run on ticker anyway queuetimedjob queuetimedjob runontickeranyway is this key currently being fetched locally locking this should be safe just about anywhere the lock protecting it is always taken last is this request token pair being executed this applies only to non persistent inserts because persistent requests and inserts are selected on a request level and requests use has key also activation issues with sendable request meaning getting a hash code would be problematic haskey sendablerequest public interface node to node message listener public void handle message byte data boolean from darknet peer node source int type nodetonodemessagelistener handlemessage fromdarknet peernode public interface probe callback void on completed string reason double target double best double nearest long id short counter short unique counter short linear counter probecallback oncompleted uniquecounter linearcounter void on completed string reason double target double best double nearest long id short counter short unique counter short linear counter void on trace long uid double target double nearest double best short htl short counter double location long nodeuid double peer locs long peerui ds double locs not visited short fork count short linear count string reason long prevuid oncompleted uniquecounter linearcounter ontrace peerlocs peeruids locsnotvisited forkcount linearcount got a rejected overload passed down from some upstream node note that not all probe request implementations may generate these rejectedoverload build one or more packets and send them from a whole bunch of messages if any message item s are formatted already they will be sent as single packets any packets which cannot be sent will be requeued on the peer node param one packet only if true we will only send one packet and will requeue any messages that don t fit in that single packet return true if we sent a packet throws blocked too long exception public boolean process outgoing or requeue message item messages peer node pn messageitem peernode onepacketonly blockedtoolongexception processoutgoingorrequeue messageitem peernode resend a single packet param kt the session key on which to send the packet sessionkey build a packet and send it from a message recently converted into byte but with no outer formatting throws packet sequence exception throws would block exception return total size including udp headers of the sent packet public int process outgoing byte buf int offset int length session key tracker short priority throws key changed exception not connected exception packetsequenceexception wouldblockexception processoutgoing sessionkey keychangedexception notconnectedexception encrypt a packet prepend packet acks and packet resend requests and send it the provided data is ready formatted meaning that it already has the message length s and message counts param buf buffer to read data from param offset point at which to start reading param length number of bytes to read param tracker the session key to use to encrypt the packet and send it to the associated peer node param packet number if specified force use of this particular packet number means this is a resend of a dropped packet throws not connected exception if the node is not connected throws key changed exception if the primary key changes while we are trying to send this packet throws packet sequence exception throws would block exception if we cannot allocate a packet number because it would block return the size of the sent packet public int process outgoing preformatted byte buf int offset int length session key tracker int packet number async message callback callbacks short priority throws key changed exception not connected exception sessionkey peernode packetnumber notconnectedexception keychangedexception packetsequenceexception wouldblockexception processoutgoingpreformatted sessionkey packetnumber asyncmessagecallback keychangedexception notconnectedexception send a handshake if possible to the node param pn public void send handshake peer node pn boolean not registered is a peer disconnected public boolean is disconnected peer context context sendhandshake peernode notregistered isdisconnected peercontext public boolean is disconnected peer context context list of supported negotiation types in preference order best last public int supported neg types isdisconnected peercontext supportednegtypes public int supported neg types size of the packet headers in bytes assuming only one message in this packet public int full headers length one message supportednegtypes fullheaderslengthonemessage public int full headers length one message the socket handler we are connected to public socket handler get socket handler fullheaderslengthonemessage sockethandler sockethandler getsockethandler public socket handler get socket handler get our addresses as peers public peer get primaryip address sockethandler getsockethandler getprimaryipaddress public peer get primaryip address get our compressed noderef public byte get compressed noderef getprimaryipaddress getcompressednoderef public byte get compressed noderef always allow local addresses public boolean always allow local addresses getcompressednoderef alwaysallowlocaladdresses port forwarding status return a status code from address tracker fixme make this more generic when we need to addresstracker is there any reason not to allow this connection e g limits on the number of nodes on a specific ip address public boolean allow connection peer node node freenet inet address addr if the lower level code detects the port forwarding is broken it will call this method public void set port forwarding broken allowconnection peernode freenetinetaddress setportforwardingbroken public interface any insert sender public abstract int get status anyinsertsender getstatus public abstract int get status public abstract short gethtl getstatus public abstract short gethtl return the current status as a string public abstract string get status string getstatusstring public abstract string get status string public abstract boolean sent request getstatusstring sentrequest public abstract boolean sent request public abstract long getuid sentrequest public interface time skew detector callback public void set time skew detected user alert timeskewdetectorcallback settimeskewdetecteduseralert public interface announcement callback public void completed announcementcallback public void completed public void bogus noderef string reason bogusnoderef public void completed public void bogus noderef string reason public void node failed peer node pn string reason bogusnoderef nodefailed peernode public void node failed peer node pn string reason rnf public void no more nodes nodefailed peernode nomorenodes rnf public void no more nodes public void added node peer node pn nomorenodes addednode peernode public void no more nodes public void added node peer node pn public void node not wanted nomorenodes addednode peernode nodenotwanted public void added node peer node pn public void node not wanted node valid but locally not added e g because we already have it public void node not added addednode peernode nodenotwanted nodenotadded decode with the key param factory the bucket factory to use to create the bucket to return the data in param max length the maximum size of the returned data in bytes bucketfactory maxlength bucket decode bucket factory factory int max length boolean dont decompress throws key decode exception io exception does the block contain metadata if not it contains real data boolean is metadata bucketfactory maxlength dontdecompress keydecodeexception ioexception ismetadata boolean is metadata return the client key for this key public client key get client key ismetadata clientkey clientkey getclientkey public client key get client key public byte memory decode throws key decode exception clientkey getclientkey memorydecode keydecodeexception final static int hash sha256 1 public key get key hash_sha256 getkey public key get key public byte get raw headers getkey getrawheaders public key get key public byte get raw headers public byte get raw data getkey getrawheaders getrawdata public byte get raw headers public byte get raw data public byte get pubkey bytes getrawheaders getrawdata getpubkeybytes public interface packet socket handler extends socket handler the maximum size of a packet not including transport layer headers int get max packet size packetsockethandler sockethandler getmaxpacketsize send a block of encoded bytes to a peer this is called by send and by incoming packet filter process outgoing param block to send the data block to send param destination the peer to send it to incomingpacketfilter processoutgoing blocktosend public void send packet byte block to send peer destination boolean allow local addresses throws local address exception get the size of the transport layer headers for byte accounting purposes public int get headers length sendpacket blocktosend allowlocaladdresses localaddressexception getheaderslength public int get headers length set the decryption filter to which incoming packets will be fed public void set low level filter incoming packet filter f getheaderslength setlowlevelfilter incomingpacketfilter public void set low level filter incoming packet filter f how big must the pending data be before we send a packet includes transport layer headers public int get packet send threshold setlowlevelfilter incomingpacketfilter getpacketsendthreshold public int get packet send threshold does this port appear to be port forwarded see address tracker int get detected connectivity status getpacketsendthreshold addresstracker getdetectedconnectivitystatus process an incoming packet this method should call usm decode packet and usm check filters if necessary to decode and dispatch messages param buf the buffer to read from note that this may be reused later on any data to keep must be copied param offset the offset to start reading from param length the length in bytes to read param peer the peer which sent us the packet we only know the peer because it s incoming we are supposed to create or find peer context s for the message s param now the exact time at which the packet was received decodepacket checkfilters peercontext outgoing packets are handled elsewhere is the given connection closed boolean is disconnected peer context context isdisconnected peercontext called when the filter is matched it will have been removed before the callback is called and no locks should be held param m the message which matched the filter check whether the filter should be removed note that usm locks may be held by the caller when this is called the implementation should not do anything that might cause usm related locks to be taken or messages to be sent return true if the filter should be immediately timed out boolean should timeout called when the filter times out and is removed from the list of filters to match void on timeout shouldtimeout ontimeout called when the filter is dropped because a connection is dropped param ctx called when the filter is dropped because a connection is restarted param ctx public interface byte counter sent some bytes includes any bytes flagged as already reported to throttle public void sent bytes int x bytecounter sentbytes public void sent bytes int x public void received bytes int x sentbytes receivedbytes sent payload only include the number of bytes of actual payload i e data from the user s point of view as opposed to overhead important this will also be reported to sent bytes do not add the total from sent bytes to the total from sent payload bytes or you will double count sentbytes sentbytes sentpayloadbytes public interface peer context largely opaque interface for now peer get peer peercontext getpeer peer get peer force the peer to disconnect param purge if true the message queue and trackers will be dumped void force disconnect boolean dump getpeer forcedisconnect void force disconnect boolean dump is the peer connected have we established the session link boolean is connected forcedisconnect isconnected boolean is connected is the peer connected are we able to route requests to it boolean is routable isconnected isroutable boolean is routable peer version if this is supported else 1 int get version number isroutable getversionnumber int get version number send a message to the node public void send async message msg async message callback cb byte counter ctr throws not connected exception getversionnumber sendasync asyncmessagecallback bytecounter notconnectedexception public void send async message msg async message callback cb byte counter ctr throws not connected exception send a throttled message to the node may block for a long time throws sync send waited too long exception public void send throttled message message msg int packet size byte counter ctr int timeout boolean wait for sent async message callback callback throws not connected exception waited too long exception sync send waited too long exception sendasync asyncmessagecallback bytecounter notconnectedexception syncsendwaitedtoolongexception sendthrottledmessage packetsize bytecounter waitforsent asyncmessagecallback notconnectedexception waitedtoolongexception syncsendwaitedtoolongexception public void send throttled message message msg int packet size byte counter ctr int timeout boolean wait for sent async message callback callback throws not connected exception waited too long exception sync send waited too long exception get the current boot id this is a random number that changes every time the node starts up public long get bootid sendthrottledmessage packetsize bytecounter waitforsent asyncmessagecallback notconnectedexception waitedtoolongexception syncsendwaitedtoolongexception getbootid public long get bootid get the packet throttle for the node s current address for the standard packet size if the address changes then we get a new throttle public packet throttle get throttle getbootid packetthrottle packetthrottle getthrottle public packet throttle get throttle get the socket handler which handles incoming packets from this node socket handler get socket handler packetthrottle getthrottle sockethandler sockethandler getsockethandler socket handler get socket handler get the outgoing packet mangler which encrypts outgoing packets to this node outgoing packet mangler get outgoing mangler sockethandler getsockethandler outgoingpacketmangler outgoingpacketmangler getoutgoingmangler outgoing packet mangler get outgoing mangler get a weak reference to this context hopefully there is only one of these for the whole object they are quite expensive weak reference extends peer context get weak ref outgoingpacketmangler getoutgoingmangler weakreference weakreference peercontext getweakref weak reference extends peer context get weak ref compact to string string short to string weakreference peercontext getweakref tostring shorttostring string short to string report a transfer failure void transfer failed string reason shorttostring transferfailed handle a message param m return false if we did not handle the message and want it to be passed on to the next filter called when the packet actually leaves the node this does not mean that it has been successfully recieved by the partner node on a lossy transport called when the packet is actually acknowledged by the other node this is the end of the transaction on a non lossy transport this may be called immediately after sent public void acknowledged called if the node is disconnected while the packet is queued or after it has been sent terminal public void disconnected public void disconnected called if the packet is lost due to an internal error public void fatal error fatalerror public interface port forward sensitive socket handler extends socket handler something has changed at a higher level suggesting the port forwarding status may be bogus so we need to rescan void rescan port forward portforwardsensitivesockethandler sockethandler rescanportforward public interface address matcher public boolean matches inet address address addressmatcher inetaddress public boolean matches inet address address get the human readable version of the matcher public string get human representation inetaddress gethumanrepresentation public static final string version id writable to data output stream java v 1 1 2005 01 29 19 12 10 amphibian exp public void write to data output stream data output stream stream throws io exception writabletodataoutputstream writetodataoutputstream dataoutputstream ioexception retrieve the value of a hash by filling the provided int with n elements of the hash where n is the bitlength of the hash 32 param digest int into which to place n elements param offset index of first of the n elements add one byte to the digest when this is implemented all of the abstract class methods end up calling this method for types other than bytes param b byte to add add many bytes to the digest param data byte data to add param offset start byte param length number of bytes to hash public void update byte data int offset int length adds the entire contents of the byte array to the digest public void update byte data returns the completed digest reinitializing the hash function return the byte array result write completed digest into the given buffer param buffer the buffer to write into param offset the byte offset at which to start writing param reset if true the hash function is reinitialized after writing to the buffer public void digest boolean reset byte buffer int offset return the hash size of this digest in bits public int digest size digestsize initializes the cipher context with the given key this might entail performing pre encryption calculation of subkeys s boxes etc void initialize byte key returns the key size in bits of the given block cipher int get key size getkeysize int get key size returns the block size in bits of the given block cipher int get block size getkeysize getblocksize enciphers the contents of b block b where block must be equal to get block size 8 the result is placed in result and too has to have length get block size 8 block and result may refer to the same array warning it is not a guarantee that b block b will not be over written in the course of the algorithm getblocksize getblocksize deciphers the contents of b block b where block must be equal to get block size 8 the result is placed in result and too has to have length get block size 8 block and result may refer to the same array warning it is not a guarantee that b block b will not be over written in the course of the algorithm getblocksize getblocksize public string write as field public string to long string writeasfield tolongstring public interface enumerable option callback public string get possible values enumerableoptioncallback getpossiblevalues public string get possible values return the current value public string get getpossiblevalues public interface charset extractor string get charset bucket data string parse charset throws data filter exception io exception charsetextractor getcharset parsecharset datafilterexception ioexception called when a freenet uri is found param uri the uri fixme indicate the type of the link e g inline image hyperlink etc called when a freenet uri is found param uri the uri fixme indicate the type of the link e g inline image hyperlink etc called when some plain text is processed this is used typically by spiders to index pages by their content param text the text will already have been fed through whatever decoding is necessary depending on the type of the source document e g html decoder will need to be re encoded before being sent to e g a browser param type can be null or may be for example the name of the html tag directly surrounding the text e g title lets you find page titles param baseuri the current base uri for this page the base uri is not necessarily the uri of the page it s the uri against which ur is on the page are resolved it defaults to the uri of the page but can be overridden by base href in html for example htmldecoder uris process a uri if it cannot be turned into something sufficiently safe then return null param override type force the return type throws comment exception if the uri is nvalid or unacceptable in some way overridetype commentexception process a uri if it cannot be turned into something sufficiently safe then return null param override type force the return type throws comment exception if the uri is nvalid or unacceptable in some way overridetype commentexception process a base uri in the page not only is this filtered it affects all relative uri s on the page process plain text notification only can t modify type can be null or can correspond for example to html tag name around text for example title note that the string will have been fed through the relevant decoder if necessary e g html decoder it must be re encoded if it is sent out as text to a browser htmldecoder process a form on the page param method the form sending method normally get or post param action the uri to send the form to return the new action uri or null if the form is not allowed throws comment exception commentexception public interface content data filter public bucket read filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception contentdatafilter readfilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception filter callback cb throws data filter exception io exception public bucket write filter bucket data bucket factory bf string charset hash map string string other params filter callback cb throws data filter exception io exception filtercallback datafilterexception ioexception writefilter bucketfactory hashmap otherparams filtercallback datafilterexception ioexception public interface link enabled callback whether to show the link param ctx boolean is enabled toadlet context ctx linkenabledcallback isenabled toadletcontext register a toadlet all requests whose url starts with the given prefix will be passed to this toadlet param at front if true add to front of list where is checked first else add to back of list where is checked last atfront find a toadlet by uri throws uri syntax exception throws redirect exception throws permanent redirect exception urisyntaxexception redirectexception permanentredirectexception public toadlet find toadlet uri uri throws permanent redirect exception get the name of the theme to be used by all the toadlets public theme get theme findtoadlet permanentredirectexception gettheme public theme get theme get the form password public string get form password gettheme getformpassword public string get form password is the given ip address allowed full access to the node public boolean is allowed full access inet address remote addr getformpassword isallowedfullaccess inetaddress remoteaddr public boolean is allowed full access inet address remote addr whether to tell spiders to go away public boolean do robots isallowedfullaccess inetaddress remoteaddr dorobots public boolean do robots public html node add form child html node parent node string target string name dorobots htmlnode addformchild htmlnode parentnode public html node add form child html node parent node string target string name public boolean enable persistent connections htmlnode addformchild htmlnode parentnode enablepersistentconnections public boolean enable persistent connections public boolean enable inline prefetch enablepersistentconnections enableinlineprefetch public boolean enable inline prefetch get the bucket factory public bucket factory get bucket factory enableinlineprefetch bucketfactory bucketfactory getbucketfactory public bucket factory get bucket factory can we deal with pos ts yet public boolean allow posts bucketfactory getbucketfactory posts allowposts is public gateway mode enabled if so users with full access will still be able to configure the node etc but everyone else will not have access to the download queue or anything else that might conceivably result in a dos public boolean public gateway mode public boolean enable activelinks publicgatewaymode enableactivelinks public boolean enable activelinks public boolean isf proxy javascript enabled enableactivelinks isfproxyjavascriptenabled write reply headers param code http code param desc http code description param mvt any extra headers param mime type the mime type of the reply param length the length of the reply param m time the modification time of the data being sent or null for now and disabling caching mimetype mtime void send reply headers int code string desc multi value table string string mvt string mime type long length date m time throws toadlet context closed exception io exception void send reply headers int code string desc multi value table string string mvt string mime type long length throws toadlet context closed exception io exception sendreplyheaders multivaluetable mimetype mtime toadletcontextclosedexception ioexception sendreplyheaders multivaluetable mimetype toadletcontextclosedexception ioexception void send reply headers int code string desc multi value table string string mvt string mime type long length throws toadlet context closed exception io exception write data note you must send reply headers first void write data byte data int offset int length throws toadlet context closed exception io exception sendreplyheaders multivaluetable mimetype toadletcontextclosedexception ioexception writedata toadletcontextclosedexception ioexception force a disconnection after handling this request used only when a throwable was thrown and we don t know what the state of the connection is fixme we could handle this better by remembering whether headers have been sent how long the attached data should be how much data has been sent etc convenience method that simply calls link write data byte int int param data the data to write throws toadlet context closed exception if the context has already been closed throws io exception if an i o error occurs writedata toadletcontextclosedexception ioexception void write data byte data throws toadlet context closed exception io exception write data from a bucket you must send reply headers first void write data bucket data throws toadlet context closed exception io exception writedata toadletcontextclosedexception ioexception writedata toadletcontextclosedexception ioexception void write data bucket data throws toadlet context closed exception io exception get the page maker object page maker get page maker writedata toadletcontextclosedexception ioexception pagemaker getpagemaker page maker get page maker bucket factory get bucket factory pagemaker getpagemaker bucketfactory getbucketfactory bucket factory get bucket factory multi value table string string get headers bucketfactory getbucketfactory multivaluetable getheaders add a form node to an html node under construction this will have the correct enctype and form password set already so all the caller needs to do is add its specific fields param parent node the parent html node param target where the form should be pos ted to param id html name for the form for stylesheet script access will be added as both id and name return the form html node htmlnode formpassword parentnode htmlnode posted htmlnode html node add form child html node parent node string target string id is this toadlet allowed full access to the node including the ability to reconfigure it restart it etc boolean is allowed full access htmlnode addformchild htmlnode parentnode isallowedfullaccess boolean is allowed full access return a robots txt excluding all spiders and other non browser http clients boolean do robots isallowedfullaccess dorobots boolean do robots toadlet container get container dorobots toadletcontainer getcontainer public interface client event returns a string describing the event public string get description clientevent getdescription public string get description returns a unique code for this event public int get code getdescription getcode hears an event param container the database context the event was generated in note that it may not have been generated in a database context at all in this case container will be null and you should use context to schedule a db job dbjob called when the event producer gets remove from object container if the listener is the main listener which probably called remove from it should do nothing if it s a tag along but request specific listener it may need to remove itself eventproducer removefrom objectcontainer removefrom sends the event to all registered event listeners param ce the client event to raise eventlisteners clientevent adds an event listener that will receive all events produced by the implementing object param cel the client event listener to add eventlistener clienteventlistener removes an event listener that will no loger receive events produced by the implementing object param cel the client event listener to remove return true if a listener was removed false otherwise eventlistener clienteventlistener boolean remove event listener client event listener cel void remove from object container container removeeventlistener clienteventlistener removefrom objectcontainer public interface cooldown queue add a key to the end of the queue returns the time at which it will be valid again public abstract long add key key sendable get client object container container cooldownqueue sendableget objectcontainer remove a key whose cooldown time has passed param dont care after if the next item to come out of the cooldown queue is more than this many millis after now return null return either an array of key s or a long indicating the time at which the next key will be removed from the cooldown or null if no keys have passed their cooldown time dontcareafter public abstract object remove key before long now long dont care after object container container int max keys return true if the key was found public abstract boolean remove key key key sendable get client long time object container container removekeybefore dontcareafter objectcontainer maxkeys removekey sendableget objectcontainer public interface sendable request set public sendable request list requests object container container sendablerequestset sendablerequest listrequests objectcontainer public sendable request list requests object container container public boolean add request sendable request req object container container sendablerequest listrequests objectcontainer addrequest sendablerequest objectcontainer public boolean add request sendable request req object container container public boolean remove request sendable request req object container container addrequest sendablerequest objectcontainer removerequest sendablerequest objectcontainer public boolean remove request sendable request req object container container public void remove from object container container removerequest sendablerequest objectcontainer removefrom objectcontainer public interface client put state get the base client putter responsible for this request state public abstract base client putter get parent clientputstate baseclientputter baseclientputter getparent public abstract base client putter get parent cancel the request public abstract void cancel object container container client context context baseclientputter getparent objectcontainer clientcontext public abstract void cancel object container container client context context schedule the request public abstract void schedule object container container client context context throws insert exception objectcontainer clientcontext objectcontainer clientcontext insertexception get the token an object which is passed around with the insert and may be used by callers once the callback has finished with this fetch it will call remove from to instruct the fetch to remove itself and all its subsidiary objects from the database param container removefrom called when a new edition is found and downloaded param edition the usk edition number param data the retrieved data void on found usk origusk long edition fetch result data priority at which the polling should run normally short get polling priority normal onfound fetchresult getpollingprioritynormal short get polling priority normal priority at which the polling should run when starting or immediately after making some progress short get polling priority progress getpollingprioritynormal getpollingpriorityprogress create a key listener a transient object used to determine which keys we want and to handle any blocks found return null if the has key listener is finished cancelled etc throws io exception keylistener haskeylistener ioexception key listener make key listener object container container client context context throws key listener construction exception is it cancelled boolean is cancelled object container container keylistener makekeylistener objectcontainer clientcontext keylistenerconstructionexception iscancelled objectcontainer boolean is cancelled object container container notify that make key listener failed void on failed key listener construction exception e object container container client context context iscancelled objectcontainer makekeylistener onfailed keylistenerconstructionexception objectcontainer clientcontext public interface client callback public void on success fetch result result client getter state object container container clientcallback onsuccess fetchresult clientgetter objectcontainer public void on success fetch result result client getter state object container container public void on failure fetch exception e client getter state object container container onsuccess fetchresult clientgetter objectcontainer onfailure fetchexception clientgetter objectcontainer public void on failure fetch exception e client getter state object container container public void on success base client putter state object container container onfailure fetchexception clientgetter objectcontainer onsuccess baseclientputter objectcontainer public void on success base client putter state object container container public void on failure insert exception e base client putter state object container container onsuccess baseclientputter objectcontainer onfailure insertexception baseclientputter objectcontainer public void on failure insert exception e base client putter state object container container public void on generateduri freeneturi uri base client putter state object container container onfailure insertexception baseclientputter objectcontainer ongenerateduri baseclientputter objectcontainer public void on generateduri freeneturi uri base client putter state object container container called when freenet async thinks that the request should be serialized to disk if it is a persistent request public void on major progress object container container ongenerateduri baseclientputter objectcontainer onmajorprogress objectcontainer public void on major progress object container container called when the inserted data is fetchable don t rely on this public void on fetchable base client putter state object container container onmajorprogress objectcontainer onfetchable baseclientputter objectcontainer public interface get completion callback public void on success fetch result result client get state state object container container client context context getcompletioncallback onsuccess fetchresult clientgetstate objectcontainer clientcontext public void on success fetch result result client get state state object container container client context context public void on failure fetch exception e client get state state object container container client context context onsuccess fetchresult clientgetstate objectcontainer clientcontext onfailure fetchexception clientgetstate objectcontainer clientcontext public void on failure fetch exception e client get state state object container container client context context called when the client get state knows that it knows about all the blocks it will need to fetch public void on block set finished client get state state object container container client context context onfailure fetchexception clientgetstate objectcontainer clientcontext clientgetstate onblocksetfinished clientgetstate objectcontainer clientcontext public void on block set finished client get state state object container container client context context public void on transition client get state old state client get state new state object container container onblocksetfinished clientgetstate objectcontainer clientcontext ontransition clientgetstate oldstate clientgetstate newstate objectcontainer public void on transition client get state old state client get state new state object container container public void on expected size long size object container container client context context ontransition clientgetstate oldstate clientgetstate newstate objectcontainer onexpectedsize objectcontainer clientcontext public void on expected size long size object container container client context context public void on expectedmime string mime object container container client context context onexpectedsize objectcontainer clientcontext onexpectedmime objectcontainer clientcontext public void on expectedmime string mime object container container client context context public void on finalized metadata object container container onexpectedmime objectcontainer clientcontext onfinalizedmetadata objectcontainer get a block by its key param key the key of the block to get return a block or null if there is no block with that key add a block param block the block to add get the set of all the keys of all the blocks return a set of the keys of the blocks in the block set not guaranteed to be kept up to date read only blockset public set keys get a high level block given a high level key public client key block get client key key clientkeyblock clientkey public interface encodeable attempt to encode the block if necessary public void try encode object container container client context context tryencode objectcontainer clientcontext public void try encode object container container client context context public boolean persistent tryencode objectcontainer clientcontext public boolean persistent public short get priority class object container container getpriorityclass objectcontainer public interface put completion callback public void on success client put state state object container container client context context putcompletioncallback onsuccess clientputstate objectcontainer clientcontext public void on success client put state state object container container client context context public void on failure insert exception e client put state state object container container client context context onsuccess clientputstate objectcontainer clientcontext onfailure insertexception clientputstate objectcontainer clientcontext public void on failure insert exception e client put state state object container container client context context called when we know the final uri of the state in question the current state eventually calls this on the client putter which relays to the fcp layer which sends a uri generated message public void on encode base client key usk client put state state object container container client context context onfailure insertexception clientputstate objectcontainer clientcontext currentstate clientputter urigenerated onencode baseclientkey clientputstate objectcontainer clientcontext public void on encode base client key usk client put state state object container container client context context public void on transition client put state old state client put state new state object container container onencode baseclientkey clientputstate objectcontainer clientcontext ontransition clientputstate oldstate clientputstate newstate objectcontainer only called if explicitly asked for in which case generally the metadata won t be inserted won t be called if there isn t any called when enough data has been inserted that the file can be retrieved even if not all data has been inserted yet note that this is only supported for splitfiles if you get on success first assume that on fetchable isn t coming onsuccess onfetchable public void on fetchable client put state state object container container called when the client put state knows that it knows about all the blocks it will need to put public void on block set finished client put state state object container container client context context onfetchable clientputstate objectcontainer clientputstate onblocksetfinished clientputstate objectcontainer clientcontext public interface client get state public void schedule object container container client context context throws key listener construction exception clientgetstate objectcontainer clientcontext keylistenerconstructionexception public void schedule object container container client context context throws key listener construction exception cancel the request and call on failure on the callback in order to tell downstream ultimately the client that cancel has succeeded and to allow it to call remove from to avoid a database leak public void cancel object container container client context context objectcontainer clientcontext keylistenerconstructionexception onfailure removefrom objectcontainer clientcontext public void cancel object container container client context context public long get token objectcontainer clientcontext gettoken once the callback has finished with this fetch it will call remove from to instruct the fetch to remove itself and all its subsidiary objects from the database warning it is possible that the caller will get deactivated be careful param container removefrom public interface db job runner public void queue db job job int priority boolean check dupes dbjobrunner dbjob checkdupes public void queue db job job int priority boolean check dupes run this database job blocking if we are already on the database thread run it inline otherwise schedule it at the specified priority and wait for it to finish public void run blocking db job job int priority dbjob checkdupes runblocking dbjob public void run blocking db job job int priority public boolean on database thread runblocking dbjob ondatabasethread public boolean on database thread public int get queue size int priority ondatabasethread getqueuesize queue a database job to be executed just after restart param early if true the job will be run just after startup at high priority the priority given determines the order of such jobs if false it will be queued to the database job scheduler at the given priority late jobs are responsible for removing themselves public void queue restart job db job job int priority object container container boolean early remove a queued on restart database job public void remove restart job db job job int priority object container container queuerestartjob dbjob objectcontainer removerestartjob dbjob objectcontainer found the latest edition param l the edition number param key a copy of the key with new edition set param new known good if the highest known good edition which has actually been fetched with what it pointed to has increased otherwise the highest known ssk slot has been increased from which searches will start but we do not know whether it can actually be fetched successfully param new slot too if new known good is set this indicates whether it is also a new highest known ssk slot if new known good is not set there is always a new highest known ssk slot newknowngood newslottoo newknowngood newknowngood void on found edition long l usk key object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too priority at which the polling should run normally short get polling priority normal onfoundedition objectcontainer clientcontext newknowngood newslottoo getpollingprioritynormal short get polling priority normal priority at which the polling should run when starting or immediately after making some progress short get polling priority progress getpollingprioritynormal getpollingpriorityprogress public interface usk fetcher callback extends usk callback failed to find any edition at all later than or equal to the specified hint void on failure object container container client context context uskfetchercallback uskcallback onfailure objectcontainer clientcontext void on failure object container container client context context void on cancelled object container container client context context onfailure objectcontainer clientcontext oncancelled objectcontainer clientcontext void on cancelled object container container client context context found the latest edition this is terminal for a usk fetcher callback it isn t for a usk callback subscription param l the edition number param key the key void on found edition long l usk key object container container client context context boolean metadata short codec byte data boolean new known good boolean new slot too oncancelled objectcontainer clientcontext uskfetchercallback uskcallback onfoundedition objectcontainer clientcontext newknowngood newslottoo interface usk checker callback data not found public void ondnf client context context uskcheckercallback clientcontext public void ondnf client context context successfully found the latest version of the key param block public void on success clientssk block block client context context clientcontext onsuccess clientsskblock clientcontext public void on success clientssk block block client context context error committed by author public void on fatal author error client context context onsuccess clientsskblock clientcontext onfatalauthorerror clientcontext public void on fatal author error client context context network on our node or on nodes we have been talking to public void on network error client context context onfatalauthorerror clientcontext onnetworkerror clientcontext public void on network error client context context request cancelled public void on cancelled client context context onnetworkerror clientcontext oncancelled clientcontext public void on cancelled client context context get priority to run the request at public short get priority oncancelled clientcontext getpriority public interface healing queue queue a bucket of data to insert as a chk void queue bucket data client context context healingqueue clientcontext fast guess at whether we want a key or not usually implemented by a bloom filter locking should avoid external locking if possible will be called within the crs base lock return true if we probably want the key false if we definitely don t want it crsbase do we want the key this is called by the ulpr code because fetching the key will involve significant work trip pending key on the other hand will go straight to handle block return 1 if we don t want the key otherwise the priority of the request interested in the key trippendingkey handleblock find the requests related to a specific key used in retrying after cooldown caller should call probably want key first probablywantkey public sendable get get requests for key key key byte salted key object container container client context context handle the found data if we really want it public boolean handle block key key byte salted key key block found object container container client context context sendableget getrequestsforkey saltedkey objectcontainer clientcontext handleblock saltedkey keyblock objectcontainer clientcontext public boolean handle block key key byte salted key key block found object container container client context context is this related to a persistent request boolean persistent handleblock saltedkey keyblock objectcontainer clientcontext priority of the associated request locking should avoid external locking if possible will be called within the crs base lock param container database handle crsbase return true if when checking the datastore on initial registration we should not promote any blocks found public abstract boolean dont cache public long count keys dontcache countkeys return the parent has key listener this does mean it will be pinned in ram but it can be deactivated so it s not a big deal locking should avoid external locking if possible will be called within the crs base lock haskeylistener crsbase public has key listener get has key listener deactivate the request once it has been removed public void on remove haskeylistener gethaskeylistener onremove has the request finished if every key has been found or enough keys have been found return true so that the caller can remove it from the list public boolean is empty public boolean isssk isempty public interface db job void run object container container client context context dbjob objectcontainer clientcontext public interface high level simple client set the maximum length of the fetched data public void set max length long max length highlevelsimpleclient setmaxlength maxlength public void set max length long max length set the maximum length of any intermediate data e g zip manifests public void set max intermediate length long max intermediate length setmaxlength maxlength setmaxintermediatelength maxintermediatelength blocking fetch of a uri throws fetch exception if there is an error fetching the data fetchexception public fetch result fetch freeneturi uri throws fetch exception blocking fetch of a uri with a configurable max size public fetch result fetch freeneturi uri long max size throws fetch exception fetchresult fetchexception fetchresult maxsize fetchexception public fetch result fetch freeneturi uri long max size throws fetch exception blocking fetch of a uri with a configurable max size and context object public fetch result fetch freeneturi uri long max size request client context throws fetch exception fetchresult maxsize fetchexception fetchresult maxsize requestclient fetchexception public fetch result fetch freeneturi uri long max size request client context throws fetch exception non blocking fetch of a uri with a configurable max size in bytes context object callback and context public client getter fetch freeneturi uri long max size request client context client callback callback fetch context fctx throws fetch exception fetchresult maxsize requestclient fetchexception clientgetter maxsize requestclient clientcallback fetchcontext fetchexception blocking insert param filename hint if set insert a single file manifest containing only this file under the given filename throws insert exception if there is an error inserting the data filenamehint insertexception public freeneturi insert insert block insert boolean getchk only string filename hint throws insert exception non blocking insert public client putter insert insert block insert boolean getchk only string filename hint boolean is metadata insert context ctx client callback cb throws insert exception insertblock getchkonly filenamehint insertexception clientputter insertblock getchkonly filenamehint ismetadata insertcontext clientcallback insertexception public client putter insert insert block insert boolean getchk only string filename hint boolean is metadata insert context ctx client callback cb throws insert exception blocking insert of a redirect public freeneturi insert redirect freeneturi inserturi freeneturi target throws insert exception clientputter insertblock getchkonly filenamehint ismetadata insertcontext clientcallback insertexception insertredirect insertexception public freeneturi insert redirect freeneturi inserturi freeneturi target throws insert exception blocking insert of multiple files as a manifest or zip manifest etc public freeneturi insert manifest freeneturi inserturi hash map buckets by name string default name throws insert exception insertredirect insertexception insertmanifest hashmap bucketsbyname defaultname insertexception public freeneturi insert manifest freeneturi inserturi hash map buckets by name string default name throws insert exception public fetch context get fetch context insertmanifest hashmap bucketsbyname defaultname insertexception fetchcontext getfetchcontext public fetch context get fetch context public fetch context get fetch context long size fetchcontext getfetchcontext fetchcontext getfetchcontext get an insert context param force non persistent if true force the request to use the non persistent bucket pool insertcontext forcenonpersistent public insert context get insert context boolean force non persistent add a client event listener public void add global hook client event listener listener insertcontext getinsertcontext forcenonpersistent clienteventlistener addglobalhook clienteventlistener generates a new key pair consisting of the insert uri at index 0 and the request uri at index 1 param doc name the document name return an array containing the insert and request uri docname prefetch a key at a very low priority if it hasn t been fetched within the timeout kill the fetch param uri param timeout public void prefetch freeneturi uri long timeout long max size set allowed types public void prefetch freeneturi uri long timeout long max size set allowed types short prio maxsize allowedtypes maxsize allowedtypes public interface archive extract callback got the data note that the bucket will be persistent if the caller asked for an off thread extraction public void got bucket bucket data object container container client context context archiveextractcallback gotbucket objectcontainer clientcontext public void got bucket bucket data object container container client context context not in the archive public void not in archive object container container client context context gotbucket objectcontainer clientcontext notinarchive objectcontainer clientcontext public void not in archive object container container client context context failed restart public void on failed archive restart exception e object container container client context context notinarchive objectcontainer clientcontext onfailed archiverestartexception objectcontainer clientcontext public void on failed archive restart exception e object container container client context context failed for some other reason public void on failed archive failure exception e object container container client context context onfailed archiverestartexception objectcontainer clientcontext onfailed archivefailureexception objectcontainer clientcontext public void on failed archive failure exception e object container container client context context public void remove from object container container onfailed archivefailureexception objectcontainer clientcontext removefrom objectcontainer public interface splitfile block get block number 0 k data blocks k n check blocks abstract int get number splitfileblock getnumber abstract int get number has data abstract boolean has data getnumber hasdata abstract boolean has data get data abstract bucket get data hasdata getdata abstract bucket get data set data abstract void set data bucket data getdata setdata abstract void set data bucket data abstract void store to object container container setdata storeto objectcontainer get the metadata for this zip manifest as a bucket the returned bucket will always be non persistent return the metadata as a bucket or null param manager the archive manager throws fetch exception if the container could not be fetched throws metadata parse exception if there was an error parsing intermediary metadata public abstract bucket get metadata archive context archive context archive manager manager throws archive failure exception archive restart exception archivemanager fetchexception metadataparseexception getmetadata archivecontext archivecontext archivemanager archivefailureexception archiverestartexception get a file from this zip manifest as a bucket if possible read it from cache if not return null the returned bucket will always be non persistent param in split zip manifest if true indicates that the key points to a splitfile zip manifest which means that we need to pass a flag to the fetcher to tell it to pretend it was a straight splitfile param manager the archive manager throws fetch exception throws metadata parse exception public abstract bucket get string internal name archive context archive context archive manager manager throws archive failure exception archive restart exception insplitzipmanifest archivemanager fetchexception metadataparseexception internalname archivecontext archivecontext archivemanager archivefailureexception archiverestartexception metadata parse exception fetch exception get the archive type public abstract archive type get archive type metadataparseexception fetchexception archive_type getarchivetype public abstract archive type get archive type get the key public abstract freeneturi get key archive_type getarchivetype getkey unpack a fetched archive to cache and call the callback if there is one param bucket the downloaded data for the archive param actx the archive context param element the single element that the caller is especially interested in param callback callback to be notified whether the content is available and if so fed the data param manager the archive manager throws archive failure exception throws archive restart exception public abstract void extract to cache bucket bucket archive context actx string element archive extract callback callback archive manager manager archivecontext archivemanager archivefailureexception archiverestartexception extracttocache archivecontext archiveextractcallback archivemanager unpack a fetched archive on a separate thread for a persistent caller this involves add a tag to the database so that it will be restarted on a crash run the actual unpack on a separate thread copy the data to a persistent bucket schedule a database job call the callback param bucket param actx param element param callback param container param context public abstract void extract persistent off thread bucket bucket boolean free bucket archive context actx string element archive extract callback callback object container container client context context public abstract void activate for execution object container container extractpersistentoffthread freebucket archivecontext archiveextractcallback objectcontainer clientcontext activateforexecution objectcontainer public abstract void activate for execution object container container public abstract archive handler clone handler activateforexecution objectcontainer archivehandler clonehandler public abstract archive handler clone handler public abstract void remove from object container container archivehandler clonehandler removefrom objectcontainer the implementor must copy the data manually from the arrays on the fec job because db4o persists arrays as inline values so we cannot update the array param container param context param job fecjob public void on encoded segment object container container client context context fec job job bucket data buckets bucket check buckets splitfile block data blocks splitfile block check blocks public void on decoded segment object container container client context context fec job job bucket data buckets bucket check buckets splitfile block data blocks splitfile block check blocks onencodedsegment objectcontainer clientcontext fecjob databuckets checkbuckets splitfileblock datablocks splitfileblock checkblocks ondecodedsegment objectcontainer clientcontext fecjob databuckets checkbuckets splitfileblock datablocks splitfileblock checkblocks public void on decoded segment object container container client context context fec job job bucket data buckets bucket check buckets splitfile block data blocks splitfile block check blocks something broke public void on failed throwable t object container container client context context ondecodedsegment objectcontainer clientcontext fecjob databuckets checkbuckets splitfileblock datablocks splitfileblock checkblocks onfailed objectcontainer clientcontext